aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* gdb/testsuite: skip gdb.threads/omp-par-scope.exp with clangGuinevere Larsen2024-11-271-0/+8
| | | | | | | | | | | | | | | | Since 2020 it has been reported to clang[1] that the debug information around OpenMP is insufficient. The OpenMP section is not declared within the correct scope, and instead clang marks as if the section was a function in the global scope. This causes several failures in the test gdb.threads/omp-par-scope.exp when using clang to test GDB. Since this isn't a true failure of GDB, and there is little expectation that clang will be able to fix this soon, this commit disables the aforementioned test when clang is being used. [1] https://github.com/llvm/llvm-project/issues/44236 Approved-by: Kevin Buettner <kevinb@redhat.com>
* [gdb/testsuite] Add gdb.dwarf2/dw2-tu-dwarf-4-5.expTom de Vries2024-11-273-0/+173
| | | | | | | | Add a regression test for PR symtab/32225. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32225
* nios2: Remove all GDB support for Nios II targets.Sandra Loosemore2024-11-266-9/+1
| | | | | | Intel has EOL'ed the Nios II architecture, and it's time to remove support from all toolchain components before it gets any more bit-rotten from lack of maintenance or regular testing.
* Convert all_bfds to new hash tableSimon Marchi2024-11-251-1/+2
| | | | | | | | | | | | | This converts gdb_bfd.c to use the new hash table for all_bfds. This patch slightly changes the htab_t pretty-printer test, which was relying on all_bfds. Note that with the new hash table, gdb-specific printers aren't needed; the libstdc++ printers suffice -- in fact, they are better, because the true types of the contents are available. Change-Id: I48b7bd142085287b34bdef8b6db5587581f94280 Co-Authored-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
* Convert typedef hash to new hash tableSimon Marchi2024-11-251-6/+19
| | | | | | | | | | | | | | This converts the typedef hash to use the new hash table. This patch found a latent bug in the typedef code. Previously, the hash function looked at the type name, but the hash equality function used types_equal -- but that strips typedefs, meaning that equality of types did not imply equality of hashes. This patch fixes the problem and updates the relevant test. Change-Id: I0d10236b01e74bac79621244a1c0c56f90d65594 Co-Authored-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
* gdb/testsuite: force TERM setting for some filename completion testsAndrew Burgess2024-11-251-62/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some of the filename completion tests perform mid-line completion. That is we enter a partial line, then move the cursor back to the middle of the line and perform completion. The problem is that, emitting characters into the middle of a terminal line relies on first emitting some control characters. And which control characters are emitted will depend on the current TERM setting. When I initially added the mid-line completion tests I setup two regexp that covered two different terminal types, but PR gdb/32338 identifies additional terminal types that emit different sequences of control characters. Rather than trying to handle all possible terminal types, lets just force the TERM variable to something simple (i.e. "dumb") and then just support that one case. The thing being tested for here was that GDB would complete a filename in the middle of a line, the specific terminal type was not really important. I've simplified the regexp used to match the completion in two places, and I now force TERM to be "dumb" for the mid-line completion tests. I've tested this by setting my global environment TERM to 'ansi', 'xterm', 'xterm-mono', and 'dumb', and I see no failures in any mode now. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32338 Tested-By: Tom de Vries <tdevries@suse.de>
* gdb: LoongArch: Add basic process record/replay supportHui Li2024-11-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GDB provides a special process record and replay target that can record a log of the process execution, and replay it later with both forward and reverse execution commands. This patch adds the basic support of process record and replay on LoongArch, it allows users to debug basic LoongArch instructions and provides reverse debugging support. Here is a simple example on LoongArch: $ cat test.c int a = 0; int main() { a = 1; a = 2; return 0; } $ gdb test ... (gdb) start ... Temporary breakpoint 1, main () at test.c:4 4 a = 1; (gdb) record (gdb) p a $1 = 0 (gdb) n 5 a = 2; (gdb) n 6 return 0; (gdb) p a $2 = 2 (gdb) rn 5 a = 2; (gdb) rn Reached end of recorded history; stopping. Backward execution from here not possible. main () at test.c:4 4 a = 1; (gdb) p a $3 = 0 (gdb) record stop Process record is stopped and all execution logs are deleted. (gdb) c Continuing. [Inferior 1 (process 129178) exited normally] Signed-off-by: Hui Li <lihui@loongson.cn> Approved-By: Guinevere Larsen <guinevere@redhat.com> (record-full) Approved-By: Tom Tromey <tom@tromey.com> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
* [gdb/contrib] Add two rules in common-misspellings.txtTom de Vries2024-11-2332-42/+42
| | | | | | | | | | | | | | | | | | | | | | | | | Eli mentioned [1] that given that we use US English spelling in our documentation, we should use "behavior" instead of "behaviour". In wikipedia-common-misspellings.txt there's a rule: ... behavour->behavior, behaviour ... which leaves this as a choice. Add an overriding rule to hardcode the choice to common-misspellings.txt: ... behavour->behavior ... and add a rule to rewrite behaviour into behavior: ... behaviour->behavior ... and re-run spellcheck.sh on gdb*. Tested on x86_64-linux. [1] https://sourceware.org/pipermail/gdb-patches/2024-November/213371.html
* gdb/record: introduce recoding support for vporGuinevere Larsen2024-11-222-15/+27
| | | | | | | | | | | | This commit adds recording support for the AVX instruction vpor, and the AVX2 extension. Since the encoding of vpor and vpxor are the same, and their semantics are basically the same, modulo the mathematical operation, they are handled by the same switch case block. This also updates the vpxor function, to test vpor and vpxor, and updates the name to vpor_xor_test to better reflect what it does. Approved-By: Tom Tromey <tom@tromey.com>
* gdb/record: Add support for recording vpmovmskbGuinevere Larsen2024-11-222-0/+52
| | | | | | | | | This commit adds support for recording the AVX instruction vpmovmskb, and tests to the relevant file. The test didn't really support checking general purpose registers, so this commit also adds a proc to gdb.reverse/i386-avx-reverse.exp, which can be used to test them Approved-By: Tom Tromey <tom@tromey.com>
* gdb/record: Add support for all vpcmpeq instructionsGuinevere Larsen2024-11-222-0/+77
| | | | | | | | | | This commit adds support to recording instructions of the form VPCMPEQ[B|W|D]. They are all encoded in the same way and only differentiated by the opcode, so they are all processed together. This commit also updates the test to (quite exhaustively) test the new instruction. Approved-By: Tom Tromey <tom@tromey.com>
* gdb/record: add support for vpxor instructionGuinevere Larsen2024-11-222-0/+45
| | | | | | | | | This commit adds support for recording the instruction vpxor, introduced in the AVX extension, and extended in AVX2 to use 256 bit registers. The test gdb.reverse/i386-avx-reverse.exp has been extended to test this instruction as well. Approved-By: Tom Tromey <tom@tromey.com>
* [gdb/python] Handle failure to initialize without exitingTom de Vries2024-11-221-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I tried out making python initialization fail by passing an incorrect PYTHONHOME, and got: ... $ PYTHONHOME=foo ./gdb.sh -q Python path configuration: PYTHONHOME = 'foo' ... Python initialization failed: \ failed to get the Python codec of the filesystem encoding Python not initialized $ ... The relevant part of the code is: ... static void gdbpy_initialize (const struct extension_language_defn *extlang) { if (!do_start_initialization () && py_isinitialized && PyErr_Occurred ()) gdbpy_print_stack (); gdbpy_enter enter_py; ... What happens is: - gdbpy_enter::gdbpy_enter () is called, where we run into: 'if (!gdb_python_initialized) error (_("Python not initialized"));' - the error propagates to gdb's toplevel - gdb print the error and exits. It seems unnecesssary that we exit gdb. We could continue the session without python support. Fix this by: - bailing out of gdbpy_initialize if !do_start_initialization - bailing out of finalize_python if !gdb_python_initialized This gets us instead: ... $ PYTHONHOME=foo gdb -q Python path configuration: PYTHONHOME = 'foo' ... Python initialization failed: \ failed to get the Python codec of the filesystem encoding (gdb) python print (1) Python not initialized (gdb) ... Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
* gdb/disasm: fix demangling when disassembling the current functionAndrew Burgess2024-11-221-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When disassembling function symbols in C++ code, if GDB is asked to disassemble a function by name then the function name in the header line can be demangled by turning on `set print asm-demangle on`, e.g.: (gdb) disassemble foo_type::some_function Dump of assembler code for function _ZN8foo_type13some_functionE7my_type: 0x0000000000401142 <+0>: push %rbp ... etc ... End of assembler dump. (gdb) set print asm-demangle on (gdb) disassemble foo_type::some_function Dump of assembler code for function foo_type::some_function(my_type): 0x0000000000401142 <+0>: push %rbp ... etc ... │ End of assembler dump. │ However, if GDB is disassembling the current function, then this demangling doesn't work, e.g.: (gdb) break foo_type::some_function Breakpoint 1 at 0x401152: file mangle.cc, line 16. (gdb) run Starting program: /tmp/mangle Breakpoint 1, foo_type::some_function (this=0x7fffffffa597, obj=...) at mangle.cc:16 16 obj.update (); (gdb) disassemble Dump of assembler code for function _ZN8foo_type13some_functionE7my_type: 0x0000000000401142 <+0>: push %rbp ... etc ... End of assembler dump. (gdb) set print asm-demangle on (gdb) disassemble Dump of assembler code for function _ZN8foo_type13some_functionE7my_type: 0x0000000000401142 <+0>: push %rbp ... etc ... End of assembler dump. This commit fixes this issue, and extends gdb.cp/disasm-func-name.exp, which was already testing the first case (disassemble by name) to also cover disassembling the current function. Approved-By: Tom Tromey <tom@tromey.com>
* [gdb/testsuite] Require local host in gdb.base/bg-exec-sigint-bp-cond.expTom de Vries2024-11-221-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | I noticed that gdb.base/bg-exec-sigint-bp-cond.exp fails for remote host (concretely, host board local-remote-host and target board remote-gdbserver-on-localhost): ... (gdb) c&^M Continuing.^M (gdb) bash: line 0: kill: (23834) - Operation not permitted^M ^M Breakpoint 2, foo () at bg-exec-sigint-bp-cond.c:23^M 23 return 0;^M ... due to getting gdb's pid like this: ... set gdb_pid [exp_pid -i [board_info host fileid]] ... For remote host using ssh, this returns the pid of the ssh session on build. Fix this by requiring local host. Tested on x86_64-linux.
* [gdb/testsuite] Fix gdb.base/bg-exec-sigint-bp-cond.exp for signal mergingTom de Vries2024-11-221-25/+36
| | | | | | | | | | | | | | | | | | | | | | The test-case gdb.base/bg-exec-sigint-bp-cond.exp sends 10 SIGINTS to gdb, and counts whether 10 have arrived. Occasionally, less than 10 arrive due to signal merging [1]. This is more likely to happen when building gdb with -fsanitize=thread. Fix this by instead, sending one SIGINT at a time, and waiting for it to arrive. This still makes the test-case fail if the fix fixing the PR that the test-case was introduced for is reverted. Tested on aarch64-linux and x86_64-linux. PR testsuite/32329 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32329 [1] https://www.gnu.org/software/libc/manual/html_node/Merged-Signals.html
* Don't put JIT_READER_DIR into help textTom Tromey2024-11-211-0/+4
| | | | | | | | | | | | | | | | | | | | | The 80-column-help-string self-test can fail if gdb's install directory is too long, because the help for "jit-reader-load" includes JIT_READER_DIR. This help text is actually somewhat misleading, though. JIT_READER_DIR is not actually used directly -- instead the relocated variant is used. This patch adds a new "show jit-reader-directory" command and changes the help text to refer to this instead. I considered adding a "set" command as well, but since absolute paths are acceptable here, and since this is a very niche command anyway, I figured there was no need to bother. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32357 Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
* gdb/build-id: protect against weirdly short build-idsAndrew Burgess2024-11-212-3/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While looking at build_id_to_bfd_suffix (in gdb/build-id.c) I realised that GDB would likely not do what we wanted if a build-id was ever a single byte. Right now, build-ids generated by the GNU linker are 32 bytes, but there's nothing that forces this to be the case, it's pretty easy to create a fake, single byte, build-id. Given that the build-id is an external input (read from the objfile), GDB should protect itself against these edge cases. The problem with build_id_to_bfd_suffix is that this function creates the path used to lookup either the debug information, or an executable, based on its build-id. So a 3-byte build-id 0xaabbcc will look in the path: `$DEBUG_FILE_DIRECTORY/.build-id/aa/bbcc.debug`. However, a single byte build-id 0xaa, will look in the file: `$DEBUG_FILE_DIRECTORY/.build-id/aa/.debug` which doesn't seem right. Worse, when looking for an objfile given a build-id GDB will look for a file called `$DEBUG_FILE_DIRECTORY/.build-id/aa/` with a trailing '/' character. I propose that, in build_id_to_bfd_suffix we just return early if the build-id is 1 byte (or less) with a return value that indicates no separate file was found. For testing I made use of the DWARF assembler. I needed to update the build-id creation proc, the existing code assumes that the build-id is a multiple of 4 bytes, so I added some additional padding to ensure that the generated note was a multiple of 4 bytes, even if the build-id was not. I added a test with a 1 byte build-id, and also for the case where the build-id has zero length. The zero length case already does what you'd expect (no debug is loaded) as the bfd library rejects the build-id when loading it from the objfile, but adding this additional test is pretty cheap. Approved-By: Kevin Buettner <kevinb@redhat.com>
* testsuite: skip confirmation in 'gdb_reinitialize_dir'Rohr, Stephan2024-11-211-2/+4
| | | | | | | | | | | | | | | | | Some shells automatically confirm the 'dir' command: (gdb) dir Reinitialize source path to empty? (y or n) [answered Y; input not from terminal] Source directories searched: $cdir;$cwd (gdb) y dir <...>/gdb/testsuite/gdb.base Undefined command: "y". Try "help". For example, this reprdocues in a MinGW32 environment with 'TERM=dumb'. Skip sending 'y' if the command is already confirmed. Approved-By: Tom Tromey <tom@tromey.com>
* Improve choice sorting in ada-lang.cTom Tromey2024-11-202-7/+7
| | | | | | | | | | | | | | ada-lang.c has a "sort_choices" function that claims to sort the symbol choices, but which does not really implement sorting. This patch changes this code to really sort the result vector, sorting first by filename, then line number, and finally by the symbol name. The filename sorting is done first by comparing basenames. It turns out that gnatmake and gprbuild invoke the compiler a bit differently, so depending on which one you use, the results of a naive sort might be different (due to the use of absolute or relative paths).
* LAM: Enable tagged pointer support for watchpoints.Christina Schimpe2024-11-183-0/+159
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Intel (R) linear address masking (LAM) feature modifies the checking applied to 64-bit linear addresses. With this so-called "modified canonicality check" the processor masks the metadata bits in a pointer before using it as a linear address. LAM supports two different modes that differ regarding which pointer bits are masked and can be used for metadata: LAM 48 resulting in a LAM width of 15 and LAM 57 resulting in a LAM width of 6. This patch adjusts watchpoint addresses based on the currently enabled LAM mode using the untag mask provided in the /proc/<pid>/status file. As LAM can be enabled at runtime or as the configuration may change when entering an enclave, GDB checks enablement state each time a watchpoint is updated. In contrast to the patch implemented for ARM's Top Byte Ignore "Clear non-significant bits of address on memory access", it is not necessary to adjust addresses before they are passed to the target layer cache, as for LAM tagged pointers are supported by the system call to read memory. Additionally, LAM applies only to addresses used for data accesses. Thus, it is sufficient to mask addresses used for watchpoints. The following examples are based on a LAM57 enabled program. Before this patch tagged pointers were not supported for watchpoints: ~~~ (gdb) print pi_tagged $2 = (int *) 0x10007ffffffffe004 (gdb) watch *pi_tagged Hardware watchpoint 2: *pi_tagged (gdb) c Continuing. Couldn't write debug register: Invalid argument. ~~~~ Once LAM 48 or LAM 57 is enabled for the current program, GDB can now specify watchpoints for tagged addresses with LAM width 15 or 6, respectively. Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
* gdb: Update linkage name lookup function to allow mst_file_data/bss types.Ijaz, Abdul B2024-11-172-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From the commit 667ed4b14ddaa9af196481f1757c0e517e80b6ed onward, instead of normal name GDB looks for the "jit_descriptor" linkage name in the JIT code initialization. Without this change, the function "lookup_minimal_symbol_linkage", only matches the non-static data. So in case jit_debugger is static type then setting up breakpoint in the JIT code fails. Issue is seen for the intel compilers, where jit_debug_descriptor has static type i.e. "mst_file_data". Hence lookup_minimal_symbol_linkage returns nullptr for it. So, in this case breakpoint does not hit in the JIT code. To resolve this, the commit introduces a new boolean argument to the lookup_minimal_symbol_linkage function. This argument allows the function to also match mst_file_data and mst_file_bss types when set to true. The function is called with this new argument set to true only from JIT code initialization handling, ensuring that the current behavior remains unchanged for other cases. Because handling of static types of data symbols for all cases result in regression for "gdb.base/print-file-var.exp" test. Example of minsym for the JIT code emitted by the intel compilers where lookup_minimal_symbol_linkage fails without this change because jit_debugger type is "mst_file_data". (top-gdb) p *msymbol $1 = {<general_symbol_info> = {m_name = 0x7fffcc77dc95 "__jit_debug_descriptor", m_value = {ivalue = 84325936, block = 0x506b630, bytes = 0x506b630 <error: Cannot access memory at address 0x506b630>, address = 0x506b630, unrel_addr = (unknown: 0x506b630), common_block = 0x506b630, chain = 0x506b630}, language_specific = {obstack = 0x0, demangled_name = 0x0}, m_language = language_unknown, ada_mangled = 0, m_section = 29}, m_size = 24, filename = 0x55555a751b70 "JITLoaderGDB.cpp", m_type = mst_file_data, created_by_gdb = 0, m_target_flag_1 = 0, m_target_flag_2 = 0, m_has_size = 1, name_set = 1, hash_next = 0x55555b86e4f0, demangled_hash_next = 0x0} Updated the test "jit-elf-so.exp" to test the static type of jit_descriptor object. Approved-By: Tom Tromey <tom@tromey.com>
* gdb/testsuite: skip gdb.opt/inline-entry.exp for gcc 7 and olderAndrew Burgess2024-11-151-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was pointed out that the recently added gdb.opt/inline-entry.exp test would fail when run using gcc 7 and earlier, on an x86-64 target: https://inbox.sourceware.org/gdb-patches/9fe35ea1-d99b-444d-bd1b-e3a1f108dd77@suse.de Bernd Edlinger points out that, for gcc, the test relies on the -gstatement-frontiers work which was added in gcc 8.x: https://inbox.sourceware.org/gdb-patches/DU2PR08MB10263357597688D9D66EA745CE4242@DU2PR08MB10263.eurprd08.prod.outlook.com For gcc 7.x and older, without the -gstatement-frontiers work, the compiler uses DW_AT_entry_pc differently, which leads to a poorer debug experience. Here is the interesting source line from inline-entry.c: if ((global && bar (1)) || bar (2)) And here's some of the relevant disassembly output: Dump of assembler code for function main: 0x401020 <+0>: mov 0x3006(%rip),%eax (1) 0x401026 <+6>: test %eax,%eax (2) 0x401028 <+8>: mov 0x2ffe(%rip),%eax (3) 0x40102e <+14>: je 0x401038 <main+24> (4) 0x401030 <+16>: sub $0x1,%eax (5) 0x401033 <+19>: jne 0x40103d <main+29> (6) Lines (1), (2), and (4) represent the check of 'global'. However, line (3) is actually the first instruction for 'bar' which has been inlined. Lines (5) and (6) are also part of the first inlined 'bar' function. If the check of 'global' returns false then the first call to 'bar' should never happen, this is accomplished by the branch at (4) being taken. For gcc 8+, gcc generates a DW_AT_entry_pc with the value 0x401030, this is where GDB places a breakpoint for 'bar', and this address is after the branch at line (4), and so, if the call to 'bar' never happens, the breakpoint is never hit. For gcc 7 and older, gcc generates a DW_AT_entry_pc with the value 0x401028, which is the first address associated with the inline 'bar' function. Unfortunately, this address is also before the check of 'global' has completed, this means that GDB hits the 'bar' breakpoint before the inferior has decided if 'bar' should actually be called or not. I don't think there's really much GDB can do in the older gcc versions, we are placing the breakpoint at the entry point, and this is within bar. Given that this test does really depend on the newer gcc behaviour, I think the only sensible solution is to skip this test when an older version of gcc is being used. I've incorporated the check for -gstatement-frontiers support that Bernd suggested and now the test will be skipped for older versions of GCC. Approved-By: Tom de Vries <tdevries@suse.de>
* gdb/python: missing PyObject_IsTrue error check in bppy_initAndrew Burgess2024-11-141-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | As with the previous two commits, this commit fixes a location where we called PyObject_IsTrue without including an error check, this time in bppy_init. The 'qualified' argument is supposed to be a bool, the docs say: The optional QUALIFIED argument is a boolean that allows interpreting the function passed in 'spec' as a fully-qualified name. It is equivalent to 'break''s '-qualified' flag (*note Linespec Locations:: and *note Explicit Locations::). It's not totally clear that the only valid values are True or False, but I'm choosing to interpret the docs that way, and so I've added a PyBool_Type check during argument parsing. Now, if a non-bool is passed the user will get a TypeError during argument parsing. I've added a test to cover this case. This is a potentially breaking change to the Python API, but hopefully this will not impact too many people. I've added a NEWS entry to highlight this change. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
* gdb/python: missing PyObject_IsTrue error check in micmdpy_set_installedAndrew Burgess2024-11-141-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | Like the previous commit, I discovered that in micmdpy_set_installed we were calling PyObject_IsTrue, but not checking for a possible error value being returned. The micmdpy_set_installed function implements the gdb.MICommand.installed attribute, and the documentation indicates that this attribute should only be assigned a bool: This attribute is read-write, setting this attribute to 'False' will uninstall the command, removing it from the set of available commands. Setting this attribute to 'True' will install the command for use. So I propose that instead of using PyObject_IsTrue we use PyBool_Check, and if the new value fails this check we raise an error. We can then compare the new value to Py_True directly instead of calling PyObject_IsTrue. This is a potentially breaking change to the Python API, but hopefully this will not impact too many people, and the fix is pretty easy (switch to using a bool). I've added a NEWS entry to draw attention to this change. Approved-By: Tom Tromey <tom@tromey.com>
* gdb/python: missing PyObject_IsTrue error check in py-arch.cAndrew Burgess2024-11-141-3/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Building on the previous two commits, I was auditing our uses of PyObject_IsTrue looking for places where we were missing an error check. The gdb.Architecture.integer_type() function takes a 'signed' argument which should be a 'bool', and the docs do say: If SIGNED is not specified, it defaults to 'True'. If SIGNED is 'False', the returned type will be unsigned. Currently we use PyObject_IsTrue, but we are missing an error check. To fix this I've tightened the code to enforce the bool requirement at the point that the arguments are parsed. With that done I can remove the call to PyObject_IsTrue and instead compare to Py_True directly, the object in question will always be a PyBool_Type. However, we were testing that passing a non-bool argument for 'signed' is treated as Py_False, this was added with this commit: commit 90fe61ced1c9aa4afb263326e336330d15603fbf Date: Mon Nov 29 13:53:06 2021 +0000 gdb/python: don't use the 'p' format for parsing args which is when the PyObject_IsTrue call was added. Given that the docs do seem pretty clear that only True or False are suitable argument values, my proposal is that we just remove these tests and instead test that any non-bool argument value for 'signed' gives a TypeError. This is a breaking change to the Python API, however, my hope is that this is such a edge case that it will not cause too many problem. I've added a NEWS entry to highlight this change though. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
* gdb/python: remove some additional PyObject_IsTrue callsAndrew Burgess2024-11-141-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | After the previous commit I audited all our uses of PyObject_IsTrue looking for places where we were missing an error check. I did find some that are missing error checks in places where we really should have error checks, and I'll fix those in later commits. This commit however, focuses on those locations where PyObject_IsTrue is called, there is no error check, and the error check isn't really necessary because we already know that the object we are dealing with is of type PyBool_Type. Inline with the previous commit, in these cases I have removed the PyObject_IsTrue call, and replaced it with a comparison against Py_True. In one location where it is not obvious that the object we have is PyBool_Type I've added an assert, but in the other cases the comparison to Py_True immediately follows a PyBool_Check call, so an assert would be redundant. I've added a test for the gdb.Value.format_string styling argument being passed a non-bool value as this wasn't previously being tested, though this new test will pass before and after this commit. There should be no functional change after this commit. Approved-By: Tom Tromey <tom@tromey.com>
* [gdb/contrib] Handle capitalized words in spellcheck.shTom de Vries2024-11-132-2/+2
| | | | | | | | | | | | | | | | | The dictionary contains a few entries with capital letters: ... $ grep -E '[A-Z]' .git/wikipedia-common-misspellings.txt | wc -l 143 ... but they don't look too interesting in the gdb context (for instance, Habsbourg->Habsburg), so filter them out. That leaves us with entries looking only like "foobat->foobar", so add handling of capitalized words, such that we also rewrite "Foobat" to "Foobar". Tested on aarch64-linux. Verified with shellcheck. Approved-by: Kevin Buettner <kevinb@redhat.com>
* [gdb/contrib] Add "doens't->doesn't" to common-misspellings.txtTom de Vries2024-11-133-4/+4
| | | | | | | | | Add "doens't->doesn't" to gdb/contrib/common-misspellings.txt, and run gdb/contrib/spellcheck.sh to fix this in a few files. Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>
* [gdb/contrib] Handle double quotes in spellcheck.shTom de Vries2024-11-131-1/+1
| | | | | | | | | | | | | | Add handling of double quotes in gdb/contrib/spellcheck.sh, and fix the following typos: ... inheritence -> inheritance psuedo -> pseudo succeded -> succeeded ... Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>
* [gdb/contrib] Handle parentheses in spellcheck.shTom de Vries2024-11-132-4/+4
| | | | | | | | | | | | | | | | | | | | | | | Currently, text adjacent to parentheses is not spell-checked: ... $ cat tmp.txt (upto) $ ./gdb/contrib/spellcheck.sh tmp.txt $ ... Add handling of parentheses, such that we get: ... $ ./gdb/contrib/spellcheck.sh tmp.txt upto -> up to $ ... Rerun spellcheck.sh, resulting in a few "thru->through" replacements. Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>
* gdb: stepping between inline functions with multiple rangesBernd Edlinger2024-11-134-0/+616
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I (Andrew) have split this small change from a larger patch which was posted here: https://inbox.sourceware.org/gdb-patches/AS1PR01MB9465608EBD5D62642C51C428E4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com And I have written the stand alone test for this issue. The original patch included this paragraph to explain this change (I've fixed one typo in this text replacing 'program' with 'function'): ... it may happen that the infrun machinery steps from one inline range to another inline range of the same inline function. That can look like jumping back and forth from the calling function to the inline function, while really the inline function just jumps from a hot to a cold section of the code, i.e. error handling. The important thing that happens here is that both the outer function and the inline function must both have multiple ranges. When the inferior is within the inline function and moves from one range to another it is critical that the address we stop at is the start of a range in both the outer function and the inline function. The diagram below represents how the functions are split and aligned: (A) (B) bar: |------------| |---| foo: |------------------| |--------| The inferior is stepping through 'bar' and eventually reaches point (A) at which point control passes to point (B). Currently, when the inferior stops, GDB notices that both 'foo' and 'bar' start at address (B), and so GDB uses the inline frame mechanism to skip 'bar' and tells the user that the inferior is in 'foo'. However, as we were in 'bar' before the step then it makes sense that we should be in 'bar' after the step, and this is what the patch does. There are two tests using the DWARF assembler, the first checks the above situation and ensures that GDB reports 'bar' after the step. The second test is similar, but after the step we enter a new range where a different inline function starts, something like this: (A) (B) bar: |------------| baz: |---| foo: |------------------| |--------| In this case as we step at (A) and land at (B) we leave 'bar' and expect to stop in 'foo', GDB shouldn't automatically enter 'baz' as that is a completely different inline function. And this is, indeed, what we see. Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
* gdb: fix handling of DW_AT_entry_pc of inlined subroutinesAndrew Burgess2024-11-134-0/+633
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The entry PC for a DIE, e.g. an inline function, might not be the base address of the DIE. Currently though, in block::entry_pc(), GDB always returns the base address (low-pc or the first address of the first range) as the entry PC. This commit extends the block class to carry the entry PC as a separate member variable. Then the DWARF reader is extended to read and set the entry PC for the block. Now in block::entry_pc(), if the entry PC has been set, this is the value returned. If the entry-pc has not been set to a specific value then the old behaviour of block::entry_pc() remains, GDB will use the block's base address. Not every DIE will set the entry-pc, but GDB still needs to have an entry-pc for every block, so the existing logic supplies the entry-pc for any block where the entry-pc was not set. The DWARF-5 spec for reading the entry PC is a super-set of the spec as found in DWARF-4. For example, if there is no DW_AT_entry_pc then DWARF-4 says to use DW_AT_low_pc while DWARF-5 says to use the base address, which is DW_AT_low_pc or the first address in the first range specified by DW_AT_ranges if there is no DW_AT_low_pc. I have taken the approach of just implementing the DWARF-5 spec for everyone. There doesn't seem to be any benefit to deliberately ignoring a ranges based entry PC value for DWARF-4. If some naughty compiler has emitted that, then lets use it. Similarly, DWARF-4 says that DW_AT_entry_pc is an address. DWARF-5 allows an address or a constant, where the constant is an offset from the base address. I allow both approaches for all DWARF versions. There doesn't seem to be any downsides to this approach. I ran into an issue when testing this patch where GCC would have the DW_AT_entry_pc point to an empty range. When GDB parses the ranges any empty ranges are ignored. As a consequence, the entry-pc appears to be outside the address range of a block. The empty range problem is certainly something that we can, and should address, but that is not the focus of this patch, so for now I'm ignoring that problem. What I have done is added a check: if the DW_AT_entry_pc is outside the range of a block then the entry-pc is ignored, GDB will then fall-back to its default algorithm for computing the entry-pc. If/when in the future we address the empty range problem, these DW_AT_entry_pc attributes will suddenly become valid and GDB will start using them. Until then, GDB continues to operate as it always has. An early version of this patch stored the entry-pc within the block like this: std::optional<CORE_ADDR> m_entry_pc; However, a concern was raised that this, on a 64-bit host, effectively increases the size of block by 16-bytes (8-bytes for the CORE_ADDR, and 8-bytes for the std::optional's bool plus padding). If we remove the std::optional part and just use a CORE_ADDR then we need to have a "special" address to indicate if m_entry_pc is in use or not. I don't really like using special addresses; different targets can access different address ranges, even zero is a valid address on some targets. However, Bernd Edlinger suggested storing the entry-pc as an offset, and I think that will resolve my concerns. So, we store the entry-pc as a signed offset from the block's base address (the first address of the first range, or the start() address value if there are now ranges). Remember, ranges can be out of order, in which case the first address of the first range might be greater than the entry-pc. When GDB needs to read the entry-pc we can add the offset onto the blocks base address to recalculate it. With this done, on a 64-bit host, block only needs to increase by 8-bytes. The inline-entry.exp test was originally contributed by Bernd here: https://inbox.sourceware.org/gdb-patches/AS1PR01MB94659E4D9B3F4A6006CC605FE4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com though I have made some edits, making more use of lib/gdb.exp functions, making the gdb_test output patterns a little tighter, and updating the test to run with Clang. I also moved the test to gdb.opt/ as that seemed like a better home for it. Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de>
* gdb/testsuite: some cleanups in gdb.base/annota{1,3}.exp testsAndrew Burgess2024-11-122-64/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fedora GDB has, for years, carried an out of tree patch for the gdb.base/annota{1,3}.exp tests. The patch simply adds a call to 'set breakpoint pending off' near the start of each test. Normally GDB tests are written using gdb_test or gdb_test_multiple, with gdb_test being a wrapper around gdb_test_multiple. Inside gdb_test_multiple we add a test pattern which detects if GDB offers the user an interactive yes/no prompt and immediately fails the test. What this means is that if something goes wrong with a test like: gdb_test "break main" ".*" and GDB ends up offering this prompt: Make breakpoint pending on future shared library load? (y or [n]) then instead of hanging waiting for the test to timeout, DejaGNU will spot the interactive prompt and immediately fail the test. In the gdb.base/annota{1,3}.exp tests we turn on GDB's annotation mode, and many of the tests in these scripts are written using send_gdb and gdb_expect or gdb_expect_list. This is done because in the past, gdb_test_multiple and friends were hard-coded to use the "normal" GDB prompt, and these tests instead expect the annotated prompt. Specifically, gdb_test_multiple expects '$gdb_prompt $' as the full prompt, that is the value of $gdb_prompt followed by a single white space. The annotation tests do update the value of $gdb_prompt, but with annotations on there is no trailing whitespace, so gdb_test_multiple's default behaviour doesn't work, which is why the test scripts originally avoided using gdb_test_multiple. As a result none of the tests in these files would early exit if we got an interactive yes/no prompt, and instead we'd be relying on each test to timeout, which could take a while. However, gdb_test_multiple now accepts a -prompt argument, so we can modify the prompt we are looking for, which is neat. So, I started off by going through these tests an changing all of the tests that create a breakpoint to use gdb_test, passing the -prompt option to change the prompt. While doing that I noticed some other things that I could improve in these tests, I've cleaned up the use of standard_testfile, switched to use prepare_for_testing, and removed some redundant clean_restart and 'set height 0' calls (set height 0 is done within clean_restart, which is called by prepare_for_testing). I've updated some comments which said "we can't use gdb_test" to say "we can use gdb_test with -prompt option", and I've removed some commented out debug code (e.g. setting 'exp_internal'). Finally, I ran these two tests through check-all-boards, and spotted that annota1.exp failed when using a remote host. This is because one test checks for a full path to the binary in some output, and with a remote host the binary ends up being copied and the path is not as expected. I'm assuming that checking the full path is important, so I've disabled this test on remote host boards. After all these changes I checked using 'make check-all-boards' and there are no unexpected results on either of these tests. Tested-By: Tom de Vries <tdevries@suse.de> Acked-By: Tom de Vries <tdevries@suse.de>
* gdb/testsuite: fix duplicate test names in gdb.trace/Andrew Burgess2024-11-124-30/+30
| | | | | | | | | | | | | | | | | | | | | | | After this commit: commit 35f09cd5d7fdd1a64f4d1751e73c3495bef1ed99 Date: Wed Jul 31 15:04:25 2024 +0200 [gdb/testsuite] Detect trailing-text-in-parentheses duplicates we are now seeing some duplicate test names in gdb.trace/ tests when using native-gdbserver or native-extended-gdbserver boards. This is all due to tests that use some text in trailing parenthesis to make the test name unique. I've gone through and edited the test names as best I could to make them all unique. Hopefully the updated test names should all make sense. On my machine I'm no longer seeing any duplicates with either of the boards listed above. Acked-By: Tom de Vries <tdevries@suse.de>
* gdb/readline: don't get stuck thinking an EOF arrivedAndrew Burgess2024-11-123-0/+178
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was brought to my attention[1] that if a user makes use of Ctrl+d to quit from a secondary prompt (e.g. the prompt used to enter lines for the 'commands' command) then GDB will start displaying some unexpected blank lines. Here's an example: Reading symbols from /tmp/hello.x... (gdb) break main Breakpoint 1 at 0x401198: file hello.c, line 18. (gdb) commands Type commands for breakpoint(s) 1, one per line. End with a line saying just "end". >quit # <----------- Use Ctrl+d to quit here. (gdb) show architecture # <----------- This blank line is unexpected. The target architecture is set to "auto" (currently "i386:x86-64"). (gdb) I've marked up where I press 'Ctrl+d', and also the unexpected blank line. This issue will only happen if bracketed-paste-mode is in use. If this has been disabled (e.g. in ~/.inputrc) then this issue will not occur. The blank line is not just emitted for the 'show architecture' command. The blank line is actually caused by an extra '\n' character emitted by readline after it has gathered a complete line of input, and so will occur for any command. The problem is caused by readline getting "stuck" in a state where it thinks that an EOF has just been delivered. This state is set when the 'Ctrl+d' does deliver an EOF, but then this state is never fully reset. As a result, every time readline completes a line, it thinks that the line was completed due to an EOF and so adds an extra '\n' character. Obviously the real fix for this issue is to patch readline, and I do have a patch for that[2], however, version 8.2 of readline has been released, and contains this issue. As such, if GDB is linked against the system readline, and that system readline is 8.2, then we can expect to see this issue. There's a pretty simple, and cheap workaround that we can add to GDB that will mitigate this issue. I propose that we add this workaround to GDB. If/when the readline patch is accepted then I'll back-port this to our local readline copy, but retaining the workaround will be harmless, and will make GDB play nicer with system readline libraries (version 8.2). [1] https://inbox.sourceware.org/gdb-patches/34ef5438-8644-44cd-8537-5068e0e5e434@redhat.com [2] https://lists.gnu.org/archive/html/bug-readline/2024-10/msg00014.html Reviewed-By: Keith Seitz <keiths@redhat.com>
* gdb/readline: add readline library version to 'show configuration'Andrew Burgess2024-11-121-0/+3
| | | | | | | | | | | | | | | | When debugging readline issues I'd like an easy way to know (for sure) what version of readline GDB is using. This could also be useful when writing readline tests, knowing the precise readline version will allow us to know if we expect a test to pass or not. Add the readline library version to the output of the 'show configuration' command. Also include a suffix indicating if we are using the system readline, or the statically linked in readline. The information about static readline vs shared readline can be figured out from the configure command output, but having it repeated in the readline version line makes it super easy to grok within tests, and it's super cheap, so I don't see this as a problem.
* gdb/testsuite: fix gdb.reverse/i386-avx-reverse.exp with clangGuinevere Larsen2024-11-122-16/+23
| | | | | | | | | | | | | | | | | | | | | | | | The test gdb.reverse/i386-avx-reverse.exp was changed by the recent commit: commit 5bf288d5a88ab6d3fa9bd7bd070e624afd264dc6 Author: Guinevere Larsen <guinevere@redhat.com> Date: Fri Jul 26 17:31:14 2024 -0300 gdb/record: support AVX instructions VMOVDQ(U|A) when recording In that commit I added a few calls to the instruction vmovdqa to and from memory addresses. Because my local gcc testing always had aligned pointers, I thought this would always work, but clang (and maybe other compilers) might not do the same, which will cause vmovdqa to segfault, and the test to fail spectacularly. This commit fixes that by using the pre-existing precise-aligned-alloc to allocate the dynamic buffers, forcing them to be aligned to the required boundary for vmovdqa instruction to work. The code was then re-shuffled to keep the current clustering of instructions. Approved-By: Tom Tromey <tom@tromey.com>
* Handle type-casting in template parameter list when hashing symbolsShahab Vahedi2024-11-122-0/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to a logical bug in gdb/cp-support.c:cp_search_name_hash(), GDB may not be able to find a symbol when asked by the user. See the accompanying test for such demonstration. The cp_search_name_hash() cannot correctly handle a (demangled) symbol that comprises of type-casting for the first parameter in its template parameter list, e.g.: foo<(enum_test)0>(int, int) In this example, the processing logic in cp_search_name_hash() considers the "foo<" string for hashing instead of "foo". This is due to a faulty logic in the processing loop that tries to _keep_ hashing if a '<' char with the following property is encountered: --------------------------------------------------------------------- for (const char *string = search_name; *string != '\0'; ++string) { ... if (*string == '(') break; ... /* Ignore template parameter list. */ if (string[0] == '<' && string[1] != '(' && string[1] != '<' && string[1] != '=' && string[1] != ' ' && string[1] = '\0') break; ... hash = SYMBOL_HASH_NEXT (hash, *string); } --------------------------------------------------------------------- Ostensibly, this logic strives to bail out of the processing loop as soon as the beginning of an argument list is encountered, "(int, int)" in the example, or the beginning of a template parameter list, the "<(enum_test)0>" in the example. However, when "string" is pointing at '<', the following incorrect logic takes precedence: --------------------------------------------------------------------- for (const char *string = search_name; *string != '\0'; ++string) { if (*string == '(') break; ... if (string[0] == '<' && string[1] != '(' ...) break; hash = SYMBOL_HASH_NEXT (hash, *string); } --------------------------------------------------------------------- In "foo<(enum_test)0>(int, int)", the '(' char that is positioned after the '<' char causes the "if" condition at the end of the loop not to "break". As a result, the '<' is considered for hashing and at the beginning of the next iteration, the loop is exited because "string" points to '(' char. It's obvious that the intention of the "if" condition at the end of the loop body is to handle cases where the method name is "operator<", "operator<<", or "operator<=". While fixing the issue, I've re-written the logic as such to make that more explicit. Still, the complexity of the function remains O(n). It is worth mentioning that in the same file the "find_toplevel_char()" follows the same explicit logic. Reviewed-By: Lancelot SIX <lancelot.six@amd.com> Reviewed-By: Pedro Alves <pedro@palves.net> Approved-by: Tom Tromey <tom@tromey.com> Change-Id: I64cbdbe79671e070cc5da465d1cce7989c58074e
* gdb/testsuite: fix typo 'unsupport' to 'unsupported'Andrew Burgess2024-11-111-1/+1
| | | | | | | | | | | | | | | I noticed that in commit: commit 5cabc8098e65ac22d4245232ad20b19fa4729802 Date: Wed Jul 31 15:55:57 2024 +0100 gdb/python: implement Python find_exec_by_build_id hook I managed to typo 'unsupported' as 'unsupport'. If you run the test on a target that doesn't support core file creation then you'll get a TCL error. Fixed in this commit.
* gdb/testsuite: fix failure in gdb.base/info_sources.expAndrew Burgess2024-11-111-10/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I ran into an unexpected failure in gdb.base/info_sources.exp. The test in question runs this command: (gdb) info sources -d -- -d That is, list all the source files whose directory name matches the regexp '-d'. The expectation is that no source files will be listed. Unfortunately, when I ran the test some source files are listed; the directory I am running in contains the pattern '-d', and so the test fails. As we cannot control where the developer is building and testing GDB, I propose that instead of just testing with '-d' we should search through all the letters a-z and find one that isn't present in the source file directory name. I'm still including the leading '-' character in the regexp. So now, unless GDB is being built in a directory that contains '-a', '-b', '-c', .... '-z', the test will find one letter which isn't present, and use that for the test. To avoid test names changing between runs in different directories I've had to tweak the test name to something more generic, but there should be no change in which parts of GDB are actually being tested. Approved-By: Tom Tromey <tom@tromey.com>
* [gdb/testsuite] Reduce quoting in gdb.base/annota1.expTom de Vries2024-11-111-7/+11
| | | | | | Reduce quoting in gdb.base/annota1.exp, mostly using string_to_regexp. Tested on arm-linux and x86_64-linux.
* [gdb/testsuite] Fix gdb.base/annota1.exp on arm-linuxTom de Vries2024-11-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On arm-linux, gdb.base/annota1.exp fails: ... PASS: gdb.base/annota1.exp: breakpoint info run^M ^M ^Z^Zpost-prompt^M Starting program: /home/linux/gdb/build/gdb/testsuite/outputs/gdb.base/annota1/annota1 ^M ^M ^Z^Zbreakpoints-invalid^M ^M ^Z^Zframes-invalid^M ^M ^Z^Zstarting^M ^M ^Z^Zframes-invalid^M [Thread debugging using libthread_db enabled]^M Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".^M ^M ^Z^Zbreakpoints-invalid^M ^M ^Z^Zbreakpoint 1^M ^M Breakpoint 1, ^M ^Z^Zframe-begin 0 0x40054a^M ^M ^Z^Zframe-function-name^M main^M ^Z^Zframe-args^M ()^M ^Z^Zframe-source-begin^M at ^M ^Z^Zframe-source-file^M /home/linux/gdb/src/gdb/testsuite/gdb.base/annota1.c^M ^Z^Zframe-source-file-end^M :^M ^Z^Zframe-source-line^M 15^M ^Z^Zframe-source-end^M ^M ^M ^Z^Zsource /home/linux/gdb/binutils-gdb.git/gdb/testsuite/gdb.base/annota1.c:15:103:beg:0x40054a^M ^M ^Z^Zframe-end^M ^M ^Z^Zstopped^M ^M ^Z^Zpre-prompt^M (gdb) ^M ^Z^Zprompt^M FAIL: gdb.base/annota1.exp: run until main breakpoint (timeout) ... because the regexp doesn't match the first frames-invalid annotation. Fix this by adding an optional frames-invalid annotation in the regexp. Tested on arm-linux and x86_64-linux.
* [gdb/testsuite] Avoid intermittent failures on another debuginfod testTom de Vries2024-11-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | With test-case gdb.debuginfod/solib-with-soname.exp on aarch64-linux, I ran into: ... (gdb) core-file solib-with-soname.core^M Downloading 197.86 K file libfoo_1.so...^M [New LWP 997314]^M [Thread debugging using libthread_db enabled]^M Using host libthread_db library "/lib64/libthread_db.so.1".^M Core was generated by `solib-with-soname'.^M Program terminated with signal SIGABRT, Aborted.^M (gdb) FAIL: $exp: load core file, use debuginfod: load core file ... The test-case doesn't expect the "197.86 K" part. The same problem was fixed for another test-case in commit a723c56efb0 ("gdb/testsuite: avoid intermittent failures on a debuginfod test"). Fix this in the same way: by updating the regexp. Tested on aarch64-linux. PR testsuite/32354 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32354
* Add setting to control frame language mismatch warningTom Tromey2024-11-112-4/+4
| | | | | | | | | A customer noted that there is no way to prevent the "current language does not match this frame" warning. This patch adds a new setting to allow this warning to be suppressed. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
* Re-run isortTom Tromey2024-11-111-1/+1
| | | | | pre-commit pointed out that one file needed a change to satisfy isort. This patch is the result.
* gdb/dwarf2/read.c: Handle empty CU nameLancelot SIX2024-11-112-0/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I recently came across a case where a compiler would emit a CU with an empty name. In such case, the attribute object constructed by GDB will return nullptr when as_string is called. One place is not checking for this possibility. As a result, loading such binary results in a GDB crash: $ gdb -q a.out Reading symbols from a.out... Fatal signal: Segmentation fault ----- Backtrace ----- [...] 0x742f4dd8afab __strcmp_avx2 ../sysdeps/x86_64/multiarch/strcmp-avx2.S:283 0x58593704a0bc prepare_one_comp_unit ../../gdb/dwarf2/read.c:21842 0x585937053fd9 process_psymtab_comp_unit ../../gdb/dwarf2/read.c:4633 0x585937053fd9 _ZN23cooked_index_debug_info11process_cusEmN9__gnu_cxx17__normal_iteratorIPSt10unique_ptrI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterESt6vectorIS5_SaIS5_EEEESA_ ../../gdb/dwarf2/read.c:4943 [...] --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: <https://www.gnu.org/software/gdb/bugs/>. Segmentation fault (core dumped) This seems to be a regression introduced by the following commit: commit 00105aa1c4d9933fe3cfe9bc1be0daefe9f8ca36 Date: Tue Sep 24 10:24:22 2024 +0200 [gdb/symtab] Don't expand non-Ada CUs for info exceptions This patch fixes this issue by checking if attr->as_string returns nullptr. Change-Id: I78fe7a090f0bd1045b8cb2f8d088a8d6cf57fe1c Approved-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
* gdb/python: implement Python find_exec_by_build_id hookAndrew Burgess2024-11-104-0/+816
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement extension_language_ops::find_objfile_from_buildid within GDB's Python API. Doing this allows users to write Python extensions that can help locate missing objfiles when GDB opens a core file. A handler might perform some project- or site-specific actions to find a missing objfile. Or might provide some project- or site-specific advice to the user on how they can obtain the missing objfile. The implementation is very similar to the approach taken in: commit 8f6c452b5a4e50fbb55ff1d13328b392ad1fd416 Date: Sun Oct 15 22:48:42 2023 +0100 gdb: implement missing debug handler hook for Python The following new commands are added as commands implemented in Python, this is similar to how the Python missing debug and unwinder commands are implemented: info missing-objfile-handlers enable missing-objfile-handler LOCUS HANDLER disable missing-objfile-handler LOCUS HANDLER To make use of this extension hook a user will create missing objfile handler objects, and registers these handlers with GDB. When GDB opens a core file and encounters a missing objfile each handler is called in turn until one is able to help. Here is a minimal handler that does nothing useful: import gdb import gdb.missing_objfile class MyFirstHandler(gdb.missing_objfile.MissingObjfileHandler): def __init__(self): super().__init__("my_first_handler") def __call__(self, pspace, build_id, filename): # This handler does nothing useful. return None gdb.missing_objfile.register_handler(None, MyFirstHandler()) Returning None from the __call__ method tells GDB that this handler was unable to find the missing objfile, and GDB should ask any other registered handlers. Possible return values from a handler: - None: This means the handler couldn't help. GDB will call other registered handlers to see if they can help instead. - False: The handler has done all it can, but the objfile couldn't be found. GDB will not call any other handlers, and will continue without the objfile. - True: The handler has installed the objfile into a location where GDB would normally expect to find it. GDB should repeat its normal lookup process and the objfile should now be found. - A string: The handler can return a filename, which is the missing objfile. GDB will load this file. Handlers can be registered globally, or per program space. GDB checks the handlers for the current program space first, and then all of the global handles. The first handler that returns a value that is not None, has "handled" the missing objfile, at which point GDB continues. The implementation of this feature is mostly straight forward. I have reworked some of the missing debug file related code so that it can be shared with this feature. E.g. gdb/python/lib/gdb/missing_files.py is mostly content moved from gdb/python/lib/gdb/missing_debug.py, but updated to be more generic. Now gdb/python/lib/gdb/missing_debug.py and the new file gdb/python/lib/gdb/missing_objfile.py both call into the missing_files.py file. For gdb/python/lib/gdb/command/missing_files.py this is even more extreme, gdb/python/lib/gdb/command/missing_debug.py is completely gone now and gdb/python/lib/gdb/command/missing_files.py provides all of the new commands in a generic way. I have made one change to the existing Python API, I renamed the attribute Progspace.missing_debug_handlers to Progspace.missing_file_handlers. I don't see this as too problematic. This attribute was only used to implement the missing debug feature and was never documented beyond the fact that it existed. There was no reason for users to be touching this attribute. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
* gdb: use mapped file information to improve debuginfod textAndrew Burgess2024-11-102-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When opening a core-file GDB is able to use debuginfod to download the executable that matches the core-file if GDB can find a build-id for the executable in the core-file. In this case GDB calls debuginfod_exec_query to download the executable and GDB prints a message like: Downloading executable for /path/to/core-file... which makes sense in that case. For a long time GDB has also had the ability to download memory-mapped files and shared libraries when opening a core-file. However, recent commits have made these cases more likely to trigger, which is a good thing, but the messaging from GDB in these cases is not ideal. When downloading a memory-mapped file GDB prints: Downloading executable for /path/to/memory-mapped-file And for a shared library: Downloading executable for /path/to/libfoo.so These last two messages could, I think, be improved. I propose making two changes. First, I suggest instead of using /path/to/core-file in the first case, we use the name of the executable that GDB is fetching. This makes the messaging consistent in that we print the name of the file we're fetching rather than the name of the file we're fetching something for. I further propose that we replace 'executable for' with the more generic word 'file'. The messages will then become: Downloading file /path/to/exec-file... Downloading file /path/to/memory-mapped-file... Downloading file /path/to/libfoo.so... I think these messages are clearer than what we used to have, and they are consistent in that we name the thing being downloaded in all cases. There is one tiny problem. The first case relies on GDB knowing the name of the executable it wants to download. The only place we can currently get that from is, I think, the memory-mapped file list. [ ASIDE: There is `bfd_core_file_failing_command` which reports the executable and argument list from the core file, but this information is not ideal for this task. First, the executable and arguments are merged into a single string, and second, the string is a relatively short, fixed length string, so the executable name is often truncated. For these reasons I don't consider fetching the executable name using this bfd function as a solution. ] We do have to consider the case that the core file does not have any mapped file information. This shouldn't ever be the case for a Linux target, but it's worth considering. [ ASIDE: I mention Linux specifically because this only becomes a problem if we try to do a lookup via debuginfod, which requires that we have build-ids available. Linux has special support for embedding build-ids into the core file, but I'm not sure if other kernels do this. ] For the unlikely edge case of a core-file that has build-ids, but doesn't have any mapped file information then I propose that we synthesis a filename like: 'with build-id xxxxxx'. We would then see a message like: Downloading file with build-id xxxxxx... Where 'xxxxxx' would be replaced by the actual build-id. This isn't ideal, but I think is good enough, and, as I said, I think this case is not going to be hit very often, or maybe at all. We already had some tests that emitted two of the above messages, which I've updated, these cover the mapped-file and shared library case. The message about downloading the exec for the core-file is actually really hard to trigger now as usually the exec will also appear in the memory-mapped file list and GDB will download the file at this stage. Then when GDB needs the executable for loading the symbols it'll ask debuginfod, and debuginfod will find the file in its cache, and so no message will be printed. If anyone has any ideas about how to trigger this case then I'm happy to add additional tests. Approved-By: Tom Tromey <tom@tromey.com>
* Add dw2-aranges.expAlexandra Hájková2024-11-083-2/+77
| | | | | | | | | | | | | | | | | | | | | | This test checks that GDB is able to load DWARF information when .debug_aranges has a section address size that is set to 0. This test was originally written by Jan Kratochvil to test commit 927aa2e778d from 2017, titled "DWARF-5: .debug_names index consumer". This test was originally written using a static .S file and has been present in the Fedora tree for a long time. If dwarf2/aranges.c is modified to turn off the address_size check, GDB will crash with SIGFPE when loading the executable with address size set to zero. I modified the DWARF assembler to make it possible to set the address size to zero in a .debug_aranges section and used the DWARF assembler to produce the assembly file. Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com> Approved-by: Kevin Buettner <kevinb@redhat.com>