This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug kprobes/15675] New: A misusing of function @module_kallsyms_on_each_symbo cause the stap generated module can not resolve the module symbols.


http://sourceware.org/bugzilla/show_bug.cgi?id=15675

            Bug ID: 15675
           Summary: A misusing of function @module_kallsyms_on_each_symbo
                    cause the stap generated module can not resolve the
                    module symbols.
           Product: systemtap
           Version: unspecified
            Status: NEW
          Severity: critical
          Priority: P2
         Component: kprobes
          Assignee: systemtap at sourceware dot org
          Reporter: yangwen at huawei dot com

/* Summary:
 * A misusing of function @module_kallsyms_on_each_symbol
 * cause the stap generated module can not resolve the
 * module symbols.
 * */

/* 1. Supporse we use stap on the following script to probe
 * the 'FuncA' in module named 'ModA'
 * */
probe kprobe.module("ModA").function ("FuncA") {
    printf("Wen Test: cache:readCache called, task:%s pid:%d\n",
           execname(), pid())
}


/* 2. The stap command will generate the following 3 pieces of
 * codes to resolve the symbol referenced above
 * */
stap_dwarfless_probes[] = {
    { .symbol_string="ModA:FuncA", .probe=(&stap_probes[1]), },
};


{
    int p = 0;
    for (i = 0; i < 1; i++) {
        struct stap_dwarfless_probe *sdp = & stap_dwarfless_probes[i];
        if (! sdp->address)
            p++;
    }
    kallsyms_on_each_symbol(kprobe_resolve, &p);
}

static int kprobe_resolve(void *data, const char *name,
                          struct module *owner,
                          unsigned long val) {
    int i;
    int *p = (int *) data;
    for (i=0; i<1 && *p > 0; i++) {
        struct stap_dwarfless_probe *sdp = & stap_dwarfless_probes[i];
        if (! sdp->address)
            if (strcmp(sdp->symbol_string, name) == 0) {
                sdp->address = val;
                (*p)--;
            }
    }
    return (p > 0) ? 0 : -1;
}

/* 3. In the generated function 'kprobe_resolve (a callback function for
 * kallsyms_on_each_symbol), it compares the sdp->symbol_string--in this
 * expamle it's "ModA:FuncA"--with the second parameter @name of
kprobe_resolve.
 *
 * The expr 'if (strcmp(sdp->symbol_string, name) == 0)' NEVER evals TRUE,
because
 * the kernel does NOT merge the module name with the symbol name to give the
parameter
 * @name, the @name parameter always contain ONLY the symbol name. 
 *
 * The kprobe_resolve should compare module name and symbol name respectively.
 * It maybe looks like this:
 * */

static int kprobe_resolve(void *data, const char *name,
                          struct module *owner,
                          unsigned long val) {
    int i;
    int *p = (int *) data;
    for (i=0; i<1 && *p > 0; i++) {
        struct stap_dwarfless_probe *sdp = & stap_dwarfless_probes[i];
        if (! sdp->address) {
            const char * colon;
            if ((colon = strchr(sdp->symbol_string, ':')) && owner) {
                if ((strlen(owner->name) == (colon - sdp->symbol_string)) &&
                    (strncmp(sdp->symbol_string, owner->name, colon -
sdp->symbol_string) == 0) &&
                    (strcmp(colon + 1, name) == 0)) {
                    sdp->address = val;
                    (*p)--;
                }
            } else {
                if (strcmp(sdp->symbol_string, name) == 0) {
                    sdp->address = val;
                    (*p)--;
                }
            }
        }
    }
    return (p > 0) ? 0 : -1;
}

-- 
You are receiving this mail because:
You are the assignee for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]