Commit Graph

110419 Commits

Author SHA1 Message Date
Tom Tromey
509e623091 Fix crash with "maint print arc"
Luis noticed that "maint print arc" would crash, because the command
handler did not find "show" in the command name, violating an
invariant.  This patch fixes the bug by changing the registration to
use add_basic_prefix_cmd instead.
2022-05-27 07:52:16 -06:00
Andrew Burgess
202be274a4 opcodes/i386: remove trailing whitespace from insns with zero operands
While working on another patch[1] I had need to touch this code in
i386-dis.c:

  ins->obufp = ins->mnemonicendp;
  for (i = strlen (ins->obuf) + prefix_length; i < 6; i++)
    oappend (ins, " ");
  oappend (ins, " ");
  (*ins->info->fprintf_styled_func)
    (ins->info->stream, dis_style_mnemonic, "%s", ins->obuf);

What this code does is add whitespace after the instruction mnemonic
and before the instruction operands.

The problem I ran into when working on this code can be seen by
assembling this input file:

    .text
    nop
    retq

Now, when I disassemble, here's the output.  I've replaced trailing
whitespace with '_' so that the issue is clearer:

    Disassembly of section .text:

    0000000000000000 <.text>:
       0:	90                   	nop
       1:	c3                   	retq___

Notice that there's no trailing whitespace after 'nop', but there are
three spaces after 'retq'!

What happens is that instruction mnemonics are emitted into a buffer
instr_info::obuf, then instr_info::mnemonicendp is setup to point to
the '\0' character at the end of the mnemonic.

When we emit the whitespace, this is then added starting at the
mnemonicendp position.  Lets consider 'retq', first the buffer is
setup like this:

  'r' 'e' 't' 'q' '\0'

Then we add whitespace characters at the '\0', converting the buffer
to this:

  'r' 'e' 't' 'q' ' ' ' ' ' ' '\0'

However, 'nop' is actually an alias for 'xchg %rax,%rax', so,
initially, the buffer is setup like this:

  'x' 'c' 'h' 'g' '\0'

Then in NOP_Fixup we spot that we have an instruction that is an alias
for 'nop', and adjust the buffer to this:

  'n' 'o' 'p' '\0' '\0'

The second '\0' is left over from the original buffer contents.
However, when we rewrite the buffer, we don't afjust mnemonicendp,
which still points at the second '\0' character.

Now, when we insert whitespace we get:

  'n' 'o' 'p' '\0' ' ' ' ' ' ' ' ' '\0'

Notice the whitespace is inserted after the first '\0', so, when we
print the buffer, the whitespace is not printed.

The fix for this is pretty easy, I can change NOP_Fixup to adjust
mnemonicendp, but now a bunch of tests start failing, we now produce
whitespace after the 'nop', which the tests don't expect.

So, I could update the tests to expect the whitespace....

...except I'm not a fan of trailing whitespace, so I'd really rather
not.

Turns out, I can pretty easily update the whitespace emitting code to
spot instructions that have zero operands and just not emit any
whitespace in this case.  So this is what I've done.

I've left in the fix for NOP_Fixup, I think updating mnemonicendp is
probably a good thing, though this is not really required any more.

I've then updated all the tests that I saw failing to adjust the
expected patterns to account for the change in whitespace.

[1] https://sourceware.org/pipermail/binutils/2022-April/120610.html
2022-05-27 14:12:33 +01:00
Alan Modra
6015985895 Replace bfd_hostptr_t with uintptr_t
bfd_hostptr_t is defined as a type large enough to hold either a long
or a pointer.  It mostly appears in the coff backend code in casts.
include/coff/internal.h struct internal_syment and union
internal_auxent have the only uses in data structures, where
comparison with include/coff/external.h and other code reveals that
the type only needs to be large enough for a 32-bit integer or a
pointer.  That should mean replacing with uintptr_t is OK.
2022-05-27 22:08:59 +09:30
Alan Modra
65d13793d9 Remove much of BFD_HOST configury
This patch removes the definition of bfd_uint64_t and bfd_int64_t as
well as most BFD_HOST_* which are now unused.
2022-05-27 22:08:59 +09:30
Alan Modra
0e3c1eebb2 Remove use of bfd_uint64_t and similar
Requiring C99 means that uses of bfd_uint64_t can be replaced with
uint64_t, and similarly for bfd_int64_t, BFD_HOST_U_64_BIT, and
BFD_HOST_64_BIT.  This patch does that, removes #ifdef BFD_HOST_*
and tidies a few places that print 64-bit values.
2022-05-27 22:08:59 +09:30
Vladimir Mezentsev
aa9b5dbc0f gprofng: fix build with --disable-shared
gprofng/ChangeLog
2022-05-26  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* libcollector/configure.ac: Use AC_MSG_WARN instead of AC_MSG_ERROR
	* libcollector/configure: Rebuild.
