binutils-gdb.git
2 years agogdbserver: special case target_write_memory len==0
Pedro Alves [Thu, 31 Mar 2022 21:04:42 +0000 (22:04 +0100)]
gdbserver: special case target_write_memory len==0

The next patch in this series adds a common helper routine for both
memory reads and writes, like this:

 static int
 proc_xfer_memory (CORE_ADDR memaddr, unsigned char *readbuf,
  const gdb_byte *writebuf, int len)
 {
   gdb_assert ((readbuf == nullptr) != (writebuf == nullptr));
   ...
 }

 int
 linux_process_target::read_memory (CORE_ADDR memaddr,
                                    unsigned char *myaddr, int len)
 {
   return proc_xfer_memory (memaddr, myaddr, nullptr, len);
 }

 linux_process_target::write_memory (CORE_ADDR memaddr,
                                    const unsigned char *myaddr, int len)
 {
   return proc_xfer_memory (memaddr, nullptr, myaddr, len);
 }

Surprisingly, the assertion fails.  That happens because it can happen
that target_write_memory is called with LEN==0, due to this in
gdb/remote.c:

 /* Determine whether the remote target supports binary downloading.
    This is accomplished by sending a no-op memory write of zero length
    to the target at the specified address. (...) */

 void
 remote_target::check_binary_download (CORE_ADDR addr)
 {
 ...
       p = rs->buf.data ();
       *p++ = 'X';
       p += hexnumstr (p, (ULONGEST) addr);
       *p++ = ',';
       p += hexnumstr (p, (ULONGEST) 0);
       *p++ = ':';
       *p = '\0';

In this scenario, in gdbserver's target_write_memory, the "myaddr"
argument of the_target->write_memory is passed the data() of a local
gdb::byte_vector (which is a specialized std::vector).  It's valid for
std::vector::data() to return NULL when the vector is empty.

This commit adds an early return to target_write_memory to avoid
target backends having to care about this.  For good measure, do the
same on the read side, in read_inferior_memory.

Change-Id: Iac8f04fcf99014c624ef4036bd318ca1771ad491

2 years agogdbserver/qXfer::threads, prepare_to_access_memory=>target_pause_all
Pedro Alves [Tue, 29 Mar 2022 11:57:17 +0000 (12:57 +0100)]
gdbserver/qXfer::threads, prepare_to_access_memory=>target_pause_all

handle_qxfer_threads_proper needs to pause all threads even if the
target can read memory when threads are running, so use
target_pause_all instead, which is what the Linux implementation of
prepare_to_access_memory uses.  (Only Linux implements this hook.)

A following patch will make the Linux backend be able to access memory
when threads are running, and thus will also make
prepare_to_access_memory do nothing, which would cause testsuite
regressions without this change.

Change-Id: I127fec7246b7c45b60dfa7341e781606bf54b5da

2 years agoIgnore 0,0 entries in .debug_aranges
Tom Tromey [Thu, 14 Apr 2022 15:36:09 +0000 (09:36 -0600)]
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.

2 years agoUse GetThreadDescription on Windows
Tom Tromey [Wed, 13 Apr 2022 14:45:34 +0000 (08:45 -0600)]
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

2 years agoSet the worker thread name on Windows
Tom Tromey [Wed, 13 Apr 2022 14:12:52 +0000 (08:12 -0600)]
Set the worker thread name on Windows

This patch is a bit different from the rest of the series, in that it
is a change to gdb's behavior on the host.  It changes gdb's thread
pool to try to set the thread name on Windows, if SetThreadDescription
is available.

This is part of PR win32/29050.

This patch isn't likely to be useful to many people in the short term,
because the Windows port of the libstdc++ thread code is not upstream.
(AdaCore uses it, and sent it upstream, but it did not land, I don't
know why.)  However, if that patch does ever go in, or presumably if
you build using some other C++ runtime library, then this will be
useful.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29050

2 years agoImplement thread_name for gdbserver
Tom Tromey [Tue, 12 Apr 2022 20:27:13 +0000 (14:27 -0600)]
Implement thread_name for gdbserver

This changes gdbserver to implement thread_name method.

2 years agoShare handle_ms_vc_exception with gdbserver
Tom Tromey [Tue, 12 Apr 2022 20:25:44 +0000 (14:25 -0600)]
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.

2 years agoMove target_read_string to target/target.c
Tom Tromey [Wed, 13 Apr 2022 12:42:19 +0000 (06:42 -0600)]
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.

2 years agoRemove the byte order parameter to target_read_string
Tom Tromey [Wed, 13 Apr 2022 12:32:28 +0000 (06:32 -0600)]
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.

2 years agoRename read_string
Tom Tromey [Wed, 13 Apr 2022 12:25:07 +0000 (06:25 -0600)]
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.

2 years agoDon't call QUIT in read_string
Tom Tromey [Tue, 12 Apr 2022 20:40:16 +0000 (14:40 -0600)]
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.

2 years agoFix possible Cygwin build problem
Tom Tromey [Wed, 13 Apr 2022 12:55:30 +0000 (06:55 -0600)]
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.

2 years agogdb/testsuite: Fix race in gdb.dwarf2/calling-convention.exp
Lancelot SIX [Thu, 14 Apr 2022 17:21:04 +0000 (18:21 +0100)]
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

2 years agoSilence -Wmaybe-uninitialized warning from target_waitstatus
Tom Tromey [Thu, 7 Apr 2022 16:17:02 +0000 (10:17 -0600)]
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.

2 years agoFix regression on Windows with WOW64
Tom Tromey [Thu, 31 Mar 2022 13:55:09 +0000 (07:55 -0600)]
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.

2 years agoReorganize Python events documentation
Tom Tromey [Fri, 25 Feb 2022 18:33:32 +0000 (11:33 -0700)]
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.

2 years agogdb: remove move constructor and move assignment operator from cooked_index
Simon Marchi [Thu, 14 Apr 2022 15:32:34 +0000 (11:32 -0400)]
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

2 years agoLet std::thread check pass even without pthreads
Tom Tromey [Thu, 31 Mar 2022 14:26:12 +0000 (08:26 -0600)]
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.

2 years agogdb: fix build errors in gdbsupport/thread-pool.h used with old gcc
Tiezhu Yang [Thu, 14 Apr 2022 02:37:30 +0000 (10:37 +0800)]
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>
2 years ago[gdb/testsuite] Detect 'No MPX support'
Tom de Vries [Thu, 14 Apr 2022 10:32:51 +0000 (12:32 +0200)]
[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.

2 years agoM68K: avoid quadratic slowdlow in label alignment check
Sergei Trofimovich [Thu, 14 Apr 2022 07:47:00 +0000 (08:47 +0100)]
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.

2 years agold:LoongArch: Fix glibc fail: tst-audit25a/b.
caiyinyu [Mon, 11 Apr 2022 03:19:50 +0000 (11:19 +0800)]
ld:LoongArch: Fix glibc fail: tst-audit25a/b.

  bfd/

  * elfnn-loongarch.c: Add new func elf_loongarch64_hash_symbol.

2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 14 Apr 2022 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb: add ATTRIBUTE_PRINTF to complaint_interceptor::issue_complaint
Simon Marchi [Wed, 13 Apr 2022 15:15:38 +0000 (11:15 -0400)]
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

2 years agogdb: fix clang build failure in msymbol_is_mips
Simon Marchi [Wed, 13 Apr 2022 15:25:08 +0000 (11:25 -0400)]
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 e165fcef1e7 ("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

2 years agobinutils: enable PE on 32bit haiku build
Alexander von Gluck IV [Wed, 13 Apr 2022 13:58:22 +0000 (14:58 +0100)]
binutils: enable PE on 32bit haiku build

* config.bfd (x86-haiku): Add i386_pei_vec as a selectable format.

2 years agoMake intrusive_list_node's next/prev private
Pedro Alves [Fri, 8 Apr 2022 19:03:46 +0000 (20:03 +0100)]
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

2 years agoTidy gdb.base/parse_number.exp
Pedro Alves [Wed, 13 Apr 2022 09:10:28 +0000 (10:10 +0100)]
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

2 years agoubsan: member access within null pointer of union
Alan Modra [Tue, 12 Apr 2022 12:20:09 +0000 (21:50 +0930)]
ubsan: member access within null pointer of union

Add some nonsense to cover "undefined behaviour".

* ldlang.c (section_for_dot): Avoid UB.

2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 13 Apr 2022 00:00:10 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoFix bug in Ada number lexing
Tom Tromey [Fri, 8 Apr 2022 16:11:58 +0000 (10:11 -0600)]
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.

2 years agogdb: fix "passing NULL to memcpy" UBsan error in dwarf2/cooked-index.c
Simon Marchi [Tue, 12 Apr 2022 18:37:24 +0000 (14:37 -0400)]
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

2 years agogdb: change subfile::line_vector to an std::vector
Simon Marchi [Thu, 7 Apr 2022 12:55:16 +0000 (08:55 -0400)]
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

2 years agogdb: use std::vector for temporary linetable_entry array in arrange_linetable
Simon Marchi [Fri, 8 Apr 2022 14:37:07 +0000 (10:37 -0400)]
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

2 years agogdb: change subfile::name and buildsym_compunit::m_comp_dir to strings
Simon Marchi [Fri, 8 Apr 2022 15:04:24 +0000 (11:04 -0400)]
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

2 years agogdb: allocate subfile with new
Simon Marchi [Thu, 7 Apr 2022 12:06:50 +0000 (08:06 -0400)]
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

2 years agogdb: use decltype instead of typeof in dwarf2/read.c
Simon Marchi [Tue, 12 Apr 2022 16:30:09 +0000 (12:30 -0400)]
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

2 years agogdbsupport: use result_of_t instead of result_of in parallel-for.h
Simon Marchi [Tue, 12 Apr 2022 16:30:08 +0000 (12:30 -0400)]
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

2 years agoRemove dwarf2_per_cu_data::v
Tom Tromey [Mon, 23 Aug 2021 22:49:39 +0000 (16:49 -0600)]
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.

2 years agoDelete DWARF psymtab code
Tom Tromey [Sun, 30 May 2021 14:00:19 +0000 (08:00 -0600)]
Delete DWARF psymtab code

This removes the DWARF psymtab reader.

2 years agoEnable the new DWARF indexer
Tom Tromey [Sun, 18 Apr 2021 20:08:54 +0000 (14:08 -0600)]
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.

2 years agoAdapt .debug_names writer to new DWARF scanner
Tom Tromey [Sat, 29 May 2021 21:12:44 +0000 (15:12 -0600)]
Adapt .debug_names writer to new DWARF scanner

This updates the .debug_names writer to work with the new DWARF
scanner.

2 years agoAdapt .gdb_index writer to new DWARF scanner
Tom Tromey [Sat, 29 May 2021 14:57:16 +0000 (08:57 -0600)]
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.

2 years agoGenericize addrmap handling in the DWARF index writer
Tom Tromey [Fri, 28 May 2021 21:52:44 +0000 (15:52 -0600)]
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.

2 years agoChange parameters to write_address_map
Tom Tromey [Thu, 27 May 2021 22:29:52 +0000 (16:29 -0600)]
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.

2 years agoChange the key type in psym_index_map
Tom Tromey [Thu, 27 May 2021 20:59:32 +0000 (14:59 -0600)]
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.

2 years agoRename write_psymtabs_to_index
Tom Tromey [Thu, 27 May 2021 20:52:11 +0000 (14:52 -0600)]
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.

2 years ago"Finalize" the DWARF index in the background
Tom Tromey [Sat, 22 May 2021 21:20:06 +0000 (15:20 -0600)]
"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.

2 years agoParallelize DWARF indexing
Tom Tromey [Sun, 18 Apr 2021 21:20:43 +0000 (15:20 -0600)]
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.)

2 years agoPre-read DWARF section data
Tom Tromey [Mon, 28 Jun 2021 00:44:29 +0000 (18:44 -0600)]
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.

2 years agoIntroduce thread-safe handling for complaints
Tom Tromey [Mon, 6 Sep 2021 16:20:02 +0000 (10:20 -0600)]
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'.

2 years agoWire in the new DWARF indexer
Tom Tromey [Sat, 22 May 2021 13:54:06 +0000 (07:54 -0600)]
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.

2 years agoImplement quick_symbol_functions for cooked DWARF index
Tom Tromey [Sat, 22 May 2021 13:53:40 +0000 (07:53 -0600)]
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.

2 years agoThe new DWARF indexer
Tom Tromey [Sat, 22 May 2021 13:51:24 +0000 (07:51 -0600)]
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.

2 years agoIntroduce the new DWARF index class
Tom Tromey [Sun, 14 Mar 2021 17:38:54 +0000 (11:38 -0600)]
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.

2 years agoUpdate skip_one_die for new abbrev properties
Tom Tromey [Sat, 13 Mar 2021 21:55:13 +0000 (14:55 -0700)]
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.

2 years agoStatically examine abbrev properties
Tom Tromey [Sun, 7 Mar 2021 02:47:38 +0000 (19:47 -0700)]
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.

2 years agoIntroduce DWARF abbrev cache
Tom Tromey [Tue, 3 Nov 2020 00:35:51 +0000 (17:35 -0700)]
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.

2 years agoAdd "fullname" handling to file_and_directory
Tom Tromey [Tue, 30 Nov 2021 00:56:56 +0000 (17:56 -0700)]
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.

2 years agoSpecialize std::hash for gdb_exception
Tom Tromey [Mon, 6 Sep 2021 21:22:44 +0000 (15:22 -0600)]
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.

2 years agoReturn vector of results from parallel_for_each
Tom Tromey [Sun, 13 Jun 2021 18:46:28 +0000 (12:46 -0600)]
Return vector of results from parallel_for_each

This changes gdb::parallel_for_each to return a vector of the results.
However, if the passed-in function returns void, the return type
remains 'void'.  This functionality is used later, to parallelize the
new indexer.

2 years agoAdd batching parameter to parallel_for_each
Tom Tromey [Sun, 23 May 2021 15:04:27 +0000 (09:04 -0600)]
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.

2 years agoRefactor build_type_psymtabs_reader
Tom Tromey [Fri, 18 Jun 2021 21:36:40 +0000 (15:36 -0600)]
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.

2 years agoAdd new overload of dwarf5_djb_hash
Tom Tromey [Sun, 21 Mar 2021 17:15:57 +0000 (11:15 -0600)]
Add new overload of dwarf5_djb_hash

This adds a new overload of dwarf5_djb_hash.  This is used in
subsequent patches.

2 years agoAdd name splitting
Tom Tromey [Sun, 21 Mar 2021 17:07:28 +0000 (11:07 -0600)]
Add name splitting

The new DWARF index code works by keeping names pre-split.  That is,
rather than storing a symbol name like "a::b::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.

2 years agoLet skip_one_die not skip children
Tom Tromey [Sun, 20 Jun 2021 16:22:01 +0000 (10:22 -0600)]
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.

2 years agoAllow ada_decode not to decode operators
Tom Tromey [Sat, 5 Jun 2021 15:24:52 +0000 (09:24 -0600)]
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.

2 years agoRefactor dwarf2_get_pc_bounds
Tom Tromey [Sat, 12 Jun 2021 15:01:50 +0000 (09:01 -0600)]
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.

2 years agoAdd dwarf2_per_cu_data::addresses_seen
Tom Tromey [Fri, 11 Jun 2021 19:23:28 +0000 (13:23 -0600)]
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.

2 years agoFix latent bug in read_addrmap_from_aranges
Tom Tromey [Tue, 16 Nov 2021 21:25:08 +0000 (14:25 -0700)]
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.

2 years agoSplit create_addrmap_from_aranges
Tom Tromey [Fri, 11 Jun 2021 19:01:15 +0000 (13:01 -0600)]
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.

2 years agoAllow thread-pool.h to work without threads
Tom Tromey [Thu, 31 Mar 2022 02:19:54 +0000 (20:19 -0600)]
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.

2 years agoRebase the zlib sources to the 1.2.12 release
Nick Clifton [Tue, 12 Apr 2022 15:24:10 +0000 (16:24 +0100)]
Rebase the zlib sources to the 1.2.12 release

2 years ago[gdb/testsuite] Fix gdb.base/stap-probe.exp with read1
Tom de Vries [Tue, 12 Apr 2022 14:36:31 +0000 (16:36 +0200)]
[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.

2 years agoAdd C++ "save gdb-index" test
Tom Tromey [Tue, 12 Apr 2022 13:55:40 +0000 (07:55 -0600)]
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.

2 years agoRemove "Ada Settings" node from the manual
Tom Tromey [Mon, 14 Mar 2022 14:01:12 +0000 (08:01 -0600)]
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.

2 years agoRequire GNAT debug info for some Ada tests
Tom Tromey [Thu, 17 Mar 2022 14:36:01 +0000 (08:36 -0600)]
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".

2 years agoStop strip from removing debuglink sections.
Nick Clifton [Tue, 12 Apr 2022 12:34:06 +0000 (13:34 +0100)]
Stop strip from removing debuglink sections.

PR 28992
* objcopy.c (is_strip_section_1): Do not delete debuglink sections
when stripping debug information.

2 years agogas: new_logical_line{,_flags}() can return "void"
Jan Beulich [Tue, 12 Apr 2022 07:04:42 +0000 (09:04 +0200)]
gas: new_logical_line{,_flags}() can return "void"

With the sole user of the return value gone, convert the return type to
void. This in turn allows simplifying another construct, by moving it
slightly later in the function.

2 years agogas: drop .appfile and .appline
Jan Beulich [Tue, 12 Apr 2022 07:04:15 +0000 (09:04 +0200)]
gas: drop .appfile and .appline

These were used originally to represent "# <line> <file>" constructs
inserted by (typically) compilers when pre-processing. Quite some time
ago they were replaced by .linefile though. Since the original
directives were never documented, we ought to be able to remove support
for them. As a result in a number of case function parameter aren't used
anymore and can hence be dropped.

2 years agogas: further adjust file/line handling for .macro
Jan Beulich [Tue, 12 Apr 2022 07:03:43 +0000 (09:03 +0200)]
gas: further adjust file/line handling for .macro

Commit 7992631e8c0b ("gas/Dwarf: improve debug info generation from .irp
and alike blocks"), while dealing okay with actual assembly source files
not using .file/.line and alike outside but not inside of .macro, has
undue effects when the logical file/line pair was already overridden:
Line numbers would continuously increment while processing the expanded
macro, while the goal of the PR gas/16908 workaround is to keep the
expansion associated with the line invoking the macro. However, as soon
as enough state was overridden _inside_ the macro to cause as_where() to
no longer fall back top as_where_physical(), honor this by resuming the
bumping of the logical line number.

Note that from_sb_is_expansion's initializer was 1 for an unknown
reason. While renaming the variable and changing its type, also change
the initializer to "expanding_none", which would have been "0" in the
original code. Originally the initializer value itself wasn't ever used
anyway (requiring sb_index != -1), as it necessarily had changed in
input_scrub_include_sb() alongside setting sb_index to other than -1.

Strictly speaking input_scrub_insert_line() perhaps shouldn't use
expanding_none, yet none of the other enumerators fit there either. And
then strictly speaking that function probably shouldn't exist in the
first place. It's used only by tic54x.

2 years agogas: further adjust file/line handling for .irp and alike
Jan Beulich [Tue, 12 Apr 2022 07:03:13 +0000 (09:03 +0200)]
gas: further adjust file/line handling for .irp and alike

Commit 7992631e8c0b ("gas/Dwarf: improve debug info generation from .irp
and alike blocks"), while dealing okay with actual assembly source files
not using .file/.line and alike outside but not inside of .irp et al,
has undue effects when the logical file/line pair was already
overridden: Line numbers would continuously increment upon every
iteration, thus potentially getting far off. Furthermore it left it to
the user to actually insert .file/.line inside such constructs. Note
though that before aforementioned change things weren't pretty either:
Diagnostics (and debug info) would be associated with the directive
terminating the iteration construct, rather than with the actual lines.

Handle this automatically by simply latching the present line and then
re-instating coordinates first thing on every iteration; note that the
file can't change from what was previously pushed on the scrubber's
state stack, and hence can be taken from there by using a new flavor of
.linefile (which is far better memory-footprint-wise than recording the
full path in the inserted directive). (This then leaves undisturbed any
file/line control occurring in the body of the construct, as these will
only be seen and processed afterwards.)

2 years agox86: make {disp16} work similarly to {disp32}
Jan Beulich [Tue, 12 Apr 2022 07:01:55 +0000 (09:01 +0200)]
x86: make {disp16} work similarly to {disp32}

In a few places {disp32} was handled specially when really {disp16}
wants handling just the same.

2 years agogprofng doesn't build with gcc 5.5
Vladimir Mezentsev [Sun, 10 Apr 2022 07:59:06 +0000 (00:59 -0700)]
gprofng doesn't build with gcc 5.5

gprofng/ChangeLog
2022-04-07  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR gprofng/29026
* configure.ac: Check version of bison.
* src/Makefile.am (QLParser.yy): Run bison
* src/QLParser.yy: Adapted for bison 3.04 or later.
* src/DbeSession.cc: make some params const.
* src/DbeSession.h: Likewise.
* configure: Regenerate.
* Makefile.in: Regenerate.
* src/Makefile.in: Regenerate.
* src/QLParser.tab.cc: Deleted.
* src/QLParser.tab.hh: Deleted.
* doc/Makefile.in: Regenerate.
* gp-display-html/Makefile.in: Regenerate.
* libcollector/configure: Regenerate.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 12 Apr 2022 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoi386-fbsd-nat: Remove two unused variables.
John Baldwin [Mon, 11 Apr 2022 18:00:01 +0000 (11:00 -0700)]
i386-fbsd-nat: Remove two unused variables.

Earlier versions of the change in
1285ce8629b37f800bf21731ee7c7a8b1b8d0233 used this variable, but not
the final version that landed.

2 years agogdb: remove MSYMBOL_TARGET_FLAG_{1,2} macros
Simon Marchi [Fri, 28 Jan 2022 15:51:22 +0000 (10:51 -0500)]
gdb: remove MSYMBOL_TARGET_FLAG_{1,2} macros

Replace with equivalent getter/setter macros.

Change-Id: I1042564dd47347337374762bd64ec31b5c573ee2

2 years agogdb: remove minimal symbol size macros
Simon Marchi [Fri, 28 Jan 2022 15:41:49 +0000 (10:41 -0500)]
gdb: remove minimal symbol size macros

Remove MSYMBOL_HAS_SIZE, MSYMBOL_SIZE and SET_MSYMBOL_SIZE, replace them
with equivalent methods.

Change-Id: I6ee1cf82df37e58dff52ea6568ceb4649c7d7538

2 years agogdb: remove MSYMBOL_TYPE macro
Simon Marchi [Fri, 28 Jan 2022 15:28:57 +0000 (10:28 -0500)]
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

2 years agogdb: remove symbol value macros
Simon Marchi [Fri, 28 Jan 2022 13:09:50 +0000 (08:09 -0500)]
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

2 years agogdb/doc: add section about Fortran intrinsic functions and types
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:56 +0000 (14:06 +0200)]
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.

2 years agogdb/fortran/testsuite: add complex from integers test
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:56 +0000 (14:06 +0200)]
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.

2 years agogdb/fortran: rewrite intrinsic handling and add some missing overloads
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:56 +0000 (14:06 +0200)]
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.

2 years agogdb/fortran: rename f77_keywords to f_keywords
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:56 +0000 (14:06 +0200)]
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.

2 years agogdb/fortran: Change GDB print for fortran default types
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:56 +0000 (14:06 +0200)]
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.

2 years agogdb/fortran: clean-up Fortran intrinsic types
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:56 +0000 (14:06 +0200)]
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.

2 years agogdb/fortran: change default logical type to builtin_logical
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:55 +0000 (14:06 +0200)]
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.

2 years agogdb/fortran: reformat build_fortran_types in f-lang.c
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:55 +0000 (14:06 +0200)]
gdb/fortran: reformat build_fortran_types in f-lang.c

Add a few newlines after the type definitions and remove some
unnecessary linebreaks.

2 years agogdb/fortran: fix complex type in Fortran builtin types
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:55 +0000 (14:06 +0200)]
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

2 years agogdb/f-lang: remove hidden ^L characters
Nils-Christian Kempke [Mon, 11 Apr 2022 12:06:55 +0000 (14:06 +0200)]
gdb/f-lang: remove hidden ^L characters