Commit Graph

114509 Commits

Author SHA1 Message Date
Simon Marchi
2a740b3ba4 gdb/record-full: disable range stepping when resuming threads
I see these failures, when running with the native-gdbserver of
native-extended-gdbserver boards:

    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.reverse/finish-reverse-next.exp ...
    FAIL: gdb.reverse/finish-reverse-next.exp: reverse next 1 LEP from function body
    FAIL: gdb.reverse/finish-reverse-next.exp: reverse next 2 at b = 5, from function body
    FAIL: gdb.reverse/finish-reverse-next.exp: reverse next 1 GEP call from function body
    FAIL: gdb.reverse/finish-reverse-next.exp: reverse next 2 at b = 50 from function body

Let's use this simpler program to illustrate the problem:

    int main()
    {
      int a = 362;
      a = a * 17;
      return a;
    }

It compiles down to:

    int a = 362;
    401689:       c7 45 fc 6a 01 00 00    movl   $0x16a,-0x4(%rbp)
    a = a * 17;
    401690:       8b 55 fc                mov    -0x4(%rbp),%edx
    401693:       89 d0                   mov    %edx,%eax
    401695:       c1 e0 04                shl    $0x4,%eax
    401698:       01 d0                   add    %edx,%eax
    40169a:       89 45 fc                mov    %eax,-0x4(%rbp)
    return a;
    40169d:       8b 45 fc                mov    -0x4(%rbp),%eax

When single stepping these lines, debugging locally, while recording,
these are the recorded instructions (basically one for each instruction
shown above):

    (gdb) maintenance print record-instruction 0
    4 bytes of memory at address 0x00007fffffffdc5c changed from: 6a 01 00 00
    Register rip changed: (void (*)()) 0x40169a <main+21>
    (gdb) maintenance print record-instruction -1
    Register rax changed: 5792
    Register eflags changed: [ PF AF IF ]
    Register rip changed: (void (*)()) 0x401698 <main+19>
    (gdb) maintenance print record-instruction -2
    Register rax changed: 362
    Register eflags changed: [ PF ZF IF ]
    Register rip changed: (void (*)()) 0x401695 <main+16>
    (gdb) maintenance print record-instruction -3
    Register rax changed: 4200069
    Register rip changed: (void (*)()) 0x401693 <main+14>
    (gdb) maintenance print record-instruction -4
    Register rdx changed: 140737488346696
    Register rip changed: (void (*)()) 0x401690 <main+11>
    (gdb) maintenance print record-instruction -5
    4 bytes of memory at address 0x00007fffffffdc5c changed from: 00 00 00 00
    Register rip changed: (void (*)()) 0x401689 <main+4>
    (gdb) maintenance print record-instruction -6
    Not enough recorded history

But when debugging remotely:

    (gdb) maintenance print record-instruction 0
    Register rdx changed: 140737488346728
    Register rip changed: (void (*)()) 0x401690 <main+11>
    (gdb) maintenance print record-instruction -1
    4 bytes of memory at address 0x00007fffffffdc7c changed from: 00 00 00 00
    Register rip changed: (void (*)()) 0x401689 <main+4>
    (gdb) maintenance print record-instruction -2
    Not enough recorded history

In this list, we only have entries for the beginning of each line.  This
is because of the remote target's support for range stepping.  The
record-full layer can only record instructions when the underlying
process target reports a stop.  With range stepping, the remote target
single-steps multiple instructions at a time, so the record-full target
doesn't get to see and record them all.

Fix this by making the record-full layer disable range-stepping
before handing the resume request to the beneath layer, forcing the
remote target to report stops for each instruction.

Change-Id: Ia95ea62720bbcd0b6536a904360ffbf839eb823d
2023-04-28 14:30:22 -04:00
Keith Seitz
1956da78cf Allow strings with printf/eval
PR 13098 explains that if a user attempts to use a string with either
`printf' (or `eval'), gdb returns an error (inferior not running):

(gdb) printf "%s\n", "hello"
evaluation of this expression requires the target program to be active

However, the parser can certainly handle this case:

(gdb) p "hello"
$1 = "hello"

This discrepancy occurs because printf_c_string does not handle
this specific case.  The passed-in value that we are attempting to print
as a string is TYPE_CODE_ARRAY but it's lval type is not_lval.

printf_c_string will only attempt to print a string from the value's
contents when !TYPE_CODE_PTR, lval is lval_internalvar, and the value's
type is considered a string type:

  if (value->type ()->code () != TYPE_CODE_PTR
      && value->lval () == lval_internalvar
      && c_is_string_type_p (value->type ()))
    {
      ...
    }

Otherwise, it attempts to read the value of the string from the target's
memory (which is what actually generates the "evaluation of this ..."
error message).
2023-04-28 10:43:20 -07:00
Tom Tromey
005b65e801 Move find_minimal_symbol_address to minsyms.c
I found find_minimal_symbol_address in parse.c, but it seems to me
that it belongs in minsyms.c.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-04-28 11:16:59 -06:00
Tom Tromey
a38b832238 Do not change type in get_discrete_low_bound
get_discrete_low_bound has this code:

    /* Set unsigned indicator if warranted.  */
    if (low >= 0)
      type->set_is_unsigned (true);

