This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA] dwarf2cfi.c obstack usage
- From: Michal Ludvig <mludvig at suse dot cz>
- To: GDB Patches <gdb-patches at sources dot redhat dot com>
- Date: Fri, 07 Jun 2002 16:47:18 +0200
- Subject: [RFA] dwarf2cfi.c obstack usage
- Organization: SuSE CR
Hi all,
functions in dwarf2cfi rely on obstack initialisation from
parse_frame_info() that is mostly called as the first one. However not
always. In such a case gdb usually segfaults, because it tries to use
random pointers from uninitialized unwind_tmp_obstack structure.
This fix adds obstack_init to every function that finally calls
obstack_free.
Simple one. If noone objects within a day or two I'll commit it as
obvious. OK?
Michal Ludvig
--
* SuSE CR, s.r.o * mludvig@suse.cz
* +420 2 9654 5373 * http://www.suse.cz
2002-06-07 Michal Ludvig <mludvig@suse.cz>
* dwarf2cfi.c (unwind_tmp_obstack_init): New.
(unwind_tmp_obstack_free, parse_frame_info)
(update_context, cfi_read_fp, cfi_write_fp)
(cfi_frame_chain, cfi_init_extra_frame_info)
(cfi_virtual_frame_pointer): Use the above function.
*** dwarf2cfi.c Fri Jun 7 13:40:46 2002
--- dwarf2cfi.c.obs Fri Jun 7 10:36:15 2002
*************** static void fde_chunks_need_space ();
*** 199,204 ****
--- 199,205 ----
static struct context *context_alloc ();
static struct frame_state *frame_state_alloc ();
+ static void unwind_tmp_obstack_init ();
static void unwind_tmp_obstack_free ();
static void context_cpy (struct context *dst, struct context *src);
*************** frame_state_alloc ()
*** 306,315 ****
}
static void
unwind_tmp_obstack_free ()
{
obstack_free (&unwind_tmp_obstack, NULL);
! obstack_init (&unwind_tmp_obstack);
}
static void
--- 307,322 ----
}
static void
+ unwind_tmp_obstack_init ()
+ {
+ obstack_init (&unwind_tmp_obstack);
+ }
+
+ static void
unwind_tmp_obstack_free ()
{
obstack_free (&unwind_tmp_obstack, NULL);
! unwind_tmp_obstack_init ();
}
static void
*************** update_context (struct context *context,
*** 1268,1275 ****
--- 1275,1285 ----
CORE_ADDR cfa;
long i;
+ unwind_tmp_obstack_init ();
+
orig_context = context_alloc ();
context_cpy (orig_context, context);
+
/* Compute this frame's CFA. */
switch (fs->cfa_how)
{
*************** parse_frame_info (struct objfile *objfil
*** 1397,1403 ****
int last_dup_fde = 0, aug_len, i;
CORE_ADDR curr_section_vma = 0;
! obstack_init (&unwind_tmp_obstack);
frame_buffer = dwarf2_read_section (objfile, frame_offset, frame_size);
--- 1407,1413 ----
int last_dup_fde = 0, aug_len, i;
CORE_ADDR curr_section_vma = 0;
! unwind_tmp_obstack_init ();
frame_buffer = dwarf2_read_section (objfile, frame_offset, frame_size);
*************** cfi_read_fp ()
*** 1659,1664 ****
--- 1669,1676 ----
struct frame_state *fs;
CORE_ADDR cfa;
+ unwind_tmp_obstack_init ();
+
context = context_alloc ();
fs = frame_state_alloc ();
*************** cfi_read_fp ()
*** 1668,1674 ****
--- 1680,1688 ----
update_context (context, fs, 0);
cfa = context->cfa;
+
unwind_tmp_obstack_free ();
+
return cfa;
}
*************** cfi_write_fp (CORE_ADDR val)
*** 1680,1685 ****
--- 1694,1701 ----
struct context *context;
struct frame_state *fs;
+ unwind_tmp_obstack_init ();
+
context = context_alloc ();
fs = frame_state_alloc ();
*************** cfi_frame_chain (struct frame_info *fi)
*** 1727,1732 ****
--- 1743,1750 ----
struct frame_state *fs;
CORE_ADDR cfa;
+ unwind_tmp_obstack_init ();
+
context = context_alloc ();
fs = frame_state_alloc ();
context_cpy (context, UNWIND_CONTEXT (fi));
*************** cfi_init_extra_frame_info (int fromleaf,
*** 1763,1768 ****
--- 1781,1788 ----
{
struct frame_state *fs;
+ unwind_tmp_obstack_init ();
+
fs = frame_state_alloc ();
fi->context = frame_obstack_alloc (sizeof (struct context));
UNWIND_CONTEXT (fi)->reg =
*************** cfi_init_extra_frame_info (int fromleaf,
*** 1782,1787 ****
--- 1802,1808 ----
frame_state_for (UNWIND_CONTEXT (fi), fs);
update_context (UNWIND_CONTEXT (fi), fs, 0);
}
+
unwind_tmp_obstack_free ();
}
*************** cfi_virtual_frame_pointer (CORE_ADDR pc,
*** 1889,1894 ****
--- 1910,1917 ----
struct context *context;
struct frame_state *fs;
+ unwind_tmp_obstack_init ();
+
context = context_alloc ();
fs = frame_state_alloc ();