binutils-gdb.git
13 months agogdb: remove unnecessary call to std::string constructor
Simon Marchi [Thu, 11 May 2023 17:33:51 +0000 (13:33 -0400)]
gdb: remove unnecessary call to std::string constructor

I spotted this explicit call to std::string, which creates an
unnecessary temporary extra std::string, while calling emplace_back.
I'm not sure if it has any impact in an optimized build, maybe the
compiler elides it.  But still, it's unnecessary.

Change-Id: I873337ea91db29ac06267aff8fc12dcf52824cac
Approved-By: Tom Tromey <tom@tromey.com>
13 months agoAdd dynamic_prop::is_constant
Tom Tromey [Wed, 19 Apr 2023 15:40:20 +0000 (09:40 -0600)]
Add dynamic_prop::is_constant

I noticed many spots checking whether a dynamic property's kind is
PROP_CONST.  Some spots, I think, are doing a slightly incorrect check
-- checking for != PROP_UNDEFINED where == PROP_CONST is actually
required, the key thing being that const_val may only be called for
PROP_CONST properties.

This patch adds dynamic::is_constant and then updates these checks to
use it.

Regression tested on x86-64 Fedora 36.

13 months agoImplement DAP register scope
Tom Tromey [Thu, 13 Apr 2023 17:24:02 +0000 (11:24 -0600)]
Implement DAP register scope

I noticed that gdb's DAP code did not provide a way to see register
values.  DAP defines a "register" scope, which this patch implements.
This patch also adds the missing (and optional) "presentationHint" to
scopes.

13 months agoFix calling debuginfo-less functions in Ada
Tom Tromey [Wed, 12 Apr 2023 15:30:21 +0000 (09:30 -0600)]
Fix calling debuginfo-less functions in Ada

A co-worker at AdaCore noticed that calling a function without
debuginfo yields:

(gdb) print plus_one(23)
'pck.plus_one' has unknown return type; cast the call to its declared return type

However, this also happens if you follow the directions and add the
cast.

This patch fixes the problem and adds a regression test.

13 months agogdb/python: implement DisassemblerResult.__str__ method
Andrew Burgess [Tue, 24 Jan 2023 15:12:34 +0000 (15:12 +0000)]
gdb/python: implement DisassemblerResult.__str__ method

Add the DisassemblerResult.__str__ method.  This gives the same result
as the DisassemblerResult.string attribute, but can be useful
sometimes depending on how the user is trying to print the object.

There's a test for the new functionality.

13 months agogdb/python: implement __repr__ methods for py-disasm.c types
Andrew Burgess [Tue, 24 Jan 2023 15:03:25 +0000 (15:03 +0000)]
gdb/python: implement __repr__ methods for py-disasm.c types

Add a __repr__ method for the DisassembleInfo and DisassemblerResult
types, and add some tests for these new methods.

13 months agogdb/doc: improve Python Disassembler API documentation
Andrew Burgess [Thu, 2 Mar 2023 13:10:08 +0000 (13:10 +0000)]
gdb/doc: improve Python Disassembler API documentation

Some small improvements to the Python Disassembler API documentation:

  * Be consistent about using the package scope in the @deftp lines,

  * Rework the description of the DisassemblerResult class to include
    mention of builtin_disassemble.

13 months agogdb/testsuite: extend special '^' handling to gdb_test_multiple
Andrew Burgess [Tue, 9 May 2023 09:28:42 +0000 (10:28 +0100)]
gdb/testsuite: extend special '^' handling to gdb_test_multiple

The commit:

  commit 08ec06d6440745ef9204d39197aa1e732df41056
  Date:   Wed Mar 29 10:41:07 2023 +0100

      gdb/testsuite: special case '^' in gdb_test pattern

Added some special handling of '^' to gdb_test -- a leading '^' will
cause the command regexp to automatically be included in the expected
output pattern.

It was pointed out that the '-wrap' flag of gdb_test_multiple is
supposed to work in the same way as gdb_test, and that the recent
changes for '^' had not been replicated for gdb_test_multiple.  This
patch addresses this issue.

So, after this commit, the following two constructs should have the
same meaning:

  gdb_test "command" "^output" "test name"

  gdb_test_multiple "command" "test name" {
    -re -wrap "^output" {
      pass $gdb_test_name
    }
  }

In both cases the '^' will case gdb.exp to inject a regexp that
matches 'command' after the '^' and before the 'output', this is in
addition to adding the $gdb_prompt pattern after 'output' in the
normal way.

The special '^' handling is only applied when '-wrap' is used, as this
is the only mode that aims to mimic gdb_test.

While working on this patch I realised that I could actually improve
the logic for the special '^' handling in the case where the expected
output pattern is empty.  I replicated these updates for both gdb_test
and gdb_test_multiple in order to keep these two paths in sync.

There were a small number of tests that needed adjustment after this
change, mostly just removing command regexps that are now added
automatically, but the gdb.base/settings.exp case was a little weird
as it turns out trying to match a single blank line is probably harder
now than it used to be -- still, I suspect this is a pretty rare case,
so I think the benefits (improved anchoring) outweigh this small
downside (IMHO).

13 months agogdb: fix error message for $_gdb_maint_setting
Andrew Burgess [Tue, 9 May 2023 14:18:51 +0000 (15:18 +0100)]
gdb: fix error message for $_gdb_maint_setting

I spotted this behaviour:

  (gdb) p $_gdb_maint_setting("xxx")
  First argument of $_gdb_maint_setting must be a valid setting of the 'show' command.

Notice that GDB claims I need to use a setting from the 'show'
command, which isn't correct for $_gdb_maint_setting, in this case I
need to use a setting from 'maintenance show'.

This same issue is present for $_gdb_maint_setting_str.

