Commit Graph

109916 Commits

Author SHA1 Message Date
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
Tiezhu Yang
11d7dd3357 gdb: fix build errors in gdbsupport/thread-pool.h used with old gcc
When I build gdb with gcc 8.3, there exist the following build errors,
rename the typedef to task_t to fix them.

  CXX      thread-pool.o
In file included from /home/loongson/gdb.git/gdbsupport/thread-pool.cc:21:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<void> gdb::thread_pool::post_task(std::function<void()>&&)’:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:69:44: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
     std::packaged_task<void ()> task (std::move (func));
                                            ^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
   typedef std::packaged_task<void ()> task;
                                       ^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<_Res> gdb::thread_pool::post_task(std::function<T()>&&)’:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:80:41: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
     std::packaged_task<T ()> task (std::move (func));
                                         ^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
   typedef std::packaged_task<void ()> task;
                                       ^~~~

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-04-14 23:05:00 +08: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
Sergei Trofimovich
c641fe0dcb M68K: avoid quadratic slowdlow in label alignment check
Before the change tc-m68k maintained a list of seen labels.
Alignment check traversed label list to resolve symbol to label.
This caused quadratic slowdown as each symbol was checked against
each label. Worst affected files are the ones built with debugging
enabled as DWARF generates many labels.

The change embeds auxiliary label information right into symbol using
TC_SYMFIELD_TYPE.

Before the change test from PR 29058 did not finish in 10 minutes. After
the change it finishes in 2 seconds.

gas/ChangeLog:

	PR 29058
	* config/tc-m68k.h (TC_SYMFIELD_TYPE): define as m68k_tc_sy.
	* config/tc-m68k.c (m68k_frob_label): Use TC_SYMFIELD_TYPE to
	store label information.
2022-04-14 11:26:38 +01:00
caiyinyu
e6f601b74d ld:LoongArch: Fix glibc fail: tst-audit25a/b.
bfd/

  * elfnn-loongarch.c: Add new func elf_loongarch64_hash_symbol.
2022-04-14 09:13:39 +08:00
GDB Administrator
a9703116de Automatic date update in version.in 2022-04-14 00:00:20 +00: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
Alexander von Gluck IV
f5e7605006 binutils: enable PE on 32bit haiku build
* config.bfd (x86-haiku): Add i386_pei_vec as a selectable format.
2022-04-13 14:58:22 +01:00
Pedro Alves
50b032ebc0 Make intrusive_list_node's next/prev private
Tromey noticed that intrusive_list_node leaves its data members
public, which seems sub-optimal.

This commit makes intrusive_list_node's data fields private.
intrusive_list_iterator, intrusive_list_reverse_iterator, and
intrusive_list do need to access the fields, so they are made friends.

Change-Id: Ia8b306b40344cc218d423c8dfb8355207a612ac5
2022-04-13 10:24:38 +01: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
Alan Modra
10c0005660 ubsan: member access within null pointer of union
Add some nonsense to cover "undefined behaviour".

	* ldlang.c (section_for_dot): Avoid UB.
2022-04-13 10:07:21 +09:30
GDB Administrator
1b35e577c3 Automatic date update in version.in 2022-04-13 00:00:10 +00: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
Simon Marchi
a09520cdd9 gdbsupport: use result_of_t instead of result_of in parallel-for.h
When building with -std=c++11, I get:

In file included from /home/smarchi/src/binutils-gdb/gdb/unittests/parallel-for-selftests.c:22:                                                                             /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/parallel-for.h:134:10: error: ‘result_of_t’ is not a member of ‘std’; did you mean ‘result_of’?
  134 |     std::result_of_t<RangeFunction (RandomIt, RandomIt)>
      |          ^~~~~~~~~~~
      |          result_of

This is because result_of_t has been introduced in C++14.  Use the
equivalent result_of<...>::type instead.

result_of and result_of_t have been removed in C++20 though, so I think
we'll need some patches eventually to make the code use invoke_result
instead, depending on the C++ version.

Change-Id: I4817f361c0ebcdd4b32976898fc368bb302b61b9
2022-04-12 14:09:49 -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
85098eeb4c Specialize std::hash for gdb_exception
This adds a std::hash specialization for gdb_exception.  This lets us
store these objects in a hash table, which is used later in this
series to de-duplicate the exception output from multiple threads.
2022-04-12 09:31:16 -06:00