It's bad to modify a type in a getter like this, so this patch removes
this code.  FWIW I looked and this code has been there since at least
1999 (it was in the initial sourceware import).

Types in general would benefit from const-ification, which would
probably reveal more code like this, but I haven't attempted that.

Regression tested on x86-64 Fedora 36.

Reviewed-by: Kevin Buettner <kevinb@redhat.com>
2023-04-28 11:05:45 -06:00
Tom Tromey
ebb83b77a7 Remove @var from @defun in Python documentation
Eli pointed out that @var isn't needed in @defun in Texinfo.  This
patch removes the cases I found in python.texi.  I also renamed some
variables in one spot, because "-" isn't valid in a Python variable
name.
2023-04-28 10:51:58 -06:00
Andrew Burgess
1f7f972f59 gdb/testsuite: additional test fixes after gdb_test changes
After this commit:

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

      gdb/testsuite: change newline patterns used in gdb_test

There were some regressions in gdb.trace/*.exp tests when run with the
native-gdbserver board.  This commit fixes these regressions.

All the problems are caused by unnecessary trailing newline characters
included in the patterns passed to gdb_test.  After the above commit
the testsuite is stricter when matching trailing newlines, and so the
additional trailing newline characters are now causing the test to
fail.  Fix by removing all the excess trailing newline characters.

In some cases this cleanup means we should use gdb_test_no_output,
I've done that where appropriate.  In a couple of other places I've
made use of multi_line to better build the expected output pattern.
2023-04-28 16:48:21 +01:00
H.J. Lu
64b59b6bb2 ld: Use run_cc_link_tests for PR ld/26391 tests
Use run_cc_link_tests for PR ld/26391 tests to compile PR ld/26391 tests
in C.

	PR ld/30002
	* testsuite/ld-elf/elf.exp: Use run_cc_link_tests for PR ld/26391
	tests.
2023-04-28 08:38:17 -07:00
Eli Zaretskii
7408b951b8 Fix a typo in gdb.texinfo. 2023-04-28 18:36:30 +03:00
Nelson Chu
03e63766ef RISC-V: Enable x0 base relaxation for relax_pc even if --no-relax-gp.
Let --no-relax-gp only disable the gp relaxation for lui and pcrel
relaxations, since x0 base and gp relaxations are different optimizations
in fact, but just use the same function to handle.

bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_pc): Like _bfd_riscv_relax_lui,
	set gp to zero when --no-relax-gp, then we should still keep the
	x0 base relaxation.
	(_bfd_riscv_relax_section): Enable _bfd_riscv_relax_pc when
	--no-relax-gp, we will disable the gp relaxation in the
	_bfd_riscv_relax_pc.
2023-04-28 14:27:35 +08:00
Nelson Chu
a48ddc3b57 RISC-V: Relax R_RISCV_[PCREL_]LO12_I/S to R_RISCV_GPREL_I/S for undefined weak.
bfd/
	*elfnn-riscv.c (_bfd_riscv_relax_lui): For undefined weak symbol,
	just relax the R_RISCV_LO12_I/S to R_RISCV_GPREL_I/S, and then don't
	update the rs1 to zero until relocate_section.
	(_bfd_riscv_relax_pc): Likewise, but for R_RISCV_PCREL_LO12_I/S.
2023-04-28 14:27:32 +08:00
Jan Beulich
e4452aa670 x86: limit data passed to i386_dis_printf()
The function doesn't use "ins" for other than retrieving "info". Remove
a thus pointless level of indirection.
2023-04-28 08:24:41 +02:00
Jan Beulich
ffe983ed7a x86: limit data passed to prefix_name()
Make apparent that neither what "ins" points to nor, in particular, that
"ins->info->private_data" is actually used in the function.
2023-04-28 08:24:11 +02:00
Jan Beulich
6b50f5f4cb x86/Intel: reduce ELF/PE conditional scope in x86_cons()
All the Intel syntax related state adjustments apply independent of
target or object format.
2023-04-28 08:20:15 +02:00
Jan Beulich
2b6132c33c gas: move shift count check
... out of mainline code, grouping together the two case labels. This
then also make more obvious that the comment there applies to both forms
of shifts.
2023-04-28 08:19:53 +02:00
Jan Beulich
1f506c06ef x86: rework AMX control insn disassembly
Consistently do 64-bit first, VEX.L second, VEX.W third, ModR/M fourth,
and only then prefix, resulting in fewer table entries. Note that in the
course of the re-work
- TILEZERO has a previously missing decode step through rm_table[]
  added,
- a wrong M_0 suffix for TILEZERO is also corrected to be M_1 (now an
  infix).
2023-04-28 08:19:34 +02:00
Jan Beulich
be3d663386 x86: rework AMX multiplication insn disassembly
Consistently do 64-bit first, ModR/M second, VEX.L third, VEX.W fourth,
and prefix last, resulting in fewer table entries. Note that in the
course of the re-work wrong M_0 suffixes are also corrected to be M_1
(partly infixes now).

Since it ended up confusing while testing the change, also adjust the
test name in x86-64-amx-bad.d (to be distinct from x86-64-amx.d's).
2023-04-28 08:19:19 +02:00
Alan Modra
143a12bd5a Re: Keeping track of rs6000-coff archive element pointers
Commit de7b90610e left a hole in the element checking, explained by
the comment added to _bfd_xcoff_openr_next_archived_file.  While
fixing this, tidy some types used to hold unsigned values so that
casts are not needed to avoid signed/unsigned comparison warnings.
Also tidy a few things in xcoff.h.

bfd/
	* coff-rs6000.c (_bfd_xcoff_openr_next_archived_file): Check
	that we aren't pointing back at the last element.  Make
	filestart a ufile_ptr.  Update for xcoff_artdata change.
	(_bfd_strntol, _bfd_strntoll): Return unsigned values.
	(_bfd_xcoff_slurp_armap): Make off a ufile_ptr.
	(add_ranges): Update for xcoff_artdata change.
	* libbfd-in.h (struct artdata): Make first_file_filepos a
	ufile_ptr.
	* libbfd.h: Regenerate.
include/
	* coff/xcoff.h (struct xcoff_artdata): Replace min_elt with
	ar_hdr_size.
	(xcoff_big_format_p): In the !SMALL_ARCHIVE case return true
	for anything but a small archive.
2023-04-28 15:19:59 +09:30
Alan Modra
4cb2aab8ab Remove deprecated bfd_read
20+ years is long enough to warn.

	* bfd-in.h (bfd_read, bfd_write): Don't define
	(_bfd_warn_deprecated): Don't declare.
	* bfd-in2.h: Regenerate.
	* libbfd.c (_bfd_warn_deprecated): Delete.
2023-04-28 15:19:59 +09:30
Alan Modra
6b25859164 Make bfd_byte an int8_t, flagword a uint32_t
* bfd-in.h (bfd_byte): Typedef as int8_t.
	(flagword): Typedef as uint32_t.
	(bfd_vma, bfd_signed_vma, bfd_size_type, symvalue): Use stdint
	types in !BFD64 case.
	* bfd-in2.h: Regenerate.
2023-04-28 15:19:44 +09:30
GDB Administrator
5a8e7e1332 Automatic date update in version.in 2023-04-28 00:00:28 +00:00
Jose E. Marchesi
2b8c7766ea gas: bpf: fix tests for pseudo-c syntax
This patch fixes the GAS BPF testsuite so the tests for pseudo-c
syntax are actually executed.

2023-04-27  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* testsuite/gas/bpf/mem.dump: New file.
	* testsuite/gas/bpf/mem-pseudoc.d: Likewise.
	* testsuite/gas/bpf/mem.d: #dump mem.dump.
	* testsuite/gas/bpf/lddw.dump: New file.
	* testsuite/gas/bpf/lddw-pseudoc.d: Likewise.
	* testsuite/gas/bpf/lddw.d: #dump lddw.dump.
	* testsuite/gas/bpf/jump.dump: New file.
	* testsuite/gas/bpf/jump-pseudoc.d: Likewise
	* testsuite/gas/bpf/jump.d: #dump jump.dump.
	* testsuite/gas/bpf/jump32.dump: New file.
	* testsuite/gas/bpf/jump32-pseudoc.d: Likewise.
	* testsuite/gas/bpf/jump32.d: #dump jump32.dump.
	* testsuite/gas/bpf/lddw-be.dump: New file.
	* testsuite/gas/bpf/lddw-be-pseudoc.d: Likewise.
	* testsuite/gas/bpf/lddw-be.d: #dump lddw-be.dump.
	* testsuite/gas/bpf/indcall-1.dump: New file.
	* testsuite/gas/bpf/indcall-1-pseudoc.d: Likewise.
	* testsuite/gas/bpf/indcall-1.d: #dump indcall-1.dump.
	* testsuite/gas/bpf/indcall-1-pseudoc.s (main): Fix lddw
	instruction.
	* testsuite/gas/bpf/atomic.dump: New file.
	* testsuite/gas/bpf/atomic-pseudoc.d: Likewise.
	* testsuite/gas/bpf/atomic.d: #dump atomic.dump.
	* testsuite/gas/bpf/alu32.dump: New file.
	* testsuite/gas/bpf/alu32-pseudoc.d: Likewise.
	* testsuite/gas/bpf/alu32.d: #dump alu32.dump.
	* testsuite/gas/bpf/alu.dump: New file.
	* testsuite/gas/bpf/alu-pseudoc.d: Likewise.
	* testsuite/gas/bpf/alu.d: #dump alu.dump.

	* testsuite/gas/bpf/alu-be.dump: New file.
	* testsuite/gas/bpf/alu-be-pseudoc.d: Likewise.
	* testsuite/gas/bpf/alu-be.d: #dump alu-be.dump.
	* testsuite/gas/bpf/alu32-be-pseudoc.d: New file.
	* testsuite/gas/bpf/alu32-be-dump: Likewise.
	* testsuite/gas/bpf/alu32-be.d: #dump alu32-be-dump.
	* testsuite/gas/bpf/bpf.exp: Run *-pseudoc tests.
2023-04-27 20:06:30 +02:00
Tom Tromey
e29ff7211b Avoid some compiler warnings in gdb.ada
Running gdb.ada/verylong.exp shows a warning from the Ada compiler:

prog.adb:16:11: warning: file name does not match unit name, should be "main.adb" [enabled by default]

This patch fixes the problem, and another similar one in
unchecked_union.exp.
2023-04-27 10:31:32 -06:00
Michael Matz
670c91c0c5 Fix PR30358, performance with --sort-section
since af31506c we only use the binary tree when section sorting is
required.  While its unbalanced and hence can degrade to a linear list
it should otherwise have been equivalent to the old code relying on
insertion sort.  Unfortunately it was not.  The old code directly used
lang_add_section to populate the sorted list, the new code first
populates the tree and only then does lang_add_section on the sorted
result.

In the testcase we have very many linkonce section groups, and hence
lang_add_section won't actually insert anything for most of them.  That
limited the to-be-sorted list length previously.  The tree-sorting code
OTOH first created a tree of all candidates sections, including those
that wouldn't be inserted by lang_add_section, hence increasing the size
of the sorting problem.  In the testcase the chain length went from
about 1500 to 106000, and in the degenerated case (as in the testcase)
that goes in quadratically.

This splits out most of the early-out code from lang_add_section to its
own function and uses the latter to avoid inserting into the tree.  This
refactoring slightly changes the order of early-out tests (the ones
based on section flags is now done last, and only in lang_add_section).
The new function is not a pure predicate: it can give warnings and it
might change output_section, like the old early-out code did.  I have
also added a skip-warning case in the first discard case, whose
non-existence seemed to have been an oversight.

	PR 30358
	* ldlang.c (wont_add_section_p): Split out from ...
	(lang_add_section): ... here.
	(output_section_callback_sort): Use wont_add_section_p to not
	always add sections to the sort tree.
2023-04-27 16:15:26 +02:00
Andrew Burgess
0d42948f0c gdb/doc: extend the documentation of the jump command
This commit addresses PR gdb/7946.  While checking for bugs relating
to the jump command I noticed a long standing bug that points out a
deficiency with GDB's documentation of the jump command.

The bug points out that 'jump 0x...' is not always the same as 'set
$pc = 0x...' and then 'continue'.  Writing directly to the $pc
register does not update any auxiliary state, e.g. $npc on SPARC,
while using 'jump' does.

It felt like this would be an easy issue to address by adding a
paragraph to the docs, so I took a stab at writing something suitable.

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

Approved-By: Eli Zaretskii <eliz@gnu.org>
2023-04-27 13:59:30 +01:00
Andrew Burgess
08ec06d644 gdb/testsuite: special case '^' in gdb_test pattern
In this commit I propose that we add special handling for the '^' when
used at the start of a gdb_test pattern.  Consider this usage:

  gdb_test "some_command" "^command output pattern"

I think the intention here is pretty clear - run 'some_command', and
the output from the command should be exactly 'command output
pattern'.

After the previous commit which tightened up how gdb_test matches the
final newline and prompt we know that the only thing after the output
pattern will be a single newline and prompt, and the leading '^'
ensures that there's no output before 'command output pattern', so
this will do what I want, right?

... except it doesn't.  The command itself will also needs to be
matched, so I should really write:

  gdb_test "some_command" "^some_command\r\ncommand output pattern"

which will do what I want, right?  Well, that's fine until I change
the command and include some regexp character, then I have to write:

  gdb_test "some_command" \
    "^[string_to_regexp some_command]\r\ncommand output pattern"

but this all gets a bit verbose, so in most cases I simply don't
bother anchoring the output with a '^', and a quick scan of the
testsuite would indicate that most other folk don't both either.

What I propose is this: the *only* thing that can appear immediately
after the '^' is the command converted into a regexp, so lets do that
automatically, moving the work into gdb_test.  Thus, when I write:

  gdb_test "some_command" "^command output pattern"

Inside gdb_test we will spot the leading '^' in the pattern, and
inject the regexp version of the command after the '^', followed by a
'\r\n'.

My hope is that given this new ability, folk will be more inclined to
anchor their output patterns when this makes sense to do so.  This
should increase our ability to catch any unexpected output from GDB
that appears as a result of running a particular command.

There is one problem case we need to consider, sometime people do
this:

  gdb_test "" "^expected output pattern"

In this case no command is sent to GDB, but we are still expecting
some output from GDB.  This might be a result of some asynchronous
event for example.  As there is no command sent to GDB (from the
gdb_test) there will be no command text to parse.

In this case my proposed new feature injects the command regexp, which
is the empty string (as the command itself is empty), but still
injects the '\r\n' after the command regexp, thus we end up with this
pattern:

  ^\r\nexpected output pattern

This extra '\r\n' is not what we should expected here, and so there is
a special case inside gdb_test -- if the command is empty then don't
add anything after the '^' character.

There are a bunch of tests that do already use '^' followed by the
command, and these can all be simplified in this commit.

I've tried to run all the tests that I can to check this commit, but I
am certain that there will be some tests that I manage to miss.
Apologies for any regressions this commit causes, hopefully fixing the
regressions will not be too hard.

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-04-27 13:56:38 +01:00
Andrew Burgess
e2f620135d gdb/testsuite: change newline patterns used in gdb_test
This commit makes two changes to how we match newline characters in
the gdb_test proc.

First, for the newline pattern between the command output and the
prompt, I propose changing from '[\r\n]+' to an explicit '\r\n'.

The old pattern would spot multiple newlines, and so there are a few
places where, as part of this commit, I've needed to add an extra
trailing '\r\n' to the pattern in the main test file, where GDB's
output actually includes a blank line.

But I think this is a good thing.  If a command produces a blank line
then we should be checking for it, the current gdb_test doesn't do
that.  But also, with the current gdb_test, if a blank line suddenly
appears in the output, this is going to be silently ignored, and I
think this is wrong, the test should fail in that case.

Additionally, the existing pattern will happily match a partial
newline.  There are a strangely large number of tests that end with a
random '.' character.  Not matching a literal period, but matching any
single character, this is then matching half of the trailing newline
sequence, while the \[\r\n\]+ in gdb_test is matching the other half
of the sequence.  I can think of no reason why this would be
intentional, I suspect that the expected output at one time included a
period, which has since been remove, but I haven't bothered to check
on this.  In this commit I've removed all these unneeded trailing '.'
characters.

The basic rule of gdb_test after this is that the expected pattern
needs to match everything up to, but not including the newline
sequence immediately before the GDB prompt.  This is generally how the
proc is used anyway, so in almost all cases, this commit represents no
significant change.

Second, while I was cleaning up newline matching in gdb_test, I've
also removed the '[\r\n]*' that was added to the start of the pattern
passed to gdb_test_multiple.

The addition of this pattern adds no value.  If the user pattern
matches at the start of a line then this would match against the
newline sequence.  But, due to the '*', if the user pattern doesn't
match at the start of a line then this group doesn't care, it'll
happily match nothing.

As such, there's no value to it, it just adds more complexity for no
gain, so I'm removing it.  No tests will need updating as a
consequence of this part of the patch.

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-04-27 13:56:37 +01:00
Andrew Burgess
c5a5f322a4 gdb/testsuite: use 'return' in gdb_test_no_output
A TCL proc will return the return value of the last command executed
within the proc's body if there is no explicit return call, so
gdb_test_no_output is already returning the return value of
gdb_test_multiple.

However, I'm not a fan of (relying on) this implicit return value
behaviour -- I prefer to be explicit about what we are doing.  So in
this commit I have extended the comment on gdb_test_no_output to
document the possible return values (just as gdb_test does), and
explicitly call return.

This should make no different to our testing, but I think it's clearer
now what the gdb_test_no_output proc is expected to do.

The two tests gdb.base/auxv.exp and gdb.base/list.exp both rely on the
return value of gdb_test_no_output, and continue to pass after this
change.

I also spotted that gdb.base/watchpoint.exp could be updated to make
use of gdb_test_no_output, so I did that.

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-04-27 13:56:36 +01:00
Andrew Burgess
131287d950 gdb: remove some trailing newlines from warning messages
While working on a later patch in this series, which tightens up some
of our pattern matching when using gdb_test, I ran into some failures
caused by some warnings having a trailing newline character.

The warning function already adds a trailing newline, and it is my
understanding that we should not be adding a second by including a
newline at the end of any warning message.

The problem cases I found were in language.c and remote.c, in this
patch I fix the cases I hit, but I also checked all the other warning
calls in these two files and removed any additional trailing newlines
I found.

In remote.c the warning actually had a newline character in the middle
of the warning message (in addition to the trailing newline), which
I've removed.  I don't think it's helpful to forcibly split a warning
as was done here -- in the middle of a sentence.  Additionally, the
message isn't even that long (71 characters), so I think removing this
newline is an improvement.

None of the expected test result need updating with this commit,
currently the patterns in gdb_test will match one or more newline
sequences, so the tests are as happy with one newline (after this
commit) as they are with two newlines (before this commit).  A later
commit will change gdb_test so that it is not so forgiving, and these
warnings would have caused some failures.

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-04-27 13:56:35 +01:00
Andrew Burgess
7492eb9f54 gdb/testsuite: fix occasional failure in gdb.base/clear_non_user_bp.exp
I noticed that the gdb.base/clear_non_user_bp.exp test would sometimes
fail when run from a particular directory.

The test tries to find the number of the first internal breakpoint
using this proc:

  proc get_first_maint_bp_num { } {
      gdb_test_multiple "maint info break" "find first internal bp num" {
  	-re -wrap "(-\[0-9\]).*" {
  	    return $expect_out(1,string)
  	}
      }
      return ""
  }

The problem is, at the time we issue 'maint info break' there are both
internal breakpoint and non-internal (user created) breakpoints in
place.  The user created breakpoints include the path to the source
file.

Sometimes, I'll be working from a directory that includes a number,
like '/tmp/blah-1/gdb/etc', in which case the pattern above actually
matches the '-1' from 'blah-1'.  In this case there's no significant
problem as it turns out that -1 is the number of the first internal
breakpoint.

Sometimes my directory name might be '/tmp/blah-4/gdb/etc', in which
case the above pattern patches '-4' from 'blah-4'.  It turns out this
is also not a problem -- the test doesn't actually need the first
internal breakpoint number, it just needs the number of any internal
breakpoint.

But sometimes my directory name might be '/tmp/blah-0/gdb/etc', in
which case the pattern above matches '-0' from 'blah-0', and in this
case the test fails - there is no internal breakpoint '-0'.

Fix this by spotting that the internal breakpoint numbers always
occurs after a '\r\n', and that they never start with a 0.  Our
pattern becomes:

  	-re -wrap "\r\n(-\[1-9\]\[0-9\]*).*" {
  	    return $expect_out(1,string)
  	}

After this I'm no longer seeing any failures.

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-04-27 13:56:34 +01:00
Tankut Baris Aktemur
c6537074be gdb, doc: add index entry for the $_inferior_thread_count convenience var
Add a marker in the documentation for indexing the $_inferior_thread_count
variable.

Approved-By: Eli Zaretskii <eliz@gnu.org>
2023-04-27 14:44:16 +02:00
Nick Clifton
c386bf4df5 Add support for %x and %lx formats to the linker's vinfo() function. 2023-04-27 13:02:00 +01:00
GDB Administrator
0bda45b270 Automatic date update in version.in 2023-04-27 00:00:31 +00:00
Philipp Tomsich
1656d3f8ef RISC-V: Support XVentanaCondOps extension
Ventana Micro has published the specification for their
    XVentanaCondOps ("conditional ops") extension at
      https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf
    which contains two new instructions
      - vt.maskc
      - vt.maskcn
    that can be used in constructing branchless sequences for
    various conditional-arithmetic, conditional-logical, and
    conditional-select operations.

    To support such vendor-defined instructions in the mainline binutils,
    this change also adds a riscv_supported_vendor_x_ext secondary
    dispatch table (but also keeps the behaviour of allowing any unknow
    X-extension to be specified in addition to the known ones from this
    table).

    As discussed, this change already includes the planned/agreed future
    requirements for X-extensions (which are likely to be captured in the
    riscv-toolchain-conventions repository):
      - a public specification document is available (see above) and is
        referenced from the gas-documentation
      - the naming follows chapter 27 of the RISC-V ISA specification
      - instructions are prefixed by a vendor-prefix (vt for Ventana)
        to ensure that they neither conflict with future standard
        extensions nor clash with other vendors

    bfd/ChangeLog:

            * elfxx-riscv.c (riscv_get_default_ext_version): Add riscv_supported_vendor_x_ext.
            (riscv_multi_subset_supports): Recognize INSN_CLASS_XVENTANACONDOPS.

    gas/ChangeLog:

            * doc/c-riscv.texi: Add section to list custom extensions and
              their documentation URLs.
            * testsuite/gas/riscv/x-ventana-condops.d: New test.
            * testsuite/gas/riscv/x-ventana-condops.s: New test.

    include/ChangeLog:

            * opcode/riscv-opc.h Add vt.maskc and vt.maskcn.
            * opcode/riscv.h (enum riscv_insn_class): Add INSN_CLASS_XVENTANACONDOPS.

    opcodes/ChangeLog:

            * riscv-opc.c: Add vt.maskc and vt.maskcn.

    Series-version: 1
    Series-to: binutils@sourceware.org
    Series-cc: Kito Cheng <kito.cheng@sifive.com>
    Series-cc: Nelson Chu <nelson.chu@sifive.com>
    Series-cc: Greg Favor <gfavor@ventanamicro.com>
    Series-cc: Christoph Muellner <cmuellner@gcc.gnu.org>
2023-04-26 14:09:34 -06:00
Jose E. Marchesi
dcdec68b0b gas: documentation for the BPF pseudo-c asm syntax
This patch expands the GAS manual in order to specify the alternate
pseudo-C assembly syntax used in BPF, and now supported by the
assembler.

gas/ChangeLog:

2023-04-19  Jose E. Marchesi  <jose.marchesi@oracle.com>

	PR gas/29757
	* doc/c-bpf.texi (BPF Pseudo-C Syntax): New section.
2023-04-26 19:29:09 +02:00
Guillermo E. Martinez
bba4624d03 gas: BPF pseudo-c syntax tests
This patch expands the GAS BPF testsuite in order to also test the
alternative pseudo-C syntax used in BPF assembly.

This includes three main changes:

- Some general GAS tests involving assignment and equality operands in
  expressions (such as = and ==) are disabled in bpf-* targets,
  because the syntax collides with the pseudo-C BPF assembly syntax.

- New tests are added to the BPF GAS testsuite that test the pseudo-c
syntax.  Tests for all BPF instructions are included.

- New tests are added to the BPF GAS testsuite that test the support
  for both syntaxes in the same source.

gas/ChangeLog:

2023-04-20  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>

	PR gas/29728
	* testsuite/gas/all/assign-bad-recursive.d: Skip test in bpf-*
	targets.
	* testsuite/gas/all/eqv-dot.d: Likewise.
	* testsuite/gas/all/gas.exp: Skip other assignment tests in bpf-*.
	* testsuite/gas/bpf/alu-pseudoc.s: New file.
	* testsuite/gas/bpf/pseudoc-normal.s: Likewise.
	* testsuite/gas/bpf/pseudoc-normal.d: Likewise.
	* testsuite/gas/bpf/pseudoc-normal-be.d: Likewise.
	* testsuite/gas/bpf/mem-pseudoc.s: Likewise.
	* testsuite/gas/bpf/lddw-pseudoc.s: Likewise.
	* testsuite/gas/bpf/jump32-pseudoc.s: Likewise.
	* testsuite/gas/bpf/jump-pseudoc.s: Likewise.
	* testsuite/gas/bpf/indcall-1-pseudoc.s: Likewise.
	* testsuite/gas/bpf/atomic-pseudoc.s: Likewise.
	* testsuite/gas/bpf/alu32-pseudoc.s: Likewise.
	* testsuite/gas/bpf/*.d: Add -pseudoc variants of the tests.
2023-04-26 19:28:06 +02:00
Guillermo E. Martinez
ff5a51b377 gas: support for the BPF pseudo-c assembly syntax
This patch adds support to the GNU assembler for an alternative
assembly syntax used in BPF.  This syntax is C-like and very
unconventional for an assembly language, but it is generated by
clang/llvm and is also used in inline asm templates in kernel code, so
we ought to support it.

After this patch, the assembler is able to parse instructions in both
supported syntax: the normal assembly-like syntax and the pseudo-C
syntax.  Instruction formats can be mixed in the source program: the
assembler recognizes the right syntax to use.

gas/ChangeLog:

2023-04-20  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>

	PR gas/29728
	* config/tc-bpf.h (TC_EQUAL_IN_INSN): Define.
	* config/tc-bpf.c (LEX_IS_SYMBOL_COMPONENT): Define.
	(LEX_IS_WHITESPACE): Likewise.
	(LEX_IS_NEWLINE): Likewise.
	(LEX_IS_ARITHM_OP): Likewise.
	(LEX_IS_STAR): Likewise.
	(LEX_IS_CLSE_BR): Likewise.
	(LEX_IS_OPEN_BR): Likewise.
	(LEX_IS_EQUAL): Likewise.
	(LEX_IS_EXCLA): Likewise.
	(ST_EOI): Likewise.
	(MAX_TOKEN_SZ): Likewise.
	(init_pseudoc_lex): New function.
	(md_begin): Call init_pseudoc_lex.
	(valid_expr): New function.
	(build_bpf_non_generic_load): Likewise.
	(build_bpf_atomic_insn): Likewise.
	(build_bpf_jmp_insn): Likewise.
	(build_bpf_arithm_insn): Likewise.
	(build_bpf_endianness): Likewise.
	(build_bpf_load_store_insn): Likewise.
	(look_for_reserved_word): Likewise.
	(is_register): Likewise.
	(is_cast): Likewise.
	(get_token): Likewise.
	(bpf_pseudoc_to_normal_syntax): Likewise.
	(md_assemble): Try pseudo-C syntax if an instruction cannot be
	parsed.
2023-04-26 19:27:41 +02:00
Jose E. Marchesi
873a1ec405 sim: bpf: update to new BPF relocations
This patch updates the BPF GNU sim testsuite in order to match the new
BPF relocations introduced in binutils in a recent patch [1].

[1] https://sourceware.org/pipermail/binutils/2023-March/126429.html
2023-04-26 19:22:14 +02:00
Tom de Vries
17f091b31e [gdb/tui] Fix length of status line string
In commit 5d10a2041e ("gdb: add string_file::release method") this was added:
...
+  std::string string_val = string.release ();
...
without updating subsequent uses of string.size (), which returns 0 after the
string.release () call.

Fix this by:
- using string_val.size () instead of string.size (), and
- adding an assert that would have caught this regression.

Tested on x86_64-linux.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
PR tui/30389
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30389
2023-04-26 18:15:56 +02:00
Tom Tromey
3ad6c165ca Rewrite gdb_mpz::operator==
Simon pointed out that the recent changes to gdb_mpz caused a build
failure on amd64 macOS.  It turns out to be somewhat difficult to
overload a method in a way that will work "naturally" for all integer
types; especially in a case like gdb_mpz::operator==, where it's
desirable to special case all integer types that are no wider than
'long'.

After a false start, I came up with this patch, which seems to work.
It applies the desirable GMP special cases directly in the body,
rather than via overloads.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-04-26 08:24:15 -06:00
Luis Machado
19e012c813 Updated debug architecture version checks for fbsd
There are two new debug architecture version entries.  I updated the
code for Linux, but fbsd also needs updating.

This patch does this, and should be pretty straightforward.

I can't test this on native fbsd, but I'm fairly confident it should
work.

Signed-off-by: Luis Machado <luis.machado@arm.com>
2023-04-26 07:00:18 +01:00
Luis Machado
dc449cb963 Add new debug architecture version
Teach gdb about a new debug architecture version for AArch64 (0x11).

No user-visible changes.

Regression-tested on aarch64-linux Ubuntu 20.04/22.04.

Signed-off-by: Luis Machado <luis.machado@arm.com>
2023-04-26 07:00:12 +01:00
Alan Modra
b4617f7904 i386-dis.c UB shift and other tidies
1) i386-dis.c:12055:11: runtime error: left shift of negative value -1
Bit twiddling is best done unsigned, due to UB on overflow of signed
expressions.  Fix this by using bfd_vma rather than bfd_signed_vma
everywhere in i386-dis.c except print_displacement.

2) Return get32s and get16 value in a bfd_vma, reducing the need for
temp variables.

3) Introduce get16s and get8s functions to simplify the code.

4) With some optimisation options gcc-13 legitimately complains about
a fall-through in OP_I.  Fix that.  OP_I also doesn't need to use
"mask" which was wrong for w_mode anyway.

5) Masking with & 0xffffffff is better than casting to unsigned.  We
don't know for sure that unsigned int is 32-bit.

6) We also don't know that unsigned char is 8 bits.  Mask codep
accesses everywhere.  I don't expect binutils will work on anything
other than an 8-bit char host, but if we are masking codep accesses in
some places we might as well be consistent.  (Better would be to use
stdint.h types more in binutils.)
2023-04-26 12:06:33 +09:30
Alan Modra
4a8635cbec binutils runtest $CC
I noticed in the binutile Makefile that runtest is being invoked with
CC, CC_FOR_BUILD and other compiler related flags in the environment.
That doesn't work.  Those variables ought to be passed on the runtest
command line.

After fixing that I had some fails due to binutils testprog.c now
being compiled with the default "-g -O2" picked up in
CFLAGS_FOR_TARGET.  Hack around that by passing -O0.

Also, with the binutils testsuite now taking notice of CC_FOR_TARGET,
I found a couple of debuginfod.exp fails with one of my compilers that
happened to be built without --debug-id being enabled by default.

	* Makefile.am (check-DEJAGNU): Pass $CC and other variable on
	the runtest command line rather than futilely in the
	environment.  Add -O0 to CFLAGS_FOR_TARGET.
	* Makefile.in: Regenerate.
	* testsuite/binutils-all/debuginfod.exp: Compile testprog.c
	with -Wl,--build-id.
2023-04-26 10:32:07 +09:30
Alan Modra
5b429b8707 Avoid another -Werror=dangling-pointer
write.c:415:7: error: dangling pointer ‘prev_frag’ to ‘dummy’ may be used

	* write.c (chain_frchains_together_1): Rewrite loop as a do
	while to avoid false positive -Wdangling-pointer.
2023-04-26 10:32:07 +09:30
GDB Administrator
9d4f5cabe2 Automatic date update in version.in 2023-04-26 00:00:45 +00:00
Tom Tromey
b6fc08e89f Use scoped_restore in varobj.c
One spot in varobj.c should use scoped_restore to save and restore
input_radix.  Note that the current code may fail to restore it on
error, so this patch fixes a latent bug.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-04-25 12:01:45 -06:00
Tom Tromey
fc53c8e021 Remove some "goto"s from parse.c
parser_state::push_dollar has some unnecessary "goto"s.  Replacing
them cleans up the code.  Regression tested on x86-64 Fedora 36.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-04-25 11:54:28 -06:00
Michael Matz
8f5cd47bee section-select: Fix performance problem (PR30367)
when using many wild-statements with non-wildcard filenames we
were running into quadraticness via repeatedly using lookup_name
on a long list of loaded files.  I've originally retained using
lookup_name because that preserved existing behaviour most obviously.
In particular in matching wild-statements when using a non-wildcard
filename it matches against local_sym_name, not the filename member.
If the wildspec would have an archive-spec or a wildcard it would use
the filename member, though.  Also it would load the named file
(and ignore it, as being not equal to the currently considered
input-statement).

Rewrite this to not use lookup_name but retain the comparison
against local_sym_name with a comment to that effect.

	PR 30367
	* ldlang.c (walk_wild_section_match): Don't use lookup_name
	but directly compare spec and local_sym_name.
2023-04-25 14:55:22 +02:00
Jan Beulich
7a29ee2903 RISC-V: adjust logic to avoid register name symbols
Special casing GPR names in my_getSmallExpression() leads to a number of
inconsistencies. Generalize this by utilizing the md_parse_name() hook,
limited to when instruction operands are being parsed (really: probed).
Then both the GPR lookup there and the yet more ad hoc workaround for
PR/gas 29940 can be removed (including its extension needed for making
the compressed form JAL work again).
2023-04-25 11:19:18 +02:00
Jan Beulich
42dabba657 RISC-V: test for expected / no unexpected symbols
Both the temporary workaround for PR/gas 29940 and the existing special
casing of GPRs in my_getSmallExpression() aren't really tested anywhere
(i.e. with the workarounds remove testing would still succeed). Nor is
there any test for uses of symbols with names matching GPRs, where such
is permitted. Before altering how this is to be dealt with, install two
testcases covering the expected behavior. (For now this includes only
known affected insns; re-ordering of entries in riscv_opcodes[] could,
however, yield more of them.)
2023-04-25 11:18:49 +02:00