Skip to content

Commit

Permalink
Stop stack unwinding at non-kernel address
Browse files Browse the repository at this point in the history
The stack unwinding is for kernel addresses only. If non-kernel address
encountered, it is usually a user space address, or non-address value
like a function call parameter. So stopping stack unwinding at non-kernel
address will decrease the invalid unwind results.

Before:
crash> gdb bt
 #0  0xffffffff816a8f65 in context_switch ...
 crash-utility#1  __schedule () ...
 crash-utility#2  0xffffffff816a94e9 in schedule ...
 crash-utility#3  0xffffffff816a86fd in schedule_hrtimeout_range_clock ...
 crash-utility#4  0xffffffff816a8733 in schedule_hrtimeout_range ...
 crash-utility#5  0xffffffff8124bb7e in ep_poll ...
 crash-utility#6  0xffffffff8124d00d in SYSC_epoll_wait ...
 crash-utility#7  SyS_epoll_wait ...
 crash-utility#8  <signal handler called>
 crash-utility#9  0x00007f0449407923 in ?? ()
 crash-utility#10 0xffff880100000001 in ?? ()
 crash-utility#11 0xffff880169b3c010 in ?? ()
 crash-utility#12 0x0000000000000040 in irq_stack_union ()
 crash-utility#13 0xffff880169b3c058 in ?? ()
 crash-utility#14 0xffff880169b3c048 in ?? ()
 crash-utility#15 0xffff880169b3c050 in ?? ()
 crash-utility#16 0x0000000000000000 in ?? ()

After:
crash> gdb bt
 #0  0xffffffff816a8f65 in context_switch ...
 crash-utility#1  __schedule () ...
 crash-utility#2  0xffffffff816a94e9 in schedule () ...
 crash-utility#3  0xffffffff816a86fd in schedule_hrtimeout_range_clock ...
 crash-utility#4  0xffffffff816a8733 in schedule_hrtimeout_range ...
 crash-utility#5  0xffffffff8124bb7e in ep_poll ...
 crash-utility#6  0xffffffff8124d00d in SYSC_epoll_wait ...
 crash-utility#7  SyS_epoll_wait ...
 crash-utility#8  <signal handler called>

Cc: Sourabh Jain <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Mahesh J Salgaonkar <[email protected]>
Cc: Naveen N. Rao <[email protected]>
Cc: Lianbo Jiang <[email protected]>
Cc: HAGIO KAZUHITO(萩尾 一仁) <[email protected]>
Cc: Tao Liu <[email protected]>
Cc: Alexey Makhalov <[email protected]>
Signed-off-by: Tao Liu <[email protected]>
  • Loading branch information
liutgnu authored and adi-g15-ibm committed Aug 27, 2024
1 parent 37399e5 commit 1b620a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7933,6 +7933,7 @@ extern unsigned char *gdb_prettyprint_arrays;
extern unsigned int *gdb_repeat_count_threshold;
extern unsigned char *gdb_stop_print_at_null;
extern unsigned int *gdb_output_radix;
int is_kvaddr(ulong);

/*
* gdb/top.c
Expand Down
29 changes: 29 additions & 0 deletions gdb-10.2.patch
Original file line number Diff line number Diff line change
Expand Up @@ -16171,3 +16171,32 @@ exit 0
}

/*
--- gdb-10.2/gdb/stack.c.orig
+++ gdb-10.2/gdb/stack.c
@@ -1990,6 +1990,10 @@
/* Print briefly all stack frames or just the innermost COUNT_EXP
frames. */

+#ifdef CRASH_MERGE
+extern "C" int is_kvaddr(ulong);
+#endif
+
static void
backtrace_command_1 (const frame_print_options &fp_opts,
const backtrace_cmd_options &bt_opts,
@@ -2082,6 +2086,15 @@
hand, perhaps the code does or could be fixed to make sure
the frame->prev field gets set to NULL in that case). */

+#ifdef CRASH_MERGE
+ CORE_ADDR pc = 0;
+ get_frame_pc_if_available (fi, &pc);
+ if (!is_kvaddr(pc)) {
+ printf_filtered (_("Backtrace stopped due to non-kernel addr: %lx\n"),pc);
+ fi = NULL;
+ break;
+ }
+#endif
print_frame_info (fp_opts, fi, 1, LOCATION, 1, 0);
if ((flags & PRINT_LOCALS) != 0)
{
6 changes: 6 additions & 0 deletions gdb_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,12 @@ gdb_lookup_module_symbol(ulong addr, ulong *offset)
}
}

int
is_kvaddr(ulong addr)
{
return IS_KVADDR(addr);
}

/*
* Used by gdb_interface() to catch gdb-related errors, if desired.
*/
Expand Down

0 comments on commit 1b620a8

Please sign in to comment.