Commit Graph

35 Commits

Author SHA1 Message Date
Jakub Jelinek a554497024 Update copyright years.
From-SVN: r267494
2019-01-01 13:31:55 +01:00
Tom de Vries eb33bf0a0a [libbacktrace] Reduce memory usage in build_address_map
In build_address_map we allocate a unit, and then look for addresses in the
unit, which we store in the addrs vector, with the elements pointing to the
unit.  However, if we cannot find addresses in the unit, the allocated unit is
not used.

Fix this by detecting if the allocated unit has been used, and reusing it
otherwise.

Bootstrapped and reg-tested on x86_64.

2018-12-28  Tom de Vries  <tdevries@suse.de>

	* dwarf.c (build_address_map): Reuse unused units.

From-SVN: r267445
2018-12-28 03:43:56 +00:00
Tom de Vries d9aa0961ea [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
2018-12-28 03:43:41 +00:00
Ian Lance Taylor 40b8d3b253 [libbacktrace] Fix memory leak in loop in build_address_map
When failing in build_address_map, we free the unit that's currently being
handled in the loop, but the ones that already have been allocated are leaked.

Fix this by keeping track of allocated units in a vector, and releasing them
upon failure.

Also, now that we have a vector of allocated units, move the freeing upon
failure of the abbrevs associated with each unit to build_address_map, and
remove the now redundant call to free_unit_addrs_vector.

Bootstrapped and reg-tested on x86_64.

2018-12-28  Ian Lance Taylor  <iant@golang.org>
	    Tom de Vries  <tdevries@suse.de>

	PR libbacktrace/88063
	* dwarf.c (free_unit_addrs_vector): Remove.
	(build_address_map): Keep track of allocated units in vector.  Free
	allocated units and corresponding abbrevs upon failure.  Remove now
	redundant call to free_unit_addrs_vector.  Free addrs vector upon
	failure.  Free allocated unit vector.

Co-Authored-By: Tom de Vries <tdevries@suse.de>

From-SVN: r267443
2018-12-28 03:43:26 +00:00
Tom de Vries 53a52133a5 [libbacktrace] Fix memory leak in build_address_map
While upon failure in build_address_map we call free_unit_addrs_vector, this
does not actually free the addrs vector, but merely the abbrevs of the units
pointed at by the elements of the addrs vector.

Fix this by adding code to build_address_map to make sure that the addrs vector
is freed upon failure.

Bootstrapped and reg-tested on x86_64.

2018-12-28  Tom de Vries  <tdevries@suse.de>

	* dwarf.c (build_address_map): Free addrs vector upon failure.

From-SVN: r267442
2018-12-28 03:43:15 +00:00
Tom de Vries 518a3a2106 [libbacktrace] Factor out backtrace_vector_free
Factor out new function backtrace_vector_free.

Bootstrapped and reg-tested on x86_64.

2018-11-30  Tom de Vries  <tdevries@suse.de>

	* internal.h (backtrace_vector_free): New static inline fuction,
	factored out of ...
	* dwarf.c (read_line_info): ... here.

From-SVN: r266658
2018-11-30 08:43:50 +00:00
Tom de Vries 18c742b5f0 [libbacktrace] Fix segfault upon allocation failure
If the allocation of abbrevs->abbrevs in read_abbrevs fails, then
abbrevs->num_abbrevs remains nonzero, and consequently free_abbrevs will
segfault when accessing abbrevs->abbrevs.

Fix this by setting abbrevs->num_abbrevs only after abbrevs->abbrevs
allocation has succeeded.

Bootstrapped and reg-tested on x86_64.

2018-11-28  Tom de Vries  <tdevries@suse.de>

	* dwarf.c (read_abbrevs): Fix handling of abbrevs->abbrevs allocation
	failure.

From-SVN: r266562
2018-11-28 14:06:23 +00:00
Tom de Vries 292592c5da [libbacktrace] Factor out read_initial_length
Factor out new function read_initial_length in dwarf.c.

Bootstrapped and reg-tested on x86_64.

2018-11-22  Tom de Vries  <tdevries@suse.de>

	* dwarf.c (read_initial_length): Factor out of ...
	(build_address_map, read_line_info): ... here.

From-SVN: r266361
2018-11-22 00:06:27 +00:00
Tom de Vries 171125708a [libbacktrace] Factor out read_string
Factor out new function read_string in dwarf.c.

Bootstrapped and reg-tested on x86_64.

2018-11-21  Tom de Vries  <tdevries@suse.de>

	* dwarf.c (read_string): Factor out of ...
	(read_attribute, read_line_header, read_line_program): ... here.

From-SVN: r266339
2018-11-21 08:31:04 +00:00
Jakub Jelinek 85ec4feb11 Update copyright years.
From-SVN: r256169
2018-01-03 11:03:58 +01:00
Than McIntosh 281161d16b dwarf.c (free_line_header): Don't free dirs if dirs_count == 0.
* dwarf.c (free_line_header): Don't free dirs if dirs_count == 0.
	(read_line_header): Don't allocate dirs if dirs_count == 0.
	* edtest.c: New file.
	* edtest2.c: New file.
	* Makefile.am (edtest_SOURCES, edtest_LDADD): Define.
	(check_PROGRAMS): Add edtest.
	(edtest2_build.c, gen_edtest2_build): New targets.
	* Makefile.in: Rebuild.

From-SVN: r248295
2017-05-19 16:07:24 +00:00
Jakub Jelinek cbe34bb5ed Update copyright years.
From-SVN: r243994
2017-01-01 13:07:43 +01:00
Carlos Liam 84ebf639b8 * all: Remove meaningless trailing whitespace.
From-SVN: r240084
2016-09-11 13:44:07 +00:00
Jakub Jelinek 818ab71a41 Update copyright years.
From-SVN: r232055
2016-01-04 15:30:50 +01:00
Ian Lance Taylor d96fa208a5 dwarf.c (read_function_entry): Add vec_inlined parameter.
* dwarf.c (read_function_entry): Add vec_inlined parameter.
	Change all callers.

From-SVN: r226878
2015-08-13 22:56:01 +00:00
Martin Sebor d99a7b4d6b re PR sanitizer/65479 (sanitizer stack trace missing frames past #0 on powerpc64)
2015-06-11  Martin Sebor  <msebor@redhat.com>

	PR sanitizer/65479
	* dwarf.c (struct line): Add new field idx.
	(line_compare): Use it.
	(add_line): Set it.
	(read_line_info): Reset it.

From-SVN: r224402
2015-06-11 18:01:50 -06:00
Jakub Jelinek 5624e564d2 Update copyright years.
From-SVN: r219188
2015-01-05 13:33:28 +01:00
Ian Lance Taylor c5604b48f9 sort.c: New file.
* sort.c: New file.
	* stest.c: New file.
	* internal.h (backtrace_qsort): Declare.
	* dwarf.c (read_abbrevs): Call backtrace_qsort instead of qsort.
	(read_line_info, read_function_entry): Likewise.
	(read_function_info, build_dwarf_data): Likewise.
	* elf.c (elf_initialize_syminfo): Likewise.
	* Makefile.am (libbacktrace_la_SOURCES): Add sort.c.
	(stest_SOURCES, stest_LDADD): Define.
	(check_PROGRAMS): Add stest.

From-SVN: r208392
2014-03-07 05:07:56 +00:00
Richard Sandiford afeba5cb1d Update copyright years in libbacktrace/
From-SVN: r206292
2014-01-02 22:24:37 +00:00
Ian Lance Taylor bfd74f227d alloc.c (backtrace_vector_finish): Add error_callback and data parameters.
* alloc.c (backtrace_vector_finish): Add error_callback and data
	parameters.  Call backtrace_vector_release.  Return address base.
	* mmap.c (backtrace_vector_finish): Add error_callback and data
	parameters.  Return address base.
	* dwarf.c (read_function_info): Get new address base from
	backtrace_vector_finish.
	* internal.h (backtrace_vector_finish): Update declaration.

From-SVN: r205716
2013-12-05 18:32:02 +00:00
Ian Lance Taylor b8ddd61b74 dwarf.c (find_address_ranges): New static function, broken out of build_address_map.
* dwarf.c (find_address_ranges): New static function, broken out
	of build_address_map.
	(build_address_map): Call it.
	* btest.c (check): Check for missing filename or function, rather
	than crashing.
	(f3): Check that enough frames were returned.

From-SVN: r205490
2013-11-28 16:19:57 +00:00
Ian Lance Taylor 49579c7e20 configure.ac: Check for support of __atomic extensions.
* configure.ac: Check for support of __atomic extensions.
	* internal.h: Declare or #define atomic functions for use in
	backtrace code.
	* atomic.c: New file.
	* dwarf.c (dwarf_lookup_pc): Use atomic functions.
	(dwarf_fileline, backtrace_dwarf_add): Likewise.
	* elf.c (elf_add_syminfo_data, elf_syminfo): Likewise.
	(backtrace_initialize): Likewise.
	* fileline.c (fileline_initialize): Likewise.
	* Makefile.am (libbacktrace_la_SOURCES): Add atomic.c.
	* configure, config.h.in, Makefile.in: Rebuild.

From-SVN: r204994
2013-11-19 01:09:47 +00:00
Ian Lance Taylor 38811401ad dwarf.c (read_function_info): Permit fvec parameter to be NULL.
* dwarf.c (read_function_info): Permit fvec parameter to be NULL.
	(dwarf_lookup_pc): Don't use ddata->fvec if threaded.

From-SVN: r195620
2013-01-31 17:50:47 +00:00
Jakub Jelinek 1e678aed6c re PR other/56076 (Several 64-bit libgo tests FAIL in read_line_header)
PR other/56076
	* dwarf.c (read_line_header): Don't crash if DW_AT_comp_dir
	attribute was not seen.

From-SVN: r195478
2013-01-25 22:36:11 +00:00
Ian Lance Taylor 6b514c5361 dwarf.c (struct unit): Add filename and abs_filename fields.
* dwarf.c (struct unit): Add filename and abs_filename fields.
	(build_address_map): Set new fields when reading unit.
	(dwarf_lookup_pc): If we don't find an entry in the line table,
	just return the main file name.

From-SVN: r195257
2013-01-17 01:20:28 +00:00
Richard Sandiford f8a7e1a44d Update copyright years in libbacktrace.
From-SVN: r195165
2013-01-14 18:17:30 +00:00
Ian Lance Taylor b20ade36e4 * dwarf.c (read_attribute): Always clear val.
From-SVN: r193670
2012-11-20 17:28:05 +00:00
Ian Lance Taylor ce8aa07436 dwarf.c (dwarf_fileline): Add cast to avoid warning.
* dwarf.c (dwarf_fileline): Add cast to avoid warning.
	(backtrace_dwarf_add): Likewise.

From-SVN: r192288
2012-10-10 04:37:06 +00:00
Ian Lance Taylor e561a9920c Add support for tracing through shared libraries.
* configure.ac: Check for link.h and dl_iterate_phdr.
	* elf.c: #include <link.h> if system has dl_iterate_phdr.  #undef
	ELF macros before #defining them.
	(dl_phdr_info, dl_iterate_phdr): Define if system does not have
	dl_iterate_phdr.
	(struct elf_syminfo_data): Add next field.
	(elf_initialize_syminfo): Initialize next field.
	(elf_add_syminfo_data): New static function.
	(elf_add): New static function, broken out of
	backtrace_initialize.  Call backtrace_dwarf_add instead of
	backtrace_dwarf_initialize.
	(struct phdr_data): Define.
	(phdr_callback): New static function.
	(backtrace_initialize): Call elf_add.
	* dwarf.c (struct dwarf_data): Add next and base_address fields.
	(add_unit_addr): Add base_address parameter.  Change all callers.
	(add_unit_ranges, build_address_map): Likewise.
	(add_line): Add ddata parameter.  Change all callers.
	(read_line_program, add_function_range): Likewise.
	(dwarf_lookup_pc): New static function, broken out of
	dwarf_fileline.
	(dwarf_fileline): Call dwarf_lookup_pc.
	(build_dwarf_data): New static function.
	(backtrace_dwarf_add): New function.
	(backtrace_dwarf_initialize): Remove.
	* internal.h (backtrace_dwarf_initialize): Don't declare.
	(backtrace_dwarf_add): Declare.
	* configure, config.h.in: Rebuild.

From-SVN: r192267
2012-10-09 18:20:45 +00:00
Ian Lance Taylor 244e2d9cd3 dwarf.c: If the system header files do not declare strnlen, provide our own version.
* dwarf.c: If the system header files do not declare strnlen,
	provide our own version.

From-SVN: r192082
2012-10-04 15:16:09 +00:00
Ian Lance Taylor be4ba8aef3 dwarf.c (read_uleb128): Fix overflow test.
* dwarf.c (read_uleb128): Fix overflow test.
	(read_sleb128): Likewise.
	(build_address_map): Don't change unit_buf.start.

From-SVN: r192053
2012-10-03 22:07:12 +00:00
Rainer Orth 768505569c configure.ac (GCC_HEADER_STDINT): Invoke.
* configure.ac (GCC_HEADER_STDINT): Invoke.
        * backtrace.h: If we can't find <stdint.h>, use "gstdint.h".
        * btest.c: Don't include <stdint.h>.
        * dwarf.c: Likewise.
        * configure, aclocal.m4, Makefile.in, config.h.in: Rebuild.

Co-Authored-By: Ian Lance Taylor <iant@google.com>

From-SVN: r191474
2012-09-19 13:41:33 +00:00
Ian Lance Taylor 30e15876ff * dwarf.c: Correct test of HAVE_DECL_STRNLEN.
From-SVN: r191437
2012-09-18 16:50:29 +00:00
Ian Lance Taylor 772a71a959 configure.ac: Check whether strnlen is declared.
* configure.ac: Check whether strnlen is declared.
	* dwarf.c: Declare strnlen if not declared.
	* configure, config.h.in: Rebuild.

From-SVN: r191433
2012-09-18 16:06:53 +00:00
Ian Lance Taylor eff02e4f84 libbacktrace/:
* Initial implementation.

./:
	* MAINTAINERS (Various Maintainers): Add libbacktrace.
	* configure.ac (host_libs): Add libbacktrace.
	(target_libraries): Add libbacktrace.
	* Makefile.def (host_modules): Add libbacktrace.
	(target_modules): Likewise.
	* configure, Makefile.in: Rebuild.

gcc/go:
	* config-lang.in (target_libs): Add target-libbacktrace.

From-SVN: r191397
2012-09-17 16:38:38 +00:00