|
|
@@ -0,0 +1,37 @@
|
|
|
+package jattach
|
|
|
+
|
|
|
+/*
|
|
|
+#cgo CFLAGS: -I include
|
|
|
+#cgo amd64 LDFLAGS: ${SRCDIR}/lib/libjattach_amd64.a
|
|
|
+#cgo arm64 LDFLAGS: ${SRCDIR}/lib/libjattach_arm64.a
|
|
|
+#include <stdlib.h>
|
|
|
+// declaration jattach
|
|
|
+int jattach(int pid, int argc, char** argv, int print_output);
|
|
|
+*/
|
|
|
+import "C"
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "unsafe"
|
|
|
+)
|
|
|
+
|
|
|
+type JvmJattacher struct {
|
|
|
+ Pid uint32
|
|
|
+ Args []string
|
|
|
+ PrintOutput int
|
|
|
+}
|
|
|
+
|
|
|
+func (j *JvmJattacher) JAttach() (int, error) {
|
|
|
+ cArgs := make([]*C.char, len(j.Args))
|
|
|
+ for i, arg := range j.Args {
|
|
|
+ cArgs[i] = C.CString(arg)
|
|
|
+ defer C.free(unsafe.Pointer(cArgs[i])) // free mem
|
|
|
+ }
|
|
|
+
|
|
|
+ // call C func jattach
|
|
|
+ // cArgs to **C.char
|
|
|
+ result := C.jattach(C.int(j.Pid), C.int(len(j.Args)), (**C.char)(unsafe.Pointer(&cArgs[0])), C.int(j.PrintOutput))
|
|
|
+ if int(result) != 0 {
|
|
|
+ return int(result), fmt.Errorf("[JAttach] jattacher failed")
|
|
|
+ }
|
|
|
+ return int(result), nil
|
|
|
+}
|