2022-05-26 23:51:37 -07:00
Jan Beulich
7063667edb x86/Intel: allow MASM representation of embedded rounding / SAE
MASM doesn't support the separate operand form; the modifier belongs
after the instruction instead. Accept this form alongside the original
(now legacy) one. Short of having access to a MASM version to actually
check in how far "after the instruction" is a precise statement in their
documentation, allow both that and the SDM mandated form where the
modifier is on the last register operand (with a possible immediate
operand following).

Sadly the split out function, at least for the time being, needs to cast
away constness at some point, as the two callers disagree in this
regard.

Adjust some, but not all of the testcases.
2022-05-27 08:48:58 +02:00
Jan Beulich
cf665fee1d x86: re-work AVX512 embedded rounding / SAE
As a preparatory step to allowing proper non-operand forms of specifying
embedded rounding / SAE, convert the internal representation to non-
operand form. While retaining properties (and in a few cases perhaps
providing more meaningful diagnostics), this means doing away with a few
hundred standalone templates, thus - as a nice side effect - reducing
memory consumption / cache occupancy.
2022-05-27 08:48:09 +02:00
Jan Beulich
90a00d6c65 x86/Intel: adjust representation of embedded rounding / SAE
MASM doesn't consider {sae} and alike a separate operand; it is attached
to the last register operand instead, just like spelled out by the SDM.
Make the disassembler follow this first, before also adjusting the
assembler (such that it'll be easy to see that the assembler change
doesn't alter generated code).
2022-05-27 08:47:28 +02:00
Jan Beulich
a5748e0d8c x86/Intel: allow MASM representation of embedded broadcast
MASM doesn't support the {1to<n>} form; DWORD BCST (paralleling
DWORD PTR) and alike are to be used there instead. Accept these forms
alongside the original (now legacy) ones.

Acceptance of the original {1to<n>} operand suffix is retained both for
backwards compatibility and to disambiguate VFPCLASSP{S,D,H} and vector
conversions with shrinking element sizes. I have no insight (yet) into
how MASM expects those to be disambiguated.

