[gdb/tdep] Add amd64/i386 epilogue override unwinders

For amd64 the current frame-unwinders are:
...
$ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
The target architecture is set to "i386:x86-64".
dummy                   DUMMY_FRAME
dwarf2 tailcall         TAILCALL_FRAME
inline                  INLINE_FRAME
python                  NORMAL_FRAME
amd64 epilogue          NORMAL_FRAME
dwarf2                  NORMAL_FRAME
dwarf2 signal           SIGTRAMP_FRAME
amd64 sigtramp          SIGTRAMP_FRAME
amd64 prologue          NORMAL_FRAME
...

For a -g0 -fasynchronous-unwind-tables exec (without .debug_info but with
.eh_frame section), we'd like to start using the dwarf2 unwinder instead of
the "amd64 epilogue" unwinder, by returning true in
compunit_epilogue_unwind_valid for cust == nullptr.

But we'd run into the following problem for a -g0
-fno-asynchronous-unwind-tables (without .debug_info and .eh_frame section)
exec:
- the "amd64 epilogue" unwinder would not run
  (because compunit_epilogue_unwind_valid () == true)
- the dwarf2 unwinder would also not run
  (because there's no .eh_frame info).

Fix this by:
- renaming the "amd64 epilogue" unwinder to "amd64 epilogue override", and
- adding a fallback "amd64 epilogue" after the dwarf unwinders,
while making sure that only one of the two is active.  Likewise for i386.  NFC.

For amd64, this results in this change:
...
 $ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
 The target architecture is set to "i386:x86-64".
 dummy                   DUMMY_FRAME
 dwarf2 tailcall         TAILCALL_FRAME
 inline                  INLINE_FRAME
 python                  NORMAL_FRAME
-amd64 epilogue          NORMAL_FRAME
+amd64 epilogue override NORMAL_FRAME
 dwarf2                  NORMAL_FRAME
 dwarf2 signal           SIGTRAMP_FRAME
+amd64 epilogue          NORMAL_FRAME
 amd64 sigtramp          SIGTRAMP_FRAME
 amd64 prologue          NORMAL_FRAME
...

And for i386:
...
 $ gdb -q -batch -ex "set arch i386" -ex "maint info frame-unwinders"
 The target architecture is set to "i386".
 dummy                   DUMMY_FRAME
 dwarf2 tailcall         TAILCALL_FRAME
 iline                  INLINE_FRAME
-i386 epilogue           NORMAL_FRAME
+i386 epilogue override  NORMAL_FRAME
 dwarf2                  NORMAL_FRAME
 dwarf2 signal           SIGTRAMP_FRAME
+i386 epilogue           NORMAL_FRAME
 i386 stack tramp        NORMAL_FRAME
 i386 sigtramp           SIGTRAMP_FRAME
 i386 prologue           NORMAL_FRAME
...
This commit is contained in:
Tom de Vries
2023-02-20 12:20:14 +01:00
parent 2f9f989c2b
commit 5aca7eaa2b
2 changed files with 103 additions and 14 deletions

View File

@ -2913,9 +2913,9 @@ amd64_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
}
static int
amd64_epilogue_frame_sniffer (const struct frame_unwind *self,
frame_info_ptr this_frame,
void **this_prologue_cache)
amd64_epilogue_frame_sniffer_1 (const struct frame_unwind *self,
frame_info_ptr this_frame,
void **this_prologue_cache, bool override_p)
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
CORE_ADDR pc = get_frame_pc (this_frame);
@ -2924,14 +2924,45 @@ amd64_epilogue_frame_sniffer (const struct frame_unwind *self,
/* We're not in the inner frame, so assume we're not in an epilogue. */
return 0;
if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc)))
/* Don't override the symtab unwinders. */
return 0;
bool unwind_valid_p
= compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc));
if (override_p)
{
if (unwind_valid_p)
/* Don't override the symtab unwinders, skip
"amd64 epilogue override". */
return 0;
}
else
{
if (!unwind_valid_p)
/* "amd64 epilogue override" unwinder already ran, skip
"amd64 epilogue". */
return 0;
}
/* Check whether we're in an epilogue. */
return amd64_stack_frame_destroyed_p (gdbarch, pc);
}
static int
amd64_epilogue_override_frame_sniffer (const struct frame_unwind *self,
frame_info_ptr this_frame,
void **this_prologue_cache)
{
return amd64_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache,
true);
}
static int
amd64_epilogue_frame_sniffer (const struct frame_unwind *self,
frame_info_ptr this_frame,
void **this_prologue_cache)
{
return amd64_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache,
false);
}
static struct amd64_frame_cache *
amd64_epilogue_frame_cache (frame_info_ptr this_frame, void **this_cache)
{
@ -3000,6 +3031,17 @@ amd64_epilogue_frame_this_id (frame_info_ptr this_frame,
(*this_id) = frame_id_build (cache->base + 16, cache->pc);
}
static const struct frame_unwind amd64_epilogue_override_frame_unwind =
{
"amd64 epilogue override",
NORMAL_FRAME,
amd64_epilogue_frame_unwind_stop_reason,
amd64_epilogue_frame_this_id,
amd64_frame_prev_register,
NULL,
amd64_epilogue_override_frame_sniffer
};
static const struct frame_unwind amd64_epilogue_frame_unwind =
{
"amd64 epilogue",
@ -3257,7 +3299,9 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
/* Hook the function epilogue frame unwinder. This unwinder is
appended to the list first, so that it supercedes the other
unwinders in function epilogues. */
frame_unwind_prepend_unwinder (gdbarch, &amd64_epilogue_frame_unwind);
frame_unwind_prepend_unwinder (gdbarch, &amd64_epilogue_override_frame_unwind);
frame_unwind_append_unwinder (gdbarch, &amd64_epilogue_frame_unwind);
/* Hook the prologue-based frame unwinders. */
frame_unwind_append_unwinder (gdbarch, &amd64_sigtramp_frame_unwind);