aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2022-10-21Fix bug in Ada packed array handlingTom Tromey5-0/+46
A user found a bug where an array of packed arrays was printed incorrectly. The bug here is that the packed array has a bit stride, but the outer array does not -- and should not. However, update_static_array_size does not distinguish between an array of packed arrays and a multi-dimensional packed array, and for the latter, only the innermost array will end up with a stride. This patch fixes the problem by adding a flag to indicate whether a given array type is a constituent of a multi-dimensional array.
2022-10-21gdb: declare variables on first use in inherit_abstract_diesSimon Marchi1-28/+23
Move variable declarations to where they are first use, plus some random style fixes. Change-Id: Idf40d60f9034996fa6a234165cd989a721eb4148
2022-10-21gdb/reverse: Fix stepping over recursive functionsBruno Larsen4-8/+74
Currently, when using GDB to do reverse debugging, if we try to use the command "reverse next" to skip a recursive function, instead of skipping all of the recursive calls and stopping in the previous line, we stop at the second to last recursive call, and need to manually step backwards until we leave the first call. This is well documented in PR gdb/16678. This bug happens because when GDB notices that a reverse step has entered into a function, GDB will add a step_resume_breakpoint at the start of the function, then single step out of the prologue once that breakpoint is hit. The problem was happening because GDB wouldn't give that step_resume_breakpoint a frame-id, so the first time the breakpoint was hit, the inferior would be stopped. This is fixed by giving the current frame-id to the breakpoint. This commit also changes gdb.reverse/step-reverse.c to contain a recursive function and attempt to both, skip it altogether, and to skip the second call from inside the first call, as this setup broke a previous version of the patch.
2022-10-21Change calculation of frame_id by amd64 epilogue unwinderBruno Larsen4-5/+206
When GDB is stopped at a ret instruction and no debug information is available for unwinding, GDB defaults to the amd64 epilogue unwinder, to be able to generate a decent backtrace. However, when calculating the frame id, the epilogue unwinder generates information as if the return instruction was the whole frame. This was an issue especially when attempting to reverse debug, as GDB would place a step_resume_breakpoint from the epilogue of a function if we were to attempt to skip that function, and this breakpoint should ideally have the current function's frame_id to avoid other problems such as PR record/16678. This commit changes the frame_id calculation for the amd64 epilogue, so that it is always the same as the dwarf2 unwinder's frame_id. It also adds a test to confirm that the frame_id will be the same, regardless of using the epilogue unwinder or not, thanks to Andrew Burgess. Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
2022-10-21GDB/Python: Make `None' stand for `unlimited' in setting integer parametersMaciej W. Rozycki3-12/+28
Similarly to booleans and following the fix for PR python/29217 make `gdb.parameter' accept `None' for `unlimited' with parameters of the PARAM_UINTEGER, PARAM_INTEGER, and PARAM_ZUINTEGER_UNLIMITED types, as `None' is already returned by parameters of the two former types, so one might expect to be able to feed it back. It also makes it possible to avoid the need to know what the internal integer representation is for the special setting of `unlimited'. Expand the testsuite accordingly. Approved-By: Simon Marchi <simon.marchi@polymtl.ca>
2022-10-21GDB/testsuite: Expand Python integer parameter coverage across all typesMaciej W. Rozycki1-16/+181
Also verify PARAM_UINTEGER, PARAM_INTEGER, and PARAM_ZINTEGER parameter types, in addition to PARAM_ZUINTEGER and PARAM_ZUINTEGER_UNLIMITED already covered, and verify a choice of existing GDB parameters. Add verification for reading parameters via `<parameter>.value' in addition to `gdb.parameter('<parameter>')' as this covers different code paths. Approved-By: Simon Marchi <simon.marchi@polymtl.ca>
2022-10-21GDB/Guile: Don't assert that an integer value is booleanMaciej W. Rozycki2-1/+177
Do not assert that a value intended for an integer parameter, of either the PARAM_UINTEGER or the PARAM_ZUINTEGER_UNLIMITED type, is boolean, causing error messages such as: ERROR: In procedure make-parameter: ERROR: In procedure gdbscm_make_parameter: Wrong type argument in position 15 (expecting integer or #:unlimited): 3 Error while executing Scheme code. when initialization with a number is attempted. Instead assert that it is integer. Keep matching `#:unlimited' keyword as an alternative. Add suitable test cases. Approved-By: Simon Marchi <simon.marchi@polymtl.ca>
2022-10-21[gdb/testsuite] Silence compilation fail in gdb.base/rtld-step.expTom de Vries1-0/+8
With gcc 7.5.0 and test-case gdb.base/rtld-step.exp, I run into: ... gdb compile failed, gcc: error: unrecognized command line option \ '-static-pie'; did you mean '-static'? ... Silence this by checking in the test-case that -static-pie is supported, and emitting instead: ... UNTESTED: gdb.base/rtld-step.exp: \ failed to compile (-static-pie not supported or static libc missing) ... Tested on x86_64-linux, with: - gcc 7.5.0: UNTESTED - gcc 12.2.1 with static glibc not installed: UNTESTED - gcc 12.2.1 with static glibc installed: PASS
2022-10-20gdb/python: break more dependencies between gdbpy_initialize_* functionsAndrew Burgess3-2/+36
In a later commit in this series I will propose removing all of the explicit gdbpy_initialize_* calls from python.c and replace these calls with a more generic mechanism. One of the side effects of this generic mechanism is that the order in which the various Python sub-systems within GDB are initialized is no longer guaranteed. On the whole I don't think this matters, most of the sub-systems are independent of each other, though testing did reveal a few places where we did have dependencies, though I don't think those dependencies were explicitly documented in comment anywhere. This commit is similar to the previous one, and fixes the second dependency issue that I found. In this case the finish_breakpoint_object_type uses the breakpoint_object_type as its tp_base, this means that breakpoint_object_type must have been initialized with a call to PyType_Ready before finish_breakpoint_object_type can be initialized. Previously we depended on the ordering of calls to gdbpy_initialize_breakpoints and gdbpy_initialize_finishbreakpoints in python.c. After this commit a new function gdbpy_breakpoint_init_breakpoint_type exists, this function ensures that breakpoint_object_type has been initialized, and can be called from any gdbpy_initialize_* function. I feel that this change makes the dependency explicit, which I think is a good thing. There should be no user visible changes after this commit.
2022-10-20gdb/python: break dependencies between gdbpy_initialize_* functionsAndrew Burgess3-14/+42
In a later commit in this series I will propose removing all of the explicit gdbpy_initialize_* calls from python.c and replace these calls with a more generic mechanism. One of the side effects of this generic mechanism is that the order in which the various Python sub-systems within GDB are initialized is no longer guaranteed. On the whole I don't think this matters, most of the sub-systems are independent of each other, though testing did reveal a few places where we did have dependencies, though I don't think those dependencies were explicitly documented in a comment anywhere. This commit removes the first dependency issue, with this and the next commit, all of the implicit inter-sub-system dependencies will be replaced by explicit dependencies, which will allow me to, I think, clean up how the sub-systems are initialized. The dependency is around the py_insn_type. This type is setup in gdbpy_initialize_instruction and used in gdbpy_initialize_record. Rather than depend on the calls to these two functions being in a particular order, in this commit I propose adding a new function py_insn_get_insn_type. This function will take care of setting up the py_insn_type type and calling PyType_Ready. This helper function can be called from gdbpy_initialize_record and gdbpy_initialize_instruction, and the py_insn_type will be initialized just once. To me this is better, the dependency is now really obvious, but also, we no longer care in which order gdbpy_initialize_record and gdbpy_initialize_instruction are called. There should be no user visible changes after this commit.
2022-10-20gdb: some int to bool conversion in breakpoint.cAndrew Burgess1-141/+135
Some int to bool conversion in breakpoint.c. I've only updated the function signatures of static functions, but I've updated some function local variables throughout the file. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-10-20gdb: make use of scoped_restore in unduplicated_should_be_insertedAndrew Burgess1-7/+4
I noticed that we could make use of a scoped_restore in the function unduplicated_should_be_inserted. I've also converted the function return type from int to bool. This change shouldn't make any difference, as I don't think anything within should_be_inserted could throw an exception, but the change doesn't hurt, and will help keep us safe if anything ever changes in the future. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-10-20gdb: used scoped_restore_frame in update_watchpointAndrew Burgess1-12/+5
I was doing some int to bool cleanup in update_watchpoint, and I noticed a manual version of scoped_restore_selected_frame. As always when these things are done manually, there is the chance that, in an error case, we might leave the wrong frame selected. This commit updates things to use scoped_restore_selected_frame, and also converts a local variable from int to bool. The only user visible change after this commit is in the case where update_watchpoint throws an error - we should now correctly restore the previously selected frame. Otherwise, this commit should be invisible to the user. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-10-20gdb: make some bp_location arguments const in breakpoint.cAndrew Burgess1-14/+14
I spotted a few places where I could make some 'bp_location *' arguments constant in breakpoint.c. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-10-20[gdb/testsuite] Fix gdb.debuginfod/fetch_src_and_symbols.exp with check-read1Tom de Vries1-3/+6
With test-case gdb.debuginfod/fetch_src_and_symbols.exp and check-read1, I run into: ... (gdb) FAIL: gdb.debuginfod/fetch_src_and_symbols.exp: local_url: \ file fetch_src_and_symbols (got interactive prompt) ... The problem is that this output: ... Enable debuginfod for this session? (y or [n]) y^M ... is matched using regexp "Enable debuginfod?.*" with matches only the first two words of the output, after which an implicit clause in gdb_test_multiple triggers on the second part containing the interactive prompt. Fix this by included the interactive prompt in the regexp. Tested on x86_64-linux.
2022-10-20[gdb/testsuite] Fix gdb.mi/mi-disassemble.exp with check-read1Tom de Vries2-2/+2
With test-case gdb.mi/mi-disassemble.exp and check-read1 I run into: ... FAIL: gdb.mi/mi-disassemble.exp: disassemble /b main FAIL: gdb.mi/mi-disassemble.exp: get valueof "*((unsigned char *) 0x400549)" ... The problem for both FAILs is that the output is parsed using gdb_test_multiple, which has implicit clauses using $gdb_prompt, which can match before the explicit clauses using $mi_gdb_prompt. Fix this by passing -prompt "$mi_gdb_prompt$" to gdb_test_multiple. Tested on x86-64-linux.
2022-10-19Test stepping within a runtime loader / dynamic linkerKevin Buettner3-0/+227
See the remarks in rtld-step.exp for a description of what this test is about. This test case has been tested using gcc on the following x86-64 Linux distributions/releases: Fedora 28 Fedora 32 Fedora 33 Fedora 34 Fedora 35 Fedora 36 Fedora 37 rawhide (f38) RHEL 9.1 Ubuntu 22.04.1 LTS It's also been tested (and found to be working) with RUNTESTFLAGS="CC_FOR_TARGET=clang" on all of the above expect for Fedora 28. The (old) version of clang available on F28 did not accept the -static-pie option. I also tried to make this test work on FreeBSD 13.1. While I think I made significant progress, I was ultimately stymied by this message which occurs when attempting to run the main program which has been set to use the fake/pretend RTLD as the ELF interpreter: ELF interpreter /path/to/rtld-step-rtld not found, error 22 I have left one of the flags (-static) in place which I believe to be needed for FreeBSD (though since I never got it to work, I don't know for sure.) I've also left some declarations needed for FreeBSD in rtld-step-rtld.c. They're currently disabled via a #if 0; you'll need to enable them if you want to try to make it work on FreeBSD.
2022-10-19Allow debugging of runtime loader / dynamic linkerKevin Buettner1-1/+4
At present, GDB does not allow for the debugging of the runtime loader and/or dynamic linker. Much of the time, this makes sense. An application programmer doesn't normally want to see symbol resolution code when stepping into a function that hasn't been resolved yet. But someone who wishes to debug the runtime loader / dynamic linker might place a breakpoint in that code and then wish to debug it as normal. At the moment, this is not possible. Attempting to step will cause GDB to internally step (and not stop) until code unrelated to the dynamic linker is reached. This commit makes a minor change to infrun.c which allows the dynamic loader / linker to be debugged in the case where a step, next, etc. is initiated from within that code. While developing this fix, I tried some approaches which weren't quite right. The GDB testusite definitely contains tests which FAIL when it's done incorrectly. (At one point, I saw 17 regressions!) This commit has been tested on x86-64 linux with no regressions.
2022-10-19[gdb] Fix assert in handle_jit_eventTom de Vries1-1/+4
With the cc-with-tweaks.sh patch submitted here ( https://sourceware.org/pipermail/gdb-patches/2022-October/192586.html ) we run with: ... $ export STRIP_ARGS_STRIP_DEBUG=--strip-all $ make check RUNTESTFLAGS="gdb.base/jit-reader.exp \ --target_board cc-with-gnu-debuglink" ... into the following assert: ... (gdb) run ^M Starting program: jit-reader ^M gdb/jit.c:1247: internal-error: jit_event_handler: \ Assertion `jiter->jiter_data != nullptr' failed.^M ... Fix this by handling the jit_bp_sym.objfile->separate_debug_objfile_backlink != nullptr case in handle_jit_event. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29277
2022-10-19internal_error: remove need to pass __FILE__/__LINE__Pedro Alves133-653/+395
Currently, every internal_error call must be passed __FILE__/__LINE__ explicitly, like: internal_error (__FILE__, __LINE__, "foo %d", var); The need to pass in explicit __FILE__/__LINE__ is there probably because the function predates widespread and portable variadic macros availability. We can use variadic macros nowadays, and in fact, we already use them in several places, including the related gdb_assert_not_reached. So this patch renames the internal_error function to something else, and then reimplements internal_error as a variadic macro that expands __FILE__/__LINE__ itself. The result is that we now should call internal_error like so: internal_error ("foo %d", var); Likewise for internal_warning. The patch adjusts all calls sites. 99% of the adjustments were done with a perl/sed script. The non-mechanical changes are in gdbsupport/errors.h, gdbsupport/gdb_assert.h, and gdb/gdbarch.py. Approved-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
2022-10-19gdb/testsuite: avoid temporary file in gdb/testsuite (unittest.exp)Andrew Burgess2-19/+137
I spotted that the gdb.gdb/unittest.exp script causes a temporary file inserters_extractors-2.txt to be created in build/gdb/testsuite/ instead of in build/gdb/testsuite/output/gdb.gdb/unittest/. This is because some of the 'maint selftest' tests create temporary files in GDB's current directory, specifically, the two source files: gdb/unittests/basic_string_view/inserters/wchar_t/2.cc gdb/unittests/basic_string_view/inserters/char/2.cc both create a temporary file called inserters_extractors-2.txt, though we only run the second of these as part of GDB's selftests. I initially proposed just using GDB's 'cd' command in unittest.exp to switch to the test output directory before running the selftests, however, Pedro pointed out that there was a risk here that, if GDB crashed during shutdown, the generated core file would be left in the test output directory rather than in the testsuite directory. As a result, our clever core file spotting logic would fail to spot the core file and alert the user. Instead, I propose this slightly more involved solution. I've added a new with_gdb_cwd directory proc, used like this: with_gdb_cwd $directory { # Tests here... } The new proc temporarily switches to $directory and then runs the tests within the block. After running the tests the previous current working directory is restored. Additionally, after switching back to the previous cwd, we check that GDB is still responsive. This means that if GDB crashed immediately prior to restoring the previous directory, and left the core file in the wrong place, then the responsiveness check will fail, and a FAIL will be emitted, this should be enough to alert the user that something has gone wrong. With this commit in place the unittest.exp script now leaves its temporary file in the test output directory.
2022-10-19gdb/testsuite: avoid creating files in gdb/testsuite directoryAndrew Burgess1-1/+1
I spotted that the test gdb.dwarf2/dw2-using-debug-str.exp was creating an output file called debug_str_section in the root build/gdb/testsuite directory instead of using the build/gdb/testsuite/output/gdb.dwarf2/dw2-using-debug-str/ directory. This appears to be caused by a missing '$' character. We setup a variable debug_str_section which contains a path within the output directory, but then when we build the objcopy command we use 'debug_str_section' without a '$' prefix, as a result, we create the debug_str_section file. This commit adds the missing '$', the file is now created in the output directory.
2022-10-19aarch64-pe support for LD, GAS and BFDJedidiah Thompson1-2/+6
Allows aarch64-pe to be targeted natively, not having to use objcopy to convert it from ELF to PE. Based on initial work by Jedidiah Thompson Co-authored-by: Jedidiah Thompson <wej22007@outlook.com> Co-authored-by: Zac Walker <zac.walker@linaro.org>
2022-10-19[gdb/testsuite] Fix ERROR in gdb.python/py-breakpoint.expTom de Vries1-0/+2
With test-case gdb.python/py-breakpoint.exp I run into: ... (gdb) ERROR: tcl error sourcing gdb.python/py-breakpoint.exp. ERROR: can't read "skip_hw_watchpoint_tests_p": no such variable while executing "if {$skip_hw_watchpoint_tests_p} { gdb_test_no_output "set can-use-hw-watchpoints 0" "" }" ... Fix this by adding the missing "global skip_hw_watchpoint_tests_p" in two procs. Tested on x86_64-linux.
2022-10-18gdb: check for groups with duplicate names in reggroups:addSimon Marchi1-2/+7
In the downstream ROCm GDB port, we would create multiple register groups with duplicate names. While it did not really hurt, it certainly wasn't the intent. And I don't think it ever makes sense to do so. To catch these, change the assert in reggroups::add to check for duplicate names. It's no longer necessary to check for duplicate reggroup pointers, because adding the same group twice would be caught by the duplicate name check. Change-Id: Id216a58acf91f1b314d3cba2d02de73656f8851d Approved-By: Tom Tromey <tom@tromey.com>
2022-10-18Remove dead code from py-finishbreakpoint.cTom Tromey1-6/+1
PR python/16324 points out that comparing a frame id to null_frame_id can never succeed, and proposes simply removing the dead code. That is what this patch does. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16324
2022-10-18Update tests to use skip_hw_watchpoint_tests to test for HW watchpoint support.Carl Love16-23/+143
The hardware watchpoint check has been updated in a couple of recent patches. This patch updates the hardware watchpoint test in the remaining gdb tests. The issue is the PowerPC processors support hardware watchpoints with the exception of Power 9. The hardware watchpoint support is disabled on Power 9. The test skip_hw_watchpoint_tests must be used to correctly determine if the PowerPC processor supports hardware watchpoints. This patch fixes 6 test failures in test gdb.threads/watchpoint-fork.exp. Test gdb.base/watch-vfork.exp runs with can-use-hw-watchpoints set to true and false. When the test is run with can-use-hw-watchpoints set to true, gdb just falls back to using software watchpoints. The patch reduces the number of expected passes by 2 since because it now only runs once with can-use-hw-watchpoints set to false. Test gdb.mi/mi-watch.exp runs the test with argument hw and sw. If the argument is hw and hardware watchpoints are not supported the test exits. The number of expected passes is cut in half with the patch as it now only runs the test using software breakpoints. Previously the pass to use hardware watchpoints was not skipped and the test actually ran using software watchpoints. The following tests run the same with and without the patch. The tests are supposed to execute the gdb command "set can-use-hw-watchpoints 0" if the processor does not support hardware bwatchpoints. However the command was not being executed and gdb was falling back to using software watchpoints since the Power 9 watchpoint resource check fails. With the patch, the tests now execute the command and the test runs using software watchpoints as it did previously. The tests are: gdb.base/commands.exp gdb.base/cond-eval-mode.exp gdb.base/display.exp gdb.base/gdb11531.exp gdb.base/recurse.exp gdb.base/value-double-free.exp gdb.base/watch-bitfields.exp gdb.base/watch-cond-infcall.exp gdb.base/watch-cond.exp gdb.base/watchpoint-solib.exp gdb.base/watchpoints.exp The following two tests are not supported on the Power 9 system used to test the changes. The patch does not change the tests results for these tests: gdb.python/py-breakpoint.exp gdb.mi/mi-watch-nonstop.exp
2022-10-18[gdb/testsuite] Handle header files with local-remote-host.expTom de Vries5-1/+21
With test-case gdb.base/included.exp and host board local-remote-host.exp with tentative fix for PR29697 I run into: ... included.c:18:10: fatal error: included.h: No such file or directory #include "included.h" ^~~~~~~~~~~~ compilation terminated. ... Fix this by adding the missing gdb_remote_download calls. Likewise in a few other test-cases. Tested on x86_64-linux.
2022-10-18[gdb/testsuite] Fix gdb.server/no-thread-db.exp with local-remote-host.expTom de Vries1-1/+2
With test-case gdb.server/no-thread-db.exp and host board local-remote-host.exp with a tentative fix for PR29697 I run into: ... (gdb) print foo^M Cannot find thread-local storage for Thread 29613.29613, executable file \ $HOME/no-thread-db:^M Remote target failed to process qGetTLSAddr request^M (gdb) FAIL: gdb.server/no-thread-db.exp: print foo ... The regexp in the test-case expects the full $binfile pathname, but we have instead $HOME/no-thread-db. Fix this by making the regexp less strict. Tested on x86_64-linux.
2022-10-18[gdb/testsuite] Fix gdb.base/return-nodebug.exp with local-remote-host.expTom de Vries3-6/+28
With host board local-remote-host.exp and test-case gdb.base/return-nodebug.exp, I run into: ... Executing on host: gcc -fno-stack-protector -fdiagnostics-color=never \ -DTYPE=signed\ char -c -g -o return-nodebug-signed-char0.o \ /home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/return-nodebug.c \ (timeout = 300) builtin_spawn [open ...]^M gcc: error: char: No such file or directory ... Avoid the quoting problem by not using spaces in the define. Tested on x86_64-linux.
2022-10-18[gdb/testsuite] Fix gdb.server/file-transfer.exp with local-remote-host.expTom de Vries1-2/+6
When running test-case gdb.server/file-transfer.exp with host board local-remote-host.exp, I get: ... Executing on host: cmp -s $outputs/gdb.server/file-transfer/file-transfer \ down-server (timeout = 300) builtin_spawn [open ...]^M XYZ2ZYX FAIL: gdb.server/file-transfer.exp: compare intermediate binary file ... The remote host and remote target cases are handled here together here in proc test_file_transfer: ... if {![is_remote host] && ![is_remote target]} { set up_server [standard_output_file $up_server] set down_server [standard_output_file $down_server] } ... Fix this by handling them separately. Tested on x86_64-linux.
2022-10-18[gdb/testsuite] Update boards/READMETom de Vries1-1/+1
Update gdb/testsuite/boards/README to reflect recent commit c4c8c27263d ("[gdb/testsuite] Fix host board local-remote-host-notty.exp timeouts"), which means the board now uses a pseudo-tty, but with editing disabled.
2022-10-18gdb, solib-svr4: support namespaces in DSO iterationMarkus Metzger6-16/+159
When looking up names, GDB needs to stay within one linker namespace to find the correct instance in case the same name is provided in more than one namespace. Modify svr4_iterate_over_objfiles_in_search_order() to stay within the namespace of the current_objfile argument. If no current_objfile is provided (i.e. it is nullptr), iterate over objfiles in the initial namespace. For objfiles that do not have a corresponding so_list to provide the namespace, assume that the objfile was loaded into the initial namespace. This would cover the main executable objfile (which is indeed loaded into the initial namespace) as well as manually added symbol files. Expected fails: - gdb.base/non-lazy-array-index.exp: the expression parser may lookup global symbols, which may result in xfers to read auxv for determining the debug base as part of svr4_iterate_over_objfiles_in_search_order(). - gdb.server/non-lazy-array-index.exp: symbol lookup may access the target to read AUXV in order to determine the debug base for SVR4 linker namespaces. Known issues: - get_symbol_address() and get_msymbol_address() search objfiles for a 'better' match. This was introduced by 4b610737f02 Handle copy relocations to handle copy relocations but it now causes a wrong address to be read after symbol lookup actually cound the correct symbol. This can be seen, for example, with gdb.base/dlmopen.exp when compiled with clang. - gnu ifuncs are only looked up in the initial namespace. - lookup_minimal_symbol() and lookup_minimal_symbol_text() directly iterate over objfiles and are not aware of linker namespaces.
2022-10-18gdb: update gnu ifunc resolveMarkus Metzger1-66/+87
Update elf_gnu_ifunc_resolve_by_cache() and elf_gnu_ifunc_resolve_by_got() to use gdbarch_iterate_over_objfiles_in_search_order() in order to restrict the objfile traversal to the initial namespace. In order to extend this to other namespaces, we'd need to provide context, e.g. via an objfile inside that namespace.
2022-10-18gdb, symtab: inline find_quick_global_symbol_languageMarkus Metzger1-24/+19
There is only one use of find_quick_global_symbol_language that calls it for the special symbol "main". Inline the function as it is probably not correct in the general case where we may have multiple instances of global symbols with the same name but different languages in different libraries in different linker namespaces. Further, change the objfiles iteration into a call to gdbarch_iterate_over_objfiles_in_search_order, which would only search the initial linker namespace, where we expect "main" to be located.
2022-10-18gdb, hppa: remove unused hppa_lookup_stub_minimal_symbolMarkus Metzger2-35/+0
I stumbled over this while reviewing all objfiles traversals with regards to impact of linker namespaces. Recursive grep only finds two occurrences of hppa_lookup_stub_minimal_symbol: - the declaration in hppa-tdep.h. - the definition in hppa-tdep.c. There appear to be no calls to this function. Remove it.
2022-10-18gdb, cp: update add_symbol_overload_list_qualifiedMarkus Metzger1-24/+24
Iterate over objfiles in search order using the objfile of the selected block as current_objfile so the iteration can stay inside the block's linker namespace.
2022-10-18fixup! gdb, ada: update ada_lookup_simple_minsymMarkus Metzger1-3/+0
remove get_selected_block()
2022-10-18gdb, ada: update ada_lookup_simple_minsymMarkus Metzger3-16/+28
Iterate over objfile in search order using the objfile of the context block as current_objfile so the iteration can stay inside the block's linker namespace.
2022-10-18gdb, ada: collect standard exceptions in all objfilesMarkus Metzger1-7/+23
When searching for standard exceptions for Ada, we lookup the minimal symbol of each exception. With linker namespaces there can be multiple instances in different namespaces. Collect them all.
2022-10-18gdb, python: use gdbarch_iterate_over_objfiles_in_search_orderMarkus Metzger3-65/+64
The implementation of gdb.lookup_objfile() iterates over all objfiles and compares their name or build id to the user-provided search string. This will cause problems when supporting linker namespaces as the first objfile in any namespace will be found. Instead, use gdbarch_iterate_over_objfiles_in_search_order to only consider the namespace of gdb.current_objfile() for the search, which defaults to the initial namespace when gdb.current_objfile() is None.
2022-10-18gdb, compile: unlink objfile stored in moduleMarkus Metzger1-12/+9
When cleaning up after a compile command, we iterate over all objfiles and unlink the first objfile with the same name as the one we compiled. Since we already store a pointer to that objfile in the module and use it to get the name we're comparing against, there's no reason to iterate, at all. We can simply use that objfile. This further avoids potential issues when an objfile with the same name is loaded into a different linker namespace.
2022-10-18gdb, gdbserver: extend RSP to support namespacesMarkus Metzger3-5/+53
Introduce a new qXfer:libraries-svr4:read annex key/value pair lmid=<namespace identifier> to be used together with start and prev to provide the namespace of start and prev to gdbserver. Unknown key/value pairs are ignored by gdbserver so no new supports check is needed. Introduce a new library-list-svr4 library attribute lmid to provide the namespace of a library entry to GDB. This implementation uses the address of a namespace's r_debug object as namespace identifier. This should have incremented the minor version but since unknown XML attributes are ignored, anyway, and since changing the version results in a warning from GDB, the version is left at 1.0.
2022-10-18gdb, gdbserver: support dlmopen()Markus Metzger9-91/+639
In glibc, the r_debug structure contains (amongst others) the following fields: int r_version: Version number for this protocol. It should be greater than 0. If r_version is 2, struct r_debug is extended to struct r_debug_extended with one additional field: struct r_debug_extended *r_next; Link to the next r_debug_extended structure. Each r_debug_extended structure represents a different namespace. The first r_debug_extended structure is for the default namespace. 1. Change solib_svr4_r_map argument to take the debug base. 2. Add solib_svr4_r_next to find the link map in the next namespace from the r_next field. 3. Update svr4_current_sos_direct to get the link map in the next namespace from the r_next field. 4. Don't check shared libraries in other namespaces when updating shared libraries in a new namespace. 5. Update svr4_same to check the load offset in addition to the name 6. Update svr4_default_sos to also set l_addr_inferior 7. Change the flat solib_list into a per-namespace list using the namespace's r_debug address to identify the namespace. Add gdb.base/dlmopen.exp to test this. To remain backwards compatible with older gdbserver, we reserve the namespace zero for a flat list of solibs from all namespaces. Subsequent patches will extend RSP to allow listing libraries grouped by namespace. This fixes PR 11839. Co-authored-by: Lu, Hongjiu <hongjiu.lu@intel.com>
2022-10-18gdb, solib-svr4: remove locate_base()Markus Metzger1-51/+11
Whenever we call locate_base(), we clear info->debug_base directly before the call. Thus, we never cache the base location as locate_base() had intended. Move the svr4_have_link_map_offsets() check into elf_locate_base(), inline locate_base() at all call sites, and remove it.
2022-10-18gdb, testsuite: extend gdb_test_multiple checksMarkus Metzger1-0/+8
Check for warning: Corrupted shared library list and for Invalid cast. warning: Probes-based dynamic linker interface failed. Reverting to original interface. in gdb_test_multiple.
2022-10-17kfail an Ada test for GCC < 12Tom Tromey1-0/+12
I noticed one particular Ada test was failing on Fedora 34, but works when I switch to GCC 12. This patch arranges to kfail the test when an older compiler is used. I tested this with GCC 11, 12, and 13. I'm going to check it in.
2022-10-17Remove a nullptr check in DWARF scannerTom Tromey1-1/+0
In scan_attributes, The DWARF scanner checks whether maybe_defer is nullptr, but this can never happen. This patch removes the check.
2022-10-17gdbarch-components.py: Remove spurious space from "frame_info_ptr " paramsPedro Alves1-15/+15
If you run gdbarch.py today, you'll get local modifications compared to what's in the tree, like: --- c/gdb/gdbarch-gen.h +++ w/gdb/gdbarch-gen.h @@ -315,8 +315,8 @@ extern void set_gdbarch_register_type (struct gdbarch *gdbarch, gdbarch_register should match the address at which the breakpoint was set in the dummy frame. */ -typedef struct frame_id (gdbarch_dummy_id_ftype) (struct gdbarch *gdbarch, frame_info_ptr this_frame); -extern struct frame_id gdbarch_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame); +typedef struct frame_id (gdbarch_dummy_id_ftype) (struct gdbarch *gdbarch, frame_info_ptr this_frame); +extern struct frame_id gdbarch_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame); extern void set_gdbarch_dummy_id (struct gdbarch *gdbarch, gdbarch_dummy_id_ftype *dummy_id); etc. The extra space comes from the "frame_info_ptr " param that appears in a number of gdbarch methods in gdbarch-components.py. With the extra space removed, running ./gdbarch.py generates the exact code that's in the tree already. Change-Id: If7d20b8c6b2fd9ff466142a01bd2611c9ef9f53e
2022-10-17Change .gdb_index de-duplication implementationTom Tromey1-36/+41
While investigating PR symtab/29179, I found that one Ada test failed because, although a certain symbol was present in the index, with the new DWARF reader it pointed to a different CU than was chosen by earlier versions of gdb. This patch changes how symbol de-duplication is done, deferring the process until the entire symbol table has been constructed. This way, it's possible to always choose the lower-numbered CU among duplicates, which is how gdb (implicitly) previously worked. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29179