binutils-gdb.git
12 months agogdbserver: don't leak program name in handle_v_run
Andrew Burgess [Wed, 4 Oct 2023 15:06:32 +0000 (16:06 +0100)]
gdbserver: don't leak program name in handle_v_run

I noticed that in handle_v_run (gdbserver/server.cc) we leak
new_program_name (a string) each time GDB starts an inferior, in the
case where GDB passes a program name to gdbserver.

This bug was introduced with this commit:

  commit 7ab2607f97e5deaeae91018edf3ef5b4255a842c
  Date:   Wed Apr 13 17:31:02 2022 -0400

      gdbsupport: make gdb_abspath return an std::string

When gdbserver receives a program name from GDB, this is first placed
into a malloc'd buffer within handle_v_run, and this buffer is then
used in this call:

  program_path.set (new_program_name);

Prior to the above commit this call took ownership of the buffer
passed to it, but now this call uses the buffer to initialise a
std::string, which copies the buffer contents, leaving ownership with
the caller.  So now, after this call (in handle_v_run)
new_program_name still owns a buffer.

At no point in handle_v_run do we free new_program_name, as a result
we are leaking the program name each time GDB starts a remote
inferior.

I could solve this by adding a 'free' call into handle_v_run, but I'd
rather automate the memory management.

So, to this end, I have added a new function in gdbserver/server.cc,
decode_v_run_arg.  This function takes care of allocating the memory
buffer and decoding the vRun packet into the buffer, but returns a
gdb::unique_xmalloc_ptr<char> (or nullptr on error).

Back in handle_v_run I have converted new_program_name to also be a
gdb::unique_xmalloc_ptr<char>.

Now, after we call program_path.set(), the allocated buffer will be
automatically released when it is no longer needed.

It is worth highlighting that within the new decode_v_run_arg
function, I have wrapped the call to hex2bin in a try/catch block.
The hex2bin function can throw an exception if it encounters an
invalid (non-hex) character.  Back in handle_v_run, we have a local
argument new_argv, which is of type std::vector<char *>.  Each
'char *' in this vector is a malloc'd buffer.  If we allow
hex2bin to throw an exception and don't catch it in either
decode_v_run_arg or handle_v_run then we are going to leak memory from
new_argv.

I chose to catch the exception in decode_v_run_arg, this seemed
cleanest, but I'm not sure it really matters, so long as the exception
is caught before we leave handle_v_run.  I am working on a patch that
changes new_argv to automatically manage its memory, but that isn't
ready for posting yet.  I think what I have here would be fine if my
follow on patch never arrives.

Additionally, within the handle_v_run loop I have changed an
assignment of nullptr to new_program_name into an assert.  Previously,
the assignment could only trigger on the first iteration of the loop,
if we had no new program name to assign.  However, new_program_name
always starts as nullptr, so, on the first loop iteration, if we have
nothing to assign to new_program_name, its value must already be
nullptr.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
12 months agogdb: make get_symbol_address a private method of symbol
Simon Marchi [Mon, 23 Oct 2023 18:05:03 +0000 (14:05 -0400)]
gdb: make get_symbol_address a private method of symbol

get_symbol_address is only used symbol::value_address, make it a private
helper method.

Change-Id: I318ddcfcf1269d95045b8efe9137812df9c5113c
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: make get_msymbol_address a private method of minimal_symbol
Simon Marchi [Mon, 23 Oct 2023 18:05:02 +0000 (14:05 -0400)]
gdb: make get_msymbol_address a private method of minimal_symbol

get_msymbol_address is only used in minimal_symbol::value_address.  Make
it a private helper method.

Change-Id: I3f30e1b9d89ace6682fb08a7ebb91746db0ccf0f
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogprofng: Fix -Wformat= warnings
Vladimir Mezentsev [Tue, 24 Oct 2023 02:55:01 +0000 (19:55 -0700)]
gprofng: Fix -Wformat= warnings

Added format attribute to several gprofng functions.
Fixed -Wformat= warnings.

gprofng/ChangeLog
2023-10-23  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* libcollector/heaptrace.c: Fixed -Wformat= warnings.
* libcollector/hwprofile.c: Likewise.
* libcollector/iolib.c: Likewise.
* libcollector/iotrace.c: Likewise.
* libcollector/jprofile.c: Likewise.
* libcollector/profile.c: Likewise.
* libcollector/synctrace.c: Likewise.
* src/ClassFile.cc: Likewise.
* src/SourceFile.cc: Likewise.
* libcollector/libcol_util.h: Added format attribute.
* src/Emsg.h: Likewise.
* src/collector_module.h: Likewise.
* src/data_pckts.h: Define fld_sizeof.

12 months agoasan: _bfd_elf_slurp_version_tables memory leak
Alan Modra [Tue, 24 Oct 2023 07:07:24 +0000 (17:37 +1030)]
asan: _bfd_elf_slurp_version_tables memory leak

Extends commit 6136093c0d00 to handle verdefs as well as verrefs.

PR 30886
* elf.c (_bfd_elf_slurp_version_tables): See free_contents for
verdefs too.  Use free_contents rather than elf_tdata fields.

12 months agoasan: out of memory in som_set_reloc_info
Alan Modra [Tue, 24 Oct 2023 04:52:00 +0000 (15:22 +1030)]
asan: out of memory in som_set_reloc_info

Sections without SEC_HAS_CONTENTS avoid the file size checks, and of
course it doesn't make sense to read such as the contents are all
zero.

* som.c (som_set_reloc_info): Don't read sections without contents.

12 months agoasan: NULL deref in alpha_ecoff_get_relocated_section_contents
Alan Modra [Tue, 24 Oct 2023 02:47:50 +0000 (13:17 +1030)]
asan: NULL deref in alpha_ecoff_get_relocated_section_contents

This fixes some holes found by fuzzers, and removes aborts that can be
triggered by user input to objdump.  Abort should only be used within
bfd to show programming errors in bfd.

* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Handle
NULL howto.  Don't abort on stack errors or on unexpected relocs.
Show more bfd reloc status messages.

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

12 months ago[gdb/cli] Add gnu-source-highlight selftest
Tom de Vries [Tue, 24 Oct 2023 12:31:34 +0000 (14:31 +0200)]
[gdb/cli] Add gnu-source-highlight selftest

Add a selftest gnu-source-highlight:
...
$ gdb -q -batch -ex "maint selftest gnu-source-highlight"
Running selftest gnu-source-highlight.
Ran 1 unit tests, 0 failed
...

Tested on x86_64-linux.

12 months ago[readelf] Handle unknown name of main in .gdb_index section
Tom de Vries [Tue, 24 Oct 2023 10:35:08 +0000 (12:35 +0200)]
[readelf] Handle unknown name of main in .gdb_index section

When compiling hello world and adding a v9 .gdb-index section:
...
$ gcc -g hello.c
$ gdb-add-index a.out
...
readelf shows it as:
...
Shortcut table:
Language of main: unknown: 0
Name of main: ^A
...

The documentation of gdb says about the "Name of main" that:
...
This value must be ignored if the value for the language of main is zero.
...

