binutils-gdb/gdb/dwarf2
Philippe Waroquiers 9d69cd24db Fix leak in the dwarf reader
Valgrind reports a leak in the dwarf reader (see details below).
The function dw2_get_file_names_reader is interning in the per_objfile
all the file names it finds, except the name of 'fnd file name and directory'.
Instead, it was xstrdup-ing the name.
Fix the leaks by also interning the name.

This was validated running the tests natively, and under valgrind.
Leaks have decreased as mentionned below.
Valgrind detected no error such as double free or use after free.

Stack trace of the leak:
==4113266== 490,735 bytes in 17,500 blocks are definitely lost in loss record 7,061 of 7,074
==4113266==    at 0x483979B: malloc (vg_replace_malloc.c:393)
==4113266==    by 0x25A454: xmalloc (alloc.c:57)
==4113266==    by 0x7D1E1E: xstrdup (xstrdup.c:34)
==4113266==    by 0x39D141: dw2_get_file_names_reader (read.c:2825)
==4113266==    by 0x39D141: dw2_get_file_names(dwarf2_per_cu_data*, dwarf2_per_objfile*) (read.c:2851)
==4113266==    by 0x39DD6C: dw_expand_symtabs_matching_file_matcher(dwarf2_per_objfile*, gdb::function_view<bool (char const*, bool)>) (read.c:4149)
==4113266==    by 0x3BC8B5: cooked_index_functions::expand_symtabs_matching(objfile*, gdb::function_view<bool (char const*, bool)>, lookup_name_info const*, gdb::function_view<bool (char const*)>, gdb::function_view<bool (compunit_symtab*)>, enum_flags<block_search_flag_values>, domain_enum, search_domain) (read.c:18688)
==4113266==    by 0x5DD1EA: objfile::map_symtabs_matching_filename(char const*, char const*, gdb::function_view<bool (symtab*)>) (symfile-debug.c:207)
==4113266==    by 0x5F04CC: iterate_over_symtabs(char const*, gdb::function_view<bool (symtab*)>) (symtab.c:633)
==4113266==    by 0x477EE3: collect_symtabs_from_filename(char const*, program_space*) (linespec.c:3712)
==4113266==    by 0x477FC1: symtabs_from_filename(char const*, program_space*) (linespec.c:3726)
==4113266==    by 0x47A9B8: convert_explicit_location_spec_to_linespec(linespec_state*, linespec*, char const*, char const*, symbol_name_match_type, char const*, line_offset) (linespec.c:2329)
==4113266==    by 0x47E86E: convert_explicit_location_spec_to_sals (linespec.c:2388)
==4113266==    by 0x47E86E: location_spec_to_sals(linespec_parser*, location_spec const*) (linespec.c:3104)
==4113266==    by 0x47EDAC: decode_line_full(location_spec*, int, program_space*, symtab*, int, linespec_result*, char const*, char const*) (linespec.c:3149)
...

Without the fix, the top 10 leaks are:
./gdb/testsuite/outputs/gdb.base/condbreak-bad/gdb.log:345:==3213924==    definitely lost: 130,937 bytes in 5,409 blocks
./gdb/testsuite/outputs/gdb.base/hbreak2/gdb.log:619:==3758919==    definitely lost: 173,323 bytes in 7,204 blocks
./gdb/testsuite/outputs/gdb.mi/mi-var-cp/gdb.log:1320:==4152873==    definitely lost: 172,826 bytes in 7,207 blocks
./gdb/testsuite/outputs/gdb.base/advance-until-multiple-locations/gdb.log:398:==2992643==    definitely lost: 172,965 bytes in 7,211 blocks
./gdb/testsuite/outputs/gdb.mi/mi-var-cmd/gdb.log:2302:==4159476==    definitely lost: 173,129 bytes in 7,211 blocks
./gdb/testsuite/outputs/gdb.cp/gdb2384/gdb.log:222:==3811851==    definitely lost: 218,106 bytes in 7,761 blocks
./gdb/testsuite/outputs/gdb.cp/mb-templates/gdb.log:310:==3787344==    definitely lost: 290,311 bytes in 10,340 blocks
./gdb/testsuite/outputs/gdb.mi/mi-var-rtti/gdb.log:2568:==4158350==    definitely lost: 435,427 bytes in 15,507 blocks
./gdb/testsuite/outputs/gdb.mi/mi-catch-cpp-exceptions/gdb.log:1704:==4119722==    definitely lost: 435,405 bytes in 15,510 blocks
./gdb/testsuite/outputs/gdb.mi/mi-vla-fortran/gdb.log:768:==4113266==    definitely lost: 508,585 bytes in 18,109 blocks