Adjust some, but not all of the testcases.
2022-05-27 08:46:29 +02:00
Jan Beulich
811f61d4c4 x86/Intel: adjust representation of embedded broadcast
MASM doesn't support the {1to<n>} form; DWORD BCST (paralleling
DWORD PTR) and alike are to be used there instead. Make the disassembler
follow this first, before also adjusting the assembler (such that it'll
be easy to see that the assembler change doesn't alter generated code).

For VFPCLASSP{S,D,H} and vector conversions with shrinking element sizes
the original {1to<n>} operand suffix is retained, to disambiguate
output. I have no insight (yet) into how MASM expects those to be
disambiguated.
2022-05-27 08:45:56 +02:00
Vladimir Mezentsev
2a2cb7cf2c gprofng: fix build with -mx32
gprofng/ChangeLog
2022-05-26  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	PR gprofng/28983
	* libcollector/libcol_util.h (__collector_getsp, __collector_getfp,
	__collector_getpc): Adapt for build with -mx32
	* libcollector/heaptrace.c: Fix -Wpointer-to-int-cast warnings.
	* libcollector/hwprofile.h: Likewise.
	* libcollector/mmaptrace.c: Likewise.
	* libcollector/synctrace.c: Likewise.
	* libcollector/unwind.c: Likewise.
2022-05-26 23:27:50 -07:00
GDB Administrator
62b5b11b1b Automatic date update in version.in 2022-05-27 00:00:06 +00:00
Hans-Peter Nilsson
5d02a15c69 ld: cris*-elf: Default to --no-warn-rwx-segment
ld:
	configure.tgt (cris-*-*, crisv32-*-* sans *-aout and *-linux): Unless
	specified through the --enable-* -option, default to
	--no-warn-rwx-segment.

Change-Id: I846bcd3e6762da807b17215a9fe337461ea0d710
2022-05-27 01:03:10 +02:00
Hans-Peter Nilsson
81cd0a49c9 cris: bfd: Correct default to no execstack
In the now-historical CRIS glibc port, the default stack permission
was no-exec as in "#define DEFAULT_STACK_PERMS (PF_R|PF_W)", and the
gcc port only emits the executable-stack marker when needed; when
emitting code needing it.  In other words, the binutils setting
mismatches.  It doesn't matter much, except being confusing and
defaulting to "off" is more sane.

ld:

	* testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Switch to 0
	for cris*-*-*.

bfd:
	* elf32-cris.c (elf_backend_default_execstack): Define to 0.

Change-Id: I52f37598f119b19111c7a6546c00a627fca0f396
2022-05-27 01:02:46 +02:00
John Baldwin
b2fdd31b03 aarch64-fbsd-nat: Move definition of debug_regs_probed under HAVE_DBREG.
This fixes the build on older FreeBSD systems without support for
hardware breakpoints/watchpoints.
2022-05-26 14:14:53 -07:00
Lancelot SIX
98aa8321ee gdb: Change psymbol_functions::require_partial_symbols to partial_symbols
The previous patch ensured that partial symbols are read before calling
most of the quick_function's methods.

The psymbol_functions class has the require_partial_symbols method which
serves this exact purpose, and does not need to do it anymore.

This patch renames this method to partial_symbols and makes it an accessor
which asserts that partial symbols have been read at this point.

Regression tested on x86_64-linux.
2022-05-26 19:01:42 +01:00
Lancelot SIX
fcf8e81420 gdb: Require psymtab before calling quick_functions in objfile
The recent DWARF indexer rewrite introduced a regression when debugging
a forking program.

Here is a way to reproduce the issue (there might be other ways, but one
is enough and this one mimics the situation we encountered).  Consider a
program which forks, and the child loads a shared library and calls a
function in this shared library:

    if (fork () == 0)
      {
        void *solib = dlopen (some_solib, RTLD_NOW);
        void (*foo) () = dlsym (some_solib, "foo");
        foo ();
      }

Suppose that this program is compiled without debug info, but the shared
library it loads has debug info enabled.

When debugging such program with the following options:

  - set detach-on-fork off
  - set follow-fork-mode child

we see something like:

    (gdb) b foo
    Function "foo" not defined.
    Make breakpoint pending on future shared library load? (y or [n]) y
    Breakpoint 1 (foo) pending.
    (gdb) run
    Starting program: a.out
    [Attaching after process 19720 fork to child process 19723]
    [New inferior 2 (process 19723)]
    [Switching to process 19723]

    Thread 2.1 "a.out" hit Breakpoint 1, 0x00007ffff7fc3101 in foo () from .../libfoo.so
    (gdb) list

    Fatal signal: Segmentation fault
    ----- Backtrace -----
    0x55a278f77d76 gdb_internal_backtrace_1
            ../../gdb/bt-utils.c:122
    0x55a278f77f83 _Z22gdb_internal_backtracev
            ../../gdb/bt-utils.c:168
    0x55a27940b83b handle_fatal_signal
            ../../gdb/event-top.c:914
    0x55a27940bbb1 handle_sigsegv
            ../../gdb/event-top.c:987
    0x7effec0343bf ???
            /build/glibc-sMfBJT/glibc-2.31/nptl/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
    0x55a27924c9d3 _ZNKSt15__uniq_ptr_implI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterE6_M_ptrEv
            /usr/include/c++/9/bits/unique_ptr.h:154
    0x55a279248bc9 _ZNKSt10unique_ptrI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterE3getEv
            /usr/include/c++/9/bits/unique_ptr.h:361
    0x55a2792ae718 _ZN27dwarf2_base_index_functions23find_last_source_symtabEP7objfile
            ../../gdb/dwarf2/read.c:3164
    0x55a279afb93e _ZN7objfile23find_last_source_symtabEv
            ../../gdb/symfile-debug.c:139
    0x55a279aa3040 _Z20select_source_symtabP6symtab
            ../../gdb/source.c:365
    0x55a279aa22a1 _Z34set_default_source_symtab_and_linev
            ../../gdb/source.c:268
    0x55a27903c44c list_command
            ../../gdb/cli/cli-cmds.c:1185
    0x55a279051233 do_simple_func
            ../../gdb/cli/cli-decode.c:95
    0x55a27905f221 _Z8cmd_funcP16cmd_list_elementPKci
            ../../gdb/cli/cli-decode.c:2514
    0x55a279c3b0ba _Z15execute_commandPKci
            ../../gdb/top.c:660
    0x55a27940a6c3 _Z15command_handlerPKc
            ../../gdb/event-top.c:598
    0x55a27940b032 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
            ../../gdb/event-top.c:797
    0x55a279caf401 tui_command_line_handler
            ../../gdb/tui/tui-interp.c:278
    0x55a279409098 gdb_rl_callback_handler
            ../../gdb/event-top.c:230
    0x55a279ed5df2 rl_callback_read_char
            ../../../readline/readline/callback.c:281
    0x55a279408bd8 gdb_rl_callback_read_char_wrapper_noexcept
            ../../gdb/event-top.c:188
    0x55a279408de7 gdb_rl_callback_read_char_wrapper
            ../../gdb/event-top.c:205
    0x55a27940a061 _Z19stdin_event_handleriPv
            ../../gdb/event-top.c:525
    0x55a27a23771e handle_file_event
            ../../gdbsupport/event-loop.cc:574
    0x55a27a237f5f gdb_wait_for_event
            ../../gdbsupport/event-loop.cc:700
    0x55a27a235d81 _Z16gdb_do_one_eventv
            ../../gdbsupport/event-loop.cc:237
    0x55a2796c2ef0 start_event_loop
            ../../gdb/main.c:418
    0x55a2796c3217 captured_command_loop
            ../../gdb/main.c:478
    0x55a2796c717b captured_main
            ../../gdb/main.c:1340
    0x55a2796c7217 _Z8gdb_mainP18captured_main_args
            ../../gdb/main.c:1355
    0x55a278d0b381 main
            ../../gdb/gdb.c:32
    ---------------------
    A fatal error internal to GDB has been detected, further
    debugging is not possible.  GDB will now terminate.

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

The first issue observed is in the message printed when hitting the
breakpoint.  It says that there was a break in the .so file as if there
was no debug info associated with it, but there is.  Later, if we try to
display the source where the execution stopped, we have a segfault.

Note that not having the debug info on the main binary is not strictly
required to encounter some issues, it only is to encounter the segfault.
If the main binary has debug information, GDB shows some source form the
main binary, unrelated to where we stopped.

The core of the issue is that GDB never loads the psymtab for the
library.  It is not loaded when we first see the .so because in case of
detach-on-fork off, follow-fork-mode child, infrun.c sets
child_inf->symfile_flags = SYMFILE_NO_READ to delay the psymtab loading
as much as possible.  If we compare to what was done to handle this
before the new indexer was activated, the psymatb construction for the
shared library was done under
psymbol_functions::expand_symtabs_matching:

    bool
    psymbol_functions::expand_symtabs_matching (...)
    {
        for (partial_symtab *ps : require_partial_symbols (objfile))
        ...
    }

The new indexer's expand_symtabs_matching callback does not have a call
to the objfile's require_partial_symbols, so if the partial symbol table
is not loaded at this point, there is no mechanism to fix this.

Instead of requiring each implementation of the quick_functions to check
that partial symbols have been read, I think it is safer to enforce this
when calling the quick functions.  The general pattern for calling the
quick functions is:

    for (auto *iter : qf)
      iter->the_actual_method_call (...)

This patch proposes to wrap the access of the `qf` field with an accessor
which ensures that partial symbols have been read before iterating:
qf_require_partial_symbols.  All calls to quick functions are updated
except:

- quick_functions::dump
- quick_functions::read_partial_symbols (from
  objfile::require_partial_symbols)
- quick_functions::can_lazily_read_symbols and quick_functions::has_symbols
  (from objfile::has_partial_symbols)

Regression tested on x86_64-gnu-linux.

Change-Id: I39a13a937fdbaae613a5cf68864b021000554546
2022-05-26 19:01:42 +01:00
Tom Tromey
834eaf9201 Fix crash in new DWARF indexer
PR gdb/29128 points out a crash in the new DWARF index code.  This
happens if the aranges for a CU claims a PC, but the symtab that is
created during CU expansion does not actually contain the PC.  This
can only occur due to bad debuginfo, but at the same time, gdb should
not crash.

This patch fixes the bug and further merges some code into
dwarf2_base_index_functions.  This merger helps prevent the same issue
from arising from the other index implementations.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29128
2022-05-26 11:37:06 -06:00
Tom Tromey
20a26f4e01 Finalize each cooked index separately
After DWARF has been scanned, the cooked index code does a
"finalization" step in a worker thread.  This step combines all the
index entries into a single master list, canonicalizes C++ names, and
splits Ada names to synthesize package names.

While this step is run in the background, gdb will wait for the
results in some situations, and it turns out that this step can be
slow.  This is PR symtab/29105.

This can be sped up by parallelizing, at a small memory cost.  Now
each index is finalized on its own, in a worker thread.  The cost
comes from name canonicalization: if a given non-canonical name is
referred to by multiple indices, there will be N canonical copies (one
per index) rather than just one.

This requires changing the users of the index to iterate over multiple
results.  However, this is easily done by introducing a new "chained
range" class.

When run on gdb itself, the memory cost seems rather low -- on my
current machine, "maint space 1" reports no change due to the patch.

For performance testing, using "maint time 1" and "file" will not show
correct results.  That approach measures "time to next prompt", but
because the patch only affects background work, this shouldn't (and
doesn't) change.  Instead, a simple way to make gdb wait for the
results is to set a breakpoint.

Before:

    $ /bin/time -f%e ~/gdb/install/bin/gdb -nx -q -batch \
        -ex 'break main' /tmp/gdb
    Breakpoint 1 at 0x43ec30: file ../../binutils-gdb/gdb/gdb.c, line 28.
    2.00

After:

    $ /bin/time -f%e ./gdb/gdb -nx -q -batch \
        -ex 'break main' /tmp/gdb
    Breakpoint 1 at 0x43ec30: file ../../binutils-gdb/gdb/gdb.c, line 28.
    0.65

Regression tested on x86-64 Fedora 34.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29105
2022-05-26 07:35:30 -06:00
Alan Modra
f420c9c84e bit-rot in target before_parse function
Copy initialisation over from the elf.em before_parse.  Commit
ba951afb99 2022-05-03 changed behaviour on arm and score regarding
exec stack.  This patch restores the previous behaviour.

	* emultempl/aarch64elf.em (before_parse): Init separate_code,
	warn_execstack, no_warn_rwx_segments and default_execstack.
	* emultempl/armelf.em (before_parse): Likewise.
	* emultempl/scoreelf.em (before_parse): Likewise.
	* testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Return
	true for arm and nacl.
2022-05-26 20:34:32 +09:30
Richard Earnshaw
20d814202a arm: avoid use of GNU builtin function in s_arm_unwind_save_mixed
Whilst reviewing Luis' proposed change to s_arm_unwind_save_mixed
yesterday I noticed that we were making use of __builting_clzl
directly within the main function, which is not guaranteed to be
portable.  Whilst studying the code further, I also realized that it
could be rewritten without using it and also reworked to remove a lot
of unnecessary iterations steps.  So this patch does that (and also
removes the source of the warning that Luis was trying to fix).
Finally, with the rewrite we can also simplify the caller of this
routine as the new version can handle all the cases directly.

	* config/tc-arm.c (s_arm_unwind_save_mixed): Rewrite without
	using __builtin_clzl.
	(s_arm_unwind_save): Simplify logic for simple/mixed register saves.
2022-05-26 11:05:59 +01:00
Lancelot SIX
284b6bb5c6 gdb/linux-nat: xfer_memory_partial return E_IO on error
When accessing /proc/PID/mem, if pread64/pwrite64/read/write encounters
an error and return -1, linux_proc_xfer_memory_partial return
TARGET_XFER_EOF.

I think it should return TARGET_XFER_E_IO in this case.  TARGET_XFER_EOF
is returned when pread64/pwrite64/read/frite returns 0, which indicates
that the address space is gone and the whole process has exited or
execed.

This patch makes this change.

Regression tested on x86_64-linux-gnu.

Change-Id: I6030412459663b8d7933483fdda22a6c2c5d7221
2022-05-26 09:42:47 +01:00
Lancelot SIX
bfcd7c2160 gdb/testsuite: prefer gdb_test in gdb.dwarf2/calling-convention
Since ed01945057 "Make gdb_test's question non-optional if specified",
if the question and response parameters are given to gdb_test, the
framework enforces that GDB asks the question.  Before this patch, tests
needed to use gdb_test_multiple to enforce this.

This patch updates the gdb.dwarf2/calling-convention.exp testcase to use
gdb_test to check that GDB asks a question.  This replaces the more
complicated gdb_test_multiple based implementation.

Tested on x86_64-gnu-linux.

Change-Id: I7216e822ca68f2727e0450970097d74c27c432fe
2022-05-26 09:37:11 +01:00
Potharla, Rupesh
f67741e172 bfd: Add Support for DW_FORM_strx* and DW_FORM_addrx* 2022-05-26 16:39:52 +09:30
Luca Boccassi
9e2bb0cb5e ld: add --package-metadata
Generate a .note.package FDO package metadata ELF note, following
the spec: https://systemd.io/ELF_PACKAGE_METADATA/

If the jansson library is available at build time (and it is explicitly
enabled), link ld to it, and use it to validate that the input is
correct JSON, to avoid writing garbage to the file. The
configure option --enable-jansson has to be used to explicitly enable
it (error out when not found). This allows bootstrappers (or others who
are not interested) to seamlessly skip it without issues.
2022-05-26 12:56:12 +09:30
GDB Administrator
d1a24139ad Automatic date update in version.in 2022-05-26 00:00:10 +00:00
Natarajan, Kavitha
f85c0e1e20 Re: Add bionutils support for DWARF v5's DW_OP_addrx
Testsuite files belonging to commit 3ac9da4937.
2022-05-26 09:12:09 +09:30
Pedro Alves
fbcda57701 Show enabled locations with disabled breakpoint parent as "y-"
Currently, breakpoint locations that are enabled while their parent
breakpoint is disabled are displayed with "y" in the Enb colum of
"info breakpoints":

 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 1       breakpoint     keep n   <MULTIPLE>
 1.1                         y   0x00000000000011b6 in ...
 1.2                         y   0x00000000000011c2 in ...
 1.3                         n   0x00000000000011ce in ...

Such locations won't trigger a break, so to avoid confusion, show "y-"
instead.  For example:

 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 1       breakpoint     keep n   <MULTIPLE>
 1.1                         y-  0x00000000000011b6 in ...
 1.2                         y-  0x00000000000011c2 in ...
 1.3                         n   0x00000000000011ce in ...

The "-" sign is inspired on how the TUI represents breakpoints on the
left side of the source window, with "b-" for a disabled breakpoint.

Change-Id: I9952313743c51bf21b4b380c72360ef7d4396a09
2022-05-25 19:51:46 +01:00
Natarajan, Kavitha
3ac9da4937 Add bionutils support for DWARF v5's DW_OP_addrx. 2022-05-25 16:10:38 +01:00
Pedro Alves
cce0ae568c gdb: Fix DUPLICATE and PATH regressions throughout
The previous patch to add -prompt/-lbl to gdb_test introduced a
regression: Before, you could specify an explicit empty message to
indicate you didn't want to PASS, like so:

  gdb_test COMMAND PATTERN ""

After said patch, gdb_test no longer distinguishes
no-message-specified vs empty-message, so tests that previously would
be silent on PASS, now started emitting PASS messages based on
COMMAND.  This in turn introduced a number of PATH/DUPLICATE
violations in the testsuite.

This commit fixes all the regressions I could see.

This patch uses the new -nopass feature introduced in the previous
commit, but tries to avoid it if possible.  Most of the patch fixes
DUPLICATE issues the usual way, of using with_test_prefix or explicit
unique messages.

See previous commit's log for more info.

In addition to looking for DUPLICATEs, I also looked for cases where
we would now end up with an empty message in gdb.sum, due to a
gdb_test being passed both no message and empty command.  E.g., this
in gdb.ada/bp_reset.exp:

 gdb_run_cmd
 gdb_test "" "Breakpoint $decimal, foo\\.nested_sub \\(\\).*"

was resulting in this in gdb.sum:

 PASS: gdb.ada/bp_reset.exp:

I fixed such cases by passing an explicit message.  We may want to
make such cases error out.

Tested on x86_64 GNU/Linux, native and native-extended-gdbserver.  I
see zero PATH cases now.  I get zero DUPLICATEs with native testing
now.  I still see some DUPLICATEs with native-extended-gdbserver, but
those were preexisting, unrelated to the gdb_test change.

Change-Id: I5375f23f073493e0672190a0ec2e847938a580b2
2022-05-25 13:44:12 +01:00
Pedro Alves
aee9dcf8a8 Add -nopass option to gdb_test/gdb_test_multiple
The previous patch to add -prompt/-lbl to gdb_test introduced a
regression: Before, you could specify an explicit empty message to
indicate you didn't want to PASS, like so:

  gdb_test COMMAND PATTERN ""

After said patch, gdb_test no longer distinguishes
no-message-specified vs empty-message, so tests that previously would
be silent on PASS, now started emitting PASS messages based on
COMMAND.  This in turn introduced a number of PATH/DUPLICATE
violations in the testsuite.

I think that not issuing a PASS should be restricted to only a few
cases -- namely in shared routines exported by gdb.exp, which happen
to use gdb_test internally.  In tests that iterate an unknown number
of tests exercising some racy scenario.  In the latter case, if we
emit PASSes for each iteration, we run into the situation where
different testsuite runs emit a different number of PASSes.

Thus, this patch preserves the current behavior, and, instead, adds a
new "-nopass" option to gdb_test and gdb_test_no_output.  Compared to
the old way of supressing PASS with an empty message, this has the
advantage that you can specify a FAIL message that is distinct from
the command string, and, it's also more explicit.

Change-Id: I5375f23f073493e0672190a0ec2e847938a580b2
2022-05-25 13:44:11 +01:00
Tsukasa OI
51498ab9ab RISC-V: Fix RV32Q conflict
This commit makes RV32 + 'Q' extension (version 2.2 or later) not
conflicting since this combination is no longer prohibited by the
specification.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_parse_check_conflicts): Remove conflict
	detection that prohibits RV32Q on 'Q' version 2.2 or later.

