aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2021-06-17Don't call sigtimedwait for scoped_ignore_sigttouPedro Alves1-0/+10
Because SIGTTOU is sent to the whole process instead of to a specific thread, consuming a pending SIGTTOU in the destructor of scoped_ignore_sigttou could consume a SIGTTOU signal raised due to actions done by some other thread. Simply avoid sigtimedwait in scoped_ignore_sigttou, thus plugging the race. This works because we know that when the thread writes to the terminal and the signal is blocked, the kernel does not raise the signal at all. Tested on GNU/Linux, Solaris 11 and FreeBSD. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * scoped_ignore_signal.h (scoped_ignore_signal): Add ConsumePending template parameter. (scoped_ignore_signal::~scoped_ignore_signal): Skip calling sigtimedwait if ConsumePending is false. (scoped_ignore_sigpipe): Initialize with ConsumePending=true. * scoped_ignore_sigttou.h (scoped_ignore_sigttou) <m_ignore_signal>: Initialize with ConsumePending=false. Change-Id: I92f754dbc45c45819dce2ce68b8c067d8d5c61b1
2021-06-17Add a unit test for scoped_ignore_sigpipePedro Alves3-0/+133
gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * Makefile.in (SELFTESTS_SRCS): Add unittests/scoped_ignore_signal-selftests.c. * unittests/scoped_ignore_signal-selftests.c: New. Change-Id: Idce24aa9432a3f1eb7065bc9aa030b1d0d7dcad5
2021-06-17Introduce scoped_restore_signalPedro Alves2-28/+13
We currently have scoped_restore_sigttou and scoped_restore_sigpipe doing basically the same thing -- temporarily ignoring a specific signal. This patch introduce a scoped_restore_signal type that can be used for both. This will become more important for the next patch which changes how the signal-ignoring is implemented. scoped_restore_sigpipe is a straight alias to scoped_restore_signal<SIGPIPE> on systems that define SIGPIPE, and an alias to scoped_restore_signal_nop (a no-op version of scoped_restore_signal) otherwise. scoped_restore_sigttou is not a straight alias because it wants to check the job_control global. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * gdbsupport/scoped_ignore_signal.h: New. * compile/compile.c: Include gdbsupport/scoped_ignore_signal.h instead of <signal.h>. Don't include <unistd.h>. (scoped_ignore_sigpipe): Remove. * gdbsupport/scoped_ignore_sigttou.h: Include gdbsupport/scoped_ignore_signal.h instead of <signal.h>. Don't include <unistd.h>. (lazy_init): New. (scoped_ignore_sigttou): Reimplement using scoped_ignore_signal and lazy_init. Change-Id: Ibb44d0bd705e96df03ef0787c77358a4a7b7086c
2021-06-17Move scoped_ignore_sigttou to gdbsupport/Pedro Alves7-61/+10
A following patch will want to use scoped_ignore_sigttou in code shared between GDB and GDBserver. Move it under gdbsupport/. Note that despite what inflow.h/inflow.c's first line says, inflow.c is no longer about ptrace, it is about terminal management. Some other files were unnecessarily including inflow.h, I guess a leftover from the days when inflow.c really was about ptrace. Those inclusions are simply dropped. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * Makefile.in (HFILES_NO_SRCDIR): Remove inflow.h. * inf-ptrace.c, inflow.c, procfs.c: Don't include "inflow.h". * inflow.h: Delete, moved to gdbsupport/ under a different name. * ser-unix.c: Don't include "inflow.h". Include "gdbsupport/scoped_ignore_sigttou.h". gdbsupport/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * scoped_ignore_sigttou.h: New file, moved from gdb/ and renamed. Change-Id: Ie390abf42c3a78bec6d282ad2a63edd3e623559a
2021-06-17gdb/testsuite: gdb.base/args.exp: add KFAIL for native-extended-gdbserverSimon Marchi2-5/+23
This test tests passing arguments made of exactly two single-quotes ('') or a single newline character through the --args argument of GDB. For some reason, GDB adds some extra single quotes when transmitting the arguments to GDBserver. This produces some FAILs when testing with the native-extended-gdbserver board: FAIL: gdb.base/args.exp: argv[2] for one empty (with single quotes) FAIL: gdb.base/args.exp: argv[2] for two empty (with single quotes) FAIL: gdb.base/args.exp: argv[3] for two empty (with single quotes) FAIL: gdb.base/args.exp: argv[2] for one newline FAIL: gdb.base/args.exp: argv[2] for two newlines FAIL: gdb.base/args.exp: argv[3] for two newlines This is documented as PR 27989. Add some appropriate KFAILs. gdb/testsuite/ChangeLog: * gdb.base/args.exp: Check target, KFAIL if remote. (args_test): Add parameter and use it. Change-Id: I49225d1c7df7ebaba480ebdd596df80f8fbf62f0
2021-06-17gdb/testsuite: gdb.base/args.exp: remove trailing parenthesis in test namesSimon Marchi2-2/+6
Some test names end with a parenthesis, we don't want that: https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages Fix that. gdb/testsuite/ChangeLog: * gdb.base/args.exp: Remove trailing parenthesis in test names. Change-Id: I0306ea202bae3a4ed5bf0bd65e0ab5ed5de52fe1
2021-06-17gdb/testsuite: gdb.base/args.exp: use $old_gdbflags last two testsSimon Marchi2-2/+6
All tests in this file append to GDBFLAGS instead of overwriting it, except the last two. I noticed because when testing with the native-extended-remote board, it removes the "set sysroot" argument, and it causes the test to be very long to run, due to big glibc debug info being read through the remote target. I think this oddity is due to a race condition between these two commits: [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c22261528c50f7760dd6a2e29314662b377eebb4 [2] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6b8ce727297b1e40738e50f83a75881b290fe6a6 The first one added the two tests. The second one changes the test to append to GDBFLAGS instead of overwriting it. But the second one was probably written before the first one was it, so missed the new tests. Change those two tests to be like the others. gdb/testsuite/ChangeLog: * gdb.base/args.exp: Use $old_gdbflags in all tests. Change-Id: I531276125ecb70e80f52adbd320ebb85b0c8eba0
2021-06-17gdb/testsuite: gdb.base/args.exp: use save_varsSimon Marchi2-29/+31
Use save_vars instead of manually saving/restoring. This ensures that if anything throws an error, GDBFLAGS will be correctly restored. Remove the global GDBFLAGS declaration at the top, it's not necessary. gdb/testsuite/ChangeLog: * gdb.base/args.exp: Use save_vars. Change-Id: I3a45e4fc1635ec0212de2415040f91eecaf4a057
2021-06-17Make the TUI command window support the mousePedro Alves4-52/+186
Currently, when the focus is on the command window, we disable the keypad. This means that when the command window has the focus, keys such as up/down/home/end etc. are not processed by curses, and their escape sequences go straight to readline. A side effect of disabling keypad mode is that wgetch no longer processes mouse escape sequences, with the end result being the mouse doesn't work, and worse, the raw mouse escape sequences are printed on the terminal. This commit makes the TUI command window support the mouse as well, by always enabling the keypad, and then to avoid losing support for up/down browsing the command history, home/end/left/right moving the cursor position, etc., we forward those keys as raw escape sequences to readline. Note we don't make an effort to pass down to readline all keys returned by curses, only the common ones that readline understands by default. Given users can specify their own readline bindings (inputrc file, bind utility), this approach is good in practice, though not 100% transparent or perfect. Note that the patch makes it so that CTLC-L is always passed to readline even if the command window does not have the focus. It was simpler to implement that way, and it just seems correct to me. I don't know of a reason we shouldn't do that. The patch improves the TUI behavior in a related way. Now we can pass special keys to readline irrespective of which window has the focus. First, we try to dispatch the key to a window, via tui_displatch_ctrl_char. If the key is dispatched, then we don't pass it to readline. E.g., pressing "up" when you have the source window in focus results in scrolling the source window, and nothing else. If however, you press ctrl-del instead, that results in killing the next word in the command window, no matter which window has has focus. Before, it would only work if you had the command window in focus. Similarly, ctrl-left/ctrl-right to move between words, etc. Similarly, the previous spot where we handled mouse events was incorrect. It was never reached if the window with focus can't scroll, which is the case for the command window. Mouse scrolling affects the window under the mouse cursor, not the window in focus. We now always try to dispatch mouse events. One last bit in the patch -- now if we don't recognize the non-8-bit curses key, then we don't pass it down to readline at all. Before that would result in bogus characters in the input line. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * tui/tui-io.c (tui_dispatch_mouse_event): New, factored out from ... (tui_dispatch_ctrl_char): ... this. Move CTRL-L handling to tui_getc_1. (cur_seq, start_sequence): New. (tui_getc_1): Pass key escape sequences for curses control keys to readline. Handle mouse and ctrl-l here. (tui_resize_all): Disable/reenable the keypad if the command window has the focus too. * tui/tui-win.c (tui_set_focus_command): Don't change keypad setting. * tui/tui.c (tui_rl_other_window): Don't change keypad setting. Change-Id: Ie0a7d849943cfb47f4a6589e1c73341563740fa9
2021-06-16sim: make some rules silent by default in Make-common.inSimon Marchi2-0/+7
Use GDB's silent-rules.mk to make some rules silent by default. These rules cover most of what is built in sim/. gdb/ChangeLog: * silent-rules.mk (ECHO_CCLD, ECHO_AR, ECHO_RANLIB): New. sim/ChangeLog: * common/Make-common.in (COMPILE, libsim.a, run$(EXEEXT), gentmap.o, gentmap): Make rules silent. Change-Id: Idf9ba5beaee10c7c614859ace5fbdcd1de0287db
2021-06-16gdb, doc: Fix missed ChangeLog entry.Felix Willgerodt1-0/+6
My previous commit "btrace, doc: Clarify record function-call-history documentation." didn't add this to the actual ChangeLog file. Fix that.
2021-06-16btrace, doc: Clarify record function-call-history documentation.Felix Willgerodt1-15/+14
The documentation for 'record function-call-history' mentions lines instead of functions when talking about the number of functions printed, as currently there is only one line printed per function. Yet the code actually handles this on function granularity not on line basis. Future patches will extend the number of lines printed per function. This also makes it consistent with the 'record instruction-history' command, where multiple lines can be printed per instruction. gdb/doc/ChangeLog: 2021-06-16 Felix Willgerodt <felix.willgerodt@intel.com> * gdb.texinfo (Process Record and Replay): Stop mentioning lines for "record function-call-history" and "set record function-call-history-size".
2021-06-16[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder(), againTom de Vries5-23/+36
This is another attempt at fixing the problem described in commit 4cf88725da1 "[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()", which was reverted in commit 3db19b2d724. First off, some context. A DWARF CU can be viewed as a symbol table: toplevel children of a CU DIE represent symbol table entries for that CU. Furthermore, there is a hierarchy: a symbol table entry such as a function itself has a symbol table containing parameters and local variables. The dwarf reader maintains a notion of current symbol table (that is: the symbol table a new symbol needs to be entered into) in dwarf2_cu member list_in_scope. A problem then presents itself when reading inter-CU references: - a new symbol read from a CU B needs to be entered into the symbol table of another CU A. - the notion of current symbol table is tracked on a per-CU basis. This is addressed in inherit_abstract_dies by temporarily overwriting the list_in_scope for CU B with the one for CU A. The current symbol table is one aspect of the current dwarf reader context that is tracked, but there are more, f.i. ones that are tracked via the dwarf2_cu member m_builder, f.i. m_builder->m_local_using_directives. A similar problem exists in relation to inter-CU references, but a different solution was chosen: - to keep track of an ancestor field in dwarf2_cu, which is updated when traversing inter-CU references, and - to use the ancestor field in dwarf2_cu::get_builder to return the m_builder in scope. There is no actual concept of a CU having an ancestor, it just marks the most recent CU from which a CU was inter-CU-referenced. Consequently, when following inter-CU references from a CU A to another CU B and back to CU A, the ancestors form a cycle, which causes dwarf2_cu::get_builder to hang or segfault, as reported in PR26327. ISTM that the ancestor implementation is confusing and fragile, and should go. Furthermore, it seems that keeping track of the m_builder in scope can be handled simply with a per-objfile variable. Fix the hang / segfault by: - keeping track of the m_builder in scope using a new variable per_obj->sym_cu, and - using it in dwarf2_cu::get_builder. Tested on x86_64-linux (openSUSE Leap 15.2), no regressions for config: - using default gcc version 7.5.0 (with 5 unexpected FAILs) - gcc 10.3.0 and target board unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects (with 1000 unexpected FAILs) gdb/ChangeLog: 2021-06-16 Tom de Vries <tdevries@suse.de> PR symtab/26327 * dwarf2/cu.h (dwarf2_cu::ancestor): Remove. (dwarf2_cu::get_builder): Declare and move ... * dwarf2/cu.c (dwarf2_cu::get_builder): ... here. Use sym_cu instead of ancestor. Assert return value is non-null. * dwarf2/read.c (read_file_scope): Set per_objfile->sym_cu. (follow_die_offset, follow_die_sig_1): Remove setting of ancestor. (dwarf2_per_objfile): Add sym_cu field.
2021-06-15Fix typo in vsx-regs.exp testCarl Love1-1/+1
gdb/ChangeLog 2021-06-15 Carl Love <cel@us.ibm.com> * testsuite/gdb.arch/vsx-regs.exp (gdb_test_no_output): Fix typo in set \$vs$i.v2_double.
2021-06-15readelf: report DF_1_PIE as "Position-Independent Executable"Alan Modra2-1/+5
I finally found time to teach readelf to identify PIEs in the file header display and program header display. So in place of "DYN (Shared object file)" which isn't completely true, show "DYN (Position-Independent Executable file)". It requires a little bit of untangling code in readelf due to process_program_headers setting up dynamic_addr and dynamic_size, needed to scan .dynamic for the DT_FLAGS_1 entry, and process_program_headers itself wanting to display the file type in some cases. At first I modified process_program_header using a "probe" parameter similar to get_section_headers in order to inhibit output, but decided it was cleaner to separate out locate_dynamic_sections. binutils/ * readelf.c (locate_dynamic_section, is_pie): New functions. (get_file_type): Replace e_type parameter with filedata. Call is_pie for ET_DYN. Update all callers. (process_program_headers): Use local variables dynamic_addr and dynamic_size, updating filedata on exit from function. Set dynamic_size of 1 to indicate no dynamic section or segment. Update tests of dynamic_size throughout. * testsuite/binutils-all/x86-64/pr27708.dump: Update expected output. ld/ * testsuite/ld-pie/vaddr-0.d: Update expected output. gdb/ * testsuite/lib/gdb.exp (exec_is_pie): Match new PIE readelf output.
2021-06-14gnulib: define the path to gnulib's parent dirMike Frysinger2-2/+7
The current setting assumes that gnulib is only used by dirs immediately under the source root. Trying to build it two or more levels deep fails. Switch GNULIB_BUILDDIR to a relative GNULIB_PARENT_DIR so that it can be used to construct both the build & source paths.
2021-06-14fbsd nat: Disable address space randomization when requested.John Baldwin6-2/+96
Use procctl(2) with PROC_ASLR_CTL to disable address space randomization in the current gdb process before forking a child process for a new inferior when address space randomization is disabled. gdb/ChangeLog: * configure.ac: Check for <sys/procctl.h>. * config.in, configure: Regenerate. * fbsd-nat.c: Include <sys/procctl.h> if present. [PROC_ASLR_CTL] (maybe_disable_address_space_randomization): New. (fbsd_nat_target::create_inferior) (fbsd_nat_target::supports_disable_randomization): New. * fbsd-nat.h (fbsd_nat_target::create_inferior) (fbsd_nat_target::supports_disable_randomization): New.
2021-06-14Fix silent gdb.base/annota1.exp test coverage regressionPedro Alves2-3/+12
This commit fixes a test coverage regression caused by: commit b001de2320446ec803b4ee5e0b9710b025b84469 Author: Andrew Burgess <andrew.burgess@embecosm.com> AuthorDate: Mon Nov 26 17:56:39 2018 +0000 Commit: Andrew Burgess <andrew.burgess@embecosm.com> CommitDate: Wed Dec 12 17:33:52 2018 +0000 gdb: Update test pattern to deal with native-extended-gdbserver While looking at a regression caused by a local patch I was working on, I noticed this: pre-prompt (gdb) prompt PASS: gdb.base/annota1.exp: breakpoint info PASS: gdb.base/annota1.exp: run until main breakpoint run post-prompt Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.base/annota1/annota1 next Note how above, we get the "run until main breakpoint" pass even before "run" shows up in the log! The issue is that the test isn't really testing anything, it always passes regardless of the gdb output. There are a few problems here, fixed by this commit: - using {} to build the list for [join], when the strings we're joining include variable names that must be expanded. Such list need to be built with [list] instead. - [join] joins strings with a space character by default. We need to pass the empty string as second parameter so that it just concats the strings. - doing too much in a "-re" (calling procedures), which doesn't work correctly. I've seen this before and never digged deeper into why. Probably something to do with how gdb_test_multiple is implemented. Regardless, easy and clear enough to build the pattern first into a variable. gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * gdb.base/annota1.exp: Build list using [list] instead of {}. Tell [join] to join with no character. Build expected pattern in separate variable instead of in the -re expression directly. Change-Id: Ib3c89290f0e9ae4a0a43422853fcd4a7a7e12b18
2021-06-14Include missing header signal.hBernd Edlinger2-0/+5
2021-06-14 Bernd Edlinger <bernd.edlinger@hotmail.de> * compile/compile.c: Include missing header signal.h.
2021-06-12remote: Fix indentation in remote_new_objfile.John Baldwin2-2/+6
gdb/remote.c:14541:5: warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation] if (current_inferior ()->in_initial_library_scan) ^ gdb/remote.c:14527:3: note: previous statement is here if (remote == nullptr) ^ gdb/ChangeLog: * remote.c (remote_new_objfile): Fix indentation.
2021-06-11Fix ChangeLog entry locationSimon Marchi2-14/+14
This ChangeLog entry is in the wrong file, fix that. Change-Id: I43464e1bdb94d2f40d4c7dfaf425fc498851964c
2021-06-11mi-sym-info.exp: Increase timeout for 114-symbol-info-functionsKevin Buettner2-27/+34
Loading libc.so's symbols increased the amount of time needed for 114-symbol-info-function to fetch symbols, causing a timeout during my testing. I enclosed the entire block with a "with_timeout_factor 4", which fixes the problem for me. (Using 2 also fixed it for me, but it might not be enough when running this test on slower machines.) gdb/testsuite/ChangeLog: * gdb.mi/mi-sym-info.exp (114-symbol-info-function test): Increase timeout.
2021-06-11print-symbol-loading.exp: Allow libc symbols to be already loadedKevin Buettner2-3/+17
One consequence of changing libpthread_name_p() in solib.c to (also) match libc is that the symbols for libc will now be loaded by solib_add() in solib.c. I think this is mostly harmless because we'll likely want these symbols to be loaded anyway, but it did cause two failures in gdb.base/print-symbol-loading.exp. Specifically... 1) sharedlibrary .* (gdb) PASS: gdb.base/print-symbol-loading.exp: shlib off: load shared-lib now looks like this: sharedlibrary .* Symbols already loaded for /lib64/libc.so.6 (gdb) PASS: gdb.base/print-symbol-loading.exp: shlib off: load shared-lib 2) sharedlibrary .* Loading symbols for shared libraries: .* (gdb) PASS: gdb.base/print-symbol-loading.exp: shlib brief: load shared-lib now looks like this: sharedlibrary .* Loading symbols for shared libraries: .* Symbols already loaded for /lib64/libc.so.6 (gdb) PASS: gdb.base/print-symbol-loading.exp: shlib brief: load shared-lib Fixing case #2 ended up being easier than #1. #1 had been using gdb_test_no_output to correctly match this no-output case. I ended up replacing it with gdb_test_multiple, matching the exact expected output for each of the two now acceptable cases. For case #2, I simply added an optional non-capturing group for the potential new output. gdb/testsuite/ChangeLog: * gdb.base/print-symbol-loading.exp (proc test_load_shlib): Allow "Symbols already loaded for..." messages.
2021-06-11testsuite/glib-2.34: Match/consume optional libthread_db related outputKevin Buettner3-1/+10
When using glibc-2.34, we now see messages related to the loading of the thread library for non-thread programs. E.g. for the test case, gdb.base/execl-update-breakpoints.exp, we will see the following when starting the program: (gdb) break -qualified main Breakpoint 1 at 0x100118c: file /ironwood1/sourceware-git/f34-2-glibc244_fix/bld/../../worktree-glibc244_fix/gdb/testsuite/gdb.base/execl-update-breakpoints.c, line 34. (gdb) run Starting program: [...]/execl-update-breakpoints1 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". The two lines of output related to libthread_db are new; we didn't see these in the past. This is a side effect of libc now containing the pthread API - we can no longer tell whether the program is multi-threaded by simply looking for libpthread.so. That said, I think that we now want to load libthread_db anyway since it's used to resolve TLS variables; i.e. we need it for correctly determining the value of errno. This commit adds the necessary regular expressions to match this (optional) additional output in the two tests which were failing without it. gdb/testsuite/ChangeLog: * gdb.base/execl-update-breakpoints.exp: Add regular expression for optionally matching output related to libthread_db. * gdb.base/fork-print-inferior-events.exp: Likewise.
2021-06-11libthread_db initialization changes related to upcoming glibc-2.34Kevin Buettner3-5/+36
This commit makes some adjustments to accomodate the upcoming glibc-2.34 release. Beginning with glibc-2.34, functionality formerly contained in libpthread has been moved to libc. For the time being, libpthread.so still exists in the file system, but it won't show up in ldd output and therefore won't be able to trigger initialization of libthread_db related code. E.g... Fedora 34 / glibc-2.33.9000: [kev@f34-2 gdb]$ ldd testsuite/outputs/gdb.threads/tls/tls linux-vdso.so.1 (0x00007ffcf94fa000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff0ba9af000) libm.so.6 => /lib64/libm.so.6 (0x00007ff0ba8d4000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff0ba8b9000) libc.so.6 => /lib64/libc.so.6 (0x00007ff0ba6c6000) /lib64/ld-linux-x86-64.so.2 (0x00007ff0babf0000) Fedora 34 / glibc-2.33: [kev@f34-1 gdb]$ ldd testsuite/outputs/gdb.threads/tls/tls linux-vdso.so.1 (0x00007fff32dc0000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f815f6de000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f815f4bf000) libm.so.6 => /lib64/libm.so.6 (0x00007f815f37b000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f815f360000) libc.so.6 => /lib64/libc.so.6 (0x00007f815f191000) /lib64/ld-linux-x86-64.so.2 (0x00007f815f721000) Note that libpthread is missing from the ldd output for the glibc-2.33.9000 machine. This means that (unless we happen to think of some entirely different mechanism), we'll now need to potentially match "libc" in addition to "libpthread" as libraries which might be thread libraries. This accounts for the change made in solib.c. Note that the new code attempts to match "/libc." via strstr(). That trailing dot (".") avoids inadvertently matching libraries such as libcrypt (and all the other many libraries which begin with "libc"). To avoid attempts to load libthread_db when encountering older versions of libc, we now attempt to find "pthread_create" (which is a symbol that we'd expect to be in any pthread library) in the associated objfile. This accounts for the changes in linux-thread-db.c. I think that other small adjustments will need to be made elsewhere too. I've been working through regressions on my glibc-2.33.9000 machine; I've fixed some fairly "obvious" changes in the testsuite (which are in other commits). For the rest, it's not yet clear to me whether the handful of remaining failures represent a problem in glibc or gdb. I'm still investigating, however, I'll note that these are problems that I only see on my glibc-2.33.9000 machine. gdb/ChangeLog: * solib.c (libpthread_name_p): Match "libc" in addition to "libpthread". * linux-thread-db.c (libpthread_objfile_p): New function. (libpthread_name_p): Adjust preexisting callers to use libpthread_objfile_p().
2021-06-11gdb: remove unused struct call_site_stuff forward declarationSimon Marchi2-1/+4
This is unused (and was event when it was introduced). Remove it. gdb/ChangeLog: * dwarf2/loc.h (struct call_site_stuff): Remove. Change-Id: Iaa82cb7cfd9768998553b4c9211aca7529eb402f
2021-06-11gdb, testsuite: Fix mi-var-child-f.exp for Intel compilers.Felix Willgerodt4-22/+29
mi-var-child-f.exp uses array.f as the inferior, which uses an unnamed main function. This causes false positive fails for Intel compilers, as they emit the following DWARF: ~~~ 0x0000002a: DW_TAG_subprogram DW_AT_low_pc (0x0000000000404800) DW_AT_high_pc (0x000000000040484c) DW_AT_frame_base (DW_OP_reg6 RBP) DW_AT_linkage_name ("MAIN__") DW_AT_name ("_unnamed_main$$") DW_AT_decl_file ("array.f") DW_AT_decl_line (16) DW_AT_external (true) DW_AT_main_subprogram (true) ~~~ The testsuite for fortran uses test_compiler_info to determine a hardcoded string which is used to run to main and as a testing regex: ~~~ proc fortran_main {} { if {[test_compiler_info {gcc-4-[012]-*}] || [test_compiler_info {gcc-*}] || [test_compiler_info {icc-*}] { return "MAIN__" } elseif {[test_compiler_info {clang-*}]} { return "MAIN_" } else { return "unknown" } } ~~~ GDB however uses DW_AT_name mostly in its output, which fails the regex. To fix this testcase immediately, I modernized array.f and gave it a named main. There was no specific reason it was unnamed anyway. Fixing the testsuite properly is not straightforward. fortran_main and test_compiler_info would need some changes, which has broader influences. I might look at this later down the road. gdb/testsuite/ChangeLog: 2021-06-11 Felix Willgerodt <felix.willgerodt@intel.com> * gdb.mi/array.f: Convert into... * gdb.mi/array.f90: ...this. * gdb.mi/mi-var-child-f.exp: Use array.f90.
2021-06-11Implement Rust raw identifiersTom Tromey6-6/+124
This patch implements Rust raw identifiers in the lexer in gdb. There was an earlier patch to do this, but the contributor didn't reply to my email asking whether he had sorted out his copyright assignment. This is relatively straightforward, but a small test suite addition was needd to ensure that the new test is skipped on older versions of rustc -- ones that predate the introduction of raw identifiers. gdb/ChangeLog 2021-06-11 Tom Tromey <tom@tromey.com> PR rust/23427 * rust-parse.c (rust_parser::lex_identifier): Handle raw identifiers. (rust_lex_tests): Add raw identifier tests. gdb/testsuite/ChangeLog 2021-06-11 Tom Tromey <tom@tromey.com> PR rust/23427 * lib/rust-support.exp (rust_compiler_version): New caching proc. * gdb.rust/rawids.exp: New file. * gdb.rust/rawids.rs: New file.
2021-06-10gdb/testsuite: capture GDB tty name in default_gdb_spawnSimon Marchi3-40/+40
The TUI test gdb.tui/empty.exp fails with the native-extended-gdbserver board, and takes a very long time to run due to numerous timeouts. The symptom, when looking at the logs, is that the TUI windows that we expect to be resized are not resized. Digging down, I found that GDB didn't receive any SIGWINCH that should have resulted from Term::resize's stty calls. The reason for this is: - The native-extended-gdbserver overrides gdb_start to first start GDB, then start GDBserver with --multi, then connect GDB to GDBserver. This means that two TCL "spawn"s are done, one for GDB and one for GDBserver. - The TUI test framework wants to know GDB's TTY name, so it can pass it to stty, to fake terminal resizes. To do so, it overrides the spawn built-in proc to capture the tty name from the internals of the built-in proc. It saves the TTY name to the gdb_spawn_name global variable. - Because the native-extended-gdbserver boards starts both GDB and GDBserver, the final value of gdb_spawn_name is the name of GDBserver's TTY. - When the TUI test framework attempts to resize GDB's terminal, it in fact resizes GDBserver's terminal. So obviously, GDB doesn't get the SIGWINCH, and we don't get the expected TUI redraw. Fix that by moving the hack to lib/gdb.exp, overriding the builtin spawn all the time. The override saves the TTY name in the last_spawn_tty_name global. The default_gdb_spawn proc then saves it in the gdb_tty_name global. This way, we specifically capture GDB's TTY name in gdb_tty_name, not the TTY name of other spawned processes. Remove tuiterm_env_init and tuiterm_env_finish, since they are now empty. In turn, the gdb_finish_hooks mechanism is now unused, remove it as well. It would be easy to add them back if needed. gdb/ChangeLog: * lib/gdb.exp (default_gdb_exit): Unset gdb_tty_name. (spawn_capture_tty_name): New, override builtin spawn. (default_gdb_spawn): Capture GDB's TTY name. * lib/tuiterm.exp (tuiterm_spawn): Remove. (tuiterm_env_init, tuiterm_env_finish): Remove spawn override. (Term) <resize>: Use new variable name. (tuiterm_env_init, tuiterm_env_finish): Remove. (tuiterm_env): Don't call tuiterm_env_init and register tuiterm_env_finish in gdb_finish_hooks. (gdb_finish_hooks): Remove. (gdb_finish): Don't call finish hooks. Change-Id: Ia5ab74184a52a996416022308f8d0cc523355a78
2021-06-10[gdb/testsuite] Fix timeout in gdb.mi/user-selected-context-sync.exp with gcc-11Tom de Vries2-8/+13
When running test-case gdb.mi/user-selected-context-sync.exp with gcc-11, we get: ... continue^M Continuing.^M FAIL: gdb.mi/user-selected-context-sync.exp: mode=all-stop: test_setup: \ inferior 1: continue to breakpoint: continue thread 1.2 to infinite \ loop breakpoint (timeout) ... This is a regression since commit aa33ea68330 "testsuite, mi: avoid a clang bug in 'user-selected-context-sync.exp'", which fixes a similar hang when using clang. The source before the commit contains: ... while (1); ... and after the commit: ... int spin = 1; while (spin); ... [ FWIW, I've filed a PR gcc/101011 - Inconsistent debug info for "while (1);" to mention that gcc-11 has different behaviour for these two loops. ] The problem is that: - the test-case expects the behaviour that a breakpoint set on the while line will trigger on every iteration, and - that is not guaranteed by either version of the loop. Fix this by using a while loop with a dummy body: ... volatile int dummy = 0; while (1) dummy = !dummy; ... and setting the breakpoint in the body. Tested on x86_64-linux with clang 10.0.1, gcc-4.8, gcc 7.5.0 and gcc 11.1.1. gdb/testsuite/ChangeLog: 2021-06-10 Tom de Vries <tdevries@suse.de> * gdb.mi/user-selected-context-sync.c (child_sub_function, main): Rewrite while (1) using dummy loop body.
2021-06-10 [gdb/testsuite] Convert multi-line function call into single line.Bhuvanendra Kumar N2-9/+15
After this clang backend patch(https://reviews.llvm.org/D91734), 8 test points started to FAIL in this test case. As mentioned in this PR, "...this test is trying to next over a function call; gcc attributes all parameter evaluation to the function name, while clang will attribute each parameter to its own location. And when the parameters span across multiple source lines, the is_stmt heuristic kicks in, so we stop on each line with actual parameters...". gdb.base/foll-exec.c test file snippet : . . . 42 execlp (prog, /* tbreak-execlp */ 43 prog, 44 "execlp arg1 from foll-exec", 45 (char *) 0); 46 47 printf ("foll-exec is about to execl(execd-prog)...\n"); . . . Line table: (before clang backend patch for the above code snippet) : 0x000000b0: 84 address += 8, line += 2 0x000000000020196a 42 3 1 0 0 0x000000b1: 08 DW_LNS_const_add_pc (0x0000000000000011) 0x000000b2: 41 address += 3, line += 5 0x000000000020197e 47 3 1 0 0 Line table: (after clang backend patch for the above code snippet) : 0x000000b5: 84 address += 8, line += 2 0x0000000000201958 42 11 1 0 0 0x000000b6: 05 DW_LNS_set_column (4) 0x000000b8: 75 address += 7, line += 1 0x000000000020195f 43 4 1 0 0 0x000000b9: 05 DW_LNS_set_column (3) 0x000000bb: 73 address += 7, line += -1 0x0000000000201966 42 3 1 0 0 0x000000bc: 08 DW_LNS_const_add_pc (0x0000000000000011) 0x000000bd: 4f address += 4, line += 5 0x000000000020197b 47 3 1 0 0 Following 8 test points started to fail after the above clang backend patch. FAIL: gdb.base/foll-exec.exp: step through execlp call FAIL: gdb.base/foll-exec.exp: step after execlp call FAIL: gdb.base/foll-exec.exp: print execd-program/global_i (after execlp) FAIL: gdb.base/foll-exec.exp: print execd-program/local_j (after execlp) FAIL: gdb.base/foll-exec.exp: print follow-exec/local_k (after execlp) FAIL: gdb.base/foll-exec.exp: step through execl call FAIL: gdb.base/foll-exec.exp: step after execl call FAIL: gdb.base/foll-exec.exp: print execd-program/local_j (after execl) As we can note, reason for these new test failures is due to additional .debug_line entries getting created in case of clang compiler, hence to fix this issue, test case required either additional next command during these multi-line function call or combine these multi-line function call into single line. This PR has taken the latter approach and converted the multi-line function call into single line in foll-exec.c, thereby there is no change in .debug_line entries now and test case works as expected.
2021-06-10[gdb/testsuite] Fix gdb.cp/nested-types.exp with check-read1Tom de Vries3-18/+34
With check-read1 I occasionally run into: ... FAIL: gdb.cp/nested-types.exp: ptype S10 (limit = 7) \ // parse failed (timeout) ... I can trigger this reliably by running check-read1 in conjunction with stress -c 5. Fix this by breaking up the regexp in cp_test_ptype_class. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-10 Tom de Vries <tdevries@suse.de> * lib/cp-support.exp (cp_test_ptype_class): Break up regexp. * gdb.cp/nested-types.exp: Remove usage of read1 timeout factor.
2021-06-10[gdb/testsuite] Fix gdb.cp/cplusfuncs.exp with check-read1Tom de Vries2-4/+11
When running check-read1, we run into: ... FAIL: gdb.cp/cplusfuncs.exp: info function for "operator=(" (timeout) ... Fix this by using using gdb_test_lines in info_func_regexp. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-10 Tom de Vries <tdevries@suse.de> * gdb.cp/cplusfuncs.exp (info_func_regexp): Use gdb_test_lines.
2021-06-09Update read1 example in gdb/testsuite/READMETom Tromey2-1/+9
Tom de Vries noticed that the recent changes to the testsuite's configury required an update to the README. This patch changes the text to document the new reality. 2021-06-09 Tom Tromey <tromey@adacore.com> * README (Example): Update read1 example.
2021-06-09gdb/testsuite: add some logging in Term::_check_boxSimon Marchi2-16/+34
I was diagnosing some problem with a TUI test case, which lead me to improve the logging of _check_box a bit. It did help me, so I think it would be nice to have it upstream. gdb/testsuite/ChangeLog: * lib/tuiterm.exp (Term) <_check_box>: Improve logging. Change-Id: I887e83c02507d6c59c991e17f795c844ed63bacf
2021-06-08Use is/is not to check for None in python code.Lancelot SIX17-22/+52
While reviewing a patch sent to the mailing list, I noticed there are few places where python code checks if a variable is 'None' or not by using the comparison operators '==' and '!='. PEP8[1], which is used as coding standard in GDB coding standards, recommends using 'is' / 'is not' when comparing to a singleton such as 'None'. This patch proposes to change the instances of '== None' by 'is None' and '!= None' by 'is not None'. [1] https://www.python.org/dev/peps/pep-0008/ gdb/doc/ChangeLog: * python.texi (Writing a Pretty-Printer): Use 'is None' instead of '== None'. gdb/ChangeLog: * python/lib/gdb/FrameDecorator.py (FrameDecorator): Use 'is None' instead of '== None'. (FrameVars): Use 'is not None' instead of '!= None'. * python/lib/gdb/command/frame_filters.py (SetFrameFilterPriority): Use 'is None' instead of '== None' and 'is not None' instead of '!= None'. gdb/testsuite/ChangeLog: * gdb.base/premature-dummy-frame-removal.py (TestUnwinder): Use 'is None' instead of '== None' and 'is not None' instead of '!= None'. * gdb.python/py-frame-args.py (lookup_function): Same. * gdb.python/py-framefilter-invalidarg.py (Reverse_Function): Same. * gdb.python/py-framefilter.py (Reverse_Function): Same. * gdb.python/py-nested-maps.py (lookup_function): Same. * gdb.python/py-objfile-script-gdb.py (lookup_function): Same. * gdb.python/py-prettyprint.py (lookup_function): Same. * gdb.python/py-section-script.py (lookup_function): Same. * gdb.python/py-unwind-inline.py (dummy_unwinder): Same. * gdb.python/python.exp: Same. * gdb.rust/pp.py (lookup_function): Same.
2021-06-08gdb: try to load libthread_db only after reading all shared libraries when ↵Simon Marchi6-7/+64
attaching / handling a fork child When trying to attach to a pthread process on a Linux system with glibc 2.33, we get: $ ./gdb -q -nx --data-directory=data-directory -p 1472010 Attaching to process 1472010 [New LWP 1472013] [New LWP 1472014] [New LWP 1472015] Error while reading shared library symbols for /usr/lib/libpthread.so.0: Cannot find user-level thread for LWP 1472015: generic error 0x00007ffff6d3637f in poll () from /usr/lib/libc.so.6 (gdb) When attaching to a process (or handling a fork child, an operation very similar to attaching), GDB reads the shared library list from the process. For each shared library (if "set auto-solib-add" is on), it reads its symbols and calls the "new_objfile" observable. The libthread-db code monitors this observable, and if it sees an objfile named somewhat like "libpthread.so" go by, it tries to load libthread_db.so in the GDB process itself. libthread_db knows how to navigate libpthread's data structures to get information about the existing threads. To locate these data structures, libthread_db calls ps_pglobal_lookup (implemented in proc-service.c), passing in a symbol name and expecting an address in return. Before glibc 2.33, libthread_db always asked for symbols found in libpthread. There was no ordering problem: since we were always trying to load libthread_db in reaction to processing libpthread (and reading in its symbols) and libthread_db only asked symbols from libpthread, the requested symbols could always be found. Starting with glibc 2.33, libthread_db now asks for a symbol name that can be found in /lib/ld-linux-x86-64.so.2 (_rtld_global). And the ordering in which GDB reads the shared libraries from the inferior when attaching is unfortunate, in that libpthread is processed before ld-linux. So when loading libthread_db in reaction to processing libpthread, and libthread_db requests the symbol that is from ld-linux, GDB is not yet able to supply it. That problematic symbol lookup happens in the thread_from_lwp function, when we call td_ta_map_lwp2thr_p, and an exception is thrown at this point: #0 0x00007ffff6681012 in __cxxabiv1::__cxa_throw (obj=0x60e000006100, tinfo=0x555560033b50 <typeinfo for gdb_exception_error>, dest=0x55555d9404bc <gdb_exception_error::~gdb_exception_error()>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:78 #1 0x000055555e5d3734 in throw_it(return_reason, errors, const char *, typedef __va_list_tag __va_list_tag *) (reason=RETURN_ERROR, error=GENERIC_ERROR, fmt=0x55555f0c5360 "Cannot find user-level thread for LWP %ld: %s", ap=0x7fffffffaae0) at /home/simark/src/binutils-gdb/gdbsupport/common-exceptions.cc:200 #2 0x000055555e5d37d4 in throw_verror (error=GENERIC_ERROR, fmt=0x55555f0c5360 "Cannot find user-level thread for LWP %ld: %s", ap=0x7fffffffaae0) at /home/simark/src/binutils-gdb/gdbsupport/common-exceptions.cc:208 #3 0x000055555e0b0ed2 in verror (string=0x55555f0c5360 "Cannot find user-level thread for LWP %ld: %s", args=0x7fffffffaae0) at /home/simark/src/binutils-gdb/gdb/utils.c:171 #4 0x000055555e5e898a in error (fmt=0x55555f0c5360 "Cannot find user-level thread for LWP %ld: %s") at /home/simark/src/binutils-gdb/gdbsupport/errors.cc:43 #5 0x000055555d06b4bc in thread_from_lwp (stopped=0x617000035d80, ptid=...) at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:418 #6 0x000055555d07040d in try_thread_db_load_1 (info=0x60c000011140) at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:912 #7 0x000055555d071103 in try_thread_db_load (library=0x55555f0c62a0 "libthread_db.so.1", check_auto_load_safe=false) at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1014 #8 0x000055555d072168 in try_thread_db_load_from_sdir () at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1091 #9 0x000055555d072d1c in thread_db_load_search () at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1146 #10 0x000055555d07365c in thread_db_load () at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1203 #11 0x000055555d07373e in check_for_thread_db () at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1246 #12 0x000055555d0738ab in thread_db_new_objfile (objfile=0x61300000c0c0) at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1275 #13 0x000055555bd10740 in std::__invoke_impl<void, void (*&)(objfile*), objfile*> (__f=@0x616000068d88: 0x55555d073745 <thread_db_new_objfile(objfile*)>) at /usr/include/c++/10.2.0/bits/invoke.h:60 #14 0x000055555bd02096 in std::__invoke_r<void, void (*&)(objfile*), objfile*> (__fn=@0x616000068d88: 0x55555d073745 <thread_db_new_objfile(objfile*)>) at /usr/include/c++/10.2.0/bits/invoke.h:153 #15 0x000055555bce0392 in std::_Function_handler<void (objfile*), void (*)(objfile*)>::_M_invoke(std::_Any_data const&, objfile*&&) (__functor=..., __args#0=@0x7fffffffb4a0: 0x61300000c0c0) at /usr/include/c++/10.2.0/bits/std_function.h:291 #16 0x000055555d3595c0 in std::function<void (objfile*)>::operator()(objfile*) const (this=0x616000068d88, __args#0=0x61300000c0c0) at /usr/include/c++/10.2.0/bits/std_function.h:622 #17 0x000055555d356b7f in gdb::observers::observable<objfile*>::notify (this=0x555566727020 <gdb::observers::new_objfile>, args#0=0x61300000c0c0) at /home/simark/src/binutils-gdb/gdb/../gdbsupport/observable.h:106 #18 0x000055555da3f228 in symbol_file_add_with_addrs (abfd=0x61200001ccc0, name=0x6190000d9090 "/usr/lib/libpthread.so.0", add_flags=..., addrs=0x7fffffffbc10, flags=..., parent=0x0) at /home/simark/src/binutils-gdb/gdb/symfile.c:1131 #19 0x000055555da3f763 in symbol_file_add_from_bfd (abfd=0x61200001ccc0, name=0x6190000d9090 "/usr/lib/libpthread.so.0", add_flags=<error reading variable: Cannot access memory at address 0xffffffffffffffb0>, addrs=0x7fffffffbc10, flags=<error reading variable: Cannot access memory at address 0xffffffffffffffc0>, parent=0x0) at /home/simark/src/binutils-gdb/gdb/symfile.c:1167 #20 0x000055555d95f9fa in solib_read_symbols (so=0x6190000d8e80, flags=...) at /home/simark/src/binutils-gdb/gdb/solib.c:681 #21 0x000055555d96233d in solib_add (pattern=0x0, from_tty=0, readsyms=1) at /home/simark/src/binutils-gdb/gdb/solib.c:987 #22 0x000055555d93646e in enable_break (info=0x608000008f20, from_tty=0) at /home/simark/src/binutils-gdb/gdb/solib-svr4.c:2238 #23 0x000055555d93cfc0 in svr4_solib_create_inferior_hook (from_tty=0) at /home/simark/src/binutils-gdb/gdb/solib-svr4.c:3049 #24 0x000055555d96610d in solib_create_inferior_hook (from_tty=0) at /home/simark/src/binutils-gdb/gdb/solib.c:1195 #25 0x000055555cdee318 in post_create_inferior (from_tty=0) at /home/simark/src/binutils-gdb/gdb/infcmd.c:318 #26 0x000055555ce00e6e in setup_inferior (from_tty=0) at /home/simark/src/binutils-gdb/gdb/infcmd.c:2439 #27 0x000055555ce59c34 in handle_one (event=...) at /home/simark/src/binutils-gdb/gdb/infrun.c:4887 #28 0x000055555ce5cd00 in stop_all_threads () at /home/simark/src/binutils-gdb/gdb/infrun.c:5064 #29 0x000055555ce7f0da in stop_waiting (ecs=0x7fffffffd170) at /home/simark/src/binutils-gdb/gdb/infrun.c:8006 #30 0x000055555ce67f5c in handle_signal_stop (ecs=0x7fffffffd170) at /home/simark/src/binutils-gdb/gdb/infrun.c:6062 #31 0x000055555ce63653 in handle_inferior_event (ecs=0x7fffffffd170) at /home/simark/src/binutils-gdb/gdb/infrun.c:5727 #32 0x000055555ce4f297 in fetch_inferior_event () at /home/simark/src/binutils-gdb/gdb/infrun.c:4105 #33 0x000055555cdbe3bf in inferior_event_handler (event_type=INF_REG_EVENT) at /home/simark/src/binutils-gdb/gdb/inf-loop.c:42 #34 0x000055555d018047 in handle_target_event (error=0, client_data=0x0) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:4060 #35 0x000055555e5ea77e in handle_file_event (file_ptr=0x60600008b1c0, ready_mask=1) at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:575 #36 0x000055555e5eb09c in gdb_wait_for_event (block=0) at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:701 #37 0x000055555e5e8d19 in gdb_do_one_event () at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:212 #38 0x000055555dd6e0d4 in wait_sync_command_done () at /home/simark/src/binutils-gdb/gdb/top.c:528 #39 0x000055555dd6e372 in maybe_wait_sync_command_done (was_sync=0) at /home/simark/src/binutils-gdb/gdb/top.c:545 #40 0x000055555d0ec7c8 in catch_command_errors (command=0x55555ce01bb8 <attach_command(char const*, int)>, arg=0x7fffffffe28d "1472010", from_tty=1, do_bp_actions=false) at /home/simark/src/binutils-gdb/gdb/main.c:452 #41 0x000055555d0f03ad in captured_main_1 (context=0x7fffffffdd10) at /home/simark/src/binutils-gdb/gdb/main.c:1149 #42 0x000055555d0f1239 in captured_main (data=0x7fffffffdd10) at /home/simark/src/binutils-gdb/gdb/main.c:1232 #43 0x000055555d0f1315 in gdb_main (args=0x7fffffffdd10) at /home/simark/src/binutils-gdb/gdb/main.c:1257 #44 0x000055555bb70cf9 in main (argc=7, argv=0x7fffffffde88) at /home/simark/src/binutils-gdb/gdb/gdb.c:32 The exception is caught here: #0 __cxxabiv1::__cxa_begin_catch (exc_obj_in=0x60e0000060e0) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_catch.cc:84 #1 0x000055555d95fded in solib_read_symbols (so=0x6190000d8e80, flags=...) at /home/simark/src/binutils-gdb/gdb/solib.c:689 #2 0x000055555d96233d in solib_add (pattern=0x0, from_tty=0, readsyms=1) at /home/simark/src/binutils-gdb/gdb/solib.c:987 #3 0x000055555d93646e in enable_break (info=0x608000008f20, from_tty=0) at /home/simark/src/binutils-gdb/gdb/solib-svr4.c:2238 #4 0x000055555d93cfc0 in svr4_solib_create_inferior_hook (from_tty=0) at /home/simark/src/binutils-gdb/gdb/solib-svr4.c:3049 #5 0x000055555d96610d in solib_create_inferior_hook (from_tty=0) at /home/simark/src/binutils-gdb/gdb/solib.c:1195 #6 0x000055555cdee318 in post_create_inferior (from_tty=0) at /home/simark/src/binutils-gdb/gdb/infcmd.c:318 #7 0x000055555ce00e6e in setup_inferior (from_tty=0) at /home/simark/src/binutils-gdb/gdb/infcmd.c:2439 #8 0x000055555ce59c34 in handle_one (event=...) at /home/simark/src/binutils-gdb/gdb/infrun.c:4887 #9 0x000055555ce5cd00 in stop_all_threads () at /home/simark/src/binutils-gdb/gdb/infrun.c:5064 #10 0x000055555ce7f0da in stop_waiting (ecs=0x7fffffffd170) at /home/simark/src/binutils-gdb/gdb/infrun.c:8006 #11 0x000055555ce67f5c in handle_signal_stop (ecs=0x7fffffffd170) at /home/simark/src/binutils-gdb/gdb/infrun.c:6062 #12 0x000055555ce63653 in handle_inferior_event (ecs=0x7fffffffd170) at /home/simark/src/binutils-gdb/gdb/infrun.c:5727 #13 0x000055555ce4f297 in fetch_inferior_event () at /home/simark/src/binutils-gdb/gdb/infrun.c:4105 #14 0x000055555cdbe3bf in inferior_event_handler (event_type=INF_REG_EVENT) at /home/simark/src/binutils-gdb/gdb/inf-loop.c:42 #15 0x000055555d018047 in handle_target_event (error=0, client_data=0x0) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:4060 #16 0x000055555e5ea77e in handle_file_event (file_ptr=0x60600008b1c0, ready_mask=1) at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:575 #17 0x000055555e5eb09c in gdb_wait_for_event (block=0) at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:701 #18 0x000055555e5e8d19 in gdb_do_one_event () at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:212 #19 0x000055555dd6e0d4 in wait_sync_command_done () at /home/simark/src/binutils-gdb/gdb/top.c:528 #20 0x000055555dd6e372 in maybe_wait_sync_command_done (was_sync=0) at /home/simark/src/binutils-gdb/gdb/top.c:545 #21 0x000055555d0ec7c8 in catch_command_errors (command=0x55555ce01bb8 <attach_command(char const*, int)>, arg=0x7fffffffe28d "1472010", from_tty=1, do_bp_actions=false) at /home/simark/src/binutils-gdb/gdb/main.c:452 #22 0x000055555d0f03ad in captured_main_1 (context=0x7fffffffdd10) at /home/simark/src/binutils-gdb/gdb/main.c:1149 #23 0x000055555d0f1239 in captured_main (data=0x7fffffffdd10) at /home/simark/src/binutils-gdb/gdb/main.c:1232 #24 0x000055555d0f1315 in gdb_main (args=0x7fffffffdd10) at /home/simark/src/binutils-gdb/gdb/main.c:1257 #25 0x000055555bb70cf9 in main (argc=7, argv=0x7fffffffde88) at /home/simark/src/binutils-gdb/gdb/gdb.c:32 Catching the exception at this point means that the thread_db_info object for this inferior will be left in place, despite the failure to load libthread_db. This means that there won't be further attempts at loading libthread_db, because thread_db_load will think that libthread_db is already loaded for this inferior and will always exit early. To fix this, add a try/catch around calling try_thread_db_load_1 in try_thread_db_load, such that if some exception is thrown while trying to load libthread_db, we reset / delete the thread_db_info for that inferior. That alone makes attach work fine again, because check_for_thread_db is called again in the thread_db_inferior_created observer (that happens after we learned about all shared libraries and their symbols), and libthread_db is successfully loaded then. When attaching, I think that the inferior_created observer is a good place to try to load libthread_db: it is called once everything has stabilized, when we learned about all shared libraries. The only problem then is that when we first try (and fail) to load libthread_db, in reaction to learning about libpthread, we show this warning: warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. This is misleading, because we do succeed in loading it later. So when attaching, I think we shouldn't try to load libthread_db in reaction to the new_objfile events, we should wait until we have learned about all shared libraries (using the inferior_created observable). To do so, add an `in_initial_library_scan` flag to struct inferior. This flag is used to postpone loading libthread_db if we are attaching or handling a fork child. When debugging remotely with GDBserver, the same problem happens, except that the qSymbol mechanism (allowing the remote side to ask GDB for symbols values) is involved. The fix there is the same idea, we make GDB wait until all shared libraries and their symbols are known before sending out a qSymbol packet. This way, we never present the remote side a state where libpthread.so's symbols are known but ld-linux's symbols aren't. gdb/ChangeLog: * inferior.h (class inferior) <in_initial_library_scan>: New. * infcmd.c (post_create_inferior): Set in_initial_library_scan. * infrun.c (follow_fork_inferior): Likewise. * linux-thread-db.c (try_thread_db_load): Catch exception thrown by try_thread_db_load_1 (thread_db_load): Return early if in_initial_library_scan is set. * remote.c (remote_new_objfile): Return early if in_initial_library_scan is set. Change-Id: I7a279836cfbb2b362b4fde11b196b4aab82f5efb
2021-06-08[gdb/testsuite] Disallow single argument in multi_lineTom de Vries5-5/+18
It's a common mistake of mine to do: ... set l [list "foo" "bar"] set re [multi_line $l] ... and to get "foo bar" while I was expecting "foo\r\nbar", which I get after doing instead: ... set re [multi_line {*}$l] ... Detect this type of mistake by erroring out in multi_line when only one argument is passed. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * lib/gdb.exp (multi_line): Require more than one argument. * gdb.base/gdbinit-history.exp: Update multi_line call. * gdb.base/jit-reader.exp: Remove multi_line call. * gdb.fortran/dynamic-ptype-whatis.exp: Same.
2021-06-08[gdb/testsuite] Fix gdb.base/info-macros.exp with check-read1Tom de Vries4-85/+91
With check-read1 we run into: ... FAIL: gdb.base/info-macros.exp: info macros info-macros.c:42 (timeout) ... Fix this by using gdb_test_lines from gdb.base/info-types.exp.tcl. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * gdb.base/info-types.exp.tcl (match_line, gdb_test_lines): Move ... * lib/gdb.exp: ... here. * gdb.base/info-macros.exp: Use gdb_test_lines.
2021-06-08[gdb/testsuite] Simplify gdb.base/info-types.exp.tcl furtherTom de Vries2-31/+46
After adding support for --any in match_line, we can simplify gdb.base/info-types.exp.tcl further: we can add the "All defined types:" regexp in the output_lines list: ... set output_lines \ [list \ + "All defined types:" \ + "--any" \ $file_re \ ... Consequently, we can simplify the state machine to track a variable "found" with values: - 0 (unmatched) - 1 (matched) - -1 (mismatch). This makes the code generic enough to factor out into a new proc gdb_test_lines. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * gdb.base/info-types.exp.tcl (match_line): Handle --any. (gdb_test_lines): Factor out of ... (run_test): ... here.
2021-06-08[gdb/testsuite] Fix gdb.base/batch-preserve-term-settings.exp with check-read1Tom de Vries2-1/+16
With check-read1, I run into: ... FAIL: gdb.base/batch-preserve-term-settings.exp: batch run: \ terminal settings preserved ... This is caused by spawn_shell matching too little output, after which things start to go out of sync. More specifically, the regexp: ... -re "PS1=\[^\r\n\]*\r\n.*$shell_prompt_re$" { ... matches the first and part of the second line of this output: ... PS1="gdb-subshell$ "^M sh-4.4$ PS1="gdb-subshell$ "^M gdb-subshell$ ... while it's supposed to match the entire output. Fix this by splitting up the regexp into a part that skips the lines with PS1, and one that reads the shell prompt. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * gdb.base/batch-preserve-term-settings.exp (spawn_shell): Fix matching of initial prompt.
2021-06-08[gdb/testsuite] Fix gdb.threads/multi-create-ns-info-thr.expTom de Vries2-1/+6
With a testsuite setup modified to make expect wait a little bit longer for gdb output (see PR27957), I reliably run into: ... PASS: gdb.threads/multi-create-ns-info-thr.exp: continue to breakpoint 1 FAIL: gdb.threads/multi-create-ns-info-thr.exp: continue to breakpoint 2 \ (timeout) ... This is due to this regexp: ... -re "Breakpoint $decimal,.*$srcfile:$bp_location1" { ... consuming several lines using the ".*" part, while it's intended to match one line looking like this: ... Thread 1 "multi-create-ns" hit Breakpoint 2, create_function () \ at multi-create.c:45^M ... Fix this by limiting the regexp to one line. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * gdb.threads/multi-create-ns-info-thr.exp: Limit breakpoint regexp to one line.
2021-06-08[gdb/testsuite] Simplify gdb.base/sect-cmd.expTom de Vries2-13/+11
While looking at gdb.base/sect-cmd.exp, I noticed a few things that can be simplified: - use gdb_test instead of gdb_test_multiple - use -wrap "" as regexp Also, I noticed this: ... fail "$gdb_test_name, saw not found marker" ... while our usual test naming scheme uses parentheses, like so: ... fail "$gdb_test_name (saw not found marker)" ... Fix the test-name and do the simplifications. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * gdb.base/sect-cmd.exp: Use gdb_test. Use -wrap "". Fix test name.
2021-06-08[gdb/testsuite] Fix gdb.base/sect-cmd.expTom de Vries2-1/+5
With a testsuite setup modified to make expect wait a little bit longer for gdb output (see PR27957), I reliably run into: ... (gdb) FAIL: gdb.base/sect-cmd.exp: set section .text to original \ address (timeout) ... The problem is a too greedy regexp: ... -re ".*$address1 \- $address2 is $section_name.*" { ... which ends up consuming the gdb prompt with the terminating ".*". Fix this by limiting the regexp to a single line. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * gdb.base/sect-cmd.exp: Fix saw_section_address_line regexp.
2021-06-08Fix a couple -Wdeprecated-copy issuesPedro Alves3-0/+9
Building GDB with current git (future 13) Clang runs into these two issues: #1: src/gdb/symtab.h:1139:3: error: definition of implicit copy assignment operator for 'symbol' is deprecated because it has a user-declared copy constructor [-Werror,-Wdeprecated-copy] symbol (const symbol &) = default; ^ #2: src/gdb/dwarf2/read.c:834:23: error: definition of implicit copy constructor for 'partial_die_info' is deprecated because it has a user-declared copy assignment operator [-Werror,-Wdeprecated-copy] partial_die_info& operator=(const partial_die_info& rhs) = delete; ^ Fix them by adding the explicit defaulted versions of copy ctor and copy-assign op appropriately. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * dwarf2/read.c (struct partial_die_info): Add defaulted copy ctor. * symtab.h (struct symbol): Add defaulted copy assignment operator.
2021-06-07gdb_rl_find_completion_word: Remove 'found_quote' localPedro Alves2-20/+9
Compiling GDB with current git Clang (future 13) runs into this: src/gdb/completer.c:287:18: error: variable 'found_quote' set but not used [-Werror,-Wunused-but-set-variable] int scan, end, found_quote, delimiter, pass_next, isbrk; ^ gdb_rl_find_completion_word came to life as a modified (stripped down) version of readline's internal _rl_find_completion_word function. When I added it, I don't remember whether I realized that 'found_quote' wasn't really necessary. Maybe I kept it thinking of keeping the source code in sync with readline? I don't recall anymore. Since the function is already stripped down compared to the original, stripping it down some more doesn't hurt. So fix the issue by removing the unnecessary code. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * completer.c (RL_QF_SINGLE_QUOTE, RL_QF_DOUBLE_QUOTE) (RL_QF_BACKSLASH, RL_QF_OTHER_QUOTE): Delete. (gdb_rl_find_completion_word): Remove write-only 'found_quote' local.
2021-06-07nat/amd64-linux-siginfo.c: Remove typedefsPedro Alves2-14/+28
Since GDB is written in C++ now, we don't need struct/union typedefs any more. Remove them from nat/amd64-linux-siginfo.c. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * nat/amd64-linux-siginfo.c (union nat_sigval): Rename to ... (nat_sigval_t): ... this and remove typedef of same name. (struct nat_siginfo): Rename to ... (nat_siginfo_t): ... this and remove typedef of same name. (struct compat_sigval): Rename to ... (compat_sigval_t): ... this and remove typedef of same name. (struct compat_siginfo): Rename to ... (compat_siginfo_t): ... this and remove typedef of same name. (struct compat_x32_siginfo): Rename to ... (compat_x32_siginfo_t): ... this and remove typedef of same name. (amd64_linux_siginfo_fixup_common): Adjust.
2021-06-07nat/amd64-linux-siginfo.c: Move align attribute from typedef to structPedro Alves2-2/+7
Compiling GDB with current git Clang (future 13) fails with (among other problems), this issue: $ make nat/amd64-linux-siginfo.o CXX nat/amd64-linux-siginfo.o src/gdb/nat/amd64-linux-siginfo.c:590:35: warning: passing 4-byte aligned argument to 8-byte aligned parameter 1 of 'compat_x32_siginfo_from_siginfo' may result in an unaligned pointer access [-Walign-mismatch] compat_x32_siginfo_from_siginfo ((struct compat_x32_siginfo *) inf, ^ 1 warning generated. The problem is that: - The flagged code is casting to "struct compat_x32_siginfo" pointer directly instead of to a pointer to the compat_x32_siginfo_t typedef. The called function is declared with a compat_x32_siginfo_t typedef pointer parameter. - Only the typedef has the __aligned__ attribute. Fix this by moving the attribute to the struct, so both struct and typedef have the same alignment. The next patch removes the typedefs. gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * nat/amd64-linux-siginfo.c (compat_x32_siginfo_t): Move __attribute__ __aligned__ from the typedef to the struct.
2021-06-07gdb/testsuite: gdb.base/continue-all-already-running.exp: add fail if can't ↵Simon Marchi2-0/+6
run to main While doing some changes, I managed to break this test in a way that running to main didn't work. However, it didn't produce any FAIL. I noticed because I diff'ed the results and saw some PASSes unexpectedly disappear, but that's a bit fragile. Add a fail in case this test fails to run to main. Ideally, I think that runto_main should by default produce a FAIL when it fails (the opposite of the existing logic), but that's a project of its own, so just fix this test for the moment. gdb/testsuite/ChangeLog: * gdb.base/continue-all-already-running.exp: Call fail if can't run to main. Change-Id: I84b816a126c92ac579ed5ebbe39b017bd5cb7096
2021-06-07gdb: handle case where type alignment is unknownAndrew Burgess5-1/+168
It was spotted that if type_align returned 0 then it was possible to trigger a divide by zero exception within GDB. It turns out this will only happen in an edge case where GDB is unable to figure out the alignment of a field within a structure. The attached test generates some non-standard, probably broken, DWARF, that triggers this condition, and then fixes this issue by throwing an exception when this case occurs. gdb/ChangeLog: PR gdb/27847 * amd64-tdep.c (amd64_has_unaligned_fields): Move call to type_align, and spot case where the alignment is unknown. gdb/testsuite/ChangeLog: PR gdb/27847 * gdb.dwarf2/dw2-weird-type-len.c: New file. * gdb.dwarf2/dw2-weird-type-len.exp: New file.