aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2024-10-06gdb/MAINTAINERS: update my email addressGaius Mulley1-1/+1
Sync the maintainers file with my new email address.
2024-10-06[gdb] Rerun spellcheck.shTom de Vries1-2/+2
Fix the following common misspellings: ... completetion -> completion inital -> initial ...
2024-10-06[gdb] Fix more common misspellingsTom de Vries10-10/+10
Fix the following common misspellings: ... addres -> address, adders behavour -> behavior, behaviour intented -> intended, indented ther -> there, their, the throught -> thought, through, throughout ... Tested on x86_64-linux.
2024-10-06[gdb] Fix common misspellingsTom de Vries107-170/+170
Fix the following common misspellings: ... accidently -> accidentally additonal -> additional addresing -> addressing adress -> address agaisnt -> against albiet -> albeit arbitary -> arbitrary artifical -> artificial auxillary -> auxiliary auxilliary -> auxiliary bcak -> back begining -> beginning cannonical -> canonical compatiblity -> compatibility completetion -> completion diferent -> different emited -> emitted emiting -> emitting emmitted -> emitted everytime -> every time excercise -> exercise existance -> existence fucntion -> function funtion -> function guarentee -> guarantee htis -> this immediatly -> immediately layed -> laid noone -> no one occurances -> occurrences occured -> occurred originaly -> originally preceeded -> preceded preceeds -> precedes propogate -> propagate publically -> publicly refering -> referring substract -> subtract substracting -> subtracting substraction -> subtraction taht -> that targetting -> targeting teh -> the thier -> their thru -> through transfered -> transferred transfering -> transferring upto -> up to vincinity -> vicinity whcih -> which whereever -> wherever wierd -> weird withing -> within writen -> written wtih -> with doesnt -> doesn't ... Tested on x86_64-linux.
2024-10-06[gdb/contrib] Add spellcheck.shTom de Vries1-0/+287
I came across a table containing common misspellings [1], and wrote a script to detect and correct these misspellings. The table also contains entries that have alternatives, like this: ... addres->address, adders ... and for those the script prints a TODO instead. The script downloads the webpage containing the table, extracts the table and caches it in .git/wikipedia-common-misspellings.txt to prevent downloading it over and over again. Example usage: ... $ gdb/contrib/spellcheck.sh gdb* ... ChangeLog files are silently skipped. Checked with shellcheck. Tested on x86_64-linux, by running it on the gdb* dirs on doing a build and test run. The results of running it are in the two following patches. Reviewed-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Tom Tromey <tom@tromey.com> [1] https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines
2024-10-04gdb segv in elfread.c:elf_rel_plt_readAlan Modra1-0/+2
After commit 68bbe1183379, ELF symbols read via bfd_canonicalize_symtab and similar functions which have bad st_name fields will have NULL in the name rather than "(null)". gdb.base/bfd-errors.exp deliberately creates a faulty shared library with st_name pointing outside of .dynsym for some symbols, and thus now results in NULL symbol names. This triggers a segv on string_buffer.assign(name). Fix that.
2024-10-03gdb-dap: disable events when deleting breakpointsoltolm1-3/+3
when I disable a breakpoint in VS Code the breakpoint is removed instead. I compared the behavior to lldb-dap and disabled events when removing a breakpoint. Now it is possible to disable and enable breakpoints in VS Code.
2024-10-02gdb: more file name stylingAndrew Burgess4-23/+41
While looking at the recent line number styling commit I noticed a few places where we could add more file name styling. So lets do that. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-01Introduce and use operation::type_pTom Tromey7-20/+32
There's currently code in gdb that checks if an expression evaluates to a type. In some spots this is done by comparing the opcode against OP_TYPE, but other spots more correctly also compare with OP_TYPEOF and OP_DECLTYPE. This patch cleans up this area, replacing opcode-checking with a new method on 'operation'. Generally, checking the opcode should be considered deprecated, although it's unfortunately difficult to get rid of opcodes entirely. I also took advantage of this change to turn eval_op_type into a method, removing a bit of indirection. Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-09-30Add line-number stylingTom Tromey28-55/+131
This patch adds separate styling for line numbers. That is, whenever gdb prints a source line number, it uses this style. v2 includes a change to ensure that %ps works in query. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-09-30gdb: fix filename completion in the middle of a lineAndrew Burgess2-4/+189
I noticed that filename completion in the middle of a line doesn't work as I would expect it too. For example, assuming '/tmp/filename' exists, and is the only file in '/tmp/' then when I do the following: (gdb) file "/tmp/filen<TAB> GDB completes to: (gdb) file "/tmp/filename" But, if I type this: (gdb) file "/tmp/filen "xxx" Then move the cursor to the end of '/tmp/filen' and press <TAB>, GDB will complete the line to: (gdb) file "/tmp/filename "xxx" But GDB will not insert the trailing double quote character. The reason for this is found in readline/readline/complete.c in the function append_to_match. This is the function that appends the trailing closing quote character, however, the closing quote is only inserted if the cursor (rl_point) is at the end (rl_end) of the line being completed. In this patch, what I do instead is add the closing quote in the function gdb_completer_file_name_quote, which is called from readline through the rl_filename_quoting_function hook. The docs for rl_filename_quoting_function say (see 'info readline'): "... The MATCH_TYPE is either 'SINGLE_MATCH', if there is only one completion match, or 'MULT_MATCH'. Some functions use this to decide whether or not to insert a closing quote character. ..." This is exactly what I'm doing in this patch, and clearly this is not an unusual choice. Now after completing a filename that is not at the end of the line GDB will add the closing quote character if appropriate. I have managed to write some tests for this. I send a line of text to GDB which includes a partial filename followed by a trailing string, I then send the escape sequence to move the cursor left, and finally I send the tab character. Obviously, expect doesn't actually see the complete output with the extra text "in place", instead expect sees the original line followed by some escape sequences to reflect the cursor movement, then an escape sequence to indicate that text is being inserted in the middle of a line, followed by the new characters ... it's a bit messy, but I think it holds together. Reviewed-By: Tom Tromey <tom@tromey.com>
2024-09-30gdb: fix for completing a second filename for a commandAndrew Burgess2-103/+121
After the recent filename completion changes I noticed that the following didn't work as expected: (gdb) file "/path/to/some/file" /path/to/so<TAB> Now, I know that the 'file' command doesn't actually take multiple filenames, but currently (and this was true before the recent filename completion changes too) the completion function doesn't know that the command only expects a single filename, and should complete any number of filenames. And indeed, this works: (gdb) file "/path/to/some/file" "/path/to/so<TAB> In this case I quoted the second path, and now GDB is happy to offer completions. It turns out that the problem in the first case is an off-by-one bug in gdb_completer_file_name_char_is_quoted. This function tells GDB if a character within the line being completed is escaped or not. An escaped character cannot be a word separator. The algorithm in gdb_completer_file_name_char_is_quoted is to scan forward through the line keeping track of whether we are inside double or single quotes, or if a character follows a backslash. When we find an opening quote we skip forward to the closing quote and then check to see if we skipped over the character we are looking for, if we did then the character is within the quoted string. The problem is that this "is character inside quoted string" check used '>=' instead if '>'. As a consequence a character immediately after a quoted string would be thought of as inside the quoted string. In our first example this means that the single white space character after the quoted string was thought to be quoted, and was not considered a word breaking character. As such, GDB would not try to complete the second path. And indeed, if we tried this: (gdb) file "/path/to/some/file" /path/to/so<TAB> That is, place multiple spaces after the first path, then GDB would consider the first space as quoted, but the second space is NOT quoted, and would be a word break. Now GDB does complete the second path. By changing '>=' to '>' in gdb_completer_file_name_char_is_quoted this bug is resolved, now the original example works and GDB will correctly complete the second path. For testing I've factored out the core of one testing proc, and I now run those tests multiple times, once with no initial path, once with an initial path in double quotes, once with an initial path in single quotes, and finally, with an unquoted initial path. Reviewed-By: Tom Tromey <tom@tromey.com>
2024-09-30gdb/MAINTAINERS: add myself to maintainersGerlicher, Klaus1-0/+1
2024-09-30gdb: Remove myself as x86 maintainer and update my emailFelix Willgerodt1-3/+2
2024-09-30gdb, testsuite: clean duplicate header includesGerlicher, Klaus14-15/+0
Some of the gdb and testsuite files double include some headers. While all headers use include guards, it helps a bit keeping the code base tidy. No functional change. Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-09-28[gdb/symtab] Dump m_all_parents_map for verbose debug dwarf-readTom de Vries4-7/+75
[ This is based on "[gdb/symtab] Add parent_map::dump" [1]. ] When building the cooked index, gdb builds up a parent map. This map is currently only visible at user level through the effect of using it, but it's useful to be able to inspect it as well. Add dumping of this parent map for "set debug dwarf-read 2". As example, take test-case gdb.dwarf2/enum-type-c++.exp with target board debug-types. The parent map looks like: ... $ gdb -q -batch \ -iex "maint set worker-threads 0" \ -iex "set debug dwarf-read 2" \ outputs/gdb.dwarf2/enum-type-c++/enum-type-c++ ... [dwarf-read] print_stats: Final m_all_parents_map: map start: 0x0000000000000000 0x0 0x0000000000000037 0x20f27d30 (0x36: ec) 0x0000000000000051 0x0 0x000000000000008b 0x20f27dc0 (0x8a: A) 0x00000000000000a6 0x0 ... There's no parent entry at address 0xd6, which is part of what causes this: ... (gdb) FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent ... With the series containing the proposed fix applied [2], we get instead: ... [dwarf-read] print_stats: Final m_all_parents_map: map start: 0x0000000000000000 0x0 0x0000000000000026 0x7e0bdc0 (0x25: ns) 0x0000000000000036 0x0 0x0000000000000037 0x7e0bdf0 (0x36: ns::ec) 0x0000000000000051 0x0 0x000000000000007f 0x7e0be80 (0x7e: ns) 0x000000000000008a 0x0 0x000000000000008b 0x7e0beb0 (0x8a: ns::A) 0x00000000000000a6 0x0 0x00000000000000cc 0x7e0bf10 (0xcb: ns) 0x00000000000000d4 0x7e0bf40 (0xd3: ns::A) 0x00000000000000dc 0x7e0bf10 (0xcb: ns) 0x00000000000000dd 0x7e0bf40 (0xd3: ns::A) 0x00000000000000f6 0x0 ... and find at 0xd6 parent ns::A. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> [1] https://sourceware.org/pipermail/gdb-patches/2023-October/202883.html [2] https://sourceware.org/pipermail/gdb-patches/2024-September/211958.html
2024-09-27Re-run 'isort' on gdb testsTom Tromey1-0/+1
Re-running 'isort' (via pre-commit) showed that the file py-read-memory-leak.py (from the gdb test suite) needed a small patch.
2024-09-27gdb/symtab: pass program space to lookup_symtab and iterate_over_symtabsSimon Marchi9-46/+37
Make the current program space references bubble up. In collect_symtabs_from_filename, remove the calls to set_current_program_space and just pass the relevant pspaces. This appears safe to do, because nothing in the `collector` callback cares about the current pspace. Change-Id: I00a7ed484bfbe5264f01a6abf0d33b51de373cbb Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-09-26Add 'const' to symmisc.cTom Tromey1-3/+5
I noticed a few spots in symmisc.c that could use a 'const'.
2024-09-26gdb/testsuite: test for memory leaks in gdb.Inferior.read_memory()Andrew Burgess3-0/+163
For a long time Fedora GDB has carried an out of tree patch which checks for memory leaks in gdb.Inferior.read_memory(). At one point in the distant past GDB did have a memory leak in this code, but this was first fixed in commit: commit 655e820cf9a039ee55325d9e1f8423796d592b4b Date: Wed Mar 28 17:38:07 2012 +0000 * python/py-inferior.c (infpy_read_memory): Remove cleanups and explicitly free 'buffer' on exit paths. Decref 'membuf_object' before returning. And the code has changed a lot since then, but the leak is still fixed. Unfortunately, this commit didn't have any associated tests. The original Fedora test wasn't really suitable for upstream, it was reading /proc/PID/... to figure out if there was a leak or not. However, we already have gdb.python/py-inferior-leak.exp in upstream GDB, which makes use of the Python tracemalloc module to check for memory leaks in a corner of the Python API, so I figured it wouldn't hurt to rewrite the test in the same style. And so here is a test for a bug which was closed 12 years ago. This detects if the gdb.Inferior.read_memory() call leaks any memory. I've tested this by hacking gdbpy_buffer_to_membuf, replacing the last line which currently looks like this: return PyMemoryView_FromObject ((PyObject *) membuf_obj.get ()); and instead doing: return PyMemoryView_FromObject ((PyObject *) membuf_obj.release ()); The use of "release" here will mean we no longer decrement the reference count on membuf_obj before returning from the function. As a consequence the membuf_obj will not be garbage collected. With this hack in place the new test will fail. The Python script in the new test is mostly a copy&paste from py-inferior-leak.py with the core changed to do a memory read instead of inferior creation. I did consider rewriting both tests into a single file, maybe, py-memory-leak.py, which would make it easier to add additional similar tests in the future. For now I've held off doing that, but if this gets merged then I _might_ revisit this idea. If folk feel that this new test should only be accepted if I do this rewrite then let me know and I can get that done. On copyright date ranges: The .exp and .py scripts are new enough for this commit that I've dated them 2024. The .c source script is lifted directly from the old Fedora patch, so I've retained the original 2014 start date for that file only. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-25[gdb/python] Make sure python sys.exit makes gdb exitTom de Vries2-0/+98
With gdb 15.1, python sys.exit no longer makes gdb exit: ... $ gdb -q -batch -ex "python sys.exit(2)" -ex "print 123"; echo $? Python Exception <class 'SystemExit'>: 2 Error occurred in Python: 2 $1 = 123 0 ... This is a change in behaviour since commit a207f6b3a38 ("Rewrite "python" command exception handling"), first available in gdb 15.1. This patch reverts to the old behaviour by handling PyExc_SystemExit in gdbpy_handle_exception, such what we have instead: ... $ gdb -q -batch -ex "python sys.exit(2)" -ex "print 123"; echo $? 2 ... Tested on x86_64-linux, with python 3.6 and 3.13. Tested-By: Guinevere Larsen <blarsen@redhat.com> Approved-By: Tom Tromey <tom@tromey.com> PR python/31946 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31946
2024-09-25gdb/testsuite: format some Python filesSimon Marchi3-0/+3
Format with black. Change-Id: I28e79e9da07ea29391ad1942047633960fa72ed2
2024-09-25gdb, gdbserver, python, testsuite: Remove MPX.Schimpe, Christina37-2424/+55
GDB deprecated the commands "show/set mpx bound" in GDB 15.1, as Intel listed Intel(R) Memory Protection Extensions (MPX) as removed in 2019. MPX is also deprecated in gcc (since v9.1), the linux kernel (since v5.6) and glibc (since v2.35). Let's now remove MPX support in GDB completely. This includes the removal of: - MPX functionality including register support - deprecated mpx commands - i386 and amd64 implementation of the hooks report_signal_info and get_siginfo_type - tests - and pretty printer. We keep MPX register numbers to not break compatibility with old gdbservers. Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
2024-09-25gdb, testsuite, python: Add missing imports.Schimpe, Christina4-1/+4
Removing the pretty printer (bound_registers.py) in the next commit leads to failures due to a missing import of 'gdb.printing': "AttributeError: module 'gdb' has no attribute 'printing'". Add this import to each file requiring it, as it's not imported by the pretty-printer anymore. Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-09-24Fix typo in gdb.ada/complete.exp testTom Tromey1-1/+1
I noticed that two tests in gdb.ada/complete.exp are testing the same thing: the completion of "p pck.inne". The second such test has this comment: # A fully qualified package name I believe the intent here was to test "p pck.inner" (note the trailing "r"). This patch makes this change.
2024-09-24gdb: testsuite: Test whether PC register is expedited in ↵Thiago Jung Bauermann6-8/+87
gdb.server/server-run.exp One thing GDB always does when the inferior stops is finding out where it's stopped at, by way of querying the value of the program counter register. To save a packet round trip, the remote target can send the PC value (often alongside other frequently consulted registers such as the stack pointer) in the stop reply packet as an "expedited register". Test that this is actually done for the targets where gdbserver is supposed to. Extend the "maintenance print remote-registers" command output with an "Expedited" column which says "yes" if the register was seen by GDB in the last stop reply packet it received, and is left blank otherwise. Tested for regressions on aarch64-linux-gnu native-extended-remote. The testcase was tested on aarch64-linux-gnu, i686-linux-gnu and x86_64-linux-gnu native-remote and native-extended-remote targets. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24gdb/elfread.c: remove unused includesSimon Marchi1-4/+0
Remove some includes reported as unused by clangd. Change-Id: If7c4729975bd90b9cc2c22bcf84d333bd0002a52
2024-09-24[gdb] Handle SIGTERM in run_eventsTom de Vries1-1/+14
While reviewing "catch (...)" uses I came across: ... for (auto &item : local) { try { item (); } catch (...) { /* Ignore exceptions in the callback. */ } } ... This means that when an item throws a gdb_exception_forced_quit, the exception is ignored and following items are executed. Fix this by handling gdb_exception_forced_quit explicity, and immediately rethrowing it. I wondered about ^C, and couldn't decide whether current behaviour is ok, so I left this alone, but I made the issue explicit in the source code. As for the "catch (...)", I think that it should let a non-gdb_exception propagate, so I've narrowed it to "catch (const gdb_exception &)". My rationale for this is as follows. There seem to be a few ways that "catch (...)" is allowed in gdb: - clean-up and rethrow (basically the SCOPE_EXIT pattern) - catch and handle an exception from a call into an external c++ library Since we're dealing with neither of those here, we remove the "catch (...)". Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb] Handle ^C in ~scoped_remote_fdTom de Vries1-0/+12
While reviewing "catch (...)" uses I came across: ... try { fileio_error remote_errno; m_remote->remote_hostio_close (m_fd, &remote_errno); } catch (...) { /* Swallow exception before it escapes the dtor. If something goes wrong, likely the connection is gone, and there's nothing else that can be done. */ } ... This also swallows gdb_exception_quit and gdb_exception_forced_quit. I don't know whether these can actually happen here, but if not it's better to accommodate for the possibility anyway. Fix this by handling gdb_exception_quit and gdb_exception_forced_quit explicitly. It could be that "catch (...)" should be replaced by "catch (const gdb_exception &)" but that depends on what kind of exception remote_hostio_close is expected to throw, and I don't know that, so I'm leaving it as is. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24btrace: Add support for further events.Felix Willgerodt1-0/+155
This is similar to the previous events that we added, and adds support for SMI, RSM, SIPI, INIT, VMENTRY, VMEXIT, SHUTDOWN, UINTR and UIRET. Though since these are mainly mechanical and not really possible to test, they are bundled in one commit. Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-09-24btrace: Add support for IRET events.Felix Willgerodt3-1/+19
This is similar to the previous events that we added. Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-09-24btrace: Add support for interrupt events.Felix Willgerodt8-25/+364
Newer Intel CPUs support recording asynchronous events in the PT trace. Libipt also recently added support for decoding these. This patch adds support for interrupt events, based on the existing aux infrastructure. GDB can now display such events during the record instruction-history and function-call-history commands. Subsequent patches will add the rest of the events currently supported. Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-09-24btrace: Enable event tracing on Linux for Intel PT.Felix Willgerodt6-6/+146
Event tracing allows GDB to show information about interesting asynchronous events when tracing with Intel PT. Subsequent patches will add support for displaying each type of event. Enabling event-tracing unconditionally would result in rather noisy output, as breakpoints themselves result in interrupt events. Which is why this patch adds a set/show command to allow the user to enable/disable event-tracing before starting a recording. The event-tracing setting has no effect on an already active recording. The default setting is off. As event tracing will use the auxiliary infrastructure added by ptwrite, the user can still disable printing events, even when event-tracing was enabled, by using the /a switch for the record instruction-history/function-call-history commands. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-09-24btrace: Add printing support for cfe and evd packets.Felix Willgerodt1-0/+13
Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-09-24btrace: Print "non-contiguous" for gaps.Felix Willgerodt2-5/+5
So far we printed "disabled" for gaps, when we saw a ptev_enabled event that doesn't have the resumed flag set. This is wrong, as the actual disabling happens with ptev_disabled. So far this didn't matter, but once we have event tracing, there can be events between a ptev_disabled and a ptev_enabled. This patch is in preparation for that, and removes the disabled reason in favour of a more accurate non-contiguous reason, and adjusts the string we print accordingly. Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-09-24[gdb] Eliminate catch(...) in pipe_commandTom de Vries1-11/+6
Remove duplicate code in pipe_command using SCOPE_EXIT. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb] Eliminate catch(...) in target_waitTom de Vries1-12/+6
Remove duplicate code in target_wait using SCOPE_EXIT. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb] Eliminate catch(...) in execute_fn_to_stringTom de Vries1-12/+2
Remove duplicate code in execute_fn_to_string using SCOPE_EXIT. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb] Handle ^C in gnu_source_highlight_testTom de Vries1-0/+6
In gnu_source_highlight_test we have: ... try { res = try_source_highlight (styled_prog, language_c, fullname); } catch (...) { saw_exception = true; } ... This also swallows gdb_exception_quit and gdb_exception_forced_quit. I don't know whether these can actually happen here, but if not it's better to accommodate for the possibility anyway. Fix this by handling gdb_exception explicitly, and rethrowing gdb_exception_quit and gdb_exception_forced_quit. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/cli] Show readline wrapping mode for maint info screenTom de Vries2-6/+70
With the same trigger patch adding "set horizontal-scroll-mode on" to INPUTRC as used in commit 250f1bbaf33 ("[gdb/testsuite] Fix gdb.tui/wrap-line.exp with wrapping disabled"), we can easily reproduce a failure in gdb.tui/wrap-line.exp mentioned in PR testsuite/31201: ... (gdb) 78901234567890123456789012345678901234567890123456789012345678901234567^M<890123456789012345678901234567890123456789012345678 ^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H9WFAIL: gdb.base/wrap-line.exp: term=ansi: width-hard-coded: wrap (timeout) ... The test-case expects wrapping, but that's disabled by horizontal-scroll-mode. Add a new line to "maint info screen", that describes the current readline wrapping mode, and use it in the test-case to handle the different cases. The reported values for the wrapping mode are as follows. Unsupported because of running in batch mode: ... $ gdb -q -batch -ex "maint info screen" Readline wrapping mode: unsupported (gdb batch mode). ... Unsupported because the terminal is not capable to move the cursor up: ... $ TERM=dumb gdb -q -ex "maint info screen" -ex q Readline wrapping mode: unsupported (terminal is not Cursor Up capable). ... Disabled by horizontal-scroll-mode: ... $ grep horizontal-scroll-mode ~/.inputrc set horizontal-scroll-mode on $ gdb -q -ex "maint info screen" -ex q Readline wrapping mode: disabled (horizontal-scroll-mode). ... Wrap done by readline because terminal is not auto wrap capable: ... $ TERM=ansi gdb -q -ex "maint info screen" -ex q Readline wrapping mode: readline (terminal is not auto wrap capable, last column reserved). ... Wrap done by terminal autowrap: ... $ TERM=xterm gdb -q -ex "maint info screen" -ex q Readline wrapping mode: terminal (terminal is auto wrap capable). ... Tested on x86_64-linux. Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de> Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31201
2024-09-24[gdb/python] Use gdbpy_handle_gdb_exception in valpy_assign_coreTom de Vries1-2/+1
In valpy_assign_core we have: ... catch (const gdb_exception &except) { gdbpy_convert_exception (except); return false; } ... Use instead: ... catch (const gdb_exception &except) { return gdbpy_handle_gdb_exception (false, except); } ... No functional changes. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/python] Eliminate GDB_PY_SET_HANDLE_EXCEPTIONTom de Vries7-21/+14
Result of: ... $ search="GDB_PY_SET_HANDLE_EXCEPTION (" $ replace="return gdbpy_handle_gdb_exception (-1, " $ sed -i \ "s/$search/$replace/" \ gdb/python/*.c ... Also remove the now unused GDB_PY_SET_HANDLE_EXCEPTION. No functional changes. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/python] Eliminate GDB_PY_HANDLE_EXCEPTIONTom de Vries23-136/+129
Result of: ... $ search="GDB_PY_HANDLE_EXCEPTION (" $ replace="return gdbpy_handle_gdb_exception (nullptr, " $ sed -i \ "s/$search/$replace/" \ gdb/python/*.c ... Also remove the now unused GDB_PY_HANDLE_EXCEPTION. No functional changes. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/python] Add gdbpy_handle_gdb_exceptionTom de Vries1-9/+19
I've recently committed two patches: - commit 2f8cd40c37a ("[gdb/python] Use GDB_PY_HANDLE_EXCEPTION more often") - commit fbf8e4c35c2 ("[gdb/python] Use GDB_PY_SET_HANDLE_EXCEPTION more often") which use the macros GDB_PY_HANDLE_EXCEPTION and GDB_PY_SET_HANDLE_EXCEPTION more often, with the goal of making things more consistent. Having done that, I wondered if a better approach could be possible. Consider GDB_PY_HANDLE_EXCEPTION: ... /* Use this in a 'catch' block to convert the exception to a Python exception and return nullptr. */ #define GDB_PY_HANDLE_EXCEPTION(Exception) \ do { \ gdbpy_convert_exception (Exception); \ return nullptr; \ } while (0) ... The macro nicely codifies how python handles exceptions: - setting an error condition using some PyErr_Set* variant, and - returning a value implying that something went wrong presumably with the goal that using the macro will mean not accidentally: - forgetting to return on error, or - returning the wrong value on error. The problems are that: - the macro hides control flow, specifically the return statement, and - the macro hides the return value. For example, when reading somewhere: ... catch (const gdb_exception &except) { GDB_PY_HANDLE_EXCEPTION (except); } ... in order to understand what this does, you have to know that the macro returns, and that it returns nullptr. Add a template gdbpy_handle_gdb_exception: ... template<typename T> [[nodiscard]] T gdbpy_handle_gdb_exception (T val, const gdb_exception &e) { gdbpy_convert_exception (e); return val; } ... which can be used instead: ... catch (const gdb_exception &except) { return gdbpy_handle_gdb_exception (nullptr, except); } ... [ Initially I tried this: ... template<auto val> [[nodiscard]] auto gdbpy_handle_gdb_exception (const gdb_exception &e) { gdbpy_convert_exception (e); return val; } ... with which the usage is slightly better looking: ... catch (const gdb_exception &except) { return gdbpy_handle_gdb_exception<nullptr> (except); } ... but I ran into trouble with older gcc compilers. ] While still a single statement, we now have it clear: - that the statement returns, - what value the statement returns. [ FWIW, this could also be handled by say: ... - GDB_PY_HANDLE_EXCEPTION (except); + GDB_PY_HANDLE_EXCEPTION_AND_RETURN_VAL (except, nullptr); ... but I still didn't find the fact that it returns easy to spot. Alternatively, this is the simplest form we could use: ... return gdbpy_convert_exception (e), nullptr; ... but the pairing would not necessarily survive a copy/paste/edit cycle. ] Also note how making the value explicit makes it easier to check for consistency: ... catch (const gdb_exception &except) { return gdbpy_handle_gdb_exception (-1, except); } if (PyErr_Occurred ()) return -1; ... given that we do use the explicit constants almost everywhere else. Compared to using GDB_PY_HANDLE_EXCEPTION, there is the burden now to specify the return value, but I assume that this will be generally copy-pasted and therefore present no problem. Also, there's no longer a guarantee that there's an immediate return, but I assume that nodiscard making sure that the return value is not silently ignored is sufficient mitigation. For now, re-implement GDB_PY_HANDLE_EXCEPTION and GDB_PY_SET_HANDLE_EXCEPTION in terms of gdbpy_handle_gdb_exception. Follow-up patches will eliminate the macros. No functional changes. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/symtab] Fix segfault on invalid debug infoTom de Vries2-39/+104
While looking at PR symtab/31478 (a problem in the cooked indexer with invalid dwarf) it occurred to me that I could trigger a similar problem using: ... Compilation Unit @ offset 0xb2: Length: 0x1f (32-bit) Version: 4 Abbrev Offset: 0x6c Pointer Size: 8 <0><bd>: Abbrev Number: 1 (DW_TAG_compile_unit) <be> DW_AT_language : 2 (non-ANSI C) <1><bf>: Abbrev Number: 2 (DW_TAG_subprogram) <c0> DW_AT_low_pc : 0x4004a7 <c8> DW_AT_high_pc : 0x4004b2 <d0> DW_AT_specification: <0xd5> <1><d4>: Abbrev Number: 0 Compilation Unit @ offset 0xd5: Length: 0x7 (32-bit) Version: 4 Abbrev Offset: 0x7f Pointer Size: 8 ... and indeed I get: ... $ gdb -q -batch outputs/gdb.dwarf2/dw2-inter-cu-error-2/dw2-inter-cu-error-2 Fatal signal: Segmentation fault ... The problem is that we're calling prepare_one_comp_unit with cu == nullptr and comp_unit_die == nullptr here in cooked_indexer::ensure_cu_exists: ... cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false, m_index_storage->get_abbrev_cache ()); prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die, language_minimal); ... Fix this by bailing out for various types of dummy CUs: ... if (new_reader.dummy_p || new_reader.comp_unit_die == nullptr || !new_reader.comp_unit_die->has_children) return nullptr; ... Also make sure in scan_attributes that this triggers a dwarf error: ... $ gdb -q -batch dw2-inter-cu-error-2 DWARF Error: cannot follow reference to DIE at 0xd5 \ [in module dw2-inter-cu-error-2] ... With target board readnow, the test-case triggers an assertion failure in follow_die_offset, so fix this by throwing the same dwarf error. While we're at it, make the other check for dummy CUs in cooked_indexer::ensure_cu_exists more robust by adding an intermediate test for comp_unit_die: ... - if (result->dummy_p || !result->comp_unit_die->has_children) + if (result->dummy_p || result->comp_unit_die == nullptr + || !result->comp_unit_die->has_children) return nullptr; ... Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/symtab] Use expand_all_symtabs in maint expand-symtabsTom de Vries1-7/+14
When issuing a command "maint expand-symtabs", maintenance_expand_symtabs is called with regexp == nullptr, and calls expand_symtabs_matching like so: ... objfile->expand_symtabs_matching ([&] (const char *filename, bool basenames) { /* KISS: Only apply the regexp to the complete file name. */ return (!basenames && (regexp == NULL || re_exec (filename))); }, ... To expand all symtabs gdb usually uses expand_all_symtabs (used for -readnow), but here we try to handle it in the filename_matcher argument. Make this more similar to how gdb usually works by using expand_all_symtabs. A previous version of the patch instead used a nullptr filename_matcher for the regexp == nullptr case. That approach regressed test-cases gdb.dwarf2/dwz-unused-pu.exp and gdb.dwarf2/dw2-dummy.exp. Tested on x86_64-linux.
2024-09-24[gdb/testsuite] Add gdb.dwarf2/dwz-unused-pu.expTom de Vries1-0/+75
Add a new test-case gdb.dwarf2/dwz-unused-pu.exp that checks that a symbol from an unused PU is not accessible. Passes with the relevant target boards: - unix (using the cooked index), - readnow (using no index at all), - cc-with-gdb-index (using .gdb_index), and - cc-with-debug-names (using .debug_names). Tested on x86_64-linux.
2024-09-24[gdb/symtab] Don't expand non-Ada CUs for info exceptionsTom de Vries12-35/+184
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-23testsuite, threads: fix LD_LIBRARY_PATH in 'tls-sepdebug.exp'Rohr, Stephan1-4/+9
Some compilers (e.g. the Intel compiler) may dynamically link against dependencies. The test uses the 'set env' command to set the LD_LIBRARY_PATH to a test specific value. Update the 'set env' command to also provide the users LD_LIBARY_PATH to gdb. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-23[gdb/testsuite] Avoid large timeout in gdb.base/checkpoint.expTom de Vries1-18/+32
I ran the testsuite in an environment simulating a stressed system, and the only test-cases that timed out in gdb.base were gdb.base/checkpoint.exp and gdb.base/checkpoint-ns.exp (which includes gdb.base/checkpoints.exp). In test-case gdb.base/checkpoint.exp there's a part where the timeout is increased with 120 seconds (in the default case that's from 10 to 130), to accommodate for a single command creating 600+ checkpoints. Instead, rewrite the test to present a gdb prompt each time a checkpoint is created, for which the default timeout is sufficient. Also ensure that the amount of checkpoints added is exactly 600 rather than 600+. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>