aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
AgeCommit message (Collapse)AuthorFilesLines
2024-11-11Wrap help strings at 80 columnsTom Tromey1-4/+5
This patch ensures that all ordinary help strings are wrapped at 80 columns. For the most part this consists of changing code like this (note the embedded \n and the trailing backslash without a newline): -Manage the space-separated list of debuginfod server URLs that GDB will query \ -when missing debuginfo, executables or source files.\nThe default value is \ -copied from the DEBUGINFOD_URLS environment variable."), ... to end each line with \n\, like: +Manage the space-separated list of debuginfod server URLs that GDB will\n\ +query when missing debuginfo, executables or source files.\n\ +The default value is copied from the DEBUGINFOD_URLS environment variable."), Approved-By: Eli Zaretskii <eliz@gnu.org>
2024-11-08gdb: make the error message for unreadable objfiles more informativeGuinevere Larsen1-2/+2
When GDB is unable to read an objfile, it prints the error message "I'm sorry Dave, I can't do that. Symbol format `%s' unknown.". While it is a great reference, an end user won't have much information about the problem. So far this wasn't much of a problem, as it is very uncommon for GDB to be unable to read an objfile. However, a future patch will allow users to selectively disable support to some formats, making it somewhat expected that the message will be seen by end users. This commit makes the end message more informative and direct. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13299 Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/symtab] Don't expand non-Ada CUs for info exceptionsTom de Vries1-2/+4
I noticed when running test-case gdb.ada/info_exc.exp with glibc debug info installed, that the "info exceptions" command that lists all Ada exceptions also expands non-Ada CUs, which includes CUs in /lib64/ld-linux-x86-64.so.2 and /lib64/libc.so.6. Fix this by: - adding a new lang_matcher parameter to the expand_symtabs_matching function, and - using that new parameter in the expand_symtabs_matching call in ada_add_global_exceptions. The new parameter is a hint, meaning implementations are free to ignore it and expand CUs with any language. This is the case for partial symtabs, I'm not sure whether it makes sense to implement support for this there. Conversely, when processing a CU with language C and name "<artificial>" (as produced by GCC LTO), the CU may not really have a single language and we should ignore the lang_matcher. See also commit d2f67711730 ("Fix 'catch exception' with -flto"). Now that we have lang_matcher available, also use it to limit name splitting styles and symbol matchers to those applicable to the matched languages. Without this patch we have (with a gdb build with -O0): ... $ time gdb -q -batch -x outputs/gdb.ada/info_exc/gdb.in.1 > /dev/null real 0m1.866s user 0m2.089s sys 0m0.120s ... and with this patch we have: ... $ time gdb -q -batch -x outputs/gdb.ada/info_exc/gdb.in.1 > /dev/null real 0m0.469s user 0m0.777s sys 0m0.051s ... Or, to put it in terms of number of CUs, we have 1853 CUs: ... $ gdb -q -batch -readnow outputs/gdb.ada/info_exc/foo \ -ex start \ -ex "maint info symtabs" \ | grep -c " name " 1853 ... Without this patch, we have: ... $ gdb -q -batch outputs/gdb.ada/info_exc/foo \ -ex start \ -ex "info exceptions" \ -ex "maint info symtabs" \ | grep -c " name " 1393 ... so ~75% of the CUs is expanded, and with this patch we have: ... $ gdb <same-as-above> 20 ... so ~1% of the CUs is expanded. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR symtab/32182 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32182
2024-09-07gdb: add remove-symbol-file command completionAndrew Burgess1-29/+85
The 'remove-symbol-file' command doesn't currently offer command completion. This commit addresses this. The 'remove-symbol-file' uses gdb_argv to split its command arguments, this means that the filename the command expects can be quoted. However, the 'remove-symbol-file' command is a little weird in that it also has a '-a' option, if this option is passed then the command expects not a filename, but an address. Currently the remove_symbol_file_command function splits the command args using gdb_argv, checks for a '-a' flag by looking at the first argument value, and then expects the filename or address to occupy a single entry in the gdb_argv array. The first thing I do is handle the '-a' flag using GDB's option system. I model this option as a flag_option_def (a boolean option). I've dropped the use of gdb_argv and instead use the new(ish) function extract_single_filename_arg, which was added a couple of commits back, to parse the filename argument (when '-a' is not given). If '-a' is given the the remove-symbol-file command expects an address rather than a filename. As we previously split the arguments using gdb_argv this meant the address needed to appear as a single argument. So a user could write: (gdb) remove-symbol-file 0x1234 Or they could write: (gdb) remove-symbol-file some_function Both of these would work fine. But a user could not write: (gdb) remove-symbol-file some_function + 0x1000 As only the 'some_function' part would be processed. Now the user could do this: (gdb) remove-symbol-file "some_function + 0x1000" By enclosing the address expression in quotes this would be handled as a single argument. However, this is a little weird, that's not how commands like 'print' or 'x' work. Also this functionality was neither documented, or tested. And so, in this commit, by removing the use of gdb_argv I bring the 'remove-symbol-file' command inline with GDB's other commands that take an expression, the quotes are no longer needed. Usually in a completer we call 'complete_options', but don't actually capture the option values. But for remove-symbol-file I do. This allows me to spot when the '-a' option has been given, I can then complete the rest of the command line as either a filename or an expression. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-09-07gdb: deprecated filename_completer and associated functionsAndrew Burgess1-1/+1
Following on from the previous commit, this commit marks the old unquoted filename completion related functions as deprecated. The aim of doing this is to make it more obvious to someone adding a new command that they should not be using the older unquoted style filename argument handling. I split this change from the previous to make for an easier review. This commit touches more files, but is _just_ function renaming. Check out gdb/completer.{c,h} for what has been renamed. All the other files have just been updated to use the new names. There should be no user visible changes after this commit.
2024-09-07gdb: split apart two different types of filename completionAndrew Burgess1-2/+2
Unfortunately we have two different types of filename completion in GDB. The majority of commands have what I call unquoted filename completion, this is for commands like 'set logging file ...', 'target core ...', and 'add-auto-load-safe-path ...'. For these commands everything after the command name (that is not a command option) is treated as a single filename. If the filename contains white space then this does not need to be escaped, nor does the filename need to be quoted. In fact, the filename argument is not de-quoted, and does not have any escaping removed, so if a user does try to add such things, they will be treated as part of the filename. As an example: (gdb) target core "/path/that contains/some white space" Will look for a directory calls '"' (double quotes) in the local directory. A small number of commands do de-quote and remove escapes from filename arguments. These command accept what I call quoted and escaped filenames. Right now these are the commands that specify the file for GDB to debug, so: file exec-file symbol-file add-symbol-file remove-symbol-file As an example of this in action: (gdb) file "/path/that contains/some white space" In this case GDB would load the file: /path/that contains/some white space Current filename completion always assumes that filenames can be quoted, though escaping doesn't work in completion right now. But the assumption that quoting is allowed is clearly wrong. This commit splits filename completion into two. The existing filename_completer is retained, and is used for unquoted filenames. A second filename_maybe_quoted_completer is added which can be used for completing quoted filenames. The filename completion test has been extended to cover more cases. As part of the extended testing I need to know the character that should be used to separate filenames within a path. For this TCL 8.6+ has $::tcl_platform(pathSeparator). To support older versions of TCL I've added some code to testsuite/lib/gdb.exp. You might notice that after this commit the completion for unquoted files is all done in the brkchars phase, that is the function filename_completer_handle_brkchars calculates the completions and marks the completion_tracker as using a custom word point. The reason for this is that we don't want to break on white space for this completion, but if we rely on readline to find the completion word, readline will consider the entire command line, and with no white space in the word break character set, readline will end up using the entire command line as the word to complete. For now at least, the completer for quoted filenames does generate its completions during the completion phase, though this is going to change in a later commit.
2024-08-19gdb: fix a target: prefix issue in find_separate_debug_fileAndrew Burgess1-18/+7
Following on from the previous commit, this commit fixes the two KFAIL in gdb.base/sysroot-debug-lookup.exp when not using the native-extended-gdbserver board. The failures in this test, when using the 'unix' board, are logged as bug PR gdb/31804. The problem appears to be caused by the use of the child_path function in find_separate_debug_file. What happens on the 'unix' board is that the file is specified to GDB with a target: prefix, however GDB spots that the target filesystem is local to GDB and so opens the file without a target: prefix. When we call into find_separate_debug_file the DIR and CANON_DIR arguments, which are computed from the objfile_name() no longer have a target: prefix. However, in this test if the file was opened with a target: prefix, then the sysroot also has a target: prefix. When child_path is called it looks for a common prefix between CANON_DIR (from the objfile_name) and the sysroot. However, the sysroot still has the target: prefix, which means the child_path() call fails and returns nullptr. What I think we need to do is this: if the sysroot has a target: prefix, and the target filesystem is local to GDB, then we should strip the target: prefix from the sysroot, just as we do when opening a file (see gdb_bfd_open in gdb_bfd.c). Now, when we make the child_path() call neither the sysroot nor CANON_DIR will have a target: prefix, the child_path() call will succeed, and GDB will correctly find the debug information. There is just one remaining issue, the last path we look in when searching for debug information is built by starting with the sysroot, then adding the debug directory, see this line: debugfile = path_join (target_prefix_str, root.c_str (), debugdir.get (), base_path, debuglink); The target_prefix_str is set to target: if DIR has a target: prefix, and DIR should have a target: prefix if the file we're looking for was opened with a target: prefix. However, in our case the file was in a local filesystem so GDB stripped the prefix off. The sysroot however, does have the target: prefix, and the test is expecting to see GDB look within a file with the target: prefix. Given that the above line is about looking within a sub-directory of the sysroot, I think we should not be stripping the target: prefix off the sysroot path (as we do when building ROOT), instead, we should, in this case, not use TARGET_PREFIX_STR, and instead just use GDB's sysroot as it is (in this case with the target: prefix). With these fixes in place I now see no failures when using the 'unix', 'native-gdbserver', or 'native-extended-gdbserver' boards with this test, and the KFAILs can be removed. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31804
2024-08-19gdb: avoid '//' in filenames when searching for debuginfoAndrew Burgess1-28/+13
I spotted that the gdb.base/sysroot-debug-lookup.exp test that I added recently actually had a KPASS when run with the native-extended-gdbserver board. This was an oversight when adding the test. The failures in this test, when using the 'unix' board, are logged as bug PR gdb/31804. The problem appears to be caused by the use of the child_path function in find_separate_debug_file. What happens on the 'unix' board is that the file is specified to GDB with a target: prefix, however GDB spots that the target filesystem is local to GDB and so opens the file without a target: prefix. When we call into find_separate_debug_file the DIR and CANON_DIR arguments, which are computed from the objfile_name() no longer have a target: prefix. However, in this test if the file was opened with a target: prefix, then the sysroot also has a target: prefix. When child_path is called it looks for a common prefix between CANON_DIR (from the objfile_name) and the sysroot. However, the sysroot still has the target: prefix, which means the child_path() call fails and returns nullptr. What happens in the native-extended-gdbserver case is that GDB doesn't see the target filesystem as local. Now the filename retains the target: prefix, which means that in the child_path() call both the sysroot and the CANON_DIR have a target: prefix, and so the child_path() call succeeds. This allows GDB to progress, try some additional paths, and then find the debug information. So, this commit changes gdb.base/sysroot-debug-lookup.exp to expect the test to succeed when using the native-extended-gdbserver protocol. This leaves one KFAIL when using the native-extended-gdbserver board, we find the debug information but (apparently) find it in the wrong file. What's happening is that when GDB builds the filename for the debug information we end up with a '//' string as a directory separator, the test regexp only expects a single separator. Instead of just fixing the test regexp, I've updated the path_join function in gdbsupport/pathstuff.{cc,h} to allow for absolute paths to appear in the argument list after the first argument. This means it's now possible to do this: auto result = path_join ("/a/b/c", "/d/e/f"); gdb_assert (result == "/a/b/c/d/e/f"); Additionally I've changed path_join so that it avoids adding unnecessary directory separators. In the above case when the two paths were joined GDB only added a single separator between 'c' and 'd'. But additionally, if we did this: auto result = path_join ("/a/b/c/", "/d/e/f"); gdb_assert (result == "/a/b/c/d/e/f"); We'd still only get a single separator. With these changes to path_join I can now make use of this function in find_separate_debug_file. With this done I now have no KFAIL when using the native-extended-gdbserver board. After this commit we still have 2 KFAIL when not using the native-gdbserver and unix boards, these will be addressed in the next commit. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31804 Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-08-12gdb: add program_space parameter to lookup_minimal_symbolSimon Marchi1-3/+6
>From what I can see, lookup_minimal_symbol doesn't have any dependencies on the global current state other than the single reference to current_program_space. Add a program_space parameter and make that current_program_space reference bubble up one level. Change-Id: I759415e2f9c74c9627a2fe05bd44eb4147eee6fe Reviewed-by: Keith Seitz <keiths@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12gdb: remove lookup_bound_minimal_symbolSimon Marchi1-2/+1
Now that lookup_minimal_symbol has default values for sfile and objf, calling lookup_bound_minimal_symbol is identical to calling lookup_minimal_symbol without sfile and objf. Remove lookup_bound_minimal_symbol, replace call sites with lookup_minimal_symbol. Change-Id: I0a420fb56de1de8bee8a7303228c9e4546e3577b Reviewed-by: Keith Seitz <keiths@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12gdb: make lookup_minimal_symbol objf and sfile parameters optionalSimon Marchi1-4/+2
Most calls to lookup_minimal_symbol don't pass a value for sfile and objf. Make these parameters optional (have a default value of nullptr). And since passing a value to `objf` is much more common than passing a value to `sfile`, swap the order so `objf` comes first, to avoid having to pass a nullptr value to `sfile` when wanting to pass a value to `objf`. Change-Id: I8e9cc6b942e593bec640f9dfd30f62786b0f5a27 Reviewed-by: Keith Seitz <keiths@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12gdb: drop struct keyword when using bound_minimal_symbolSimon Marchi1-5/+5
This is a simple find / replace from "struct bound_minimal_symbol" to "bound_minimal_symbol", to make things shorter and more consisten througout. In some cases, move variable declarations where first used. Change-Id: Ica4af11c4ac528aa842bfa49a7afe8fe77a66849 Reviewed-by: Keith Seitz <keiths@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-07-15gdb: pass program space to overlay_invalidate_allSimon Marchi1-7/+5
Make the current program space bubble up one level. Change-Id: I5ac1e3290ad266730465cd60aa3672d45ffa6475
2024-07-15gdb: pass program space to objfile::makeSimon Marchi1-2/+3
Make the current program space reference bubble up one level. Change-Id: Iee8b11c853c76e539c991c4785737c69e6a1925c Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: pass program space to objfiles_changedSimon Marchi1-1/+1
Make the current program space reference bubble up one level. Change-Id: I9b33c9e0d22c171eb1bb59ce480621b02c7b7bf7 Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: pass program space to have_{full,partial}_symbolsSimon Marchi1-3/+5
Make the current program space reference bubble up one level. Change-Id: I19c4fc2ca955f9c828ef426a077b43983865697b Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: pass program space to clear_current_source_symtab_and_lineSimon Marchi1-1/+1
Make the current program space reference bubble up one level. Change-Id: I692554474d17e4f4708fd8ad662bf6c0bb964726 Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: pass program space to no_shared_librariesSimon Marchi1-1/+1
Make the current program space reference bubble up one level. Pass `current_program_space` everywhere, except in some cases where we can get the pspace another way, and it's relatively obvious that it's the same as the current program space. Change-Id: Id86b79f1e44f92a398f49d137d57457174dfa96d Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: split no_shared_libraries, command vs implementationSimon Marchi1-1/+1
The `no_shared_libraries` function is currently used to implement the `nosharedlibrary` command, but it also used internally by other functions. This does not make a very good internal API. Add the `no_shared_libraries_command` function to implement the CLI command. Remove the unused parameters from `no_shared_libraries`. Remove the `from_tty` parameter of `target_pre_inferior`, since it's now unused. Change-Id: I4fcba5ee1e0f7d250aab1a7b62b9ea16265fe962 Approved-By: Tom Tromey <tom@tromey.com> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15gdb: make objfile::pspace privateSimon Marchi1-3/+3
Rename to m_pspace, add getter. An objfile's pspace never changes, so no setter is necessary. Change-Id: If4dfb300cb90dc0fb9776ea704ff92baebb8f626
2024-06-24Rename symtab::fullnameTom Tromey1-1/+0
This renames symtab::fullname to m_fullname and adds new accessor methods.
2024-06-11gdb: convert separate-debug-file to new(ish) debug schemeAndrew Burgess1-29/+16
Convert 'set/show debug separate-debug-file' to the new debug scheme. Though I'm not sure if we can really call it "new" any more! Approved-By: Tom Tromey <tom@tromey.com>
2024-06-07gdb: remove get_exec_fileSimon Marchi1-1/+3
I believe that the get_exec_file function is unnecessary, and the code can be simplified if we remove it. Consider for instance when you "run" a program on Linux with native debugging. 1. run_command_1 obtains the executable file from `current_program_space->exec_filename ()` 2. it passes it to `run_target->create_inferior()`, which is `inf_ptrace_target::create_inferior()` in this case, which then passes it to `fork_inferior()` 3. `fork_inferior()` then has a fallback, where if the passed exec file is nullptr, it gets its from `get_exec_file()`. 4. `get_exec_file()` returns `current_program_space->exec_filename ()` - just like the things we started with - or errors out if the current program space doesn't have a specified executable. If there's no exec filename passed in step 1, there's not going to be any in step 4, so it seems pointless to call `get_exec_file()`, we could just error out when `exec_file` is nullptr. But we can't error out directly in `fork_inferior()`, since the error is GDB-specific, and that function is shared with GDBserver. Speaking of GDBserver, all code paths that lead to `fork_inferior()` provide a non-nullptr exec file. Therefore, to simplify things: - Make `fork_inferior()` assume that the passed exec file is not nullptr, don't call `get_exec_file()` - Change some targets (darwin-nat, go32-nat, gnu-nat, inf-ptrace, nto-procfs, procfs) to error out when the exec file passed to their create_inferior method is nullptr. Some targets are fine with a nullptr exec file, so we can't check that in `run_command_1()`. - Add the `no_executable_specified_error()` function, which re-uses the error message that `get_exec_file()` had. - Change some targets (go32-nat, nto-procfs) to not call `get_exec_file()`, since it's pointless for the same reason as in the example above, if it returns, it's going the be the same value as the `exec_file` parameter. Just rely on `exec_file`. - Remove the final use of `get_exec_file()`, in `load_command()`. - Remove the `get_exec_file()` implementations in GDB and GDBserver and remove the shared declaration. Change-Id: I601c16498e455f7baa1f111a179da2f6c913baa3 Approved-By: Tom Tromey <tom@tromey.com>
2024-06-07gdb: replace `get_exec_file (0)` calls with ↵Simon Marchi1-1/+1
`current_program_space->exec_filename ()` Calls of `get_exec_file (0)` are equivalent to just getting the exec filename from the current program space. I'm looking to remove `get_exec_file`, so replace these uses with `current_program_space->exec_filename ()`. Remove the `err` parameter of `get_exec_wrapper` since all the calls that remain pass 1, meaning to error out if no executable is specified. Change-Id: I7729ea4c7f03dbb046211cc5aa3858ab3a551965 Approved-By: Tom Tromey <tom@tromey.com>
2024-05-30gdb: remove unused includes in symfile.cSimon Marchi1-9/+1
Remove some includes reported as unused by clangd. Change-Id: Iebd986eaf42409f1e526f09df0fcb0ce45c2fad6
2024-04-25gdb: remove gdbcmd.hSimon Marchi1-1/+1
Most files including gdbcmd.h currently rely on it to access things actually declared in cli/cli-cmds.h (setlist, showlist, etc). To make things easy, replace all includes of gdbcmd.h with includes of cli/cli-cmds.h. This might lead to some unused includes of cli/cli-cmds.h, but it's harmless, and much faster than going through the 170 or so files by hand. Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f Approved-By: Tom Tromey <tom@tromey.com>
2024-04-23gdb: move symbol_file_command declaration to symfile.hSimon Marchi1-13/+1
Move it out of defs.h, the corresponding definition is in symfile.c. Change-Id: I984666c3bcd213f8574e9ec91462e1d61f77f16b Approved-By: Tom Tromey <tom@tromey.com>
2024-04-22gdb: move store/extract integer functions to extract-store-integer.{c,h}Simon Marchi1-0/+1
Move the declarations out of defs.h, and the implementations out of findvar.c. I opted for a new file, because this functionality of converting integers to bytes and vice-versa seems a bit to generic to live in findvar.c. Change-Id: I524858fca33901ee2150c582bac16042148d2251 Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-03-26gdb, gdbserver, gdbsupport: remove includes of early headersSimon Marchi1-1/+0
Now that defs.h, server.h and common-defs.h are included via the `-include` option, it is no longer necessary for source files to include them. Remove all the inclusions of these files I could find. Update the generation scripts where relevant. Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837 Approved-By: Pedro Alves <pedro@palves.net>
2024-02-20Add obj_section::contains methodTom Tromey1-2/+1
I noticed a number of spots checking whether an address is in an obj_section. This patch introduces a new method for this and changes some code to use it. Regression tested on x86-64 Fedora 38. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-01-28Use domain_search_flags in lookup_symbol et alTom Tromey1-2/+2
This changes lookup_symbol and associated APIs to accept domain_search_flags rather than a domain_enum. Note that this introduces some new constants to Python and Guile. I chose to break out the documentation patch for this, because the internals here do not change until a later patch, and it seemed simpler to patch the docs just once, rather than twice.
2024-01-28Use domain_search_flags in lookup_global_symbol_languageTom Tromey1-3/+2
This changes quick_symbol_functions::lookup_global_symbol_language to accept domain_search_flags rather than just a domain_enum, and fixes up the fallout. To avoid introducing any regressions, any code passing VAR_DOMAIN now uses SEARCH_VFT. That is, no visible changes should result from this patch. However, it sets the stage to refine some searches later on.
2024-01-28Replace search_domain with domain_search_flagsTom Tromey1-1/+1
This patch changes gdb to replace search_domain with domain_search_flags everywhere. search_domain is removed.
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess1-1/+1
This commit is the result of the following actions: - Running gdb/copyright.py to update all of the copyright headers to include 2024, - Manually updating a few files the copyright.py script told me to update, these files had copyright headers embedded within the file, - Regenerating gdbsupport/Makefile.in to refresh it's copyright date, - Using grep to find other files that still mentioned 2023. If these files were updated last year from 2022 to 2023 then I've updated them this year to 2024. I'm sure I've probably missed some dates. Feel free to fix them up as you spot them.
2024-01-08Lazy language settingTom Tromey1-5/+13
When gdb starts up with a symbol file, it uses the program's "main" to decide the "static context" and the initial language. With background DWARF reading, this means that gdb has to wait for a significant amount of DWARF to be read synchronously. This patch introduces lazy language setting. The idea here is that in many cases, the prompt can show up early, making gdb feel more responsive.
2024-01-08Remove two quick_symbol_functions methodsTom Tromey1-4/+0
quick_symbol_functions::read_partial_symbols is no longer implemented, so both it and quick_symbol_functions::can_lazily_read_symbols can be removed. This allows for other functions to be removed as well. Note that SYMFILE_NO_READ is now pretty much dead. I haven't removed it here -- but could if that's desirable. I tend to think that this functionality would be better implemented in the core; but whenever I dive into the non-DWARF readers it is pretty depressing.
2023-12-11Use TARGET_SYSROOT_PREFIX in more placesTom Tromey1-8/+10
I found some spots using "target:"; I think it's better to use the define everywhere, so this changes these to use TARGET_SYSROOT_PREFIX. In some spots, is_target_filename is used rather than an explicit check. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-11-29Use C++17 [[fallthrough]] attributeTom Tromey1-1/+1
This changes gdb to use the C++17 [[fallthrough]] attribute rather than special comments. This was mostly done by script, but I neglected a few spellings and so also fixed it up by hand. I suspect this fixes the bug mentioned below, by switching to a standard approach that, presumably, clang supports. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159 Approved-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Replace gdb::optional with std::optionalLancelot Six1-1/+1
Since GDB now requires C++17, we don't need the internally maintained gdb::optional implementation. This patch does the following replacing: - gdb::optional -> std::optional - gdb::in_place -> std::in_place - #include "gdbsupport/gdb_optional.h" -> #include <optional> This change has mostly been done automatically. One exception is gdbsupport/thread-pool.* which did not use the gdb:: prefix as it already lives in the gdb namespace. Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-20gdb: move all bfd_cache_close_all calls in gdb_bfd.cAndrew Burgess1-1/+0
In the following commit I ran into a problem. The next commit aims to improve GDB's handling of the main executable being a file on a remote target (i.e. one with a 'target:' prefix). To do this I have replaced a system 'stat' call with a bfd_stat call. However, doing this caused a regression in gdb.base/attach.exp. The problem is that the bfd library caches open FILE* handles for bfd objects that it has accessed, which is great for short-lived, non interactive programs (e.g. the assembler, or objcopy, etc), however, for GDB this caching causes us a problem. If we open the main executable as a bfd then the bfd library will cache the open FILE*. If some time passes, maybe just sat at the GDB prompt, or with the inferior running, and then later we use bfd_stat to check if the underlying, on-disk file has changed, then the bfd library will actually use fstat on the underlying file descriptor. This is of course slightly different than using system stat on with the on-disk file name. If the on-disk file has changed then system stat will give results for the current on-disk file. But, if the bfd cache is still holding open the file descriptor for the original on-disk file (from before the change) then fstat will return a result based on the original file, and so show no change as having happened. This is a known problem in GDB, and so far this has been solved by scattering bfd_cache_close_all() calls throughout GDB. But, as I said, in the next commit I've made a change and run into a problem (gdb.base/attach.exp) where we are apparently missing a bfd_cache_close_all() call. Now I could solve this problem by adding a bfd_cache_close_all() call before the bfd_stat call that I plan to add in the next commit, that would for sure solve the problem, but feels a little crude. Better I think would be to track down where the bfd is being opened and add a corresponding bfd_cache_close_all() call elsewhere in GDB once we've finished doing whatever it is that caused us to open the bfd in the first place. This second solution felt like the better choice, so I tracked the problem down to elf_locate_base and fixed that. But that just exposed another problem in gdb_bfd_map_section which was also re-opening the bfd, so I fixed this (with another bfd_cache_close_all() call), and that exposed another issue in gdbarch_lookup_osabi... and at this point I wondered if I was approaching this problem the wrong way... .... And so, I wonder, is there a _better_ way to handle these bfd_cache_close_all() calls? I see two problems with the current approach: 1. It's fragile. Folk aren't always aware that they need to clear the bfd cache, and this feels like something that is easy to overlook in review. So adding new code to GDB can innocently touch a bfd, which populates the cache, which will then be a bug that can lie hidden until an on-disk file just happens to change at the wrong time ... and GDB fails to spot the change. Additionally, 2. It's in efficient. The caching is intended to stop the bfd library from continually having to re-open the on-disk file. If we have a function that touches a bfd then often that function is the obvious place to call bfd_cache_close_all. But if a single GDB command calls multiple functions, each of which touch the bfd, then we will end up opening and closing the same on-disk file multiple times. It feels like we would be better postponing the bfd_cache_close_all call until some later point, then we can benefit from the bfd cache. So, in this commit I propose a new approach. We now clear the bfd cache in two places: (a) Just before we display a GDB prompt. We display a prompt after completing a command, and GDB is about to enter an idle state waiting for further input from the user (or in async mode, for an inferior event). If while we are in this idle state the user changes the on-disk file(s) then we would like GDB to notice this the next time it leaves its idle state, e.g. the next time the user executes a command, or when an inferior event arrives, (b) When we resume the inferior. In synchronous mode, resuming the inferior is another time when GDB is blocked and sitting idle, but in this case we don't display a prompt. As with (a) above, when an inferior event arrives we want GDB to notice any changes to on-disk files. It turns out that there are existing observers for both of these cases (before_prompt and target_resumed respectively), so my initial thought was that I should attach to these observers in gdb_bfd.c, and in both cases call bfd_cache_close_all(). And this does indeed solve the gdb.base/attach.exp problem that I see with the following commit. However, I see a problem with this solution. Both of the observers I'm using are exposed through the Python API as events that a user can hook into. The user can potentially run any GDB command (using gdb.execute), so Python code might end up causing some bfds to be reopened, and inserted into the cache. To solve this one solution would be to add a bfd_cache_close_all() call into gdbpy_enter::~gdbpy_enter(). Unfortunately, there's no similar enter/exit object for Guile, though right now Guile doesn't offer the same event API, so maybe we could just ignore that problem... but this doesn't feel great. So instead, I think a better solution might be to not use observers for the bfd_cache_close_all() calls. Instead, I'll call bfd_cache_close_all() directly from core GDB after we've notified the before_prompt and target_resumed observers, this was we can be sure that the cache is cleared after the observers have run, and before GDB enters an idle state. This commit also removes all of the other bfd_cache_close_all() calls from GDB. My claim is that these are no longer needed. Approved-By: Tom Tromey <tom@tromey.com>
2023-11-17gdb: remove get_current_regcacheSimon Marchi1-1/+1
Remove get_current_regcache, inlining the call to get_thread_regcache in callers. When possible, pass the right thread_info object known from the local context. Otherwise, fall back to passing `inferior_thread ()`. This makes the reference to global context bubble up one level, a small step towards the long term goal of reducing the number of references to global context (or rather, moving those references as close as possible to the top of the call tree). No behavior change expected. Change-Id: Ifa6980c88825d803ea586546b6b4c633c33be8d6
2023-10-19gdb: remove target_section_table typedefSimon Marchi1-1/+1
Remove this typedef. I think that hiding the real type (std::vector) behind a typedef just hinders readability. Change-Id: I80949da3392f60a2826c56c268e0ec6f503ad79f Approved-By: Pedro Alves <pedro@palves.net> Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
2023-10-10gdb: remove target_gdbarchSimon Marchi1-5/+6
This function is just a wrapper around the current inferior's gdbarch. I find that having that wrapper just obscures where the arch is coming from, and that it's often used as "I don't know which arch to use so I'll use this magical target_gdbarch function that gets me an arch" when the arch should in fact come from something in the context (a thread, objfile, symbol, etc). I think that removing it and inlining `current_inferior ()->arch ()` everywhere will make it a bit clearer where that arch comes from and will trigger people into reflecting whether this is the right place to get the arch or not. Change-Id: I79f14b4e4934c88f91ca3a3155f5fc3ea2fadf6b Reviewed-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-05gdb: use objfile->pspace in free_objfile observersSimon Marchi1-1/+1
Use objfile->pspace instead of current_program_space. Change-Id: I127a1788e155b321563114452ed5b530f1d1f618 Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: remove unnecessary nullptr check in free_objfile observersSimon Marchi1-2/+1
The free_objfile observable is never called with a nullptr objfile. Change-Id: I1e990edeb45bc38009ccb129c623911097ab65fe Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: add all_objfiles_removed observerSimon Marchi1-1/+1
The new_objfile observer is currently used to indicate both when a new objfile is added to program space (when passed non-nullptr) and when all objfiles of a program space were just removed (when passed nullptr). I think this is confusing (and Andrew apparently thinks so too [1]). Add a new "all_objfiles_removed" observer to remove the second role from "new_objfile". Some existing users of new_objfile do nothing if the passed objfile is nullptr. For them, we can simply drop the nullptr check. For others, add a new all_objfiles_removed callback, and refactor things a bit to keep the existing behavior as much as possible. Some callbacks relied on current_program_space, and following the refactoring now use either objfile->pspace or the pspace passed to all_objfiles_removed. I think this should be relatively safe, and in general a step in the right direction. On the notify side, I found only one call site to change from new_objfile to all_objfiles_removed, in clear_symtab_users. It is not entirely clear to me that this is entirely correct. clear_symtab_users appears to be called in spots that don't remove all objfiles (functions finish_new_objfile, remove_symbol_file_command, reread_symbols, do_module_cleanups). But I think that this patch at least makes the current code clearer. [1] https://gitlab.com/gnutools/binutils-gdb/-/commit/a0a031bce0527b1521788b5dad640e7883b3a252 Change-Id: Icb648f72862e056267f30f44dd439bd4ec766f13 Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: fix reread_symbols when an objfile has target: prefixAndrew Burgess1-10/+22
When using a remote target, it is possible to tell GDB that the executable to be debugged is located on the remote machine, like this: (gdb) target extended-remote :54321 ... snip ... (gdb) file target:/tmp/hello.x Reading /tmp/hello.x from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /tmp/hello.x from remote target... Reading symbols from target:/tmp/hello.x... (gdb) So far so good. However, when we try to start the inferior we run into a small problem: (gdb) set remote exec-file /tmp/hello.x (gdb) start `target:/tmp/hello.x' has disappeared; keeping its symbols. Temporary breakpoint 1 at 0x401198: file /tmp/hello.c, line 18. Starting program: target:/tmp/hello.x ... snip ... Temporary breakpoint 1, main () at /tmp/hello.c:18 18 printf ("Hello World\n"); (gdb) Notice this line: `target:/tmp/hello.x' has disappeared; keeping its symbols. That's wrong, the executable hasn't been removed, GDB just doesn't know how to check if the remote file has changed, and so falls back to assuming that the file has been removed. In this commit I update reread_symbols to use bfd_stat instead of a direct stat call, this adds support for target: files, and fixes the problem. This change was proposed before in this commit: https://inbox.sourceware.org/gdb-patches/20200114210956.25115-3-tromey@adacore.com/ However, that patch never got merged, and seemed to get stuck discussing issues around gnulib stat vs system stat as used by BFD. I didn't 100% understand the issues discussed in that thread, however, I think the problem with the previous thread related to the changes in gdb_bfd.c, rather than to the change in symfile.c. As such, I think this change might be acceptable, my reasoning is: - the objfile::mtime field is set by a call to bfd_get_mtime (see objfiles.c), which calls bfd_stat under the hood. This will end up using the system stat, - In symfile.c we currently call stat directly, which will call the gnulib stat, which, if I understand the above thread correctly, might give a different result to the system stat in some cases, - By switching to using bfd_stat in symfile.c we should now be consistently calling the system stat. There is another issue that came up during testing that this commit fixes. Consider this GDB session: $ gdb -q (gdb) target extended-remote | ./gdbserver/gdbserver --multi --once - Remote debugging using | ./gdbserver/gdbserver --multi --once - Remote debugging using stdio (gdb) file /tmp/hello.x Reading symbols from /tmp/hello.x... (gdb) set remote exec-file /tmp/hello.x (gdb) start ... snip ... (gdb) load `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. Loading section .interp, size 0x1c lma 0x4002a8 ... snip ... Start address 0x0000000000401050, load size 2004 Transfer rate: 326 KB/sec, 87 bytes/write. Notice this line: `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. We actually see the same output, for the same reasons, when using a native target, like this: $ gdb -q (gdb) file /tmp/hello.x Reading symbols from /tmp/hello.x... (gdb) start ... snip ... (gdb) load `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. You can't do that when your target is `native' (gdb) In both cases this line appears because load_command (symfile.c) calls reread_symbols, and reread_symbols loops over every currently loaded objfile and tries to check if the file has changed on disk by calling stat. However, the `system-supplied DSO at 0x7ffff7fcf000' is an in-memory BFD, the filename for this BFD is literally the string 'system-supplied DSO at 0x7ffff7fcf000'. Before this commit GDB would try to use the system 'stat' call to stat the file `system-supplied DSO at 0x7ffff7fcf000', which obviously fails; there's no file with that name (usually). As a consequence of the stat failing GDB prints the ' .... has disappeared ...' line. Initially, all this commit did was switch from using 'stat' to using 'bfd_stat'. Calling bfd_stat on an in-memory BFD works just fine, however, BFD just fills the 'struct stat' buffer with zeros (except for the file size), see memory_bstat in bfd/bfdio.c. However, there is a bit of a weirdness about in-memory BFDs. When they are initially created the libbfd caches an mtime within the bfd object, this is done in bfd_from_remote_memory (elfcode.h), the cached mtime is the time at which the in-memory BFD is created. What this means is that when GDB creates the in-memory BFD, and we call bfd_get_mtime(), the value returned, which GDB caches within objfile::mtime is the creation time of the in-memory BFD. But, when this patch changes to use bfd_stat() we now get back 0, and so we believe that the in-memory BFD has changed. This is a change in behaviour. To avoid this change in behaviour, in this commit, I propose that we always skip in-memory BFDs in reread_symbols. This preserves the behaviour from before this commit -- mostly. As I'm not specifically checking for, and then skipping, in-memory BFDs, we no longer see this line: `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols. Which I think is an improvement. Co-Authored-By: Tom Tromey <tromey@adacore.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: remove print_sys_errmsgAndrew Burgess1-3/+2
This started with me running into this comment in symfile.c: /* FIXME, should use print_sys_errmsg but it's not filtered. */ gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"), styled_string (file_name_style.style (), filename)); In this particular case I think I disagree with the comment; I think the output should be a warning rather than just a message printed to gdb_stdout, I think when the executable, or some other objfile that is currently being debugged, disappears from disk, this is likely an unexpected situation, and worth warning the user about. So, in theory, I could just call print_sys_errmsg and remove the comment, but that would mean loosing the filename styling in the output... so in the end I remove the comment and updated the code to call warning. But that got me looking at print_sys_errmsg and how it's used. Currently the function takes a string and an errno, and prints, to stderr, the string followed by the result of calling strerror on the errno. In some places the string passed to print_sys_errmsg is just a filename, and this is used when something goes wrong. In these cases, I think calling warning rather than gdb_printf to gdb_stderr, would be better, and in fact, in a couple of places we manually print a "warning" prefix, and then call print_sys_errmsg. And so, for these users I have added a new function warning_filename_and_errno, which takes a filename, which is printed with styling, and an errno, which is passed through strerror and the resulting string printed. This new function calls warning to print its output. I then updated some of the print_sys_errmsg users to use this new function. Some other users of print_sys_errmsg are also emitting what is clearly a warning, however, the string being passed in is more than just a filename, so the new warning_filename_and_errno function can't be used, it would style the whole string. For these users I have switched to calling warning directly, this allows me to style the warning message correctly. Finally, in inflow.c there is one last call to print_sys_errmsg, in this case I just inlined the definition of print_sys_errmsg. This is a really weird case, as after printing this message GDB just does a hard exit. This is pretty old code, dating back to the initial GDB import, I guess it should be updated to call error() maybe, but I'm reluctant to make this change as part of this commit, just in case there's some reason why we can't throw an error at this point. With that done there are now no users of print_sys_errmsg, and so the old function can be removed. While I was doing all of the above I added some additional filename styling in soure.c, this is in an else block where the if contained the print_sys_errmsg call, so these felt related. And finally, while I was updating the uses of print_sys_errmsg in procfs.c, I noticed that we used a static errmsg buffer to format some error strings. As the above changes got rid of one of the users of errmsg I also removed the other two users, and the static buffer. There were a couple of tests that depended on the existing output message format that needed updating. In one case we gained an extra 'warning: ' prefix, and in the other 'Warning: ' becomes 'warning: ', I think in both cases the new output is an improvement. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: use archive name in warning when appropriateAndrew Burgess1-6/+7
While working on some other patch I noticed that in reread_symbols there is a diagnostic message that can be printed, and in some cases we might use the wrong filename in the message. The code in question is checking to see if an objfile has changed on disk, we do this by stat-ing the on disk file and checking the mtime. If this file has been removed from disk then we print a message that the file has been removed, however, if the objfile is within an archive then we stat the archive itself, but then warn that the component within the archive has disappeared. I think it makes more sense to say that the archive has disappeared. The last related commit is this one: commit 02aeec7bde8ec8a04d14a5637e75f1c6ab899e23 Date: Tue Apr 27 21:01:30 2010 +0000 Check library name rather than member name when rereading symbols. Though this just makes the code to stat the archive unconditional, the code in question existed before this commit. However, the above commit doesn't include any tests, and seems to indicate that the problem being addressed was seen on Darwin. I'm not sure how to setup a test where GDB is using an objfile from within an archive, and so there's no tests for this commit... ... but if someone can let me know how I can setup a suitable test, please let me know and I'll try to get something working. Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05gdb: some additional filename stylingAndrew Burgess1-2/+3
Fix up another couple of places where we can apply filename styling. Approved-By: Tom Tromey <tom@tromey.com>