binutils-gdb.git
20 months agogdb, cp: update add_symbol_overload_list_qualified
Markus Metzger [Tue, 26 Apr 2022 13:11:09 +0000 (15:11 +0200)]
gdb, cp: update add_symbol_overload_list_qualified

Iterate over objfiles in search order using the objfile of the selected
block as current_objfile so the iteration can stay inside the block's
linker namespace.

20 months agofixup! gdb, ada: update ada_lookup_simple_minsym
Markus Metzger [Tue, 19 Jul 2022 06:05:25 +0000 (08:05 +0200)]
fixup! gdb, ada: update ada_lookup_simple_minsym

remove get_selected_block()

20 months agogdb, ada: update ada_lookup_simple_minsym
Markus Metzger [Tue, 12 Apr 2022 14:05:26 +0000 (16:05 +0200)]
gdb, ada: update ada_lookup_simple_minsym

Iterate over objfile in search order using the objfile of the context
block as current_objfile so the iteration can stay inside the block's
linker namespace.

20 months agogdb, ada: collect standard exceptions in all objfiles
Markus Metzger [Mon, 11 Apr 2022 15:58:23 +0000 (17:58 +0200)]
gdb, ada: collect standard exceptions in all objfiles

When searching for standard exceptions for Ada, we lookup the minimal
symbol of each exception.  With linker namespaces there can be multiple
instances in different namespaces.  Collect them all.

20 months agogdb, python: use gdbarch_iterate_over_objfiles_in_search_order
Markus Metzger [Mon, 11 Apr 2022 14:44:36 +0000 (16:44 +0200)]
gdb, python: use gdbarch_iterate_over_objfiles_in_search_order

The implementation of gdb.lookup_objfile() iterates over all objfiles and
compares their name or build id to the user-provided search string.

This will cause problems when supporting linker namespaces as the first
objfile in any namespace will be found.  Instead, use
gdbarch_iterate_over_objfiles_in_search_order to only consider the
namespace of gdb.current_objfile() for the search, which defaults to the
initial namespace when gdb.current_objfile() is None.

20 months agogdb, compile: unlink objfile stored in module
Markus Metzger [Mon, 11 Apr 2022 13:12:33 +0000 (15:12 +0200)]
gdb, compile: unlink objfile stored in module

When cleaning up after a compile command, we iterate over all objfiles and
unlink the first objfile with the same name as the one we compiled.

Since we already store a pointer to that objfile in the module and use it
to get the name we're comparing against, there's no reason to iterate, at
all.  We can simply use that objfile.

This further avoids potential issues when an objfile with the same name is
loaded into a different linker namespace.

20 months agogdb, gdbserver: extend RSP to support namespaces
Markus Metzger [Tue, 15 Mar 2022 17:08:06 +0000 (18:08 +0100)]
gdb, gdbserver: extend RSP to support namespaces

Introduce a new qXfer:libraries-svr4:read annex key/value pair

    lmid=<namespace identifier>

to be used together with start and prev to provide the namespace of start
and prev to gdbserver.

Unknown key/value pairs are ignored by gdbserver so no new supports check
is needed.

Introduce a new library-list-svr4 library attribute

    lmid

to provide the namespace of a library entry to GDB.

This implementation uses the address of a namespace's r_debug object as
namespace identifier.

This should have incremented the minor version but since unknown XML
attributes are ignored, anyway, and since changing the version results in
a warning from GDB, the version is left at 1.0.

20 months agogdbserver: move main_lm handling into caller
Markus Metzger [Tue, 15 Mar 2022 16:41:13 +0000 (17:41 +0100)]
gdbserver: move main_lm handling into caller

When listing SVR4 shared libraries, special care has to be taken about the
first library in the default namespace as that refers to the main
executable.  The load map address of this main executable is provided in
an attribute of the library-list-svr4 element.

Move that code from where we enumerate libraries inside a single namespace
to where we generate the rest of the library-list-svr4 element.  This
allows us to complete the library-list-svr4 element inside one function.

There should be no functional change.

20 months agogdb, gdbserver: support dlmopen()
Markus Metzger [Mon, 4 Oct 2021 08:24:35 +0000 (10:24 +0200)]
gdb, gdbserver: support dlmopen()

In glibc, the r_debug structure contains (amongst others) the following
fields:

  int r_version:
    Version number for this protocol.  It should be greater than 0.

If r_version is 2, struct r_debug is extended to struct r_debug_extended
with one additional field:

  struct r_debug_extended *r_next;
    Link to the next r_debug_extended structure.  Each r_debug_extended
    structure represents a different namespace.  The first r_debug_extended
    structure is for the default namespace.

1. Change solib_svr4_r_map argument to take the debug base.
2. Add solib_svr4_r_next to find the link map in the next namespace from
the r_next field.
3. Update svr4_current_sos_direct to get the link map in the next namespace
from the r_next field.
4. Don't check shared libraries in other namespaces when updating shared
libraries in a new namespace.
5. Update svr4_same to check the load offset in addition to the name
6. Update svr4_default_sos to also set l_addr_inferior
7. Change the flat solib_list into a per-namespace list using the
namespace's r_debug address to identify the namespace.

Add gdb.base/dlmopen.exp to test this.

To remain backwards compatible with older gdbserver, we reserve the
namespace zero for a flat list of solibs from all namespaces.  Subsequent
patches will extend RSP to allow listing libraries grouped by namespace.

This fixes PR 11839.

Co-authored-by: Lu, Hongjiu <hongjiu.lu@intel.com>
20 months agogdb, solib-svr4: remove locate_base()
Markus Metzger [Fri, 11 Mar 2022 05:46:15 +0000 (06:46 +0100)]
gdb, solib-svr4: remove locate_base()

Whenever we call locate_base(), we clear info->debug_base directly before
the call.  Thus, we never cache the base location as locate_base() had
intended.

Move the svr4_have_link_map_offsets() check into elf_locate_base(), inline
locate_base() at all call sites, and remove it.

20 months agogdb, testsuite: extend gdb_test_multiple checks
Markus Metzger [Fri, 18 Feb 2022 11:16:33 +0000 (12:16 +0100)]
gdb, testsuite: extend gdb_test_multiple checks

Check for

    warning: Corrupted shared library list

and for

    Invalid cast.
    warning: Probes-based dynamic linker interface failed.
    Reverting to original interface.

in gdb_test_multiple.

20 months agox86: generalize gas documentation for disabling of ISA extensions
Jan Beulich [Tue, 18 Oct 2022 06:27:42 +0000 (08:27 +0200)]
x86: generalize gas documentation for disabling of ISA extensions

