aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2021-06-05Use ACX_NONCANONICAL_TARGET in gdb/configureTom Tromey3-0/+26
Shahab Vahedi pointed out that the patch to remove gdb/testsuite/configure regressed the site.exp creation a bit -- it left an unresolved configure substitution. Andrew Burgess pointed out that the patch removed the call to ACX_NONCANONICAL_TARGET, which caused this problem. This patch adds ACX_NONCANONICAL_TARGET to gdb's configure, and fixes the bug. gdb/ChangeLog 2021-06-05 Tom Tromey <tromey@adacore.com> * configure: Rebuild. * configure.ac: Add ACX_NONCANONICAL_TARGET.
2021-06-05Fix symbol constants tests for Python 3Hannes Domani2-22/+26
gdb/testsuite/ChangeLog: 2021-06-05 Hannes Domani <ssbssa@yahoo.de> * gdb.python/py-symbol.exp: Fix tests for Python 3.
2021-06-05arc: Add 'set disassembler-options' supportShahab Vahedi8-4/+92
Implement ARC target support for passing options to the disassembler through the command interface. e.g.: gdb> set disassembler-options cpu=hs38_linux ... gdb/ChangeLog: * NEWS: Document 'set disassembler-options' support for the ARC target. * arc-tdep.c (arc_gdbarch_init): Set 'gdbarch_valid_disassembler_options'. gdb/doc/ChangeLog: * gdb.texinfo (Source and Machine Code): Document 'set disassembler-options' support for the ARC target. gdb/testsuite/ChangeLog: * gdb.arch/arc-disassembler-options.exp: New test. * gdb.arch/arc-disassembler-options.s: New test source.
2021-06-04Add PROP_VARIABLE_NAMETom Tromey12-5/+312
With -fgnat-encodings=minimal, an internal version (these patches will be upstreamed in the near future) of the Ada compiler can emit DWARF for an array where the bound comes from a variable, like: <1><12a7>: Abbrev Number: 7 (DW_TAG_array_type) <12a8> DW_AT_name : (indirect string, offset: 0x1ae9): pck__my_array [...] <2><12b4>: Abbrev Number: 8 (DW_TAG_subrange_type) <12b5> DW_AT_type : <0x1294> <12b9> DW_AT_upper_bound : <0x1277> With the upper bound DIE being: <1><1277>: Abbrev Number: 2 (DW_TAG_variable) <1278> DW_AT_name : (indirect string, offset: 0x1a4d): pck__my_length___U <127c> DW_AT_type : <0x128f> <1280> DW_AT_external : 1 <1280> DW_AT_artificial : 1 <1280> DW_AT_declaration : 1 Note that the variable is just a declaration -- in this situation, the variable comes from another compilation unit, and must be found when trying to compute the array bound. This patch adds a new PROP_VARIABLE_NAME kind, to enable this search. This same scenario can occur with DW_OP_GNU_variable_value, so this patch adds support for that as well. gdb/ChangeLog 2021-06-04 Tom Tromey <tromey@adacore.com> * dwarf2/read.h (dwarf2_fetch_die_type_sect_off): Add 'var_name' parameter. * dwarf2/loc.c (dwarf2_evaluate_property) <case PROP_VARIABLE_NAME>: New case. (compute_var_value): New function. (sect_variable_value): Use compute_var_value. * dwarf2/read.c (attr_to_dynamic_prop): Handle DW_TAG_variable. (var_decl_name): New function. (dwarf2_fetch_die_type_sect_off): Add 'var_name' parameter. * gdbtypes.h (enum dynamic_prop_kind) <PROP_VARIABLE_NAME>: New constant. (union dynamic_prop_data) <variable_name>: New member. (struct dynamic_prop) <variable_name, set_variable_name>: New methods. gdb/testsuite/ChangeLog 2021-06-04 Tom Tromey <tromey@adacore.com> * gdb.ada/array_of_symbolic_length.exp: New file. * gdb.ada/array_of_symbolic_length/foo.adb: New file. * gdb.ada/array_of_symbolic_length/gl.adb: New file. * gdb.ada/array_of_symbolic_length/gl.ads: New file. * gdb.ada/array_of_symbolic_length/pck.adb: New file. * gdb.ada/array_of_symbolic_length/pck.ads: New file.
2021-06-04gdb: add some additional debug output in remote.cAndrew Burgess2-0/+14
I needed more debug output from: remote_target::select_thread_for_ambiguous_stop_reply I thought this would be useful for others too. gdb/ChangeLog: * remote.c (remote_target) <select_thread_for_ambiguous_stop_reply>: Add additional debug output.
2021-06-04Forward mouse click to python TUI windowHannes Domani4-0/+33
If the TUI window object implements the click method, it is called for each mouse click event in this window. gdb/ChangeLog: 2021-06-04 Hannes Domani <ssbssa@yahoo.de> * python/py-tui.c (class tui_py_window): Add click function. (tui_py_window::click): Likewise. gdb/doc/ChangeLog: 2021-06-04 Hannes Domani <ssbssa@yahoo.de> * python.texi (TUI Windows In Python): Document Window.click.
2021-06-04Initial TUI mouse supportHannes Domani5-0/+62
Implements an overridable tui_win_info::click method whose arguments are the mouse coordinates inside the specific window, and the mouse button clicked. And if the curses implementation supports 5 buttons, the 4th and 5th buttons are used for scrolling. gdb/ChangeLog: 2021-06-04 Hannes Domani <ssbssa@yahoo.de> * ser-mingw.c (console_select_thread): Handle MOUSE_EVENT. * tui/tui-data.h (struct tui_win_info): Add click function. * tui/tui-io.c (tui_prep_terminal): Enable mouse events. (tui_deprep_terminal): Disable mouse events. (tui_dispatch_ctrl_char): Handle KEY_MOUSE. * tui/tui.c (tui_disable): Disable mouse events.
2021-06-03gdb: fix eval.c assert during inferior exit eventMagne Hov5-1/+54
Evaluating expressions from within an inferior exit event handler can cause a crash: echo "int main() { return 0; }" > repro.c gcc -g repro.c -o repro ./gdb -q --ex "set language c++" --ex "python gdb.events.exited.connect(lambda _: gdb.execute('set \$_a=0'))" --ex "run" repro Reading symbols from repro... Starting program: /home/mhov/repos/binutils-gdb-master/install-bad/bin/repro [Inferior 1 (process 1974779) exited normally] ../../gdb/thread.c:72: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) [answered Y; input not from terminal] This is a bug, please report it. For instructions, see: <https://www.gnu.org/software/gdb/bugs/>. Backtrace 0 in internal_error of ../../gdbsupport/errors.cc:51 1 in inferior_thread of ../../gdb/thread.c:72 2 in expression::evaluate of ../../gdb/eval.c:98 3 in evaluate_expression of ../../gdb/eval.c:115 4 in set_command of ../../gdb/printcmd.c:1502 5 in do_const_cfunc of ../../gdb/cli/cli-decode.c:101 6 in cmd_func of ../../gdb/cli/cli-decode.c:2181 7 in execute_command of ../../gdb/top.c:670 ... 22 in python_inferior_exit of ../../gdb/python/py-inferior.c:182 In `expression::evaluate (...)' there is a call to `inferior_thread ()' that is guarded by `target_has_execution ()': struct value * expression::evaluate (struct type *expect_type, enum noside noside) { gdb::optional<enable_thread_stack_temporaries> stack_temporaries; if (target_has_execution () && language_defn->la_language == language_cplus && !thread_stack_temporaries_enabled_p (inferior_thread ())) stack_temporaries.emplace (inferior_thread ()); The `target_has_execution ()' guard maps onto `inf->pid' and the `inferior_thread ()' call assumes that `current_thread_' is set to something meaningful: struct thread_info* inferior_thread (void) { gdb_assert (current_thread_ != nullptr); return current_thread_; } In other words, it is assumed that if `inf->pid' is set then `current_thread_' must also be set. This does not hold at the point where inferior exit observers are notified: - `generic_mourn_inferior (...)' - `switch_to_no_thread ()' - `current_thread_ = nullptr;' - `exit_inferior (...)' - `gdb::observers::inferior_exit.notify (...)' - `inf->pid = 0' The inferior exit notification means that a Python handler can get a chance to run while `current_thread' has been cleared and the `inf->pid' has not been cleared. Since the Python handler can call any GDB command with `gdb.execute(...)' (in my case `gdb.execute("set $_a=0")' we can end up evaluating expressions and asserting in `evaluate_subexp (...)'. This patch adds a test in `evaluate_subexp (...)' to check the global `inferior_ptid' which is reset at the same time as `current_thread_'. Checking `inferior_ptid' at the same time as `target_has_execution ()' seems to be a common pattern: $ git grep -n -e inferior_ptid --and -e target_has_execution gdb/breakpoint.c:2998: && (inferior_ptid == null_ptid || !target_has_execution ())) gdb/breakpoint.c:3054: && (inferior_ptid == null_ptid || !target_has_execution ())) gdb/breakpoint.c:4587: if (inferior_ptid == null_ptid || !target_has_execution ()) gdb/infcmd.c:360: if (inferior_ptid != null_ptid && target_has_execution ()) gdb/infcmd.c:2380: /* FIXME: This should not really be inferior_ptid (or target_has_execution). gdb/infrun.c:3438: if (!target_has_execution () || inferior_ptid == null_ptid) gdb/remote.c:11961: if (!target_has_execution () || inferior_ptid == null_ptid) gdb/solib.c:725: if (target_has_execution () && inferior_ptid != null_ptid) The testsuite has been run on 5.4.0-59-generic x86_64 GNU/Linux: - Ubuntu 20.04.1 LTS - gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 - DejaGnu version 1.6.2 - Expect version 5.45.4 - Tcl version 8.6 - Native configuration: x86_64-pc-linux-gnu - Target: unix Results show a few XFAIL in gdb.threads/attach-many-short-lived-threads.exp. The existing py-events.exp tests are skipped for native-gdbserver and fail for native-extended-gdbserver, but the new tests pass with native-extended-gdbserver when run without the existing tests. gdb/ChangeLog: 2021-06-03 Magne Hov <mhov@undo.io> PR python/27841 * eval.c (expression::evaluate): Check inferior_ptid. gdb/testsuite/ChangeLog: 2021-06-03 Magne Hov <mhov@undo.io> PR python/27841 * gdb.python/py-events.exp: Extend inferior exit tests. * gdb.python/py-events.py: Print inferior exit PID.
2021-06-03Update my email address in MAINTAINERSPedro Alves2-3/+9
gdb/ChangeLog: yyyy-mm-dd Pedro Alves <pedro@palves.net> * MAINTAINERS (The Official FSF-appointed GDB Maintainers): Remove affiliation. (Global Maintainers): Update my address. (Write After Approval): Remove stale entry. Change-Id: I3266fedeebfa6800faa2217baf6c032408e84902
2021-06-03Report additional details for signals received on FreeBSD.John Baldwin2-0/+293
Provide a description for si_code values as a sigcode-meaning field. For signals raised by a system call, provide the pid and user ID of the sending process. For signals raised by a POSIX timer exparation, provide the id of the timer. For signals raised by a POSIX message queue, provide the id of the message queue. For SIGCHLD provide the pid and user ID of the child process along with the exit status or relevant signal number. Sample output for SIGUSR1 raised by kill(): before: Program received signal SIGUSR1, User defined signal 1. kill () at kill.S:4 4 RSYSCALL(kill) after: Program received signal SIGUSR1, User defined signal 1. Sent by kill() from pid 30529 and user 1001. kill () at kill.S:4 4 RSYSCALL(kill) SIGCHLD for exited process: before: Program received signal SIGCHLD, Child status changed. after: Program received signal SIGCHLD, Child status changed. Child has exited: pid 31929, uid 1001, exit status 0. SIGALRM raised by a POSIX timer (timer_create): before: Program received signal SIGALRM, Alarm clock. after: Program received signal SIGALRM, Alarm clock. Timer expired: timerid 3. gdb/ChangeLog: * fbsd-tdep.c (FBSD_SI_USER, FBSD_SI_QUEUE, FBSD_SI_TIMER) (FBSD_SI_ASYNCIO, FBSD_SI_MESGQ, FBSD_SI_KERNEL, FBSD_SI_LWP) (FBSD_ILL_ILLOPC, FBSD_ILL_ILLOPN, FBSD_ILL_ILLADR) (FBSD_ILL_ILLTRP, FBSD_ILL_PRVOPC, FBSD_ILL_PRVREG) (FBSD_ILL_COPROC, FBSD_ILL_BADSTK, FBSD_BUS_ADRALN) (FBSD_BUS_ADRERR, FBSD_BUS_OBJERR, FBSD_BUS_OOMERR) (FBSD_SEGV_MAPERR, FBSD_SEGV_ACCERR, FBSD_SEGV_PKUERR) (FBSD_FPE_INTOVF, FBSD_FPE_INTDIV, FBSD_FPE_FLTDIV) (FBSD_FPE_FLTOVF, FBSD_FPE_FLTUND, FBSD_FPE_FLTRES) (FBSD_FPE_FLTINV, FBSD_FPE_FLTSUB, FBSD_TRAP_BRKPT) (FBSD_TRAP_TRACE, FBSD_TRAP_DTRACE, FBSD_TRAP_CAP) (FBSD_CLD_EXITED, FBSD_CLD_KILLED, FBSD_CLD_DUMPED) (FBSD_CLD_TRAPPED, FBSD_CLD_STOPPED, FBSD_CLD_CONTINUED) (FBSD_POLL_IN, FBSD_POLL_OUT, FBSD_POLL_MSG, FBSD_POLL_ERR) (FBSD_POLL_PRI, FBSD_POLL_HUP, fbsd_signal_cause) (fbsd_report_signal_info): New. (fbsd_init_abi): Use fbsd_report_signal_info as gdbarch report_signal_info method.
2021-06-03Add ChangeLog entry for previous commitMagne Hov1-0/+4
2021-06-03Add myself to gdb/MAINTAINERSMagne Hov1-0/+1
gdb/ChangeLog: 2021-06-03 Magne Hov <mhov@undo.io> * MAINTAINERS (Write After Approval): Add Magne Hov.
2021-06-03Restore gdb.SYMBOL_LABEL_DOMAIN constantHannes Domani4-0/+59
It was removed (probably by mistake) in 51e78fc5fa21870d415c52f90b93e3c6ad57be46. gdb/ChangeLog: 2021-06-03 Hannes Domani <ssbssa@yahoo.de> * python/py-symbol.c (gdbpy_initialize_symbols): Restore gdb.SYMBOL_LABEL_DOMAIN constant. gdb/testsuite/ChangeLog: 2021-06-03 Hannes Domani <ssbssa@yahoo.de> * gdb.python/py-symbol.exp: Test symbol constants.
2021-06-02Fix temp-dir leakage in per-bfd-sharing.expBernd Edlinger2-5/+9
Whan using clang as compiler this compile step fails due to the unknown option "-Wl,--build-id". This leaks the already created temp-dir. Fixed by compiling first, and creating the temp-dir only when the compile succeeded. 2021-06-02 Bernd Edlinger <bernd.edlinger@hotmail.de> * gdb.dwarf2/per-bfd-sharing.exp: Fix temp-dir leakage.
2021-06-02Fix threadapply testCarl Love2-7/+12
The current test case leaves detached processes running at the end of the test. This patch changes the test to use a barrier wait to ensure all processes exit cleanly at the end of the tests. gdb/testsuite/ChangeLog: 2021-06-02 Carl Love <cel@us.ibm.com> * gdb.threads/threadapply.c: Add global mybarrier. (main): Add pthread_barrier_init. (thread_function): Replace while loop with myp increment and pthread_barrier_wait.
2021-06-02gdb/testsuite: only add -J option when compiling with gfortranAndrew Burgess2-1/+9
We currently make use of the -J option to gfortran in order that compiled modules should be placed in the correct output directory. Obviously different compilers, e.g. flang, will have different options to achieve the same result. This commit makes it so we only add the -J flag when using a gcc based (i.e. gfortran) compiler. I had a look through the flang help page and tried a few likely looking options, but couldn't find anything that seemed to do the same thing, so, for now, I'm only adding an extra option when compiling with gfortran. This does mean that any compiler other than gfortran might run into problems if running the testsuite in parallel due to modules of the same name all being written to the same directory, and so possibly overwriting each other. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_compile): Only add the -J option when using a gcc based Fortran compiler, for example, flang does not support this option.
2021-06-02gdb/testsuite: escape '*' character in pattern used by flangAndrew Burgess2-1/+5
One of the integer type patterns used by flang included a '*' character which was not escaped. gdb/testsuite/ChangeLog: * lib/fortran.exp (fortran_int8): Escape '*' in pattern.
2021-06-01Conditionally restore displaced stepping state after fork.John Baldwin2-4/+18
There is no default method for gdbarch_displaced_step_restore_all_in_ptid, so calling it unconditionally for fork events triggered an assertion failure on platforms that do not support displaced stepping. To fix, only invoke the method if the gdbarch supports displaced stepping. Note that not all gdbarches support both displaced stepping and fork events, so gdbarch validation does not require gdbarch_displaced_step_restore_all_in_ptid for any gdbarch supporting displaced stepping. However, the internal assertion in gdbarch_displaced_step_restore_all_in_ptid should catch any gdbarches which do support both but fail to provide this method. gdb/ChangeLog: * infrun.c (handle_inferior_event): Only call gdbarch_displaced_step_restore_all_in_ptid if gdbarch_supports_displaced_stepping is true.
2021-06-01Remove some gdb/data-directory special casesTom Tromey2-8/+5
I found an odd special case for data-directory in gdb's Makefile. I don't see a reason to have this, so this removes it in favor of having this code work in the most ordinary way for a subdirectory build. gdb/ChangeLog 2021-06-01 Tom Tromey <tromey@adacore.com> * Makefile.in (all-data-directory): Remove. (data-directory/Makefile): Remove.
2021-06-01Clean up gdb's --enable-sharedTom Tromey3-2/+7
The old testsuite configure did not use AS_HELP_STRING, and it had a typo in the help for --enable-shared. This patch fixes these problems. gdb/ChangeLog 2021-06-01 Tom Tromey <tromey@adacore.com> * configure: Rebuild. * configure.ac: Use AS_HELP_STRING for enable-shared. Fix typo.
2021-06-01Apply silent Makefile rules to gdb/testsuiteTom Tromey4-33/+47
This applies the silent-rules.mk treatment to gdb/testsuite/Makefile. gdb/ChangeLog 2021-06-01 Tom Tromey <tromey@adacore.com> * silent-rules.mk (ECHO_CC): New variable. gdb/testsuite/ChangeLog 2021-06-01 Tom Tromey <tromey@adacore.com> * Makefile.in (all): Don't print anything. ($(abs_builddir)/site.exp site.exp): Use $(ECHO_GEN). (expect-read1): Likewise. (read1.so): Use $(ECHO_CC). Include silent-rules.mk.
2021-06-01Always build 'all' in gdb/testsuiteTom Tromey2-2/+7
gdb's Makefile currently excludes testsuite from the subdirectories to build. I don't think there's a good reason for this, so this patch adds testsuite to the SUBDIRS list and removes a special case from 'all'. gdb/ChangeLog 2021-06-01 Tom Tromey <tromey@adacore.com> * Makefile.in (SUBDIRS): Add testsuite. (all): Don't exclude testsuite.
2021-06-01Remove gdb/testsuite/configureTom Tromey8-4961/+141
I didn't see a strong reason to have a separate configure script in gdb/testsuite, so this patch removes it. The few relevant configury bits are moved into gdb's configure script. Some of the old testsuite/configure script (e.g., the header check) is dead code. This also adds a Makefile rule to rebuild lib/pdtrace. This was missing from the old code. 'read1' is now a dependency of check-read1, rather than extra code at configure time. Finally, the old "ENABLE_LIBCTF" subst in gdb/configure was not used; nor was the variable defined, so this was always empty. However, the lower-case variant was used by the testsuite, so this patch renames the subst. gdb/ChangeLog 2021-06-01 Tom Tromey <tromey@adacore.com> * configure.ac: Copy some code from testsuite/configure.ac. (enable_libctf): Subst this, not ENABLE_LIBCTF. * configure: Rebuild. gdb/testsuite/ChangeLog 2021-06-01 Tom Tromey <tromey@adacore.com> * aclocal.m4, configure.ac, configure: Remove. * Makefile.in (EXTRA_RULES): Remove. ($(abs_builddir)/site.exp site.exp): Don't depend on config.status. (distclean maintainer-clean realclean, Makefile): Update. (config.status): Remove target. (lib/pdtrace): New target. (all): Don't depend on EXTRA_RULES. (check-read1): Depend on read1.so, expect-read1.
2021-06-01[gdb/symtab] Ignore cold clonesTom de Vries5-0/+148
Consider the test-case contained in this patch, compiled for c using gcc-10: ... $ gcc-10 -x c src/gdb/testsuite/gdb.cp/cold-clone.cc -O2 -g -Wall -Wextra ... When setting a breakpoint on foo, we get one breakpoint location: ... $ gdb -q -batch a.out -ex "b foo" Breakpoint 1 at 0x400560: file cold-clone.cc, line 28. ... However, when we compile for c++ instead, we get two breakpoint locations: ... $ gdb -q -batch a.out -ex "b foo" -ex "info break" Breakpoint 1 at 0x400430: foo. (2 locations) Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x0000000000400430 in foo() at cold-clone.cc:30 1.2 y 0x0000000000400560 in foo() at cold-clone.cc:28 ... The additional breakpoint location at 0x400430 corresponds to the cold clone: ... $ nm a.out | grep foo 0000000000400560 t _ZL3foov 0000000000400430 t _ZL3foov.cold ... which demangled looks like this: ... $ nm -C a.out | grep foo 0000000000400560 t foo() 0000000000400430 t foo() [clone .cold] ... [ Or, in the case of the cc1 mentioned in PR23710: ... $ nm cc1 | grep do_rpo_vn.*cold 000000000058659d t \ _ZL9do_rpo_vnP8functionP8edge_defP11bitmap_headbb.cold.138 $ nm -C cc1 | grep do_rpo_vn.*cold 000000000058659d t \ do_rpo_vn(function*, edge_def*, bitmap_head*, bool, bool) [clone .cold.138] ... ] The cold clone is a part of the function that is split off from the rest of the function because it's considered cold (not frequently executed). So while the symbol points to code that is part of a function, it doesn't point to a function entry, so the desirable behaviour for "break foo" is to ignore this symbol. When compiling for c, the symbol "foo.cold" is entered as minimal symbol with the search name "foo.cold", and the lookup using "foo" fails to find that symbol. But when compiling for c++, the symbol "foo.cold" is entered as minimal symbol with both the mangled and demangled name, and for the demangled name "foo() [clone .cold]" we get the search name "foo" (because cp_search_name_hash stops hashing at '('), and the lookup using "foo" succeeds. Fix this by recognizing the cold clone suffix and returning false for such a minimal symbol in msymbol_is_function. Tested on x86_64-linux. gdb/ChangeLog: 2021-06-01 Tom de Vries <tdevries@suse.de> PR symtab/26096 * minsyms.c (msymbol_is_cold_clone): New function. (msymbol_is_function): Use msymbol_is_cold_clone. gdb/testsuite/ChangeLog: 2021-06-01 Tom de Vries <tdevries@suse.de> PR symtab/26096 * gdb.cp/cold-clone.cc: New test. * gdb.cp/cold-clone.exp: New file.
2021-06-01gdb: run 'maint selftest' with an executable loadedAndrew Burgess3-19/+78
I spotted that 'maint selftest' with an executable loaded into GDB, would (when GDB was compiled for all targets) crash GDB. I fixed this with a commit to bfd: commit 427e4066afd13d1bf52c849849475f536e285d66 Date: Thu May 20 09:16:41 2021 +0100 gdb/bfd: avoid crash when architecture is forced to csky or riscv However, this issue was not spotted as we currently only run 'maint selftest' without an executable loaded. This commit extends the testsuite to run 'maint selftest' both with and without an executable loaded into GDB. Currently, when no executable is loaded into GDB all of the selftest pass (i.e. the fail count is 0), however, when running with an executable loaded, I am seeing 1 failure (on an x86-64 GNU/Linux host). This failure is from the ARM disassembler tests, it appears that the disassembler somehow gets itself into a state where it thinks it is in thumb mode; when running the same test without an executable loaded this doesn't happen. This commit doesn't fix the ARM disassembler issue, but I thought it was worth adding this anyway, as this will spot if GDB again starts to crash when 'maint selftest' is run. gdb/testsuite/ChangeLog: * gdb.gdb/unittest.c: New file. * gdb.gdb/unittest.exp: Run with and without a binary file loaded into GDB.
2021-06-01gdb/arm: add support for bare-metal core dumpsAndrew Burgess4-1/+226
This commit adds support for bare metal core dumps on the ARM target, and is based off of this patch submitted to the mailing list: https://sourceware.org/pipermail/gdb-patches/2020-October/172845.html Compared to the version linked above this version is updated to take account of recent changes to the core dump infrastructure in GDB, there is now more shared infrastructure for core dumping within GDB, and also some common bare metal core dumping infrastructure. As a result this patch is smaller than the original proposed patch. Further, the original patch included some unrelated changes to the simulator that have been removed from this version. I have written a ChangeLog entry as the original patch was missing one. I have done absolutely no testing of this patch. It is based on the original submitted patch, which I assume was tested, but after my modifications things might have been broken, however, the original patch author has tested this version and reported it as being good: https://sourceware.org/pipermail/gdb-patches/2021-May/178900.html The core dump format is based around generating an ELF containing sections for the writable regions of memory that a user could be using. Which regions are dumped rely on GDB's existing common core dumping code, GDB will attempt to figure out the stack and heap as well as copying out writable data sections as identified by the original ELF. Register information is added to the core dump using notes, just as it is for Linux of FreeBSD core dumps. The note types used consist of the 2 basic types you would expect in a OS based core dump, NT_PRPSINFO, NT_PRSTATUS, along with the architecture specific NT_ARM_VFP note. The data layouts for each note type are described below, in all cases, all padding fields should be set to zero. Note NT_PRPSINFO is optional. Its data layout is: struct prpsinfo_t { uint8_t padding[28]; char fname[16]; char psargs[80]; } Field 'fname' - null terminated string consisting of the basename of (up to the fist 15 characters of) the executable. Any additional space should be set to zero. If there's no executable name then this field can be set to all zero. Field 'psargs' - a null terminated string up to 80 characters in length. Any additional space should be filled with zero. This field contains the full executable path and any arguments passed to the executable. If there's nothing sensible to write in this field then fill it with zero. Note NT_PRSTATUS is required, its data layout is: struct prstatus_t { uint8_t padding_1[12]; uint16_t sig; uint8_t padding_2[10]; uint32_t thread_id; uint8_t padding_3[44]; uint32_t gregs[18]; } Field 'sig' - the signal that stopped this thread. It's implementation defined what this field actually means. Within GDB this will be the signal number that the remote target reports as the stop reason for this thread. Field 'thread_is' - the thread id for this thread. It's implementation defined what this field actually means. Within GDB this will be thread thread-id that is assigned to each remote thread. Field 'gregs' - holds the general purpose registers $a1 through to $pc at indices 0 to 15. At index 16 the program status register. Index 17 should be set to zero. Note NT_ARM_VFP is optional, its data layout is: armvfp_t { uint64_t regs[32]; uint32_t fpscr; } Field 'regs' - holds the 32 d-registers 0 to 31 in order. Field 'fpscr' - holds the fpscr register. The rules for ordering the notes is the same as for Linux. The NT_PRSTATUS note must come before any other notes about additional register sets. And for multi-threaded targets all registers for a single thread should be grouped together. This is because only NT_PRSTATUS includes a thread-id, all additional register notes after a NT_PRSTATUS are assumed to belong to the same thread until a different NT_PRSTATUS is seen. gdb/ChangeLog: PR gdb/14383 * Makefile.in (ALL_TARGET_OBS): Add arm-none-tdep.o. (ALLDEPFILES): Add arm-none-tdep.c * arm-none-tdep.c: New file. * configure.tgt (arm*-*-*): Add arm-none-tdep.o to cpu_obs.
2021-06-01gdb: avoid premature dummy frame garbage collectionAndrew Burgess6-4/+238
Consider the following chain of events: * GDB is performing an inferior call, and * the inferior calls longjmp, and * GDB detects that the longjmp has completed, stops, and enters check_longjmp_breakpoint_for_call_dummy (in breakpoint.c), and * GDB tries to unwind the stack in order to check that the dummy frame (setup for the inferior call) is still on the stack, but * The unwind fails, possibly due to missing debug information, so * GDB incorrectly concludes that the inferior has longjmp'd past the dummy frame, and so deletes the dummy frame, including the dummy frame breakpoint, but then * The inferior continues, and eventually returns to the dummy frame, which is usually (always?) on the stack, the inferior starts trying to execute the random contents of the stack, this results in undefined behaviour. This situation is already warned about in the comment on the function check_longjmp_breakpoint_for_call_dummy where we say: You should call this function only at places where it is safe to currently unwind the whole stack. Failed stack unwind would discard live dummy frames. The warning here is fine, the problem is that, even though we call the function from a location within GDB where we hope to be able to unwind, sometime the state of the inferior means that the unwind will not succeed. This commit tries to improve the situation by adding the following additional check; when GDB fails to find the dummy frame on the stack, instead of just assuming that the dummy frame can be garbage collected, first find the stop_reason for the last frame on the stack. If this stop_reason indicates that the stack unwinding may have failed then we assume that the dummy frame is still in use. However, if the last frame's stop_reason indicates that the stack unwind completed successfully then we can be confident that the dummy frame is no longer in use, and we garbage collect it. Tested on x86-64 GNU/Linux. gdb/ChangeLog: * breakpoint.c (check_longjmp_breakpoint_for_call_dummy): Add check for why the backtrace stopped. gdb/testsuite/ChangeLog: * gdb.base/premature-dummy-frame-removal.c: New file. * gdb.base/premature-dummy-frame-removal.exp: New file. * gdb.base/premature-dummy-frame-removal.py: New file. Change-Id: I8f330cfe0f3f33beb3a52a36994094c4abada07e
2021-05-31gdb: pass signature to allocate_signatured_type and signatured_type constructorSimon Marchi3-28/+34
All signatured_type constucted (even those used only for lookups in hash maps) need a signature. Enforce that by passing the signature all the way to the signatured_type constructor. gdb/ChangeLog: * dwarf2/read.h (struct structured_type) <signatured_type>: New. Update all callers. (struct dwarf2_per_bfd) <allocate_signatured_type>: Add signature parameter, update all callers. * dwar2/read.c (dwarf2_per_bfd::allocate_signatured_type): Add signature parameter. Change-Id: I99bc1f88f54127666aa133ddbbabb7f7668fa14a
2021-05-31gdb: add and use signatured_type_upSimon Marchi3-7/+13
Add an alias for std::unique_ptr<signatured_type> and use it where possible. gdb/ChangeLog: * dwarf2/read.h (signatured_type_up): New, use where possible. Change-Id: I5a41e8345551434c8beeb9f269b03bdcf27989be
2021-05-31gdb: move dwarf2_per_cu_data and signatured_type upSimon Marchi2-215/+221
Move them up before dwarf2_per_bfd, this will allow adding and using signatured_type_up in the next patch. gdb/ChangeLog: * dwarf2/read.h (signatured_type, dwarf2_per_cu_data): Move up. Change-Id: I85acad4476c8236930b6f9e53ddb8bbbad009e5e
2021-05-30Set is_debug_types in allocate_signatured_typeTom Tromey2-4/+9
All callers of allocate_signatured_type set the is_debug_types flag on the result -- in fact, they are required to, because this is the sign that downcasting the object to signatured_type is safe. This patch moves this assignment into the allocation function. 2021-05-30 Tom Tromey <tom@tromey.com> * dwarf2/read.c (dwarf2_per_bfd::allocate_signatured_type): Set is_debug_types. (create_signatured_type_table_from_index) (create_signatured_type_table_from_debug_names, add_type_unit) (read_comp_units_from_section): Update.
2021-05-30Remove dwarf2_per_bfd::m_num_psymtabsTom Tromey3-15/+12
Now that CUs and TUs are stored together in all_comp_units, the m_num_psymtabs member is no longer needed -- it is always identical to the length of the vector. This patch removes it. 2021-05-30 Tom Tromey <tom@tromey.com> * dwarf2/read.h (struct dwarf2_per_bfd) <num_psymtabs, m_num_psymtabs>: Remove. (resize_symtabs): Update. * dwarf2/read.c (dwarf2_per_bfd::allocate_per_cu) (dwarf2_per_bfd::allocate_signatured_type): Update.
2021-05-29Fix InlinedFrameDecorator exampleHannes Domani2-1/+5
Argument fobj was only available in the constructor. gdb/doc/ChangeLog: 2021-05-29 Hannes Domani <ssbssa@yahoo.de> * python.texi (Writing a Frame Filter): Fix example.
2021-05-27gdb: fix tab after space indentation issuesSimon Marchi46-138/+142
I spotted some indentation issues where we had some spaces followed by tabs at beginning of line, that I wanted to fix. So while at it, I did a quick grep to find and fix all I could find. gdb/ChangeLog: * Fix tab after space indentation issues throughout. Change-Id: I1acb414dd9c593b474ae2b8667496584df4316fd
2021-05-27gdb: fix some indentation issuesSimon Marchi27-677/+685
I wrote a small script to spot a pattern of indentation mistakes I saw happened in breakpoint.c. And while at it I ran it on all files and fixed what I found. No behavior changes intended, just indentation and addition / removal of curly braces. gdb/ChangeLog: * Fix some indentation mistakes throughout. gdbserver/ChangeLog: * Fix some indentation mistakes throughout. Change-Id: Ia01990c26c38e83a243d8f33da1d494f16315c6e
2021-05-27gdb: remove iterate_over_bp_locations functionSimon Marchi4-29/+25
Remove it, change users (well, a single one) to use all_bp_locations. This requires moving all_bp_locations to breakpoint.h to expose it. gdb/ChangeLog: * breakpoint.h (iterate_over_bp_locations): Remove. Update users to use all_bp_locations. (all_bp_locations): New. * breakpoint.c (all_bp_locations): Make non-static. (iterate_over_bp_locations): Remove. Change-Id: Iaf1f716d6c2c5b2975579b3dc113a86f5d0975be
2021-05-27gdb: remove iterate_over_breakpoints functionSimon Marchi9-77/+65
Now that we have range functions that let us use ranged for loops, we can remove iterate_over_breakpoints in favor of those, which are easier to read and write. This requires exposing the declaration of all_breakpoints and all_breakpoints_safe in breakpoint.h, as well as the supporting types. Change some users of iterate_over_breakpoints to use all_breakpoints, when they don't need to delete the breakpoint, and all_breakpoints_safe otherwise. gdb/ChangeLog: * breakpoint.h (iterate_over_breakpoints): Remove. Update callers to use all_breakpoints or all_breakpoints_safe. (breakpoint_range, all_breakpoints, breakpoint_safe_range, all_breakpoints_safe): Move here. * breakpoint.c (all_breakpoints, all_breakpoints_safe): Make non-static. (iterate_over_breakpoints): Remove. * python/py-finishbreakpoint.c (bpfinishpy_detect_out_scope_cb): Return void. * python/py-breakpoint.c (build_bp_list): Add comment, reverse return value logic. * guile/scm-breakpoint.c (bpscm_build_bp_list): Return void. Change-Id: Idde764a1f577de0423e4f2444a7d5cdb01ba5e48
2021-05-27gdb: add all_bp_locations_at_addr functionSimon Marchi2-148/+119
Add the all_bp_locations_at_addr function, which returns a range of all breakpoint locations at exactly the given address. This lets us replace: bp_location *loc, **loc2p, *locp; ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) { loc = *loc2p; // use loc } with for (bp_location *loc : all_bp_locations_at_addr (address)) { // use loc } The all_bp_locations_at_addr returns a bp_locations_at_addr_range object, which is really just a wrapper around two std::vector iterators representing the beginning and end of the interesting range. These iterators are found when constructing the bp_locations_at_addr_range object using std::equal_range, which seems a perfect fit for this use case. One thing I noticed about the current ALL_BP_LOCATIONS_AT_ADDR is that if you call it with a NULL start variable, that variable gets filled in and can be re-used for subsequent iterations. This avoids the cost of finding the start of the interesting range again for the subsequent iterations. This happens in build_target_command_list, for example. The same effect can be achieved by storing the range in a local variable, it can be iterated on multiple times. Note that the original comment over ALL_BP_LOCATIONS_AT_ADDR says: Iterates through locations with address ADDRESS for the currently selected program space. I don't see anything restricting the iteration to a given program space, as we iterate over all bp_locations, which as far as I know contains all breakpoint locations, regardless of the program space. So I just dropped that part of the comment. gdb/ChangeLog: * breakpoint.c (get_first_locp_gte_addr): Remove. (ALL_BP_LOCATIONS_AT_ADDR): Remove. Replace all uses with all_bp_locations_at_addr. (struct bp_locations_at_addr_range): New. (all_bp_locations_at_addr): New. (bp_locations_compare_addrs): New. Change-Id: Icc8c92302045c47a48f507b7f1872bdd31d4ba59
2021-05-27gdb: add all_bp_locations functionSimon Marchi2-58/+32
Add the all_bp_locations function to replace the ALL_BP_LOCATIONS macro. For simplicity, all_bp_locations simply returns a const reference to the bp_locations vector. But the callers just treat it as a range to iterate on, so if we ever change the breakpoint location storage, we can change the all_bp_locations function to return some other range type, and the callers won't need to be changed. gdb/ChangeLog: * breakpoint.c (ALL_BP_LOCATIONS): Remove, update users to use all_bp_locations. (all_bp_locations): New. Change-Id: Iae71a1ba135c1a5bcdb4658bf3cf9793f0e9f81c
2021-05-27gdb: make bp_locations an std::vectorSimon Marchi2-58/+40
Change the type of the global location list, bp_locations, to be an std::vector. Adjust the users to deal with that, mostly in an obvious way by using .data() and .size(). The user where it's slightly less obvious is update_global_location_list. There, we std::move the old location list out of the global vector into a local variable. The code to fill the new location list gets simpler, as it's now simply using .push_back(), no need to count the locations beforehand. In the rest of update_global_location_list, the code is adjusted to work with indices instead of `bp_location **`, to iterate on the location list. I believe it's a bit easier to understand this way. But more importantly, when we build with _GLIBCXX_DEBUG, the operator[] of the vector does bound checking, so we will know if we ever access past a vector size (which we won't if we access by raw pointer). I think that work can further be done to make that function easier to understand, notably find better names than "loc" and "loc2" for variables, but that's work for later. gdb/ChangeLog: * breakpoint.c (bp_locations): Change to std::vector, update all users. (bp_locations_count): Remove. (update_global_location_list): Change to work with indices rather than bp_location**. Change-Id: I193ce40f84d5dc930fbab8867cf946e78ff0df0b
2021-05-27gdb: add breakpoint::locations methodSimon Marchi9-101/+83
Add the breakpoint::locations method, which returns a range that can be used to iterate over a breakpoint's locations. This shortens for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) into for (bp_location *loc : b->locations ()) Change all the places that I found that could use it. gdb/ChangeLog: * breakpoint.h (bp_locations_range): New. (struct breakpoint) <locations>: New. Use where possible. Change-Id: I1ba2f7d93d57e544e1f8609124587dcf2e1da037
2021-05-27gdb: add all_tracepoints functionSimon Marchi4-48/+58
Same idea as the previous patches, but to replace the ALL_TRACEPOINTS macro. Define a new filtered_iterator that only keeps the breakpoints for which is_tracepoint returns true (just like the macro did). I would have like to make it so tracepoint_range yields some `tracepoint *` instead of some `breakpoint *`, that would help simplify the callers, who wouldn't have to do the cast themselves. But I didn't find an obvious way to do it. It can always be added later. It turns out there is already an all_tracepoints function, which returns a vector containing all the breakpoints that are tracepoint. Remove it, most users will just work seamlessly with the new function. The exception is start_tracing, which iterated multiple times on the vector. Adapt this one so it iterates multiple times on the returned range. Since the existing users of all_tracepoints are outside of breakpoint.c, this requires defining all_tracepoints and a few supporting types in breakpoint.h. So, move breakpoint_iterator from breakpoint.c to breakpoint.h. gdb/ChangeLog: * breakpoint.h (all_tracepoints): Remove. (breakpoint_iterator): Move here. (struct tracepoint_filter): New. (tracepoint_iterator): New. (tracepoint_range): New. (all_tracepoints): New. * breakpoint.c (ALL_TRACEPOINTS): Remove, replace all users with all_tracepoints. (breakpoint_iterator): Move to header. (all_tracepoints): New. * tracepoint.c (start_tracing): Adjust. Change-Id: I76b1bba4215dbec7a03846c568368aeef7f1e05a
2021-05-27gdb: add all_breakpoints_safe functionSimon Marchi2-68/+47
Same as the previous patch, but intended to replace the ALL_BREAKPOINTS_SAFE macro, which allows deleting the current breakpoint while iterating. The new range type simply wraps the range added by the previous patch with basic_safe_range. I didn't remove the ALL_BREAKPOINTS_SAFE macro, because there is one spot where it's more tricky to remove, in the check_longjmp_breakpoint_for_call_dummy function. More thought it needed for this one. gdb/ChangeLog: * breakpoint.c (breakpoint_safe_range): New. (all_breakpoints_safe): New. Use instead of ALL_BREAKPOINTS_SAFE where possible. Change-Id: Ifccab29f135e1f85700e3697ed60f0b643c7682f
2021-05-27gdb: add all_breakpoints functionSimon Marchi2-119/+78
Introduce the all_breakpoints function, which returns a range that can be used to iterate on breakpoints. Replace all uses of the ALL_BREAKPOINTS macro with this. In one instance, I could replace the breakpoint iteration with a call to get_breakpoint. gdb/ChangeLog: * breakpoint.c (ALL_BREAKPOINTS): Remove, replace all uses with all_breakpoints. (breakpoint_iterator): New. (breakpoint_range): New. (all_breakpoints): New. Change-Id: I229595bddad7c9100b179a9dd56b04b8c206e86c
2021-05-27Add optional full_window argument to TuiWindow.writeHannes Domani4-7/+30
To prevent flickering when first calling erase, then write, this new argument indicates that the passed string contains the full contents of the window. This fills every unused cell of the window with a space, so it's not necessary to call erase beforehand. gdb/ChangeLog: 2021-05-27 Hannes Domani <ssbssa@yahoo.de> * python/py-tui.c (tui_py_window::output): Add full_window argument. (gdbpy_tui_write): Parse "full_window" argument. gdb/doc/ChangeLog: 2021-05-27 Hannes Domani <ssbssa@yahoo.de> * python.texi (TUI Windows In Python): Document "full_window" argument.
2021-05-27gdb: add option to reverse order of _initialize function callsSimon Marchi4-1/+51
An earlier patch in this series fixed a dependency problem between two _initialize functions. That problem was uncovered by reversing the order of the initialize function calls. In short, symtab.c tried to add the alias "maintenance flush-symbol-cache" for the command "maintenance flush symbol-cache". Because the "maintenance flush" prefix command was not yet created (it happens in maint.c, initialized later in this reversed order), the add_alias_cmd function returned NULL. That result was passed to deprecate_cmd, which didn't expected that value, and that caused a segfault. This was fixed by changing alias creation functions to take the target command as a cmd_list_element, instead of by name. This patch adds a runtime option to reverse the order of the initialize calls at will. I chose to use an environment variable for this, over a parameter (even a "maintenance" one), because: - The init functions are called before the early init commands are executed, so we could use -iex to turn this mode on early enough. This is obvious when you remember that commands / parameters are created by initialize funcitions :). - This is not something anybody would want to tweak after startup anyway. gdb/ChangeLog: * make-init-c: Add option to reverse function calls. gdb/testsuite/ChangeLog: * gdb.base/reverse-init-functions.exp: New. Change-Id: I543e609cf526e7cb145a006a794d0e6851b63f45
2021-05-27gdb: add make-init-c scriptSimon Marchi5-27/+82
I would like to modify how the init.c file is generated (its content). But as it is, a shell script with multiple sed invocations in a Makefile target, it's not very maintainable. Replace that with a shell script that does the same, but in a more readable way. The Makefile rule uses the "-" prefix in front of the for loop, I presume to ignore any error coming from the fact that xml-builtin.c and cp-name-parser.c are not found in the srcdir (they are generated source files). I prefer not to blindly ignore errors, so filter these files out of INIT_FILES instead (we already filter out other files). There are no expected meaningful changes to the generated init.c file. Just the _initialize_all_file declaration that is moved down and "void" in parenthesis that is removed. The new regular expression is a bit tighter than the existing one, it requires the init function to be followed by exactly ` ()`. Update bpf-tdep.c accordingly. gdb/ChangeLog: * Makefile.in (INIT_FILES_FILTER_OUT): New. (INIT_FILES): Use INIT_FILES_FILTER_OUT. (stamp-init): Use make-init-c. * bpf-tdep.c (_initialize_bpf_tdep): Remove "void". * silent-rules.mk (ECHO_INIT_C): Change. * make-init-c: New file. Change-Id: I6d6b12cbccf24ab79d1219bff05df01624c684f9
2021-05-27gdb: remove add_alias_cmd overload that accepts a stringSimon Marchi26-214/+260
Same idea as previous patch, but for add_alias_cmd. Remove the overload that accepts the target command as a string (the target command name), leaving only the one that takes the cmd_list_element. gdb/ChangeLog: * command.h (add_alias_cmd): Accept target as cmd_list_element. Update callers. Change-Id: I546311f411e9e7da9302322d6ffad4e6c56df266
2021-05-27gdb: make add_info_alias accept target as a cmd_list_elementSimon Marchi9-29/+43
Same idea as previous patch, but for add_info_alias. gdb/ChangeLog: * command.h (add_info_alias): Accept target as cmd_list_element. Update callers. Change-Id: If830d423364bf42d7bea5ac4dd3a81adcfce6f7a
2021-05-27gdb: make add_com_alias accept target as a cmd_list_elementSimon Marchi22-173/+219
The alias creation functions currently accept a name to specify the target command. They pass this to add_alias_cmd, which needs to lookup the target command by name. Given that: - We don't support creating an alias for a command before that command exists. - We always use add_info_alias just after creating that target command, and therefore have access to the target command's cmd_list_element. ... change add_com_alias to accept the target command as a cmd_list_element (other functions are done in subsequent patches). This ensures we don't create the alias before the target command, because you need to get the cmd_list_element from somewhere when you call the alias creation function. And it avoids an unecessary command lookup. So it seems better to me in every aspect. gdb/ChangeLog: * command.h (add_com_alias): Accept target as cmd_list_element. Update callers. Change-Id: I24bed7da57221cc77606034de3023fedac015150