Skip to contentSkip to conversation

perf dwarf-aux: fix __die_find_scope_cb for namespaces

PATCH Superseded Zecheng Li 3 participants 3 messages Aug 25, 2025 – Sep 13, 2025 perf events

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zecheng Li

author
#0 lore raw

PATCH v2 9/10 perf dwarf-aux: fix __die_find_scope_cb for namespaces

Currently __die_find_scope_cb goes to check siblings when the DIE doesn't include the given PC. However namespaces don't have a PC and could contain children that have that PC. When we encounter a namespace, we should check both its children and siblings.

---
 tools/perf/util/dwarf-aux.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/util/dwarf-aux.c +9 -0
index 56e1b5690dc4..013862ea8924 100644
@@ -1962,6 +1962,7 @@ struct find_scope_data {
 static int __die_find_scope_cb(Dwarf_Die *die_mem, void *arg)
 {
 	struct find_scope_data *data = arg;
+	int tag = dwarf_tag(die_mem);
 
 	if (dwarf_haspc(die_mem, data->pc)) {
 		Dwarf_Die *tmp;
@@ -1975,6 +1976,14 @@ static int __die_find_scope_cb(Dwarf_Die *die_mem, void *arg)
 		data->nr++;
 		return DIE_FIND_CB_CHILD;
 	}
+
+	/*
+	 * If the DIE doesn't have the PC, we still need to check its children
+	 * and siblings if it's a container like a namespace.
+	 */
+	if (tag == DW_TAG_namespace)
+		return DIE_FIND_CB_CONTINUE;
+
 	return DIE_FIND_CB_SIBLING;
 }
 
Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog
maintainer Reviewed-by on v2 9/10
#1 lore raw
Quoted 6 lines · Zecheng Li

Currently __die_find_scope_cb goes to check siblings when the DIE doesn't include the given PC. However namespaces don't have a PC and could contain children that have that PC. When we encounter a namespace, we should check both its children and siblings.

Thanks,
Namhyung

Quoted 34 lines
---
 tools/perf/util/dwarf-aux.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/util/dwarf-aux.c +9 -0
index 56e1b5690dc4..013862ea8924 100644
@@ -1962,6 +1962,7 @@ struct find_scope_data {
 static int __die_find_scope_cb(Dwarf_Die *die_mem, void *arg)
 {
 	struct find_scope_data *data = arg;
+	int tag = dwarf_tag(die_mem);
 
 	if (dwarf_haspc(die_mem, data->pc)) {
 		Dwarf_Die *tmp;
@@ -1975,6 +1976,14 @@ static int __die_find_scope_cb(Dwarf_Die *die_mem, void *arg)
 		data->nr++;
 		return DIE_FIND_CB_CHILD;
 	}
+
+	/*
+	 * If the DIE doesn't have the PC, we still need to check its children
+	 * and siblings if it's a container like a namespace.
+	 */
+	if (tag == DW_TAG_namespace)
+		return DIE_FIND_CB_CONTINUE;
+
 	return DIE_FIND_CB_SIBLING;
 }
 
Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog
#2 lore raw
Quoted 9 lines · Namhyung Kim
Quoted 6 lines · Zecheng Li

Currently __die_find_scope_cb goes to check siblings when the DIE doesn't include the given PC. However namespaces don't have a PC and could contain children that have that PC. When we encounter a namespace, we should check both its children and siblings.

I'm cherry picking this one as well.

- Arnaldo