This commit fixes this minor issue.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
13 months ago[gdb/testsuite] Fix gdb.dwarf2/opt-out-not-implptr.exp for -m32
Tom de Vries [Fri, 12 May 2023 09:43:41 +0000 (11:43 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/opt-out-not-implptr.exp for -m32

When running test-case gdb.dwarf2/opt-out-not-implptr.exp with target board
unix/-m32 we have:
...
(gdb) print noptr^M
$1 = {0, <optimized out>, <optimized out>, <optimized out>}^M
(gdb) FAIL: gdb.dwarf2/opt-out-not-implptr.exp: print noptr
...

The problem happens when evaluating this dwarf expression:
...
  <45> DW_AT_location : 13 byte block: 10 86 ea d7 d0 96 8e cf 92 5c 9f 93 8 \
  (DW_OP_constu: 6639779683436459270; DW_OP_stack_value; DW_OP_piece: 8)
...

The DW_OP_constu pushes a value with "generic type" on to the DWARF stack, and
the "generic type" has the size of an address on the target machine, which for
target board unix/-m32 is 4 bytes.  Consequently, the constant is abbreviated.

Next, the DW_OP_piece declares that the resulting 4-byte value is 8 bytes
large, and we hit this clause in rw_pieced_value:
...
            /* Use zeroes if piece reaches beyond stack value.  */
            if (p->offset + p->size > stack_value_size_bits)
              break;
...
and consequently get a zero.

We could just add require is_target_64 to the test-case, but instead, add a
32-bit case and require is_target_64 just for the 64-bit case.

Tested on x86_64-linux.

13 months ago[gdb/testsuite] Make is_64_target more robust
Tom de Vries [Fri, 12 May 2023 09:43:41 +0000 (11:43 +0200)]
[gdb/testsuite] Make is_64_target more robust

I ran test-case gdb.dwarf2/opt-out-not-implptr.exp with make-check-all.sh, and
with target board dwarf64 ran into:
...
FAIL: gdb.dwarf2/opt-out-not-implptr.exp: print noptr
...
due to is_target_64 failing because of:
...
builtin_spawn -ignore SIGHUP gcc -fno-stack-protector \
  -fdiagnostics-color=never -w -c -gdwarf64 -g -o is_64_target.o \
  is_64_target.c^M
gcc: error: '-gdwarf64' is ambiguous; use '-gdwarf-64' for DWARF version or \
  '-gdwarf -g64' for debug level^M
compiler exited with status 1
...

The FAIL is the same FAIL I run into with target board unix/-m32: is_target_64
fails for both cases.

The reason that is_target_64 is failing for target board dwarf64, is because
of using system compiler 7.5.0 which doesn't support -gdwarf64.

Fix this by making is_target_64 use nodebug instead of debug for compilation.

Tested on x86_64-linux.

13 months ago[gdb/cli] Fix wrapping for TERM=ansi
Tom de Vries [Fri, 12 May 2023 09:43:41 +0000 (11:43 +0200)]
[gdb/cli] Fix wrapping for TERM=ansi

I. Auto-detected width (xterm vs. ansi)

Say we have a terminal with a width of 40 chars:
...
$ echo $COLUMNS
40
...

With TERM=xterm, we report a width of 40 chars:
...
$ TERM=xterm gdb
(gdb) show width
Number of characters gdb thinks are in a line is 40.
...

And with TERM=ansi, a width of 39 chars:
...
$ TERM=ansi gdb
(gdb) show width
Number of characters gdb thinks are in a line is 39.
...

Gdb uses readline to auto-detect screen size, and readline decides in the
TERM=ansi case that the terminal does not have reliable auto-wrap, and
consequently decides to hide the last terminal column from the readline user
(in other words GDB), hence we get 39 instead of 40.

II. Types of wrapping

Looking a bit more in detail inside gdb, it seems there are two types of
wrapping:
- readline wrapping (in other words, prompt edit wrapping), and
- gdb output wrapping (can be observed by issuing "info sources").
  This type of wrapping attempts to wrap some of the gdb output earlier
  than the indicated width, to not break lines in inconvenient places.

III. Readline wrapping, auto-detected screen size

Let's investigate readline wrapping with the auto-detected screen widths.

First, let's try with xterm:
...
$ TERM=xterm gdb
(gdb) 7890123456789012345678901234567890
123
...
That looks as expected, wrapping occurs after 40 chars.

Now, let's try with ansi:
...
$ TERM=ansi gdb
(gdb) 78901234567890123456789012345678
90123
...
It looks like wrapping occurred after 38, while readline should be capable of
wrapping after 39 chars.

This is caused by readline hiding the last column, twice.

In more detail:
- readline detects the screen width: 40,
- readline hides the last column, setting the readline screen width to 39,
- readline reports 39 to gdb as screen width,
- gdb sets its width setting to 39,
- gdb sets readline screen width to 39,
- readline hides the last column, again, setting the readline screen width to
  38.

This is reported as PR cli/30346.

IV. gdb output wrapping, auto-detected screen size

Say we set the terminal width to 56. With TERM=xterm, we have:
...
/home/abuild/rpmbuild/BUILD/glibc-2.31/csu/elf-init.c,
/data/vries/hello.c,
...
but with TERM=ansi:
...
/home/abuild/rpmbuild/BUILD/glibc-2.31/csu/elf-init.c, /
data/vries/hello.c,
...

So what happened here?  With TERM=ansi, the width setting is auto-detected to
55, and gdb assumes the terminal inserts a line break there, which it doesn't
because the terminal width is 56.

This is reported as PR cli/30411.

V. Fix PRs

Fix both mentioned PRs by taking into account the hidden column when readline
reports the screen width in init_page_info, and updating chars_per_line
accordingly.

Note that now we report the same width for both TERM=xterm and TERM=ansi,
which is much clearer.

The point where readline respectively expects or ensures wrapping is still
indicated by "maint info screen", for xterm:
...
Number of characters readline reports are in a line is 40.
...
and ansi:
...
Number of characters readline reports are in a line is 39.
...

VI. Testing

PR cli/30346 is covered by existing regression tests gdb.base/wrap-line.exp
and gdb.tui/wrap-line.exp, so remove the KFAILs there.

I didn't manage to come up with a regression test for PR cli/30411.  Perhaps
that would be easier if we had a maintenance command that echoes its arguments
while applying gdb output wrapping.

Tested on x86_64-linux.

PR cli/30346
PR cli/30411
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30346
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30411

13 months agox86: move a few more disassembler helper functions
Jan Beulich [Fri, 12 May 2023 06:57:58 +0000 (08:57 +0200)]
x86: move a few more disassembler helper functions

... such that they wouldn't need forward declarations anymore. Note that
append_seg() already was suitably placed.

13 months agox86: move get<N>() disassembler helper functions
Jan Beulich [Fri, 12 May 2023 06:57:37 +0000 (08:57 +0200)]
x86: move get<N>() disassembler helper functions

... such that none of them would need forward declarations anymore.

13 months agox86: slightly simplify i386_parse_name()
Jan Beulich [Fri, 12 May 2023 06:56:07 +0000 (08:56 +0200)]
x86: slightly simplify i386_parse_name()

With the switch to parse_real_register() (commit 4faaa10f3fab) "bad_reg"
cannot come back anymore. Drop the respective check.

13 months agogas: equates of registers
Jan Beulich [Fri, 12 May 2023 06:55:48 +0000 (08:55 +0200)]
gas: equates of registers

There are two problems: symbol_equated_p() doesn't recognize equates of
registers, and S_CAN_BE_REDEFINED() goes by section rather than by
expression type. Both together undermine .eqv and .equiv clearly meaning
to guard the involved symbols against re-definition (both ways).

To compensate pseudo_set() now using O_symbol and S_CAN_BE_REDEFINED()
now checking for O_register,
- for targets creating register symbols through symbol_{new,create}() ->
  symbol_init() -> S_SET_VALUE() (alpha, arc, dlx, ia64, m68k, mips,
  mmix, tic4x, tic54x, plus anything using cgen or itbl-ops), have
  symbol_init() set their expressions to O_register,
- x86'es parse_register() also can't go by section anymore when
  trying to "look through" equates; probably symbol_equated_p() should
  have been used there from the beginning, if only that had worked for
  equates of registers,
- various targets need to "look through" equates when parsing insn
  operands (which also helps transitive forward equates); perhaps even
  more ought to, but many don't look to consider the possibility of
  register equates in the first place.

This was uncovered by code reported in PR gas/30274 (duplicating
PR gas/30272), except that there .eqv was used when really .equ was
meant. Therefore that bug report is addressed here only in so far as
gas wouldn't crash anymore; the code there still won't assemble
successfully, just that now the issues there are properly diagnosed.

13 months agoAutomatic date update in version.in
GDB Administrator [Fri, 12 May 2023 00:00:57 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoDo not print <synthetic pointer> when piece is optimized out
Tom Tromey [Thu, 20 Apr 2023 21:47:41 +0000 (15:47 -0600)]
Do not print <synthetic pointer> when piece is optimized out

A user reported a bug where printing a certain array of integer types
would result in the nonsensical:

(gdb) p l_126
$1 = {6639779683436459270, <synthetic pointer>, <synthetic pointer>, <synthetic pointer>}

I tracked this down to some issues in the DWARF expression code.
First, check_pieced_synthetic_pointer did not account for the
situation where a location expression does not describe all the bits
of a value -- in this case it returned true, meaning there is a
synthetic pointer, but in fact these bits are optimized out.  (It
turns out this incorrect output had already been erroneously tested
for as well.)

Next, rw_pieced_value did not mark these bits as optimized-out,
either.

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

13 months agogdb/testsuite: Match file size in gdb.debuginfod/crc_mismatch.exp
Aaron Merey [Thu, 11 May 2023 16:38:12 +0000 (12:38 -0400)]
gdb/testsuite: Match file size in gdb.debuginfod/crc_mismatch.exp

gdb's debuginfod progress messages include the size of the file being
downloaded if the size information is available at the time the message
is printed.  For example:

    Downloading 10 MB separate debug info for /lib64/libxyz.so

This size information is omitted if it's not available at the time of
printing:

    Downloading separate debug info for /lib64/libxyz.so

A pattern in crc_mismatch.exp fails to be matched if a progress message
includes a file size.  Add a wildcard to the pattern so that it matches
the progress message whether or not it includes the file size.

13 months agoDisable out-of-scope watchpoints
Johnson Sun [Thu, 11 May 2023 15:46:20 +0000 (23:46 +0800)]
Disable out-of-scope watchpoints

Currently, when a local software watchpoint goes out of scope, GDB sets
the watchpoint's disposition to `delete at next stop' and then normal
stops (i.e., stop and wait for the next GDB command). When GDB normal
stops, it automatically deletes the breakpoints with their disposition
set to `delete at next stop'.

Suppose a Python script decides not to normal stop when a local
software watchpoint goes out of scope, the watchpoint will not be
automatically deleted even when its disposition is set to
`delete at next stop'.

Since GDB single-steps the program and tests the watched expression
after each instruction, not deleting the watchpoint causes the
watchpoint to be hit many more times than it should, as reported in
PR python/29603.

This was happening because the watchpoint is not deleted or disabled
when going out of scope.

This commit fixes this issue by disabling the watchpoint when going out
of scope. It also adds a test to ensure this feature isn't regressed in
the future.

Calling `breakpoint_auto_delete' on all kinds of stops (in
`fetch_inferior_event') seem to solve this issue, but is in fact
inappropriate, since `breakpoint_auto_delete' goes over all breakpoints
instead of just going through the bpstat chain (which only contains the
breakpoints that were hit right now).

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29603
Change-Id: Ia85e670b2bcba2799219abe4b6be3b582387e383

13 months agoAdd "scheduler-locking" to documentation index
Tom Tromey [Wed, 10 May 2023 16:58:17 +0000 (10:58 -0600)]
Add "scheduler-locking" to documentation index

I noticed that "scheduler-locking" does not appear in the index of the
gdb manual.  This patch corrects this oversight.

13 months agoAdd LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook [GCC PR109128]
Joseph Myers [Thu, 11 May 2023 14:31:09 +0000 (14:31 +0000)]
Add LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook [GCC PR109128]

This is one part of the fix for GCC PR109128, along with a
corresponding GCC change.  Without this patch, what happens in the
linker, when an unused object in a .a file has offload data, is that
elf_link_is_defined_archive_symbol calls bfd_link_plugin_object_p,
which ends up calling the plugin's claim_file_handler, which then
records the object as one with offload data. That is, the linker never
decides to use the object in the first place, but use of this _p
interface (called as part of trying to decide whether to use the
object) results in the plugin deciding to use its offload data (and a
consequent mismatch in the offload data present at runtime).

The new hook allows the linker plugin to distinguish calls to
claim_file_handler that know the object is being used by the linker
(from ldmain.c:add_archive_element), from calls that don't know it's
being used by the linker (from elf_link_is_defined_archive_symbol); in
the latter case, the plugin should avoid recording the object as one
with offload data.

bfd/
* plugin.c (struct plugin_list_entry): Add claim_file_v2.
(register_claim_file_v2): New.
(try_load_plugin): Use LDPT_REGISTER_CLAIM_FILE_HOOK_V2.
(ld_plugin_object_p): Take second argument.
(bfd_link_plugin_object_p): Update call to ld_plugin_object_p.
(register_ld_plugin_object_p): Update argument prototype.
(bfd_plugin_object_p): Update call to ld_plugin_object_p.
* plugin.h (register_ld_plugin_object_p): Update argument
prototype.

include/
* plugin.api.h (ld_plugin_claim_file_handler_v2)
(ld_plugin_register_claim_file_v2)
(LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New.
(struct ld_plugin_tv): Add tv_register_claim_file_v2.

ld/
* plugin.c (struct plugin): Add claim_file_handler_v2.
(LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New.
(plugin_object_p): Add second argument.  Update call to
plugin_call_claim_file.
(register_claim_file_v2): New.
(set_tv_header): Handle LDPT_REGISTER_CLAIM_FILE_HOOK_V2.
(plugin_call_claim_file): Add argument known_used.
(plugin_maybe_claim): Update call to plugin_object_p.
* testplug.c, testplug2.c, testplug3.c, testplug4.c: Handle
LDPT_REGISTER_CLAIM_FILE_HOOK_V2.
* testsuite/ld-plugin/plugin-1.d, testsuite/ld-plugin/plugin-10.d,
testsuite/ld-plugin/plugin-11.d, testsuite/ld-plugin/plugin-13.d,
testsuite/ld-plugin/plugin-14.d, testsuite/ld-plugin/plugin-15.d,
testsuite/ld-plugin/plugin-16.d, testsuite/ld-plugin/plugin-17.d,
testsuite/ld-plugin/plugin-18.d, testsuite/ld-plugin/plugin-19.d,
testsuite/ld-plugin/plugin-2.d, testsuite/ld-plugin/plugin-26.d,
testsuite/ld-plugin/plugin-3.d, testsuite/ld-plugin/plugin-30.d,
testsuite/ld-plugin/plugin-4.d, testsuite/ld-plugin/plugin-5.d,
testsuite/ld-plugin/plugin-6.d, testsuite/ld-plugin/plugin-7.d,
testsuite/ld-plugin/plugin-8.d, testsuite/ld-plugin/plugin-9.d:
Update test expectations.

13 months agoAutomatic date update in version.in
GDB Administrator [Thu, 11 May 2023 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months ago[gdb/tui] Fix tui compact-source a bit more
Tom de Vries [Wed, 10 May 2023 18:11:35 +0000 (20:11 +0200)]
[gdb/tui] Fix tui compact-source a bit more

Andrew pointed out that the behaviour as tested in gdb.tui/compact-source.exp
is incorrect:
...
0 +-compact-source.c--------------------------------------------------------+
1 |___3_{                                                                   |
2 |___4_  return 0;                                                         |
3 |___5_}                                                                   |
4 |___6_                                                                    |
5 |___7_                                                                    |
6 |___8_                                                                    |
7 |___9_                                                                    |
8 +-------------------------------------------------------------------------+
...

The last line number in the source file is 5, and there are 7 lines to display
source lines, so if we'd scroll all the way down, the first line number in the
source window would be 5, and the last one would be 11.

To represent 11 we'd need 2 digits, so we expect to see ___04_ here instead of
___4_, even though all line numbers currently in the src window (3-9) can be
represented with only 1 digit.

Fix this in tui_source_window::set_contents, by updating the computation of
max_line_nr:
...
-      int max_line_nr = std::max (lines_in_file, last_line_nr_in_window);
+      int max_line_nr = lines_in_file + nlines - 1;
...

Tested on x86_64-linux.

Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
13 months agogdb/rust: fix crash for expression debug with strings
Andrew Burgess [Tue, 9 May 2023 11:13:02 +0000 (12:13 +0100)]
gdb/rust: fix crash for expression debug with strings

While working on another patch I did this:

  (gdb) set debug expression 1
  (gdb) set language rust
  (gdb) p "foo"
  Operation: OP_AGGREGATE
   Type: &str

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

The problem is that the second field of the rust_aggregate_operation
is created as a nullptr, this can be seen in rust-parse.c. in the
function rust_parser::parse_string().

However, in expop.h, in the function dump_for_expression, we make the
assumption that the expressions will never be nullptr.

I did consider moving the nullptr handling into a new function
rust_aggregate_operation::dump, however, as the expression debug
dumping code is not exercised as much as it might be, I would rather
that this code be hardened and able to handle a nullptr without
crashing, so I propose that we add nullptr handling into the general
dump_for_expression function.  The behaviour is now:

  (gdb) set debug expression 1
  (gdb) set language rust
  (gdb) p "foo"
  Operation: OP_AGGREGATE
   Type: &str
   nullptr
   Vector:
    String: data_ptr
    Operation: UNOP_ADDR
     Operation: OP_STRING
      String: foo
    String: length
    Operation: OP_LONG
     Type: usize
     Constant: 3
  evaluation of this expression requires the target program to be active
  (gdb)

There's a new test to check for this case.

Reviewed-By: Tom Tromey <tom@tromey.com>
13 months agoRe: stack overflow in debug_write_type
Alan Modra [Wed, 10 May 2023 13:35:00 +0000 (23:05 +0930)]
Re: stack overflow in debug_write_type

Apparently u.kindirect->slot can point at a NULL.

* debug.c (debug_write_type): Don't segfault on NULL indirect.

13 months agoor1k relocation truncated to fit: R_OR1K_GOT16 even when using -mcmodel=large
Luca Bonissi [Wed, 10 May 2023 11:08:28 +0000 (12:08 +0100)]
or1k relocation truncated to fit: R_OR1K_GOT16 even when using -mcmodel=large

  PR 30422
  * elf32-or1k.c (or1k_elf_relocate_section): Prescan for R_OR1K_GOT_AHI16 relocs as they may occur after R_OR1K_GOT16 relocs.

13 months agoAdd linker option to include local symbols in the linker map.
Nick Clifton [Wed, 10 May 2023 09:29:52 +0000 (10:29 +0100)]
Add linker option to include local symbols in  the linker map.

  PR 16566
  * ldlang.c (ld_is_local_symbol): New function. (print_input_section): Add code to display local symbols in the section.
  * ldlex.h (enum option_values): Add OPTION_PRINT_MAP_LOCALS and OPTION_PRINT_MAP_LOCALS.
  * lexsup.c (ld_options[]): Add entries for --print-map-locals and --no-print-map-locals.
  * NEWS: Mention the new feature.
  * ld.h (struct ld_config_type): Add print_map_locals field.
  * ld.texi: Document the new command line option.
  * testsuite/ld-scripts/sizeof.s: Add a local symbol.
  * testsuite/ld-scripts/map-locals.d: New test control file.
  * testsuite/ld-scripts/map-address.exp: Run the new test.

13 months ago[gdb/tui] Fix tui compact-source
Tom de Vries [Wed, 10 May 2023 04:56:08 +0000 (06:56 +0200)]
[gdb/tui] Fix tui compact-source

Consider a hello.c, with less than 10 lines:
...
$ wc -l hello.c
8 hello.c
...
and compiled with -g into an a.out.

With compact-source off:
...
$ gdb -q a.out \
    -ex "set tui border-kind ascii" \
    -ex "maint set tui-left-margin-verbose on" \
    -ex "set tui compact-source off" \
    -ex "tui enable"
...
we get:
...
+-./data/hello.c-----------------------+
|___000005_{                           |
|___000006_  printf ("hello\n");       |
|___000007_  return 0;                 |
|___000008_}                           |
|___000009_                            |
|___000010_                            |
|___000011_                            |
...
but with compact-source on:
...
+-./data/hello.c-----------------------+
|___5{                                 |
|___6  printf ("hello\n");             |
|___7  return 0;                       |
|___8}                                 |
|___9                                  |
|___1                                  |
|___1                                  |
...

There are a couple of problems with compact-source.

First of all the documentation mentions:
...
The default display uses more space for line numbers and starts the
source text at the next tab stop; the compact display uses only as
much space as is needed for the line numbers in the current file, and
only a single space to separate the line numbers from the source.
...

The bit about the default display and the next tab stop looks incorrect.  The
source doesn't start at a tab stop, instead it uses a single space to separate
the line numbers from the source.

Then the documentation mentions that there's single space in the compact
display, but evidently that's missing.

Then there's the fact that the line numbers "10" and "11" are both abbreviated
to "1" in the compact case.

The abbreviation is due to allocating space for <lines in source>, which is
8 for this example, and takes a single digit.  The line numbers though
continue past the end of the file, so fix this by allocating space for
max (<lines in source>, <last line in window>), which in this example takes 2
digits.

The missing space is due to some confusion about what the "1" here in
tui_source_window::set_contents represent:
...
      double l = log10 ((double) offsets->size ());
      m_digits = 1 + (int) l;
...

It could be the trailing space that's mentioned in tui-source.h:
...
  /* How many digits to use when formatting the line number.  This
     includes the trailing space.  */
  int m_digits;
...

Then again, it could be part of the calculation for the number of digits
needed for printing.  With this minimal example:
...
int main () {
  for (int i = 8; i <= 11; ++i) {
    double l = log10 ((double) i);
    printf ("%d %d\n", i, (int)l);
  }
  return 0;
}
...
we get:
...
$ ./a.out
8 0
9 0
10 1
11 1
...
which shows that the number of digits needed for printing i is
"1 + (int)log10 ((double) i)".

Fix this by introducing named variables needed_digits and trailing_space, each
adding 1.

With the fixes, we get for compact-source on:
...
+-./data/hello.c-----------------------+
|___05_{                               |
|___06_  printf ("hello\n");           |
|___07_  return 0;                     |
|___08_}                               |
|___09_                                |
|___10_                                |
|___11_                                |
|...

Also fix the documentation and help text to actually match effect of
compact-source.

Tested on x86_64-linux.

13 months agoAutomatic date update in version.in
GDB Administrator [Wed, 10 May 2023 00:00:47 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoSupport higher baud rates when they are defined
Dan Callaghan [Mon, 8 May 2023 08:29:45 +0000 (18:29 +1000)]
Support higher baud rates when they are defined

On Linux at least, baud rate codes are defined up to B4000000. Allow the
user to select them if they are present in the system headers.

Change-Id: I393ff32e4a4b6127bdf97e3306ad5b6ebf7c934e

13 months agogdb: fix use-after-free in check_longjmp_breakpoint_for_call_dummy
Simon Marchi [Mon, 8 May 2023 14:41:36 +0000 (10:41 -0400)]
gdb: fix use-after-free in check_longjmp_breakpoint_for_call_dummy

Commit 7a8de0c33019 ("Remove ALL_BREAKPOINTS_SAFE") introduced a
use-after-free in the breakpoints iterations (see below for full ASan
report).  This makes gdb.base/stale-infcall.exp fail when GDB is build
with ASan.

check_longjmp_breakpoint_for_call_dummy iterates on all breakpoints,
possibly deleting the current breakpoint as well as related breakpoints.
The problem arises when a breakpoint in the B->related_breakpoint chain
is also B->next.  In that case, deleting that related breakpoint frees
the breakpoint that all_breakpoints_safe has saved.

The old code worked around that by manually changing B_TMP, which was
the next breakpoint saved by the "safe iterator":

while (b->related_breakpoint != b)
  {
    if (b_tmp == b->related_breakpoint)
      b_tmp = b->related_breakpoint->next;
    delete_breakpoint (b->related_breakpoint);
  }

(Note that this seemed to assume that b->related_breakpoint->next was
the same as b->next->next, not sure this is guaranteed.)

The new code kept the B_TMP variable, but it's not useful in that
context.  We can't go change the next breakpoint as saved by the safe
iterator, like we did before.  I suggest fixing that by saving the
breakpoints to delete in a map and deleting them all at the end.

Here's the full ASan report:

    (gdb) PASS: gdb.base/stale-infcall.exp: continue to breakpoint: break-run1
    print infcall ()
    =================================================================
    ==47472==ERROR: AddressSanitizer: heap-use-after-free on address 0x611000034980 at pc 0x563f7012c7bc bp 0x7ffdf3804d70 sp 0x7ffdf3804d60
    READ of size 8 at 0x611000034980 thread T0
        #0 0x563f7012c7bb in next_iterator<breakpoint>::operator++() /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/next-iterator.h:66
        #1 0x563f702ce8c0 in basic_safe_iterator<next_iterator<breakpoint> >::operator++() /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/safe-iterator.h:84
        #2 0x563f7021522a in check_longjmp_breakpoint_for_call_dummy(thread_info*) /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:7611
        #3 0x563f714567b1 in process_event_stop_test /home/smarchi/src/binutils-gdb/gdb/infrun.c:6881
        #4 0x563f71454e07 in handle_signal_stop /home/smarchi/src/binutils-gdb/gdb/infrun.c:6769
        #5 0x563f7144b680 in handle_inferior_event /home/smarchi/src/binutils-gdb/gdb/infrun.c:6023
        #6 0x563f71436165 in fetch_inferior_event() /home/smarchi/src/binutils-gdb/gdb/infrun.c:4387
        #7 0x563f7136ff51 in inferior_event_handler(inferior_event_type) /home/smarchi/src/binutils-gdb/gdb/inf-loop.c:42
        #8 0x563f7168038d in handle_target_event /home/smarchi/src/binutils-gdb/gdb/linux-nat.c:4219
        #9 0x563f72fccb6d in handle_file_event /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:573
        #10 0x563f72fcd503 in gdb_wait_for_event /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:694
        #11 0x563f72fcaf2b in gdb_do_one_event(int) /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:217
        #12 0x563f7262b9bb in wait_sync_command_done() /home/smarchi/src/binutils-gdb/gdb/top.c:426
        #13 0x563f7137a7c3 in run_inferior_call /home/smarchi/src/binutils-gdb/gdb/infcall.c:650
        #14 0x563f71381295 in call_function_by_hand_dummy(value*, type*, gdb::array_view<value*>, void (*)(void*, int), void*) /home/smarchi/src/binutils-gdb/gdb/infcall.c:1332
        #15 0x563f7137c0e2 in call_function_by_hand(value*, type*, gdb::array_view<value*>) /home/smarchi/src/binutils-gdb/gdb/infcall.c:780
        #16 0x563f70fe5960 in evaluate_subexp_do_call(expression*, noside, value*, gdb::array_view<value*>, char const*, type*) /home/smarchi/src/binutils-gdb/gdb/eval.c:649
        #17 0x563f70fe6617 in expr::operation::evaluate_funcall(type*, expression*, noside, char const*, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/eval.c:677
        #18 0x563f6fd19668 in expr::operation::evaluate_funcall(type*, expression*, noside, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/expression.h:136
        #19 0x563f70fe6bba in expr::var_value_operation::evaluate_funcall(type*, expression*, noside, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/eval.c:689
        #20 0x563f704b71dc in expr::funcall_operation::evaluate(type*, expression*, noside) /home/smarchi/src/binutils-gdb/gdb/expop.h:2219
        #21 0x563f70fe0f02 in expression::evaluate(type*, noside) /home/smarchi/src/binutils-gdb/gdb/eval.c:110
        #22 0x563f71b1373e in process_print_command_args /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1319
        #23 0x563f71b1391b in print_command_1 /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1332
        #24 0x563f71b147ec in print_command /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1465
        #25 0x563f706029b8 in do_simple_func /home/smarchi/src/binutils-gdb/gdb/cli/cli-decode.c:95
        #26 0x563f7061972a in cmd_func(cmd_list_element*, char const*, int) /home/smarchi/src/binutils-gdb/gdb/cli/cli-decode.c:2735
        #27 0x563f7262d0ef in execute_command(char const*, int) /home/smarchi/src/binutils-gdb/gdb/top.c:572
        #28 0x563f7100ed9c in command_handler(char const*) /home/smarchi/src/binutils-gdb/gdb/event-top.c:543
        #29 0x563f7101014b in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/smarchi/src/binutils-gdb/gdb/event-top.c:779
        #30 0x563f72777942 in tui_command_line_handler /home/smarchi/src/binutils-gdb/gdb/tui/tui-interp.c:104
        #31 0x563f7100d059 in gdb_rl_callback_handler /home/smarchi/src/binutils-gdb/gdb/event-top.c:250
        #32 0x7f5a80418246 in rl_callback_read_char (/usr/lib/libreadline.so.8+0x3b246) (BuildId: 092e91fc4361b0ef94561e3ae03a75f69398acbb)
        #33 0x563f7100ca06 in gdb_rl_callback_read_char_wrapper_noexcept /home/smarchi/src/binutils-gdb/gdb/event-top.c:192
        #34 0x563f7100cc5e in gdb_rl_callback_read_char_wrapper /home/smarchi/src/binutils-gdb/gdb/event-top.c:225
        #35 0x563f728c70db in stdin_event_handler /home/smarchi/src/binutils-gdb/gdb/ui.c:155
        #36 0x563f72fccb6d in handle_file_event /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:573
        #37 0x563f72fcd503 in gdb_wait_for_event /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:694
        #38 0x563f72fcb15c in gdb_do_one_event(int) /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:264
        #39 0x563f7177ec1c in start_event_loop /home/smarchi/src/binutils-gdb/gdb/main.c:412
        #40 0x563f7177f12e in captured_command_loop /home/smarchi/src/binutils-gdb/gdb/main.c:476
        #41 0x563f717846e4 in captured_main /home/smarchi/src/binutils-gdb/gdb/main.c:1320
        #42 0x563f71784821 in gdb_main(captured_main_args*) /home/smarchi/src/binutils-gdb/gdb/main.c:1339
        #43 0x563f6fcedfbd in main /home/smarchi/src/binutils-gdb/gdb/gdb.c:32
        #44 0x7f5a7e43984f  (/usr/lib/libc.so.6+0x2384f) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
        #45 0x7f5a7e439909 in __libc_start_main (/usr/lib/libc.so.6+0x23909) (BuildId: 2f005a79cd1a8e385972f5a102f16adba414d75e)
        #46 0x563f6fcedd84 in _start (/home/smarchi/build/binutils-gdb/gdb/gdb+0xafb0d84) (BuildId: 50bd32e6e9d5e84543e9897b8faca34858ca3995)

    0x611000034980 is located 0 bytes inside of 208-byte region [0x611000034980,0x611000034a50)
    freed by thread T0 here:
        #0 0x7f5a7fce312a in operator delete(void*, unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:164
        #1 0x563f702bd1fa in momentary_breakpoint::~momentary_breakpoint() /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:304
        #2 0x563f702771c5 in delete_breakpoint(breakpoint*) /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:12404
        #3 0x563f702150a7 in check_longjmp_breakpoint_for_call_dummy(thread_info*) /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:7673
        #4 0x563f714567b1 in process_event_stop_test /home/smarchi/src/binutils-gdb/gdb/infrun.c:6881
        #5 0x563f71454e07 in handle_signal_stop /home/smarchi/src/binutils-gdb/gdb/infrun.c:6769
        #6 0x563f7144b680 in handle_inferior_event /home/smarchi/src/binutils-gdb/gdb/infrun.c:6023
        #7 0x563f71436165 in fetch_inferior_event() /home/smarchi/src/binutils-gdb/gdb/infrun.c:4387
        #8 0x563f7136ff51 in inferior_event_handler(inferior_event_type) /home/smarchi/src/binutils-gdb/gdb/inf-loop.c:42
        #9 0x563f7168038d in handle_target_event /home/smarchi/src/binutils-gdb/gdb/linux-nat.c:4219
        #10 0x563f72fccb6d in handle_file_event /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:573
        #11 0x563f72fcd503 in gdb_wait_for_event /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:694
        #12 0x563f72fcaf2b in gdb_do_one_event(int) /home/smarchi/src/binutils-gdb/gdbsupport/event-loop.cc:217
        #13 0x563f7262b9bb in wait_sync_command_done() /home/smarchi/src/binutils-gdb/gdb/top.c:426
        #14 0x563f7137a7c3 in run_inferior_call /home/smarchi/src/binutils-gdb/gdb/infcall.c:650
        #15 0x563f71381295 in call_function_by_hand_dummy(value*, type*, gdb::array_view<value*>, void (*)(void*, int), void*) /home/smarchi/src/binutils-gdb/gdb/infcall.c:1332
        #16 0x563f7137c0e2 in call_function_by_hand(value*, type*, gdb::array_view<value*>) /home/smarchi/src/binutils-gdb/gdb/infcall.c:780
        #17 0x563f70fe5960 in evaluate_subexp_do_call(expression*, noside, value*, gdb::array_view<value*>, char const*, type*) /home/smarchi/src/binutils-gdb/gdb/eval.c:649
        #18 0x563f70fe6617 in expr::operation::evaluate_funcall(type*, expression*, noside, char const*, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/eval.c:677
        #19 0x563f6fd19668 in expr::operation::evaluate_funcall(type*, expression*, noside, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/expression.h:136
        #20 0x563f70fe6bba in expr::var_value_operation::evaluate_funcall(type*, expression*, noside, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/eval.c:689
        #21 0x563f704b71dc in expr::funcall_operation::evaluate(type*, expression*, noside) /home/smarchi/src/binutils-gdb/gdb/expop.h:2219
        #22 0x563f70fe0f02 in expression::evaluate(type*, noside) /home/smarchi/src/binutils-gdb/gdb/eval.c:110
        #23 0x563f71b1373e in process_print_command_args /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1319
        #24 0x563f71b1391b in print_command_1 /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1332
        #25 0x563f71b147ec in print_command /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1465
        #26 0x563f706029b8 in do_simple_func /home/smarchi/src/binutils-gdb/gdb/cli/cli-decode.c:95
        #27 0x563f7061972a in cmd_func(cmd_list_element*, char const*, int) /home/smarchi/src/binutils-gdb/gdb/cli/cli-decode.c:2735
        #28 0x563f7262d0ef in execute_command(char const*, int) /home/smarchi/src/binutils-gdb/gdb/top.c:572
        #29 0x563f7100ed9c in command_handler(char const*) /home/smarchi/src/binutils-gdb/gdb/event-top.c:543

    previously allocated by thread T0 here:
        #0 0x7f5a7fce2012 in operator new(unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:95
        #1 0x563f7029a9a3 in new_momentary_breakpoint<program_space*&, frame_id&, int&> /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:8129
        #2 0x563f702212f6 in momentary_breakpoint_from_master /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:8169
        #3 0x563f70212db1 in set_longjmp_breakpoint_for_call_dummy() /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:7582
        #4 0x563f713804db in call_function_by_hand_dummy(value*, type*, gdb::array_view<value*>, void (*)(void*, int), void*) /home/smarchi/src/binutils-gdb/gdb/infcall.c:1260
        #5 0x563f7137c0e2 in call_function_by_hand(value*, type*, gdb::array_view<value*>) /home/smarchi/src/binutils-gdb/gdb/infcall.c:780
        #6 0x563f70fe5960 in evaluate_subexp_do_call(expression*, noside, value*, gdb::array_view<value*>, char const*, type*) /home/smarchi/src/binutils-gdb/gdb/eval.c:649
        #7 0x563f70fe6617 in expr::operation::evaluate_funcall(type*, expression*, noside, char const*, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/eval.c:677
        #8 0x563f6fd19668 in expr::operation::evaluate_funcall(type*, expression*, noside, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/expression.h:136
        #9 0x563f70fe6bba in expr::var_value_operation::evaluate_funcall(type*, expression*, noside, std::__debug::vector<std::unique_ptr<expr::operation, std::default_delete<expr::operation> >, std::allocator<std::unique_ptr<expr::operation, std::default_delete<expr::operation> > > > const&) /home/smarchi/src/binutils-gdb/gdb/eval.c:689
        #10 0x563f704b71dc in expr::funcall_operation::evaluate(type*, expression*, noside) /home/smarchi/src/binutils-gdb/gdb/expop.h:2219
        #11 0x563f70fe0f02 in expression::evaluate(type*, noside) /home/smarchi/src/binutils-gdb/gdb/eval.c:110
        #12 0x563f71b1373e in process_print_command_args /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1319
        #13 0x563f71b1391b in print_command_1 /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1332
        #14 0x563f71b147ec in print_command /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1465
        #15 0x563f706029b8 in do_simple_func /home/smarchi/src/binutils-gdb/gdb/cli/cli-decode.c:95
        #16 0x563f7061972a in cmd_func(cmd_list_element*, char const*, int) /home/smarchi/src/binutils-gdb/gdb/cli/cli-decode.c:2735
        #17 0x563f7262d0ef in execute_command(char const*, int) /home/smarchi/src/binutils-gdb/gdb/top.c:572
        #18 0x563f7100ed9c in command_handler(char const*) /home/smarchi/src/binutils-gdb/gdb/event-top.c:543
        #19 0x563f7101014b in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/smarchi/src/binutils-gdb/gdb/event-top.c:779
        #20 0x563f72777942 in tui_command_line_handler /home/smarchi/src/binutils-gdb/gdb/tui/tui-interp.c:104
        #21 0x563f7100d059 in gdb_rl_callback_handler /home/smarchi/src/binutils-gdb/gdb/event-top.c:250
        #22 0x7f5a80418246 in rl_callback_read_char (/usr/lib/libreadline.so.8+0x3b246) (BuildId: 092e91fc4361b0ef94561e3ae03a75f69398acbb)

Change-Id: Id00c17ab677f847fbf4efdf0f4038373668d3d88
Approved-By: Tom Tromey <tom@tromey.com>
13 months agoCorrect a spelling mistake in the binutils README file.
Enze Li [Tue, 9 May 2023 10:44:22 +0000 (11:44 +0100)]
Correct a spelling mistake in the binutils README file.

13 months agostack overflow in debug_write_type
Alan Modra [Tue, 9 May 2023 07:41:46 +0000 (17:11 +0930)]
stack overflow in debug_write_type

Another fuzzer attack.  This one was a "set" with elements using an
indirect type pointing back at the set.  The existing recursion check
only prevented simple recursion.

* debug.c (struct debug_type_s): Add mark.
(debug_write_type): Set mark and check before recursing into
indirect types.

13 months agoalpha-vms reloc sanity check
Alan Modra [Tue, 9 May 2023 03:21:42 +0000 (12:51 +0930)]
alpha-vms reloc sanity check

Stops fuzzed files triggering reads past the end of the reloc buffer.

* vms-alpha.c (alpha_vms_slurp_relocs): Sanity check reloc records.

13 months agoregen ld/Makefile.in
Alan Modra [Tue, 9 May 2023 00:07:52 +0000 (09:37 +0930)]
regen ld/Makefile.in

13 months agoAutomatic date update in version.in
GDB Administrator [Tue, 9 May 2023 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

14 months agogdbserver: Clear upper ZMM registers in the right location.
John Baldwin [Mon, 8 May 2023 17:39:52 +0000 (10:39 -0700)]
gdbserver: Clear upper ZMM registers in the right location.

This was previously clearing the upper 32 bytes of ZMM0-15 rather than
ZMM16-31.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agox86-fbsd-nat: Add missing public label.
John Baldwin [Mon, 8 May 2023 17:39:52 +0000 (10:39 -0700)]
x86-fbsd-nat: Add missing public label.

These two methods are both overrides of public methods in base
classes.

14 months agogdb: Avoid warning for the jump command inside an inline function.
Felix Willgerodt [Thu, 4 Nov 2021 14:46:45 +0000 (15:46 +0100)]
gdb: Avoid warning for the jump command inside an inline function.

When stopped inside an inline function, trying to jump to a different line
of the same function currently results in a warning about jumping to another
function.  Fix this by taking inline functions into account.

Before:
  Breakpoint 1, function_inline (x=510) at jump-inline.cpp:22
  22        a = a + x;             /* inline-funct */
  (gdb) j 21
  Line 21 is not in `function_inline(int)'.  Jump anyway? (y or n)

After:
  Breakpoint 2, function_inline (x=510) at jump-inline.cpp:22
  22        a = a + x;            /* inline-funct */
  (gdb) j 21
  Continuing at 0x400679.

  Breakpoint 1, function_inline (x=510) at jump-inline.cpp:21
  21        a += 1020 + a;                /* increment-funct */

This was regression-tested on X86-64 Linux.

Co-Authored-by: Cristian Sandu <cristian.sandu@intel.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
14 months agope.em and pep.em make_import_fixup
Alan Modra [Sun, 7 May 2023 23:46:24 +0000 (09:16 +0930)]
pe.em and pep.em make_import_fixup

This is a little cleanup that I made when looking at pr30343 that
makes it more obvious that make_import_fixup in both files are
identical (and in fact the new pep.em read_addend could be used in
both files).

* emultempl/pep.em (read_addend): Extract from..
(make_import_fixup): ..here.
* emultempl/pe.em (read_addend): Similarly.
(make_import_fixup): Similarly.  Add debug code from pep.em.

14 months agoPR30343, LTO ignores linker reference to _pei386_runtime_relocator
Alan Modra [Sun, 7 May 2023 08:16:57 +0000 (17:46 +0930)]
PR30343, LTO ignores linker reference to _pei386_runtime_relocator

Make a reference to _pei386_runtime_relocator before LTO recompilation.
This is done regardless of whether such a reference will be used,
because it can't be known whether it is needed before LTO.

I also found it necessary to enable long section names for the bfd
created in make_runtime_pseudo_reloc, because otherwise when writing
it out to the bfd-in-memory we get the section written as .rdata_r
which when read back in leads to a linker warning ".rdata_r: section
below image base" and likely runtime misbehaviour.

PR 30343
* emultempl/pe.em (make_runtime_ref): New function.
(gld${EMULATION_NAME}_before_plugin_all_symbols_read): New function.
(LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): Define.
* emultempl/pep.em: Similarly to pe.em.
* pe-dll.c (make_runtime_pseudo_reloc): Set long section names.

14 months agoAutomatic date update in version.in
GDB Administrator [Mon, 8 May 2023 00:00:33 +0000 (00:00 +0000)]
Automatic date update in version.in

14 months agoRemove parameter from select_source_symtab
Tom Tromey [Mon, 21 Mar 2022 01:52:13 +0000 (19:52 -0600)]
Remove parameter from select_source_symtab

I noticed that select_source_symtab is only ever called with nullptr
as an argument, so this patch removes the parameter and associated
logic.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
14 months agoRemove ALL_BREAKPOINTS_SAFE
Tom Tromey [Sun, 16 Apr 2023 15:35:49 +0000 (09:35 -0600)]
Remove ALL_BREAKPOINTS_SAFE

There's just a single remaining use of the ALL_BREAKPOINTS_SAFE macro;
this patch replaces it with a for-each and an explicit temporary
variable.

14 months agoRemove ALL_DICT_SYMBOLS
Tom Tromey [Sun, 16 Apr 2023 15:10:02 +0000 (09:10 -0600)]
Remove ALL_DICT_SYMBOLS

This replaces ALL_DICT_SYMBOLS with an iterator so that for-each can
be used.

14 months agoRemove ALL_OBJFILE_OSECTIONS
Tom Tromey [Mon, 10 Apr 2023 16:43:32 +0000 (10:43 -0600)]
Remove ALL_OBJFILE_OSECTIONS

This replaces ALL_OBJFILE_OSECTIONS with an iterator so that for-each
can be used.

14 months agoRename objfile::sections
Tom Tromey [Mon, 10 Apr 2023 16:50:09 +0000 (10:50 -0600)]
Rename objfile::sections

I think objfile::sections makes sense as the name of the method to
iterate over an objfile's sections, so this patch renames the existing
field to objfile::sections_start in preparation for that.

14 months agoAutomatic date update in version.in
GDB Administrator [Sun, 7 May 2023 00:00:32 +0000 (00:00 +0000)]
Automatic date update in version.in

14 months agoAllow pretty-print of static members
Tom Tromey [Sat, 22 Apr 2023 00:53:48 +0000 (18:53 -0600)]
Allow pretty-print of static members

Python pretty-printers haven't applied to static members for quite
some time.  I tracked this down to the call to cp_print_value_fields
in cp_print_static_field -- it doesn't let pretty-printers have a
chance to print the value.  This patch fixes the problem.

The way that static members are handled is very weird to me.  I tend
to think this should be done more globally, like in value_print.
However, I haven't made any big change.

Reviewed-by: Keith Seitz <keiths@redhat.com>
Tested-by: Keith Seitz <keiths@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30057

14 months agogas: documents .gnu_attribute Tag_GNU_MIPS_ABI_MSA
YunQiang Su [Fri, 5 May 2023 09:27:16 +0000 (17:27 +0800)]
gas: documents .gnu_attribute Tag_GNU_MIPS_ABI_MSA

It is added since 2016 by
  Add support for .MIPS.abiflags and .gnu.attributes sections
  b52717c0e104eb603e8189c3c0d3658ef5d903f5
But never documented.

14 months agoAutomatic date update in version.in
GDB Administrator [Sat, 6 May 2023 00:00:26 +0000 (00:00 +0000)]
Automatic date update in version.in

14 months agoFilter out types from DAP scopes request
Tom Tromey [Thu, 6 Apr 2023 12:56:11 +0000 (06:56 -0600)]
Filter out types from DAP scopes request

The DAP scopes request examines the symbols in a block tree, but
neglects to omit types.  This patch fixes the problem.

14 months agoUse discrete_position in ada-valprint.c
Tom Tromey [Thu, 27 Apr 2023 16:59:59 +0000 (10:59 -0600)]
Use discrete_position in ada-valprint.c

I found a couple of spots in ada-valprint.c that use an explicit loop,
but where discrete_position could be used instead.

Reviewed-by: Keith Seitz <keiths@redhat.com>
14 months agogdb/python: add mechanism to manage Python initialization functions
Andrew Burgess [Fri, 16 Sep 2022 15:08:17 +0000 (16:08 +0100)]
gdb/python: add mechanism to manage Python initialization functions

Currently, when we add a new python sub-system to GDB,
e.g. py-inferior.c, we end up having to create a new function like
gdbpy_initialize_inferior, which then has to be called from the
function do_start_initialization in python.c.

In some cases (py-micmd.c and py-tui.c), we have two functions
gdbpy_initialize_*, and gdbpy_finalize_*, with the second being called
from finalize_python which is also in python.c.

This commit proposes a mechanism to manage these initialization and
finalization calls, this means that adding a new Python subsystem will
no longer require changes to python.c or python-internal.h, instead,
the initialization and finalization functions will be registered
directly from the sub-system file, e.g. py-inferior.c, or py-micmd.c.

The initialization and finalization functions are managed through a
new class gdbpy_initialize_file in python-internal.h.  This class
contains a single global vector of all the initialization and
finalization functions.

In each Python sub-system we create a new gdbpy_initialize_file
object, the object constructor takes care of registering the two
callback functions.

Now from python.c we can call static functions on the
gdbpy_initialize_file class which take care of walking the callback
list and invoking each callback in turn.

To slightly simplify the Python sub-system files I added a new macro
GDBPY_INITIALIZE_FILE, which hides the need to create an object.  We
can now just do this:

  GDBPY_INITIALIZE_FILE (gdbpy_initialize_registers);

One possible problem with this change is that there is now no
guaranteed ordering of how the various sub-systems are initialized (or
finalized).  To try and avoid dependencies creeping in I have added a
use of the environment variable GDB_REVERSE_INIT_FUNCTIONS, this is
the same environment variable used in the generated init.c file.

Just like with init.c, when this environment variable is set we
reverse the list of Python initialization (and finalization)
functions.  As there is already a test that starts GDB with the
environment variable set then this should offer some level of
protection against dependencies creeping in - though for full
protection I guess we'd need to run all gdb.python/*.exp tests with
the variable set.

I have tested this patch with the environment variable set, and saw no
regressions, so I think we are fine right now.

One other change of note was for gdbpy_initialize_gdb_readline, this
function previously returned void.  In order to make this function
have the correct signature I've updated its return type to int, and we
now return 0 to indicate success.

All of the other initialize (and finalize) functions have been made
static within their respective sub-system files.

There should be no user visible changes after this commit.

14 months agogdb/testsuite: more newline pattern cleanup
Andrew Burgess [Tue, 2 May 2023 09:56:55 +0000 (10:56 +0100)]
gdb/testsuite: more newline pattern cleanup

After this commit:

  commit e2f620135d92f7cd670af4e524fffec7ac307666
  Date:   Thu Mar 30 13:26:25 2023 +0100

      gdb/testsuite: change newline patterns used in gdb_test

It was pointed out in PR gdb/30403 that the same patterns can be found
in other lib/gdb.exp procs and that it would probably be a good idea
if these procs remained in sync with gdb_test.  Actually, the bug
specifically calls out gdb_test_multiple when using with '-wrap', but
I found a couple of other locations in gdb_continue_to_breakpoint,
gdb_test_multiline, get_valueof, and get_local_valueof.

In all these locations one or both of the following issues are
addressed:

  1. A leading pattern of '[\r\n]*' is pointless.  If there is a
  newline it will be matched, but if there is not then the testsuite
  doesn't care.  Also, as expect is happy to skip non-matched output
  at the start of a pattern, if there is a newline expect is happy to
  skip over it before matching the rest.  As such, this leading
  pattern is removed.

  2. Using '\[\r\n\]*$gdb_prompt' means that we will swallow
  unexpected blank lines at the end of a command's output, but also,
  if the pattern from the test script ends with a '\r', '\n', or '.'
  then these will partially match the trailing newline, with the
  remainder of the newline matched by the pattern from gdb.exp.  This
  split matching doesn't add any value, it's just something that has
  appeared as a consequence of how gdb.exp was originally written.  In
  this case the '\[\r\n\]*' is replaced with '\r\n'.

I've rerun the testsuite and fixed the regressions that I saw, these
were places where GDB emits a blank line at the end of the command
output, which we now need to explicitly match in the test script, this
was for:

  gdb.dwarf2/dw2-out-of-range-end-of-seq.exp
  gdb.guile/guile.exp
  gdb.python/python.exp

Or a location where the test script was matching part of the newline
sequence, while gdb.exp was previously matching the remainder of the
newline sequence.  Now we rely on gdb.exp to match the complete
newline sequence, this was for:

  gdb.base/commands.exp

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

14 months ago[gdb/testsuite] Generate long string in gdb.base/page.exp
Tom de Vries [Fri, 5 May 2023 16:57:06 +0000 (18:57 +0200)]
[gdb/testsuite] Generate long string in gdb.base/page.exp

I noticed in gdb.base/page.exp:
...
set fours [string repeat 4 40]
...
but then shortly afterwards:
...
    [list 1\r\n 2\r\n 3\r\n 444444444444444444444444444444]
...

Summarize the long string in the same way using string repeat:
...
    [list 1\r\n 2\r\n 3\r\n [string repeat 4 30]]
...

Tested on x86_64-linux.

14 months agogdb/testsuite: tighten patterns in build-id-no-debug-warning.exp
Andrew Burgess [Fri, 5 May 2023 12:38:04 +0000 (13:38 +0100)]
gdb/testsuite: tighten patterns in build-id-no-debug-warning.exp

Tighten the expected output pattern in the test script:

  gdb.debuginfod/build-id-no-debug-warning.exp

While working on some other patch I broke GDB such that this warning:

  warning: "FILENAME": separate debug info file has no debug info

(which is generated in build-id.c) didn't actually include the
FILENAME any more -- yet this test script continued to pass.  It turns
out that this script doesn't actually check for FILENAME.

This commit extends the test pattern to check for the full warning
string, including FILENAME, and also removes some uses of '.*' to make
the test stricter.

14 months agoSimplify decode_locdesc
Tom Tromey [Fri, 7 Apr 2023 21:31:43 +0000 (15:31 -0600)]
Simplify decode_locdesc

While looking into another bug, I noticed that the DWARF cooked
indexer picks up an address for this symbol:

 <1><82>: Abbrev Number: 2 (DW_TAG_variable)
    <83>   DW_AT_specification: <0x9f>
    <87>   DW_AT_location    : 10 byte block: e 0 0 0 0 0 0 0 0 e0  (DW_OP_const8u: 0 0; DW_OP_GNU_push_tls_address or DW_OP_HP_unknown)
    <92>   DW_AT_linkage_name: (indirect string, offset: 0x156): _ZN9container8tlsvar_0E

This happens because decode_locdesc allows the use of
DW_OP_GNU_push_tls_address.

This didn't make sense to me.  I looked into it a bit more, and I
think decode_locdesc is used in three ways:

1. Find a constant address of a symbol that happens to be encoded as a
   location expression.

2. Find the offset of a function in a virtual table.  (This one should
   probably be replaced by code to just evaluate the expression in
   gnu-v3-abi.c -- but there's no point yet because no compiler
   actually seems to emit correct DWARF here, see the bug linked in
   the patch.)

3. Find the offset of a field, if the offset is a constant.

None of these require TLS.

This patch simplifies decode_locdesc by removing any opcodes that
don't fit into the above.  It also changes the API a little, to make
it less difficult to use.

Regression tested on x86-64 Fedora 36.

14 months agoSimplify auto_load_expand_dir_vars and remove substitute_path_component
Tom Tromey [Tue, 4 Apr 2023 18:50:03 +0000 (12:50 -0600)]
Simplify auto_load_expand_dir_vars and remove substitute_path_component

This simplifies auto_load_expand_dir_vars to first split the string,
then do any needed substitutions.  This was suggested by Simon, and is
much simpler than the current approach.

Then this patch also removes substitute_path_component, as it is no
longer called.  This is nice because it helps with the long term goal
of removing utils.h.

Regression tested on x86-64 Fedora 36.

14 months ago[gdb/testsuite] Add gdb.base/wrap-line.exp
Tom de Vries [Fri, 5 May 2023 12:34:00 +0000 (14:34 +0200)]
[gdb/testsuite] Add gdb.base/wrap-line.exp

Add a test-case that tests prompt edit wrapping in CLI, both
for TERM=xterm and TERM=ansi, both with auto-detected and hard-coded width.

In the TERM=ansi case with auto-detected width we run into PR cli/30346, so
add a KFAIL for that failure mode.

Tested on x86_64-linux.

14 months ago[gdb/testsuite] Add gdb.tui/wrap-line.exp
Tom de Vries [Fri, 5 May 2023 10:20:20 +0000 (12:20 +0200)]
[gdb/testsuite] Add gdb.tui/wrap-line.exp

Add a test-case that tests prompt edit wrapping behaviour in the tuiterm, both
for CLI and TUI, both with auto-detected and hard-coded width.

In the CLI case with auto-detected width we run into PR cli/30411, so add a
KFAIL for that failure mode.

Tested on x86_64-linux.

14 months agoDebug info is lost for functions only called from functions marked with cmse_nonsecur...
Nick Clifton [Fri, 5 May 2023 10:11:32 +0000 (11:11 +0100)]
Debug info is lost for functions only called from functions marked with cmse_nonsecure_entr

  PR 30354
  * elf32-arm.c (elf32_arm_gc_mark_extra_sections): If any debug sections are marked then rerun the extra marking in order to pick up any dependencies.

14 months agoAutomatic date update in version.in
GDB Administrator [Fri, 5 May 2023 00:00:42 +0000 (00:00 +0000)]
Automatic date update in version.in

14 months agoRevert "gdb/testsuite: add KFAILs to gdb.reverse/step-reverse.exp"
Bruno Larsen [Thu, 4 May 2023 10:31:01 +0000 (12:31 +0200)]
Revert "gdb/testsuite: add KFAILs to gdb.reverse/step-reverse.exp"

This reverts commit 476410b3bca1389ee69e9c8fa18aaee16793a56d.

One of Simon's recent commits (2a740b3ba4c9f39c86dd75e0914ee00942cab471)
changed the way recording a remote target works and fixed the underlying
issue of the bug, so the KFails can be removed from the test.

Approved-By: Tom Tromey <tom@tromey.com>
14 months agoDon't treat references to compound values as "simple".
Gareth Rees [Sat, 11 Mar 2023 11:49:34 +0000 (11:49 +0000)]
Don't treat references to compound values as "simple".

SUMMARY

The '--simple-values' argument to '-stack-list-arguments' and similar
GDB/MI commands does not take reference types into account, so that
references to arbitrarily large structures are considered "simple" and
printed. This means that the '--simple-values' argument cannot be used
by IDEs when tracing the stack due to the time taken to print large
structures passed by reference.

DETAILS

Various GDB/MI commands ('-stack-list-arguments', '-stack-list-locals',
'-stack-list-variables' and so on) take a PRINT-VALUES argument which
may be '--no-values' (0), '--all-values' (1) or '--simple-values' (2).
In the '--simple-values' case, the command is supposed to print the
name, type, and value of variables with simple types, and print only the
name and type of variables with compound types.

The '--simple-values' argument ought to be suitable for IDEs that need
to update their user interface with the program's call stack every time
the program stops. However, it does not take C++ reference types into
account, and this makes the argument unsuitable for this purpose.

For example, consider the following C++ program:

    struct s {
        int v[10];
    };

    int
    sum(const struct s &s)
    {
        int total = 0;
        for (int i = 0; i < 10; ++i) total += s.v[i];
        return total;
    }

    int
    main(void)
    {
        struct s s = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } };
        return sum(s);
    }

If we start GDB in MI mode and continue to 'sum', the behaviour of
'-stack-list-arguments' is as follows:

    (gdb)
    -stack-list-arguments --simple-values
    ^done,stack-args=[frame={level="0",args=[{name="s",type="const s &",value="@0x7fffffffe310: {v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}"}]},frame={level="1",args=[]}]

Note that the value of the argument 's' was printed, even though 's' is
a reference to a structure, which is not a simple value.

See https://github.com/microsoft/MIEngine/pull/673 for a case where this
behaviour caused Microsoft to avoid the use of '--simple-values' in
their MIEngine debug adapter, because it caused Visual Studio Code to
take too long to refresh the call stack in the user interface.

SOLUTIONS

There are two ways we could fix this problem, depending on whether we
consider the current behaviour to be a bug.

1. If the current behaviour is a bug, then we can update the behaviour
   of '--simple-values' so that it takes reference types into account:
   that is, a value is simple if it is neither an array, struct, or
   union, nor a reference to an array, struct or union.

   In this case we must add a feature to the '-list-features' command so
   that IDEs can detect that it is safe to use the '--simple-values'
   argument when refreshing the call stack.

2. If the current behaviour is not a bug, then we can add a new option
   for the PRINT-VALUES argument, for example, '--scalar-values' (3),
   that would be suitable for use by IDEs.

   In this case we must add a feature to the '-list-features' command
   so that IDEs can detect that the '--scalar-values' argument is
   available for use when refreshing the call stack.

PATCH

This patch implements solution (1) as I think the current behaviour of
not printing structures, but printing references to structures, is
contrary to reasonable expectation.

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

14 months agoStop the linker from loosing the entry point for COFF/PE code when compiling with...
Nick Clifton [Thu, 4 May 2023 13:24:16 +0000 (14:24 +0100)]
Stop the linker from loosing the entry point for COFF/PE code when compiling with LTO enabled.

  PR 30300
  * emultempl/pep.em (set_entry_point): Add an undefined reference to the entry point if it has been constructed heuristically.
  * emultempl/pe.em (set_entry_point): Likewise.

14 months agold: pru: Place exception-handling sections correctly
Dimitar Dimitrov [Thu, 4 May 2023 11:41:55 +0000 (12:41 +0100)]
ld: pru: Place exception-handling sections correctly

  * scripttempl/pru.sc (OUTPUT_SECTION_ALIGN): New helper variable to place at end of DMEM output sections.
  (.data): Use the helper variable.
  (.eh_frame): New output section.
  (.gnu_extab): Ditto.
  (.gcc_except_table): Ditto.
  (.resource_table): Use the helper variable.

14 months agoRISC-V: tighten post-relocation-operator separator expectation
Jan Beulich [Thu, 4 May 2023 08:24:36 +0000 (10:24 +0200)]
RISC-V: tighten post-relocation-operator separator expectation

As per the spec merely a blank isn't okay as a separator, the operand
to the relocation function ought to be parenthesized. Enforcing this
then also eliminates an inconsistency in that

lui t0, %hi sym
lui t0, %hi 0x1000

were accepted, but

lui t0, %hi +sym
lui t0, %hi -0x1000

were not.

14 months agogas: fix building tc-bpf.c on s390x
Ilya Leoshkevich [Thu, 4 May 2023 06:35:30 +0000 (08:35 +0200)]
gas: fix building tc-bpf.c on s390x

char is unsigned on s390x, so there are a lot of warnings like:

    gas/config/tc-bpf.c: In function 'get_token':
    gas/config/tc-bpf.c:900:14: error: comparison is always false due to limited range of data type [-Werror=type-limits]
      900 |       if (ch == EOF || len > MAX_TOKEN_SZ)
          |              ^~

Change its type to int, like in the other similar code.

There is also:

    gas/config/tc-bpf.c:735:30: error: 'bpf_endianness' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      735 |    dst, be ? size[endianness - BPF_BE16] : size[endianness - BPF_LE16]);
          |                   ~~~~~~~~~~~^~~~~~~~~~

