[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Libunwind-devel] [PATCH 07/19] Eliminate one heap allocation in dwarf_f
From: |
Tommi Rantala |
Subject: |
[Libunwind-devel] [PATCH 07/19] Eliminate one heap allocation in dwarf_find_debug_frame() |
Date: |
Wed, 5 Sep 2012 14:50:15 +0300 |
Allocate `tab' from stack in dwarf_find_debug_frame(), as it's only a
few members and we only need it locally in the function.
---
src/dwarf/Gfind_proc_info-lsb.c | 35 ++++++++++++-----------------------
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/src/dwarf/Gfind_proc_info-lsb.c b/src/dwarf/Gfind_proc_info-lsb.c
index 5305a5a..ae0b939 100644
--- a/src/dwarf/Gfind_proc_info-lsb.c
+++ b/src/dwarf/Gfind_proc_info-lsb.c
@@ -332,18 +332,6 @@ struct debug_frame_tab
uint32_t size;
};
-static struct debug_frame_tab *
-debug_frame_tab_new (unsigned int base_size)
-{
- struct debug_frame_tab *tab = malloc (sizeof (struct debug_frame_tab));
-
- tab->tab = calloc (base_size, sizeof (struct table_entry));
- tab->length = 0;
- tab->size = base_size;
-
- return tab;
-}
-
static void
debug_frame_tab_append (struct debug_frame_tab *tab,
unw_word_t fde_offset, unw_word_t start_ip)
@@ -412,7 +400,7 @@ dwarf_find_debug_frame (int found, unw_dyn_info_t
*di_debug, unw_word_t ip,
unw_word_t item_start, item_end = 0;
uint32_t u32val = 0;
uint64_t cie_id = 0;
- struct debug_frame_tab *tab;
+ struct debug_frame_tab tab;
Debug (15, "loaded .debug_frame\n");
@@ -435,7 +423,9 @@ dwarf_find_debug_frame (int found, unw_dyn_info_t
*di_debug, unw_word_t ip,
/* Find all FDE entries in debug_frame, and make into a sorted
index. */
- tab = debug_frame_tab_new (16);
+ tab.length = 0;
+ tab.size = 16;
+ tab.tab = calloc (tab.size, sizeof (struct table_entry));
while (addr < (unw_word_t) (uintptr_t) (buf + bufsize))
{
@@ -488,7 +478,7 @@ dwarf_find_debug_frame (int found, unw_dyn_info_t
*di_debug, unw_word_t ip,
{
Debug (15, "start_ip = %lx, end_ip = %lx\n",
(long) this_pi.start_ip, (long) this_pi.end_ip);
- debug_frame_tab_append (tab,
+ debug_frame_tab_append (&tab,
item_start - (unw_word_t)
(uintptr_t) buf,
this_pi.start_ip);
}
@@ -499,18 +489,17 @@ dwarf_find_debug_frame (int found, unw_dyn_info_t
*di_debug, unw_word_t ip,
addr = item_end;
}
- debug_frame_tab_shrink (tab);
- qsort (tab->tab, tab->length, sizeof (struct table_entry),
+ debug_frame_tab_shrink (&tab);
+ qsort (tab.tab, tab.length, sizeof (struct table_entry),
debug_frame_tab_compare);
- /* for (i = 0; i < tab->length; i++)
+ /* for (i = 0; i < tab.length; i++)
{
fprintf (stderr, "ip %x, fde offset %x\n",
- (int) tab->tab[i].start_ip_offset,
- (int) tab->tab[i].fde_offset);
+ (int) tab.tab[i].start_ip_offset,
+ (int) tab.tab[i].fde_offset);
}*/
- fdesc->index = tab->tab;
- fdesc->index_size = tab->length;
- free (tab);
+ fdesc->index = tab.tab;
+ fdesc->index_size = tab.length;
}
di->format = UNW_INFO_FORMAT_TABLE;
--
1.7.9.5
- [Libunwind-devel] [PATCH 00/19] misc fixes, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 04/19] PPC: add missing debug level in Debug() calls in Gstep.c, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 02/19] Check __builtin___clear_cache() at configuration time, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 03/19] HPPA: fix common_init() bitrot, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 01/19] Annotate unused argument in mark_as_used() to avoid -Wextra compiler noise, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 05/19] PPC: return failure from the unw_get_proc_info() stub, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 06/19] Remove free() NULL pointer checks in load_debug_frame() error path, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 08/19] Rename `backtrace' to `do_backtrace' in tests/Gtest-init.cxx, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 07/19] Eliminate one heap allocation in dwarf_find_debug_frame(),
Tommi Rantala <=
- [Libunwind-devel] [PATCH 09/19] Check correct variable for offset in tests/Gtest-init.cxx, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 11/19] Do not print garbage proc info in tests/Gtest-bt.c, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 14/19] Provide manual page for `unw_backtrace()', Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 12/19] Avoid LLVM -Wunused-value warning in src/dwarf/Gexpr.c, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 13/19] Remove AC_FUNC_MEMCMP check from configure.in, Tommi Rantala, 2012/09/05
- [Libunwind-devel] [PATCH 10/19] Change test-varargs to check libunwind backtracing, Tommi Rantala, 2012/09/05