gas/ChangeLog:

	* testsuite/gas/riscv/march-fail-rv32iq.d: Removed.
	* testsuite/gas/riscv/march-fail-rv32iq.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iq2p0.d: New test
	showing RV32IQ fails on 'Q' extension version 2.0.
	* testsuite/gas/riscv/march-fail-rv32iq2p0.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iq2.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iq-isa-2p2.d: New test
	showing RV32IQ fails on ISA specification version 2.2.
	* testsuite/gas/riscv/march-ok-rv32iq2p2.d: New test
	showing RV32IQ succesds on 'Q' extension version 2.2.
	* testsuite/gas/riscv/march-ok-rv32iq-isa-20190608.d: New test
	showing RV32IQ succesds on ISA specification 20190608.
2022-05-25 11:19:59 +08:00
Dmitry Selyutin
dd4832bf3e opcodes: introduce BC field; fix isel
Per Power ISA Version 3.1B 3.3.12, isel uses BC field rather than CRB
field present in binutils sources. Also, per 1.6.2, BC has the same
semantics as BA and BB fields, so this should keep the same flags and
mask, only with the different offset.

opcodes/
        * ppc-opc.c
        (BC): Define new field, with the same definition as CRB field,
        but with the PPC_OPERAND_CR_BIT flag present.
