]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
2 weeks agoAutomatic date update in version.in
GDB Administrator [Mon, 9 Jun 2025 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 weeks agoAutomatic date update in version.in
GDB Administrator [Sun, 8 Jun 2025 00:00:39 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 weeks ago[gdb/build] Fix buildbreaker in hardwire_setbaudrate
Tom de Vries [Sat, 7 Jun 2025 21:28:53 +0000 (23:28 +0200)] 
[gdb/build] Fix buildbreaker in hardwire_setbaudrate

When building on x86_64-cygwin, I run into:
...
In file included from gdbsupport/common-defs.h:203,
                 from gdb/defs.h:26,
                 from <command-line>:
gdb/ser-unix.c: In function ‘void hardwire_setbaudrate(serial*, int)’:
gdbsupport/gdb_locale.h:28:20: error: expected ‘)’ before ‘gettext’
   28 | # define _(String) gettext (String)
      |                    ^~~~~~~
gdbsupport/gdb_assert.h:43:43: note: in expansion of macro ‘_’
   43 |   internal_error_loc (__FILE__, __LINE__, _("%s: " message), __func__, \
      |                                           ^
gdb/ser-unix.c:590:7: note: in expansion of macro ‘gdb_assert_not_reached’
  590 |       gdb_assert_not_reached (_("Serial baud rate was not found in B_codes"));
      |       ^~~~~~~~~~~~~~~~~~~~~~
gdb/ser-unix.c:590:31: note: in expansion of macro ‘_’
  590 |       gdb_assert_not_reached (_("Serial baud rate was not found in B_codes"));
      |                               ^
gdbsupport/gdb_locale.h:28:28: note: to match this ‘(’
   28 | # define _(String) gettext (String)
      |                            ^
gdbsupport/gdb_assert.h:43:43: note: in expansion of macro ‘_’
   43 |   internal_error_loc (__FILE__, __LINE__, _("%s: " message), __func__, \
      |                                           ^
gdb/ser-unix.c:590:7: note: in expansion of macro ‘gdb_assert_not_reached’
  590 |       gdb_assert_not_reached (_("Serial baud rate was not found in B_codes"));
      |       ^~~~~~~~~~~~~~~~~~~~~~
...

Fix this by dropping the unneeded _() on the gdb_assert_not_reached argument.

PR build/33064
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33064

2 weeks ago[gdb/testsuite] Fix gdb.ada/dyn-bit-offset.exp on s390x
Tom de Vries [Sat, 7 Jun 2025 11:59:52 +0000 (13:59 +0200)] 
[gdb/testsuite] Fix gdb.ada/dyn-bit-offset.exp on s390x

On s390x-linux, with test-case gdb.ada/dyn-bit-offset.exp and gcc 7.5.0 I get:
...
(gdb) print spr^M
$1 = (discr => 3, array_field => (-5, -6, -7), field => -6, another_field => -6)^M
(gdb) FAIL: $exp: print spr
print spr.field^M
$2 = -6^M
(gdb) FAIL: $exp: print spr.field
...

On x86_64-linux, with the same compiler version I get:
...
(gdb) print spr^M
$1 = (discr => 3, array_field => (-5, -6, -7), field => -4, another_field => -4)^M
(gdb) XFAIL: $exp: print spr
print spr.field^M
$2 = -4^M
(gdb) PASS: $exp: print spr.field
...

In both cases, we're hitting the same compiler problem, but it manifests
differently on little and big endian.

Make sure the values seen for both little and big endian trigger xfails
for both tests.

Printing spr.field gives the expected value -4 for x86_64, but that's an
accident.  Change the actual spr.field value to -5, to make sure
that we get the same number of xfails on x86_64 and s390x.

Finally, make the xfails conditional on the compiler version.

Tested using gcc 7.5.0 on both x86_64-linux and s390x-linux.

Approved-By: Andrew Burgess <aburgess@redhat.com>
PR testsuite/33042
https://sourceware.org/bugzilla/show_bug.cgi?id=33042

2 weeks agoAVR: ld/32968 - Assert that .progmem data resides in the lower 64 KiB.
Georg-Johann Lay [Thu, 15 May 2025 08:29:25 +0000 (10:29 +0200)] 
AVR: ld/32968 - Assert that .progmem data resides in the lower 64 KiB.

This patch locates the linker stubs / trampolines *after* all the .progmem
sections.  This is the natural placement since progmem data has to reside
in the lower 64 KiB (it is accessed using LPM), whereas the linker stubs
are only required to be located in the lower 128 KiB of program memory.
(They must be in the range of EICALL / EIJMP with EIND = 0.)

The current location of the linker stubs was motivated by an invalid test
case from PR13812 that allocates more than 64 KiB of progmem data.

The patch adds an assertion that makes sure that no progmem data is
allocated past 0xffff.

Data that is accessed using ELPM should be located to .progmemx so that
no .progmem addresses are wasted.  .progmemx was introduced in 2017 and
is used by __memx, __flashx and by the current AVR-LibC.
(The compiler uses .jumptables.gcc for its jump dispatch tables since
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63223 / GCC v4.9.2).

PR ld/32968
ld/
* scripttempl/avr.sc: Move the trampolines section after the
.progmem sections.  Assert that .progmem is in the lower 64 KiB.

2 weeks agoAutomatic date update in version.in
GDB Administrator [Sat, 7 Jun 2025 00:01:08 +0000 (00:01 +0000)] 
Automatic date update in version.in

2 weeks agogdb/guile: fix memory leak in gdbscm_parse_command_name
Andrew Burgess [Thu, 5 Jun 2025 13:50:41 +0000 (14:50 +0100)] 
gdb/guile: fix memory leak in gdbscm_parse_command_name

For reference see the previous commit.

Fix a memory leak in gdbscm_parse_command_name when a guile exception
is thrown.  To reveal the memory leak I placed the following content
into a file 'leak.scm':

  (use-modules (gdb))
  (register-command!
   (make-command
    "break cmd"
    #:command-class COMMAND_OBSCURE
    #:invoke (lambda (self arg from-tty)
               (display "Hello World"))))

Then in GDB:

  (gdb) source leak.scm
  ERROR: In procedure register-command!:
  In procedure gdbscm_register_command_x: Out of range: 'break' is not a prefix command in position 1: "break cmd"
  Error while executing Scheme code.

Running this under valgrind reveals a memory leak for 'result' and
'prefix_text' from gdbscm_parse_command_name.

Another leak can be revealed with this input script:

  (use-modules (gdb))
  (register-command!
   (make-command
    "unknown-prefix cmd"
    #:command-class COMMAND_OBSCURE
    #:invoke (lambda (self arg from-tty)
               (display "Hello World"))))

This one occurs earlier in gdbscm_parse_command_name, and now only
'result' leaks.

The problem is that, when guile throws an exception then a longjmp is
performed from the function that raise the exception back to the guile
run-time.  A consequence of this is that no function local destructors
will be run.

In gdbscm_parse_command_name, this means that the two function locals
`result` and `prefix_text` will not have their destructors run, and
any memory managed by these objects will be leaked.

Fix this by assigning nullptr to these two function locals before
throwing an exception.  This will cause the managed memory to be
deallocated.

I could have implemented a fix that made use of Guile's dynwind
mechanism to register a cleanup callback, however, this felt like
overkill.  At the point the exception is being thrown we know that we
no longer need the managed memory, so we might as well just free the
memory at that point.

With this fix in place, the two leaks are now fixed in the valgrind
output.

Approved-By: Tom Tromey <tom@tromey.com>
2 weeks agogdb/python/guile: remove some explicit calls to xmalloc
Andrew Burgess [Wed, 4 Jun 2025 18:54:01 +0000 (19:54 +0100)] 
gdb/python/guile: remove some explicit calls to xmalloc

In gdbpy_parse_command_name (python/py-cmd.c) there is a call to
xmalloc that can easily be replaced with a call to
make_unique_xstrndup, which makes the code easier to read (I think).

In gdbscm_parse_command_name (guile/scm-cmd.c) the same fix can be
applied to remove an identical xmalloc call.  And there is an
additional xmalloc call, which can also be replaced with
make_unique_xstrndup in the same way.

The second xmalloc call in gdbscm_parse_command_name was also present
in gdbpy_parse_command_name at one point, but was replaced with a use
of std::string by this commit:

  commit 075c55e0cc0a68eeab777027213c2f545618e844
  Date:   Wed Dec 26 11:05:57 2018 -0700

      Remove more calls to xfree from Python

I haven't changed the gdbscm_parse_command_name to use std::string
though, as that doesn't work well with the guile exception model.
Guile exceptions work by performing a longjmp from the function that
raises the exception, back to the guile run-time.  The consequence of
this is that destructors are not run.  For example, if
gdbscm_parse_command_name calls gdbscm_out_of_range_error, then any
function local objects in gdbscm_parse_command_name will not have
their destructors called.

What this means is that, for the existing `result` and `prefix_text`
locals, any allocated memory managed by these objects will be leaked
if an exception is called.  However, fixing this is pretty easy, one
way is to just assign nullptr to these locals before raising the
exception, this would cause the allocated memory to be released.

But for std::string it is harder to ensure that the managed memory has
actually been released.  We can call std::string::clear() and then
maybe std::string::shrink_to_fit(), but this is still not guaranteed
to release any managed memory.  In fact, I believe the only way to
ensure all managed memory is released, is to call the std::string
destructor.

And so, for functions that can throw a guile exception, it is easier
to just avoid std::string.

As for the memory leak that I identify above; I'll fix that in a
follow on commit.

Approved-By: Tom Tromey <tom@tromey.com>
2 weeks agogdb/solib: make _linker_namespace use selected frame
Guinevere Larsen [Fri, 6 Jun 2025 19:23:37 +0000 (16:23 -0300)] 
gdb/solib: make _linker_namespace use selected frame

When the convenience variable $_linker_namespace was introduced, I meant
for it to print the namespace of the frame that where the user was
stopped. However, due to confusing what "current_frame" and
"selected_frame" meant, it instead printed the namespace of the
lowermost frame.

This commit updates the code to follow my original intent. Since the
variable was never in a GDB release, updating the behavior should not
cause any disruption. It also adds a test to verify the functionality.

Approved-By: Tom Tromey <tom@tromey.com>
2 weeks agobfd: sframe: fix typo in comments
Indu Bhagat [Fri, 6 Jun 2025 20:36:04 +0000 (13:36 -0700)] 
bfd: sframe: fix typo in comments

bfd/
* elflink.c (elf_link_input_bfd): Replace ctf frame with SFrame.

2 weeks agogdb: unix: allow to use custom baud rate
Alexey Lapshin [Wed, 9 Apr 2025 16:19:02 +0000 (16:19 +0000)] 
gdb: unix: allow to use custom baud rate

Modern unix systems allow to set custom baud rate instead of predefined in termios.h.

- To use this in Linux it must have BOTHER macro in "asm/termio.h"
- MacOS could handle this using IOSSIOSPEED passed to ioctl()

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I5bc95982f5d90c7030b73f484ecc0f75c060ebf7

2 weeks agogdb: unix: extend supported baudrate B_codes
Alexey Lapshin [Wed, 9 Apr 2025 16:17:05 +0000 (16:17 +0000)] 
gdb: unix: extend supported baudrate B_codes

Added B_codes that may be supported in some unix systems

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I48624d6573dc6c72e26818dd44b24182c1dabb70

2 weeks agogdb/amd-dbgapi: remove one xfree
Simon Marchi [Thu, 5 Jun 2025 20:30:25 +0000 (16:30 -0400)] 
gdb/amd-dbgapi: remove one xfree

Replace a manual xfree with unique_xmalloc_ptr.

Change-Id: Id4d2065e3294c4761fe3c852962360712b53d7a8
Approved-By: Tom Tromey <tom@tromey.com>
Approved-by: Lancelot Six <lancelot.six@amd.com> (amdgpu)
2 weeks agogdb/solib-rocm: remove one xfree
Simon Marchi [Thu, 5 Jun 2025 20:30:24 +0000 (16:30 -0400)] 
gdb/solib-rocm: remove one xfree

Replace a manual xfree with unique_xmalloc_ptr.

Change-Id: I12a20106545905f1a80d069fc0555812cc3d6680
Approved-By: Tom Tromey <tom@tromey.com>
Approved-by: Lancelot Six <lancelot.six@amd.com> (amdgpu)
2 weeks agoFix regression with DW_AT_bit_offset handling
Tom Tromey [Tue, 27 May 2025 18:18:30 +0000 (12:18 -0600)] 
Fix regression with DW_AT_bit_offset handling

Internal AdaCore testing using -gdwarf-4 found a spot where GCC will
emit a negative DW_AT_bit_offset.  However, my recent signed/unsigned
changes assumed that this value had to be positive.

I feel this bug somewhat invalidates my previous thinking about how
DWARF attributes should be handled.

In particular, both GCC and LLVM at understand that a negative bit
offset can be generated -- but for positive offsets they might use a
smaller "data" form, which is expected not to be sign-extended.  LLVM
has similar code but GCC does:

  if (bit_offset < 0)
    add_AT_int (die, DW_AT_bit_offset, bit_offset);
  else
    add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);

What this means is that this attribute is "signed but default
unsigned".

To fix this, I've added a new attribute::confused_constant method.
This should be used when a constant value might be signed, but where
narrow forms (e.g., DW_FORM_data1) should *not* cause sign extension.

I examined the GCC and LLVM DWARF writers to come up with the list of
attributes where this applies, namely DW_AT_bit_offset,
DW_AT_const_value and DW_AT_data_member_location (GCC only, but LLVM
always emits it as unsigned, so we're safe here).

This patch corrects the bug and imports the relevant test case.

Regression tested on x86-64 Fedora 41.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680
Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118837
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 weeks agogdb: prevent assertion after 'set debug breakpoint on'
Andrew Burgess [Mon, 2 Jun 2025 15:05:14 +0000 (16:05 +0100)] 
gdb: prevent assertion after 'set debug breakpoint on'

Turns out that using 'set debug breakpoint on' will trigger an
assertion for 'catch' style breakpoints, e.g.:

  (gdb) file /tmp/hello.x
  Reading symbols from /tmp/hello.x...
  (gdb) catch exec
  Catchpoint 1 (exec)
  (gdb) set debug breakpoint on
  (gdb) start
  [breakpoint] dump_condition_tokens: Tokens: { INFERIOR: "1" }
  Temporary breakpoint 2 at 0x401198: file /tmp/hello.c, line 18.
  [breakpoint] update_global_location_list: insert_mode = UGLL_MAY_INSERT
  Starting program: /tmp/hello.x
  [breakpoint] update_global_location_list: insert_mode = UGLL_MAY_INSERT
  ../../gdb-16.1/gdb/gdbarch-gen.c:1764: internal-error: gdbarch_addr_bit: Assertion `gdbarch != NULL' failed.
  .... etc ...

The problem is that catch breakpoints don't set the
bp_location::gdbarch member variable, they a "dummy" location added
with a call to add_dummy_location (breakpoint.c).

The breakpoint_location_address_str function (which is only used for
breakpoint debug output) relies on bp_location::gdbarch being set in
order to call the paddress function.

I considered trying to ensure that the bp_location::gdbarch variable
is always set to sane value.  For example, in add_dummy_location I
tried copying the gdbarch from the breakpoint object, and this does
work for the catchpoint case, but for some of the watchpoint cases,
even the breakpoint object has no gdbarch value set.

Now this seemed a little suspect, but, the more I thought about it, I
wondered if "fixing" the gdbarch was allowing me to solve the wrong
problem.

If the gdbarch was set, then this would allow us to print the address
field of the bp_location, which is going to be 0, after all, as this
is a dummy location, which has no address.

But does it really make sense to print the address 0?  For some
targets, 0 is a valid address.  But that wasn't an address we actually
selected, it's just the default value for dummy locations.

And we already have a helper function bl_address_is_meaningful, which
returns false for dummy locations.

So, I propose that in breakpoint_location_address_str, we use
bl_address_is_meaningful to detect dummy locations, and skip the
address printing code in that case.

For testing, I temporarily changed insert_bp_location so that
breakpoint_location_address_str was always called, even when
breakpoint debugging was off.  I then ran the whole testsuite.
Without the fixes included in this commit I saw lots of assertion
failures, but with the fixes from this commit in place, I now see no
assertion failures.

I've added a new test which reveals the original assertion failure.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 weeks agogdb/configure: Fix POSIX non-compliance
Guinevere Larsen [Thu, 5 Jun 2025 19:41:29 +0000 (16:41 -0300)] 
gdb/configure: Fix POSIX non-compliance

My recent GDB commit:

    commit 4b42385c470c5f72f158f382f4d9c36f927aa84f
    Author: Guinevere Larsen <guinevere@redhat.com>
    Date:   Wed Feb 12 08:25:46 2025 -0300
    gdb: Make dwarf support optional at compile time

Introduced a change that made the configure script not POSIX compliant,
by using fallthrough in some case statements. This commit reworks that
part of the change to only use if statements, so that no code is
duplicated but things remain POSIX compliant.

Reviewed-by: Sam James <sam@gentoo.org>
Approved-By: Tom Tromey <tom@tromey.com>
2 weeks agoMake default_gdb_exit resilient to failed closes
Pedro Alves [Mon, 10 Mar 2025 20:08:54 +0000 (20:08 +0000)] 
Make default_gdb_exit resilient to failed closes

For some reason, when testing GDB on Cygwin, I get:

 child process exited abnormally
     while executing
 "exec sh -c "exec > /dev/null 2>&1 && (kill -2 -$spid || kill -2 $spid)""
     (procedure "close_wait_program" line 20)
     invoked from within
 "close_wait_program $shell_id $pid"
     (procedure "standard_close" line 23)
     invoked from within
 "standard_close "Windows-ROCm""
     ("eval" body line 1)
     invoked from within
 "eval ${try}_${proc} \"$dest\" $args"
     (procedure "call_remote" line 42)
     invoked from within
 "call_remote "" close $host"
     (procedure "remote_close" line 3)
     invoked from within
 "remote_close host"
     (procedure "log_and_exit" line 30)
     invoked from within
 "log_and_exit"

When that happens from within clean_restart, clean_restart doesn't
clear the gdb_spawn_id variable, and then when clean_restart starts up
a new GDB, that sees that gdb_spawn_id is already set, so it doesn't
actually spawn a new GDB, and so clean_restart happens to reuse the
same GDB (!).  Many tests happen to actually work OK with this, but
some don't, and the failure modes can be head-scratching.

Of course, the failure to close GDB should be fixed, but when it
happens, I think it's good to not end up with the current weird state.
Connecting the "child process exit abnormally" errors at the end of a
testcase run with weird FAILs in other testcases took me a while (as
in, weeks!), it wasn't obvious to me immediately.

Thus, this patch makes default_gdb_exit more resilient to failed
closes, so that gdb_spawn_id is unset even is closing GDB fails, and
we move on to start a new GDB.

Approved-By: Andrew Burgess <aburgess@redhat.com>
Change-Id: I9ec95aa61872a40095775534743525e0ad2097d2

2 weeks agogdb_test_multiple: Anchor prompt match if -lbl
Pedro Alves [Thu, 5 Jun 2025 17:09:44 +0000 (18:09 +0100)] 
gdb_test_multiple: Anchor prompt match if -lbl

The testcase added by this patch has a gdb_test_multiple call that
wants to match different lines of output that all have a common
prefix, and do different actions on each.  Instead of a single regular
expression with alternatives, it's clearer code if the different
expressions are handled with different "-re", like so:

  gdb_test_multiple "command" "" -lbl {
     -re "^command(?=\r\n)" {
 exp_continue
     }
     -re "^\r\nprefix foo(?=\r\n)" {
 # Some action for "foo".
 exp_continue
     }
     -re "^\r\nprefix bar(?=\r\n)" {
 # Some action for "bar".
 exp_continue
     }
     -re "^\r\nprefix \[^\r\n\]*(?=\r\n)" {
 # Some action for all others.
 exp_continue
     }
     -re "^\r\n$::gdb_prompt $" {
 gdb_assert {$all_prefixes_were_seen} $gdb_test_name
     }
  }

Above, the leading anchors in the "^\r\nprefix..." matches are needed
to avoid too-eager matching due to the common prefix.  Without the
anchors, if the expect output buffer happens to contain at least:

  "\r\nprefix xxx\r\nprefix foo\r\n"

... then the "prefix foo" pattern match inadvertently consumes the
first "prefix xxx" line.

Without the anchor in the prompt match, like:

  -re "\r\n$::gdb_prompt $" {
      gdb_assert {$all_prefixes_were_seen} $gdb_test_name
  }

Or the equivalent:

  -re -wrap "" {
      gdb_assert {$all_prefixes_were_seen} $gdb_test_name
  }

... then if the expect buffer contains:

  "\r\nmeant-to-be-matched-by-lbl\r\nprefix foo\r\n$gdb_prompt "

... then the prompt regexp matches this, consuming the "prefix" line
inadvertently, and we get a FAIL.  The built-in regexp matcher for
-lbl doesn't get a chance to match the
"\r\nmeant-to-be-matched-by-lbl\r\n" part, because the built-in prompt
match appears first within gdb_test_multiple.

By adding the anchor to the prompt regexp, we avoid that problem.

However, the same expect output buffer contents will still match the
built-in prompt regexp.  That is what is fixed by this patch.  It
makes it so that if -lbl is specified, the built-in prompt regexp has
a leading anchor.

Original idea for turning this into a gdb.testsuite/ testcase by Tom
de Vries <tdevries@suse.de>.

Approved-By: Tom de Vries <tdevries@suse.de>
Change-Id: Ic2571ec793d856a89ee0d533ec363e2ac6036ea2

2 weeks ago[gdb] Fix typo in gdb/break-catch-syscall.c
Tom de Vries [Fri, 6 Jun 2025 11:18:30 +0000 (13:18 +0200)] 
[gdb] Fix typo in gdb/break-catch-syscall.c

Fix typo "if the feature if supported" -> "if the feature is supported".

2 weeks agox86/Solaris: cope with new HANDLE_ALIGN behavior
Jan Beulich [Fri, 6 Jun 2025 09:02:43 +0000 (11:02 +0200)] 
x86/Solaris: cope with new HANDLE_ALIGN behavior

Extend the expectation adjustments done by 83d94ae428b1 ("tidy x86
HANDLE_ALIGN") to the Solaris clone of an affected testcase.

2 weeks ago[gdb/testsuite] Fix timeout in gdb.multi/attach-while-running.exp
Tom de Vries [Fri, 6 Jun 2025 08:14:47 +0000 (10:14 +0200)] 
[gdb/testsuite] Fix timeout in gdb.multi/attach-while-running.exp

With test-case gdb.multi/attach-while-running.exp usually I get:
...
(gdb) run &^M
Starting program: attach-while-running ^M
(gdb) PASS: $exp: run &
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
add-inferior^M
[New inferior 2]^M
Added inferior 2 on connection 1 (native)^M
(gdb) PASS: $exp: add-inferior
...
or:
...
(gdb) run &
Starting program: attach-while-running
(gdb) PASS: $exp: run &
add-inferior
[New inferior 2]
Added inferior 2 on connection 1 (native)
(gdb) PASS: $exp: add-inferior
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
...
but sometimes I run into:
...
(gdb) run &
Starting program: attach-while-running
(gdb) PASS: $exp: run &
add-inferior
[New inferior 2]
Added inferior 2 on connection 1 (native)
(gdb) [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
FAIL: $exp: add-inferior (timeout)
...

Fix this by using -no-prompt-anchor.

Tested on x86_64-linux.

2 weeks ago[gdb/tdep] Don't call WaitForSingleObject with INFINITE arg
Tom de Vries [Fri, 6 Jun 2025 06:25:46 +0000 (08:25 +0200)] 
[gdb/tdep] Don't call WaitForSingleObject with INFINITE arg

I decided to try to build and test gdb on Windows.

I found a page on the wiki [1] suggesting three ways of building gdb:
- MinGW,
- MinGW on Cygwin, and
- Cygwin.

I picked Cygwin, because I've used it before (though not recently).

I managed to install Cygwin and sufficient packages to build gdb and start the
testsuite.

However, testsuite progress ground to a halt at gdb.base/branch-to-self.exp.
[ AFAICT, similar problems reported here [2]. ]

I managed to reproduce this hang by running just the test-case.

I attempted to kill the hanging processes by:
- first killing the inferior process, using the cygwin "kill -9" command, and
- then killing the gdb process, likewise.

But the gdb process remained, and I had to point-and-click my way through task
manager to actually kill the gdb process.

I investigated this by attaching to the hanging gdb process.  Looking at the
main thread, I saw it was stopped in a call to WaitForSingleObject, with
the dwMilliseconds parameter set to INFINITE.

The backtrace in more detail:
...
(gdb) bt
 #0  0x00007fff196fc044 in ntdll!ZwWaitForSingleObject () from
     /cygdrive/c/windows/SYSTEM32/ntdll.dll
 #1  0x00007fff16bbcdcf in WaitForSingleObjectEx () from
     /cygdrive/c/windows/System32/KERNELBASE.dll
 #2  0x0000000100998065 in wait_for_single (handle=0x1b8, howlong=4294967295) at
     gdb/windows-nat.c:435
 #3  0x0000000100999aa7 in
     windows_nat_target::do_synchronously(gdb::function_view<bool ()>)
       (this=this@entry=0xa001c6fe0, func=...) at gdb/windows-nat.c:487
 #4  0x000000010099a7fb in windows_nat_target::wait_for_debug_event_main_thread
     (event=<optimized out>, this=0xa001c6fe0)
     at gdb/../gdbsupport/function-view.h:296
 #5  windows_nat_target::kill (this=0xa001c6fe0) at gdb/windows-nat.c:2917
 #6  0x00000001008f2f86 in target_kill () at gdb/target.c:901
 #7  0x000000010091fc46 in kill_or_detach (from_tty=0, inf=0xa000577d0)
     at gdb/top.c:1658
 #8  quit_force (exit_arg=<optimized out>, from_tty=from_tty@entry=0)
     at gdb/top.c:1759
 #9  0x00000001004f9ea8 in quit_command (args=args@entry=0x0,
     from_tty=from_tty@entry=0) at gdb/cli/cli-cmds.c:483
 #10 0x000000010091c6d0 in quit_cover () at gdb/top.c:295
 #11 0x00000001005e3d8a in async_disconnect (arg=<optimized out>)
     at gdb/event-top.c:1496
 #12 0x0000000100499c45 in invoke_async_signal_handlers ()
     at gdb/async-event.c:233
 #13 0x0000000100eb23d6 in gdb_do_one_event (mstimeout=mstimeout@entry=-1)
     at gdbsupport/event-loop.cc:198
 #14 0x00000001006df94a in interp::do_one_event (mstimeout=-1,
     this=<optimized out>) at gdb/interps.h:87
 #15 start_event_loop () at gdb/main.c:402
 #16 captured_command_loop () at gdb/main.c:466
 #17 0x00000001006e2865 in captured_main (data=0x7ffffcba0) at gdb/main.c:1346
 #18 gdb_main (args=args@entry=0x7ffffcc10) at gdb/main.c:1365
 #19 0x0000000100f98c70 in main (argc=10, argv=0xa000129f0) at gdb/gdb.c:38
...

In the docs [3], I read that using an INFINITE argument to WaitForSingleObject
might cause a system deadlock.

This prompted me to try this simple change in wait_for_single:
...
   while (true)
     {
-      DWORD r = WaitForSingleObject (handle, howlong);
+      DWORD r = WaitForSingleObject (handle,
+                                     howlong == INFINITE ? 100 : howlong);
+      if (howlong == INFINITE && r == WAIT_TIMEOUT)
+        continue;
...
with the timeout of 0.1 second estimated to be:
- small enough for gdb to feel reactive, and
- big enough not to consume too much cpu cycles with looping.

And indeed, the test-case, while still failing, now finishes in ~50 seconds.

While there may be an underlying bug that triggers this behaviour, the failure
mode is so severe that I consider it a bug in itself.

Fix this by avoiding calling WaitForSingleObject with INFINITE argument.

Tested on x86_64-cygwin, by running the testsuite past the test-case.

Approved-By: Pedro Alves <pedro@palves.net>
PR tdep/32894
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32894

[1] https://sourceware.org/gdb/wiki/BuildingOnWindows
[2] https://sourceware.org/pipermail/gdb-patches/2025-May/217949.html
[3] https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject

2 weeks agoAutomatic date update in version.in
GDB Administrator [Fri, 6 Jun 2025 00:00:50 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 weeks agogdb/solib-svr4: make svr4_info::debug_loader_name an std::string
Simon Marchi [Tue, 3 Jun 2025 16:45:14 +0000 (12:45 -0400)] 
gdb/solib-svr4: make svr4_info::debug_loader_name an std::string

Remove some manual memory management.

Change-Id: I9c752d35a70e3659509fed57df1c9a8d27ecc742
Approved-By: Tom Tromey <tom@tromey.com>
3 weeks agogdb/solib: rename convenience variable to _linker_namespace
Guinevere Larsen [Thu, 15 May 2025 14:07:03 +0000 (11:07 -0300)] 
gdb/solib: rename convenience variable to _linker_namespace

Based on feedback from IRC and PR solib/32959, this commit renames the
recently introduced convenience variable $_current_linker_namespace to
the shorter name $_linker_namespace. This makes it more in line with
existing convenience variables such as $_thread and $_inferior, and
faster to type.

It should be ok to simply change the name because the variable was never
released to the public, so there should be no existing scripts depending
on the name.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32959
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
3 weeks agogdb/solib: Change type of convenience variable _current_linker_namespace
Guinevere Larsen [Thu, 15 May 2025 13:45:57 +0000 (10:45 -0300)] 
gdb/solib: Change type of convenience variable _current_linker_namespace

Based on IRC feedback since commit 6a0da68c036a85a46415aa0dada2421eee7c2269

    gdb: add convenience variables around linker namespace debugging

This commit changes the type of the _current_linker_namespace variable
to be a simple integer. This makes it easier to use for expressions,
like breakpoint conditions or printing from a specific namespace once
that is supported, at the cost of making namespace IDs slightly less
consistent.

This is based on PR solib/32960, where no negative feedback was given
for the suggestion.

The commit also changes the usage of "linkage namespaces" to "linker
namespaces" in the NEWS file, to reduce chance of confusion from an end
user.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32960
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
3 weeks ago[gdb/testsuite] Fix gdb.base/bp-permanent.exp with gcc 15
Tom de Vries [Thu, 5 Jun 2025 05:37:09 +0000 (07:37 +0200)] 
[gdb/testsuite] Fix gdb.base/bp-permanent.exp with gcc 15

With test-case gdb.base/bp-permanent.exp and gcc 15 I run into:
...
gdb compile failed, bp-permanent.c: In function 'test_signal_nested':
bp-permanent.c:118:20: error: passing argument 2 of 'signal' from \
  incompatible pointer type [-Wincompatible-pointer-types]
  118 |   signal (SIGALRM, test_signal_nested_handler);
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                    |
      |                    void (*)(void)
In file included from bp-permanent.c:20:
/usr/include/signal.h:88:57: note: expected '__sighandler_t' \
  {aka 'void (*)(int)'} but argument is of type 'void (*)(void)'
...

Fix this by adding an int parameter to test_signal_nested_handler.

Tested on x86_64-linux.

PR testsuite/32756
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32756

3 weeks agoAutomatic date update in version.in
GDB Administrator [Thu, 5 Jun 2025 00:00:31 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 weeks agolibctf: use __attribute__((__gnu_printf__)) where appropriate
Nick Alcock [Tue, 3 Jun 2025 12:39:33 +0000 (13:39 +0100)] 
libctf: use __attribute__((__gnu_printf__)) where appropriate

We don't use any GNU-specific printf args, but this prevents warnings about
%z, observed on MinGW even though every libc anyone is likely to use there
supports %z perfectly well, and we're not stopping using it just because
MinGW complains.  Doing this means we stand more chance of seeing *actual*
problems on such platforms without them being drowned in noise.

We turn this off on clang, which doesn't support __gnu_printf__.

Suggested by Eli Zaretskii.

libctf/
PR libctf/31863
* ctf-impl.h (_libctf_printflike_): Use __gnu_printf__.

3 weeks agolibctf, dedup: reclaim space wasted by duplicate hidden types
Nick Alcock [Tue, 3 Jun 2025 11:01:45 +0000 (12:01 +0100)] 
libctf, dedup: reclaim space wasted by duplicate hidden types

In normal deduplicating links, we insert every type (identified by its
unique hash) precisely once.  But conflicting types appear in multiple
dicts, so for those, we loop, inserting them into every target dict
in turn (each corresponding to an input dict that type appears in).
But in cu-mapped links, some of those dicts may have been merged into
one: now that we are hiding duplicate conflicting types more
aggressively in such links, we are getting duplicate identical hidden
types turning up in large numbers.

Fix this by eliminating them in cu-mapping phase 1 (the phase in which this
merging takes place), by checking to see if a type with this hash has
already been inserted in this dict and skipping it if so.  This is
redundant and a waste of time in other cu-mapping phases and in normal
links, but in cu-mapped links it saves a few tens to hundreds of kilobytes
in kernel-sized links.

libctf/
PR libctf/33047
* ctf-dedup.c (ctf_dedup_emit_type): Check for already-emitted
types in cu-mapping phase 1.

3 weeks agolibctf: dedup: preserve non-root flag across normal links
Nick Alcock [Fri, 30 May 2025 21:12:37 +0000 (22:12 +0100)] 
libctf: dedup: preserve non-root flag across normal links

The previous commits dropped preservation of the non-root flag in ctf_link
and arranged to use it somewhat differently to track conflicting types in
cu-mapped CUs when doing cu-mapped links.  This was necessary to prevent
entirely spuriously hidden types from appearing on the output of such links.

Bring it (and the test for it) back.  The problem with the previous design
was that it implicitly assumed that the non-root flag it saw on the input
was always meant to be preserved (when in the final phase of cu-mapped links
it merely means that conflicting types were found in intermediate links),
and also that it could figure out what the non-root flag on the input was by
sucking in the non-root flag of the input type corresponding to an output in
the output mapping (which maps type hashes to a corresponding type on some
input).

This method of getting properties of the input type *does* work *if* that
property was one of those hashed by the ctf_dedup_hash_type process.  In
that case, every type with a given hash will have the same value for all
hashed-in properties, so it doesn't matter which one is consulted (the
output mapping points at an arbitrary one of those input types).  But the
non-root flag is explicitly *not* hashed in: as a comment in
ctf_dedup_rhash_type notes, being non-root is not a property of a type, and
two types (one non-root, one not) can perfectly well be the same type even
though one is visible and one isn't.  So just copying the non-root flag from
the output mapping's idea of the input type will copy in a value that is not
stabilized by the hash, so is more-or-less random!

So we cannot do that.  We have to do something else, which means we have to
decide what to do if two identical types with different nonroot flag values
pop up.  The most sensible thing to do is probably to say that if all
instances of a type are non-root-visible, the linked output should also be
non-root-visible: any root-visible types in that set, and the output type is
root-visible again.

We implement this with a new cd_nonroot_consistency dynhash, which maps type
hashes to the value 0 ("all instances root-visible"), 1 ("all instances
non-root-visible") or 2 ("inconsistent").  After hashing is over, we save a
bit of memory by deleting everything from this hashtab that doesn't have a
value of 1 ("non-root-visible"), then use this to decide whether to emit any
given type as non-root-visible or not.

However... that's not quite enough.  In cu-mapped links, we want to
disregard this whole thing because we just hide everything -- but in phase
2, when we take the smushed-together CUs resulting from phase 1 and
deduplicate them against each other, we want to do what the previous commits
implemented and ignore the non-root flag entirely, instead falling back to
preventing clashes by hiding anything that would be considered conflicting.
We extend the existing cu_mapped parameter to various bits of ctf_dedup so
that it is now tristate: 0 means a normal link, 1 means the smush-it-
together phase of cu-mapped links, and 2 means the final phase of cu-mapped
links.  We do the hide-conflicting stuff only in phase 2, meaning that
normal links by GNU ld can always respect the value of the nonroot flag put
on types in the input.

(One extra thing added as part of this: you can now efficiently delete the
last value returned by ctf_dynhash_next() by calling
ctf_dynhash_next_remove.)

We bring back the ctf-nonroot-linking test with one tweak: linking now works
on mingw as long as you're using the ucrt libc, so re-enable it for better
test coverage on that platform.

libctf/
PR libctf/33047
* ctf-hash.c (ctf_dynhash_next_remove): New.
* ctf-impl.h (struct ctf_dedup) [cd_nonroot_consistency]: New.
* ctf-link.c (ctf_link_deduplicating):  Differentiate between
cu-mapped and non-cu-mapped links, even in the final phase.
* ctf-dedup.c (ctf_dedup_hash_type): Callback prototype addition.
Get the non-root flag and pass it down.
(ctf_dedup_rhash_type): Callback prototype addition. Document
restrictions on use of the nonroot flag.
(ctf_dedup_populate_mappings): Populate cd_nonroot_consistency.
(ctf_dedup_hash_type_fini): New function: delete now-unnecessary
values from cd_nonroot_consistency.
(ctf_dedup_init): Initialize it.
(ctf_dedup_fini): Destroy it.
(ctf_dedup): cu_mapping is now cu_mapping_phase.  Call
ctf_dedup_hash_type_fini.
(ctf_dedup_emit_type): Use cu_mapping_phase and
cd_nonroot_consistency to propagate the non-root flag into outputs
for normal links, and to do name-based conflict checking only for
phase 2 of cu-mapped links.
(ctf_dedup_emit): cu_mapping is now cu_mapping_phase.  Adjust
assertion accordingly.
* testsuite/libctf-writable/ctf-nonroot-linking.c: Bring back.
* testsuite/libctf-writable/ctf-nonroot-linking.lk: Likewise.

3 weeks agolibctf: dedup: improve hiding of conflicting types in the same dict
Nick Alcock [Fri, 30 May 2025 14:26:26 +0000 (15:26 +0100)] 
libctf: dedup: improve hiding of conflicting types in the same dict

If types are conflicting, they are usually moved into separate child dicts
-- but not always.  If they are added to the same dict by the cu-mapping
mechanism (as used e.g. for multi-TU kernel modules), we can easily end
up adding multiple conflicting types with the same name to the same dict.

The mechanism used for turning on the non-root-visible flag in order to do
this had a kludge attached which always hid types with the same name,
whether or not they were conflicting.  This is unnecessary and can hide
types that should not be hidden, as well as hiding bugs.  Remove it, and
replace it with two different approaches:

 - for everything but cu-mapped links (the in-memory first phase of a link
   with ctf_link_add_cu_mapping in force), check for duplicate names if
   types are conflicting, and mark them as hidden if the names are found.
   This will never happen in normal links (in an upcoming commit we will
   suppress doing even this much in such cases).

 - for cu-mapped links, the only case that merges multiple distinct target
   dicts into one, we apply a big hammer and simply hide everything!  The
   non-root flag will be ignored in the next link phase anyway (which dedups
   the cu-mapped pieces against each other), and this way we can be sure
   that merging multiple types cannot incur name clashes at this stage.

The result seems to work: the only annoyance is that when enums with
conflicting enumerators are found in a single cu-mapped child (so, really
multiple merged children), you may end up with every instance of that enum
being hidden for reasons of conflictingness.  I don't see a real way to
avoid that.

libctf/
PR libctf/33047
* ctf-dedup.c (ctf_dedup_emit_type): Only consider non
conflicting types.  Improve type hiding in the presence of clashing
enumerators.  Hide everything when doing a cu-mapped link: they will
be unhidden by the next link pass if nonconflicting.

3 weeks agoRevert "libctf: fix linking of non-root-visible types"
Nick Alcock [Fri, 30 May 2025 14:31:36 +0000 (15:31 +0100)] 
Revert "libctf: fix linking of non-root-visible types"

This reverts commit 87b2f673102884d7c69144c85a26ed5dbaa4f86a.

It is based on a misconception, that hidden types in the deduplicator
input should always be hidden in the output.  For cu-mapped links,
and final links following cu-mapped links, this is not true: we want
to hide inputs if they were conflicting on the output and no more.

We will reintroduce the testcase once a better fix is found.

libctf/
PR libctf/33047
* ctf-dedup.c (ctf_dedup_emit_type): Don't respect the nonroot flag.
* testsuite/libctf-writable/ctf-nonroot-linking.c: Removed.
* testsuite/libctf-writable/ctf-nonroot-linking.lk: Removed.

3 weeks agoaarch64: Support id_aa64fpfr0_el1, id_aa64pfr2_el1
Dmitry Chestnykh [Thu, 29 May 2025 19:13:03 +0000 (22:13 +0300)] 
aarch64: Support id_aa64fpfr0_el1, id_aa64pfr2_el1

3 weeks agogdb/python/guile: fix segfault from nested prefix command creation
Andrew Burgess [Tue, 3 Jun 2025 16:23:10 +0000 (17:23 +0100)] 
gdb/python/guile: fix segfault from nested prefix command creation

A commit I recently pushed:

  commit 0b5023cc71d3af8b18e10e6599a3f9381bc15265
  Date:   Sat Apr 12 09:15:53 2025 +0100

      gdb/python/guile: user created prefix commands get help list

can trigger a segfault if a user tries to create nested prefix
commands.  For example, this will trigger a crash:

  (gdb) python gdb.ParameterPrefix("prefix-1", gdb.COMMAND_NONE)
  (gdb) python gdb.ParameterPrefix("prefix-1 prefix-2", gdb.COMMAND_NONE)

  Fatal signal: Segmentation fault
  ... etc ...

If the user adds an actual parameter under 'prefix-1' before creating
'prefix-2', then everything is fine:

  (gdb) python gdb.ParameterPrefix("prefix-1", gdb.COMMAND_NONE)
  (gdb) python gdb.Parameter('prefix-1 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)
  (gdb) python gdb.ParameterPrefix("prefix-1 prefix-2", gdb.COMMAND_NONE)

The mistake in the above patch is in how gdbpy_parse_command_name is
used.  The BASE_LIST output argument from this function points to the
list of commands for the prefix, not to the prefix command itself.

So when gdbpy_parse_command_name is called for 'prefix-1 prefix-2',
BASE_LIST points to the list of commands associated with 'prefix-1',
not to the actual 'prefix-1' cmd_list_element.

Back in cmdpy_init, from where gdbpy_parse_command_name was called, I
was walking back from the first entry in BASE_LIST to figure out if
this was a "show" prefix command or not.  However, if BASE_LIST is
empty then there is no first item, and this would trigger the
segfault.

The solution it to extend gdbpy_parse_command_name to also return the
prefix cmd_list_element in addition to the existing values.  With this
done, and cmdpy_init updated, the segfault is now avoided.

There's a new test that would trigger the crash without the patch.

And, of course, the above commit also broke guile in the exact same
way.  And the fix is exactly the same.  And there's a guile test too.

NOTE: We should investigate possibly sharing some of this boiler plate
helper code between Python and Guile.  But not in this commit.

Approved-By: Tom Tromey <tom@tromey.com>
3 weeks ago[gdb/testsuite] Fix gdb.base/exec-invalid-sysroot.exp
Tom de Vries [Wed, 4 Jun 2025 07:58:07 +0000 (09:58 +0200)] 
[gdb/testsuite] Fix gdb.base/exec-invalid-sysroot.exp

Since commit d462550c91c ("gdb/testsuite: also compile foll-exec.exp as C++"),
we run into:
...
Running gdb.base/exec-invalid-sysroot.exp ...
gdb compile failed, foll-exec.c: In function 'main':
foll-exec.c:35:52: error: 'EXECD_PROG' undeclared (first use in this function)
   printf ("foll-exec is about to execlp(%s)...\n", EXECD_PROG);
                                                    ^~~~~~~~~~
foll-exec.c:35:52: note: each undeclared identifier is reported only once \
  for each function it appears in
...

Fix this by default-defining EXECD_PROG to "execd-prog".

Tested on x86_64-linux.

3 weeks agoReject compressed sections exceding 4 GiB on LLP64 machines
Rui Ueyama [Tue, 3 Jun 2025 02:16:02 +0000 (11:16 +0900)] 
Reject compressed sections exceding 4 GiB on LLP64 machines

According to the zlib FAQ (*1), zlib does not support compressed data
larger than 4 GiB when the compiler's long type is 32 bits. Therefore,
we need to report an error if a zlib-compressed debug section exceeds
4 GiB on LLP64 machines.

(*1) https://zlib.net/zlib_faq.html#faq32

Signed-off-by: Rui Ueyama <rui314@gmail.com>
3 weeks agosframe: fix PR libsframe/33051
Indu Bhagat [Wed, 4 Jun 2025 06:10:46 +0000 (23:10 -0700)] 
sframe: fix PR libsframe/33051

Fix PR libsframe/Bug 33051 - ASAN: heap-buffer-overflow
../../src/libsframe/sframe.c:1054 in
sframe_get_funcdesc_with_addr_internal

The previous commit 9d2a24349e2 (libsframe: correct binary search for
SFrame FDE) adapted the binary search logic in
sframe_get_funcdesc_with_addr_internal.  Adjusting the upper end of the
search index was missed.

The search must only be done for FDEs starting at index 0 and up until
num_fdes - 1.  Prior logic of searching (before commit 9d2a24349e2) was
a bit different.

libsframe/
* sframe.c: Use the correct high index.

3 weeks agoAutomatic date update in version.in
GDB Administrator [Wed, 4 Jun 2025 00:00:35 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 weeks agogdb/testsuite: also compile foll-exec.exp as C++
Andrew Burgess [Mon, 2 Jun 2025 13:58:51 +0000 (14:58 +0100)] 
gdb/testsuite: also compile foll-exec.exp as C++

For a long time, Fedora GDB has carried a test that performs some
basic testing that GDB can handle 'catch exec' related commands for a
C++ executable.

The exact motivation for this test has been lost in the mists of time,
but looking at the test script, the concern seems to be that GDB would
have problems inserting C++ related internal breakpoints if a non C++
process is execd from a C++ one.

There's no actual GDB fix associated with the Fedora test.  This
usually means that the issue was fixed upstream long ago.  This patch
does seem to date from around 2010ish (or maybe earlier).

Having a look through the upstream tests, I cannot see anything that
covers this sort of thing (C++ to C exec calls), and I figure it
cannot hurt to have some additional testing in this area, and so I
wrote this patch.

I've taken the existing foll-exec.exp test, which compiles a C
executable and then execs a different C executable, and split it into
two copies.

We now have foll-exec-c.exp and foll-exec-c++.exp.  These tests
compile a C and C++ executable respectively.  Then within each of
these scripts both a C and C++ helper application is built, which can
then be execd from the main test executable.

And so, we now cover 4 cases, the initial executable can be C or C++,
and the execd process can be C or C++.

As expected, everything passes.  This is just increasing test
coverage.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
3 weeks agogdb: Make dwarf support optional at compile time
Guinevere Larsen [Wed, 12 Feb 2025 11:25:46 +0000 (08:25 -0300)] 
gdb: Make dwarf support optional at compile time

This commit allows a user to enable or disable dwarf support at
compilation time. To do that, a new configure option is introduced, in
the form of --enable-gdb-dwarf-support (and the accompanying --disable
version). By default, dwarf support is enabled, so no behavior changes
occur if a user doesn't use the new feature. If support is disabled, no
.c files inside the dwarf2/ subfolder will be compiled into the final
binary.

To achieve this, this commit also introduces the new macro
DWARF_FORMAT_AVAILABLE, which guards the definitions of functions
exported from the dwarf reader. If the macro is not defined, there are a
couple behaviors that exported functions may have:
* no-ops: several functions are used to register things at
  initialization time, like unwinders. These are turned into no-ops
  because the user hasn't attempted to read DWARF yet, there's no point
  in warning that DWARF is unavailable.
* warnings: similar to the previous commit, if dwarf would be read or
  used, the funciton will emit the warning "No dwarf support available."
* throw exceptions: If the code that calls a function expects an
  exceptin in case of errors, and has a try-catch block, an error with
  the previous message is thrown.

I believe that the changed functions should probalby be moved to the
dwarf2/public.h header, but that require a much larger refactor, so it
is left as a future improvement.

Finally, the --enable-gdb-compile configure option has been slightly
changed, since compile requires dwarf support. If compile was requested
and dwarf was disabled, configure will throw an error. If the option was
not used, support will follow what was requested for dwarf (warning the
user of what is decided).

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
3 weeks agogdb: wrap mdebug debuginfo reading in ifdefs
Guinevere Larsen [Fri, 3 Jan 2025 17:59:16 +0000 (14:59 -0300)] 
gdb: wrap mdebug debuginfo reading in ifdefs

This commit aims to allow a user to enable or disable mdebug support at
compilation time. To do that, a new configure option is added, called
--enable-gdb-mdebug-support (and the accompanying --disable version). By
default, support is enabled, and if a user decides to disable support,
the file mdebugread.c won't be compiled in the final binary, and the
macro MDEBUG_FORMAT_AVAILABLE won't be defined.

That macro is used to control the definitions of mdebug reading, either
the actual definition in mdebugread.c, or a static inline version that
only emits the following warning:

> No mdebug support available.

Ideally, we'd like to guard the entirity of mdebugread in the macro, but
the alpha-mdebug-tdep file uses those directly, and I don't think we
should restrict alpha hosts to requiring that debug format compiled in,
nor do I understand the tdep file enough to be comfortable disentangling
the requirements.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
3 weeks agogdb: Use multiple minimal_symbol_readers in mipscoff_symfile_read
Guinevere Larsen [Thu, 12 Dec 2024 12:37:36 +0000 (09:37 -0300)] 
gdb: Use multiple minimal_symbol_readers in mipscoff_symfile_read

Currently, mipscoff_symfile_read uses a single minimal_symbol_reader to
get all minimal symbols from mdebug-formatted debuginfo, and from
alphacoff. This pattern has been around since minimal_symbol_reader has
been introduced, and from own research, there's no need to use the same
reader. This made it so mipscoff_symfile_read could call
mdebug_build_psymtabs directly, since the latter needs a reference to
the minsym reader object. The issue is that future commits need a
unified entrance point to read debuginfo, and this pattern is very
different to how elf does mdebug reading.

In fact, the elf mdebug reader does some preparatory steps and then
calls mdebug_build_psymtabs, so what the mips version does is just
spread these preparatory steps through the mipscoff function instead.

To make it easier for future commits to query debuginfo support
dynamically (as opposed to assuming things at compile time), this commit
introduces a new mipsmdebug_build_psymtabs function, which does similar
preparatory steps as elfmdebug_build_psymtabs. It is added to
mdebugread.c to help with maintaining a separation between reading an
objfile (in mipsread.c) and its debuginfo (mdebug), so that in the
future we have an easier time selectively disabling debuginfo formats
at compilation time. This should have no visible changes for the end
user.

The new function must receive the pointers to ecoff_debug_swap and
ecoff_debug_info because finding those structures based on the bfd
object necessitates including the headers libcoff.h and libecoff.h,
and those headers can't be included at the same time as libaout.h
- which mdebugread.c already uses.

Approved-By: Tom Tromey <tom@tromey.com>
3 weeks agoAdd checks for illegal symbol binding and type values when reading ELF symbols.
Nick Clifton [Tue, 3 Jun 2025 16:07:03 +0000 (17:07 +0100)] 
Add checks for illegal symbol binding and type values when reading ELF symbols.

PR 33019

3 weeks agogdb/python/guile: user created prefix commands get help list
Andrew Burgess [Sat, 12 Apr 2025 08:15:53 +0000 (09:15 +0100)] 
gdb/python/guile: user created prefix commands get help list

Consider GDB's builtin prefix set/show prefix sub-commands, if they
are invoked with no sub-command name then they work like this:

  (gdb) show print
  print address:  Printing of addresses is on.
  print array:  Pretty formatting of arrays is off.
  print array-indexes:  Printing of array indexes is off.
  print asm-demangle:  Demangling of C++/ObjC names in disassembly listings is off.
  ... cut lots of lines ...
  (gdb) set print
  List of set print subcommands:

  set print address -- Set printing of addresses.
  set print array -- Set pretty formatting of arrays.
  set print array-indexes -- Set printing of array indexes.
  set print asm-demangle -- Set demangling of C++/ObjC names in disassembly listings.
  ... cut lots of lines ...

  Type "help set print" followed by set print subcommand name for full documentation.
  Type "apropos word" to search for commands related to "word".
  Type "apropos -v word" for full documentation of commands related to "word".
  Command name abbreviations are allowed if unambiguous.
  (gdb)

That is 'show print' lists the values of all settings under the
'print' prefix, and 'set print' lists the help text for all settings
under the 'set print' prefix.

Now, if we try to create something similar using the Python API:

  (gdb) python gdb.ParameterPrefix("my-prefix", gdb.COMMAND_NONE)
  (gdb) python gdb.Parameter("my-prefix foo", gdb.COMMAND_OBSCURE, gdb.PARAM_BOOLEAN)
  (gdb) show my-prefix
  (gdb) set my-prefix

Neither 'show my-prefix' or 'set my-prefix' gives us the same details
relating to the sub-commands that we get with the builtin prefix
commands.

This commit aims to address this.

Currently, in cmdpy_init, when a new command is created, we always set
the commands callback function to cmdpy_function.  It is within
cmdpy_function that we spot that the command is a prefix command, and
that there is no gdb.Command.invoke method, and so return early.

This commit changes things so that the rules are now:

  1. For NON prefix commands, we continue to use cmdpy_function.
  2. For prefix commands that do have a gdb.Command.invoke
     method (i.e. can handle unknown sub-commands), continue to use
     cmdpy_function.
  3. For all other prefix commands, don't use cmdpy_function, instead
     use GDB's normal callback function for set/show prefixes.

This requires splitting the current call to add_prefix_cmd into either
a call to add_prefix_cmd, add_show_prefix_cmd, or
add_basic_prefix_cmd, as appropriate.

After these changes, we now see this:

  (gdb) python gdb.ParameterPrefix("my-prefix", gdb.COMMAND_NONE)     │
  (gdb) python gdb.Parameter("my-prefix foo", gdb.COMMAND_OBSCURE, gdb.PARAM_BOOLEAN)
  (gdb) show my-prefix                                                │
  my-prefix foo:  The current value of 'my-prefix foo' is "off".
  (gdb) set my-prefix
  List of "set my-prefix" subcommands:

  set my-prefix foo -- Set the current value of 'my-prefix foo'.

  Type "help set my-prefix" followed by subcommand name for full documentation.
  Type "apropos word" to search for commands related to "word".
  Type "apropos -v word" for full documentation of commands related to "word".
  Command name abbreviations are allowed if unambiguous.
  (gdb)

Which matches how a prefix defined within GDB would act.

I have made the same changes to the Guile API.

3 weeks agoClean up comment in dw2-ranges-psym-warning.exp
Tom Tromey [Tue, 3 Jun 2025 14:05:41 +0000 (08:05 -0600)] 
Clean up comment in dw2-ranges-psym-warning.exp

This removes a trailing backslash from a comment in
dw2-ranges-psym-warning.exp.  This backslash causes Emacs to try to
reindent the next line.  This happens because comments are weird in
Tcl -- they are not exactly syntactic and the backslash still acts as
a line-continuation marker here.

3 weeks agosframe: doc: add date to the pdf output
Indu Bhagat [Tue, 3 Jun 2025 13:54:55 +0000 (06:54 -0700)] 
sframe: doc: add date to the pdf output

libsframe/doc/
* sframe-spec.texi: Include date with each publication.

3 weeks agoHandle dynamic DW_AT_data_bit_offset
Tom Tromey [Tue, 20 May 2025 16:45:07 +0000 (10:45 -0600)] 
Handle dynamic DW_AT_data_bit_offset

In Ada, a field can have a dynamic bit offset in its enclosing record.

In DWARF 3, this was handled using a dynamic
DW_AT_data_member_location, combined with a DW_AT_bit_offset -- this
combination worked out ok because in practice GNAT only needs a
dynamic byte offset with a fixed offset within the byte.

However, this approach was deprecated in DWARF 4 and then removed in
DWARF 5.  No replacement approach was given, meaning that in strict
mode there is no way to express this.

This is a DWARF bug, see

    https://dwarfstd.org/issues/250501.1.html

In a discussion on the DWARF mailing list, a couple people mentioned
that compilers could use the obvious extension of a dynamic
DW_AT_data_bit_offset.  I've implemented this for LLVM:

    https://github.com/llvm/llvm-project/pull/141106

In preparation for that landing, this patch implements support for
this construct in gdb.

New in v2: renamed some constants and added a helper method, per
Simon's review.

New in v3: more renamings.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
3 weeks agogdb: support zero inode in generate-core-file command
Andrew Burgess [Wed, 7 May 2025 11:58:41 +0000 (12:58 +0100)] 
gdb: support zero inode in generate-core-file command

It is possible, when creating a shared memory segment (i.e. with
shmget), that the id of the segment will be zero.

When looking at the segment in /proc/PID/smaps, the inode field of the
entry holds the shared memory segment id.

And so, it can be the case that an entry (in the smaps file) will have
an inode of zero.

When GDB generates a core file, with the generate-core-file (or its
gcore alias) command, the shared memory segment should be written into
the core file.

Fedora GDB has, since 2008, carried a patch that tests this case.
There is no fix for GDB associated with the test, and unfortunately,
the motivation for the test has been lost to the mists of time.  This
likely means that a fix was merged upstream without a suitable test,
but I've not been able to find and relevant commit.  The test seems to
be checking that the shared memory segment with id zero, is being
written to the core file.

While looking at this test and trying to work out if it should be
posted upstream, I saw that GDB does appear to write the shared memory
segment into the core file (as expected), which is good.  However, GDB
still isn't getting this case exactly right, there appears to be no
NT_FILE entry for the shared memory mapping if the mapping had an id
of zero.

In gcore_memory_sections (gcore.c) we call back into linux-tdep.c (via
the gdbarch_find_memory_regions call) to correctly write the shared
memory segment into the core file, however, in
linux_make_mappings_corefile_notes, when we use
linux_find_memory_regions_full to create the NT_FILE note, we call
back in to dump_note_entry_p for each mapping, and in here we reject
any mapping with a zero inode.

The result of this, is that, for a shared memory segment with a
non-zero id, after loading the core file, the shared memory segment
will appear in the 'proc info mappings' output.  But, for a shared
memory segment with a zero id, the segment will not appear in the
'proc info mappings' output.

I initially tried just dropping the inode check in this function (see
previous commit 1e21c846c27, which I then reverted in commit
998165ba99a.

The problem with dropping the inode check is that the special kernel
mappings, e.g. '[vvar]' would now get a NT_FILE entry.  In fact, any
special entry except '[vdso]' and '[vsyscall]' which are specifically
checked for in dump_note_entry_p would get a NT_FILE entry, which is
not correct.

So, instead, I propose that if the inode is zero, and the filename
starts with '[' and finished with ']' then we should not create a
NT_FILE entry.  But otherwise a zero inode should not prevent a
NT_FILE entry being created.

The test for this change is a bit tricky.  The original Fedora
test (mentioned above) has a loop that tries to grab the shared memory
mapping with id zero.  This was, unfortunately, not very reliable.

I tried to make this more reliable by going multi-threaded, and
waiting for longer, see my proposal here:

  https://inbox.sourceware.org/gdb-patches/0d389b435cbb0924335adbc9eba6cf30b4a2c4ee.1741776651.git.aburgess@redhat.com

But this was still not great.  On further testing this was only
passing (i.e. managing to find the shared memory mapping with id zero)
about 60% of the time.

However, I realised that GDB finds the shared memory id by reading the
/proc/PID/smaps file.  But we don't really _need_ the shared memory id
for anything, we just use the value (as an inode) to decide if the
segment should be included in the core file or not.  The id isn't even
written to the core file.  So, if we could intercept the read of the
smaps file, then maybe, we could lie to GDB, and tell it that the id
was zero, and then see how GDB handles this.

And luckily, we can do that using a preload library!

We already have a test that uses a preload library to modify GDB, see
gdb.threads/attach-slow-waitpid.exp.

So, I have created a new preload library.  This one intercepts open,
open64, close, read, and pread.  When GDB attempts to open
/proc/PID/smaps, the library spots this and loads the file contents
into a memory buffer.  The buffer is then modified to change the id of
any shared memory mapping to zero.  Any reads from this file are
served from the modified memory buffer.

I tested on x86-64, AArch64, PPC, s390, and ARM, all running various
versions of GNU/Linux.  The requirement for open64() came from my ARM
testing.  The other targets used plain open().

And so, the test is now simple.  Start GDB with the preload library in
place, start the inferior and generate a core file.  Then restart GDB,
load the core file, and check the shared memory mapping was included.
This test will fail with an unpatched GDB, and succeed with the patch
applied.

Tested-By: Guinevere Larsen <guinevere@redhat.com>
3 weeks agogdb: handle struct and union types in evaluate_subexp_for_address_base
Piotr Rudnicki [Fri, 30 May 2025 13:21:49 +0000 (15:21 +0200)] 
gdb: handle struct and union types in evaluate_subexp_for_address_base

Suppose a function returns a struct and a method of that struct is
called.  E.g.:

  struct S
  {
    int a;
    int get () { return a; }
  };

  S f ()
  {
    S s;
    s.a = 42;
    return s;
  }

  ...
  int z = f().get();
  ...

GDB is able to evaluate the expression:

  (gdb) print f().get()
  $1 = 42

However, type-checking the expression fails:

  (gdb) ptype f().get()
  Attempt to take address of value not located in memory.

This happens because the `get` function takes an implicit `this`
pointer, which in this case is the value returned by `f()`, and GDB
wants to get an address for that value, as if passing the implicit
this pointer.  However, during type-checking, the struct value
returned by `f()` is a `not_lval`.

A similar issue exists for union types, where methods called on
temporary union objects would fail type-checking in the same way.

Address the problems by handling `TYPE_CODE_STRUCT` and
`TYPE_CODE_UNION` in `evaluate_subexp_for_address_base`.

With this change, for struct's method call, we get

  (gdb) ptype f().get()
  type = int

Add new test cases to file gdb.cp/chained-calls.exp to test this change.

Regression-tested in X86-64 Linux.

3 weeks agogdb: remove unused argument in evaluate_subexp_for_address_base
Piotr Rudnicki [Fri, 30 May 2025 13:14:47 +0000 (15:14 +0200)] 
gdb: remove unused argument in evaluate_subexp_for_address_base

Remove the unused 'struct expression *exp' parameter from
evaluate_subexp_for_address_base and also do some format cleanup.

3 weeks ago[gdb/cli] Use captured per_command_time in worker threads
Tom de Vries [Tue, 3 Jun 2025 06:59:58 +0000 (08:59 +0200)] 
[gdb/cli] Use captured per_command_time in worker threads

With test-case gdb.base/maint.exp, I ran into:
...
(gdb) file maint^M
Reading symbols from maint...^M
(gdb) mt set per-command on^M
(gdb) Time for "DWARF indexing worker": ...^M
Time for "DWARF indexing worker": ...^M
Time for "DWARF indexing worker": ...^M
Time for "DWARF indexing worker": ...^M
Time for "DWARF skeletonless type units": ...^M
Time for "DWARF add parent map": ...^M
Time for "DWARF finalize worker": ...^M
Time for "DWARF finalize worker": ...^M
Time for "DWARF finalize worker": ...^M
Time for "DWARF finalize worker": ...^M
Time for "DWARF finalize worker": ...^M
FAIL: $exp: warnings: per-command: mt set per-command on (timeout)
mt set per-command off^M
2025-05-31 09:33:44.711 - command started^M
(gdb) PASS: $exp: warnings: per-command: mt set per-command off
...

I didn't manage to reproduce this by rerunning the test-case, but it's fairly
easy to reproduce using a file with more debug info, for instance gdb:
...
$ gdb -q -batch -ex "file build/gdb/gdb" -ex "mt set per-command on"
...

Due to the default "mt dwarf synchronous" == off, the file command starts
building the cooked index in the background, and returns immediately without
waiting for the result.

The subsequent "mt set per-command on" implies "mt set per-command time on",
which switches on displaying of per-command execution time.

The "Time for" lines are the result of those two commands, but these lines
shouldn't be there because "mt per-command time" == off at the point of
issuing the file command.

Fix this by capturing the per_command_time variable, and using the captured
value instead.

Tested on x86_64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
PR cli/33039
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33039

3 weeks agoAutomatic date update in version.in
GDB Administrator [Tue, 3 Jun 2025 00:00:28 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 weeks agogdb/dwarf2: update call_site::target comment
Simon Marchi [Mon, 2 Jun 2025 20:31:12 +0000 (20:31 +0000)] 
gdb/dwarf2: update call_site::target comment

This comment refers to the field location kind enum, even though call
sites were moved to their own enum in 7eb21cc70224 ("Change
call_site_target to use custom type and enum").  Update it.

Change-Id: I089923170c919853efb2946529221a4b55e720c1

3 weeks agogdb: use quoted filename completion for the shell command
Andrew Burgess [Mon, 19 May 2025 19:54:54 +0000 (20:54 +0100)] 
gdb: use quoted filename completion for the shell command

With the quoted filename completion work that I did last year the
deprecated_filename_completer function will now only complete a single
word as a filename, for example:

  (gdb) save breakpoints /tm<TAB>

The 'save breakpoints' command uses the deprecated_filename_completer
completion function.  In the above '/tm' will complete to '/tmp/' as
expected.  However, if you try this:

  (gdb) save breakpoints /tmp/ /tm<TAB>

The second '/tm' will not complete for GDB 16.x, but will complete
with GDB 15.x as GDB 15.x is before my changes were merged.

What's actually happening here is that, before my changes, the
filename completion was breaking words on white space, so in the above
the first '/tmp/' and the second '/tm' are seen as separate words for
completion, the second word is therefore seen as the start of a new
filename.

After my changes, deprecated_filename_completer allows spaces to be
part of the filename, so in the above, GDB is actually trying to
complete a filename '/tmp/ /tm' which likely doesn't exist, and so
completion stops.

This change for how deprecated_filename_completer works makes sense,
commands like 'save breakpoints' take their complete command arguments
and treat it as a single filename, so given this:

  (gdb) save breakpoints /tmp/ /tm<ENTER>

GDB really will try to save breakpoints to a file called '/tmp/ /tm',
weird as that may seem.  How GDB interprets the command arguments
didn't change with my completion patches, I simply brought completion
into line with how GDB interprets the arguments.

The patches I'm talking about here are this set:

  * 4076f962e8c gdb: split apart two different types of filename completion
  * dc22ab49e9b gdb: deprecated filename_completer and associated functions
  * 35036875913 gdb: improve escaping when completing filenames
  * 1d1df753977 gdb: move display of completion results into completion_result class
  * bbbfe4af4fb gdb: simplify completion_result::print_matches
  * 2bebc9ee270 gdb: add match formatter mechanism for 'complete' command output
  * f2f866c6ca8 gdb: apply escaping to filenames in 'complete' results
  * 8f87fcb1daf gdb: improve gdb_rl_find_completion_word for quoted words
  * 67b8e30af90 gdb: implement readline rl_directory_rewrite_hook callback
  * 1be3b2e82f7 gdb: extend completion of quoted filenames to work in brkchars phase
  * 9dedc2ac713 gdb: fix for completing a second filename for a command
  * 4339a3ffc39 gdb: fix filename completion in the middle of a line

Bug PR gdb/32982 identifies a problem with the shell command;
completion broke between 15.x and 16.x.  The shell command also uses
deprecated_filename_completer for completion.  But consider a shell
command line:

  (gdb) shell ls /tm<TAB>

The arguments to the shell command are 'ls /tm' at the point <TAB> is
pressed.  Under the old 15.x completion GDB would split the words on
white space and then try to complete '/tm' as a filename.

Under the 16.x model, GDB completes all the arguments as a single
filename, that is 'ls /tm', which is unlikely to match any filenames,
and so completion fails.

The fix is to write a custom completion function for the shell_command
function (cli/cli-cmds.c), this custom completion function will skip
forward to find the last word in the arguments, and then try to
complete that, so in the above example, GDB will skip over 'ls ', and
then tries to complete '/tm', which is exactly what we want.

Given that the filenames passed to the shell command are forwarded to
an actual shell, I have switched over the new quoted filename
completion function for the shell command, this means that white space
within a filename will be escaped with a backslash by the completion
function, which is likely what the user wants, this means the filename
will arrive in the (actual) shell as a single word, rather than
splitting on white space and arriving as two words.

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

Reviewed-By: Tom Tromey <tom@tromey.com>
3 weeks agoFix DAP defer_stop_events implementation
Tom Tromey [Thu, 13 Feb 2025 14:24:08 +0000 (07:24 -0700)] 
Fix DAP defer_stop_events implementation

DAP requests have a "defer_stop_events" option that is intended to
defer the emission of any "stopped" event until after the current
request completes.  This was needed to handle async continues like
"finish &".

However, I noticed that sometimes DAP tests can fail, because a stop
event does arrive before the response to the "stepOut" request.  I've
only noticed this when the machine is fairly loaded -- for instance
when I'm regression-testing a series, it may occur in some of the
tests mid-series.

I believe the problem is that the implementation in the "request"
function is incorrect -- the flag is set when "request" is invoked,
but instead it must be deferred until the request itself is run.  That
is, the setting must be captured in one of the wrapper functions.

Following up on this, Simon pointed out that introducing a delay
before sending a request's response will cause test case failures.
That is, there's a race here that is normally hidden.

Investigation showed that that deferred requests can't force event
deferral.  This patch implements this; but more testing showed many
more race failures.  Some of these are due to how the test suite is
written.

Anyway, in the end I took the radical approach of deferring all events
by default.  Most DAP requests are asynchronous by nature, so this
seemed ok.  The only case I found that really required this is
pause.exp, where the test (rightly) expects to see a 'continued' event
while performing an inferior function call.

I went through all events and all requests and tried to convince
myself that this patch will cause acceptable behavior in every case.
However, it's hard to be completely sure about this approach.  Maybe
there are cases that do still need an event before the response, but
we just don't have tests for them.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32685
Acked-By: Simon Marchi <simon.marchi@efficios.com>
3 weeks agogdb: introduce a per-interpreter event servicing method
Patrick Monnerat [Fri, 30 May 2025 17:16:56 +0000 (19:16 +0200)] 
gdb: introduce a per-interpreter event servicing method

This allows an interpreter to override internal calls to
gdb_do_one_event in case the former needs to handle alternate event
sources.

The default action is to call gdb_do_one_event and this is not overriden
in current internal interpreters. However this feature allows to easily
embed Tcl/Tk in insight that needs to concurrently handle Tcl events for
GUI handling.

In all cases, an interpreter event servicing method must call
gdb_do_one_event at some point.

All internal event servicing calls from gdb now direct to the
interpreter-specific method rather than gdb_do_one_event itself.

3 weeks ago[gdb/python] Reimplement F405 fix
Tom de Vries [Mon, 2 Jun 2025 04:44:59 +0000 (06:44 +0200)] 
[gdb/python] Reimplement F405 fix

At commit 34b0776fd73^, flake8 reports the following F405 warnings:
...
$ pre-commit run flake8 --file gdb/python/lib/gdb/__init__.py
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

F405 'flush' may be undefined, or defined from star imports: _gdb
F405 'write' may be undefined, or defined from star imports: _gdb
F405 'STDOUT' may be undefined, or defined from star imports: _gdb
F405 'STDERR' may be undefined, or defined from star imports: _gdb
  ...
F405 'selected_inferior' may be undefined, or defined from star imports: _gdb
F405 'execute' may be undefined, or defined from star imports: _gdb
F405 'parameter' may be undefined, or defined from star imports: _gdb
...

The F405s are addressed by commit 34b0776fd73 ('Suppress some "undefined"
warnings from flake8').

The problem indicated by the first F405 is that the use of flush here:
...
class _GdbFile(object):
     ...
    def flush(self):
        flush(stream=self.stream)
...
cannot be verified by flake8.  It concludes that either, flush is undefined,
or it is defined by this "star import":
...
from _gdb import *  # noqa: F401,F403
...

In this particular case, indeed flush is defined by the star import.

This can be addressed by simply adding:
...
        flush(stream=self.stream)  # noqa: F405
...
but that has only effect for flake8, so other analyzers may report the same
problem.

The commit 34b0776fd73 addresses it instead by adding an "import _gdb" and
adding a "_gdb." prefix:
...
        _gdb.flush(stream=self.stream)
...

This introduces a second way to specify _gdb names, but the first one still
remains, and occasionally someone will use the first one, which then requires
fixing once flake8 is run [1].

While this works to silence the warnings, there is a problem: if a developer
makes a typo:
...
        _gdb.flash(stream=self.stream)
...
this is not detected by flake8.

This matters because although the python import already complains:
...
$ gdb -q -batch -ex "python import gdb"
Exception ignored in: <gdb._GdbFile object at 0x7f6186d4d7f0>
Traceback (most recent call last):
  File "__init__.py", line 63, in flush
    _gdb.flash(stream=self.stream)
AttributeError: module '_gdb' has no attribute 'flash'
...
that doesn't trigger if the code is hidden behind some control flow:
...
if _var_mostly_false:
    flash(stream=self.stream)
...

Instead, fix the F405s by reverting commit 34b0776fd73 and adding a second
import of _gdb alongside the star import which lists the names used locally:
...
 from _gdb import *  # noqa: F401,F403
+from _gdb import (
+    STDERR,
+    STDOUT,
+    Command,
+    execute,
+    flush,
+    parameter,
+    selected_inferior,
+    write,
+)
...

This gives the following warnings for the flash typo:
...
31:1: F401 '_gdb.flush' imported but unused
70:5: F811 redefinition of unused 'flush' from line 31
71:9: F405 'flash' may be undefined, or defined from star imports: _gdb
...

The benefits of this approach compared to the previous one are that:
- the typo is noticed, and
- when using a new name, the F405 fix needs to be done once (by adding it to
  the explicit import list), while previously the fix had to be applied to
  each use (by adding the "_gdb." prefix).

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] Commit 475799b692e ("Fix some pre-commit nits in gdb/__init__.py")

3 weeks agoAutomatic date update in version.in
GDB Administrator [Mon, 2 Jun 2025 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 weeks agoHave bfd_thread_init fail when thread-local storage is unavailable
Tom Tromey [Sun, 1 Jun 2025 19:58:18 +0000 (13:58 -0600)] 
Have bfd_thread_init fail when thread-local storage is unavailable

If thread-local storage is unavailable, bfd_thread_init should fail,
because in this case BFD can't be used from multiple threads -- it
relies on TLS working.

3 weeks ago[gdb/tdep] Fix gdb.ada/finish-var-size.exp on ppc64le-linux
Tom de Vries [Sun, 1 Jun 2025 12:06:01 +0000 (14:06 +0200)] 
[gdb/tdep] Fix gdb.ada/finish-var-size.exp on ppc64le-linux

On openSUSE Tumbleweed ppc64le-linux using gcc 14.3.0, with a gdb 16.3 based
package and test-case gdb.ada/finish-var-size.exp, I run into:
...
(gdb) finish^M
Run till exit from #0  pck.get (value=true) at pck.adb:19^M
0x0000000100004a20 in p () at finish-var-size/p.adb:18^M
18        V : Result_T := Get (True);^M
Value returned is $1 = <error reading variable: \
  Cannot access memory at address 0x0>^M
(gdb) FAIL: gdb.ada/finish-var-size.exp: finish
...

Function pck.get returns type Result_T:
...
  type Array_Type is array (1 .. 64) of Integer;

  type Maybe_Array (Defined : Boolean := False) is
    record
      Arr : Array_Type;
      Arr2 : Array_Type;
    end record;

  type Result_T (Defined : Boolean := False) is
    record
      case Defined is
        when False =>
          Arr : Maybe_Array;
        when True =>
          Payload : Boolean;
      end case;
    end record;
...
and uses r3 as address of the return value, which means
RETURN_VALUE_STRUCT_CONVENTION, but while executing finish_command we do:
...
      return_value
= gdbarch_return_value_as_value (gdbarch,
                                         read_var_value (sm->function, nullptr,
                                                         callee_frame),
                                         val_type, nullptr, nullptr, nullptr);
...
and get:
...
(gdb) p return_value
$1 = RETURN_VALUE_REGISTER_CONVENTION
...

This is caused by this check in ppc64_sysv_abi_return_value:
...
   /* In the ELFv2 ABI, aggregate types of up to 16 bytes are
      returned in registers r3:r4.  */
   if (tdep->elf_abi == POWERPC_ELF_V2
       && valtype->length () <= 16
...
which succeeds because valtype->length () == 0.

Fix this by also checking for !TYPE_HAS_DYNAMIC_LENGTH (valtype).

[ I also tested a version of this patch using "!is_dynamic_type (valtype)"
instead, but ran into a regression in test-case gdb.ada/variant-record.exp,
because type T:
...
    Length : constant Positive := 8;
    subtype Name_T is String (1 .. Length);

    type A_Record_T is
      record
        X1 : Natural;
        X2 : Natural;
      end record;

    type Yes_No_T is (Yes, No);
    type T (Well : Yes_No_T := Yes) is
      record
case Well is
          when Yes =>
            Name : Name_T;
          when No =>
            Unique_Name : A_Record_T;
end case;
      end record;
...
while being dynamic, also has a non-zero size, and is small enough to be
returned in registers r3:r4. ]

Fixing this causes the test-case to fail with the familiar:
...
warning: Cannot determine the function return value.
Try compiling with -fvar-tracking.
...
and indeed using -fvar-tracking makes the test-case pass.

Tested on ppc64le-linux.

PR tdep/33000
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33000

3 weeks agoweakref gas internal error
Alan Modra [Sat, 31 May 2025 04:19:24 +0000 (13:49 +0930)] 
weakref gas internal error

This horrible testcase (cleaned up from oss-fuzz)
 r=x*2
 x=r-r
 .weakref r,x
 r=r-5
triggers resolve_symbol_value "gas_assert (final_val == 0)" in weakref
handling.

* read.c (assign_symbol): Clear weakrefr.

3 weeks agodecompress_contents: fuss over 32-bit long
Alan Modra [Sun, 1 Jun 2025 03:37:58 +0000 (13:07 +0930)] 
decompress_contents: fuss over 32-bit long

Some 64-bit compilers have a 32-bit long, which could result in an
endless loop if uncompressed_size is larger than 4G.

3 weeks agoPR 33033, Support compressed debug sections larger than 4 GiB
Rui Ueyama [Sat, 31 May 2025 12:16:34 +0000 (21:16 +0900)] 
PR 33033, Support compressed debug sections larger than 4 GiB

z_stream's avail_in and avail_out are defined as "unsigned int", so it
cannot decode an entire compressed stream in one pass if the stream is
larger than 4 GiB. The simplest solution to this problem is to use zlib's
convenient uncompress2() function, which handles the details for us.

Signed-off-by: Rui Ueyama <rui314@gmail.com>
3 weeks agoAutomatic date update in version.in
GDB Administrator [Sun, 1 Jun 2025 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 weeks agoDo not allocate macro_scope on the heap
Tom Tromey [Thu, 29 May 2025 23:23:04 +0000 (17:23 -0600)] 
Do not allocate macro_scope on the heap

I noticed that there's no particular reason to allocate the
macro_scope objects on the heap.  They can be passed around by value
just as easily.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
3 weeks agoDefine TLS in bfd.c if not already defined
Tom Tromey [Fri, 30 May 2025 13:04:03 +0000 (07:04 -0600)] 
Define TLS in bfd.c if not already defined

If configure decides that thread-local storage isn't available, it
does not define "TLS".  However, this is used unconditionally in a
definition.  So, define it if it isn't already defined.

3 weeks agoAutomatic date update in version.in
GDB Administrator [Sat, 31 May 2025 00:00:25 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 weeks agoPR 33020 segv in _bfd_elf_strtab_offset
Alan Modra [Fri, 30 May 2025 22:43:20 +0000 (08:13 +0930)] 
PR 33020 segv in _bfd_elf_strtab_offset

The PR fuzzer testcase creates a SHT_NOBITS .debug_info section, then
triggers a bug in --compress-debug-sections=zlib whereby sh_name is
set to -1 in elf_fake_sections as a flag to indicate the name is not
set yet (may change to zdebug_*), but the section never hits the debug
compression code in assign_file_positions_for_non_load_sections that
is responsible for setting sh_name.

PR 33020
* elf.c (_bfd_elf_init_reloc_shdr): Rename delay_st_name_p
param to delay_sh_name_p.
(elf_fake_sections): Rename delay_st_name_p to delay_sh_name_p.
Don't set delay_sh_name_p for no contents debug sections.

3 weeks agoRevert "Replace assertions with error return values, thus ensuring an illegal memory...
Alan Modra [Fri, 30 May 2025 22:45:45 +0000 (08:15 +0930)] 
Revert "Replace assertions with error return values, thus ensuring an illegal memory access does not occur."

This reverts commit 429fb15134cfbdafe2b203086ee05d827726b63b.

3 weeks agogprofng: Use __x86_64__ instead of __x86_64
Andrew Pinski [Fri, 30 May 2025 18:37:09 +0000 (11:37 -0700)] 
gprofng: Use __x86_64__ instead of __x86_64

With some compilers, only __x86_64__ is defined so use that
instead of __x86_64.

gprofng/ChangeLog
2025-05-30  Andrew Pinski  <quic_apinski@quicinc.com>
* common/core_pcbe.c: s/__x86_64/__x86_64__/.
* common/cpu_frequency.h: Likewise.
* common/cpuid.c: Likewise.
* common/gp-defs.h: Likewise.
* common/hwctable.c: Likewise.
* libcollector/libcol-i386-dis.c: Likewise.
* libcollector/libcol_util.h: Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 weeks agoRemove some Rust expression helpers
Tom Tromey [Fri, 30 May 2025 20:07:57 +0000 (14:07 -0600)] 
Remove some Rust expression helpers

When I did the big expression conversion, I left some helper functions
lying around, primarily because the conversion was already quite large
and I didn't want to add on.

This patch removes a couple such helpers, turning them into methods on
the appropriate operation objects.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
3 weeks agogdb: fix DW_AT_compile_unit -> DW_TAG_compile_unit in comment
Simon Marchi [Fri, 30 May 2025 20:19:40 +0000 (16:19 -0400)] 
gdb: fix DW_AT_compile_unit -> DW_TAG_compile_unit in comment

While (mistakenly) grepping for DW_AT_compile_unit, I found this typo.

Change-Id: I04d97d7b1b27eacfca9da3853711b6092d330575

3 weeks agoPrevent illegal memory access when generating map file entries for ifuncs removed...
Nick Clifton [Fri, 30 May 2025 14:31:14 +0000 (15:31 +0100)] 
Prevent illegal memory access when generating map file entries for ifuncs removed by garbage collection

3 weeks agoRequire Python 3.4
Tom Tromey [Wed, 16 Oct 2024 15:58:14 +0000 (09:58 -0600)] 
Require Python 3.4

I believe we previously agreed that the minimum supported Python
version should be 3.4.  This patch makes this change, harmonizing the
documentation (which was inconsistent about the minimum version) and
the code.

New in v2: rebased, and removed a pre-3.4 workaround from __init__.py.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-by: Kevin Buettner <kevinb@redhat.com>
Acked-By: Tom de Vries <tdevries@suse.de>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31870

3 weeks agoReplace assertions with error return values, thus ensuring an illegal memory access...
Nick Clifton [Fri, 30 May 2025 12:00:59 +0000 (13:00 +0100)] 
Replace assertions with error return values, thus ensuring an illegal memory access does not occur.

PR 33020

3 weeks agoUpdated Malay translation for the bfd/ sub-directory
Nick Clifton [Fri, 30 May 2025 09:04:49 +0000 (10:04 +0100)] 
Updated Malay translation for the bfd/ sub-directory

3 weeks agoelf symbol size
Alan Modra [Thu, 29 May 2025 10:40:28 +0000 (20:10 +0930)] 
elf symbol size

This changes elf_obj_sy.size from being malloc'd to being on the notes
obstack.  That means no code needs to free these expressions, which in
turn means that the size expression can be shared when cloning
symbols.  Nothing modifies the size expressions except when resolving.
In all cases I could see, if the size changes the entire expression is
replaced.

The patch also extracts code from elf_copy_symbol_attributes into a
separate function for use by riscv and aarch64.

* config/obj-elf.c (elf_obj_symbol_clone_hook): Delete.
(elf_copy_symbol_size): New function, extracted and modified from..
(elf_copy_symbol_attributes): ..here.
(obj_elf_size): Don't free size and use notes_alloc.
(elf_frob_symbol): Don't free size.
(elf_format_ops): Zero symbol_clone_hook.
* config/obj-elf.h (elf_obj_symbol_clone_hook): Delete.
(obj_symbol_clone_hook): Don't define.
(elf_copy_symbol_size): Declare.
* config/tc-aarch64.c (aarch64_elf_copy_symbol_attributes): Delete.
* config/tc-aarch64.h (OBJ_COPY_SYMBOL_ATTRIBUTES): Define as
elf_copy_symbol_size.
* config/tc-alpha.c (s_alpha_end): notes_alloc symbol size exp.
* config/tc-ia64.c (dot_endp): Likewise.
* config/tc-kvx.c (kvx_endp): Likewise.
* config/tc-mips.c (s_mips_end): Likewise.
* config/tc-riscv.c (riscv_elf_copy_symbol_attributes): Delete.
* config/tc-riscv.h (OBJ_COPY_SYMBOL_ATTRIBUTES): Define as
elf_copy_symbol_size.

3 weeks agogas symbol_remove
Alan Modra [Thu, 29 May 2025 03:20:45 +0000 (12:50 +0930)] 
gas symbol_remove

If a symbol is at the start of the symbol chain then symbol_rootP
points at the symbol and symbol->x->previous is NULL.  Testing either
condition is sufficient, there is no need to test both.  Similarly for
the symbol at the end of the symbol chain.

I'm testing the previous/next pointer because it's most likely that
the symbol is not at the start/finish of the chain and thus we need to
use that pointer.

* symbols.c (symbol_remove): Tidy list handling.
(symbol_append, symbol_clone, symbol_insert): Likewise.

3 weeks agoReduce rs_align_code memory for small alignments
Alan Modra [Tue, 27 May 2025 01:10:59 +0000 (10:40 +0930)] 
Reduce rs_align_code memory for small alignments

On x86, MAX_MEM_FOR_RS_ALIGN_CODE is 35, when the most common
alignment is 2**3 or 2**4, where the max memory required for the
alignment nops is 7 and 15 bytes respectively.  So there is some
memory wasted since commit 83d94ae428b1.  It's not a large amount,
especially considering that frag overhead on x86_46 is 144 bytes,
but even so I'd rather not be blamed for increasing gas memory usage.

So to reduce the memory we'd like to take the alignment into
consideration when initialising an rs_align_code frag.  The only
difficulty here is start_bundle making an rs_align_code frag with an
alignment of zero initially, then later increasing the alignment.  We
change that to use the bundle alignment when setting up the frag.  I
think that is sufficient as bundle_align_p2 can't change in the middle
of a start_bundle/finish_bundle sequence.

I haven't modified any targets other than x86 in this patch.  Most
won't benefit much due to using fairly small MAX_MEM_FOR_RS_ALIGN_CODE.

* read.c (start_bundle): Create rs_align_code frag with
bundle_align_p2 alignment, then set to zero alignment.
(finish_bundle): Adjust comment.
* frags.c (MAX_MEM_FOR_RS_ALIGN_CODE): Pass p2align and max
to macro.
* config/tc-i386.h (HANDLE_ALIGN): Assert that max_bytes is
sufficient for nop padding.
(max_mem_for_rs_align_code): New inline function.
(MAX_MEM_FOR_RS_ALIGN_CODE): Use it.
* config/tc-aarch64.h: Adjust MAX_MEM_FOR_RS_ALIGN_CODE.
* config/tc-alpha.h: Likewise.
* config/tc-arc.h: Likewise.
* config/tc-arm.h: Likewise.
* config/tc-epiphany.h: Likewise.
* config/tc-frv.h: Likewise.
* config/tc-ia64.h: Likewise.
* config/tc-kvx.h: Likewise.
* config/tc-loongarch.h: Likewise.
* config/tc-m32r.h: Likewise.
* config/tc-metag.h: Likewise.
* config/tc-mips.h: Likewise.
* config/tc-nds32.h: Likewise.
* config/tc-ppc.h: Likewise.
* config/tc-riscv.h: Likewise.
* config/tc-rl78.h: Likewise.
* config/tc-rx.h: Likewise.
* config/tc-score.h: Likewise.
* config/tc-sh.h: Likewise.
* config/tc-sparc.h: Likewise.
* config/tc-spu.h: Likewise.
* config/tc-tilegx.h: Likewise.
* config/tc-tilepro.h: Likewise.
* config/tc-visium.h: Likewise.
* config/tc-xtensa.h: Likewise.

3 weeks agoAutomatic date update in version.in
GDB Administrator [Fri, 30 May 2025 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 weeks agogdb: update corner case when canonicalizing riscv syscall names
Guinevere Larsen [Wed, 23 Apr 2025 14:26:51 +0000 (11:26 -0300)] 
gdb: update corner case when canonicalizing riscv syscall names

The script syscalls/riscv-canonicalize-syscall-gen.py has been recently
introduced to help support record-full in riscv systems.  However, it
was developed before commit 432eca4113d5748ad284a068873455f9962b44fe,
which made the GDB enum more consistent, which forced the python script
to have a corner case for the "gdb_old_mmap" case.

Since the aforementioned commit has already been merged, we need to
update the special case for the mmap syscall. A special case is still
needed because the script would expect that the glibc sources call the
syscall "old_mmap", or that gdb call it "gdb_sys_mmap", neither of which
happens unfortunately.

This commit doesn't change the .c file because it was already fixed by a
different commit, 65ab41b7d5c612b6000b28f4c50bb256b2a9e22b, which was
pushed as obvious to fix the build issues.

Approved-By: Tom Tromey <tom@tromey.com>
4 weeks agogdb/dap: fix completion request for empty strings
Jorenar [Sun, 25 May 2025 15:40:25 +0000 (17:40 +0200)] 
gdb/dap: fix completion request for empty strings

When DAP completion requests receives empty string to complete,
the script crashes due trying to access element -1 from list
being a result of `text.splitlines()` (which for `text == ""`
evaluates into empty list).

This patch adds simple check if `text` is populated, and when it
is not, skips transformations and assigns correct result directly.

Approved-By: Tom Tromey <tom@tromey.com>
4 weeks agogdb, gdbsupport: fix all `;;` instances
Simon Marchi [Thu, 29 May 2025 15:13:08 +0000 (11:13 -0400)] 
gdb, gdbsupport: fix all `;;` instances

I forgot to fix a `;;` typo when pushing a previous patch.  Fix it, and
fix all the other instances I could find in the code base.

Change-Id: I298f9ffb1a5157925076ef67b439579b1aeeaa2b

4 weeks agoFix build when RUSAGE_THREAD is not available & add warning
Pedro Alves [Sat, 17 May 2025 21:30:56 +0000 (22:30 +0100)] 
Fix build when RUSAGE_THREAD is not available & add warning

Building current GDB on Cygwin, fails like so:

 /home/pedro/gdb/src/gdbsupport/run-time-clock.cc: In function ‘void get_run_time(user_cpu_time_clock::time_point&, system_cpu_time_clock::time_point&, run_time_scope ’:
 /home/pedro/gdb/src/gdbsupport/run-time-clock.cc:52:13: error: ‘RUSAGE_THREAD’ was not declared in this scope; did you mean ‘SIGEV_THREAD’?
    52 |       who = RUSAGE_THREAD;
       |             ^~~~~~~~~~~~~
       |             SIGEV_THREAD

Cygwin does not implement RUSAGE_THREAD.  Googling around, I see
Cygwin is not alone, other platforms don't support it either.  For
example, here is someone suggesting an alternative for darwin/macos:
https://stackoverflow.com/questions/5652463/equivalent-to-rusage-thread-darwin

Fix this by falling back to process scope if thread scope can't be
supported.  I chose this instead of returning zero usage or some other
constant, because if gdb is built without threading support, then
process-scope run time usage is the right info to return.

But instead of falling back silently, print a warning (just once),
like so:

 (gdb) maint set per-command time on
 ⚠️ warning: per-thread run time information not available on this platform

... so that developers on other platforms at least have a hint
upfront.

This new warning also shows on platforms that don't have getrusage in
the first place, but does not show if the build doesn't support
threading at all.

New tests are added to gdb.base/maint.exp, to expect the warning, and
also to ensure other "mt per-command" sub commands don't trigger the
new warning.

Change-Id: Ie01b916b62f87006f855e31594a5ac7cf09e4c02
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Tom Tromey <tom@tromey.com>
4 weeks agogdb/solib: make solib_ops::solib_create_inferior_hook optional
Simon Marchi [Mon, 26 May 2025 20:26:17 +0000 (16:26 -0400)] 
gdb/solib: make solib_ops::solib_create_inferior_hook optional

The solib-target implementation of solib_create_inferior_hook is empty.
Make that method / function pointer optional.

Change-Id: Ie27b8d2c4fc6df74069ac8f88fbe69cf88a6662d
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agogdb/solib: make solib_ops::in_dynsym_resolve_code optional
Simon Marchi [Mon, 26 May 2025 20:26:16 +0000 (16:26 -0400)] 
gdb/solib: make solib_ops::in_dynsym_resolve_code optional

Two solib ops implementations have dummy implementations for the
in_dynsym_resolve_code callback.  Make it optional, to avoid this.

Change-Id: I786776fb82ce1b96335a97713fbfe8074c84c00c
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agogdb/solib: make implementation of solib_ops::open_symbol_file_object optional
Simon Marchi [Mon, 26 May 2025 20:26:15 +0000 (16:26 -0400)] 
gdb/solib: make implementation of solib_ops::open_symbol_file_object optional

The only solib implementation that implements open_symbol_file_object is
SVR4.  All others just return 0.  Make it optional, to avoid having
these empty functions.

Change-Id: I835197a73323d39231d071f9a9eaac2553f10726
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agogdb/solib: boolify in_dynsym_resolve_code functions
Simon Marchi [Mon, 26 May 2025 20:26:14 +0000 (16:26 -0400)] 
gdb/solib: boolify in_dynsym_resolve_code functions

Change-Id: I66f5986e1a2452e3817f326d908b2e49f99e2fc6
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agogdb/solib: move solist.h content to solib.h
Simon Marchi [Mon, 26 May 2025 20:26:13 +0000 (16:26 -0400)] 
gdb/solib: move solist.h content to solib.h

I don't think that the file solist.h is useful.  It would make sense to
have `struct solib` in solib.h.  And then, all that would remain is
`struct solib_ops` and some solib-related function declarations.  So,
move it all to solib.h.

Change-Id: I20ecf19787c378066f2c7a6a8a737c1db7c55d9a
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agogdb/progspace: rename progspace::so_list, make private
Simon Marchi [Mon, 26 May 2025 20:26:12 +0000 (16:26 -0400)] 
gdb/progspace: rename progspace::so_list, make private

Rename the field to m_solib_list, make it private.  Update users to go
through the accessor.

Change-Id: Id720c3a0b1781f4acf31e0dc626f1bd23ed8b39a
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agogdb: fix stale references to so_list
Simon Marchi [Mon, 26 May 2025 20:26:11 +0000 (16:26 -0400)] 
gdb: fix stale references to so_list

Adjust some comments and function names that refer to the ancient
so_list type.

Update some other stale comments in solib-svr4.c at the same time.

Change-Id: Ia42efa6554d0cc6abb4183b6bffc96c6358c5735
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agogdb/solib: remove so_ prefix from so_name and so_original_name
Simon Marchi [Mon, 26 May 2025 20:26:10 +0000 (16:26 -0400)] 
gdb/solib: remove so_ prefix from so_name and so_original_name

The `so_` prefix is unnecessary here, it's already clear by the fact
that they are field of the solib type (and previously so_list).

Change-Id: I2c6773afc121d7631901e602913ea8a068840d0b
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks agoAutomatic date update in version.in
GDB Administrator [Thu, 29 May 2025 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 weeks ago[gdb/symtab] Note errors in process_skeletonless_type_units
Tom de Vries [Wed, 28 May 2025 20:17:19 +0000 (22:17 +0200)] 
[gdb/symtab] Note errors in process_skeletonless_type_units

With a hello world a.out, and using the compiler flags from target board
dwarf5-fission-debug-types:
...
$ gcc -gdwarf-5 -fdebug-types-section -gsplit-dwarf ~/data/hello.c
...
I run into:
...
$ gdb -q -batch a.out
terminate called after throwing an instance of 'gdb_exception_error'
...

What happens is that an error is thrown due to invalid dwarf, but the error is
not caught, causing gdb to terminate.

In a way, this is a duplicate of PR32861, in the sense that we no longer run
into this after:
- applying the proposed patch (work around compiler bug), or
- using gcc 9 or newer (compiler bug fixed).

But in this case, the failure mode is worse than in PR32861.

Fix this by catching the error in
cooked_index_worker_debug_info::process_skeletonless_type_units.

With the patch, we get instead:
...
$ gdb -q -batch a.out
Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing outside of \
  .debug_str.dwo section in CU at offset 0x0 [in module a.out]
...

While we're at it, absorb the common use of
cooked_index_worker_result::note_error:
...
  try
    {
      ...
    }
  catch (gdb_exception &exc)
    {
      (...).note_error (std::move (exc));
    }
...
into the method and rename it to catch_error, resulting in more compact code
for the fix:
...
  (...).catch_error ([&] ()
    {
      ...
    });
...

While we're at it, also use it in
cooked_index_worker_debug_info::process_units which looks like it needs the
same fix.

Tested on x86_64-linux.

PR symtab/32979
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32979

4 weeks agoelfedit: segv with --enable-x86-feature
Alan Modra [Wed, 28 May 2025 12:59:45 +0000 (22:29 +0930)] 
elfedit: segv with --enable-x86-feature

PR 33024
PR 33025
* elfedit.c (update_gnu_property): Sanity check program headers.

4 weeks agoFurther rs_code_align support refinement
Alan Modra [Sun, 25 May 2025 02:16:05 +0000 (11:46 +0930)] 
Further rs_code_align support refinement

Don't write the repeating nop pattern if it won't be used.

4 weeks agoCall restore_original_signal_state after GDB forks.
Alexandra Hájková [Thu, 15 May 2025 18:10:49 +0000 (20:10 +0200)] 
Call restore_original_signal_state after GDB forks.

When I run GDB under Valgrind, GDB seems to segfault
displaying:

Fatal signal: Segmentation fault
----- Backtrace -----
0x2803f7 ???
0x3c9696 ???
0x3c9899 ???
0x55f8fcf ???
0x486c000 ???
---------------------
A fatal error internal to GDB has been detected, further
debugging is not possible.  GDB will now terminate.

This is a bug, please report it.  For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.

warning: linux_ptrace_test_ret_to_nx: PC 0x5821c09d is neither near return address 0x486c000 nor is the return instruction 0x4f8f4a!

but then, acts like nothing happened and excutes normally. This is
because it's the child from linux_ptrace_test_ret_to_nx that
segfaults and parent GDB carries on normally. Restore the original
signal states to not to print confusing backtrace. After restoring,
only such warning is displayed:

warning: linux_ptrace_test_ret_to_nx: WSTOPSIG 19 is neither SIGTRAP nor SIGSEGV!

4 weeks agoPR 33029 segv in dwarf2_finish with --gdwarf-5
Alan Modra [Wed, 28 May 2025 08:50:17 +0000 (18:20 +0930)] 
PR 33029 segv in dwarf2_finish with --gdwarf-5

Specifying --gdwarf-5 with a source lacking a ".file 0" directive
results in this segfault.

* dwarf2dbg.c (out_debug_str): Use files[1] if files[0] is
empty regardless of dwarf level.