Allow users to set external defined global variables as event arguments (e.g. jiffies).
Unified · Split
| @@ -406,6 +406,9 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) · 405 unmodified lines | ||
| 406 | 406 | struct probe_trace_arg *tvar = pf->tvar; |
| 407 | 407 | int ret; |
| 408 | 408 | |
| 409 | + if (dwarf_attr(vr_die, DW_AT_external, &attr) != NULL) | |
| 410 | + goto static_var; | |
| 411 | + | |
| 409 | 412 | /* TODO: handle more than 1 exprs */ |
| 410 | 413 | if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL || |
| 411 | 414 | dwarf_getlocation_addr(&attr, pf->addr, &op, &nops, 1) <= 0 || |
| @@ -417,6 +420,7 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) · 5 unmodified lines | ||
| 417 | 420 | } |
| 418 | 421 | |
| 419 | 422 | if (op->atom == DW_OP_addr) { |
| 423 | +static_var: | |
| 420 | 424 | /* Static variables on memory (not stack), make @varname */ |
| 421 | 425 | ret = strlen(dwarf_diename(vr_die)); |
| 422 | 426 | tvar->value = zalloc(ret + 2); |
| @@ -746,17 +750,22 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) · 323 unmodified lines | ||
| 746 | 750 | else { |
| 747 | 751 | /* Search upper class */ |
| 748 | 752 | nscopes = dwarf_getscopes_die(sp_die, &scopes); |
| 749 | − if (nscopes > 0) { | |
| 750 | − ret = dwarf_getscopevar(scopes, nscopes, pf->pvar->var, | |
| 751 | − 0, NULL, 0, 0, &vr_die); | |
| 752 | − if (ret >= 0) | |
| 753 | + while (nscopes-- > 1) { | |
| 754 | + pr_debug("Searching variables in %s\n", | |
| 755 | + dwarf_diename(&scopes[nscopes])); | |
| 756 | + /* We should check this scope, so give dummy address */ | |
| 757 | + if (die_find_variable_at(&scopes[nscopes], | |
| 758 | + pf->pvar->var, 0, | |
| 759 | + &vr_die)) { | |
| 753 | 760 | ret = convert_variable(&vr_die, pf); |
| 754 | − else | |
| 755 | − ret = -ENOENT; | |
| 761 | + goto found; | |
| 762 | + } | |
| 763 | + } | |
| 764 | + if (scopes) | |
| 756 | 765 | free(scopes); |
| 757 | − } else | |
| 758 | − ret = -ENOENT; | |
| 766 | + ret = -ENOENT; | |
| 759 | 767 | } |
| 768 | +found: | |
| 760 | 769 | if (ret < 0) |
| 761 | 770 | pr_warning("Failed to find '%s' in this function.\n", |
| 762 | 771 | pf->pvar->var); |