aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2023-11-06Change gdb.base/examine-backwards.exp for AIX.Aditya Vidyadhar Kamath1-4/+4
In AIX unused or constant variables are collected as garbage by the linker and in the dwarf dump an address with all f's in hexadecimal are assigned. Hence the testcase fails with many failures stating it cannot access memory. This patch is a small change to get it working in AIX as well.
2023-11-06[gdb/testsuite] Fix gdb.dwarf2/dw2-gas-workaround.expTom de Vries1-1/+1
Recently added test-case gdb.dwarf2/dw2-gas-workaround.exp: - passes when gdb is configured using $(cd ../src; pwd)/configure, but - fails when using ../src/configure. Fix this by making the matching more precise: ... - -re -wrap "$objdir.*" { + -re -wrap "name_for_id = $objdir/$srcfile\r\n.*" { ... such that we only fail on the line: ... [symtab-create] start_subfile: name = dw2-lines.c, name_for_id = \ /data/vries/gdb/leap-15-4/build/gdb/testsuite/dw2-lines.c^M ... Reported-By: Carl Love <cel@us.ibm.com>
2023-11-05Pre-read DWZ file in DWARF readerTom Tromey2-9/+2
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 Vries1-0/+92
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-10-31Implement DAP setVariable requestTom Tromey3-0/+211
This patch implements the DAP setVariable request. setVariable is a bit odd in that it specifies the variable to modify by passing in the variable's container and the name of the variable. This approach can't handle variable shadowing (there are a couple of open DAP bugs on this topic), so this patch renames duplicates to avoid the problem.
2023-10-26gdb/python: Add new gdb.Value.bytes attributeAndrew Burgess1-1/+108
Add a gdb.Value.bytes attribute. This attribute contains the bytes of the value (assuming the complete bytes of the value are available). If the bytes of the gdb.Value are not available then accessing this attribute raises an exception. The bytes object returned from gdb.Value.bytes is cached within GDB so that the same bytes object is returned each time. The bytes object is created on-demand though to reduce unnecessary work. For some values we can of course obtain the same information by reading inferior memory based on gdb.Value.address and gdb.Value.type.sizeof, however, not every value is in memory, so we don't always have an address. The gdb.Value.bytes attribute will convert any value to a bytes object, so long as the contents are available. The value can be one created purely in Python code, the value could be in a register, or (of course) the value could be in memory. The Value.bytes attribute can also be assigned too. Assigning to this attribute is similar to calling Value.assign, the value of the underlying value is updated within the inferior. The value assigned to Value.bytes must be a buffer which contains exactly the correct number of bytes (i.e. unlike value creation, we don't allow oversized buffers). To support this assignment like behaviour I've factored out the core of valpy_assign. I've also updated convert_buffer_and_type_to_value so that it can (for my use case) check the exact buffer length. The restrictions for when the Value.bytes can or cannot be written too are exactly the same as for Value.assign. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13267 Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-26gdb: handle main thread exiting during detachAndrew Burgess2-0/+201
Overview ======== Consider the following situation, GDB is in non-stop mode, the main thread is running while a second thread is stopped. The user has the second thread selected as the current thread and asks GDB to detach. At the exact moment of detach the main thread exits. This situation currently causes crashes, assertion failures, and unexpected errors to be reported from GDB for both native and remote targets. This commit addresses this situation for native and remote targets. There are a number of different fixes, but all are required in order to get this functionality working correct for native and remote targets. Native Linux Target =================== For the native Linux target, detaching is handled in the function linux_nat_target::detach. In here we call stop_wait_callback for each thread, and it is this callback that will spot that the main thread has exited. GDB then detaches from everything except the main thread by calling detach_callback. After this the first problem is this assert: /* Only the initial process should be left right now. */ gdb_assert (num_lwps (pid) == 1); The num_lwps call will return 0 as the main thread has exited and all of the other threads have now been detached. I fix this by changing the assert to allow for 0 or 1 lwps at this point. As the 0 case can only happen in non-stop mode, the assert becomes: gdb_assert (num_lwps (pid) == 1 || (target_is_non_stop_p () && num_lwps (pid) == 0)); The next problem is that we do: main_lwp = find_lwp_pid (ptid_t (pid)); and then proceed assuming that main_lwp is not nullptr. In the case that the main thread has exited though, main_lwp will be nullptr. However, we only need main_lwp so that GDB can detach from the thread. If the main thread has exited, and GDB has already detached from every other thread, then GDB has finished detaching, GDB can skip the calls that try to detach from the main thread, and then tell the user that the detach was a success. For Remote Targets ================== On remote targets there are two problems. First is that when the exit occurs during the early phase of the detach, we see the stop notification arrive while GDB is removing the breakpoints ahead of the detach. The 'set debug remote on' trace looks like this: [remote] Sending packet: $z0,7f1648fe0241,1#35 [remote] Notification received: Stop:W0;process:2a0ac8 # At this point an unpatched gdbserver segfaults, and the connection # is broken. A patched gdbserver continues as below... [remote] Packet received: E01 [remote] Sending packet: $z0,7f1648ff00a8,1#68 [remote] Packet received: E01 [remote] Sending packet: $z0,7f1648ff132f,1#6b [remote] Packet received: E01 [remote] Sending packet: $D;2a0ac8#3e [remote] Packet received: E01 I was originally running into Segmentation Faults, from within gdbserver/mem-break.cc, in the function find_gdb_breakpoint. This function calls current_process() and then dereferences the result to find the breakpoint list. However, in our case, the current process has already exited, and so the current_process() call returns nullptr. At the point of failure, the gdbserver backtrace looks like this: #0 0x00000000004190e4 in find_gdb_breakpoint (z_type=48 '0', addr=4198762, kind=1) at ../../src/gdbserver/mem-break.cc:982 #1 0x000000000041930d in delete_gdb_breakpoint (z_type=48 '0', addr=4198762, kind=1) at ../../src/gdbserver/mem-break.cc:1093 #2 0x000000000042d8db in process_serial_event () at ../../src/gdbserver/server.cc:4372 #3 0x000000000042dcab in handle_serial_event (err=0, client_data=0x0) at ../../src/gdbserver/server.cc:4498 ... The problem is that, as a result non-stop being on, the process exiting is only reported back to GDB after the request to remove a breakpoint has been sent. Clearly gdbserver can't actually remove this breakpoint -- the process has already exited -- so I think the best solution is for gdbserver just to report an error, which is what I've done. The second problem I ran into was on the gdb side, as the process has already exited, but GDB has not yet acknowledged the exit event, the detach -- the 'D' packet in the above trace -- fails. This was being reported to the user with a 'Can't detach process' error. As the test actually calls detach from Python code, this error was then becoming a Python exception. Though clearly the detach has returned an error, and so, maybe, having GDB throw an error would be fine, I think in this case, there's a good argument that the remote error can be ignored -- if GDB tries to detach and gets back an error, and if there's a pending exit event for the pid we tried to detach, then just ignore the error and pretend the detach worked fine. We could possibly check for a pending exit event before sending the detach packet, however, I believe that it might be possible (in non-stop mode) for the stop notification to arrive after the detach is sent, but before gdbserver has started processing the detach. In this case we would still need to check for pending stop events after seeing the detach fail, so I figure there's no point having two checks -- we just send the detach request, and if it fails, check to see if the process has already exited. Testing ======= In order to test this issue I needed to ensure that the exit event arrives at the same time as the detach call. The window of opportunity for getting the exit to arrive is so small I've never managed to trigger this in real use -- I originally spotted this issue while working on another patch, which did manage to trigger this issue. However, if we trigger both the exit and the detach from a single Python function then we never return to GDB's event loop, as such GDB never processes the exit event, and so the first time GDB gets a chance to see the exit is during the detach call. And so that is the approach I've taken for testing this patch. Tested-By: Kevin Buettner <kevinb@redhat.com> Approved-By: Kevin Buettner <kevinb@redhat.com>
2023-10-26[gdb/testsuite] Add wait-for-index-cache in gdb.dwarf2/per-bfd-sharing.expTom de Vries1-0/+1
If we make writing an index-cache entry very slow by doing this in index_cache::store: ... try { + sleep (15); index_cache_debug ("writing index cache for objfile %s", bfd_get_filename (per_bfd->obfd)); ... we run into: ... FAIL: gdb.dwarf2/per-bfd-sharing.exp: \ couldn't remove files in temporary cache dir ... The FAIL happens because there is no index-cache entry in the cache dir. The problem is that gdb is killed (by gdb_exit) before the index-cache entry is written. Fix this by using "maint wait-for-index-cache". Tested on x86_64-linux. PR testsuite/30528 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30528
2023-10-25gdb/testsuite: add a clang XFAIL to gdb.python/py-watchpoint.expGuinevere Larsen1-1/+16
Clang doesn't use CFA information for variable locations. This makes it so software breakpoints get a false hit when rbp gets popped, causing a FAIL in gdb.python/py-watchpoint.exp. Since this is nothing wrong with GDB itself, add an xfail to reduce noise. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-25gdb/testsuite: fix running gdb.python/py-explore-cc with clangGuinevere Larsen1-1/+2
The test gdb.python/py-explore-cc.exp was showing one unexpected failure. This was due to how clang mapped instructions to lines, resulting in the inferior seemingly stopping at a different location. This patch adds a nop line in the relevant location so we don't need to add XFAILs for existing clang releases, if this gets solved in future versions. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-22Style history variable outputTom Tromey1-1/+2
When printing a value, I think the history reference -- the "$1" in the output -- should be styled using the "variable" style. This patch implements this.
2023-10-18gdb/testsuite/gdb.rocm: Fix incorrect use of continue N in ↵Lancelot Six1-1/+1
multi-inferior-gpu.exp The gdb.rocm/multi-inferior-gpu.exp testcase uses a "continue $thread" command, but this is incorrect. If "continue" is given an argument, it sets the ignore count of the breakpoint the thread stopped at. For this testcase it does not really matter since the breakpoint is not meant to be hit anymore, so whatever the ignore count is won't influence the outcome of the test. It is worth fixing nevertheless. Change-Id: I0eb674d5529cdeb9e808b74870a29b6077265737 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-10-18gdb/testsuite/gdb.rocm: Check value returned by hipDeviceSynchronizeLancelot Six6-6/+52
Functions of the hip runtime returning a hipError_t can be marked nodiscard depending on the configuration[1] (when compiled with C++17). This patch makes sure that we always check the value returned by hipDeviceSynchronize and friends, and print an error message when appropriate. This avoid a wall of warnings when running the testsuite if the compiler defaults to using C++17. It is always a good practice to check the return values anyway. [1] https://github.com/ROCm-Developer-Tools/HIP/blob/docs/5.7.1/include/hip/hip_runtime_api.h#L203-L218 Change-Id: I2a819a8ac45f4bcf814efe9a2ff12c6a7ad22f97 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-10-18[gdb/testsuite] Fix gdb.base/jit-bfd-name.expTom de Vries1-1/+1
When running test-case gdb.base/jit-bfd-name.exp, I run into: ... ERROR: tcl error sourcing gdb/testsuite/gdb.base/jit-bfd-name.exp. ERROR: can't read "start": no such variable ... The problem is that commit c96ceed9dce ("gdb: include the end address in in-memory bfd filenames") introduced a use of variable start, but not a definition. Fix this by adding the missing definition. Tested on x86_64-linux.
2023-10-17gdb: include the end address in in-memory bfd filenamesMarkus Metzger1-3/+10
Commit 66984afd29e gdb: include the base address in in-memory bfd filenames added the base address to in-memory bfd filenames. Also add the end address to allow dumping the in-memory bfd using the 'dump memory' command.
2023-10-16Have DAP handle non-Value results from 'children'Tom Tromey2-0/+159
A pretty-printer's 'children' method may return values other than a gdb.Value -- it may return any value that can be converted to a gdb.Value. I noticed that this case did not work for DAP. This patch fixes the problem.
2023-10-16Handle gdb.LazyString in DAPTom Tromey3-0/+140
Andry pointed out that the DAP code did not properly handle gdb.LazyString results from a pretty-printer, yielding: TypeError: Object of type LazyString is not JSON serializable This patch fixes the problem, partly with a small patch in varref.py, but mainly by implementing tp_str for LazyString. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-10-16Fix register-setting response from DAPTom Tromey1-3/+22
Andry noticed that given a DAP setExpression request, where the expression to set is a register, DAP will return the wrong value -- it will return the old value, not the updated one. This happens because gdb.Value.assign (which was recently added for DAP) does not update the value. In this patch, I chose to have the assign method update the Value in-place. It's also possible to have it return a new value, but this didn't seem very useful to me.
2023-10-16Add DAP scope cacheTom Tromey1-0/+7
Andry Ogorodnik, a co-worker, noticed that multiple "scopes" requests with the same frame would yield different variableReference values in the response. This patch adds a regression test for this, and adds a scope cache in scopes.py, ensuring that multiple identical requests will get the same response. Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2023-10-16[gdb/symtab] Work around PR gas/29517Tom de Vries2-8/+37
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-16Only allow closure lookup by address if there are threads displaced-steppingLuis Machado2-0/+60
Since commit 1e5ccb9c5ff4fd8ade4a8694676f99f4abf2d679, we have an assertion in displaced_step_buffers::copy_insn_closure_by_addr that makes sure a closure is available whenever we have a match between the provided address argument and the buffer address. That is fine, but the report in PR30872 shows this assertion triggering when it really shouldn't. After some investigation, here's what I found out. The 32-bit Arm architecture is the only one that calls gdbarch_displaced_step_copy_insn_closure_by_addr directly, and that's because 32-bit Arm needs to figure out the thumb state of the original instruction that we displaced-stepped through the displaced-step buffer. Before the assertion was put in place by commit 1e5ccb9c5ff4fd8ade4a8694676f99f4abf2d679, there was the possibility of getting nullptr back, which meant we were not doing a displaced-stepping operation. Now, with the assertion in place, this is running into issues. It looks like displaced_step_buffers::copy_insn_closure_by_addr is being used to return a couple different answers depending on the state we're in: 1 - If we are actively displaced-stepping, then copy_insn_closure_by_addr is supposed to return a valid closure for us, so we can determine the thumb mode. 2 - If we are not actively displaced-stepping, then copy_insn_closure_by_addr should return nullptr to signal that there isn't any displaced-step buffers in use, because we don't have a valid closure (but we should always have this). Since the displaced-step buffers are always allocated, but not always used, that means the buffers will always contain data. In particular, the buffer addr field cannot be used to determine if the buffer is active or not. For instance, we cannot set the buffer addr field to 0x0, as that can be a valid PC in some cases. My understanding is that the current_thread field should be a good candidate to signal that a particular displaced-step buffer is active or not. If it is nullptr, we have no threads using that buffer to displaced-step. Otherwise, it is an active buffer in use by a particular thread. The following fix modifies the displaced_step_buffers::copy_insn_closure_by_addr function so we only attempt to return a closure if the buffer has an assigned current_thread and if the buffer address matches the address argument. Alternatively, I think we could use a function to answer the question of whether we're actively displaced-stepping (so we have an active buffer) or not. I've also added a testcase that exercises the problem. It should reproduce reliably on Arm, as that is the only architecture that faces this problem at the moment. Regression-tested on Ubuntu 20.04. OK? Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30872 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-10-12Fix test suite failure in file-then-restart.expTom Tromey3-18/+19
Simon pointed out that the new file-then-restart.exp test fails with the extended-remote target board. The problem is that the test suite doesn't use gdb_file_cmd -- which handles things like "set remote exec-file". This patch changes gdb_file_cmd to make the "kill" command optional, and then switches the test case to use it. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30933 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-10-10gdb/python: implement support for sending custom MI async notificationsJan Vrany1-0/+71
This commit adds a new Python function, gdb.notify_mi, that can be used to emit custom async notification to MI channel. This can be used, among other things, to implement notifications about events MI does not support, such as remote connection closed or register change. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-09gdb/testsuite: match complete lines in gdb.base/maint.expAndrew Burgess1-2/+2
This thread: https://inbox.sourceware.org/gdb-patches/20231003195338.334948-1-thiago.bauermann@linaro.org/ pointed out that within gdb.base/maint.exp, some regexps within a gdb_test_multiple were failing to match a complete line, while later regexps within the gdb_test_multiple made use of the '^' anchor, and so assumed that earlier lines had been completely matched and removed from expect's buffer. When testing with READ1 set this assumption was failing. Fix this by extending the offending patterns with a trailing '\r\n'. Tested-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-08Bump version to 15.0.50.DATE-git.Joel Brobecker1-1/+1
Now that the GDB 14 branch has been created, this commit bumps the version number in gdb/version.in to 15.0.50.DATE-git For the record, the GDB 14 branch was created from commit 8f12a1a841cd0c447de7a5a0f134a0efece73588. Also, as a result of the version bump, the following changes have been made in gdb/testsuite: * gdb.base/default.exp: Change $_gdb_major to 15.
2023-10-07[gdb/testsuite] Fix gdb.arch/i386-signal.exp on x86_64Tom de Vries2-1/+10
On x86_64-linux, with test-case gdb.arch/i386-signal.exp I run into: ... builtin_spawn -ignore SIGHUP gcc -fno-stack-protector i386-signal.c \ -fdiagnostics-color=never -fno-pie -g -no-pie -lm -o i386-signal^M /tmp/cc2xydTG.s: Assembler messages:^M /tmp/cc2xydTG.s:50: Error: operand size mismatch for `push'^M compiler exited with status 1 output is: /tmp/cc2xydTG.s: Assembler messages:^M /tmp/cc2xydTG.s:50: Error: operand size mismatch for `push'^M gdb compile failed, /tmp/cc2xydTG.s: Assembler messages: /tmp/cc2xydTG.s:50: Error: operand size mismatch for `push' UNTESTED: gdb.arch/i386-signal.exp: failed to compile ... This is with gas 2.41, it compiles without problems with gas 2.40. Some more strict checking was added in commit 5cc007751cd ("x86: further adjust extend-to-32bit-address conditions"). This may or may not be a gas regression ( https://sourceware.org/pipermail/binutils/2023-October/129818.html ). The offending bit is: ... " push $sigframe\n" ... which refers to a function: ... " .globl sigframe\n" "sigframe:\n" ... The test-case passes with target board unix/-m32. Make the test-case work by using pushq instead of push for the is_amd64_regs_target case. Tested on x86_64-linux, with target boards: - unix/-m64 (is_amd64_regs_target == 1), and - unix/-m32 (is_amd64_regs_target == 0), PR testsuite/30928 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30928
2023-10-06process-dies-while-detaching.exp: Exit early if GDB misses sync breakpointThiago Jung Bauermann2-7/+7
I'm seeing a lot of variability in the failures of gdb.threads/process-dies-while-detaching.exp on aarch64-linux. On this platform, a problem yet to be investigated causes GDB to miss the _exit breakpoint. What happens next is random because after missing that breakpoint, GDB is out of sync with the inferior. This causes the tests following that point in the testcase to fail in a random way. In this scenario it's better to exit the testcase early to avoid random results in the testsuite. We are relying on gdb_continue_to_breakpoint to return the result of gdb_test_multiple. This is already the case because in Tcl the return value of a function is the return value of the last command it runs. But change gdb_continue_to_breakpoint to explicitly return this value, to make it clear this is the intended behaviour. Tested on aarch64-linux. Tested-By: Guinevere Larsen <blarsen@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-06gdb/testsuite: cleanup in gdb.base/args.expAndrew Burgess1-52/+36
The last few commits resolved the KFAILs in gdb.base/args.exp. With those out of the way we can clean up this test script a little. In this commit I have: - Stopped passing 'nowarnings' flag when building the source file. I see no reason why this source should issue a warning, - Moved setup of GDBFLAGS into args_test proc, callers that passed a newline needed a small tweak, and also the matching code needs updating for newline handling, but I think this is nicer, the argument lists are now given just once, - Updated comment on args_test, - Updated other comments. There should be no change in what is tested after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-06gdbserver: handle newlines in inferior argumentsAndrew Burgess1-15/+5
Similarly to how single quotes were mishandled, which was fixed two commits ago, this commit fixes handling of newlines in arguments passed to gdbserver. We already had a test that covered this, gdb.base/args.exp, which, when run with the native-extended-gdbserver board contained several KFAIL covering this situation. In this commit I remove the unnecessary, attempt to quote incoming newlines within arguments, and do some minimal cleanup of the related code. There is additional cleanup that can be done, but I'm leaving that for the next commit. Then I've removed the KFAIL from the test case, and performed some minimal cleanup there too. After this commit the gdb.base/args.exp is 100% passing with the native-extended-gdbserver board file. During review I was pointed to this older series: https://inbox.sourceware.org/gdb-patches/20211022071933.3478427-1-m.weghorn@posteo.de/ which also includes this fix as part of a larger set of changes. I'm giving a Co-Authored-By credit to the author of that original series. I believe this smaller fix brings some benefits on its own, though the original series does offer additional improvements. Once this is merged I'll take a look at rebasing and resubmitting the original series. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27989 Co-Authored-By: Michael Weghorn <m.weghorn@posteo.de> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-06gdbserver: fix handling of trailing empty argumentAndrew Burgess1-3/+6
When I posted the previous patch for review Andreas Schwab pointed out that passing a trailing empty argument also doesn't work. The fix for this is in the same area of code as the previous patch, but is sufficiently different that I felt it deserved a patch of its own. I noticed that passing arguments containing single quotes to gdbserver didn't work correctly: gdb -ex 'set sysroot' --args /tmp/show-args Reading symbols from /tmp/show-args... (gdb) target extended-remote | gdbserver --once --multi - /tmp/show-args Remote debugging using | gdbserver --once --multi - /tmp/show-args stdin/stdout redirected Process /tmp/show-args created; pid = 176054 Remote debugging using stdio Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007ffff7fd3110 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) set args abc "" (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /tmp/show-args \' stdin/stdout redirected Process /tmp/show-args created; pid = 176088 2 args are: /tmp/show-args abc Done. [Inferior 1 (process 176088) exited normally] (gdb) target native Done. Use the "run" command to start a process. (gdb) run Starting program: /tmp/show-args \' 2 args are: /tmp/show-args abc Done. [Inferior 1 (process 176095) exited normally] (gdb) q The 'shows-args' program used here just prints the arguments passed to the inferior. Notice that when starting the inferior using the extended-remote target there is only a single argument 'abc', while when using the native target there is a second argument, the blank line, representing the empty argument. The problem here is that the vRun packet coming from GDB looks like this (I've removing the trailing checksum): $vRun;PROGRAM_NAME;616263; If we compare this to a packet with only a single argument and no trailing empty argument: $vRun;PROGRAM_NAME;616263 Notice the lack of the trailing ';' character here. The problem is that gdbserver processes this string in a loop. At each point we maintain a pointer to the character just after a ';', and then we process everything up to either the next ';' character, or to the end of the string. We break out of this loop when the character we start with (in that loop iteration) is the null-character. This means in the trailing empty argument case, we abort the loop before doing anything with the empty argument. In this commit I've updated the loop, we now break out using a 'break' statement at the end of the loop if the (sub-)string we just processed was empty, with this change we now notice the trailing empty argument. I've updated the test case to cover this issue. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-06gdbserver: fix handling of single quote argumentsAndrew Burgess2-4/+7
I noticed that passing arguments containing single quotes to gdbserver didn't work correctly: gdb -ex 'set sysroot' --args /tmp/show-args Reading symbols from /tmp/show-args... (gdb) target extended-remote | gdbserver --once --multi - /tmp/show-args Remote debugging using | gdbserver --once --multi - /tmp/show-args stdin/stdout redirected Process /tmp/show-args created; pid = 176054 Remote debugging using stdio Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007ffff7fd3110 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) set args \' (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /tmp/show-args \' stdin/stdout redirected Process /tmp/show-args created; pid = 176088 2 args are: /tmp/show-args \' Done. [Inferior 1 (process 176088) exited normally] (gdb) target native Done. Use the "run" command to start a process. (gdb) run Starting program: /tmp/show-args \' 2 args are: /tmp/show-args ' Done. [Inferior 1 (process 176095) exited normally] (gdb) q The 'shows-args' program used here just prints the arguments passed to the inferior. Notice that when starting the inferior using the extended-remote target the second argument is "\'", while when running using native target the argument is "'". The second of these is correct, the \' used with the "set args" command is just to show GDB that the single quote is not opening an argument string. It turns out that the extra backslash is injected on the gdbserver side when gdbserver processes the arguments that GDB passes it, the code that does this was added as part of this much larger commit: commit 2090129c36c7e582943b7d300968d19b46160d84 Date: Thu Dec 22 21:11:11 2016 -0500 Share fork_inferior et al with gdbserver In this commit I propose removing the specific code that adds what I believe is a stray backslash. I've extended an existing test to cover this case, and I now see identical behaviour when using an extended-remote target as with the native target. This partially fixes PR gdb/27989, though there are still some issues with newline handling which I'll address in a later commit. During review I was pointed to this older series: https://inbox.sourceware.org/gdb-patches/20211022071933.3478427-1-m.weghorn@posteo.de/ which also includes this fix as part of a larger set of changes. I'm giving a Co-Authored-By credit to the author of that original series. I believe this smaller fix brings some benefits on its own, though the original series does offer additional improvements. Once this is merged I'll take a look at rebasing and resubmitting the original series. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27989 Co-Authored-By: Michael Weghorn <m.weghorn@posteo.de> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: fix reread_symbols when an objfile has target: prefixAndrew Burgess2-0/+196
When using a remote target, it is possible to tell GDB that the executable to be debugged is located on the remote machine, like this: (gdb) target extended-remote :54321 ... snip ... (gdb) file target:/tmp/hello.x Reading /tmp/hello.x from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /tmp/hello.x from remote target... Reading symbols from target:/tmp/hello.x... (gdb) So far so good. However, when we try to start the inferior we run into a small problem: (gdb) set remote exec-file /tmp/hello.x (gdb) start `target:/tmp/hello.x' has disappeared; keeping its symbols. Temporary breakpoint 1 at 0x401198: file /tmp/hello.c, line 18. Starting program: target:/tmp/hello.x ... snip ... Temporary breakpoint 1, main () at /tmp/hello.c:18 18 printf ("Hello World\n"); (gdb) Notice this line: `target:/tmp/hello.x' has disappeared; keeping its symbols. That's wrong, the executable hasn't been removed, GDB just doesn't know how to check if the remote file has changed, and so falls back to assuming that the file has been removed. In this commit I update reread_symbols to use bfd_stat instead of a direct stat call, this adds support for target: files, and fixes the problem. This change was proposed before in this commit: https://inbox.sourceware.org/gdb-patches/20200114210956.25115-3-tromey@adacore.com/ However, that patch never got merged, and seemed to get stuck discussing issues around gnulib stat vs system stat as used by BFD. I didn't 100% understand the issues discussed in that thread, however, I think the problem with the previous thread related to the changes in gdb_bfd.c, rather than to the change in symfile.c. As such, I think this change might be acceptable, my reasoning is: - the objfile::mtime field is set by a call to bfd_get_mtime (see objfiles.c), which calls bfd_stat under the hood. This will end up using the system stat, - In symfile.c we currently call stat directly, which will call the gnulib stat, which, if I understand the above thread correctly, might give a different result to the system stat in some cases, - By switching to using bfd_stat in symfile.c we should now be consistently calling the system stat. There is another issue that came up during testing that this commit fixes. Consider this GDB session: $ gdb -q (gdb) target extended-remote | ./gdbserver/gdbserver --multi --once - Remote debugging using | ./gdbserver/gdbserver --multi --once - Remote debugging using stdio (gdb) file /tmp/hello.x Reading symbols from /tmp/hello.x... (gdb) set remote exec-file /tmp/hello.x (gdb) start ... snip ... (gdb) load `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. Loading section .interp, size 0x1c lma 0x4002a8 ... snip ... Start address 0x0000000000401050, load size 2004 Transfer rate: 326 KB/sec, 87 bytes/write. Notice this line: `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. We actually see the same output, for the same reasons, when using a native target, like this: $ gdb -q (gdb) file /tmp/hello.x Reading symbols from /tmp/hello.x... (gdb) start ... snip ... (gdb) load `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. You can't do that when your target is `native' (gdb) In both cases this line appears because load_command (symfile.c) calls reread_symbols, and reread_symbols loops over every currently loaded objfile and tries to check if the file has changed on disk by calling stat. However, the `system-supplied DSO at 0x7ffff7fcf000' is an in-memory BFD, the filename for this BFD is literally the string 'system-supplied DSO at 0x7ffff7fcf000'. Before this commit GDB would try to use the system 'stat' call to stat the file `system-supplied DSO at 0x7ffff7fcf000', which obviously fails; there's no file with that name (usually). As a consequence of the stat failing GDB prints the ' .... has disappeared ...' line. Initially, all this commit did was switch from using 'stat' to using 'bfd_stat'. Calling bfd_stat on an in-memory BFD works just fine, however, BFD just fills the 'struct stat' buffer with zeros (except for the file size), see memory_bstat in bfd/bfdio.c. However, there is a bit of a weirdness about in-memory BFDs. When they are initially created the libbfd caches an mtime within the bfd object, this is done in bfd_from_remote_memory (elfcode.h), the cached mtime is the time at which the in-memory BFD is created. What this means is that when GDB creates the in-memory BFD, and we call bfd_get_mtime(), the value returned, which GDB caches within objfile::mtime is the creation time of the in-memory BFD. But, when this patch changes to use bfd_stat() we now get back 0, and so we believe that the in-memory BFD has changed. This is a change in behaviour. To avoid this change in behaviour, in this commit, I propose that we always skip in-memory BFDs in reread_symbols. This preserves the behaviour from before this commit -- mostly. As I'm not specifically checking for, and then skipping, in-memory BFDs, we no longer see this line: `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. Which I think is an improvement. Co-Authored-By: Tom Tromey <tromey@adacore.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: remove print_sys_errmsgAndrew Burgess2-3/+3
This started with me running into this comment in symfile.c: /* FIXME, should use print_sys_errmsg but it's not filtered. */ gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"), styled_string (file_name_style.style (), filename)); In this particular case I think I disagree with the comment; I think the output should be a warning rather than just a message printed to gdb_stdout, I think when the executable, or some other objfile that is currently being debugged, disappears from disk, this is likely an unexpected situation, and worth warning the user about. So, in theory, I could just call print_sys_errmsg and remove the comment, but that would mean loosing the filename styling in the output... so in the end I remove the comment and updated the code to call warning. But that got me looking at print_sys_errmsg and how it's used. Currently the function takes a string and an errno, and prints, to stderr, the string followed by the result of calling strerror on the errno. In some places the string passed to print_sys_errmsg is just a filename, and this is used when something goes wrong. In these cases, I think calling warning rather than gdb_printf to gdb_stderr, would be better, and in fact, in a couple of places we manually print a "warning" prefix, and then call print_sys_errmsg. And so, for these users I have added a new function warning_filename_and_errno, which takes a filename, which is printed with styling, and an errno, which is passed through strerror and the resulting string printed. This new function calls warning to print its output. I then updated some of the print_sys_errmsg users to use this new function. Some other users of print_sys_errmsg are also emitting what is clearly a warning, however, the string being passed in is more than just a filename, so the new warning_filename_and_errno function can't be used, it would style the whole string. For these users I have switched to calling warning directly, this allows me to style the warning message correctly. Finally, in inflow.c there is one last call to print_sys_errmsg, in this case I just inlined the definition of print_sys_errmsg. This is a really weird case, as after printing this message GDB just does a hard exit. This is pretty old code, dating back to the initial GDB import, I guess it should be updated to call error() maybe, but I'm reluctant to make this change as part of this commit, just in case there's some reason why we can't throw an error at this point. With that done there are now no users of print_sys_errmsg, and so the old function can be removed. While I was doing all of the above I added some additional filename styling in soure.c, this is in an else block where the if contained the print_sys_errmsg call, so these felt related. And finally, while I was updating the uses of print_sys_errmsg in procfs.c, I noticed that we used a static errmsg buffer to format some error strings. As the above changes got rid of one of the users of errmsg I also removed the other two users, and the static buffer. There were a couple of tests that depended on the existing output message format that needed updating. In one case we gained an extra 'warning: ' prefix, and in the other 'Warning: ' becomes 'warning: ', I think in both cases the new output is an improvement. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-04gdb/testsuite: XFAIL some gdb.base/fileio.expGuinevere Larsen2-1/+28
Some gdb.base/fileio.exp tests expect the inferior to not have write access to some files. If the test is being run as root, this is never possible. This commit adds a way to identify if the user is root and xfails the tests that expect no write access. Approved-By: Tom de Vries <tdevries@suse.de>
2023-10-04sme2: Extend SME tests to include SME2Luis Machado8-8/+178
Reusing the SME tests, this patch introduces additional tests to exercise reading/writing ZT0, availability of the register set, signal context reading for ZT0 and also core file generation. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-04sme: Add SVE/SME testcasesLuis Machado45-0/+3778
Add 5 SVE/SME tests to exercise all the new features like reading/writing registers, pseudo-registers, signal frames and core files. - Sanity check for SME: Gives a brief smoke test to make sure the most basic of features are working correctly. - ZA unavailability tests: Validates the behavior/content of the ZA register is correct when no payload is available. It also exercises changing the vector lengths. - ZA availability tests: These tests exercise reading/writing to all the possible ZA pseudo-registers, and validates the state is correct. - Core file tests: Validates that core file reading and writing works correctly and that all state dumped/loaded is sane. This is exercised for both Linux Kernel core files and gcore core files. - Signal frame tests: Validates the correct restoration of SME/SVE/FPSIMD values across signal frames. Since some of these tests are very lengthy and take a little while to run (under QEMU at the moment), I decided to parallelize them into smaller chunks so we can throw some more CPU power at them so they run faster. I'd still like to add a few more tests to give the testsuite more coverage in the areas of SME/SVE. Hopefully in the near future that will happen. Just a reminder that these SME tests are currently unsupported when gdb is connected to a remote target. That's because the RSP doesn't support communicating changes in vector lenghts mid-execution, so gdb will always get wrong state from the remote target. Co-Authored-By: Ezra Sitorus <ezra.sitorus@arm.com> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-02gdb/python: reformat file with blackAndrew Burgess1-0/+3
Reformat a Python file with black after this commit: commit 59912fb2d22f8a4bb0862487f12a5cc65b6a013f Date: Tue Sep 19 11:45:36 2023 +0100 gdb: add Python events for program space addition and removal There should be no functional change with this commit.
2023-10-02Add regression test for instructionReference changeTom Tromey2-6/+23
Yesterday I pushed a patch to fix a small oversight in the DAP code that caused an instructionReference to be an array instead of a string. This patch adds a test case for that regression. This required exposing the TON form of the response -- something I mentioned might be necessary when this code was changed to return just the Tcl form. I tested this by backing out yesterday's bug fix and verifying that a failure is seen.
2023-10-02Clean up intermediate values in val_print_packed_array_elementsTom Tromey2-35/+43
Following on Tom de Vries' work in the other array-printers, this patch changes val_print_packed_array_elements to also avoid allocating too many values when printing an Ada packed array.
2023-10-02gdb/testsuite: accept variable number of spaces in ↵Simon Marchi1-2/+2
gdb.base/jit-reader-simple.exp regex I see this failure: FAIL: gdb.base/jit-reader-simple.exp: standalone: change addr: initial run: maint info breakpoints shows jit breakpoint The jit breakpoint expected by the test is there, it's just that the number of spaces doesn't match what the test expects, after "jit events": -2 jit events keep y 0x0000555555555119 <__jit_debug_register_code> inf 1 Fix that by relaxing the regex a bit. Change-Id: Ia3b04e6d5978399d940fd1a590f95f15275ca7ac
2023-10-02[gdb/testsuite] Handle older gcc in gdb.ada/import.expTom de Vries1-0/+34
When running test-case gdb.ada/import.exp with gcc 7, most test fail: ... FAIL: gdb.ada/import.exp: print imported_var_ada FAIL: gdb.ada/import.exp: print local_imported_var FAIL: gdb.ada/import.exp: print pkg.imported_var_ada FAIL: gdb.ada/import.exp: print pkg.exported_var_ada FAIL: gdb.ada/import.exp: print exported_var_ada FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at pkg.imported_func_ada FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at imported_func_ada FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at local_imported_func ... When running with gcc 8 or 9, only 2 tests fail: ... FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at pkg.imported_func_ada FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at imported_func_ada ... The test-case passes fully with gcc 10, 11, 12 and 13. Debug info for pragma import seems to not have been supported before gcc 8, so require that version. The two FAILs with gcc 8 and 9 seem to be due to problems in debug info. Add an xfail for these. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-02[gdb/testsuite] Add KFAIL for PR ada/30908Tom de Vries2-4/+44
With gcc 13.2.1, I run into a cluster of fails: ... FAIL: gdb.ada/str_binop_equal.exp: print my_str = "ABCD" FAIL: gdb.ada/widewide.exp: print my_wws = " helo" FAIL: gdb.ada/widewide.exp: print my_ws = "wide" ... The problem is that the debug info contains information about function ada.strings.maps."=", and gdb uses it to implement the comparison. The function is supposed to compare two char sets, not strings, so gdb shouldn't use it. This is PR ada/30908. I don't see the same problem with gcc 7.5.0, because the exec doesn't contain the debug info for the function, because the corresponding object is not linked in. Adter adding "with Ada.Strings.Maps; use Ada.Strings.Maps;" to gdb.ada/widewide/foo.adb I run into the same problem with gcc 7.5.0. Add KFAILs for the PR. Tested on x86_64-linux: - openSUSE Leap 15.4 (using gcc 7.5.0), and - openSUSE Tumbleweed (using gcc 13.2.1). Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30908
2023-10-02gdb: add Python events for program space addition and removalAndrew Burgess3-0/+227
Initially I just wanted a Python event for when GDB removes a program space, I'm writing a Python extension that caches information for each program space, and need to know when I should discard entries for a particular program space. But, it seemed easy enough to also add an event for when GDB adds a new program space, so I went ahead and added both new events. Of course, we don't currently have an observable for program space addition or removal, so I first needed to add these. After that it's pretty simple to add two new Python events and have these trigger. The two new event registries are: events.new_progspace events.free_progspace These emit NewProgspaceEvent and FreeProgspaceEvent objects respectively, each of these new event types has a 'progspace' attribute that contains the relevant gdb.Progspace object. There's a couple of things to be mindful of. First, it is not possible to catch the NewProgspaceEvent for the very first program space, the one that is created when GDB first starts, as this program space is created before any Python scripts are sourced. In order to allow this event to be caught we would need to defer creating the first program space, and as a consequence the first inferior, until some later time. But, existing scripts could easily depend on there being an initial inferior, so I really don't think we should change that -- and so, we end up with the consequence that we can't catch the event for the first program space. The second, I think minor, issue, is that GDB doesn't clean up its program spaces upon exit -- or at least, they are not cleaned up before Python is shut down. As a result, any program spaces in use at the time GDB exits don't generate a FreeProgspaceEvent. I'm not particularly worried about this for my use case, I'm using the event to ensure that a cache doesn't hold stale entries within a single GDB session. It's also easy enough to add a Python at-exit callback which can do any final cleanup if needed. Finally, when testing, I did hit a slightly weird issue with some of the remote boards (e.g. remote-stdio-gdbserver). As a consequence of this issue I see some output like this in the gdb.log: (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1 step FreeProgspaceEvent: <gdb.Progspace object at 0x7fb7e1d19c10> warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. warning: cannot close "target:/lib64/libc.so.6": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. warning: cannot close "target:/lib64/ld-linux-x86-64.so.2": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. do_parent_stuff () at py-progspace-events.c:41 41 ++global_var; (gdb) PASS: gdb.python/py-progspace-events.exp: step The 'FreeProgspaceEvent ...' line is expected, that's my test Python extension logging the event. What isn't expected are all the blocks like: warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. It turns out that this has nothing to do with my changes, this is just a consequence of reading files over the remote protocol. The test forks a child process which GDB stays attached too. When the child exits, GDB cleans up by calling prune_inferiors, which in turn can result in GDB trying to close some files that are open because of the inferior being deleted. If the prune_inferiors call occurs when the remote target is running (and in non-async mode) then GDB will try to send a fileio packet while the remote target is waiting for a stop reply, and the remote target will throw an error, see remote_target::putpkt_binary in remote.c for details. I'm going to look at fixing this, but, as I said, this is nothing to do with this change, I just mention it because I ended up needing to account for these warning messages in one of my tests, and it all looks a bit weird. Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2023-09-29Support the NO_COLOR environment variableTom Tromey14-47/+49
I ran across this site: https://no-color.org/ ... which lobbies for tools to recognize the NO_COLOR environment variable and disable any terminal styling when it is seen. This patch implements this for gdb. Regression tested on x86-64 Fedora 38. Co-Authored-By: Andrew Burgess <aburgess@redhat.com> Reviewed-by: Kevin Buettner <kevinb@redhat.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-28gdb/testsuite: Add relative versus absolute LD_LIBRARY_PATH testKevin Buettner3-0/+145
At one time, circa 2006, there was a bug, which was presumably fixed without adding a test case: If you provided some relative path to the shared library, such as with export LD_LIBRARY_PATH=. then gdb would fail to match the shared library name during the TLS lookup. I think there may have been a bit more to it than is provided by that explanation, since the test also takes care to split the debug info into a separate file. In any case, this commit is based on one of Red Hat's really old local patches. I've attempted to update it and remove a fair amount of cruft, hopefully without losing any critical elements from the test. Testing on Fedora 38 (correctly) shows 1 unsupported test for native-gdbserver and 5 PASSes for the native target as well as native-extended-gdbserver. In his review of v1 of this patch, Lancelot SIX observed that 'thread_local' could be used in place of '__thread' in the C source files. But it only became available via the standard in C11, so I used additional_flags=-std=c11 for compiling both the shared object and the main program. Also, while testing with CC_FOR_TARGET=clang, I found that 'additional_flags=-Wl,-soname=${binsharedbase}' caused clang to complain that this linker flag was unused when compiling the source file, so I moved this linker option to 'ldflags='. My testing for this v2 patch shows the same results as with v1, but I've done additional testing with CC_FOR_TARGET=clang as well. The results are the same as when gcc is used. Co-Authored-by: Jan Kratochvil <jan@jankratochvil.net> Reviewed-By: Lancelot Six <lancelot.six@amd.com>
2023-09-28gdb: use reopen_exec_file from reread_symbolsAndrew Burgess1-5/+0
This commit fixes an issue that was discovered while writing the tests for the previous commit. I noticed that, when GDB restarts an inferior, the executable_changed event would trigger twice. The first notification would originate from: #0 exec_file_attach (filename=0x4046680 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513 #1 0x00000000006f3adb in reopen_exec_file () at ../../src/gdb/corefile.c:122 #2 0x0000000000e6a3f2 in generic_mourn_inferior () at ../../src/gdb/target.c:3682 #3 0x0000000000995121 in inf_child_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/inf-child.c:192 #4 0x0000000000995cff in inf_ptrace_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/inf-ptrace.c:125 #5 0x0000000000a32472 in linux_nat_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/linux-nat.c:3609 #6 0x0000000000e68a40 in target_mourn_inferior (ptid=...) at ../../src/gdb/target.c:2761 #7 0x0000000000a323ec in linux_nat_target::kill (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/linux-nat.c:3593 #8 0x0000000000e64d1c in target_kill () at ../../src/gdb/target.c:924 #9 0x00000000009a19bc in kill_if_already_running (from_tty=1) at ../../src/gdb/infcmd.c:328 #10 0x00000000009a1a6f in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:381 #11 0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527 #12 0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95 While the second originates from: #0 exec_file_attach (filename=0x3d7a1d0 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513 #1 0x0000000000dfe525 in reread_symbols (from_tty=1) at ../../src/gdb/symfile.c:2517 #2 0x00000000009a1a98 in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:398 #3 0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527 #4 0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95 In the first case the call to exec_file_attach first passes through reopen_exec_file. The reopen_exec_file performs a modification time check on the executable file, and only calls exec_file_attach if the executable has changed on disk since it was last loaded. However, in the second case things work a little differently. In this case GDB is really trying to reread the debug symbol. As such, we iterate over the objfiles list, and for each of those we check the modification time, if the file on disk has changed then we reload the debug symbols from that file. However, there is an additional check, if the objfile has the same name as the executable then we will call exec_file_attach, but we do so without checking the cached modification time that indicates when the executable was last reloaded, as a result, we reload the executable twice. In this commit I propose that reread_symbols be changed to unconditionally call reopen_exec_file before performing the objfile iteration. This will ensure that, if the executable has changed, then the executable will be reloaded, however, if the executable has already been recently reloaded, we will not reload it for a second time. After handling the executable, GDB can then iterate over the objfiles list and reload them in the normal way. With this done I now see the executable reloaded only once when GDB restarts an inferior, which means I can remove the kfail that I added to the gdb.python/py-exec-file.exp test in the previous commit. Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28gdb/python: make the executable_changed event available from PythonAndrew Burgess1-0/+100
This commit makes the executable_changed observable available through the Python API as an event. There's nothing particularly interesting going on here, it just follows the same pattern as many of the other Python events we support. The new event registry is called events.executable_changed, and this emits an ExecutableChangedEvent object which has two attributes, a gdb.Progspace called 'progspace', this is the program space in which the executable changed, and a Boolean called 'reload', which is True if the same executable changed on disk and has been reloaded, or is False when a new executable has been loaded. One interesting thing did come up during testing though, you'll notice the test contains a setup_kfail call. During testing I observed that the executable_changed event would trigger twice when GDB restarted an inferior. However, the ExecutableChangedEvent object is identical for both calls, so the wrong information is never sent out, we just see one too many events. I tracked this down to how the reload_symbols function (symfile.c) takes care to also reload the executable, however, I've split fixing this into a separate commit, so see the next commit for details. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28gdb/python: new Progspace.executable_filename attributeAndrew Burgess2-0/+122
Add a new Progspace.executable_filename attribute that contains the path to the executable for this program space, or None if no executable is set. The path within this attribute will be set by the "exec-file" and/or "file" commands. Accessing this attribute for an invalid program space will raise an exception. This new attribute is similar too, but not the same as the existing gdb.Progspace.filename attribute. If I could change the past, I'd change the 'filename' attribute to 'symbol_filename', which is what it actually represents. The old attribute will be set by the 'symbol-file' command, while the new attribute is set by the 'exec-file' command. Obviously the 'file' command sets both of these attributes. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28gdb/python: new Progspace.symbol_file attributeAndrew Burgess1-0/+9
Add a new Progspace.symbol_file attribute. This attribute holds the gdb.Objfile object that corresponds to Progspace.filename, or None if there is no main symbol file currently set. Currently, to get this gdb.Objfile, a user would need to use Progspace.objfiles, and then search for the objfile with a name that matches Progspace.filename -- which should work just fine, but having direct access seems a little nicer. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2023-09-28[gdb/testsuite] Add nopie to gdb.base/unwind-on-each-insn-amd64-2.expTom de Vries5-7/+23
When running test-case gdb.base/unwind-on-each-insn-amd64-2.exp with target board unix/-fPIE/-pie, I run into: ... gdb compile failed, ld: unwind-on-each-insn-amd64-21.o: relocation \ R_X86_64_32S against `.text' can not be used when making a PIE object; \ recompile with -fPIE ld: failed to set dynamic section sizes: bad value ... Fix this by hardcoding nopie in the test-case, and for good measure in the other test-cases that source unwind-on-each-insn.exp.tcl and use a .s file. Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>