Tom Tromey [Tue, 31 Jan 2023 19:16:29 +0000 (12:16 -0700)]
Convert value_lval_const and deprecated_lval_hack to methods
This converts the value_lval_const and deprecated_lval_hack functions
to be methods on value.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 19:12:39 +0000 (12:12 -0700)]
Turn value_computed_closure and value_computed_funcs functions into methods
This changes the value_computed_funcs and value_computed_closure
functions to be methods of value.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 18:11:17 +0000 (11:11 -0700)]
Turn value_stack and set_value_stack functions into methods
This changes the value_stack and set_value_stack functions to be
methods of value.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 17:52:04 +0000 (10:52 -0700)]
Turn value_lazy and set_value_lazy functions into methods
This changes the value_lazy and set_value_lazy functions to be methods
of value. Much of this patch was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 17:40:38 +0000 (10:40 -0700)]
Turn some value offset functions into method
This changes various offset-related functions to be methods of value.
Much of this patch was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 17:19:10 +0000 (10:19 -0700)]
Turn value_enclosing_type into method
This changes value_enclosing_type to be a method of value. Much of
this patch was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 17:17:10 +0000 (10:17 -0700)]
Turn deprecated_value_modifiable into method
This changes deprecated_value_modifiable to be a method of value.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 17:05:01 +0000 (10:05 -0700)]
Turn value_offset into method
This changes value_offset to be a method of value. Much of this patch
was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 16:56:33 +0000 (09:56 -0700)]
Turn value_parent into method
This changes value_parent to be a method of value. Much of this patch
was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 16:44:47 +0000 (09:44 -0700)]
Turn value_bitpos into method
This changes value_bitpos to be a method of value. Much of this patch
was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 16:38:22 +0000 (09:38 -0700)]
Turn value_bitsize into method
This changes value_bitsize to be a method of value. Much of this patch
was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 15:31:48 +0000 (08:31 -0700)]
Turn value_arch into method
This changes value_arch to be a method of value. Much of this patch
was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 15:24:35 +0000 (08:24 -0700)]
Turn deprecated_set_value_type into a method
This changes deprecated_set_value_type to be a method of value. Much
of this patch was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 14:52:09 +0000 (07:52 -0700)]
Turn value_type into method
This changes value_type to be a method of value. Much of this patch
was written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 14:46:56 +0000 (07:46 -0700)]
Move struct value to value.h
This moves struct value to value.h. For now, all members remain
public, but this is a temporary state -- by the end of the series
we'll add 'private'.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 14:41:09 +0000 (07:41 -0700)]
Move ~value body out-of-line
struct value is going to move to value.h, but to avoid having
excessive code there, first move the destructor body out-of-line.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Jan 2023 14:40:33 +0000 (07:40 -0700)]
Rename all fields of struct value
This renames all the fields of struct value, in preparation for the
coming changes.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Michael Matz [Mon, 13 Feb 2023 17:20:44 +0000 (18:20 +0100)]
PR30120: fix x87 fucomp misassembled
this fixes the entry for 'fucomp' to use the correct Reg value
(otherwise it's assembled as 'fucom').
Tom Tromey [Mon, 13 Feb 2023 17:16:05 +0000 (10:16 -0700)]
Remove unused imports from gdb's Python code
The "sys" import is unused in several Python files. This removes this
line from all the places where it is unnecessary.
Andrew Burgess [Thu, 12 Jan 2023 16:18:53 +0000 (16:18 +0000)]
gdb/tui: don't leak the known_window_types map
This commit finishes the task that was started in the previous
commit.
Now that all Python TUI window factories are correctly deleted when
the Python interpreter is shut down, we no longer need to dynamically
allocate the known_window_types map in tui-layout.c
This commit changes known_window_types to a statically allocated data
structure, removes the dynamic allocation from
initialize_known_windows, and then replaces lots of '->' with '.'
throughout this file.
There should be no user visible changes after this commit.
Reviewed-By: Tom Tromey <tom@tromey.com>
Andrew Burgess [Thu, 12 Jan 2023 15:47:17 +0000 (15:47 +0000)]
gdb/python: deallocate tui window factories at Python shut down
The previous commit relied on spotting when a Python defined TUI
window factory was deleted. I spotted that the window factories are
not deleted when GDB shuts down its Python environment, they are only
deleted when one window factory replaces another. Consider this
example Python script:
class TestWindowFactory:
def __init__(self, msg):
self.msg = msg
print("Entering TestWindowFactory.__init__: %s" % self.msg)
def __call__(self, tui_win):
print("Entering TestWindowFactory.__call__: %s" % self.msg)
return TestWindow(tui_win, self.msg)
def __del__(self):
print("Entering TestWindowFactory.__del__: %s" % self.msg)
gdb.register_window_type("test_window", TestWindowFactory("A"))
gdb.register_window_type("test_window", TestWindowFactory("B"))
And this GDB session:
(gdb) source tui.py
Entering TestWindowFactory.__init__: A
Entering TestWindowFactory.__init__: B
Entering TestWindowFactory.__del__: B
(gdb) quit
Notice that when the 'B' window replaces the 'A' window we see the 'A'
object being deleted. But, when Python is shut down (after the
'quit') the 'B' object is never deleted.
Instead, GDB retains a reference to the window factory object, which
forces the Python object to remain live even after the Python
interpreter itself has been shut down.
The references themselves are held in a dynamically allocated
std::unordered_map (in tui/tui-layout.c) which is never deallocated,
thus the underlying Python references are never decremented to zero,
and so GDB never tries to delete these Python objects.
This commit is the first half of the work to clean up this edge case.
All gdbpy_tui_window_maker objects (the objects that implement the
TUI window factory callback for Python defined TUI windows), are now
linked together into a global list using the intrusive list mechanism.
When GDB shuts down the Python interpreter we can now walk this global
list and release the reference that is held to the underlying Python
object. By releasing this reference the Python object will now be
deleted.
I've added a new assert in gdbpy_tui_window_maker::operator(), this
will catch the case where we somehow end up in here after having
reset the reference to the underlying Python object. I don't think
this should ever happen though as we only clear the references when
shutting down the Python interpreter, and the ::operator() function is
only called when trying to apply a new TUI layout - something that
shouldn't happen while GDB itself is shutting down.
This commit does not update the std::unordered_map in tui-layout.c,
that will be done in the next commit.
Reviewed-By: Tom Tromey <tom@tromey.com>
Andrew Burgess [Thu, 12 Jan 2023 15:47:11 +0000 (15:47 +0000)]
gdb/python: allow Python TUI windows to be replaced
The documentation for gdb.register_window_type says:
"... It's an error to try to replace one of the built-in windows,
but other window types can be replaced. ..."
I take this to mean that if I imported a Python script like this:
gdb.register_window_type('my_window', FactoryFunction)
Then GDB would have a new TUI window 'my_window', which could be
created by calling FactoryFunction(). If I then, in the same GDB
session imported a script which included:
gdb.register_window_type('my_window', UpdatedFactoryFunction)
Then GDB would replace the old 'my_window' factory with my new one,
GDB would now call UpdatedFactoryFunction().
This is pretty useful in practice, as it allows users to iterate on
their window implementation within a single GDB session.
However, right now, this is not how GDB operates. The second call to
register_window_type is basically ignored and the old window factory
is retained.
This is because in tui_register_window (tui/tui-layout.c) we use
std::unordered_map::emplace to insert the new factory function, and
emplace doesn't replace an existing element in an unordered_map.
In this commit, before the emplace call, I now search for an already
existing element, and delete any matching element from the map, the
emplace call will then add the new factory function.
Reviewed-By: Tom Tromey <tom@tromey.com>
Keith Seitz [Mon, 13 Feb 2023 14:14:40 +0000 (06:14 -0800)]
Fix doc build dependencies for --with-system-readline
PR build/30108 concerns building gdb documentation with
--with-sytem-readline. If the in-tree readline directory is
missing, though, the docs will fail to build:
make[4]: Entering directory '/home/keiths/work/readline-doc-issue/linux/gdb/doc'
make[4]: *** No rule to make target '../../../src/gdb/doc/../../readline/readline/doc/rluser.texi', needed by 'gdb.info'. Stop.
The listed file (and hsuser.texi) are conditionally included by gdb.texinfo.
When system readline is used, gdb/configure.ac will leave
READLINE_TEXI_INCFLAGS empty, causing doc/Makefile.in to output a line to
$BUILD/doc/GDBvn.texi with "@set SYSTEM_READLINE". This surpresses the
inclusion of the missing files. They are not needed or used in this
scenario.
However, GDB_DOC_SOURCE_INCLUDES always lists these two files as dependencies,
thus provoking the build error whenever readline/ is missing.
This patch fixes this by creating (essentially) a conditional setting of the
dependencies to be included from readline.
Michael Matz [Thu, 9 Feb 2023 14:29:00 +0000 (15:29 +0100)]
Fix PR30079: abort on mingw
the early-out in wild_sort is not enough, it might still be
that filenames are equal _and_ the wildcard list doesn't specify
a sort order either. Don't call compare_section then.
Tested on all targets.
Alan Modra [Mon, 13 Feb 2023 11:45:05 +0000 (22:15 +1030)]
_bfd_ecoff_slurp_symbol_table buffer overflow
Add missing bounds check, and tidy the existing bounds checking.
* ecoff.c (_bfd_ecoff_slurp_symbol_table): Break overlong lines.
Set bfd_error. Bounds check internal_sym.iss.
Andrew Burgess [Fri, 6 Jan 2023 16:42:23 +0000 (16:42 +0000)]
opcodes/mips: disassemble unknown micromips instructions as two shorts
Before commit:
commit
2438b771ee07be19d5b01ea55e077dd8b7cef445
Date: Wed Nov 2 15:53:43 2022 +0000
opcodes/mips: use .word/.short for undefined instructions
unknown 32-bit microMIPS instructions were disassembled as a raw
32-bit number with no '.word' directive. The above commit changed
this and added a '.word' directive before the 32-bit number.
It was pointed out on the mailing list, that for microMIPS it would be
better to display such 32-bit instructions using a '.short' directive
followed by two 16-bit values.
This commit updates the mips disassembler to do this, and adds a new
test that validates this output.
Andrew Burgess [Mon, 13 Feb 2023 11:19:57 +0000 (11:19 +0000)]
gdb/testsuite: handle differences in guile error string output
A new guile test added in commit:
commit
0a9ccb9dd79384f3ba3f8cd75940e8868f3b526f
Date: Mon Feb 6 13:04:16 2023 +0000
gdb: only allow one of thread or task on breakpoints or watchpoints
fails for some versions of guile. It turns out that some versions of
guile emit an error like this:
(gdb) guile (set-breakpoint-thread! bp 1)
ERROR: In procedure set-breakpoint-thread!:
In procedure gdbscm_set_breakpoint_thread_x: cannot set both task and thread attributes
Error while executing Scheme code.
while other versions of guile emit the error like this:
(gdb) guile (set-breakpoint-thread! bp 1)
ERROR: In procedure set-breakpoint-thread!:
ERROR: In procedure gdbscm_set_breakpoint_thread_x: cannot set both task and thread attributes
Error while executing Scheme code.
notice the extra 'ERROR: ' on the second line of output. This commit
updates the test regexp to handle this optional 'ERROR: ' string.
Alan Modra [Mon, 13 Feb 2023 09:58:41 +0000 (20:28 +1030)]
stabs.c static state
Move all the function local static state variables to file scope,
in order to tidy memory on exit and to reinit everything for that
annoying oss-fuzz. Also fix a couple memory leaks.
* read.h (read_begin, read_end): Declare.
* read.c (read_begin): Call stabs_begin.
(read_end): Call stabs_end.
* stabs.c (stabs_begin, stabs_end): New functions.
(in_dot_func_p): Delete, use current_function_label instead.
(cached_sec): Move from s_stab_generic.
(last_asm_file, file_label_count): Move from generate_asm_file.
(line_label_count, prev_lineno, prev_line_file): Move from
stabs_generate_asm_lineno.
(void_emitted_p): Move from stabs_generate_asm_func.
(endfunc_label_count): Move from stabs_generate_asm_endfunc.
(stabs_generate_asm_lineno): Simplify setting of
prev_line_file.
(stabs_generate_asm_func): Don't leak current_function_label.
(stabs_generate_asm_endfunc): Likewise.
Alan Modra [Mon, 13 Feb 2023 09:54:52 +0000 (20:24 +1030)]
Split off gas init to functions
With some slight reordering.
* as.c (gas_early_init, gas_late_init): New functions, split..
(main): ..from here.
Lancelot SIX [Tue, 7 Feb 2023 15:13:47 +0000 (15:13 +0000)]
gdb/testsuite: look for hipcc in env(ROCM_PATH)
If the hipcc compiler cannot be found in dejagnu's tool_root_dir, look
for it in $::env(ROCM_PATH) (if set). If hipcc is still not found,
fallback to "hipcc" so the compiler will be searched in the PATH. This
removes the fallback to the hard-coded "/opt/rocm/bin" prefix.
This change is done so ROCM tools are searched in a uniform manner.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Lancelot SIX [Sat, 4 Feb 2023 23:57:07 +0000 (23:57 +0000)]
gdb/testsuite: allow_hipcc_tests tests the hipcc compiler
Update allow_hipcc_tests so all gdb.rocm tests are skipped if we do not
have a working hipcc compiler available.
To achieve this, adjust gdb_simple_compile to ensure that the hip
program is saved in a ".cpp" file before calling hipcc otherwise
compilation will fail.
One thing to note is that it is possible to have a hipcc installed with
a CUDA backend. Compiling with this back-end will successfully result
in an application, but GDB cannot debug it (at least for the offload
part). In the context of the gdb.rocm tests, we want to detect such
situation where gdb_simple_compile would give a false positive.
To achieve this, this patch checks that there is at least one AMDGPU
device available and that hipcc can compile for this or those targets.
Detecting the device is done using the rocm_agent_enumerator tool which
is installed with the all ROCm installations (it is used by hipcc to
detect identify targets if this is not specified on the comand line).
This patch also makes the allow_hipcc_tests proc a cached proc.
Co-Authored-By: Pedro Alves <pedro@palves.net>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Lancelot SIX [Mon, 6 Feb 2023 19:08:13 +0000 (19:08 +0000)]
gdb/testsuite: require amd-dbgapi support to run rocm tests
Update allow_hipcc_tests to check that GDB has the amd-dbgapi support
built-in. Without this support, all tests using hipcc and the rocm
stack will fail.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Lancelot SIX [Mon, 6 Feb 2023 18:05:31 +0000 (18:05 +0000)]
gdb/testsuite: Rename skip_hipcc_tests to allow_hipcc_tests
Rename skip_hipcc_tests to allow_hipcc_tests so it can be used as a
"require" predicate in tests.
Use require in gdb.rocm/simple.exp.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Lancelot SIX [Mon, 6 Feb 2023 19:16:14 +0000 (19:16 +0000)]
gdb: 'show config' shows --with[out]-amd-dbgapi
Ensure that the "show configuration" command and the "--configuration"
command line switch shows if GDB was built with the AMDGPU support or
not.
This will be used in a later patch in this series.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Alan Modra [Sun, 12 Feb 2023 12:04:27 +0000 (22:34 +1030)]
objcopy memory leaks
This fixes some objcopy memory leaks. commit
450da4bd38ae used
xatexit to tidy most of the hash table memory, but of course that's
ineffective without a call to xexit. The other major memory leak
happens if there is an error of some sort writing the output file, due
to not closing the input file and thus not freeing memory attached to
the bfd.
* objcopy.c (copy_file): Don't return when bfd_close of output
gives an error, always bfd_close input too.
(main): Call xexit.
GDB Administrator [Mon, 13 Feb 2023 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Fri, 27 Jan 2023 04:13:20 +0000 (21:13 -0700)]
Move some code from dwarf2/read.c to die.c
This patch introduces a new file, dwarf2/die.c, and moves some
DIE-related code out of dwarf2/read.c and into this new file. This is
just a small part of the long-term project to split up read.c.
(According to 'wc', dwarf2/read.c is the largest file in gdb by around
8000 LOC.)
Regression tested on x86-64 Fedora 36.
Andrew Burgess [Sun, 12 Feb 2023 07:14:31 +0000 (07:14 +0000)]
gdb: fix describe_other_breakpoints for default task being -1
Commit:
commit
2ecee236752932672fb3d6cd63c6976927f747d8
CommitDate: Sun Feb 12 05:46:44 2023 +0000
gdb: use -1 for breakpoint::task default value
Failed to take account of an earlier commit:
commit
f1f517e81039f6aa673b7d87a66bfbd25a66e3d3
CommitDate: Sat Feb 11 17:36:24 2023 +0000
gdb: show task number in describe_other_breakpoints
That both of these are my own commits is only more embarrassing.
This small fix updates describe_other_breakpoints to take account of
the default task number now being -1. This fixes regressions in
gdb.base/break.exp, gdb.base/break-always.exp, and many other tests.
Andrew Burgess [Fri, 16 Dec 2022 15:15:42 +0000 (15:15 +0000)]
gdb/c++: fix handling of breakpoints on @plt symbols
This commit should fix PR gdb/20091, PR gdb/17201, and PR gdb/17071.
Additionally, PR gdb/17199 relates to this area of code, but is more
of a request to refactor some parts of GDB, this commit does not
address that request, but it is probably worth reading that PR when
looking at this commit.
When the current language is C++, and the user places a breakpoint on
a function in a shared library, GDB will currently find two locations
for the breakpoint, one location will be within the function itself as
we would expect, but the other location will be within the PLT table
for the call to the named function. Consider this session:
$ gdb -q /tmp/breakpoint-shlib-func
Reading symbols from /tmp/breakpoint-shlib-func...
(gdb) start
Temporary breakpoint 1 at 0x40112e: file /tmp/breakpoint-shlib-func.cc, line 20.
Starting program: /tmp/breakpoint-shlib-func
Temporary breakpoint 1, main () at /tmp/breakpoint-shlib-func.cc:20
20 int answer = foo ();
(gdb) break foo
Breakpoint 2 at 0x401030 (2 locations)
(gdb) info breakpoints
Num Type Disp Enb Address What
2 breakpoint keep y <MULTIPLE>
2.1 y 0x0000000000401030 <foo()@plt>
2.2 y 0x00007ffff7fc50fd in foo() at /tmp/breakpoint-shlib-func-lib.cc:20
This is not the expected behaviour. If we compile the same test using
a C compiler then we see this:
(gdb) break foo
Breakpoint 2 at 0x7ffff7fc50fd: file /tmp/breakpoint-shlib-func-c-lib.c, line 20.
(gdb) info breakpoints
Num Type Disp Enb Address What
2 breakpoint keep y 0x00007ffff7fc50fd in foo at /tmp/breakpoint-shlib-func-c-lib.c:20
Here's what's happening. When GDB parses the symbols in the main
executable and the shared library we see a number of different symbols
for foo, and use these to create entries in GDB's msymbol table:
- In the main executable we see a symbol 'foo@plt' that points at
the plt entry for foo, from this we add two entries into GDB's
msymbol table, one called 'foo@plt' which points at the plt entry
and has type mst_text, then we create a second symbol, this time
called 'foo' with type mst_solib_trampoline which also points at
the plt entry,
- Then, when the shared library is loaded we see another symbol
called 'foo', this one points at the actual implementation in the
shared library. This time GDB creates a msymbol called 'foo' with
type mst_text that points at the implementation.
This means that GDB creates 3 msymbols to represent the 2 symbols
found in the executable and shared library.
When the user creates a breakpoint on 'foo' GDB eventually ends up in
search_minsyms_for_name (linespec.c), this function then calls
iterate_over_minimal_symbols passing in the name we are looking for
wrapped in a lookup_name_info object.
In iterate_over_minimal_symbols we iterate over two hash tables (using
the name we're looking for as the hash key), first we walk the hash
table of symbol linkage names, then we walk the hash table of
demangled symbol names.
When the language is C++ the symbols for 'foo' will all have been
mangled, as a result, in this case, the iteration of the linkage name
hash table will find no matching results.
However, when we walk the demangled hash table we do find some
results. In order to match symbol names, GDB obtains a symbol name
matching function by calling the get_symbol_name_matcher method on the
language_defn class. For C++, in this case, the matching function we
use is cp_fq_symbol_name_matches, which delegates the work to
strncmp_iw_with_mode with mode strncmp_iw_mode::MATCH_PARAMS and
language set to language_cplus.
The strncmp_iw_mode::MATCH_PARAMS mode means that strncmp_iw_mode will
skip any parameters in the demangled symbol name when checking for a
match, e.g. 'foo' will match the demangled name 'foo()'. The way this
is done is that the strings are matched character by character, but,
once the string we are looking for ('foo' here) is exhausted, if we
are looking at '(' then we consider the match a success.
Lets consider the 3 symbols GDB created. If the function declaration
is 'void foo ()' then from the main executable we added symbols
'_Z3foov@plt' and '_Z3foov', while from the shared library we added
another symbol call '_Z3foov'. When these are demangled they become
'foo()@plt', 'foo()', and 'foo()' respectively.
Now, the '_Z3foov' symbol from the main executable has the type
mst_solib_trampoline, and in search_minsyms_for_name, we search for
any symbols of type mst_solib_trampoline and filter these out of the
results.
However, the '_Z3foov@plt' symbol (from the main executable), and the
'_Z3foov' symbol (from the shared library) both have type mst_text.
During the demangled name matching, due to the use of MATCH_PARAMS
mode, we stop the comparison as soon as we hit a '(' in the demangled
name. And so, '_Z3foov@plt', which demangles to 'foo()@plt' matches
'foo', and '_Z3foov', which demangles to 'foo()' also matches 'foo'.
By contrast, for C, there are no demangled hash table entries to be
iterated over (in iterate_over_minimal_symbols), we only consider the
linkage name symbols which are 'foo@plt' and 'foo'. The plain 'foo'
symbol obviously matches when we are looking for 'foo', but in this
case the 'foo@plt' will not match due to the '@plt' suffix.
And so, when the user asks for a breakpoint in 'foo', and the language
is C, search_minsyms_for_name, returns a single msymbol, the mst_text
symbol for foo in the shared library, while, when the language is C++,
we get two results, '_Z3foov' for the shared library function, and
'_Z3foov@plt' for the plt entry in the main executable.
I propose to fix this in strncmp_iw_with_mode. When the mode is
MATCH_PARAMS, instead of stopping at a '(' and assuming the match is a
success, GDB will instead search forward for the matching, closing,
')', effectively skipping the parameter list, and then resume
matching. Thus, when comparing 'foo' to 'foo()@plt' GDB will
effectively compare against 'foo@plt' (skipping the parameter list),
and the match will fail, just as it does when the language is C.
There is one slight complication, which is revealed by the test
gdb.linespec/cpcompletion.exp, when searching for the symbol of a
const member function, the demangled symbol will have 'const' at the
end of its name, e.g.:
struct_with_const_overload::const_overload_fn() const
Previously, the matching would stop at the '(' character, but after my
change the whole '()' is skipped, and the match resumes. As a result,
the 'const' modifier results in a failure to match, when previously
GDB would have found a match.
To work around this issue, in strncmp_iw_with_mode, when mode is
MATCH_PARAMS, after skipping the parameter list, if the next character
is '@' then we assume we are looking at something like '@plt' and
return a value indicating the match failed, otherwise, we return a
value indicating the match succeeded, this allows things like 'const'
to be skipped.
With these changes in place I now see GDB correctly setting a
breakpoint only at the implementation of 'foo' in the shared library.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20091
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17201
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17071
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17199
Tested-By: Bruno Larsen <blarsen@redhat.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Andrew Burgess [Wed, 8 Feb 2023 10:31:14 +0000 (10:31 +0000)]
gdb: use -1 for breakpoint::task default value
Within the breakpoint struct we have two fields ::thread and ::task
which are used for thread or task specific breakpoints. When a
breakpoint doesn't have a specific thread or task then these fields
have the values -1 and 0 respectively.
There's no particular reason (as far as I can tell) why these two
"default" values are different, and I find the difference a little
confusing. Long term I'd like to potentially fold these two fields
into a single field, but that isn't what this commit does.
What this commit does is switch to using -1 as the "default" value for
both fields, this means that the default for breakpoint::task has
changed from 0 to -1. I've updated all the code I can find that
relied on the value of 0, and I see no test regressions, especially in
gdb.ada/tasks.exp, which still fully passes.
There should be no user visible changes after this commit.
Approved-By: Pedro Alves <pedro@palves.net>
Andrew Burgess [Mon, 6 Feb 2023 13:04:16 +0000 (13:04 +0000)]
gdb: only allow one of thread or task on breakpoints or watchpoints
After this mailing list posting:
https://sourceware.org/pipermail/gdb-patches/2023-February/196607.html
it seems to me that in practice an Ada task maps 1:1 with a GDB
thread, and so it doesn't really make sense to allow uses to give both
a thread and a task within a single breakpoint or watchpoint
condition.
This commit updates GDB so that the user will get an error if both
are specified.
I've added new tests to cover the CLI as well as the Python and Guile
APIs. For the Python and Guile testing, as far as I can tell, this
was the first testing for this corner of the APIs, so I ended up
adding more than just a single test.
For documentation I've added a NEWS entry, but I've not added anything
to the docs themselves. Currently we document the commands with a
thread-id or task-id as distinct command, e.g.:
'break LOCSPEC task TASKNO'
'break LOCSPEC task TASKNO if ...'
'break LOCSPEC thread THREAD-ID'
'break LOCSPEC thread THREAD-ID if ...'
As such, I don't believe there is any indication that combining 'task'
and 'thread' would be expected to work; it seems clear to me in the
above that those four options are all distinct commands.
I think the NEWS entry is enough that if someone is combining these
keywords (it's not clear what the expected behaviour would be in this
case) then they can figure out that this was a deliberate change in
GDB, but for a new user, the manual doesn't suggest combining them is
OK, and any future attempt to combine them will give an error.
Approved-By: Pedro Alves <pedro@palves.net>
GDB Administrator [Sun, 12 Feb 2023 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in
Andrew Burgess [Wed, 8 Feb 2023 13:23:14 +0000 (13:23 +0000)]
gdb: show task number in describe_other_breakpoints
I noticed that describe_other_breakpoints doesn't show the task
number, but does show the thread-id. I can't see any reason why we'd
want to not show the task number in this situation, so this commit
adds this missing information, and extends gdb.ada/tasks.exp to check
this case.
Approved-By: Pedro Alves <pedro@palves.net>
Andrew Burgess [Wed, 8 Feb 2023 11:37:44 +0000 (11:37 +0000)]
gdb: don't print global thread-id to CLI in describe_other_breakpoints
I noticed that describe_other_breakpoints was printing the global
thread-id to the CLI. For CLI output we should be printing the
inferior local thread-id (e.g. "2.1"). This can be seen in the
following GDB session:
(gdb) info threads
Id Target Id Frame
1.1 Thread
4065742.
4065742 "bp-thread-speci" main () at /tmp/bp-thread-specific.c:27
* 2.1 Thread
4065743.
4065743 "bp-thread-speci" main () at /tmp/bp-thread-specific.c:27
(gdb) break foo thread 2.1
Breakpoint 3 at 0x40110a: foo. (2 locations)
(gdb) break foo thread 1.1
Note: breakpoint 3 (thread 2) also set at pc 0x40110a.
Note: breakpoint 3 (thread 2) also set at pc 0x40110a.
Breakpoint 4 at 0x40110a: foo. (2 locations)
Notice that GDB says:
Note: breakpoint 3 (thread 2) also set at pc 0x40110a.
The 'thread 2' in here is using the global thread-id, we should
instead say 'thread 2.1' which corresponds to how the user specified
the breakpoint.
This commit fixes this issue and adds a test.
Approved-By: Pedro Alves <pedro@palves.net>
Andrew Burgess [Thu, 9 Feb 2023 10:52:47 +0000 (10:52 +0000)]
gdb: add test for readline handling very long commands
The test added in this commit tests for a long fixed readline issue
relating to long command lines. A similar patch has existed in the
Fedora GDB tree for several years, but I don't see any reason why this
test would not be suitable for inclusion in upstream GDB. I've
updated the patch to current testsuite standards.
The test is checking for an issue that was fixed by this readline
patch:
https://lists.gnu.org/archive/html/bug-readline/2006-11/msg00002.html
Which was merged into readline 6.0 (released ~2010). The issue was
triggered when the user enters a long command line, which wrapped over
multiple terminal lines. The crash looks like this:
free(): invalid pointer
Fatal signal: Aborted
----- Backtrace -----
0x4fb583 gdb_internal_backtrace_1
../../src/gdb/bt-utils.c:122
0x4fb583 _Z22gdb_internal_backtracev
../../src/gdb/bt-utils.c:168
0x6047b9 handle_fatal_signal
../../src/gdb/event-top.c:964
0x7f26e0cc56af ???
0x7f26e0cc5625 ???
0x7f26e0cae8d8 ???
0x7f26e0d094be ???
0x7f26e0d10aab ???
0x7f26e0d124ab ???
0x7f26e1d32e12 rl_free_undo_list
../../readline-5.2/undo.c:119
0x7f26e1d229eb readline_internal_teardown
../../readline-5.2/readline.c:405
0x7f26e1d3425f rl_callback_read_char
../../readline-5.2/callback.c:197
0x604c0d gdb_rl_callback_read_char_wrapper_noexcept
../../src/gdb/event-top.c:192
0x60581d gdb_rl_callback_read_char_wrapper
../../src/gdb/event-top.c:225
0x60492f stdin_event_handler
../../src/gdb/event-top.c:545
0xa60015 gdb_wait_for_event
../../src/gdbsupport/event-loop.cc:694
0xa6078d gdb_wait_for_event
../../src/gdbsupport/event-loop.cc:593
0xa6078d _Z16gdb_do_one_eventi
../../src/gdbsupport/event-loop.cc:264
0x6fc459 start_event_loop
../../src/gdb/main.c:411
0x6fc459 captured_command_loop
../../src/gdb/main.c:471
0x6fdce4 captured_main
../../src/gdb/main.c:1310
0x6fdce4 _Z8gdb_mainP18captured_main_args
../../src/gdb/main.c:1325
0x44f694 main
../../src/gdb/gdb.c:32
---------------------
I recreated the above crash by a little light hacking on GDB, and then
linking GDB against readline 5.2. The above stack trace was generated
from the test included in this patch, and matches the trace that was
included in the original bug report.
It is worth acknowledging that without hacking things GDB has a
minimum requirement of readline 7.0. This test is not about checking
whether GDB has been built against an older version of readline, it is
about checking that readline doesn't regress in this area.
Reviewed-By: Tom Tromey <tom@tromey.com>
Andrew Burgess [Wed, 8 Feb 2023 16:47:34 +0000 (16:47 +0000)]
gdb: remove unnecessary 'dir' commands from gdb-gdb.gdb script
While debugging GDB I used 'show directories' and spotted lots of
entries that didn't make much sense. Here are all the entries that are
in my directories list:
/tmp/binutils-gdb/build
/tmp/binutils-gdb/build/../../src/gdb
/tmp/binutils-gdb/build/../../src/gdb/../bfd
/tmp/binutils-gdb/build/../../src/gdb/../libiberty
$cdir
$cwd
Notice the second, third, and fourth entries in this list, these
should really be:
/tmp/binutils-gdb/build/../src/gdb
/tmp/binutils-gdb/build/../src/gdb/../bfd
/tmp/binutils-gdb/build/../src/gdb/../libiberty
The problem is because I generally run everything from the top level
build directory, not the gdb/ sub-directory, thus, I start GDB like:
./gdb/gdb --data-directory ./gdb/data-directory
If run GDB under GDB, then I end up loading the gdb/gdb-gdb.gdb
script, which contains these lines:
dir ../../src/gdb/../libiberty
dir ../../src/gdb/../bfd
dir ../../src/gdb
dir .
These commands only make sense when running within the gdb/
sub-directory.
However, my debugging experience doesn't seem to be degraded at all, I
can still see the GDB source code just fine; which is because the
directory list still contains $cdir.
The build/gdb/gdb-gdb.gdb script is created from the
src/gdb/gdb-gdb.gdb.in template, which includes the automake @srcdir@
markers.
The 'dir' commands have mostly been around since the sourceware
repository was first created, though this commit
67f0714670383a did
reorder some of the 'dir' commands, which would seem to indicate these
commands were important to some people, at some time.
One possible fix would be to replace @srcdir@ with @abs_srcdir@, this
would ensure that the entries added were all valid, no matter the
user's current directory when debugging GDB.
However... I'd like to propose that we instead remove all the extra
directories completely. My hope is that, with more recent tools, the
debug information should allow us to correctly find all of the source
files without having to add any extra 'dir' entries. Obviously,
commit
67f0714670383a does make me a little nervous, but the
gdb-gdb.gdb script isn't something a non-maintainer will be using, so
I think we can afford to be a little more aggressive here. If it
turns out the 'dir' entries are needed then we can add them back, but
actually document why they are needed. Plus, when we add them back we
will use @abs_srcdir@ instead of @srcdir@.
Reviewed-By: Tom Tromey <tom@tromey.com>
Tom de Vries [Sat, 11 Feb 2023 08:04:51 +0000 (09:04 +0100)]
[gdb/tdep] Don't use i386 unwinder for amd64
For i386 we have these unwinders:
...
$ gdb -q -batch -ex "set arch i386" -ex "maint info frame-unwinders"
The target architecture is set to "i386".
dummy DUMMY_FRAME
dwarf2 tailcall TAILCALL_FRAME
inline INLINE_FRAME
i386 epilogue NORMAL_FRAME
dwarf2 NORMAL_FRAME
dwarf2 signal SIGTRAMP_FRAME
i386 stack tramp NORMAL_FRAME
i386 sigtramp SIGTRAMP_FRAME
i386 prologue NORMAL_FRAME
...
and for amd64:
...
$ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
The target architecture is set to "i386:x86-64".
dummy DUMMY_FRAME
dwarf2 tailcall TAILCALL_FRAME
inline INLINE_FRAME
python NORMAL_FRAME
amd64 epilogue NORMAL_FRAME
i386 epilogue NORMAL_FRAME
dwarf2 NORMAL_FRAME
dwarf2 signal SIGTRAMP_FRAME
amd64 sigtramp SIGTRAMP_FRAME
amd64 prologue NORMAL_FRAME
i386 stack tramp NORMAL_FRAME
i386 sigtramp SIGTRAMP_FRAME
i386 prologue NORMAL_FRAME
...
ISTM me there's no reason for the i386 unwinders to be there for amd64.
Furthermore, there's a generic need to play around with enabling and disabling
unwinders, see PR8434. Currently, that's only available for both the dwarf2
unwinders at once using "maint set dwarf unwinders on/off".
If I manually disable the "amd64 epilogue" unwinder, the "i386 epilogue"
unwinder becomes active and gives the wrong answer, while I'm actually
interested in the result of the dwarf2 unwinder. Of course I can also
manually disable the "i386 epilogue", but I take the fact that I have to do
that as evidence that on amd64, the "i386 epilogue" is not only unnecessary,
but in the way.
Fix this by only adding the i386 unwinders if
"info.bfd_arch_info->bits_per_word == 32".
Note that the x32 abi (x86_64/-mx32):
- has the same unwinder list as amd64 (x86_64/-m64) before this commit,
- has info.bfd_arch_info->bits_per_word == 64, the same as amd64, and
consequently,
- has the same unwinder list as amd64 after this commit.
Tested on x86_64-linux, -m64 and -m32. Not tested with -mx32.
Reviewed-By: John Baldwin <jhb@freebsd.org>
PR tdep/30102
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30102
Alan Modra [Fri, 10 Feb 2023 22:06:24 +0000 (08:36 +1030)]
objdump -D of bss sections and -s with -j
There is some inconsistency between the behaviour of objdump -D and
objdump -s, both supposedly operating on all sections by default.
objdump -s ignores bss sections, while objdump -D dissassembles the
zeros. Fix this by making objdump -D ignore bss sections too.
Furthermore, "objdump -s -j .bss" doesn't dump .bss as it should,
since the user is specifically asking to look at all those zeros.
This change does find some tests that used objdump -D with expected
output in bss-style sections. I've updated all the msp430 tests that
just wanted to find a non-empty section to look at section headers
instead, making the tests slightly more stringent. The ppc xcoff and
spu tests are fixed by adding -j options to objdump, which makes the
tests somewhat more lenient.
binutils/
* objdump.c (disassemble_section): Ignore sections without
contents, unless overridden by -j.
(dump_section): Allow -j to override the default of not
displaying sections without contents.
* doc/binutils.texi (objdump options): Update -D, -s and -j
description.
gas/
* testsuite/gas/ppc/xcoff-tls-32.d: Select wanted objdump
sections with -j.
* testsuite/gas/ppc/xcoff-tls-64.d: Likewise.
ld/
* testsuite/ld-msp430-elf/main-bss-lower.d,
* testsuite/ld-msp430-elf/main-bss-upper.d,
* testsuite/ld-msp430-elf/main-const-lower.d,
* testsuite/ld-msp430-elf/main-const-upper.d,
* testsuite/ld-msp430-elf/main-text-lower.d,
* testsuite/ld-msp430-elf/main-text-upper.d,
* testsuite/ld-msp430-elf/main-var-lower.d,
* testsuite/ld-msp430-elf/main-var-upper.d: Expect -wh output.
* testsuite/ld-msp430-elf/msp430-elf.exp: Use objdump -wh
rather than objdump -D or objdump -d with tests checking for
non-empty given sections.
* testsuite/ld-spu/ear.d,
* testsuite/ld-spu/icache1.d,
* testsuite/ld-spu/ovl.d,
* testsuite/ld-spu/ovl2.d: Select wanted objdump sections.
Alan Modra [Fri, 10 Feb 2023 12:46:34 +0000 (23:16 +1030)]
.debug sections without contents
* dwarf1.c (_bfd_dwarf1_find_nearest_line): Exclude .debug
sections without contents.
Aaron Merey [Fri, 10 Feb 2023 01:35:32 +0000 (20:35 -0500)]
gdb/source: Fix open_source_file error handling
open_source_file relies on errno to communicate the reason for a missing
source file.
open_source_file may also call debuginfod_find_source. It is possible
for debuginfod_find_source to set errno to a value unrelated to the
reason for a failed download.
This can result in bogus error messages being reported as the reason for
a missing source file. The following error message should instead be
"No such file or directory":
Temporary breakpoint 1, 0x00005555556f4de0 in main ()
(gdb) list
Downloading source file /usr/src/debug/glibc-2.36-8.fc37.x86_64/elf/<built-in>
1 /usr/src/debug/glibc-2.36-8.fc37.x86_64/elf/<built-in>: Directory not empty.
Fix this by having open_source_file return a negative errno if it fails
to open a source file. Use this value to generate the error message
instead of errno.
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29999
Aaron Merey [Fri, 10 Feb 2023 01:28:20 +0000 (20:28 -0500)]
Move implementation of perror_with_name to gdbsupport
gdbsupport/errors.h declares perror_with_name and leaves the
implementation to the clients.
However gdb and gdbserver's implementations are essentially the
same, resulting in unnecessary code duplication.
Fix this by implementing perror_with_name in gdbsupport. Add an
optional parameter for specifying the errno used to generate the
error message.
Also move the implementation of perror_string to gdbsupport since
perror_with_name requires it.
Approved-By: Tom Tromey <tom@tromey.com>
GDB Administrator [Sat, 11 Feb 2023 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in
Andrew Burgess [Fri, 10 Feb 2023 23:49:19 +0000 (23:49 +0000)]
GDB: Introduce limited array lengths while printing values
This commit introduces the idea of loading only part of an array in
order to print it, what I call "limited length" arrays.
The motivation behind this work is to make it possible to print slices
of very large arrays, where very large means bigger than
`max-value-size'.
Consider this GDB session with the current GDB:
(gdb) set max-value-size 100
(gdb) p large_1d_array
value requires 400 bytes, which is more than max-value-size
(gdb) p -elements 10 -- large_1d_array
value requires 400 bytes, which is more than max-value-size
notice that the request to print 10 elements still fails, even though 10
elements should be less than the max-value-size. With a patched version
of GDB:
(gdb) p -elements 10 -- large_1d_array
$1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}
So now the print has succeeded. It also has loaded `max-value-size'
worth of data into value history, so the recorded value can be accessed
consistently:
(gdb) p -elements 10 -- $1
$2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}
(gdb) p $1
$3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, <unavailable> <repeats 75 times>}
(gdb)
Accesses with other languages work similarly, although for Ada only
C-style [] array element/dimension accesses use history. For both Ada
and Fortran () array element/dimension accesses go straight to the
inferior, bypassing the value history just as with C pointers.
Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com>
Maciej W. Rozycki [Fri, 10 Feb 2023 23:49:19 +0000 (23:49 +0000)]
GDB/testsuite: Add `-nonl' option to `gdb_test'
Add a `-nonl' option to `gdb_test' making it possible to match output
from commands such as `output' that do not produce a new line sequence
at the end, e.g.:
(gdb) output 0
0(gdb)
Maciej W. Rozycki [Fri, 10 Feb 2023 23:49:19 +0000 (23:49 +0000)]
GDB: Only make data actually retrieved into value history available
While it makes sense to allow accessing out-of-bounds elements in the
debuggee and see whatever there might happen to be there in memory (we
are a debugger and not a programming rules enforcement facility and we
want to make people's life easier in chasing bugs), e.g.:
(gdb) print one_hundred[-1]
$1 = 0
(gdb) print one_hundred[100]
$2 = 0
(gdb)
we shouldn't really pretend that we have any meaningful data around
values recorded in history (what these commands really retrieve are
current debuggee memory contents outside the original data accessed,
really confusing in my opinion). Mark values recorded in history as
such then and verify accesses to be in-range for them:
(gdb) print one_hundred[-1]
$1 = <unavailable>
(gdb) print one_hundred[100]
$2 = <unavailable>
Add a suitable test case, which also covers integer overflows in data
location calculation.
Approved-By: Tom Tromey <tom@tromey.com>
Maciej W. Rozycki [Fri, 10 Feb 2023 23:49:19 +0000 (23:49 +0000)]
GDB: Fix the mess with value byte/bit range types
Consistently use the LONGEST and ULONGEST types for value byte/bit
offsets and lengths respectively, avoiding silent truncation for ranges
exceeding the 32-bit span, which may cause incorrect matching. Also
report a conversion overflow on byte ranges that cannot be expressed in
terms of bits with these data types, e.g.:
(gdb) print one_hundred[1LL << 58]
Integer overflow in data location calculation
(gdb) print one_hundred[(-1LL << 58) - 1]
Integer overflow in data location calculation
(gdb)
Previously such accesses would be let through with unpredictable results
produced.
Maciej W. Rozycki [Fri, 10 Feb 2023 23:49:19 +0000 (23:49 +0000)]
GDB: Ignore `max-value-size' setting with value history accesses
We have an inconsistency in value history accesses where array element
accesses cause an error for entries exceeding the currently selected
`max-value-size' setting even where such accesses successfully complete
for elements located in the inferior, e.g.:
(gdb) p/d one
$1 = 0
(gdb) p/d one_hundred
$2 = {0 <repeats 100 times>}
(gdb) p/d one_hundred[99]
$3 = 0
(gdb) set max-value-size 25
(gdb) p/d one_hundred
value requires 100 bytes, which is more than max-value-size
(gdb) p/d one_hundred[99]
$7 = 0
(gdb) p/d $2
value requires 100 bytes, which is more than max-value-size
(gdb) p/d $2[99]
value requires 100 bytes, which is more than max-value-size
(gdb)
According to our documentation the `max-value-size' setting is a safety
guard against allocating an overly large amount of memory. Moreover a
statement in documentation says, concerning this setting, that: "Setting
this variable does not affect values that have already been allocated
within GDB, only future allocations." While in the implementer-speak
the sentence may be unambiguous I think the outside user may well infer
that the setting does not apply to values previously printed.
Therefore rather than just fixing this inconsistency it seems reasonable
to lift the setting for value history accesses, under an implication
that by having been retrieved from the debuggee they have already passed
the safety check. Do it then, by suppressing the value size check in
`value_copy' -- under an observation that if the original value has been
already loaded (i.e. it's not lazy), then it must have previously passed
said check -- making the last two commands succeed:
(gdb) p/d $2
$8 = {0 <repeats 100 times>}
(gdb) p/d $2 [99]
$9 = 0
(gdb)
Expand the testsuite accordingly, covering both value history handling
and the use of `value_copy' by `make_cv_value', used by Python code.
Maciej W. Rozycki [Fri, 10 Feb 2023 23:49:19 +0000 (23:49 +0000)]
GDB: Switch to using C++ standard integer type limits
Use <climits> instead of <limits.h> and ditch local fallback definitions
for minimum and maximum value macros provided by C++11. Add LONGEST_MAX
and LONGEST_MIN definitions.
Approved-By: Tom Tromey <tom@tromey.com>
Tom Tromey [Fri, 10 Feb 2023 18:59:03 +0000 (11:59 -0700)]
Ensure all DAP requests are keyword-only
Python functions implementing DAP requests should not use positional
parameters -- it only makes sense to call them with keyword arguments.
This patch changes the few remaining cases to start with the special
"*" parameter, following this rule.
Simon Marchi [Tue, 17 Jan 2023 16:33:39 +0000 (11:33 -0500)]
gdb/testsuite: fix gdb.gdb/selftest.exp for native-extended-gdbserver
Following commit
4e2a80ba606 ("gdb/testsuite: expect SIGSEGV from top
GDB spawn id"), the next failure I get in gdb.gdb/selftest.exp, using
the native-extended-gdbserver, is:
(gdb) PASS: gdb.gdb/selftest.exp: send ^C to child process
signal SIGINT
Continuing with signal SIGINT.
FAIL: gdb.gdb/selftest.exp: send SIGINT signal to child process (timeout)
The problem is that in this gdb_test_multiple:
set description "send SIGINT signal to child process"
gdb_test_multiple "signal SIGINT" "$description" {
-re "^signal SIGINT\r\nContinuing with signal SIGINT.\r\nQuit\r\n.* $" {
pass "$description"
}
}
The "Continuing with signal SIGINT" portion is printed by the top GDB,
while the Quit portion is printed by the bottom GDB. As the
gdb_test_multiple is written, it expects both the the top GDB's spawn
id.
Fix this by splitting the gdb_test_multiple in two. The first one
expects the "Continuing with signal SIGINT" from the top GDB. The
second one expect "Quit" and the "(xgdb)" prompt from
$inferior_spawn_id. When debugging natively, this spawn id will be the
same as the top GDB's spawn id, but it's different when debugging with
GDBserver.
Change-Id: I689bd369a041b48f4dc9858d38bf977d09600da2
Tom Tromey [Fri, 30 Dec 2022 18:23:43 +0000 (11:23 -0700)]
Use std::string in main_info
This changes main_info to use std::string. It removes some manual
memory management.
Tom de Vries [Fri, 10 Feb 2023 14:58:00 +0000 (15:58 +0100)]
[gdb/testsuite] Fix linespec ambiguity in gdb.base/longjmp.exp
PR testsuite/30103 reports the following failure on aarch64-linux
(ubuntu 22.04):
...
(gdb) PASS: gdb.base/longjmp.exp: with_probes=0: pattern 1: next to longjmp
next
warning: Breakpoint address adjusted from 0x83dc305fef755015 to \
0xffdc305fef755015.
Warning:
Cannot insert breakpoint 0.
Cannot access memory at address 0xffdc305fef755015
__libc_siglongjmp (env=0xaaaaaaab1018 <env>, val=1) at ./setjmp/longjmp.c:30
30 }
(gdb) KFAIL: gdb.base/longjmp.exp: with_probes=0: pattern 1: gdb/26967 \
(PRMS: next over longjmp)
delete breakpoints
Delete all breakpoints? (y or n) y
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break 63
No line 63 in the current file.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) FAIL: gdb.base/longjmp.exp: with_probes=0: pattern 2: setup: breakpoint \
at pattern start (got interactive prompt)
...
The test-case intends to set the breakpoint on line number 63 in
gdb.base/longjmp.c.
It tries to do so by specifying "break 63", which specifies a line in the
"current source file".
Due to the KFAIL PR, gdb stopped in __libc_siglongjmp, and because of presence
of debug info, the "current source file" becomes glibc's ./setjmp/longjmp.c.
Consequently, setting the breakpoint fails.
Fix this by adding a $subdir/$srcfile: prefix to the breakpoint linespecs.
I've managed to reproduce the FAIL on x86_64/-m32, by installing the
glibc-32bit-debuginfo package. This allowed me to confirm the "current source
file" that is used:
...
(gdb) KFAIL: gdb.base/longjmp.exp: with_probes=0: pattern 1: gdb/26967 \
(PRMS: next over longjmp)
info source^M
Current source file is ../setjmp/longjmp.c^M
...
Tested on x86_64-linux, target boards unix/{-m64,-m32}.
Reported-By: Luis Machado <luis.machado@arm.com>
Reviewed-By: Tom Tromey <tom@tromey.com>
PR testsuite/30103
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30103
Tom de Vries [Fri, 10 Feb 2023 12:07:14 +0000 (13:07 +0100)]
[gdb/cli] Add maint info frame-unwinders
Add a new command "maint info frame-unwinders":
...
(gdb) help maint info frame-unwinders
List the frame unwinders currently in effect, starting with the highest \
priority.
...
Output for i386:
...
$ gdb -q -batch -ex "set arch i386" -ex "maint info frame-unwinders"
The target architecture is set to "i386".
dummy DUMMY_FRAME
dwarf2 tailcall TAILCALL_FRAME
inline INLINE_FRAME
i386 epilogue NORMAL_FRAME
dwarf2 NORMAL_FRAME
dwarf2 signal SIGTRAMP_FRAME
i386 stack tramp NORMAL_FRAME
i386 sigtramp SIGTRAMP_FRAME
i386 prologue NORMAL_FRAME
...
Output for x86_64:
...
$ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
The target architecture is set to "i386:x86-64".
dummy DUMMY_FRAME
dwarf2 tailcall TAILCALL_FRAME
inline INLINE_FRAME
python NORMAL_FRAME
amd64 epilogue NORMAL_FRAME
i386 epilogue NORMAL_FRAME
dwarf2 NORMAL_FRAME
dwarf2 signal SIGTRAMP_FRAME
amd64 sigtramp SIGTRAMP_FRAME
amd64 prologue NORMAL_FRAME
i386 stack tramp NORMAL_FRAME
i386 sigtramp SIGTRAMP_FRAME
i386 prologue NORMAL_FRAME
...
Tested on x86_64-linux.
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Tsukasa OI [Fri, 10 Feb 2023 09:27:28 +0000 (09:27 +0000)]
RISC-V: Reduce effective linker relaxation passses
Commit
43025f01a0c9 ("RISC-V: Improve link time complexity.") reduced the
time complexity of the linker relaxation but some code portions did not
reflect this change.
This commit fixes a comment describing each relaxation pass and reduces
actual number of passes for the RISC-V linker relaxation from 3 to 2.
Though it does not change the functionality, it marginally improves the
performance while linking large programs (with many relocations).
bfd/ChangeLog:
* elfnn-riscv.c (_bfd_riscv_relax_section): Fix a comment to
reflect current roles of each relaxation pass.
ld/ChangeLog:
* emultempl/riscvelf.em: Reduce the number of linker relaxation
passes from 3 to 2.
Alan Modra [Fri, 10 Feb 2023 09:38:40 +0000 (20:08 +1030)]
Fix mmo memory leaks
The main one here is the section buffer, which can be quite large.
By using alloc rather than malloc we can leave tidying memory to the
generic bfd code when the bfd is closed. bfd_check_format also
releases memory when object_p fails, so while it wouldn't be wrong
to bfd_release at bad_format_free in mmo_object_p, it's a little extra
code and work for no gain.
* mmo.c (mmo_object_p): bfd_alloc rather than bfd_malloc
lop_stab_symbol. Don't free/release on error.
(mmo_get_spec_section): bfd_zalloc rather than bfd_zmalloc
section buffer.
(mmo_scan): Free fname on another error path.
Alan Modra [Fri, 10 Feb 2023 07:33:35 +0000 (18:03 +1030)]
Local label checks in integer_constant
"Local labels are never absolute" says the comment. Except when they
are. Testcase
.offset
0:
a=0b
I don't see any particular reason to disallow local labels inside
struct definitions, so delete the comment and assertions.
* expr.c (integer_constant): Delete local label assertions.
Jan Beulich [Fri, 10 Feb 2023 07:15:11 +0000 (08:15 +0100)]
x86: drop use of VEX3SOURCES
The attribute really specifies that the sum of register and memory
operands is 4. Express it like that in most places, while using the 2nd
(apart from XOP) CPU feature flags (FMA4) in reversed operand matching
logic.
With the use in build_modrm_byte() gone, part of an assertion there
also becomes meaningless - simplify that at the same time.
With all uses of the opcode modifier field gone, also drop that.
Jan Beulich [Fri, 10 Feb 2023 07:14:46 +0000 (08:14 +0100)]
x86: drop use of XOP2SOURCES
The few XOP insns which used it wrongly didn't have VexVVVV specified.
With that added, the only further missing piece to use more generic code
elsewhere is SwapSources - see e.g. the BMI2 insns for similar operand
patterns.
With the only users gone, drop the #define as well as the special case
code.
Jan Beulich [Fri, 10 Feb 2023 07:14:27 +0000 (08:14 +0100)]
x86: limit use of XOP2SOURCES
The VPROT* forms with an immediate operand are entirely standard in the
way their ModR/M bytes are built. There's no reason to invoke special
case code. With that the handling of an immediate there can also be
dropped; it was partially bogus anyway, as in its "no memory operands"
portion it ignores the possibility of an immediate operand (which was
okay only because that case was already handled by more generic code).
Jan Beulich [Fri, 10 Feb 2023 07:10:38 +0000 (08:10 +0100)]
x86: move (and rename) opcodespace attribute
This really isn't a "modifier" and rather ought to live next to the base
opcode anyway. Use the bits we presently have available to fit in the
field, renaming it to opcode_space. As an intended side effect this
helps readability at the use sites, by shortening the references quite a
bit.
In generated code arrange for human readable output, by using the
SPACE_* constants there rather than raw numbers. This may aid debugging
down the road.
Jan Beulich [Fri, 10 Feb 2023 07:10:03 +0000 (08:10 +0100)]
x86: simplify a few expressions
Fold adjacent comparisons when, by ORing in a certain mask, the same
effect can be achieved by a single one. In load_insn_p() this extends
to further uses of an already available local variable.
Jan Beulich [Fri, 10 Feb 2023 07:09:35 +0000 (08:09 +0100)]
x86: improve special casing of certain insns
Now that we have identifiers for the mnemonic strings we can avoid
opcode based comparisons, for (in many cases) being more expensive and
(in a few cases) being a little fragile and not self-documenting.
Note that the MOV optimization can be engaged by the earlier LEA one,
and hence LEA also needs checking for there.
Alan Modra [Fri, 10 Feb 2023 00:24:32 +0000 (10:54 +1030)]
objcopy of mach-o indirect symbols
Anti-fuzzer measure. I'm not sure what the correct fix is for
objcopy. Probably the BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS,
BFD_MACH_O_S_LAZY_SYMBOL_POINTERS and BFD_MACH_O_S_SYMBOL_STUBS
contents should be read.
* mach-o.c (bfd_mach_o_section_get_nbr_indirect): Omit sections
with NULL sec->indirect_syms.
GDB Administrator [Fri, 10 Feb 2023 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Thu, 9 Feb 2023 20:33:21 +0000 (13:33 -0700)]
Add full display feature to dwarf-mode.el
I've found that I often use dwarf-mode with relatively small test
files. In this situation, it's handy to be able to expand all the
DWARF, rather than moving to each "..." separately and using C-u C-m.
This patch implements this feature. It also makes a couple of other
minor changes:
* I removed a stale FIXME from dwarf-mode. In practice I find I often
use "g" to restore the buffer to a pristine state; checking the file
mtime would work against this.
* I tightened the regexp in dwarf-insert-substructure. This prevents
the C-m binding from trying to re-read a DIE which has already been
expanded.
* Finally, I've bumped the dwarf-mode version number so that this
version can easily be installed using package.el.
2023-02-09 Tom Tromey <tromey@adacore.com>
* dwarf-mode.el: Bump version to 1.8.
(dwarf-insert-substructure): Tighten regexp.
(dwarf-refresh-all): New defun.
(dwarf-mode-map): Bind "A" to dwarf-refresh-all.
(dwarf-mode): Remove old FIXME.
Tom Tromey [Thu, 9 Feb 2023 19:23:08 +0000 (12:23 -0700)]
Fix comment in gdb.rust/fnfield.exp
gdb.rust/fnfield.exp has a comment that, I assume, I copied from some
other test. This patch fixes it.
Tom Tromey [Thu, 9 Feb 2023 19:13:08 +0000 (12:13 -0700)]
Trivially simplify rust_language::print_enum
rust_language::print_enum computes:
int nfields = variant_type->num_fields ();
... but then does not reuse this in one spot. This patch corrects the
oversight.
Roland McGrath [Thu, 9 Feb 2023 18:47:17 +0000 (10:47 -0800)]
[aarch64] Avoid initializers for VLAs
Clang doesn't accept initializer syntax for variable-length
arrays in C. Just use memset instead.
Christina Schimpe [Fri, 21 Oct 2022 16:02:57 +0000 (09:02 -0700)]
gdb, testsuite: Remove unnecessary call of "set print pretty on"
The command has no effect for the loading of GDB pretty printers and is
removed by this patch to avoid confusion.
Documentation for "set print pretty"
"Cause GDB to print structures in an indented format with one member per line"
Tom Tromey [Wed, 11 Jan 2023 19:42:40 +0000 (12:42 -0700)]
Increase size of main_type::nfields
main_type::nfields is a 'short', and has been for many years. PR
c++/29985 points out that 'short' is too narrow for an enum that
contains more than 2^15 constants.
This patch bumps the size of 'nfields'. To verify that the field
isn't directly used, it is also renamed. Note that this does not
affect the size of main_type on x86-64 Fedora 36. And, if it does
have a negative effect somewhere, it's worth considering that types
could be shrunk more drastically by using subclasses for the different
codes.
This is v2 of this patch, which has these changes:
* I changed nfields to 'unsigned', per Simon's request. I looked at
changing all the uses, but this quickly fans out into a very large
patch. (One additional tweak was needed, though.)
* I wrote a test case. I discovered that GCC cannot compile a large
enough C test case, so I resorted to using the DWARF assembler.
This test doesn't reproduce the crash, but it does fail without the
patch.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29985
Tom Tromey [Thu, 9 Feb 2023 14:36:16 +0000 (07:36 -0700)]
Remove mention of cooked_index_vector
I noticed a leftover mention of cooked_index_vector. This updates the
text.
Tom Tromey [Tue, 6 Dec 2022 15:05:28 +0000 (08:05 -0700)]
Let user C-c when waiting for DWARF index finalization
In PR gdb/29854, Simon pointed out that it would be good to be able to
use C-c when the DWARF cooked index is waiting for finalization. The
idea here is to be able to interrupt a command like "break" -- not to
stop the finalization process itself, which runs in a worker thread.
This patch implements this idea, by changing the index wait functions
to, by default, allow a quit. Polling is done, because there doesn't
seem to be a better way to interrupt a wait on a std::future.
For v2, I realized that the thread compatibility code in thread-pool.h
also needed an update.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29854
Alan Modra [Thu, 9 Feb 2023 01:38:10 +0000 (12:08 +1030)]
coff keep_relocs and keep_contents
keep_relocs is set by pe_ILF_save_relocs but not used anywhere in the
coff/pe code. It is tested by the xcoff backend but not set.
keep_contents is only used by the xcoff backend when dealing with
the .loader section, and it's easy enough to dispense with it there.
keep_contents is set in various places but that's fairly useless when
the contents aren't freed anyway until later linker support functions,
add_dynamic_symbols and check_dynamic_ar_symbols. There the contents
were freed if keep_contents wasn't set. I reckon we can free them
unconditionally.
* coff-bfd.h (struct coff_section_tdata): Delete keep_relocs
and keep_contents.
* peicode.h (pe_ILF_save_relocs): Don't set keep_relocs.
* xcofflink.c (xcoff_get_section_contents): Cache contents.
Return the contents. Update callers.
(_bfd_xcoff_canonicalize_dynamic_symtab): Don't set
keep_contents for .loader.
(xcoff_link_add_dynamic_symbols): Free .loader contents
unconditionally.
(xcoff_link_check_dynamic_ar_symbols): Likewise.
GDB Administrator [Thu, 9 Feb 2023 00:00:27 +0000 (00:00 +0000)]
Automatic date update in version.in
Alan Modra [Wed, 8 Feb 2023 13:21:04 +0000 (23:51 +1030)]
coff-sh.c keep_relocs, keep_contents and keep_syms
keep_relocs and keep_contents are unused nowadays except by
xcofflink.c, and I can't see a reason why keep_syms needs to be set.
The external syms are read and used by sh_relax_section and used by
sh_relax_delete_bytes. There doesn't appear to be any way that
freeing them will cause trouble.
* coff-sh.c (sh_relax_section): Don't set keep_relocs,
keep_contents or keep_syms.
(sh_relax_delete_bytes): Don't set keep_contents.
Alan Modra [Wed, 8 Feb 2023 13:19:46 +0000 (23:49 +1030)]
Memory leak in bfd_init_section_compress_status
* compress.c (bfd_init_section_compress_status): Free
uncompressed_buffer on error return.
Alan Modra [Wed, 8 Feb 2023 04:11:58 +0000 (14:41 +1030)]
Clear cached file size when bfd changed to BFD_IN_MEMORY
If file size is calculated by bfd_get_file_size, as it is by
_bfd_alloc_and_read calls in coff_object_p, then it is cached and when
pe_ILF_build_a_bfd converts an archive entry over to BFD_IN_MEMORY,
the file size is no longer valid. Found when attempting objdump -t on
a very small (27 bytes) ILF file and hitting the pr24707 fix (commit
781152ec18f5). So, clear file size when setting BFD_IN_MEMORY on bfds
that may have been read. (It's not necessary in writable bfds,
because caching is ignored by bfd_get_size when bfd_write_p.)
I also think the PR 24707 fix is no longer neeeded. All of the
testcases in that PR and in PR24712 are caught earlier by file size
checks when reading the symbols from file. So I'm reverting that fix,
which just compared the size of an array of symbol pointers against
file size. That's only valid if on-disk symbols are larger than a
host pointer, so the test is better done in format-specific code.
bfd/
* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Clear cached
file size when making a BFD_IN_MEMORY bfd.
* opncls.c (bfd_make_readable): Likewise.
* peicode.h (pe_ILF_build_a_bfd): Likewise.
binutils/
PR 24707
* objdump.c (slurp_symtab): Revert PR24707 fix. Tidy.
(slurp_dynamic_symtab): Tidy.
Alan Modra [Wed, 8 Feb 2023 02:57:24 +0000 (13:27 +1030)]
Internal error at gas/expr.c:1814
This is the assertion
know (*input_line_pointer != ' ');
after calling operand.
The usual exit from operand calls SKIP_ALL_WHITESPACE.
* expr.c (operand): Call SKIP_ALL_WHITESPACE after call to expr.
Simon Marchi [Mon, 30 Jan 2023 20:02:49 +0000 (15:02 -0500)]
gdb: give sentinel for user frames distinct IDs, register sentinel frames to the frame cache
The test gdb.base/frame-view.exp fails like this on AArch64:
frame^M
#0 baz (z1=hahaha, /home/simark/src/binutils-gdb/gdb/value.c:4056: internal-error: value_fetch_lazy_register: Assertion `next_frame != NULL' failed.^M
A problem internal to GDB has been detected,^M
further debugging may prove unreliable.^M
FAIL: gdb.base/frame-view.exp: with_pretty_printer=true: frame (GDB internal error)
The sequence of events leading to this is the following:
- When we create the user frame (the "select-frame view" command), we
create a sentinel frame just for our user-created frame, in
create_new_frame. This sentinel frame has the same id as the regular
sentinel frame.
- When printing the frame, after doing the "select-frame view" command,
the argument's pretty printer is invoked, which does an inferior
function call (this is the point of the test). This clears the frame
cache, including the "real" sentinel frame, which sets the
sentinel_frame global to nullptr.
- Later in the frame-printing process (when printing the second
argument), the auto-reinflation mechanism re-creates the user frame
by calling create_new_frame again, creating its own special sentinel
frame again. However, note that the "real" sentinel frame, the
sentinel_frame global, is still nullptr. If the selected frame had
been a regular frame, we would have called get_current_frame at some
point during the reinflation, which would have re-created the "real"
sentinel frame. But it's not the case when reinflating a user frame.
- Deep down the stack, something wants to fill in the unwind stop
reason for frame 0, which requires trying to unwind frame 1. This
leads us to trying to unwind the PC of frame 1:
#0 gdbarch_unwind_pc (gdbarch=0xffff8d010080, next_frame=...) at /home/simark/src/binutils-gdb/gdb/gdbarch.c:2955
#1 0x000000000134569c in dwarf2_tailcall_sniffer_first (this_frame=..., tailcall_cachep=0xffff773fcae0, entry_cfa_sp_offsetp=0xfffff7f7d450)
at /home/simark/src/binutils-gdb/gdb/dwarf2/frame-tailcall.c:390
#2 0x0000000001355d84 in dwarf2_frame_cache (this_frame=..., this_cache=0xffff773fc928) at /home/simark/src/binutils-gdb/gdb/dwarf2/frame.c:1089
#3 0x00000000013562b0 in dwarf2_frame_unwind_stop_reason (this_frame=..., this_cache=0xffff773fc928) at /home/simark/src/binutils-gdb/gdb/dwarf2/frame.c:1101
#4 0x0000000001990f64 in get_prev_frame_always_1 (this_frame=...) at /home/simark/src/binutils-gdb/gdb/frame.c:2281
#5 0x0000000001993034 in get_prev_frame_always (this_frame=...) at /home/simark/src/binutils-gdb/gdb/frame.c:2376
#6 0x000000000199b814 in get_frame_unwind_stop_reason (frame=...) at /home/simark/src/binutils-gdb/gdb/frame.c:3051
#7 0x0000000001359cd8 in dwarf2_frame_cfa (this_frame=...) at /home/simark/src/binutils-gdb/gdb/dwarf2/frame.c:1356
#8 0x000000000132122c in dwarf_expr_context::execute_stack_op (this=0xfffff7f80170, op_ptr=0xffff8d8883ee "\217\002", op_end=0xffff8d8883ee "\217\002")
at /home/simark/src/binutils-gdb/gdb/dwarf2/expr.c:2110
#9 0x0000000001317b30 in dwarf_expr_context::eval (this=0xfffff7f80170, addr=0xffff8d8883ed "\234\217\002", len=1) at /home/simark/src/binutils-gdb/gdb/dwarf2/expr.c:1239
#10 0x000000000131d68c in dwarf_expr_context::execute_stack_op (this=0xfffff7f80170, op_ptr=0xffff8d88840e "", op_end=0xffff8d88840e "") at /home/simark/src/binutils-gdb/gdb/dwarf2/expr.c:1811
#11 0x0000000001317b30 in dwarf_expr_context::eval (this=0xfffff7f80170, addr=0xffff8d88840c "\221p", len=2) at /home/simark/src/binutils-gdb/gdb/dwarf2/expr.c:1239
#12 0x0000000001314c3c in dwarf_expr_context::evaluate (this=0xfffff7f80170, addr=0xffff8d88840c "\221p", len=2, as_lval=true, per_cu=0xffff90b03700, frame=..., addr_info=0x0,
type=0xffff8f6c8400, subobj_type=0xffff8f6c8400, subobj_offset=0) at /home/simark/src/binutils-gdb/gdb/dwarf2/expr.c:1078
#13 0x000000000149f9e0 in dwarf2_evaluate_loc_desc_full (type=0xffff8f6c8400, frame=..., data=0xffff8d88840c "\221p", size=2, per_cu=0xffff90b03700, per_objfile=0xffff9070b980,
subobj_type=0xffff8f6c8400, subobj_byte_offset=0, as_lval=true) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:1513
#14 0x00000000014a0100 in dwarf2_evaluate_loc_desc (type=0xffff8f6c8400, frame=..., data=0xffff8d88840c "\221p", size=2, per_cu=0xffff90b03700, per_objfile=0xffff9070b980, as_lval=true)
at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:1557
#15 0x00000000014aa584 in locexpr_read_variable (symbol=0xffff8f6cd770, frame=...) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:3052
- AArch64 defines a special "prev register" function,
aarch64_dwarf2_prev_register, to handle unwinding the PC. This
function does
frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
- frame_unwind_register_unsigned ultimately creates a lazy register
value, saving the frame id of this_frame->next. this_frame is the
user-created frame, to this_frame->next is the special sentinel frame
we created for it. So the saved ID is the sentinel frame ID.
- When time comes to un-lazify the value, value_fetch_lazy_register
calls frame_find_by_id, to find the frame with the ID we saved.
- frame_find_by_id sees it's the sentinel frame ID, so returns the
sentinel_frame global, which is, if you remember, nullptr.
- We hit the `gdb_assert (next_frame != NULL)` assertion in
value_fetch_lazy_register.
The issues I see here are:
- The ID of the sentinel frame created for the user-created frame is
not distinguishable from the ID of the regular sentinel frame. So
there's no way frame_find_by_id could find the right frame, in
value_fetch_lazy_register.
- Even if they had distinguishable IDs, sentinel frames created for
user frames are not registered anywhere, so there's no easy way
frame_find_by_id could find it.
This patch addresses these two issues:
- Give sentinel frames created for user frames their own distinct IDs
- Register sentinel frames in the frame cache, so they can be found
with frame_find_by_id.
I initially had this split in two patches, but I then found that it was
easier to explain as a single patch.
Rergarding the first part of the change: with this patch, the sentinel
frames created for user frames (in create_new_frame) still have
stack_status == FID_STACK_SENTINEL, but their code_addr and stack_addr
fields are now filled with the addresses used to create the user frame.
This ensures this sentinel frame ID is different from the "target"
sentinel frame ID, as well as any other "user" sentinel frame ID. If
the user tries to create the same frame, with the same addresses,
multiple times, create_sentinel_frame just reuses the existing frame.
So we won't end up with multiple user sentinels with the same ID.
Regular "target" sentinel frames remain with code_addr and stack_addr
unset.
The concrete changes for that part are:
- Remove the sentinel_frame_id constant, since there isn't one
"sentinel frame ID" now. Add the frame_id_build_sentinel function
for building sentinel frame IDs and a is_sentinel_frame_id function
to check if a frame id represents a sentinel frame.
- Replace the sentinel_frame_id check in frame_find_by_id with a
comparison to `frame_id_build_sentinel (0, 0)`. The sentinel_frame
global is meant to contain a reference to the "target" sentinel, so
the one with addresses (0, 0).
- Add stack and code address parameters to create_sentinel_frame, to be
able to create the various types of sentinel frames.
- Adjust get_current_frame to create the regular "target" sentinel.
- Adjust create_new_frame to create a sentinel with the ID specific to
the created user frame.
- Adjust sentinel_frame_prev_register to get the sentinel frame ID from
the frame_info object, since there isn't a single "sentinel frame ID"
now.
- Change get_next_frame_sentinel_okay to check for a
sentinel-frame-id-like frame ID, rather than for sentinel_frame
specifically, since this function could be called with another
sentinel frame (and we would want the assert to catch it).
The rest of the change is about registering the sentinel frame in the
frame cache:
- Change frame_stash_add's assertion to allow sentinel frame levels
(-1).
- Make create_sentinel_frame add the frame to the frame cache.
- Change the "sentinel_frame != NULL" check in reinit_frame_cache for a
check that the frame stash is not empty. The idea is that if we only
have some user-created frames in the cache when reinit_frame_cache is
called, we probably want to emit the frames invalid annotation. The
goal of that check is to avoid unnecessary repeated annotations, I
suppose, so the "frame cache not empty" check should achieve that.
After this change, I think we could theoritically get rid of the
sentienl_frame global. That sentinel frame could always be found by
looking up `frame_id_build_sentinel (0, 0)` in the frame cache.
However, I left the global there to avoid slowing the typical case down
for nothing. I however, noted in its comment that it is an
optimization.
With this fix applied, the gdb.base/frame-view.exp now passes for me on
AArch64. value_of_register_lazy now saves the special sentinel frame ID
in the value, and value_fetch_lazy_register is able to find that
sentinel frame after the frame cache reinit and after the user-created
frame was reinflated.
Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Tested-By: Luis Machado <luis.machado@arm.com>
Change-Id: I8b77b3448822c8aab3e1c3dda76ec434eb62704f
Simon Marchi [Mon, 30 Jan 2023 20:02:48 +0000 (15:02 -0500)]
gdb: call frame unwinders' dealloc_cache methods through destroying the frame cache
Currently, some frame resources are deallocated by iterating on the
frame chain (starting from the sentinel), calling dealloc_cache. The
problem is that user-created frames are not part of that chain, so we
never call dealloc_cache for them.
I propose to make it so the dealloc_cache callbacks are called when the
frames are removed from the frame_stash hash table, by registering a
deletion function to the hash table. This happens when
frame_stash_invalidate is called by reinit_frame_cache. This way, all
frames registered in the cache will get their unwinder's dealloc_cache
callbacks called.
Note that at the moment, the sentinel frames are not registered in the
cache, so we won't call dealloc_cache for them. However, it's just a
theoritical problem, because the sentinel frame unwinder does not
provide this callback. Also, a subsequent patch will change things so
that sentinel frames are registered to the cache.
I moved the obstack_free / obstack_init pair below the
frame_stash_invalidate call in reinit_frame_cache, because I assumed
that some dealloc_cache would need to access some data on that obstack,
so it would be better to free it after clearing the hash table.
Change-Id: If4f9b38266b458c4e2f7eb43e933090177c22190
Tom Tromey [Sat, 21 Jan 2023 21:00:12 +0000 (14:00 -0700)]
Remove block.h includes from some tdep files
A few tdep files include block.h but do not need to. This patch
removes the inclusions. I checked that this worked correctly by
examining the resulting .Po file to make sure that block.h was not
being included by some other route.
Tom Tromey [Sat, 21 Jan 2023 21:00:05 +0000 (14:00 -0700)]
Don't include block.h from expop.h
expop.h needs block.h for a single inline function. However, I don't
think most of the check_objfile functions need to be defined in the
header (just the templates). This patch moves the one offending
function and removes the include.
Pedro Alves [Fri, 27 Jan 2023 18:07:56 +0000 (18:07 +0000)]
Simplify interp::exec / interp_exec - let exceptions propagate
This patch implements a simplication that I suggested here:
https://sourceware.org/pipermail/gdb-patches/2022-March/186320.html
Currently, the interp::exec virtual method interface is such that
subclass implementations must catch exceptions and then return them
via normal function return.
However, higher up the in chain, for the CLI we get to
interpreter_exec_cmd, which does:
for (i = 1; i < nrules; i++)
{
struct gdb_exception e = interp_exec (interp_to_use, prules[i]);
if (e.reason < 0)
{
interp_set (old_interp, 0);
error (_("error in command: \"%s\"."), prules[i]);
}
}
and for MI we get to mi_cmd_interpreter_exec, which has:
void
mi_cmd_interpreter_exec (const char *command, char **argv, int argc)
{
...
for (i = 1; i < argc; i++)
{
struct gdb_exception e = interp_exec (interp_to_use, argv[i]);
if (e.reason < 0)
error ("%s", e.what ());
}
}
Note that if those errors are reached, we lose the original
exception's error code. I can't see why we'd want that.
And, I can't see why we need to have interp_exec catch the exception
and return it via the normal return path. That's normally needed when
we need to handle propagating exceptions across C code, like across
readline or ncurses, but that's not the case here.
It seems to me that we can simplify things by removing some
try/catch-ing and just letting exceptions propagate normally.
Note, the "error in command" error shown above, which only exists in
the CLI interpreter-exec command, is only ever printed AFAICS if you
run "interpreter-exec console" when the top level interpreter is
already the console/tui. Like:
(gdb) interpreter-exec console "foobar"
Undefined command: "foobar". Try "help".
error in command: "foobar".
You won't see it with MI's "-interpreter-exec console" from a top
level MI interpreter:
(gdb)
-interpreter-exec console "foobar"
&"Undefined command: \"foobar\". Try \"help\".\n"
^error,msg="Undefined command: \"foobar\". Try \"help\"."
(gdb)
nor with MI's "-interpreter-exec mi" from a top level MI interpreter:
(gdb)
-interpreter-exec mi "-foobar"
^error,msg="Undefined MI command: foobar",code="undefined-command"
^done
(gdb)
in both these cases because MI's -interpreter-exec just does:
error ("%s", e.what ());
You won't see it either when running an MI command with the CLI's
"interpreter-exec mi":
(gdb) interpreter-exec mi "-foobar"
^error,msg="Undefined MI command: foobar",code="undefined-command"
(gdb)
This last case is because MI's interp::exec implementation never
returns an error:
gdb_exception
mi_interp::exec (const char *command)
{
mi_execute_command_wrapper (command);
return gdb_exception ();
}
Thus I think that "error in command" error is pretty pointless, and
since it simplifies things to not have it, the patch just removes it.
The patch also ends up addressing an old FIXME.
Change-Id: I5a6432a80496934ac7127594c53bf5221622e393
Approved-By: Tom Tromey <tromey@adacore.com>
Approved-By: Kevin Buettner <kevinb@redhat.com>
Tom Tromey [Thu, 19 Jan 2023 21:01:27 +0000 (14:01 -0700)]
Avoid FAILs in gdb.compile
Many gdb.compile C++ tests fail for me on Fedora 36. I think these
are largely bugs in the plugin, though I didn't investigate too
deeply. Once one failure is seen, this often cascades and sometimes
there are many timeouts.
For example, this can happen:
(gdb) compile code var = a->get_var ()
warning: Could not find symbol "_ZZ9_gdb_exprP10__gdb_regsE1a" for compiled module "/tmp/gdbobj-0xdI6U/out2.o".
1 symbols were missing, cannot continue.
I think this is probably a plugin bug because, IIRC, in theory these
symbols should be exempt from a lookup via gdb.
This patch arranges to catch any catastrophic failure and then simply
exit the entire .exp file.
Tom Tromey [Thu, 19 Jan 2023 18:19:32 +0000 (11:19 -0700)]
Don't let .gdb_history file cause failures
I had a .gdb_history file in my testsuite directory in the build tree,
and this provoked a failure in gdbhistsize-history.exp. It seems
simple to prevent this file from causing a failure.
Tom Tromey [Fri, 13 Jan 2023 16:59:29 +0000 (09:59 -0700)]
Merge fixup_section and fixup_symbol_section
fixup_symbol_section delegates all its work to fixup_section, so merge
the two.
Because there is only a single caller to fixup_symbol_section, we can
also remove some of the introductory logic. For example, this will
never be called with a NULL objfile any more.
The LOC_BLOCK case can be removed, because such symbols are handled by
the buildsym code now.
Finally, a symbol can only appear in a SEC_ALLOC section, so the loop
is modified to skip sections that do not have this flag set.
Tom Tromey [Fri, 13 Jan 2023 16:27:54 +0000 (09:27 -0700)]
Remove most calls to fixup_symbol_section
Nearly every call to fixup_symbol_section in gdb is incorrect, and if
any such call has an effect, it's purely by happenstance.
fixup_section has a long comment explaining that the call should only
be made before runtime section offsets are applied. And, the loop in
this code (the fallback loop -- the minsym lookup code is "ok") is
careful to remove these offsets before comparing addresses.
However, aside from a single call in dwarf2/read.c, every call in gdb
is actually done after section offsets have been applied. So, these
calls are incorrect.
Now, these calls could be made when the symbol is created. I
considered this approach, but I reasoned that the code has been this
way for many years, seemingly without ill effect. So, instead I chose
to simply remove the offending calls.
Tom Tromey [Fri, 13 Jan 2023 16:17:27 +0000 (09:17 -0700)]
Set section index when setting a symbol's block
When a symbol's block is set, the block has the runtime section offset
applied. So, it seems to me that the symbol implicitly is in the same
section as the block. Therefore, this patch sets the symbol's section
index at this same spot.
Tom Tromey [Thu, 19 Jan 2023 13:14:49 +0000 (06:14 -0700)]
Remove compunit_symtab::m_block_line_section
The previous patch hard-coded SECT_OFF_TEXT into the buildsym code.
After this, it's clear that there is only one caller of
compunit_symtab::set_block_line_section, and it always passes
SECT_OFF_TEXT. So, remove compunit_symtab::m_block_line_section and
use SECT_OFF_TEXT instead.
Tom Tromey [Fri, 13 Jan 2023 16:08:41 +0000 (09:08 -0700)]
Do not pass section index to end_compunit_symtab
Right now, the section index passed to end_compunit_symtab is always
SECT_OFF_TEXT. Remove this parameter and simply always use
SECT_OFF_TEXT.