iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

The user stack name could not be resolved successfully #5048

Closed zhangzihengya closed 2 months ago

zhangzihengya commented 3 months ago

User state stack fetch function:

event.u_stack_id = bpf_get_stackid(ctx, &user_stackmap, BPF_F_USER_STACK | BPF_F_REUSE_STACKID);

User state stack name resolution function:

void print_user_stack(FILE *filep, int perf_max_stack_depth, int sfd, bool logfile, int u_stack_id, unsigned long pid, struct syms_cache *syms_cache)
{
        const struct syms *syms;
        const struct sym *sym;
        int i;
        unsigned long *ip;

        //  printf("------dump user stack------\n");
        ip = calloc(perf_max_stack_depth, sizeof(*ip));
        if (!ip)
        {
                if (logfile)
                        fprintf(filep, "failed to alloc ip\n");
                else
                        fprintf(stderr, "failed to alloc ip\n");
                return;
        }

        if (bpf_map_lookup_elem(sfd, &u_stack_id, ip) != 0)
        {
                if (logfile)
                        fprintf(filep, "    [Missed User Stack:%d]\n", u_stack_id);
                else
                        fprintf(stderr, "    [Missed User Stack:%d]\n", u_stack_id);
                goto skip_user_stack;
        }

        syms = syms_cache__get_syms(syms_cache, pid);
        if (!syms)
        {
                if (logfile)
                        fprintf(filep, "    failed to get syms\n");
                else
                        fprintf(stderr, "    failed to get syms\n");
                goto skip_user_stack;
        }

        for (i = 0; i < perf_max_stack_depth && ip[i]; i++)
        {
                sym = syms__map_addr(syms, ip[i]);
                if (sym)
                {
                        if (logfile)
                                fprintf(filep, "    0x%lx %s+0x%lx\n", ip[i], sym->name, sym->offset);
                        else
                                printf("    0x%lx %s+0x%lx\n", ip[i], sym->name, sym->offset);
                }
                else
                {
                        if (logfile)
                                fprintf(filep, "    0x%lx [unknown]\n", ip[i]);
                        else
                                printf("    0x%lx [unknown]\n", ip[i]);
                }
        }

skip_user_stack:
        free(ip);
}

The functions refer to the repository's trace_helpers.h The following results will appear, the same stack address, but sometimes can not be resolved: image