Explorar o código

Feature #TASK_QT-18250 现在uprobe点能正常挂载,解决handle_stream无return的问题。

rock hai 7 meses
pai
achega
79227db8ff
Modificáronse 2 ficheiros con 32 adicións e 29 borrados
  1. 8 8
      ebpftracer/ebpf/utrace/go/net/grpc.server.probe.bpf.c
  2. 24 21
      ebpftracer/tls.go

+ 8 - 8
ebpftracer/ebpf/utrace/go/net/grpc.server.probe.bpf.c

@@ -141,14 +141,14 @@ handleStream(struct pt_regs *ctx, void *stream_ptr, struct go_iface *go_context)
     // start_span(&start_span_params);
 
     // Set attributes
-    void *method_ptr = stream_ptr + stream_method_ptr_pos;
-    bool parsed_method =
-        get_go_string_from_user_ptr(method_ptr, grpcReq->method, sizeof(grpcReq->method));
-    if (!parsed_method) {
-        bpf_printk("grpc:server:handleStream: failed to read gRPC method from stream");
-        bpf_map_delete_elem(&streamid_to_grpc_events, &stream_id);
-        return -3;
-    }
+    // void *method_ptr = stream_ptr + stream_method_ptr_pos;
+    // bool parsed_method =
+    //     get_go_string_from_user_ptr(method_ptr, grpcReq->method, sizeof(grpcReq->method));
+    // if (!parsed_method) {
+    //     bpf_printk("grpc:server:handleStream: failed to read gRPC method from stream");
+    //     bpf_map_delete_elem(&streamid_to_grpc_events, &stream_id);
+    //     return -3;
+    // }
 
     if (server_addr_supported) {
         void *http2server = get_argument(ctx, 3);

+ 24 - 21
ebpftracer/tls.go

@@ -297,7 +297,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, appInfo *AppInfo, codeType uint1
 		}
 		switch s.Name {
 		case goTlsWriteSymbol, goTlsReadSymbol:
-		case goExecute, goNewproc1, goRunqget, goServeHTTP, goTransport, goGrpcHttp2OperateHeader,goGrpcServerHandleStream:
+		case goExecute, goNewproc1, goRunqget, goServeHTTP, goTransport, goGrpcHttp2OperateHeader,goGrpcServerHandleStream,goGrpcServerWritestatus:
 		default:
 			continue
 		}
@@ -403,26 +403,29 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, appInfo *AppInfo, codeType uint1
 			}
 			klog.Infoln("google.golang.org/grpc.(*Server).handleStream ok")
 			links = append(links, l)
-			sStart := s.Value - textSection.Addr
-			sEnd := sStart + s.Size
-			if sEnd > textSectionLen {
-				continue
-			}
-			sBytes := textSectionData[sStart:sEnd]
-			returnOffsets := getReturnOffsets(ef.Machine, sBytes)
-			if len(returnOffsets) == 0 {
-				err = fmt.Errorf("failed to attach uprobe_server_handleStream2 no return offsets found")
-				klog.Errorln(err)
-				return nil, err
-			}
-			for _, offset := range returnOffsets {
-				l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_server_handleStream_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
-				if err != nil {
-					klog.WithError(err).Errorln(fmt.Errorf("failed to attach exit_runtime_newproc1 uprobe"))
-					return nil, err
-				}
-				links = append(links, l)
-			}
+			// sStart := s.Value - textSection.Addr
+			// sEnd := sStart + s.Size
+			// klog.Infoln("google.golang.org/grpc.(*Server).handleStream ok----111111")
+			// if sEnd > textSectionLen {
+			// 	continue
+			// }
+			// klog.Infoln("google.golang.org/grpc.(*Server).handleStream ok----2222")
+			// sBytes := textSectionData[sStart:sEnd]
+			// returnOffsets := getReturnOffsets(ef.Machine, sBytes)
+			// if len(returnOffsets) == 0 {
+			// 	err = fmt.Errorf("failed to attach uprobe_server_handleStream2 no return offsets found")
+			// 	klog.Errorln(err)
+			// 	return nil, err
+			// }
+			// for _, offset := range returnOffsets {
+			// 	l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_server_handleStream_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
+			// 	if err != nil {
+			// 		klog.WithError(err).Errorln(fmt.Errorf("failed to attach exit_runtime_newproc1 uprobe"))
+			// 		return nil, err
+			// 	}
+			// 	klog.Infoln("google.golang.org/grpc.(*Server).handleStream ok----")
+			// 	links = append(links, l)
+			// }
 		case goServeHTTP:
 			l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_HandlerFunc_ServeHTTP"], &link.UprobeOptions{Address: address})
 			if err != nil {