perf dwarf-aux: Allow unnamed struct/union/enum
authorNamhyung Kim <namhyung@kernel.org>
Mon, 12 Jun 2023 23:41:02 +0000 (16:41 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Jun 2023 02:40:32 +0000 (23:40 -0300)
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.

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: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230612234102.3909116-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/dwarf-aux.c

index 3bff678..45e018c 100644 (file)
@@ -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);