aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2024-04-19gdb: Document qIsAddressTagged packetGustavo Romero2-3/+44
This commit documents the qIsAddressTagged packet. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Reviewed-by: Eli Zaretskii <eliz@gnu.org> Approved-By: Eli Zaretskii <eliz@gnu.org>
2024-04-19gdb/testsuite: Add unit tests for qIsAddressTagged packetGustavo Romero1-0/+67
Add unit tests for testing qIsAddressTagged packet request creation and reply checks. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-04-19gdb: Add qIsAddressTagged packetGustavo Romero1-0/+75
This commit adds a new packet, qIsAddressTagged, allowing GDB remote targets to use it to query the stub if a given address is tagged. Currently, the memory tagging address check is done via a read query, where the contents of /proc/<PID>/smaps is read and the flags are inspected for memory tagging-related flags that indicate the address is in a memory tagged region. This is not ideal, for example, for QEMU stub and other cases, such as on bare-metal, where there is no notion of an OS file like 'smaps.' Hence, the introduction of qIsAddressTagged packet allows checking if an address is tagged in an agnostic way. The is_address_tagged target hook in remote.c attempts to use the qIsAddressTagged packet first for checking if an address is tagged and if the stub does not support such a packet (reply is empty) it falls back to using the current mechanism that reads the contents of /proc/<PID>/smaps via vFile requests. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-04-19gdb: Introduce is_address_tagged target hookGustavo Romero13-25/+100
This commit introduces a new target hook, target_is_address_tagged, which is used instead of the gdbarch_tagged_address_p gdbarch hook in the upper layer (printcmd.c). This change enables easy specialization of memory tagging address check per target in the future. As target_is_address_tagged continues to utilize the gdbarch_tagged_address_p hook, there is no change in behavior for all the targets that use the new target hook (i.e., the remote.c, aarch64-linux-nat.c, and corelow.c targets). Just the gdbarch_tagged_address_p signature is changed for convenience, since target_is_address_tagged takes the address to be checked as a CORE_ADDR type. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-04-19gdb: Use passed gdbarch instead of calling current_inferiorGustavo Romero1-1/+1
In do_examine function, use passed gdbarch when checking if an address is tagged instead of calling current_inferior()->arch() to make the code more localized and help modularity by not calling a current_* function, which disguises the use of a global state/variable. There is no change in the code behavior. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Suggested-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-04-19gdb: aarch64: Remove MTE address checking from memtag_matches_pGustavo Romero1-4/+0
This commit removes aarch64_linux_tagged_address_p from aarch64_linux_memtag_matches_p. aarch64_linux_tagged_address_p checks if an address is tagged (MTE) or not. The check is redundant because aarch64_linux_memtag_matches_p is always called from the upper layers (i.e. from printcmd.c via gdbarch hook gdbarch_memtag_matches_p) after either gdbarch_tagged_address_p (that already points to aarch64_linux_tagged_address_p) has been called or after should_validate_memtags (that calls gdbarch_tagged_address_p at the end) has been called, so the address is already checked. Hence: a) in print_command_1, gdbarch_memtag_matches_p is called only after should_validate_memtags is called, which checks the address at its end; b) in memory_tag_check_command, gdbarch_memtag_matches_p is called only after gdbarch_tagged_address_p is called directly. Also, because after this change the address checking only happens at the upper layer it now allows the address checking to be specialized easily per target, via a target hook. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-04-19gdb: aarch64: Move MTE address check out of set_memtagGustavo Romero2-9/+5
Remove check in parse_set_allocation_tag_input as it is redundant: currently the check happens at the end of parse_set_allocation_tag_input and also in set_memtag (called after parse_set_allocation_tag_input). After it, move MTE address check out of set_memtag and add this check to the upper layer, before set_memtag is called. This is a preparation for using a target hook instead of a gdbarch hook on MTE address checks. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Approved-By: Luis Machado <luis.machado@arm.com>
2024-04-19gdb: aarch64: Remove MTE address checking from get_memtagGustavo Romero1-4/+0
This commit removes aarch64_linux_tagged_address_p from aarch64_linux_get_memtag. aarch64_linux_tagged_address_p checks if an address is tagged (MTE) or not. The check is redundant because aarch64_linux_get_memtag is always called from the upper layers (i.e. from printcmd.c via gdbarch hook gdbarch_get_memtag) after either gdbarch_tagged_address_p (that already points to aarch64_linux_tagged_address_p) has been called or after should_validate_memtags (that calls gdbarch_tagged_address_p at the end) has been called, so the address is already checked. Hence: a) in print_command_1, aarch64_linux_get_memtag (via gdbarch_get_memtag hook) is called but only after should_validate_memtags, which calls gdbarch_tagged_address_p; b) in do_examine, aarch64_linux_get_memtag is also called only after gdbarch_tagged_address_p is directly called; c) in memory_tag_check_command, gdbarch_get_memtag is called -- tags matching or not -- after the initial check via direct call to gdbarch_tagged_address_p; d) in memory_tag_print_tag_command, address is checked directly via gdbarch_tagged_address_p before gdbarch_get_memtag is called. Also, because after this change the address checking only happens at the upper layer it now allows the address checking to be specialized easily per target, via a target hook. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-04-18[gdb/testsuite] Use find_gnatmake instead of gdb_find_gnatmakeTom de Vries2-1/+16
On SLE-11, with an older dejagnu version, I ran into: ... Running gdb.ada/mi_prot.exp ... UNRESOLVED: gdb.ada/mi_prot.exp: \ testcase aborted due to invalid command name: gdb_find_gnatmake ERROR: tcl error sourcing gdb.ada/mi_prot.exp. ERROR: invalid command name "gdb_find_gnatmake" while executing "::gdb_tcl_unknown gdb_find_gnatmake" ("uplevel" body line 1) invoked from within "uplevel 1 ::gdb_tcl_unknown $args" (procedure "::unknown" line 5) invoked from within "gdb_find_gnatmake" (procedure "gnatmake_version_at_least" line 2) invoked from within ... Proc gdb_find_gnatmake is actually a backup for find_gnatmake: ... if {[info procs find_gnatmake] == ""} { rename gdb_find_gnatmake find_gnatmake ... so gnatmake_version_at_least should use find_gnatmake instead. For a recent dejagnu with find_gnatmake, gdb_find_gnatmake is kept, and we don't run into this error. For an older dejagnu without find_gnatmake, gdb_find_gnatmake is renamed to find_gnatmake, and we do run into the error. It's confusing that we're using the gdb_ prefix for gdb_find_gnatmake, it seems something legitimate to use. Maybe we should use future_ or gdb_future_ prefix instead to make this more clear, but I've left that alone for now. Fix this by: - triggering the same error with a recent dejagnu by removing gdb_find_gnatmake unless used (and likewise for other procs in future.exp), and - using find_gnatmake in gnatmake_version_at_least. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR testsuite/31647 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31647
2024-04-18[gdb/testsuite] Use allocator_may_return_null=1 in two test-casesTom de Vries3-6/+33
Simon reported [1] that recent commit 06e967dbc9b ("[gdb/python] Throw MemoryError in inferior.read_memory if malloc fails") introduced AddressSanitizer allocation-size-too-big errors in the two test-cases affected by this commit. Fix this by suppressing the error in the two test-cases using allocator_may_return_null=1. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> [1] https://sourceware.org/pipermail/gdb-patches/2024-April/208171.html
2024-04-18gdbsupport: constify some return values in print-utils.{h,cc}Simon Marchi2-2/+2
There is no reason the callers of these functions need to change the returned string, so change the `char *` return types to `const char *`. Update a few callers to also use `const char *`. Change-Id: I94adff574d5e1b326e8cc688cf1817a15b408b96 Approved-By: Tom Tromey <tom@tromey.com>
2024-04-18Add DW_TAG_compile_unit DIE to Dummy CUsWill Hawkins1-0/+1
Dummy CUs help detect errors and are very helpful. However, the DWARF spec seems to indicate the CUs need a DW_TAG_compile_unit in addition to the header. This patch adds that. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31650 Signed-off-by: Will Hawkins <hawkinsw@obs.cr> Approved-By: Tom de Vries <tdevries@suse.de> Tested-By: Tom de Vries <tdevries@suse.de>
2024-04-17Remove a copy from c-exp.y:parse_numberTom Tromey1-18/+13
parse_number copies its input string, but there is no need to do this. This patch removes the copy. Regression tested on x86-64 Fedora 38. Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-04-17gdb/Windows: Fix detach while runningPedro Alves3-8/+267
While testing a WIP Cygwin GDB that supports non-stop, I noticed that gdb.threads/attach-non-stop.exp exposes that this: (gdb) attach PID& ... (gdb) detach ... hangs. And it turns out that it hangs in all-stop as well. This commits fixes that. After "attach &", the target is set running, we've called ContinueDebugEvent and the process_thread thread is waiting for WaitForDebugEvent events. It is the equivalent of "attach; c&". In windows_nat_target::detach, the first thing we do is unconditionally call windows_continue (for ContinueDebugEvent), which blocks in do_synchronously, until the process_thread sees an event out of WaitForDebugEvent. Unless the inferior happens to run into a breakpoint, etc., then this hangs indefinitely. If we've already called ContinueDebugEvent earlier, then we shouldn't be calling it again in ::detach. Still in windows_nat_target::detach, we have an interesting issue that ends up being the bulk of the patch -- only the process_thread thread can call DebugActiveProcessStop, but if it is blocked in WaitForDebugEvent, we need to somehow force it to break out of it. The only way to do that, is to force the inferior to do something that causes WaitForDebugEvent to return some event. This patch uses CreateRemoteThread to do it, which results in WaitForDebugEvent reporting CREATE_THREAD_DEBUG_EVENT. We then terminate the injected thread before it has a chance to run any userspace code. Note that Win32 functions like DebugBreakProcess and GenerateConsoleCtrlEvent would also inject a new thread in the inferior. I first used DebugBreakProcess, but that is actually more complicated to use, because we'd have to be sure to consume the breakpoint event before detaching, otherwise the inferior would likely die due a breakpoint exception being raised with no debugger around to intercept it. See the new break_out_process_thread method. So the fix has two parts: - Keep track of whether we've called ContinueDebugEvent and the process_thread thread is waiting for events, or whether WaitForDebugEvent already returned an event. - In windows_nat_target::detach, if the process_thread thread is waiting for events, unblock out of its WaitForDebugEvent, before proceeding with the actual detach. New test included. Passes cleanly on GNU/Linux native and gdbserver, and also passes cleanly on Cygwin and MinGW, with the fix. Before the fix, it would hang and fail with a timeout. Tested-By: Hannes Domani <ssbssa@yahoo.de> Reviewed-By: Tom Tromey <tom@tromey.com> Change-Id: Ifb91c58c08af1a9bcbafecedc93dfce001040905
2024-04-17gdb+gdbserver/Linux: Remove USE_SIGTRAP_SIGINFO fallbackPedro Alves2-58/+6
It's been over 9 years (since commit faf09f0119da) since Linux GDB and GDBserver started relying on SIGTRAP si_code to tell whether a breakpoint triggered, which is important for non-stop mode. When that then-new code was added, I had left the then-old code as fallback, in case some architectured still needed it. Given AFAIK there haven't been complaints since, this commit finally removes the fallback code, along with USE_SIGTRAP_SIGINFO. Change-Id: I140a5333a9fe70e90dbd186aca1f081549b2e63d
2024-04-17Use section name in DWARF error messageTom Tromey1-2/+3
A bug points out that a certain error message in read_str_index uses a hard-coded section name. This patch changes it to use dwarf2_section_info::get_name instead, like the other errors in the function. No test because it didn't seem worthwhile. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31639 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-17gdbsupport, gdbserver, gdb: use -Wno-vla-cxx-extensionSimon Marchi1-0/+1
When building with clang 18, I see: CXX aarch64-linux-tdep.o /home/smarchi/src/binutils-gdb/gdb/aarch64-linux-tdep.c:1299:26: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension] 1299 | gdb_byte za_zeroed[za_bytes]; | ^~~~~~~~ /home/smarchi/src/binutils-gdb/gdb/aarch64-linux-tdep.c:1299:26: note: read of non-const variable 'za_bytes' is not allowed in a constant expression /home/smarchi/src/binutils-gdb/gdb/aarch64-linux-tdep.c:1282:10: note: declared here 1282 | size_t za_bytes = std::pow (sve_vl_from_vg (svg), 2); | ^ Since we are using VLAs right now, that warning doesn't make sense for us. add `-Wno-vla-cxx-extension` to the list of warning flags we try to enable. If we ever choose to disallow VLAs, we can remove that flag. Change-Id: Ie41feafc50c343f6e75333d4f836ce32fbeb6d8c
2024-04-17Fix include guard typoMatt Wozniski1-1/+1
Signed-off-by: Matt Wozniski <godlygeek@gmail.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31645 Approved-By: Tom Tromey <tom@tromey.com>
2024-04-17gdb/record: minor clean, remove some unneeded argumentsAndrew Burgess3-6/+37
I spotted that the two functions: record_full_open_1 record_full_core_open_1 both took two arguments, neither of which are used. I stumbled onto this while reviewing how filename_completer is used. The 'record full restore' command uses filename_completer and invokes the cmd_record_full_restore function. The cmd_record_full_restore function calls core_file_command and then record_full_open, which then calls one of the above functions. As 'record full restore' takes a filename, this is passed to cmd_record_full_restore, which forwards the filename to both core_file_command and record_full_open. However, record_full_open never actually uses the filename that is passed in. The record_full_open function is also used for 'target record-full'. I propose that record_full_open should no longer expect to see any user supplied arguments passed in (it doesn't use any). In fact, I've added a check that if we do get any user supplied arguments we'll throw an error. Now that we know record_full_open isn't being passed any user arguments we can stop passing the arguments to record_full_open_1 and record_full_core_open_1, this will make no user visible difference as these arguments were not used. It is possible that a user was previously doing: (gdb) target record-full blah blah blah And this previously would work fine, the 'blah blah blah' was ignored. Now this will give an error. Other than this case there should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2024-04-17gdb/record: add an assert in cmd_record_startAndrew Burgess1-1/+6
The 'record' command is both a prefix command AND an alias for 'target record-full'. As it is a prefix command, if a user types: (gdb) record blah Then GDB will look for, and try to invoke the 'blah' sub-command. This will either succeed (if blah is found) or throw an error (if blah is not found). As such, the only way to invoke the 'record' command is like: (gdb) record It is impossible to pass arguments to the 'record' command. As we know this is true then we can assert this in cmd_record_start. I added this assert because initially I was going to try forwarding ARGS from cmd_record_start to the 'target record-full' command, but then I realised passing arguments to 'record' was impossible. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2024-04-17gdb/record: remove unnecessary use of filename_completerAndrew Burgess1-2/+0
Spotted that the 'record' command has its completer set to filename_completer. The problem is that 'record' is a prefix command, as such, its completer is hard-coded to complete on sub-commands. The attempt to use filename_completer is irrelevant. The 'record' command is itself a command though, that is, a user can do this: (gdb) record which is really just an alias for: (gdb) target record-full Nowhere does cmd_record_start (which is called when 'record' is used) expect a filename, and 'target record-full' doesn't expect a filename either. So lets just drop the line which sets filename_completer as the completer for 'record'. Approved-By: Tom Tromey <tom@tromey.com>
2024-04-17[gdb/testsuite] Require DW_LNE_end_sequenceTom de Vries4-0/+43
The dwarf standard requires that every line number program sequence ends with a DW_LNE_end_sequence instruction. Enforce this in the dwarf assembler for the last sequence in a line number program (we have no means to enforce this for earlier sequences), and fix a few test-case that don't have it. Tested on aarch64-linux. PR testsuite/31618 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31618
2024-04-17[gdb/testsuite] Fix end_sequence addressesTom de Vries10-11/+16
I noticed in test-case gdb.reverse/map-to-same-line.exp, that the end of main: ... 00000000004102c4 <end_of_sequence>: 4102c4: 52800000 mov w0, #0x0 // #0 4102c8: 9100c3ff add sp, sp, #0x30 4102cc: d65f03c0 ret ... is not described by the line table: ... File name Line number Starting address View Stmt ... map-to-same-line.c 54 0x4102ac x map-to-same-line.c - 0x4102c4 ... Fix this by ending the line table at $main_end. Likewise in a few other test-cases, found using: ... $ find gdb/testsuite/ -type f \ | xargs grep -B1 DW_LNE_end_sequence \ | grep set_address \ | egrep -v "_end|_len" ... Tested on aarch64-linux.
2024-04-17[gdb/testsuite] Require address update for DW_LNS_copyTom de Vries7-0/+16
No address update before a DW_LNS_copy might mean an incorrect dwarf assembly test-case. Try to catch such incorrect dwarf assembly test-cases by: - requiring an explicit address update for each DW_LNS_copy, and - handling the cases where an update is indeed not needed, by adding "DW_LNS_advance_pc 0". Tested on aarch64-linux.
2024-04-17[gdb/testsuite] Require address update for DW_LNE_end_sequenceTom de Vries11-27/+32
With test-case gdb.dwarf2/dw2-epilogue-begin.exp, we have an end_sequence entry with the same address as the line entry before it: ... File name Line number Starting address View Stmt dw2-epilogue-begin.c 44 0x4101e8 x dw2-epilogue-begin.c 47 0x4101ec x dw2-epilogue-begin.c - 0x4101ec ... and consequently the line entry is removed by gdb: ... INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PRO EPI 0 20 0x00000000004101a8 0x00000000004101a8 Y Y Y 1 27 0x00000000004101b0 0x00000000004101b0 Y 2 32 0x00000000004101b8 0x00000000004101b8 Y Y 3 34 0x00000000004101c0 0x00000000004101c0 Y Y 4 35 0x00000000004101c8 0x00000000004101c8 Y 5 40 0x00000000004101d4 0x00000000004101d4 Y Y 6 44 0x00000000004101e8 0x00000000004101e8 Y 7 END 0x00000000004101ec 0x00000000004101ec Y ... This is a common mistake in dwarf assembly test-cases. Fix this by: - requiring an address update for each DW_LNE_end_sequence, and - fixing the test-cases where that triggers an error. I also encountered the error in test-case gdb.dwarf2/dw2-bad-elf.exp, and in this case I worked around it using "DW_LNS_advance_pc 0". Tested on aarch64-linux. PR testsuite/31592 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31592
2024-04-17Fix max-depth test case for AIX.Aditya Vidyadhar Kamath1-0/+9
In AIX, if in the main program the global variables are unused then the linker optimises these variables and the dwarf will not have proper address to the same. Hence we cannot access these variables. This patch is a fix to the same so that all the test case of max-depth can passs in AIX as well.
2024-04-17[gdb/testsuite] Fix gdbserver pid in gdb.server/server-kill-python.expTom de Vries1-16/+21
The commit ed32754a8c7 ("[gdb/testsuite] Fix gdb.server/multi-ui-errors.exp for remote target") intended to addresss the problem that this command: ... set gdbserver_pid [exp_pid -i $server_spawn_id] ... does not return the pid of the gdbserver for remote target, but rather the one of the ssh client session. To fix this, it added another way of getting the gdbserver_pid. For the trivial case of non-remote target, the PID found by either method should be identical, but if we compare those by adding "puts [exec ps -p $gdbserver_pid]" we get: ... PID TTY TIME CMD 31711 pts/8 00:00:00 gdbserver PID TTY TIME CMD 31718 pts/8 00:00:00 server-kill-pyt ... The problem is that while the gdbserver PID is supposed to be read from the result of "gdb.execute ('p server_pid')" in the python script, instead it's taken from: ... Process server-kill-python created; pid = 31718^M ... Fix this by moving the printing of the gdbserver PID out of the python script. Also double-check the two methods against each other, in the cases that they should match. Tested on x86_64-linux. PR testsuite/31633 https://sourceware.org/bugzilla/show_bug.cgi?id=31633
2024-04-17[gdb/testsuite] Simplify gdb.server/server-kill-python.expTom de Vries1-3/+5
In test-case gdb.server/server-kill-python.exp we have: ... if {[gdb_spawn_with_cmdline_opts \ "-quiet -iex \"set height 0\" -iex \"set width 0\" -ex \"source $host_file1\""] != 0} { fail "spawn" return } ... I reproduced the problem by reverting the fix at the commit adding both the fix and the test-case, and the reproduced the same problem using: ... (gdb) source $host_file1 ... so there doesn't seem to be a specific need to source the python file using "-ex". Simplify the test-case by sourcing the python file using send_gdb. This also allow us to simplify the python script. Tested on x86_64-linux.
2024-04-16[gdb/testsuite] Add gdb.dwarf2/backward-spec-inter-cu.expTom de Vries1-0/+103
Add another regression test for PR symtab/30846. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30846
2024-04-16[gdb/testsuite] Add gdb.dwarf2/forward-spec-inter-cu.expTom de Vries1-0/+103
Add a regression test for PR symtab/30846. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30846
2024-04-16Correctly handle DIE parent computationsTom Tromey4-50/+80
Tom de Vries pointed out that the combination of sharding, multi-threading, and per-CU "racing" means that sometimes a cross-CU DIE reference might not be correctly resolved. However, it's important to handle this correctly, due to some unfortunate aspects of DWARF. This patch implements this by arranging to preserve each worker's DIE map through the end of index finalization. The extra data is discarded when finalization is done. This approach also allows the parent name resolution to be sharded, by integrating it into the existing entry finalization loop. In an earlier review, I remarked that addrmap couldn't be used here. However, I was mistaken. A *mutable* addrmap cannot be used, as those are based on splay trees and restructure the tree even during lookups (and thus aren't thread-safe). A fixed addrmap, on the other hand, is just a vector and is thread-safe. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30846
2024-04-16Introduce class parent_map for DIE range mapTom Tromey3-31/+154
This changes the DIE range map from a raw addrmap to a custom class. A new type is used to represent the ranges, in an attempt to gain a little type safety as well. Note that the new code includes a map-of-maps type. This is not used yet, but will be used in the next patch. Co-Authored-By: Tom de Vries <tdevries@suse.de>
2024-04-16Add move operators for addrmapTom Tromey2-6/+25
A subsequent patch needs to move an addrmap. This patch adds the necessary support. It also changes addrmap_fixed to take a 'const' addrmap_mutable. This is fine according to the contract of addrmap_mutable; but it did require a compensating const_cast in the implementation.
2024-04-16Change handling of DW_TAG_enumeration_type in DWARF scannerTom Tromey1-9/+7
Currently the DWARF scanner will enter enumeration constants into the same namespace as the DW_TAG_enumeration_type itself. This is the right thing to do, but the implementation may result in strange entries being added to the addrmap that maps DIE ranges to entries. This came up when debugging an earlier version of this series; and while I don't think this should impact the current series, it seems better to clean this up anyway. In the new code, rather than pass the "wrong" scope down through recursive calls to the scanner, the correct scope is always passed, and then the parent handling is done when creating the enumerator entry.
2024-04-16[gdb/symtab] Refactor condition in scan_attributesTom de Vries1-8/+10
In scan_attributes there's code: ... if (new_reader->cu == reader->cu && new_info_ptr > watermark_ptr && *parent_entry == nullptr) ... else if (*parent_entry == nullptr) ... ... that uses the "*parent_entry == nullptr" condition twice. Make this somewhat more readable by factoring out the condition: ... if (*parent_entry == nullptr) { if (new_reader->cu == reader->cu && new_info_ptr > watermark_ptr) ... else ... } ... This also allows us to factor out "form_addr (origin_offset, origin_is_dwz)". Tested on x86_64-linux.
2024-04-16gdb/make-target-delegates.py: don't handle "void" in parse_argtypesSimon Marchi1-1/+2
I suppose this was needed when we had `void` in declarations of methods with no parameters. If so, we no longer need it. There are no changes in the generated file. Change-Id: I0a2b398408aa129634e2d73097a038f7f80db4b4 Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-04-16Remove excess whitespace from doc strings of some commandsEli Zaretskii4-10/+10
I've noticed that doc strings of some commands, like "set cwd" and "set inferior-tty", have some excess whitespace, which makes them display with unexpected indentation, at least in a Windows command prompt window. This patch fixes that. * gdb/linux-nat.c (_initialize_linux_nat): * gdb/riscv-tdep.c (riscv_insn): * gdb/top.c (quit_force): * gdb/infcmd.c (_initialize_infcmd): Remove excess whitespace.
2024-04-16[gdb/python] Throw MemoryError in inferior.read_memory if malloc failsTom de Vries4-3/+28
PR python/31631 reports a gdb internal error when doing: ... (gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff) utils.c:709: internal-error: virtual memory exhausted. A problem internal to GDB has been detected, further debugging may prove unreliable. ... Fix this by throwing a python MemoryError, such that we have instead: ... (gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff) Python Exception <class 'MemoryError'>: Error occurred in Python. (gdb) ... Likewise for DAP. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31631
2024-04-15Fix crash in gdb_rl_callback_handlerTom Tromey1-4/+7
commit bdcd50f9 ("Strip trailing newlines from input string") introduced a crash in eof-exit.exp. This patch fixes the problem by adding a NULL check in the appropriate spot. Regression tested on x86-64 Fedora 38. I'm checking this in.
2024-04-15Remove 'copy_names' parameter from add_using_directiveTom Tromey4-32/+13
I noticed that add_using_directive's 'copy_names' parameter is only used by a single caller. This patch removes the parameter and changes that caller to copy the names itself. I chose to use intern here since I suspect the names may well be repeated in a given objfile. Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-04-15gdb: Add Felix Willgerodt as the x86 architecture maintainerJohn Baldwin1-0/+2
This includes both the i386 and x86-64 architectures.
2024-04-15Change printf attribute to fix clang buildTom Tromey1-2/+2
commit e8cd90f0 ("Rewrite gdb_bfd_error_handler") broke the clang build. The problem here is that print_error_callback isn't marked as being printf-like, but it calls string_file::vprintf, triggering: ../../binutils-gdb/gdb/gdb_bfd.c:1202:18: error: format string is not a string literal [-Werror,-Wformat-nonliteral] This patch applies the attribute to this function. It also removes the attribute from gdb_bfd_error_handler, because that function is no longer really printf-like.
2024-04-15Avoid complaint warning on mingwTom Tromey5-29/+27
The mingw build currently issues a warning: ./../../src/gdb/utils.h:378:56: warning: ignoring attributes on template argument 'void(const char*, va_list)' {aka 'void(const char*, char*)'} [-Wignored-attributes] This patch fixes the problem as suggested by Simon: https://sourceware.org/pipermail/gdb-patches/2024-April/207908.html ...that is, by changing the warning interceptor to a class with a single 'warn' method. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-15Strip trailing newlines from input stringTom Tromey2-0/+53
A co-worker noticed a strange situation where "target remote" would fail due to a trailing newline in the address part of the command. Eventually he tracked this down to the fact that he was pasting the command into the terminal, and due to bracketed paste mode, the newline was being preserved by readline. It seems to me that we basically never want a trailing newline on a gdb command, so this patch removes it when handling the readline result. Co-Authored-By: Kévin Le Gouguec <legouguec@adacore.com> Approved-By: Luis Machado <luis.machado@arm.com> Tested-By: Luis Machado <luis.machado@arm.com>
2024-04-12Fix setting watchpoints when current thread is runningPedro Alves3-4/+192
Currently, when the current thread is running, you can print global variables. However, if you try to set a watchpoint on the same globals, GDB errors out, complaining that the selected thread is running. Like so: (gdb) c& Continuing. (gdb) p global $1 = 1098377287 (gdb) watch global Selected thread is running. This patch makes setting the watchpoint work. You'll now get: (gdb) c& Continuing. (gdb) [New Thread 0x7ffff7d6e640 (LWP 434993)] [New Thread 0x7ffff756d640 (LWP 434994)] p global $1 = 88168 (gdb) watch global Hardware watchpoint 2: global (gdb) [Switching to Thread 0x7ffff7d6e640 (LWP 434993)] Thread 2 "function0" hit Hardware watchpoint 2: global Old value = 185420 New value = 185423 int_return () at threads.c:39 39 } The problem is that update_watchpoint calls get_selected_frame unconditionally. We can skip it if the watchpoint expression is only watching globals. This adds a testcase that exercises both all-stop and non-stop, and also software and hardware watchpoints. It is kfailed for software watchpoints, as those require another fix not handled by this patch (the sw watchpoint doesn't fire because GDB doesn't force the running-free thread to switch to single-stepping). Change-Id: I68ca948541aea3edd4f70741f272f543187abe40
2024-04-12New testcase gdb.threads/leader-exit-attach.exp (PR threads/8153)Pedro Alves1-0/+87
Add a new testcase for exercising attaching to a process after its main thread has exited. This is not possible on Linux, the kernel does not allow attaching to a zombie task, so the test is kfailed there. It is possible however on Windows at least, and was the scenario addressed by the Windows backend fix in https://sourceware.org/legacy-ml/gdb-patches/2003-12/msg00479.html, nowadays PR threads/8153, back in 2003. Passes cleanly on Cygwin. KFAILed on GNU/Linux native and gdbserver. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8153 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31554 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31555 Change-Id: Ib554f92f68c965bb4603cdf2aadb55ca45ded53b
2024-04-12Cygwin/testsuite: Avoid infinite hangPedro Alves1-1/+1
On Cygwin, the gdb.base/fork-no-detach-follow-child-dlopen.exp testcase hits a sequence of cascading FAILs: (gdb) run Starting program: ..../gdb.base/fork-no-detach-follow-child-dlopen/fork-no-detach-follow-child-dlopen [New Thread 12672.0x318c] [New Thread 12672.0x2844] [New Thread 12672.0x714] FAIL: gdb.base/fork-no-detach-follow-child-dlopen.exp: runto: run to add (timeout) frame FAIL: gdb.base/fork-no-detach-follow-child-dlopen.exp: frame (timeout) list FAIL: gdb.base/fork-no-detach-follow-child-dlopen.exp: list (timeout) And the test program never makes progress. ... and at this point, Cygwin is completely stuck. I can't run any other Cygwin program. However, if we run the test program outside DejaGnu, we see something different: (gdb) b add Function "add" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (add) pending. (gdb) r Starting program: ..../gdb.base/fork-no-detach-follow-child-dlopen/fork-no-detach-follow-child-dlopen [New Thread 10968.0x834] [New Thread 10968.0x29a4] [New Thread 10968.0x16b8] [New Thread 10968.0xf9c] [Switching to Thread 10968.0x16b8] Thread 4 "sig" hit Breakpoint 1.2, pending_signals::add (pack=..., this=0x7ffa1e748a40 <sigq>) at /usr/src/debug/cygwin-3.4.9-1/winsup/cygwin/sigproc.cc:1304 1304 se = sigs + pack.si.si_signo; (gdb) Ah, the test wanted to run to a global "add" function, but managed to stop at an internal Cygwin method called "add". And stopping there deadlocks everything Cygwin in the system. (I believe some cygwin1.dll mechanisms use cross-process synchronization or communication, we're probably blocking something like that.) Fix this by using "break -q". The tests FAIL because we don't support follow-fork for Cygwin, but at least we no longer deadlock the machine. Approved-by: Kevin Buettner <kevinb@redhat.com> Change-Id: I7181d8481c2ae1024b0d73e3bb194f9a4f0a7eb9
2024-04-12gdb/data-directory: silence output from mkinstalldirs scriptAndrew Burgess1-1/+1
After my recent changes the data-directory build now uses silent-rules.mk to reduce the output. One problem that remains was the use of mkinstalldirs by stamp-python and stamp-guile for creating some directories, the mkinstalldirs prints some messages, so we're left with output like this: GEN stamp-python mkdir -p -- ./python/gdb mkdir -p -- ./python/gdb/command mkdir -p -- ./python/gdb/dap mkdir -p -- ./python/gdb/function mkdir -p -- ./python/gdb/printer I was looking at adding a --silent option to the mkinstalldirs script, however, when I took a look at the automake package (which is where mkinstalldirs comes from) it turns out that mkinstalldirs is deprecated, at the advice is to use 'install-sh -d' instead. Just like we carry mkinstalldirs in the top-level directory, we also carry install-sh, and a version of install-sh which supports the -d flag. And best of all, 'install-sh -d' doesn't appear to print any of the information messages to stdout that mkinstalldirs does, so if we switch to use that, we get a quieter build. There should be no changes in what is built after this commit Approved-By: Tom Tromey <tom@tromey.com>
2024-04-11[gdb/testsuite] Fix gdb.threads/access-mem-running-thread-exit.exp with clangTom de Vries1-0/+2
When running test-case gdb.threads/access-mem-running-thread-exit.exp with clang, we run into: ... (gdb) print global_var = 555^M No symbol "global_var" in current context.^M (gdb) FAIL: gdb.threads/access-mem-running-thread-exit.exp: all-stop: \ access mem (write to global_var, inf=2, iter=1) ... The problem is that clang removes the unused variable. Fix this in the same way as done in commit b4f767131f7 ("Fix gdb.base/align-*.exp and Clang + LTO and AIX GCC"), by incrementing the variable. Tested on x86_64-linux with gcc and clang.
2024-04-11gdb: fix format in remote.cTankut Baris Aktemur1-3/+3
Fix space-before-parenthesis format at three spots in remote.c.