From: Anton Kolesov <Anton.Kolesov@synopsys.com>
To: gdb-patches@sourceware.org
Cc: Anton Kolesov <Anton.Kolesov@synopsys.com>,
Francois Bedard <Francois.Bedard@synopsys.com>
Subject: [PATCH 2/3] arc: Add evaluation of long jump targets
Date: Fri, 07 Oct 2016 12:38:00 -0000 [thread overview]
Message-ID: <1475843870-11449-2-git-send-email-Anton.Kolesov@synopsys.com> (raw)
In-Reply-To: <1475843870-11449-1-git-send-email-Anton.Kolesov@synopsys.com>
Standard get_longjmp_target implementation, similar to what is in arm-tdep.c.
Actual value of jb_pc should be set in init_osabi methods of particular OS/ABI
implementations.
gdb/ChangeLog:
* arc-tdep.h (gdbarch_tdep): Add jb_pc.
* arc-tdep.c (arc_get_longjmp_target): New function.
(arc_gdbarch_init): Set get_longjmp_target if jb_pc is non-negative.
(arc_dump_tdep): Print jb_pc.
---
gdb/arc-tdep.c | 36 +++++++++++++++++++++++++++++++++++-
gdb/arc-tdep.h | 3 +++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 58de8e9..bc8bb98 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -557,6 +557,34 @@ arc_store_return_value (struct gdbarch *gdbarch, struct type *type,
error (_("arc_store_return_value: type length too large."));
}
+/* Implement the "get_longjmp_target" gdbarch method.
+
+ Detemine the address the longjmp will jump to. We need to use the frame
+ info to get the register pointing to the jmp_buf, then extract the PC from
+ that. Since jmp_buf is the first argument to longjmp () it will be in r0.
+ Where we then go depends on the OS - OS/ABI initialization should set offset
+ from jmp_buf start to the stored PC location. */
+
+static int
+arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
+{
+ if (arc_debug)
+ debug_printf ("arc: get_longjmp_target\n");
+
+ struct gdbarch *gdbarch = get_frame_arch (frame);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
+ gdb_byte buf[ARC_REGISTER_SIZE];
+ CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
+
+ if (target_read_memory (jb_addr + pc_offset, buf, ARC_REGISTER_SIZE))
+ return 0; /* Failed to read from memory. */
+
+ *pc = extract_unsigned_integer (buf, ARC_REGISTER_SIZE,
+ gdbarch_byte_order (gdbarch));
+ return 1;
+}
+
/* Implement the "return_value" gdbarch method. */
static enum return_value_convention
@@ -1162,6 +1190,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
/* Allocate the ARC-private target-dependent information structure, and the
GDB target-independent information structure. */
struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep);
+ tdep->jb_pc = -1; /* No longjmp support by default. */
struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep);
/* Data types. */
@@ -1246,6 +1275,9 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
It can override functions set earlier. */
gdbarch_init_osabi (info, gdbarch);
+ if (tdep->jb_pc >= 0)
+ set_gdbarch_get_longjmp_target (gdbarch, arc_get_longjmp_target);
+
tdesc_use_registers (gdbarch, tdesc, tdesc_data);
return gdbarch;
@@ -1256,7 +1288,9 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
static void
arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
{
- /* Empty for now. */
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+ fprintf_unfiltered (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
}
/* Suppress warning from -Wmissing-prototypes. */
diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h
index ea34b9e..1e792b9 100644
--- a/gdb/arc-tdep.h
+++ b/gdb/arc-tdep.h
@@ -81,6 +81,9 @@ extern int arc_debug;
struct gdbarch_tdep
{
+ /* Offset to PC value in jump buffer. If this is negative, longjmp
+ support will be disabled. */
+ int jb_pc;
};
/* Utility functions used by other ARC-specific modules. */
--
2.8.1
next prev parent reply other threads:[~2016-10-07 12:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 12:38 [PATCH 1/3] arc: Add a gdbarch_tdep structure Anton Kolesov
2016-10-07 12:38 ` Anton Kolesov [this message]
2016-10-11 16:22 ` [PATCH 2/3] arc: Add evaluation of long jump targets Yao Qi
2016-10-07 12:38 ` [PATCH 3/3] arc: Add support for Newlib Anton Kolesov
2016-10-11 14:14 ` Yao Qi
2016-10-11 15:36 ` Anton Kolesov
2016-10-11 16:25 ` Yao Qi
2016-10-12 11:57 ` Anton Kolesov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475843870-11449-2-git-send-email-Anton.Kolesov@synopsys.com \
--to=anton.kolesov@synopsys.com \
--cc=Francois.Bedard@synopsys.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox