aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2025-01-11Use bool in linespecTom Tromey1-21/+21
This changes various spots in linespec to use a bool rather than an int. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-11Hoist lambda in linespec.c:add_matching_symbols_to_infoTom Tromey1-5/+7
I noticed that two parts of linespec.c:add_matching_symbols_to_info use the same lambda, and hoisting this seems slightly more efficient. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-11Minor cleanup in linespec.c:add_minsymTom Tromey1-5/+2
This cleans up a 'return' in linespec.c:add_minsym. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-11Use std::vector in linespec_stateTom Tromey1-31/+14
This changes linespec_state to use a std::vector, and changes linespec_canonical_name to use std::string. This removes some manual memory management, including some odd cleanup code in in decode_line_full. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-11Use gdb::unordered_set in linespec_stateTom Tromey1-67/+22
This patch changes linespec_state to use gdb::unordered_set. This simplifies the code a little and removes some manual management. It also replaces address_entry with a std::pair, which simplifies the code even more; and since this is a private type, IMO it doesn't reduce readability at all. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-11Add constructor and destructor to linespec_stateTom Tromey1-74/+61
This changes linespec_state to have real constructors and a destructor. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-10GDB: Use gdb::array_view for buffers used in register reading and unwindingThiago Jung Bauermann4-39/+48
This allows checking the size of the given buffer. Changes frame_register_unwind (), frame_unwind_register (), get_frame_register () and deprecated_frame_register_read (). As pointed out by Baris, in the case of MIPS target code this is best done by changing a couple of alloca-based buffers in mips_read_fp_register_single and mips_print_fp_register to gdb::byte_vector instances. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-10GDB: frame: Make VALUEP argument optional in frame_register_unwindThiago Jung Bauermann3-5/+5
It already accepts a nullptr value and a couple of places were always calling it that way, so make it possible to omit the argument entirely. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-10Minor test case updates for gnat-llvmTom Tromey12-3/+156
gnat-llvm seems to be a bit more aggressive about eliminating unused variables. This patch improves the test results a tiny bit by arranging for some variables to appear to be used. Note the copyright dates on the new files are done that way because I simply copied existing files.
2025-01-10[gdb/tdep] Fix gdb.cp/non-trivial-retval.exp on riscv64-linuxTom de Vries3-1/+30
With test-case gdb.cp/non-trivial-retval.exp on riscv64-linux, I ran into: ... (gdb) finish^M Run till exit from #0 f1 (i1=i1@entry=23, i2=i2@entry=100) \ at non-trivial-retval.cc:34^M main () at non-trivial-retval.cc:163^M 163 B b = f2 (i1, i2);^M Value returned is $6 = {a = -5856}^M (gdb) FAIL: $exp: finish from f1 ... where "Value returned is $6 = {a = 123}" is expected. The problem is that gdb thinks that the return value is in $a0: ... $ gdb -q -batch non-trivial-retval \ -ex "b f1" \ -ex run \ -ex "set debug riscv infcall on" \ -ex finish Breakpoint 1 at 0x80a: file non-trivial-retval.cc, line 34. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1". Breakpoint 1, f1 (i1=i1@entry=23, i2=i2@entry=100) at non-trivial-retval.cc:34 34 { [riscv-infcall] riscv_return_value: \ [R] type: 'A', length: 0x4, alignment: 0x4, register a0 [riscv-infcall] riscv_return_value: \ [R] type: 'A', length: 0x4, alignment: 0x4, register a0 [riscv-infcall] riscv_return_value: \ [R] type: 'A', length: 0x4, alignment: 0x4, register a0 main () at non-trivial-retval.cc:163 163 B b = f2 (i1, i2); Value returned is $1 = {a = -3568} ... while $a0 actually contains a pointer to the returned value 123: ... (gdb) p /x $a0 $3 = 0x3ffffff210 (gdb) p *((unsigned int *)$a0) $5 = 123 ... The returned type is: ... class A { public: A () {} A (A &obj); int a; }; ... which is a C++ aggregate with a nontrivial (because it's user-defined) copy constructor: According to the ABI [1], indeed this is returned by reference: ... Values are returned in the same manner as a first named argument of the same type would be passed. If such an argument would have been passed by reference, the caller allocates memory for the return value, and passes the address as an implicit first parameter. ... Aggregates larger than 2×XLEN bits are passed by reference and are replaced in the argument list with the address, as are C++ aggregates with nontrivial copy constructors, destructors, or vtables. ... Fix this in riscv_call_arg_scalar_int by checking for language_pass_by_reference ().trivially_copy_constructible. The vtable case is explictly mentioned in the ABI, but AFAIU already covered by the nontrivial copy constructor case. The nontrivial destructor case is also not supported, but the testsuite doesn't seem to trigger this. Fix this by: - extending the test-case to cover this scenario, and - fixing it in riscv_call_arg_scalar_int by checking for language_pass_by_reference ().trivially_destructible. Tested on riscv64-linux. PR tdep/32152 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32152 Approved-By: Andrew Burgess <aburgess@redhat.com> [1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc
2025-01-10[gdb/testsuite] Fix gdb.rust/completion.exp timeout on riscv64-linuxTom de Vries1-1/+3
On riscv64-linux, with test-case gdb.rust/completion.exp I run into the following timeout: ... (gdb) complete break pars^M FAIL: gdb.rust/completion.exp: complete break pars (timeout) ... Replaying the scenario outside the testsuite show us that the command takes ~13 seconds: ... $ gdb -q -batch -x gdb.in ... 2025-01-08 12:23:46.853 - command started +complete break pars break parse.rs break parse_printf_format break parse_running_mmaps_unix.rs break parser.rs 2025-01-08 12:23:59.600 - command finished Command execution time: 12.677752 (cpu), 12.748565 (wall) ... while the timeout is 10 seconds. The riscv64 processor on the server (cfarm91) is not fast (a fair amount of the skip_huge_test test-cases times out), but something else is going on as well. For x86_64-linux, roughly measuring the size of debug info in the exec get us: ... $ readelf -wi outputs/gdb.rust/completion/completion | wc -l 2007 ... while on the riscv64 server I get: ... $ readelf -wi outputs/gdb.rust/completion/completion | wc -l 1606950 ... So it seems reasonable that the test is somewhat slower on riscv64. Fix this by using timeout factor 2. Tested on riscv64-linux and x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2025-01-10[gdb/build, c++20] Fix build with gcc 10Tom de Vries1-1/+7
With gcc 10 and -std=c++20, we run into the same problem as reported in commit 6feae66da1d ("[gdb/build, c++20] Handle deprecated std::allocator::construct"). The problem was fixed using: ... -template<typename T, typename A = std::allocator<T>> +template<typename T, + typename A +#if __cplusplus >= 202002L + = std::pmr::polymorphic_allocator<T> +#else + = std::allocator<T> +#endif + > ... but that doesn't work for gcc 10, because it defines __cplusplus differently: ... $ echo | g++-10 -E -dD -x c++ - -std=c++20 2>&1 | grep __cplusplus #define __cplusplus 201709L $ echo | g++-11 -E -dD -x c++ - -std=c++20 2>&1 | grep __cplusplus #define __cplusplus 202002L ... Fix this by using the library feature test macro __cpp_lib_polymorphic_allocator [1], which is undefined for c++17 and defined for c++20: ... $ echo | g++-10 -E -dD -x c++ - -include memory_resource -std=c++17 2>&1 \ | grep __cpp_lib_polymorphic_allocator $ echo | g++-10 -E -dD -x c++ - -include memory_resource -std=c++20 2>&1 \ | grep __cpp_lib_polymorphic_allocator #define __cpp_lib_polymorphic_allocator 201902L $ ... A similar problem exists for commit 3173529d7de ("[gdb/guile, c++20] Work around Werror=volatile in libguile.h"). Fix this by testing for 201709L instead. Tested on x86_64-linux, by building gdb with {gcc 10, clang 17.0.6} x {-std=c++17, -std=c++20}. PR build/32503 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32503 Approved-By: Tom Tromey <tom@tromey.com> [1] https://en.cppreference.com/w/cpp/feature_test#cpp_lib_polymorphic_allocator
2025-01-09GDB: trad-frame: Store length of value_bytes in trad_frame_saved_regThiago Jung Bauermann7-22/+35
The goal is to ensure that it is available in frame_unwind_got_bytes () to make sure that the provided buf isn't larger than the size of the register being provisioned. In the process, regcache's cached_reg_t::data also needed to be converted to a gdb::byte_vector, so that the register contents' size can be tracked. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-09GDB: remote: Print total bytes received in debug messageThiago Jung Bauermann1-2/+2
This is useful information I missed while debugging issues with the g packet reply. Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-09[gdb/tdep] Fix gdb.base/readnever.exp on s390xTom de Vries2-0/+40
On s390x-linux, I run into: ... (gdb) backtrace #0 0x000000000100061a in fun_three () #1 0x000000000100067a in fun_two () #2 0x000003fffdfa9470 in ?? () Backtrace stopped: frame did not save the PC (gdb) FAIL: gdb.base/readnever.exp: backtrace ... This is really due to a problem handling the fun_three frame. When generating a backtrace from fun_two, everying looks ok: ... $ gdb -readnever -q -batch outputs/gdb.base/readnever/readnever \ -ex "b fun_two" \ -ex run \ -ex bt ... #0 0x0000000001000650 in fun_two () #1 0x00000000010006b6 in fun_one () #2 0x00000000010006ee in main () ... For reference the frame info with debug info (without -readnever) looks like this: ... $ gdb -q -batch outputs/gdb.base/readnever/readnever \ -ex "b fun_three" \ -ex run \ -ex "info frame" ... Stack level 0, frame at 0x3fffffff140: pc = 0x1000632 in fun_three (readnever.c:20); saved pc = 0x100067a called by frame at 0x3fffffff1f0 source language c. Arglist at 0x3fffffff140, args: a=10, b=49 '1', c=0x3fffffff29c Locals at 0x3fffffff140, Previous frame's sp in v0 ... But with -readnever, like this instead: ... Stack level 0, frame at 0x0: pc = 0x100061a in fun_three; saved pc = 0x100067a called by frame at 0x3fffffff140 Arglist at 0xffffffffffffffff, args: Locals at 0xffffffffffffffff, Previous frame's sp in r15 ... An obvious difference is the "Previous frame's sp in" v0 vs. r15. Looking at the code: ... 0000000001000608 <fun_three>: 1000608: b3 c1 00 2b ldgr %f2,%r11 100060c: b3 c1 00 0f ldgr %f0,%r15 1000610: e3 f0 ff 50 ff 71 lay %r15,-176(%r15) 1000616: b9 04 00 bf lgr %r11,%r15 ... it becomes clear what is going on. This is an unusual prologue. Rather than saving r11 (frame pointer) and r15 (stack pointer) to stack, instead they're saved into call-clobbered floating point registers. [ For reference, this is the prologue of fun_two: ... 0000000001000640 <fun_two>: 1000640: eb bf f0 58 00 24 stmg %r11,%r15,88(%r15) 1000646: e3 f0 ff 50 ff 71 lay %r15,-176(%r15) 100064c: b9 04 00 bf lgr %r11,%r15 ... where the first instruction stores registers r11 to r15 to stack. ] Gdb fails to properly analyze the prologue, which causes the problems getting the frame info. Fix this by: - adding handling of the ldgr insn [1] in s390_analyze_prologue, and - recognizing the insn as saving a register in s390_prologue_frame_unwind_cache. This gets us instead: ... Stack level 0, frame at 0x0: pc = 0x100061a in fun_three; saved pc = 0x100067a called by frame at 0x3fffffff1f0 Arglist at 0xffffffffffffffff, args: Locals at 0xffffffffffffffff, Previous frame's sp in f0 ... and: ... (gdb) backtrace^M #0 0x000000000100061a in fun_three ()^M #1 0x000000000100067a in fun_two ()^M #2 0x00000000010006b6 in fun_one ()^M #3 0x00000000010006ee in main ()^M (gdb) PASS: gdb.base/readnever.exp: backtrace ... Tested on s390x-linux. PR tdep/32417 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32417 Approved-By: Andreas Arnez <arnez@linux.ibm.com> [1] https://www.ibm.com/support/pages/sites/default/files/2021-05/SA22-7871-10.pdf
2025-01-09[gdb/tdep] Use symbolic constants in s390_prologue_frame_unwind_cacheTom de Vries1-2/+2
In s390_prologue_frame_unwind_cache there are two loops using a hardcoded constant 16: ... for (i = 0; i < 16; i++) if (s390_register_call_saved (gdbarch, S390_R0_REGNUM + i) ... for (i = 0; i < 16; i++) if (s390_register_call_saved (gdbarch, S390_F0_REGNUM + i) ... Fix this by using symbolic constants S390_NUM_GPRS and S390_NUM_FPRS instead. Tested on s390x-linux, by rebuilding. Approved-By: Andreas Arnez <arnez@linux.ibm.com>
2025-01-09[gdb/testsuite] Run one more test-case with ↵Tom de Vries1-1/+11
ASAN_OPTIONS=verify_asan_link_order=0 After building gdb with asan, and running test-case gdb.trace/basic-libipa.exp, I got: ... (gdb) run ^M Starting program: basic-libipa ^M [Thread debugging using libthread_db enabled]^M Using host libthread_db library "/lib64/libthread_db.so.1".^M ==7705==ASan runtime does not come first in initial library list; you should \ either link runtime to your application or manually preload it with \ LD_PRELOAD.^M [Inferior 1 (process 7705) exited with code 01]^M (gdb) FAIL: gdb.trace/basic-libipa.exp: runto: run to main ... Fix this in the same way as in commit 75948417af8 ("[gdb/testsuite] Run two test-cases with ASAN_OPTIONS=verify_asan_link_order=0"). Tested on x86_64-linux.
2025-01-09gdb: boolify thread_info's 'stop_requested' fieldTankut Baris Aktemur3-6/+6
Boolify the field. The 'set_stop_requested' function was already taking a bool parameter, whose value is assigned to the field. Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-01-08Rename two Ada test suite functionsTom Tromey2-4/+4
I happened to notice that the Ada compiler emitted a warning when compiling a couple of DAP tests. This wasn't intentional, and this patch renames the functions to match the filename.
2025-01-08GDB, gdbserver: Convert regcache_register_size function to methodThiago Jung Bauermann6-15/+16
The regcache_register_size function has one implementation in GDB, and one in gdbserver. Both of them have a gdb::checked_static_cast to their corresponding regcache class. This can be avoided by defining a pure virtual register_size method in the reg_buffer_common class, which is then implemented by the reg_buffer class in GDB, and by the regcache class in gdbserver. Calls to the register_size () function from methods of classes in the reg_buffer_common hierarchy need to be changed to calls to the newly defined method, otherwise the compiler complains that a matching method cannot be found. Co-Authored-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Simon Marchi <simon.marchi@efficios.com> Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> Change-Id: I7f4f74a51e96c42604374e87321ca0e569bc07a3
2025-01-08[gdb/testsuite] Check gnatmake version in gdb.ada/scalar_storage.expTom de Vries1-1/+1
On a system with gcc 14.2.0 and gnatmake 13.3.0 I run into: ... (gdb) PASS: gdb.ada/scalar_storage.exp: print V_LE get_compiler_info: gcc-14-2-0 print V_BE^M $2 = (value => 126, another_value => 12, color => red)^M (gdb) FAIL: gdb.ada/scalar_storage.exp: print V_BE ... The test-case contains a corresponding kfail: ... # This requires a compiler fix that is in GCC 14. if {[gcc_major_version] < 14} { setup_kfail "DW_AT_endianity on enum types" *-*-* } ... which doesn't trigger because it checks the gcc version rather than the gnatmake version. Fix this by checking the gnatmake version instead. Tested on aarch64-linux and x86_64-linux.
2025-01-08[gdb/testsuite] Require can_spawn_for_attach in gdb.base/gstack.expTom de Vries1-0/+2
I ran test-case gdb.base/gstack.exp on a machine with kernel.yama.ptrace_scope set to 1 and ran into: ... PASS: gdb.base/gstack.exp: spawn gstack ptrace: Operation not permitted.^M GSTACK-END^M PASS: gdb.base/gstack.exp: gstack exits with no error PASS: gdb.base/gstack.exp: gstack's exit status is 0 FAIL: gdb.base/gstack.exp: got backtrace ... Fix this by requiring can_spawn_for_attach. Tested on x86_64-linux.
2025-01-08[gdb/testsuite] Require supports_process_record in ↵Tom de Vries1-0/+2
gdb.reverse/test_ioctl_TCSETSW.exp I ran test-case gdb.reverse/test_ioctl_TCSETSW.exp on riscv64-linux, and got: ... (gdb) record full^M Process record: the current architecture doesn't support record function.^M (gdb) FAIL: gdb.reverse/test_ioctl_TCSETSW.exp: record full ... Fix this by requiring supports_process_record. Tested on riscv64-linux and x86_64-linux.
2025-01-08[gdb/testsuite] Fix gdb.base/reset-catchpoint-cond.exp for ↵Tom de Vries1-1/+2
!supports_catch_syscall I ran test-case gdb.base/reset-catchpoint-cond.exp on riscv64-linux, and got: ... (gdb) catch syscall write^M The feature 'catch syscall' is not supported on this architecture yet.^M (gdb) FAIL: $exp: mode=syscall: catch syscall write ... Fix this by checking for supports_catch_syscall. Tested on riscv64-linux and x86_64-linux.
2025-01-07Rename two maint commandsTom Tromey7-18/+26
This renames two maint commands, removing a hyphen from "check-symtabs" and "check-psymtabs"; that is, moving them under the existing "maint check" prefix. Regression tested on x86-64 Fedora 40. Reviewed-By: Tom de Vries <tdevries@suse.de> Approved-By: Andrew Burgess <aburgess@redhat.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2025-01-07Fix crash in DWARF indexerTom Tromey2-0/+68
Iain pointed out a crash in the DWARF indexer when run on a certain D program. The DWARF in this case has a nameless enum class; this causes an assertion failure. This patch arranges to simply ignore such types. The fact that an enum class is nameless in this case appears to be a compiler bug. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32518 Approved-By: Tom de Vries <tdevries@suse.de>
2025-01-07testsuite: adapt to new --debug command line optionChristina Schimpe2-15/+38
Since commit "gdbserver: allow the --debug command line option to take a value", gdbserver no longer supports --debug --remote-debug --event-loop-debug. Instead, --debug now takes a comma separated list of components. The make check parameter GDBSERVER_DEBUG doesn't support these changes yet. This patch fixes this, by adding the --debug gdbserver arguments, as "debug-threads", "debug-remote", "debug-event-loop" or "debug-all" for GDBSERVER_DEBUG. Replay logging is still enabled by adding the "replay" GDBSERVER_DEBUG argument. We can also configure "all" to enable all of the available options. Now, for instance, we can use it as follows: make check GDBSERVER_DEBUG="debug-remote,debug-event-loop,replay" RUNTESTFLAGS="--target_board=native-gdbserver" TESTS="gdb.trace/ftrace.exp" or simply make check GDBSERVER_DEBUG="all" RUNTESTFLAGS="--target_board=native-gdbserver" TESTS="gdb.trace/ftrace.exp" to enable all debug options. Approved-By: Tom Tromey <tom@tromey.com>
2025-01-07Clarify documentation of signal numbersTom Tromey1-0/+28
A user was confused by the meaning of signal numbers in the gdb CLI. For instance, when using "signal 3", exactly which signal is delivered? Is it always 3, or is it always SIGQUIT? This patch attempts to clarify the documentation here.
2025-01-06[gdb/cli] Show LOC_CONST_BYTES var for info localsTom de Vries2-1/+16
PR cli/32525 reports that a variable with this DWARF: .. <2><423>: Abbrev Number: 14 (DW_TAG_variable) <424> DW_AT_name : var1867 <42a> DW_AT_type : <0x2f8> <42e> DW_AT_const_value : 8 byte block: 0 0 0 0 0 0 0 0 ... is not shown by info locals. Fix this by handling LOC_CONST_BYTES in iterate_over_block_locals. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32525 Approved-By: Tom Tromey <tom@tromey.com>
2025-01-06Fix procfs.c compilationRainer Orth1-0/+1
procfs.c compilation is currently broken on Solaris: /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c: In member function ‘virtual ptid_t procfs_target::wait(ptid_t, target_waitstatus*, target_wait_flags)’: /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2067:34: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’? 2067 | wait_retval = gdb::wait (&wstat); | ^~~~ In file included from ../gnulib/import/sys/wait.h:28, from /usr/include/stdlib.h:16, from /usr/gcc/14/include/c++/14.2.0/cstdlib:79, from /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/../gdbsupport/common-defs.h:99, from /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/defs.h:26, from <command-line>: /usr/include/sys/wait.h:85:14: note: ‘wait’ declared here 85 | extern pid_t wait(int *); | ^~~~ /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2154:41: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’? 2154 | int temp = gdb::wait (&wstat); | ^~~~ /usr/include/sys/wait.h:85:14: note: ‘wait’ declared here 85 | extern pid_t wait(int *); | ^~~~ /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c: In function ‘void unconditionally_kill_inferior(procinfo*)’: /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2566:12: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’? 2566 | gdb::wait (NULL); | ^~~~ /usr/include/sys/wait.h:85:14: note: ‘wait’ declared here 85 | extern pid_t wait(int *); | ^~~~ The use of gdb::wait was introduced in commit 4e4dfc4728622d83c5d600949024449e21de868a Author: Tom de Vries <tdevries@suse.de> Date: Fri Nov 22 17:44:29 2024 +0100 [gdb] Add gdb::wait but obviously never tested. Fixed by including gdbsupport/eintr.h to provide the declaration. Tested on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11.
2025-01-06Handle linesStartAt1 in DAPTom Tromey8-20/+119
The DAP initialize request has a "linesStartAt1" option, where the client can indicate that it prefers whether line numbers be 0-based or 1-based. This patch implements this. I audited all the line-related code in the DAP implementation. Note that while a similar option exists for column numbers, gdb doesn't handle these yet, so nothing is done here. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32468
2025-01-06Don't lex floating-point number in Rust field expressionTom Tromey3-40/+55
Consider this Rust tuple: let tuple_tuple = ((23i32, 24i32), 25i32); Here, the value is a tuple whose first element is also a tuple. You should be able to print this with: (gdb) print tuple_tuple.0.1 However, currently the Rust lexer sees "0.1" as a floating-point number. This patch fixes the problem by introducing a special case in the lexer: when parsing a field expression, the parser informs the lexer that a number should be handled as a decimal integer only. This change then lets us remove the decimal integer special case from lex_number. v2: I realized that the other DECIMAL_INTEGER cases aren't needed any more. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32472
2025-01-06Remove "then" from test suiteTom Tromey9-18/+17
This removes the "then" keyword from the test suite. Andrew did this once before, but some new ones crept in. This also adds braces to the "if" conditions and normalizes the failures to just use "return".
2025-01-06[gdb/build] Use const_cast in fd_copyTom de Vries1-1/+1
Recent commit 6ab5d62ebc5 ("[gdb] Fix compilation error in event-top.c") did: ... fd_copy (fd_set *dst, const fd_set *src, int n) { FD_ZERO (dst); for (int i = 0; i < n; ++i) - if (FD_ISSET (i, src)) + if (FD_ISSET (i, (fd_set *)src)) ... but according to [1] only const_cast may be used to cast away constness. Fix this by using const_cast. Tested by rebuilding on x86_64-linux. [1] https://en.cppreference.com/w/cpp/language/const_cast
2025-01-05Some small cleanups in add_symbol_overload_list_qualifiedTom Tromey1-16/+13
This applies some more cleanups to add_symbol_overload_list_qualified, consolidating calls to get_selected_block. It also moves the symtab expansion call after the code that walks up from the selected block, merging two loops.
2025-01-05Fix latent bug in Ada import symbol handlingTom Tromey1-1/+5
The code in dwarf2/read.c:new_symbol that handles Ada 'import' symbols has a bug. It uses the current scope, which by default this is the file scope -- even for a global symbol like: <1><1186>: Abbrev Number: 4 (DW_TAG_variable) <1187> DW_AT_name : (indirect string, offset: 0x1ad2): pkg__imported_var_ada ... <1196> DW_AT_external : 1 This disagrees with the scope computed by the DWARF indexer. Now, IMO new_symbol and its various weirdness really has to go. And, ideally, this information would come from the indexer rather than perhaps being erroneously recomputed. But meanwhile, this patch fixes the issue at hand. This came up while working on another change that exposes the bug. Reviewed-By: Tom de Vries <tdevries@suse.de>
2025-01-04[gdb/testsuite] Add gdb.python/py-commands-breakpoint.expTom de Vries3-0/+135
A recent discussion about what commands are allowed during gdb.Breakpoint.stop, made me wonder if there would be less restrictions if we'd do those commands as part of a breakpoint command list instead. Attribute gdb.Breakpoint.commands is a string with gdb commands, so I tried implementing a new class PyCommandsBreakpoint, derived from gdb.Breakpoint, that supports a py_commands method. My original idea was to forbid setting PyCommandsBreakpoint.commands, and do: ... def py_commands(self): print("VAR: %d" % self.var) self.var += 1 gdb.execute("continue") ... but as it turns out 'gdb.execute("continue")' does not behave the same way as continue. I've filed PR python/32454 about this. So the unsatisfactory solution is to first execute PyCommandsBreakpoint.py_commands: ... def py_commands(self): print("VAR: %d" % self.var) self.var += 1 ... and then: ... self.commands = "continue" ... I was hoping for a better outcome, but having done the work of writing this, I suppose it has use as a test-case, perhaps also as an example of how to work around PR python/32454. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32454
2025-01-04[gdb/tdep] Fix gdb.base/finish-pretty.exp on s390xTom de Vries3-2/+72
On s390x-linux, with test-case gdb.base/finish-pretty.exp I ran into: ... (gdb) finish Run till exit from #0 foo () at finish-pretty.c:28 main () at finish-pretty.c:40 40 return v.a + v.b; Value returned has type: struct s. Cannot determine contents (gdb) FAIL: $exp: finish foo prettyprinted function result ... The function being finished is foo, which returns a value of type struct s. The ABI [1] specifies: - that the value is returned in a storage buffer allocated by the caller, and - that the address of this buffer is passed as a hidden argument in r2. GDB fails to print the value when finishing foo, because it doesn't know the address of the buffer. Implement the gdbarch_get_return_buf_addr hook for s390x to fix this. This is based on ppc_sysv_get_return_buf_addr, the only other implementation of gdbarch_get_return_buf_addr. For readability I've factored out dwarf_reg_on_entry. There is one difference with ppc_sysv_get_return_buf_addr: only NO_ENTRY_VALUE_ERROR is caught. If this patch is approved, I intend to submit a follow-up patch to fix this in ppc_sysv_get_return_buf_addr as well. The hook is not guaranteed to work, because it attempts to get the value r2 had at function entry. The hook can be called after function entry, and the ABI doesn't guarantee that r2 is the same throughout the function. Using -fvar-tracking adds debug information, which allows the hook to succeed more often, and indeed after adding this to the test-case, it passes. Do likewise in one more test-case. Tested on s390x-linux. Fixes: - gdb.ada/finish-large.exp - gdb.base/finish-pretty.exp - gdb.base/retval-large-struct.exp - gdb.cp/non-trivial-retval.exp - gdb.ada/array_return.exp AFAICT, I've also enabled the hook for s390 and from the ABI I get the impression that it should work, but I haven't been able to test it. [1] https://github.com/IBM/s390x-abi
2025-01-04[gdb/selftest] Fix 'help_doc_invariants' self-testEli Zaretskii1-3/+3
Running selftest help_doc_invariants. help doc broken invariant: command 'signal-event' help doc has over-long line Self test failed: self-test failed at unittests/command-def-selftests.c:121 The reason is that doc string of 'signal-event' doesn't have newlines at end of its line. Fix by adding newlines.
2025-01-04[gdb] Fix compilation error in event-top.cEli Zaretskii1-1/+1
CXX event-top.o In file included from d:\usr\include\winsock2.h:69, from ./../gdbsupport/gdb_select.h:30, from event-top.c:43: event-top.c: In function 'fd_set* fd_copy(fd_set*, const fd_set*, int)': event-top.c:1279:22: error: invalid conversion from 'const fd_set*' to 'fd_set*' [-fpermissive] 1279 | if (FD_ISSET (i, src)) | ^ | | | const fd_set* d:\usr\include\winsock.h:164:50: note: initializing argument 2 of 'int __FD_ISSET(SOCKET, fd_set*)' 164 | __CRT_ALIAS int __FD_ISSET( SOCKET __fd, fd_set *__set ) | ~~~~~~~~^~~~~ Use an explicit type cast to prevent this. * gdb/event-top.c (fd_copy): Type-cast in call to FD_ISSET.
2025-01-04[gdb/cli] Warn about forced return from signal trampolineTom de Vries2-2/+9
The Linaro CI reported a regression on arm-linux in test-case gdb.base/sigstep.exp following commit 7b46460a619 ("[gdb/symtab] Apply workaround for PR gas/31115 a bit more") [1]: ... (gdb) return^M Make __default_sa_restorer return now? (y or n) n^M Not confirmed^M (gdb) FAIL: $exp: return from handleri: \ leave signal trampoline (got interactive prompt) ... After installing package glibc-debuginfo and adding --with-separate-debug-dir to the configure flags, I managed to reproduce the FAIL. The regression seems to be a progression in the sense that the function name for the signal trampoline is found. After reading up on the signal trampoline [2] and the return command [3], my understanding is that forced returning from the signal trampoline is potentially unsafe, given that for instance the process signal mask won't be restored. Fix this by: - rather than using the name, using "signal trampoline" in the query, and - adding a warning about returning from a signal trampoline, giving us: ... (gdb) return^M warning: Returning from signal trampoline does not fully restore pre-signal \ state, such as process signal mask.^M Make signal trampoline return now? (y or n) y^M 87 dummy = 0; dummy = 0; while (!done);^M (gdb) PASS: $exp: return from handleri: leave signal trampoline (in main) ... Tested on x86_64-linux. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> [1] https://linaro.atlassian.net/browse/GNU-1459 [2] https://man7.org/linux/man-pages/man2/sigreturn.2.html [3] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Returning.html
2025-01-04[gdb/testsuite] Skip stabs board in make-check-all.shTom de Vries1-1/+1
I ran make-check-all.sh with gdb.linespec/explicit.exp, and the only problems were found with target board stabs. With target board unix the test-case runs in two seconds, but with target board stabs it takes 12 seconds due to a timeout. Stabs support in gdb has been unmaintained for a while, and there's an ongoing discussion to deprecate and remove it (PR symtab/31210). It seems unnecessary to excercise this unmaintained feature in make-check-all.sh, so drop it. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31210
2025-01-03skip -gfile: call fnmatch without FNM_FILE_NAMEFangrui Song4-42/+8
fnmatch is called with the FNM_FILE_NAME flag so that `skip -gfi /usr/*` doesn't match /usr/include/*. This makes the file matching feature not useful for STL headers that reside in multiple directories. In addition, the user cannot use a single `*` to match multiple leading path components. Let's drop the FNM_FILE_NAME flag and remove the assertion from gdb_filename_fnmatch (originally for the auto-load feature).
2024-12-31Use 'flags' when expanding symtabs in gdbpy_lookup_static_symbolsTom Tromey4-5/+32
This changes gdbpy_lookup_static_symbols to pass the 'flags' parameter to expand_symtabs_matching. This should refine the search somewhat. Note this is "just" a performance improvement, as the loop over symtabs already checks 'flags'. v2 also removes 'SEARCH_GLOBAL_BLOCK' and updates py-symbol.exp to verify that this works properly. Thanks to Tom for this insight. Co-Authored-By: Tom de Vries <tdevries@suse.de>
2024-12-29Update gdb/NEWS after GDB 16 branch creation.Joel Brobecker1-1/+3
This commit a new section for the next release branch, and renames the section of the current branch, now that it has been cut.
2024-12-29Bump version to 17.0.50.DATE-git.Joel Brobecker2-2/+2
Now that the GDB 16 branch has been created, this commit bumps the version number in gdb/version.in to 17.0.50.DATE-git For the record, the GDB 16 branch was created from commit ee29a3c4ac7adc928ae6ed1fed3b59c940a519a4. 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 17.
2024-12-24gdb/testsuite: add some xfail in gdb.base/startup-with-shell.expAndrew Burgess1-0/+9
There are two tests that fail in gdb.base/startup-with-shell.exp when using the native-extended-remote board. I plan to fix these issues, and I've posted a series that does just that: https://inbox.sourceware.org/gdb-patches/cover.1730731085.git.aburgess@redhat.com But until that series is reviewed, I thought I'd merge this commit, which marks the FAIL as XFAIL and links them to the relevant bug number. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28392 Tested-By: Guinevere Larsen <guinevere@redhat.com>
2024-12-24gdb/freebsd: port core file context parsing to FreeBSDAndrew Burgess3-2/+146
This commit implements the gdbarch_core_parse_exec_context method for FreeBSD. This is much simpler than for Linux. On FreeBSD, at least the version (13.x) that I have installer, there are additional entries in the auxv vector that point directly to the argument and environment vectors, this makes it trivial to find this information. If these extra auxv entries are not available on earlier FreeBSD, then that's fine. The fallback behaviour will be for GDB to act as it always has up to this point, you'll just not get the extra functionality. Other differences compared to Linux are that FreeBSD has AT_FREEBSD_EXECPATH instead of AT_EXECFN, the AT_FREEBSD_EXECPATH is the full path to the executable. On Linux AT_EXECFN is the command the user typed, so this can be a relative path. This difference is handy as on FreeBSD we don't parse the mapped files from the core file (are they even available?). So having the EXECPATH means we can use that as the absolute path to the executable. However, if the user ran a symlink then AT_FREEBSD_EXECPATH will be the absolute path to the symlink, not to the underlying file. This is probably a good thing, but it does mean there is one case we test on Linux that fails on FreeBSD. On Linux if we create a symlink to an executable, then run the symlink and generate a corefile. Now delete the symlink and load the core file. On Linux GDB will still find (and open) the original executable. This is because we use the mapped file information to find the absolute path to the executable, and the mapped file information only stores the real file names, not symlink names. This is a total edge case, I only added the deleted symlink test originally because I could see that this would work on Linux. Though it is neat that Linux finds this, I don't feel too bad that this fails on FreeBSD. Other than this, everything seems to work on x86-64 FreeBSD (13.4) which is all I have setup right now. I don't see why other architectures wouldn't work too, but I haven't tested them.
2024-12-24gdb: improve GDB's ability to auto-load the exec for a core fileAndrew Burgess5-29/+455
GDB already has a limited mechanism for auto-loading the executable corresponding to a core file, this can be found in the function locate_exec_from_corefile_build_id in corelow.c. However, this approach uses the build-id of the core file to look in either the debug directory (for a symlink back to the executable) or by asking debuginfod. This is great, and works fine if the core file is a "system" binary, but often, when I'm debugging a core file, it's part of my development cycle, so there's no build-id symlink in the debug directory, and debuginfod doesn't know about the binary either, so GDB can't auto load the executable.... ... but the executable is right there! This commit builds on the earlier commits in this series to make GDB smarter. On GNU/Linux, when we parse the execution context from the core file (see linux-tdep.c), we already grab the command pointed to by AT_EXECFN. If this is an absolute path then GDB can use this to locate the executable, a build-id check ensures we've found the correct file. With this small change GDB suddenly becomes a lot better at auto-loading the executable for a core file. But we can do better! Often the AT_EXECFN is not an absolute path. If it is a relative path then we check for this path relative to the core file. This helps if a user does something like: $ ./build/bin/some_prog Aborted (core dumped) $ gdb -c corefile In this case the core file in the current directory will have an AT_EXECFN value of './build/bin/some_prog', so if we look for that path relative to the location of the core file this might result in a hit, again, a build-id check ensures we found the right file. But we can do better still! What if the user moves the core file? Or the user is using some tool to manage core files (e.g. the systemd core file management tool), and the user downloads the core file to a location from which the relative path no longer works? Well in this case we can make use of the core file's mapped file information (the NT_FILE note). The executable will be included in the mapped file list, and the path within the mapped file list will be an absolute path. We can search for mapped file information based on an address within the mapped file, and the auxv vector happens to include an AT_ENTRY value, which is the entry address in the main executable. If we look up the mapped file containing this address we'll have the absolute path to the main executable, a build-id check ensures this really is the file we're looking for. It might be tempting to jump straight to the third approach, however, there is one small downside to the third approach: if the executable is a symlink then the AT_EXECFN string will be the name of the symlink, that is, the thing the user asked to run. The mapped file entry will be the name of the actual file, i.e. the symlink target. When we auto-load the executable based on the third approach, the file loaded might have a different name to that which the user expects, though the build-id check (almost) guarantees that we've loaded the correct binary. But there's one more thing we can check for! If the user has placed the core file and the executable into a directory together, for example, as might happen with a bug report, then neither the absolute path check, nor the relative patch check will find the executable. So GDB will also look for a file with the right name in the same directory as the core file. Again, a build-id check is performed to ensure we find the correct file. Of course, it's still possible that GDB is unable to find the executable using any of these approaches. In this case, nothing changes, GDB will check in the debug info directory for a build-id based link back to the executable, and if that fails, GDB will ask debuginfod for the executable. If this all fails, then, as usual, the user is able to load the correct executable with the 'file' command, but hopefully, this should be needed far less from now on.
2024-12-24gdb/testsuite: make some of the core file / build-id tests harderAndrew Burgess3-148/+130
We have a few tests that load core files, which depend on GDB not auto-loading the executable that matches the core file. One of these tests (corefile-buildid.exp) exercises GDB's ability to load the executable via the build-id links in the debug directory, while the other two tests are just written assuming that GDB hasn't auto-loaded the executable. In the next commit, GDB is going to get better at finding the executable for a core file, and as a consequence these tests could start to fail if the testsuite is being run using a compiler that adds build-ids by default, and is on a target (currently only Linux) with the improved executable auto-loading. To avoid these test failures, this commit updates some of the tests. coredump-filter.exp and corefile.exp are updated to unload the executable should it be auto-loaded. This means that the following output from GDB will match the expected patterns. If the executable wasn't auto-loaded then the new step to unload is harmless. The corefile-buildid.exp test needed some more significant changes. For this test it is important that the executable be moved aside so that GDB can't locate it, but we do still need the executable around somewhere, so that the debug directory can link to it. The point of the test is that the executable _should_ be auto-loaded, but using the debug directory, not using GDB's context parsing logic. While looking at this test I noticed two additional problems, first we were creating the core file more times than we needed. We only need to create one core file for each test binary (total two), while we previously created one core file for each style of debug info directory (total four). The extra core files should be identical, and were just overwriting each other, harmless, but still pointless work. The other problem is that after running an earlier test we modified the test binary in order to run a later test. This means it's not possible to manually re-run the first test as the binary for that test is destroyed. As part of the rewrite in this commit I've addressed these issues. This test does change many of the test names, but there should be no real changes in what is being tested after this commit. However, when the next commit is added, and GDB gets better at auto-loading the executable for a core file, these tests should still be testing what is expected.