This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch/rfc] Funky INIT_FRAME_PC and INIT_FRAME_PC_FIRST
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 05 Dec 2002 16:29:13 -0500
- Subject: [patch/rfc] Funky INIT_FRAME_PC and INIT_FRAME_PC_FIRST
Hello,
The attached patch converts the two architecture methods:
INIT_FRAME_PC
INIT_FRAME_PC_FIRST
into pure functions (they return the initial PC value). It's part of
the campain to make `struct frame_info' opaque.
I'll commit in a few days (baring comment),
Andrew
2002-12-05 Andrew Cagney <ac131313@redhat.com>
* gdbarch.sh (INIT_FRAME_PC_FIRST, INIT_FRAME_PC_DEFAULT): Convert
to pure functions.
* gdbarch.h, gdbarch.c: Re-generate.
* frame.c (get_prev_frame): Explictly assign prev's pc with value
returned by INIT_FRAME_PC_FIRST and INIT_EXTRA_FRAME_INFO.
* arch-utils.h (init_frame_pc_default, init_frame_pc_noop): Change
declaration to a function returning a CORE_ADDR.
* arch-utils.c (init_frame_pc_noop): Return the PC value.
(init_frame_pc_default): Ditto.
* x86-64-linux-tdep.c (x86_64_init_frame_pc): Ditto.
* s390-tdep.c (s390_init_frame_pc_first): Ditto.
* mips-tdep.c (mips_init_frame_pc_first): Ditto.
* dwarf2cfi.h (cfi_init_frame_pc): Ditto.
* dwarf2cfi.c (cfi_init_frame_pc): Ditto.
* alpha-tdep.c (alpha_init_frame_pc_first): Ditto.
* i386-interix-tdep.c (i386_interix_init_abi): Set init_frame_pc
to init_frame_pc_noop.
(i386_interix_init_frame_pc): Delete function.
* z8k-tdep.c (init_frame_pc): Delete function.
* config/z8k/tm-z8k.h (INIT_FRAME_PC, INIT_FRAME_PC_FIRST): Define
as init_frame_pc_noop.
* config/rs6000/tm-rs6000.h (INIT_FRAME_PC): Redefine as
init_frame_pc_noop.
(INIT_FRAME_PC_FIRST): Convert to an expression.
Index: alpha-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/alpha-tdep.c,v
retrieving revision 1.45
diff -u -r1.45 alpha-tdep.c
--- alpha-tdep.c 1 Dec 2002 19:07:14 -0000 1.45
+++ alpha-tdep.c 5 Dec 2002 21:16:52 -0000
@@ -457,11 +457,12 @@
fi->saved_regs[SP_REGNUM] = fi->frame;
}
-static void
+static CORE_ADDR
alpha_init_frame_pc_first (int fromleaf, struct frame_info *prev)
{
- prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) :
- prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
+ return (fromleaf ? SAVED_PC_AFTER_CALL (get_next_frame (prev))
+ : get_next_frame (prev) ? FRAME_SAVED_PC (prev->next)
+ : read_pc ());
}
static CORE_ADDR
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.71
diff -u -r1.71 arch-utils.c
--- arch-utils.c 25 Nov 2002 04:47:56 -0000 1.71
+++ arch-utils.c 5 Dec 2002 21:16:53 -0000
@@ -373,21 +373,22 @@
}
-void
+CORE_ADDR
init_frame_pc_noop (int fromleaf, struct frame_info *prev)
{
- return;
+ /* Do nothing, implies return the same PC value. */
+ return get_frame_pc (prev);
}
-void
+CORE_ADDR
init_frame_pc_default (int fromleaf, struct frame_info *prev)
{
if (fromleaf)
- prev->pc = SAVED_PC_AFTER_CALL (prev->next);
- else if (prev->next != NULL)
- prev->pc = FRAME_SAVED_PC (prev->next);
+ return SAVED_PC_AFTER_CALL (get_next_frame (prev));
+ else if (get_next_frame (prev) != NULL)
+ return FRAME_SAVED_PC (get_next_frame (prev));
else
- prev->pc = read_pc ();
+ return read_pc ();
}
void
Index: arch-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.h,v
retrieving revision 1.42
diff -u -r1.42 arch-utils.h
--- arch-utils.h 25 Nov 2002 04:47:56 -0000 1.42
+++ arch-utils.h 5 Dec 2002 21:16:53 -0000
@@ -117,9 +117,9 @@
/* Versions of init_frame_pc(). Do nothing; do the default. */
-void init_frame_pc_noop (int fromleaf, struct frame_info *prev);
+extern CORE_ADDR init_frame_pc_noop (int fromleaf, struct frame_info *prev);
-void init_frame_pc_default (int fromleaf, struct frame_info *prev);
+extern CORE_ADDR init_frame_pc_default (int fromleaf, struct frame_info *prev);
/* Do nothing version of elf_make_msymbol_special. */
Index: dwarf2cfi.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
retrieving revision 1.21
diff -u -r1.21 dwarf2cfi.c
--- dwarf2cfi.c 14 Nov 2002 00:25:02 -0000 1.21
+++ dwarf2cfi.c 5 Dec 2002 21:16:53 -0000
@@ -1746,13 +1746,19 @@
}
/* Sets the pc of the frame. */
-void
+CORE_ADDR
cfi_init_frame_pc (int fromleaf, struct frame_info *fi)
{
if (fi->next)
- get_reg ((char *) &(fi->pc), UNWIND_CONTEXT (fi->next), PC_REGNUM);
+ {
+ CORE_ADDR pc;
+ /* FIXME: cagney/2002-12-04: This is straight wrong. It's
+ assuming that the PC is CORE_ADDR (a host quantity) in size. */
+ get_reg (&pc, UNWIND_CONTEXT (fi->next), PC_REGNUM);
+ return pc;
+ }
else
- fi->pc = read_pc ();
+ return read_pc ();
}
/* Initialize unwind context informations of the frame. */
Index: dwarf2cfi.h
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2cfi.h,v
retrieving revision 1.3
diff -u -r1.3 dwarf2cfi.h
--- dwarf2cfi.h 24 Oct 2002 01:37:40 -0000 1.3
+++ dwarf2cfi.h 5 Dec 2002 21:16:53 -0000
@@ -67,7 +67,7 @@
CORE_ADDR cfi_frame_chain (struct frame_info *fi);
/* Sets the pc of the frame. */
-void cfi_init_frame_pc (int fromleaf, struct frame_info *fi);
+CORE_ADDR cfi_init_frame_pc (int fromleaf, struct frame_info *fi);
/* Initialize unwind context informations of the frame. */
void cfi_init_extra_frame_info (int fromleaf, struct frame_info *fi);
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.37
diff -u -r1.37 frame.c
--- frame.c 4 Dec 2002 00:05:53 -0000 1.37
+++ frame.c 5 Dec 2002 21:16:53 -0000
@@ -1040,7 +1040,7 @@
FRAME_SAVED_PC() is being superseed by frame_pc_unwind() and that
function does have somewhere to cache that PC value. */
- INIT_FRAME_PC_FIRST (fromleaf, prev);
+ prev->pc = (INIT_FRAME_PC_FIRST (fromleaf, prev));
if (INIT_EXTRA_FRAME_INFO_P ())
INIT_EXTRA_FRAME_INFO (fromleaf, prev);
@@ -1048,7 +1048,7 @@
/* This entry is in the frame queue now, which is good since
FRAME_SAVED_PC may use that queue to figure out its value (see
tm-sparc.h). We want the pc saved in the inferior frame. */
- INIT_FRAME_PC (fromleaf, prev);
+ prev->pc = (INIT_FRAME_PC (fromleaf, prev));
/* If ->frame and ->pc are unchanged, we are in the process of
getting ourselves into an infinite backtrace. Some architectures
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.166
diff -u -r1.166 gdbarch.c
--- gdbarch.c 5 Dec 2002 15:19:45 -0000 1.166
+++ gdbarch.c 5 Dec 2002 21:16:53 -0000
@@ -1559,13 +1559,10 @@
/*INIT_EXTRA_FRAME_INFO ()*/);
#endif
#ifdef INIT_FRAME_PC
-#if GDB_MULTI_ARCH
- /* Macro might contain `[{}]' when not multi-arch */
fprintf_unfiltered (file,
"gdbarch_dump: %s # %s\n",
"INIT_FRAME_PC(fromleaf, prev)",
XSTRING (INIT_FRAME_PC (fromleaf, prev)));
-#endif
if (GDB_MULTI_ARCH)
fprintf_unfiltered (file,
"gdbarch_dump: INIT_FRAME_PC = 0x%08lx\n",
@@ -1573,13 +1570,10 @@
/*INIT_FRAME_PC ()*/);
#endif
#ifdef INIT_FRAME_PC_FIRST
-#if GDB_MULTI_ARCH
- /* Macro might contain `[{}]' when not multi-arch */
fprintf_unfiltered (file,
"gdbarch_dump: %s # %s\n",
"INIT_FRAME_PC_FIRST(fromleaf, prev)",
XSTRING (INIT_FRAME_PC_FIRST (fromleaf, prev)));
-#endif
if (GDB_MULTI_ARCH)
fprintf_unfiltered (file,
"gdbarch_dump: INIT_FRAME_PC_FIRST = 0x%08lx\n",
@@ -3776,7 +3770,7 @@
gdbarch->fix_call_dummy = fix_call_dummy;
}
-void
+CORE_ADDR
gdbarch_init_frame_pc_first (struct gdbarch *gdbarch, int fromleaf, struct frame_info *prev)
{
gdb_assert (gdbarch != NULL);
@@ -3785,7 +3779,7 @@
"gdbarch: gdbarch_init_frame_pc_first invalid");
if (gdbarch_debug >= 2)
fprintf_unfiltered (gdb_stdlog, "gdbarch_init_frame_pc_first called\n");
- gdbarch->init_frame_pc_first (fromleaf, prev);
+ return gdbarch->init_frame_pc_first (fromleaf, prev);
}
void
@@ -3795,7 +3789,7 @@
gdbarch->init_frame_pc_first = init_frame_pc_first;
}
-void
+CORE_ADDR
gdbarch_init_frame_pc (struct gdbarch *gdbarch, int fromleaf, struct frame_info *prev)
{
gdb_assert (gdbarch != NULL);
@@ -3804,7 +3798,7 @@
"gdbarch: gdbarch_init_frame_pc invalid");
if (gdbarch_debug >= 2)
fprintf_unfiltered (gdb_stdlog, "gdbarch_init_frame_pc called\n");
- gdbarch->init_frame_pc (fromleaf, prev);
+ return gdbarch->init_frame_pc (fromleaf, prev);
}
void
Index: gdbarch.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.h,v
retrieving revision 1.130
diff -u -r1.130 gdbarch.h
--- gdbarch.h 1 Dec 2002 19:07:14 -0000 1.130
+++ gdbarch.h 5 Dec 2002 21:16:54 -0000
@@ -1183,8 +1183,8 @@
#define INIT_FRAME_PC_FIRST(fromleaf, prev) (init_frame_pc_noop (fromleaf, prev))
#endif
-typedef void (gdbarch_init_frame_pc_first_ftype) (int fromleaf, struct frame_info *prev);
-extern void gdbarch_init_frame_pc_first (struct gdbarch *gdbarch, int fromleaf, struct frame_info *prev);
+typedef CORE_ADDR (gdbarch_init_frame_pc_first_ftype) (int fromleaf, struct frame_info *prev);
+extern CORE_ADDR gdbarch_init_frame_pc_first (struct gdbarch *gdbarch, int fromleaf, struct frame_info *prev);
extern void set_gdbarch_init_frame_pc_first (struct gdbarch *gdbarch, gdbarch_init_frame_pc_first_ftype *init_frame_pc_first);
#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (INIT_FRAME_PC_FIRST)
#error "Non multi-arch definition of INIT_FRAME_PC_FIRST"
@@ -1200,8 +1200,8 @@
#define INIT_FRAME_PC(fromleaf, prev) (init_frame_pc_default (fromleaf, prev))
#endif
-typedef void (gdbarch_init_frame_pc_ftype) (int fromleaf, struct frame_info *prev);
-extern void gdbarch_init_frame_pc (struct gdbarch *gdbarch, int fromleaf, struct frame_info *prev);
+typedef CORE_ADDR (gdbarch_init_frame_pc_ftype) (int fromleaf, struct frame_info *prev);
+extern CORE_ADDR gdbarch_init_frame_pc (struct gdbarch *gdbarch, int fromleaf, struct frame_info *prev);
extern void set_gdbarch_init_frame_pc (struct gdbarch *gdbarch, gdbarch_init_frame_pc_ftype *init_frame_pc);
#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (INIT_FRAME_PC)
#error "Non multi-arch definition of INIT_FRAME_PC"
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.178
diff -u -r1.178 gdbarch.sh
--- gdbarch.sh 5 Dec 2002 15:19:45 -0000 1.178
+++ gdbarch.sh 5 Dec 2002 21:16:54 -0000
@@ -513,8 +513,8 @@
v:1:CALL_DUMMY_STACK_ADJUST_P:int:call_dummy_stack_adjust_p::::0:-1:::0x%08lx
v:2:CALL_DUMMY_STACK_ADJUST:int:call_dummy_stack_adjust::::0:::gdbarch->call_dummy_stack_adjust_p && gdbarch->call_dummy_stack_adjust == 0:0x%08lx::CALL_DUMMY_STACK_ADJUST_P
f:2:FIX_CALL_DUMMY:void:fix_call_dummy:char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs, struct value **args, struct type *type, int gcc_p:dummy, pc, fun, nargs, args, type, gcc_p:::0
-f:2:INIT_FRAME_PC_FIRST:void:init_frame_pc_first:int fromleaf, struct frame_info *prev:fromleaf, prev:::init_frame_pc_noop::0
-f:2:INIT_FRAME_PC:void:init_frame_pc:int fromleaf, struct frame_info *prev:fromleaf, prev:::init_frame_pc_default::0
+f:2:INIT_FRAME_PC_FIRST:CORE_ADDR:init_frame_pc_first:int fromleaf, struct frame_info *prev:fromleaf, prev:::init_frame_pc_noop::0
+f:2:INIT_FRAME_PC:CORE_ADDR:init_frame_pc:int fromleaf, struct frame_info *prev:fromleaf, prev:::init_frame_pc_default::0
#
v:2:BELIEVE_PCC_PROMOTION:int:believe_pcc_promotion:::::::
v:2:BELIEVE_PCC_PROMOTION_TYPE:int:believe_pcc_promotion_type:::::::
Index: i386-interix-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-interix-tdep.c,v
retrieving revision 1.2
diff -u -r1.2 i386-interix-tdep.c
--- i386-interix-tdep.c 18 Nov 2002 22:19:27 -0000 1.2
+++ i386-interix-tdep.c 5 Dec 2002 21:16:54 -0000
@@ -117,12 +117,6 @@
return i386_pe_skip_trampoline_code (pc, 0);
}
-static void
-i386_interix_init_frame_pc (int fromleaf, struct frame_info *prev)
-{
- /* Nothing to do on Interix. */
-}
-
static int
i386_interix_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe)
{
@@ -337,7 +331,7 @@
set_gdbarch_skip_trampoline_code (gdbarch,
i386_interix_skip_trampoline_code);
set_gdbarch_init_extra_frame_info (gdbarch, i386_interix_back_one_frame);
- set_gdbarch_init_frame_pc (gdbarch, i386_interix_init_frame_pc);
+ set_gdbarch_init_frame_pc (gdbarch, init_frame_pc_noop);
set_gdbarch_frame_chain_valid (gdbarch, i386_interix_frame_chain_valid);
set_gdbarch_frame_saved_pc (gdbarch, i386_interix_frame_saved_pc);
set_gdbarch_name_of_malloc (gdbarch, "_malloc");
Index: mips-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mips-tdep.c,v
retrieving revision 1.143
diff -u -r1.143 mips-tdep.c
--- mips-tdep.c 5 Dec 2002 05:17:39 -0000 1.143
+++ mips-tdep.c 5 Dec 2002 21:16:55 -0000
@@ -1677,7 +1677,7 @@
target_remove_breakpoint (next_pc, break_mem);
}
-static void
+static CORE_ADDR
mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
{
CORE_ADDR pc, tmp;
@@ -1685,7 +1685,7 @@
pc = ((fromleaf) ? SAVED_PC_AFTER_CALL (prev->next) :
prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
tmp = SKIP_TRAMPOLINE_CODE (pc);
- prev->pc = tmp ? tmp : pc;
+ return tmp ? tmp : pc;
}
Index: s390-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/s390-tdep.c,v
retrieving revision 1.59
diff -u -r1.59 s390-tdep.c
--- s390-tdep.c 1 Dec 2002 19:07:15 -0000 1.59
+++ s390-tdep.c 5 Dec 2002 21:16:55 -0000
@@ -881,25 +881,24 @@
for the moment.
For some reason the blockframe.c calls us with fi->next->fromleaf
so this seems of little use to us. */
-void
+CORE_ADDR
s390_init_frame_pc_first (int next_fromleaf, struct frame_info *fi)
{
CORE_ADDR sigcaller_pc;
-
- fi->pc = 0;
+ CORE_ADDR pc = 0;
if (next_fromleaf)
{
- fi->pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
+ pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
/* fix signal handlers */
}
- else if (fi->next && fi->next->pc)
- fi->pc = s390_frame_saved_pc_nofix (fi->next);
- if (fi->pc && fi->next && fi->next->frame &&
- s390_is_sigreturn (fi->pc, fi->next, NULL, &sigcaller_pc))
+ else if (get_next_frame (fi) && get_frame_pc (get_next_frame (fi)))
+ pc = s390_frame_saved_pc_nofix (get_next_frame (fi));
+ if (pc && get_next_frame (fi) && get_frame_base (get_next_frame (fi))
+ && s390_is_sigreturn (pc, get_next_frame (fi), NULL, &sigcaller_pc))
{
- fi->pc = sigcaller_pc;
+ pc = sigcaller_pc;
}
-
+ return pc;
}
void
Index: x86-64-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/x86-64-linux-tdep.c,v
retrieving revision 1.9
diff -u -r1.9 x86-64-linux-tdep.c
--- x86-64-linux-tdep.c 18 Nov 2002 22:19:31 -0000 1.9
+++ x86-64-linux-tdep.c 5 Dec 2002 21:16:55 -0000
@@ -175,17 +175,17 @@
return fp;
}
-void
+CORE_ADDR
x86_64_init_frame_pc (int fromleaf, struct frame_info *fi)
{
CORE_ADDR addr;
- if (fi->next && (get_frame_type (fi->next) == SIGTRAMP_FRAME))
+ if (get_next_frame (fi) && (get_frame_type (fi->next) == SIGTRAMP_FRAME))
{
- addr = fi->next->next->frame
+ addr = get_frame_base (get_next_frame (get_next_frame (fi)))
+ LINUX_SIGINFO_SIZE + LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
- fi->pc = read_memory_integer (addr + LINUX_SIGCONTEXT_PC_OFFSET, 8);
+ return read_memory_integer (addr + LINUX_SIGCONTEXT_PC_OFFSET, 8);
}
else
- cfi_init_frame_pc (fromleaf, fi);
+ return cfi_init_frame_pc (fromleaf, fi);
}
Index: z8k-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/z8k-tdep.c,v
retrieving revision 1.14
diff -u -r1.14 z8k-tdep.c
--- z8k-tdep.c 29 Nov 2002 19:15:15 -0000 1.14
+++ z8k-tdep.c 5 Dec 2002 21:16:55 -0000
@@ -166,12 +166,6 @@
return 0;
}
-void
-init_frame_pc (void)
-{
- internal_error (__FILE__, __LINE__, "failed internal consistency check");
-}
-
/* Put here the code to store, into a struct frame_saved_regs,
the addresses of the saved registers of frame described by FRAME_INFO.
This includes special registers such as pc and fp saved in special
Index: config/rs6000/tm-rs6000.h
===================================================================
RCS file: /cvs/src/src/gdb/config/rs6000/tm-rs6000.h,v
retrieving revision 1.18
diff -u -r1.18 tm-rs6000.h
--- config/rs6000/tm-rs6000.h 11 Oct 2002 14:02:39 -0000 1.18
+++ config/rs6000/tm-rs6000.h 5 Dec 2002 21:16:55 -0000
@@ -79,9 +79,9 @@
/* Define other aspects of the stack frame. */
#define INIT_FRAME_PC_FIRST(fromleaf, prev) \
- prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
- prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
-#define INIT_FRAME_PC(fromleaf, prev) /* nothing */
+ (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
+ prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ())
+#define INIT_FRAME_PC(fromleaf, prev) (init_frame_pc_noop (fromleaf, prev))
/* Flag for machine-specific stuff in shared files. FIXME */
#define IBM6000_TARGET
Index: config/z8k/tm-z8k.h
===================================================================
RCS file: /cvs/src/src/gdb/config/z8k/tm-z8k.h,v
retrieving revision 1.15
diff -u -r1.15 tm-z8k.h
--- config/z8k/tm-z8k.h 1 Dec 2002 19:07:16 -0000 1.15
+++ config/z8k/tm-z8k.h 5 Dec 2002 21:16:57 -0000
@@ -108,9 +108,8 @@
#define REGISTER_VIRTUAL_TYPE(N) \
(REGISTER_VIRTUAL_SIZE(N) == 2? builtin_type_unsigned_int : builtin_type_long)
-/*#define INIT_FRAME_PC(x,y) init_frame_pc(x,y) */
-/* Initializer for an array of names of registers.
- Entries beyond the first NUM_REGS are ignored. */
+#define INIT_FRAME_PC(x,y) (init_frame_pc_noop (x, y))
+#define INIT_FRAME_PC_FIRST(x,y) (init_frame_pc_noop (x, y))
#define REGISTER_NAMES \
{"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \