binutils-gdb.git
3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 19 May 2021 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agosim: depend on gnulib
Mike Frysinger [Sat, 8 May 2021 02:30:30 +0000 (22:30 -0400)]
sim: depend on gnulib

We're going to start using gnulib in the sim, so make sure it exists.

ChangeLog:

* Makefile.def: Add configure-sim dependency on all-gnulib.
* Makefile.in: Regenerated.

3 years agoconfig: delete unused sim macros
Mike Frysinger [Wed, 12 May 2021 04:26:17 +0000 (00:26 -0400)]
config: delete unused sim macros

Nothing in gcc or binutils or gdb or anything anywhere uses these.

config/

* acinclude.m4 (CYG_AC_PATH_SIM, CYG_AC_PATH_DEVO): Delete.

3 years agoRISC-V: PR27814, Objdump crashes when disassembling a non-ELF RISC-V binary.
Job Noorman [Tue, 18 May 2021 00:41:11 +0000 (08:41 +0800)]
RISC-V: PR27814, Objdump crashes when disassembling a non-ELF RISC-V binary.

2021-05-18  Job Noorman  <mtvec@pm.me>

opcodes/
    PR 27814
    * riscv-dis.c (riscv_get_disassembler): Get elf attributes only for
    the elf objects.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 18 May 2021 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agoRename dwarf2/comp-unit.h
Tom Tromey [Mon, 17 May 2021 20:16:06 +0000 (14:16 -0600)]
Rename dwarf2/comp-unit.h

Simon pointed out that dwarf2/cu.h and dwarf2/comp-unit.h seemingly
mean the same thing.  He suggested renaming the latter to
comp-unit-head.h, which is what this patch does.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tom@tromey.com>

* dwarf2/read.h: Update include.
* dwarf2/read.c: Update include.
* dwarf2/line-header.c: Update include.
* dwarf2/cu.h: Update include.
* dwarf2/comp-unit-head.h: Rename from comp-unit.h.
* dwarf2/comp-unit-head.c: Rename from comp-unit.c.
* Makefile.in (COMMON_SFILES): Update.

3 years agoChange dwarf2_cu marking to use methods
Tom Tromey [Mon, 17 May 2021 20:16:06 +0000 (14:16 -0600)]
Change dwarf2_cu marking to use methods

This changes the dwarf2_cu marking functions to be methods on
dwarf2_cu.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (maybe_queue_comp_unit)
(dwarf2_per_objfile::age_comp_units): Update.
(dwarf2_add_dependence, dwarf2_mark_helper, dwarf2_mark): Move to
dwarf2_cu methods.
* dwarf2/cu.h (struct dwarf2_cu) <mark, clear_mark, is_marked,
add_dependence>: New methods.
<m_dependencies>: Add "m_" prefix.  Now private.
<m_mark>: Add "m_" prefix.
* dwarf2/cu.c (dwarf2_cu::dwarf2_cu): Update.
(dwarf2_mark_helper): New function.
(dwarf2_cu::mark, dwarf2_cu::add_dependence): New methods.

3 years agoMove some dwarf2_cu methods to new file
Tom Tromey [Mon, 17 May 2021 20:16:06 +0000 (14:16 -0600)]
Move some dwarf2_cu methods to new file

This moves some of the dwarf2_cu methods to a new file, dwarf2/cu.c.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (dwarf2_cu::addr_sized_int_type)
(dwarf2_cu::start_symtab, dwarf2_cu::addr_type)
(dwarf2_cu::dwarf2_cu): Move to cu.c.
* dwarf2/cu.c: New file.
* Makefile.in (COMMON_SFILES): Add dwarf2/cu.c.

3 years agoMove dwarf2_cu to new header file
Tom Tromey [Mon, 17 May 2021 20:16:06 +0000 (14:16 -0600)]
Move dwarf2_cu to new header file

This moves dwarf2_cu and one supporting data structure to a new header
file.  The main goal, as always with this kind of change, is to make
the DWARF reader a bit more understandable.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tom@tromey.com>

* Makefile.in (HFILES_NO_SRCDIR): Add dwarf2/cu.h.
* dwarf2/read.c (struct delayed_method_info, struct dwarf2_cu):
Move to cu.h.
* dwarf2/cu.h: New file.

3 years agogdb: additional settings for emacs in .dir-locals.el
Andrew Burgess [Mon, 17 May 2021 12:09:22 +0000 (13:09 +0100)]
gdb: additional settings for emacs in .dir-locals.el

Two additional settings for developers who use emacs:

  1. Set brace-list-open to 0 for C and C++ modes, this ensures we
  format things like:

  enum blah
  {
    ....
  };

  Instead of the default for the emacs GNU style:

  enum blah
    {
      ...
    };

  The former seems to be the GDB style.

  2. Set sentence-end-double-space to t.  This is actually the default
  value for this setting, but if anyone has customised this to nil in
  general, then forcing this back to t for GDB files will give a
  better behaviour for the paragraph filling.

gdb/ChangeLog:

* .dir-locals.el: Set sentence-end-double-space for all modes, and
set brace-list-open to 0 for C and C++ modes.

gdbserver/ChangeLog:

* .dir-locals.el: Set sentence-end-double-space for all modes, and
set brace-list-open to 0 for C and C++ modes.

gdbsupport/ChangeLog:

* .dir-locals.el: Set sentence-end-double-space for all modes, and
set brace-list-open to 0 for C and C++ modes.

3 years agoAvoid crash with GCC trunk
Tom Tromey [Mon, 17 May 2021 19:07:25 +0000 (13:07 -0600)]
Avoid crash with GCC trunk

With GCC trunk, gdb.ada/access_to_packed_array.exp causes a GDB crash.
The problem is that ptype tries to resolve a dynamic type.  However,
the inferior is not running, so there are no frames.

This patch updates dwarf2_evaluate_loc_desc::get_frame_base to handle
this situation.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tromey@adacore.com>

* dwarf2/loc.c (dwarf2_evaluate_loc_desc::get_frame_base): Throw
if frame is null.

3 years agoFix ubsan build
Tom Tromey [Mon, 17 May 2021 18:55:18 +0000 (12:55 -0600)]
Fix ubsan build

I tried a build using the undefined behavior sanitizer, and gcc gave
this error:

In file included from /usr/include/string.h:495,
                 from ../gnulib/import/string.h:41,
                 from ../../binutils-gdb/gdb/../gdbsupport/common-defs.h:95,
                 from ../../binutils-gdb/gdb/nat/linux-osdata.c:20:
In function 'char* strncpy(char*, const char*, size_t)',
    inlined from 'void time_from_time_t(char*, int, TIME_T)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:923:15,
    inlined from 'void time_from_time_t(char*, int, TIME_T)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:911:1,
    inlined from 'void linux_xfer_osdata_sem(buffer*)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:1082:22:
/usr/include/bits/string_fortified.h:106:34: error: 'char* __builtin_strncpy(char*, const char*, long unsigned int)' specified bound 32 equals destination size [-Werror=stringop-truncation]

This patch fixes the problem by subtracting one from the length
parameter to strncpy.

I changed a couple of other similar functions -- gcc does not warn
about these, but I didn't see any substantial difference between the
different cases, and I think these are just latent warnings, to be
triggered in the future by a change to inlining heuristics.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tromey@adacore.com>

* nat/linux-osdata.c (user_from_uid, time_from_time_t)
(group_from_gid): Subtract one from strncpy length.

3 years agoFix buffer underflow in add_path
Tom Tromey [Mon, 17 May 2021 18:55:18 +0000 (12:55 -0600)]
Fix buffer underflow in add_path

