This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH/SPARC] Use the same frame cache for 32-bit and 64-bit code
- From: Mark Kettenis <kettenis at chello dot nl>
- To: gdb-patches at sources dot redhat dot com
- Date: Mon, 22 Dec 2003 00:14:03 +0100 (CET)
- Subject: [PATCH/SPARC] Use the same frame cache for 32-bit and 64-bit code
This makes it possible to use the same prologue analyzer on SPARC and
UltraSPARC. As a result it gets rid of some duplicated code.
Committed on the SPARC branch.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* sparc-tdep.h (struct sparc_frame_cache): Rename from `struct
sparc32_frame_cache'.
(sparc_analyze_prologue, sparc_frame_cache): New prototypes.
(sparc32_frame_cache): Adjust prototype.
* sparc-tdep.c (sparc_alloc_frame_cache): Rename from
sparc32_alloc_frame_cache. Use `struct sparc_frame_cache' instead
of `struct sparc32_frame_cache'.
(sparc_analyze_prologue): Rename from sparc32_analyze_prologue.
Use `struct sparc_frame_cache' instead of `struct
sparc32_frame_cache'.
(sparc32_skip_prologue): Use `struct sparc_frame_cache' instead of
`struct sparc32_frame_cache'. Call sparc_analyze_prologue instead
of sparc32_analyze_prologue.
(sparc_frame_cache): New function with generic code from...
(sparc32_frame_cache): ...here.
(sparc32_frame_this_id, sparc32_frame_prev_register)
(sparc32_frame_base_address): Use `struct sparc_frame_cache'
instead of `struct sparc32_frame_cache'.
* sparc-sol2-tdep.c (sparc32_sol2_sigtramp_frame_cache)
(sparc32_sol2_sigtramp_frame_this_id)
(sparc32_sol2_sigtramp_frame_prev_register): Change return type to
`struct sparc_frame_cache *'.
* sparc-linux-tdep.c (sparc32_linux_sigtramp_frame_cache)
(sparc32_linux_sigtramp_frame_this_id)
(sparc32_linux_sigtramp_frame_prev_register): Change return type
to `struct sparc_frame_cache *'.
* sparc64-tdep.c (X_OP, X_RD, X_A, X_COND, X_OP2, X_IMM22, X_OP3)
(X_I, X_DISP22, X_DISP19): Remove macros.
(struct sparc64_frame_cache): Remove.
(sparc64_alloc_frame_cache, sparc64_analyze_prologue): Remove
functions.
(sparc64_skip_prologue): Use `struct sparc_frame_cache' instead of
`struct sparc64_frame_cache. Call sparc_analyze_prologue instead
of sparc64_analuze_prologue.
(sparc64_frame_this_id, sparc64_frame_prev_register,
sparc64_frame_base_address): Use `struct sparc_frame_cache'
instead of `struct sparc64_frame_cache.
(sparc64_frame_cache): Change return type to `struct
sparc_frame_cache *'. Simply call sparc_frame_cache.
Index: sparc-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/Attic/sparc-linux-tdep.c,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 sparc-linux-tdep.c
--- sparc-linux-tdep.c 15 Nov 2003 18:18:02 -0000 1.1.2.5
+++ sparc-linux-tdep.c 21 Dec 2003 23:13:01 -0000
@@ -149,11 +149,11 @@ sparc32_linux_pc_in_sigtramp (CORE_ADDR
|| strcmp ("__restore_rt", name) == 0);
}
-static struct sparc32_frame_cache *
+static struct sparc_frame_cache *
sparc32_linux_sigtramp_frame_cache (struct frame_info *next_frame,
void **this_cache)
{
- struct sparc32_frame_cache *cache;
+ struct sparc_frame_cache *cache;
CORE_ADDR sigcontext_addr, addr;
int regnum;
@@ -208,7 +208,7 @@ sparc32_linux_sigtramp_frame_this_id (st
void **this_cache,
struct frame_id *this_id)
{
- struct sparc32_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc32_linux_sigtramp_frame_cache (next_frame, this_cache);
(*this_id) = frame_id_build (cache->base, cache->pc);
@@ -222,7 +222,7 @@ sparc32_linux_sigtramp_frame_prev_regist
CORE_ADDR *addrp,
int *realnump, void *valuep)
{
- struct sparc32_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc32_linux_sigtramp_frame_cache (next_frame, this_cache);
trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
Index: sparc-sol2-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/Attic/sparc-sol2-tdep.c,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 sparc-sol2-tdep.c
--- sparc-sol2-tdep.c 7 Nov 2003 21:46:10 -0000 1.1.2.3
+++ sparc-sol2-tdep.c 21 Dec 2003 23:13:01 -0000
@@ -56,11 +56,11 @@ sparc_sol2_pc_in_sigtramp (CORE_ADDR pc,
return (name && strcmp (name, "sigacthandler") == 0);
}
-static struct sparc32_frame_cache *
+static struct sparc_frame_cache *
sparc32_sol2_sigtramp_frame_cache (struct frame_info *next_frame,
void **this_cache)
{
- struct sparc32_frame_cache *cache;
+ struct sparc_frame_cache *cache;
CORE_ADDR mcontext_addr, addr;
int regnum;
@@ -106,7 +106,7 @@ sparc32_sol2_sigtramp_frame_this_id (str
void **this_cache,
struct frame_id *this_id)
{
- struct sparc32_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc32_sol2_sigtramp_frame_cache (next_frame, this_cache);
(*this_id) = frame_id_build (cache->base, cache->pc);
@@ -120,7 +120,7 @@ sparc32_sol2_sigtramp_frame_prev_registe
CORE_ADDR *addrp,
int *realnump, void *valuep)
{
- struct sparc32_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc32_sol2_sigtramp_frame_cache (next_frame, this_cache);
trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
Index: sparc-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc-tdep.c,v
retrieving revision 1.127.2.8
diff -u -p -r1.127.2.8 sparc-tdep.c
--- sparc-tdep.c 15 Dec 2003 20:41:41 -0000 1.127.2.8
+++ sparc-tdep.c 21 Dec 2003 23:13:01 -0000
@@ -437,13 +437,13 @@ sparc_breakpoint_from_pc (CORE_ADDR *pc,
/* Allocate and initialize a frame cache. */
-static struct sparc32_frame_cache *
-sparc32_alloc_frame_cache (void)
+static struct sparc_frame_cache *
+sparc_alloc_frame_cache (void)
{
- struct sparc32_frame_cache *cache;
+ struct sparc_frame_cache *cache;
int i;
- cache = FRAME_OBSTACK_ZALLOC (struct sparc32_frame_cache);
+ cache = FRAME_OBSTACK_ZALLOC (struct sparc_frame_cache);
/* Base address. */
cache->base = 0;
@@ -457,9 +457,9 @@ sparc32_alloc_frame_cache (void)
return cache;
}
-static CORE_ADDR
-sparc32_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
- struct sparc32_frame_cache *cache)
+CORE_ADDR
+sparc_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
+ struct sparc_frame_cache *cache)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
unsigned long insn;
@@ -527,7 +527,7 @@ sparc32_skip_prologue (CORE_ADDR start_p
{
struct symtab_and_line sal;
CORE_ADDR func_start, func_end;
- struct sparc32_frame_cache cache;
+ struct sparc_frame_cache cache;
/* This is the preferred method, find the end of the prologue by
using the debugging information. */
@@ -540,21 +540,20 @@ sparc32_skip_prologue (CORE_ADDR start_p
return sal.end;
}
- return sparc32_analyze_prologue (start_pc, 0xffffffffUL, &cache);
+ return sparc_analyze_prologue (start_pc, 0xffffffffUL, &cache);
}
/* Normal frames. */
-struct sparc32_frame_cache *
-sparc32_frame_cache (struct frame_info *next_frame, void **this_cache)
+struct sparc_frame_cache *
+sparc_frame_cache (struct frame_info *next_frame, void **this_cache)
{
- struct sparc32_frame_cache *cache;
- struct symbol *sym;
+ struct sparc_frame_cache *cache;
if (*this_cache)
return *this_cache;
- cache = sparc32_alloc_frame_cache ();
+ cache = sparc_alloc_frame_cache ();
*this_cache = cache;
/* In priciple, for normal frames, %fp (%i6) holds the frame
@@ -569,7 +568,7 @@ sparc32_frame_cache (struct frame_info *
if (cache->pc != 0)
{
CORE_ADDR addr_in_block = frame_unwind_address_in_block (next_frame);
- sparc32_analyze_prologue (cache->pc, addr_in_block, cache);
+ sparc_analyze_prologue (cache->pc, addr_in_block, cache);
}
if (cache->frameless_p)
@@ -580,6 +579,20 @@ sparc32_frame_cache (struct frame_info *
SPARC_SP_REGNUM);
}
+ return cache;
+}
+
+struct sparc_frame_cache *
+sparc32_frame_cache (struct frame_info *next_frame, void **this_cache)
+{
+ struct sparc_frame_cache *cache;
+ struct symbol *sym;
+
+ if (*this_cache)
+ return *this_cache;
+
+ cache = sparc_frame_cache (next_frame, this_cache);
+
sym = find_pc_function (cache->pc);
if (sym)
{
@@ -602,7 +615,7 @@ static void
sparc32_frame_this_id (struct frame_info *next_frame, void **this_cache,
struct frame_id *this_id)
{
- struct sparc32_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc32_frame_cache (next_frame, this_cache);
/* This marks the outermost frame. */
@@ -618,7 +631,7 @@ sparc32_frame_prev_register (struct fram
enum lval_type *lvalp, CORE_ADDR *addrp,
int *realnump, void *valuep)
{
- struct sparc32_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc32_frame_cache (next_frame, this_cache);
if (regnum == SPARC32_PC_REGNUM || regnum == SPARC32_NPC_REGNUM)
@@ -690,7 +703,7 @@ sparc32_frame_sniffer (struct frame_info
static CORE_ADDR
sparc32_frame_base_address (struct frame_info *next_frame, void **this_cache)
{
- struct sparc32_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc32_frame_cache (next_frame, this_cache);
return cache->base;
Index: sparc-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/sparc-tdep.h,v
retrieving revision 1.3.10.6
diff -u -p -r1.3.10.6 sparc-tdep.h
--- sparc-tdep.h 16 Nov 2003 10:19:38 -0000 1.3.10.6
+++ sparc-tdep.h 21 Dec 2003 23:13:01 -0000
@@ -120,7 +120,7 @@ enum sparc32_regnum
};
-struct sparc32_frame_cache
+struct sparc_frame_cache
{
/* Base address. */
CORE_ADDR base;
@@ -136,7 +136,13 @@ struct sparc32_frame_cache
struct trad_frame_saved_reg *saved_regs;
};
-extern struct sparc32_frame_cache *
+extern CORE_ADDR sparc_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
+ struct sparc_frame_cache *cache);
+
+extern struct sparc_frame_cache *
+ sparc_frame_cache (struct frame_info *next_frame, void **this_cache);
+
+extern struct sparc_frame_cache *
sparc32_frame_cache (struct frame_info *next_frame, void **this_cache);
Index: sparc64-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc64-tdep.c,v
retrieving revision 1.3.4.3
diff -u -p -r1.3.4.3 sparc64-tdep.c
--- sparc64-tdep.c 15 Dec 2003 20:41:41 -0000 1.3.4.3
+++ sparc64-tdep.c 21 Dec 2003 23:13:01 -0000
@@ -495,91 +495,6 @@ sparc64_pseudo_register_write (struct gd
}
-struct sparc64_frame_cache
-{
- /* Base address. */
- CORE_ADDR base;
- CORE_ADDR pc;
-
- /* Do we have a frame? */
- int frameless_p;
-};
-
-/* Allocate and initialize a frame cache. */
-
-static struct sparc64_frame_cache *
-sparc64_alloc_frame_cache (void)
-{
- struct sparc64_frame_cache *cache;
- int i;
-
- cache = FRAME_OBSTACK_ZALLOC (struct sparc64_frame_cache);
-
- /* Base address. */
- cache->base = 0;
- cache->pc = 0;
-
- /* Frameless until proven otherwise. */
- cache->frameless_p = 1;
-
- return cache;
-}
-
-static CORE_ADDR
-sparc64_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
- struct sparc64_frame_cache *cache)
-{
- struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
- unsigned long insn;
- int offset = 0;
- int dest = -1;
-
- if (current_pc <= pc)
- return current_pc;
-
- /* We have to handle to "Procedure Linkage Table" (PLT) special. On
- SPARC the linker usually defines a symbol (typically
- _PROCEDURE_LINKAGE_TABLE_) at the start of the .plt section.
- This symbol makes us end up here with PC pointing at the start of
- the PLT and CURRENT_PC probably pointing at a PLT entry. If we
- would do our normal prologue analysis, we would probably conclude
- that we've got a frame when in reality we don't, since the
- dynamic linker patches up the first PLT with some code that
- starts with a SAVE instruction. Patch up PC such that it points
- at the start of our PLT entry. */
- if (tdep->plt_entry_size > 0 && in_plt_section (current_pc, NULL))
- pc = current_pc - ((current_pc - pc) % tdep->plt_entry_size);
-
- insn = sparc_fetch_instruction (pc);
-
- /* Recognize a SETHI insn and record its destination. */
- if (X_OP (insn) == 0 && X_OP2 (insn) == 0x04)
- {
- dest = X_RD (insn);
- offset += 4;
-
- insn = sparc_fetch_instruction (pc + 4);
- }
-
- /* Allow for an arithmetic operation on DEST or %g1. */
- if (X_OP (insn) == 2 && X_I (insn)
- && (X_RD (insn) == 1 || X_RD (insn) == dest))
- {
- offset += 4;
-
- insn = sparc_fetch_instruction (pc + 8);
- }
-
- /* Check for the SAVE instruction that sets up the frame. */
- if (X_OP (insn) == 2 && X_OP3 (insn) == 0x3c)
- {
- cache->frameless_p = 0;
- return pc + offset + 4;
- }
-
- return pc;
-}
-
/* Return PC of first real instruction of the function starting at
START_PC. */
@@ -588,7 +503,7 @@ sparc64_skip_prologue (CORE_ADDR start_p
{
struct symtab_and_line sal;
CORE_ADDR func_start, func_end;
- struct sparc64_frame_cache cache;
+ struct sparc_frame_cache cache;
/* This is the preferred method, find the end of the prologue by
using the debugging information. */
@@ -601,53 +516,22 @@ sparc64_skip_prologue (CORE_ADDR start_p
return sal.end;
}
- return sparc64_analyze_prologue (start_pc, 0xffffffffffffffffUL, &cache);
+ return sparc_analyze_prologue (start_pc, 0xffffffffffffffffUL, &cache);
}
/* Normal frames. */
-static struct sparc64_frame_cache *
+static struct sparc_frame_cache *
sparc64_frame_cache (struct frame_info *next_frame, void **this_cache)
{
- struct sparc64_frame_cache *cache;
-
- if (*this_cache)
- return *this_cache;
-
- cache = sparc64_alloc_frame_cache ();
- *this_cache = cache;
-
- /* In priciple, for normal frames, %fp (%i6) holds the frame
- pointer, which holds the base address for the current stack
- frame. */
-
- cache->base = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
- if (cache->base == 0)
- return cache;
-
- cache->pc = frame_func_unwind (next_frame);
- if (cache->pc != 0)
- {
- CORE_ADDR addr_in_block = frame_unwind_address_in_block (next_frame);
- sparc64_analyze_prologue (cache->pc, addr_in_block, cache);
- }
-
- if (cache->frameless_p)
- {
- /* We didn't find a valid frame, which means that CACHE->base
- currently holds the frame pointer for our calling frame. */
- cache->base = frame_unwind_register_unsigned (next_frame,
- SPARC_SP_REGNUM);
- }
-
- return cache;
+ return sparc_frame_cache (next_frame, this_cache);
}
static void
sparc64_frame_this_id (struct frame_info *next_frame, void **this_cache,
struct frame_id *this_id)
{
- struct sparc64_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc64_frame_cache (next_frame, this_cache);
/* This marks the outermost frame. */
@@ -663,7 +547,7 @@ sparc64_frame_prev_register (struct fram
enum lval_type *lvalp, CORE_ADDR *addrp,
int *realnump, void *valuep)
{
- struct sparc64_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc64_frame_cache (next_frame, this_cache);
if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
@@ -729,7 +613,7 @@ sparc64_frame_sniffer (struct frame_info
static CORE_ADDR
sparc64_frame_base_address (struct frame_info *next_frame, void **this_cache)
{
- struct sparc64_frame_cache *cache =
+ struct sparc_frame_cache *cache =
sparc64_frame_cache (next_frame, this_cache);
/* ??? Should we take BIAS into account here? */