perf dwarf-aux: Fix off-by-one in die_get_varname()
Namhyung Kim
maintainerPATCH 1/2 perf dwarf-aux: Fix off-by-one in die_get_varname()
The die_get_varname() returns "(unknown_type)" string if it failed to find a type for the variable. But it had a space before the opening parenthesis and it made the closing parenthesis cut off due to the off-by-one in the string length (14).
--- tools/perf/util/dwarf-aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/dwarf-aux.c +1 -1
@@ -1103,7 +1103,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf) ret =die_get_typename (vr_die, buf);if (ret <0 ) {pr_debug ("Failed to get type, make it unknown.\n" ); - ret =strbuf_add (buf," (unknown_type)" ,14 ); + ret =strbuf_add (buf,"(unknown_type)" ,14 ); }return ret <0 ? ret :strbuf_addf (buf,"\t%s" ,dwarf_diename (vr_die));
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Namhyung Kim
maintainerPATCH 2/2 perf dwarf-aux: Allow unnamed struct/union/enum
It's possible some struct/union/enum type don't have type name. Allow the empty name after "struct"/"union"/"enum" string rather than fail.
--- tools/perf/util/dwarf-aux.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/dwarf-aux.c +5 -3
@@ -1074,16 +1074,18 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)/* Function pointer */ return strbuf_add (buf,"(function_type)" ,15 ); }else { -if (!dwarf_diename (&type)) -return -ENOENT ; +const char *name =dwarf_diename (&type); +if (tag == DW_TAG_union_type) tmp ="union " ;else if (tag == DW_TAG_structure_type) tmp ="struct " ;else if (tag == DW_TAG_enumeration_type) tmp ="enum " ; +else if (name ==NULL ) +return -ENOENT ;/* Write a base name */ -return strbuf_addf (buf,"%s%s" , tmp,dwarf_diename (&type)); +return strbuf_addf (buf,"%s%s" , tmp, name ?:"" ); } ret =die_get_typename (&type, buf);return ret ? ret :strbuf_addstr (buf, tmp);
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Em Mon, Jun 12, 2023 at 04:41:01PM -0700, Namhyung Kim escreveu:
Quoted 4 lines
The
die_get_varname()returns "(unknown_type)" string if it failed to find a type for the variable. But it had a space before the opening parenthesis and it made the closing parenthesis cut off due to the off-by-one in the string length (14).
Thanks, applied and added:
I introduced this long ago :-\
- Arnaldo
Quoted 20 lines
Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/dwarf-aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/dwarf-aux.c +1
-1@@ -1103,7 +1103,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf) ret =die_get_typename (vr_die, buf);if (ret <0 ) {pr_debug ("Failed to get type, make it unknown.\n" ); - ret =strbuf_add (buf," (unknown_type)" ,14 ); + ret =strbuf_add (buf,"(unknown_type)" ,14 ); }return ret <0 ? ret :strbuf_addf (buf,"\t%s" ,dwarf_diename (vr_die));Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Em Mon, Jun 12, 2023 at 04:41:01PM -0700, Namhyung Kim escreveu:
Quoted 4 lines
The
die_get_varname()returns "(unknown_type)" string if it failed to find a type for the variable. But it had a space before the opening parenthesis and it made the closing parenthesis cut off due to the off-by-one in the string length (14).
Thanks, applied both patches.
- Arnaldo
Quoted 21 lines
Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/dwarf-aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/dwarf-aux.c +1
-1@@ -1103,7 +1103,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf) ret =die_get_typename (vr_die, buf);if (ret <0 ) {pr_debug ("Failed to get type, make it unknown.\n" ); - ret =strbuf_add (buf," (unknown_type)" ,14 ); + ret =strbuf_add (buf,"(unknown_type)" ,14 ); }return ret <0 ? ret :strbuf_addf (buf,"\t%s" ,dwarf_diename (vr_die));Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Signature · 1 line
- Arnaldo