@@ -147,12 +147,10 @@ static const gdb_byte amd64_x32_linux_sigtramp_code[] =
the routine. Otherwise, return 0. */
static CORE_ADDR
-amd64_linux_sigtramp_start (const frame_info_ptr &this_frame)
+amd64_linux_sigtramp_start (gdbarch *gdbarch, CORE_ADDR pc)
{
- struct gdbarch *gdbarch;
const gdb_byte *sigtramp_code;
- CORE_ADDR pc = get_frame_pc (this_frame);
- gdb_byte buf[LINUX_SIGTRAMP_LEN];
+ std::array<gdb_byte, LINUX_SIGTRAMP_LEN> buf {};
/* We only recognize a signal trampoline if PC is at the start of
one of the two instructions. We optimize for finding the PC at
@@ -161,7 +159,7 @@ amd64_linux_sigtramp_start (const frame_info_ptr &this_frame)
PC is not at the start of the instruction sequence, there will be
a few trailing readable bytes on the stack. */
- if (!safe_frame_unwind_memory (this_frame, pc, buf))
+ if (target_read_memory (pc, buf.data (), buf.size ()) != 0)
return 0;
if (buf[0] != LINUX_SIGTRAMP_INSN0)
@@ -170,28 +168,25 @@ amd64_linux_sigtramp_start (const frame_info_ptr &this_frame)
return 0;
pc -= LINUX_SIGTRAMP_OFFSET1;
- if (!safe_frame_unwind_memory (this_frame, pc, buf))
+ if (target_read_memory (pc, buf.data (), buf.size ()) != 0)
return 0;
}
- gdbarch = get_frame_arch (this_frame);
if (gdbarch_ptr_bit (gdbarch) == 32)
sigtramp_code = amd64_x32_linux_sigtramp_code;
else
sigtramp_code = amd64_linux_sigtramp_code;
- if (memcmp (buf, sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
+ if (memcmp (buf.data (), sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
return 0;
return pc;
}
-/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
- routine. */
+/* Return whether PC is pointing to a GNU/Linux sigtramp routine. */
static int
-amd64_linux_sigtramp_p (const frame_info_ptr &this_frame)
+amd64_linux_is_sigtramp_pc (gdbarch* gdbarch, const CORE_ADDR pc)
{
- CORE_ADDR pc = get_frame_pc (this_frame);
const char *name;
find_pc_partial_function (pc, &name, NULL, NULL);
@@ -203,11 +198,22 @@ amd64_linux_sigtramp_p (const frame_info_ptr &this_frame)
__sigaction, or __libc_sigaction (all aliases to the same
function). */
if (name == NULL || strstr (name, "sigaction") != NULL)
- return (amd64_linux_sigtramp_start (this_frame) != 0);
+ return (amd64_linux_sigtramp_start (gdbarch, pc) != 0);
return (streq ("__restore_rt", name));
}
+/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
+ routine. */
+
+static int
+amd64_linux_sigtramp_frame_p (const frame_info_ptr &this_frame)
+{
+ gdbarch *gdbarch = get_frame_arch (this_frame);
+ CORE_ADDR pc = get_frame_pc (this_frame);
+ return amd64_linux_is_sigtramp_pc (gdbarch, pc);
+}
+
/* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
#define AMD64_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 40
@@ -2026,7 +2032,7 @@ amd64_linux_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch,
linux_init_abi (info, gdbarch, num_disp_step_buffers);
- tdep->sigtramp_p = amd64_linux_sigtramp_p;
+ tdep->sigtramp_p = amd64_linux_sigtramp_frame_p;
tdep->sigcontext_addr = amd64_linux_sigcontext_addr;
tdep->sc_reg_offset = amd64_linux_sc_reg_offset;
tdep->sc_num_regs = ARRAY_SIZE (amd64_linux_sc_reg_offset);
@@ -2084,6 +2090,8 @@ amd64_linux_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch,
set_gdbarch_is_no_return_shadow_stack_address
(gdbarch, amd64_linux_is_no_return_shadow_stack_address);
+
+ set_gdbarch_is_sigtramp_pc (gdbarch, amd64_linux_is_sigtramp_pc);
}
static void
@@ -257,6 +257,7 @@ struct gdbarch
gdbarch_top_addr_empty_shadow_stack_ftype *top_addr_empty_shadow_stack = nullptr;
int shadow_stack_element_size_aligned = 8;
gdbarch_is_no_return_shadow_stack_address_ftype *is_no_return_shadow_stack_address = nullptr;
+ gdbarch_is_sigtramp_pc_ftype *is_sigtramp_pc = nullptr;
};
/* Create a new ``struct gdbarch'' based on information provided by
@@ -521,6 +522,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of top_addr_empty_shadow_stack, has predicate. */
/* Skip verify of shadow_stack_element_size_aligned, invalid_p == 0. */
/* Skip verify of is_no_return_shadow_stack_address, has predicate. */
+ /* Skip verify of is_sigtramp_pc, has predicate. */
if (!log.empty ())
internal_error (_("verify_gdbarch: the following are invalid ...%s"),
log.c_str ());
@@ -1365,6 +1367,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
gdb_printf (file,
"gdbarch_dump: is_no_return_shadow_stack_address = <%s>\n",
host_address_to_string (gdbarch->is_no_return_shadow_stack_address));
+ gdb_printf (file,
+ "gdbarch_dump: gdbarch_is_sigtramp_pc_p() = %d\n",
+ gdbarch_is_sigtramp_pc_p (gdbarch));
+ gdb_printf (file,
+ "gdbarch_dump: is_sigtramp_pc = <%s>\n",
+ host_address_to_string (gdbarch->is_sigtramp_pc));
if (gdbarch->dump_tdep != nullptr)
gdbarch->dump_tdep (gdbarch, file);
}
@@ -5394,3 +5402,27 @@ set_gdbarch_is_no_return_shadow_stack_address (struct gdbarch *gdbarch,
{
gdbarch->is_no_return_shadow_stack_address = is_no_return_shadow_stack_address;
}
+
+bool
+gdbarch_is_sigtramp_pc_p (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != nullptr);
+ return gdbarch->is_sigtramp_pc != nullptr;
+}
+
+int
+gdbarch_is_sigtramp_pc (struct gdbarch *gdbarch, const CORE_ADDR pc)
+{
+ gdb_assert (gdbarch != nullptr);
+ gdb_assert (gdbarch->is_sigtramp_pc != nullptr);
+ if (gdbarch_debug >= 2)
+ gdb_printf (gdb_stdlog, "gdbarch_is_sigtramp_pc called\n");
+ return gdbarch->is_sigtramp_pc (gdbarch, pc);
+}
+
+void
+set_gdbarch_is_sigtramp_pc (struct gdbarch *gdbarch,
+ gdbarch_is_sigtramp_pc_ftype is_sigtramp_pc)
+{
+ gdbarch->is_sigtramp_pc = is_sigtramp_pc;
+}
@@ -1814,3 +1814,14 @@ bool gdbarch_is_no_return_shadow_stack_address_p (struct gdbarch *gdbarch);
using gdbarch_is_no_return_shadow_stack_address_ftype = std::optional<shadow_stack_frame_info> (struct gdbarch *gdbarch, const CORE_ADDR ssp, const CORE_ADDR value, const unsigned long level);
std::optional<shadow_stack_frame_info> gdbarch_is_no_return_shadow_stack_address (struct gdbarch *gdbarch, const CORE_ADDR ssp, const CORE_ADDR value, const unsigned long level);
void set_gdbarch_is_no_return_shadow_stack_address (struct gdbarch *gdbarch, gdbarch_is_no_return_shadow_stack_address_ftype *is_no_return_shadow_stack_address);
+
+/* Return whether PC is pointing to a sigtramp routine. This is needed in
+ addition to tdep->sigtramp_p, which requires a frame, because some callers
+ (e.g. the shadow stack backtrace command) only have a return address
+ available. */
+
+bool gdbarch_is_sigtramp_pc_p (struct gdbarch *gdbarch);
+
+using gdbarch_is_sigtramp_pc_ftype = int (struct gdbarch *gdbarch, const CORE_ADDR pc);
+int gdbarch_is_sigtramp_pc (struct gdbarch *gdbarch, const CORE_ADDR pc);
+void set_gdbarch_is_sigtramp_pc (struct gdbarch *gdbarch, gdbarch_is_sigtramp_pc_ftype *is_sigtramp_pc);
@@ -2872,3 +2872,16 @@ backtrace. Otherwise, return an empty optional.
],
predicate=True,
)
+
+Method(
+ comment="""
+Return whether PC is pointing to a sigtramp routine. This is needed in
+addition to tdep->sigtramp_p, which requires a frame, because some callers
+(e.g. the shadow stack backtrace command) only have a return address
+available.
+""",
+ type="int",
+ name="is_sigtramp_pc",
+ params=[("const CORE_ADDR", "pc")],
+ predicate=True,
+)
@@ -267,6 +267,8 @@ do_print_shadow_stack_frame_info
}
else if (frame.type == ssp_frame_type::dummy_frame)
str = "<function called from gdb>";
+ else if (frame.type == ssp_frame_type::sigtramp_frame)
+ str = "<signal handler called>";
else
gdb_assert_not_reached ("Invalid shadow stack frame type.");
@@ -480,6 +482,15 @@ get_shadow_stack_frame_info
if (sal_arch == nullptr)
sal_arch = fallback_arch;
+ if (gdbarch_is_sigtramp_pc_p (sal_arch)
+ && gdbarch_is_sigtramp_pc (sal_arch, value))
+ {
+ return std::optional<shadow_stack_frame_info>
+ ({ssp, value, level, sal_arch, sal,
+ ssp_frame_type::sigtramp_frame, {},
+ ssp_unwind_stop_reason::no_error});
+ }
+
return std::optional<shadow_stack_frame_info>
({ssp, value, level, sal_arch, sal,
ssp_frame_type::normal_frame, {},
@@ -80,6 +80,11 @@ enum class ssp_frame_type
/* A fake frame, created by GDB when performing an inferior function
call. */
dummy_frame,
+
+ /* A shadow stack frame containing a return address which is in a signal
+ handler, similar to the SIGTRAMP_FRAME frame type in
+ frame.h:frame_type. */
+ sigtramp_frame,
};
/* Information of a shadow stack frame belonging to a shadow stack element
@@ -41,7 +41,7 @@ save_vars { ::env(GLIBC_TUNABLES) } {
# Test shadow stack backtrace including <sigframe token>.
gdb_test "bt -shadow" \
[multi_line \
- "#0\[ \t\]*$hex in \[^\r\n\]+" \
+ "#0\[ \t\]*<signal handler called>" \
"#1\[ \t\]*<sigframe token>" \
"#2\[ \t\]*$hex in \[^\r\n\]+" \
".*" ] \