gas/
        * testsuite/gas/ppc/476.d: Update.
        * testsuite/gas/ppc/a2.d: Update.
        * testsuite/gas/ppc/e500.d: Update.
        * testsuite/gas/ppc/power7.d: Update.
2022-05-25 12:13:44 +09:30
Dmitry Selyutin
8e5eb8e1b0 ppc: extend opindex to 16 bits
With the upcoming SVP64 extension[0] to PowerPC architecture, it became
evident that PowerPC operand indices no longer fit 8 bits. This patch
switches the underlying type to uint16_t, also introducing a special
typedef so that any future extension goes even smoother.

[0] https://libre-soc.org

include/
	* opcode/ppc.h (ppc_opindex_t): New typedef.
	(struct powerpc_opcode): Use it.
	(PPC_OPINDEX_MAX): Define.
gas/
	* write.h (struct fix): Increase size of fx_pcrel_adjust.
	Reorganise.
	* config/tc-ppc.c (insn_validate): Use ppc_opindex_t for operands.
	(md_assemble): Likewise.
	(md_apply_fix): Likewise.  Mask fx_pcrel_adjust with PPC_OPINDEX_MAX.
	(ppc_setup_opcodes): Adjust opcode index assertion.
opcodes/
	* ppc-dis.c (skip_optional_operands): Use ppc_opindex_t for
	operand pointer.
	(lookup_powerpc, lookup_prefix, lookup_vle, lookup_spe2): Likewise.
	(print_insn_powerpc): Likewise.
