|
@@ -71,7 +71,7 @@ struct bpf_map_def SEC("maps") should_trace_goid = {
|
|
|
SEC("uprobe/ent")
|
|
SEC("uprobe/ent")
|
|
|
int ent(struct pt_regs *ctx)
|
|
int ent(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
@@ -81,18 +81,18 @@ int ent(struct pt_regs *ctx)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: proc_info_map::%ld, %d, %d\n", info->code_type);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: proc_info_map::%ld, %d, %d\n", info->code_type);
|
|
|
|
|
|
|
|
__u64 trace_id = get_apm_trace_id(pid, pid_tgid);
|
|
__u64 trace_id = get_apm_trace_id(pid, pid_tgid);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: get_apm_trace_id::%ld, %d, %d\n", trace_id, pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][ent][HTTP]pid:[%d]--[%lld]--[%x]", pid_tgid, bpf_ktime_get_ns(), PT_REGS_IP(ctx));
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: get_apm_trace_id::%ld, %d, %d\n", trace_id, pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][ent][HTTP]pid:[%d]--[%lld]--[%x]", pid_tgid, bpf_ktime_get_ns(), PT_REGS_IP(ctx));
|
|
|
|
|
|
|
|
__u32 key = 0;
|
|
__u32 key = 0;
|
|
|
struct event *e = bpf_map_lookup_elem(&event_stack, &key);
|
|
struct event *e = bpf_map_lookup_elem(&event_stack, &key);
|
|
|
if (!e)
|
|
if (!e)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: conot get event");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: conot get event");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
__builtin_memset(e, 0, sizeof(*e));
|
|
__builtin_memset(e, 0, sizeof(*e));
|
|
@@ -107,9 +107,9 @@ int ent(struct pt_regs *ctx)
|
|
|
__u64 should_trace = true;
|
|
__u64 should_trace = true;
|
|
|
bpf_map_update_elem(&should_trace_goid, &e->goid, &should_trace, BPF_ANY);
|
|
bpf_map_update_elem(&should_trace_goid, &e->goid, &should_trace, BPF_ANY);
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: e->goid: %llu", e->goid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: e->ip: %d", e->ip);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: yes");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: e->goid: %llu", e->goid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: e->ip: %d", e->ip);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: yes");
|
|
|
|
|
|
|
|
e->pid = pid;
|
|
e->pid = pid;
|
|
|
e->trace_id = trace_id;
|
|
e->trace_id = trace_id;
|
|
@@ -122,10 +122,10 @@ int ent(struct pt_regs *ctx)
|
|
|
ra = (void *)PT_REGS_SP(ctx); // 父函数的 sp,此时 sp 指向父函数的最后一个地址
|
|
ra = (void *)PT_REGS_SP(ctx); // 父函数的 sp,此时 sp 指向父函数的最后一个地址
|
|
|
bpf_probe_read_user(&e->caller_ip, sizeof(e->caller_ip), ra);
|
|
bpf_probe_read_user(&e->caller_ip, sizeof(e->caller_ip), ra);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: goid: %llu", e->goid);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: goid: %llu", e->goid);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: event: location:%x,ip:%lx,time_ns_start:%llu\n", e->location, e->ip, e->time_ns_start);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: event: bp:%x,caller_bp:%x,caller_ip:%x\n", e->bp,e->caller_bp,e->caller_ip);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: event: location:%x,ip:%lx,time_ns_start:%llu\n", e->location, e->ip, e->time_ns_start);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: event: bp:%x,caller_bp:%x,caller_ip:%x\n", e->bp,e->caller_bp,e->caller_ip);
|
|
|
|
|
|
|
|
struct trace_stack_entry_key_t trace_key = {};
|
|
struct trace_stack_entry_key_t trace_key = {};
|
|
|
trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
|
|
trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
|
|
@@ -135,12 +135,12 @@ int ent(struct pt_regs *ctx)
|
|
|
// trace_key.caller_bp = e->caller_bp;
|
|
// trace_key.caller_bp = e->caller_bp;
|
|
|
// trace_key.bp = e->bp;
|
|
// trace_key.bp = e->bp;
|
|
|
// cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: bp: %x", trace_key.bp);
|
|
// cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: bp: %x", trace_key.bp);
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x, %lld", trace_key.caller_bp, trace_key.bp, trace_key.trace_id);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x, %lld", trace_key.caller_bp, trace_key.bp, trace_key.trace_id);
|
|
|
|
|
|
|
|
struct event *event_p = bpf_map_lookup_elem(&trace_stack_entry, &trace_key);
|
|
struct event *event_p = bpf_map_lookup_elem(&trace_stack_entry, &trace_key);
|
|
|
|
|
|
|
|
if (event_p) {
|
|
if (event_p) {
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]:Error get alike funEntry %x, %x, %x", event_p->ip, event_p->caller_bp, event_p->bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]:Error get alike funEntry %x, %x, %x", event_p->ip, event_p->caller_bp, event_p->bp);
|
|
|
// return 0;
|
|
// return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -160,14 +160,14 @@ int ent(struct pt_regs *ctx)
|
|
|
// return bpf_map_push_elem(&event_queue, e, BPF_EXIST);
|
|
// return bpf_map_push_elem(&event_queue, e, BPF_EXIST);
|
|
|
// bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
// bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent] end");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent] end");
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SEC("uprobe/ret")
|
|
SEC("uprobe/ret")
|
|
|
int ret(struct pt_regs *ctx)
|
|
int ret(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
@@ -177,7 +177,7 @@ int ret(struct pt_regs *ctx)
|
|
|
struct event *e = bpf_map_lookup_elem(&event_stack, &key);
|
|
struct event *e = bpf_map_lookup_elem(&event_stack, &key);
|
|
|
if (!e)
|
|
if (!e)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: conot get event");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: conot get event");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
__builtin_memset(e, 0, sizeof(*e));
|
|
__builtin_memset(e, 0, sizeof(*e));
|
|
@@ -186,10 +186,10 @@ int ret(struct pt_regs *ctx)
|
|
|
e->goid = get_current_goroutine();
|
|
e->goid = get_current_goroutine();
|
|
|
if (!bpf_map_lookup_elem(&should_trace_goid, &e->goid))
|
|
if (!bpf_map_lookup_elem(&should_trace_goid, &e->goid))
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: conot get event: %llu", e->goid);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: conot get event: %llu", e->goid);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: yes");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: yes");
|
|
|
e->pid = pid;
|
|
e->pid = pid;
|
|
|
e->trace_id = trace_id;
|
|
e->trace_id = trace_id;
|
|
|
e->location = ENTPOINT;
|
|
e->location = ENTPOINT;
|
|
@@ -199,10 +199,10 @@ int ret(struct pt_regs *ctx)
|
|
|
e->caller_bp = PT_REGS_FP(ctx);
|
|
e->caller_bp = PT_REGS_FP(ctx);
|
|
|
|
|
|
|
|
// __u64 caller_bp = PT_REGS_FP(ctx);
|
|
// __u64 caller_bp = PT_REGS_FP(ctx);
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: e->ip:%lx,bp:%x,caller_bp:%x", e->ip, e->bp, e->caller_bp);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: sp:%x, goid: %llu, goid:0x:%x", PT_REGS_SP(ctx), e->goid, e->goid);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: e->ip:%lx,bp:%x,caller_bp:%x", e->ip, e->bp, e->caller_bp);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: sp:%x, goid: %llu, goid:0x:%x", PT_REGS_SP(ctx), e->goid, e->goid);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: event: location:%x,ip:%x,time_ns_end:%llu\n", e->location, e->ip, e->time_ns_end);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: event: location:%x,ip:%x,time_ns_end:%llu\n", e->location, e->ip, e->time_ns_end);
|
|
|
|
|
|
|
|
struct trace_stack_entry_key_t trace_key = {};
|
|
struct trace_stack_entry_key_t trace_key = {};
|
|
|
trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
|
|
trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
|
|
@@ -212,46 +212,46 @@ int ret(struct pt_regs *ctx)
|
|
|
// trace_key.caller_bp = caller_bp;
|
|
// trace_key.caller_bp = caller_bp;
|
|
|
// trace_key.bp = e->bp;
|
|
// trace_key.bp = e->bp;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
// cw_bpf_debug("[Go] [uprobe/ret]: trace_keytrace_keytrace_key: bp: %x", trace_key.bp);
|
|
// cw_bpf_debug("[Go] [uprobe/ret]: trace_keytrace_keytrace_key: bp: %x", trace_key.bp);
|
|
|
|
|
|
|
|
struct event *event_p = bpf_map_lookup_elem(&trace_stack_entry, &trace_key);
|
|
struct event *event_p = bpf_map_lookup_elem(&trace_stack_entry, &trace_key);
|
|
|
|
|
|
|
|
if (!event_p) {
|
|
if (!event_p) {
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]:ErrorErrorErrorError Not get funEntry");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]:ErrorErrorErrorError Not get funEntry");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
event_p->time_ns_end = e->time_ns_end;
|
|
event_p->time_ns_end = e->time_ns_end;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: ent:event: location:%d,ip:%x,time_ns_start:%llu\n", event_p->location, event_p->ip, event_p->time_ns_start);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: ent:event: bp:%x,caller_bp:%x,caller_ip:%x\n", event_p->bp,event_p->caller_bp,event_p->caller_ip);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: ent:event: location:%d,ip:%x,time_ns_start:%llu\n", event_p->location, event_p->ip, event_p->time_ns_start);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: ent:event: bp:%x,caller_bp:%x,caller_ip:%x\n", event_p->bp,event_p->caller_bp,event_p->caller_ip);
|
|
|
|
|
|
|
|
e->time_ns_start = event_p->time_ns_start;
|
|
e->time_ns_start = event_p->time_ns_start;
|
|
|
// e->caller_ip = event_p->caller_ip;
|
|
// e->caller_ip = event_p->caller_ip;
|
|
|
// e->ip = event_p->ip;
|
|
// e->ip = event_p->ip;
|
|
|
|
|
|
|
|
// return bpf_map_push_elem(&event_queue, e, BPF_EXIST);
|
|
// return bpf_map_push_elem(&event_queue, e, BPF_EXIST);
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: ent:event_ret push: event_p->ip:%llx,ip:%llx\n", event_p->ip, e->ip);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: ent:event_ret push: event_p->ip:%llx,ip:%llx\n", event_p->ip, e->ip);
|
|
|
long err = bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
long err = bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
if (err == 0) {
|
|
if (err == 0) {
|
|
|
__u32 count = cw_add_event_count(trace_id);
|
|
__u32 count = cw_add_event_count(trace_id);
|
|
|
if (event_p->trace_id != trace_id) {
|
|
if (event_p->trace_id != trace_id) {
|
|
|
- cw_bpf_debug("[pref] fuck err<%d> ip->%x->%x", err, PT_REGS_IP(ctx), e->ip);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[pref] fuck err<%d> ip->%x->%x", err, PT_REGS_IP(ctx), e->ip);
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[pref] err<%d> count->%d trace_id->%llu", err, count, trace_id);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[pref] err<%d> count->%d trace_id->%llu", err, count, trace_id);
|
|
|
} else {
|
|
} else {
|
|
|
- cw_bpf_debug("[pref] err<%d> trace_id->%d", err, trace_id);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[pref] err<%d> trace_id->%d", err, trace_id);
|
|
|
}
|
|
}
|
|
|
bpf_map_delete_elem(&trace_stack_entry, &trace_key);
|
|
bpf_map_delete_elem(&trace_stack_entry, &trace_key);
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret] end");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret] end");
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SEC("uprobe/dotnetent")
|
|
SEC("uprobe/dotnetent")
|
|
|
int dotnetent(struct pt_regs *ctx)
|
|
int dotnetent(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
@@ -261,18 +261,18 @@ int dotnetent(struct pt_regs *ctx)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: proc_info_map::%ld, %d, %d\n", info->code_type);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: proc_info_map::%ld, %d, %d\n", info->code_type);
|
|
|
|
|
|
|
|
__u64 trace_id = get_apm_trace_id(pid, pid_tgid);
|
|
__u64 trace_id = get_apm_trace_id(pid, pid_tgid);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: get_apm_trace_id::%ld, %d, %d\n", trace_id, pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][ent][HTTP]pid:[%d]--[%lld]--[%x]", pid_tgid, bpf_ktime_get_ns(), PT_REGS_IP(ctx));
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: get_apm_trace_id::%ld, %d, %d\n", trace_id, pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][ent][HTTP]pid:[%d]--[%lld]--[%x]", pid_tgid, bpf_ktime_get_ns(), PT_REGS_IP(ctx));
|
|
|
|
|
|
|
|
__u32 key = 0;
|
|
__u32 key = 0;
|
|
|
struct event *e = bpf_map_lookup_elem(&event_stack, &key);
|
|
struct event *e = bpf_map_lookup_elem(&event_stack, &key);
|
|
|
if (!e)
|
|
if (!e)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobe/ret]: conot get event");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ret]: conot get event");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
__builtin_memset(e, 0, sizeof(*e));
|
|
__builtin_memset(e, 0, sizeof(*e));
|
|
@@ -287,15 +287,15 @@ int dotnetent(struct pt_regs *ctx)
|
|
|
__u64 should_trace = true;
|
|
__u64 should_trace = true;
|
|
|
bpf_map_update_elem(&should_trace_goid, &e->goid, &should_trace, BPF_ANY);
|
|
bpf_map_update_elem(&should_trace_goid, &e->goid, &should_trace, BPF_ANY);
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: e->goid: %llu", e->goid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: e->ip: %d", e->ip);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: yes");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: e->goid: %llu", e->goid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: e->ip: %d", e->ip);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: yes");
|
|
|
|
|
|
|
|
__u64 asm_;
|
|
__u64 asm_;
|
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)e->ip);
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)e->ip);
|
|
|
|
|
|
|
|
asm_ = asm_ >> 32;
|
|
asm_ = asm_ >> 32;
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
|
e->pid = pid;
|
|
e->pid = pid;
|
|
|
e->trace_id = trace_id;
|
|
e->trace_id = trace_id;
|
|
@@ -308,10 +308,10 @@ int dotnetent(struct pt_regs *ctx)
|
|
|
ra = (void *)PT_REGS_SP(ctx); // 父函数的 sp,此时 sp 指向父函数的最后一个地址
|
|
ra = (void *)PT_REGS_SP(ctx); // 父函数的 sp,此时 sp 指向父函数的最后一个地址
|
|
|
bpf_probe_read_user(&e->caller_ip, sizeof(e->caller_ip), ra);
|
|
bpf_probe_read_user(&e->caller_ip, sizeof(e->caller_ip), ra);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: goid: %llu", e->goid);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: goid: %llu", e->goid);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: event: location:%x,ip:%lx,time_ns_start:%lld\n", e->location, e->ip, e->time_ns_start);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: event: bp:%x,caller_bp:%x,caller_ip:%x\n", e->bp,e->caller_bp,e->caller_ip);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: event: location:%x,ip:%lx,time_ns_start:%lld\n", e->location, e->ip, e->time_ns_start);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: event: bp:%x,caller_bp:%x,caller_ip:%x\n", e->bp,e->caller_bp,e->caller_ip);
|
|
|
|
|
|
|
|
struct trace_stack_entry_key_t trace_key = {};
|
|
struct trace_stack_entry_key_t trace_key = {};
|
|
|
trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
|
|
trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
|
|
@@ -321,7 +321,7 @@ int dotnetent(struct pt_regs *ctx)
|
|
|
// trace_key.caller_bp = e->caller_bp;
|
|
// trace_key.caller_bp = e->caller_bp;
|
|
|
// trace_key.bp = e->bp;
|
|
// trace_key.bp = e->bp;
|
|
|
// cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: bp: %x", trace_key.bp);
|
|
// cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: bp: %x", trace_key.bp);
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
|
struct event event_current = {};
|
|
struct event event_current = {};
|
|
|
event_current.bp = e->bp,
|
|
event_current.bp = e->bp,
|
|
@@ -339,44 +339,44 @@ int dotnetent(struct pt_regs *ctx)
|
|
|
// return bpf_map_push_elem(&event_queue, e, BPF_EXIST);
|
|
// return bpf_map_push_elem(&event_queue, e, BPF_EXIST);
|
|
|
// bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
// bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobe/ent] end");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobe/ent] end");
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SEC("uprobe/SocketConnectionStartStart")
|
|
SEC("uprobe/SocketConnectionStartStart")
|
|
|
int SocketConnectionStartStart(struct pt_regs *ctx)
|
|
int SocketConnectionStartStart(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
|
__u64 rdi_ptr = (__u64)PT_REGS_PARM1(ctx);
|
|
__u64 rdi_ptr = (__u64)PT_REGS_PARM1(ctx);
|
|
|
// __u64 rdi_ptr_long = (__u64)rdi_ptr;
|
|
// __u64 rdi_ptr_long = (__u64)rdi_ptr;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]: rdi_ptr:: %llx\n", rdi_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]: rdi_ptr:: %llx\n", rdi_ptr);
|
|
|
// cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]: rdi_ptr:: %llx\n", rdi_ptr_long);
|
|
// cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]: rdi_ptr:: %llx\n", rdi_ptr_long);
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SocketConnectionStartStart][HTTP]pid:[%d]--[%lld]--request[%llx]", pid_tgid, bpf_ktime_get_ns(), rdi_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SocketConnectionStartStart][HTTP]pid:[%d]--[%lld]--request[%llx]", pid_tgid, bpf_ktime_get_ns(), rdi_ptr);
|
|
|
|
|
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
int num = 1;
|
|
int num = 1;
|
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (pre_e) {
|
|
if (pre_e) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
num = pre_e->num + 1;
|
|
num = pre_e->num + 1;
|
|
|
}
|
|
}
|
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
|
connection_ptr_key.num = num;
|
|
connection_ptr_key.num = num;
|
|
|
connection_ptr_key.connection_ptr = rdi_ptr;
|
|
connection_ptr_key.connection_ptr = rdi_ptr;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/insert/SocketConnectionStartStart]getget: rdi_ptr:: %d -> %llx\n", pid, rdi_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/insert/SocketConnectionStartStart]getget: rdi_ptr:: %d -> %llx\n", pid, rdi_ptr);
|
|
|
|
|
|
|
|
struct pid_of_connection_ptr_key_t *e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (!e) {
|
|
if (!e) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]getget: ErrorErrorErrorError rdi_ptr\n");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]getget: ErrorErrorErrorError rdi_ptr\n");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]getget: rdi_ptr:: %llx -> %d\n", e->connection_ptr, e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart]getget: rdi_ptr:: %llx -> %d\n", e->connection_ptr, e->num);
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
|
|
|
|
|
|
|
|
|
@@ -386,7 +386,7 @@ int SocketConnectionStartStart(struct pt_regs *ctx)
|
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)ip);
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)ip);
|
|
|
|
|
|
|
|
asm_ = asm_ >> 32;
|
|
asm_ = asm_ >> 32;
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
|
__u64 bp = PT_REGS_SP(ctx);
|
|
__u64 bp = PT_REGS_SP(ctx);
|
|
|
// __u64 bp = PT_REGS_SP(ctx) + asm_;
|
|
// __u64 bp = PT_REGS_SP(ctx) + asm_;
|
|
@@ -397,8 +397,8 @@ int SocketConnectionStartStart(struct pt_regs *ctx)
|
|
|
trace_key.bp = bp;
|
|
trace_key.bp = bp;
|
|
|
trace_key.trace_id = 0;
|
|
trace_key.trace_id = 0;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip:%x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip:%x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartStart/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
|
bpf_map_update_elem(&trace_stack_entry_thread, &trace_key, &pid, BPF_ANY);
|
|
bpf_map_update_elem(&trace_stack_entry_thread, &trace_key, &pid, BPF_ANY);
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
@@ -409,12 +409,12 @@ int SocketConnectionStartStart(struct pt_regs *ctx)
|
|
|
SEC("uprobe/SocketConnectionStartEnd")
|
|
SEC("uprobe/SocketConnectionStartEnd")
|
|
|
int SocketConnectionStartEnd(struct pt_regs *ctx)
|
|
int SocketConnectionStartEnd(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SocketConnectionStartEnd][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SocketConnectionStartEnd][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
|
|
|
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
@@ -427,28 +427,28 @@ int SocketConnectionStartEnd(struct pt_regs *ctx)
|
|
|
trace_key.bp = bp;
|
|
trace_key.bp = bp;
|
|
|
trace_key.trace_id = 0;
|
|
trace_key.trace_id = 0;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip: %x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip: %x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
|
__u64 *pid_p = bpf_map_lookup_elem(&trace_stack_entry_thread, &trace_key);
|
|
__u64 *pid_p = bpf_map_lookup_elem(&trace_stack_entry_thread, &trace_key);
|
|
|
|
|
|
|
|
if (!pid_p) {
|
|
if (!pid_p) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]:ErrorErrorErrorError Not get funEntry");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]:ErrorErrorErrorError Not get funEntry");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]:Delete It: %d", *pid_p);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]:Delete It: %d", *pid_p);
|
|
|
bpf_map_delete_elem(&trace_stack_entry_thread, &trace_key);
|
|
bpf_map_delete_elem(&trace_stack_entry_thread, &trace_key);
|
|
|
|
|
|
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
|
if (ed_e && ed_e->num > 1) {
|
|
if (ed_e && ed_e->num > 1) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SocketConnectionStartEnd]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
ed_e->num = ed_e->num - 1;
|
|
ed_e->num = ed_e->num - 1;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, pid_p, ed_e, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, pid_p, ed_e, BPF_ANY);
|
|
|
} else {
|
|
} else {
|
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/delete/SocketConnectionStartEnd]getget: rdi_ptr:: %d\n", *pid_p);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/delete/SocketConnectionStartEnd]getget: rdi_ptr:: %d\n", *pid_p);
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
@@ -457,35 +457,35 @@ int SocketConnectionStartEnd(struct pt_regs *ctx)
|
|
|
SEC("uprobe/OnConnectionAsyncStart")
|
|
SEC("uprobe/OnConnectionAsyncStart")
|
|
|
int OnConnectionAsyncStart(struct pt_regs *ctx)
|
|
int OnConnectionAsyncStart(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
|
|
|
|
|
|
__u64 rsi_ptr = (__u64)PT_REGS_PARM2(ctx);
|
|
__u64 rsi_ptr = (__u64)PT_REGS_PARM2(ctx);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]: rsi_ptr:: %llx\n", rsi_ptr);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]: rsi_ptr:: %llx\n", rsi_ptr);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
int num = 1;
|
|
int num = 1;
|
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (pre_e) {
|
|
if (pre_e) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
num = pre_e->num + 1;
|
|
num = pre_e->num + 1;
|
|
|
}
|
|
}
|
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
|
connection_ptr_key.num = num;
|
|
connection_ptr_key.num = num;
|
|
|
connection_ptr_key.connection_ptr = rsi_ptr;
|
|
connection_ptr_key.connection_ptr = rsi_ptr;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/insert/OnConnectionAsyncStart]getget: rdi_ptr:: %d -> %llx\n", pid, rsi_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/insert/OnConnectionAsyncStart]getget: rdi_ptr:: %d -> %llx\n", pid, rsi_ptr);
|
|
|
|
|
|
|
|
struct pid_of_connection_ptr_key_t *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (!e3) {
|
|
if (!e3) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]getget: ErrorErrorErrorError rsi_ptr3\n");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]getget: ErrorErrorErrorError rsi_ptr3\n");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]getget: rsi_ptr3:: %llx -> %d\n", e3->connection_ptr, e3->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncStart]getget: rsi_ptr3:: %llx -> %d\n", e3->connection_ptr, e3->num);
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
@@ -493,31 +493,31 @@ int OnConnectionAsyncStart(struct pt_regs *ctx)
|
|
|
SEC("uprobe/OnConnectionAsyncEnd")
|
|
SEC("uprobe/OnConnectionAsyncEnd")
|
|
|
int OnConnectionAsyncEnd(struct pt_regs *ctx)
|
|
int OnConnectionAsyncEnd(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][OnConnectionAsyncEnd][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][OnConnectionAsyncEnd][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
__u64 *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
__u64 *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (!e3) {
|
|
if (!e3) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
|
|
|
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (ed_e && ed_e->num > 1) {
|
|
if (ed_e && ed_e->num > 1) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/OnConnectionAsyncEnd]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
ed_e->num = ed_e->num - 1;
|
|
ed_e->num = ed_e->num - 1;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, ed_e, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, ed_e, BPF_ANY);
|
|
|
} else {
|
|
} else {
|
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, &pid);
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/delete/OnConnectionAsyncEnd]getget: rdi_ptr:: %d\n", pid);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/delete/OnConnectionAsyncEnd]getget: rdi_ptr:: %d\n", pid);
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
@@ -532,33 +532,33 @@ struct {
|
|
|
SEC("uprobe/SendAsync1Start")
|
|
SEC("uprobe/SendAsync1Start")
|
|
|
int SendAsync1Start(struct pt_regs *ctx)
|
|
int SendAsync1Start(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeTshread/SendAsync1Start] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeTshread/SendAsync1Start] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
|
void *rsi_ptr = (void *)PT_REGS_PARM2(ctx);
|
|
void *rsi_ptr = (void *)PT_REGS_PARM2(ctx);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]: rsi_ptr:: %llx\n", rsi_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]: rsi_ptr:: %llx\n", rsi_ptr);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SendAsync1Start][HTTP]pid:[%d]--[%lld]--request[%llx]", pid_tgid, bpf_ktime_get_ns(), rsi_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SendAsync1Start][HTTP]pid:[%d]--[%lld]--request[%llx]", pid_tgid, bpf_ktime_get_ns(), rsi_ptr);
|
|
|
|
|
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
__u64 *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
__u64 *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (!e3) {
|
|
if (!e3) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]getget: rsi_ptr:: %llx\n", *e3);
|
|
|
|
|
|
|
|
bpf_map_update_elem(&request_of_connection_ptr_maps, &rsi_ptr, e3, BPF_ANY);
|
|
bpf_map_update_elem(&request_of_connection_ptr_maps, &rsi_ptr, e3, BPF_ANY);
|
|
|
|
|
|
|
|
__u64 *e2 = bpf_map_lookup_elem(&request_of_connection_ptr_maps, &rsi_ptr);
|
|
__u64 *e2 = bpf_map_lookup_elem(&request_of_connection_ptr_maps, &rsi_ptr);
|
|
|
if (!e2) {
|
|
if (!e2) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start] ErrorErrorError getget: rsi_ptr2:: %llx\n", *e2);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start] ErrorErrorError getget: rsi_ptr2:: %llx\n", *e2);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]getget: rsi_ptr2:: %llx\n", *e2);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync1Start]getget: rsi_ptr2:: %llx\n", *e2);
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -567,14 +567,14 @@ int SendAsync1Start(struct pt_regs *ctx)
|
|
|
SEC("uprobe/SendAsync1End")
|
|
SEC("uprobe/SendAsync1End")
|
|
|
int SendAsync1End(struct pt_regs *ctx)
|
|
int SendAsync1End(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeTshread/SendAsync1End] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeTshread/SendAsync1End] enter");
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SEC("uprobe/SendAsync2Start")
|
|
SEC("uprobe/SendAsync2Start")
|
|
|
int SendAsync2Start(struct pt_regs *ctx)
|
|
int SendAsync2Start(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
@@ -585,38 +585,38 @@ int SendAsync2Start(struct pt_regs *ctx)
|
|
|
// return 1;
|
|
// return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]: fd_ptr:: %llx\n", fd_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]: fd_ptr:: %llx\n", fd_ptr);
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SendAsync2Start][HTTP]pid:[%d]--[%lld]--request[%llx]", pid_tgid, bpf_ktime_get_ns(), fd_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SendAsync2Start][HTTP]pid:[%d]--[%lld]--request[%llx]", pid_tgid, bpf_ktime_get_ns(), fd_ptr);
|
|
|
|
|
|
|
|
|
|
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
__u64 *e2 = bpf_map_lookup_elem(&request_of_connection_ptr_maps, &fd_ptr);
|
|
__u64 *e2 = bpf_map_lookup_elem(&request_of_connection_ptr_maps, &fd_ptr);
|
|
|
if (!e2) {
|
|
if (!e2) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start] ErrorErrorError getget: fd_ptr:: %llx\n", *e2);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start] ErrorErrorError getget: fd_ptr:: %llx\n", *e2);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: fd_ptr:: %llx\n", *e2);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: fd_ptr:: %llx\n", *e2);
|
|
|
|
|
|
|
|
int num = 1;
|
|
int num = 1;
|
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (pre_e) {
|
|
if (pre_e) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
num = pre_e->num + 1;
|
|
num = pre_e->num + 1;
|
|
|
}
|
|
}
|
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
|
connection_ptr_key.num = num;
|
|
connection_ptr_key.num = num;
|
|
|
connection_ptr_key.connection_ptr = *e2;
|
|
connection_ptr_key.connection_ptr = *e2;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/insert/SendAsync2Start]getget: rdi_ptr:: %d -> %llx\n", pid, *e2);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/insert/SendAsync2Start]getget: rdi_ptr:: %d -> %llx\n", pid, *e2);
|
|
|
|
|
|
|
|
struct pid_of_connection_ptr_key_t *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (!e3) {
|
|
if (!e3) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: ErrorErrorErrorError rsi_ptr3\n");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: ErrorErrorErrorError rsi_ptr3\n");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: rsi_ptr3:: %llx -> %d\n", e3->connection_ptr, e3->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start]getget: rsi_ptr3:: %llx -> %d\n", e3->connection_ptr, e3->num);
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
|
|
|
|
|
|
|
|
|
@@ -626,7 +626,7 @@ int SendAsync2Start(struct pt_regs *ctx)
|
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)ip);
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)ip);
|
|
|
|
|
|
|
|
asm_ = asm_ >> 32;
|
|
asm_ = asm_ >> 32;
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
|
__u64 bp = PT_REGS_SP(ctx);
|
|
__u64 bp = PT_REGS_SP(ctx);
|
|
|
// __u64 bp = PT_REGS_SP(ctx) + asm_;
|
|
// __u64 bp = PT_REGS_SP(ctx) + asm_;
|
|
@@ -637,8 +637,8 @@ int SendAsync2Start(struct pt_regs *ctx)
|
|
|
trace_key.bp = bp;
|
|
trace_key.bp = bp;
|
|
|
trace_key.trace_id = 0;
|
|
trace_key.trace_id = 0;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip:%x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip:%x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2Start/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
|
bpf_map_update_elem(&trace_stack_entry_thread, &trace_key, &pid, BPF_ANY);
|
|
bpf_map_update_elem(&trace_stack_entry_thread, &trace_key, &pid, BPF_ANY);
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
@@ -649,12 +649,12 @@ int SendAsync2Start(struct pt_regs *ctx)
|
|
|
SEC("uprobe/SendAsync2End")
|
|
SEC("uprobe/SendAsync2End")
|
|
|
int SendAsync2End(struct pt_regs *ctx)
|
|
int SendAsync2End(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2End] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2End] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2End]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SendAsync2End][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2End]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][SendAsync2End][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
|
// __u64 bp = PT_REGS_SP(ctx) - 8;
|
|
// __u64 bp = PT_REGS_SP(ctx) - 8;
|
|
@@ -666,28 +666,28 @@ int SendAsync2End(struct pt_regs *ctx)
|
|
|
trace_key.bp = bp;
|
|
trace_key.bp = bp;
|
|
|
trace_key.trace_id = 0;
|
|
trace_key.trace_id = 0;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip: %x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip: %x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
|
__u64 *pid_p = bpf_map_lookup_elem(&trace_stack_entry_thread, &trace_key);
|
|
__u64 *pid_p = bpf_map_lookup_elem(&trace_stack_entry_thread, &trace_key);
|
|
|
|
|
|
|
|
if (!pid_p) {
|
|
if (!pid_p) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]:ErrorErrorErrorError Not get funEntry");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]:ErrorErrorErrorError Not get funEntry");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]:Delete It: %d", *pid_p);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2End/ent]:Delete It: %d", *pid_p);
|
|
|
bpf_map_delete_elem(&trace_stack_entry_thread, &trace_key);
|
|
bpf_map_delete_elem(&trace_stack_entry_thread, &trace_key);
|
|
|
|
|
|
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
|
if (ed_e && ed_e->num > 1) {
|
|
if (ed_e && ed_e->num > 1) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/SendAsync2End]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/SendAsync2End]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
ed_e->num = ed_e->num - 1;
|
|
ed_e->num = ed_e->num - 1;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, pid_p, ed_e, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, pid_p, ed_e, BPF_ANY);
|
|
|
} else {
|
|
} else {
|
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/delete/SendAsync2End]getget: rdi_ptr:: %d\n", pid_p);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/delete/SendAsync2End]getget: rdi_ptr:: %d\n", pid_p);
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -696,7 +696,7 @@ int SendAsync2End(struct pt_regs *ctx)
|
|
|
SEC("uprobe/DoSendStart")
|
|
SEC("uprobe/DoSendStart")
|
|
|
int DoSendStart(struct pt_regs *ctx)
|
|
int DoSendStart(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
@@ -707,29 +707,29 @@ int DoSendStart(struct pt_regs *ctx)
|
|
|
if (bpf_probe_read(&fd_ptr, sizeof(fd_ptr), rdi_ptr - 0xe8 + 0x28)) {
|
|
if (bpf_probe_read(&fd_ptr, sizeof(fd_ptr), rdi_ptr - 0xe8 + 0x28)) {
|
|
|
// return 1;
|
|
// return 1;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart]: fd_ptr: %llx\n", fd_ptr);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart]: fd_ptr: %llx\n", fd_ptr);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
// cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][DoSendStart][HTTP]pid:[%d]--[%lld]--id[%s]", pid_tgid, bpf_ktime_get_ns(), final_connection_id);
|
|
// cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][DoSendStart][HTTP]pid:[%d]--[%lld]--id[%s]", pid_tgid, bpf_ktime_get_ns(), final_connection_id);
|
|
|
|
|
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
int num = 1;
|
|
int num = 1;
|
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *pre_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (pre_e) {
|
|
if (pre_e) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart]getget: rdi_ptr:: %llx -> %d\n", pre_e->connection_ptr, pre_e->num);
|
|
|
num = pre_e->num + 1;
|
|
num = pre_e->num + 1;
|
|
|
}
|
|
}
|
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
struct pid_of_connection_ptr_key_t connection_ptr_key = {};
|
|
|
connection_ptr_key.num = num;
|
|
connection_ptr_key.num = num;
|
|
|
connection_ptr_key.connection_ptr = fd_ptr;
|
|
connection_ptr_key.connection_ptr = fd_ptr;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, &pid, &connection_ptr_key, BPF_ANY);
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/insert/DoSendStart]getget: rdi_ptr:: %d -> %llx\n", pid, fd_ptr);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/insert/DoSendStart]getget: rdi_ptr:: %d -> %llx\n", pid, fd_ptr);
|
|
|
|
|
|
|
|
struct pid_of_connection_ptr_key_t *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
struct pid_of_connection_ptr_key_t *e3 = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, &pid);
|
|
|
if (!e3) {
|
|
if (!e3) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart] ErrorErrorError getget: rsi_ptr3\n");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart] ErrorErrorError getget: rsi_ptr3\n");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart]getget: rsi_ptr3:: %llx -> %d\n", e3->connection_ptr, e3->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart]getget: rsi_ptr3:: %llx -> %d\n", e3->connection_ptr, e3->num);
|
|
|
// 维护 pid 与 connection 的关系
|
|
// 维护 pid 与 connection 的关系
|
|
|
|
|
|
|
|
|
|
|
|
@@ -739,7 +739,7 @@ int DoSendStart(struct pt_regs *ctx)
|
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)ip);
|
|
bpf_probe_read_user(&asm_, sizeof(asm_), (void*)ip);
|
|
|
|
|
|
|
|
asm_ = asm_ >> 32;
|
|
asm_ = asm_ >> 32;
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart/ent]: e->asm: %x", asm_);
|
|
|
|
|
|
|
|
__u64 bp = PT_REGS_SP(ctx);
|
|
__u64 bp = PT_REGS_SP(ctx);
|
|
|
// __u64 bp = PT_REGS_SP(ctx) + asm_;
|
|
// __u64 bp = PT_REGS_SP(ctx) + asm_;
|
|
@@ -750,8 +750,8 @@ int DoSendStart(struct pt_regs *ctx)
|
|
|
trace_key.bp = bp;
|
|
trace_key.bp = bp;
|
|
|
trace_key.trace_id = 0;
|
|
trace_key.trace_id = 0;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip:%x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendStart/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart/ent]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip:%x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendStart/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
|
bpf_map_update_elem(&trace_stack_entry_thread, &trace_key, &pid, BPF_ANY);
|
|
bpf_map_update_elem(&trace_stack_entry_thread, &trace_key, &pid, BPF_ANY);
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
@@ -762,12 +762,12 @@ int DoSendStart(struct pt_regs *ctx)
|
|
|
SEC("uprobe/DoSendEnd")
|
|
SEC("uprobe/DoSendEnd")
|
|
|
int DoSendEnd(struct pt_regs *ctx)
|
|
int DoSendEnd(struct pt_regs *ctx)
|
|
|
{
|
|
{
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendEnd] enter");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendEnd] enter");
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u64 pid = pid_tgid >> 32;
|
|
__u64 pid = pid_tgid >> 32;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendEnd]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][DoSendEnd][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendEnd]: get_apm_trace_id:: %d, %d\n", pid, pid_tgid);
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/pidpidpidpid][DoSendEnd][HTTP]pid:[%d]--[%lld]", pid_tgid, bpf_ktime_get_ns());
|
|
|
|
|
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
|
// __u64 bp = PT_REGS_SP(ctx) - 8;
|
|
// __u64 bp = PT_REGS_SP(ctx) - 8;
|
|
@@ -779,28 +779,28 @@ int DoSendEnd(struct pt_regs *ctx)
|
|
|
trace_key.bp = bp;
|
|
trace_key.bp = bp;
|
|
|
trace_key.trace_id = 0;
|
|
trace_key.trace_id = 0;
|
|
|
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip: %x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]: trace_keytrace_keytrace_key: rbp: %x, rbp: %x, rip: %x", PT_REGS_FP(ctx), PT_REGS_SP(ctx), PT_REGS_IP(ctx));
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
|
|
|
|
|
|
|
|
__u64 *pid_p = bpf_map_lookup_elem(&trace_stack_entry_thread, &trace_key);
|
|
__u64 *pid_p = bpf_map_lookup_elem(&trace_stack_entry_thread, &trace_key);
|
|
|
|
|
|
|
|
if (!pid_p) {
|
|
if (!pid_p) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]:ErrorErrorErrorError Not get funEntry");
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]:ErrorErrorErrorError Not get funEntry");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]:Delete It: %d", *pid_p);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendEnd/ret]:Delete It: %d", *pid_p);
|
|
|
bpf_map_delete_elem(&trace_stack_entry_thread, &trace_key);
|
|
bpf_map_delete_elem(&trace_stack_entry_thread, &trace_key);
|
|
|
|
|
|
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
// 删除 pid 与 connection 的关系,由于 hook 点可能共用同一个线程,需要维护 num
|
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
struct pid_of_connection_ptr_key_t *ed_e = bpf_map_lookup_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
|
if (ed_e && ed_e->num > 1) {
|
|
if (ed_e && ed_e->num > 1) {
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/DoSendEnd]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/DoSendEnd]getget: rdi_ptr:: %llx -> %d\n", ed_e->connection_ptr, ed_e->num);
|
|
|
ed_e->num = ed_e->num - 1;
|
|
ed_e->num = ed_e->num - 1;
|
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, pid_p, ed_e, BPF_ANY);
|
|
bpf_map_update_elem(&pid_of_connection_ptr_maps, pid_p, ed_e, BPF_ANY);
|
|
|
} else {
|
|
} else {
|
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
bpf_map_delete_elem(&pid_of_connection_ptr_maps, pid_p);
|
|
|
}
|
|
}
|
|
|
- cw_bpf_debug("[Go] [uprobeThread/delete/DoSendEnd]getget: rdi_ptr:: %d\n", pid_p);
|
|
|
|
|
|
|
+ // cw_bpf_debug("[Go] [uprobeThread/delete/DoSendEnd]getget: rdi_ptr:: %d\n", pid_p);
|
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
// 维护函数出入口,用于关闭 当前 Connection 与线程的关系
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|