Address sanitizer pointed out a buglet in source.c:add_path.
In this test, from gdb.base/source-dir.exp:

    (gdb) set directories :/foo:/bar

... 'p[-1]' will result in a buffer underflow.
This patch fixes the bug by introducing a new check.

2021-05-17  Tom Tromey  <tromey@adacore.com>

* source.c (add_path): Check 'p' before using 'p[-1]'.

3 years agoChange how dwarf2_per_cu_data is deleted
Tom Tromey [Mon, 17 May 2021 18:55:18 +0000 (12:55 -0600)]
Change how dwarf2_per_cu_data is deleted

Address sanitizer pointed out that the patch to use 'delete' for
dwarf2_per_cu_data introduced a bug -- now it is possible to delete a
signatured_type using a pointer to its base class.

This patch fixes the problem by introducing a deleter and a unique_ptr
specialization.  A virtual destructor would be more ordinary here, but
it seemed wasteful to add a vtable just for this purpose.  If virtual
methods are ever needed here, we can revisit this.

2021-05-17  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.h (struct dwarf2_per_cu_data_deleter: New.
(dwarf2_per_cu_data_up): New typedef.
(struct dwarf2_per_bfd) <allocate_per_cu>: Change return type.
<all_comp_units>: Use dwarf2_per_cu_data_up.
* dwarf2/read.c (dwarf2_per_cu_data::operator()): New function.
(dwarf2_per_bfd::allocate_per_cu): Return dwarf2_per_cu_data_up.
(create_cu_from_index_list): Likewise.
(create_signatured_type_table_from_index)
(create_cus_from_debug_names_list, add_type_unit)
(read_comp_units_from_section): Update.
(dwarf2_find_containing_comp_unit): Change type of all_comp_units.
(run_test): Update.

3 years agoReplace sort_tu_by_abbrev_offset with operator<
Tom Tromey [Mon, 17 May 2021 18:50:33 +0000 (12:50 -0600)]
Replace sort_tu_by_abbrev_offset with operator<

I noticed that sort_tu_by_abbrev_offset only has a single caller.  It
seemed simpler to replace it with an implementation of operator<
instead.

2021-05-17  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (tu_abbrev_offset::operator<): New method.
(sort_tu_by_abbrev_offset): Remove.
(build_type_psymtabs): Update.

3 years agogdb/testsuite: rename .py.in files to .py
Simon Marchi [Mon, 17 May 2021 18:58:26 +0000 (14:58 -0400)]
gdb/testsuite: rename .py.in files to .py

I noticed these files because they weren't considered by black for
reformatting, prior to adding pyproject.toml, because their extension is
not .py.  I don't think they specifically need to be named .py.in, so I
suggest renaming them to .py.  This will make it nicer to edit them, as
editors will recognize them more easily as Python files.

Perhaps this was needed before, when the testsuite didn't always put
output files in the output directory.  Then, a different name for the
source and destination file might have been desirable to avoid
overwriting a file with itself (perhaps that wasn't well handled).  But
in any case, it doesn't see to cause any problem now.

gdb/testsuite/ChangeLog:

* gdb.python/py-framefilter-gdb.py.in: Rename to:
* gdb.python/py-framefilter-gdb.py: ... this.
* gdb.python/py-framefilter-invalidarg-gdb.py.in: Rename to:
* gdb.python/py-framefilter-invalidarg-gdb.py: ... this.

Change-Id: I63bb94010bbbc33434ee1c91a386c91fc1ff80bc

3 years agogdb: add pyproject.toml
Simon Marchi [Mon, 17 May 2021 18:31:00 +0000 (14:31 -0400)]
gdb: add pyproject.toml

When running black to format Python files, files with extension .py.in
are ignored, because they don't end in .py.  Add a pyproject.toml file
to instruct black to pick up these files too.

gdb/ChangeLog:

* py-project.toml: New.
* gdb-gdb.py.in: Re-format.

gdb/testsuite/ChangeLog:

* gdb.python/py-framefilter-gdb.py.in: Re-format.
* gdb.python/py-framefilter-invalidarg-gdb.py.in: Re-format.

Change-Id: I9b88faec3360ea24788f44c8b89fe0b2a5f4eb97

3 years agogdb: add cmd_list_element::is_command_class_help
Simon Marchi [Mon, 17 May 2021 18:01:32 +0000 (14:01 -0400)]
gdb: add cmd_list_element::is_command_class_help

Same idea as the previous patches, but for whether a command is a
"command class help" command.  I think this one is particularly useful,
because it's not obvious when reading code what "c->func == NULL" means.

Remove the cmd_func_p function, which does kind of the same thing as
cmd_list_element::is_command_class_help (except it doesn't give a clue
about the semantic of a NULL func value).

gdb/ChangeLog:

* cli/cli-decode.h (cmd_list_element) <is_command_class_help>:
New, use it.
* command.h (cmd_func_p): Remove.
* cli/cli-decode.c (cmd_func_p): Remove.

Change-Id: I521a3e1896dc93a5babe1493d18f5eb071e1b3b7

3 years agogdb: add cmd_list_element::is_prefix
Simon Marchi [Fri, 14 May 2021 19:38:49 +0000 (15:38 -0400)]
gdb: add cmd_list_element::is_prefix

Same idea as the previous patch, but for prefix instead of alias.

gdb/ChangeLog:

* cli/cli-decode.h (cmd_list_element) <is_prefix>: New, use it.

Change-Id: I76a9d2e82fc8d7429904424674d99ce6f9880e2b

3 years agogdb: add cmd_list_element::is_alias
Simon Marchi [Mon, 17 May 2021 18:01:20 +0000 (14:01 -0400)]
gdb: add cmd_list_element::is_alias

Add the cmd_list_element::is_alias helper to check whether a command is
an alias.  I find it easier to understand the intention in:

  if (c->is_alias ())

than

  if (c->alias_target != nullptr)

Change all the spots that are reading alias_target just to compare it to
NULL/nullptr to use is_alias instead.

gdb/ChangeLog:

* cli/cli-decode.h (cmd_list_element) <is_alias>: New, use it.

Change-Id: I26ed56f99ee47fe884fdfedf87016501631693ce

3 years agogdb: rename cmd_list_element::cmd_pointer to target
Simon Marchi [Mon, 17 May 2021 18:01:14 +0000 (14:01 -0400)]
gdb: rename cmd_list_element::cmd_pointer to target

cmd_pointer is another field whose name I found really not clear.  Yes,
it's a pointer to a command, the type tells me that.  But what's the
relationship of that command to the current command?  This field
contains, for an alias, the command that it aliases.  So I think that
the name "alias_target" would be more appropriate.

Also, rename "old" parameters to "target" in the functions that add
aliases.

gdb/ChangeLog:

* cli/cli-decode.h (cmd_list_element) <cmd_pointer>: Rename
to...
<alias_target>: ... this.
(add_alias_cmd): Rename old to target.
(add_info_alias): Rename old_name to target_name.
(add_com_alias): Likewise.

Change-Id: I8db36c6dd799fae155f7acd3805f6d62d98befa9

3 years agogdb: rename cmd_list_element::prefixlist to subcommands
Simon Marchi [Mon, 17 May 2021 18:01:08 +0000 (14:01 -0400)]
gdb: rename cmd_list_element::prefixlist to subcommands

While browsing this code, I found the name "prefixlist" really
confusing.  I kept reading it as "list of prefixes".  Which it isn't:
it's a list of sub-commands, for a prefix command.  I think that
renaming it to "subcommands" would make things clearer.

gdb/ChangeLog:

* Rename "prefixlist" parameters to "subcommands" throughout.
* cli/cli-decode.h (cmd_list_element) <prefixlist>: Rename to...
<subcommands>: ... this.
* cli/cli-decode.c (lookup_cmd_for_prefixlist): Rename to...
(lookup_cmd_with_subcommands): ... this.

Change-Id: I150da10d03052c2420aa5b0dee41f422e2a97928

3 years agogdb: don't handle old == nullptr in add_alias_cmd
Simon Marchi [Mon, 17 May 2021 18:01:01 +0000 (14:01 -0400)]
gdb: don't handle old == nullptr in add_alias_cmd

I don't think this can ever happen, that we add an alias command and
pass a nullptr old (target) command.  Remove the "if" handling this,
replace with an assert.

gdb/ChangeLog:

* cli/cli-decode.c (add_alias_cmd): Don't handle old == 0.

Change-Id: Ibb39e8dc4e0c465fa42e6826215f30a0a0aef932

3 years agogdb: move cmd_list_element::prefixname to cli/cli-decode.c
Simon Marchi [Mon, 17 May 2021 18:00:48 +0000 (14:00 -0400)]
gdb: move cmd_list_element::prefixname to cli/cli-decode.c

I don't think this method really benefits from being implemented in the
header file, especially because it's recursive, it can't be inlined.
Move it to the source file, so it's no re-compiled by every CU
including cli/cli-decode.h.

I also noticed this method could be const, make it so.

gdb/ChangeLog:

* cli/cli-decode.h (prefixname): Make const, move implementation
to cli/cli-decode.c.
* cli/cli-decode.c (cmd_list_element::prefixname): New.

Change-Id: I1597cace98d9a4ba71f51f1f495e73cc07b5dcf3

3 years agoarm: Fix bugs with MVE vmov from two GPRs to vector lanes
Alex Coplan [Mon, 17 May 2021 14:12:39 +0000 (15:12 +0100)]
arm: Fix bugs with MVE vmov from two GPRs to vector lanes

The initial problem I wanted to fix here is that GAS was rejecting MVE
instructions such as:

vmov q3[2], q3[0], r2, r2

with:

Error: General purpose registers may not be the same -- `vmov q3[2],q3[0],r2,r2'

which is incorrect; such instructions are valid. Note that for moves in
the other direction, e.g.:

vmov r2, r2, q3[2], q3[0]

GAS is correct in rejecting this as it does not make sense to move both
lanes into the same register (the Arm ARM says this is CONSTRAINED
UNPREDICTABLE).

After fixing this issue, I added assembly/disassembly tests for these
vmovs. This revealed several disassembly issues, including incorrectly
marking the moves into vector lanes as UNPREDICTABLE, and disassembling
many of the vmovs as vector loads. These are now fixed.

gas/ChangeLog:

* config/tc-arm.c (do_mve_mov): Only reject vmov if we're moving
into the same GPR twice.
* testsuite/gas/arm/mve-vmov-bad-2.l: Tweak error message.
* testsuite/gas/arm/mve-vmov-3.d: New test.
* testsuite/gas/arm/mve-vmov-3.s: New test.

opcodes/ChangeLog:

* arm-dis.c (mve_opcodes): Fix disassembly of
MVE_VMOV2_GP_TO_VEC_LANE when idx == 1.
(is_mve_encoding_conflict): MVE vector loads should not match
when P = W = 0.
(is_mve_unpredictable): It's not unpredictable to use the same
source register twice (for MVE_VMOV2_GP_TO_VEC_LANE).

3 years agogdb/fortran: test case modified to suit the clang behavior.
Bhuvanendra Kumar N [Mon, 17 May 2021 06:52:19 +0000 (12:22 +0530)]
gdb/fortran: test case modified to suit the clang behavior.

As mentioned in the test case itself, depending on the fortran compiler
used, class member names used in the print commands and also output of
these print commands varies. Existing print commands and its output are
suited for gfortran, hence they were failing with clang compiler and test
case was modified accordingly for clang compiler.

gdb/testsuite/ChangeLog:
        * gdb.base/class-allocatable-array.exp: Modified test for clang.

3 years agosim: fully merge sim_state_base into sim_state
Mike Frysinger [Fri, 22 Jan 2016 03:51:00 +0000 (22:51 -0500)]
sim: fully merge sim_state_base into sim_state

Now that all ports have migrated to the new framework, drop support
for the old sim_state_base layout.

3 years agosim: riscv: invert sim_state storage
Mike Frysinger [Thu, 13 May 2021 09:44:02 +0000 (05:44 -0400)]
sim: riscv: invert sim_state storage

3 years agosim: h8300: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 03:46:34 +0000 (22:46 -0500)]
sim: h8300: invert sim_state storage

3 years agosim: mips: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 03:40:43 +0000 (22:40 -0500)]
sim: mips: invert sim_state storage

3 years agosim: avr: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 03:34:05 +0000 (22:34 -0500)]
sim: avr: invert sim_state storage

3 years agosim: cgen: invert sim_state storage for cgen ports
Mike Frysinger [Fri, 22 Jan 2016 02:13:06 +0000 (21:13 -0500)]
sim: cgen: invert sim_state storage for cgen ports

3 years agosim: bfin: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 02:05:33 +0000 (21:05 -0500)]
sim: bfin: invert sim_state storage

3 years agosim: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 02:00:25 +0000 (21:00 -0500)]
sim: invert sim_state storage

Currently all ports have to declare sim_state themselves in their
sim-main.h and then embed the common sim_state_base & sim_cpu in it.
This dynamic makes it impossible to share common object code among
multiple ports because the core data structure is always different.

Let's invert this relationship: common code declares sim_state, and
if the port actually needs state on a per-instance basis, it can use
the new arch_data field for it.  Most ports don't actually use it,
so they don't need to declare anything at all.

This is the first in a series of changes: it adds a define to select
between the old & new layouts, then converts all the ports that don't
need custom state over to the new layout.

3 years agosim: install library header files
Mike Frysinger [Fri, 14 May 2021 05:57:06 +0000 (01:57 -0400)]
sim: install library header files

We install libsim.a for people to link against, but haven't been
installing the header files to for its API.  Export them!

3 years agosim: switch config.h usage to defs.h
Mike Frysinger [Sat, 1 May 2021 22:05:23 +0000 (18:05 -0400)]
sim: switch config.h usage to defs.h

The defs.h header will take care of including the various config.h
headers.  For now, it's just config.h, but we'll add more when we
integrate gnulib in.

This header should be used instead of config.h, and should be the
first include in every .c file.  We won't rely on the old behavior
where we expected files to include the port's sim-main.h which then
includes the common sim-basics.h which then includes config.h.  We
have a ton of code that includes things before sim-main.h, and it
sometimes needs to be that way.  Creating a dedicated header avoids
the ordering mess and implicit inclusion that shows up otherwise.

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 17 May 2021 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agoCTF: handle forward reference type
Weimin Pan [Sun, 16 May 2021 22:24:14 +0000 (18:24 -0400)]
CTF: handle forward reference type

The problems can be illustrated, with any program, below:

(gdb) print main
$1 = {main} 0x0

The return type was incorrectly set in read_func_kind_type, with
the name of the function, which leads c_type_print_base_1 to print
it. In addition, the address of a new function needs to be set with
that info in its minimal symtab entry, when the new function is added.

After the fix:

(gdb) print main
$1 = {int ()} 0x4004b7 <main>

A new test, gdb.ctf/funcreturn.exp, is added to the testsuite.

gdb/ChangeLog:
        * ctfread.c (new_symbol): Set function address.
        (read_func_kind_type): Remove incorrect type name setting.
        Don't copy name returned from ctf_type_ame_raw throughout file.

gdb/testsuite/ChangeLog:
        * gdb.ctf/funcreturn.exp: New file.
        * gdb.ctf/whatis.c: Copy from gdb.base.

3 years agosim: riscv: move __int128 check to configure
Mike Frysinger [Sun, 16 May 2021 03:50:33 +0000 (23:50 -0400)]
sim: riscv: move __int128 check to configure

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 16 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agosim: ppc: clean up various warnings
Mike Frysinger [Sat, 15 May 2021 14:48:02 +0000 (10:48 -0400)]
sim: ppc: clean up various warnings

A random grab bag of minor fixes to enable -Werror for this port.

Cast address vars to long when the format was using %l.
Use %zu with sizeof operations.
Add const to a bunch of strings.
Trim unused variables.
Fix sizeof call to calculate target storage and not the pointer itself.

3 years agosim: switch to libiberty environ.h
Mike Frysinger [Sat, 15 May 2021 12:43:36 +0000 (08:43 -0400)]
sim: switch to libiberty environ.h

Drop our compat code and assume environ exists to simplify.

3 years agoprocess_cu_tu_index
Alan Modra [Sat, 15 May 2021 06:10:46 +0000 (15:40 +0930)]
process_cu_tu_index

* dwarf.c (process_cu_tu_index): Avoid pointer UB.  Use _mul_overflow.
Delete dead code.

3 years agodisplay_gdb_index
Alan Modra [Sat, 15 May 2021 06:07:07 +0000 (15:37 +0930)]
display_gdb_index

* dwarf.c (display_gdb_index): Avoid pointer UB and overflow in
length calculations.

3 years agodisplay_debug_names
Alan Modra [Sat, 15 May 2021 05:59:47 +0000 (15:29 +0930)]
display_debug_names

* dwarf.c (display_debug_names): Complain when header length is
too small.  Avoid pointer UB.  Sanity check augmentation string,
CU table, TU table and foreign TU table sizes.

3 years agodisplay_debug_frames
Alan Modra [Sat, 15 May 2021 05:54:03 +0000 (15:24 +0930)]
display_debug_frames

* dwarf.c (display_debug_frames): Delete initial_length_size.
Avoid pointer UB.  Constrain data reads to length given in header.
Sanity check cie header length.  Only skip up to next FDE on
finding augmentation data too long.

3 years agoread_cie
Alan Modra [Sat, 15 May 2021 05:52:39 +0000 (15:22 +0930)]
read_cie

* dwarf.c (read_cie): Add more sanity checks to ensure data
pointer is not bumped past end.

3 years agodisplay_debug_ranges
Alan Modra [Sat, 15 May 2021 05:47:58 +0000 (15:17 +0930)]
display_debug_ranges

* dwarf.c (display_debug_ranges): Delete initial_length_size.
Correct fallback size calculated on finding a reloc.  Constrain
data reads to length given in header.  Avoid pointer UB.

3 years agodisplay_debug_rnglists_list
Alan Modra [Sat, 15 May 2021 05:47:16 +0000 (15:17 +0930)]
display_debug_rnglists_list

* dwarf.c (display_debug_rnglists_list): Avoid pointer UB.

3 years agodisplay_debug_str_offsets
Alan Modra [Sat, 15 May 2021 05:45:47 +0000 (15:15 +0930)]
display_debug_str_offsets

* dwarf.c (display_debug_str_offsets): Constrain reads to length
given in header.

3 years agodisplay_debug_aranges
Alan Modra [Sat, 15 May 2021 05:43:55 +0000 (15:13 +0930)]
display_debug_aranges

* dwarf.c (display_debug_aranges): Delete initial_length_size.
Use end_ranges to constrain data reads to header length.  Avoid
pointer UB.

3 years agodisplay_loc_list
Alan Modra [Sat, 15 May 2021 05:40:44 +0000 (15:10 +0930)]
display_loc_list

* dwarf.c (display_loc_list): Avoid pointer UB.  Correct check
before reading uleb length.  Warn on excess length.

3 years agodisplay_debug_macro
Alan Modra [Sat, 15 May 2021 05:39:20 +0000 (15:09 +0930)]
display_debug_macro

* dwarf.c (display_debug_macro): Print strings that might not
be zero terminated with %*s.  Don't bump curr if unterminated.

3 years agoget_line_filename_and_dirname
Alan Modra [Sat, 15 May 2021 05:36:28 +0000 (15:06 +0930)]
get_line_filename_and_dirname

* dwarf.c (get_line_filename_and_dirname): Delete initial_length_size.
Simplify length sanity check, and check for too small lengths.
Constrain data reads to header length.  Avoid pointer UB.

3 years agodisplay_debug_macinfo
Alan Modra [Sat, 15 May 2021 05:31:51 +0000 (15:01 +0930)]
display_debug_macinfo

The existing code went to the bother of using strnlen for scanning but
went wild when printing, and possibly incremented curr past end.

* dwarf.c (display_debug_macinfo): Print strings that might not
be zero terminated with %*s.  Don't bump curr if unterminated.

3 years agodisplay_debug_pubnames_worker
Alan Modra [Sat, 15 May 2021 05:28:37 +0000 (14:58 +0930)]
display_debug_pubnames_worker

* dwarf.c (display_debug_pubnames_worker): Delete initial_length_size.
Simplify length check.  Constrain reads to length given by header.

3 years agodisplay_debug_lines_decoded
Alan Modra [Sat, 15 May 2021 05:24:55 +0000 (14:54 +0930)]
display_debug_lines_decoded

The directory_table strnlen used the negative of the proper size.  After
fixing that I realised we don't need strnlen here.

* dwarf.c (display_debug_lines_decoded): Don't use strnlen when
we have already checked for NUL termination.

3 years agoread_debug_line_header
Alan Modra [Sat, 15 May 2021 05:18:48 +0000 (14:48 +0930)]
read_debug_line_header

This patch also better constrains the data read, and removes pointer UB.

* dwarf.c (read_debug_line_header): Delete initial_length_size.
Avoid pointer UB.  Keep within length specified by header.
Delete dead code.

3 years agoprocess_debug_info
Alan Modra [Sat, 15 May 2021 05:09:11 +0000 (14:39 +0930)]
process_debug_info

This patch constrains process_debug_info to stay within the data
specified by the CU length rather than allowing access up to the end
of the section.

* dwarf.c (process_debug_info): Always do the first CU length
scan for sanity checks.  Remove initial_length_size var and
instead calculate end_cu.  Use end_cu to limit data reads.
Delete now dead code checking length.

3 years agoSAFE_BYTE_GET_INTERNAL
Alan Modra [Sat, 15 May 2021 05:07:42 +0000 (14:37 +0930)]
SAFE_BYTE_GET_INTERNAL

We won't want this assert triggering in the next release.

* dwarf.c (SAFE_BYTE_GET_INTERNAL): Assert only when ENABLE_CHECKING.

3 years ago_mul_overflow and get_encoded_value
Alan Modra [Sat, 15 May 2021 05:06:26 +0000 (14:36 +0930)]
_mul_overflow and get_encoded_value

A sufficiently mad compiler optimiser can take undefined behaviour
according to the C standard as an opportunity to remove code.  Since
"data + size" might be seen to be past the end of an array,
calculating such an expression is UB.

_mul_overflow is infrastructure for later patches.

* bucomm.h (_mul_overflow): Define.
* dwarf.c (get_encoded_value): Avoid pointer UB.

3 years ago[GOLD]: Re: Add -Bno-symbolic
Alan Modra [Sat, 15 May 2021 04:43:47 +0000 (14:13 +0930)]
[GOLD]: Re: Add -Bno-symbolic

PR 27834
* options.cc (General_options::General_options): Init bsymbolic_.

3 years agoFix Python pretty-printing bug in Rust
Tom Tromey [Sat, 15 May 2021 01:54:35 +0000 (19:54 -0600)]
Fix Python pretty-printing bug in Rust

An upstream Rust bug notes notes that the Python pretty-printing
feature is broken for values that appear as members of certain types
in Rust.

The bug here is that some of the Rust value-printing code calls
value_print_inner, a method on rust_language.  This bypasses the
common code that calls into Python.

I'm checking this in.

gdb/ChangeLog
2021-05-14  Tom Tromey  <tom@tromey.com>

* rust-lang.c (rust_language::val_print_struct)
(rust_language::print_enum): Use common_val_print, not
value_print_inner.

gdb/testsuite/ChangeLog
2021-05-14  Tom Tromey  <tom@tromey.com>

* gdb.rust/pp.exp: New file.
* gdb.rust/pp.py: New file.
* gdb.rust/pp.rs: New file.

3 years agosim: callback: convert FS interfaces to 64-bit
Mike Frysinger [Sat, 24 Apr 2021 18:40:43 +0000 (14:40 -0400)]
sim: callback: convert FS interfaces to 64-bit

Rather than rely on off_t being the right size between the host &
target, have the interface always be 64-bit.  We can figure out if
we need to truncate when actually outputting it to the right target.

3 years agosim: callback: convert time interface to 64-bit
Mike Frysinger [Sat, 24 Apr 2021 18:35:14 +0000 (14:35 -0400)]
sim: callback: convert time interface to 64-bit

PR sim/27705
Rather than rely on time_t being the right size between the host &
target, have the interface always be 64-bit.  We can figure out if
we need to truncate when actually outputting it to the right target.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 15 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agogold: Add -Bno-symbolic
Fangrui Song [Fri, 14 May 2021 22:51:16 +0000 (15:51 -0700)]
gold: Add -Bno-symbolic

gold/
    PR 27834
    * options.h (General_options): Make -Bsymbolic and
    -Bsymbolic-functions special and adjust the help messages. Add
    enum Bsymbolic_kind and -Bno-symbolic.
    * options.cc (General_options): Define parse_Bno_symbolic,
    parse_Bsymbolic_functions, and parse_Bsymbolic.

3 years agotestsuite: Cleanup some temp dirs with gdb-index files
Bernd Edlinger [Fri, 14 May 2021 12:53:19 +0000 (14:53 +0200)]
testsuite: Cleanup some temp dirs with gdb-index files

After the gdb test-suite runs there are some files
left in /tmp/tmp*/*.gdb-index, remove those files
and the directory at the end of the test case.

gdb/testsuite:
2021-05-14  Bernd Edlinger  <bernd.edlinger@hotmail.de>

* gdb.base/index-cache.exp: Cleanup $cache_dir/*.gdb-index and
remove the directory.
* gdb.dwarf2/per-bfd-sharing.exp: Likewise.

3 years agogdb/python: add a 'connection_num' attribute to Inferior objects
Tankut Baris Aktemur [Fri, 14 May 2021 09:56:31 +0000 (11:56 +0200)]
gdb/python: add a 'connection_num' attribute to Inferior objects

Define a 'connection_num' attribute for Inferior objects.  The
read-only attribute is the ID of the connection of an inferior, as
printed by "info inferiors".  In GDB's internal terminology, that's
the process stratum target of the inferior.  If the inferior has no
target connection, the attribute is None.

gdb/ChangeLog:
2021-05-14  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* python/py-inferior.c (infpy_get_connection_num): New function.
(inferior_object_getset): Add a new element for 'connection_num'.
* NEWS: Mention the 'connection_num' attribute of Inferior objects.

gdb/doc/ChangeLog:
2021-05-14  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* python.texi (Inferiors In Python): Mention the 'connection_num'
attribute.

gdb/testsuite/ChangeLog:
2021-05-14  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.python/py-inferior.exp: Add test cases for 'connection_num'.

3 years agogdb: some int to bool conversion in remote.c
Andrew Burgess [Tue, 11 May 2021 12:40:24 +0000 (13:40 +0100)]
gdb: some int to bool conversion in remote.c

Convert a couple of local variables from int to bool.  There should be
no user visible changes after this commit.

gdb/ChangeLog:

* remote.c (check_pending_events_prevent_wildcard_vcont): Change
argument type, update and re-wrap, header comment.
(remote_target::commit_resumed): Convert any_process_wildcard and
may_global_wildcard_vcont from int to bool.

3 years agoRISC-V: Check the overflow for %pcrel_lo addend more strictly.
Nelson Chu [Fri, 14 May 2021 05:30:02 +0000 (13:30 +0800)]
RISC-V: Check the overflow for %pcrel_lo addend more strictly.

The %pcrel_lo addend may causes the overflow, and need more than one
%pcrel_hi values.  But there may be only one auipc, shared by those
%pcrel_lo with addends.  However, the existing check method in the
riscv_resolve_pcrel_lo_relocs, may not be able to work for some
special/corner cases.

Consider the testcases pcrel-lo-addend-2b.  Before applying this patch,
I can compile it successfully.  But in fact the addend cause the value
of %pcrel_hi to be different.  This patch try to check the value of
%pcrel_hi directly, to make sure it won't be changed.  Otherwise, linker
will report the following errors,

(.text+0xa): dangerous relocation: %pcrel_lo overflow with an addend,
the value of %pcrel_hi is 0x1000 without any addend, but may be 0x2000
after adding the %pcrel_lo addend

The toolchain regressions, rv64gc-linux/rv64gc-elf/rv32gc-linux/rv32i-elf,
pass expectedly and looks fine.

bfd/
    * elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Check the values
    of %pcrel_hi, before and after adding the addend.  Make sure the
    value won't be changed, otherwise, report dangerous error.
ld/
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-2a.d: Renamed from
    pcrel-lo-addend-2.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-2a.s: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-2b.d: New testcase.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-2b.s: Likewise.

3 years agogdb: fix pretty printing max depth behaviour
Kent Cheung [Thu, 13 May 2021 14:42:20 +0000 (15:42 +0100)]
gdb: fix pretty printing max depth behaviour

The 'print max-depth' feature incorrectly causes GDB to skip printing
the string representation of pretty printed variables if the variable
is stored at a nested depth corresponding to the set max-depth value.
This change ensures that it is always printed before checking whether
the maximum print depth has been reached.

Regression tested with GCC 7.3.0 on x86_64, ppc64le, aarch64.

gdb/ChangeLog:

* cp-valprint.c (cp_print_value): Replaced duplicate code.
* guile/scm-pretty-print.c (ppscm_print_children): Check max_depth
just before printing child values.
(gdbscm_apply_val_pretty_printer): Don't check max_depth before
printing string representation.
* python/py-prettyprint.c (print_children): Check max_depth just
before printing child values.
(gdbpy_apply_val_pretty_printer): Don't check max_depth before
printing string representation.

gdb/testsuite/ChangeLog:

* gdb.python/py-format-string.c: Added a variable to test.
* gdb.python/py-format-string.exp: Check string representation is
printed at appropriate max_depth settings.
* gdb.python/py-nested-maps.exp: Likewise.
* gdb.guile/scm-pretty-print.exp: Add additional tests.

3 years agosim: callback: inline PTR define
Mike Frysinger [Sat, 24 Apr 2021 18:02:07 +0000 (14:02 -0400)]
sim: callback: inline PTR define

We require C11 now, so no need for these pre-ANSI C hacks.
PTR is simply void*, so use that directly.

3 years agosim: callback: use ATTRIBUTE_NORETURN
Mike Frysinger [Sat, 24 Apr 2021 17:58:04 +0000 (13:58 -0400)]
sim: callback: use ATTRIBUTE_NORETURN

This define is handled by ansidecl.h, so no need to duplicate effort.

3 years agosim: callback: always include necessary headers
Mike Frysinger [Sat, 24 Apr 2021 17:57:21 +0000 (13:57 -0400)]
sim: callback: always include necessary headers

We use types from these headers, so always include them.

3 years agosim: create header namespace
Mike Frysinger [Wed, 12 May 2021 04:35:54 +0000 (00:35 -0400)]
sim: create header namespace

The gdb/callback.h & gdb/remote-sim.h headers have nothing to do with
gdb and are really definitions for the libsim API under the sim/ tree.
While gdb uses those headers as a client, it's not specific to it.  So
create a new sim/ namespace and move the headers there.

3 years agogdb: lm32: drop unused sim headers
Mike Frysinger [Sat, 1 May 2021 16:48:08 +0000 (12:48 -0400)]
gdb: lm32: drop unused sim headers

Looks like these were copied & pasted as nothing from them are used.

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 14 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agogdb: maybe unpush target from old inferior in inf_child_target::follow_exec
Simon Marchi [Thu, 13 May 2021 19:28:42 +0000 (15:28 -0400)]
gdb: maybe unpush target from old inferior in inf_child_target::follow_exec

I realized that with "follow-exec-mode == new", the process target
stayed pushed in the original inferior.  This can cause a small
incoherence:

    $ ./gdb -q -nx --data-directory=data-directory -ex "set follow-exec-mode new" --args execer args-for-execer
    Reading symbols from execer...
    (gdb) r
    Starting program: /home/smarchi/build/binutils-gdb/gdb/execer args-for-execer
    I am execer and my argv[1] is: args-for-execer
    process 3562426 is executing new program: /home/smarchi/build/binutils-gdb/gdb/execee
    [New inferior 2]
    [New process 3562426]
    I am execee and my argv[1] is: arg-for-execee
    [Inferior 2 (process 3562426) exited normally]
    (gdb) info inferiors
      Num  Description       Connection           Executable
      1    <null>            1 (native)           /home/smarchi/build/binutils-gdb/gdb/execer
    * 2    <null>                                 /home/smarchi/build/binutils-gdb/gdb/execee
    (gdb) maintenance print target-stack
    The current target stack is:
      - exec (Local exec file)
      - None (None)
    (gdb) inferior 1
    [Switching to inferior 1 [<null>] (/home/smarchi/build/binutils-gdb/gdb/execer)]
    (gdb) maintenance print target-stack
    The current target stack is:
      - native (Native process)
      - exec (Local exec file)
      - None (None)

On exec, when execution continues into inferior 2, the native target
isn't unpushed from inferior 1.  When inferior 2's execution finishes
normally, inf_child_target::mourn_inferior unpushes the native target,
because the native target has been implicitly opened.

I think that if the native target was implicitly opened, it should be
unpushed from inferior 1, just like it is unpushed from an inferior
whose execution terminate.  This patch implements that.

gdb/ChangeLog:

* inf-child.h (inf_child_target) <follow_exec>: New.
* inf-child.c (inf_child_target::follow_exec): New.

Change-Id: I782cc08d73d93a990f4e53611107f68b2cb58af1

3 years agogdb: on exec, delegate pushing / unpushing target and adding thread to target_ops...
Simon Marchi [Thu, 13 May 2021 19:28:20 +0000 (15:28 -0400)]
gdb: on exec, delegate pushing / unpushing target and adding thread to target_ops::follow_exec

On "exec", some targets need to unpush themselves from the inferior,
and do some bookkeeping, like forgetting the data associated to the
exec'ing inferior.

One such example is the thread-db target.  It does so in
a special case in thread_db_target::wait, just before returning the
TARGET_WAITKIND_EXECD event to its caller.

We have another such case in the context of rocm-gdb [1], where the
"rocm" target is pushed on top of the linux-nat target.  When an exec
happens, we want to unpush the rocm target from the exec'ing inferior to
close some file descriptors that refer to the pre-exec address space and
forget about that inferior.  We then want to push the target on the
inferior in which execution continues, to open the file descriptors for
the post-exec address space.

I think that a good way to address this cleanly is to do all this in the
target_ops::follow_exec implementations.  Make the
process_stratum_target::follow_exec implementation have the default
behavior of pushing itself to the new inferior's target stack (if
execution continues in a new inferior) and add the initial thread.

remote_target::follow_exec is an example of process target that wants to
do a bit more than the default behavior.  So it calls
process_stratum_target::follow_exec first and does the extra work
second.

linux-thread-db (a non-process target) implements follow_exec to do some
bookeeping (forget about that process' data), before handing down the
event down to the process target (which hits
process_stratum_target::follow_exec).

gdb/ChangeLog:

* target.h (struct target_ops) <follow_exec>: Add ptid_t
parameter.
(target_follow_exec): Likewise.
* target.c (target_follow_exec): Add ptid_t parameter.
* infrun.c (follow_exec): Adjust call to target_follow_exec,
don't push target nor create thread.
* linux-thread-db.c (class thread_db_target) <follow_exec>: New.
(thread_db_target::wait): Just return on TARGET_WAITKIND_EXECD.
(thread_db_target::follow_exec): New.
* remote.c (class remote_target) <follow_exec>: Add ptid_t parameter.
(remote_target::follow_exec): Call
process_stratum_target::follow_exec.
* target-delegates.c: Re-generate.

Change-Id: I3f96d0ba3ea0dde6540b7e1b4d5cdb01635088c8

3 years agogdb: call target_follow_exec when "set follow-exec-mode" is "same"
Simon Marchi [Thu, 13 May 2021 19:27:55 +0000 (15:27 -0400)]
gdb: call target_follow_exec when "set follow-exec-mode" is "same"

target_follow_exec is currently only called in the "follow-exec-mode ==
new" branch of follow_exec, not the "follow-exec-mode == same" branch.
I think it would make sense to call it regardless of the mode to let
targets do some necessary handling.

This is needed in the context of rocm-gdb [1], where a target is pushed
on top of the linux-nat target.  On exec, it needs to do some
bookkeeping, close some file descriptors / handles that were related to
the process pre-exec and open some new ones for the process post-exec.

However, by looking at the only in-tree implementation of
target_ops::follow_exec, remote_target::follow_exec, I found that it
would be useful for the extended-remote target too, to align its
behavior with native debugging (although I think that behavior is not
very user-friendly, see PR 27745 [2]).

Using two programs, one (let's call it "execer") that execs the other
(let's call it "execee"), with native:

    $ ./gdb -q -nx --data-directory=data-directory ./execer
    Reading symbols from ./execer...
    (gdb) r
    Starting program: /home/simark/build/binutils-gdb/gdb/execer
    I am execer
    process 1495622 is executing new program: /home/simark/build/binutils-gdb/gdb/execee
    I am execee
    [Inferior 1 (process 1495622) exited normally]
    (gdb) r
    Starting program: /home/simark/build/binutils-gdb/gdb/execee
    I am execee
    [Inferior 1 (process 1495626) exited normally]

And now with gdbserver (some irrelevant output lines removed for brevity):

    $ ./gdbserver --once --multi :1234
    ...

    $ ./gdb -q -nx --data-directory=data-directory ./execer -ex "set remote exec-file /home/simark/build/binutils-gdb/gdb/execer" -ex "tar ext :1234"
    Reading symbols from ./execer...
    Remote debugging using :1234
    (gdb) r
    Starting program: /home/simark/build/binutils-gdb/gdb/execer
    process 1495724 is executing new program: /home/simark/build/binutils-gdb/gdb/execee
    [Inferior 1 (process 1495724) exited normally]
    (gdb) r
    `target:/home/simark/build/binutils-gdb/gdb/execee' has disappeared; keeping its symbols.
    Starting program: target:/home/simark/build/binutils-gdb/gdb/execee
    warning: Build ID mismatch between current exec-file target:/home/simark/build/binutils-gdb/gdb/execee
    and automatically determined exec-file target:/home/simark/build/binutils-gdb/gdb/execer
    exec-file-mismatch handling is currently "ask"
    Reading /home/simark/build/binutils-gdb/gdb/execer from remote target...
    Load new symbol table from "target:/home/simark/build/binutils-gdb/gdb/execer"? (y or n)

When handling the exec, GDB updates the exec-file of the inferior to be
the execee.  This means that a subsequent "run" will run the execee, not
the original executable (execer).

remote_target::follow_exec is meant to update the "remote exec-file",
which is the file on the remote system that will be executed if you
"run" the inferior, to the execee as well.  However, this is not called
when follow-exec-mode is same, because target_follow_exec is not called
in this branch.  As a result, GDB thinks the inferior is executing
execee but the remote side is really executing execer, hence the
mismatch message.

By calling target_follow_exec in the "same" branch of the follow_exec
function, we ensure that everybody agrees, and we get the same behavior
with the extended-remote target as we get with the native target, the
execee is executed on the second run:

    $ ./gdbserver --once --multi :1234
    ...

    $ ./gdb -q -nx --data-directory=data-directory ./execer -ex "set remote exec-file /home/simark/build/binutils-gdb/gdb/execer" -ex "tar ext :1234"
    Reading symbols from ./execer...
    Remote debugging using :1234
    (gdb) r
    Starting program: /home/simark/build/binutils-gdb/gdb/execer
    process 1501445 is executing new program: /home/simark/build/binutils-gdb/gdb/execee
    [Inferior 1 (process 1501445) exited normally]
    (gdb) r
    `target:/home/simark/build/binutils-gdb/gdb/execee' has disappeared; keeping its symbols.
    Starting program: target:/home/simark/build/binutils-gdb/gdb/execee
    [Inferior 1 (process 1501447) exited normally]
    (gdb)

This scenario is tested in gdb.base/foll-exec-mode.exp, and in fact this
patch fixes the test for me when using
--target_board=native-extended-gdbserver.

gdb/ChangeLog:

* infrun.c (follow_exec): Call target_follow_fork when
follow-exec-mode is same.
* target.h (target_follow_fork): Improve doc.

[1] https://github.com/ROCm-Developer-Tools/ROCgdb
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=27745

Change-Id: I4ee84a875e39bf3f8eaf3e6789a4bfe23a2a430e

3 years agogdb/testsuite: fix dates in last 3 ChangeLog entries
Andrew Burgess [Thu, 13 May 2021 16:58:49 +0000 (17:58 +0100)]
gdb/testsuite: fix dates in last 3 ChangeLog entries

Incorrect dates in last 3 ChangeLog entries for gdb/testsuite/ChangeLog.

3 years agogdb/testsuite: resolve remaining duplicate tests in gdb.guile/
Andrew Burgess [Thu, 13 May 2021 16:04:35 +0000 (17:04 +0100)]
gdb/testsuite: resolve remaining duplicate tests in gdb.guile/

The remaining duplicates are resolved by adding a with_test_prefix and
reindenting a proc.  I also added a couple of additional test names to
some of the tests.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-pretty-print.exp (run_lang_tests): Give some tests
unique names, also wrap proc body in with_test_prefix.

3 years agogdb/testsuite: resolve duplicate test names in gdb.guile/*.exp
Andrew Burgess [Thu, 13 May 2021 15:56:03 +0000 (16:56 +0100)]
gdb/testsuite: resolve duplicate test names in gdb.guile/*.exp

This commit resolves almost all of the remaining duplicate test names
in gdb.guile/*.exp.  This is done by either:

 - Making use of with_test_prefix,
 - Giving tests a unique name,
 - Extending the existing name to make it unique,
 - Not printing PASS lines for simple setup commands (e.g. loading
   support modules, or adjusting GDB internal settings not relating to
   guile).

gdb/testsuite/ChangeLog:

* gdb.guile/scm-frame-args.exp: Add with_test_prefix to resolve
duplicate test names.
* gdb.guile/scm-parameter.exp: Provide test names to avoid
duplicate names based on the command being run.
* gdb.guile/scm-symbol.exp: Extend test name to make it unique.
* gdb.guile/scm-type.exp (restart_gdb): Don't print PASS line when
loading a support module.
(test_equality): Update test name to match the actual test, making
the name unique in the process.
* gdb.guile/scm-value.exp (test_value_in_inferior): Add test names
to resolve duplicate tests.
(test_inferior_function_call): Likewise.
(test_subscript_regression): Likewise.

3 years agogdb/testsuite: remove some duplicate test names from guile tests
Andrew Burgess [Thu, 13 May 2021 15:50:28 +0000 (16:50 +0100)]
gdb/testsuite: remove some duplicate test names from guile tests

The guile support library has some "tests" that are actually being
used to setup GDB ready for the real guile tests, e.g. we load some
support modules, and define some helper functions.

As this setup is done every time we call gdb_guile_runto_main, which
could be called multiple times in a single test script, this can lead
to duplicate PASS lines.

As this setup is all pretty basic, and isn't the actual focus of the
real tests, then in this commit I pass an empty test name through to
the gdb_test_no_output calls, the result of this is that the PASS
lines are no longer printed.  This removes some duplicate tests from
the gdb.guile/*.exp set of tests.

gdb/testsuite/ChangeLog:

* lib/guile.exp (gdb_scm_load_file): Use empty test name to
silence PASS lines.
(gdb_install_guile_module): Likewise.

3 years agogdb: remove cmd_list_element::pre_show_hook
Simon Marchi [Thu, 13 May 2021 14:13:48 +0000 (10:13 -0400)]
gdb: remove cmd_list_element::pre_show_hook

This is unused, remove it.

gdb/ChangeLog:

* cli/cli-decode.h (struct cmd_list_element) <pre_show_hook>:
Remove.
* cli/cli-setshow.c (do_show_command): Adjust.

Change-Id: Ib9cd79d842550392b062309e1e5c079ad5d7571a

3 years agorevert previous delta
Nick Clifton [Thu, 13 May 2021 13:33:39 +0000 (14:33 +0100)]
revert previous delta

3 years agoFix an infinite loop in the DWARF decoder when parsing a corrupt string table.
Nick Clifton [Thu, 13 May 2021 13:31:09 +0000 (14:31 +0100)]
Fix an infinite loop in the DWARF decoder when parsing a corrupt string table.

PR 27861
* dwarf.c (display_debug_str_offsets): Warn if the length field is
larger than the amount of data remaining in the section.

3 years agoPR27861, Infinite loop in dwarf.c:7507-7526
Alan Modra [Thu, 13 May 2021 13:16:36 +0000 (22:46 +0930)]
PR27861, Infinite loop in dwarf.c:7507-7526

PR 27861
* dwarf.c (display_debug_str_offsets): Sanity check dwarf5
header length.

3 years agoPR27860, Segmentation fault on readelf -w
Alan Modra [Thu, 13 May 2021 12:52:45 +0000 (22:22 +0930)]
PR27860, Segmentation fault on readelf -w

Well it didn't take long for the SAFE_BYTE_GET assert to trigger.

PR 27860
* dwarf.c (display_debug_frames): Sanity check cie_off before
attempting to read cie.

3 years ago[AArch64] Fix off-by-one when calculating tag granules.
Luis Machado [Thu, 29 Apr 2021 18:10:06 +0000 (15:10 -0300)]
[AArch64] Fix off-by-one when calculating tag granules.

When we want to fetch tags from a memory range, the last address in that
range is not included.

There is a off-by-one error in aarch64_mte_get_tag_granules, which this
patch fixes.

gdb/ChangeLog:

2021-05-13  Luis Machado  <luis.machado@linaro.org>

* arch/aarch64-mte-linux.c (aarch64_mte_get_tag_granules): Don't
include the last address in the range.

3 years agoRISC-V: Record implicit subsets in a table, to avoid repeated codes.
Nelson Chu [Thu, 13 May 2021 03:48:26 +0000 (11:48 +0800)]
RISC-V: Record implicit subsets in a table, to avoid repeated codes.

Add a new table, riscv_implicit_subsets, to record all implicit information.
So that we add all implicit subsets according to the table, to avoid too
many repeated codes in the riscv_parse_add_implicit_subsets.  Besides, the
check_func is used to check whether we should add this implicit subset.
For example, check_implicit_for_i checks the version of i, and we only add
zicsr and zifencei implicitly only when the version less than 2.1.

bfd/
    * elfxx-riscv.c (check_implicit_always): The check_func, always add
    the implicit subset without checking.
    (check_implicit_for_i): The check_func for i, only add zicsr and
    zifencei when the version of i less than 2.1.
    (struct riscv_implicit_subset): Record the subsets and their
    corresponding implicit subsets.
    (riscv_implicit_subsets): Table records all implicit informations.
    (riscv_parse_add_implicit_subsets): Updated and add implicit subsets
    according to riscv_implicit_subsets.  Remove the redundant codes.

3 years agold: Add -Bno-symbolic
Fangrui Song [Wed, 12 May 2021 06:10:45 +0000 (23:10 -0700)]
ld: Add -Bno-symbolic

PR 27834
* ldlex.h (enum option_values): Add OPTION_NO_SYMBOLIC.
* lexsup.c (ld_options): Add -Bno-symbolic.
(parse_args): Handle -Bno-symbolic.
* ld.texi: Document -Bno-symbolic.
* NEWS: Mention -Bno-symbolic.
* testsuite/ld-elf/shared.exp: Add a test.

3 years agoPR27858, global-buffer-overflow
Alan Modra [Thu, 13 May 2021 00:41:20 +0000 (10:11 +0930)]
PR27858, global-buffer-overflow

PR 27858
* elf32-sh.c (sh_elf_info_to_howto): Correct check for last valid
reloc howto.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 13 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agogdb: make gdbpy_parse_command_name return a unique_xmalloc_ptr
Simon Marchi [Wed, 12 May 2021 17:50:05 +0000 (13:50 -0400)]
gdb: make gdbpy_parse_command_name return a unique_xmalloc_ptr

This avoids some manual memory management.

cmdpy_init correctly transfers ownership of the name to the
cmd_list_element, as it sets the name_allocated flag.  However,
cmdpy_init (and add_setshow_generic) doesn't, it looks like the name is
just leaked.  This is a bit tricky, because it actually creates two
commands (one set and one show), it would take a bit of refactoring of
the command code to give each their own allocated copy.  For now, just
keep doing what the current code does but in a more explicit fashion,
with an explicit release.

gdb/ChangeLog:

* python/python-internal.h (gdbpy_parse_command_name): Return
gdb::unique_xmalloc_ptr.
* python/py-cmd.c (gdbpy_parse_command_name): Likewise.
(cmdpy_init): Adjust.
* python/py-param.c (parmpy_init): Adjust.
(add_setshow_generic): Take gdb::unique_xmalloc_ptr, release it
when done.

Change-Id: Iae5bc21fe2b22f12d5f954057b0aca7ca4cd3f0d

3 years agoRevert "[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()"
Tom de Vries [Wed, 12 May 2021 14:03:02 +0000 (16:03 +0200)]
Revert "[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()"

This reverts commit 4cf88725da1cb503be04d3237354105ec170bc86.

It causes the following regression:
...
$ cat shadow.cc
namespace A {}

int
main()
{
  using namespace A;
  return 0;
}
$ g++-10 -g shadow.cc -flto -o shadow
$ ./gdb -q -batch ./shadow  -ex "b main"
Aborted (core dumped)
...

3 years agoEnsure data pointer kept within bounds
Alan Modra [Wed, 12 May 2021 07:57:34 +0000 (17:27 +0930)]
Ensure data pointer kept within bounds

* dwarf.c (process_extended_line_op): Don't bump data pointer past
end when strnlen doesn't find string terminator.
(decode_location_expression): Remove dead code.
(skip_attr_bytes): Remove const from end param.  Ensure data
pointer doesn't pass end.
(get_type_signedness): Remove const from end param.
(read_and_display_attr_value): Ensure data pointer doesn't pass end.
(display_debug_lines_raw, display_debug_lines_decoded): Likewise.
(display_debug_pubnames_worker): Likewise.
(display_debug_pubnames_worker): Use SAFE_BYTE_GET_AND INC rather
than blindly incrementing data pointer.
(display_debug_addr, display_debug_str_offsets): Likewise.  Don't
compare pointers, compare lengths.

3 years agoSAFE_BYTE_GET
Alan Modra [Wed, 12 May 2021 03:21:52 +0000 (12:51 +0930)]
SAFE_BYTE_GET

This rearranges SAFE_BYTE_GET* macros, eliminating some duplication,
and making sure that the _INC variants never increment their PTR arg
past END.  I've added an assertion that should show us places where we
use them improperly with user derived PTR args, which I'm sure the
fuzzers will find for us.

* dwarf.c (SAFE_BYTE_GET_INTERNAL): Define.
(SAFE_BYTE_GET, SAFE_BYTE_GET_AND_INC): Define using the above.
(SAFE_SIGNED_BYTE_GET, SAFE_SIGNED_BYTE_GET_AND_INC): Likewise.
(display_discr_list): Use SAFE_BYTE_GET_AND_INC rather than
SAFE_BYTE_GET followed by increment.
(process_debug_info): Likewise, and test bytes remaining before
incrementing section_begin rather than using pointer comparison.
(display_debug_names): Pass lvalue as SAFE_BYTE_GET PTR.
(process_cu_tu_index): Likewise for SAFE_BYTE_GET_AND_INC.

3 years agoSAFE_BYTE_GET64
Alan Modra [Wed, 12 May 2021 08:18:13 +0000 (17:48 +0930)]
SAFE_BYTE_GET64

Functions dealing with lack of a 64-bit integer type can disappear now
that we require C99.  Printing using dwarf_vmatoa is better too.

binutils/
* dwarf.c (dwarf_vmatoa64, SAFE_BYTE_GET64, add64): Delete.
(skip_attr_bytes): Replace use of SAFE_BYTE_GET64 with
SAFE_BYTE_GET_AND_INC.
(read_and_display_attr_value): Likewise.  Print using dwarf_vmatoa.
(process_debug_info, process_cu_tu_index): Likewise.
* elfcomm.c (byte_put, byte_put_little_endian, byte_put_big_endian),
(byte_get, byte_get_little_endian, byte_get_big_endian),
(byte_get_signed): Make size param unsigned.  Remove code dealing
with 4-byte elf_vma.
(byte_get_64): Delete.
* elfcomm.h  (byte_put, byte_put_little_endian, byte_put_big_endian),
(byte_get, byte_get_little_endian, byte_get_big_endian),
(byte_get_signed): Update prototypes.
(byte_get_64): Delete.
gas/
* testsuite/gas/elf/dwarf-5-file0.d: Update.
* testsuite/gas/i386/dwarf5-line-1.d: Update.