Commit fb9596d1 authored by He Kuang's avatar He Kuang Committed by Arnaldo Carvalho de Melo

perf probe: Remove length limitation for showing available variables

Use struct strbuf instead of bare char[] to remove the length limitation
of variables in variable_list, so they will not disappear due to
overlength, and make preparation for adding more description for
variables.
Signed-off-by: default avatarHe Kuang <hekuang@huawei.com>
Acked-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1431336304-16863-1-git-send-email-hekuang@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ff8f695c
...@@ -848,19 +848,17 @@ Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, ...@@ -848,19 +848,17 @@ Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
/** /**
* die_get_typename - Get the name of given variable DIE * die_get_typename - Get the name of given variable DIE
* @vr_die: a variable DIE * @vr_die: a variable DIE
* @buf: a buffer for result type name * @buf: a strbuf for result type name
* @len: a max-length of @buf
* *
* Get the name of @vr_die and stores it to @buf. Return the actual length * Get the name of @vr_die and stores it to @buf. Return 0 if succeeded.
* of type name if succeeded. Return -E2BIG if @len is not enough long, and * and Return -ENOENT if failed to find type name.
* Return -ENOENT if failed to find type name.
* Note that the result will stores typedef name if possible, and stores * Note that the result will stores typedef name if possible, and stores
* "*(function_type)" if the type is a function pointer. * "*(function_type)" if the type is a function pointer.
*/ */
int die_get_typename(Dwarf_Die *vr_die, char *buf, int len) int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
{ {
Dwarf_Die type; Dwarf_Die type;
int tag, ret, ret2; int tag, ret;
const char *tmp = ""; const char *tmp = "";
if (__die_get_real_type(vr_die, &type) == NULL) if (__die_get_real_type(vr_die, &type) == NULL)
...@@ -871,8 +869,8 @@ int die_get_typename(Dwarf_Die *vr_die, char *buf, int len) ...@@ -871,8 +869,8 @@ int die_get_typename(Dwarf_Die *vr_die, char *buf, int len)
tmp = "*"; tmp = "*";
else if (tag == DW_TAG_subroutine_type) { else if (tag == DW_TAG_subroutine_type) {
/* Function pointer */ /* Function pointer */
ret = snprintf(buf, len, "(function_type)"); strbuf_addf(buf, "(function_type)");
return (ret >= len) ? -E2BIG : ret; return 0;
} else { } else {
if (!dwarf_diename(&type)) if (!dwarf_diename(&type))
return -ENOENT; return -ENOENT;
...@@ -883,39 +881,35 @@ int die_get_typename(Dwarf_Die *vr_die, char *buf, int len) ...@@ -883,39 +881,35 @@ int die_get_typename(Dwarf_Die *vr_die, char *buf, int len)
else if (tag == DW_TAG_enumeration_type) else if (tag == DW_TAG_enumeration_type)
tmp = "enum "; tmp = "enum ";
/* Write a base name */ /* Write a base name */
ret = snprintf(buf, len, "%s%s", tmp, dwarf_diename(&type)); strbuf_addf(buf, "%s%s", tmp, dwarf_diename(&type));
return (ret >= len) ? -E2BIG : ret; return 0;
}
ret = die_get_typename(&type, buf, len);
if (ret > 0) {
ret2 = snprintf(buf + ret, len - ret, "%s", tmp);
ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret;
} }
ret = die_get_typename(&type, buf);
if (ret == 0)
strbuf_addf(buf, "%s", tmp);
return ret; return ret;
} }
/** /**
* die_get_varname - Get the name and type of given variable DIE * die_get_varname - Get the name and type of given variable DIE
* @vr_die: a variable DIE * @vr_die: a variable DIE
* @buf: a buffer for type and variable name * @buf: a strbuf for type and variable name
* @len: the max-length of @buf
* *
* Get the name and type of @vr_die and stores it in @buf as "type\tname". * Get the name and type of @vr_die and stores it in @buf as "type\tname".
*/ */
int die_get_varname(Dwarf_Die *vr_die, char *buf, int len) int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
{ {
int ret, ret2; int ret;
ret = die_get_typename(vr_die, buf, len); ret = die_get_typename(vr_die, buf);
if (ret < 0) { if (ret < 0) {
pr_debug("Failed to get type, make it unknown.\n"); pr_debug("Failed to get type, make it unknown.\n");
ret = snprintf(buf, len, "(unknown_type)"); strbuf_addf(buf, "(unknown_type)");
} }
if (ret > 0) {
ret2 = snprintf(buf + ret, len - ret, "\t%s", strbuf_addf(buf, "\t%s", dwarf_diename(vr_die));
dwarf_diename(vr_die));
ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; return 0;
}
return ret;
} }
...@@ -117,8 +117,8 @@ extern Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, ...@@ -117,8 +117,8 @@ extern Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
Dwarf_Die *die_mem); Dwarf_Die *die_mem);
/* Get the name of given variable DIE */ /* Get the name of given variable DIE */
extern int die_get_typename(Dwarf_Die *vr_die, char *buf, int len); extern int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf);
/* Get the name and type of given variable DIE, stored as "type\tname" */ /* Get the name and type of given variable DIE, stored as "type\tname" */
extern int die_get_varname(Dwarf_Die *vr_die, char *buf, int len); extern int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf);
#endif #endif
...@@ -1255,14 +1255,11 @@ int debuginfo__find_trace_events(struct debuginfo *dbg, ...@@ -1255,14 +1255,11 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
return (ret < 0) ? ret : tf.ntevs; return (ret < 0) ? ret : tf.ntevs;
} }
#define MAX_VAR_LEN 64
/* Collect available variables in this scope */ /* Collect available variables in this scope */
static int collect_variables_cb(Dwarf_Die *die_mem, void *data) static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
{ {
struct available_var_finder *af = data; struct available_var_finder *af = data;
struct variable_list *vl; struct variable_list *vl;
char buf[MAX_VAR_LEN];
int tag, ret; int tag, ret;
vl = &af->vls[af->nvls - 1]; vl = &af->vls[af->nvls - 1];
...@@ -1274,10 +1271,16 @@ static int collect_variables_cb(Dwarf_Die *die_mem, void *data) ...@@ -1274,10 +1271,16 @@ static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
af->pf.fb_ops, &af->pf.sp_die, af->pf.fb_ops, &af->pf.sp_die,
NULL); NULL);
if (ret == 0) { if (ret == 0) {
ret = die_get_varname(die_mem, buf, MAX_VAR_LEN); struct strbuf buf;
pr_debug2("Add new var: %s\n", buf);
if (ret > 0) strbuf_init(&buf, 64);
strlist__add(vl->vars, buf); ret = die_get_varname(die_mem, &buf);
pr_debug2("Add new var: %s\n", buf.buf);
if (ret == 0) {
strlist__add(vl->vars,
strbuf_detach(&buf, NULL));
}
strbuf_release(&buf);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment