This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch rfc] get_frame_func() / frame_func_unwind()
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 03 Apr 2003 23:57:10 -0500
- Subject: [patch rfc] get_frame_func() / frame_func_unwind()
Hello,
The attached is a simple cleanup adding the methods:
get_frame_func()
frame_func_unwind()
that return the function containing the relevant frame (or 0 if it can't
be easily figured out). It's a caching method so any symbol lookup
overhead only occures once (but I don't expect it to exactly make a
difference).
It then replaces occurances of things like:
get_pc_function_start (get_frame_pc (func))
with
get_frame_func (func)
I'll look to commit this in a few days (that memory corruption bug makes
testing hard :-().
Andrew
2003-04-03 Andrew Cagney <cagney at redhat dot com>
* frame.c (frame_func_unwind, get_frame_func): New functions.
* frame.h (get_frame_func, frame_func_unwind): Declare.
(struct frame_info): Add field "prev_func" for caching the
previous frame's function address.
* arm-tdep.c (arm_frameless_function_invocation): Combine
get_pc_function_start and get_frame_pc into get_frame_func.
* sh-tdep.c (sh_nofp_frame_init_saved_regs): Ditto.
(sh64_nofp_frame_init_saved_regs): Ditto.
* s390-tdep.c (s390_function_start): Ditto.
* rs6000-tdep.c (rs6000_pop_frame): Ditto.
(rs6000_frameless_function_invocation): Ditto.
(rs6000_frame_saved_pc): Ditto.
* m68k-tdep.c (m68k_frame_init_saved_regs): Ditto.
* ia64-tdep.c (ia64_frame_init_saved_regs): Ditto.
* i386-tdep.c (i386_frameless_signal_p): Ditto.
(i386_frame_init_saved_regs): Ditto.
* hppa-tdep.c (hppa_frame_find_saved_regs): Ditto.
* d10v-tdep.c (d10v_frame_unwind_cache): Combine
get_pc_function_start and frame_pc_unwind into frame_func_unwind.
* cris-tdep.c (cris_frame_init_saved_regs): Ditto.
* blockframe.c (frameless_look_for_prologue): Ditto.
Index: arm-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/arm-tdep.c,v
retrieving revision 1.125
diff -u -r1.125 arm-tdep.c
--- arm-tdep.c 1 Apr 2003 17:17:27 -0000 1.125
+++ arm-tdep.c 4 Apr 2003 04:42:58 -0000
@@ -295,7 +295,7 @@
stmdb sp!, {}
sub sp, ip, #4. */
- func_start = (get_pc_function_start (get_frame_pc (fi)) + FUNCTION_START_OFFSET);
+ func_start = (get_frame_func (fi)) + FUNCTION_START_OFFSET);
after_prologue = SKIP_PROLOGUE (func_start);
/* There are some frameless functions whose first two instructions
Index: blockframe.c
===================================================================
RCS file: /cvs/src/src/gdb/blockframe.c,v
retrieving revision 1.65
diff -u -r1.65 blockframe.c
--- blockframe.c 24 Mar 2003 03:54:47 -0000 1.65
+++ blockframe.c 4 Apr 2003 04:42:59 -0000
@@ -146,7 +146,7 @@
{
CORE_ADDR func_start, after_prologue;
- func_start = get_pc_function_start (get_frame_pc (frame));
+ func_start = get_frame_func (frame);
if (func_start)
{
func_start += FUNCTION_START_OFFSET;
Index: cris-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/cris-tdep.c,v
retrieving revision 1.65
diff -u -r1.65 cris-tdep.c
--- cris-tdep.c 1 Apr 2003 17:17:27 -0000 1.65
+++ cris-tdep.c 4 Apr 2003 04:43:05 -0000
@@ -1178,7 +1178,7 @@
}
else
{
- ip = get_pc_function_start (get_frame_pc (fi));
+ ip = get_frame_func (fi);
sal = find_pc_line (ip, 0);
/* If there is no symbol information then sal.end == 0, and we end up
Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.101
diff -u -r1.101 d10v-tdep.c
--- d10v-tdep.c 1 Apr 2003 19:55:03 -0000 1.101
+++ d10v-tdep.c 4 Apr 2003 04:43:07 -0000
@@ -720,7 +720,7 @@
info->sp_offset = 0;
info->uses_frame = 0;
- for (pc = get_pc_function_start (frame_pc_unwind (next_frame));
+ for (pc = frame_func_unwind (next_frame);
pc < frame_pc_unwind (next_frame);
pc += 4)
{
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.93
diff -u -r1.93 frame.c
--- frame.c 1 Apr 2003 19:11:01 -0000 1.93
+++ frame.c 4 Apr 2003 04:43:09 -0000
@@ -192,6 +192,23 @@
return this_frame->pc_unwind_cache;
}
+CORE_ADDR
+frame_func_unwind (struct frame_info *fi)
+{
+ if (!fi->prev_func.p)
+ {
+ fi->prev_func.p = 1;
+ fi->prev_func.addr = get_pc_function_start (frame_pc_unwind (fi));
+ }
+ return fi->prev_func.addr;
+}
+
+CORE_ADDR
+get_frame_func (struct frame_info *fi)
+{
+ return frame_func_unwind (fi->next);
+}
+
static int
do_frame_unwind_register (void *src, int regnum, void *buf)
{
Index: frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.80
diff -u -r1.80 frame.h
--- frame.h 1 Apr 2003 19:26:52 -0000 1.80
+++ frame.h 4 Apr 2003 04:43:17 -0000
@@ -149,6 +149,12 @@
this frame. */
extern CORE_ADDR get_frame_pc (struct frame_info *);
+/* Following on from the `resume' address. Return the function
+ containing that resume address, or zero if that function isn't
+ known. */
+extern CORE_ADDR frame_func_unwind (struct frame_info *fi);
+extern CORE_ADDR get_frame_func (struct frame_info *fi);
+
/* Closely related to the resume address, various symbol table
attributes that are determined by the PC. Note that for a normal
frame, the PC refers to the resume address after the return, and
@@ -407,6 +413,13 @@
/* Cached copy of the previous frame's resume address. */
int pc_unwind_cache_p;
CORE_ADDR pc_unwind_cache;
+
+ /* Cached copy of the previous frame's function address. */
+ struct
+ {
+ CORE_ADDR addr;
+ int p;
+ } prev_func;
/* This frame's ID. Note that the frame's ID, base and PC contain
redundant information. */
Index: hppa-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.65
diff -u -r1.65 hppa-tdep.c
--- hppa-tdep.c 1 Apr 2003 17:17:27 -0000 1.65
+++ hppa-tdep.c 4 Apr 2003 04:43:28 -0000
@@ -3912,7 +3912,7 @@
/* Get the starting address of the function referred to by the PC
saved in frame. */
- pc = get_pc_function_start (frame_info->pc);
+ pc = get_frame_func (frame_info);
/* Yow! */
u = find_unwind_entry (pc);
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.131
diff -u -r1.131 i386-tdep.c
--- i386-tdep.c 1 Apr 2003 17:17:28 -0000 1.131
+++ i386-tdep.c 4 Apr 2003 04:43:28 -0000
@@ -502,7 +502,7 @@
return (get_next_frame (frame)
&& get_frame_type (get_next_frame (frame)) == SIGTRAMP_FRAME
&& (frameless_look_for_prologue (frame)
- || get_frame_pc (frame) == get_pc_function_start (get_frame_pc (frame))));
+ || get_frame_pc (frame) == get_frame_func (frame)));
}
/* Return the chain-pointer for FRAME. In the case of the i386, the
@@ -714,7 +714,7 @@
frame_saved_regs_zalloc (fip);
- pc = get_pc_function_start (get_frame_pc (fip));
+ pc = get_frame_func (fip);
if (pc != 0)
locals = i386_get_frame_setup (pc);
Index: ia64-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/ia64-tdep.c,v
retrieving revision 1.66
diff -u -r1.66 ia64-tdep.c
--- ia64-tdep.c 1 Apr 2003 17:17:29 -0000 1.66
+++ ia64-tdep.c 4 Apr 2003 04:43:30 -0000
@@ -1205,7 +1205,7 @@
{
CORE_ADDR func_start;
- func_start = get_pc_function_start (get_frame_pc (frame));
+ func_start = get_frame_func (frame);
examine_prologue (func_start, get_frame_pc (frame), frame);
}
}
Index: m68k-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/m68k-tdep.c,v
retrieving revision 1.54
diff -u -r1.54 m68k-tdep.c
--- m68k-tdep.c 1 Apr 2003 14:38:50 -0000 1.54
+++ m68k-tdep.c 4 Apr 2003 04:43:31 -0000
@@ -614,7 +614,7 @@
}
else
{
- pc = get_pc_function_start (get_frame_pc (frame_info));
+ pc = get_frame_func (frame_info);
nextinsn = read_memory_unsigned_integer (pc, 2);
if (P_PEA_FP == nextinsn
Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.123
diff -u -r1.123 rs6000-tdep.c
--- rs6000-tdep.c 3 Apr 2003 17:56:25 -0000 1.123
+++ rs6000-tdep.c 4 Apr 2003 04:43:34 -0000
@@ -990,7 +990,7 @@
still in the link register, otherwise walk the frames and retrieve the
saved %pc value in the previous frame. */
- addr = get_pc_function_start (get_frame_pc (frame));
+ addr = get_frame_func (frame);
(void) skip_prologue (addr, get_frame_pc (frame), &fdata);
wordsize = gdbarch_tdep (current_gdbarch)->wordsize;
@@ -1499,7 +1499,7 @@
&& !(get_frame_type (get_next_frame (fi)) == SIGTRAMP_FRAME))
return 0;
- func_start = get_pc_function_start (get_frame_pc (fi));
+ func_start = get_frame_func (fi);
/* If we failed to find the start of the function, it is a mistake
to inspect the instructions. */
@@ -1540,7 +1540,7 @@
return deprecated_read_register_dummy (get_frame_pc (fi),
get_frame_base (fi), PC_REGNUM);
- func_start = get_pc_function_start (get_frame_pc (fi));
+ func_start = get_frame_func (fi);
/* If we failed to find the start of the function, it is a mistake
to inspect the instructions. */
@@ -1596,8 +1596,7 @@
if (fdatap == NULL)
{
fdatap = &work_fdata;
- (void) skip_prologue (get_pc_function_start (get_frame_pc (fi)),
- get_frame_pc (fi), fdatap);
+ (void) skip_prologue (get_frame_func (fi), get_frame_pc (fi), fdatap);
}
frame_saved_regs_zalloc (fi);
@@ -1720,8 +1719,7 @@
/* Find out if this function is using an alloca register. */
- (void) skip_prologue (get_pc_function_start (get_frame_pc (fi)),
- get_frame_pc (fi), &fdata);
+ (void) skip_prologue (get_frame_func (fi), get_frame_pc (fi), &fdata);
/* If saved registers of this frame are not known yet, read and
cache them. */
Index: s390-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/s390-tdep.c,v
retrieving revision 1.88
diff -u -r1.88 s390-tdep.c
--- s390-tdep.c 1 Apr 2003 17:17:29 -0000 1.88
+++ s390-tdep.c 4 Apr 2003 04:43:34 -0000
@@ -775,7 +775,7 @@
if (get_frame_extra_info (fi) && get_frame_extra_info (fi)->initialised)
function_start = get_frame_extra_info (fi)->function_start;
else if (get_frame_pc (fi))
- function_start = get_pc_function_start (get_frame_pc (fi));
+ function_start = get_frame_func (fi);
return function_start;
}
Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.114
diff -u -r1.114 sh-tdep.c
--- sh-tdep.c 1 Apr 2003 17:17:29 -0000 1.114
+++ sh-tdep.c 4 Apr 2003 04:43:36 -0000
@@ -1116,7 +1116,7 @@
that does not appear to be part of the prologue. But give up
after 20 of them, since we're getting silly then. */
- pc = get_pc_function_start (get_frame_pc (fi));
+ pc = get_frame_func (fi);
if (!pc)
{
deprecated_update_frame_pc_hack (fi, 0);
@@ -1456,7 +1456,7 @@
that does not appear to be part of the prologue. But give up
after 20 of them, since we're getting silly then. */
- pc = get_pc_function_start (get_frame_pc (fi));
+ pc = get_frame_func (fi);
if (!pc)
{
deprecated_update_frame_pc_hack (fi, 0);
@@ -1657,7 +1657,7 @@
that does not appear to be part of the prologue. But give up
after 20 of them, since we're getting silly then. */
- pc = get_pc_function_start (get_frame_pc (fi));
+ pc = get_frame_func (fi);
if (!pc)
{
deprecated_update_frame_pc_hack (fi, 0);