aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
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
2021-05-27gdb/python: use return values of add_setshow functions in add_setshow_genericSimon Marchi2-67/+71
In add_setshow_generic, we create set/show commands using add_setshow_* functions, then look up the commands by name to set the context pointer. It would be simpler and more efficient to use the return values of the add_setshow_* functions, do that. gdb/ChangeLog: * python/py-param.c (add_setshow_generic): Use return values of add_setshow functions. Change-Id: I04d50736e1001ddb732d81e088468876df9c88ff
2021-05-27gdb: remove unnecessary lookup_cmd when deprecating commandsSimon Marchi4-42/+37
Remove a few instances where we look up a command by name, but could just use the return value of a previous "add command" function call instead. gdb/ChangeLog: * mi/mi-main.c (_initialize_mi_main): * python/py-auto-load.c (gdbpy_initialize_auto_load): * remote.c (_initialize_remote): Change-Id: I6d06f9ca636e340c88c1064ae870483ad392607d
2021-05-27gdb: make add_setshow commands return set_show_commandsSimon Marchi7-264/+221
Some add_set_show commands return a single cmd_list_element, the one for the "set" command. A subsequent patch will need to access the show command's cmd_list_element as well. Change these functions to return a new structure type that holds both pointers. I initially only modified add_setshow_boolean_cmd (the one I needed), but I think it's better to change the whole chain to keep everything in sync. gdb/ChangeLog: * command.h (set_show_commands): New. (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd, add_setshow_filename_cmd, add_setshow_string_cmd, add_setshow_string_noescape_cmd, add_setshow_optional_filename_cmd, add_setshow_integer_cmd, add_setshow_uinteger_cmd, add_setshow_zinteger_cmd, add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd): Return set_show_commands. Adjust callers. * cli/cli-decode.c (add_setshow_cmd_full): Return set_show_commands, remove result parameters, adjust callers. Change-Id: I17492b01b76002d09effc84830f9c6db26f1db7a
2021-05-27Document gdb.SYMBOL_LOC_LABELHannes Domani2-0/+8
Looks like it was missing from the beginning. gdb/doc/ChangeLog: 2021-05-27 Hannes Domani <ssbssa@yahoo.de> * python.texi (Symbols In Python): Document gdb.SYMBOL_LOC_LABEL.
2021-05-27[gdb/symtab] Fix segfault in process_psymtab_comp_unitTom de Vries4-5/+16
When running test-case gdb.dwarf2/dw2-dummy-cu.exp without -readnow, we run into: ... (gdb) file outputs/gdb.dwarf2/dw2-dummy-cu/dw2-dummy-cu^M Reading symbols from outputs/gdb.dwarf2/dw2-dummy-cu/dw2-dummy-cu...^M ERROR: Couldn't load dw2-dummy-cu into GDB (eof). ... The problem is that we're running into a segfault: ... Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. process_psymtab_comp_unit (this_cu=0x2141090, per_objfile=0x1aa4140, want_partial_unit=false, pretend_language=language_minimal) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:7023 7023 switch (reader.comp_unit_die->tag) ... due to reader.comp_unit_die == nullptr: ... (gdb) p reader.comp_unit_die $1 = (die_info *) 0x0 ... Indeed, there's no CU DIE in the test-case: ... $ readelf -wi outputs/gdb.dwarf2/dw2-dummy-cu/dw2-dummy-cu Contents of the .debug_info section: Compilation Unit @ offset 0x0: Length: 0x7 (32-bit) Version: 2 Abbrev Offset: 0x0 Pointer Size: 4 $ ... Fix this by handling reader.comp_unit_die == nullptr in process_psymtab_comp_unit. Update the test-case to trigger this PR, as per PR27920 - "[gdb/testsuite] hardcoding -readnow skips testing of partial symbols". Tested on x86_64-linux. gdb/ChangeLog: 2021-05-27 Tom de Vries <tdevries@suse.de> PR symtab/27919 * dwarf2/read.c (process_psymtab_comp_unit): gdb/testsuite/ChangeLog: 2021-05-27 Tom de Vries <tdevries@suse.de> PR symtab/27919 PR testsuite/27920 * gdb.dwarf2/dw2-dummy-cu.exp: Use maint expand-symtabs instead of -readnow.
2021-05-27[gdb/testsuite] Prevent proc override in gdb-index.expTom de Vries2-2/+9
When running these two test-cases in this specific order we get: ... $ make check 'RUNTESTFLAGS=gdb.dwarf2/gdb-index.exp \ gdb.dwarf2/gdb-add-index-symlink.exp' ... Running gdb.dwarf2/gdb-index.exp ... Running gdb.dwarf2/gdb-add-index-symlink.exp ... FAIL: gdb.dwarf2/gdb-add-index-symlink.exp: gdb-index file created FAIL: gdb.dwarf2/gdb-add-index-symlink.exp: Unable to call \ gdb-add-index with a symlink to a symfile ... The problem is that gdb-index.exp introduces a proc add_gdb_index which overrides the one in lib/gdb.exp and stays active after the test is done. Consequently it's used in gdb-add-index-symlink.exp, which should use the one from lib/gdb.exp. Fix this by renaming proc add_gdb_index in gdb-index.exp. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-05-27 Tom de Vries <tdevries@suse.de> PR testsuite/27921 * gdb.dwarf2/gdb-index.exp (add_gdb_index): Rename to ... (local_add_gdb_index): ... this.
2021-05-27[gdb/symtab] Fix typo in dwarf error messageTom de Vries2-1/+6
Fix "Cannot not" typo in dwarf error message. Tested on x86_64-linux. gdb/ChangeLog: 2021-05-27 Tom de Vries <tdevries@suse.de> * dwarf2/read.c (find_partial_die): Fix "Cannot not" typo in dwarf error.
2021-05-27[gdb/symtab] Fix Dwarf Error: cannot find DIETom de Vries5-11/+21
When loading the debug info package libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug from openSUSE Leap 15.2, we run into a dwarf error: ... $ gdb -q -batch libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug Dwarf Error: Cannot not find DIE at 0x18a936e7 \ [from module libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug] ... The DIE @ 0x18a936e7 does in fact exist, and is part of a CU @ 0x18a23e52. No error message is printed when using -readnow. What happens is the following: - a dwarf2_per_cu_data P is created for the CU. - a dwarf2_cu A is created for the same CU. - another dwarf2_cu B is created for the same CU. - the dwarf2_cu B is set in per_objfile->m_dwarf2_cus, such that per_objfile->get_cu (P) returns B. - P->load_all_dies is set to 1. - all dies are read into the A->partial_dies htab - dwarf2_cu A is destroyed. - we try to find the partial_die for the DIE @ 0x18a936e7 in B->partial_dies. We can't find it, but do not try to load all dies, because P->load_all_dies is already set to 1. - an error message is generated. The question is why we're creating dwarf2_cu A and B for the same CU. The dwarf2_cu A is created here: ... (gdb) bt #0 dwarf2_cu::dwarf2_cu (this=0x79a9660, per_cu=0x23c0b30, per_objfile=0x1ad01b0) at dwarf2/cu.c:38 #1 0x0000000000675799 in cutu_reader::cutu_reader (this=0x7fffffffd040, this_cu=0x23c0b30, per_objfile=0x1ad01b0, abbrev_table=0x0, existing_cu=0x0, skip_partial=false) at dwarf2/read.c:6487 #2 0x0000000000676eb3 in process_psymtab_comp_unit (this_cu=0x23c0b30, per_objfile=0x1ad01b0, want_partial_unit=false, pretend_language=language_minimal) at dwarf2/read.c:7028 ... And the dwarf2_cu B is created here: ... (gdb) bt #0 dwarf2_cu::dwarf2_cu (this=0x885e8c0, per_cu=0x23c0b30, per_objfile=0x1ad01b0) at dwarf2/cu.c:38 #1 0x0000000000675799 in cutu_reader::cutu_reader (this=0x7fffffffcc50, this_cu=0x23c0b30, per_objfile=0x1ad01b0, abbrev_table=0x0, existing_cu=0x0, skip_partial=false) at dwarf2/read.c:6487 #2 0x0000000000678118 in load_partial_comp_unit (this_cu=0x23c0b30, per_objfile=0x1ad01b0, existing_cu=0x0) at dwarf2/read.c:7436 #3 0x000000000069721d in find_partial_die (sect_off=(unknown: 0x18a55054), offset_in_dwz=0, cu=0x0) at dwarf2/read.c:19391 #4 0x000000000069755b in partial_die_info::fixup (this=0x9096900, cu=0xa6a85f0) at dwarf2/read.c:19512 #5 0x0000000000697586 in partial_die_info::fixup (this=0x8629bb0, cu=0xa6a85f0) at dwarf2/read.c:19516 #6 0x00000000006787b1 in scan_partial_symbols (first_die=0x8629b40, lowpc=0x7fffffffcf58, highpc=0x7fffffffcf50, set_addrmap=0, cu=0x79a9660) at dwarf2/read.c:7563 #7 0x0000000000678878 in scan_partial_symbols (first_die=0x796ebf0, lowpc=0x7fffffffcf58, highpc=0x7fffffffcf50, set_addrmap=0, cu=0x79a9660) at dwarf2/read.c:7580 #8 0x0000000000676b82 in process_psymtab_comp_unit_reader (reader=0x7fffffffd040, info_ptr=0x7fffc1b3f29b, comp_unit_die=0x6ea90f0, pretend_language=language_minimal) at dwarf2/read.c:6954 #9 0x0000000000676ffd in process_psymtab_comp_unit (this_cu=0x23c0b30, per_objfile=0x1ad01b0, want_partial_unit=false, pretend_language=language_minimal) at dwarf2/read.c:7057 ... So in frame #9, a cutu_reader is created with dwarf2_cu A. Then a fixup takes us to the following CU @ 0x18aa33d6, in frame #5. And a similar fixup in frame #4 takes us back to CU @ 0x18a23e52. At that point, there's no information available that we're already trying to read that CU, and we end up creating another cutu_reader with dwarf2_cu B. It seems that there are two related problems: - creating two dwarf2_cu's is not optimal - the unoptimal case is not handled correctly This patch addresses the last problem, by moving the load_all_dies flag from dwarf2_per_cu_data to dwarf2_cu, such that it is paired with the partial_dies field, which ensures that the two can be kept in sync. Tested on x86_64-linux. gdb/ChangeLog: 2021-05-27 Tom de Vries <tdevries@suse.de> PR symtab/27898 * dwarf2/cu.c (dwarf2_cu::dwarf2_cu): Add load_all_dies init. * dwarf2/cu.h (dwarf2_cu): Add load_all_dies field. * dwarf2/read.c (load_partial_dies, find_partial_die): Update. * dwarf2/read.h (dwarf2_per_cu_data::dwarf2_per_cu_data): Remove load_all_dies init. (dwarf2_per_cu_data): Remove load_all_dies field.
2021-05-26Revert "gdb: change dwarf_die_debug to bool"Simon Marchi2-12/+7
This was wrong: dwarf_die_debug is used as an integer, for example where it is passed to dump_die. It is documented in the command's help, which I missed the first time. This reverts commit 749369c430d88c4abc9acde5cfc7b5218651de10. Change-Id: I1d09c3da57f8885f4f9fe9f4eae0cf86006e617a
2021-05-26gdb: change dwarf_die_debug to boolSimon Marchi2-7/+12
gdb/ChangeLog: * dwarf2/read.c (dwarf_die_debug): Change type to bool. (_initialize_dwarf2_read): Update. Change-Id: I6d9e2fe4b662409a540acb2c0b82c7d5314d541b
2021-05-26gdb: don't zero-initialize reg_buffer contentsSimon Marchi2-2/+10
The reg_buffer constructor zero-initializes (value-initializes, in C++ speak) the gdb_bytes of the m_registers array. This is not necessary, as these bytes are only meaningful if the corresponding register_status is REG_VALID. If the corresponding register_status is REG_VALID, then they will have been overwritten with the actual register data when reading the registers from the system into the reg_buffer. Fix that by removing the empty parenthesis following the new expression, meaning that the bytes will now be default-initialized, meaning they'll be left uninitialized. For reference, this is explained here: https://en.cppreference.com/w/cpp/language/new#Construction These new expressions were added in 835dcf92618e ("Use std::unique_ptr in reg_buffer"). As mentioned in that commit message, the use of value-initialisation was done on purpose to keep existing behavior, but now there is some data that suggest it would be beneficial not to do it, which is why I suggest changing it. This doesn't make a big difference on typical architectures where the register buffer is not that big. However, on ROCm (AMD GPU), the register buffer is about 65000 bytes big, so the reg_buffer constructor shows up in profiling. If you want to make some tests and profile it on a standard system, it's always possible to change: - m_registers.reset (new gdb_byte[m_descr->sizeof_raw_registers] ()); + m_registers.reset (new gdb_byte[65000] ()); and run a program that constantly hits a breakpoint with a false condition. For example, by doing this change and running the following program: static void break_here () {} int main () { for (int i = 0; i < 100000; i++) break_here (); } with the following GDB incantation: /usr/bin/time ./gdb -nx --data-directory=data-directory -q test -ex "b break_here if 0" -ex r -batch I get, for value-intializing: 11.75user 7.68system 0:18.54elapsed 104%CPU (0avgtext+0avgdata 56644maxresident)k And for default-initializing: 6.83user 8.42system 0:14.12elapsed 108%CPU (0avgtext+0avgdata 56512maxresident)k gdb/ChangeLog: * regcache.c (reg_buffer::reg_buffer): Default-initialize m_registers array. Change-Id: I5071a4444dee0530ce1bc58ebe712024ddd2b158
2021-05-26Introduce htab_delete_entryTom Tromey4-39/+28
In a bigger series I'm working on, it is convenient to have a libiberty hash table that manages objects allocated with 'new'. To make this simpler, I wrote a small template function to serve as a concise wrapper. Then I realized that this could be reused in a few other places. gdb/ChangeLog 2021-05-26 Tom Tromey <tom@tromey.com> * dwarf2/read.c (allocate_type_unit_groups_table) (handle_DW_AT_stmt_list, allocate_dwo_file_hash_table): Use htab_delete_entry. (free_line_header_voidp): Remove. * completer.c (completion_tracker::completion_hash_entry::deleter): Remove. (completion_tracker::discard_completions): Use htab_delete_entry. * utils.h (htab_delete_entry): New template function.
2021-05-25Fix documentation of gdb.SYMBOL_LOC_COMMON_BLOCKHannes Domani2-2/+6
gdb/doc/ChangeLog: 2021-05-25 Hannes Domani <ssbssa@yahoo.de> * python.texi (Symbols In Python): Fix gdb.SYMBOL_LOC_COMMON_BLOCK.
2021-05-24Prevent flickering when redrawing the TUI python windowHannes Domani2-1/+8
tui_win_info::refresh_window first redraws the background window, then tui_wrefresh draws the python text on top of it, which flickers. By using wnoutrefresh for the background window, the actual drawing on the screen is only done once, without flickering. gdb/ChangeLog: 2021-05-24 Hannes Domani <ssbssa@yahoo.de> * python/py-tui.c (tui_py_window::refresh_window): Avoid flickering.
2021-05-24gdb/doc: add '@:' after 'e.g.' to help texinfoAndrew Burgess2-5/+13
Add '@:' after 'e.g.' to let texinfo know that this is not the end of a sentence. This is only needed when there's a space immediately after the last '.'. gdb/doc/ChangeLog: * gdb.texi (Initialization Files): Add '@:' after 'e.g.'. (Source Path): Likewise. (GDB/MI Development and Front Ends): Likewise. (ARM Features): Likewise. (gdb man): Likewise.
2021-05-23[gdb/tdep] Use pid to choose process 64/32-bitnessTom de Vries8-16/+34
In a linux kernel mailing list discussion, it was mentioned that "gdb has this odd thing where it takes the 64-bit vs 32-bit data for the whole process from one thread, and picks the worst possible thread to do it (ie explicitly not even the main thread, ...)" [1]. The picking of the thread is done here in x86_linux_nat_target::read_description: ... /* GNU/Linux LWP ID's are process ID's. */ tid = inferior_ptid.lwp (); if (tid == 0) tid = inferior_ptid.pid (); /* Not a threaded program. */ ... To understand what this code does, let's investigate a scenario in which inferior_ptid.lwp () != inferior_ptid.pid (). Say we start exec jit-attach-pie, identified with pid x. The main thread starts another thread that sleeps, and then the main thread waits for the sleeping thread. So we have two threads, identified with LWP IDs x and x+1: ... PID LWP CMD x x ./jit-attach-pie x x+1 ./jit-attach-pie ... [ The thread with LWP x is known as the thread group leader. ] When attaching to this exec using the pid, gdb does a stop_all_threads which iterates over all the threads, first LWP x, and then LWP x+1. So the state we arrive with at x86_linux_nat_target::read_description is: ... (gdb) p inferior_ptid $1 = {m_pid = x, m_lwp = x+1, m_tid = 0} ... and consequently we probe 64/32-bitness from thread LWP x+1. [ Note that this is different from when gdb doesn't attach but instead launches the exec itself, in which case there's just one thread to begin with, and consequently the probed thread is LWP x. ] According to aforementioned remark, a better choice would have been the main thread, that is, LWP x. This patch implement that choice, by simply doing: ... tid = inferior_ptid.pid (); ... The fact that gdb makes a per-process permanent choice for 64/32-bitness is a problem in itself: each thread can be in either 64 or 32 bit mode, and change forth and back. That is a problem that this patch doesn't fix. Now finally: why does this matter in the context of the linux kernel discussion? The discussion was related to a patch that exposed io_uring threads to user-space. This made it possible that one of those threads would be picked out to select 64/32-bitness. Given that such threads are atypical user-space threads in the sense that they don't return to user-space and don't have a userspace register state, reading their registers returns garbage, and so it could f.i. occur that in a 64-bit process with all normal user-space threads in 64-bit mode, the probing would return 32-bit. It may be that this is worked-around on the kernel side by providing userspace register state in those threads such that current gdb is happy. Nevertheless, it seems prudent to fix this on the gdb size as well. Tested on x86_64-linux. [1] https://lore.kernel.org/io-uring/CAHk-=wh0KoEZXPYMGkfkeVEerSCEF1AiCZSvz9TRrx=Kj74D+Q@mail.gmail.com/ gdb/ChangeLog: 2021-05-23 Tom de Vries <tdevries@suse.de> PR tdep/27822 * target.h (struct target_ops): Mention target_thread_architecture in read_description comment. * x86-linux-nat.c (x86_linux_nat_target::read_description): Use pid to determine if process is 64-bit or 32-bit. * aarch64-linux-nat.c (aarch64_linux_nat_target::read_description): Same. * ppc-linux-nat.c (ppc_linux_nat_target::read_description): Same. * riscv-linux-nat.c (riscv_linux_nat_target::read_description): Same. * s390-linux-nat.c (s390_linux_nat_target::read_description): Same. * arm-linux-nat.c (arm_linux_nat_target::read_description): Same. Likewise, use pid to determine if kernel supports reading VFP registers.
2021-05-22Fix option type comments for CMDARG_EARLYINIT_FILE and CMDARG_EARLYINIT_COMMAND.Philippe Waroquiers2-3/+8
The comments in the enum cmdarg_kind were using -sx and -sex instead of -eix and -eiex. (Note that gdb --help does not speak about these options). (pushed as obvious)
2021-05-21[gdb/testsuite] Add target board cc-with-gnu-debuglink.expTom de Vries4-1/+81
Add target board cc-with-gnu-debuglink.exp that splits off debuginfo into a seperate .debug file and links to it using .gnu_debuglink. Tested on x86_64-linux. gdb/ChangeLog: 2021-05-21 Tom de Vries <tdevries@suse.de> PR testsuite/25047 * contrib/cc-with-tweaks.sh: Handle -l. gdb/testsuite/ChangeLog: 2021-05-21 Tom de Vries <tdevries@suse.de> PR testsuite/25047 * boards/cc-with-gnu-debuglink.exp: New file.
2021-05-21testsuite/gdb.dwarf2: avoid dead code in dw2-inline-with-lexical-scope.cTankut Baris Aktemur2-2/+8
The test in gdb.dwarf2/dw2-inline-with-lexical-scope.c fails with icc. The reason is, icc did not emit code for a dead statement, which in turn caused some labels to be collapsed. Fix this by replacing the dead code with assignment to a global value. The statement itself does not change the test scenario. Also fix a whitespacing problem around an assignment operator. gdb/testsuite/ChangeLog: 2021-05-21 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.dwarf2/dw2-inline-with-lexical-scope.c (func): Replace a dead code with an assignment to a global var. Fix a whitespacing problem around an assignment operator.
2021-05-21[gdb/breakpoint] Fix assert in jit_event_handlerTom de Vries2-1/+11
Consider a minimal test-case test.c: ... int main (void) { return 0; } ... which we can compile into llvm byte code using clang: ... $ clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf test.c ... and then run using lli, which uses the llvm jit: ... $ lli test.ll ... If we run this under gdb, we run into an assert: ... $ gdb -q -batch -ex run --args /usr/bin/lli test.ll Dwarf Error: Cannot not find DIE at 0x18a936e7 \ [from module libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". src/gdb/jit.c:1178: internal-error: \ void jit_event_handler(gdbarch*, objfile*): \ Assertion `jiter->jiter_data != nullptr' failed. ... This is caused by the following. When running jit_breakpoint_re_set_internal, we first handle libLLVM.so.10.debug, and set a jit breakpoint. Next we handle libLLVM.so.10: ... (gdb) p the_objfile.original_name $42 = 0x2494170 "libLLVM.so.10" ... but the minimal symbols we find are from libLLVM.so.10.debug: ... (gdb) p reg_symbol.objfile.original_name $43 = 0x38e7c50 "libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug" (gdb) p desc_symbol.objfile.original_name $44 = 0x38e7c50 "libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug" ... and consequently, the objf_data is the one from libLLVM.so.10.debug: ... jiter_objfile_data *objf_data = get_jiter_objfile_data (reg_symbol.objfile); ... and so we hit this: ... if (objf_data->cached_code_address == addr) continue; ... and no second jit breakpoint is inserted. Subsequently, the jit breakpoint is triggered and handled, but when finding the symbol for the breakpoint address we get: ... (gdb) p jit_bp_sym.objfile.original_name $52 = 0x2494170 "libLLVM.so.10" ... The assert 'jiter->jiter_data != nullptr' triggers because it checks libLLVM.so.10 while the one with jiter_data setup is libLLVM.so.10.debug. This fixes the assert: ... jiter_objfile_data *objf_data - = get_jiter_objfile_data (reg_symbol.objfile); - = get_jiter_objfile_data (the_objfile); ... but consequently we'll have two jit breakpoints, so we also make sure we don't set a jit breakpoint on separate debug objects like libLLVM.so.10.debug. Tested on x86_64-linux. gdb/ChangeLog: 2021-05-21 Tom de Vries <tdevries@suse.de> PR breakpoint/27889 * jit.c (jit_breakpoint_re_set_internal): Skip separate debug objects. Call get_jiter_objfile_data with the_objfile.
2021-05-20gdb: remove linespec_p typedefSimon Marchi2-12/+16
I guess this was used with the old VEC implementation, but there is no reason to have this typedef anymore. gdb/ChangeLog: * linespec.c (linespec_p): Remove. Replace all uses with "linespec *". Change-Id: I4cea59ae1cd46985da9c08d3a69686846b1ad028
2021-05-20cli-script: use unique_ptr to not leak next structAlexandra Hájková3-36/+55
In cli/cli-script.c, process_next_line() allocates memory which will eventually end up being assigned to the 'next' field in struct command_line. However, in a case recurse_read_control_structure returns 'invalid_control' this memory is leaked. This commit uses std::unique_ptr as appropriate to prevent this leakage. This issue was found by coverity scanning. gdb/ChangeLog: * cli/cli-script.h (command_line_up): New unique_ptr typedef. * cli/cli-script.c (multi_line_command_p): Use unique_ptr command_line_up instead of struct command_line. (build_command_line): Likewise. (get_command_line): Update the cmd function call parameter. (process_next_line): Use unique_ptr command_line_up instead of struct command_line. (recurse_read_control_structure): Change the the type of next to command_line_up. (read_command_lines_1): Change type of `next' to be command_line_up and update all references of `next' accordingly.
2021-05-20Add myself to gdb/MAINTAINERSAlexandra Hájková2-0/+5
gdb/ChangeLog: * MAINTAINERS (Write After Approval): Add myself.
2021-05-20Clean up my ChangeLog entryAlexandra Hájková1-5/+4