GDB Administrator [Thu, 20 May 2021 00:00:44 +0000 (00:00 +0000)]
Automatic date update in version.in
John Baldwin [Wed, 19 May 2021 18:46:02 +0000 (11:46 -0700)]
Mark tu_abbrev_offset::operator<() const.
clang 11 with libc++'s <algorithm> fails to match the existing
operator<() for std::less<> since the method is not marked const.
gdb/ChangeLog:
* dwarf2/read.c (tu_abbrev_offset::operator<): Mark const.
Tom de Vries [Wed, 19 May 2021 17:08:53 +0000 (19:08 +0200)]
sim: ppc: fix some Wenum-compare warnings
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
src/sim/ppc/hw_phb.c: In function 'hw_phb_attach_address':
src/sim/ppc/hw_phb.c:315:12: error: comparison between \
'attach_type {aka enum _attach_type}' and \
'enum <anonymous>' [-Werror=enum-compare]
if (type != hw_phb_normal_decode
^~
...
Fix this by casting type to hw_phb_decode.
Tom de Vries [Wed, 19 May 2021 16:42:59 +0000 (18:42 +0200)]
sim: ppc: fix Wnonnull warning
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
src/sim/ppc/emul_netbsd.c: In function 'do_gettimeofday':
src/sim/ppc/emul_netbsd.c:770:16: error: null argument where non-null \
required (argument 1) [-Werror=nonnull]
int status = gettimeofday((t_addr != 0 ? &t : NULL),
^~~~~~~~~~~~
...
Fix this by unconditionally passing &t as first argument.
Marco Barisione [Wed, 19 May 2021 15:48:05 +0000 (16:48 +0100)]
gdb: Move definitions of std::string overloads in ui_out to the header
These methods are just trivial wrappers around the versions accepting
a char pointer. By moving them to the header the compiler can inline
them.
gdb/ChangeLog:
* ui-out.c (ui_out::field_string): Move to ui-out.h.
(ui_out::text): Ditto.
* ui-out.h (class ui_out): Add definitions of
ui_out::field_string and ui_out::text which were previously
defined in ui-out.c.
Tom de Vries [Wed, 19 May 2021 15:46:24 +0000 (17:46 +0200)]
sim: ppc: fix some more Wunused-function warnings
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
In file included from src/sim/ppc/cpu.h:26:0,
from src/sim/ppc/mon.c:25,
from src/sim/ppc/inline.c:64,
from idecode.c:26:
src/sim/ppc/device.h:788:8: error: 'device_event_queue_deschedule' \
declared 'static' but never defined [-Werror=unused-function]
(void) device_event_queue_deschedule
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
This seems to be caused by the fact that the function is declared using
INLINE_EVENT instead of INLINE_DEVICE.
Fix this and a similar error in the same file.
Tom de Vries [Wed, 19 May 2021 15:46:24 +0000 (17:46 +0200)]
sim: ppc: fix some Wunused-function warnings
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
In file included from src/sim/ppc/cpu.h:251:0,
from src/sim/ppc/emul_generic.h:24,
from src/sim/ppc/emul_generic.c:24:
src/sim/ppc/cpu.c:76:1: error: 'cpu_create' defined but not used \
[-Werror=unused-function]
cpu_create(psim *system,
^~~~~~~~~~
...
The function is defined as:
...
INLINE_CPU\
(cpu *)
cpu_create(psim *system,
...
which expands to:
...
static cpu * __attribute__((__unused__))
cpu_create(psim *system,
...
The problem is that gcc does not associate the attribute to the function.
I've filed a PR about this ( PR gcc/100670 ), which may or may not be valid.
Work around/fix this by modifying the INLINE_* definitions in inline.h to move
UNUSED to the start such that we have:
...
__attribute__((__unused__)) static cpu *
cpu_create(psim *system,
...
John David Anglin [Wed, 19 May 2021 15:27:28 +0000 (15:27 +0000)]
Fix offset for ia64 PCREL60B relocation on HP-UX
gas/ChangeLog:
2021-05-19 John Buddery <jvb@cyberscience.com>
PR 25599
* config/tc-ia64.c (emit_one_bundle): Increment fixup offset
by one for PCREL60B relocation on HP-UX.
Marco Barisione [Wed, 19 May 2021 12:58:41 +0000 (13:58 +0100)]
gdb: Pass std::strings to ui_out::field_string () where convenient
While adding a ui_out::text () overload accepting a std::string, I
noticed that several callers of ui_out::field_string () were converting
std::string instances to char pointers even if not necessary.
gdb/ChangeLog:
* ui-out.c (ui_out::field_string): Add missing style_argument
to the overload accepting a std::string, to make it equivalent
to the char pointer version.
* ui-out.h (class ui_out): Ditto.
* break-catch-sig.c (signal_catchpoint_print_one): Do not
convert std::strings to char pointers before passing them to
ui_out::field_string ().
* break-catch-throw.c (print_one_detail_exception_catchpoint):
Ditto.
* cli/cli-setshow.c (do_show_command): Ditto.
* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
Ditto.
* infcmd.c (print_return_value_1): Ditto.
* inferior.c (print_inferior): Ditto.
* linux-thread-db.c (info_auto_load_libthread_db): Ditto.
* mi/mi-cmd-var.c (print_varobj): Ditto.
(mi_cmd_var_set_format): Ditto.
(mi_cmd_var_info_type): Ditto.
(mi_cmd_var_info_expression): Ditto.
(mi_cmd_var_evaluate_expression): Ditto.
(mi_cmd_var_assign): Ditto.
(varobj_update_one): Ditto.
* mi/mi-main.c (list_available_thread_groups): Ditto.
(mi_cmd_data_read_memory_bytes): Ditto.
(mi_cmd_trace_frame_collected): Ditto.
* osdata.c (info_osdata): Ditto.
* probe.c (info_probes_for_spops): Ditto.
* target-connection.c (print_connection): Ditto.
* thread.c (print_thread_info_1): Ditto.
* tracepoint.c (print_one_static_tracepoint_marker): Ditto.
Marco Barisione [Wed, 19 May 2021 12:58:40 +0000 (13:58 +0100)]
gdb: Add an overloaded ui_out::text accepting a const std::string &
gdb/ChangeLog:
* ui-out.h (class ui_out): Add ui_out::text accepting a constant
reference to a std::string. Fix all callers using
std::string::c_str.
* ui-out.c (ui_out::text): Ditto.
Andrew Burgess [Wed, 19 May 2021 12:39:27 +0000 (13:39 +0100)]
gdb/testsuite: resolve duplicate test names in gdb.guile/*.exp
This commit:
commit
ecf25064e87a3d2d59871b3ea7126fa0dee0001d
Date: Thu May 13 15:42:20 2021 +0100
gdb: fix pretty printing max depth behaviour
Introduced a couple of duplicate tests, this commit resolves them by
providing unique test names.
gdb/testsuite/ChangeLog:
* gdb.guile/scm-pretty-print.exp: Add test names to resolve
duplicate test names.
Tom de Vries [Wed, 19 May 2021 12:02:08 +0000 (14:02 +0200)]
[gdb/testsuite] Fix read1 timeout in gdb.base/info-types-c++.exp
When running test-case gdb.base/info-types-c++.exp with check-read1 I run
into:
...
425: typedef const void * std::allocator_traits<std::allocator<std::\
_Sp_counted_ptr_inplace<std::filesystem::__cxx11::\
recursive_directory_iterator::_Dir_stack, std::allocator<std::filesystem::\
__cxx11::recursive_directory_iterator::_Dir_stack>, \
FAIL: gdb.base/info-types-c++.exp: info types (timeout)
...
The corresponding gdb_test_multiple does contain an exp_continue which
resets the timeout counter every time info for another file is printed, but
this doesn't help for this timeout because it times out during printing info
for a single file.
Fix this by processing line-by-line.
Tested on x86_64-linux, both with gcc-7.5.0 and gcc-4.8.5 (the latter is
different because the "unsigned int" type is missing).
gdb/testsuite/ChangeLog:
2021-05-19 Tom de Vries <tdevries@suse.de>
* gdb.base/info-types.exp.tcl: Scan info types output line-by-line.
Eli Schwartz [Wed, 19 May 2021 11:08:30 +0000 (12:08 +0100)]
Fix a build problem if ENABLE_CHECKING is not defined.
* dwarf.c (ENABLE_CHECKING): Define to 0 if not previously set.
Nick Clifton [Wed, 19 May 2021 10:53:23 +0000 (11:53 +0100)]
Warn when the plugin interface runs out of file descriptors.
* plugin.c (bfd_plugin_open_input): Inform the user if the limit
on the number of open files is reached. If possible, try to
increase this limit before failing.
Alexandra Hájková [Tue, 11 May 2021 07:47:42 +0000 (09:47 +0200)]
inflow.c: Do not leak tty.
In a case open() returns 0 tty might be leaked. While 0 should be
stdin (and therefore is an unlikely return value from open()), it's
still the case that the test should be for non-negative return values
from open().
gdb/ChangeLog:
2021-05-11 Alexandra Hájková <ahajkova@redhat.com>
* inflow.c (new_tty): Do not leak tty.
Alan Modra [Tue, 18 May 2021 14:11:10 +0000 (23:41 +0930)]
PR27884, skip_attr_bytes: Assertion (data) <= (end) failed
PR 27884
* dwarf.c (get_type_abbrev_from_form): Replace cu_offset_return
param with map_return, and return map for DW_FORM_ref_addr.
(get_type_signedness): Adjust calls to get_type_abbrev_from_form.
Pass returned cu map start and end to recursive call.
(read_and_display_attr_value): Similarly.
Alan Modra [Tue, 18 May 2021 14:09:35 +0000 (23:39 +0930)]
PR27879, stack-buffer-overflow on sysdump
PR 27879
* sysdump.c (getBARRAY): Sanity check size against max.
(getINT): Avoid UB shift left.
GDB Administrator [Wed, 19 May 2021 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in
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.
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.
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.
GDB Administrator [Tue, 18 May 2021 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in
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.
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.
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.
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.
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.
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.
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.
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]'.
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.
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.
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
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
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
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
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
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
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
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
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
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).
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.
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.
Mike Frysinger [Thu, 13 May 2021 09:44:02 +0000 (05:44 -0400)]
sim: riscv: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 03:46:34 +0000 (22:46 -0500)]
sim: h8300: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 03:40:43 +0000 (22:40 -0500)]
sim: mips: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 03:34:05 +0000 (22:34 -0500)]
sim: avr: invert sim_state storage
Mike Frysinger [Fri, 22 Jan 2016 02:13:06 +0000 (21:13 -0500)]
sim: cgen: invert sim_state storage for cgen ports
Mike Frysinger [Fri, 22 Jan 2016 02:05:33 +0000 (21:05 -0500)]
sim: bfin: 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.
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!
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.
GDB Administrator [Mon, 17 May 2021 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in
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.
Mike Frysinger [Sun, 16 May 2021 03:50:33 +0000 (23:50 -0400)]
sim: riscv: move __int128 check to configure
GDB Administrator [Sun, 16 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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_.
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.
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.
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.
GDB Administrator [Sat, 15 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in
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.
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.
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'.
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.
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.
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.
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.
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.
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.
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.
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.
GDB Administrator [Fri, 14 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in
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
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
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
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.
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.