2022-05-25 12:13:44 +09:30
GDB Administrator
f59e7b1289 Automatic date update in version.in 2022-05-25 00:00:06 +00:00
Tom de Vries
9e9f0d02b4 [gdb/testsuite] Fix gdb.opt/clobbered-registers-O2.exp with clang
When running test-case gdb.opt/clobbered-registers-O2.exp with clang 12.0.1, I
get:
...
(gdb) run ^M
Starting program: clobbered-registers-O2 ^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
gen_movsd (operand0=<optimized out>, operand1=<optimized out>) at \
  clobbered-registers-O2.c:31^M
31              return *start_sequence(operand0, operand1);^M
(gdb) FAIL: gdb.opt/clobbered-registers-O2.exp: runto: run to start_sequence
...

The problem is that the breakpoint in start_sequence doesn't trigger, because:
- the call to start_sequence in gen_movsd is optimized away, despite the
  __attribute__((noinline)), so the actual function start_sequence doesn't get
  called, and
- the debug info doesn't contain inlined function info, so there's only one
  breakpoint location.

Adding noclone and noipa alongside the noinline attribute doesn't fix this.

Adding the clang-specific attribute optnone in start_sequence does, but since
it inhibits all optimization, that's not a preferred solution in a gdb.opt
test-case, and it would work only for clang and not other compilers that
possibly have the same issue.