As of commit ae89daecb132 ("x86: generalize disabling of sub-
architectures") there's no arbitrary subset of ISAs which can also be
disabled. This should have been reflected in documentation right away.
Since I failed to do so, correct this now.

20 months agox86: correct CPU_AMX_{BF16,INT8}_FLAGS
Jan Beulich [Tue, 18 Oct 2022 06:26:56 +0000 (08:26 +0200)]
x86: correct CPU_AMX_{BF16,INT8}_FLAGS

AMX-TILE is a prereq to these, as already correctly expressed by
CPU_ANY_AMX_TILE_FLAGS. Express the dependency also in the reverse
("positive") direction.

20 months agoAutomatic date update in version.in
GDB Administrator [Tue, 18 Oct 2022 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

20 months agokfail an Ada test for GCC < 12
Tom Tromey [Mon, 17 Oct 2022 19:16:59 +0000 (13:16 -0600)]
kfail an Ada test for GCC < 12

I noticed one particular Ada test was failing on Fedora 34, but works
when I switch to GCC 12.  This patch arranges to kfail the test when
an older compiler is used.

I tested this with GCC 11, 12, and 13.  I'm going to check it in.

20 months agoRemove a nullptr check in DWARF scanner
Tom Tromey [Mon, 17 Oct 2022 18:46:21 +0000 (12:46 -0600)]
Remove a nullptr check in DWARF scanner

In scan_attributes, The DWARF scanner checks whether maybe_defer is
nullptr, but this can never happen.  This patch removes the check.

20 months agogdbarch-components.py: Remove spurious space from "frame_info_ptr " params
Pedro Alves [Mon, 17 Oct 2022 16:48:35 +0000 (17:48 +0100)]
gdbarch-components.py: Remove spurious space from "frame_info_ptr " params

If you run gdbarch.py today, you'll get local modifications compared
to what's in the tree, like:

 --- c/gdb/gdbarch-gen.h
 +++ w/gdb/gdbarch-gen.h
 @@ -315,8 +315,8 @@ extern void set_gdbarch_register_type (struct gdbarch *gdbarch, gdbarch_register
     should match the address at which the breakpoint was set in the dummy
     frame. */

 -typedef struct frame_id (gdbarch_dummy_id_ftype) (struct gdbarch *gdbarch, frame_info_ptr this_frame);
 -extern struct frame_id gdbarch_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame);
 +typedef struct frame_id (gdbarch_dummy_id_ftype) (struct gdbarch *gdbarch, frame_info_ptr  this_frame);
 +extern struct frame_id gdbarch_dummy_id (struct gdbarch *gdbarch, frame_info_ptr  this_frame);
  extern void set_gdbarch_dummy_id (struct gdbarch *gdbarch, gdbarch_dummy_id_ftype *dummy_id);

etc.

The extra space comes from the "frame_info_ptr " param that appears in
a number of gdbarch methods in gdbarch-components.py.  With the extra
space removed, running ./gdbarch.py generates the exact code that's in
the tree already.

Change-Id: If7d20b8c6b2fd9ff466142a01bd2611c9ef9f53e

20 months agoChange .gdb_index de-duplication implementation
Tom Tromey [Thu, 22 Sep 2022 19:10:55 +0000 (13:10 -0600)]
Change .gdb_index de-duplication implementation

While investigating PR symtab/29179, I found that one Ada test failed
because, although a certain symbol was present in the index, with the
new DWARF reader it pointed to a different CU than was chosen by
earlier versions of gdb.

This patch changes how symbol de-duplication is done, deferring the
process until the entire symbol table has been constructed.  This way,
it's possible to always choose the lower-numbered CU among duplicates,
which is how gdb (implicitly) previously worked.

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

20 months agoImprove Ada support in .gdb_index
Tom Tromey [Thu, 22 Sep 2022 14:43:47 +0000 (08:43 -0600)]
Improve Ada support in .gdb_index

The cooked index work changed how .gdb_index is constructed, and in
the process broke .gdb_index support.  This is PR symtab/29179.

This patch partially fixes the problem.  It arranges for Ada names to
be encoded in the form expected by the index code.  In particular,
linkage names for Ada are emitted, including the "main" name; names
are Ada-encoded; and names are no longer case-folded, something that
prevented operator names from round-tripping correctly.

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

20 months agoDon't add type linkage names to cooked index
Tom Tromey [Fri, 14 Oct 2022 13:08:57 +0000 (07:08 -0600)]
Don't add type linkage names to cooked index

The compiler will sometimes emit a linkage name for a type, like:

    <1d3>   DW_AT_linkage_name: (indirect string, offset: 0x106f): 11__mbstate_t

These names aren't very useful, and this patch changes the DWARF
reader so that they are ignored by the cooked index.

20 months agoFix regression in c-linkage-name.exp with gdb index
Tom Tromey [Fri, 14 Oct 2022 13:10:08 +0000 (07:10 -0600)]
Fix regression in c-linkage-name.exp with gdb index

c-linkage-name.exp started failing with the gdb-index target board due
to an earlier patch.  The problem here is that some linkage names must
be in the index -- but, based on inspection, not C++ linkage names.
This patch updates the code to exclude only these.

20 months agoFix null pointer representations
TaiseiIto [Tue, 13 Sep 2022 13:55:03 +0000 (22:55 +0900)]
Fix null pointer representations

Since "NULL" and "0" are used to represent invalid address in function
"gdbarch_find_by_info" in "binutils-gdb/gdb/arch-utils.c", I modified
them to "nullptr".

20 months agogdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y
Simon Marchi [Wed, 12 Oct 2022 17:32:56 +0000 (13:32 -0400)]
gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y

When building with clang 15 on Ubuntu 20.04, I get:

      CXX    cp-name-parser.o
    cp-name-parser.c.tmp:1777:9: error: variable 'cpnameyynerrs' set but not used [-Werror,-Wunused-but-set-variable]
        int yynerrs;
            ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:58:18: note: expanded from macro 'yynerrs'
    #define yynerrs         GDB_YY_REMAP (yynerrs)
                            ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:40:29: note: expanded from macro 'GDB_YY_REMAP'
    #define GDB_YY_REMAP(YYSYM) GDB_YY_REMAP_1 (GDB_YY_REMAP_PREFIX, YYSYM)
                                ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:39:39: note: expanded from macro 'GDB_YY_REMAP_1'
    #define GDB_YY_REMAP_1(PREFIX, YYSYM) GDB_YY_REMAP_2 (PREFIX, YYSYM)
                                          ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:38:39: note: expanded from macro 'GDB_YY_REMAP_2'
    #define GDB_YY_REMAP_2(PREFIX, YYSYM) PREFIX ## YYSYM
                                          ^
    <scratch space>:45:1: note: expanded from here
    cpnameyynerrs
    ^

This is because clang 15 warns for something like this:

    int n;
    n = 0;
    ++n;

whereas previous versions do not.

yynerrs is defined in yyparse and is there for actions to use.  Since
the actions in cp-name-parser.y don't use it, we get a warning.  We see
this problem on this particular .y file because it uses `%pure-parser`
[1], which makes yynerrs a local rather than a global.

I initially fixed this by using
DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE (like in commit f7aa1a5acc5
("gold: Suppress "unused" variable warning on Clang")), but then I
realized we could suppress the warning in a more fine-grained way using
this in a rule:

    (void) yynerrs;

[1] https://www.gnu.org/software/bison/manual/html_node/Error-Reporting-Function.html

Change-Id: I6cae7a4207c19fe1b719e2ac19be69122ebe3af1

20 months agold/testsuite: consistently add board_ldflags when linking with GCC
Clément Chigot [Thu, 15 Sep 2022 07:23:50 +0000 (09:23 +0200)]
ld/testsuite: consistently add board_ldflags when linking with GCC

Currently, the functions checking if the compiler is available or if a
feature is available add both board_cflags and board_ldflags.
However, functions running the tests only retrieve board_cflags. This
can lead to unexpected errors when mandaratory flags are defined in
board_ldflags and not board_cflags.

ld/ChangeLog:

* testsuite/ld-unique/unique.exp: Add board_ldflags when
linking with GCC.
* testsuite/lib/ld-lib.exp: Likewise.

20 months agoAllow explicit size specifier for predicate operand of {sq, uq, }{incp, decp}
CaiJingtao [Tue, 11 Oct 2022 01:55:10 +0000 (09:55 +0800)]
Allow explicit size specifier for predicate operand of {sq, uq, }{incp, decp}

Omitting predicate size specifier in vector form of {sq, uq, }{decp, incp} is deprecated and will be prohibited in a future release of the aarch64,
see https://developer.arm.com/documentation/ddi0602/2021-09/SVE-Instructions/DECP--vector---Decrement-vector-by-count-of-true-predicate-elements-.

This allows explicit size specifier, e.g. `decp z0.h, p0.h`, for predicate operand of these SVE instructions.
The existing behaviour of not requiring the specifier is preserved.
And the disasembly is with the specifier with this patch.

The GAS tests passed under our local tests.

opcodes/
* aarch64-asm.c: Modify `sve_size_hsd` encoding.
* aarch64-tbl.h (aarch64_opcode_table): Add QUALS's type OP_SVE_Vv_HSD
for decp, incp, sqdecp, sqincp, uqdecp and uqincp.

gas/
* testsuite/gas/aarch64/sve-movprfx_23.s: Update movprfx_23 testcase's
test_sametwo macro, where take the predicate size specifier.
* testsuite/gas/aarch64/sve-movprfx_23.d: Update movprfx_23 testcase's
expected disassembly.
* testsuite/gas/aarch64/sve-movprfx_23.l: Update movprfx_23 testcase's
expected assembler messages.
* testsuite/gas/aarch64/sve.s: Add sve testcase's instructions for
decp, incp, sqdecp, sqincp, uqdecp and uqincp, which take the
predicate size specifier.
* testsuite/gas/aarch64/sve.d: Update sve testcase's expected
disassembly.

Signed-off-by: CaiJingtao <caijingtao@huawei.com>
20 months agoaarch64: Tweak handling of F_STRICT
Richard Sandiford [Fri, 30 Sep 2022 11:34:59 +0000 (12:34 +0100)]
aarch64: Tweak handling of F_STRICT

Current F_STRICT qualifier checking is enforced after the fact
rather than as part of the match.  This makes it impossible to
have, e.g.:

   QLF2(S_D, S_D)
   QLF2(S_D, NIL)

in the same list.

opcodes/
* aarch64-opc.c (aarch64_find_best_match): Handle F_STRICT here
rather than...
(match_operands_qualifier): ...here.

20 months agox86: properly decode EVEX.W for AVX512_4{FMAPS,VNNIW} insns
Jan Beulich [Mon, 17 Oct 2022 06:27:32 +0000 (08:27 +0200)]
x86: properly decode EVEX.W for AVX512_4{FMAPS,VNNIW} insns

These require EVEX.W=0. Use %XS to facilitate the checking, even if for
the AVX512_4VNNIW ones this is kind of an abuse (as 's' there stands for
"signed", not "single").

While there also correct the 3rd operand for the AVX512_4VNNIW entries:
Only the memory form is allowed (just like for AVX512_4FMAPS, where the
correct type is already in use).

20 months agox86: fold AVX512-VNNI disassembler entries with AVX-VNNI ones
Jan Beulich [Mon, 17 Oct 2022 06:27:03 +0000 (08:27 +0200)]
x86: fold AVX512-VNNI disassembler entries with AVX-VNNI ones

Make %XV also print the separating blank in the VEX case, while making
it do nothing for EVEX-encoded insns. This way the AVX-VNNI entries
can be re-used for AVX512-VNNI, at the same time fixing the lack of
EVEX.W decoding.

For the AVX-VNNI ones further make sure only VEX.66 forms are actually
decoded.

20 months agoAutomatic date update in version.in
GDB Administrator [Mon, 17 Oct 2022 00:00:06 +0000 (00:00 +0000)]
Automatic date update in version.in

20 months agoMore uses of checked_static_cast
Tom Tromey [Sat, 24 Sep 2022 19:38:42 +0000 (13:38 -0600)]
More uses of checked_static_cast

This patch changes a few more uses of static_cast to use
checked_static_cast.  In this patch, cast-to-references are converted
by moving the dereference outside of the cast, as checked_static_cast
only handles pointers.

20 months agoUse checked_static_cast in more places
Tom Tromey [Sat, 24 Sep 2022 19:34:09 +0000 (13:34 -0600)]
Use checked_static_cast in more places

I looked through all the uses of static_cast<... *> in gdb and
converted many of them to checked_static_cast.

I couldn't test a few of these changes.

20 months agoPowerPC se_rfmci and VLE, SPE2 and LSP insns with -many
Alan Modra [Fri, 14 Oct 2022 01:58:33 +0000 (12:28 +1030)]
PowerPC se_rfmci and VLE, SPE2 and LSP insns with -many

I noticed recently that se_rfmci, a VLE mode instruction, was being
accepted by non-VLE cpus, and also that se_rfmci by itself in a
section did not cause SHF_PPC_VLE to be set.  ie. both testcases added
by this patch fail without the changes to tc-ppc.c here.

Also, VLE, SPE2 and LSP insns were not accepted by the assembler with
-many nor were SPE2 and LSP being disassembled with -Many.

gas/
* config/tc-ppc.c (ppc_setup_opcodes): Wrap long lines.  Add
vle_opcodes when PPC_OPCODE_VLE or PPC_OPCODE_ANY.  Simplify
disassembler index segment checks.  Add LSP and SPE2 opcodes
when PPC_OPCODE_ANY too.
(md_assemble): Correct logic adding PPC_APUINFO_VLE and
SHF_PPC_VLE.
* testsuite/gas/ppc/se_rfmci.s
* testsuite/gas/ppc/se_rfmci.d,
* testsuite/gas/ppc/se_rfmci_bad.d: New tests.
* testsuite/gas/ppc/ppc.exp: Run them.
opcodes/
* ppc-dis.c (print_insn_powerpc): Disassemble SPE2 and LSP insn
when -Many.
* ppc-opc.c (vle_opcodes <se_rfmci>): Comment.

20 months agozlib-gabi to zstd woes
Alan Modra [Fri, 14 Oct 2022 11:29:23 +0000 (21:59 +1030)]
zlib-gabi to zstd woes

So we had a zlib-gabi .debug_info section that increased in size with
zstd, so much so that it was better to leave the section
uncompressed.  Things went horribly wrong when the section was read
again later.  The section was read again off disk using the
uncompressed size.  So you get the zlib section again with some
garbage at the end.  Fix that particular problem by setting the
section flag SEC_IN_MEMORY.  Any future read will get sec->contents.

Also, if the section is to be left uncompressed, the input
SHF_COMPRESSED flag needs to be reset otherwise objcopy will copy it
to output.

Finally, bfd_convert_section_contents needed a small update to handle
zstd compressed sections, and I've deleted bfd_cache_section_contents.

* bfd.c (bfd_convert_section_contents): Handle zstd.
* compress.c (bfd_compress_section_contents): When section
contents are uncompressed set SEC_IN_MEMORY flag,
compress_status to COMRESS_SECTION_NONE, and clear
SHF_COMPRESSED.  Set SEC_IN_MEMORY for compressed contents.
(bfd_get_full_section_contents): Don't check section size
against file size when SEC_IN_MEMORY.
(bfd_cache_section_contents): Delete function.
* elf32-arm.c (elf32_arm_get_synthetic_symtab): Expand
bfd_cache_section_contents here.
* bfd-in2.h: Regenerate.

20 months agoAutomatic date update in version.in
GDB Administrator [Sun, 16 Oct 2022 00:00:31 +0000 (00:00 +0000)]
Automatic date update in version.in

20 months agogdb/arm: Don't rely on loop detection to stop unwinding
Torbjörn SVENSSON [Fri, 14 Oct 2022 13:34:24 +0000 (15:34 +0200)]
gdb/arm: Don't rely on loop detection to stop unwinding

Setting SP of the next frame to the same address as the current frame
is an ugly way to stop the unwinding.  A cleaner way is to rely on
the frame_unwind_stop_reason function to return UNWIND_OUTERMOST.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
20 months agoAutomatic date update in version.in
GDB Administrator [Sat, 15 Oct 2022 00:00:42 +0000 (00:00 +0000)]
Automatic date update in version.in

20 months ago[gdb/testsuite] Add boards/README
Tom de Vries [Fri, 14 Oct 2022 19:22:57 +0000 (21:22 +0200)]
[gdb/testsuite] Add boards/README

Add a file gdb/testsuite/boards/README, to make it easier to get a high-level
overview of the various boards.

20 months ago[gdb/contrib] Handle STRIP_ARGS_{STRIP,KEEP}_DEBUG in cc-with-tweaks.sh
Tom de Vries [Fri, 14 Oct 2022 19:22:57 +0000 (21:22 +0200)]
[gdb/contrib] Handle STRIP_ARGS_{STRIP,KEEP}_DEBUG in cc-with-tweaks.sh

Handle new environment variable STRIP_ARGS_STRIP_DEBUG, defaulting to
--strip-debug in gdb/contrib/cc-with-tweaks.sh, such that we can easily
reproduce the PR29277 assert using:
...
$ export STRIP_ARGS_STRIP_DEBUG=--strip-all
$ make check RUNTESTFLAGS="gdb.base/jit-reader.exp \
    --target_board cc-with-gnu-debuglink"
...

For completeness sake and to avoid confusion about which of the two used strip
invocations the passed args apply to, likewise add STRIP_ARGS_KEEP_DEBUG,
defaulting to --only-keep-debug.

Script checked with shellcheck, no new warnings added.

Tested on x86_64-linux.

20 months ago[gdb] Fix heap-buffer-overflow in find_program_interpreter
Tom de Vries [Fri, 14 Oct 2022 19:22:57 +0000 (21:22 +0200)]
[gdb] Fix heap-buffer-overflow in find_program_interpreter

With the test-case included in this patch, we run into:
...
(gdb) target remote localhost:2347^M
`target:twice-connect' has disappeared; keeping its symbols.^M
Remote debugging using localhost:2347^M
warning: Unable to find dynamic linker breakpoint function.^M
GDB will be unable to debug shared library initializers^M
and track explicitly loaded dynamic code.^M
Reading /usr/lib/debug/.build-id/$hex/$hex.debug from remote target...^M
0x00007ffff7dd4550 in ?? ()^M
(gdb) PASS: gdb.server/twice-connect.exp: session=second: gdbserver started
FAIL: gdb.server/twice-connect.exp: found interpreter
...

The problem originates in find_program_interpreter, where
bfd_get_section_contents is called to read .interp, but fails.  The function
returns false but the result is ignored, so find_program_interpreter returns
some random string.

Fix this by checking the result of the call to bfd_get_section_contents.

Tested on x86_64-linux.

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

20 months ago[gdb/testsuite] Fix gdb.server/unittest.exp with host board local-remote-host.exp
Tom de Vries [Fri, 14 Oct 2022 17:59:26 +0000 (19:59 +0200)]
[gdb/testsuite] Fix gdb.server/unittest.exp with host board local-remote-host.exp

With test-case gdb.server/unittest.exp and host board local-remote-host.exp I
run into:
...
builtin_spawn build/gdbserver/gdbserver --selftest^M
ERROR: : spawn id exp7 not open
    while executing
"expect {
-i exp7 -timeout 10
    -i $server_spawn_id
    -re "Ran ($decimal) unit tests, 0 failed" {
        set num_ran $expect_out(1,string)
        gdb_assert "..."
    ("uplevel" body line 1)
    invoked from within
"uplevel $body" NONE : spawn id exp7 not open
UNRESOLVED: gdb.server/unittest.exp: unit tests
...

The problem is (as fixed for avr in commit df5b8876083 ("gdb/testsuite: better
handle failures in simavr board, reap simavr process")), that gdb_expect through
remote_expect adds a "-i <gdb spawn id> -timeout 10", which is the one causing
the error.

As in aforementioned commit, fix this by using expect instead.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Fix host board local-remote-host-notty.exp timeouts
Tom de Vries [Fri, 14 Oct 2022 17:59:26 +0000 (19:59 +0200)]
[gdb/testsuite] Fix host board local-remote-host-notty.exp timeouts

With test-case gdb.server/stop-reply-no-thread-multi.exp and host board
local-remote-host-notty.exp we occasionally run into a silent out, due to
getting:
...
(gdb) kill^M
(gdb) The program is not being run.^M
...
instead of the expected:
...
(gdb) kill^M
The program is not being run.^M
(gdb)
...

Likewise, we occasionally run into a nonsilent timeout:
...
(gdb) disconnect^M
(gdb) You can't do that when your target is `exec'^M
FAIL: gdb.server/stop-reply-no-thread.exp: to_disable=Tthread: t_nonstop=on: \
  disconnect (timeout)
...

Typically, this results in the test-case taking more than two minutes to run.

The problem can be reproduced using just:
...
$ ssh -l $USER 127.0.0.1 gdb -q -ex kill
...

Note that ssh by default uses -T which disables pseudo-tty allocation (as
opposed to -t which forces pseudo-tty allocation):
...
$ ssh -l $USER 127.0.0.1 -T tty
not a tty
$ ssh -l $USER 127.0.0.1 -t tty
/dev/pts/5
Connection to 127.0.0.1 closed.
...
and according to https://stackoverflow.com/a/63241102 the behaviour we're
seeing is specific to using '-T'.

The related host board local-remote-host.exp does use '-t', and the only
difference between the two boards mentioned is whether editing is on or off.

Fix this by:
- moving the content of local-remote-host-notty.exp into
  local-remote-host.exp
- consequently, extending the copyright years in local-remote-host.exp
- including local-remote-host.exp in local-remote-host-notty.exp
  (making local-remote-host-notty.exp use '-t')
- adding -iex "set editing off" to GDBFLAGS in local-remote-host-notty.exp

This results in the test-case taking just 6 seconds to run.

Tested on x86_64-linux.

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

20 months ago[gdb/testsuite] Disable styling in host board local-remote-host.exp
Tom de Vries [Fri, 14 Oct 2022 17:59:26 +0000 (19:59 +0200)]
[gdb/testsuite] Disable styling in host board local-remote-host.exp

With test-case gdb.server/stop-reply-no-thread.exp and host board
local-remote-host.exp, I run into:
...
Breakpoint 1, ^[[33mmain^[[m () at ^[[32mstop-reply-no-thread.c^[[m:21^M
21        ^[[01;34mreturn^[[m ^[[35m0^[[m^[[31m;^[[m^M
(gdb) FAIL: gdb.server/stop-reply-no-thread.exp: to_disable=: t_nonstop=off: \
  continue to main
...

The problem is that styling is enabled, and that is causing a regexp mismatch.

With native, styling is disabled in default_gdb_init by doing
'setenv TERM "dumb"', but that only has effect because the build (where we
execute runtest, and consequently the setenv) and the host (where we execute
gdb) are the same.  For this host board however, gdb executes on a remote
host, and the setenv has no effect.

We could try to make some generic way to set TERM on the host, but for the
purposes of this test-case it seems sufficient to just add:
...
set GDBFLAGS "${GDBFLAGS} -iex \"set style enabled off\""
...
so let's go with that for now.

Tested on x86_64-linux.

20 months agoUse scoped_value_mark in more places
Tom Tromey [Mon, 3 Oct 2022 19:51:58 +0000 (13:51 -0600)]
Use scoped_value_mark in more places

I looked at all the spots using value_mark, and converted all the
straightforward ones to use scoped_value_mark instead.

Regression tested on x86-64 Fedora 34.

20 months agogdb/arm: Stop unwinding on error, but do not assert
Torbjörn SVENSSON [Thu, 6 Oct 2022 14:15:56 +0000 (16:15 +0200)]
gdb/arm: Stop unwinding on error, but do not assert

When it's impossible to read the FPCCR and XPSR, the unwinding is
unpredictable as the it's not possible to determine the correct
frame size or padding.
The only sane thing to do in this condition is to stop the unwinding.

Example session without this patch:

  (gdb) bt
  #0  SVC_Handler () at .../GPIO/GPIO_EXTI/Src/stm32f4xx_it.c:112
  .../gdb/arm-tdep.c:3594: internal-error: arm_m_exception_cache: Assertion `safe_read_memory_unsigned_integer (FPCCR, ARM_INT_REGISTER_SIZE, byte_order, &fpccr)' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  ----- Backtrace -----
  0x5583bfb2a157 gdb_internal_backtrace_1
  ...
  ---------------------

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

  Aborted (core dumped)

Example session with this patch:

  (gdb) bt
  #0  SVC_Handler () at .../GPIO/GPIO_EXTI/Src/stm32f4xx_it.c:112
  warning: Could not fetch required FPCCR content.  Further unwind is impossible.
  #1  <signal handler called>
  (gdb)

Reviewed-by: Pedro Alves <pedro@palves.net>
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
20 months agoPowerPC SPE disassembly and tests
Alan Modra [Thu, 13 Oct 2022 05:40:15 +0000 (16:10 +1030)]
PowerPC SPE disassembly and tests

Where sub and subf forms of an instruction exist we generally
disassemble to the extended insn sub form rather than the underlying
machine subf instruction.  Do so for SPE evsubw and evsubiw too.

spe_ambiguous.d always was a bit too optimistic.  There is no sensible
way to disassemble identical bytes back to different and original
source.  Instead change the test to check -Mraw results.

gas/
* testsuite/gas/ppc/ppc.exp: Run spe_ambiguous test.
* testsuite/gas/ppc/spe.d: Expect evsubw and evsubiw rather than
evsubfw and evsubifw.
* testsuite/gas/ppc/spe_ambiguous.s: Test evnor form equivalent
to evnot.
* testsuite/gas/ppc/spe_ambiguous.d: Test Mraw.
opcodes/
* ppc-opc.c (powerpc_opcodes): Move evsubw before evsubfw and
evsubiw before evsubifw and mark EXT.

20 months agoe200 LSP support
Alan Modra [Wed, 12 Oct 2022 22:16:28 +0000 (08:46 +1030)]
e200 LSP support

It has bothered me for a long time that we have disabled LSP (and SPE)
tests.  Also the LSP test comment indicating there is something wrong
with get_powerpc_dialect.  I don't think there is.  Decoding of a VLE
instruction depends on whether the processor is in VLE mode (some
processors support both VLE and standard PPC) which we flag per
section with SHF_PPC_VLE for decoding when disassembling.

Background: Some versions of powerpc e200 have "Lightweight Signal
Processing" support, examples being e200z215 and e200z425.  As far as
I can tell, LSP and SPE are mutually exclusive.  This seems to be
borne out by insn encoding, for example LSP "zvaddih" and SPE "evaddw"
have the same encoding.  So none of the processor descriptions in
ppc_opts ought to have both PPC_OPCODE_LSP and PPC_OPCODE_SPE/2, if we
want disassembly to work.  I also could not find anything to suggest
that the LSP insns are enabled only in VLE mode, which means the LSP
insns should not be in vle_opcodes.

Fix all this by moving the LSP insns to their own table, and add a new
e200z2 cpu entry with LSP support, removing LSP from -me200z4 and from
-mvle.  (Yes, I know, as I said above some of the e200z4 processors
have LSP.  Others have SPE.  It's hard to choose good options.  Think
of z2 as meaning earlier, z4 as later.)  Also add -mlsp to allow
adding the LSP insn set.

include/
* opcode/ppc.h (lsp_opcodes, lsp_num_opcodes): Declare.
(LSP_OP_TO_SEG): Define.
binutils/
* doc/binutils.texi: Update ppc docs.
gas/
* config/tc-ppc.c (ppc_setup_opcodes): Add lsp opcodes to ppc_hash.
* doc/c-ppc.texi: Document e200 and lsp.
* testsuite/gas/ppc/lsp-checks.d: Assemble with -me200z2.
* testsuite/gas/ppc/lsp.d: Likewise, disassembly too.
* testsuite/gas/ppc/ppc.exp: Don't xfail lsp test.
opcodes/
* ppc-dis.c (ppc_opts): Add e200z2 and lsp.  Don't set
PPC_OPCODE_LSP for e200z4 or vle.
(ppc_parse_cpu): Mutually exclude LSP and SPE.
(LSP_OPCD_SEGS): Define.
(lsp_opcd_indices): New array.
(disassemble_init_powerpc): Init lsp_opcd_indices.
(lookup_lsp): New function.
(print_insn_powerpc): Call it.
* ppc-opc.c: Include libiberty.h for ARRAY_SIZE and use throughout.
(vle_opcodes): Move LSP opcodes to..
(lsp_opcodes): ..here, and sort.
(lsp_num_opcodes): New.

20 months agoPR29677, Field `the_bfd` of `asymbol` is uninitialised
Alan Modra [Fri, 14 Oct 2022 00:00:21 +0000 (10:30 +1030)]
PR29677, Field `the_bfd` of `asymbol` is uninitialised

Besides not initialising the_bfd of synthetic symbols, counting
symbols when sizing didn't match symbols created if there were any
dynsyms named "".  We don't want synthetic symbols without names
anyway, so get rid of them.  Also, simplify and correct sanity checks.

PR 29677
* mach-o.c (bfd_mach_o_get_synthetic_symtab): Rewrite.

20 months ago[gdb/testsuite] Drop unnecessary -Wl,-soname in gdb.base/skip-solib.exp
Tom de Vries [Fri, 14 Oct 2022 11:09:51 +0000 (13:09 +0200)]
[gdb/testsuite] Drop unnecessary -Wl,-soname in gdb.base/skip-solib.exp

I noticed in gdb.base/skip-solib.exp:
...
if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} \
        [list debug -Wl,-soname,${libname}.so]] != ""} {
    return -1
}
...
that the -Wl,-soname argument is missing an ldflags= prefix, but adding it
gives us a duplicate:
...
Executing on host: gcc -fno-stack-protector \
  outputs/gdb.base/skip-solib/skip-solib-lib.c.o  -fdiagnostics-color=never \
  -shared -g  -Wl,-soname,libskip-solib.so -Wl,-soname,libskip-solib.so -lm \
  -o outputs/gdb.base/skip-solib/libskip-solib.so    (timeout = 300)
...
so apparently it's taken care of by gdb_compile_shlib.

Drop the inactive and also unnecessary -Wl,-soname,${libname}.so from the
flags list for the gdb_compile_shlib call.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Fix gdb.base/infoline-reloc-main-from-zero.exp with PIE
Tom de Vries [Fri, 14 Oct 2022 11:09:51 +0000 (13:09 +0200)]
[gdb/testsuite] Fix gdb.base/infoline-reloc-main-from-zero.exp with PIE

With test-case gdb.base/infoline-reloc-main-from-zero.exp and target board
unix/-fPIE/-pie I run into:
...
gdb compile failed, ld: infoline-reloc-main-from-zero: error: \
  PHDR segment not covered by LOAD segment
collect2: error: ld returned 1 exit status
...

When running with native, I find that the executable is static:
...
$ file infoline-reloc-main-from-zero
infoline-reloc-main-from-zero: ELF 64-bit LSB executable, x86-64, \
  version 1 (SYSV), statically linked, BuildID[sha1]=$hex, with debug_info, \
  not stripped
...
despite not having been compiled with -static.

Fix the compilation by adding -static to the compilation flags.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Fix gdb.base/infoline-reloc-main-from-zero.exp with clang
Tom de Vries [Fri, 14 Oct 2022 11:09:51 +0000 (13:09 +0200)]
[gdb/testsuite] Fix gdb.base/infoline-reloc-main-from-zero.exp with clang

With test-case gdb.base/infoline-reloc-main-from-zero.exp and clang I run into:
...
gdb compile failed, clang-13.0: warning: -e main: 'linker' input unused \
  [-Wunused-command-line-argument]
clang-13.0: warning: -Wl,-Ttext=0x00: 'linker' input unused \
  [-Wunused-command-line-argument]
clang-13.0: warning: -Wl,-N: 'linker' input unused \
  [-Wunused-command-line-argument]
UNTESTED: gdb.base/infoline-reloc-main-from-zero.exp: \
  infoline-reloc-main-from-zero.exp
UNTESTED: gdb.base/infoline-reloc-main-from-zero.exp: failed to compile
...

Fix this by using ldflags instead of additional_flags.

Likewise, fix all occurrences of:
...
$ find gdb/testsuite -name *.exp | xargs grep additional_flags.*Wl
...

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie
Tom de Vries [Fri, 14 Oct 2022 11:09:50 +0000 (13:09 +0200)]
[gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie

Compilers default to either PIE or no-PIE executables.

In order to test PIE executables with a compiler that produces non-PIE by
default, we can use target board unix/-fPIE/-pie, which set the multilib_flags
of the target board to "-fPIE -pie".

Likewise, we can use target board unix/-fno-PIE/-no-pie with a compiler that
produces PIE by default.

The target board unix/-fno-PIE/-no-pie has a potential problem when compiling
shared libs, because the multilib_flags will override the attempts of
gdb_compile_shlib to compile with -fPIC.  This is taken care of by running the
body of gdb_compile_shlib wrapped in with_PIE_multilib_flags_filtered.

The target board unix/-fPIE/-pie has a problem with nopie compilations.  The
current approach is to do the compilation hoping for the best, and if we find
out that the resulting executable is PIE despite specifying nopie, we error
out with the standard error message "nopie failed to prevent PIE executable".

That however does not work for hard-coded assembly nopie test-cases, which will
just noisily refuse to compile:
...
ld: amd64-disp-step0.o: relocation R_X86_64_32S against `.text' can not be \
  used when making a PIE object; recompile with -fPIE^M
...

Fix this in gdb_compile by filtering out the PIE settings in the target board
multilib_flags when pie or nopie is specified.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Factor out with_PIE_multilib_flags_filtered
Tom de Vries [Fri, 14 Oct 2022 11:09:50 +0000 (13:09 +0200)]
[gdb/testsuite] Factor out with_PIE_multilib_flags_filtered

Factor out new procs with_PIE_multilib_flags_filtered and
with_multilib_flags_filtered from proc gdb_compile_shlib.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Add cond_wrap proc
Tom de Vries [Fri, 14 Oct 2022 11:09:50 +0000 (13:09 +0200)]
[gdb/testsuite] Add cond_wrap proc

Add a new proc cond_wrap, that can be used to replace the repetitive:
...
    if { $cond } {
wrap {
    <body>
}
    } else {
<body>
    }
...
with the shorter:
...
    cond_wrap $cond wrap {
<body>
    }
...

Tested on x86_64-linux.

20 months agogdb: add Torbjörn Svensson to gdb/MAINTAINERS
Torbjörn SVENSSON [Fri, 14 Oct 2022 11:02:11 +0000 (13:02 +0200)]
gdb: add Torbjörn Svensson to gdb/MAINTAINERS

20 months agoRISC-V: Zicbo{m,p,z} adjustments to riscv_multi_subset_supports_ext()
Jan Beulich [Fri, 14 Oct 2022 10:52:16 +0000 (12:52 +0200)]
RISC-V: Zicbo{m,p,z} adjustments to riscv_multi_subset_supports_ext()

The lack thereof did caused gas to issue "internal: unreachable
INSN_CLASS_*" errors when trying to assemble respective insns without
the feature(s) enabled via e.g. ".option arch, ...". Of course a proper
hint towards the missing extension then wasn't given either.

20 months agoRISC-V: Imply 'Zicsr' from privileged extensions with CSRs
Tsukasa OI [Mon, 5 Sep 2022 08:11:54 +0000 (08:11 +0000)]
RISC-V: Imply 'Zicsr' from privileged extensions with CSRs

'H', 'Smstateen', 'Sscofpmf' and 'Sstc' are four privileged extensions with
their CSR definitions and 'Smepmp' is a privileged extension with additional
CSR bits.

Volume II: Privileged Architecture of the RISC-V ISA Manual states that the
privileged architecture requires the 'Zicsr' extension.  However, current
GNU Binutils has no direct way whether the program has dependency to the
privileged architecture itself.

As a workaround, we should add implications from privileged extensions that
either add new CSRs, extend existing CSRs or depends on using CSRs.

This commit adds such implications for existing privileged extensions that
satisfy this condition.

gas/ChangeLog:

* testsuite/gas/riscv/march-imply-h.d: New test, at least for 'H'.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_implicit_subsets): Add 'Zicsr'
implicications for privileged extensions 'H', 'Smstateen',
'Sscofpmf', 'Sstc' and 'Smepmp'.

20 months agoopcodes/riscv-dis.c: Remove last_map_state
Tsukasa OI [Sat, 27 Aug 2022 13:08:03 +0000 (13:08 +0000)]
opcodes/riscv-dis.c: Remove last_map_state

Before changing the core disassembler, we take care of minor code clarity
issues and improve readability.

This commit removes unused variable last_map_state (set by the
print_insn_riscv function but not read anywhere else).

opcodes/ChangeLog:

* riscv-dis.c (last_map_state): Remove.
(print_insn_riscv): Remove setting last_map_state.

20 months agoopcodes/riscv-dis.c: Make XLEN variable static
Tsukasa OI [Sat, 27 Aug 2022 13:33:51 +0000 (13:33 +0000)]
opcodes/riscv-dis.c: Make XLEN variable static

Before changing the core disassembler, we take care of minor code clarity
issues and improve readability.

Since xlen variable is not (and should not) used outside riscv-dis.c,
this commit makes this variable static.

opcodes/ChangeLog:

* riscv-dis.c (xlen): Make this variable static.

20 months agoopcodes/riscv-dis.c: Use bool type whenever possible
Tsukasa OI [Sat, 27 Aug 2022 13:09:06 +0000 (13:09 +0000)]
opcodes/riscv-dis.c: Use bool type whenever possible

Before changing the core disassembler, we take care of minor code clarity
issues and improve readability.

This commit replaces uses of int with bool whenever possible.

opcodes/ChangeLog:

* riscv-dis.c (no_aliases) Change type to bool.
(set_default_riscv_dis_options): Use boolean.
(parse_riscv_dis_option_without_args): Likewise.
(riscv_disassemble_insn): Use boolean keywords.

20 months agoopcodes/riscv-dis.c: Tidying with spacing
Tsukasa OI [Sat, 27 Aug 2022 13:07:34 +0000 (13:07 +0000)]
opcodes/riscv-dis.c: Tidying with spacing

Before changing the core disassembler, we take care of minor code clarity
issues and improve readability.

This commit takes care of improper spacing for code clarity.

opcodes/ChangeLog:

* riscv-dis.c (riscv_disassemble_insn): Tidying with spacing.

20 months agoopcodes/riscv-dis.c: Tidying with comments/clarity
Tsukasa OI [Sat, 27 Aug 2022 13:07:05 +0000 (13:07 +0000)]
opcodes/riscv-dis.c: Tidying with comments/clarity

Before changing the core disassembler, we take care of minor code clarity
issues and improve readability.

First, we need to clarify the roles of variables and code portions.

opcodes/ChangeLog:

* riscv-dis.c (xlen): Move before default_isa_spec. Add comment.
(default_isa_spec, default_priv_spec): Add comment.
(riscv_gpr_names, riscv_fpr_names): Likewise.
(parse_riscv_dis_option_without_args): Likewise.
(parse_riscv_dis_option, parse_riscv_dis_options): Likewise.
(maybe_print_address): Likewise.
(riscv_disassemble_insn): Fix comment about the Zfinx "extension".
Add comment about the riscv_multi_subset_supports call.

20 months agoRISC-V: Test DWARF register number for "fp"
Tsukasa OI [Thu, 11 Aug 2022 21:20:03 +0000 (06:20 +0900)]
RISC-V: Test DWARF register number for "fp"

This commit adds "fp" (x8 or s0) to dw-regnums.{s,d}.

gas/ChangeLog:

* testsuite/gas/riscv/dw-regnums.s: Add "fp".
* testsuite/gas/riscv/dw-regnums.d: Likewise.

20 months agoRISC-V: Move standard hints before all instructions
Tsukasa OI [Fri, 30 Sep 2022 04:39:13 +0000 (04:39 +0000)]
RISC-V: Move standard hints before all instructions

Because all standard hints must be placed before corresponding instruction
for the disassembler, they may taint basic RVI instruction section.

This commit moves all standard hints before all basic RVI instructions
to improve maintainability.

opcodes/ChangeLog:

* riscv-opc.c (riscv_opcodes): Move all standard hints before all
standard instructions.

20 months agoRISC-V: Move certain arrays to riscv-opc.c
Tsukasa OI [Sat, 8 Oct 2022 13:58:11 +0000 (13:58 +0000)]
RISC-V: Move certain arrays to riscv-opc.c

This is a part of small tidying (declare tables in riscv-opc.c).

include/ChangeLog:

* opcode/riscv.h (riscv_rm, riscv_pred_succ): Move declarations to
opcodes/riscv-opc.c.  New non-static definitions.

opcodes/ChangeLog:

* riscv-opc.c (riscv_rm, riscv_pred_succ): Move from
include/opcode/riscv.h.  Add description.

20 months agold: Add --undefined-version
Fangrui Song [Fri, 14 Oct 2022 02:06:43 +0000 (19:06 -0700)]
ld: Add --undefined-version

This cancels a previous --no-undefined-version.
gold has had --undefined-version for a long time.

20 months agoAutomatic date update in version.in
GDB Administrator [Fri, 14 Oct 2022 00:00:42 +0000 (00:00 +0000)]
Automatic date update in version.in

20 months agoPowerPC, fix gdb.base/watchpoint.exp on Power 9
Carl Love [Thu, 13 Oct 2022 21:05:55 +0000 (17:05 -0400)]
PowerPC, fix gdb.base/watchpoint.exp on Power 9

Test gdb.base/watchpoint.exp generates 4 test errors on Power 9.  The
test uses the test [target_info exists gdb,no_hardware_watchpoints] to
determine if the processor supports hardware watchpoints.  The check
only examines the processor type to determine if it supports hardware
watchpoints.

The PowerPC processors support hardware watchpoints with the
exception of Power 9. The hardware watchpoint support is disabled on
Power 9.  The test skip_hw_watchpoint_tests must be used to correctly
determine if the PowerPC processor supports hardware watchpoints.

This patch replaces the [target_info exists gdb,no_hardware_watchpoints]
with the skip_hw_watchpoint_tests_p check.  With the patch, the test runs
on Power 9 with hardware watchpoint force-disabled.  The test runs on
all other PowerPC processors with and without hardware watchpoints
enabled.

The patch has been tested on Power 9 to verify the test only runs with
hardware breakpoints disabled.  The patch has been tested on X86-64 with
no regression failures.  The test fails on Power 10 due to an internal GDB
error due to resource management.  The resource management issue will be
addressed in another patch.

20 months ago[gdb/testsuite] Fix gdb.dwarf2/macro-source-path.exp with -m32
Tom de Vries [Thu, 13 Oct 2022 10:18:39 +0000 (12:18 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/macro-source-path.exp with -m32

With test-case gdb.dwarf2/macro-source-path.exp and target board unix/-m32, I
run into:
...
as: macro-source-path-gcc11-ld238-dw5-filename-641.o: \
  unsupported relocation type: 0x1^M
...

The problem is that we have 64-bit dwarf so the debug_line offset in the
.debug_macro section is an 8-byte entity, emitted using ".8byte":
...
        .section .debug_macro
.Lcu_macros4:
        .2byte        5                 /* version */
        .byte        3                  /* flags */
        .8byte        .LLlines3         /* debug_line offset */
...
but the linker doesn't support 8-byte relocation types on a 32-bit architecture.

This is similar to what was fixed in commit a5ac8e7fa3b
("[gdb/testsuite] Fix 64-bit dwarf test-cases with -m32") for for instance
.debug_abbrev.

Fix this in the same way, by using _op_offset to emit the debug_line offset.

Tested on x86_64-linux with native and target board unix/-m32.

20 months ago[gdb/testsuite] Fix gdb.dwarf2/entry-value-typedef.exp with -m32
Tom de Vries [Thu, 13 Oct 2022 08:03:09 +0000 (10:03 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/entry-value-typedef.exp with -m32

With test-case gdb.dwarf2/entry-value-typedef.exp and target board unix/-m32,
I run into:
...
builtin_spawn -ignore SIGHUP g++ -fno-stack-protector \
  gdb/testsuite/gdb.dwarf2/entry-value-typedef-amd64.S \
  -fdiagnostics-color=never -Lbuild/libiberty -lm -m32 \
  -o outputs/gdb.dwarf2/entry-value-typedef/entry-value-typedef^M
entry-value-typedef.cpp: Assembler messages:^M
entry-value-typedef.cpp:38: Error: bad register name `%rbp'^M
...

The problem is that the test-cases selects an amd64 .S file based on the check:
...
if { [istarget "x86_64-*-linux*"] } {
...
which is also true for target board unix/-m32 on x86_64-linux.

Fix this by adding the missing is_lp64_target check.

Tested on x86_64-linux, using native and target board unix/-m32.

20 months ago[gdb/testsuite] Fix gdb.mi/mi-disassemble.exp with -m32
Tom de Vries [Thu, 13 Oct 2022 07:43:23 +0000 (09:43 +0200)]
[gdb/testsuite] Fix gdb.mi/mi-disassemble.exp with -m32

With target board unix/-m32 and test-case gdb.mi/mi-disassemble.exp we have:
...
(gdb) ^M
print/x *((unsigned char *) 0x8048485)^M
&"print/x *((unsigned char *) 0x8048485)\n"^M
~"$9 = 0x83\n"^M
^done^M
(gdb) ^M
PASS: gdb.mi/mi-disassemble.exp: get valueof "*((unsigned char *) 0x8048485)"
FAIL: gdb.mi/mi-disassemble.exp: byte at 0x8048485 matches
...
The test-case passes with native.

With native we see in gdb.log that variable longest_insn_bytes is:
...
Longest instruction at 0x0000000000400549 with bytes '48 8b 05 20 01 00 00'
...
and variable split_bytes (added debug puts) ends up as:
...
SPLIT_BYTES: 48 8b 05 20 01 00 00
...

But with unix/-m32 we have longest_insn_byte:
...
Longest instruction at 0x08048481 with bytes '8d 4c 24 04        '
...
and split_bytes ends up as:
...
SPLIT_BYTES: 8d 4c 24 04 {} {} {} {} {} {} {} {}
...
so the trailing whitespace is translated by split to empty bytes, and the
mismatch FAILs are generated for those.

Fix this by stripping the whitespace, which makes us end up with a different
and indeed longer insn:
...
Longest instruction at 0x08048492 with bytes 'dd 05 98 85 04 08'
...

Tested on x86_64-linux, with native and target board unix/-m32.

20 months agoAutomatic date update in version.in
GDB Administrator [Thu, 13 Oct 2022 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in

20 months agoPowerPC, fix test gdb.base/watchpoint-stops-at-right-insn.exp
Carl Love [Wed, 12 Oct 2022 20:58:25 +0000 (16:58 -0400)]
PowerPC, fix test gdb.base/watchpoint-stops-at-right-insn.exp

Test gdb.base/watchpoint-stops-at-right-insn.exp generates 4 test errors
on Power 9.  The test uses the test [target_info exists gdb,
no_hardware_watchpoints] to determine if the processor supports hardware
watchpoints.  The check only examines the processor type to determine if
it supports hardware watchpoints.  Note, the test works fine on Power 10.

The PowerPC processors support hardware watchpoints with the
exception of Power 9. The hardware watchpoint support is disabled on
Power 9.  The test skip_hw_watchpoint_tests must be used to correctly
determine if the PowerPC processor supports hardware watchpoints.

This patch replaces the [target_info exists gdb,no_hardware_watchpoints]
with the skip_hw_watchpoint_tests_p check.  With the patch, the test is
disabled on Power 9 but runs on all other PowerPC processors.

The patch has been tested on Power 9, Power 10 and X86-64 with no
regression failures.

20 months agox86: drop "regmask" static variable
Jan Beulich [Wed, 12 Oct 2022 16:03:43 +0000 (18:03 +0200)]
x86: drop "regmask" static variable

Replace its two uses by more direct checks, paralleling what's already
there for SIMD registers.

20 months ago[gdb/symtab] Factor out elf_symfile_read_dwarf2
Tom de Vries [Wed, 12 Oct 2022 15:07:35 +0000 (17:07 +0200)]
[gdb/symtab] Factor out elf_symfile_read_dwarf2

Factor out elf_symfile_read_dwarf2 from elf_symfile_read.  NFC.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Fix ctf test-cases on openSUSE Tumbleweed
Tom de Vries [Wed, 12 Oct 2022 15:02:15 +0000 (17:02 +0200)]
[gdb/testsuite] Fix ctf test-cases on openSUSE Tumbleweed

When running test-case gdb.base/ctf-constvars.exp on openSUSE Tumbleweed (with
system gcc version 12, providing gcc -gctf support, enabling the ctf test-cases
in the gdb testsuite), I run into:
...
(gdb) print vox^M
'vox' has unknown type; cast it to its declared type^M
(gdb) FAIL: gdb.base/ctf-constvars.exp: print vox
...

There are two causes for this:
- the linker flags are missing --ctf-variables, so the information for variable
  vox is missing (reported in PR29468), and
- the executable contains some dwarf2 due to some linked-in glibc objects,
  so the ctf info is ignored (reported in PR29160).

By using:
- -Wl,--ctf-variable,
- -Wl,--strip-debug, and
we can make the test-case and some similar test-cases pass.

Tested on x86_64-linux.

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

20 months ago[gdb/testsuite] Silence warnings about obsolete -gstabs
Tom de Vries [Wed, 12 Oct 2022 15:02:15 +0000 (17:02 +0200)]
[gdb/testsuite] Silence warnings about obsolete -gstabs

When running test-case gdb.base/gdbindex-stabs.exp on openSUSE Tumbleweed (with
gcc 12) I get:
...
gdb compile failed, gdb/testsuite/gdb.base/gdbindex-stabs.c: warning: \
  STABS debugging information is obsolete and not supported anymore
...

Silence the warning by passing quiet to gdb_compile.  Likewise in two other
test-cases.

20 months ago[gdb/testsuite] Replace remaining -gt with -gctf
Tom de Vries [Wed, 12 Oct 2022 15:02:15 +0000 (17:02 +0200)]
[gdb/testsuite] Replace remaining -gt with -gctf

With test-cases gdb.base/cvexpr.exp and gdb.base/whatis.exp I run into:
...
gdb compile failed, gcc: error: unrecognized debug output level 't'
...

This is due to using additional_flags=-gt.

Commit ffb3f587933 ("CTF: multi-CU and archive support") replaced
additional_flags=-gt with additional_flags=-gctf in gdb.ctf/*.exp and
gdb.base/ctf-*.exp.

Do the same in these two test-cases.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Fix gdb.base/infoline-reloc-main-from-zero.exp with recent ld
Tom de Vries [Wed, 12 Oct 2022 14:50:16 +0000 (16:50 +0200)]
[gdb/testsuite] Fix gdb.base/infoline-reloc-main-from-zero.exp with recent ld

On openSUSE Tumbleweed (with ld 2.39) and test-case
gdb.base/infoline-reloc-main-from-zero.exp, I get:
...
gdb compile failed, ld: warning: infoline-reloc-main-from-zero has a LOAD \
  segment with RWX permissions
UNTESTED: gdb.base/infoline-reloc-main-from-zero.exp: \
  infoline-reloc-main-from-zero.exp
...

Fix this by compiling with -Wl,--no-warn-rwx-segments.

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Fix gdb.base/nested-subp{2,3}.exp with recent ld
Tom de Vries [Wed, 12 Oct 2022 14:50:16 +0000 (16:50 +0200)]
[gdb/testsuite] Fix gdb.base/nested-subp{2,3}.exp with recent ld

On openSUSE Tumbleweed (with ld 2.39) I get for test-case
gdb.base/nested-subp2.exp:
...
gdb compile failed, ld: warning: tmp.o: requires executable stack \
  (because the .note.GNU-stack section is executable)
...

Fix this by compiling with -Wl,--no-warn-execstack.

Likewise in gdb.base/nested-subp3.exp

Tested on x86_64-linux.

20 months ago[gdb/testsuite] Remove unnecessary perror in some test-cases
Tom de Vries [Wed, 12 Oct 2022 14:50:16 +0000 (16:50 +0200)]
[gdb/testsuite] Remove unnecessary perror in some test-cases

On openSUSE Tumbleweed I noticed:
...
UNTESTED: gdb.dwarf2/fission-absolute-dwo.exp: fission-absolute-dwo.exp
ERROR: failed to compile fission-absolute-dwo
...

The ERROR is unnecessary, given that an UNTESTED is already emitted.

Furthermore, it could be argued that it is incorrect because it's not a
testsuite error to not be able to compile something, and UNTESTED or
UNSUPPORTED is more appropriate.

Remove the perror call, likewise in fission-relative-dwo.exp.

Tested on x86_64-linux.

20 months agoFix objcopy's error message when it cannot add a .gnu_debuglink section because the...
Nick Clifton [Wed, 12 Oct 2022 14:32:18 +0000 (15:32 +0100)]
Fix objcopy's error message when it cannot add a .gnu_debuglink section because the section already exists.

PR 29665
* objcopy.c (copy_object): Use the input filename when
reporting that a .gnu_debuglink section already exists.

20 months agosim/ppc: Fix core_find_mapping diagnostics
Tsukasa OI [Wed, 12 Oct 2022 12:22:12 +0000 (12:22 +0000)]
sim/ppc: Fix core_find_mapping diagnostics

Because "%p" is the pointer conversion specifier to print a pointer in an
implementation-defined manner, the result with format string containing
"0x%p" can be strange.  For instance, core_map_find_mapping prints error
containing "0x0x...." (processor is not NULL) or "0x(null)" (processor is
NULL) on glibc.

This commit replaces "0x%p" with "%p" to prevent unpredictable behavior.

20 months agosim/ppc: fixes for arguments to printf style functions
Andrew Burgess [Tue, 11 Oct 2022 14:02:08 +0000 (15:02 +0100)]
sim/ppc: fixes for arguments to printf style functions

After the recent series of fixes to mark more functions in the
simulator with ATTRIBUTE_PRINTF, there were some build failures in the
ppc sim due, in some cases, to bugs with the arguments being passed,
and in other cases, the issues were (maybe) less serious, with
arguments being the wrong size, or type, for the printf format being
used.

This commit fixes all of the issues that I ran into.

In each case I selected the easiest solution to the problem, which is
usually just casting the argument to the correct type.  If anyone
later on thinks the print format should change, please feel free to do
that.  What we have here should keep the simulator basically working
as it does currently, which is my goal with this commit.

20 months ago[gdb/contrib] Use OBJCOPY everywhere in cc-with-tweaks.sh
Tom de Vries [Wed, 12 Oct 2022 08:55:39 +0000 (10:55 +0200)]
[gdb/contrib] Use OBJCOPY everywhere in cc-with-tweaks.sh

I noticed that the $want_gnu_debuglink code in gdb/contrib/cc-with-tweaks.sh
uses objcopy instead of $OBJCOPY.  Fix this.

Script checked with shellcheck, no new warnings added.

Tested on x86_64-linux.

20 months agoRe-apply "Pass PKG_CONFIG_PATH down from top-level Makefile"
Simon Marchi [Fri, 8 Apr 2022 14:56:41 +0000 (10:56 -0400)]
Re-apply "Pass PKG_CONFIG_PATH down from top-level Makefile"

Commit 228cf97dd3c8 ("Merge configure.ac from gcc project") undid the
change originally done in de83289ef32e ("Pass PKG_CONFIG_PATH down from
top-level Makefile").  Re-apply it.

Change-Id: I91138dfca41c43b05e53e445f62e4b27882536bf

20 months agogdb: rename target_read_auxv(target_ops *) to target_read_auxv_raw
Simon Marchi [Wed, 12 Oct 2022 00:53:39 +0000 (20:53 -0400)]
gdb: rename target_read_auxv(target_ops *) to target_read_auxv_raw

Having two overloads of target_read_auxv that don't have the same goals
is confusing.  Rename the one that reads from an explicit target_ops to
target_read_auxv_raw.  Also, it occured to me that the non-raw version
could use the raw version, that reduces duplication a bit.

Change-Id: I28e5f7cecbfcacd0174d4686efb3e4a23b4ad491

20 months agoAutomatic date update in version.in
GDB Administrator [Wed, 12 Oct 2022 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in

20 months agoRe: Merge configure.ac from gcc project
Alan Modra [Tue, 11 Oct 2022 23:36:35 +0000 (10:06 +1030)]
Re: Merge configure.ac from gcc project

Also copy over config.acx.m4, and regenerate.

20 months agogdb: fix auxv caching
Simon Marchi [Thu, 29 Sep 2022 20:14:40 +0000 (16:14 -0400)]
gdb: fix auxv caching

There's a flaw in the interaction of the auxv caching and the fact that
target_auxv_search allows reading auxv from an arbitrary target_ops
(passed in as a parameter).  This has consequences as explained in this
thread:

  https://inbox.sourceware.org/gdb-patches/20220719144542.1478037-1-luis.machado@arm.com/

In summary, when loading an AArch64 core file with MTE support by
passing the executable and core file names directly to GDB, we see the
MTE info:

    $ ./gdb -nx --data-directory=data-directory -q aarch64-mte-gcore aarch64-mte-gcore.core
    ...
    Program terminated with signal SIGSEGV, Segmentation fault
    Memory tag violation while accessing address 0x0000ffff8ef5e000
    Allocation tag 0x1
    Logical tag 0x0.
    #0  0x0000aaaade3d0b4c in ?? ()
    (gdb)

But if we do it as two separate commands (file and core) we don't:

    $ ./gdb -nx --data-directory=data-directory -q -ex "file aarch64-mte-gcore" -ex "core aarch64-mte-gcore.core"
    ...
    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  0x0000aaaade3d0b4c in ?? ()
    (gdb)

The problem with the latter is that auxv data gets improperly cached
between the two commands.  When executing the file command, auxv gets
first queried here, when loading the executable:

    #0  target_auxv_search (ops=0x55555b842400 <exec_ops>, match=0x9, valp=0x7fffffffc5d0) at /home/simark/src/binutils-gdb/gdb/auxv.c:383
    #1  0x0000555557e576f2 in svr4_exec_displacement (displacementp=0x7fffffffc8c0) at /home/simark/src/binutils-gdb/gdb/solib-svr4.c:2482
    #2  0x0000555557e594d1 in svr4_relocate_main_executable () at /home/simark/src/binutils-gdb/gdb/solib-svr4.c:2878
    #3  0x0000555557e5989e in svr4_solib_create_inferior_hook (from_tty=1) at /home/simark/src/binutils-gdb/gdb/solib-svr4.c:2933
    #4  0x0000555557e6e49f in solib_create_inferior_hook (from_tty=1) at /home/simark/src/binutils-gdb/gdb/solib.c:1253
    #5  0x0000555557f33e29 in symbol_file_command (args=0x7fffffffe01c "aarch64-mte-gcore", from_tty=1) at /home/simark/src/binutils-gdb/gdb/symfile.c:1655
    #6  0x00005555573319c3 in file_command (arg=0x7fffffffe01c "aarch64-mte-gcore", from_tty=1) at /home/simark/src/binutils-gdb/gdb/exec.c:555
    #7  0x0000555556e47185 in do_simple_func (args=0x7fffffffe01c "aarch64-mte-gcore", from_tty=1, c=0x612000047740) at /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:95
    #8  0x0000555556e551c9 in cmd_func (cmd=0x612000047740, args=0x7fffffffe01c "aarch64-mte-gcore", from_tty=1) at /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:2543
    #9  0x00005555580e63fd in execute_command (p=0x7fffffffe02c "e", from_tty=1) at /home/simark/src/binutils-gdb/gdb/top.c:692
    #10 0x0000555557771913 in catch_command_errors (command=0x5555580e55ad <execute_command(char const*, int)>, arg=0x7fffffffe017 "file aarch64-mte-gcore", from_tty=1, do_bp_actions=true) at /home/simark/src/binutils-gdb/gdb/main.c:513
    #11 0x0000555557771fba in execute_cmdargs (cmdarg_vec=0x7fffffffd570, file_type=CMDARG_FILE, cmd_type=CMDARG_COMMAND, ret=0x7fffffffd230) at /home/simark/src/binutils-gdb/gdb/main.c:608
    #12 0x00005555577755ac in captured_main_1 (context=0x7fffffffda10) at /home/simark/src/binutils-gdb/gdb/main.c:1299
    #13 0x0000555557775c2d in captured_main (data=0x7fffffffda10) at /home/simark/src/binutils-gdb/gdb/main.c:1320
    #14 0x0000555557775cc2 in gdb_main (args=0x7fffffffda10) at /home/simark/src/binutils-gdb/gdb/main.c:1345
    #15 0x00005555568bdcbe in main (argc=10, argv=0x7fffffffdba8) at /home/simark/src/binutils-gdb/gdb/gdb.c:32

Here, target_auxv_search is called on the inferior's target stack.  The
target stack only contains the exec target, so the query returns empty
auxv data.  This gets cached for that inferior in `auxv_inferior_data`.

In its constructor (before it is pushed to the inferior's target stack),
the core_target needs to identify the right target description from the
core, and for that asks the gdbarch to read a target description from
the core file.  Because some implementations of
gdbarch_core_read_description (such as AArch64's) need to read auxv data
from the core in order to determine the right target description, the
core_target passes a pointer to itself, allowing implementations to call
target_auxv_search it.  However, because we have previously cached
(empty) auxv data for that inferior, target_auxv_search searched that
cached (empty) auxv data, not auxv data read from the core.  Remember
that this data was obtained by reading auxv on the inferior's target
stack, which only contained an exec target.

The problem I see is that while target_auxv_search offers the
flexibility of reading from an arbitrary (passed as an argument) target,
the caching doesn't do the distinction of which target is being queried,
and where the cached data came from.  So, you could read auxv from a
target A, it gets cached, then you try to read auxv from a target B, and
it returns the cached data from target A.  That sounds wrong.  In our
case, we expect to read different auxv data from the core target than
what we have read from the target stack earlier, so it doesn't make
sense to hit the cache in this case.

To fix this, I propose splitting the code paths that read auxv data from
an inferior's target stack and those that read from a passed-in target.
The code path that reads from the target stack will keep caching,
whereas the one that reads from a passed-in target won't.  And since,
searching in auxv data is independent from where this data came from,
split the "read" part from the "search" part.

From what I understand, auxv caching was introduced mostly to reduce
latency on remote connections, when doing many queries.  With the change
I propose, only the queries done while constructing the core_target
end up not using cached auxv data.  This is fine, because there are just
a handful of queries max, done at this point, and reading core files is
local.

The changes to auxv functions are:

 - Introduce 2 target_read_auxv functions.  One reads from an explicit
   target_ops and doesn't do caching (to be used in
   gdbarch_core_read_description context).  The other takes no argument,
   reads from the current inferior's target stack (it looks just like a
   standard target function wrapper) and does caching.

   The first target_read_auxv actually replaces get_auxv_inferior_data,
   since it became a trivial wrapper around it.

 - Change the existing target_auxv_search to not read auxv data from the
   target, but to accept it as a parameter (a gdb::byte_vector).  This
   function doesn't care where the data came from, it just searches in
   it.  It still needs to take a target_ops and gdbarch to know how to
   parse auxv entries.

 - Add a convenience target_auxv_search overload that reads auxv
   data from the inferior's target stack and searches in it.  This
   overload is useful to replace the exist target_auxv_search calls that
   passed the `current_inferior ()->top_target ()` target and keep the
   call sites short.

 - Modify parse_auxv to accept a target_ops and gdbarch to use for
   parsing entries.  Not strictly related to the rest of this change,
   but it seems like a good change in the context.

Changes in architecture-specific files (tdep and nat):

 - In linux-tdep, linux_get_hwcap and linux_get_hwcap2 get split in two,
   similar to target_auxv_search.  One version receives auxv data,
   target and arch as parameters.  The other gets everything from the
   current inferior.  The latter is for convenience, to avoid making
   call sites too ugly.

 - Call sites of linux_get_hwcap and linux_get_hwcap2 are adjusted to
   use either of the new versions.  The call sites in
   gdbarch_core_read_description context explicitly read auxv data from
   the passed-in target and call the linux_get_hwcap{,2} function with
   parameters.  Other call sites use the versions without parameters.

 - Same idea for arm_fbsd_read_description_auxv.

 - Call sites of target_auxv_search that passed
   `current_inferior ()->top_target ()` are changed to use the
   target_auxv_search overload that works in the current inferior.

Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Reviewed-By: Luis Machado <luis.machado@arm.com>
Change-Id: Ib775a220cf1e76443fb7da2fdff8fc631128fe66

20 months ago[gdb/testsuite] Fix gdb.debuginfod/fetch_src_and_symbols.exp with native-gdbserver
Tom de Vries [Tue, 11 Oct 2022 16:11:52 +0000 (18:11 +0200)]
[gdb/testsuite] Fix gdb.debuginfod/fetch_src_and_symbols.exp with native-gdbserver

When running test-case gdb.debuginfod/fetch_src_and_symbols.exp with target
board native-gdbserver, I get:
...
Running gdb.debuginfod/fetch_src_and_symbols.exp ...
ERROR: tcl error sourcing gdb.debuginfod/fetch_src_and_symbols.exp.
ERROR: gdbserver does not support start without extended-remote
    while executing
"error "gdbserver does not support $command without extended-remote""
    (procedure "gdb_test_multiple" line 51)
    invoked from within
"gdb_test_multiple $command $message {*}$opts $user_code"
    (procedure "gdb_test" line 56)
    invoked from within
"gdb_test "start" "Temporary breakpoint.*""
...

Fix this by replacing gdb_test "start" with runto_main.

Tested on x86_64-linux.

20 months agoRe: Error: attempt to get value of unresolved symbol `L0'
Nick Clifton [Tue, 11 Oct 2022 14:28:10 +0000 (15:28 +0100)]
Re: Error: attempt to get value of unresolved symbol `L0'

* symbols.c (S_GET_VALUE): If the unresolved symbol is the fake
label provide a more helpful error message to the user.
(S_GET_VALUE_WHERE): Like S_GET_VALUE, but includes a file/line
number for error reporting purposes.
* symbols.h (S_GET_VALUE_WHERE): Prototype.
* write.c (fixup_segment): Use S_GET_VALUE_WHERE.

20 months agosim: Initialize pbb_br_* by default
Tsukasa OI [Thu, 6 Oct 2022 06:43:53 +0000 (06:43 +0000)]
sim: Initialize pbb_br_* by default

On the files generated by sim/common/genmloop.sh, variables pbb_br_type and
pbb_br_npc are declared uninitialized and passed to other functions in some
cases.  Despite that those are harmless, they will generate GCC warnings
("-Wmaybe-uninitialized").

This commit ensures that pbb_br_type and pbb_br_npc variables are
initialized to a harmless value.

20 months agosim: Check known getopt definition existence
Tsukasa OI [Thu, 6 Oct 2022 06:43:52 +0000 (06:43 +0000)]
sim: Check known getopt definition existence

Clang generates a warning if there is a function declaration/definition
with zero arguments.  Such declarations/definitions without a prototype (an
argument list) are deprecated forms of indefinite arguments
("-Wdeprecated-non-prototype").  On the default configuration, it causes a
build failure (unless "--disable-werror" is specified).

include/getopt.h defines some getopt function definitions but one of them
has a form "extern int getopt ();".  If this form is selected in
include/getopt.h, Clang generates a warning and the build fails by default.

In really old environments, this getopt definition with no arguments is
necessary (because the definition may change between environments).
However, this definition is now a cause of problems on modern environments.

A good news is, this definition is not always selected (e.g. if used by
binutils/*.c).  This is because configuration scripts of binutils, gas,
gprof and ld tries to find known definition of getopt function is used and
defines HAVE_DECL_GETOPT macro.  If this macro is defined when getopt.h is
included, a good form of getopt is used and Clang won't generate warnings.

This commit adds a modified portion of ld/configure.ac to find the known
getopt definition.  If we could find one (and we *will* in most modern
environments), we don't need to rely on the deprecated definition.

20 months agosim: Suppress non-literal printf warning
Tsukasa OI [Thu, 6 Oct 2022 06:43:51 +0000 (06:43 +0000)]
sim: Suppress non-literal printf warning

Clang generates a warning if the format string of a printf-like function is
not a literal ("-Wformat-nonliteral"). On the default configuration, it
causes a build failure (unless "--disable-werror" is specified).

To avoid this warning, this commit now uses vsnprintf to format error
message and pass the message to sim_engine_abort function with another
printf-style formatting.

This patch is mostly authored by Andrew Burgess and slightly modified by
Tsukasa OI.

Co-authored-by: Andrew Burgess <aburgess@redhat.com>
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
20 months agosim: Make WITH_{TRACE,PROFILE}-based macros bool
Tsukasa OI [Thu, 6 Oct 2022 06:43:50 +0000 (06:43 +0000)]
sim: Make WITH_{TRACE,PROFILE}-based macros bool

Clang generates a warning if there is an ambiguous expression (possibly a
bitwise operation (& or |), but a logical operator (&& or ||) is used;
"-Wconstant-logical-operand").  On the default configuration, it causes a
build failure (unless "--disable-werror" is specified).

This is caused by predicate macros that use the form (base_variable & flag).
Clang considers them as regular integer values (not boolean) and
generates that warning.

This commit makes Clang think those predicate macros to be boolean.

20 months agosim: Remove self-assignments
Tsukasa OI [Sun, 25 Sep 2022 08:42:02 +0000 (08:42 +0000)]
sim: Remove self-assignments

Clang generates a warning if there is a redundant self-assignment
("-Wself-assign").  On the default configuration, it causes a build failure
(unless "--disable-werror" is specified).

This commit removes redundant self-assignments from two files.

20 months agosim/rl78: Add ATTRIBUTE_PRINTF
Tsukasa OI [Thu, 6 Oct 2022 06:36:33 +0000 (06:36 +0000)]
sim/rl78: Add ATTRIBUTE_PRINTF

Clang generates a warning if the format string of a printf-like function is
not a literal ("-Wformat-nonliteral").  On the default configuration, it
causes a build failure (unless "--disable-werror" is specified).

To avoid warnings on the printf-like wrapper, it requires proper
__attribute__((format)) and we have ATTRIBUTE_PRINTF macro for this reason.

This commit adds ATTRIBUTE_PRINTF to the printf-like functions.

20 months agosim/ppc: Add ATTRIBUTE_PRINTF
Tsukasa OI [Thu, 6 Oct 2022 06:36:32 +0000 (06:36 +0000)]
sim/ppc: Add ATTRIBUTE_PRINTF

Clang generates a warning if the format string of a printf-like function is
not a literal ("-Wformat-nonliteral").  On the default configuration, it
causes a build failure (unless "--disable-werror" is specified).

To avoid warnings on the printf-like wrapper, it requires proper
__attribute__((format)) and we have ATTRIBUTE_PRINTF macro for this reason.

This commit adds ATTRIBUTE_PRINTF to the printf-like functions.

For the error function defined in sim_calls.c, the ATTRIBUTE_NORETURN
has been moved to the function declaration.

20 months agosim/m68hc11: Add ATTRIBUTE_PRINTF
Tsukasa OI [Thu, 6 Oct 2022 06:36:31 +0000 (06:36 +0000)]
sim/m68hc11: Add ATTRIBUTE_PRINTF

Clang generates a warning if the format string of a printf-like function is
not a literal ("-Wformat-nonliteral").  On the default configuration, it
causes a build failure (unless "--disable-werror" is specified).

To avoid warnings on the printf-like wrapper, it requires proper
__attribute__((format)) and we have ATTRIBUTE_PRINTF macro for this reason.

This commit adds ATTRIBUTE_PRINTF to a printf-like function.

20 months agosim/m32c: Add ATTRIBUTE_PRINTF
Tsukasa OI [Thu, 6 Oct 2022 06:36:30 +0000 (06:36 +0000)]
sim/m32c: Add ATTRIBUTE_PRINTF

Clang generates a warning if the format string of a printf-like function is
not a literal ("-Wformat-nonliteral").  On the default configuration, it
causes a build failure (unless "--disable-werror" is specified).

To avoid warnings on the printf-like wrapper, it requires proper
__attribute__((format)) and we have ATTRIBUTE_PRINTF macro for this reason.

This commit adds ATTRIBUTE_PRINTF to the printf-like functions.