Skip to content

Commit 60cb19b

Browse files
namhyungacmel
authored andcommitted
perf dwarf-aux: Factor out die_get_typename_from_type()
The die_get_typename_from_type() is to get the name of the given DIE in C-style type name. The difference from die_get_typename() is that it does not retrieve the DW_AT_type and use the given DIE directly. This will be used when users know the type DIE already. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: linux-toolchains@vger.kernel.org Cc: linux-trace-devel@vger.kernel.org Link: https://lore.kernel.org/r/20231213001323.718046-2-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent ac254df commit 60cb19b

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

tools/perf/util/dwarf-aux.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,32 +1051,28 @@ Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
10511051
}
10521052

10531053
/**
1054-
* die_get_typename - Get the name of given variable DIE
1055-
* @vr_die: a variable DIE
1054+
* die_get_typename_from_type - Get the name of given type DIE
1055+
* @type_die: a type DIE
10561056
* @buf: a strbuf for result type name
10571057
*
1058-
* Get the name of @vr_die and stores it to @buf. Return 0 if succeeded.
1058+
* Get the name of @type_die and stores it to @buf. Return 0 if succeeded.
10591059
* and Return -ENOENT if failed to find type name.
10601060
* Note that the result will stores typedef name if possible, and stores
10611061
* "*(function_type)" if the type is a function pointer.
10621062
*/
1063-
int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
1063+
int die_get_typename_from_type(Dwarf_Die *type_die, struct strbuf *buf)
10641064
{
1065-
Dwarf_Die type;
10661065
int tag, ret;
10671066
const char *tmp = "";
10681067

1069-
if (__die_get_real_type(vr_die, &type) == NULL)
1070-
return -ENOENT;
1071-
1072-
tag = dwarf_tag(&type);
1068+
tag = dwarf_tag(type_die);
10731069
if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)
10741070
tmp = "*";
10751071
else if (tag == DW_TAG_subroutine_type) {
10761072
/* Function pointer */
10771073
return strbuf_add(buf, "(function_type)", 15);
10781074
} else {
1079-
const char *name = dwarf_diename(&type);
1075+
const char *name = dwarf_diename(type_die);
10801076

10811077
if (tag == DW_TAG_union_type)
10821078
tmp = "union ";
@@ -1089,7 +1085,7 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
10891085
/* Write a base name */
10901086
return strbuf_addf(buf, "%s%s", tmp, name ?: "");
10911087
}
1092-
ret = die_get_typename(&type, buf);
1088+
ret = die_get_typename(type_die, buf);
10931089
if (ret < 0) {
10941090
/* void pointer has no type attribute */
10951091
if (tag == DW_TAG_pointer_type && ret == -ENOENT)
@@ -1100,6 +1096,26 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
11001096
return strbuf_addstr(buf, tmp);
11011097
}
11021098

1099+
/**
1100+
* die_get_typename - Get the name of given variable DIE
1101+
* @vr_die: a variable DIE
1102+
* @buf: a strbuf for result type name
1103+
*
1104+
* Get the name of @vr_die and stores it to @buf. Return 0 if succeeded.
1105+
* and Return -ENOENT if failed to find type name.
1106+
* Note that the result will stores typedef name if possible, and stores
1107+
* "*(function_type)" if the type is a function pointer.
1108+
*/
1109+
int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
1110+
{
1111+
Dwarf_Die type;
1112+
1113+
if (__die_get_real_type(vr_die, &type) == NULL)
1114+
return -ENOENT;
1115+
1116+
return die_get_typename_from_type(&type, buf);
1117+
}
1118+
11031119
/**
11041120
* die_get_varname - Get the name and type of given variable DIE
11051121
* @vr_die: a variable DIE

tools/perf/util/dwarf-aux.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name,
116116
Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
117117
Dwarf_Die *die_mem);
118118

119+
/* Get the name of given type DIE */
120+
int die_get_typename_from_type(Dwarf_Die *type_die, struct strbuf *buf);
121+
119122
/* Get the name of given variable DIE */
120123
int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf);
121124

0 commit comments

Comments
 (0)