Commit Graph

48763 Commits

Author SHA1 Message Date
Tom Tromey
fa265c9bef Remove a const-removing cast from coff-pe-read.c
coff-pe-read.c casts away const at one spot, but this is easily
replaced by calling bfd_get_filename directly in a couple of debugging
prints.
2022-04-22 06:55:51 -06:00
Tom Tromey
5a0d4dfbf8 Simplify BFD section iteration in coff-pe-read.c
coff-pe-read.c iterates over BFD sections using bfd_map_over_sections,
but it's much simpler to use a for-each loop.  This allows for the
removal of helper functions and types.
2022-04-22 06:54:02 -06:00
Tom Tromey
6acc36f71d Fix method naming bug in new DWARF indexer
Pedro pointed out that gdb-add-index is much slower with the new DWARF
indexer.  He also noticed that, in some cases, the generated
.gdb_index would have the wrong fully-qualified name for a method.

I tracked this down to a bug in the indexer.  If a type could have
methods but was marked as a declaration, the indexer was ignoring it.
However, this meant that the internal map to find the qualified name
was not updated for this container.
2022-04-22 06:40:49 -06:00
Carl Love
83ac2319e7 Fix for gdb.base/solib-search.exp test.
The variable right_lib_flags is not being set correctly to define RIGHT.
The value RIGHT is needed to force the address of the library functions
lib1_func3 and lib2_func4 to occur at different address in the wrong and
right libraries.

With RIGHT defined correctly, functions lib1_func3 and lib2_func4 occur
at different addresses the test runs correctly on Powerpc.

The test needs the lib2 addresses to be different in the right and
wrong cases.  That is the point of introducing function lib2_spacer
with the ifdef RIGHT compiler directive.

On Intel, the ARRAY_SIZE of 1 versus 8192 is sufficient to get the
dynamic linker to move the addresses of the library.  You can also get
the same effect on PowerPC but you must use a value much larger than
8192.

The key thing is that the test was not properly setting RIGHT to
defined to get the lib2_spacer function on Intel and Powerpc.

Without the patch, we have the Intel backtrace for the bad libraries:

backtrace
#0  break_here () at /home/ ... /gdb/testsuite/gdb.base/solib-search.c:30
#1  0x00007ffff7fae156 in ?? ()
#2  0x00007fffffffc150 in ?? ()
#3  0x00007ffff7fbb156 in ?? ()
#4  0x00007fffffffc160 in ?? ()
#5  0x00007ffff7fae146 in ?? ()
#6  0x00007fffffffc170 in ?? ()
#7  0x00007ffff7fbb146 in ?? ()
#8  0x00007fffffffc180 in ?? ()
#9  0x0000555555555156 in main () at /home/ ... /binutils-gdb/gdb/testsuite/gdb.base/solib-search.c:23
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) PASS: gdb.base/solib-search.exp: backtrace (with wrong libs) (data collection)

The backtrace on Intel with the good libraries is:

backtrace
#0  break_here () at /.../binutils-gdb/gdb/testsuite/gdb.base/solib-search.c:30
#1  0x00007ffff7fae156 in lib2_func4 () at /.../binutils-gdb/gdb/testsuite/gdb.base/solib-search-lib2.c:49
#2  0x00007ffff7fbb156 in lib1_func3 () at /.../gdb.base/solib-search-lib1.c:49
#3  0x00007ffff7fae146 in lib2_func2 () at /.../testsuite/gdb.base/solib-search-lib2.c:30
#4  0x00007ffff7fbb146 in lib1_func1 () at /.../gdb.base/solib-search-lib1.c:30
#5  0x0000555555555156 in main () at /...solib-search.c:23
(gdb) PASS: gdb.base/solib-search.exp: backtrace (with right libs) (data collection)
PASS: gdb.base/solib-search.exp: backtrace (with right libs)

In one case the backtrace is correct and the other it
is wrong on Intel.  This is due to the fact that the ARRAY_SIZE caused
the dynamic linker to move the library function addresses around.  I
believe it has to do with the default size of the data and code
sections used by the dynamic linker.

So without the patch the backtrace on PowerPC looks like:

 backtrace
#0  break_here () at /.../solib-search.c:30
#1  0x00007ffff7f007f4 in lib2_func4 () at /.../solib-search-lib2.c:49
#2  0x00007ffff7f307f4 in lib1_func3 () at /.../solib-search-lib1.c:49
#3  0x00007ffff7f007ac in lib2_func2 () at /.../solib-search-lib2.c:30
#4  0x00007ffff7f307ac in lib1_func1 () at /.../solib-search-lib1.c:30
#5  0x000000001000074c in main () at /.../solib-search.c:23

for both the good and bad libraries.

The patch fixes defining RIGHT in solib-search-lib1.c and solib-search-
lib2.c.  Note, without the patch the lib1_spacer and lib2_spacer
functions do not show up in the object dump of the Intel or Powerpc
libraries as it should.  The patch fixes that by making sure RIGHT gets
defined.

Now with the patch the backtrace for the bad library on PowerPC looks
like:

backtrace
#0  break_here () at /.../solib-search.c:30
#1  0x00007ffff7f0083c in __glink_PLTresolve () from /.../solib-search-lib2.so
Backtrace stopped: frame did not save the PC

And the backtrace for the good libraries on PowerPC looks like:

backtrace
#0  break_here () at /.../solib-search.c:30
#1  0x00007ffff7f0083c in lib2_func4 () at /.../solib-search-lib2.c:49
#2  0x00007ffff7f3083c in lib1_func3 () at /.../solib-search-lib1.c:49
#3  0x00007ffff7f007cc in lib2_func2 () at /.../solib-search-lib2.c:30
#4  0x00007ffff7f307cc in lib1_func1 () at /.../solib-search-lib1.c:30
#5  0x000000001000074c in main () at /.../solib-search.c:23
(gdb) PASS: gdb.base/solib-search.exp: backtrace (with right libs) (data collection)
PASS: gdb.base/solib-search.exp: backtrace (with right libs)

The issue then is on Power where the ARRAY_SIZE of 1 versus 8192 is not
sufficient to cause the dymanic linker to allocate the libraries at
different addresses.  I don't claim to understand the specifics of how
the dynamic linker works and what the default size is for the data and
code sections are.  My guess is by default PowerPC allocates a larger
data size by default, which is large enough to hold array[8192].  The
default size of the data section allocated by the dynamic linker on
Intel is not large enough to hold array[8192] thus causing the code
section on Intel to have to move when the large array is defined.

Note on PowerPC, if you make ARRAY_SIZE big enough, then you will cause
the library addresses to occur at different addresses as the larger
data section forces the code section to a different address.  That was
actually my original fix for the program until I spoke with Doug Evans
who originally wrote the test.  Doug noticed that RIGHT was not getting
defined as he originally intended in the test.

With the patch to fix the definition of RIGHT, PowerPC has a bad and a
good backtrace because the address of lib1_func3 and lib2_func4 both
move because lib1_spacer and lib2_spacer are now defined
before lib1_func3 and lib2_func4.

Without the patch, the lib1_spacer and lib2_spacer function doesn't show
up in the binary for the correct or incorrect library on Intel or PowerPC.
With the patch, RIGHT gets defined as originally intended for the test on
both architectures and lib1_spacer and lib2_spacer function show up in the
binaries on both architectures changing the other function addresses as
intended thus causing the test work as intended on PowerPC.
2022-04-21 20:08:39 +00:00
Simon Marchi
b0b299477c gdb/dwarf: remove line_header::header_length field
This can be a local in dwarf_decode_line_header.

Change-Id: I2ecf4616d1a3197bd1e81ded9f999a2da9a685af
2022-04-21 15:05:53 -04:00
Simon Marchi
ebf58f8eb1 gdb/dwarf: remove line_header::total_length field
This doesn' have to be a field, it can simply be a local variable in
dwarf_decode_line_header.  Name the local variable "unit_length", since
that's what the field in called in DWARF 4 and 5.  It's always easier to
follow the code with the standard on the side when we use the same
terminology.

