History

perf probe: Support global variables

Allow users to set external defined global variables as event arguments (e.g. jiffies).

Masami Hiramatsu committed 16 years ago

Commit 632941c1 parent 378eeaa1 file · +17 −8Browse files

Unified · Split

tools/perf/util/probe-finder.c+17−8
@@ -406,6 +406,9 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) · 405 unmodified lines
406406 struct probe_trace_arg *tvar = pf->tvar;
407407 int ret;
408408
409+ if (dwarf_attr(vr_die, DW_AT_external, &attr) != NULL)
410+ goto static_var;
411+
409412 /* TODO: handle more than 1 exprs */
410413 if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL ||
411414 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
417420 }
418421
419422 if (op->atom == DW_OP_addr) {
423+static_var:
420424 /* Static variables on memory (not stack), make @varname */
421425 ret = strlen(dwarf_diename(vr_die));
422426 tvar->value = zalloc(ret + 2);
@@ -746,17 +750,22 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) · 323 unmodified lines
746750 else {
747751 /* Search upper class */
748752 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)) {
753760 ret = convert_variable(&vr_die, pf);
754− else
755− ret = -ENOENT;
761+ goto found;
762+ }
763+ }
764+ if (scopes)
756765 free(scopes);
757− } else
758− ret = -ENOENT;
766+ ret = -ENOENT;
759767 }
768+found:
760769 if (ret < 0)
761770 pr_warning("Failed to find '%s' in this function.\n",
762771 pf->pvar->var);