Fix this by moving functions start_sequence and gen_movsd into their own
files, as a way of trying harder to enforce noinline/noipa/noclone.

Tested on x86_64-linux.
2022-05-24 22:41:45 +02:00
Tom de Vries
a0ae328a26 [gdb/testsuite] Fix gdb.opt/clobbered-registers-O2.exp with gcc-12
When running test-case gdb.opt/clobbered-registers-O2.exp with gcc-12, I run
into:
...
(gdb) PASS: gdb.opt/clobbered-registers-O2.exp: backtracing
print operand0^M
$1 = (unsigned int *) 0x7fffffffd070^M
(gdb) print *operand0^M
$2 = 4195541^M
(gdb) FAIL: gdb.opt/clobbered-registers-O2.exp: print operand0
...

The problem is that starting gcc-12, the assignments to x and y in main are
optimized away:
...
int main(void)
{
  unsigned x, y;

  x = 13;
  y = 14;
  return (int)gen_movsd (&x, &y);
...

Fix this by making x and y volatile.

Note that the test-case intends to check the handling of debug info for
optimized code in function gen_movsd, so inhibiting optimization in main
doesn't interfere with that.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29161
2022-05-24 22:41:45 +02:00
Tiezhu Yang
387e00f3b3 gdb: LoongArch: Define LOONGARCH_LINUX_NUM_GREGSET as 45
LOONGARCH_LINUX_NUM_GREGSET should be defined as 45 (32 + 1 + 1 + 11)
due to reserved 11 for extension in glibc, otherwise when execute:

  make check-gdb TESTS="gdb.base/corefile.exp"

there exists the following failed testcase:

  (gdb) core-file /home/loongson/build.git/gdb/testsuite/outputs/gdb.base/corefile/corefile.core
  [New LWP 7742]
  warning: Unexpected size of section `.reg/7742' in core file.
  Core was generated by `/home/loongson/build.git/gdb/testsuite/outputs/gdb.base/corefile/corefile'.
  Program terminated with signal SIGABRT, Aborted.
  warning: Unexpected size of section `.reg/7742' in core file.
  #0  0x000000fff76f4e24 in raise () from /lib/loongarch64-linux-gnu/libc.so.6
  (gdb) FAIL: gdb.base/corefile.exp: core-file warning-free

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-05-24 22:05:03 +08:00
Christophe Lyon
81657e5800 AArch64: add support for DFP (Decimal Floating point)
This small patch adds support for TYPE_CODE_DECFLOAT in
aapcs_is_vfp_call_or_return_candidate_1 and pass_in_v_vfp_candidate,
so that GDB for AArch64 knows how to pass DFP parameters and how to
read DFP results when calling a function.

Tested on aarch64-linux-gnu, with a GCC with DFP support in the PATH,
all of GDB's DFP tests pass.
2022-05-24 10:47:29 +01:00
Christophe Lyon
a55dfbb9ab Merge config/ changes from GCC, to enable DFP on AArch64
2022-04-28  Christophe Lyon  <christophe.lyon@arm.com>

	config/
	* dfp.m4 (enable_decimal_float): Enable BID for AArch64.

	libdecnumber/
	* configure: Regenerate.
2022-05-24 10:47:29 +01:00
Alan Modra
be38442dda PR29171, invalid read causing SIGSEGV
The fix here is to pass "section" down to read_and_display_attr_value.
The test in read_and_display_attr_value is a little bit of hardening.

	PR 29171
	* dwarf.c (display_debug_macro, display_debug_names): Pass section
	to read_and_display_attr_value2.
	(read_and_display_attr_value): Don't attempt to check for .dwo
	section name when section is NULL.
2022-05-24 12:05:39 +09:30
Alan Modra
5fbb38fcc5 PR29170, divide by zero displaying fuzzed .debug_names
PR 29170
	* dwarf.c (display_debug_names): Don't attempt to display bucket
	clashes when bucket count is zero.
2022-05-24 10:52:05 +09:30
Alan Modra
244e19c791 PR29169, invalid read displaying fuzzed .gdb_index
PR 29169
	* dwarf.c (display_gdb_index): Combine sanity checks.  Calculate
	element counts, not word counts.
2022-05-24 09:50:17 +09:30
GDB Administrator
9e0f632935 Automatic date update in version.in 2022-05-24 00:00:08 +00:00
John Baldwin
e8123c847f Tweak the std::hash<> specialization for aarch64_features.
Move the specialization into an explicit std namespace to workaround a
bug in older compilers.  GCC 6.4.1 at least fails to compile the previous
version with the following error:

gdb/arch/aarch64.h:48:13: error: specialization of 'template<class _Tp> struct std::hash' in different namespace [-fpermissive]

  struct std::hash<aarch64_features>
2022-05-23 11:02:55 -07:00
John Baldwin
d9b6e047f6 Fix loongarch_iterate_over_regset_sections for non-native targets.
Define a constant for the number of registers stored in a register set
and use this with register_size to compute the size of the
general-purpose register set in core dumps.

This also fixes the build on hosts such as FreeBSD that do not define
an elf_gregset_t type.
2022-05-23 10:59:13 -07:00
Tiezhu Yang
a6b446b222 gdb: LoongArch: Implement the iterate_over_regset_sections gdbarch method
When execute the following command on LoongArch:

  make check-gdb TESTS="gdb.base/auxv.exp"

there exist the following unsupported and failed testcases:

  UNSUPPORTED: gdb.base/auxv.exp: gcore
  FAIL: gdb.base/auxv.exp: load core file for info auxv on native core dump
  FAIL: gdb.base/auxv.exp: info auxv on native core dump
  FAIL: gdb.base/auxv.exp: matching auxv data from live and core
  UNSUPPORTED: gdb.base/auxv.exp: info auxv on gcore-created dump
  UNSUPPORTED: gdb.base/auxv.exp: matching auxv data from live and gcore

we can see the following messages in gdb/testsuite/gdb.log:

  gcore /home/loongson/build.git/gdb/testsuite/outputs/gdb.base/auxv/auxv.gcore
  Target does not support core file generation.
  (gdb) UNSUPPORTED: gdb.base/auxv.exp: gcore

In order to fix the above issues, implement the iterate_over_regset_sections
gdbarch method to iterate over core file register note sections on LoongArch.

By the way, with this patch, the failed testcases in gdb.base/corefile.exp
and gdb.base/gcore.exp can also be fixed.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-05-23 22:31:24 +08:00
Tom de Vries
01a62a6d5f [gdb/testsuite] Fix -prompt handling in gdb_test
With check-read1 I run into:
...
   [infrun] maybe_set_commit_resumed_all_targets: not requesting
commit-resumed for target native, no resumed threads^M
(gdb) FAIL: gdb.base/ui-redirect.exp: debugging: continue
[infrun] fetch_inferior_event: exit^M
...

The problem is that proc gdb_test doesn't pass down the -prompt option to proc
gdb_test_multiple, due to a typo making this lappend without effect:
...
    set opts {}
    lappend "-prompt $prompt"
...

Fix this by actually appending to opts.

Tested on x86_64-linux.
2022-05-23 14:50:02 +02:00
Tom de Vries
735dfe028c [gdbsupport] Fix UB in print-utils.cc:int_string
When building gdb with -fsanitize=undefined, I run into:
...
(gdb) PASS: gdb.ada/access_to_packed_array.exp: set logging enabled on
maint print symbols^M
print-utils.cc:281:29:runtime error: negation of -9223372036854775808 cannot \
  be represented in type 'long int'; cast to an unsigned type to negate this \
  value to itself
(gdb) FAIL: gdb.ada/access_to_packed_array.exp: maint print symbols
...

By running in a debug session, we find that this happens during printing of:
...
   typedef system.storage_elements.storage_offset: \
     range -9223372036854775808 .. 9223372036854775807;
...
Possibly, an ada test-case could be created that exercises this in isolation.

The problem is here in int_string, where we negate a val with type LONGEST:
...
         return decimal2str ("-", -val, width);
...

Fix this by, as recommend, using "-(ULONGEST)val" instead.

Tested on x86_64-linux.
2022-05-23 14:50:02 +02:00