aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2020-11-02Fix gdb.base/print-file-var.exp with ClangGary Benson2-8/+16
The C++ parts of gdb.base/print-file-var.exp failed to build with Clang because the "-x c++" option added by gdb_compile caused the compiler to attempt to parse .so files as C++. This commit splits the compiler and linker options into separate lists, and switches to building via build_executable_from_specs which can accommodate this separation. gdb/testsuite/ChangeLog: * gdb.base/print-file-var.exp (test): Separate compiler and linker options, and build using build_executable_from_specs to accommodate this.
2020-11-02Detect and report incompatible gdb_compile optionsGary Benson2-3/+20
In commits 221db974e653659edb280787af1b3efdd1615083 and 68d654afdfcff840ebb3ae432ed72dca0521d670, these patches: 2020-06-24 Pedro Alves <palves@redhat.com> * lib/gdb.exp (gdb_compile): Pass "-x c++" explicitly when compiling C++ programs. 2020-09-25 Gary Benson <gbenson@redhat.com> * lib/gdb.exp (gdb_compile): Pass "-x c++" earlier, and only for .c files. attempted to fix problems with testcases that compile .c files using the C++ compiler. These patches cause gdb_compile to add "-x c++" to the compiler options when using Clang. This fix does not work for gdb.base/print-file-var.exp, however, which attempts to compile a .c input file to an executable linked with shared libraries: the resulting command caused the compiler to attempt to parse the .so files as C++. This commit causes gdb_compile to reject this combination of options. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_compile): Inhibit passing "-x c++" for .c files compiled as C++ with Clang if any shared libraries are specified.
2020-11-02Fix testcases using __attribute__((noclone)) with ClangGary Benson5-36/+89
Clang fails to compile a number of files with the following warning: unknown attribute 'noclone' ignored [-Wunknown-attributes]. This commit adds a new header, lib/noclone.h, which defines the macro ATTRIBUTE_NOCLONE accordingly, and updates the relevant testcases to use it. gdb/testsuite/ChangeLog: * lib/attributes.h: New header. * gdb.base/backtrace.c: Include the above. Replace __attribute__(noclone)) with ATTRIBUTE_NOCLONE. * gdb.base/infcall-nested-structs.c: Likewise. * gdb.base/vla-optimized-out.c: Likewise.
2020-11-02[gdb/testsuite] Remove .debug_line.dwo from gdb.dwarf2/fission-multi-cu.STom de Vries2-14/+4
Consider test-case gdb.dwarf2/fission-multi-cu.exp. It produces an executable fission-multi-cu and a dwo file fission-multi-cu.dwo. The file fission-multi-cu.dwo contains a .debug_line.dwo section, which according to the DWARF v5 standard is a "specialized line number table" for type units in the .debug_info.dwo section, and contains only the directory and filename lists. When reading the actual .debug_line.dwo section using readelf -w, we get: ... The Directory Table is empty. The File Name Table is empty. No Line Number Statements. ... So, the section does not contain any actual information. Furthermore, no information is required because the .debug_line.dwo section does not contain any type units. This is confirmed by: - re-doing the commands listed at the start of fission-multi-cu.S, which were used as starting point for fission-multi-cu.S, and - compiling the fission-multi-cu{1,2}.c files with clang -flto -g -gsplit-dwarf In both cases, no .debug_line.dwo section is generated. Remove the .debug_line.dwo section, to make it fit how split dwarf is actually generated by clang. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-11-02 Tom de Vries <tdevries@suse.de> * gdb.dwarf2/fission-multi-cu.S: Remove .debug_line.dwo section.
2020-11-02gdb/riscv: read frame base register as unsigned in the unwinderAndrew Burgess2-1/+7
I noticed an issue with the RISC-V prologue scanning stack unwinder. We currently read the frame base register (either $sp or $fp) as a signed value. This means that the frame_id's stack_addr field will be a signed value. In other contexts though these registers are data pointers, and so are unsigned. There's not many places where this mismatch actually shows though, but I did find one place. Consider this GDB session: (gdb) maintenance set dwarf unwinders off (gdb) set backtrace past-main on ... (gdb) b main Breakpoint 1 at 0x20400344: file main.c, line 86. (gdb) run ... (gdb) bt #0 main () at main.c:86 #1 0x2040005c in _start () at start.S:59 Backtrace stopped: frame did not save the PC (gdb) info frame 1 Stack frame at 0x80000a1c: pc = 0x2040005c in _start (start.S:59); saved pc = <not saved> Outermost frame: frame did not save the PC caller of frame at 0x80000a1c source language asm. Arglist at 0x80000a1c, args: Locals at 0x80000a1c, Previous frame's sp is 0x80000a1c (gdb) frame address 0x80000a1c No frame at address 0x80000a1c. (gdb) frame address 0xffffffff80000a1c #1 0x2040005c in _start () at start.S:59 59 call main Notice that the 'info frame 1' reports that the frame is at '0x80000a1c', this is the unsigned frame base value, but when I try to select a frame using this address I can't. The reason is that the frame_id for frame #1 actually has the unsigned (and hence sign-extended) stack_addr value. When I use the sign extended address I can correctly select the frame. I propose changing the prologue scanning unwinder to read the frame base as unsigned. After this in the above case I can now do this: (gdb) frame address 0x80000a1c #1 0x2040005c in _start () at start.S:59 59 call main (gdb) frame address 0xffffffff80000a1c No frame at address 0xffffffff80000a1c. Which I think makes more sense. This issue causes failures in gdb.base/frame-selection.exp if you compile for RV32 with a linker script that places the stack in the correct location, which are resolved by this patch. gdb/ChangeLog: * riscv-tdep.c (riscv_frame_cache): Read the frame base register as an unsigned value.
2020-11-01Change end_psymtab_common to a methodTom Tromey7-24/+33
This changes end_psymtab_common to be a method on partial_symtab. This seems a little cleaner to me. gdb/ChangeLog 2020-11-01 Tom Tromey <tom@tromey.com> * dbxread.c (dbx_end_psymtab): Update. * dwarf2/read.c (process_psymtab_comp_unit_reader) (build_type_psymtabs_reader): Update. * xcoffread.c (xcoff_end_psymtab): Update. * ctfread.c (scan_partial_symbols): Update. * psymtab.c (sort_pst_symbols): Remove. (partial_symtab::end): Rename from end_psymtab_common. Inline sort_pst_symbols. * psympriv.h (struct partial_symtab) <end>: New method. (end_psymtab_common): Don't declare.
2020-11-01Remove partial symbol statisticsTom Tromey4-17/+28
The "n_psyms" statistic in the per-objfile stats is not really needed, but its use requires passing the objfile to add_psymbol. This patch removes the field in favor of counting the psyms when needed. Note that this is not exactly equivalent -- in the old approach, a psymbol can in theory be created and then the psymtab discarded, which would increment the counter. This does not seem very important to me. I rewrote the code to count partial symbols; though TBH I think that this information is not really very useful. gdb/ChangeLog 2020-11-01 Tom Tromey <tom@tromey.com> * symmisc.c (count_psyms): New function. (print_objfile_statistics): Use it. * psymtab.c (append_psymbol_to_list): Remove. (partial_symtab::add_psymbol): Inline append_psymbol_to_list. * objfiles.h (struct objstats) <n_psyms>: Remove.
2020-11-01Remove parameter from end_psymtab_commonTom Tromey7-10/+20
The objfile parameter to end_psymtab_common is no longer needed, so this removes it. gdb/ChangeLog 2020-11-01 Tom Tromey <tom@tromey.com> * dbxread.c (dbx_end_psymtab): Update. * dwarf2/read.c (process_psymtab_comp_unit_reader): Update. (build_type_psymtabs_reader): Update. * xcoffread.c (xcoff_end_psymtab): Update. * ctfread.c (scan_partial_symbols): Update. * psympriv.h (end_psymtab_common): Update. * psymtab.c (end_psymtab_common): Remove objfile parameter. (sort_pst_symbols): Likewise.
2020-11-01Remove init_psymbol_listTom Tromey6-24/+8
init_psymbol_list is now empty, and so this removes it. gdb/ChangeLog 2020-11-01 Tom Tromey <tom@tromey.com> * dbxread.c (dbx_symfile_read): Update. * dwarf2/read.c (dwarf2_build_psymtabs): Update. * xcoffread.c (xcoff_initial_scan): Update. * psympriv.h (init_psymbol_list): Don't declare. * psymtab.c (init_psymbol_list): Remove.
2020-11-01avoid unwarranted assumption in gdb.ada/fixed_points/fixed_points.adbJoel Brobecker2-2/+7
The test program being used declares a fixed-point type (Base_Fixed_Point_Type) Base_Fixed_Point_Type whose (scaled) range is System.Min_Int .. System.Max_Int. is an unwarranted assumption because the range is implementation-defined. It means the compiler is therefore free to reject that declaration. We noticed this while one of my coworkers was working on enhancing GNAT to support 128bit integers. The bulk of the work has been done, but one side-effect is that there is a small gap in this particular area where the compiler is now rejecting this code. We will eventually plug that gap, but in meantime, since the testcase itself doesn't really need such a large range, this commit simply adjusts the test program to use hard-coded bounds for the range whose value are more reasonable. gdb/testsuite/ChangeLog: * gdb.ada/fixed_points/fixed_points.adb: Replace use of System.Min_Int and System.Max_Int with smaller hardcoded constants.
2020-11-01ada-lang.c: Rename gnat_encoded_fixed_type_infoJoel Brobecker2-5/+10
This commit renames gnat_encoded_fixed_type_info into gnat_encoded_fixed_point_type_info, so as to be more consistent with the naming used for the other associated routines (i.e. use "fixed_point" rather than just "fixed"). gdb/ChangeLog: * ada-lang.c (gnat_encoded_fixed_point_type_info): Renames gnat_encoded_fixed_type_info. Update all callers.
2020-11-01ada-lang.c: fix line too long in cast_from_gnat_encoded_fixed_point_typeJoel Brobecker2-1/+7
One of the lines got too long after a renaming done in a previous commit. This fixes that. gdb/ChangeLog: * ada-lang.c (cast_from_gnat_encoded_fixed_point_type): Split line too long.
2020-11-01ada-lang.c: Renaming some fixed-point-related routinesJoel Brobecker5-14/+28
This patch renames some of the fixed-point-related subprograms in ada-lang.c so as to make it obvious that those routines only handle the case where the types are encoded using the GNAT encoding. No function change; this patch is preparation work for adding support for fixed-point types purely based on standard DWARF debug info. gdb/ChangeLog: * ada-lang.c (cast_from_gnat_encoded_fixed_point_type): Renames cast_from_fixed. Update all callers. (cast_to_gnat_encoded_fixed_point_type): Renames cast_to_fixed. Update all callers. (gnat_encoded_fixed_point_scaling_factor): Renames ada_scaling_factor. Update all callers. * ada-lang.h (gnat_encoded_fixed_point_scaling_factor): Renames ada_scaling_factor. * ada-typeprint.c: Replace call to ada_scaling_factor by call to print_gnat_encoded_fixed_point_type. * ada-valprint.c: Likewise.
2020-10-31gdb: restore some checks of debug flagsAndrew Burgess3-3/+25
This partially reverts some parts of the commit: commit 17417fb0ec9842de1774e1e76f1f11c00cdafc47 Date: Sat Oct 31 09:01:25 2020 -0400 gdb, gdbsupport: add debug_prefixed_printf, remove boilerplate functions This commit removed 3 places where some debug flags were being checked. The result was that debug tracing was being printed unconditionally. This commit adds back the 3 flag checks. gdb/ChangeLog: * infrun.h (infrun_debug_printf): Add check of debug_infrun flag. (debug_prefixed_printf): Add check of debug_displaced flag. * linux-nat.c (linux_nat_debug_printf): Add check of debug_linux_nat flag.
2020-10-31gdb, gdbsupport: add debug_prefixed_printf, remove boilerplate functionsSimon Marchi4-60/+20
The *_debug_print_1 functions are all very similar, the only difference being the subsystem name. Remove them all and make the logging macros use a new debug_prefixed_printf function directly. gdb/ChangeLog: * infrun.c (infrun_debug_printf_1): Remove. (displaced_debug_printf_1): Remove. (stop_all_threads): Use debug_prefixed_printf. * infrun.h (infrun_debug_printf_1): Remove. (infrun_debug_printf): Use debug_prefixed_printf. (displaced_debug_printf_1): Remove. (displaced_debug_printf): Use debug_prefixed_printf. * linux-nat.c (linux_nat_debug_printf_1): Remove. (linux_nat_debug_printf): Use debug_prefixed_printf. gdbsupport/ChangeLog: * common-debug.cc (debug_prefixed_printf): New. * common-debug.h (debug_prefixed_printf): New declaration. * event-loop.cc (event_loop_debug_printf_1): Remove. * event-loop.h (event_loop_debug_printf_1): Remove. (event_loop_debug_printf): Use debug_prefixed_printf. (event_loop_ui_debug_printf): Use debug_prefixed_printf. Change-Id: Ib323087c7257f0060121d302055c41eb64aa60c6
2020-10-31gdb: replace AC_TRY_LINK in sanitize.m4Simon Marchi3-1/+12
... with AC_LINK_IFELSE + AC_LANG_PROGRAM. All changes in the generated configure file are insignificant whitespace changes. gdb/ChangeLog: * configure: Re-generate. * sanitize.m4: Replace AC_TRY_LINK with AC_LINK_IFELSE + AC_LANG_PROGRAM. Change-Id: I6fc4c39e10b28d2ade964e0d59a7f8ec0d3a272a
2020-10-31gdbsupport: replace AC_TRY_COMPILE in common.m4Simon Marchi2-4/+11
... with AC_COMPILE_IFELSE + AC_LANG_PROGRAM. All the changes in the generated configure files are insignificant whitespace changes. gdb/ChangeLog: * configure: Re-generate. gdbserver/ChangeLog: * configure: Re-generate. gdbsupport/ChangeLog: * common.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE + AC_LANG_PROGRAM. * configure: Re-generate. Change-Id: Id58e6e887f6be817d52b189921845838031dbd2a
2020-10-31gdbsupport: replace AC_TRY_COMPILE in warning.m4Simon Marchi2-3/+8
Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE + AC_LANG_PROGRAM. All changes in generated configure files are insignificant whitespace changes. gdb/ChangeLog: * configure: Re-generate. gdbserver/ChangeLog: * configure: Re-generate. gdbsupport/ChangeLog: * configure: Re-generate. * warning.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE + AC_LANG_PROGRAM. Change-Id: I517bd20ec3af960ad999a586761df0ac8959a3fc
2020-10-31gdbsupport: replace AC_TRY_COMPILE in ptrace.m4Simon Marchi2-1/+10
Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE + AC_LANG_PROGRAM. All the changes in the generated configure files are insignificant whitespace changes. gdb/ChangeLog: * configure: Re-generate. gdbserver/ChangeLog: * configure: Re-generate. gdbsupport/ChangeLog: * configure: Re-generate. * ptrace.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE + AC_LANG_PROGRAM. Change-Id: Ia782b5477fe49dad04e68c0f41c6d8ab3fde5bf0
2020-10-31gdbsupport: re-indent ptrace.m4Simon Marchi2-27/+32
For some reason, autoupdate isn't able to grok ptrace.m4: $ autoupdate ptrace.m4 /usr/bin/m4:/tmp/auYjuodw/input.m4:171: ERROR: end of file in string autoupdate: /usr/bin/m4 failed with exit status: 1 Honestly, I'm unable to grok it either. This patch re-indents it in a way that I think is easier to read. With this patch applied, autoupdate becomes able to parse ptrace.m4, but I chose to keep this re-indent in a patch of its own. All the changes in generated configure files consist of insignificant whitespace changes. gdb/ChangeLog: * configure: Re-generate. gdbserver/ChangeLog: * configure: Re-generate. gdbsupport/ChangeLog: * configure: Re-generate. * ptrace.m4: Re-indent. Change-Id: Ie2afab09fecc8b6d0cccccb47ac9756f3843881e
2020-10-31gdb: modernize acinclude.m4Simon Marchi3-22/+47
Run autoupdate, fix indentation for readability. gdb/ChangeLog: * acinclude.m4: Modernize. * configure: Re-generate. Change-Id: I8949f885326a3206f414776b63a1fdba197bb19a
2020-10-31gdb/testsuite: modernize configure.acSimon Marchi3-1/+8
Run autoupdate, the only change is to split AC_INIT into AC_INIT and AC_CONFIG_SRCDIR. gdb/testsuite/ChangeLog: * configure.ac: Split AC_INIT into AC_INIT and AC_CONFIG_SRCDIR. * configure: Re-generate. Change-Id: I6e40c0261bda4fe9144b896799ef460d23e22e09
2020-10-31gdb: modernize configure.acSimon Marchi3-173/+316
Run autoupdate on configure.ac and adjust the indentation of the result for better readability. This removes a bunch of warnings when running `autoreconf -vf -Wall`. The changes are: * Replace AC_INIT with AC_INIT and no arguments plus AC_CONFIG_SRCDIR. * Replace AC_ERROR with AC_MSG_ERROR. * Replace AC_TRY_LINK with AC_LINK_IFELSE. * Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE. * Replace AC_HELP_STRING with AS_HELP_STRING. autoupdate erroneously tries to replace AC_C_LONG_DOUBLE in a comment, which I reverted manually. All the changes in the generated configure file are insignificant whitespaces changes. gdb/ChangeLog: * configure.ac: Modernize. * configure: Re-generate. Change-Id: Ie3a1409c8032a36a6383da964286a46ece9b546e
2020-10-31gdb: use AC_PROG_CC_STDC instead of AM_PROG_CC_STDCSimon Marchi4-191/+6
`autoconf -Wall` notes that AM_PROG_CC_STDC is obsolete: Fixes this autoconf warning: configure.ac:40: warning: 'AM_PROG_CC_STDC': this macro is obsolete. configure.ac:40: You should simply use the 'AC_PROG_CC' macro instead. configure.ac:40: Also, your code should no longer depend upon 'am_cv_prog_cc_stdc', configure.ac:40: but upon 'ac_cv_prog_cc_stdc'. aclocal.m4:770: AM_PROG_CC_STDC is expanded from... configure.ac:40: the top level Since we build with a C++ compiler now, I don't think this is relevant. If you look at the messages removed from gdbsupport/aclocal.m4, it says that this functionality is now integrated in AC_PROG_CC, which we already call. So it might not even make a difference. We had a local version of AM_PROG_CC_STDC, in gdb/acinclude.m4 (only used by gdb/configure.ac), remove it. gdb/ChangeLog: * acinclude.m4 (AM_PROG_CC_STDC): Remove. * configure: Re-generate. * configure.ac: Remove AM_PROG_CC_STDC. gdbsupport/ChangeLog: * aclocal.m4: Re-generate. * configure: Re-generate. * configure.ac: Remove AM_PROG_CC_STDC. Change-Id: Ic824393598805d4f78cda9d119f8af46096e9c73
2020-10-31gdb, gdbserver, gdbsupport: use AC_CANONICAL_{BUILD,HOST,TARGET} instead of ↵Simon Marchi3-1/+25
AC_CANONICAL_SYSTEM `autoreconf -Wall` notes that AC_CANONICAL_SYSTEM is obsolete: configure.ac:36: warning: The macro `AC_CANONICAL_SYSTEM' is obsolete. Replace it by AC_CANONICAL_BUILD, AC_CANONICAL_HOST and AC_CANONICAL_TARGET in configure.ac files in gdb, gdbserver and gdbsupport. All three macros may not be needed everywhere, but it is hard to completely audit the configure files to see which are required, so I think it's better (and that there's no downside) to just call all three. gdb/ChangeLog: * configure.ac: Use AC_CANONICAL_{BUILD,HOST,TARGET} instead of AC_CANONICAL_SYSTEM. * configure: Re-generate. gdbserver/ChangeLog: * configure.ac: Use AC_CANONICAL_{BUILD,HOST,TARGET} instead of AC_CANONICAL_SYSTEM. * configure: Re-generate. gdbsupport/ChangeLog: * configure.ac: Use AC_CANONICAL_{BUILD,HOST,TARGET} instead of AC_CANONICAL_SYSTEM. * configure: Re-generate. Change-Id: Ifd0e21f1e478634e768b5de1b8ee06a7f690d863
2020-10-30gdb: introduce displaced_debug_printfSimon Marchi12-460/+311
Move all debug prints of the "displaced" category to use a new displaced_debug_printf macro, like what was done for infrun and others earlier. The debug output for one displaced step one amd64 looks like: [displaced] displaced_step_prepare_throw: stepping process 3367044 now [displaced] displaced_step_prepare_throw: saved 0x555555555042: 1e fa 31 ed 49 89 d1 5e 48 89 e2 48 83 e4 f0 50 [displaced] amd64_displaced_step_copy_insn: copy 0x555555555131->0x555555555042: b8 00 00 00 00 5d c3 0f 1f 84 00 00 00 00 00 f3 [displaced] displaced_step_prepare_throw: displaced pc to 0x555555555042 [displaced] resume_1: run 0x555555555042: b8 00 00 00 [displaced] displaced_step_restore: restored process 3367044 0x555555555042 [displaced] amd64_displaced_step_fixup: fixup (0x555555555131, 0x555555555042), insn = 0xb8 0x00 ... [displaced] amd64_displaced_step_fixup: relocated %rip from 0x555555555047 to 0x555555555136 On test case needed to be updated because it relied on the specific formatting of the message. gdb/ChangeLog: * infrun.h (displaced_debug_printf): New macro. Replace displaced debug prints throughout to use it. (displaced_debug_printf_1): New declaration. (displaced_step_dump_bytes): Return string, remove ui_file parameter, update all callers. * infrun.c (displaced_debug_printf_1): New function. (displaced_step_dump_bytes): Return string, remove ui_file parameter gdb/testsuite/ChangeLog: * gdb.arch/amd64-disp-step-avx.exp: Update displaced step debug expected output. Change-Id: Ie78837f56431f6f98378790ba1e6051337bf6533
2020-10-30gdb: rs6000_dwarf2_reg_to_regnum return -1 for unknown register numberSimon Marchi2-2/+7
With the current implementation of rs6000_dwarf2_reg_to_regnum, if an unknown DWARF register number is passed, the same number is returned as the internal GDB number. This assumes that the internal GDB register numbers match the DWARF register numbers, which is not the case. Change it to return -1, as documented in gdbarch.sh for the dwarf2_reg_to_regnum method. This fixes a failure in gdb.dwarf2/bad-regnum.exp: (gdb) info addr foo1 -Symbol "foo1" is a variable in $. -(gdb) FAIL: gdb.dwarf2/bad-regnum.exp: info addr foo1 +Symbol "foo1" is a variable in $bad_register_number. +(gdb) PASS: gdb.dwarf2/bad-regnum.exp: info addr foo1 I ran the entire testsuite on powerpc64 (gcc203 on the compile farm) and didn't see any regression. gdb/ChangeLog: * rs6000-tdep.c (rs6000_dwarf2_reg_to_regnum): Return -1 for unknown register numbers. Change-Id: I585aa07a08f845a46c36bfdb6d3118ea94f8f54d
2020-10-30Have stamp-init depend on config.statusTom Tromey2-1/+5
I recently wrote a patch to modify configure.tgt. However, I did this incorrectly the first time, and had to go back and add another file. After building, I was surprised that my changes did not seem to work. I tracked this down to the fact that init.c had not been rebuilt after my changes -- because the files I added to the build were already older than the existing init.c. This patch changes the gdb Makefile so that init.c will be rebuilt if config.status changes. This should cover various scenarios that cause a re-configure, like editing configure.tgt. 2020-10-30 Tom Tromey <tromey@adacore.com> * Makefile.in (stamp-init): Depend on config.status.
2020-10-30gdb/infrun: disable pagination in fetch_inferior_eventTankut Baris Aktemur8-264/+40
Having pagination enabled when handling an inferior event gives the user an option to quit, which causes early exit in GDB's flow and may lead to half-baked state. For instance, here is a case where we quit in the middle of handling an inferior exit: $ gdb ./a.out Reading symbols from ./a.out... (gdb) set height 2 (gdb) run Starting program: ./a.out --Type <RET> for more, q to quit, c to continue without paging--q Quit Couldn't get registers: No such process. (gdb) set height unlimited Couldn't get registers: No such process. (gdb) info threads Id Target Id Frame * 1 process 27098 Couldn't get registers: No such process. Couldn't get registers: No such process. (gdb) Or suppose having a multi-threaded program like below: static void * fun (void *dummy) { int a = 1; /* break-here */ return NULL; } int main (void) { pthread_t thread; pthread_create (&thread, NULL, fun, NULL); pthread_join (thread, NULL); return 0; } If we define a breakpoint at line "break-here", we expect only Thread 2 to hit it. $ gdb ./a.out Reading symbols from ./a.out... (gdb) break 7 Breakpoint 1 at 0x1182: file mt.c, line 7. (gdb) set height 2 (gdb) run Starting program: ./a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff77c4700 (LWP 23048)] --Type <RET> for more, q to quit, c to continue without paging--q Quit (gdb) set height unlimited (gdb) info thread Id Target Id Frame * 1 Thread 0x7ffff7fe3740 (LWP 23044) "a.out" 0x00007ffff7bbed2d in ... 2 Thread 0x7ffff77c4700 (LWP 23048) "a.out" fun (dummy=0x0) at mt.c:7 (gdb) The prompt for continuation was triggered because Thread 2 hit the breakpoint. (If we had hit 'c', we were going to see that stop event, but we didn't.) The context did not switch to Thread 2. GDB also did not execute several other things it would normally do in infrun.c:normal_stop after outputting "[Switching to Thread ...]" (but it seems harmless in this case). If we 'continue' at this state, both threads run until termination, and we don't see the breakpoint hit event ever. Here is another related and more complicated scenario that leads to a GDB crash. Create two inferiors, one sitting on top of a native target, and the other on a remote target, so that we have a multi-target setting, like so: (gdb) i inferiors Num Description Connection Executable 1 process 13786 1 (native) a.out * 2 process 13806 2 (remote ...) target:a.out Next, resume both inferiors to run until termination: (gdb) set schedule-multiple on (gdb) set height 2 (gdb) continue Continuing. --Type <RET> for more, q to quit, c to continue without paging--[Inferior 2 (process 13806) exited normally] terminate called after throwing an instance of 'gdb_exception_error' Aborted Here, GDB first received a termination event from Inferior 1. GDB attempted to print this event, triggering a "prompt for continue", and GDB started polling for events, hoping to get an input from the user. However, the exit event from Inferior 2 was received instead. So, GDB started processing an exit event while being in the middle of processing another exit event. It was not ready for this situation and eventually crashed. To address these cases, temporarily disable pagination in fetch_inferior_event. This doesn't affect commands like 'info threads', 'backtrace', or 'thread apply'. Regression-tested on X86_64 Linux. gdb/ChangeLog: 2020-10-30 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * infrun.c (fetch_inferior_event): Temporarily disable pagination. gdb/testsuite/ChangeLog: 2020-10-30 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.base/paginate-after-ctrl-c-running.exp: Update with no pagination behavior. * gdb.base/paginate-bg-execution.exp: Ditto. * gdb.base/paginate-inferior-exit.exp: Ditto. * gdb.base/double-prompt-target-event-error.c: Remove. * gdb.base/double-prompt-target-event-error.exp: Remove.
2020-10-30Move lookup_selected_frame to frame.cPedro Alves3-63/+71
This function is now external, and isn't really threads related. Move it to frame.c. gdb/ChangeLog: * thread.c (lookup_selected_frame): Move ... * frame.c (lookup_selected_frame): ... here. Change-Id: Ia96b79c15767337c68efd3358bcc715ce8e26c15
2020-10-30Make scoped_restore_current_thread's cdtors exception free (RFC)Pedro Alves8-124/+206
If the remote target closes while we're reading registers/memory for restoring the selected frame in scoped_restore_current_thread's dtor, the corresponding TARGET_CLOSE_ERROR error is swallowed by the scoped_restore_current_thread's dtor, because letting exceptions escape from a dtor is bad. It isn't great to lose that errors like that, though. I've been thinking about how to avoid it, and I came up with this patch. The idea here is to make scoped_restore_current_thread's dtor do as little as possible, to avoid any work that might throw in the first place. And to do that, instead of having the dtor call restore_selected_frame, which re-finds the previously selected frame, just record the frame_id/level of the desired selected frame, and have get_selected_frame find the frame the next time it is called. In effect, this implements most of Cagney's suggestion, here: /* On demand, create the selected frame and then return it. If the selected frame can not be created, this function prints then throws an error. When MESSAGE is non-NULL, use it for the error message, otherwize use a generic error message. */ /* FIXME: cagney/2002-11-28: At present, when there is no selected frame, this function always returns the current (inner most) frame. It should instead, when a thread has previously had its frame selected (but not resumed) and the frame cache invalidated, find and then return that thread's previously selected frame. */ extern struct frame_info *get_selected_frame (const char *message); The only thing missing to fully implement that would be to make reinit_frame_cache just clear selected_frame instead of calling select_frame(NULL), and the call select_frame(NULL) explicitly in the places where we really wanted reinit_frame_cache to go back to the current frame too. That can done separately, though, I'm not proposing to do that in this patch. Note that this patch renames restore_selected_frame to lookup_selected_frame, and adds a new restore_selected_frame function that doesn't throw, to be paired with the also-new save_selected_frame function. There's a restore_selected_frame function in infrun.c that I think can be replaced by the new one in frame.c. Also done in this patch is make the get_selected_frame's parameter be optional, so that we don't have to pass down nullptr explicitly all over the place. lookup_selected_frame should really move from thread.c to frame.c, but I didn't do that here, just to avoid churn in the patch while it collects comments. I did make it extern and declared it in frame.h already, preparing for the move. I will do the move as a follow up patch if people agree with this approach. Incidentally, this patch alone would fix the crashes fixed by the previous patches in the series, because with this, scoped_restore_current_thread's constructor doesn't throw either. gdb/ChangeLog: * blockframe.c (block_innermost_frame): Use get_selected_frame. * frame.c (scoped_restore_selected_frame::scoped_restore_selected_frame): Use save_selected_frame. Save language as well. (scoped_restore_selected_frame::~scoped_restore_selected_frame): Use restore_selected_frame, and restore language as well. (selected_frame_id, selected_frame_level): New. (selected_frame): Update comments. (save_selected_frame, restore_selected_frame): New. (get_selected_frame): Use lookup_selected_frame. (get_selected_frame_if_set): Delete. (select_frame): Record selected_frame_level and selected_frame_id. * frame.h (scoped_restore_selected_frame) <m_level, m_lang>: New fields. (get_selected_frame): Make 'message' parameter optional. (get_selected_frame_if_set): Delete declaration. (select_frame): Update comments. (save_selected_frame, restore_selected_frame) (lookup_selected_frame): Declare. * gdbthread.h (scoped_restore_current_thread) <m_lang>: New field. * infrun.c (struct infcall_control_state) <selected_frame_level>: New field. (save_infcall_control_state): Use save_selected_frame. (restore_selected_frame): Delete. (restore_infcall_control_state): Use restore_selected_frame. * stack.c (select_frame_command_core, frame_command_core): Use get_selected_frame. * thread.c (restore_selected_frame): Rename to ... (lookup_selected_frame): ... this and make extern. Select the current frame if the frame level is -1. (scoped_restore_current_thread::restore): Also restore the language. (scoped_restore_current_thread::~scoped_restore_current_thread): Don't try/catch. (scoped_restore_current_thread::scoped_restore_current_thread): Save the language as well. Use save_selected_frame. Change-Id: I73fd1cfc40d8513c28e5596383b7ecd8bcfe700f
2020-10-29gdb: fix documentation of gdbarch_displaced_step_hw_singlestepSimon Marchi3-17/+21
The last commit missed updating the doc of gdbarch_displaced_step_hw_singlestep to avoid mentioning the removed parameter, this one fixes it. gdb/ChangeLog: * gdbarch.sh (displaced_step_hw_singlestep): Adjust documentation. * gdbarch.h: Re-generate. Change-Id: I33675d9a6c253443eee707e8285d16615ce20aaa
2020-10-29gdb: remove parameter of gdbarch_displaced_step_hw_singlestepSimon Marchi11-23/+32
I noticed that the closure parameter of gdbarch_displaced_step_hw_singlestep is never used by any implementation of the method, so this patch removes it. gdb/ChangeLog: * gdbarch.sh (displaced_step_hw_singlestep): Remove closure parameter. * aarch64-tdep.c (aarch64_displaced_step_hw_singlestep): Likewise. * aarch64-tdep.h (aarch64_displaced_step_hw_singlestep): Likewise. * arch-utils.c (default_displaced_step_hw_singlestep): Likewise. * arch-utils.h (default_displaced_step_hw_singlestep): Likewise. * rs6000-tdep.c (ppc_displaced_step_hw_singlestep): Likewise. * s390-tdep.c (s390_displaced_step_hw_singlestep): Likewise. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. * infrun.c (resume_1): Adjust. Change-Id: I7354f0b22afc2692ebff0cd700a462db8f389fc1
2020-10-29Remove call to exec_closeTom Tromey2-1/+5
There's no need to call exec_close from ~progspace, because that method just does some cleanup that's already going to be done during destruction. This patch removes the call. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.c (program_space::~program_space): Don't call exec_close.
2020-10-29Don't change current program space in exec_target::closeTom Tromey2-3/+5
Now that we've removed the macros and moved various functions to be methods on program_space (removing uses of current_program_space), it's clear that exec_target::close can operate on program spaces without changing the current program space. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * exec.c (exec_target::close): Don't change current program space.
2020-10-29Change add_target_sections_of_objfile to method on program_spaceTom Tromey6-12/+19
This changes add_target_sections_of_objfile to be a method on program_space. It is renamed to be another overload of add_target_sections, because they are semantically equivalent in a sense. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * symfile.c (add_symbol_file_command): Update. * exec.c (program_space::add_target_sections): Rename. * symfile-mem.c (symbol_file_add_from_memory): Update. * progspace.h (struct program_space) <add_target_sections>: Declare new overload. * exec.h (add_target_sections_of_objfile): Don't declare.
2020-10-29Change add_target_sections to method on program_spaceTom Tromey5-16/+22
This changes add_target_sections to be a method on program_space. Like the earlier change to remove_target_sections, this makes sense because this function is manipulating data that is stored on the program space. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * solib.c (solib_map_sections): Update. * exec.c (program_space::add_target_sections): Now a method. (exec_file_attach): Update. * exec.h (add_target_sections): Don't declare. * progspace.h (struct program_space) <add_target_sections>: Declare.
2020-10-29Change remove_target_sections to method on program_spaceTom Tromey6-20/+20
This changes remove_target_sections to be a method on program_space. This makes sense because this function manipulates data that is attached to the program space. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.h (struct program_space) <remove_target_sections>: Declare. * exec.c (program_space::remove_target_sections): Now a method. * exec.h (remove_target_sections): Don't declare.
2020-10-29Change program_space_empty_p to method on program_spaceTom Tromey4-10/+16
This changes program_space_empty_p to be a method on program_space. It also changes it to return bool. I removed the "_p" suffix because "empty" is a "well-known" C++ method name. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * inferior.c (delete_inferior): Update. * progspace.c (program_space::empty): Rename from program_space_empty_p. Return bool. * progspace.h (struct program_space) <empty>: New method. (program_space_empty_p): Don't declare.
2020-10-29Change clear_program_space_solib_cache to method on program_spaceTom Tromey4-10/+20
This changes clear_program_space_solib_cache to be a method on program_space. Also, it removes a call to this function from the program_space destructor, as that is not necessary. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.c (program_space::~program_space): Don't call clear_program_space_solib_cache. (program_space::clear_solib_cache): Rename from clear_solib_cache. * solib.c (handle_solib_event): Update. * progspace.h (struct program_space) <clear_solib_cache>: New method. (clear_program_space_solib_cache): Don't declare.
2020-10-29Remove symfile_objfile macroTom Tromey18-79/+124
This removes the symfile_objfile macro, in favor of just spelling out the member access. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * windows-tdep.c (windows_solib_create_inferior_hook): Update. * target.c (info_target_command): Update. * symfile.c (syms_from_objfile_1, finish_new_objfile) (symbol_file_clear, reread_symbols): Update. * symfile-mem.c (add_symbol_file_from_memory_command): Update. * stabsread.c (scan_file_globals): Update. * solib.c (update_solib_list): Update. * solib-svr4.c (elf_locate_base, open_symbol_file_object) (svr4_fetch_objfile_link_map, enable_break) (svr4_relocate_main_executable) (svr4_iterate_over_objfiles_in_search_order): Update. * solib-frv.c (lm_base, enable_break) (frv_relocate_main_executable): Update. (main_got, frv_fdpic_find_canonical_descriptor): Update. (frv_fetch_objfile_link_map): Update. * solib-dsbt.c (lm_base, dsbt_relocate_main_executable): Update. * solib-darwin.c (darwin_solib_create_inferior_hook): Update. * solib-aix.c (solib_aix_solib_create_inferior_hook): Update. * remote.c (remote_target::get_offsets): Update. (remote_target::start_remote) (extended_remote_target::post_attach): Update. * objfiles.c (entry_point_address_query): Update. * nto-procfs.c (nto_procfs_target::create_inferior): Update. * minsyms.c (get_symbol_leading_char): Update. * frame.c (inside_main_func): Update. * progspace.h (symfile_objfile): Remove macro.
2020-10-29Change program_space::ebfd to a gdb_bfd_ref_ptrTom Tromey4-9/+16
This changes program_space::ebfd to a gdb_bfd_ref_ptr, removing some manual management. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * exec.c (exec_file_attach): Update. * progspace.c (program_space::exec_close): Update. * progspace.h (struct program_space) <ebfd>: Now a gdb_bfd_ref_ptr. <set_exec_bfd>: Change argument type. <exec_bfd>: Update.
2020-10-29Remove the exec_bfd macroTom Tromey28-120/+218
This removes the exec_bfd macro, in favor of new accessors on program_space. In one spot the accessor can't be used; but this is still a big improvement over the macro, IMO. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * windows-tdep.c (windows_solib_create_inferior_hook): Update. * symfile.c (reread_symbols): Update. * symfile-mem.c (add_symbol_file_from_memory_command) (add_vsyscall_page): Update. * source-cache.c (source_cache::get_plain_source_lines): Update. * solib-svr4.c (find_program_interpreter, elf_locate_base) (svr4_current_sos_direct, svr4_exec_displacement) (svr4_relocate_main_executable): Update. (svr4_iterate_over_objfiles_in_search_order): Update. * solib-frv.c (enable_break2, enable_break): Update. * solib-dsbt.c (lm_base, enable_break): Update. * solib-darwin.c (find_program_interpreter) (darwin_solib_create_inferior_hook): Update. * sol-thread.c (rw_common, ps_pdmodel): Update. * rs6000-nat.c (rs6000_nat_target::create_inferior): Update. * remote.c (compare_sections_command) (remote_target::trace_set_readonly_regions): Update. * remote-sim.c (get_sim_inferior_data) (gdbsim_target::create_inferior, gdbsim_target::create_inferior): Update. (gdbsim_target_open, gdbsim_target::files_info): Update. * exec.h (exec_bfd): Remove macro. * progspace.c (initialize_progspace): Update. * proc-service.c (ps_addr_to_core_addr, core_addr_to_ps_addr): Update. * nto-procfs.c (nto_procfs_target::post_attach) (nto_procfs_target::create_inferior): Update. * maint.c (maintenance_info_sections): Update. * linux-thread-db.c (thread_db_target::get_thread_local_address): Update. * infcmd.c (post_create_inferior): Update. * gcore.c (default_gcore_arch, default_gcore_target): Update. (objfile_find_memory_regions): Update. * exec.c (validate_exec_file, exec_file_attach) (exec_read_partial_read_only, print_section_info): Update. * corelow.c (core_target_open): Update. * corefile.c (reopen_exec_file, validate_files): Update. * arm-tdep.c (gdb_print_insn_arm): Update. * arch-utils.c (gdbarch_update_p, default_print_insn): Update. * progspace.h (struct program_space) <exec_bfd, set_exec_bfd>: New methods.
2020-10-29Remove current_target_sections macroTom Tromey5-15/+23
This removes the current_target_sections macro, replacing it with uses of the appropriate member from current_program_space. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.h (current_target_sections): Remove macro. * solib-svr4.c (scan_dyntag): Update. * solib-dsbt.c (scan_dyntag): Update. * exec.c (exec_target::close): Update. (add_target_sections, add_target_sections_of_objfile) (remove_target_sections, exec_target::get_section_table) (exec_target::files_info, set_section_command) (exec_set_section_address, exec_target::has_memory) (exec_target::has_memory): Update.
2020-10-29Remove exec_bfd_mtime defineTom Tromey5-4/+13
This removes the exec_bfd_mtime define, in favor of directly using the appropriate member of the current program space. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * source-cache.c (source_cache::get_plain_source_lines): Use current_program_space. * corefile.c (reopen_exec_file): Use current_program_space. * exec.c (exec_file_attach): Use current_program_space. * exec.h (exec_bfd_mtime): Remove.
2020-10-29Remove commented-out code from gcore.cTom Tromey2-20/+6
I found some code in gcore.c that has been commented out since d3420b2fce5e (Mark Kettenis 2003-09-04 166) #if 1 /* See if this even matters... */ This patch deletes this entire function, because the body was reduced to just "return 0". gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * gcore.c (default_gcore_mach): Remove. (create_gcore_bfd): Update.
2020-10-29Change exec_close to be a method on program_spaceTom Tromey5-28/+35
exec_close uses the current program space, so it seemed cleaner to change it to be a method on program_space. This patch makes this change. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.c (program_space::exec_close): New method, from exec_close in exec.c. * exec.c (exec_close): Move to progspace.c. (exec_target::close, exec_file_attach): Update. * progspace.h (struct program_space) <exec_close>: Declare method.
2020-10-29Remove exec_filename macroTom Tromey8-20/+34
This removes the exec_filename macro, replacing it with uses of the member of current_program_space. This also renames that member, and changes it to be a unique pointer. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.h (struct program_space) <exec_filename>: Rename from pspace_exec_filename. Now a unique_xmalloc_ptr. * inferior.c (print_selected_inferior): Update. (print_inferior): Update. * mi/mi-main.c (print_one_inferior): Update. * exec.h (exec_filename): Remove macro. * corefile.c (get_exec_file): Update. * exec.c (exec_close): Update. (exec_file_attach): Update. * progspace.c (clone_program_space): Update. (print_program_space): Update.
2020-10-29Add target_section constructorTom Tromey4-18/+23
This adds a constructor to target_section, simplifying the code that creates instances of this. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * target-section.h (struct target_section): Add constructor. * exec.c (build_section_table, add_target_sections_of_objfile): Update. * corelow.c (core_target::build_file_mappings): Update.
2020-10-29gdb: restore thread after detaching or killing an inferiorTankut Baris Aktemur4-0/+18
The "detach inferiors N" command causes the current inferior to switch. E.g.: $ gdb a.out Reading symbols from a.out... (gdb) start ... (gdb) add-inferior [New inferior 2] Added inferior 2 on connection 1 (native) (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Connection Executable 1 process 18242 1 (native) /path/to/a.out * 2 <null> 1 (native) (gdb) detach inferiors 1 Detaching from program: /path/to/a.out, process 18242 [Inferior 1 (process 18242) detached] (gdb) info inferiors Num Description Connection Executable * 1 <null> /path/to/a.out 2 <null> 1 (native) (gdb) The same switch happens with the "kill inferiors N" command. Prevent it by restoring the current thread. gdb/ChangeLog: 2020-10-29 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> PR gdb/19318 * inferior.c (detach_inferior_command): Restore the current thread. (kill_inferior_command): Ditto. gdb/testsuite/ChangeLog: 2020-10-29 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.base/kill-detach-inferiors-cmd.exp: Check that 'kill inferiors' and 'detach inferiors' do not change the current inferior.