aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
AgeCommit message (Collapse)AuthorFilesLines
2023-12-13gdb: improve error reporting for 'save gdb-index'Andrew Burgess1-1/+9
While making recent changes to 'save gdb-index' command I triggered some errors -- of the kind a user might be expected to trigger if they do something wrong -- and I didn't find GDB's output as helpful as it might be. For example: $ gdb -q /tmp/hello.x ... (gdb) save gdb-index /non_existing_dir Error while writing index for `/tmp/hello': mkstemp: No such file or directory. That the error message mentions '/tmp/hello', which does exist, but doesn't mention '/non_existing_dir', which doesn't is, I think, confusing. Also, I find the 'mkstemp' in the error message confusing for a user facing error. A user might not know what mkstemp means, and even if they do, that it appears in the error message is an internal GDB detail. The user doesn't care what function failed, but wants to know what was wrong with their input, and what they should do to fix things. Similarly, for a directory that does exist, but can't be written to: (gdb) save gdb-index /no_access_dir Error while writing index for `/tmp/hello': mkstemp: Permission denied. In this case, the 'Permission denied' might make the user thing there is a permissions issue with '/tmp/hello', which is not the case. After this patch, the new errors are: (gdb) save gdb-index /non_existing_dir Error while writing index for `/tmp/hello': `/non_existing_dir': No such file or directory. and: (gdb) save gdb-index /no_access_dir Error while writing index for `/tmp/hello': `/no_access_dir': Permission denied. we also have: (gdb) save gdb-index /tmp/not_a_directory Error while writing index for `/tmp/hello': `/tmp/not_a_directory': Is not a directory. I think these do a better job of guiding the user towards fixing the problem. I've added a new test that exercises all of these cases, and also checks the case where a user tries to use an executable that already contains an index in order to generate an index. As part of the new test I've factored out some code from ensure_gdb_index (lib/gdb.exp) into a new proc (get_index_type), which I've then used in the new test. I've confirmed that all the tests that use ensure_gdb_index still pass. During review it was pointed out that the testsuite proc have_index (lib/gdb.exp) is similar to the new get_index_type proc, so I've rewritten have_index to also use get_index_type, I've confirmed that all the tests that use have_index still pass. Nothing that worked correctly before this patch should give an error after this patch; I've only changed the output when the user was going to get an error anyway. Reviewed-By: Tom de Vries <tdevries@suse.de> Reviewed-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-12-06Remove quick_symbol_functions::expand_matching_symbolsTom Tromey3-290/+0
The only caller of quick_symbol_functions::expand_matching_symbols was removed, so now this method and all implementations of it can be removed.
2023-12-06Always use expand_symtabs_matching in ada-lang.cTom Tromey1-1/+5
The previous patch fixed the immediate performance problem with Ada name matching, by having a subset of matches call expand_symtabs_matching rather than expand_matching_symbols. However, it seemed to me that expand_matching_symbols should not be needed at all. To achieve this, this patch changes ada_lookup_name_info::split_name to use the decoded name, rather than the encoded name. In order to make this work correctly, a new decoded form is used: one that does not decode operators (this is already done) and also does not decode wide characters. The latter change is done so that changes to the Ada source charset don't affect the DWARF index. With this in place, we can change ada-lang.c to always use expand_symtabs_matching rather than expand_matching_symbols.
2023-12-06[gdb/symtab] Redo "Fix assert in set_length"Tom de Vries via Gdb-patches3-108/+114
This reverts commit 1c04f72368c ("[gdb/symtab] Fix assert in set_length"), due to a regression reported in PR29572, and implements a different fix for PR29453. The fix is to not use the CU table in a .debug_names section to construct all_units, but instead use create_all_units, and then verify the CU table from .debug_names. This also fixes PR25969, so remove the KFAIL. Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29572 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25969
2023-12-05Fix off-by-one error in compute_delayed_physnamesTom Tromey1-1/+1
compute_delayed_physnames does this: size_t len = strlen (physname); ... if (physname[len] == ')') /* shortcut */ break; However, physname[len] will always be \0. This patch changes it to the correct len-1.
2023-11-29Remove gdb_static_assertTom Tromey2-3/+3
C++17 makes the second parameter to static_assert optional, so we can remove gdb_static_assert now.
2023-11-29Use try_emplace in index-write.cTom Tromey1-16/+9
index-write.c has a comment indicating that C++17's try_emplace could be used. This patch makes the change. Approved-By: Pedro Alves <pedro@palves.net>
2023-11-29Use C++17 [[fallthrough]] attributeTom Tromey2-13/+13
This changes gdb to use the C++17 [[fallthrough]] attribute rather than special comments. This was mostly done by script, but I neglected a few spellings and so also fixed it up by hand. I suspect this fixes the bug mentioned below, by switching to a standard approach that, presumably, clang supports. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159 Approved-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-28gdb: generate dwarf-5 index identically as worker-thread count changesAndrew Burgess1-2/+15
Similar to the previous commit, this commit ensures that the dwarf-5 index files are generated identically as the number of worker-threads changes. Building the dwarf-5 index makes use of a closed hash table, the bucket_hash local within debug_names::build(). Entries are added to bucket_hash from m_name_to_value_set, which, in turn, is populated by calls to debug_names::insert() in write_debug_names. The insert calls are ordered based on the entries within the cooked_index, and the ordering within cooked_index depends on the number of worker threads that GDB is using. My proposal is to sort each chain within the bucket_hash closed hash table prior to using this to build the dwarf-5 index. The buckets within bucket_hash will always have the same ordering (for a given GDB build with a given executable), and by sorting the chains within each bucket, we can be sure that GDB will see each entry in a deterministic order. I've extended the index creation test to cover this case. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-28gdb: generate gdb-index identically regardless of work thread countAndrew Burgess1-0/+69
It was observed that changing the number of worker threads that GDB uses (maintenance set worker-threads NUM) would have an impact on the layout of the generated gdb-index. The cause seems to be how the CU are distributed between threads, and then symbols that appear in multiple CU can be encountered earlier or later depending on whether a particular CU moves between threads. I certainly found this behaviour was reproducible when generating an index for GDB itself, like: gdb -q -nx -nh -batch \ -eiex 'maint set worker-threads NUM' \ -ex 'save gdb-index /tmp/' And then setting different values for NUM will change the generated index. Now, the question is: does this matter? I would like to suggest that yes, this does matter. At Red Hat we generate a gdb-index as part of the build process, and we would ideally like to have reproducible builds: for the same source, compiled with the same tool-chain, we should get the exact same output binary. And we do .... except for the index. Now we could simply force GDB to only use a single worker thread when we build the index, but, I don't think the idea of reproducible builds is that strange, so I think we should ensure that our generated indexes are always reproducible. To achieve this, I propose that we add an extra step when building the gdb-index file. After constructing the initial symbol hash table contents, we will pull all the symbols out of the hash, sort them, then re-insert them in sorted order. This will ensure that the structure of the generated hash will remain consistent (given the same set of symbols). I've extended the existing index-file test to check that the generated index doesn't change if we adjust the number of worker threads used. Given that this test is already rather slow, I've only made one change to the worker-thread count. Maybe this test should be changed to use a smaller binary, which is quicker to load, and for which we could then try many different worker thread counts. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-28gdb: C++-ify mapped_symtab from dwarf2/index-write.cAndrew Burgess1-46/+92
Make static the functions add_index_entry, find_slot, and hash_expand, member functions of the mapped_symtab class. Fold an additional snippet of code from write_gdbindex into mapped_symtab::minimize, this code relates to minimisation, so this seems like a good home for it. Make the n_elements, data, and m_string_obstack member variables of mapped_symtab private. Provide a new obstack() member function to provide access to the obstack when needed, and also add member functions begin(), end(), cbegin(), and cend() so that the mapped_symtab class can be treated like a contained and iterated over. I've also taken this opportunity to split out the logic for whether the hash table (m_data) needs expanding, this is the new function hash_needs_expanding. This will be useful in a later commit. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-28gdb: reduce size of generated gdb-index fileAndrew Burgess1-10/+19
I noticed in passing that out algorithm for generating the gdb-index file is incorrect. When building the hash table in add_index_entry we count every incoming entry rehash when the number of entries gets too large. However, some of the incoming entries will be duplicates, which don't actually result in new items being added to the hash table. As a result, we grow the gdb-index hash table far too often. With an unmodified GDB, generating a gdb-index for GDB, I see a file size of 90M, with a hash usage (in the generated index file) of just 2.6%. With a patched GDB, generating a gdb-index for the _same_ GDB binary, I now see a gdb-index file size of 30M, with a hash usage of 41.9%. This is a 67% reduction in gdb-index file size. Obviously, not every gdb-index file is going to see such big savings, however, the larger a program, and the more symbols that are duplicated between compilation units, the more GDB would over count, and so, over-grow the index. The gdb-index hash table we create has a minimum size of 1024, and then we grow the hash when it is 75% full, doubling the hash table at that time. Given this, then we expect that either: a. The hash table is size 1024, and less than 75% full, or b. The hash table is between 37.5% and 75% full. I've include a test that checks some of these constraints -- I've not bothered to check the upper limit, and over full hash table isn't really a problem here, but if the fill percentage is less than 37.5% then this indicates that we've done something wrong (obviously, I also check for the 1024 minimum size). Approved-By: Tom Tromey <tom@tromey.com>
2023-11-28gdb: option completion for 'save gdb-index' commandAndrew Burgess1-17/+52
Add proper support for option completion to the 'save gdb-index' command. Update save_gdb_index_command function to make use of the new option_def data structures for parsing the '-dwarf-5' option. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-28gdb: allow use of ~ in 'save gdb-index' commandAndrew Burgess1-2/+5
Add a call to gdb_tilde_expand in the save_gdb_index_command function, this means that we can now do: (gdb) save gdb-index ~/blah/ Previous this wouldn't work. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-21Use enum accessibility in types and member functionsTom Tromey1-4/+4
This changes nested types and member functions to use the new 'accessibility' enum, rather than separate private/protected flags. This is done for consistency, but it also lets us simplify some other code in the next patch. Acked-By: Simon Marchi <simon.marchi@efficios.com> Reviewed-by: Keith Seitz <keiths@redhat.com>
2023-11-21Remove byte vectors from cplus_struct_typeTom Tromey1-70/+16
This removes some byte vectors from cplus_struct_type, moving the information into bitfields in holes in struct field. A new 'enum accessibility' is added to hold some of this information. A similar enum is removed from c-varobj.c. Note that the stabs reader treats "ignored" as an accessibility. However, the stabs texinfo documents this as a public field that is optimized out -- unfortunately nobody has updated the stabs reader to use the better value-based optimized-out machinery. I looked and apparently gcc never emitted this visibility value, so whatever compiler generated this stab is unknown. I left a comment in gdbtypes.h to this effect. Acked-By: Simon Marchi <simon.marchi@efficios.com> Reviewed-by: Keith Seitz <keiths@redhat.com>
2023-11-21gdb: Use initializers in lambda captures unconditionallyLancelot Six1-6/+1
Initializers in lambda captures were introduced in C++14, and conditionally used in gdb/cp-support.c and gdb/dwarf2/cooked-index.c. Since C++17 is now required by GDB, use this feature unconditionally. Change-Id: I87a3d567941e5c71217538fa75c952e4d421fa1d Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Remove uses of gdb::to_string (const std::string_view &)Lancelot Six1-2/+1
This patch removes all uses of to_string(const std::string_view&) and use the std::string ctor or implicit conversion from std::string_view to std::string instead. A later patch will remove this gdb::to_string while removing gdbsupport/gdb_string_view.h. Change-Id: I877cde557a0727be7b0435107e3c7a2aac165895 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Use std::string_view instead of gdb::string_viewLancelot Six5-7/+8
Given that GDB now requires a C++17, replace all uses of gdb::string_view with std::string_view. This change has mostly been done automatically: - gdb::string_view -> std::string_view - #include "gdbsupport/gdb_string_view.h" -> #include <string_view> One things which got brought up during review is that gdb::stging_view does support being built from "nullptr" while std::sting_view does not. Two places are manually adjusted to account for this difference: gdb/tui/tui-io.c:tui_getc_1 and gdbsupport/format.h:format_piece::format_piece. The above automatic change transformed "gdb::to_string (const gdb::string_view &)" into "gdb::to_string (const std::string_view &)". The various direct users of this function are now explicitly including "gdbsupport/gdb_string_view.h". A later patch will remove the users of gdb::to_string. The implementation and tests of gdb::string_view are unchanged, they will be removed in a following patch. Change-Id: Ibb806a7e9c79eb16a55c87c6e41ad396fecf0207 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Replace gdb::optional with std::optionalLancelot Six11-31/+31
Since GDB now requires C++17, we don't need the internally maintained gdb::optional implementation. This patch does the following replacing: - gdb::optional -> std::optional - gdb::in_place -> std::in_place - #include "gdbsupport/gdb_optional.h" -> #include <optional> This change has mostly been done automatically. One exception is gdbsupport/thread-pool.* which did not use the gdb:: prefix as it already lives in the gdb namespace. Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Use C++17's std::make_unique instead of gdb::make_uniqueLancelot Six4-4/+4
gdb::make_unique is a wrapper around std::make_unique when compiled with C++17. Now that C++17 is required, use std::make_unique directly in the codebase, and remove gdb::make_unique. Change-Id: I80b615e46e4b7c097f09d78e579a9bdce00254ab Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net
2023-11-17Remove extraneous blocks from dwarf2/read.c:new_symbolTom Tromey1-43/+41
dwarf2/read.c:new_symbol has some extra braces in a couple of 'case's. These read weirdly to me, and since they aren't necessary, this patch removes the braces and reindents the bodies. Tested by rebuilding.
2023-11-05Pre-read DWZ file in DWARF readerTom Tromey3-14/+29
While working on background reading of DWARF, I came across the DWZ-reading code. This code can query the user (via the debuginfod support) -- something that cannot be done off the main thread. Looking into it, I realized that this code can be run much earlier, avoiding this problem. Digging a bit deeper, I also found a discrepancy here between how the DWARF reader works in "readnow" mode as compared to the normal modes. This patch cleans this up by trying to read the DWZ file earlier, and also by having the DWARF reader convert any exception here into a warning. This unifies the various cases, but also makes it so that errors do not prevent gdb from continuing on to the extent possible. Regression tested on x86-64 Fedora 38.
2023-11-01[gdb/symtab] Work around gas PR28629Tom de Vries3-1/+38
When running test-case gdb.tui/tui-layout-asm-short-prog.exp on AlmaLinux 9.2 ppc64le, I run into: ... FAIL: gdb.tui/tui-layout-asm-short-prog.exp: check asm box contents ... The problem is that we get: ... 7 [ No Assembly Available ] ... because tui_get_begin_asm_address doesn't succeed. In more detail, tui_get_begin_asm_address calls: ... find_line_pc (sal.symtab, sal.line, &addr); ... with: ... (gdb) p *sal.symtab $5 = {next = 0x130393c0, m_compunit = 0x130392f0, m_linetable = 0x0, filename = "tui-layout-asm-short-prog.S", filename_for_id = "$gdb/build/gdb/testsuite/tui-layout-asm-short-prog.S", m_language = language_asm, fullname = 0x0} (gdb) p sal.line $6 = 1 ... The problem is the filename_for_id which is the source file prefixed with the compilation dir rather than the source dir. This is due to faulty debug info generated by gas, PR28629: ... <1a> DW_AT_name : tui-layout-asm-short-prog.S <1e> DW_AT_comp_dir : $gdb/build/gdb/testsuite <22> DW_AT_producer : GNU AS 2.35.2 ... The DW_AT_name is relative, and it's relative to the DW_AT_comp_dir entry, making the effective name $gdb/build/gdb/testsuite/tui-layout-asm-short-prog.S. The bug is fixed starting version 2.38, where we get instead: ... <1a> DW_AT_name : $gdb/src/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.S <1e> DW_AT_comp_dir : $gdb/build/gdb/testsuite <22> DW_AT_producer : GNU AS 2.38 ... Work around the faulty debug info by constructing the filename_for_id using the second directory from the directory table in the .debug_line header: ... The Directory Table (offset 0x22, lines 2, columns 1): Entry Name 0 $gdb/build/gdb/testsuite 1 $gdb/src/gdb/testsuite/gdb.tui ... Note that the used gas contains a backport of commit 3417bfca676 ("GAS: DWARF-5: Ensure that the 0'th entry in the directory table contains the current working directory."), because directory 0 is correct. With the unpatched 2.35.2 release the directory 0 entry is incorrect: it's a copy of entry 1. Add a dwarf assembly test-case that reflects the debug info as generated by unpatched gas 2.35.2. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-01[gdb/symtab] Add producer_is_gasTom de Vries1-2/+2
Add producer_is_gas, a generic way to get the gas version from the producer string. Tested on x86_64-linux.
2023-10-29Move read_addrmap_from_aranges to new fileTom Tromey5-186/+237
In the interest of shrinking dwarf2/read.c a little more, this patch moves the code that deciphers .debug_aranges into a new file. Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
2023-10-29Pre-read .debug_aranges sectionTom Tromey2-5/+7
While working on background DWARF reading, I found a race case that I tracked down to the handling of the .debug_aranges section. Currently the section data is only read in after the CUs have all been created. However, there's no real reason to do this -- it seems fine to read it a little earlier, when all the other necessary sections are read in. This patch makes this change, and updates the read_addrmap_from_aranges API to assert that the section is read in. This patch slightly changes the read_addrmap_from_aranges API as well, to reject an empty section. This seems better to me than what the current code does, which is try to read an empty section but then do no work. Regression tested on x86-64 Fedora 38. Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
2023-10-20Don't include cooked-index.h from dwarf2/read.hTom Tromey2-1/+1
dwarf2/read.h includes cooked-index.h, but it doesn't need to. This patch removes the inclusion from this header, and adds one to index-write.c to make up for the absence.
2023-10-20[gdb/symtab] Fix more style issues in v9 .gdb_index section supportTom de Vries4-8/+8
I noticed a few more style issues in commit 8b9c08eddac ("[gdb/symtab] Add name_of_main and language_of_main to the DWARF index"), after checking it with gcc's check_GNU_style.{sh,py}. Fix these. Build on x86_64-linux.
2023-10-19Fix race in DWARF readerTom Tromey3-25/+41
The recent change to record the DWARF language in the per-CU data yielded a race warning in my testing: ThreadSanitizer: data race ../../binutils-gdb/gdb/dwarf2/read.c:21779 in prepare_one_comp_unit This patch fixes the bug by applying the same style of fix that was done for the ordinary (gdb) language. I wonder if this code could be improved. Requiring an atomic for the language in particular seems unfortunate, as it is often consulted during index finalization. However, I haven't investigated this. Regression tested on x86-64 Fedora 38. Reviewed-by: Tom de Vries <tdevries@suse.de>
2023-10-18[gdb/symtab] Fix two style issues in gdb/dwarf2/index-write.cTom de Vries1-3/+3
While reviewing gdb/dwarf2/index-write.c I noticed two style issues. Fix these. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-18[gdb/symtab] Fix style issues in v9 .gdb_index section supportTom de Vries4-15/+15
Post-commit review pointed out a few style issues in commit 8b9c08eddac ("[gdb/symtab] Add name_of_main and language_of_main to the DWARF index"). Fix these. Tested on x86_64-linux. Reported-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-16[gdb/symtab] Work around PR gas/29517Tom de Vries3-0/+25
When using glibc debuginfo generated with gas 2.39, we run into PR gas/29517: ... $ gdb -q -batch a.out -ex start -ex "p (char *)strstr (\"haha\", \"ah\")" Temporary breakpoint 1 at 0x40051b: file hello.c, line 6. Temporary breakpoint 1, main () at hello.c:6 6 printf ("hello\n"); Invalid cast. ... while without glibc debuginfo installed we get the expected result: ... $n = 0x7ffff7daa1b1 "aha" ... and likewise with glibc debuginfo generated with gas 2.40. The strstr ifunc resolves to __strstr_sse2_unaligned. The problem is that gas generates dwarf that states that the return type is void: ... <1><3e1e58>: Abbrev Number: 2 (DW_TAG_subprogram) <3e1e59> DW_AT_name : __strstr_sse2_unaligned <3e1e5d> DW_AT_external : 1 <3e1e5e> DW_AT_low_pc : 0xbbd2e <3e1e66> DW_AT_high_pc : 0xbc1c3 ... while the return type should be a DW_TAG_unspecified_type, as is the case with gas 2.40. We can still use the workaround of casting to another function type for both __strstr_sse2_unaligned: ... (gdb) p ((char * (*) (const char *, const char *))__strstr_sse2_unaligned) \ ("haha", "ah") $n = 0x7ffff7daa211 "aha" ... and strstr (which requires using *strstr to dereference the ifunc before we cast): ... gdb) p ((char * (*) (const char *, const char *))*strstr) ("haha", "ah") $n = 0x7ffff7daa251 "aha" ... but that's a bit cumbersome to use. Work around this in the dwarf reader, such that we have instead: ... (gdb) p (char *)strstr ("haha", "ah") $n = 0x7ffff7daa1b1 "aha" ... This also requires fixing producer_is_gcc to stop returning true for producer "GNU AS 2.39.0". Tested on x86_64-linux. Approved-By: Andrew Burgess <aburgess@redhat.com> PR symtab/30911 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30911
2023-10-10[gdb/symtab] Add name_of_main and language_of_main to the DWARF indexMatheus Branco Borella4-11/+122
This patch adds a new section to the DWARF index containing the name and the language of the main function symbol, gathered from `cooked_index::get_main`, if available. Currently, for lack of a better name, this section is called the "shortcut table". The way this name is both saved and applied upon an index being loaded in mirrors how it is done in `cooked_index_functions`, more specifically, the full name of the main function symbol is saved and `set_objfile_main_name` is used to apply it after it is loaded. The main use case for this patch is in improving startup times when dealing with large binaries. Currently, when an index is used, GDB has to expand symtabs until it finds out what the language of the main function symbol is. For some large executables, this may take a considerable amount of time to complete, slowing down startup. This patch bypasses that operation by having both the name and language of the main function symbol be provided ahead of time by the index. In my testing (a binary with about 1.8GB worth of DWARF data) this change brings startup time down from about 34 seconds to about 1.5 seconds. When testing the patch with target board cc-with-gdb-index, test-case gdb.fortran/nested-funcs-2.exp starts failing, but this is due to a pre-existing issue, filed as PR symtab/30946. Tested on x86_64-linux, with target board unix and cc-with-gdb-index. PR symtab/24549 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24549 Approved-By: Tom de Vries <tdevries@suse.de>
2023-09-20Remove explanatory comments from includesTom Tromey1-2/+2
I noticed a comment by an include and remembered that I think these don't really provide much value -- sometimes they are just editorial, and sometimes they are obsolete. I think it's better to just remove them. Tested by rebuilding. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-20[gdb/symtab] Error out for .debug_types section in dwz fileTom de Vries4-0/+15
There are two methods to factor out type information in a dwarf4 executable: - use -fdebug-info-types to generate type units in a .debug_types section, and - use dwz to create partial units. The dwz method has an extra benefit: it also allows to factor out information between executables into a newly created .dwz file, pointed to by a .gnu_debugaltlink section. There is nothing prohibiting a .gnu_debugaltlink file to contain a .debug_types section. It's just not generated by dwz or any other tool atm, and consequently gdb has no support for it. Enhancement PR symtab/30838 is open about the lack of support. Make the current situation explicit by emitting a dwarf error: ... (gdb) file struct-with-sig-2^M Reading symbols from struct-with-sig-2...^M Dwarf Error: .debug_types section not supported in dwz file^M ... and add an assert in write_gdbindex: ... + /* See enhancement PR symtab/30838. */ + gdb_assert (!(per_cu->is_dwz && per_cu->is_debug_types)); ... to clarify why we can use: ... data_buf &cu_list = (per_cu->is_debug_types ? types_cu_list : per_cu->is_dwz ? dwz_cu_list : objfile_cu_list); ... The test-case is a modified copy from gdb.dwarf2/struct-with-sig.exp, so it keeps the copyright years range. Tested on x86_64-linux. Tested-By: Guinevere Larsen <blarsen@redhat.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30838
2023-09-19Give a language to a typeTom Tromey1-32/+29
This changes main_type to hold a language, and updates the debug readers to set this field. This is done by adding the language to the type-allocator object. Note that the non-DWARF readers are changed on a "best effort" basis. This patch also reimplements type::is_array_like to use the type's language, and it adds a new type::is_string_like as well. This in turn lets us change the Python implementation of these methods to simply defer to the type.
2023-09-19Regularize some DWARF type initializationTom Tromey1-11/+13
In one spot, it will be convenient for a subsequent patch if the CU is passed to a type-creation helper function. In another spot, remove the redundant 'objfile' parameter to another such function.
2023-09-19Pass a type allocator to init_fixed_point_typeTom Tromey1-2/+2
init_fixed_point_type currently takes an objfile and creates its own type allocator. However, for a later patch it is more convenient if this function accepts a type allocator. This patch makes this change.
2023-09-16[gdb/symtab] Fix overly large gdb-index file check for 32-bitTom de Vries1-2/+82
Add a unit test which checks that write_gdb_index_1 will throw an error when the size of the file would exceed the maximum value capable of being represented by 'offset_type'. The unit test fails on 32-bit systems due to wrapping overflow. Fix this by changing the type of total_len in write_gdbindex_1 from size_t to uint64_t. Tested on x86_64-linux. Co-Authored-By: Kevin Buettner <kevinb@redhat.com> Approved-by: Kevin Buettner <kevinb@redhat.com>
2023-09-15Rename split_style::DOTTom Tromey1-1/+1
This renames split_style::DOT, to avoid name clashes when building gdb with an old version of Bison (2.3, the version available on macOS). In particular the error looks like: ./split-name.h:34:3: error: expected identifier DOT, ^ m2-exp.c:163:13: note: expanded from macro 'DOT' Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30286
2023-09-14Throw error when creating an overly large gdb-index fileKevin Buettner1-1/+8
The header in a .gdb_index section uses 32-bit unsigned offsets to refer to other areas of the section. Thus, there is a size limit of 2^32-1 which is currently unaccounted for by GDB's code for outputting these sections. At the moment, when GDB creates an overly large section, it will exit abnormally due to an internal error, which is caused by a failed assert in assert_file_size, which in turn is called from write_gdbindex_1, both of which are in gdb/dwarf2/index-write.c. This is what happens when that assert fails: $ gdb -q -nx -iex 'set auto-load no' -iex 'set debuginfod enabled off' -ex file ./libgraph_tool_inference.so -ex "save gdb-index `pwd`/" Reading symbols from ./libgraph_tool_inference.so... No executable file now. Discard symbol table from `libgraph_tool_inference.so'? (y or n) n Not confirmed. ../../gdb/dwarf2/index-write.c:1069: internal-error: assert_file_size: Assertion `file_size == expected_size' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- 0x55fddb4d78b0 gdb_internal_backtrace_1 ../../gdb/bt-utils.c:122 0x55fddb4d78b0 _Z22gdb_internal_backtracev ../../gdb/bt-utils.c:168 0x55fddb98b5d4 internal_vproblem ../../gdb/utils.c:396 0x55fddb98b8de _Z15internal_verrorPKciS0_P13__va_list_tag ../../gdb/utils.c:476 0x55fddbb71654 _Z18internal_error_locPKciS0_z ../../gdbsupport/errors.cc:58 0x55fddb5a0f23 assert_file_size ../../gdb/dwarf2/index-write.c:1069 0x55fddb5a1ee0 assert_file_size /usr/include/c++/13/bits/stl_iterator.h:1158 0x55fddb5a1ee0 write_gdbindex_1 ../../gdb/dwarf2/index-write.c:1119 0x55fddb5a51be write_gdbindex ../../gdb/dwarf2/index-write.c:1273 [...] --------------------- ../../gdb/dwarf2/index-write.c:1069: internal-error: assert_file_size: Assertion `file_size == expected_size' failed. This problem was encountered while building the python-graph-tool package on Fedora. The Fedora bugzilla bug can be found here: https://bugzilla.redhat.com/show_bug.cgi?id=1773651 This commit prevents the internal error from occurring by calling error() when the file size exceeds 2^32-1. Using a gdb built with this commit, I now see this behavior instead: $ gdb -q -nx -iex 'set auto-load no' -iex 'set debuginfod enabled off' -ex file ./libgraph_tool_inference.so -ex "save gdb-index `pwd`/" Reading symbols from ./libgraph_tool_inference.so... No executable file now. Discard symbol table from `/mesquite2/fedora-bugs/1773651/libgraph_tool_inference.so'? (y or n) n Not confirmed. Error while writing index for `/mesquite2/fedora-bugs/1773651/libgraph_tool_inference.so': gdb-index maximum file size of 4294967295 exceeded (gdb) I wish I could provide a test case, but due to the sizes of both the input and output files, I think that testing resources would be strained or exceeded in many environments. My testing on Fedora 38 shows no regressions. Approved-by: Tom Tromey <tom@tromey.com>
2023-09-14gdb: fix buffer overflow in DWARF readerAndrew Burgess1-1/+1
In this commit: commit 48ac197b0c209ccf1f2de9704eb6cdf7c5c73a8e Date: Fri Nov 19 10:12:44 2021 -0700 Handle multiple addresses in call_site_target a buffer overflow bug was introduced when the following code was added: CORE_ADDR *saved = XOBNEWVAR (&objfile->objfile_obstack, CORE_ADDR, addresses.size ()); std::copy (addresses.begin (), addresses.end (), saved); The definition of XOBNEWVAR is (from libiberty.h): #define XOBNEWVAR(O, T, S) ((T *) obstack_alloc ((O), (S))) So 'saved' is going to point to addresses.size () bytes of memory, however, the std::copy will write addresses.size () number of CORE_ADDR sized entries to the address pointed to by 'saved', this is going to result in memory corruption. The mistake is that we should have used XOBNEWVEC, which allocates a vector of entries, the definition of XOBNEWVEC is: #define XOBNEWVEC(O, T, N) \ ((T *) obstack_alloc ((O), sizeof (T) * (N))) Which means we will have set aside enough space to create a copy of the contents of the addresses vector. I'm not sure how to create a test for this problem, this issue cropped up when debugging a particular i686 built binary, which just happened to trigger a glibc assertion (likely due to random memory corruption), debugging the same binary built for x86-64 appeared to work just fine. Using valgrind on the failing GDB binary pointed straight to the cause of the problem, and with this patch in place there are no longer valgrind errors in this area. If anyone has ideas for a test I'm happy to work on something. Co-Authored-By: Keith Seitz <keiths@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-07[gdb/symtab] Fix gdb-index writing for .debug_typesTom de Vries1-7/+3
With test-case gdb.ada/same_enum.exp and target board dwarf4-gdb-index we run into: ... (gdb) print red^M No definition of "red" in current context.^M (gdb) FAIL: gdb.ada/same_enum.exp: print red ... [ This is a regression since commit 844a72efbce ("Simplify gdb_index writing"), so this is broken in gdb 12 and 13. ] The easiest way to see what's going wrong is with readelf. We have in section .gdb_index: ... [7194] pck__red: 2 [static, variable] 3 [static, variable] ... which points to the CUs 2 and 3 in the CU list (shown using "2" and "3"), but should be pointing to the TUs 2 and 3 in the TU list (shown using "T2" and "T3"). Fix this by removing the counter / types_counter distinction in write_gdbindex, such that we get the expected: ... [7194] pck__red: T2 [static, variable] T3 [static, variable] ... [ While reading write_gdbindex I noticed a few oddities related to dwz handling, I've filed PR30829 about this. ] Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR symtab/30827 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30827
2023-09-05Introduce TYPE_SPECIFIC_RUST_STUFFTom Tromey1-1/+8
This adds a new enum constant, TYPE_SPECIFIC_RUST_STUFF, and changes the DWARF reader to set this on Rust types. This will be used as a flag in a later patch. Note that the size of the type_specific_field bitfield had to be increased. I checked that this did not impact the size of main_type.
2023-09-05Avoid crash with Ada and -fdata-sectionsTom Tromey1-1/+2
A user noticed that gdb would crash when showing a backtrace. Investigation showed this to be a crash in the DWARF reader when handling a "pragma export" symbol. The bug here is that earlier code decides to eliminate the symbol, but the export code tries to add it anyway -- but to a NULL list.
2023-08-31gdb: remove FIELD_BITSIZESimon Marchi1-1/+1
Replace with field::bitsize. Change-Id: I400be235d6a1f446d0a4aafac01df5e850185d3a Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31gdb: introduce field::bitsize / field::set_bitsizeSimon Marchi1-8/+4
Add these two methods, rename the field to m_bitsize to make it pseudo private. Change-Id: Ief95e5cf106e72f2c22ae47b033d0fa47202b413 Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31gdb: remove TYPE_FIELD_ARTIFICIALSimon Marchi1-4/+4
Replace with type::field + field::is_artificial. Change-Id: Ie3bacae49d9bd02e83e504c1ce01470aba56a081 Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31gdb: introduce field::is_artificial / field::set_is_artificialSimon Marchi1-7/+7
Add these two methods, rename the field to m_artificial to make it pseudo private. Change-Id: If3a3825473d1d79bb586a8a074b87bba9b43fb1a Approved-By: Tom Tromey <tom@tromey.com>