|
|
@@ -2,10 +2,12 @@ package ebpftracer
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
-
|
|
|
+ "io/ioutil"
|
|
|
+ "strings"
|
|
|
|
|
|
"fmt"
|
|
|
"debug/elf"
|
|
|
+ "path/filepath"
|
|
|
|
|
|
"github.com/coroot/coroot-node-agent/utils"
|
|
|
|
|
|
@@ -15,7 +17,7 @@ import (
|
|
|
|
|
|
const (
|
|
|
// goServeHTTP = "net/http.serverHandler.ServeHTTP"
|
|
|
- binPath = "/root/code/jdk8u/build/linux-x86_64-normal-server-release/jdk/lib/amd64/libnio.so"
|
|
|
+ // binPath = "/root/code/jdk8u/build/linux-x86_64-normal-server-release/jdk/lib/amd64/libnio.so"
|
|
|
symbolsocketRead0 = "Java_sun_nio_ch_FileDispatcherImpl_read0"
|
|
|
)
|
|
|
|
|
|
@@ -24,12 +26,17 @@ func (t *Tracer) AttachJavaNioReadUprobes(pid uint32, insID utils.ID) []link.Lin
|
|
|
return nil
|
|
|
}
|
|
|
var links []link.Link
|
|
|
- ex, err := link.OpenExecutable(binPath)
|
|
|
+ bpath := getSoPath(pid, "nio.so")
|
|
|
+ if bpath == ""{
|
|
|
+ fmt.Println("can,t find the nio.so")
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ fmt.Println("find the nio.so path is ", bpath)
|
|
|
+ ex, err := link.OpenExecutable(bpath)
|
|
|
if err != nil {
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
- ef, err := elf.Open(binPath)
|
|
|
+ ef, err := elf.Open(bpath)
|
|
|
if err != nil {
|
|
|
return nil
|
|
|
}
|
|
|
@@ -108,7 +115,7 @@ func (t *Tracer) AttachJavaNioReadUprobes(pid uint32, insID utils.ID) []link.Lin
|
|
|
if len(links) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
- fmt.Println("jvm uprobes attached")
|
|
|
+ fmt.Println("jvm uprobes attached, pid is ", pid)
|
|
|
return links
|
|
|
}
|
|
|
|
|
|
@@ -133,3 +140,31 @@ func getCallNextMoveOffsets(machine elf.Machine, instructions []byte) []int {
|
|
|
}
|
|
|
return res
|
|
|
}
|
|
|
+
|
|
|
+func getSoPath(pid uint32, soname string) string{
|
|
|
+ // 获取进程的maps文件路径
|
|
|
+ mapsPath := fmt.Sprintf("/proc/%d/maps", pid)
|
|
|
+
|
|
|
+ // 读取maps文件内容
|
|
|
+ mapsData, err := ioutil.ReadFile(mapsPath)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("无法读取maps文件")
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
+ lines := strings.Split(string(mapsData), "\n")
|
|
|
+ for _, line := range lines {
|
|
|
+ fields := strings.Fields(line)
|
|
|
+ if len(fields) >= 6 {
|
|
|
+ perms := fields[1]
|
|
|
+ path := fields[len(fields)-1]
|
|
|
+
|
|
|
+ if strings.Contains(perms, "x") && filepath.Ext(path) == ".so" {
|
|
|
+ if strings.Contains(path, soname){
|
|
|
+ return path
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|