summaryrefslogtreecommitdiff
path: root/libbacktrace
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2018-12-28 03:43:41 +0000
committerTom de Vries <vries@gcc.gnu.org>2018-12-28 03:43:41 +0000
commitd9aa0961ea1b37aa2159761b147e9668422925ba (patch)
treed8f22fb7f9f03de37f2adc91fb45badba377d6b3 /libbacktrace
parent40b8d3b2536246b7449b6c7ce7a972537e5f11e1 (diff)
[libbacktrace] Simplify memory management in build_address_map
In the main loop in build_address_map, we first read the abbrevs into a local variable abbrevs, and then allocate the corresponding unit, after which we assign the abbrevs to the unit. This results in dedicated free-upon-failure handling for the variable, and extra code to make sure that free-upon-failure doesn't trigger once the unit has taken ownership of the abbrevs. Simplify this by reversing the order of abbrev reading and unit allocation, and eliminating the abbrevs local variable. Bootstrapped and reg-tested on x86_64. 2018-12-28 Tom de Vries <tdevries@suse.de> * dwarf.c (build_address_map): Simplify by removing local variable abbrevs. From-SVN: r267444
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/ChangeLog5
-rw-r--r--libbacktrace/dwarf.c20
2 files changed, 13 insertions, 12 deletions
diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog
index 27a0f429331..ee31ef0dd5e 100644
--- a/libbacktrace/ChangeLog
+++ b/libbacktrace/ChangeLog
@@ -1,3 +1,8 @@
+2018-12-28 Tom de Vries <tdevries@suse.de>
+
+ * dwarf.c (build_address_map): Simplify by removing local variable
+ abbrevs.
+
2018-12-28 Ian Lance Taylor <iant@golang.org>
Tom de Vries <tdevries@suse.de>
diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index f3499a9f45a..7ef99bdd7f2 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -1432,7 +1432,6 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address,
void *data, struct unit_addrs_vector *addrs)
{
struct dwarf_buf info;
- struct abbrevs abbrevs;
struct backtrace_vector units;
size_t units_count;
size_t i;
@@ -1457,7 +1456,6 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address,
memset (&units, 0, sizeof units);
units_count = 0;
- memset (&abbrevs, 0, sizeof abbrevs);
while (info.left > 0)
{
const unsigned char *unit_data_start;
@@ -1488,13 +1486,6 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address,
goto fail;
}
- abbrev_offset = read_offset (&unit_buf, is_dwarf64);
- if (!read_abbrevs (state, abbrev_offset, dwarf_abbrev, dwarf_abbrev_size,
- is_bigendian, error_callback, data, &abbrevs))
- goto fail;
-
- addrsize = read_byte (&unit_buf);
-
pu = ((struct unit **)
backtrace_vector_grow (state, sizeof (struct unit *),
error_callback, data, &units));
@@ -1509,6 +1500,14 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address,
*pu = u;
++units_count;
+ memset (&u->abbrevs, 0, sizeof u->abbrevs);
+ abbrev_offset = read_offset (&unit_buf, is_dwarf64);
+ if (!read_abbrevs (state, abbrev_offset, dwarf_abbrev, dwarf_abbrev_size,
+ is_bigendian, error_callback, data, &u->abbrevs))
+ goto fail;
+
+ addrsize = read_byte (&unit_buf);
+
u->unit_data = unit_buf.buf;
u->unit_data_len = unit_buf.left;
u->unit_data_offset = unit_buf.buf - unit_data_start;
@@ -1519,8 +1518,6 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address,
u->comp_dir = NULL;
u->abs_filename = NULL;
u->lineoff = 0;
- u->abbrevs = abbrevs;
- memset (&abbrevs, 0, sizeof abbrevs);
/* The actual line number mappings will be read as needed. */
u->lines = NULL;
@@ -1559,7 +1556,6 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address,
}
backtrace_vector_free (state, &units, error_callback, data);
}
- free_abbrevs (state, &abbrevs, error_callback, data);
if (addrs->count > 0)
{
backtrace_vector_free (state, &addrs->vec, error_callback, data);