With the fix:
./gdb/testsuite/outputs/gdb.base/fork-running-state/gdb.log:1536:==2924193==    indirectly lost: 13,848 bytes in 98 blocks
./gdb/testsuite/outputs/gdb.base/fork-running-state/gdb.log:1675:==2928777==    indirectly lost: 13,848 bytes in 98 blocks
./gdb/testsuite/outputs/gdb.python/py-inferior-leak/gdb.log:4729:==3353335==    definitely lost: 3,360 bytes in 140 blocks
./gdb/testsuite/outputs/gdb.base/kill-detach-inferiors-cmd/gdb.log:210:==2746927==    indirectly lost: 13,246 bytes in 154 blocks
./gdb/testsuite/outputs/gdb.base/inferior-clone/gdb.log:179:==3034984==    indirectly lost: 12,921 bytes in 161 blocks
./gdb/testsuite/outputs/gdb.base/interrupt-daemon/gdb.log:209:==3006248==    indirectly lost: 20,683 bytes in 174 blocks
./gdb/testsuite/outputs/gdb.threads/watchpoint-fork/gdb.log:714:==3512403==    indirectly lost: 20,707 bytes in 175 blocks
./gdb/testsuite/outputs/gdb.threads/watchpoint-fork/gdb.log:962:==3514498==    indirectly lost: 20,851 bytes in 178 blocks
./gdb/testsuite/outputs/gdb.base/multi-forks/gdb.log:336:==2585839==    indirectly lost: 53,630 bytes in 386 blocks
./gdb/testsuite/outputs/gdb.base/multi-forks/gdb.log:1338:==2592417==    indirectly lost: 100,008 bytes in 1,154 blocks

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-11-27 21:11:25 +01:00
..
abbrev-cache.c Introduce DWARF abbrev cache 2022-04-12 09:31:16 -06:00
abbrev-cache.h Add comments to dwarf2/abbrev-cache.h 2022-04-16 13:58:34 -06:00
abbrev.c Fix method naming bug in new DWARF indexer 2022-04-22 06:40:49 -06:00
abbrev.h Statically examine abbrev properties 2022-04-12 09:31:16 -06:00
attribute.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
attribute.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
comp-unit-head.c internal_error: remove need to pass __FILE__/__LINE__ 2022-10-19 15:32:36 +01:00
comp-unit-head.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
cooked-index.c [gdb/symtab] Add get/set functions for per_cu->lang/unit_type 2022-07-04 10:28:42 +02:00
cooked-index.h Fix incorrect .gdb_index with new DWARF scanner 2022-10-21 09:54:38 -06:00
cu.c Fix jump on uninit producer_is_clang bit of cu.h dwarf2_cu struct. 2022-11-26 12:43:58 +01:00
cu.h remove the declared but undefined/unused method find_partial_die 2022-11-26 12:42:41 +01:00
die.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
dwz.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
dwz.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
expr.c internal_error: remove need to pass __FILE__/__LINE__ 2022-10-19 15:32:36 +01:00
expr.h Change GDB to use frame_info_ptr 2022-10-10 11:57:10 +02:00
file-and-dir.h Add "fullname" handling to file_and_directory 2022-04-12 09:31:16 -06:00
frame-tailcall.c Change GDB to use frame_info_ptr 2022-10-10 11:57:10 +02:00
frame-tailcall.h Change GDB to use frame_info_ptr 2022-10-10 11:57:10 +02:00
frame.c gdb: remove spurious spaces after frame_info_ptr 2022-10-25 11:04:58 -04:00
frame.h gdb: remove spurious spaces after frame_info_ptr 2022-10-25 11:04:58 -04:00
index-cache.c Use gdb_bfd_ref_ptr in objfile 2022-08-03 13:26:58 -06:00
index-cache.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
index-common.c Add new overload of dwarf5_djb_hash 2022-04-12 09:31:16 -06:00
index-common.h Add new overload of dwarf5_djb_hash 2022-04-12 09:31:16 -06:00
index-write.c Fix incorrect .gdb_index with new DWARF scanner 2022-10-21 09:54:38 -06:00
index-write.h Rename write_psymtabs_to_index 2022-04-12 09:31:16 -06:00
leb.c internal_error: remove need to pass __FILE__/__LINE__ 2022-10-19 15:32:36 +01:00
leb.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
line-header.c gdbsupport: change path_join parameter to array_view<const char *> 2022-09-21 11:36:01 -04:00
line-header.h gdb: add "id" fields to identify symtabs and subfiles 2022-07-29 20:54:49 -04:00
loc.c PowerPC, fix support for printing the function return value for non-trivial values. 2022-11-14 16:22:37 -05:00
loc.h PowerPC, fix support for printing the function return value for non-trivial values. 2022-11-14 16:22:37 -05:00
macro.c gdb: Fix issue with Clang CLI macros 2022-11-03 14:08:17 +01:00
macro.h gdb: Fix issue with Clang CLI macros 2022-11-03 14:08:17 +01:00
mapped-index.h Fix crash when creating index from index 2022-05-04 08:38:05 -06:00
public.h Always use dwarf2_initialize_objfile 2022-04-21 12:18:25 -06:00
read.c Fix leak in the dwarf reader 2022-11-27 21:11:25 +01:00
read.h gdb: Fix issue with Clang CLI macros 2022-11-03 14:08:17 +01:00
sect-names.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
section.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
section.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
stringify.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
stringify.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
tag.h Fix .debug_names regression with new indexer 2022-04-29 13:16:44 -06:00