Implement this approach in display_gdb_index, such that we have instead:
...
Shortcut table:
Language of main: unknown: 0
Name of main: <unknown>
...

Tested on x86_64-linux.

Approved-By: Jan Beulich <jbeulich@suse.com>
12 months agoas: fixed internal error when immediate value of relocation overflow.
Lulu Cai [Wed, 11 Oct 2023 02:20:45 +0000 (10:20 +0800)]
as: fixed internal error when immediate value of relocation overflow.

The as and ld use _bfd_error_handler to output error messages when
checking relocation alignment and relocation overflow. However, the
abfd value passed by as to the function is NULL, resulting in an
internal error. The ld passes a non-null value to the function,
so it can output an error message normally.

12 months agoAutomatic date update in version.in
GDB Administrator [Tue, 24 Oct 2023 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

12 months ago[gdb/python] Only include gdbsupport/selftest.h if GDB_SELF_TEST
Tom de Vries [Mon, 23 Oct 2023 16:25:12 +0000 (18:25 +0200)]
[gdb/python] Only include gdbsupport/selftest.h if GDB_SELF_TEST

I noticed that gdb/python/python.c unconditionally includes
gdbsupport/selftest.h.

Make this conditional on GDB_SELF_TEST.

Tested on x86_64-linux.

12 months agogas: make .nops output visible in listing
Jan Beulich [Mon, 23 Oct 2023 08:36:36 +0000 (10:36 +0200)]
gas: make .nops output visible in listing

Due to using a different frag type (in turn due to storing data
differently), making the resulting code appear in listings requires
special handling.

12 months agox86: fold NOP testcase expectations where possible
Jan Beulich [Mon, 23 Oct 2023 08:35:35 +0000 (10:35 +0200)]
x86: fold NOP testcase expectations where possible

Like done earlier for files needing adjustment anyway, also do this for
the remaining set.

12 months agox86: fold a few of the "alternative" NOP patterns
Jan Beulich [Mon, 23 Oct 2023 08:35:11 +0000 (10:35 +0200)]
x86: fold a few of the "alternative" NOP patterns

Since named objects may not overlap, the compiler is not permitted to do
this for us, to avoid wasting space and cache bandwidth/capacity.

12 months agox86: add a few more NOP patterns
Jan Beulich [Mon, 23 Oct 2023 08:34:11 +0000 (10:34 +0200)]
x86: add a few more NOP patterns

First of all add f32_5[], allowing to eliminate the extra slot-is-NULL
code from i386_output_nops(). Plus then introduce f32_8[] and f16_5[]
following the same concept of adding a %cs segment override prefix.

Also re-use patterns when possible and correct comments as applicable.
Similarly re-use testcase expectations as much as possible, where they
need touching anyway.

12 months agox86: don't record full i386_cpu_flags in struct i386_tc_frag_data
Jan Beulich [Mon, 23 Oct 2023 08:33:25 +0000 (10:33 +0200)]
x86: don't record full i386_cpu_flags in struct i386_tc_frag_data

We only use a single bit of this ever growing structure.

12 months agox86: i686 != PentiumPro
Jan Beulich [Mon, 23 Oct 2023 08:33:02 +0000 (10:33 +0200)]
x86: i686 != PentiumPro

The two are distinct in opcodes/, distinguished precisely by CpuNOP
that's relevant in i386_generate_nops(), yet the function has the PPro
case label in the other group. Simply removing it revealed that
cpu_arch[] had a wrong entry for i686.

While there also add PROCESSOR_IAMCU to the respective comment.

12 months agox86: respect ".arch nonop" when selecting which NOPs to emit
Jan Beulich [Mon, 23 Oct 2023 08:32:32 +0000 (10:32 +0200)]
x86: respect ".arch nonop" when selecting which NOPs to emit

Making GENERIC64 a special case was never correct; prior to the
generalization of ".arch .no*" to cover all ISA extensions other
processor families supporting long NOPs should have been covered as
well. When introducing ".arch .nonops" (among others) it wasn't
apparent that a hidden implication of .cpunop not being possible to
separately turn off existed here. Seeing that the two large case label
blocks in the 2nd switch() already had identical behavior, simply
collapse all of the (useful) case labels into a single "default" one.

12 months agox86: don't use operand size override with NOP in 16-bit code
Jan Beulich [Mon, 23 Oct 2023 08:30:55 +0000 (10:30 +0200)]
x86: don't use operand size override with NOP in 16-bit code

Since we don't key the NOP selection to user-controlled properties, we
may not use i386 features; otherwise we would violate a possible .arch
directive restricting ISA to pre-386.

12 months agox86: don't use 32-bit LEA as NOP surrogate in 64-bit code
Jan Beulich [Mon, 23 Oct 2023 08:30:30 +0000 (10:30 +0200)]
x86: don't use 32-bit LEA as NOP surrogate in 64-bit code

Except for the shared 1- and 2-byte cases, the LEA uses corrupt %rsi
(by zero-extending %esi to %rsi). Introduce separate 64-bit patterns
which keep %rsi intact.

12 months agox86: i386_generate_nops() may not derive decisions from global variables
Jan Beulich [Mon, 23 Oct 2023 08:29:54 +0000 (10:29 +0200)]
x86: i386_generate_nops() may not derive decisions from global variables

What matters is what was in effect at the time the original directive
was issued. Later changes to global state (bitness or ISA) must not
affect what code is generated.

12 months agox86: record flag_code in tc_frag_data
Jan Beulich [Mon, 23 Oct 2023 08:28:44 +0000 (10:28 +0200)]
x86: record flag_code in tc_frag_data

The recorded value, and not the global variable, will want using in
TC_FRAG_INIT(). The so far file scope variable therefore needs to become
external, to be accessible there.

12 months agoobjcopy: fix typo in --heap and --stack parser
Clément Chigot [Tue, 17 Oct 2023 12:57:25 +0000 (14:57 +0200)]
objcopy: fix typo in --heap and --stack parser

The help says that <reserve> and <commit> should be separated by a ","
but the implementation is checking for ".". Having two numbers being
separated by a "." could be confusing, thus adjust the implementation to
match the help syntax.

binutils/ChangeLog:

* objcopy.c (copy_main): Set separator to "," between <reserve>
and <commit> for --heap and --stack.
* doc/binutils.texi: Add <commit> for --heap and --stack.

13 months agoAutomatic date update in version.in
GDB Administrator [Mon, 23 Oct 2023 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agobfd-in2.h BFD_RELOC_* comments
Alan Modra [Sat, 21 Oct 2023 07:24:59 +0000 (17:54 +1030)]
bfd-in2.h BFD_RELOC_* comments

I noticed the regenerated BFD_RELOC_MICROBLAZE_32_NONE comment didn't
match that committed to bfd-in2.h, and was just going to regen
bfd-in2.h but then decided to do something about the silly formatting
of these comments in bfd-in2.h.  eg. the BFD_RELOC_MICROBLAZE_32_NONE
comment:

-/* This is a 32 bit reloc that stores the 32 bit pc relative
-value in two words (with an imm instruction).No relocation is
-done here - only used for relaxing  */
+  /* This is a 32 bit reloc that stores the 32 bit pc relative value in
+     two words (with an imm instruction).  No relocation is done here -
+     only used for relaxing.  */
   BFD_RELOC_MICROBLAZE_32_NONE,

You'll notice how the second and third line of the original comment
aren't indented properly relative to the first line, and the whole
comment needs to be indented to match the code.

I've also edited reloc.c ENUMDOC paragraphs.  Some of these had excess
indentation, presumably in an attempt to properly indent bfd-in2.h
comments but that fails due to chew.c removing leading whitespace
early by skip_white_and_stars.  COMMENT was used in reloc.c to add
extra blank lines in bfd-in2.h.  I've removed them too as I don't
think they add anything to readability of that file.  (Perhaps more
usefully, they also add blank lines to libbfd.h separating relocs for
one target from others, but this isn't done consistently.)

* doc/chew.c (drop, idrop): Move earlier.
(strip_trailing_newlines): Check index before accessing array,
not after.
(wrap_comment): New function.
(main): Add "wrap_comment" intrinsic.
* doc/proto.str (ENUMDOC): Use wrap_comment.
(make_enum_header, ENDSENUM): Put start and end braces on
separate lines.
* reloc.c: Remove uses of COMMENT and edit ENUMDOC paragraphs.
* libbfd.h: Regenerate.
* bfd-in2.h: Regenerate.

13 months agoStyle history variable output
Tom Tromey [Mon, 12 Jun 2023 23:10:14 +0000 (17:10 -0600)]
Style history variable output

When printing a value, I think the history reference -- the "$1" in
the output -- should be styled using the "variable" style.  This patch
implements this.

13 months agoAutomatic date update in version.in
GDB Administrator [Sun, 22 Oct 2023 00:00:08 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agogdb: fix owner passed to remove_target_sections in clear_solib
Simon Marchi [Thu, 19 Oct 2023 20:40:52 +0000 (20:40 +0000)]
gdb: fix owner passed to remove_target_sections in clear_solib

Commit 8971d2788e7 ("gdb: link so_list using intrusive_list") introduced
a bug in clear_solib.  Instead of passing an `so_list *` to
remove_target_sections, it passed an `so_list **`.  This was not caught
by the compiler, because remove_target_sections takes a `void *` as the
"owner", so you can pass it any pointer and it won't complain.

This happened because I previously had a patch to change the type of the
disposer parameter to be a reference rather than a pointer, so had to
change `so` to `&so`.  When dropping that patch, I forgot to revert this
bit and / or it got re-introduced when handling subsequent merge
conflicts.  And I didn't properly retest.

Fix that, but try to make things less error prone.  Add a union to
represent the possible owner kinds for a target_section.  Trying to pass
a pointer to another type than those will not compile.

Change-Id: I600cab5ea0408ccc5638467b760768161ca3036c

13 months agoAutomatic date update in version.in
GDB Administrator [Sat, 21 Oct 2023 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months ago[gdb/cli] Allow source-highlight to autodetect language
Tom de Vries [Fri, 20 Oct 2023 20:23:13 +0000 (22:23 +0200)]
[gdb/cli] Allow source-highlight to autodetect language

Currently when gdb asks the source-highlight library to highlight a file, it
tells it what language file to use.

For instance, if gdb learns from the debug info that the file is language_c,
the language file "c.lang" is used.  This mapping is hardcoded in
get_language_name.

However, if gdb doesn't know what language file to use, it falls back to using
python pygments, and in absence of that, unhighlighted source text.

In the case of python pygments, it autodetects which language to use based on
the file name.

Add the same capability when using the source-highlight library.

Tested on x86_64-linux.

Verified that it works by:
- making get_language_name return nullptr for language_c, and
- checking that source-highlight still manages to highlight a hello world.

Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
PR cli/30966
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30966

13 months agoDon't include cooked-index.h from dwarf2/read.h
Tom Tromey [Thu, 23 Mar 2023 02:47:36 +0000 (20:47 -0600)]
Don't include cooked-index.h from dwarf2/read.h

dwarf2/read.h includes cooked-index.h, but it doesn't need to.  This
patch removes the inclusion from this header, and adds one to
index-write.c to make up for the absence.

13 months agogas: testsuite: microblaze: cosmetic fix
Neal Frager [Fri, 20 Oct 2023 14:26:54 +0000 (15:26 +0100)]
gas: testsuite: microblaze: cosmetic fix

This patch makes a cosmetic change to the reloc_weaksym.s
by making the bneid instruction all lower case like all of
the other instructions in the example.

Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
13 months agolibctf: fix creation-time parent/child dict confusions
Nick Alcock [Wed, 18 Oct 2023 17:34:57 +0000 (18:34 +0100)]
libctf: fix creation-time parent/child dict confusions

The fixes applied a few years ago to resolve confusions between parent and
child dicts at lookup time also apply in various forms to creation.  In
general, if you have a type in a parent dict ctf_imported into a child and
you do something to it, and the parent dict is writable (created via
ctf_create, not opened via ctf_open*) it should work just the same to make
changes to that type via a child dict as it does to make the change
to the parent dict directly -- and nothing you're prohibited from doing
to the parent dict when done directly should be allowed just because
you're doing it via a child.

Specifically, the following don't work when doing things from the child, but
should:

 - adding a member of a type in the parent to a struct or union in the
   parent via ctf_add_member or ctf_add_member_offset: this yields
   ECTF_BADID

 - adding a member of a type in the parent to a struct or union in the
   parent via ctf_add_member_encoded: this dumps core (!).

 - adding an enumerand to an enumerator in the parent: this yields
   ECTF_BADID

 - setting the properties of an array in the parent via ctf_set_array;
   this yields ECTF_BADID

Relatedly, some things work when doing things via a child that should fail,
yielding a CTF dictionary with invalid content (readable, but meaningless):
in particular, you can add a child type to a struct in the parent via
any of the ctf_add_member* family and nothing complains at all, even though
you should never be able to add references to children to parents (since any
given parent can be associated with many different children).

A family of tests is added to check each of these cases independently, since
some can result in coredumps and it would be nice to test the other cases
even if some dump core.  They use a common library to do all the actual
work.  The set of affected API calls was determined by code inspection
(auditing all calls to ctf_dtd_lookup): it's possible that I missed a few,
but I doubt it, since other cases use ctf_lookup* functions, which already
climb to the parent where appropriate.

libctf/ChangeLog:

PR libctf/30985
* ctf-create.c (ctf_dtd_lookup): Traverse to parents if necessary.
(ctf_set_array): Likewise.  Report errors on the child; require
both parent and child to be writable.
(ctf_add_enumerator): Likewise.
(ctf_add_member_offset): Likewise.  Prohibit addition of child types
to structs in the parent.
(ctf_add_member_encoded): Do not dereference a NULL dtd: report
ECTF_BADID instead.
* ctf-string.c (ctf_str_add_ref_internal): Report ENOMEM on the
dict if addition of a string ref fails.
* testsuite/libctf-writable/parent-child-dtd-crash-lib.c: New library.
* testsuite/libctf-writable/parent-child-dtd-enum.*: New test.
* testsuite/libctf-writable/parent-child-dtd-enumerator.*: New test.
* testsuite/libctf-writable/parent-child-dtd-member-encoded.*: New test.
* testsuite/libctf-writable/parent-child-dtd-member-offset.*: New test.
* testsuite/libctf-writable/parent-child-dtd-set-array.*: New test.
* testsuite/libctf-writable/parent-child-dtd-struct.*: New test.
* testsuite/libctf-writable/parent-child-dtd-union.*: New test.

13 months agobfd: microblaze: Add 32_NONE reloc type
Neal Frager [Tue, 17 Oct 2023 08:40:06 +0000 (09:40 +0100)]
bfd: microblaze: Add 32_NONE reloc type

This patch adds the R_MICROBLAZE_32_NONE relocation type.
This is a 32-bit reloc that stores the 32-bit pc relative
value in two words (with an imm instruction).

Add test case to gas test suite.

Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
13 months ago[gdb/symtab] Fix more style issues in v9 .gdb_index section support
Tom de Vries [Fri, 20 Oct 2023 09:56:49 +0000 (11:56 +0200)]
[gdb/symtab] Fix more style issues in v9 .gdb_index section support

I noticed a few more style issues in commit 8b9c08eddac ("[gdb/symtab] Add
name_of_main and language_of_main to the DWARF index"), after checking it
with gcc's check_GNU_style.{sh,py}.

Fix these.

Build on x86_64-linux.

13 months agoopcodes: microblaze: Fix bit masking bug
Neal Frager [Thu, 19 Oct 2023 11:37:40 +0000 (12:37 +0100)]
opcodes: microblaze: Fix bit masking bug

There is currently a bug in the bit masking for the barrel shift
instructions because the bit mask is not including all of the
register bits which must be zero.  With this patch, the disassembler
can be sure that the 32-bit value is indeed a barrel shift instruction
and not a data value in memory.

This fix can be verified by assembling and disassembling the following:

.text
.long 0x65005f5f

With this patch, the bug is fixed, and the objdump will know that
0x65005f5f is not a barrel shift instruction.

Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
13 months agoAutomatic date update in version.in
GDB Administrator [Fri, 20 Oct 2023 00:00:11 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoFix race in DWARF reader
Tom Tromey [Tue, 17 Oct 2023 20:32:26 +0000 (14:32 -0600)]
Fix race in DWARF reader

The recent change to record the DWARF language in the per-CU data
yielded a race warning in my testing:

ThreadSanitizer: data race ../../binutils-gdb/gdb/dwarf2/read.c:21779 in prepare_one_comp_unit

This patch fixes the bug by applying the same style of fix that was
done for the ordinary (gdb) language.

I wonder if this code could be improved.  Requiring an atomic for the
language in particular seems unfortunate, as it is often consulted
during index finalization.  However, I haven't investigated this.

Regression tested on x86-64 Fedora 38.

Reviewed-by: Tom de Vries <tdevries@suse.de>
13 months agoPR30984, assertion fail elf.c:8485
Alan Modra [Thu, 19 Oct 2023 22:21:20 +0000 (08:51 +1030)]
PR30984, assertion fail elf.c:8485

PR 30984
* ldelf.c (ldelf_place_orphan): Don't allow bfd_abs_section as
a potential output section.

13 months agogdb: fix no-expat build of solib-target.c
Simon Marchi [Thu, 19 Oct 2023 20:17:34 +0000 (20:17 +0000)]
gdb: fix no-expat build of solib-target.c

Fixes:

      CXX    solib-target.o
    /home/smarchi/src/binutils-gdb/gdb/solib-target.c:57:8: error: ‘lm_info_vector’ does not name a type
       57 | static lm_info_vector
          |        ^~~~~~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/solib-target.c: In function ‘intrusive_list<shobj> solib_target_current_sos()’:
    /home/smarchi/src/binutils-gdb/gdb/solib-target.c:244:7: error: ‘solib_target_parse_libraries’ was not declared in this scope
      244 |     = solib_target_parse_libraries (library_document->data ());
          |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: Ib477d3343b401017d79729118242143bc95f24b2

13 months agold: fix typo in ld.texi metdata->metadata
Jose E. Marchesi [Thu, 19 Oct 2023 19:53:57 +0000 (21:53 +0200)]
ld: fix typo in ld.texi metdata->metadata

13 months agogdb: rename struct so_list to shobj
Simon Marchi [Tue, 17 Oct 2023 19:37:58 +0000 (15:37 -0400)]
gdb: rename struct so_list to shobj

Now that so_list lists are implemented using intrusive_list, it doesn't
really make sense for the element type to be named "_list".  Rename to
just `struct shobj` (`struct so` was deemed to be not greppable enough).

Change-Id: I1063061901298bb40fee73bf0cce44cd12154c0e
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: remove free_so function
Simon Marchi [Tue, 10 Oct 2023 16:32:42 +0000 (16:32 +0000)]
gdb: remove free_so function

Remove this function, replace it with deleting the so_list in callers.

Change-Id: Idbd0cb84674ade1d8e17af471550dbd388264f60
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: don't call so_list::clear in free_so
Simon Marchi [Tue, 10 Oct 2023 16:28:03 +0000 (16:28 +0000)]
gdb: don't call so_list::clear in free_so

I think this `so.clear ()` call is not useful.

 - so_list::clear deletes some things that now get automatically deleted
   when the so_list gets deleted right after in free_so.
 - so_list::clear resets some scalar fields of so_list, which we don't
   really care about since the so_list gets deleted right after.
 - so_list::clear calls target_so_ops::clear_so, of which there is a
   single implementation, svr4_clear_so.  That implementation just
   resets a field in lm_info_svr4, which we don't care about, as it will
   get deleted when the so_list gets deleted right after.

Change-Id: Ie4d72f2a04a4129e55c460bb5c69bc0af0d12b32
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: link so_list using intrusive_list
Simon Marchi [Thu, 19 Oct 2023 14:55:38 +0000 (10:55 -0400)]
gdb: link so_list using intrusive_list

Replace the hand-made linked list implementation with intrusive_list,
simplying management of list items.

Change-Id: I7f55fd88325bb197cc655c9be5a2ec966d8cc48d
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make so_list::{so_original_name,so_name} std::strings
Simon Marchi [Sun, 8 Oct 2023 01:16:29 +0000 (01:16 +0000)]
gdb: make so_list::{so_original_name,so_name} std::strings

Change these two fields, simplifying memory management and copying.

Change-Id: If2559284c515721e71e1ef56ada8b64667eebe55
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make so_list::abfd a gdb_bfd_ref_ptr
Simon Marchi [Tue, 10 Oct 2023 16:01:08 +0000 (16:01 +0000)]
gdb: make so_list::abfd a gdb_bfd_ref_ptr

Change the field from a `bfd *` to a gdb_bfd_ref_ptr to automatically
manage the reference.

Change-Id: I3ace18bea985bc194c5e67bb559eec567e258950
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make so_list::sections not a pointer
Simon Marchi [Tue, 10 Oct 2023 15:59:57 +0000 (15:59 +0000)]
gdb: make so_list::sections not a pointer

Make the field a vector directly, instead of a pointer to a vector.
This was needed when so_list had to be a trivial type, which is not the
case anymore.

Change-Id: I79a8378ce0d0d1e2206ca08a273ebf332cb3ba14
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: remove target_section_table typedef
Simon Marchi [Tue, 10 Oct 2023 15:47:41 +0000 (15:47 +0000)]
gdb: remove target_section_table typedef

Remove this typedef.  I think that hiding the real type (std::vector)
behind a typedef just hinders readability.

Change-Id: I80949da3392f60a2826c56c268e0ec6f503ad79f
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make clear_so a method of struct so_list
Simon Marchi [Mon, 2 Oct 2023 20:31:04 +0000 (16:31 -0400)]
gdb: make clear_so a method of struct so_list

... just because it seems to make sense to do so.

Change-Id: Ie283c92d9b90c54e3deee96a43c6a942d8b5910b
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make so_list::lm_info a unique_ptr
Simon Marchi [Tue, 10 Oct 2023 18:47:13 +0000 (14:47 -0400)]
gdb: make so_list::lm_info a unique_ptr

Make it a unique_ptr, so it gets automatically deleted when the so_list
is deleted.

Change-Id: Ib62d60ae2a80656239860b80e4359121c93da13d
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: remove lm_info_vector typedef
Simon Marchi [Tue, 10 Oct 2023 18:56:11 +0000 (14:56 -0400)]
gdb: remove lm_info_vector typedef

I think this typedef hinders readability.  First, it's not well named
(it's not clear it contains lm_info_target objects).  And hiding the
fact that it contains unique pointers is not very useful either.  I was
looking at the code in solib_target_current_sos where the unique
pointers get moved from the vector, and it wasn't obvious at all what
the source of the move was.

Change-Id: I4a5cda7c90554f018b7c466b1535b41d69cbcbe7
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make solib-rocm not use so_list internally
Simon Marchi [Thu, 5 Oct 2023 20:43:20 +0000 (20:43 +0000)]
gdb: make solib-rocm not use so_list internally

Same rationale as the previous patch, but for solib-rocm.

 - Introduce rocm_so, which is a name a unique_name (see comment in
   rocm_update_solib_list for that) and a unique_ptr to the
   lm_info_svr4.
 - Change the internal lists from so_list lists to vectors of rocm_so.
 - Remove rocm_free_solib_list, as everything is automatic now.
 - Replace rocm_solib_copy_list with so_list_from_rocm_sos.

Change-Id: I71e06e3ea22d6420c9e4e500501c06e9a13398a8
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make solib-svr4 not use so_list internally
Simon Marchi [Tue, 10 Oct 2023 18:45:05 +0000 (14:45 -0400)]
gdb: make solib-svr4 not use so_list internally

A subsequent patch makes use of non-trivial types in struct so_list.
This trips on the fact that svr4_copy_library_list uses memcpy to copy
so_list objects:

      so_list *newobj = new so_list;
      memcpy (newobj, src, sizeof (struct so_list));

solib-svr4 maintains lists of so_list objects in its own internal data
structures.  When requested to return a list of so_list objects (through
target_so_ops::current_sos), it duplicates the internal so_list lists,
using memcpy.  When changing so_list to make it non-trivial, we would
need to replace this use of memcpy somehow.  That would mean making
so_list copyable, with all the complexity that entails, just to satisfy
this internal usage of solib-svr4 (and solib-rocm, which does the same).

Change solib-svr4 to use its own data type for its internal lists.  The
use of so_list is a bit overkill anyway, as most fields of so_list are
irrelevant for this internal use.

 - Introduce svr4_so, which contains just an std::string for the name
   and a unique_ptr for the lm_info.
 - Change the internal so_list lists to be std::vector<svr4_so>.  Vector
   seems like a good choice for this, we don't need to insert/remove
   elements in the middle of these internal lists.
 - Remove svr4_free_library_list, free_solib_lists and ~svr4_info, as
   everything is managed automatically now.
 - Replace svr4_copy_library_list (which duplicated internal lists in
   order to return them to the core) with so_list_from_svr4_sos, which
   creates an so_list list from a vector of svr4_so.
 - Generalize svr4_same a bit, because find_debug_base_for_solib now
   needs to compare an so_list and an svr4_so to see if they are the
   same.

Change-Id: I6012e48e07aace2a8172b74b389f9547ce777877
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: use gdb::checked_static_cast when casting lm_info
Simon Marchi [Tue, 10 Oct 2023 18:03:18 +0000 (14:03 -0400)]
gdb: use gdb::checked_static_cast when casting lm_info

Now that the lm_info class hierarchy has a virtual destructor and
therefore a vtable, use checked_static_cast instead of C-style cases to
ensure (when building in dev mode) that we're casting to the right kind
of lm_info.

Change-Id: I9a99b7d6aa9a44edbe76377d57a7008cfb75a744
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: remove target_so_ops::free_so
Simon Marchi [Mon, 2 Oct 2023 20:00:55 +0000 (16:00 -0400)]
gdb: remove target_so_ops::free_so

target_so_ops::free_so is responsible for freeing the specific lm_info
object.  All implementations basically just call delete.  Remove that
method, make the destructor of lm_info virtual, and call delete directly
from the free_so function.  Make the sub-classes final, just because
it's good practice.

Change-Id: Iee1fd4861c75034a9e41a656add8ed8dfd8964ee
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: rename lm_info_base to lm_info
Simon Marchi [Mon, 2 Oct 2023 19:57:46 +0000 (15:57 -0400)]
gdb: rename lm_info_base to lm_info

The base class doesn't need to have "_base" in its name, all the
sub-classes have a specific suffix.

Change-Id: I87652105cfedd87898770a81f0eda343ff7f2bdb
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: allocate so_list with new, deallocate with delete
Simon Marchi [Mon, 2 Oct 2023 19:17:04 +0000 (15:17 -0400)]
gdb: allocate so_list with new, deallocate with delete

Initialize all fields in the class declaration, change allocations to
use "new", change deallocations to use "delete".  This is needed by a
subsequent patches that use C++ stuff in so_list.

Change-Id: I4b140d9f1ec9ff809554a056f76e3eb2b9e23222
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make get_cbfd_soname_build_id static
Simon Marchi [Mon, 2 Oct 2023 19:41:34 +0000 (15:41 -0400)]
gdb: make get_cbfd_soname_build_id static

It is only used in solib.c.

Change-Id: I43461d13d84d65c4f6913d4033678d8983b9910b
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdbsupport: use "reference" and "pointer" type aliases in intrusive_list
Simon Marchi [Mon, 2 Oct 2023 16:50:32 +0000 (12:50 -0400)]
gdbsupport: use "reference" and "pointer" type aliases in intrusive_list

It seems to me like the code should used the defined type aliases, for
consistency.

Change-Id: Ib52493ff18ad29464405275bc10a0c6704ed39e9
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: replace some so_list parameters to use references
Simon Marchi [Sat, 30 Sep 2023 02:59:22 +0000 (22:59 -0400)]
gdb: replace some so_list parameters to use references

A subsequent patch changes so_list to be linked using
intrusive_list.  Iterating an intrusive_list yields some references to
the list elements.  Convert some functions accepting so_list objects to
take references, to make things easier and more natural.  Add const
where possible and convenient.

Change-Id: Id5ab5339c3eb6432e809ad14782952d6a45806f3
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: make interps_notify work with references
Simon Marchi [Sat, 30 Sep 2023 02:36:23 +0000 (22:36 -0400)]
gdb: make interps_notify work with references

A subsequent patch changes the interp::on_solib_loaded and
interp::on_solib_unloaded methods to take references.  This highlighted
that interps_notify did not work with reference parameters.

Fix that by changing interps_notify's `args` arg to be a universal
reference (&&).  Change the type of the method to be auto-deduced as an
additional template parameter, otherwise the signature of the callback
function would never match:

      CXX    interps.o
    /home/simark/src/binutils-gdb/gdb/interps.c: In function ‘void interps_notify_signal_received(gdb_signal)’:
    /home/simark/src/binutils-gdb/gdb/interps.c:378:18: error: no matching function for call to ‘interps_notify(void (interp::*)(gdb_signal), gdb_signal&)’
      378 |   interps_notify (&interp::on_signal_received, sig);
          |   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/binutils-gdb/gdb/interps.c:363:1: note: candidate: ‘template<class ... Args> void interps_notify(void (interp::*)(Args ...), Args&& ...)’
      363 | interps_notify (void (interp::*method) (Args...), Args&&... args)
          | ^~~~~~~~~~~~~~
    /home/simark/src/binutils-gdb/gdb/interps.c:363:1: note:   template argument deduction/substitution failed:
    /home/simark/src/binutils-gdb/gdb/interps.c:378:18: note:   inconsistent parameter pack deduction with ‘gdb_signal’ and ‘gdb_signal&’
      378 |   interps_notify (&interp::on_signal_received, sig);
          |   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I0cd9378e24ef039f30f8e14f054f8d7fb539c838
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: add program_space parameter to target_so_ops::clear_solib
Simon Marchi [Mon, 2 Oct 2023 18:46:18 +0000 (14:46 -0400)]
gdb: add program_space parameter to target_so_ops::clear_solib

The clear_solib is implicitly meant to clear the resources associated to
the current program space (that's what the solib implementations that
actually support multi-program-space / multi-inferior do).  Make that
explicit by adding a program_space parameter and pass down
current_program_space in call sites.  The implementation of the
clear_solib callbacks is fairly simple, I don't think any of them rely
on global state other than accessing current_program_space.

Change-Id: I8d0cc4db7b4f8db8d7452879c0c62db03269bf46
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agogdb: remove empty clear_solib functions
Simon Marchi [Mon, 2 Oct 2023 18:52:09 +0000 (14:52 -0400)]
gdb: remove empty clear_solib functions

Make the target_so_ops::clear_solib method optional, remove two empty
implementations.

Change-Id: Ifda297d50c74327d337091c58cdb5b3b60382591
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agoRISC-V: Don't do undefweak relaxations for the linker_def symbols.
Nelson Chu [Thu, 19 Oct 2023 04:10:42 +0000 (12:10 +0800)]
RISC-V: Don't do undefweak relaxations for the linker_def symbols.

I get the following truncated errors recently when running riscv-gnu-toolchain
regressions,

/scratch/riscv-gnu-toolchain/regression/build/linux-rv32imafdc-ilp32d-medlow/build-glibc-linux-rv32imafdc-ilp32d/libc.a(libc-start.o): in function `elf_irela':
/scratch/riscv-gnu-toolchain/glibc/csu/../sysdeps/riscv/dl-irel.h:47:(.text+0x88): relocation truncated to fit: R_RISCV_GPREL_I against symbol `__ehdr_start' defined in .note.ABI-tag section in /scratch/riscv-gnu-toolchain/regression/build/linux-rv32imafdc-ilp32d-medlow/build-glibc-linux-rv32imafdc-ilp32d/elf/sln

The linker_def symbols like __ehdr_start that may be undefweak in early stages
of linking, including relax stage, but are guaranteed to be defined later.
Therefore, it seems like we shouldn't do the undefweak relaxations for these
kinds of symbols since they may be defined after relaxations.

bfd/
* elfnn-riscv.c (_bfd_riscv_relax_section): Don't do undefweak
relaxations for the linker_def symbols.

13 months agoRISC-V: Remove semicolons from DECLARE_INSN
Tsukasa OI [Thu, 19 Oct 2023 00:58:36 +0000 (00:58 +0000)]
RISC-V: Remove semicolons from DECLARE_INSN

This is for consistency and to prevent possible unnecessary errors due
to this inconsistency.

include/ChangeLog:

* opcode/riscv-opc.h (DECLARE_INSN): Remove semicolons from the
end of each entry.

13 months agoAutomatic date update in version.in
GDB Administrator [Thu, 19 Oct 2023 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agogdb/testsuite/gdb.rocm: Fix incorrect use of continue N in multi-inferior-gpu.exp
Lancelot Six [Wed, 18 Oct 2023 10:24:53 +0000 (10:24 +0000)]
gdb/testsuite/gdb.rocm: Fix incorrect use of continue N in multi-inferior-gpu.exp

The gdb.rocm/multi-inferior-gpu.exp testcase uses a "continue $thread"
command, but this is incorrect.  If "continue" is given an argument, it
sets the ignore count of the breakpoint the thread stopped at.

For this testcase it does not really matter since the breakpoint is not
meant to be hit anymore, so whatever the ignore count is won't influence
the outcome of the test.  It is worth fixing nevertheless.

Change-Id: I0eb674d5529cdeb9e808b74870a29b6077265737
Approved-By: Simon Marchi <simon.marchi@efficios.com>
13 months agosim/riscv: fix JALR instruction simulation
Jaydeep Patil [Wed, 18 Oct 2023 16:37:59 +0000 (17:37 +0100)]
sim/riscv: fix JALR instruction simulation

Fix 32bit 'jalr rd,ra,imm' integer instruction, where RD was written
before using it to calculate destination address.

This commit also improves testutils.inc for riscv; make use of
pushsection and popsection when adding things to .data, and setup the
%gp global pointer register within the 'start' macro.

Approved-By: Andrew Burgess <aburgess@redhat.com>
13 months agolibctf: check for problems with error returns
Nick Alcock [Wed, 11 Oct 2023 14:15:16 +0000 (15:15 +0100)]
libctf: check for problems with error returns

We do this as a writable test because the only known-affected platforms
(with ssize_t longer than unsigned long) use PE, and we do not have support
for CTF linkage in the PE linker yet.

PR libctf/30836
* libctf/testsuite/libctf-writable/libctf-errors.*: New test.

13 months agogdb/testsuite/gdb.rocm: Check value returned by hipDeviceSynchronize
Lancelot Six [Tue, 17 Oct 2023 15:45:45 +0000 (15:45 +0000)]
gdb/testsuite/gdb.rocm: Check value returned by hipDeviceSynchronize

Functions of the hip runtime returning a hipError_t can be marked
nodiscard depending on the configuration[1] (when compiled with C++17).

This patch makes sure that we always check the value returned by
hipDeviceSynchronize and friends, and print an error message when
appropriate.  This avoid a wall of warnings when running the testsuite
if the compiler defaults to using C++17.

It is always a good practice to check the return values anyway.

[1] https://github.com/ROCm-Developer-Tools/HIP/blob/docs/5.7.1/include/hip/hip_runtime_api.h#L203-L218

Change-Id: I2a819a8ac45f4bcf814efe9a2ff12c6a7ad22f97
Approved-By: Simon Marchi <simon.marchi@efficios.com>
13 months agolibctf: Return CTF_ERR in ctf_type_resolve_unsliced PR 30836
Torbjörn SVENSSON [Tue, 17 Oct 2023 18:36:50 +0000 (20:36 +0200)]
libctf: Return CTF_ERR in ctf_type_resolve_unsliced PR 30836

In commit 998a4f589d68503f79695f180fdf1742eeb0a39d, all but one return
statement was updated to return the error proper value. This commit
rectifies that missed return statement.

libctf/
ctf-types.c (ctf_type_resolve_unsliced): Return CTF_ERR on error.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
13 months ago[gdb/testsuite] Fix gdb.base/jit-bfd-name.exp
Tom de Vries [Wed, 18 Oct 2023 06:26:20 +0000 (08:26 +0200)]
[gdb/testsuite] Fix gdb.base/jit-bfd-name.exp

When running test-case gdb.base/jit-bfd-name.exp, I run into:
...
ERROR: tcl error sourcing gdb/testsuite/gdb.base/jit-bfd-name.exp.
ERROR: can't read "start": no such variable
...

The problem is that commit c96ceed9dce ("gdb: include the end address in
in-memory bfd filenames") introduced a use of variable start, but not a
definition.

Fix this by adding the missing definition.

Tested on x86_64-linux.

13 months ago[gdb/symtab] Fix two style issues in gdb/dwarf2/index-write.c
Tom de Vries [Wed, 18 Oct 2023 05:45:39 +0000 (07:45 +0200)]
[gdb/symtab] Fix two style issues in gdb/dwarf2/index-write.c

While reviewing gdb/dwarf2/index-write.c I noticed two style issues.

Fix these.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
13 months ago[gdb/symtab] Fix style issues in v9 .gdb_index section support
Tom de Vries [Wed, 18 Oct 2023 05:45:39 +0000 (07:45 +0200)]
[gdb/symtab] Fix style issues in v9 .gdb_index section support

Post-commit review pointed out a few style issues in commit 8b9c08eddac
("[gdb/symtab] Add name_of_main and language_of_main to the DWARF index").

Fix these.

Tested on x86_64-linux.

Reported-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
13 months agoRISC-V: Make sure rv32q conflict won't affect the zfa gas testcases.
Nelson Chu [Wed, 18 Oct 2023 00:45:28 +0000 (08:45 +0800)]
RISC-V: Make sure rv32q conflict won't affect the zfa gas testcases.

According to the commit 51498ab9abc6, the q extension was no longer allowed
for rv32 since version 2.2.  Therefore, make sure the version of q is larger
than 2.2, in case the new extension conflict breaks the toolchain regressions,
which built with the old -misa-spec.

gas/
* testsuite/gas/riscv/zfa-zvfh.d: Set q to v2.2.
* testsuite/gas/riscv/zfa.d: Likewise.

13 months agoLoongArch: Correct comments.
caiyinyu [Tue, 17 Oct 2023 12:58:40 +0000 (20:58 +0800)]
LoongArch: Correct comments.

13 months agoAutomatic date update in version.in
GDB Administrator [Wed, 18 Oct 2023 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agogas: testsuite: microblaze: Add new bit-field tests
Neal Frager [Fri, 13 Oct 2023 07:28:56 +0000 (08:28 +0100)]
gas: testsuite: microblaze: Add new bit-field tests

This patch adds new gas tests for the
microblaze bsefi and bsifi instructions.

Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
13 months agogdb: include the end address in in-memory bfd filenames
Markus Metzger [Tue, 9 May 2023 10:39:07 +0000 (10:39 +0000)]
gdb: include the end address in in-memory bfd filenames

Commit

    66984afd29e gdb: include the base address in in-memory bfd filenames

added the base address to in-memory bfd filenames.  Also add the end
address to allow dumping the in-memory bfd using the 'dump memory'
command.

13 months agolibctf: Sanitize error types for PR 30836
Torbjörn SVENSSON [Wed, 13 Sep 2023 09:02:36 +0000 (11:02 +0200)]
libctf: Sanitize error types for PR 30836

Made sure there is no implicit conversion between signed and unsigned
return value for functions setting the ctf_errno value.
An example of the problem is that in ctf_member_next, the "offset" value
is either 0L or (ctf_id_t)-1L, but it should have been 0L or -1L.
The issue was discovered while building a 64 bit ld binary to be
executed on the Windows platform.
Example object file that demonstrates the issue is attached in the PR.

libctf/
Affected functions adjusted.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
13 months agoUpdate the documentation of the LINKER_VERSIOn script command to actually mention...
Nick Clifton [Tue, 17 Oct 2023 09:42:44 +0000 (10:42 +0100)]
Update the documentation of the LINKER_VERSIOn script command to actually mention the name of the command.

13 months ago[gdb/cli] Keep track of styling failures in source_cache
Tom de Vries [Tue, 17 Oct 2023 09:38:06 +0000 (11:38 +0200)]
[gdb/cli] Keep track of styling failures in source_cache

In source_cache::ensure, keep track of which files failed to be styled, and
don't attempt to style them again in case the file dropped out of the cache.

Tested on x86_64-linux.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months ago[gdb/cli] Factor out try_source_highlight
Tom de Vries [Tue, 17 Oct 2023 09:38:06 +0000 (11:38 +0200)]
[gdb/cli] Factor out try_source_highlight

Function source_cache::ensure contains some code using the GNU
source-highlight library.

The code is a sizable part of the function, and contains conditional
compilation in a slightly convoluted way:
...
       if (!already_styled)
 #endif /* HAVE_SOURCE_HIGHLIGHT */
       {
...

Fix this by factoring out the code into new function try_source_highlight,
such that:
- source_cache::ensure is easier to read, and
- the conditional compilation is at the level of the function body.

Tested on x86_64-linux.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months ago[gdb/cli] Skip string copy in source_cache::ensure
Tom de Vries [Tue, 17 Oct 2023 09:38:06 +0000 (11:38 +0200)]
[gdb/cli] Skip string copy in source_cache::ensure

In function source_cache::ensure we have:
...
        std::ostringstream output;
      ...
      contents = output.str ();
...
The last line causes an unnecessary string copy.

C++20 allows us to skip it, like this:
...
      contents = std::move (output).str ();
...

Use the more efficient solution.

Tested on x86_64-linux.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
13 months agoLoongArch: readelf -d RELASZ excludes .rela.plt size
mengqinggang [Mon, 31 Jul 2023 09:09:48 +0000 (17:09 +0800)]
LoongArch: readelf -d RELASZ excludes .rela.plt size

Before, readelf -d RELASZ is the sum of .rela.dyn size and .rela.plt size.
To consistent with LoongArch lld, RELASZ chang to only the size of .rela.dyn.

13 months agoasan: Invalid free in alpha_ecoff_get_relocated_section_contents
Alan Modra [Mon, 16 Oct 2023 09:04:03 +0000 (19:34 +1030)]
asan: Invalid free in alpha_ecoff_get_relocated_section_contents

This fixes an ancient bug in commit a3a33af390 (which makes me think
this code has never been used).

* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Iterate
through reloc_vector using a temp.

13 months agoRISC-V: Fix typo
Tsukasa OI [Tue, 17 Oct 2023 02:09:44 +0000 (02:09 +0000)]
RISC-V: Fix typo

include/ChangeLog:

* opcode/riscv-opc.h: Fix typo.

13 months agonat/x86-cpuid.h: Remove non-x86 fallbacks
John Baldwin [Tue, 17 Oct 2023 00:36:58 +0000 (17:36 -0700)]
nat/x86-cpuid.h: Remove non-x86 fallbacks

This header is only suitable for use on x86 hosts and is only included
there, so these fallbacks should not be needed.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
13 months agoAutomatic date update in version.in
GDB Administrator [Tue, 17 Oct 2023 00:00:45 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agogdb: remove unnecessary declarations in target.c
Simon Marchi [Mon, 16 Oct 2023 16:24:53 +0000 (16:24 +0000)]
gdb: remove unnecessary declarations in target.c

I found that these local declarations were not needed, remove them.
Tested by rebuilding.

Change-Id: I8d4fd0839ee1063b91dc002216d683aee0d4be22

13 months agoHave DAP handle non-Value results from 'children'
Tom Tromey [Fri, 6 Oct 2023 13:42:00 +0000 (07:42 -0600)]
Have DAP handle non-Value results from 'children'

A pretty-printer's 'children' method may return values other than a
gdb.Value -- it may return any value that can be converted to a
gdb.Value.

I noticed that this case did not work for DAP.  This patch fixes the
problem.

13 months agoHandle gdb.LazyString in DAP
Tom Tromey [Wed, 4 Oct 2023 17:22:05 +0000 (11:22 -0600)]
Handle gdb.LazyString in DAP

Andry pointed out that the DAP code did not properly handle
gdb.LazyString results from a pretty-printer, yielding:

    TypeError: Object of type LazyString is not JSON serializable

This patch fixes the problem, partly with a small patch in varref.py,
but mainly by implementing tp_str for LazyString.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
13 months agoFix register-setting response from DAP
Tom Tromey [Wed, 4 Oct 2023 18:58:32 +0000 (12:58 -0600)]
Fix register-setting response from DAP

Andry noticed that given a DAP setExpression request, where the
expression to set is a register, DAP will return the wrong value -- it
will return the old value, not the updated one.

This happens because gdb.Value.assign (which was recently added for
DAP) does not update the value.

In this patch, I chose to have the assign method update the Value
in-place.  It's also possible to have it return a new value, but this
didn't seem very useful to me.

13 months agoFix: GNU-ld: ARM: Issues when trying to set target output architecture
Nick Clifton [Mon, 16 Oct 2023 15:11:49 +0000 (16:11 +0100)]
Fix: GNU-ld: ARM: Issues when trying to set target output architecture

  PR 28910
  * elf32-arm.c (elf32_arm_merge_private_bfd_data): Do not set output flags if the input flags have not been set.

13 months agoFix: GNU-ld: ARM: Issues when trying to set target output architecture
Nick Clifton [Mon, 16 Oct 2023 14:48:26 +0000 (15:48 +0100)]
Fix: GNU-ld: ARM: Issues when trying to set target output architecture

  PR 28910
  * lexsup.c (ld_options): Require that the --architecture option is given exactly two dashes, so that it does not become confused with the -a option.

13 months agoAdd DAP scope cache
Tom Tromey [Wed, 27 Sep 2023 17:48:24 +0000 (11:48 -0600)]
Add DAP scope cache

Andry Ogorodnik, a co-worker, noticed that multiple "scopes" requests
with the same frame would yield different variableReference values in
the response.

This patch adds a regression test for this, and adds a scope cache in
scopes.py, ensuring that multiple identical requests will get the same
response.

Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
13 months ago[gdb/symtab] Work around PR gas/29517
Tom de Vries [Mon, 16 Oct 2023 14:32:28 +0000 (16:32 +0200)]
[gdb/symtab] Work around PR gas/29517

When using glibc debuginfo generated with gas 2.39, we run into PR gas/29517:
...
$ gdb -q -batch a.out -ex start -ex "p (char *)strstr (\"haha\", \"ah\")"
Temporary breakpoint 1 at 0x40051b: file hello.c, line 6.

Temporary breakpoint 1, main () at hello.c:6
6   printf ("hello\n");
Invalid cast.
...
while without glibc debuginfo installed we get the expected result:
...
$n = 0x7ffff7daa1b1 "aha"
...
and likewise with glibc debuginfo generated with gas 2.40.

The strstr ifunc resolves to __strstr_sse2_unaligned.  The problem is that gas
generates dwarf that states that the return type is void:
...
<1><3e1e58>: Abbrev Number: 2 (DW_TAG_subprogram)
    <3e1e59>   DW_AT_name        : __strstr_sse2_unaligned
    <3e1e5d>   DW_AT_external    : 1
    <3e1e5e>   DW_AT_low_pc      : 0xbbd2e
    <3e1e66>   DW_AT_high_pc     : 0xbc1c3
...
while the return type should be a DW_TAG_unspecified_type, as is the case
with gas 2.40.

We can still use the workaround of casting to another function type for both
__strstr_sse2_unaligned:
...
(gdb) p ((char * (*) (const char *, const char *))__strstr_sse2_unaligned) \
  ("haha", "ah")
$n = 0x7ffff7daa211 "aha"
...
and strstr (which requires using *strstr to dereference the ifunc before we
cast):
...
gdb) p ((char * (*) (const char *, const char *))*strstr) ("haha", "ah")
$n = 0x7ffff7daa251 "aha"
...
but that's a bit cumbersome to use.

Work around this in the dwarf reader, such that we have instead:
...
(gdb) p (char *)strstr ("haha", "ah")
$n = 0x7ffff7daa1b1 "aha"
...

This also requires fixing producer_is_gcc to stop returning true for
producer "GNU AS 2.39.0".

Tested on x86_64-linux.

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