Skip to contentSkip to conversation

perf dwarf-aux: Print array type name with "[]"

PATCH Applied Namhyung Kim 3 participants 3 messages May 7, 2024 – May 8, 2024 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf dwarf-aux: Print array type name with "[]"

It's confusing both pointers and arrays are printed as *. Let's print array types with [] so that we can identify them easily. Although it's interchangable, sometimes it can cause confusion with size like in the below example.

Note that it is not the same with C syntax where it goes to the variable names, but we want to have it in the type names (like in Go language).

Before:
mov [20] 0x68(reg5) -> reg0 type='struct page**' size=0x80 (die:0x4e61d32)

After:
mov [20] 0x68(reg5) -> reg0 type='struct page*[]' size=0x80 (die:0x4e61d32)

Cc Masami Hiramatsu <[email protected]>
---
 tools/perf/util/dwarf-aux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/dwarf-aux.c +3 -1
index c0a492e65388..ec988f294497 100644
@@ -1110,8 +1110,10 @@ int die_get_typename_from_type(Dwarf_Die *type_die, struct strbuf *buf)
 	const char *tmp = "";
 
 	tag = dwarf_tag(type_die);
-	if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)
+	if (tag == DW_TAG_pointer_type)
 		tmp = "*";
+	else if (tag == DW_TAG_array_type)
+		tmp = "[]";
 	else if (tag == DW_TAG_subroutine_type) {
 		/* Function pointer */
 		return strbuf_add(buf, "(function_type)", 15);
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Mon, 6 May 2024 21:13:38 -0700 Namhyung Kim <[email protected]> wrote:

It's confusing both pointers and arrays are printed as *. Let's print array types with [] so that we can identify them easily. Although it's interchangable, sometimes it can cause confusion with size like in the below example.

Quoted 9 lines

Note that it is not the same with C syntax where it goes to the variable names, but we want to have it in the type names (like in Go language).

Before:
mov [20] 0x68(reg5) -> reg0 type='struct page**' size=0x80 (die:0x4e61d32)

After:
mov [20] 0x68(reg5) -> reg0 type='struct page*[]' size=0x80 (die:0x4e61d32)

Good improvement!

Thank you!

Quoted 25 lines
Cc Masami Hiramatsu <[email protected]>
---
 tools/perf/util/dwarf-aux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/dwarf-aux.c +3 -1
index c0a492e65388..ec988f294497 100644
@@ -1110,8 +1110,10 @@ int die_get_typename_from_type(Dwarf_Die *type_die, struct strbuf *buf)
 	const char *tmp = "";
 
 	tag = dwarf_tag(type_die);
-	if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)
+	if (tag == DW_TAG_pointer_type)
 		tmp = "*";
+	else if (tag == DW_TAG_array_type)
+		tmp = "[]";
 	else if (tag == DW_TAG_subroutine_type) {
 		/* Function pointer */
 		return strbuf_add(buf, "(function_type)", 15);
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
maintainer Applied
#2 lore raw
Quoted 14 lines · Masami Hiramatsu
Quoted 11 lines · On Mon, 6 May 2024 21:13:38 -0700 Namhyung Kim <[email protected]> wrote:

It's confusing both pointers and arrays are printed as *. Let's print array types with [] so that we can identify them easily. Although it's interchangable, sometimes it can cause confusion with size like in the below example.

Note that it is not the same with C syntax where it goes to the variable names, but we want to have it in the type names (like in Go language).

Before:
mov [20] 0x68(reg5) -> reg0 type='struct page**' size=0x80 (die:0x4e61d32)

Quoted 7 lines
Quoted 3 lines

After:
mov [20] 0x68(reg5) -> reg0 type='struct page*[]' size=0x80 (die:0x4e61d32)

Good improvement!

Indeed,

Thanks, applied to perf-tools-next,

- Arnaldo