aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2022-05-26gdb: Change psymbol_functions::require_partial_symbols to partial_symbolsLancelot SIX2-23/+19
The previous patch ensured that partial symbols are read before calling most of the quick_function's methods. The psymbol_functions class has the require_partial_symbols method which serves this exact purpose, and does not need to do it anymore. This patch renames this method to partial_symbols and makes it an accessor which asserts that partial symbols have been read at this point. Regression tested on x86_64-linux.
2022-05-26gdb: Require psymtab before calling quick_functions in objfileLancelot SIX5-15/+148
The recent DWARF indexer rewrite introduced a regression when debugging a forking program. Here is a way to reproduce the issue (there might be other ways, but one is enough and this one mimics the situation we encountered). Consider a program which forks, and the child loads a shared library and calls a function in this shared library: if (fork () == 0) { void *solib = dlopen (some_solib, RTLD_NOW); void (*foo) () = dlsym (some_solib, "foo"); foo (); } Suppose that this program is compiled without debug info, but the shared library it loads has debug info enabled. When debugging such program with the following options: - set detach-on-fork off - set follow-fork-mode child we see something like: (gdb) b foo Function "foo" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (foo) pending. (gdb) run Starting program: a.out [Attaching after process 19720 fork to child process 19723] [New inferior 2 (process 19723)] [Switching to process 19723] Thread 2.1 "a.out" hit Breakpoint 1, 0x00007ffff7fc3101 in foo () from .../libfoo.so (gdb) list Fatal signal: Segmentation fault ----- Backtrace ----- 0x55a278f77d76 gdb_internal_backtrace_1 ../../gdb/bt-utils.c:122 0x55a278f77f83 _Z22gdb_internal_backtracev ../../gdb/bt-utils.c:168 0x55a27940b83b handle_fatal_signal ../../gdb/event-top.c:914 0x55a27940bbb1 handle_sigsegv ../../gdb/event-top.c:987 0x7effec0343bf ??? /build/glibc-sMfBJT/glibc-2.31/nptl/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 0x55a27924c9d3 _ZNKSt15__uniq_ptr_implI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterE6_M_ptrEv /usr/include/c++/9/bits/unique_ptr.h:154 0x55a279248bc9 _ZNKSt10unique_ptrI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterE3getEv /usr/include/c++/9/bits/unique_ptr.h:361 0x55a2792ae718 _ZN27dwarf2_base_index_functions23find_last_source_symtabEP7objfile ../../gdb/dwarf2/read.c:3164 0x55a279afb93e _ZN7objfile23find_last_source_symtabEv ../../gdb/symfile-debug.c:139 0x55a279aa3040 _Z20select_source_symtabP6symtab ../../gdb/source.c:365 0x55a279aa22a1 _Z34set_default_source_symtab_and_linev ../../gdb/source.c:268 0x55a27903c44c list_command ../../gdb/cli/cli-cmds.c:1185 0x55a279051233 do_simple_func ../../gdb/cli/cli-decode.c:95 0x55a27905f221 _Z8cmd_funcP16cmd_list_elementPKci ../../gdb/cli/cli-decode.c:2514 0x55a279c3b0ba _Z15execute_commandPKci ../../gdb/top.c:660 0x55a27940a6c3 _Z15command_handlerPKc ../../gdb/event-top.c:598 0x55a27940b032 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE ../../gdb/event-top.c:797 0x55a279caf401 tui_command_line_handler ../../gdb/tui/tui-interp.c:278 0x55a279409098 gdb_rl_callback_handler ../../gdb/event-top.c:230 0x55a279ed5df2 rl_callback_read_char ../../../readline/readline/callback.c:281 0x55a279408bd8 gdb_rl_callback_read_char_wrapper_noexcept ../../gdb/event-top.c:188 0x55a279408de7 gdb_rl_callback_read_char_wrapper ../../gdb/event-top.c:205 0x55a27940a061 _Z19stdin_event_handleriPv ../../gdb/event-top.c:525 0x55a27a23771e handle_file_event ../../gdbsupport/event-loop.cc:574 0x55a27a237f5f gdb_wait_for_event ../../gdbsupport/event-loop.cc:700 0x55a27a235d81 _Z16gdb_do_one_eventv ../../gdbsupport/event-loop.cc:237 0x55a2796c2ef0 start_event_loop ../../gdb/main.c:418 0x55a2796c3217 captured_command_loop ../../gdb/main.c:478 0x55a2796c717b captured_main ../../gdb/main.c:1340 0x55a2796c7217 _Z8gdb_mainP18captured_main_args ../../gdb/main.c:1355 0x55a278d0b381 main ../../gdb/gdb.c:32 --------------------- 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/>. The first issue observed is in the message printed when hitting the breakpoint. It says that there was a break in the .so file as if there was no debug info associated with it, but there is. Later, if we try to display the source where the execution stopped, we have a segfault. Note that not having the debug info on the main binary is not strictly required to encounter some issues, it only is to encounter the segfault. If the main binary has debug information, GDB shows some source form the main binary, unrelated to where we stopped. The core of the issue is that GDB never loads the psymtab for the library. It is not loaded when we first see the .so because in case of detach-on-fork off, follow-fork-mode child, infrun.c sets child_inf->symfile_flags = SYMFILE_NO_READ to delay the psymtab loading as much as possible. If we compare to what was done to handle this before the new indexer was activated, the psymatb construction for the shared library was done under psymbol_functions::expand_symtabs_matching: bool psymbol_functions::expand_symtabs_matching (...) { for (partial_symtab *ps : require_partial_symbols (objfile)) ... } The new indexer's expand_symtabs_matching callback does not have a call to the objfile's require_partial_symbols, so if the partial symbol table is not loaded at this point, there is no mechanism to fix this. Instead of requiring each implementation of the quick_functions to check that partial symbols have been read, I think it is safer to enforce this when calling the quick functions. The general pattern for calling the quick functions is: for (auto *iter : qf) iter->the_actual_method_call (...) This patch proposes to wrap the access of the `qf` field with an accessor which ensures that partial symbols have been read before iterating: qf_require_partial_symbols. All calls to quick functions are updated except: - quick_functions::dump - quick_functions::read_partial_symbols (from objfile::require_partial_symbols) - quick_functions::can_lazily_read_symbols and quick_functions::has_symbols (from objfile::has_partial_symbols) Regression tested on x86_64-gnu-linux. Change-Id: I39a13a937fdbaae613a5cf68864b021000554546
2022-05-26Fix crash in new DWARF indexerTom Tromey2-39/+95
PR gdb/29128 points out a crash in the new DWARF index code. This happens if the aranges for a CU claims a PC, but the symtab that is created during CU expansion does not actually contain the PC. This can only occur due to bad debuginfo, but at the same time, gdb should not crash. This patch fixes the bug and further merges some code into dwarf2_base_index_functions. This merger helps prevent the same issue from arising from the other index implementations. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29128
2022-05-26Finalize each cooked index separatelyTom Tromey2-163/+192
After DWARF has been scanned, the cooked index code does a "finalization" step in a worker thread. This step combines all the index entries into a single master list, canonicalizes C++ names, and splits Ada names to synthesize package names. While this step is run in the background, gdb will wait for the results in some situations, and it turns out that this step can be slow. This is PR symtab/29105. This can be sped up by parallelizing, at a small memory cost. Now each index is finalized on its own, in a worker thread. The cost comes from name canonicalization: if a given non-canonical name is referred to by multiple indices, there will be N canonical copies (one per index) rather than just one. This requires changing the users of the index to iterate over multiple results. However, this is easily done by introducing a new "chained range" class. When run on gdb itself, the memory cost seems rather low -- on my current machine, "maint space 1" reports no change due to the patch. For performance testing, using "maint time 1" and "file" will not show correct results. That approach measures "time to next prompt", but because the patch only affects background work, this shouldn't (and doesn't) change. Instead, a simple way to make gdb wait for the results is to set a breakpoint. Before: $ /bin/time -f%e ~/gdb/install/bin/gdb -nx -q -batch \ -ex 'break main' /tmp/gdb Breakpoint 1 at 0x43ec30: file ../../binutils-gdb/gdb/gdb.c, line 28. 2.00 After: $ /bin/time -f%e ./gdb/gdb -nx -q -batch \ -ex 'break main' /tmp/gdb Breakpoint 1 at 0x43ec30: file ../../binutils-gdb/gdb/gdb.c, line 28. 0.65 Regression tested on x86-64 Fedora 34. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29105
2022-05-26gdb/linux-nat: xfer_memory_partial return E_IO on errorLancelot SIX1-1/+1
When accessing /proc/PID/mem, if pread64/pwrite64/read/write encounters an error and return -1, linux_proc_xfer_memory_partial return TARGET_XFER_EOF. I think it should return TARGET_XFER_E_IO in this case. TARGET_XFER_EOF is returned when pread64/pwrite64/read/frite returns 0, which indicates that the address space is gone and the whole process has exited or execed. This patch makes this change. Regression tested on x86_64-linux-gnu. Change-Id: I6030412459663b8d7933483fdda22a6c2c5d7221
2022-05-26gdb/testsuite: prefer gdb_test in gdb.dwarf2/calling-conventionLancelot SIX1-6/+8
Since ed01945057c "Make gdb_test's question non-optional if specified", if the question and response parameters are given to gdb_test, the framework enforces that GDB asks the question. Before this patch, tests needed to use gdb_test_multiple to enforce this. This patch updates the gdb.dwarf2/calling-convention.exp testcase to use gdb_test to check that GDB asks a question. This replaces the more complicated gdb_test_multiple based implementation. Tested on x86_64-gnu-linux. Change-Id: I7216e822ca68f2727e0450970097d74c27c432fe
2022-05-25Show enabled locations with disabled breakpoint parent as "y-"Pedro Alves4-20/+68
Currently, breakpoint locations that are enabled while their parent breakpoint is disabled are displayed with "y" in the Enb colum of "info breakpoints": (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep n <MULTIPLE> 1.1 y 0x00000000000011b6 in ... 1.2 y 0x00000000000011c2 in ... 1.3 n 0x00000000000011ce in ... Such locations won't trigger a break, so to avoid confusion, show "y-" instead. For example: (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep n <MULTIPLE> 1.1 y- 0x00000000000011b6 in ... 1.2 y- 0x00000000000011c2 in ... 1.3 n 0x00000000000011ce in ... The "-" sign is inspired on how the TUI represents breakpoints on the left side of the source window, with "b-" for a disabled breakpoint. Change-Id: I9952313743c51bf21b4b380c72360ef7d4396a09
2022-05-25gdb: Fix DUPLICATE and PATH regressions throughoutPedro Alves38-934/+969
The previous patch to add -prompt/-lbl to gdb_test introduced a regression: Before, you could specify an explicit empty message to indicate you didn't want to PASS, like so: gdb_test COMMAND PATTERN "" After said patch, gdb_test no longer distinguishes no-message-specified vs empty-message, so tests that previously would be silent on PASS, now started emitting PASS messages based on COMMAND. This in turn introduced a number of PATH/DUPLICATE violations in the testsuite. This commit fixes all the regressions I could see. This patch uses the new -nopass feature introduced in the previous commit, but tries to avoid it if possible. Most of the patch fixes DUPLICATE issues the usual way, of using with_test_prefix or explicit unique messages. See previous commit's log for more info. In addition to looking for DUPLICATEs, I also looked for cases where we would now end up with an empty message in gdb.sum, due to a gdb_test being passed both no message and empty command. E.g., this in gdb.ada/bp_reset.exp: gdb_run_cmd gdb_test "" "Breakpoint $decimal, foo\\.nested_sub \\(\\).*" was resulting in this in gdb.sum: PASS: gdb.ada/bp_reset.exp: I fixed such cases by passing an explicit message. We may want to make such cases error out. Tested on x86_64 GNU/Linux, native and native-extended-gdbserver. I see zero PATH cases now. I get zero DUPLICATEs with native testing now. I still see some DUPLICATEs with native-extended-gdbserver, but those were preexisting, unrelated to the gdb_test change. Change-Id: I5375f23f073493e0672190a0ec2e847938a580b2
2022-05-25Add -nopass option to gdb_test/gdb_test_multiplePedro Alves1-28/+32
The previous patch to add -prompt/-lbl to gdb_test introduced a regression: Before, you could specify an explicit empty message to indicate you didn't want to PASS, like so: gdb_test COMMAND PATTERN "" After said patch, gdb_test no longer distinguishes no-message-specified vs empty-message, so tests that previously would be silent on PASS, now started emitting PASS messages based on COMMAND. This in turn introduced a number of PATH/DUPLICATE violations in the testsuite. I think that not issuing a PASS should be restricted to only a few cases -- namely in shared routines exported by gdb.exp, which happen to use gdb_test internally. In tests that iterate an unknown number of tests exercising some racy scenario. In the latter case, if we emit PASSes for each iteration, we run into the situation where different testsuite runs emit a different number of PASSes. Thus, this patch preserves the current behavior, and, instead, adds a new "-nopass" option to gdb_test and gdb_test_no_output. Compared to the old way of supressing PASS with an empty message, this has the advantage that you can specify a FAIL message that is distinct from the command string, and, it's also more explicit. Change-Id: I5375f23f073493e0672190a0ec2e847938a580b2
2022-05-24[gdb/testsuite] Fix gdb.opt/clobbered-registers-O2.exp with clangTom de Vries4-17/+50
When running test-case gdb.opt/clobbered-registers-O2.exp with clang 12.0.1, I get: ... (gdb) run ^M Starting program: clobbered-registers-O2 ^M ^M Program received signal SIGSEGV, Segmentation fault.^M gen_movsd (operand0=<optimized out>, operand1=<optimized out>) at \ clobbered-registers-O2.c:31^M 31 return *start_sequence(operand0, operand1);^M (gdb) FAIL: gdb.opt/clobbered-registers-O2.exp: runto: run to start_sequence ... The problem is that the breakpoint in start_sequence doesn't trigger, because: - the call to start_sequence in gen_movsd is optimized away, despite the __attribute__((noinline)), so the actual function start_sequence doesn't get called, and - the debug info doesn't contain inlined function info, so there's only one breakpoint location. Adding noclone and noipa alongside the noinline attribute doesn't fix this. Adding the clang-specific attribute optnone in start_sequence does, but since it inhibits all optimization, that's not a preferred solution in a gdb.opt test-case, and it would work only for clang and not other compilers that possibly have the same issue. Fix this by moving functions start_sequence and gen_movsd into their own files, as a way of trying harder to enforce noinline/noipa/noclone. Tested on x86_64-linux.
2022-05-24[gdb/testsuite] Fix gdb.opt/clobbered-registers-O2.exp with gcc-12Tom de Vries1-1/+1
When running test-case gdb.opt/clobbered-registers-O2.exp with gcc-12, I run into: ... (gdb) PASS: gdb.opt/clobbered-registers-O2.exp: backtracing print operand0^M $1 = (unsigned int *) 0x7fffffffd070^M (gdb) print *operand0^M $2 = 4195541^M (gdb) FAIL: gdb.opt/clobbered-registers-O2.exp: print operand0 ... The problem is that starting gcc-12, the assignments to x and y in main are optimized away: ... int main(void) { unsigned x, y; x = 13; y = 14; return (int)gen_movsd (&x, &y); ... Fix this by making x and y volatile. Note that the test-case intends to check the handling of debug info for optimized code in function gen_movsd, so inhibiting optimization in main doesn't interfere with that. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29161
2022-05-24gdb: LoongArch: Define LOONGARCH_LINUX_NUM_GREGSET as 45Tiezhu Yang1-2/+2
LOONGARCH_LINUX_NUM_GREGSET should be defined as 45 (32 + 1 + 1 + 11) due to reserved 11 for extension in glibc, otherwise when execute: make check-gdb TESTS="gdb.base/corefile.exp" there exists the following failed testcase: (gdb) core-file /home/loongson/build.git/gdb/testsuite/outputs/gdb.base/corefile/corefile.core [New LWP 7742] warning: Unexpected size of section `.reg/7742' in core file. Core was generated by `/home/loongson/build.git/gdb/testsuite/outputs/gdb.base/corefile/corefile'. Program terminated with signal SIGABRT, Aborted. warning: Unexpected size of section `.reg/7742' in core file. #0 0x000000fff76f4e24 in raise () from /lib/loongarch64-linux-gnu/libc.so.6 (gdb) FAIL: gdb.base/corefile.exp: core-file warning-free Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-05-24AArch64: add support for DFP (Decimal Floating point)Christophe Lyon1-0/+2
This small patch adds support for TYPE_CODE_DECFLOAT in aapcs_is_vfp_call_or_return_candidate_1 and pass_in_v_vfp_candidate, so that GDB for AArch64 knows how to pass DFP parameters and how to read DFP results when calling a function. Tested on aarch64-linux-gnu, with a GCC with DFP support in the PATH, all of GDB's DFP tests pass.
2022-05-23Tweak the std::hash<> specialization for aarch64_features.John Baldwin1-12/+15
Move the specialization into an explicit std namespace to workaround a bug in older compilers. GCC 6.4.1 at least fails to compile the previous version with the following error: gdb/arch/aarch64.h:48:13: error: specialization of 'template<class _Tp> struct std::hash' in different namespace [-fpermissive] struct std::hash<aarch64_features>
2022-05-23Fix loongarch_iterate_over_regset_sections for non-native targets.John Baldwin1-2/+12
Define a constant for the number of registers stored in a register set and use this with register_size to compute the size of the general-purpose register set in core dumps. This also fixes the build on hosts such as FreeBSD that do not define an elf_gregset_t type.
2022-05-23gdb: LoongArch: Implement the iterate_over_regset_sections gdbarch methodTiezhu Yang1-0/+16
When execute the following command on LoongArch: make check-gdb TESTS="gdb.base/auxv.exp" there exist the following unsupported and failed testcases: UNSUPPORTED: gdb.base/auxv.exp: gcore FAIL: gdb.base/auxv.exp: load core file for info auxv on native core dump FAIL: gdb.base/auxv.exp: info auxv on native core dump FAIL: gdb.base/auxv.exp: matching auxv data from live and core UNSUPPORTED: gdb.base/auxv.exp: info auxv on gcore-created dump UNSUPPORTED: gdb.base/auxv.exp: matching auxv data from live and gcore we can see the following messages in gdb/testsuite/gdb.log: gcore /home/loongson/build.git/gdb/testsuite/outputs/gdb.base/auxv/auxv.gcore Target does not support core file generation. (gdb) UNSUPPORTED: gdb.base/auxv.exp: gcore In order to fix the above issues, implement the iterate_over_regset_sections gdbarch method to iterate over core file register note sections on LoongArch. By the way, with this patch, the failed testcases in gdb.base/corefile.exp and gdb.base/gcore.exp can also be fixed. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-05-23[gdb/testsuite] Fix -prompt handling in gdb_testTom de Vries1-1/+1
With check-read1 I run into: ... [infrun] maybe_set_commit_resumed_all_targets: not requesting commit-resumed for target native, no resumed threads^M (gdb) FAIL: gdb.base/ui-redirect.exp: debugging: continue [infrun] fetch_inferior_event: exit^M ... The problem is that proc gdb_test doesn't pass down the -prompt option to proc gdb_test_multiple, due to a typo making this lappend without effect: ... set opts {} lappend "-prompt $prompt" ... Fix this by actually appending to opts. Tested on x86_64-linux.
2022-05-23[gdb/exp] Fix UB in scalar_binopTom de Vries2-1/+6
When building gdb with -fsanitize=undefined, I run into: ... $ gdb -q -batch -ex "p -(-0x7fffffffffffffff - 1)" src/gdb/valarith.c:1385:10: runtime error: signed integer overflow: \ 0 - -9223372036854775808 cannot be represented in type 'long int' $1 = -9223372036854775808 ... Fix this by performing the substraction in scalar_binop using unsigned types. Tested on x86_64-linux.
2022-05-23[gdb/ada] Fix gdb.ada/dynamic-iface.exp with gcc 7Tom de Vries1-1/+2
This test in test-case gdb.ada/dynamic-iface.exp passes with gcc 8: ... (gdb) print obj^M $1 = (n => 3, a => "ABC", value => 93)^M (gdb) PASS: gdb.ada/dynamic-iface.exp: print local as interface ... but fails with gcc 7: ... (gdb) print obj^M $1 = ()^M (gdb) FAIL: gdb.ada/dynamic-iface.exp: print local as interface ... More concretely, we have trouble finding the type of obj. With gcc 8: ... $ gdb -q -batch main -ex "b concrete.adb:20" -ex run -ex "ptype obj" ... type = <ref> new concrete.intermediate with record value: integer; end record ... and with gcc 7: ... type = <ref> tagged record null; end record ... The translation from tagged type to "full view" type happens in ada_tag_value_at_base_address, where we hit this code: ... /* Storage_Offset'Last is used to indicate that a dynamic offset to top is used. In this situation the offset is stored just after the tag, in the object itself. */ if (offset_to_top == last) { struct value *tem = value_addr (tag); tem = value_ptradd (tem, 1); tem = value_cast (ptr_type, tem); offset_to_top = value_as_long (value_ind (tem)); } ... resulting in an offset_to_top for gcc 8: ... (gdb) p offset_to_top $1 = -16 ... and for gcc 7: ... (gdb) p offset_to_top $1 = 16 ... The difference is expected, it bisects to gcc commit d0567dc0dbf ("[multiple changes]") which mentions this change. There's some code right after the code quoted above that deals with this change: ... else if (offset_to_top > 0) { /* OFFSET_TO_TOP used to be a positive value to be subtracted from the base address. This was however incompatible with C++ dispatch table: C++ uses a *negative* value to *add* to the base address. Ada's convention has therefore been changed in GNAT 19.0w 20171023: since then, C++ and Ada use the same convention. Here, we support both cases by checking the sign of OFFSET_TO_TOP. */ offset_to_top = -offset_to_top; } ... but it's not activated because of the 'else'. Fix this by removing the 'else'. Tested on x86_64-linux, with gcc 7.5.0. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29057
2022-05-23[gdb/testsuite] Skip language auto in gdb.base/parse_number.expTom de Vries1-0/+5
In test-case gdb.base/parse_number.exp, we skip architecture auto in the $supported_archs loop, to prevent duplicate testing. Likewise, skip language auto and its alias local in the $::all_languages loop. This reduces the number of tests from 17744 to 15572. Tested on x86_64-linux, with a build with --enable-targets=all.
2022-05-22Accept functions with DW_AT_linkage_name presentAlok Kumar Sharma3-1/+115
Currently GDB is not able to debug (Binary generated with Clang) variables present in shared/private clause of OpenMP Task construct. Please note that LLVM debugger LLDB is able to debug. In case of OpenMP, compilers generate artificial functions which are not present in actual program. This is done to apply parallelism to block of code. For non-artifical functions, DW_AT_name attribute should contains the name exactly as present in actual program. (Ref# http://wiki.dwarfstd.org/index.php?title=Best_Practices) Since artificial functions are not present in actual program they not having DW_AT_name and having DW_AT_linkage_name instead should be fine. Currently GDB is invalidating any function not havnig DW_AT_name which is why it is not able to debug OpenMP (Clang). It should be fair to fallback to check DW_AT_linkage_name in case DW_AT_name is absent.
2022-05-20Rename base_breakpoint -> code_breakpointPedro Alves9-57/+57
Even after the previous patches reworking the inheritance of several breakpoint types, the present breakpoint hierarchy looks a bit surprising, as we have "breakpoint" as the superclass, and then "base_breakpoint" inherits from "breakpoint". Like so, simplified: breakpoint base_breakpoint ordinary_breakpoint internal_breakpoint momentary_breakpoint ada_catchpoint exception_catchpoint tracepoint watchpoint catchpoint exec_catchpoint ... The surprising part to me is having "base_breakpoint" being a subclass of "breakpoint". I'm just refering to naming here -- I mean, you'd expect that it would be the top level baseclass that would be called "base". Just flipping the names of breakpoint and base_breakpoint around wouldn't be super great for us, IMO, given we think of every type of *point as a breakpoint at the user visible level. E.g., "info breakpoints" shows watchpoints, tracepoints, etc. So it makes to call the top level class breakpoint. Instead, I propose renaming base_breakpoint to code_breakpoint. The previous patches made sure that all code breakpoints inherit from base_breakpoint, so it's fitting. Also, "code breakpoint" contrasts nicely with a watchpoint also being typically known as a "data breakpoint". After this commit, the resulting hierarchy looks like: breakpoint code_breakpoint ordinary_breakpoint internal_breakpoint momentary_breakpoint ada_catchpoint exception_catchpoint tracepoint watchpoint catchpoint exec_catchpoint ... ... which makes a lot more sense to me. I've left this patch as last in the series in case people want to bikeshed on the naming. "code" has a nice property that it's exactly as many letters as "base", so this patch didn't require any reindentation. :-) Change-Id: Id8dc06683a69fad80d88e674f65e826d6a4e3f66
2022-05-20Test "set multiple-symbols on" creating multiple breakpointsPedro Alves1-25/+75
To look for code paths that lead to create_breakpoints_sal creating multiple breakpoints, I ran the whole testsuite with this hack: --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8377,8 +8377,7 @@ create_breakpoints_sal (struct gdbarch *gdbarch, int from_tty, int enabled, int internal, unsigned flags) { - if (canonical->pre_expanded) - gdb_assert (canonical->lsals.size () == 1); + gdb_assert (canonical->lsals.size () == 1); surprisingly, the assert never failed... The way to get to create_breakpoints_sal with multiple lsals is to use "set multiple-symbols ask" and then select multiple options from the menu, like so: (gdb) set multiple-symbols ask (gdb) b overload1arg [0] cancel [1] all [2] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg() [3] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(char) [4] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(double) [5] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(float) [6] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(int) [7] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(long) [8] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(short) [9] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(signed char) [10] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned char) [11] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned int) [12] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned long) [13] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned short) > 2-3 Breakpoint 2 at 0x1532: file /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc, line 107. Breakpoint 3 at 0x154b: file /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc, line 110. warning: Multiple breakpoints were set. Use the "delete" command to delete unwanted breakpoints. ... which would trigger the assert. This commit makes gdb.cp/ovldbreak.exp test this scenario. It does that by making set_bp_overloaded take a list of expected created breakpoints rather than just one breakpoint. It converts the procedure to use gdb_test_multiple instead of send_gdb/gdb_expect along the way. Change-Id: Id87d1e08feb6670440d926f5344e5081f5e37c8e
2022-05-20Make sure momentary breakpoints are always thread-specificPedro Alves1-37/+46
This adds a new ctor to momentary_breakpoints with a few parameters that are always necessary for momentary breakpoints. In particular, I noticed that set_std_terminate_breakpoint doesn't make the breakpoint be thread specific, which looks like a bug to me. The point of that breakpoint is to intercept std::terminate calls that happen as result of the called thread throwing an exception that won't be caught by the dummy frame. If some other thread calls std::terminate, IMO, it's no different from some other thread calling exit/_exit, for example. Change-Id: Ifc5ff4a6d6e58b8c4854d00b86725382d38a1a02
2022-05-20Momentary breakpoints should have no breakpoint numberPedro Alves1-1/+0
Momentary breakpoints have no breakpoint number, their breakpoint number should be always 0, to avoid constantly incrementing (or decrementing) the internal breakpoint count. Indeed, set_momentary_breakpoint installs the created breakpoint without a number. However, momentary_breakpoint_from_master incorrectly gives an internal breakpoint number to the new breakpoint. This commit fixes that. Change-Id: Iedcae5432cdf232db9e9a6e1a646d358abd34f95
2022-05-20Add/tweak intro comments of struct breakpoint and several subclassesPedro Alves2-8/+17
This tweaks the intro comments of the following classes: internal_breakpoint momentary_breakpoint breakpoint base_breakpoint watchpoint catchpoint Change-Id: If6b31f51ebbb81705fbe5b8435f60ab2c88a98c8
2022-05-20Move add_location(sal) to base_breakpointPedro Alves5-37/+31
After the previous patches, only base_breakpoint subclasses use add_location(sal), so we can move it to base_breakpoint (a.k.a. base class for code breakpoints). This requires a few casts here and there, but always at spots where you can see from context what the breakpoint's type actually is. I inlined new_single_step_breakpoint into its only caller exactly for this reason. I did try to propagate more use of base_breakpoint to avoid casts, but that turned out unwieldy for this patch. Change-Id: I49d959322b0fdce5a88a216bb44730fc5dd7c6f8
2022-05-20Move common bits of catchpoint/exception_catchpoint to breakpoint's ctorPedro Alves3-19/+21
Move common bits of catchpoint and exception_catchpoint to breakpoint's ctor, to avoid duplicating code. Change-Id: I3a115180f4d496426522f1d89a3875026aea3cf2
2022-05-20Make catchpoint inherit breakpoint, eliminate init_raw_breakpointPedro Alves3-37/+7
struct catchpoint's ctor currently calls init_raw_breakpoint, which is a bit weird, as that ctor-like function takes a sal argument, but catchpoints don't have code locations. Instead, make struct catchpoint's ctor add the catchpoint's dummy location using add_dummy_location. init_raw_breakpoint uses add_location under the hood, and with a dummy sal it would ultimately use the breakpoint's gdbarch for the location's gdbarch, so replace the references to loc->gdbarch (which is now NULL) in syscall_catchpoint to references to the catchpoint's gdbarch. struct catchpoint's ctor was the last user of init_raw_breakpoint, so this commit eliminates the latter. Since catchpoint locations aren't code locations, make struct catchpoint inherit struct breakpoint instead of base_breakpoint. This let's us delete the tracepoint::re_set override too. Change-Id: Ib428bf71efb09fdaf399c56e4372b0f41d9c5869
2022-05-20Make breakpoint_address_bits look at the location kindPedro Alves2-37/+23
Software watchpoints allocate a special dummy location using software_watchpoint_add_no_memory_location, and then breakpoint_address_bits checks whether the location is that special location to decide whether the location has a meaninful address to print. Introduce a new bp_loc_software_watchpoint location kind, and make breakpoint_address_bits use bl_address_is_meaningful instead, which returns false for bp_loc_other, which is in accordance with we document for bp_location::address: /* (... snip ...) Valid for all types except bp_loc_other. */ CORE_ADDR address = 0; Rename software_watchpoint_add_no_memory_location to add_dummy_location, and simplify it. This will be used by catchpoints too in a following patch. Note that neither "info breakpoints" nor "maint info breakpoints" actually prints the addresses of watchpoints, but I think it would be useful to do so in "maint info breakpoints". This approach let's us implement that in the future. Change-Id: I50e398f66ef618c31ffa662da755eaba6295aed7
2022-05-20Make exception_catchpoint inherit base_breakpoint instead of catchpointPedro Alves1-6/+12
exception_catchpoint is really a code breakpoint, with locations set by sals, re-set like other code breakpoints, etc., so make it inherit base_breakpoint. This adds a bit of duplicated code to exception_catchpoint's ctor (copied from struct catchpoint's ctor), but it will be eliminated in a following patch. Change-Id: I9fbb2927491120e9744a4f5e5cb5e6870ca07009
2022-05-20Refactor momentary breakpoints, eliminate set_raw_breakpoint{,_without_location}Pedro Alves1-73/+24
This commit makes set_momentary_breakpoint allocate the breakpoint type without relying on set_raw_breakpoint, and similarly, momentary_breakpoint_from_master not rely on set_raw_breakpoint_without_location. This will let us convert init_raw_breakpoint to a ctor in a following patch. The comment about set_raw_breakpoint being used in gdbtk sources is stale. gdbtk no longer uses it. Change-Id: Ibbf77731e4b22e18ccebc1b5799bbec0aff28c8a
2022-05-20Refactor set_internal_breakpoint / internal_breakpoint ctorPedro Alves1-19/+18
This moves initialization of internal_breakpoint's breakpoint fields to internal_breakpoint's ctor, and stops using new_breakpoint_from_type for internal_breakpoint breakpoints. Change-Id: I898ed0565f47cb00e4429f1c6446e6f9a385a78d
2022-05-20Convert init_ada_exception_catchpoint to a ctorPedro Alves3-59/+49
Currently, init_ada_exception_catchpoint is defined in breakpoint.c, I presume so it can call the static describe_other_breakpoints function. I think this is a dependency inversion. init_ada_exception_catchpoint, being code specific to Ada catchpoints, should be in ada-lang.c, and describe_other_breakpoints, a core function, should be exported. And then, we can convert init_ada_exception_catchpoint to an ada_catchpoint ctor. Change-Id: I07695572dabc5a75d3d3740fd9b95db1529406a1
2022-05-20Make ada_catchpoint_location's owner ctor parameter be ada_catchpointPedro Alves1-16/+16
This commit changes ada_catchpoint_location's ctor from: ada_catchpoint_location (breakpoint *owner) to: ada_catchpoint_location (ada_catchpoint *owner) just to make the code better document intention. To do this, we need to move the ada_catchpoint_location type's definition to after ada_catchpoint is defined, otherwise the compiler doesn't know that ada_catchpoint is convertible to struct breakpoint. Change-Id: Id908b2e38bde30b262381e00c5637adb9bf0129d
2022-05-20init_breakpoint_sal -> base_breakpoint::base_breakpointPedro Alves2-122/+129
This converts init_breakpoint_sal to a base_breakpoint constructor. It removes a use of init_raw_breakpoint. To avoid manually adding a bunch of parameters to new_breakpoint_from_type, and manually passing them down to the constructors of a number of different base_breakpoint subclasses, make new_breakpoint_from_type a variable template function. Change-Id: I4cc24133ac4c292f547289ec782fc78e5bbe2510
2022-05-20Remove "internal" parameter from a couple functionsPedro Alves1-3/+3
None of init_breakpoint_sal, create_breakpoint_sal, and strace_marker_create_breakpoints_sal make use of their "internal" parameter, so remove it. Change-Id: I943f3bb44717ade7a7b7547edf8f3ff3c37da435
2022-05-20More breakpoint_ops parameter eliminationPedro Alves2-11/+8
Remove breakpoint_ops parameters from a few functions that don't need it. Change-Id: Ifcf5e1cc688184acbf5e19b8ea60138ebe63cf28
2022-05-20Make a few functions work with base_breakpoint instead of breakpointPedro Alves2-31/+8
This makes tracepoints inherit from base_breakpoint, since their locations are code locations. If we do that, then we can eliminate tracepoint::re_set and tracepoint::decode_location, as they are doing the same as the base_breakpoint implementations. With this, all breakpoint types created by new_breakpoint_from_type are code breakpoints, i.e., base_breakpoint subclasses, and thus we can make it return a base_breakpoint pointer. Finally, init_breakpoint_sal can take a base_breakpoint pointer as "self" pointer too. This will let us convert this function to a base_breakpoint ctor in a following patch. Change-Id: I3a4073ff1a4c865f525588095c18dc42b744cb54
2022-05-20ranged_breakpoint: move initialization to ctorPedro Alves1-8/+19
Move initialization of ranged_breakpoint's fields to its ctor. Change-Id: If7b842861f3cc6a429ea329d45598b5852283ba3
2022-05-20ranged_breakpoint: use install_breakpointPedro Alves1-12/+5
This commit replaces a chunk of code in break_range_command by an equivalent call to install_breakpoint. Change-Id: I31c06cabd36f5be91740aab029265f678aa78e35
2022-05-20ranged_breakpoint: don't use init_raw_breakpointPedro Alves1-1/+1
ranged_breakpoint's ctor already sets the breakpoint's type to bp_hardware_breakpoint. Since this is a "regular" breakpoint, b->pspace should remain NULL. Thus, the only thing init_raw_breakpoint is needed for, is to add the breakpoint's location. Do that directly. Change-Id: I1505de94c3919881c2b300437e2c0da9b05f76bd
2022-05-20Make structs breakpoint/base_breakpoint/catchpoint be abstractPedro Alves2-1/+20
You should never instanciate these types directly. Change-Id: I8086c74c415eadbd44924bb0ef20f34b5b97ee6f
2022-05-20add_location_to_breakpoint -> breakpoint::add_locationPedro Alves2-37/+36
Make add_location_to_breakpoint be a method of struct breakpoint. A patch later in the series will move this to base_breakpoint, but for now, it needs to be here. Change-Id: I5bdc2ec1a7c2d66f26f51bf6f6adc8384a90b129
2022-05-20PowerPC: Make test gdb.arch/powerpc-power10.exp Endian independent.Carl Love1-368/+746
The .quad statement stores the 64-bit hex value in Endian order. When used to store a 64-bit prefix instructions on Big Endian (BE) systems, the .quad statement stores the 32-bit suffix followed by the 32-bit prefix rather than the expected order of prefix word followed by the suffix word. GDB fetches 32-bits at a time when disassembling instructions. The disassembly on BE gets messed up since GDB fetches the suffix first and interprets it as a word instruction not a prefixed instruction. When gdb fetches the prefix part of the instruction, following the initial suffix word, gdb associates the prefix word incorrectly with the following 32-bits as the suffix for the instruction when in fact it is the following instruction. For example on BE we have two prefixed instructions stored using the .quad statement as follows: addr word GDB action --------------------------------------------- 1 suffix inst A <- GDB interprets as a word instruction 2 prefix inst A <- GDB uses this prefix with 3 suffix inst B <- this suffix rather than the suffix at addr 1. 4 prefix inst B This patch changes the .quad statement into two .longs to explicitly store the prefix followed by the suffix of the instruction. The patch rearranges the instructions to put all of the word instructions together followed by the prefix instructions for clarity. The patch has been tested on Power 10 and Power 7 BE and LE to verify the change works as expected.
2022-05-20Remove obsolete text from documentationTom Tromey1-3/+0
The documentation says that -enable-pretty-printing is experimental in 7.0 and may change -- that's long enough ago that I think we can say that this text is no longer correct or useful.
2022-05-20Fix non-pointer type compilation error in aix-thread.cAditya Vidyadhar Kamath1-2/+2
In aix-thread.c we use ms->value_address () to get the symbol address. This triggers the following compiler error... base operand of '->' has non-pointer type 'bound_minimal_symbol' ... because ms is not a pointer. This commit fixes this error by using ms.value_address () instead.
2022-05-19gdb/doc: use @value{GDBP} in 'info pretty-printer' exampleAndrew Burgess1-8/+8
Update the 'info pretty-printer' example in the manual to make use of @value{GDBP} instead of hard-coding '(gdb)'.
2022-05-19gdb/doc: make use of group/end group in 'info pretty-printers' exampleAndrew Burgess1-0/+10
The 'info pretty-printers' example is pretty long and consists of many commands and their output. Currently, when the pdf manual is generated this example spans a page-break, with the page-break falling part way through some example output from GDB. This commit breaks up the example using @group .... @end group, within each group is a single GDB command and all its output. Now, when the pdf manual is created, the page-break is placed after the output of one GDB command, and before the subsequent command, this looks much nicer.
2022-05-19gdb/doc: fix inconsistent info pretty-printer exampleNikolaos Chatzikonstantinou1-3/+1
The example for 'info pretty-printer' in the manual passes an object-regexp in some cases, but presents output as though no object-regexp was passed. This commit fixes the two mistakes, in one case, fixing the output to filter based on object-regexp, and in the other, to remove the object-regexp from the command and leave all the output.