aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2024-10-25[gdb/testsuite] Fix some test-cases for check-read1 (gdb_test_lines)Tom de Vries7-88/+80
I ran the testsuite in an environment simulating a stressed system in combination with check-read1. This exposes a few more FAILs. Fix some by using gdb_test_lines, as well as related gdb_get_lines. Tested on x86_64-linux.
2024-10-24Add locking when reading BFD sectionsTom Tromey1-0/+23
This adds some per-BFD locking to gdb_bfd_map_section and gdb_bfd_get_full_section_contents. It turned out that the background DWARF reader could race with the auto-load code, because the reader might try to mmap a section when the main thread was trying to read in .debug_gdb_scripts. The current BFD threading model is that only BFD globals will be locked, so any multi-threaded use of a BFD has to be handled specially by the application. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31626 Reviewed-by: Kevin Buettner <kevinb@redhat.com>
2024-10-24Use gdb_bfd_get_full_section_contents in auto-load.cTom Tromey1-7/+4
This changes auto-load.c ot use gdb_bfd_get_full_section_contents. This shouldn't change any behavior, but makes it easier to add locking in a subsequent patch. Reviewed-by: Kevin Buettner <kevinb@redhat.com>
2024-10-23gdb/testsuite: introduce dwarf5 option to gdb_compileGuinevere Larsen5-5/+12
A few tests on the testsuite require dwarf5 to work. Up until now, the way to do this was to explicitly add the command line flag -gdwarf-5. This isn't very portable, in case a compiler requires a different flag to emit dwarf5. This commit adds a new option to gdb_compile that would be able to add the correct flag (if known) or error out in case we are unable to tell which flag to use. It also changes the existing tests to use this general option instead of hard coding -gdwarf-5. Reviewed-by: Keith Seitz <keiths@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2024-10-22Implement 'Object_SizeTom Tromey12-16/+254
This patch started as an attempt to allow the 'Size attribute to be applied to types, and not just objects. However, that turns out to be difficult due to the Ada semantcs of 'Size. In particular, Ada requires 'Size to denote the size of the representation of the value, so for example Boolean'Size must be 1. Implementing this properly requires information not readily available to gdb... and while we could synthesize this information in many cases, it also seemed to me that this wasn't strictly very useful when debugging. So instead, this patch adds support for the 'Object_Size attribute, which is somewhat closer to 'sizeof'. Note also that while 'Object_Size is defined for some dynamic types, I chose not to implement this here, as again this information is not readily available -- and I think it's preferable to error than to print something that might be incorrect. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-10-22[gdb/testsuite] Handle maint set dwarf synchronous off defaultTom de Vries3-3/+19
I ran the testsuite with a patch setting dwarf_synchronous to false by default, and ran into FAILs in test-cases gdb.dwarf2/dw2-inter-cu-error.exp and gdb.dwarf2/dw2-inter-cu-error-2.exp, because the expected DWARF errors did not show up as a result of the file command. Fix this by forcing "maint set dwarf synchronous on". Add the same in gdb.base/index-cache.exp, where this is also required. Tested on aarch64-linux.
2024-10-22[gdb/testsuite] Improve class name in gdb.dwarf2/self-spec.expTom de Vries1-3/+3
I ran into: ... (gdb) pipe maint print objfiles self-spec | grep c1^M name: c1^M canonical: c1^M qualified: c1^M [3] ((addrmap *) 0xfffedfc1f010)^M (gdb) FAIL: gdb.dwarf2/self-spec.exp: class c1 in cooked index ... Fix this by renaming the class from c1 to class1. Tested on aarch64-linux.
2024-10-22[gdb] Handle EINTR in run_under_shellTom de Vries1-1/+6
When building gdb with -O2 -fsanitize=thread and running test-case gdb.base/bg-exec-sigint-bp-cond.exp, I run into: ... (gdb) c&^M Continuing.^M (gdb) Quit^M (gdb) quit_count=1 ^M Breakpoint 2, foo () at bg-exec-sigint-bp-cond.c:23^M 23 return 0;^M FAIL: $exp: no force memory write: \ SIGINT does not interrupt background execution ... What happens is that: - the breakpoint hits - while evaluating the condition of the breakpoint, $_shell("kill -INT <pid-of-gdb>") is called, handled by run_under_shell - in run_under_shell, a vfork is issued - in the vfork child, execl executes the kill command - in the vfork parent, waitpid is called to wait for the result of the kill command - waitpid returns -1 with errno set to EINTR - run_under_shell doesn't check the result of waitpid, and returns the value of local variable status. Since waitpid returned -1, status was not assigned a value, so it's uninitialized, and happens to be non-zero - the breakpoint condition evaluates to true, because $_shell("kill -INT <pid-of-gdb>") != 0 - the breakpoint triggers a stop, which the test-case doesn't expect. Fix this by using gdb::handle_eintr to call waitpid in run_under_shell. Also handle the case that waitpid returns an error other than EINTR, using perror_with_name. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR gdb/30695 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30695
2024-10-21[gdb/symtab] Fix incorrect filenames with inter-CU refsTom de Vries3-6/+118
With target board unix we get: ... $ gdb -q -batch outputs/gdb.cp/cplusfuncs/cplusfuncs \ -ex "info function operator\*" All functions matching regular expression "operator\*": File /home/vries/gdb/src/gdb/testsuite/gdb.cp/cplusfuncs.cc: 72: void foo::operator*(foo&); 85: void foo::operator*=(foo&); ... but with target board cc-with-dwz-m: ... All functions matching regular expression "operator\*": File /usr/lib/gcc/aarch64-redhat-linux/14/include/stddef.h: 72: void foo::operator*(foo&); 85: void foo::operator*=(foo&); ... The first operator: ... $ c++filt _ZN3foomlERS_ foo::operator*(foo&) ... matches address 0x410250 which is defined here in the CU in the exec: ... <1><10f1>: Abbrev Number: 13 (DW_TAG_subprogram) <10f2> DW_AT_specification: <alt 0x93> <10f6> DW_AT_decl_line : 72 <10f7> DW_AT_decl_column : 7 <10f7> DW_AT_object_pointer: <0x1106> <10f9> DW_AT_low_pc : 0x410250 <1101> DW_AT_high_pc : 32 <1102> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <1104> DW_AT_call_all_calls: 1 ... and declared here in the PU in the .dwz file: ... <2><93>: Abbrev Number: 20 (DW_TAG_subprogram) <94> DW_AT_external : 1 <94> DW_AT_name : operator* <98> DW_AT_decl_file : 2 <98> DW_AT_decl_line : 10 <99> DW_AT_decl_column : 9 <9a> DW_AT_linkage_name: _ZN3foomlERS_ <9e> DW_AT_accessibility: 1 (public) <9e> DW_AT_declaration : 1 <9e> DW_AT_object_pointer: <0xa2> ... When creating a new symbol for the operator, the DW_AT_decl_file attribute is looked up, and found to be 2. The 2 is supposed to be mapped using the PU, which has this file name table: ... The File Name Table (offset 0x78, lines 3, columns 2): Entry Dir Name 0 0 <dwz> 1 1 stddef.h 2 2 cplusfuncs.cc ... Instead, it's mapped using the CU, which has this file name table: ... The File Name Table (offset 0x34, lines 3, columns 2): Entry Dir Name 0 1 cplusfuncs.cc 1 1 cplusfuncs.cc 2 2 stddef.h ... This is PR symtab/30814. There's a similar PR for lto, PR symtab/25771, where the same problem happens for two CUs. Fix this by using the correct file name table. Add a dwarf assembly test-case for PR25771. Tested on aarch64-linux. Reviewed-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25771 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30814
2024-10-21[gdb/contrib] Handle dot in spellcheck.shTom de Vries7-38/+52
Add handling of '.' in gdb/contrib/spellcheck.sh. While we're at, simplify the sed invocation by using a single s command instead of 3 s commands. Also introduce sed_join and grep_join. Fix the following common misspellings: ... bandwith -> bandwidth emmitted -> emitted immediatly -> immediately suprize -> surprise thru -> through transfered -> transferred ... Verified with shellcheck.
2024-10-21[gdb/contrib] Speed up spellcheck.sh --checkTom de Vries1-15/+34
Speed up gdb/contrib/shellcheck.sh by caching the grep pattern. Without cached grep pattern: ... $ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c real 0m2,750s user 0m0,013s sys 0m0,032s ... and with cached grep pattern: ... $ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c real 0m0,192s user 0m0,022s sys 0m0,024s ... Tested on aarch64-linux.
2024-10-21[gdb/contrib] Add spellcheck.sh --checkTom de Vries1-1/+18
Add a new option --check to gdb/contrib/spellcheck.sh, to do the spell check and bail out ASAP with an exit code of 1 if misspelled words were found, or 0 otherwise. Verified with shellcheck.
2024-10-21gdb/guile: add get-basic-typeAndrew Burgess4-1/+29
A question was asked on stackoverflow.com about the guile function get-basic-type[1] which is mentioned in the docs along with an example of its use. The problem is, the function was apparently never actually added to GDB. But it turns out that it's pretty easy to implement, so lets add it now. Better late than never. The implementation mirrors the Python get_basic_type function. I've added a test which is a copy of the documentation example. One issue is that the docs suggest that the type will be returned as just "int", however, I'm not sure what this actually means. It makes more sense that the function return a gdb:type object which would be represented as "#<gdb:type int>", so I've updated the docs to show this output. [1] https://stackoverflow.com/questions/79058691/unbound-variable-get-basic-type-in-gdb-guile-session Reviewed-By: Kevin Buettner <kevinb@redhat.com>
2024-10-21[gdb/build, c++20] Fix more deprecated implicit capture of thisTom de Vries2-3/+3
When building gdb with -std=c++20 I run into: ... gdb/dwarf2/cooked-index.c: In lambda function: gdb/dwarf2/cooked-index.c:471:47: error: implicit capture of ‘this’ via \ ‘[=]’ is deprecated in C++20 [-Werror=deprecated] 471 | gdb::thread_pool::g_thread_pool->post_task ([=] () | ^ gdb/dwarf2/cooked-index.c:471:47: note: add explicit ‘this’ or ‘*this’ capture ... Fix this and two more spots by removing the capture default, and explicitly listing all captures. Tested on x86_64-linux.
2024-10-20gdb: fix 'maint info inline-frames' after 'stepi'Andrew Burgess2-7/+44
There is an invalid assumption within 'maint info inline-frames' which triggers an assert: (gdb) stepi 0x000000000040119d 18 printf ("Hello World\n"); (gdb) maintenance info inline-frames ../../src/gdb/inline-frame.c:554: internal-error: maintenance_info_inline_frames: Assertion `it != inline_states.end ()' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- ... etc ... The problem is this assert: /* Stopped threads always have cached inline_state information. */ gdb_assert (it != inline_states.end ()); If you check out infrun.c and look in handle_signal_stop for the call to skip_inline_frames then you'll find a rather large comment that explains that we don't always compute the inline state information for performance reasons. So the assertion is not valid. I've updated the code so that if there is cached information we use that, but if there is not then we just create our own information for the current $pc of the current thread. This means that, if there is cached information, GDB still correctly shows which frame the inferior is in (it might not be in the inner most frame). If there is no cached information we will always display the inferior as being in the inner most frame, but that's OK, because if skip_inline_frames has not been called then GDB will have told the user they are in the inner most frame, so everything lines up. I've extended the test to check 'maint info inline-frames' after a stepi which would previously have triggered the assertion.
2024-10-20Use std::make_unique in more placesTom Tromey11-31/+35
I searched for spots using ".reset (new ...)" and replaced most of these with std::make_unique. I think this is a bit cleaner and more idiomatic. Regression tested on x86-64 Fedora 40. Reviewed-By: Klaus Gerlicher<klaus.gerlicher@intel.com>
2024-10-19Capture the current directory and debug directory in DWARF readerTom Tromey2-7/+18
This changes the DWARF reader to capture the current working directory and the current debug directory. This avoids races when the DWARF reader is working in the background. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31716
2024-10-19Add cwd paramter to openpTom Tromey2-5/+8
This patch adds a cwd paramter to openp, so that the current directory can be passed in by the caller. This is useful when background threads call this function -- they can then avoid using the global and thus avoid races with the user using "cd". Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31716
2024-10-19[gdbsupport] Add gdb::array_view::{iterator,const_iterator}Tom de Vries1-0/+36
While trying to substitute some std::vector type A in the code with a gdb::array_view: ... - using A = std::vector<T> + using A = gdb::array_view<T> .... I ran into the problem that the code was using A::iterator while gdb::array_view doesn't define such a type. Fix this by: - adding types gdb::array_view::iterator and gdb::array_view::const_iterator, - using them in gdb::array_view::(c)begin and gdb::array_view::(c)end, as is usual, and - using them explicitly in a unit test. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-19[gdb/guile, c++20] Work around Werror=volatile in libguile.hTom de Vries1-1/+8
When building gdb with -std=c++20, I run into: ... In file included from /usr/include/guile/2.0/libguile/__scm.h:479, from /usr/include/guile/2.0/libguile.h:31, from /data/vries/gdb/src/gdb/guile/guile-internal.h:30, from /data/vries/gdb/src/gdb/guile/guile.c:37: /usr/include/guile/2.0/libguile/gc.h: In function ‘scm_unused_struct* \ scm_cell(scm_t_bits, scm_t_bits)’: /usr/include/guile/2.0/libguile/tags.h:98:63: error: using value of \ assignment with ‘volatile’-qualified left operand is deprecated \ [-Werror=volatile] 98 | # define SCM_UNPACK(x) ((scm_t_bits) (0? (*(volatile SCM *)0=(x)): x)) | ~~~~~~~~~~~~~~~~~~~^~~~~ ... This was reported upstream [1]. Work around this by using SCM_DEBUG_TYPING_STRICTNESS == 0 instead of the default SCM_DEBUG_TYPING_STRICTNESS == 1. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR guile/30767 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30767 [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65333
2024-10-19[gdb/symtab] Skip local variables in cooked indexTom de Vries3-7/+66
Consider test-case gdb.dwarf2/local-var.exp. The corresponding source contains a function with a local variable: ... program test logical :: local_var local_var = .TRUE. end ... Currently, the local variable shows up in the cooked index: ... [2] ((cooked_index_entry *) 0xfffec40063b0) name: local_var canonical: local_var qualified: local_var DWARF tag: DW_TAG_variable flags: 0x2 [IS_STATIC] DIE offset: 0xa3 parent: ((cooked_index_entry *) 0xfffec4006380) [test] ... making the cooked index larger than necessary. Fix this by skipping it in cooked_indexer::index_dies. Tested on aarch64-linux. PR symtab/32276 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32276
2024-10-18Require a command argument in gdb.execute_miTom Tromey2-0/+11
Hannes pointed out that gdb.execute_mi() will crash. This patch fixes the bug. Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2024-10-18[gdb] Handle bad alloc handling in gdb_bfd_openTom de Vries1-7/+8
Say we simulate a bad alloc in gdb_bfd_init_data: ... + { + static bool throw_bad_alloc = true; + if (throw_bad_alloc) + { + throw_bad_alloc = false; + + va_list dummy; + throw gdb_quit_bad_alloc (gdb_exception_quit ("bad alloc", dummy)); + } + } gdata = new gdb_bfd_data (abfd, st); ... That works out fine for doing "file a.out" once: ... $ gdb -q -batch -ex "file a.out" bad alloc $ ... but doing so twice get us: ... $ gdb -q -batch -ex "file a.out" -ex "file a.out" bad alloc Fatal signal: Segmentation fault ----- Backtrace ----- 0x5183f7 gdb_internal_backtrace_1 /home/vries/gdb/src/gdb/bt-utils.c:121 0x5183f7 _Z22gdb_internal_backtracev /home/vries/gdb/src/gdb/bt-utils.c:167 0x62329b handle_fatal_signal /home/vries/gdb/src/gdb/event-top.c:917 0x6233ef handle_sigsegv /home/vries/gdb/src/gdb/event-top.c:990 0xfffeffba483f ??? 0x65554c eq_bfd /home/vries/gdb/src/gdb/gdb_bfd.c:231 0xeaca77 htab_find_with_hash /home/vries/gdb/src/libiberty/hashtab.c:597 0x657487 _Z12gdb_bfd_openPKcS0_ib /home/vries/gdb/src/gdb/gdb_bfd.c:580 0x6272d7 _Z16exec_file_attachPKci /home/vries/gdb/src/gdb/exec.c:451 0x627e67 exec_file_command /home/vries/gdb/src/gdb/exec.c:550 0x627f23 file_command /home/vries/gdb/src/gdb/exec.c:565 Segmentation fault (core dumped) $ ... The problem is in gdb_bfd_open, where we insert abfd into gdb_bfd_cache: ... if (bfd_sharing) { slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT); gdb_assert (!*slot); *slot = abfd; } gdb_bfd_init_data (abfd, &st); ... while the bad alloc means that gdb_bfd_init_data is interrupted and abfd is not properly initialized. Fix this by reversing the order, inserting abfd into gdb_bfd_cache only after a successful call to gdb_bfd_init_data, such that we get: ... $ gdb -q -batch -ex "file a.out" -ex "file a.out" bad alloc $ ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-18[gdb/symtab] Fix qualified name for cooked index dumpTom de Vries2-6/+13
While looking at the cooked index entry for local variable l4 of function test in test-case gdb.fortran/logical.exp: ... $ gdb -q -batch outputs/gdb.fortran/logical/logical \ -ex "maint print objfiles" ... [9] ((cooked_index_entry *) 0x7fc6e0003010) name: l4 canonical: l4 qualified: l4 DWARF tag: DW_TAG_variable flags: 0x2 [IS_STATIC] DIE offset: 0x17c parent: ((cooked_index_entry *) 0x7fc6e0002f20) [test] ... I noticed that while the entry does have a parent, that's not reflected in the qualified name. This makes it harder to write test-cases that check the parent of a cooked index entry. This is due to the implementation of full_name, which skips printing parents if the language does not specify an appropriate separator. Fix this by using "::" as default separator, getting us instead: ... [9] ((cooked_index_entry *) 0x7f94ec0040c0) name: l4 canonical: l4 qualified: test::l4 DWARF tag: DW_TAG_variable flags: 0x2 [IS_STATIC] DIE offset: 0x17c parent: ((cooked_index_entry *) 0x7f94ec003fd0) [test] ... Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-17[gdb/testsuite] Fix gdb.ada/fixed_points.exp for gcc < 10Tom de Vries1-1/+1
When running test-case gdb.ada/fixed_points.exp with system gcc 7, I run into: ... (gdb) PASS: gdb.ada/fixed_points.exp: scenario=all: print fp4_var / 1 get_compiler_info: gcc-7-5-0 p Float(Another_Fixed) = Float(Another_Delta * 5)^M No definition of "another_delta" in current context.^M (gdb) FAIL: gdb.ada/fixed_points.exp: scenario=all: value of another_fixed ... This is a regression since commit 1411185a57e ("Introduce and use gnat_version_compare"), which did: ... # This failed before GCC 10. - if {$scenario == "all" && [test_compiler_info {gcc-10-*}]} { + if {$scenario == "all" && [gnat_version_compare < 10]} { gdb_test "p Float(Another_Fixed) = Float(Another_Delta * 5)" "true" \ "value of another_fixed" } ... Fix this by using gnat_version_compare >= 10 instead. Tested on x86_64-linux, with gcc 7 - 13.
2024-10-17Add myself to gdb/MAINTAINERSkamathforaix1-0/+1
2024-10-15Introduce and use gnat_version_compareTom Tromey15-25/+55
While testing a modified GNAT, I found that this test in fun_renaming.exp was returning 0 for GCC 13: if {[test_compiler_info {gcc-6*}]} This patch introduces a new, more robust way to check the GNAT compiler version, and changes the gda.ada tests to use it. A small update to version_compare was also needed. Note that, in its current form, this new code won't really interact well with non-GCC compilers (specifically gnat-llvm). This doesn't seem like a major issue at this point, though, because gnat-llvm doesn't properly emit debuginfo yet, and when it does, more changes will be needed in these tests anyway. Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-10-14gdb/testsuite: fix gdb.multi/inferior-specific-bp.expGuinevere Larsen1-1/+2
A recent commit, "16a6f7d2ee3 gdb: avoid breakpoint::clear_locations calls in update_breakpoint_locations", started checking if GDB correctly relocates a breakpoint from inferior 1's declaration of the function "bar" to inferior 2's declaration. Unfortunately, inferior 2 never calls bar in its regular execution, and because of that, clang would optimize that whole function away, making it so there is no location for the breakpoint to be relocated to. This commit changes the .c file so that the function is not optimized away and the test fully passes with clang. It is important to actually call bar instead of using __attribute__((used)) because the latter causes the breakpoint locations to be inverted, 3.1 belongs to inferior 2 and 3.2 belongs to inferior 1, which will cause an unrelated failure. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-10-14gdb: make frame_unwind_try_unwinder return boolGuinevere Larsen1-6/+6
Before this commit, the function frame_unwind_try_unwinder would return an int, where 1 meant the unwinder works, and 0 it doesn't. This is just a boolean with extra steps, so this commit updates the function to return bool instead.
2024-10-12Add to GDB manual information about building index with 'gold'Robert Guthrie1-0/+13
* gdb/doc/gdb.texinfo (Index Files): New subsection about building the index using 'gold'. Copyright-paperwork-exempt: yes
2024-10-10gdb/gdbserver: change shared set_tdesc_osabi to take gdb_osabiAndrew Burgess12-18/+46
There is a single declaration of set_tdesc_osabi that is shared between gdbserver/ and gdb/, this declaration takes a 'const char *' argument which is the string representing an osabi. Then in gdb/ we have an overload of set_tdesc_osabi which takes an 'enum gdb_osabi'. In this commit I change the shared set_tdesc_osabi to be the version which takes an 'enum gdb_osabi', and I remove the version which takes a 'const char *'. All users of set_tdesc_osabi are updated to pass an 'enum gdb_osabi'. The features/ code, which is generated from the xml files, requires a new function to be added to osabi.{c,h} which can return a string representation of an 'enum gdb_osabi'. With that new function in place the features/ code is regenerated. This change is being made to support the next commit. In the next commit gdbserver will be updated to call set_tdesc_osabi in more cases. The problem is that gdbserver stores the osabi as a string. The issue here is that a typo in the gdbserver/ code might go unnoticed and result in gdbserver sending back an invalid osabi string. To fix this we want gdbserver to pass an 'enum gdb_osabi' to the set_tdesc_osabi function. With that requirement in place it seems to make sense if all calls to set_tdesc_osabi pass an 'enum gdb_osabi'. There should be no user visible changes after this commit. Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-10gdb: split osabi support between gdb/ and gdbsupport/ directoriesAndrew Burgess2-131/+1
In future commits I want to call set_tdesc_osabi from gdbserver/ code. Currently the only version of set_tdesc_osabi available to gdbserver takes a string representing the osabi. The problem with this is that, having lots of calls to set_tdesc_osabi which all take a string is an invite for a typo to slip in. This typo could potentially go unnoticed until someone tries to debug the wrong combination of GDB and gdbserver, at which point GDB will fail to find the correct gdbarch because it doesn't understand the osabi string. It would be better if the set_tdesc_osabi calls in gdbserver could take an 'enum gdb_osabi' value and then convert this to the "correct" string internally. In this way we are guaranteed to always have a valid, known, osabi string. This commit splits the osabi related code, which currently lives entirely on the GDB side, between gdb/ and gdbsupport/. I've moved the enum definition along with the array of osabi names into gdbsupport/. Then all the functions that access the names list, and which convert between names and enum values are also moved. I've taken the opportunity of this move to add a '.def' file which contains all the enum names along with the name strings. This '.def' file is then used to create 'enum gdb_osabi' as well as the array of osabi name strings. By using a '.def' file we know that the enum order will always match the name string array. This commit is just a refactor, there are no user visible changes after this commit. This commit doesn't change how gdbserver sets the target description osabi string, that will come in the next commit. Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-10gdb: make use of set_tdesc_osabi overload in features/ filesAndrew Burgess6-6/+6
There are two versions of the set_tdesc_osabi function in GDB: void set_tdesc_osabi (struct target_desc *target_desc, const char *name) { set_tdesc_osabi (target_desc, osabi_from_tdesc_string (name)); } void set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi) { target_desc->osabi = osabi; } In the gdb/features/ files we call the second of these functions, like this: set_tdesc_osabi (result.get (), osabi_from_tdesc_string ("GNU/Linux")); This can be replaced with a call to the first set_tdesc_osabi function, so lets do that. I think that this makes the features/ code slightly simpler and easier to understand. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-10[gdb/breakpoints] Fix gdb.base/scope-hw-watch-disable.exp on arm-linuxTom de Vries2-47/+71
On arm-linux, with test-case gdb.base/scope-hw-watch-disable.exp I run into: ... (gdb) awatch a^M Can't set read/access watchpoint when hardware watchpoints are disabled.^M (gdb) PASS: $exp: unsuccessful attempt to create an access watchpoint rwatch b^M Can't set read/access watchpoint when hardware watchpoints are disabled.^M (gdb) PASS: $exp: unsuccessful attempt to create a read watchpoint continue^M Continuing.^M ^M Program received signal SIGSEGV, Segmentation fault.^M 0xf7ec82c8 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6^M (gdb) FAIL: $exp: continue until exit ... Using "maint info break", we can see that the two failed attempts to set a watchpoint each left behind a stale "watchpoint scope" breakpoint: ... -5 watchpoint scope del y 0xf7ec569a inf 1 -5.1 y 0xf7ec569a inf 1 stop only in stack frame at 0xfffef4f8 -6 watchpoint scope del y 0xf7ec569a inf 1 -6.1 y 0xf7ec569a inf 1 stop only in stack frame at 0xfffef4f8 ... The SIGSEGV is a consequence of the stale "watchpoint scope" breakpoint: the same happens if we: - have can-use-hw-watchpoints == 1, - set one of the watchpoints, and - continue to exit. The problem is missing symbol info on libc which is supposed to tell which code is thumb. After doing "set arm fallback-mode thumb" the SIGSEGV disappears. Extend the test-case to check the "maint info break" command before and after the two failed attempts, to make sure that we catch the stale "watchpoint scope" breakpoints also on x86_64-linux. Fix this in watch_command_1 by moving creation of the "watchpoint scope" breakpoint after the call to update_watchpoint. Tested on x86_64-linux. PR breakpoints/31860 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31860
2024-10-10[gdb/testsuite] Fix gdb.dwarf2/enum-type-c++.exp with clangTom de Vries2-31/+78
When running test-case gdb.dwarf2/enum-type-c++.exp with clang, we get: ... FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent FAIL: gdb.dwarf2/enum-type-c++.exp: print ns::A::val1 FAIL: gdb.dwarf2/enum-type-c++.exp: val2 has correct parent FAIL: gdb.dwarf2/enum-type-c++.exp: print ns::ec::val2 ... The problem is that the debug info produced by clang does not contain any references to enumerators val1 and val2, or the corresponding enumeration types. Instead, the variables u1 and u2 are considered to be simply of type int: ... <1><fb>: Abbrev Number: 2 (DW_TAG_variable) <fc> DW_AT_name : u1 <fd> DW_AT_type : <0x106> <101> DW_AT_external : 1 <103> DW_AT_location : (DW_OP_addrx <0>) <1><106>: Abbrev Number: 3 (DW_TAG_base_type) <107> DW_AT_name : int <108> DW_AT_encoding : 5 (signed) <109> DW_AT_byte_size : 4 <1><10a>: Abbrev Number: 2 (DW_TAG_variable) <10b> DW_AT_name : u2 <10c> DW_AT_type : <0x106> <110> DW_AT_external : 1 <112> DW_AT_location : (DW_OP_addrx <0x1>) ... Fix this by checking whether val1 and val2 are present in the cooked index before checking whether they have the correct parent. This cannot be expressed efficiently with gdb_test_lines, so factor out gdb_get_lines and use that instead. The test-case still calls "maint print objfiles" twice, but the first time is for have_index. We should probably use a gdb_caching_proc for this. Tested on aarch64-linux. Reported-By: Guinevere Larsen <guinevere@redhat.com> Reviewed-By: Keith Seitz <keiths@redhat.com> Tested-By: Guinevere Larsen <guinevere@redhat.com>
2024-10-10[gdb/testsuite] Fix some gdb.dwarf2 test-cases for check-read1Tom de Vries5-6/+15
I ran the testsuite in an environment simulating a stressed system in combination with check-read1. This exposes a few more FAILs. Fix the gdb.dwarf2 ones by using pipe / grep to filter out unnecessary output. Tested on x86_64-linux.
2024-10-09[gdb/testsuite] Fix gdb.base/reggroups.exp with check-read1Tom de Vries1-7/+21
On aarch64-linux, with make target check-read1, I run into: ... (gdb) info reg vector^M ... d19 {f = 0x0, u = 0x0, s = 0x0} {f =FAIL: gdb.base/reggroups.exp: fetch reggroup regs vector (timeout) 0, u = 0, s = 0}^M ... The problem is that while (as documented) the corresponding gdb_test_multiple doesn't work for vector registers, it doesn't skip them either. This causes the timeout, and it also causes the registers after a vector register not to be found. Fix this by using -lbl style matching. Make which reggroups and registers are found more explicit using verbose -log, which makes us notice that regnames with underscores are skipped, so fix that as well. While we're at it, this: ... set invalid_register_re "Invalid register .*" ... and this: ... -re $invalid_register_re { fail "$test (unexpected invalid register response)" } ... means that the prompt may or may not be consumed. Fix this by limiting the regexp to one line, and using exp_continue. While we're at it, improve readability of the complex regexp matching a single register by factoring out regexps. Tested on aarch64-linux and x86_64-linux.
2024-10-08Use ui-out tables in "maint print user-regs"Tom Tromey2-3/+13
This changes "maint print user-regs" to use ui-out tables rather than printfs. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-10-08Use ui-out tables for info proc mappingsTom Tromey3-103/+76
This changes a few implementations of "info proc mappings" to use ui-out tables rather than printf. Note that NetBSD and FreeBSD also use printfs here, but since I can't test these, I didn't update them. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-10-08[gdb/testsuite] Fix gdb.base/break-interp.exp with check-read1Tom de Vries1-17/+5
When running test-case gdb.base/break-interp.exp with check-read1, I run into: ... (gdb) info files^M ... 0x00007ffff7e75980 - 0x00007ffff7e796a0 @ 0x001f1970 is .bss in /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.base/break-interp/break-interp-BINprelinkNOdebugNOFAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=NO: binpie=NO: INNER: symbol-less: info files (timeout) pieNO.d/libc.so.6^M ... The code has two adaptations to deal with the large output: - nested gdb_test_multiple, and - an exp_continue in the inner gdb_test_multiple. The former seems unnecessary, and the latter doesn't trigger often enough because of an incomplete hex number regexp, causing the timeout. Get rid of both of these, and use -lbl instead. Tested on x86_64-linux.
2024-10-08gdb: include --enable-targets in 'show configuration' outputAndrew Burgess4-2/+23
Include the value of configuration flag --enable-targets in the output of GDB command 'show configuration' and also in the output printed for 'gdb --configuration'. This will make it easier to see how GDB was built. No tests added or updated as we can't really check for a specific flag appearing or not appearing on the configuration output. But we do print the configuration within lib/gdb.exp to check which features are built into GDB, so if this change broke configuration printing then plenty of tests should stop working (they don't). Approved-By: Tom Tromey <tom@tromey.com>
2024-10-08gdb: avoid breakpoint::clear_locations calls in update_breakpoint_locationsAndrew Burgess5-29/+121
The commit: commit 6cce025114ccd0f53cc552fde12b6329596c6c65 Date: Fri Mar 3 19:03:15 2023 +0000 gdb: only insert thread-specific breakpoints in the relevant inferior added a couple of calls to breakpoint::clear_locations() inside update_breakpoint_locations(). The intention of these calls was to avoid leaving redundant locations around when a thread- or inferior-specific breakpoint was switched from one thread or inferior to another. Without the clear_locations() calls the tests gdb.multi/tids.exp and gdb.multi/pending-bp.exp have some failures. A b/p is changed such that the program space it is associated with changes. This triggers a call to breakpoint_re_set_one() but the FILTER_PSPACE argument will be the new program space. As a result GDB correctly calculates the new locations and adds these to the breakpoint, but the old locations, in the old program space, are incorrectly retained. The call to clear_locations() solves this by deleting the old locations. However, while working on another patch I realised that the approach taken here is not correct. The FILTER_PSPACE argument passed to breakpoint_re_set_one() and then on to update_breakpoint_locations() might not be the program space to which the breakpoint is associated. Consider this example: (gdb) file /tmp/hello.x Reading symbols from /tmp/hello.x... (gdb) start Temporary breakpoint 1 at 0x401198: file hello.c, line 18. Starting program: /tmp/hello.x Temporary breakpoint 1, main () at hello.c:18 18 printf ("Hello World\n"); (gdb) break main thread 1 Breakpoint 2 at 0x401198: file hello.c, line 18. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y 0x0000000000401198 in main at hello.c:18 stop only in thread 1 (gdb) add-inferior -exec /tmp/hello.x [New inferior 2] Added inferior 2 on connection 1 (native) Reading symbols from /tmp/hello.x... (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y <PENDING> main stop only in thread 1.1 Notice that after creating the second inferior and loading a file the thread-specific breakpoint was incorrectly made pending. Loading the exec file in the second inferior triggered a call to breakpoint_re_set() with the new, second, program space as the current_program_space. This program space ends up being passed to update_breakpoint_locations(). In update_breakpoint_locations this condition is true: if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) and so we end up discarding all of the locations for this breakpoint, making the breakpoint pending. What we really want to do in update_breakpoint_locations() is, for thread- or inferior- specific breakpoints, delete any locations which are associated with a program space that this breakpoint is NOT associated with. But then I realised the answer was easier than that. The ONLY time that a b/p can have locations associated with the "wrong" program space like this is at the moment we change the thread or inferior the b/p is associated with by calling breakpoint_set_thread() or breakpoint_set_inferior(). And so, I think the correct solution is to hoist the call to clear_locations() out of update_breakpoint_locations() and place a call in each of the breakpoint_set_{thread,inferior} functions. I've done this, and added a couple of new tests. All of which are now passing. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-08[gdb/testsuite] Fix gdb.ada/tagged-lookup.exp with read1+readnowTom de Vries1-6/+2
When running test-case gdb.ada/tagged-lookup.exp with target board readnow and make target check-read1: ... $ ( cd build/gdb; \ make check-read1 \ RUNTESTFLAGS="--target_board=readnow gdb.ada/tagged-lookup.exp" ) ... I run into: ... (gdb) PASS: gdb.ada/tagged-lookup.exp: set debug symtab-create 1 print *the_local_var^M $1 = (n => 2)^M (gdb) FAIL: gdb.ada/tagged-lookup.exp: only one CU expanded ... The problem is that the corresponding gdb_test_multiple uses line-by-line matching (using -lbl) which doesn't work well with the multiline pattern matching both the prompt and the line before it: ... -re -wrap ".* = \\\(n => $decimal\\\)" { ... Fix this by making it a one-line pattern: ... -re -wrap "" { ... While we're at it, replace an if-then-pass-else-fail with a gdb_assert. Tested on aarch64-linux.
2024-10-08[gdb/symtab] Fix gdb.dwarf2/enum-type-c++.exp with cc-with-debug-typesTom de Vries2-3/+5
When running test-case gdb.dwarf2/enum-type-c++.exp with target board cc-with-debug-types, we run into: ... (gdb) FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent ... because val1 has no parent: ... [31] ((cooked_index_entry *) 0x7efedc002e90) name: val1 canonical: val1 qualified: val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0xef parent: ((cooked_index_entry *) 0) ... [37] ((cooked_index_entry *) 0x38ffd280) name: val1 canonical: val1 qualified: val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0xef parent: ((cooked_index_entry *) 0) ... There are two entries, which seems to be an inefficiency, but for now let's focus on the correctness issue. The debug info for val1 looks like this: ... <1><cb>: Abbrev Number: 2 (DW_TAG_namespace) <cc> DW_AT_name : ns <cf> DW_AT_declaration : 1 <2><d3>: Abbrev Number: 12 (DW_TAG_class_type) <d4> DW_AT_name : A <d6> DW_AT_declaration : 1 <3><d6>: Abbrev Number: 13 (DW_TAG_enumeration_type) <db> DW_AT_declaration : 1 <1><dd>: Abbrev Number: 14 (DW_TAG_enumeration_type) <e7> DW_AT_specification: <0xd6> <2><ef>: Abbrev Number: 5 (DW_TAG_enumerator) <f0> DW_AT_name : val1 <f4> DW_AT_const_value : 1 ... Fix this by: - adding a cooked index entry for DIE 0xcb (and consequently for child DIE 0xd3), by marking it interesting, - making sure that the entry for DIE 0xcb has a name, and - using the entry for DIE 0xd3 as parent entry for DIE 0xdd. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-08[gdb/symtab] Fix parent of enumeratorTom de Vries2-10/+52
As mentioned in commit 489b82720f5 ('[gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF scanner"'), when doing "maint print objfiles" in test-case gdb.dwarf2/enum-type.exp, for val1 we get an entry without parent: ... [27] ((cooked_index_entry *) 0x7fbbb4002ef0) name: val1 canonical: val1 qualified: val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0x124 parent: ((cooked_index_entry *) 0) ... This happens here in cooked_indexer::index_dies: ... info_ptr = recurse (reader, info_ptr, is_enum_class ? this_entry : parent_entry, fully); ... when we're passing down a nullptr parent_entry, while the parent of this_entry is deferred. Fix this in cooked_indexer::index_dies by passing down a deffered parent instead, such that we get: ... [27] ((cooked_index_entry *) 0x7ff0e4002ef0)^M name: val1^M canonical: val1^M qualified: ns::val1^M DWARF tag: DW_TAG_enumerator^M flags: 0x0 []^M DIE offset: 0x124^M parent: ((cooked_index_entry *) 0x7ff0e4002f20) [ns]^M ... Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-08[gdb/contrib] Fix "sofar->so far" misspellingTom de Vries3-2/+3
I forgot to follow up on a review comment and fix the "sofar->so far" misspelling [1]. Fix this by adding it to gdb/contrib/common-misspellings.txt. Tested on x86_64-linux. [1] https://sourceware.org/pipermail/gdb-patches/2024-September/211894.html
2024-10-08[gdb/contrib] Add more separators in spellcheck.shTom de Vries7-8/+52
Add two more separators in spellcheck.sh: colon and comma. Doing so triggers the "inbetween->between" rule, which gives an incorrect result. Override this with "inbetween->between, in between, in-between" [1], in a new file gdb/contrib/common-misspellings.txt. Fix the following common misspellings: ... everytime -> every time sucess -> success thru -> through transfered -> transferred inbetween -> between, in between, in-between ... Verified with spellcheck.sh. Tested on x86_64-linux. [1] https://www.grammarly.com/blog/commonly-confused-words/in-between-or-inbetween/
2024-10-08[gdb/contrib] Factor out grep_or and sed_or in spellcheck.shTom de Vries1-2/+41
While trying to add more separators here: ... # Separators: space, slash, tab. grep_separator=" |/| " sed_separator=" \|/\|\t" ... I mistakingly used "|" instead of "\|" in sed_separator. Factor out new variables grep_or and sed_or, and construct the grep_separator and sed_separator variables by joining the elements of a list using grep_or and sed_or. Verified with shellcheck, and tested by rerunning on x86_64-linux. Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2024-10-07[gdb/testsuite] Fix gdb.python/py-inferior.exp with -fsanitize=threadTom de Vries2-2/+4
With a gdb build with -fsanitize=thread, and test-case gdb.python/py-inferior.exp I run into: ... (gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff)^M ERROR: ThreadSanitizer: requested allocation size 0xffffffffffffffff exceeds \ maximum supported size of 0x10000000000^M ... There's already a workaround for this using ASAN_OPTIONS, and apparently the same is needed for TSAN_OPTIONS. Add the allocator_may_return_null=1 workaround also in TSAN_OPTIONS. Likewise in gdb.dap/memory.exp. Tested on x86_64-linux.
2024-10-06gdb/m2: add builtin procedure function ADRGaius Mulley3-1/+41
This patch introduces ADR to the Modula-2 language interface. It return the address of the parameter supplied. The patch also contains a dejagnu test for ADR. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>