aboutsummaryrefslogtreecommitdiff
path: root/libbacktrace/dwarf.c
AgeCommit message (Collapse)AuthorFilesLines
2021-03-02libbacktrace: don't special case file 0Ian Lance Taylor1-25/+14
It's no longer necessary as file 0 is now set up in all cases. * dwarf.c (read_line_program): Don't special case file 0. (read_function_entry): Likewise.
2021-03-02libbacktrace: pass -1 to error callback for unrecognized DWARFIan Lance Taylor1-23/+35
PR libbacktrace/98818 * dwarf.c (dwarf_buf_error): Add errnum parameter. Change all callers. * backtrace.h: Update backtrace_error_callback comment.
2021-01-18libbacktrace: use correct directory/filename for DWARF 5Ian Lance Taylor1-31/+33
PR debug/98716 * dwarf.c (read_v2_paths): Allocate zero entry for dirs and filenames. (read_line_program): Remove parameter u, change caller. Don't subtract one from dirs and filenames index. (read_function_entry): Don't subtract one from filenames index.
2021-01-04Update copyright years.Jakub Jelinek1-1/+1
2020-12-02libbacktrace: correct buffer overflow testsIan Lance Taylor1-2/+2
* dwarf.c (resolve_string): Use > rather than >= to check whether string index extends past buffer. (resolve_addr_index): Similarly for address index.
2020-09-22libbacktrace: handle pc == low correctlyIan Lance Taylor1-11/+27
* dwarf.c (report_inlined_functions): Handle PC == -1 and PC == p->low. (dwarf_lookup_pc): Likewise.
2020-09-08libbacktrace: avoid ambiguous binary searchIan Lance Taylor1-45/+135
Searching for a range match can cause the search order to not match the sort order, which can cause libbacktrace to miss matching entries. Allocate an extra entry at the end of function_addrs and unit_addrs vectors, so that we can safely compare to the next entry when searching. Adjust the matching code accordingly. Fixes https://github.com/ianlancetaylor/libbacktrace/issues/44. * dwarf.c (function_addrs_search): Compare against the next entry low address, not the high address. (unit_addrs_search): Likewise. (build_address_map): Add a trailing unit_addrs. (read_function_entry): Add a trailing function_addrs. (read_function_info): Likewise. (report_inlined_functions): Search backward for function_addrs match. (dwarf_lookup_pc): Search backward for unit_addrs and function_addrs matches.
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-12-13libbacktrace: add DWARF 5 supportIan Lance Taylor1-148/+979
* dwarf.c (struct attr): Add val field. (enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX, ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX. (struct line_header): Add addrsize field. (struct line_header_format): Define. (struct unit): Add str_offsets_base, addr_base, and rnglists_base fields. (read_uint24): New static function. (read_attribute): Add implicit_val parameter. Replace dwarf_str and dwarf_str_size parameters with dwarf_sections parameter. Add support for new DWARF 5 forms. Change all callers. (resolve_string): New static function. (resolve_addr_index): Likewise. (read_abbrevs): Support DW_FORM_implicit_const. (struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index, and ranges_is_index fields. (update_pcrange): Support DWARF 5 encodings. (add_high_low_range): New static function, split out of add_ranges. (add_ranges_from_ranges): Likewise. (add_ranges_from_rnglists): New static function. (add_ranges): Just call new helper functions. (find_address_ranges): Use resolve_string for strings, after reading all attributes. Handle new DWARF 5 attributes. (build_address_map): Support DWARF 5 compilation units. (read_v2_paths): New static function, split out of read_line_header. (read_lnct): New static function. (read_line_header_format_entries): Likewise. (read_line_header): Add ddata parameter. Support DWARF 5 line headers. Call new helper functions. Change all callers. (read_line_program): Use addrsize from line program header. Don't special case directory index 0 for DWARF 5. (read_referenced_name): Use resolve_string. (read_function_entry): Handle DWARF 5 encodings. Use resolve_string. * internal.h (enum dwarf_section): Add DEBUG_ADDR, DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS. * elf.c (dwarf_section_names): Add new section names. * pecoff.c (dwarf_section_names): Likewise. * xcoff.c (xcoff_add): Clear dwarf_sections before setting fields. * configure.ac: Define HAVE_DWARF5 automake conditional. * Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5. (dwarf5_CFLAGS, dwarf5_LDADD): Likewise. (dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise. (dwarf5_alloc_LDADD): Likewise. (BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5. (CLEANFILES, clean-local): Define. From-SVN: r279380
2019-12-10libbacktrace: remove duplicate low_pc/high_pc/range handlingIan Lance Taylor1-235/+164
* dwarf.c (struct pcrange): Define. (update_pcrange, add_ranges): New static functions. (add_unit_addr): Change signature to work with add_ranges. Don't add base_address here. (add_unit_ranges): Remove. (find_address_ranges): Replace str/ranges parameters with dwarf_sections. Use update_pcrange and add_ranges. Change all callers. (add_function_range): Change signature to work with add_ranges. Don't add base_address here. (add_function_ranges): Remove. (read_function_entry): Use update_pcrange and add_ranges. From-SVN: r279154
2019-12-05libbacktrace: simplify DWARF section handlingIan Lance Taylor1-73/+37
This is in preparation for adding DWARF 5 support. * internal.h (enum dwarf_section): Define. (struct dwarf_sections): Define. (backtrace_dwarf_add): Update declaration to replace specific section parameters with dwarf_sections parameter. * dwarf.c (struct dwarf_data): Replace specific section fields with dwarf_sections field. (read_attribute): Use dwarf_sections with altlink. (build_address_map): Replace specific section parameters with dwarf_sections parameter. Change all callers. (read_line_info): Use dwarf_sections with ddata. (read_referenced_name): Likewise. (add_function_ranges): Likewise. (read_function_entry): Likewise. (read_function_info): Likewise. (build_dwarf_data): Replace specific section parameters with dwarf_sections parameter. Change all callers. (backtrace_dwarf_add): Likewise. * elf.c (enum debug_section): Remove. (dwarf_section_names): Remove .zdebug names. (elf_add): Track zsections separately. Build dwarf_sections. * pecoff.c (enum debug_section): Remove. (struct debug_section_info): Remove data field. (coff_add): Build dwarf_sections. * xcoff.c (enum dwarf_section): Remove. Replace DWSECT_xxx references with DEBUG_xxx references. (xcoff_add): Build dwarf_sections. From-SVN: r278984
2019-02-12[libbacktrace] Handle bsearch with NULL base in dwarf_lookup_pcTom de Vries1-2/+4
The call to bsearch in dwarf_lookup_pc can have NULL as base argument when the nmemb argument is 0. The base argument is required to be pointing to the initial member of an array of nmemb objects. It is not specified what constitutes a valid pointer to an array of 0 objects, but glibc declares base with attribute non-null, so the NULL will trigger a sanitizer runtime error. Fix this by only calling bsearch if nmemb != 0. 2019-02-12 Tom de Vries <tdevries@suse.de> PR libbacktrace/81983 * dwarf.c (dwarf_lookup_pc): Don't call bsearch if nmemb == 0. From-SVN: r268796
2019-02-08[libbacktrace] Handle DW_FORM_ref_addrTom de Vries1-20/+12
Add handling of the DW_FORM_ref_addr encoding to libbacktrace. 2019-02-08 Tom de Vries <tdevries@suse.de> PR libbacktrace/78063 * dwarf.c (build_address_map): Keep all parsed units. (read_referenced_name_from_attr): Handle DW_FORM_ref_addr. From-SVN: r268663
2019-01-23[libbacktrace] Use size_t for low_offset/high_offset fields of struct unitTom de Vries1-6/+6
2019-01-23 Tom de Vries <tdevries@suse.de> * dwarf.c (struct unit): Use size_t for low_offset/high_offset fields. (units_search, find_unit): Use size_t for offset. (build_address_map): Use size_t for unit_offset. From-SVN: r268180
2019-01-17[libbacktrace] Handle DW_FORM_GNU_ref_altTom de Vries1-1/+16
Handle DW_FORM_GNU_ref_alt which references the .debug_info section in the .gnu_debugaltlink file. 2019-01-17 Tom de Vries <tdevries@suse.de> PR libbacktrace/82857 * dwarf.c (enum attr_val_encoding): Add ATTR_VAL_REF_ALT_INFO. (read_attribute): Handle DW_FORM_GNU_ref_alt using ATTR_VAL_REF_ALT_INFO. (read_referenced_name_from_attr): Handle DW_FORM_GNU_ref_alt. From-SVN: r268031
2019-01-17[libbacktrace] Add find_unitTom de Vries1-11/+76
Add a function that finds the unit given an offset into .debug_info. 2019-01-17 Tom de Vries <tdevries@suse.de> * dwarf.c (struct unit): Add low_offset and high_offset fields. (struct unit_vector): New type. (struct dwarf_data): Add units and units_counts fields. (find_unit): New function. (find_address_ranges): Add and handle unit_tag parameter. (build_address_map): Add and handle units_vec parameter. (build_dwarf_data): Pass units_vec to build_address_map. Store resulting units vector. From-SVN: r268030
2019-01-17[libbacktrace] Handle DW_FORM_GNU_strp_altTom de Vries1-8/+17
Handle DW_FORM_GNU_strp_alt which references the .debug_str section in the .gnu_debugaltlink file. 2019-01-17 Tom de Vries <tdevries@suse.de> PR libbacktrace/82857 * dwarf.c (read_attribute): Handle DW_FORM_GNU_strp_alt using altlink. From-SVN: r267996
2019-01-17[libbacktrace] Handle alt FORMS without .gnu_debugaltlinkTom de Vries1-15/+29
Handle DW_FORM_GNU_strp_alt and DW_FORM_GNU_ref_alt references robustly in presence of missing .gnu_debugaltlink file. 2019-01-17 Tom de Vries <tdevries@suse.de> * dwarf.c (enum attr_val_encoding): Add ATTR_VAL_NONE. (read_attribute): Add altlink parameter. Handle missing altlink for DW_FORM_GNU_strp_alt and DW_FORM_GNU_ref_alt. (find_address_ranges, build_address_map, build_dwarf_data): Add and handle altlink parameter. (read_referenced_name, read_function_entry): Add argument to read_attribute call. From-SVN: r267995
2019-01-17[libbacktrace] Add altlink field to struct dwarf_dataTom de Vries1-1/+6
Add an altlink field to struct dwarf_data, and initialize it with the pointer to the struct dwarf_data for the .gnu_debugaltlink. 2019-01-17 Tom de Vries <tdevries@suse.de> * dwarf.c (struct dwarf_data): Add altlink field. (backtrace_dwarf_add): Add and handle fileline_altlink parameter. * elf.c (elf_add): Add argument to backtrace_dwarf_add call. (phdr_callback, backtrace_initialize): Add argument to elf_add calls. * internal.h (backtrace_dwarf_add): Add fileline_altlink parameter. * pecoff.c (coff_add): Add argument to backtrace_dwarf_add call. * xcoff.c (xcoff_add): Same. From-SVN: r267994
2019-01-17[libbacktrace] Return struct dwarf_data pointer from elf_addTom de Vries1-1/+5
Allow the caller of elf_add access to the struct dwarf_data pointer corresponding to the added elf. 2019-01-17 Tom de Vries <tdevries@suse.de> * internal.h (backtrace_dwarf_add): Add fileline_entry parameter. * dwarf.c (backtrace_dwarf_add): Add and handle fileline_entry parameter. * elf.c (elf_add): Add and handle fileline_entry parameter. Add argument to backtrace_dwarf_add call. (phdr_callback, backtrace_initialize): Add argument to elf_add calls. * pecoff.c (coff_add): Add argument to backtrace_dwarf_add call. * xcoff.c (xcoff_add): Same. From-SVN: r267993
2019-01-16[libbacktrace] Factor out read_referenced_name_from_attrTom de Vries1-35/+54
Factor out the common handling of DW_AT_abstract_origin and DW_AT_specification from read_function_entry and read_referenced_name. 2019-01-16 Tom de Vries <tdevries@suse.de> * dwarf.c (read_referenced_name_from_attr): New function. Factor out of ... (read_referenced_name): ... here, and ... (read_function_entry): ... here. From-SVN: r267986
2019-01-16[libbacktrace] Unify function name preference handlingTom de Vries1-10/+23
Both read_function_entry and read_referenced_name implement a priority scheme for names. The priorities are: - 1st: DW_AT_linkage_name - 2nd: Name from DW_AT_abstract_origin or DW_AT_specification - 3rd: DW_AT_name. Ensure both functions fully adhere to it. 2019-01-16 Tom de Vries <tdevries@suse.de> * dwarf.c (read_referenced_name): Don't allow DW_AT_name to override any name. (read_function_entry): Same. Don't allow name found via DW_AT_abstract_origin or case DW_AT_specification to override linkage name. From-SVN: r267963
2019-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r267494
2018-12-28[libbacktrace] Reduce memory usage in build_address_mapTom de Vries1-0/+14
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[libbacktrace] Simplify memory management in build_address_mapTom de Vries1-12/+8
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[libbacktrace] Fix memory leak in loop in build_address_mapIan Lance Taylor1-26/+34
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[libbacktrace] Fix memory leak in build_address_mapTom de Vries1-0/+5
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-11-30[libbacktrace] Factor out backtrace_vector_freeTom de Vries1-3/+1
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-28[libbacktrace] Fix segfault upon allocation failureTom de Vries1-1/+1
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-22[libbacktrace] Factor out read_initial_lengthTom de Vries1-15/+21
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-21[libbacktrace] Factor out read_stringTom de Vries1-11/+28
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-01-03Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r256169
2017-05-19dwarf.c (free_line_header): Don't free dirs if dirs_count == 0.Than McIntosh1-11/+14
* 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-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r243994
2016-09-11* all: Remove meaningless trailing whitespace.Carlos Liam1-6/+6
From-SVN: r240084
2016-01-04Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r232055
2015-08-13dwarf.c (read_function_entry): Add vec_inlined parameter.Ian Lance Taylor1-4/+13
* dwarf.c (read_function_entry): Add vec_inlined parameter. Change all callers. From-SVN: r226878
2015-06-11re PR sanitizer/65479 (sanitizer stack trace missing frames past #0 on ↵Martin Sebor1-5/+12
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-01-05Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r219188
2014-03-07sort.c: New file.Ian Lance Taylor1-9/+10
* 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-01-02Update copyright years in libbacktrace/Richard Sandiford1-1/+1
From-SVN: r206292
2013-12-05alloc.c (backtrace_vector_finish): Add error_callback and data parameters.Ian Lance Taylor1-2/+6
* 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-11-28dwarf.c (find_address_ranges): New static function, broken out of ↵Ian Lance Taylor1-156/+184
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-19configure.ac: Check for support of __atomic extensions.Ian Lance Taylor1-27/+9
* 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-01-31dwarf.c (read_function_info): Permit fvec parameter to be NULL.Ian Lance Taylor1-9/+36
* 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-25re PR other/56076 (Several 64-bit libgo tests FAIL in read_line_header)Jakub Jelinek1-1/+2
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-17dwarf.c (struct unit): Add filename and abs_filename fields.Ian Lance Taylor1-2/+51
* 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-14Update copyright years in libbacktrace.Richard Sandiford1-1/+1
From-SVN: r195165
2012-11-20* dwarf.c (read_attribute): Always clear val.Ian Lance Taylor1-0/+6
From-SVN: r193670
2012-10-10dwarf.c (dwarf_fileline): Add cast to avoid warning.Ian Lance Taylor1-3/+3
* dwarf.c (dwarf_fileline): Add cast to avoid warning. (backtrace_dwarf_add): Likewise. From-SVN: r192288