提交 8bd0e1be 编写于 作者: I Ingo Molnar

Merge branch 'perf/core' of...

Merge branch 'perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 into perf/core
...@@ -42,7 +42,7 @@ Synopsis of kprobe_events ...@@ -42,7 +42,7 @@ Synopsis of kprobe_events
+|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**) +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
NAME=FETCHARG : Set NAME as the argument name of FETCHARG. NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
(u8/u16/u32/u64/s8/s16/s32/s64) are supported. (u8/u16/u32/u64/s8/s16/s32/s64) and string are supported.
(*) only for return probe. (*) only for return probe.
(**) this is useful for fetching a field of data structures. (**) this is useful for fetching a field of data structures.
......
此差异已折叠。
...@@ -94,8 +94,8 @@ Each probe argument follows below syntax. ...@@ -94,8 +94,8 @@ Each probe argument follows below syntax.
[NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE] [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE]
'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. 'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
LINE SYNTAX LINE SYNTAX
----------- -----------
......
...@@ -605,33 +605,35 @@ endif ...@@ -605,33 +605,35 @@ endif
ifdef NO_DEMANGLE ifdef NO_DEMANGLE
BASIC_CFLAGS += -DNO_DEMANGLE BASIC_CFLAGS += -DNO_DEMANGLE
else ifdef HAVE_CPLUS_DEMANGLE
EXTLIBS += -liberty
BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
else else
FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd ifdef HAVE_CPLUS_DEMANGLE
has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)) EXTLIBS += -liberty
ifeq ($(has_bfd),y) BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
EXTLIBS += -lbfd else
else FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY)) ifeq ($(has_bfd),y)
ifeq ($(has_bfd_iberty),y) EXTLIBS += -lbfd
EXTLIBS += -lbfd -liberty
else else
FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z)) has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY))
ifeq ($(has_bfd_iberty_z),y) ifeq ($(has_bfd_iberty),y)
EXTLIBS += -lbfd -liberty -lz EXTLIBS += -lbfd -liberty
else else
FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE)) has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z))
ifeq ($(has_cplus_demangle),y) ifeq ($(has_bfd_iberty_z),y)
EXTLIBS += -liberty EXTLIBS += -lbfd -liberty -lz
BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
else else
msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling) FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty
BASIC_CFLAGS += -DNO_DEMANGLE has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE))
ifeq ($(has_cplus_demangle),y)
EXTLIBS += -liberty
BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
else
msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
BASIC_CFLAGS += -DNO_DEMANGLE
endif
endif endif
endif endif
endif endif
......
...@@ -557,7 +557,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) ...@@ -557,7 +557,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
/* Parse perf-probe event argument */ /* Parse perf-probe event argument */
static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
{ {
char *tmp; char *tmp, *goodname;
struct perf_probe_arg_field **fieldp; struct perf_probe_arg_field **fieldp;
pr_debug("parsing arg: %s into ", str); pr_debug("parsing arg: %s into ", str);
...@@ -580,7 +580,7 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) ...@@ -580,7 +580,7 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
pr_debug("type:%s ", arg->type); pr_debug("type:%s ", arg->type);
} }
tmp = strpbrk(str, "-."); tmp = strpbrk(str, "-.[");
if (!is_c_varname(str) || !tmp) { if (!is_c_varname(str) || !tmp) {
/* A variable, register, symbol or special value */ /* A variable, register, symbol or special value */
arg->var = strdup(str); arg->var = strdup(str);
...@@ -590,10 +590,11 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) ...@@ -590,10 +590,11 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
return 0; return 0;
} }
/* Structure fields */ /* Structure fields or array element */
arg->var = strndup(str, tmp - str); arg->var = strndup(str, tmp - str);
if (arg->var == NULL) if (arg->var == NULL)
return -ENOMEM; return -ENOMEM;
goodname = arg->var;
pr_debug("%s, ", arg->var); pr_debug("%s, ", arg->var);
fieldp = &arg->field; fieldp = &arg->field;
...@@ -601,22 +602,38 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) ...@@ -601,22 +602,38 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
*fieldp = zalloc(sizeof(struct perf_probe_arg_field)); *fieldp = zalloc(sizeof(struct perf_probe_arg_field));
if (*fieldp == NULL) if (*fieldp == NULL)
return -ENOMEM; return -ENOMEM;
if (*tmp == '.') { if (*tmp == '[') { /* Array */
str = tmp + 1; str = tmp;
(*fieldp)->ref = false; (*fieldp)->index = strtol(str + 1, &tmp, 0);
} else if (tmp[1] == '>') {
str = tmp + 2;
(*fieldp)->ref = true; (*fieldp)->ref = true;
} else { if (*tmp != ']' || tmp == str + 1) {
semantic_error("Argument parse error: %s\n", str); semantic_error("Array index must be a"
return -EINVAL; " number.\n");
return -EINVAL;
}
tmp++;
if (*tmp == '\0')
tmp = NULL;
} else { /* Structure */
if (*tmp == '.') {
str = tmp + 1;
(*fieldp)->ref = false;
} else if (tmp[1] == '>') {
str = tmp + 2;
(*fieldp)->ref = true;
} else {
semantic_error("Argument parse error: %s\n",
str);
return -EINVAL;
}
tmp = strpbrk(str, "-.[");
} }
tmp = strpbrk(str, "-.");
if (tmp) { if (tmp) {
(*fieldp)->name = strndup(str, tmp - str); (*fieldp)->name = strndup(str, tmp - str);
if ((*fieldp)->name == NULL) if ((*fieldp)->name == NULL)
return -ENOMEM; return -ENOMEM;
if (*str != '[')
goodname = (*fieldp)->name;
pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref);
fieldp = &(*fieldp)->next; fieldp = &(*fieldp)->next;
} }
...@@ -624,11 +641,13 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) ...@@ -624,11 +641,13 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
(*fieldp)->name = strdup(str); (*fieldp)->name = strdup(str);
if ((*fieldp)->name == NULL) if ((*fieldp)->name == NULL)
return -ENOMEM; return -ENOMEM;
if (*str != '[')
goodname = (*fieldp)->name;
pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref);
/* If no name is specified, set the last field name */ /* If no name is specified, set the last field name (not array index)*/
if (!arg->name) { if (!arg->name) {
arg->name = strdup((*fieldp)->name); arg->name = strdup(goodname);
if (arg->name == NULL) if (arg->name == NULL)
return -ENOMEM; return -ENOMEM;
} }
...@@ -776,8 +795,11 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len) ...@@ -776,8 +795,11 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
len -= ret; len -= ret;
while (field) { while (field) {
ret = e_snprintf(tmp, len, "%s%s", field->ref ? "->" : ".", if (field->name[0] == '[')
field->name); ret = e_snprintf(tmp, len, "%s", field->name);
else
ret = e_snprintf(tmp, len, "%s%s",
field->ref ? "->" : ".", field->name);
if (ret <= 0) if (ret <= 0)
goto error; goto error;
tmp += ret; tmp += ret;
...@@ -904,6 +926,7 @@ static int __synthesize_kprobe_trace_arg_ref(struct kprobe_trace_arg_ref *ref, ...@@ -904,6 +926,7 @@ static int __synthesize_kprobe_trace_arg_ref(struct kprobe_trace_arg_ref *ref,
static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg, static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg,
char *buf, size_t buflen) char *buf, size_t buflen)
{ {
struct kprobe_trace_arg_ref *ref = arg->ref;
int ret, depth = 0; int ret, depth = 0;
char *tmp = buf; char *tmp = buf;
...@@ -917,16 +940,24 @@ static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg, ...@@ -917,16 +940,24 @@ static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg,
buf += ret; buf += ret;
buflen -= ret; buflen -= ret;
/* Special case: @XXX */
if (arg->value[0] == '@' && arg->ref)
ref = ref->next;
/* Dereferencing arguments */ /* Dereferencing arguments */
if (arg->ref) { if (ref) {
depth = __synthesize_kprobe_trace_arg_ref(arg->ref, &buf, depth = __synthesize_kprobe_trace_arg_ref(ref, &buf,
&buflen, 1); &buflen, 1);
if (depth < 0) if (depth < 0)
return depth; return depth;
} }
/* Print argument value */ /* Print argument value */
ret = e_snprintf(buf, buflen, "%s", arg->value); if (arg->value[0] == '@' && arg->ref)
ret = e_snprintf(buf, buflen, "%s%+ld", arg->value,
arg->ref->offset);
else
ret = e_snprintf(buf, buflen, "%s", arg->value);
if (ret < 0) if (ret < 0)
return ret; return ret;
buf += ret; buf += ret;
......
...@@ -50,6 +50,7 @@ struct perf_probe_point { ...@@ -50,6 +50,7 @@ struct perf_probe_point {
struct perf_probe_arg_field { struct perf_probe_arg_field {
struct perf_probe_arg_field *next; /* Next field */ struct perf_probe_arg_field *next; /* Next field */
char *name; /* Name of the field */ char *name; /* Name of the field */
long index; /* Array index number */
bool ref; /* Referencing flag */ bool ref; /* Referencing flag */
}; };
......
...@@ -406,14 +406,50 @@ static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, ...@@ -406,14 +406,50 @@ static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
* Probe finder related functions * Probe finder related functions
*/ */
static struct kprobe_trace_arg_ref *alloc_trace_arg_ref(long offs)
{
struct kprobe_trace_arg_ref *ref;
ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
if (ref != NULL)
ref->offset = offs;
return ref;
}
/* Show a location */ /* Show a location */
static int convert_location(Dwarf_Op *op, struct probe_finder *pf) static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf)
{ {
Dwarf_Attribute attr;
Dwarf_Op *op;
size_t nops;
unsigned int regn; unsigned int regn;
Dwarf_Word offs = 0; Dwarf_Word offs = 0;
bool ref = false; bool ref = false;
const char *regs; const char *regs;
struct kprobe_trace_arg *tvar = pf->tvar; struct kprobe_trace_arg *tvar = pf->tvar;
int ret;
/* TODO: handle more than 1 exprs */
if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL ||
dwarf_getlocation_addr(&attr, pf->addr, &op, &nops, 1) <= 0 ||
nops == 0) {
/* TODO: Support const_value */
pr_err("Failed to find the location of %s at this address.\n"
" Perhaps, it has been optimized out.\n", pf->pvar->var);
return -ENOENT;
}
if (op->atom == DW_OP_addr) {
/* Static variables on memory (not stack), make @varname */
ret = strlen(dwarf_diename(vr_die));
tvar->value = zalloc(ret + 2);
if (tvar->value == NULL)
return -ENOMEM;
snprintf(tvar->value, ret + 2, "@%s", dwarf_diename(vr_die));
tvar->ref = alloc_trace_arg_ref((long)offs);
if (tvar->ref == NULL)
return -ENOMEM;
return 0;
}
/* If this is based on frame buffer, set the offset */ /* If this is based on frame buffer, set the offset */
if (op->atom == DW_OP_fbreg) { if (op->atom == DW_OP_fbreg) {
...@@ -455,27 +491,72 @@ static int convert_location(Dwarf_Op *op, struct probe_finder *pf) ...@@ -455,27 +491,72 @@ static int convert_location(Dwarf_Op *op, struct probe_finder *pf)
return -ENOMEM; return -ENOMEM;
if (ref) { if (ref) {
tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); tvar->ref = alloc_trace_arg_ref((long)offs);
if (tvar->ref == NULL) if (tvar->ref == NULL)
return -ENOMEM; return -ENOMEM;
tvar->ref->offset = (long)offs;
} }
return 0; return 0;
} }
static int convert_variable_type(Dwarf_Die *vr_die, static int convert_variable_type(Dwarf_Die *vr_die,
struct kprobe_trace_arg *targ) struct kprobe_trace_arg *tvar,
const char *cast)
{ {
struct kprobe_trace_arg_ref **ref_ptr = &tvar->ref;
Dwarf_Die type; Dwarf_Die type;
char buf[16]; char buf[16];
int ret; int ret;
/* TODO: check all types */
if (cast && strcmp(cast, "string") != 0) {
/* Non string type is OK */
tvar->type = strdup(cast);
return (tvar->type == NULL) ? -ENOMEM : 0;
}
if (die_get_real_type(vr_die, &type) == NULL) { if (die_get_real_type(vr_die, &type) == NULL) {
pr_warning("Failed to get a type information of %s.\n", pr_warning("Failed to get a type information of %s.\n",
dwarf_diename(vr_die)); dwarf_diename(vr_die));
return -ENOENT; return -ENOENT;
} }
pr_debug("%s type is %s.\n",
dwarf_diename(vr_die), dwarf_diename(&type));
if (cast && strcmp(cast, "string") == 0) { /* String type */
ret = dwarf_tag(&type);
if (ret != DW_TAG_pointer_type &&
ret != DW_TAG_array_type) {
pr_warning("Failed to cast into string: "
"%s(%s) is not a pointer nor array.",
dwarf_diename(vr_die), dwarf_diename(&type));
return -EINVAL;
}
if (ret == DW_TAG_pointer_type) {
if (die_get_real_type(&type, &type) == NULL) {
pr_warning("Failed to get a type information.");
return -ENOENT;
}
while (*ref_ptr)
ref_ptr = &(*ref_ptr)->next;
/* Add new reference with offset +0 */
*ref_ptr = zalloc(sizeof(struct kprobe_trace_arg_ref));
if (*ref_ptr == NULL) {
pr_warning("Out of memory error\n");
return -ENOMEM;
}
}
if (die_compare_name(&type, "char") != 0 &&
die_compare_name(&type, "unsigned char") != 0) {
pr_warning("Failed to cast into string: "
"%s is not (unsigned) char *.",
dwarf_diename(vr_die));
return -EINVAL;
}
tvar->type = strdup(cast);
return (tvar->type == NULL) ? -ENOMEM : 0;
}
ret = die_get_byte_size(&type) * 8; ret = die_get_byte_size(&type) * 8;
if (ret) { if (ret) {
/* Check the bitwidth */ /* Check the bitwidth */
...@@ -495,8 +576,8 @@ static int convert_variable_type(Dwarf_Die *vr_die, ...@@ -495,8 +576,8 @@ static int convert_variable_type(Dwarf_Die *vr_die,
strerror(-ret)); strerror(-ret));
return ret; return ret;
} }
targ->type = strdup(buf); tvar->type = strdup(buf);
if (targ->type == NULL) if (tvar->type == NULL)
return -ENOMEM; return -ENOMEM;
} }
return 0; return 0;
...@@ -510,16 +591,44 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, ...@@ -510,16 +591,44 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
struct kprobe_trace_arg_ref *ref = *ref_ptr; struct kprobe_trace_arg_ref *ref = *ref_ptr;
Dwarf_Die type; Dwarf_Die type;
Dwarf_Word offs; Dwarf_Word offs;
int ret; int ret, tag;
pr_debug("converting %s in %s\n", field->name, varname); pr_debug("converting %s in %s\n", field->name, varname);
if (die_get_real_type(vr_die, &type) == NULL) { if (die_get_real_type(vr_die, &type) == NULL) {
pr_warning("Failed to get the type of %s.\n", varname); pr_warning("Failed to get the type of %s.\n", varname);
return -ENOENT; return -ENOENT;
} }
pr_debug2("Var real type: (%x)\n", (unsigned)dwarf_dieoffset(&type));
/* Check the pointer and dereference */ tag = dwarf_tag(&type);
if (dwarf_tag(&type) == DW_TAG_pointer_type) {
if (field->name[0] == '[' &&
(tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)) {
if (field->next)
/* Save original type for next field */
memcpy(die_mem, &type, sizeof(*die_mem));
/* Get the type of this array */
if (die_get_real_type(&type, &type) == NULL) {
pr_warning("Failed to get the type of %s.\n", varname);
return -ENOENT;
}
pr_debug2("Array real type: (%x)\n",
(unsigned)dwarf_dieoffset(&type));
if (tag == DW_TAG_pointer_type) {
ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
if (ref == NULL)
return -ENOMEM;
if (*ref_ptr)
(*ref_ptr)->next = ref;
else
*ref_ptr = ref;
}
ref->offset += die_get_byte_size(&type) * field->index;
if (!field->next)
/* Save vr_die for converting types */
memcpy(die_mem, vr_die, sizeof(*die_mem));
goto next;
} else if (tag == DW_TAG_pointer_type) {
/* Check the pointer and dereference */
if (!field->ref) { if (!field->ref) {
pr_err("Semantic error: %s must be referred by '->'\n", pr_err("Semantic error: %s must be referred by '->'\n",
field->name); field->name);
...@@ -545,10 +654,15 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, ...@@ -545,10 +654,15 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
*ref_ptr = ref; *ref_ptr = ref;
} else { } else {
/* Verify it is a data structure */ /* Verify it is a data structure */
if (dwarf_tag(&type) != DW_TAG_structure_type) { if (tag != DW_TAG_structure_type) {
pr_warning("%s is not a data structure.\n", varname); pr_warning("%s is not a data structure.\n", varname);
return -EINVAL; return -EINVAL;
} }
if (field->name[0] == '[') {
pr_err("Semantic error: %s is not a pointor nor array.",
varname);
return -EINVAL;
}
if (field->ref) { if (field->ref) {
pr_err("Semantic error: %s must be referred by '.'\n", pr_err("Semantic error: %s must be referred by '.'\n",
field->name); field->name);
...@@ -575,6 +689,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, ...@@ -575,6 +689,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
} }
ref->offset += (long)offs; ref->offset += (long)offs;
next:
/* Converting next field */ /* Converting next field */
if (field->next) if (field->next)
return convert_variable_fields(die_mem, field->name, return convert_variable_fields(die_mem, field->name,
...@@ -586,51 +701,32 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, ...@@ -586,51 +701,32 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
/* Show a variables in kprobe event format */ /* Show a variables in kprobe event format */
static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
{ {
Dwarf_Attribute attr;
Dwarf_Die die_mem; Dwarf_Die die_mem;
Dwarf_Op *expr;
size_t nexpr;
int ret; int ret;
if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL) pr_debug("Converting variable %s into trace event.\n",
goto error; dwarf_diename(vr_die));
/* TODO: handle more than 1 exprs */
ret = dwarf_getlocation_addr(&attr, pf->addr, &expr, &nexpr, 1);
if (ret <= 0 || nexpr == 0)
goto error;
ret = convert_location(expr, pf); ret = convert_variable_location(vr_die, pf);
if (ret == 0 && pf->pvar->field) { if (ret == 0 && pf->pvar->field) {
ret = convert_variable_fields(vr_die, pf->pvar->var, ret = convert_variable_fields(vr_die, pf->pvar->var,
pf->pvar->field, &pf->tvar->ref, pf->pvar->field, &pf->tvar->ref,
&die_mem); &die_mem);
vr_die = &die_mem; vr_die = &die_mem;
} }
if (ret == 0) { if (ret == 0)
if (pf->pvar->type) { ret = convert_variable_type(vr_die, pf->tvar, pf->pvar->type);
pf->tvar->type = strdup(pf->pvar->type);
if (pf->tvar->type == NULL)
ret = -ENOMEM;
} else
ret = convert_variable_type(vr_die, pf->tvar);
}
/* *expr will be cached in libdw. Don't free it. */ /* *expr will be cached in libdw. Don't free it. */
return ret; return ret;
error:
/* TODO: Support const_value */
pr_err("Failed to find the location of %s at this address.\n"
" Perhaps, it has been optimized out.\n", pf->pvar->var);
return -ENOENT;
} }
/* Find a variable in a subprogram die */ /* Find a variable in a subprogram die */
static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
{ {
Dwarf_Die vr_die; Dwarf_Die vr_die, *scopes;
char buf[32], *ptr; char buf[32], *ptr;
int ret; int ret, nscopes;
/* TODO: Support arrays */
if (pf->pvar->name) if (pf->pvar->name)
pf->tvar->name = strdup(pf->pvar->name); pf->tvar->name = strdup(pf->pvar->name);
else { else {
...@@ -657,12 +753,26 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) ...@@ -657,12 +753,26 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
pr_debug("Searching '%s' variable in context.\n", pr_debug("Searching '%s' variable in context.\n",
pf->pvar->var); pf->pvar->var);
/* Search child die for local variables and parameters. */ /* Search child die for local variables and parameters. */
if (!die_find_variable(sp_die, pf->pvar->var, &vr_die)) { if (die_find_variable(sp_die, pf->pvar->var, &vr_die))
ret = convert_variable(&vr_die, pf);
else {
/* Search upper class */
nscopes = dwarf_getscopes_die(sp_die, &scopes);
if (nscopes > 0) {
ret = dwarf_getscopevar(scopes, nscopes, pf->pvar->var,
0, NULL, 0, 0, &vr_die);
if (ret >= 0)
ret = convert_variable(&vr_die, pf);
else
ret = -ENOENT;
free(scopes);
} else
ret = -ENOENT;
}
if (ret < 0)
pr_warning("Failed to find '%s' in this function.\n", pr_warning("Failed to find '%s' in this function.\n",
pf->pvar->var); pf->pvar->var);
return -ENOENT; return ret;
}
return convert_variable(&vr_die, pf);
} }
/* Show a probe point to output buffer */ /* Show a probe point to output buffer */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册