Change-Id: I3ad1022afd9410b193ea11b9b5437686c1e4e633
2022-04-21 15:05:51 -04:00
Simon Marchi
0b84fbd54e gdb/testsuite: fix "set temporary breakpoint" DUPLICATEs
Commit c67f4e538 ("gdb/testsuite: make gdb.ada/mi_prot.exp stop at
expected location") introduced some DUPLICATEs in MI tests using
mi_continue_to_line, for example:

    DUPLICATE: gdb.ada/mi_ref_changeable.exp: mi_continue_to_line: set temporary breakpoint

These test names were previously differentiated by the location passed
to mi_continue_to_line.  Since the location can contain a path, that
commit removed the location from the test name, in favor of a hardcoded
string "set temporary breakpoint", hence removing the differentiator.

mi_continue_to_line receives a "test" parameter, containing a test
name.  Add a "with_test_prefix" with that name, so that all tests
recorded during mi_continue_to_line have this in their name.

mi_continue_to_line passes that "test" string to mi_get_stop_line, that
is a bit superfluous.  mi_get_stop_line only uses that string in case of
failures (it doesn't record a pass if everything goes fine).  Since it's
not crucial, just remove it, and adjust all callers.

Adjust three gdb.mi/mi-var-*.exp tests to use prefixes to differentiate
the multiple calls to mi_run_inline_test (which calls
mi_continue_to_line).

Change-Id: I511c6caa70499f8657b1cde37d71068d74d56a74
2022-04-21 15:05:32 -04:00
Tom Tromey
31de881f8f Always use dwarf2_initialize_objfile
Internally we noticed that some tests would fail like so on Windows:

warning: Section .debug_aranges in [...] has duplicate debug_info_offset 0x0, ignoring .debug_aranges.

Debugging showed that, in fact, a second CU was being created at this
offset.  We tracked this down to the fact that, while the ELF reader
is careful to re-use the per-BFD data, other readers are not, and
could re-read the DWARF data multiple times.

However, since the change to allow an objfile to have multiple "quick
symbol" implementations, there's no reason for this approach -- it's
safe and easy for all symbol readers to reuse the per-BFD data when
reading DWARF.

This patch implements this idea, simplifying dwarf2_build_psymtabs and
making it private, and then switching to dwarf2_initialize_objfile as
the sole way to start the DWARF reader.

Note that, while I think the call to dwarf2_build_frame_info in
machoread.c is also obsolete, I haven't attempted to remove it here.
2022-04-21 12:18:25 -06:00
Andrew Burgess
5f21c7aae2 gdb: fix 'remote show FOO-packet' aliases
The following behaviour was observed in GDB:

  (gdb) show remote X-packet
  Support for the `p' packet is auto-detected, currently unknown.

Note the message mentions the 'p' packet.  This is a regression since
this commit:

  commit 8579fd136a
  Date:   Mon Nov 8 14:58:46 2021 +0000

      gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptr

Before this commit the behaviour was:

  (gdb) show remote X-packet
  Support for the `X' packet is auto-detected, currently unknown.

The problem was caused by a failed attempt to ensure that some
allocated strings were deleted when GDB exits.  The code in the above
commit attempted to make use of 'static' to solve this problem,
however, the solution was just wrong.

In this new commit I instead allocate a static vector into which all
the allocated strings are stored, this ensures the strings are
released when GDB exits (which makes output from tools like valgrind
cleaner), but each string within the vector can be unique, which fixes
the regression.
2022-04-21 17:25:46 +01:00
Simon Marchi
ffaebc199e gdbsupport: add path_join function
In this review [1], Eli pointed out that we should be careful when
concatenating file names to avoid duplicated slashes.  On Windows, a
double slash at the beginning of a file path has a special meaning.  So
naively concatenating "/"  and "foo/bar" would give "//foo/bar", which
would not give the desired results.  We already have a few spots doing:

  if (first_path ends with a slash)
    path = first_path + second_path
  else
    path = first_path + slash + second_path

In general, I think it's nice to avoid superfluous slashes in file
paths, since they might end up visible to the user and look a bit
unprofessional.

Introduce the path_join function that can be used to join multiple path
components together (along with unit tests).

I initially wanted to make it possible to join two absolute paths, to
support the use case of prepending a sysroot path to a target file path,
or the prepending the debug-file-directory to a target file path.  But
the code in solib_find_1 shows that it is more complex than this anyway
(for example, when the right hand side is a Windows path with a drive
letter).  So I don't think we need to support that case in path_join.
That also keeps the implementation simpler.

Change a few spots to use path_join to show how it can be used.  I
believe that all the spots I changed are guarded by some checks that
ensure the right hand side operand is not an absolute path.

Regression-tested on Ubuntu 18.04.  Built-tested on Windows, and I also
ran the new unit-test there.

[1] https://sourceware.org/pipermail/gdb-patches/2022-April/187559.html

Change-Id: I0df889f7e3f644e045f42ff429277b732eb6c752
2022-04-21 11:11:21 -04:00
Lancelot SIX
78088b8960 gdb_spawn_attach_cmdline: use unsupported instead of untested
In a previous commit (b750766ac9: gdb/testsuite: Introduce and use
gdb_spawn_attach_cmdline), if gdb_spawn_attach_cmdline cannot have GDB
attach to the process because of ptrace restrictions (operation not
permitted), the proc issues UNTESTED.  This should really be
UNSUPPORTED, as it is done in gdb_attach.

This patch fixes this oversight.

Change-Id: Ib87e33b9230f3fa7a85e06220ef4c63814b71f7d
2022-04-21 14:41:19 +01:00
Enze Li
9d748d023d gdb/testsuite: add binary testcases to py-format-string.exp
We currently only test decimal and hexadecimal for the
gdb.Value.format_string() interface, this patch adds testcases for
binary format.

Tested on x86_64 openSUSE Tumbleweed(VERSION_ID="20220413").
2022-04-21 20:49:27 +08:00
Pedro Alves
9cf71b1354 gdb.debuginfod/fetch_src_and_symbols.exp: Fix "notice empty URL" test
The gdb_test_multiple pattern for the "notice empty URL" test in
gdb.debuginfod/fetch_src_and_symbols.exp misses expecting the prompt.
Fix it by using -re -wrap.

Also, by using "confirm off", the message GDB prints if Debuginfod
downloading is available doesn't contain "Enable debuginfod" any
longer.  E.g.:

~~~
  (gdb) file testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols
  Reading symbols from testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols...

  This GDB supports auto-downloading debuginfo from the following URLs:
    <http://localhost:123>
  Enable debuginfod for this session? (y or [n])
~~~

~~~
  (gdb) with confirm off -- file testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols
  Reading symbols from testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols...

  This GDB supports auto-downloading debuginfo from the following URLs:
    <http://127.0.0.1:8000>
    <127.0.0.1:8000>
  Debuginfod has been disabled.
  To make this setting permanent, add 'set debuginfod enabled off' to .gdbinit.
  (No debugging symbols found in testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols)
  (gdb)
~~~

I handled that correctly in the other tests that use test_urls, but
had forgotten to update the "notice empty URL" one.

Change-Id: I00040c83466e1494b3875574eb009c571a1504bf
2022-04-21 13:47:17 +01:00
Aaron Merey
52449404c4 gdb/debuginfod: Prevent out_of_range exception
Trailing whitespace in the string of debuginfod URLs causes an
out_of_range exception during the printing of URLs for the first
use notice.

To fix this, stop printing URLs when the substring to be printed
consists only of whitespace.

Also add first use notice testcases.

Co-Authored-By: Pedro Alves <pedro@palves.net>
2022-04-20 17:40:05 -04:00
Lancelot SIX
b750766ac9 gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline
Following a7e6a19e87 "gdb: testsuite: add
new gdb_attach to check "attach" command", this commit proposes to
introduce the gdb_spawn_attach_cmdline helper and use it in
gdb.base/attach.exp.

This helper starts GDB and adds the "--pid=$PID" argument.

Also note that both the original and new implementation use
gdb_spawn_with_cmdline_opts, which in the end uses default_gdb_spawn.
This makes sure that we use $INTERNAL_GDBFLAGS, which by default already
contain "-iex \"set height 0\" -iex \"set width 0\"".  To avoid
repetition of those arguments, gdb_spawn_attach_cmdline does not repeat
those arguments.

To maintain a behavior similat to what gdb.base/attach.exp used to do,
gdb_spawn_attach_cmdline keeps the -quiet flag.

Tested on x86_64-gnu-linux

Change-Id: I1fdcdb71c86d9c5d34bb28fc86fac68bcec37358
2022-04-20 20:50:12 +01:00
Tom Tromey
4206d69e96 Replace symbol_symtab with symbol::symtab
This turns symbol_symtab into a method on symbol.  It also replaces
symbol_set_symtab with a method.
2022-04-20 09:28:40 -06:00
Tom Tromey
bcd6845e2b Replace symbol_arch with symbol::arch
This turns symbol_arch into a method on symbol.
2022-04-20 09:28:17 -06:00
Tom Tromey
e19b2d9465 Replace symbol_objfile with symbol::objfile
This turns symbol_objfile into a method on symbol.
2022-04-20 09:28:16 -06:00
Tom Tromey
f66b536343 Remove symbol::aclass_index
Symbols have an aclass_index method, but this isn't needed, because
the aclass index isn't useful outside of the symbol implementation.
2022-04-20 09:28:16 -06:00
Tom Tromey
6bc3c5b438 Use array_view for symbol_impls
It seemed to me that using array_view for symbol_impls would give a
bit more error checking, at least when gdb is built in libstdc++ debug
mode.
2022-04-20 09:28:16 -06:00
Tom Tromey
496feb16f8 Add accessors for symbol's artificial field
For a series I'm experimenting with, it was handy to hide a symbol's
"artificial" field behind accessors.  This patch is the result.
2022-04-20 09:28:12 -06:00
Tom Tromey
a827b8ec32 Unify the DWARF index holders
The dwarf2_per_bfd object has a separate field for each possible kind
of index.  Until an earlier patch in this series, two of these were
even derived from a common base class, but still had separate slots.
This patch unifies all the index fields using the common base class
that was introduced earlier in this series.  This makes it more
obvious that only a single index can be active at a time, and also
removes some code from dwarf2_initialize_objfile.
2022-04-20 09:10:03 -06:00
Tom Tromey
f75a1d3a73 Add an ad hoc version check to dwarf_scanner_base
Some generic code in the DWARF reader has a special case for older
versions of .gdb_index.  This patch adds an ad hoc version check
method so that these spots can work without specific knowledge of
which index is in use.
2022-04-20 09:10:03 -06:00
Tom Tromey
c1a56932c4 Simplify version check in dw2_symtab_iter_next
This simplifies the index versio check in dw2_symtab_iter_next, by
passing a reference to the index object to this function.  This avoids
an indirection via the per_bfd object.
2022-04-20 09:10:03 -06:00
Tom Tromey
6606799fc4 Introduce and use dwarf_scanner_base
This introduces dwarf_scanner_base, a base class for all the index
readers in the DWARF code.  Then, it changes both mapped_index_base
and cooked_index_vector to derive from this new base class.
2022-04-20 09:10:03 -06:00
Tom Tromey
045a7baed2 Introduce readnow_functions
This introduces readnow_functions, a new subclass of
dwarf2_base_index_functions, and changes the DWARF reader to use it.
This lets us drop the "index is NULL" hack from the gdb index code.
2022-04-20 09:10:03 -06:00
Tom Tromey
dfaa040b44 Remove some "OBJF_READNOW" code from dwarf2_debug_names_index
The dwarf2_debug_names_index code treats a NULL debug_names_table as
if it were from OBJF_READNOW.  However, this trick is only done for
gdb_index, never for debug_names -- see dwarf2_initialize_objfile.
2022-04-20 09:10:03 -06:00
Tom Tromey
32ae6b930c Let mapped index classes create the quick_symbol_functions object
This changes the mapped index classes to create the
quick_symbol_functions objects.  This is a step toward having a more
abstract interface to mapped indices.
2022-04-20 09:10:03 -06:00
Tom Tromey
6555809e3e Give mapped_index_base a virtual destructor
This changes mapped_index_base to have a virtual destructor, so it can
be destroyed via its base class.
2022-04-20 09:10:03 -06:00
Tom Tromey
20386fa32d Move mapped_index_base to new header file
This moves mapped_index_base and the helper struct name_component to a
new header file in gdb/dwarf2/.
2022-04-20 09:10:03 -06:00
Tom Tromey
3b70bcb00f Use symbol_symtab accessor in compile-object-load.c
I noticed that compile-object-load.c directly references owner.symtab
of a symbol.  However, I think it's better for all users to call
symbol_symtab.  This patch makes this change.
2022-04-20 06:50:59 -06:00
Tom Tromey
72b580b8f4 Micro-optimize cooked_index_entry::full_name
I noticed that cooked_index_entry::full_name can return the canonical
string when there is no parent entry.

Regression tested on x86-64 Fedora 34.
2022-04-20 06:21:06 -06:00
Tiezhu Yang
6e0d24c448 gdb: LoongArch: Implement loongarch_scan_prologue()
If can't determine prologue from the symbol table, need to examine
instructions. Implement loongarch_scan_prologue() to analyze the
function prologue from START_PC to LIMIT_PC, return the address of
the first instruction past the prologue.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-04-20 19:13:40 +08:00
Lancelot SIX
531c82a1c7 gdb/selftest-arch: Make register_test_foreach_arch generate arch tests lazily
The register_test_foreach_arch is used to instantiate a given selftest
for all architectures supported by GDB.  It is used in many _initialize_*
functions (under initialize_all_files, called by gdb_init).

Because the call is done during GDB's initialization, and because there
is no guaranty about the order in which all the _initialize_* functions
are executed, when register_test_foreach_arch is called, GDB is not
fully initialized.  Specifically, when a particular initialize function
is executed, only the architectures registered at that point are listed
by gdbarch_printable_names.

As a consequence, the list of selftest effectively executed depends on
the order the _initialize_* functions are called.  This can be observed
with the following:

    $ ./gdb/gdb \
        -data-directory ./gdb/data-directory \
        -quiet -batch -ex "maint selftest" 2>&1 \
        | grep -E "Ran [0-9]+ unit tests"
    Ran 145 unit tests, 0 failed
    $ GDB_REVERSE_INIT_FUNCTIONS=1 ./gdb/gdb \
        -data-directory ./gdb/data-directory \
        -quiet -batch -ex "maint selftest" 2>&1 \
        | grep -E "Ran [0-9]+ unit tests"
    Ran 82 unit tests, 0 failed

To fix this, make register_test_foreach_arch register a lazy selftest
generator.  This way when the test generator is eventually executed, all
architectures are registered and we do not have a dependency on the
order the initialize functions are executed in.

Tested on x86_64-linux

Change-Id: I88eefebf7d372ad672f42d3a103e89354bc8a925
2022-04-19 09:12:42 +01:00
Lancelot SIX
c57207c15c gdbsupport/selftest: Replace for_each_selftest with an iterator_range
Remove the callback-based selftests::for_each_selftest function and use
an iterator_range instead.

Also use this iterator range in run_tests so all iterations over the
selftests are done in a consistent way.  This will become useful in a
later commit.

Change-Id: I0b3a5349a7987fbcb0071f11c394e353df986583
2022-04-19 09:12:42 +01:00
Simon Marchi
9a0de6abdd gdb/testsuite/dwarf: don't automatically add directory and file entry for DWARF 5
To support DWARF 5 in the DWARF assembler line tables, we currently copy
the first user-provided directory and the first user-provided files and
make them elements at indices 0 in the directory and file name tables.
That was a sufficient behavior at the time (see commit 44fda08939
("[gdb/testsuite] Support .debug_line v5 in dwarf assembler")), but in
the following patches, I would need to have finer grained control on
what is generated exactly.  For example, I'd like to generate a DWARF 5 line
table with just a single file and a single directory.

Get rid of this behavior, and implement what is suggested in
44fda08939: make include_dir return the directory index that can be
used to refer to that directory entry (based on the DWARF version), and
use it afterwards.

Adjust dw2-lines.exp and dw2-prologue-end.exp accordingly.  Their produced
DWARF5 binaries will change a bit, in that they will now have a single
directory and file, where they had two before.  But it doesn't change
the expected GDB behavior.

Change-Id: I5459b16ac9b7f28c34c9693c35c9afd2ebb3aa3b
2022-04-18 16:57:36 -04:00
Simon Marchi
5f2491c300 gdbsupport: make gdb_realpath_keepfile return an std::string
I'm trying to switch these functions to use std::string instead of char
arrays, as much as possible.  Some callers benefit from it (can avoid
doing a copy of the result), while others suffer (have to make one more
copy).

Change-Id: I793aab17baaef8345488f4c40b9094e2695425bc
2022-04-18 15:48:03 -04:00
Simon Marchi
7ab2607f97 gdbsupport: make gdb_abspath return an std::string
I'm trying to switch these functions to use std::string instead of char
arrays, as much as possible.  Some callers benefit from it (can avoid
doing a copy of the result), while others suffer (have to make one more
copy).

Change-Id: Iced49b8ee2f189744c5072a3b217aab5af17a993
2022-04-18 15:48:03 -04:00
Simon Marchi
e0c3463701 gdb: call gdb_tilde_expand instead of gdb_tilde_expand_up in source_script_with_search
This removes a use of gdb_tilde_expand_up, which is removed later in
this series.

Change-Id: I5887d526cea987103e4ca24514a982b0a28e992a
2022-04-18 15:48:03 -04:00
Tom Tromey
2390419d1c Fix C++ cast of derived class to base class
PR c++/28907 points out that casting from a derived class to a base
class fails in some situations.  The problem turned out to be a
missing use of value_embedded_offset.  One peculiarity here is that,
if you managed to construct a pointer-to-derived with an embedded
offset of 0, the cast would work -- for example, one of the two new
tests here passes without the patch.

This embedded offset stuff is an endless source of bugs.  I wonder if
it's possible to get rid of it somehow.

Regression tested on x86-64 Fedora 34.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28907
2022-04-18 09:34:55 -06:00
Simon Marchi
c67f4e5389 gdb/testsuite: make gdb.ada/mi_prot.exp stop at expected location
This test attempts to run until the line marked "STOP", which is at
prot.adb:34.  It first runs until the "main" symbol, then tries to place
a breakpoint by line at line 34, without specifying the source file.  When looking at the logs:

    -break-insert -t 34^M
    ^done,bkpt={number="2",type="breakpoint",disp="del",enabled="y",addr="0x0000555555558a6c",func="adafinal",file="/home/simark/build/binutils-gdb-one-target/gdb/testsuite/outputs/gdb.ada/mi_pro    t/b~prot.adb",fullname="/home/simark/build/binutils-gdb-one-target/gdb/testsuite/outputs/gdb.ada/mi_prot/b~prot.adb",line="44",thread-groups=["i1"],times="0",original-location="/home/simark/b    uild/binutils-gdb-one-target/gdb/testsuite/outputs/gdb.ada/mi_prot/b~prot.adb:34"}^M
    ... continues ...
     *stopped,reason="breakpoint-hit",disp="del",bkptno="2",frame={addr="0x0000555555558a6c",func="adafinal",args=[],file="/home/simark/build/binutils-gdb-one-target/gdb/testsuite/outputs/gdb.ada/    mi_prot/b~prot.adb",fullname="/home/simark/build/binutils-gdb-one-target/gdb/testsuite/outputs/gdb.ada/mi_prot/b~prot.adb",line="44",arch="i386:x86-64"},thread-id="1",stopped-threads="all",co    re="8"^M

... we see that the breakpoint is placed in some generated file, not in
the test source file as we expect.  The problem is that "b main" in Ada
does not place a breakpoint on the "Ada main", but on some symbol in a
generated source file.  So when stopped at the "main" symbol, we are not
stopped in the file that contains the STOP marker at line 34.

The test passes anyway today, so it doesn't seem to matter that we are
stopped at an unexpected location.  But it starts failing with this
patch [1], because b~prot.adb:34 happens to be between two functions, so
the breakpoint doesn't resolve.

Fix this by placing the breakpoint at "$srcfile:$line", which works
regardless of what is the current source file.

However, this ends up introducing a path in the test name.  Modify
mi_tbreak and mi_continue_to_line to avoid that.

[1] https://sourceware.org/pipermail/gdb-patches/2022-April/187686.html

Change-Id: I742e2a9993046dcb5e30c64fe2ad920a363baf75
2022-04-18 10:28:25 -04:00
Vignesh Balasubramanian
2bb8c72b39 gdb/testsuite: add text_segment option to gdb_compile
LLVM's lld linker doesn't have the "-Ttext-segment" option, but
"--image-base" can be used instead.

To centralize the logic of checking which option is supported, add the
text_segment option to gdb_compile.  Change tests that are currently
using -Ttext-segment to use that new option instead.

This patch fixes only compilation error, for example:

Before:

    $ make check TESTS="gdb.base/jit-elf.exp" RUNTESTFLAGS="CC_FOR_TARGET=clang LDFLAGS_FOR_TARGET=-fuse-ld=ld"
    Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/jit-elf.exp ...
    gdb compile failed, clang-13: warning: -Xlinker -Ttext-segment=0x7000000: 'linker' input unused [-Wunused-command-line-argument]

After:

    $ make check TESTS="gdb.base/jit-elf.exp" RUNTESTFLAGS="CC_FOR_TARGET=clang LDFLAGS_FOR_TARGET=-fuse-ld=ld"
    Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/jit-elf.exp ...
    FAIL: gdb.base/jit-elf.exp: one_jit_test-1: continue to breakpoint: break here 1
    FAIL: gdb.base/jit-elf.exp: one_jit_test-1: continue to breakpoint: break here 2
    FAIL: gdb.base/jit-elf.exp: one_jit_test-2: continue to breakpoint: break here 1
    FAIL: gdb.base/jit-elf.exp: one_jit_test-2: info function ^jit_function
    FAIL: gdb.base/jit-elf.exp: one_jit_test-2: continue to breakpoint: break here 2
    FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: continue to breakpoint: break here 1
    FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: break here 1: attach
    FAIL: gdb.base/jit-elf.exp: PIE: one_jit_test-1: continue to breakpoint: break here 1
    FAIL: gdb.base/jit-elf.exp: PIE: one_jit_test-1: continue to breakpoint: break here 2

                    === gdb Summary ===

    # of expected passes            26
    # of unexpected failures        9

Change-Id: I3678c5c9bbfc2f80671698e28a038e6b3d14e635
2022-04-18 10:24:48 -04:00
Enze Li
a5c69b1e49 gdb: fix using clear command to delete non-user breakpoints(PR cli/7161)
The clear command shouldn't delete momentary and internal breakpoints,
nor internal breakpoints created via Python's gdb.Breakpoint.

This patch fixes this issue and adds a testcase.

Regression tested on x86_64 openSUSE Tumbleweed(VERSION_ID="20220413").

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7161
2022-04-18 21:40:31 +08:00
Tom Tromey
3c8184c43d Add comments to dwarf2/abbrev-cache.h
This patch started when I noticed that the unordered_set include
wasn't needed in abbrev-cache.h.  (That was probably leftover from
some earlier implementation of the class.)  Then, I noticed that the
class itself was under-commented.  This patch fixes both issues.
2022-04-16 13:58:34 -06:00
Tom Tromey
4311246bb1 Return void from gdb_putc
I don't think it's very useful to return the character from gdb_putc,
so this patch changes it to return void.
2022-04-15 11:38:13 -06:00
Tom Tromey
111d19818a Handle "set height 1"
PR cli/17151 points out that "set height 1" has pathological behavior
in gdb.  What I see is that gdb will endlessly print the pagination
prompt.  This patch takes a simple and expedient approach to a fix:
pretend that the height is really 2.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17151
2022-04-15 11:38:13 -06:00
Tom Tromey
1f0f8b5d9d Allow word wrapping even when paging is disabled
PR cli/20741 points out that when pagination is disabled, this also
disabled word wrapping.  However, the manual documents that these
settings are separate -- if you intend to disable the wrapping, you
must use "set width unlimited".

This patch fixes the bug by letting the pagination-disabled case fall
through to the code that also handles word-wrapping.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20741
2022-04-15 11:38:13 -06:00
Tom Tromey
1c9cc05244 Implement value_print for Rust
This adds an implementation of the value_print method to Rust.  As
described in PR rust/22254, this removes a bit of weird-looking output
from some "print"s -- because c_value_print is bypassed.  I don't have
a test for the bug that inspired this patch, because I only know how
to reproduce it when using a relatively old Rust compiler.  However,
the new "cast-printing" code in value_print is required, because
omitting this causes some existing tests to fail.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22254
2022-04-15 10:34:03 -06:00
Tom Tromey
506ec52e88 Reimplement Rust slice printing
The current nightly Rust compiler (aka 1.61) added better DWARF
representation for unsized types.  Fixing this is PR rust/21466; but
the code is actually the same as what is required to make slice
printing more useful, which is PR rust/23871.  This patch implements
this.  I tested this against various Rust compilers: 1.48, current
stable, current beta, and current nightly.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21466
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23871
2022-04-15 10:34:03 -06:00
Tom Tromey
925ea601f1 Remove some dead code from the Rust value printer
This removes a bit of dead code from the Rust value printer.  This
code wasn't always dead -- it fixed a real bug, and a test case was
added for it.  However, once val_print was removed, it became
unnecessary.
2022-04-15 10:34:03 -06:00
Tom Tromey
7410508723 Match rustc beta versions
The rust_compiler_version proc extracts the Rust compiler version from
the "rustc --version" output.  For a beta compiler, the output looks
like:

    rustc 1.60.0-beta.6 (7bccde197 2022-03-22)

This patch slightly relaxes the regexp -- removing a space -- so that
this can be understood by this proc.
2022-04-15 10:34:03 -06:00
Tom de Vries
3b9809bc62 [gdb/testsuite] Fix gdb.ada/float-bits.exp with -m32
With test-case gdb.ada/float-bits.exp and native we get:
...
(gdb) print 16llf#7FFFF7FF4054A56FA5B99019A5C8#^M
$9 = 5.0e+25^M
(gdb) PASS: gdb.ada/float-bits.exp: print 16llf#7FFFF7FF4054A56FA5B99019A5C8#
...
but with target board unix/-m32 we have instead:
...
(gdb) print 16llf#7FFFF7FF4054A56FA5B99019A5C8#^M
Cannot export value 2596145952482202326224873165792712 as 96-bits \
  unsigned integer (must be between 0 and 79228162514264337593543950335)^M
(gdb) FAIL: gdb.ada/float-bits.exp: print 16llf#7FFFF7FF4054A56FA5B99019A5C8#
...

Fix this by testing whether 16llf is supported by doing ptype long_long_float
which gets us either:
...
type = <16-byte float>^M
...
or:
...
type = <12-byte float>^M
...

Tested on x86_64-linux with native and unix/-m32.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29041
2022-04-15 18:00:30 +02:00
Tom Tromey
d4cd7e84e2 Remove WITH_SIM define
Since score-tdep.c was removed, the WITH_SIM define is not used in
gdb.  This patch removes it.

Note that re-running autoheader shows a separate change that was
missed.  I've kept it in this patch to avoid extra work.
2022-04-15 09:32:31 -06:00
Tom de Vries
552a161c8d [gdb/testsuite] Fix gdb.go/methods.exp with check-readmore
When running test-case gdb.go/methods.exp with make check we have:
...
(gdb) break main.T.Foo^M
Function "main.T.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) XFAIL: gdb.go/methods.exp: gdb_breakpoint: set breakpoint at main.T.Foo
...
but with make check-readmore the XFAIL fails to trigger:
...
(gdb) break main.T.Foo^M
Function "main.T.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) FAIL: gdb.go/methods.exp: gdb_breakpoint: set breakpoint at main.T.Foo
...

This happens because this gdb_test_multiple "maintenance print symbols"
regexp:
...
    -re "\r\n$gdb_prompt $" {
...
matches the entire command output.

Fix this by adding the missing ^ at the regexp start.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29064
2022-04-15 16:53:08 +02:00
Tom Tromey
1a7c41d5ec Ignore 0,0 entries in .debug_aranges
When running the internal AdaCore test suite against the new DWARF
indexer, I found one regression on RISC-V.  The test in question uses
--gc-sections, and winds up with an entry in the middle of a
.debug_aranges that has both address and length of 0.  In this
scenario, gdb assumes the entries are terminated and then proceeds to
reject the section because it reads a subsequent entry as if it were a
header.

It seems to me that, because each header describes the size of each
.debug_aranges CU, it's better to simply ignore 0,0 entries and simply
read to the end.  That is what this patch does.

I've patched an existing test to provide a regression test for this.
2022-04-14 12:22:07 -06:00
Tom Tromey
8bbdbd6985 Use GetThreadDescription on Windows
Windows 10 introduced SetThreadDescription and GetThreadDescription, a
simpler way to set a thread's name.  This changes gdb and gdbserver to
use this convention when it is available.

This is part of PR win32/29050.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29050
2022-04-14 12:12:35 -06:00
Tom Tromey
44ac251ad2 Share handle_ms_vc_exception with gdbserver
Currently, gdb's native Windows target implements the exception-based
approach for setting thread names, but gdbserver does not.  This patch
moves handle_ms_vc_exception to the shared nat/windows-nat.c code, as
preparation for adding this support to gdbserver.
2022-04-14 12:12:34 -06:00
Tom Tromey
b17c7ab380 Move target_read_string to target/target.c
This moves the two overloads of target_read_string to a new file,
target/target.c, and updates both gdb and gdbserver to build this.
2022-04-14 12:12:34 -06:00
Tom Tromey
9da74023eb Remove the byte order parameter to target_read_string
target_read_string takes a byte order parameter, but only uses this to
check whether a given character is zero.  This is readily done without
requiring the parameter, so remove it.
2022-04-14 12:12:34 -06:00
Tom Tromey
3b1bdd53b5 Rename read_string
This renames read_string to be an overload of target_read_string.
This makes it more consistent for the eventual merger with gdbserver.
2022-04-14 12:12:34 -06:00
Tom Tromey
94ea6ddb94 Don't call QUIT in read_string
read_string does not need to call QUIT, because target_read_memory
already does.  This change is needed to make string-reading usable by
gdbserver.
2022-04-14 12:12:34 -06:00
Tom Tromey
a69599e68b Fix possible Cygwin build problem
I noticed that nat/windows-nat.c checks __USEWIDE, but nothing sets it
there -- I forgot to copy over the definition when making this file.
This patch tries to fix the problem.  I don't have a Cygwin setup, so
I don't know whether this is sufficient, but it's probably necessary.
2022-04-14 12:12:34 -06:00
Lancelot SIX
a79fa8c5fb gdb/testsuite: Fix race in gdb.dwarf2/calling-convention.exp
Pedro Alves warned me that there is a race in
gdb.dwarf2/calling-convention.exp making the test sometimes fail on his
setup.  This can be reliably reproduced using :

    make check-read1 TESTS="gdb.dwarf2/calling-convention.exp"

The relevant part of the gdb.log file is:

    return 35
    Function 'foo' does not follow the target calling convention.
    If you continue, setting the return value will probably lead to unpredictable behaviors.
    Make foo return now? (y or n) PASS: gdb.dwarf2/calling-convention.exp: return 35
    n
    Not confirmed
    (gdb) FAIL: gdb.dwarf2/calling-convention.exp: finish

The issue is that when doing the test for "return 35", the DejaGnu test
sends "n" (to tell GDB not to perform the return action) but never
consumes the "Not confirmed" acknowledgment sent by GDB.  Later, when
trying to do the next test, DejaGnu tries to match the leftover output
from the "return" test. As this output is not expected, the test fails.

Fix by using gdb_test to send the "n" answer and match the confirmation
and consume all output to the prompt.

Also do minor adjustments to the main regex:
  - Remove the leading ".*" which is not required.
  - Ensure that the "?" from the question is properly escaped.

Tested on x86_64-gnu-linux, using

- make check TESTS="gdb.dwarf2/calling-convention.exp"
- make check-read1 TESTS="gdb.dwarf2/calling-convention.exp"
- make check-readmore TESTS="gdb.dwarf2/calling-convention.exp"

Co-authored-by: Pedro Alves <pedro@palves.net>
Change-Id: I42858b13db2cbd623c5c1739de65ad423e0c0938
2022-04-14 18:21:04 +01:00
Tom Tromey
4536b3bb61 Silence -Wmaybe-uninitialized warning from target_waitstatus
Currently, one use of target_waitstatus yields a warning:

     target/waitstatus.h: In function 'void stop_all_threads()':
     target/waitstatus.h:175:13: warning: 'ws.target_waitstatus::m_value' may be used uninitialized in this function [-Wmaybe-uninitialized]
       175 |     m_value = other.m_value;
	   |     ~~~~~~~~^~~~~~~~~~~~~~~

This patch silences the warning.  I tried the "volatile member"
approach that was used for gdb::optional, but that didn't work, so
this patch simply initializes the member.
2022-04-14 10:04:13 -06:00
Tom Tromey
7ae6857316 Fix regression on Windows with WOW64
Internally at AdaCore, we recently started testing a 64-bit gdb
debugging 32-bit processes.  This failed with gdb head, but not with
gdb 11.

The tests fail like this:

     Starting program: [...].exe
     warning: Could not load shared library symbols for WOW64_IMAGE_SECTION.
     Do you need "set solib-search-path" or "set sysroot"?
     warning: Could not load shared library symbols for WOW64_IMAGE_SECTION.
     Do you need "set solib-search-path" or "set sysroot"?
     warning: Could not load shared library symbols for NOT_AN_IMAGE.
     Do you need "set solib-search-path" or "set sysroot"?
     warning: Could not load shared library symbols for NOT_AN_IMAGE.
     Do you need "set solib-search-path" or "set sysroot"?

After some debugging and bisecting, to my surprise the bug was
introduced by commit 183be222 ("gdb, gdbserver: make target_waitstatus
safe").

The problem occurs in handle_exception.  Previously the code did:

    -  ourstatus->kind = TARGET_WAITKIND_STOPPED;
    [...]
	 case EXCEPTION_BREAKPOINT:
    [...]
    -	  ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
    [...]
	   /* FALLTHROUGH */
	 case STATUS_WX86_BREAKPOINT:
	   DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT");
    -      ourstatus->value.sig = GDB_SIGNAL_TRAP;
    [...]
    -  last_sig = ourstatus->value.sig;

However, in the new code, the fallthrough case does:

    +      ourstatus->set_stopped (GDB_SIGNAL_TRAP);

... which changes the 'kind' in 'ourstatus' after falling through.

This patch rearranges the 'last_sig' setting to more closely match
what was done before (this is probably not strictly needed but also
seemed harmless), and removes the fall-through in the
'ignore_first_breakpoint' case when __x86_64__ is defined.
2022-04-14 09:56:26 -06:00
Tom Tromey
77d97a0a19 Reorganize Python events documentation
This slightly reorganizes the Python events documentation.  It hoists
the "ThreadEvent" text out of the list of events, where it seemed to
be misplaced.  It tidies the formatting a little bit (adding some
vertical space for easier reading in info), fixes a typo, adds some
missing commas, and fixes an incorrect reference to NewInferiorEvent.
2022-04-14 09:50:44 -06:00
Simon Marchi
df4397e378 gdb: remove move constructor and move assignment operator from cooked_index
Building with clang++-14, I see:

      CXX    dwarf2/cooked-index.o
    In file included from /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:21:
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:172:12: error: explicitly defaulted move constructor is implicitly deleted [-Werror,-Wdefaulted-function-deleted]
      explicit cooked_index (cooked_index &&other) = default;
               ^
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:225:16: note: move constructor of 'cooked_index' is implicitly deleted because field 'm_storage' has a deleted move constructor
      auto_obstack m_storage;
                   ^
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb_obstack.h:128:28: note: 'auto_obstack' has been explicitly marked deleted here
      DISABLE_COPY_AND_ASSIGN (auto_obstack);
                               ^
    In file included from /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:21:
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:174:17: error: explicitly defaulted move assignment operator is implicitly deleted [-Werror,-Wdefaulted-function-deleted]
      cooked_index &operator= (cooked_index &&other) = default;
                    ^
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:225:16: note: move assignment operator of 'cooked_index' is implicitly deleted because field 'm_storage' has a deleted move assignment operator
      auto_obstack m_storage;
                   ^
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb_obstack.h:128:3: note: 'operator=' has been explicitly marked deleted here
      DISABLE_COPY_AND_ASSIGN (auto_obstack);
      ^
    /home/smarchi/src/binutils-gdb/gdb/../include/ansidecl.h:425:8: note: expanded from macro 'DISABLE_COPY_AND_ASSIGN'
      void operator= (const TYPE &) = delete
           ^

We explicitly make cooked_index have a default move constructor and
move assignment operator.  But it doesn't actually happen because
cooked_index has a field of type auto_obstack, which isn't movable.
We don't actually need cooked_index to be movable at the moment, so
remove those lines.

Change-Id: Ifc1fe3d7d67e3ae1a14363d6c1869936fe80b0a2
2022-04-14 11:32:34 -04:00
Tom Tromey
c560a5fbae Let std::thread check pass even without pthreads
Currently, the configure check for std::thread relies on pthreads
existing.  However, this means that if std::thread is implemented for
a non-pthreads host, then the check will yield the wrong answer.  This
happened in AdaCore internal builds.  Here, we have this GCC patch:

    https://gcc.gnu.org/legacy-ml/gcc-patches/2019-06/msg01840.html

... which adds mingw support to GCC's gthreads implementation, and
also to std::thread.

This configure change fixes this problem and enables threading for
gdb.
2022-04-14 09:28:56 -06:00
Tom de Vries
75b2a443d5 [gdb/testsuite] Detect 'No MPX support'
On openSUSE Leap 15.3, mpx support has been disabled for m32, so I run into:
...
(gdb) run ^M
Starting program: outputs/gdb.arch/i386-mpx/i386-mpx ^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
No MPX support^M
...
and eventually into all sort of fails in this and other mpx test-cases.

Fix this by detecting the "No MPX support" message in have_mpx.

Tested on x86_64-linux with target boards unix and unix/-m32.
2022-04-14 12:32:51 +02:00
Simon Marchi
08755c5aad gdb: add ATTRIBUTE_PRINTF to complaint_interceptor::issue_complaint
Fix this error when building with clang++-14:

      CXX    complaints.o
    /home/smarchi/src/binutils-gdb/gdb/complaints.c:130:65: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
      g_complaint_interceptor->m_complaints.insert (string_vprintf (fmt, args));
                                                                    ^~~

Change-Id: I0ef11f970510eb8638d1651fa0d5eeecd6a9d31a
2022-04-13 14:39:14 -04:00
Simon Marchi
febb368c89 gdb: fix clang build failure in msymbol_is_mips
Building with clang++-14, I see:

      CXX    mips-tdep.o
    /home/smarchi/src/binutils-gdb/gdb/mips-tdep.c:453:12: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
      return !(MSYMBOL_TARGET_FLAG_MIPS16 (msym)
              ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/mips-tdep.h:54:2: note: expanded from macro 'MSYMBOL_TARGET_FLAG_MIPS16'
            (sym)->target_flag_1 ()
            ^
    /home/smarchi/src/binutils-gdb/gdb/mips-tdep.c:453:12: note: cast one or both operands to int to silence this warning
    /home/smarchi/src/binutils-gdb/gdb/mips-tdep.h:54:2: note: expanded from macro 'MSYMBOL_TARGET_FLAG_MIPS16'
            (sym)->target_flag_1 ()
            ^

That's since commit e165fcef1e ("gdb: remove MSYMBOL_TARGET_FLAG_{1,2}
macros").  Fix this by using the boolean || rather than the bitwise |,
since the new methods return bool values.  No change in behavior
expected.

Change-Id: Ia82664135aa25db64c29c92f5c1141859d345bf7
2022-04-13 14:38:06 -04:00
Pedro Alves
d095eb4e87 Tidy gdb.base/parse_number.exp
Now that Ada is able to parse & print 0xffffffffffffffff (2^64-1) in
hex, move it to the else branch like most other languages.

Change-Id: Ib305f6bb2b6b230a1190ea783b245b865821094c
2022-04-13 10:16:24 +01:00
Tom Tromey
36baf73637 Fix bug in Ada number lexing
On irc, Pedro pointed out that Ada couldn't properly handle
0xffffffffffffffff.  This used to work, but is a regression due to
some patches I wrote in the Ada lexer.  This patch fixes the bug.
2022-04-12 12:59:28 -06:00
Simon Marchi
a8b7a13911 gdb: fix "passing NULL to memcpy" UBsan error in dwarf2/cooked-index.c
Reading a simple file compiled with :

    $ gcc -DONE=1 -gdwarf-4 -g3  test.c
    $ gcc --version
    gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0

I get:

    Reading symbols from /tmp/cwd/a.out...
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:332:11: runtime error: null pointer passed as argument 2, which is declared to never be null

It looks like even if the size is 0 (the size of the `entries` vector is
0), we shouldn't be passing a NULL pointer to memcpy.  And
`entries.data ()` returns NULL.

Fix that by using std::vector::insert to insert the items of entries
into m_entries.  I haven't checked, but it should essentially compile
down to a memcpy, since the vector elements are trivially copyiable.

Change-Id: I75f1c901e9b522e42e89eb5936e2c70d68eb21e5
2022-04-12 14:42:02 -04:00
Simon Marchi
558802e4d1 gdb: change subfile::line_vector to an std::vector
Change this field to an std::vector to facilitate memory management.
Since the linetable_entry array is copied into the symtab resulting from
the subfile, it is possible to change it without changing how symtab
stores the linetable entries (which would be a much larger change).

There is a small change in buildsym_compunit::record_line to avoid
accessing a now invalid linetable_entry.  Before this patch, we keep a
pointer to the last linetable entry, pop it from the vector, and then
read last->line.  It works with the manually-maintained array, but since
we now use std::vector::pop_back, I am afraid that it could be flagged
as an invalid access by the various static / dynamic analysis tools to
access the linetable_entry object after popping it from the vector.
Instead, record just the line number in an optional and use it.

There are substantial changes in xcoffread.c that simplify the code, but
I can't test them.  I was hesitant to do this change because of that,
but I decided to send it anyway.  I don't think that an almost dead
platform should hold back improving the code in the common parts of GDB.

The changes in xcoffread.c are:

 - Make arrange_linetable "arrange" the linetable passed as a parameter,
   instead of returning possibly a new one, possibly the same one.
 - In the "Process main file's line numbers.", I'm not too sure what
   happens.  We get the lintable from "main_subfile", "arrange" it, but
   then assign the result to the current subfile, obtained with
   get_current_subfile.  I assume that the current subfile is also the
   main one, so now I just call arrange_linetable on the main subfile's
   line table.
 - Remove that weird "Useless if!!!" FIXME comment.  It's been there
   forever, but the "if" is still there, so I guess the "if" can stay
   there.

Change-Id: I11799006fd85189e8cf5bd3a168f8f38c2c27a80
2022-04-12 14:17:43 -04:00
Simon Marchi
b08c778be9 gdb: use std::vector for temporary linetable_entry array in arrange_linetable
Reduce manual memory management and make the code a bit easier to read.
This helps me a bit in the following patch.

I don't have a way to test this, it's best-effort.

Change-Id: I64af9cd756311deabc6cd95e701dfb21234a40a5
2022-04-12 14:13:11 -04:00
Simon Marchi
ebd4e6d017 gdb: change subfile::name and buildsym_compunit::m_comp_dir to strings
Change subfile::name to be a string, for easier memory management.
Change buildsym_compunit::m_comp_dir as well, since we move one in to
the other at some point in patch_subfile_names, so it's easier to do
both at the same time.  There are various NULL checks for both fields
currently, replace them with empty checks, I think it ends up
equivalent.

I can't test the change in xcoffread.c, it's best-effort.

Change-Id: I62b5fb08b2089e096768a090627ac7617e90a016
2022-04-12 14:13:10 -04:00
Simon Marchi
71bc95ed20 gdb: allocate subfile with new
Allocate struct subfile with new, initialize its fields instead of
memset-ing it to 0.  Use a unique_ptr for the window after a subfile has
been allocated but before it is linked in the buildsym_compunit's list
of subfile (and therefore owned by the buildsym_compunit.

I can't test the change in xcoffread.c, it's best-effort.  I couldn't
find where subfiles are freed in that file, I assume they were
intentionally (or not) leaked.

Change-Id: Ib3b6877de31b7e65bc466682f08dbf5840225f24
2022-04-12 14:13:10 -04:00
Simon Marchi
30bf8e1ce4 gdb: use decltype instead of typeof in dwarf2/read.c
When building with -std=c++11, I get:

  CXX    dwarf2/read.o
/home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c: In function ‘void dwarf2_build_psymtabs_hard(dwarf2_per_objfile*)’:
/home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:7130:23: error: expected type-specifier before ‘typeof’
 7130 |     using iter_type = typeof (per_bfd->all_comp_units.begin ());
      |                       ^~~~~~

This is because typeof is a GNU extension.  Use C++'s decltype keyword
instead.

Change-Id: Ieca2e8d25e50f71dc6c615a405a972a54de3ef14
2022-04-12 14:09:55 -04:00
Tom Tromey
8dddb06c59 Remove dwarf2_per_cu_data::v
Now that the psymtab reader has been removed, the
dwarf2_per_cu_data::v union is no longer needed.  Instead, we can
simply move the members from dwarf2_per_cu_quick_data into
dwarf2_per_cu_data and remove the "quick" object entirely.
2022-04-12 09:31:17 -06:00
Tom Tromey
6209cde4dd Delete DWARF psymtab code
This removes the DWARF psymtab reader.
2022-04-12 09:31:17 -06:00
Tom Tromey
3d20b8d99a Enable the new DWARF indexer
This patch finally enables the new indexer.  It is left until this
point in the series to avoid any regressions; in particular, it has to
come after the changes to the DWARF index writer to avoid this
problem.

However, if you experiment with the series, this patch can be moved
anywhere from the patch to wire in the new reader to this point.
Moving this patch around is how I got separate numbers for the
parallelization and background finalization patches.

In the ongoing performance example, this reduces the time from the
baseline of 1.598869 to 0.903534.
2022-04-12 09:31:17 -06:00
Tom Tromey
600f5f7027 Adapt .debug_names writer to new DWARF scanner
This updates the .debug_names writer to work with the new DWARF
scanner.
2022-04-12 09:31:16 -06:00
Tom Tromey
6dd7aa909b Adapt .gdb_index writer to new DWARF scanner
This updates the .gdb_index writer to work with the new DWARF scanner.
The .debug_names writer is deferred to another patch, to make review
simpler.

This introduces a small hack to psyms_seen_size, but is
inconsequential because this function will be deleted in a subsequent
patch.
2022-04-12 09:31:16 -06:00
Tom Tromey
fa38ad7d8a Genericize addrmap handling in the DWARF index writer
This updates the DWARF index writing code to make the addrmap-writing
a bit more generic.  Now, it can handle multiple maps, and it can work
using the maps generated by the new indexer.

Note that the new addrmap_index_data::using_index field will be
deleted in a future patch, when the rest of the DWARF psymtab code is
removed.
2022-04-12 09:31:16 -06:00
Tom Tromey
fca9326e27 Change parameters to write_address_map
To support the removal of partial symtabs from the DWARF index writer,
this makes a small change to have write_address_map accept the address
map as a parameter, rather than assuming it always comes from the
per-BFD object.
2022-04-12 09:31:16 -06:00
Tom Tromey
88a981942d Change the key type in psym_index_map
In order to change the DWARF index writer to avoid partial symtabs,
this patch changes the key type in psym_index_map (and renames that
type as well).  Using the dwarf2_per_cu_data as the key makes it
simpler to reuse this code with the new indexer.
2022-04-12 09:31:16 -06:00
Tom Tromey
58f707487b Rename write_psymtabs_to_index
We'll be removing all the psymtab code from the DWARF reader.  As a
preparatory step, this renames write_psymtabs_to_index to avoid the
"psymtab" name.
2022-04-12 09:31:16 -06:00
Tom Tromey
7e75279093 "Finalize" the DWARF index in the background
After scanning the CUs, the DWARF indexer merges all the data into a
single vector, canonicalizing C++ names as it proceeds.  While not
necessarily single-threaded, this process is currently done in just
one thread, to keep memory costs lower.

However, this work is all done without reference to any data outside
of the indexes.  This patch improves the apparent performance of GDB
by moving it to the background.  All uses of the index are then made
to wait for this process to complete.

In our ongoing example, this reduces the scanning time on gdb itself
to 0.173937 (wall).  Recall that before this patch, the time was
0.668923; and psymbol reader does this in 1.598869.  That is, at the
end of this series, we see about a 10x speedup.
2022-04-12 09:31:16 -06:00
Tom Tromey
46114cb7be Parallelize DWARF indexing
This parallelizes the new DWARF indexer.  The indexer's storage was
designed so that each storage object and each indexer is fully
independent.  This setup makes it simple to scan different CUs
independently.

This patch creates a new cooked index storage object per thread, and
then scans a subset of all the CUs in each such thread, using gdb's
existing thread pool.

In the ongoing "gdb gdb" example, this patch reduces the wall time
down to 0.668923, from 0.903534.  (Note that the 0.903534 is the time
for the new index -- that is, when the "enable the new index" patch is
rebased to before this one.  However, in the final series, that patch
appears toward the end.  Hopefully this isn't too confusing.)
2022-04-12 09:31:16 -06:00
Tom Tromey
c748b24c47 Pre-read DWARF section data
Because BFD is not thread-safe, we need to be sure that any section
data that is needed is read before trying to do any DWARF indexing in
the background.

This patch takes a simple approach to this -- it pre-reads the
"info"-related sections.  This is done for the main file, but also any
auxiliary files as well, such as the DWO file.

This patch could be perhaps enhanced by removing some now-redundant
calls to dwarf2_section_info::read.
2022-04-12 09:31:16 -06:00
Tom Tromey
da63229779 Introduce thread-safe handling for complaints
This introduces a new class that can be used to make the "complaint"
code thread-safe.  Instantiating the class installs a new handler that
collects complaints, and then prints them all when the object is
destroyed.

This approach requires some locks.  I couldn't think of a better way
to handle this, though, because the I/O system is not thread-safe.

It seemed to me that only GDB developers are likely to enable
complaints, and because the complaint macro handle this case already
(before any locks are required), I reasoned that any performance
degradation that would result here would be fine.

As an aside about complaints -- are they useful at all?  I just ignore
them, myself, since mostly they seem to indicate compiler problems
that can't be solved in the GDB world anyway.  I'd personally prefer
them to be in a separate tool, like a hypothetical 'dwarflint'.
2022-04-12 09:31:16 -06:00
Tom Tromey
68a85bc267 Wire in the new DWARF indexer
This wires the new DWARF indexer into the existing reader code.  That
is, this patch makes the modification necessary to enable the new
indexer.  It is not actually enabled by this patch -- that will be
done later.

I did a bit of performance testing for this patch and a few others.  I
copied my built gdb to /tmp, so that each test would be done on the
same executable.  Then, each time, I did:

    $ ./gdb -nx
    (gdb) maint time 1
    (gdb) file /tmp/gdb

This patch is the baseline and on one machine came in at 1.598869 wall
time.
2022-04-12 09:31:16 -06:00
Tom Tromey
698379cc2c Implement quick_symbol_functions for cooked DWARF index
This implements quick_symbol_functions for the cooked DWARF index.
This is the code that interfaces between the new index and the rest of
gdb.  Cooked indexes still aren't created by anything.

For the most part this is straightforward.  It shares some concepts
with the existing DWARF indices.  However, because names are stored
pre-split in the cooked index, name lookup here is necessarily
different; see expand_symtabs_matching for the gory details.
2022-04-12 09:31:16 -06:00
Tom Tromey
2e57de7c84 The new DWARF indexer
This patch adds the code to index DWARF.  This is just the scanner; it
reads the DWARF and constructs the index, but nothing calls it yet.

The indexer is split into two parts: a storage object and an indexer
object.  This is done to support the parallelization of this code -- a
future patch will create a single storage object per thread.
2022-04-12 09:31:16 -06:00
Tom Tromey
51f5a4b8e9 Introduce the new DWARF index class
This patch introduces the new DWARF index class.  It is called
"cooked" to contrast against a "raw" index, which is mapped from disk
without extra effort.

Nothing constructs a cooked index yet.  The essential idea here is
that index entries are created via the "add" method; then when all the
entries have been read, they are "finalize"d -- name canonicalization
is performed and the entries are added to a sorted vector.

Entries use the DWARF name (DW_AT_name) or linkage name, not the full
name as is done for partial symbols.

These two facets -- the short name and the deferred canonicalization
-- help improve the performance of this approach.  This will become
clear in later patches, when parallelization is added.

Some special code is needed for Ada, because GNAT only emits mangled
("encoded", in the Ada lingo) names, and so we reconstruct the
hierarchical structure after the fact.  This is also done in the
finalization phase.

One other aspect worth noting is that the way the "main" function is
found is different in the new code.  Currently gdb will notice
DW_AT_main_subprogram, but won't recognize "main" during reading --
this is done later, via explicit symbol lookup.  This is done
differently in the new code so that finalization can be done in the
background without then requiring a synchronization to look up the
symbol.
2022-04-12 09:31:16 -06:00
Tom Tromey
a2f0ab9310 Update skip_one_die for new abbrev properties
This updates skip_one_die to speed it up in the cases where either
sibling_offset or size_if_constant are set.
2022-04-12 09:31:16 -06:00
Tom Tromey
696eef26e0 Statically examine abbrev properties
The new DIE scanner works more or less along the lines indicated by
the text for the .debug_names section, disregarding the bugs in the
specification.

While working on this, I noticed that whether a DIE is interesting is
a static property of the DIE's abbrev.  It also turns out that many
abbrevs imply a static size for the DIE data, and additionally that
for many abbrevs, the sibling offset is stored at a constant offset
from the start of the DIE.

This patch changes the abbrev reader to analyze each abbrev and stash
the results on the abbrev.  These combine to speed up the new indexer.
If the "interesting" flag is false, GDB knows to skip the DIE
immediately.  If the sibling offset is statically known, skipping can
be done without reading any attributes; and in some other cases, the
DIE can be skipped using simple arithmetic.
2022-04-12 09:31:16 -06:00
Tom Tromey
8c83177441 Introduce DWARF abbrev cache
The replacement for the DWARF psymbol reader works in a somewhat
different way.  The current reader reads and stores all the DIEs that
might be interesting.  Then, if it is missing a DIE, it re-scans the
CU and reads them all.  This approach is used for both intra- and
inter-CU references.

I instrumented the partial DIE hash to see how frequently it was used:

    [  0] -> 1538165
    [  1] ->    4912
    [  2] ->   96102
    [  3] ->     175
    [  4] ->     244

That is, most DIEs are never used, and some are looked up twice -- but
this is just an artifact of the implementation of
partial_die_info::fixup, which may do two lookups.

Based on this, the new implementation doesn't try to store any DIEs,
but instead just re-scans them on demand.  In order to do this,
though, it is convenient to have a cache of DWARF abbrevs.  This way,
if a second CU is needed to resolve an inter-CU reference, the abbrevs
for that CU need only be computed a single time.
2022-04-12 09:31:16 -06:00
Tom Tromey
c600d77cb7 Add "fullname" handling to file_and_directory
This changes the file_and_directory object to be able to compute and
cache the "fullname" in the same way that is done by other code, like
the psymtab reader.
2022-04-12 09:31:16 -06:00
Tom Tromey
82d734f7a3 Add batching parameter to parallel_for_each
parallel_for_each currently requires each thread to process at least
10 elements.  However, when indexing, it's fine for a thread to handle
just a single CU.  This patch parameterizes this, and updates the one
user.
2022-04-12 09:31:16 -06:00
Tom Tromey
c0892a1d5d Refactor build_type_psymtabs_reader
The new DWARF scanner needs to save the entire cutu_reader object, not
just parts of it.  In order to make this possible, this patch
refactors build_type_psymtabs_reader.  This change is done separately
because it is easy to review in isolation and it helps make the later
patches smaller.
2022-04-12 09:31:16 -06:00
Tom Tromey
4e9e4fcda5 Add new overload of dwarf5_djb_hash
This adds a new overload of dwarf5_djb_hash.  This is used in
subsequent patches.
2022-04-12 09:31:16 -06:00
Tom Tromey
b2bc564fe8 Add name splitting
The new DWARF index code works by keeping names pre-split.  That is,
rather than storing a symbol name like "a:🅱️:c", the names "a", "b",
and "c" will be stored separately.

This patch introduces some helper code to split a full name into its
components.
2022-04-12 09:31:15 -06:00
Tom Tromey
073954a792 Let skip_one_die not skip children
This patch adds an option to skip_one_die that causes it not to skip
child DIEs.  This is needed in the new scanner.
2022-04-12 09:31:15 -06:00
Tom Tromey
5c94f93871 Allow ada_decode not to decode operators
The new DWARF scanner records names as they appear in DWARF.  However,
because Ada is unusual, it also decodes the Ada names to synthesize
package components for them.  In order for this to work out properly,
gdb also needs a mode where ada_decode can be instructed not to decode
Ada operator names.  That is what this patch implements.
2022-04-12 09:31:15 -06:00
Tom Tromey
6ee823fc4e Refactor dwarf2_get_pc_bounds
This changes dwarf2_get_pc_bounds so that it does not directly access
a psymtab or psymtabs_addrmap.  Instead, both the addrmap and the
desired payload are passed as parameters.  This makes it suitable to
be used by the new indexer.
2022-04-12 09:31:15 -06:00
Tom Tromey
cffae852e3 Add dwarf2_per_cu_data::addresses_seen
This adds a new member to dwarf2_per_cu_data that indicates whether
addresses have been seen for this CU.  This is then set by the
.debug_aranges reader.  The idea here is to detect when a CU does not
have address information, so that the new indexer will know to do
extra scanning in that case.
2022-04-12 09:31:15 -06:00
Tom Tromey
1ddd39f58f Fix latent bug in read_addrmap_from_aranges
Tom de Vries found a failure that we tracked down to a latent bug in
read_addrmap_from_aranges (previously create_addrmap_from_aranges).
The bug is that this code can erroneously reject .debug_aranges when
dwz is in use, due to CUs at duplicate offsets.  Because aranges can't
refer to a CU coming from the dwz file, the fix is to simply skip such
CUs in the loop.
2022-04-12 09:31:15 -06:00
Tom Tromey
fe50c292d7 Split create_addrmap_from_aranges
This patch splits create_addrmap_from_aranges into a wrapper function
and a worker function.  The worker function is then used in a later
patch.
2022-04-12 09:31:15 -06:00
Tom Tromey
0981fe1017 Allow thread-pool.h to work without threads
thread-pool.h requires CXX_STD_THREAD in order to even be included.
However, there's no deep reason for this, and during review we found
that one patch in the new DWARF indexer series unconditionally
requires the thread pool.

Because the thread pool already allows a task to be run in the calling
thread (for example if it is configured to have no threads in the
pool), it seemed straightforward to make this code ok to use when host
threads aren't available at all.

This patch implements this idea.  I built it on a thread-less host
(mingw, before my recent configure patch) and verified that the result
builds.

After the thread-pool change, parallel-for.h no longer needs any
CXX_STD_THREAD checks at all, so this patch removes these as well.
2022-04-12 09:31:15 -06:00
Tom de Vries
63e0ee15a3 [gdb/testsuite] Fix gdb.base/stap-probe.exp with read1
When running test-case gdb.base/stap-probe.exp with make target check-read1, I
run into this and similar:
...
FAIL: gdb.base/stap-probe.exp: without semaphore, not optimized: \
  info probes stap (timeout)
...

Fix this by using gdb_test_lines instead of gdb_test.

Tested on x86_64-linux.
2022-04-12 16:36:31 +02:00
Tom Tromey
ce70f11ffe Add C++ "save gdb-index" test
I found a bug in the new DWARF reader series, related to the handling
of enumerator names.  This bug caused a crash, so this patch adds a
regression test for this particular case.  I'm checking this in.
2022-04-12 08:05:39 -06:00
Tom Tromey
dc262faf37 Remove "Ada Settings" node from the manual
A while back, I sent a patch to unify the Ada varsize-limit setting
with the more generic max-value-size:

https://sourceware.org/pipermail/gdb-patches/2021-September/182004.html

However, it turns out I somehow neglected to send part of the patch.
Internally, I also removed the "Ada Settings" node from the manual, as
it only documents the obsolete setting.

This patch removes this text.
2022-04-12 06:55:21 -06:00
Tom Tromey
44a29af963 Require GNAT debug info for some Ada tests
A few Ada tests require some debug info in the GNAT runtime.  When run
without this info, these tests can't pass.  This patch changes these
tests to detect this situation and stop with "untested".
2022-04-12 06:38:01 -06:00
John Baldwin
aa1402a95d i386-fbsd-nat: Remove two unused variables.
Earlier versions of the change in
1285ce8629 used this variable, but not
the final version that landed.
2022-04-11 11:01:43 -07:00
Simon Marchi
e165fcef1e gdb: remove MSYMBOL_TARGET_FLAG_{1,2} macros
Replace with equivalent getter/setter macros.

Change-Id: I1042564dd47347337374762bd64ec31b5c573ee2
2022-04-11 10:47:54 -04:00
Simon Marchi
5bbfd12dda gdb: remove minimal symbol size macros
Remove MSYMBOL_HAS_SIZE, MSYMBOL_SIZE and SET_MSYMBOL_SIZE, replace them
with equivalent methods.

Change-Id: I6ee1cf82df37e58dff52ea6568ceb4649c7d7538
2022-04-11 10:46:52 -04:00
Simon Marchi
60f62e2b83 gdb: remove MSYMBOL_TYPE macro
Add a getter and a setter for a minimal symbol's type.  Remove the
corresponding macro and adjust all callers.

Change-Id: I89900df5ffa5687133fe1a16b2e0d4684e67a77d
2022-04-11 10:46:07 -04:00
Simon Marchi
4aeddc50d7 gdb: remove symbol value macros
Remove all macros related to getting and setting some symbol value:

    #define SYMBOL_VALUE(symbol)           (symbol)->value.ivalue
    #define SYMBOL_VALUE_ADDRESS(symbol)                         \
    #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value)    \
    #define SYMBOL_VALUE_BYTES(symbol)     (symbol)->value.bytes
    #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
    #define SYMBOL_BLOCK_VALUE(symbol)     (symbol)->value.block
    #define SYMBOL_VALUE_CHAIN(symbol)     (symbol)->value.chain
    #define MSYMBOL_VALUE(symbol)          (symbol)->value.ivalue
    #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0)
    #define MSYMBOL_VALUE_ADDRESS(objfile, symbol)                         \
    #define BMSYMBOL_VALUE_ADDRESS(symbol) \
    #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value)   \
    #define MSYMBOL_VALUE_BYTES(symbol)    (symbol)->value.bytes
    #define MSYMBOL_BLOCK_VALUE(symbol)    (symbol)->value.block

Replace them with equivalent methods on the appropriate objects.

Change-Id: Iafdab3b8eefc6dc2fd895aa955bf64fafc59ed50
2022-04-11 10:45:36 -04:00
Nils-Christian Kempke
96d368d104 gdb/doc: add section about Fortran intrinsic functions and types
The earlier version of this document had no sections about the
available Fortran intrinsic functions or the Fortran builtin types.

I added two sections 'Fortran intrinsics' and 'Fortran types' to
document the available Fortran language features.  The subsection
'Fortran Defaults' has been integrated into the Fortran subsection.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
27e8f72f35 gdb/fortran/testsuite: add complex from integers test
When working on the files I noted that there was no actual test for a
COMPLEX built from two INTEGERS.  I added that now for completion.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
891e4190ba gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND.  This
parameter determines the kind of the associated return value.  So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.

This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.

It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.

After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate.  E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function.  This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
04ba653650 gdb/fortran: rename f77_keywords to f_keywords
Rename f77_keywords to f_keywords since some of the introduced keywords
in the array are f90 only.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
87abd9825d gdb/fortran: Change GDB print for fortran default types
Currently, when asking GDB to print the type of a Fortran default type
such as INTEGER or REAL, GDB will return the default name of that type,
e.g. "integer"/"real":

   (gdb) ptype integer
   type = integer
   (gdb) ptype real
   type = real

For LOGICAL and COMPLEX it would return the actual underlying types

   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex
   type = complex*4

Similarly, GDB would print the default integer type for the underlying
default type:

   (gdb) ptype integer*4
   type = integer
   (gdb) ptype real*4
   type = real
   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex*4
   type = complex*4

This is inconsistent and a bit confusing.  Both options somehow indicate
what the internal underlying type for the default type is - but I think
the logical/complex version is a bit clearer.

Consider again:

   (gdb) ptype integer
   type = integer

This indicates to a user that the type of "integer" is Fortran's default
integer type.  Without examining "ptype integer*4" I would expect, that
any variable declared integer in the actual code would also fit into a
GDB integer.  But, since we cannot adapt out internal types to the
compiler flags used at compile time of a debugged binary, this might be
wrong.  Consider debugging Fortran code compiled with GNU and e.g. the
"-fdefault-integer-8" flag.  In this case the gfortran default integer
would be integer*8 while GDB internally still would use a builtin_integer,
so an integer of the size of an integer*4 type.  On the other hand having
GDB print

   (gdb) ptype integer
   type = integer*4

makes this clearer.  I would still be tempted to fit a variable declared
integer in the code into a GDB integer - but at least ptype would
directly tell me what is going on.  Note, that when debugging a binary
compiled with "-fdefault-integer-8" a user will always see the actual
underlying type of any variable declared "integer" in the Fortran code.
So having the code

   program test
     integer :: a = 5
     print *, a ! breakpt
   end program test

will, when breaking at breakpt print

   (gdb) ptype var
   type = integer(kind=4)

or

   (gdb) ptype var
   type = integer(kind=8)

depending on the compiler flag.

This patch changes the outputs for the REAL and INTEGER default types to
actually print the internally used type over the default type name.

The new behavior for the above examples is:

   (gdb) ptype integer
   type = integer*4
   (gdb) ptype integer*4
   type = integer*4

Existing testcases have been adapted to reflect the new behavior.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
adc29023a7 gdb/fortran: clean-up Fortran intrinsic types
The currently implemented intrinsic type handling for Fortran missed some
tokens and their parsing.  While still not all Fortran type kinds are
implemented this patch at least makes the currently handled types
consistent.  As an example for what this patch does, consider the
intrinsic type INTEGER.  GDB implemented the handling of the
keywords "integer" and "integer_2" but missed "integer_4" and "integer_8"
even though their corresponding internal types were already available as
the Fortran builtin types builtin_integer and builtin_integer_s8.
Similar problems applied to LOGICAL, REAL, and COMPLEX.  This patch adds
all missing tokens and their parsing.  Whenever a section containing the
type handling was touched, it also was reordered to be in a more easy to
grasp order.  All INTEGER/REAL/LOGICAL/COMPLEX types were grouped
together and ordered ascending in their size making a missing one more
easy to spot.

Before this change GDB would print the following when tyring to use the
INTEGER keywords:

   (gdb) set language fortran
   (gdb) ptype integer*1
   unsupported kind 1 for type integer
   (gdb) ptype integer_1
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer
   (gdb) ptype integer_4
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer
   type = integer

With this patch all keywords are available and the GDB prints:

   (gdb) set language fortran
   (gdb) ptype integer*1
   type = integer*1
   (gdb) ptype integer_1
   type = integer*1
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer*4
   (gdb) ptype integer_4
   type = integer*4
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   type = integer*8
   (gdb) ptype integer
   type = integer

The described changes have been applied to INTEGER, REAL, COMPLEX,
and LOGICAL. Existing testcases have been adapted to reflect the
new behavior.  Tests for formerly missing types have been added.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
4ec8aa9e94 gdb/fortran: change default logical type to builtin_logical
According to the Fortran standard, logical is of the size of a
'single numeric storage unit' (just like real and integer). For
gfortran, flang and ifx/ifort this storage unit (or the default
logical type) is of size kind 4, actually occupying 4 bytes of
storage, and so the default type for logical expressions in
Fortran should probably also be Logical*4 and not Logical*2.  I
adapted GDB's behavior to be in line with
gfortran/ifort/ifx/flang.
2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
ed9ec61174 gdb/fortran: reformat build_fortran_types in f-lang.c
Add a few newlines after the type definitions and remove some
unnecessary linebreaks.
2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
4e436fdabe gdb/fortran: fix complex type in Fortran builtin types
Before this patch things like

  (gdb) ptype complex*8
  complex*16
  (gdb) ptype complex*4
  complex*8

were possible in GDB, which seems confusing for a user.  The reason
is a mixup in the implementation of the Fortran COMPLEX type.  In
Fortran the "*X" after a type would normally (I don't think this
is language required) specify the type's size in memory.  For the
COMPLEX type the kind parameters usually (at least for GNU, Intel, Flang)
specify not the size of the whole type but the size of the individual
two REALs used to form the COMPLEX.  Thus, a COMPLEX*4 will usually
consist of two REAL*4s.  Internally this type was represented by a
builtin_complex_s8 - but here I think the s8 actually meant the raw
size of the type.  This is confusing and I renamed the types (e.g.
builting_complex_s8 became builtin_complex_s4 according to its most
common useage) and their printed names to their language equivalent.
Additionally, I added the default COMPLEX type "COMPLEX" being the same
as a COMPLEX*4 (as is normally the case) and removed the latter.  I added
a few tests for this new behavior as well.

The new behavior is

  (gdb) ptype complex*8
  complex*8
  (gdb) ptype complex*4
  complex*4
2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
c08ec64081 gdb/f-lang: remove hidden ^L characters 2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
d4c948427d gdb/f-lang: add Integer*1 to Fortran builtin types
Add builtin_integer_s1 of size TARGET_CHAR_BIT to Fortran builtin types.
2022-04-11 14:06:55 +02:00
Tom de Vries
04f4c17c7a [gdb/testsuite] Fix gdb.base/annota1.exp with pie
Since commit 359efc2d89 ("[gdb/testsuite] Make gdb.base/annota1.exp more
robust") we see this fail with target board unix/-fPIE/-pie:
...
FAIL: gdb.base/annota1.exp: run until main breakpoint (timeout)
...

The problem is that the commit makes the number and order of matched
annotations fixed, while between target boards unix and unix/-fPIE/-pie there
is a difference:
...
 \032\032post-prompt
 Starting program: outputs/gdb.base/annota1/annota1

+\032\032breakpoints-invalid
+
 \032\032starting

 \032\032frames-invalid
...

Fix this by optionally matching the additional annotation.

Tested on x86_64-linux.
2022-04-11 10:28:41 +02:00
Tom de Vries
e7be729233 [gdb/testsuite] Fix gdb.dwarf2/dw2-lines.exp for m32 pie
As reported in PR29043, when running test-case gdb.dwarf2/dw2-lines.exp with
target board unix/-m32/-fPIE/-pie, we run into:
...
Breakpoint 2, 0x56555540 in bar ()^M
(gdb) PASS: gdb.dwarf2/dw2-lines.exp: cv=2: cdw=32: lv=2: ldw=32: \
  continue to breakpoint: foo \(1\)
next^M
Single stepping until exit from function bar,^M
which has no line number information.^M
0x56555587 in main ()^M
(gdb) FAIL: gdb.dwarf2/dw2-lines.exp: cv=2: cdw=32: lv=2: ldw=32: \
  next to foo (2)
...

The problem is that the bar breakpoint ends up at an unexpected location
because:
- the synthetic debug info is incomplete and doesn't provide line info
  for the prologue part of the function, so consequently gdb uses the i386
  port prologue skipper to get past the prologue
- the i386 port prologue skipper doesn't get past a get_pc_thunk call.

Work around this in the test-case by breaking on bar_label instead.

Tested on x86_64-linux with target boards unix, unix/-m32, unix/-fPIE/-pie and
unix/-m32/-fPIE/-pie.
2022-04-11 10:17:31 +02:00
Tom Tromey
bd1c798f0a Remove MSYMBOL_VALUE_CHAIN
I noticed that MSYMBOL_VALUE_CHAIN is unused, so this patch removes it.
2022-04-09 08:33:11 -06:00
Pedro Alves
6849c6a2b8 gdb: Avoid undefined shifts, fix Go shifts
I noticed that a build of GDB with GCC + --enable-ubsan, testing
against GDBserver showed this GDB crash:

  (gdb) PASS: gdb.trace/trace-condition.exp: trace: 0x00abababcdcdcdcd << 46 == 0x7373400000000000: advance to trace begin
  tstart
  ../../src/gdb/valarith.c:1365:15: runtime error: left shift of 48320975398096333 by 46 places cannot be represented in type 'long int'
  ERROR: GDB process no longer exists
  GDB process exited with wait status 269549 exp9 0 1
  UNRESOLVED: gdb.trace/trace-condition.exp: trace: 0x00abababcdcdcdcd << 46 == 0x7373400000000000: start trace experiment

The problem is that, "0x00abababcdcdcdcd << 46" is an undefined signed
left shift, because the result is not representable in the type of the
lhs, which is signed.  This actually became defined in C++20, and if
you compile with "g++ -std=c++20 -Wall", you'll see that GCC no longer
warns about it, while it warns if you specify prior language versions.

While at it, there are a couple other situations that are undefined
(and are still undefined in C++20) and result in GDB dying: shifting
by a negative ammount, or by >= than the bit size of the promoted lhs.
For the latter, GDB shifts using (U)LONGEST internally, so you have to
shift by >= 64 bits to see it:

 $ gdb --batch -q -ex "p 1 << -1"
 ../../src/gdb/valarith.c:1365:15: runtime error: shift exponent -1 is negative
 $ # gdb exited

 $ gdb --batch -q -ex "p 1 << 64"
 ../../src/gdb/valarith.c:1365:15: runtime error: shift exponent 64 is too large for 64-bit type 'long int'
 $ # gdb exited

Also, right shifting a negative value is implementation-defined
(before C++20, after which it is defined).  For this, I chose to
change nothing in GDB other than adding tests, as I don't really know
whether we need to do anything.  AFAIK, most implementations do an
arithmetic right shift, and it may be we don't support any host or
target that behaves differently.  Plus, this becomes defined in C++20
exactly as arithmetic right shift.

Compilers don't error out on such shifts, at best they warn, so I
think GDB should just continue doing the shifts anyhow too.

Thus:

- Adjust scalar_binop to avoid the undefined paths, either by adding
  explicit result paths, or by casting the lhs of the left shift to
  unsigned, as appropriate.

  For the shifts by a too-large count, I made the result be what you'd
  get if you split the large count in a series of smaller shifts.
  Thus:

     Left shift, positive or negative lhs:

       V << 64
	 =>  V << 16 << 16 << 16 << 16
	   => 0

     Right shift, positive lhs:

       Vpos >> 64
	 =>  Vpos >> 16 >> 16 >> 16 >> 16
	   => 0

     Right shift, negative lhs:

       Vneg >> 64
	 =>  Vneg >> 16 >> 16 >> 16 >> 16
	   => -1

  This is actually Go's semantics (the compiler really emits
  instructions to make it so that you get 0 or -1 if you have a
  too-large shift).  So for that language GDB does the shift and
  nothing else.  For other C-like languages where such a shift is
  undefined, GDB warns in addition to performing the shift.

  For shift by a negative count, for Go, this is a hard error.  For
  other languages, since their compilers only warn, I made GDB warn
  too.  The semantics I chose (we're free to pick them since this is
  undefined behavior) is as-if you had shifted by the count cast to
  unsigned, thus as if you had shifted by a too-large count, thus the
  same as the previous scenario illustrated above.

  Examples:

    (gdb) set language go
    (gdb) p 1 << 100
    $1 = 0
    (gdb) p -1 << 100
    $2 = 0
    (gdb) p 1 >> 100
    $3 = 0
    (gdb) p -1 >> 100
    $4 = -1
    (gdb) p -2 >> 100
    $5 = -1
    (gdb) p 1 << -1
    left shift count is negative

    (gdb) set language c
    (gdb) p -2 >> 100
    warning: right shift count >= width of type
    $6 = -1
    (gdb) p -2 << 100
    warning: left shift count >= width of type
    $7 = 0
    (gdb) p 1 << -1
    warning: left shift count is negative
    $8 = 0
    (gdb) p -1 >> -1
    warning: right shift count is negative
    $9 = -1

- The warnings' texts are the same as what GCC prints.

- Add comprehensive tests in a new gdb.base/bitshift.exp testcase, so
  that we exercise all these scenarios.

Change-Id: I8bcd5fa02de3114b7ababc03e65702d86ec8d45d
2022-04-08 16:19:15 +01:00
Pedro Alves
01772c548b Fix undefined behavior in the Fortran, Go and Pascal number parsers
This commit ports these two fixes to the C parser:

  commit ebf13736b4
  CommitDate: Thu Sep 4 21:46:28 2014 +0100

      parse_number("0") reads uninitialized memory

  commit 20562150d8
  CommitDate: Wed Oct 3 15:19:06 2018 -0600

      Avoid undefined behavior in parse_number

... to the Fortran, Go, and Fortran number parsers, fixing the same
problems there.

Also add a new testcase that exercises printing 0xffffffffffffffff
(max 64-bit) in all languages, which crashes a GDB built with UBsan
without the fix.

I moved get_set_option_choices out of all-architectures.exp.tcl to
common code to be able to extract all the supported languages.  I did
a tweak to it to generalize it a bit -- you now have to pass down the
"set" part of the command as well.  This is so that the proc can be
used with "maintenance set" commands as well in future.

Change-Id: I8e8f2fdc1e8407f63d923c26fd55d98148b9e16a
2022-04-08 16:19:15 +01:00
Simon Marchi
0c80fce42a gdb/testsuite: use nopie in gdb.dwarf2/dw2-inline-param.exp
I see this failure:

    (gdb) run ^M
    Starting program: /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-inline-param/dw2-inline-param ^M
    Warning:^M
    Cannot insert breakpoint 1.^M
    Cannot access memory at address 0x113b^M
    ^M
    (gdb) FAIL: gdb.dwarf2/dw2-inline-param.exp: runto: run to *0x113b

The test loads the binary in GDB, grabs the address of a symbol, strips
the binary, reloads it in GDB, runs the program, and then tries to place
a breakpoint at that address.  The problem is that the binary is built
as position independent, so the address GDB grabs in the first place
isn't where the code ends up after running.

Fix this by linking the binary as non-position-independent.  The
alternative would be to compute the relocated address where to place the
breakpoint, but that's not very straightforward, unfortunately.

I was confused for a while, I was trying to load the binary in GDB
manually to get the symbol address, but GDB was telling me the symbol
could not be found.  Meanwhile, it clearly worked in gdb.log.  The thing
is that GDB strips the binary in-place, so we don't have access to the
intermediary binary with symbols.  Change the test to output the
stripped binary to a separate file instead.

Change-Id: I66c56293df71b1ff49cf748d6784bd0e935211ba
2022-04-08 09:55:29 -04:00
Bernhard Heckel
110aae55a8 gdb/fortran: print fortran extended types with ptype
Add the print of the base-class of an extended type to the output of
ptype.  This requires the Fortran compiler to emit DW_AT_inheritance
for the extended type.

Co-authored-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
2022-04-08 12:17:13 +02:00
Bernhard Heckel
87e10e9c28 gdb/fortran: add support for accessing fields of extended types
Fortran 2003 supports type extension.  This patch allows access
to inherited members by using their fully qualified name as described
in the Fortran standard.

In doing so the patch also fixes a bug in GDB when trying to access the
members of a base class in a derived class via the derived class' base
class member.

This patch fixes PR22497 and PR26373 on GDB side.

Using the example Fortran program from PR22497

program mvce
  implicit none

  type :: my_type
     integer :: my_int
  end type my_type

  type, extends(my_type) :: extended_type
  end type extended_type

  type(my_type) :: foo
  type(extended_type) :: bar

  foo%my_int = 0
  bar%my_int = 1

  print*, foo, bar

end program mvce

and running this with GDB and setting a BP at 17:

Before:
(gdb) p bar%my_type
A syntax error in expression, near `my_type'.
(gdb) p bar%my_int
There is no member named my_int.
(gdb) p bar%my_type%my_int
A syntax error in expression, near `my_type%my_int'.
(gdb) p bar
$1 = ( my_type = ( my_int = 1 ) )

After:
(gdb) p bar%my_type
$1 = ( my_int = 1 )
(gdb) p bar%my_int
$2 = 1                 # this line requires DW_TAG_inheritance to work
(gdb) p bar%my_type%my_int
$3 = 1
(gdb) p bar
$4 = ( my_type = ( my_int = 1 ) )

In the above example "p bar%my_int" requires the compiler to emit
information about the inheritance relationship between extended_type
and my_type which gfortran and flang currently do not de.  The
respective issue gcc/49475 has been put as kfail.

Co-authored-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26373
     https://sourceware.org/bugzilla/show_bug.cgi?id=22497
2022-04-08 12:17:13 +02:00
Nils-Christian Kempke
916c9be4a3 gdb: add Nils-Christian Kempke to gdb/MAINTAINERS
Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
2022-04-08 12:03:45 +02:00
Simon Marchi
d3a76a5583 gdb: change file_file_name to return an std::string
Straightforward change, return an std::string instead of a
gdb::unique_xmalloc_ptr<char>.  No behavior change expected.

Change-Id: Ia5e94c94221c35f978bb1b7bdffbff7209e0520e
2022-04-07 20:31:31 -04:00
Andrew Burgess
3fb842cea1 gdb/fortran: fix fetching assumed rank array content
Commit:

  commit df7a7bdd97
  Date:   Thu Mar 17 18:56:23 2022 +0000

      gdb: add support for Fortran's ASSUMED RANK arrays

Added support for Fortran assumed rank arrays.  Unfortunately, this
commit contained a bug that means though GDB can correctly calculate
the rank of an assumed rank array, GDB can't fetch the contents of an
assumed rank array.

The history of this patch can be seen on the mailing list here:

  https://sourceware.org/pipermail/gdb-patches/2022-January/185306.html

The patches that were finally committed can be found here:

  https://sourceware.org/pipermail/gdb-patches/2022-March/186906.html

The original patches did support fetching the array contents, it was
only the later series that introduced the regression.

The problem is that when calculating the array rank the result is a
count of the number of ranks, i.e. this is a 1 based result, 1, 2, 3,
etc.

In contrast, when computing the details of any particular rank the
value passed to the DWARF expression evaluator should be a 0 based
rank offset, i.e. a 0 based number, 0, 1, 2, etc.

In the patches that were originally merged, this was not the case, and
we were passing the 1 based rank number to the expression evaluator,
e.g. passing 1 when we should pass 0, 2 when we should pass 1, etc.
As a result the DWARF expression evaluator was reading the
wrong (undefined) memory, and returning garbage results.

In this commit I have extended the test case to cover checking the
array contents, I've then ensured we make use of the correct rank
value, and extended some comments, and added or adjusted some asserts
as appropriate.
2022-04-07 21:12:13 +01:00
Simon Marchi
9be5d742db gdb/testsuite: add "macros" option to gdb_compile
Make gdb_compile handle a new "macros" option, which makes it pass the
appropriate flag to make the compiler include macro information in the
debug info.  This will help simplify tests using macros, reduce
redundant code, and make it easier to add support for a new compiler.

Right now it only handles clang specially (using -fdebug-macro) and
falls back to -g3 otherwise (which works for gcc).  Other compilers can
be added as needed.

There are some tests that are currently skipped if the compiler is nor
gcc nor clang.  After this patch, the tests will attempt to run (the -g3
fall back will be used).  That gives a chance to people using other
compilers to notice something is wrong and maybe add support for their
compiler.  If it is needed to support a compiler that doesn't have a way
to include macro information, then we can always introduce a
"skip_macro_tests" that can be used to skip over them.

Change-Id: I50cd6ab1bfbb478c1005486408e214b551364c9b
2022-04-07 14:41:28 -04:00
Simon Marchi
4f7df13ee7 gdb: remove subfile::buildsym_compunit field
It is only set, never used.

Change-Id: Ia46ed2f9da243b0ccfc4588c1b57be2a0f3939de
2022-04-07 14:08:45 -04:00
Tom de Vries
359efc2d89 [gdb/testsuite] Make gdb.base/annota1.exp more robust
On openSUSE Tumbleweed I run into:
...
FAIL: gdb.base/annota1.exp: run until main breakpoint (timeout)
...

The problem is that the libthread_db message occurs at a location where it's
not expected:
...
Starting program: outputs/gdb.base/annota1/annota1 ^M
^M
^Z^Zstarting^M
^M
^Z^Zframes-invalid^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
^M
^Z^Zbreakpoints-invalid^M
^M
...

Fix this by making the matching more robust:
- rewrite the regexp such that each annotation is on a single line,
  starting with \r\n\032\032 and ending with \r\n
- add a regexp variable optional_re, that matches all possible optional
  output, and use it as a separator in the first part of the regexp

Tested on x86_64-linux.
2022-04-07 19:25:26 +02:00
Simon Marchi
d4c4a2298c gdb/testsuite/dwarf: simplify line number program syntax
By calling `uplevel $body` in the program proc (a pattern we use at many
places), we can get rid of curly braces around each line number program
directive.  That seems like a nice small improvement to me.

Change-Id: Ib327edcbffbd4c23a08614adee56c12ea25ebc0b
2022-04-07 13:09:45 -04:00
Simon Marchi
ae58413816 gdb/testsuite/dwarf: remove two unused variables
These variables seem to be unused, remove them.

Change-Id: I7d613d9d35735930ee78b2c348943c73a702afbb
2022-04-07 13:09:38 -04:00
Simon Marchi
7678d1304a gdb: remove symtab::pspace
Same idea as previous patch, but for symtab::pspace.

Change-Id: I1023abe622bea75ef648c6a97a01b53775d4104d
2022-04-07 13:05:29 -04:00
Simon Marchi
3c86fae3d9 gdb: remove symtab::objfile
Same idea as previous patch, but for symtab::objfile.  I find
it clearer without this wrapper, as it shows that the objfile is
common to all symtabs of a given compunit.  Otherwise, you could think
that each symtab (of a given compunit) can have a specific objfile.

Change-Id: Ifc0dbc7ec31a06eefa2787c921196949d5a6fcc6
2022-04-07 13:05:22 -04:00
Simon Marchi
44281e6c08 gdb: remove symtab::blockvector
symtab::blockvector is a wrapper around compunit_symtab::blockvector.
It is a bit misleadnig, as it gives the impression that a symtab has a
blockvector.  Remove it, change all users to fetch the blockvector
through the compunit instead.

Change-Id: Ibd062cd7926112a60d52899dff9224591cbdeebf
2022-04-07 13:04:53 -04:00