This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch/rfc] More dynamic allocation of scratch `struct frame_info'
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 05 Jan 2003 10:37:27 -0500
- Subject: [patch/rfc] More dynamic allocation of scratch `struct frame_info'
Hello,
The attached goes through and (hopefully) modifies any target using a
`struct frame_info' scratch buffer so that it is allocated in a way that
doesn't assume knowledge of the `struct frame_info's internals.
I need to check that this hasn't broken the arm so I'll commit it once
that is done (in a few days).
Andrew
2003-01-05 Andrew Cagney <ac131313@redhat.com>
* frame.h (deprecated_frame_xmalloc_with_cleanup): Declare.
* frame.c (deprecated_frame_xmalloc_with_cleanup): New function.
* arm-tdep.c (arm_frame_chain): Allocate caller_fi using
deprecated_frame_xmalloc_with_cleanup.
* m32r-tdep.c (m32r_virtual_frame_pointer): Allocate `fi' using
deprecated_frame_xmalloc.
* mcore-tdep.c (analyze_dummy_frame): Ditto for dummy.
* mn10200-tdep.c (mn10200_frame_chain): Ditto for dummy_frame.
Index: arm-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/arm-tdep.c,v
retrieving revision 1.90
diff -u -r1.90 arm-tdep.c
--- arm-tdep.c 5 Jan 2003 13:31:26 -0000 1.90
+++ arm-tdep.c 5 Jan 2003 15:29:42 -0000
@@ -1041,23 +1041,15 @@
caller_fi. */
if (arm_pc_is_thumb (caller_pc) != arm_pc_is_thumb (get_frame_pc (fi)))
{
- struct frame_info caller_fi;
- struct cleanup *old_chain;
-
- /* Create a temporary frame suitable for scanning the caller's
- prologue. (Ugh.) */
- memset (&caller_fi, 0, sizeof (caller_fi));
- caller_fi.extra_info = (struct frame_extra_info *)
- xcalloc (1, sizeof (struct frame_extra_info));
- old_chain = make_cleanup (xfree, caller_fi.extra_info);
- caller_fi.saved_regs = (CORE_ADDR *)
- xcalloc (1, SIZEOF_FRAME_SAVED_REGS);
- make_cleanup (xfree, caller_fi.saved_regs);
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+ struct frame_info *caller_fi =
+ deprecated_frame_xmalloc_with_cleanup (SIZEOF_FRAME_SAVED_REGS,
+ sizeof (struct frame_extra_info));
/* Now, scan the prologue and obtain the frame register. */
- deprecated_update_frame_pc_hack (&caller_fi, caller_pc);
- arm_scan_prologue (&caller_fi);
- framereg = caller_fi.extra_info->framereg;
+ deprecated_update_frame_pc_hack (caller_fi, caller_pc);
+ arm_scan_prologue (caller_fi);
+ framereg = caller_fi->extra_info->framereg;
/* Deallocate the storage associated with the temporary frame
created above. */
Index: cris-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/cris-tdep.c,v
retrieving revision 1.37
diff -u -r1.37 cris-tdep.c
--- cris-tdep.c 5 Jan 2003 01:39:54 -0000 1.37
+++ cris-tdep.c 5 Jan 2003 15:29:45 -0000
@@ -734,17 +734,15 @@
CORE_ADDR
cris_skip_prologue_main (CORE_ADDR pc, int frameless_p)
{
- struct frame_info fi;
- static struct frame_extra_info fei;
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+ struct frame_info *fi;
struct symtab_and_line sal = find_pc_line (pc, 0);
int best_limit;
CORE_ADDR pc_after_prologue;
- /* frame_info now contains dynamic memory. Since fi is a dummy here,
- I use static memory for extra_info, and don't bother allocating
- memory for saved_regs. */
- memset (&fi, 0, sizeof (fi));
- fi.extra_info = &fei;
+ /* frame_info now contains dynamic memory. Since fi is a dummy
+ here, I don't bother allocating memory for saved_regs. */
+ fi = deprecated_frame_xmalloc_with_cleanup (0, sizeof (struct frame_extra_info));
/* If there is no symbol information then sal.end == 0, and we end up
examining only the first instruction in the function prologue.
@@ -754,7 +752,8 @@
else
best_limit = pc + 100;
- pc_after_prologue = cris_examine (pc, best_limit, &fi, frameless_p);
+ pc_after_prologue = cris_examine (pc, best_limit, fi, frameless_p);
+ do_cleanups (old_chain);
return pc_after_prologue;
}
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.50
diff -u -r1.50 frame.c
--- frame.c 5 Jan 2003 01:39:54 -0000 1.50
+++ frame.c 5 Jan 2003 15:29:47 -0000
@@ -1316,6 +1316,24 @@
return frame;
}
+struct frame_info *
+deprecated_frame_xmalloc_with_cleanup (long sizeof_saved_regs,
+ long sizeof_extra_info)
+{
+ struct frame_info *frame = deprecated_frame_xmalloc ();
+ make_cleanup (xfree, frame);
+ if (sizeof_saved_regs > 0)
+ {
+ frame->saved_regs = xcalloc (1, sizeof_saved_regs);
+ make_cleanup (xfree, frame->saved_regs);
+ }
+ if (sizeof_extra_info > 0)
+ {
+ frame->extra_info = xcalloc (1, sizeof_extra_info);
+ make_cleanup (xfree, frame->extra_info);
+ }
+ return frame;
+}
void
_initialize_frame (void)
Index: frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.55
diff -u -r1.55 frame.h
--- frame.h 5 Jan 2003 01:39:54 -0000 1.55
+++ frame.h 5 Jan 2003 15:29:47 -0000
@@ -684,4 +684,13 @@
been created. By always creating a frame, this problem goes away. */
extern struct frame_info *deprecated_frame_xmalloc (void);
+/* FIXME: cagney/2003-01-05: Allocate a frame, along with the
+ saved_regs and extra_info. Set up cleanups for all three. Same as
+ for deprecated_frame_xmalloc, targets are calling this when
+ creating a scratch `struct frame_info'. The frame overhaul makes
+ this unnecessary since all frame queries are parameterized with a
+ common cache parameter and a frame. */
+extern struct frame_info *deprecated_frame_xmalloc_with_cleanup (long sizeof_saved_regs,
+ long sizeof_extra_info);
+
#endif /* !defined (FRAME_H) */
Index: m32r-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/m32r-tdep.c,v
retrieving revision 1.11
diff -u -r1.11 m32r-tdep.c
--- m32r-tdep.c 11 Dec 2002 02:26:36 -0000 1.11
+++ m32r-tdep.c 5 Jan 2003 15:29:48 -0000
@@ -426,20 +426,20 @@
void
m32r_virtual_frame_pointer (CORE_ADDR pc, long *reg, long *offset)
{
- struct frame_info fi;
+ struct frame_info *fi = deprecated_frame_xmalloc ();
+ struct cleanup *old_chain = make_cleanup (xfree, fi);
/* Set up a dummy frame_info. */
- fi.next = NULL;
- fi.prev = NULL;
- fi.frame = 0;
- fi.pc = pc;
+ fi->next = NULL;
+ fi->prev = NULL;
+ fi->frame = 0;
+ fi->pc = pc;
/* Analyze the prolog and fill in the extra info. */
- m32r_init_extra_frame_info (&fi);
-
+ m32r_init_extra_frame_info (fi);
/* Results will tell us which type of frame it uses. */
- if (fi.using_frame_pointer)
+ if (fi->using_frame_pointer)
{
*reg = FP_REGNUM;
*offset = 0;
@@ -449,6 +449,7 @@
*reg = SP_REGNUM;
*offset = 0;
}
+ do_cleanups (old_chain);
}
/* Function: find_callers_reg
Index: mcore-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mcore-tdep.c,v
retrieving revision 1.31
diff -u -r1.31 mcore-tdep.c
--- mcore-tdep.c 5 Jan 2003 01:39:54 -0000 1.31
+++ mcore-tdep.c 5 Jan 2003 15:29:51 -0000
@@ -289,7 +289,7 @@
if (dummy == NULL)
{
- dummy = (struct frame_info *) xmalloc (sizeof (struct frame_info));
+ dummy = deprecated_frame_xmalloc ();
dummy->saved_regs = (CORE_ADDR *) xmalloc (SIZEOF_FRAME_SAVED_REGS);
dummy->extra_info =
(struct frame_extra_info *) xmalloc (sizeof (struct frame_extra_info));
Index: mn10200-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mn10200-tdep.c,v
retrieving revision 1.12
diff -u -r1.12 mn10200-tdep.c
--- mn10200-tdep.c 3 Jan 2003 18:23:01 -0000 1.12
+++ mn10200-tdep.c 5 Jan 2003 15:29:52 -0000
@@ -607,7 +607,9 @@
CORE_ADDR
mn10200_frame_chain (struct frame_info *fi)
{
- struct frame_info dummy_frame;
+ struct frame_info *dummy_frame = deprecated_frame_xmalloc ();
+ struct cleanup *old_chain = make_cleanup (xfree, dummy_frame);
+ CORE_ADDR ret;
/* Walk through the prologue to determine the stack size,
location of saved registers, end of the prologue, etc. */
@@ -638,31 +640,33 @@
So we set up a dummy frame and call mn10200_analyze_prologue to
find stuff for us. */
- deprecated_update_frame_pc_hack (&dummy_frame, FRAME_SAVED_PC (fi));
- deprecated_update_frame_base_hack (&dummy_frame, fi->frame);
- memset (dummy_frame.fsr.regs, '\000', sizeof dummy_frame.fsr.regs);
- dummy_frame.status = 0;
- dummy_frame.stack_size = 0;
- mn10200_analyze_prologue (&dummy_frame, 0);
+ deprecated_update_frame_pc_hack (dummy_frame, FRAME_SAVED_PC (fi));
+ deprecated_update_frame_base_hack (dummy_frame, fi->frame);
+ memset (dummy_frame->fsr.regs, '\000', sizeof dummy_frame->fsr.regs);
+ dummy_frame->status = 0;
+ dummy_frame->stack_size = 0;
+ mn10200_analyze_prologue (dummy_frame, 0);
- if (dummy_frame.status & MY_FRAME_IN_FP)
+ if (dummy_frame->status & MY_FRAME_IN_FP)
{
/* Our caller has a frame pointer. So find the frame in $a2, $a0,
or in the stack. */
if (fi->fsr.regs[6])
- return (read_memory_integer (fi->fsr.regs[FP_REGNUM], REGISTER_SIZE)
- & 0xffffff);
+ ret = (read_memory_integer (fi->fsr.regs[FP_REGNUM], REGISTER_SIZE)
+ & 0xffffff);
else if (fi->status & CALLER_A2_IN_A0)
- return read_register (4);
+ ret = read_register (4);
else
- return read_register (FP_REGNUM);
+ ret = read_register (FP_REGNUM);
}
else
{
/* Our caller does not have a frame pointer. So his frame starts
at the base of our frame (fi->frame) + <his size> + 4 (saved pc). */
- return fi->frame + -dummy_frame.stack_size + 4;
+ ret = fi->frame + -dummy_frame->stack_size + 4;
}
+ do_cleanups (old_chain);
+ return ret;
}
/* Function: skip_prologue
Index: mn10300-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mn10300-tdep.c,v
retrieving revision 1.44
diff -u -r1.44 mn10300-tdep.c
--- mn10300-tdep.c 5 Jan 2003 01:39:55 -0000 1.44
+++ mn10300-tdep.c 5 Jan 2003 15:29:52 -0000
@@ -153,7 +153,7 @@
static struct frame_info *dummy = NULL;
if (dummy == NULL)
{
- dummy = xmalloc (sizeof (struct frame_info));
+ dummy = deprecated_frame_xmalloc ();
dummy->saved_regs = xmalloc (SIZEOF_FRAME_SAVED_REGS);
dummy->extra_info = xmalloc (sizeof (struct frame_extra_info));
}