From 434ffe7d9d428d375626f00ae610cbd09da8d6ce Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Thu, 14 Feb 2008 00:24:24 +0000 Subject: [PATCH] Fix incomplete stack traces by gdb. Gdb tries unwinding a stack frame by analyzing the function prologue. If it can not find the beginning of the function, which happens for stripped binaries, etc., it will resort to guessing. It then assumes that the function is a frame-less function without any local stack variables. This of course is wrong for almost all functions. We work around this problem by assuming a valid stack frame. Previous versions of gdb were broken the same way, but libbfd would actually compensate with another bug which would simply report a wrong function start address -- the address of a preceding, known function. Because most functions indeed use a proper stack frame, this would trick gdb into doing the unwinding properly. --- contrib/gdb-6/gdb/i386-tdep.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contrib/gdb-6/gdb/i386-tdep.c b/contrib/gdb-6/gdb/i386-tdep.c index 1831db0f26..fe057df3b4 100644 --- a/contrib/gdb-6/gdb/i386-tdep.c +++ b/contrib/gdb-6/gdb/i386-tdep.c @@ -979,6 +979,16 @@ i386_frame_cache (struct frame_info *next_frame, void **this_cache) /* This will be added back below. */ cache->saved_regs[I386_EIP_REGNUM] -= cache->base; } + else if (cache->pc == 0) + { + /* We're in a function without proper pc. This + happens if the binary was stripped and we couldn't + find the beginning of the function. + We'll just assume that it is a framed function. */ + + cache->saved_regs[I386_EBP_REGNUM] = 0; + cache->sp_offset += 4; + } else { frame_unwind_register (next_frame, I386_ESP_REGNUM, buf); -- 2.41.0