Просмотр исходного кода

Fixed #TASK_QT-9810 解决由于变量申请在栈上,导致的编译失败问题。

roger.wang 1 год назад
Родитель
Сommit
f7d62b2673

+ 2 - 2
ebpftracer/ebpf/utrace/go/include/span_context.h

@@ -241,11 +241,11 @@ static __always_inline void cw_string_to_span_context(char *str, struct apm_span
 	hex_string_to_bytes(str + type_from_start_pos, APM_TYPE_FROM_STRING_SIZE, ctx->type_from);
 	hex_string_to_bytes(str + sample_start_pos, APM_SAMPLE_STRING_SIZE, ctx->sample);
 	hex_string_to_bytes(str + host_id_start_pos, APM_HOST_ID_STRING_SIZE, ctx->host_id);
-	// hex_string_to_bytes(str + app_id_start_pos, APM_APP_ID_STRING_SIZE, ctx->app_id);
+	hex_string_to_bytes(str + app_id_start_pos, APM_APP_ID_STRING_SIZE, ctx->app_id);
 	hex_string_to_bytes(str + instance_id_start_pos, APM_INSTANCE_ID_STRING_SIZE, ctx->instance_id);
 	hex_string_to_bytes(str + trace_id_start_pos, APM_TRACE_ID_STRING_SIZE, ctx->trace_id);
 	hex_string_to_bytes(str + assumed_app_id_start_pos, APM_ASSUMED_APP_ID_STRING_SIZE, ctx->assumed_app_id);
-	// hex_string_to_bytes(str + span_id_start_pos, APM_SPAN_ID_STRING_SIZE, ctx->span_id);
+	hex_string_to_bytes(str + span_id_start_pos, APM_SPAN_ID_STRING_SIZE, ctx->span_id);
 }
 
 

+ 18 - 10
ebpftracer/ebpf/utrace/java/net/server.probe.bpf.c

@@ -23,6 +23,13 @@ struct {
 	__uint(max_entries, 1);
 } socket_heap SEC(".maps");
 
+struct {
+	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+	__type(key, int);
+	__type(value, struct apm_span_context);
+	__uint(max_entries, 1);
+} apm_span_context_heap SEC(".maps");
+
 struct {
     __uint(type, BPF_MAP_TYPE_ARRAY);
     __type(key, int); // 键类型为int
@@ -67,7 +74,7 @@ static __inline int is_http_header(const char *data)
 SEC("uprobe/Java_sun_nio_ch_FileDispatcherImpl_read0")
 int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 	//计算 rbp-0x30
-    bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0\n");
+    // bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0\n");
 	unsigned long jhttpdata_ptr;
 	jhttpdata_ptr = (ctx)->rbp;
 	jhttpdata_ptr = jhttpdata_ptr - 0x70;
@@ -80,7 +87,7 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 	unsigned long jbytechar_ptr;
 	long ret = bpf_probe_read_user(&jbytechar_ptr, sizeof(unsigned long), (void *) jhttpdata_ptr);
 	// bpf_printk("x/1gx (p rbp-0x30) value is %llx.\n", jbytechar_ptr);
-    bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ------22222222\n");
+    // bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ------22222222\n");
 	if (ret != 0) {
 		// bpf_printk("Failed to read first level ptr: %d\n", ret);
 		return 0;
@@ -89,7 +96,7 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 		// bpf_printk("First level pointer is null.\n");
 		return 0;
 	}
-    bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ----111111111\n");
+    // bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ----111111111\n");
 	
 	//x/s addr
 	int key = 0;
@@ -103,7 +110,7 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 		return 0;
 	}
 
-	bpf_printk("read data is : %s\n", map_data->payload);
+	// bpf_printk("read data is : %s\n", map_data->payload);
 	// if (!is_http_request2(httpdata, 1024))
 	// {
 	// 	bpf_printk("not a http request\n");
@@ -112,25 +119,26 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 
 
 	int offset = is_http_header(map_data->payload);
-	bpf_printk("found the header, %d\n", offset);
+	// bpf_printk("found the header, %d\n", offset);
 	char *data;
 	data = bpf_map_lookup_elem(&large_array_map, &key);
 	if (!data)
 		return 0;
-	struct apm_span_context cw_parent_span_context = {};
+	// struct apm_span_context cw_parent_span_context = {};
+	struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&apm_span_context_heap, &key);
     if(offset > 0 && offset < 512 - 123)
 	{
         __builtin_memcpy(data, &(map_data->payload[offset]), 123);
-		bpf_printk("found the data, %s\n", data);
+		// bpf_printk("found the data, %s\n", data);
 
-		cw_string_to_span_context(data, &cw_parent_span_context);
+		cw_string_to_span_context(data, cw_parent_span_context);
 	}
     else
     {
-        generate_random_bytes(cw_parent_span_context.trace_id, TRACE_ID_SIZE);
+        generate_random_bytes(cw_parent_span_context->trace_id, TRACE_ID_SIZE);
     }
 	// 保存 trace_id 到psc
-    cw_save_parent_tracking_span(&cw_parent_span_context);
+    cw_save_parent_tracking_span(cw_parent_span_context);
 	return 0;
 }