-Wmaybe-uninitialized doesn't seem to understand the FSM; just
initialize bpf_endianness to silence it.  Add an assertion to
build_bpf_endianness() in order to catch potential bugs.

14 months agoMIPS: revert "default r6 if vendor is img"
YunQiang Su [Thu, 4 May 2023 01:45:22 +0000 (09:45 +0800)]
MIPS: revert "default r6 if vendor is img"

In commit: 9171de358f230b64646bbb525a74e5f8e3dbe0dc,
The default output is set to r6 if the vendor is img,
It is ugly and should not be in upstream.

Let's revert it.

14 months agoAutomatic date update in version.in
GDB Administrator [Thu, 4 May 2023 00:00:21 +0000 (00:00 +0000)]
Automatic date update in version.in

14 months ago[gdb/build] Fix frame_list position in frame.c
Tom de Vries [Wed, 3 May 2023 19:43:03 +0000 (21:43 +0200)]
[gdb/build] Fix frame_list position in frame.c

In commit 995a34b1772 ("Guard against frame.c destructors running before
frame-info.c's") the following problem was addressed.

The frame_info_ptr destructor:
...
  ~frame_info_ptr ()
  {
    frame_list.erase (frame_list.iterator_to (*this));
  }
...
uses frame_list, which is a static member of class frame_info_ptr,
instantiated in frame-info.c:
...
intrusive_list<frame_info_ptr> frame_info_ptr::frame_list;
...

Then there's a static frame_info_pointer variable named selected_frame in
frame.c:
...
static frame_info_ptr selected_frame;
...

Because the destructor of selected_frame uses frame_list, its destructor needs
to be called before the destructor of frame_list.

But because they're in different compilation units, the initialization order and
consequently destruction order is not guarantueed.

The commit fixed this by handling the case that the destructor of frame_list
is called first, adding a check on is_linked ():
...
   ~frame_info_ptr ()
   {
-    frame_list.erase (frame_list.iterator_to (*this));
+    /* If this node has static storage, it may be deleted after
+       frame_list.  Attempting to erase ourselves would then trigger
+       internal errors, so make sure we are still linked first.  */
+    if (is_linked ())
+      frame_list.erase (frame_list.iterator_to (*this));
   }
...

However, since then frame_list has been moved into frame.c, and
initialization/destruction order is guarantueed inside a compilation unit.

Revert aforementioned commit, and fix the destruction order problem by moving
frame_list before selected_frame.

Reverting the commit is another way of fixing the already fixed
Wdangling-pointer warning reported in PR build/30413, in a different way than
commit 9b0ccb1ebae ("Pass const frame_info_ptr reference for
skip_[language_]trampoline").

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tested on x86_64-linux.
PR build/30413
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413

14 months agogdb/show_args_command: print to the ui_file argument
Lancelot SIX [Wed, 3 May 2023 10:56:48 +0000 (11:56 +0100)]
gdb/show_args_command: print to the ui_file argument

The show_args_command uses gdb_printf without specifying the ui_file.
This means that it prints to gdb_stdout instead of the stream given as
an argument to the function.

This commit fixes this.

Reviewed-By: Tom Tromey <tom@tromey.com>
14 months agoMake ar faster
Oleg Tolmatcev [Wed, 3 May 2023 15:23:13 +0000 (16:23 +0100)]
Make ar faster

 * archive.c (_bfd_write_archive_contents): Use a larger buffer in order to improve efficiency.

14 months agoPass const frame_info_ptr reference for skip_[language_]trampoline
Mark Wielaard [Tue, 2 May 2023 18:23:32 +0000 (20:23 +0200)]
Pass const frame_info_ptr reference for skip_[language_]trampoline

g++ 13.1.1 produces a -Werror=dangling-pointer=

In file included from ../../binutils-gdb/gdb/frame.h:75,
                 from ../../binutils-gdb/gdb/symtab.h:40,
                 from ../../binutils-gdb/gdb/language.c:33:
In member function ‘void intrusive_list<T, AsNode>::push_empty(T&) [with T = frame_info_ptr; AsNode = intrusive_base_node<frame_info_ptr>]’,
    inlined from ‘void intrusive_list<T, AsNode>::push_back(reference) [with T = frame_info_ptr; AsNode = intrusive_base_node<frame_info_ptr>]’ at gdbsupport/intrusive_list.h:332:24,
    inlined from ‘frame_info_ptr::frame_info_ptr(const frame_info_ptr&)’ at gdb/frame.h:241:26,
    inlined from ‘CORE_ADDR skip_language_trampoline(frame_info_ptr, CORE_ADDR)’ at gdb/language.c:530:49:
gdbsupport/intrusive_list.h:415:12: error: storing the address of local variable ‘<anonymous>’ in ‘frame_info_ptr::frame_list.intrusive_list<frame_info_ptr>::m_back’ [-Werror=dangling-pointer=]
  415 |     m_back = &elem;
      |     ~~~~~~~^~~~~~~
gdb/language.c: In function ‘CORE_ADDR skip_language_trampoline(frame_info_ptr, CORE_ADDR)’:
gdb/language.c:530:49: note: ‘<anonymous>’ declared here
  530 |       CORE_ADDR real_pc = lang->skip_trampoline (frame, pc);
      |                           ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
gdb/frame.h:359:41: note: ‘frame_info_ptr::frame_list’ declared here
  359 |   static intrusive_list<frame_info_ptr> frame_list;
      |                                         ^~~~~~~~~~

Each new frame_info_ptr is being pushed on a static frame list and g++
cannot see why that is safe in case the frame_info_ptr is created and
destroyed immediately when passed as value.

It isn't clear why only in this one place g++ sees the issue (probably
because it can inline enough code in this specific case).

Since passing the frame_info_ptr as const reference is cheaper, use
that as workaround for this warning.

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

Tested-by: Kevin Buettner <kevinb@redhat.com>
Reviewed-by: Kevin Buettner <kevinb@redhat.com>
Reviewed-by: Tom Tromey <tom@tromey.com>
14 months agoImprove the speed of computing checksums for COFF binaries.
Oleg Tolmatcev [Wed, 3 May 2023 14:36:43 +0000 (15:36 +0100)]
Improve the speed of computing checksums for COFF binaries.

 * coffcode.h (coff_read_word_from_buffer): New function.
 * coffcode.h (COFF_CHECKSUM_BUFFER_SIZE): New constant.
 * coffcode.h (coff_compute_checksum): Improve speed by reducing the number of seeks and reads used.

14 months agoRemove unused args from bfd_make_debug_symbol
Alan Modra [Wed, 3 May 2023 06:23:29 +0000 (15:53 +0930)]
Remove unused args from bfd_make_debug_symbol

The ptr and size args are unused.  Make the function look the same as
bfd_make_empty_symbol.

14 months agoGenerated docs and include files
Alan Modra [Sun, 30 Apr 2023 11:12:30 +0000 (20:42 +0930)]
Generated docs and include files

bfd/doc/chew.c extracts documentation from source code comments
annotated with keywords, and generates much of bfd.h and libbfd.h from
those same comments.  The docs have suffered from people (me too)
adding things like CODE_FRAGMENT to the source to put code into bfd.h
without realising that CODE_FRAGMENT also puts @example around said
code into the docs.  So we have random senseless things in the docs.
This patch fixes that problem (well, the senseless things from
CODE_FRAGMENT), moves most of the code out of bfd-in.h, and improves a
few chew.c features.  libbfd.h now automatically gets ATTRIBUTE_HIDDEN
prototypes, and indentation in bfd.h and libbfd.h is better.

14 months agoMove bfd_alloc, bfd_zalloc and bfd_release to libbfd.c
Alan Modra [Wed, 3 May 2023 03:30:11 +0000 (13:00 +0930)]
Move bfd_alloc, bfd_zalloc and bfd_release to libbfd.c

These functions don't belong in opncls.c.

* libbfd-in.h (bfd_release): Delete prototype.
* opncls.c (bfd_alloc, bfd_zalloc, bfd_release): Move to..
* libbfd.c: ..here.  Include objalloc.c and provide bfd_release
with a FUNCTION comment.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.

14 months agoMove bfd_elf_bfd_from_remote_memory to opncls.c
Alan Modra [Wed, 3 May 2023 03:17:15 +0000 (12:47 +0930)]
Move bfd_elf_bfd_from_remote_memory to opncls.c

bfd_elf_bfd_from_remote_memory is just a wrapper, and the function
could be implemented for other formats.  Move it to opncls.c because
it acts a little like some of the other bfd_open* routines.  Also give
it the usual FUNCTION etc. comment so prototypes and docs are handled
automatically.

* elf.c (bfd_elf_bfd_from_remote_memory): Move to..
* opncls.c: ..here, add FUNCTION comment.
* bfd-in.h (bfd_elf_bfd_from_remote_memory): Delete prototype.
* bfd-in2.h: Regenerate.

14 months agohash.c: replace some unsigned long with unsigned int
Alan Modra [Tue, 2 May 2023 11:00:38 +0000 (20:30 +0930)]
hash.c: replace some unsigned long with unsigned int

* hash.c (higher_prime_number): Use uint32_t param, return value,
tables and variables.
(bfd_default_hash_table_size): Make it an unsigned int.
(bfd_hash_set_default_size): Use unsigned int param and return.
* bfd-in.h (bfd_hash_set_default_size): Update prototype.
* bfd-in2.h: Regenerate.

14 months agolibbfc.c: Use stdint types for unsigned char and unsigned long
Alan Modra [Sat, 29 Apr 2023 03:30:46 +0000 (13:00 +0930)]
libbfc.c: Use stdint types for unsigned char and unsigned long

* libbfd.c (bfd_put_8): Use bfd_byte rather than unsigned char.
(bfd_get_8, bfd_get_signed_8): Likewise.
(_bfd_read_unsigned_leb128, _bfd_safe_read_leb128): Likewise.
(_bfd_read_signed_leb128): Likewise.
(bfd_getb24, bfd_getl24): Replace unsigned long with uint32_t.
(bfd_getb32, bfd_getl32): Likewise.
(bfd_getb_signed_32, bfd_getl_signed_32): Likewise.

14 months agoChange signature of bfd crc functions
Alan Modra [Sat, 29 Apr 2023 01:07:28 +0000 (10:37 +0930)]
Change signature of bfd crc functions

The crc calculated is 32 bits.  Replace uses of unsigned long with
uint32_t.  Also use bfd_byte* for buffers.

bfd/
* opncls.c (bfd_calc_gnu_debuglink_crc32): Use stdint types.
(bfd_get_debug_link_info_1, bfd_get_debug_link_info): Likewise.
(separate_debug_file_exists, bfd_follow_gnu_debuglink): Likewise.
(bfd_fill_in_gnu_debuglink_section): Likewise.
* bfd-in2.h: Regenerate.
gdb/
* auto-load.c (auto_load_objfile_script): Update type of
bfd_get_debug_link_info argument.
* symfile.c (find_separate_debug_file_by_debuglink): Likewise.
* gdb_bfd.c (get_file_crc): Update type of
bfd_calc_gnu_debuglink_crc32 argument.

14 months ago_bfd_mips_elf_lo16_reloc vallo comment
Alan Modra [Sat, 29 Apr 2023 01:30:30 +0000 (11:00 +0930)]
_bfd_mips_elf_lo16_reloc vallo comment

This explains exactly why the high reloc adjustment is as it is,
replacing the rather nebulous existing comment.  I've also changed the
expression from (lo+0x8000)&0xffff to (lo&0xffff)^0x8000 which better
matches part of the standard 16-bit sign extension (resulting in
exactly the same value), and hoisted the calculation out of the loop.

* elfxx-mips.c (_bfd_mips_elf_lo16_reloc): Expand vallo
comment.  Hoist calculation out of loop.

14 months agogdb.base/watchpoint-unaligned.exp: Always initialize wpoffset_to_wpnum
Alexandra Hájková [Tue, 2 May 2023 20:33:49 +0000 (22:33 +0200)]
gdb.base/watchpoint-unaligned.exp: Always initialize wpoffset_to_wpnum

Initialize wpoffset_to_wpnumto avoid TCL error which happens in some aarch64 types.

ERROR: in testcase /root/build/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
ERROR:  can't read "wpoffset_to_wpnum(1)": no such element in array
ERROR:  tcl error code TCL READ VARNAME
ERROR:  tcl error info:
can't read "wpoffset_to_wpnum(1)": no such element in array
    while executing

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

Reviewed-by: Luis Machado <luis.machado@arm.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
14 months agoxcoffread.c: Fix -Werror=dangling-pointer= issue with main_subfile.
Mark Wielaard [Sat, 29 Apr 2023 20:46:11 +0000 (22:46 +0200)]
xcoffread.c: Fix -Werror=dangling-pointer= issue with main_subfile.

GCC 13 points out that main_subfile has local function scope, but a
pointer to it is assigned to the global inclTable array subfile
element field:

In function ‘void process_linenos(CORE_ADDR, CORE_ADDR)’,
    inlined from ‘void aix_process_linenos(objfile*)’ at xcoffread.c:727:19,
    inlined from ‘void aix_process_linenos(objfile*)’ at xcoffread.c:720:1:
xcoffread.c:629:37: error: storing the address of local variable ‘main_subfile’ in ‘*inclTable.19_45 + _28._inclTable::subfile’ [-Werror=dangling-pointer=]
  629 |               inclTable[ii].subfile = &main_subfile;
      |               ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
xcoffread.c: In function ‘void aix_process_linenos(objfile*)’:
xcoffread.c:579:18: note: ‘main_subfile’ declared here
  579 |   struct subfile main_subfile;
      |                  ^~~~~~~~~~~~
xcoffread.c:496:19: note: ‘inclTable’ declared here
  496 | static InclTable *inclTable;    /* global include table */
      |                   ^~~~~~~~~

Fix this by making main_subfile file static. And allocate and
deallocated together with inclTable in allocate_include_entry and
xcoff_symfile_finish. Adjust the use of main_subfile in
process_linenos to take a pointer to the subfile.

14 months ago[gdb/testsuite] Use set in lmap in gdb.dwarf2/dw2-abs-hi-pc.exp
Tom de Vries [Tue, 2 May 2023 15:37:58 +0000 (17:37 +0200)]
[gdb/testsuite] Use set in lmap in gdb.dwarf2/dw2-abs-hi-pc.exp

In gdb.dwarf2/dw2-abs-hi-pc.exp we do:
...
set sources [lmap i $sources { expr { "$srcdir/$subdir/$i" } }]
...

The use of expr is not idiomatic.  Fix this by using set instead:
...
set sources [lmap i $sources { set tmp $srcdir/$subdir/$i }]
...

Reported-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andreas Schwab <schwab@suse.de>
14 months agoFix Assertion pid != 0 failure in AIX.
Aditya Kamath [Tue, 2 May 2023 15:08:14 +0000 (10:08 -0500)]
Fix Assertion pid != 0 failure in AIX.

In AIX if there is a main and a thread created from it , then once the
program completed execution and goes to pd_disable () inferior_ptid
had pid 0 leading to an assertion failure while finding the thread's data
in aix-thread.c file.

This patch is a fix for the same.

14 months agoRemove error_stream
Tom Tromey [Sun, 16 Apr 2023 18:40:33 +0000 (12:40 -0600)]
Remove error_stream

error_stream is trivial and only used in a couple of spots in
breakpoint.c.  This patch removes it in favor of just writing it out
at the spots where it was used.

14 months agoRemove Dimity Diky as MSP430 maintainer.
Nick Clifton [Tue, 2 May 2023 12:33:53 +0000 (13:33 +0100)]
Remove Dimity Diky as MSP430 maintainer.

14 months agogdb/testsuite: compile gdb.linespec/cp-completion-aliases.exp as C++
Andrew Burgess [Tue, 2 May 2023 10:48:46 +0000 (11:48 +0100)]
gdb/testsuite: compile gdb.linespec/cp-completion-aliases.exp as C++

Noticed in passing that the prepare_for_testing call in
gdb.linespec/cp-completion-aliases.exp does not pass the 'c++' flag,
despite this being a C++ test.

I guess, as the source file has the '.cc' extension, all the compilers
are doing the right thing anyway -- the source file uses templates, so
is definitely being compiled as C++.

I noticed this when I tried to set CXX_FOR_TARGET (but not
CC_FOR_TARGET) and spotted that this script was still using the C
compiler.

Fixed in this commit by adding the 'c++' flag for prepare_for_testing.

14 months agoAutomatic date update in version.in
GDB Administrator [Tue, 2 May 2023 00:00:42 +0000 (00:00 +0000)]
Automatic date update in version.in

14 months agoDocument DAP 'launch' parameter
Tom Tromey [Fri, 14 Apr 2023 18:16:58 +0000 (12:16 -0600)]
Document DAP 'launch' parameter

The Debugger Adapter Protocol defines a "launch" request but leaves
the parameters up to the implementation:

    Since launching is debugger/runtime specific, the arguments for
    this request are not part of this specification.

This patch adds some documentation for the parameter GDB currently
defines.  Note that I plan to add more parameters here, and perhaps
there will be other extensions in time as well.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
14 months agogdb: remove ui_interp_info
Simon Marchi [Fri, 28 Apr 2023 18:27:13 +0000 (14:27 -0400)]
gdb: remove ui_interp_info

I don't think that having struct ui_interp_info separated from struct ui
is very useful.  As of today, it looks like an unnecessary indirection
layer.  Move the contents of ui_interp_info directly into struct ui, and
update all users.

Change-Id: I817ba6e047dbcc4ba15b666af184b40bfed7e521

14 months agogdb: store interps in an intrusive_list
Simon Marchi [Fri, 28 Apr 2023 18:27:12 +0000 (14:27 -0400)]
gdb: store interps in an intrusive_list

Use intrusive_list, instead of hand-made linked list.

Change-Id: Idc857b40dfa3e3c35671045898331cca2c928097

14 months agogdb: move struct ui and related things to ui.{c,h}
Simon Marchi [Fri, 28 Apr 2023 18:27:11 +0000 (14:27 -0400)]
gdb: move struct ui and related things to ui.{c,h}

I'd like to move some things so they become methods on struct ui.  But
first, I think that struct ui and the related things are big enough to
deserve their own file, instead of being scattered through top.{c,h} and
event-top.c.

Change-Id: I15594269ace61fd76ef80a7b58f51ff3ab6979bc

14 months agoTurn set_inferior_args_vector into method of inferior
Tom Tromey [Fri, 14 Apr 2023 19:18:05 +0000 (13:18 -0600)]
Turn set_inferior_args_vector into method of inferior

This patch turns set_inferior_args_vector into an overload of
inferior::set_args.

Regression tested on x86-64 Fedora 36.

14 months agoRemove evaluate_type
Tom Tromey [Fri, 28 Apr 2023 13:26:44 +0000 (07:26 -0600)]
Remove evaluate_type

Like evaluate_expression, evaluate_type is also just a simple wrapper.
Removing it makes the code a little nicer.

14 months agoRemove evaluate_expression
Tom Tromey [Fri, 28 Apr 2023 13:24:59 +0000 (07:24 -0600)]
Remove evaluate_expression

evaluate_expression is just a little wrapper for a method on
expression.  Removing it also removes a lot of ugly (IMO) calls to
get().