Skip to contentSkip to conversation

stacktrace: print real address of trace entries

PATCH In review Haesung Kim 2 participants 2 messages Sep 4, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 stacktrace: print real address of trace entries

If function is marked as static and compiler decies to lnline function with or without inline keyword, the function has no symbol. We just know symbol located near the address of the inline function by %pS type that shows symbol and offset. But we don't know function name.
The real address let us extract the function name and location of source code by debugging tools such as addr2line. This is helpful to debug.

---
 kernel/stacktrace.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/stacktrace.c +8 -3
index 946f44a..b7168c5 100644
@@ -24,12 +24,15 @@ void stack_trace_print(const unsigned long *entries, unsigned int nr_entries,
 		       int spaces)
 {
 	unsigned int i;
+	unsigned long ip;
 
 	if (WARN_ON(!entries))
 		return;
 
 	for (i = 0; i < nr_entries; i++)
-		printk("%*c%pS\n", 1 + spaces, ' ', (void *)entries[i]);
+		ip = entries[i];
+		printk("%*c[<%px>] %pS\n",
+			1 + spaces, ' ', (void *) ip, (void *) ip);
 }
 EXPORT_SYMBOL_GPL(stack_trace_print);
 
@@ -47,13 +50,15 @@ int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,
 			unsigned int nr_entries, int spaces)
 {
 	unsigned int generated, i, total = 0;
+	unsigned long ip;
 
 	if (WARN_ON(!entries))
 		return 0;
 
 	for (i = 0; i < nr_entries && size; i++) {
-		generated = snprintf(buf, size, "%*c%pS\n", 1 + spaces, ' ',
-				     (void *)entries[i]);
+		ip = entries[i];
+		generated = snprintf(buf, size, "%*c[<%px>] %pS\n",
+				     1 + spaces, ' ', (void *) ip, (void *) ip);
 
 		total += generated;
 		if (generated >= size) {
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Haesung Kim

If function is marked as static and compiler decies to lnline function with or without inline keyword, the function has no symbol. We just know symbol located near the address of the inline function by %pS type that shows symbol and offset. But we don't know function name.

What exactly is output in this case today? Can't you get the real addr/symbol from scripts/faddr2line?

Quoted 3 lines

The real address let us extract the function name and location of source code by debugging tools such as addr2line. This is helpful to debug.

Not logging the address was a deliberate decision to minimize leakage of the kernel's VA layout. This undermines that, and I don't think doing so is a good idea.

If there is a problem with faddr2line we should work out how to improve that.

Mark.

Quoted 48 lines
---
 kernel/stacktrace.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/stacktrace.c +8 -3
index 946f44a..b7168c5 100644
@@ -24,12 +24,15 @@ void stack_trace_print(const unsigned long *entries, unsigned int nr_entries,
 		       int spaces)
 {
 	unsigned int i;
+	unsigned long ip;
 
 	if (WARN_ON(!entries))
 		return;
 
 	for (i = 0; i < nr_entries; i++)
-		printk("%*c%pS\n", 1 + spaces, ' ', (void *)entries[i]);
+		ip = entries[i];
+		printk("%*c[<%px>] %pS\n",
+			1 + spaces, ' ', (void *) ip, (void *) ip);
 }
 EXPORT_SYMBOL_GPL(stack_trace_print);
 
@@ -47,13 +50,15 @@ int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,
 			unsigned int nr_entries, int spaces)
 {
 	unsigned int generated, i, total = 0;
+	unsigned long ip;
 
 	if (WARN_ON(!entries))
 		return 0;
 
 	for (i = 0; i < nr_entries && size; i++) {
-		generated = snprintf(buf, size, "%*c%pS\n", 1 + spaces, ' ',
-				     (void *)entries[i]);
+		ip = entries[i];
+		generated = snprintf(buf, size, "%*c[<%px>] %pS\n",
+				     1 + spaces, ' ', (void *) ip, (void *) ip);
 
 		total += generated;
 		if (generated >= size) {
Signature · 1 line
2.7.4