Mike Frysinger [Tue, 4 May 2021 03:27:16 +0000 (23:27 -0400)]
sim: clean up bfd_vma printing
A lot of this code predates the bfd_vma format define, so we have a
random mix of casts to known types so we can printf the value. Use
the BFD_VMA_FMT that now exists to simplify and reliability output
across different build configs.
Tom de Vries [Tue, 4 May 2021 08:26:16 +0000 (10:26 +0200)]
[gdb/guile] Don't allow libguile to change libgmp mem fns
Since gdb commit
880ae75a2b7 "gdb delay guile initialization until
gdbscm_finish_initialization" I'm running into:
...
(gdb) print My_Var > 10.0^M
free(): invalid pointer^M
ERROR: GDB process no longer exists
GDB process exited with wait status 5995 exp9 0 0 CHILDKILLED SIGABRT SIGABRT
UNRESOLVED: gdb.ada/fixed_cmp.exp: gnat_encodings=all: print My_Var > 10.0
...
The problem is that both gdb and libguile try to set the libgmp memory functions,
and since the gdb commit the ones from libguile are effective, which results
in gdb freeing some memory in a way that is not compatible with the way that
memory was actually allocated.
The fact that libguile tries to set the libgmp memory functions is a bug which
should be fixed starting version v3.0.6.
Meanwhile, work around this in gdb by not allowing libguile to set the libgomp
memory functions.
Tested on x86_64-linux.
gdb/ChangeLog:
2021-05-04 Tom de Vries <tdevries@suse.de>
PR guile/27806
* guile/guile.c (gdbscm_initialize): Don't let guile change libgmp
memory functions.
GDB Administrator [Tue, 4 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in
Jim Wilson [Mon, 3 May 2021 23:19:17 +0000 (16:19 -0700)]
RISC-V: PR27764, Add tests for A extension
ChangeLog entry for last patch.
Christoph Muellner [Wed, 21 Apr 2021 22:28:27 +0000 (00:28 +0200)]
RISC-V: PR27764, Add tests for A extension
gas/
PR 27764
* testsuite/gas/riscv/a-ext-64.d: New testcase.
* testsuite/gas/riscv/a-ext-64.s: Likewise.
* testsuite/gas/riscv/a-ext.d: Likewise.
* testsuite/gas/riscv/a-ext.s: Likewise.
Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
Tom Tromey [Mon, 3 May 2021 14:57:46 +0000 (08:57 -0600)]
Fix x86_64 mingw build
PR build/27807 points out that my recent changes to the Windows port
missed a spot in win32-i386-low.cc -- a call to
win32_Wow64GetThreadContext remained, causing link errors in
gdbserver. This happened because I tested an i686 build, but this
code is only used on an x86_64 build.
This patch fixes the bug. I am checking it in.
gdbserver/ChangeLog
2021-05-03 Tom Tromey <tromey@adacore.com>
PR build/27807:
* win32-i386-low.cc (i386_get_thread_context): Call
Wow64GetThreadContext, not win32_Wow64GetThreadContext.
Simon Marchi [Mon, 3 May 2021 14:54:08 +0000 (10:54 -0400)]
sim: add ATTRIBUTE_PRINTF / ATTRIBUTE_NULL_PRINTF where necessary
I finally got the all-targets sim building with Clang, these are all the
instances where an ATTRIBUTE_PRINTF or ATTRIBUTE_NULL_PRINTF attribute
needed to be added to avoid errors like:
/home/simark/src/binutils-gdb/sim/aarch64/../common/sim-profile.c:464:19: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
vfprintf (fp, fmt, ap);
^~~
There are more fixes needed to get everything building, but adding these
attributes is trivial enough, so I send them all in a single patch.
Adding the format attributes introduces some format string errors when
building with GCC (because now format strings are checked), so
corresponding changes are needed to avoid breaking the build. Other
than simple format string specified changes, there is this one:
/home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c: In function 'hw_event_queue_schedule':
/home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c:95:15: error: too many arguments for format [-Werror=format-extra-args]
95 | NULL, dummy);
| ^~~~~
We can fix it and avoid using a dummy variable by simply calling
hw_event_queue_schedule_tracef instead of
hw_event_queue_schedule_vtracef.
sim/arm/ChangeLog:
* armdefs.h (ARMul_ConsolePrint): Use format attribute.
* wrapper.c (op_printf): Likewise.
sim/bfin/ChangeLog:
* interp.c (sim_open): Adjust format string specifier.
sim/common/ChangeLog:
* hw-events.h (hw_event_queue_schedule_tracef): Use format attribute.
(hw_event_queue_schedule_vtracef): Likewise.
* hw-tree.h (hw_tree_vparse): Likewise.
* sim-profile.c (profile_vprintf): Likewise.
* sim-trace.c (dis_printf): Likewise.
* sim-trace.h (trace_printf): Likewise.
(trace_vprintf): Likewise.
* sim-utils.h (sim_do_commandf): Likewise.
* hw-events.c (hw_event_queue_schedule): Use
hw_event_queue_schedule_tracef.
sim/rx/ChangeLog:
* trace.c (op_printf): Likewise.
sim/v850/ChangeLog:
* interp.c (sim_open): Adjust format string specifier.
Change-Id: I1445115ce57db15bb8e35dca93014555e7555794
Jan Beulich [Mon, 3 May 2021 11:28:30 +0000 (13:28 +0200)]
x86: allow @secrel32 also in data definitions
Now that lex_got() is uniform for all targets using it, permit COFF
targets to also use @secrel32 with, in particular, .long. This is more
natural than the custom .secrel32 directive, and also allows more
flexibility (the "+six" form of the two added test lines doesn't work
with a .secrel32 equivalent, in that it silently produces an unintended
relocation type).
As an extra benefit this also makes sure that data definitions in Intel
syntax mode would get treated like they do for e.g. ELF targets.
Jan Beulich [Mon, 3 May 2021 11:27:47 +0000 (13:27 +0200)]
x86: use UNIX EOL in secrel testcase
For some reason these were using Windows EOL.
Jan Beulich [Mon, 3 May 2021 11:26:41 +0000 (13:26 +0200)]
x86: fold both instances of lex_got()
I see no reason at all for us to carry two copies of almost identical
code. The differences, apart from the table entries, are benign. And
the #ifdef-ary doesn't really get any worse.
Jan Beulich [Mon, 3 May 2021 11:25:12 +0000 (13:25 +0200)]
x86: don't request useless overflow checking
Relocations with a bitsize matching the architecture's address width
can't usefully use an overflow checking approach other than "dont" or
"signed": All others involve perhaps complex calculations in
_bfd_relocate_contents() (or, not as severe, in bfd_check_overflow())
without ever finding anything to complain about - because of the address
width masking applied. Avoid this unnecessary overhead and switch all
such reloc types to "dont".
Note that "signed" checking with rela relocations (i.e. x86-64 here) is
only going to be useful if the addend actually got passed to
_bfd_relocate_contents() (and maybe others) instead of bogusly adding in
prior section contents (which apparently is assumed to be zero, and
hence again no overflow would ever be detected). See
https://sourceware.org/pipermail/binutils/2021-April/116164.html.
Andrew Burgess [Thu, 29 Apr 2021 09:11:35 +0000 (10:11 +0100)]
gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp
The test gdb.python/py-startup-opt.exp checks the behaviour of GDB's:
set python dont-write-bytecode on
This flag (when on) stops Python creating .pyc files. The test first
checks that .pyc files will be created, then turns this option on and
checks .pyc files will not be created.
However, if the user has PYTHONDONTWRITEBYTECODE set in their
environment then this will prevent Python from creating .pyc files, as
such the first test, that .pyc files are being created, currently
fails.
We could unset PYTHONDONTWRITEBYTECODE, however, until Python 3.8
there is no way to control where Python writes the .pyc files. As the
GDB developer clearly doesn't want .pyc files created in their
file-system it feels wrong to silently unset this environment
variable.
My proposal then, is that we just spot when this environment variable
is set and adjust the expected results. My hope is that across all
GDB developers some will be running with PYTHONDONTWRITEBYTECODE
unset, so this feature will be fully tested at least some of the time.
gdb/testsuite/ChangeLog:
PR testsuite/27788
* gdb.python/py-startup-opt.exp (test_python_settings): Change the
expected results when environment variable PYTHONDONTWRITEBYTECODE
is set.
Alan Modra [Mon, 3 May 2021 02:58:46 +0000 (12:28 +0930)]
PPC: undefweak dynamic relocs
This makes the default for ppc to keep dynamic relocs on undefweak
symbols when the code won't cause DT_TEXTREL (for instance when -fPIE
or -fPIC). If ld is given -z dynamic-undefined-weak then dynamic
relocations will be created for non-PIC at the expense of possibly
causing DT_TEXTREL to be set on ppc32. Note that DT_TEXTREL and GNU
indirect functions are incompatible.
* elf32-ppc.c (allocate_dynrelocs): Keep dyn_relocs for undefweak
symbols when -z dynamic-undefined-weak or when there are no
dynamic relocs in read-only sections and -z nodynamic-undefined-weak
is not given.
* elf64-ppc.c (allocate_dynrelocs): Likewise.
Alan Modra [Mon, 3 May 2021 00:33:06 +0000 (10:03 +0930)]
PPC: ensure_undef_dynamic on weak undef only in plt
It's slightly weird to have a call to a weak function not protected by
a test of that function being non-NULL, but the non-NULL test might be
covered by a test of another function. For example:
if (func1)
{
func1 ();
func2 ();
}
where func2 is known to exist if func1 exists.
* elf32-ppc.c (allocate_dynrelocs): Call ensure_undef_dynamic for
weak undefined symols that only appear on PLT relocs.
* elf64-ppc.c (allocate_dynrelocs): Likewise.
Alan Modra [Mon, 3 May 2021 04:07:00 +0000 (13:37 +0930)]
PR27755, powerpc-ld infinite loop
PR 27755
* elf32-ppc.c (ppc_elf_inline_plt): Do increment rel in loop.
Alan Modra [Sun, 2 May 2021 22:27:39 +0000 (07:57 +0930)]
csky: fix annobin test fails
* elf32-csky.c (is_mapping_symbol_name): New function.
(csky_elf_is_target_special_symbol): Likewise.
(csky_elf_maybe_function_sym): Likewise.
(bfd_elf32_bfd_is_target_special_symbol): Define.
(elf_backend_maybe_function_sym): Define.
Alan Modra [Sun, 2 May 2021 22:20:03 +0000 (07:50 +0930)]
testsuite: Don't start directives in first column
Fixes fails on hppa64-hp-hpux11.23
* testsuite/gas/elf/section25.s: Don't start directives in first
column.
* testsuite/gas/elf/section26.s: Likewise.
Alan Modra [Sun, 2 May 2021 22:14:23 +0000 (07:44 +0930)]
Re: section symbols without a name
commit
23356397449 changed this file but missed one place.
* testsuite/ld-s390/tlspic_64.rd: Adjust expected output for
named section symbols.
GDB Administrator [Mon, 3 May 2021 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in
Simon Marchi [Sun, 2 May 2021 15:04:58 +0000 (11:04 -0400)]
sim: add default cases to two switches in sim-options.c
This is the next compilation error I hit when I build all targets with
Clang:
/home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:234:12: error: no case matching constant switch condition '0' [-Werror] switch (WITH_ENVIRONMENT)
^~~~~~~~~~~~~~~~ ./config.h:215:26: note: expanded from macro 'WITH_ENVIRONMENT'
#define WITH_ENVIRONMENT ALL_ENVIRONMENT ^~~~~~~~~~~~~~~
/home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:276:15: error: no case matching constant switch condition '0' [-Werror] switch (WITH_ALIGNMENT)
^~~~~~~~~~~~~~ /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-config.h:220:24: note: expanded from macro 'WITH_ALIGNMENT'
#define WITH_ALIGNMENT 0
^
This is a little bit special because these are switches on compile-time
value. But regardless, the idea is that we logically can't reach the
switches if WITH_ENVIRONMENT == 0 or WITH_ALIGNMENT == 0, so the code is
correct.
In addition to getting rid of the compiler warning, adding default cases
to these switches ensure that if we do get in an unexpected situation,
it is caught. In GDB, I'd use gdb_assert_not_reached, I don't know if
there is something similar in sim so I went with abort.
sim/common/ChangeLog:
* sim-options.c (standard_option_handler): Add default cases to
switches.
Change-Id: Ie237d67a201caa6b72de0d17cc815193417156b6
Mike Frysinger [Sun, 2 May 2021 04:07:21 +0000 (00:07 -0400)]
sim: replace custom attributes with ansidecl.h
A lot of this code predates the common attributes. We had already
started migrating over piece by piece, so just do a pass across all
the attributes and replace most of them.
Mike Frysinger [Sat, 2 Jan 2016 15:54:42 +0000 (10:54 -0500)]
sim: bfin: move option inits to respective modules
Now that modules can self declare their own init funcs, change the mmu
and mach logic to use it. We don't need to export the option symbols
or specifically call this logic from the sim_open function anymore.
Mike Frysinger [Sun, 2 May 2021 03:04:01 +0000 (23:04 -0400)]
sim: options: fix --help output
The hash table rewrite broke --help output due to subtle behavior:
calling dup_arg_p(NULL) will create & clear the table, not just
create it. The --help output relies on this to clear the table
before it shows things.
Mike Frysinger [Sat, 2 Jan 2016 15:53:03 +0000 (10:53 -0500)]
sim: dv-sockser: localize init callback
Now that we don't need to hardcode the module init list in a single
place, move the dv-sockser logic to the place to the one file.
Mike Frysinger [Sun, 2 May 2021 01:16:17 +0000 (21:16 -0400)]
sim: mips: mark local func static
Mike Frysinger [Sat, 2 Jan 2016 15:50:46 +0000 (10:50 -0500)]
sim: add framework for declaring init callbacks locally
To facilitate decentralized module initialization/registration with an
eye towards multi-target support, add a framework to detect init calls
declared in the source and automatically call them. This is akin to
gdb's _initialize_xxx framework for letting modules autodiscover.
GDB Administrator [Sun, 2 May 2021 00:00:30 +0000 (00:00 +0000)]
Automatic date update in version.in
Mike Frysinger [Sat, 1 May 2021 20:30:59 +0000 (16:30 -0400)]
sim: nrun: add local strsignal prototype
While libiberty provides a definition for this for systems that lack
the function (e.g. Windows), it doesn't provide a prototype. So add
our own local copy in the one file that uses the func.
Mike Frysinger [Sat, 1 May 2021 20:03:10 +0000 (16:03 -0400)]
sim: rx: cast bfd_vma when printing
A bit of a hack, but it's what we've been doing so far when printing
bfd_vma's since bfd doesn't provide PRI helper types for us to use.
Mike Frysinger [Sat, 1 May 2021 19:58:09 +0000 (15:58 -0400)]
sim: riscv: fix building on 32-bit hosts w/out int128
Check for __SIZEOF_INT128__ before trying to use the builtin type.
This fixes building on some 32-bit systems like x86.
Mike Frysinger [Sat, 1 May 2021 19:54:33 +0000 (15:54 -0400)]
sim: aarch64: use PRIx64 for formatting 64-bit types
We can't assume that %lx is big enough for 64-bit types as it isn't on
most 32-bit builds. Use the standard format define for this instead.
Mike Frysinger [Sat, 1 May 2021 19:51:37 +0000 (15:51 -0400)]
sim: aarch64: fix 64-bit immediate shifts
Trying to shift immediates 63 bits fails on 32-bit systems since UL
is only 32-bits, not 64-bits. Switch to ULL to guarantee at least
64-bits here.
Mike Frysinger [Sat, 24 Apr 2021 16:51:46 +0000 (12:51 -0400)]
sim: arm: move build logic to source files
This simplifies the build logic a bit by just having source file
inputs. It also simplifies code that assumes there's a source
file for each object.
Mike Frysinger [Sat, 24 Apr 2021 18:28:17 +0000 (14:28 -0400)]
sim: callback: inline wrap helper
This is annoying as it requires inlining boiler plate, but we don't
have much choice: the wrap helper assumes the return value is always
an int, but that's already not the case with some of the callbacks
which use long. GCC has extensions to define macros-as-functions,
but we can't assume GCC.
Max Filippov [Sat, 1 May 2021 09:22:19 +0000 (02:22 -0700)]
opcodes: xtensa: support branch visualization
2021-05-01 Max Filippov <jcmvbkbc@gmail.com>
opcodes/
* xtensa-dis.c (print_insn_xtensa): Fill in info->insn_type and
info->insn_info_valid.
GDB Administrator [Sat, 1 May 2021 00:00:31 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Fri, 30 Apr 2021 20:07:58 +0000 (14:07 -0600)]
Do not separately read type units
Currently, the DWARF reader has a separate pass to read type units --
create_all_type_units. While working on other patches, I discovered
that this caused DWARF 5 type units to be read twice, once by
create_all_comp_units and once by create_all_type_units.
There's no need any more (if there ever was) to treat type units
differently from CUs. So, this patch removes create_all_type_units
and unifies the code paths.
Note that the DWO code still has a second pass. I haven't looked into
this code yet; perhaps it can also be simplified.
Regression tested using the debug-types board file on x86-64 Fedora 32.
gdb/ChangeLog
2021-04-30 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (dwarf2_initialize_objfile): Update.
(add_signatured_type_cu_to_table): Remove.
(create_debug_type_hash_table): Assume dwo_file is non-null.
(create_debug_types_hash_table): Update comment.
(create_all_type_units): Remove.
(sort_tu_by_abbrev_offset): Update comment.
(build_type_psymtabs): Rename from build_type_psymtabs_1.
(build_type_psymtabs): Remove.
(process_skeletonless_type_unit, dwarf2_build_psymtabs_hard):
Update.
(read_comp_units_from_section): Add types_htab, section_kind
parameters.
(create_all_comp_units): Read type units.
Tom Tromey [Fri, 30 Apr 2021 20:07:58 +0000 (14:07 -0600)]
Remove dwarf2_per_bfd::all_type_units
I don't think there is any deep reason to separate CUs and TUs in
dwarf2_per_bfd. This patch removes all_type_units and unifies these
two containers. Some minor tweaks are needed to the index writers,
because both forms of index keep CUs and TUs separate;
Regression tested on x86-63 Fedora 32.
gdb/ChangeLog
2021-04-30 Tom Tromey <tom@tromey.com>
* dwarf2/read.h (struct tu_stats) <nr_tus>: New member.
(struct dwarf2_per_bfd) <get_cutu, get_tu>: Remove
<get_cu>: Now inline.
<all_type_units>: Remove.
* dwarf2/read.c (dwarf2_per_bfd::~dwarf2_per_bfd): Update.
(dwarf2_per_bfd::get_cutu, dwarf2_per_bfd::get_cu)
(dwarf2_per_bfd::get_tu): Remove.
(dwarf2_per_bfd::allocate_signatured_type): Update nr_tus.
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(dw2_symtab_iter_next, dwarf2_base_index_functions::print_stats)
(dwarf2_base_index_functions::expand_all_symtabs)
(dw2_expand_marked_cus, dw_expand_symtabs_matching_file_matcher)
(dwarf2_base_index_functions::map_symbol_filenames)
(dw2_debug_names_iterator::next, dwarf2_initialize_objfile)
(add_signatured_type_cu_to_table, create_all_type_units)
(add_type_unit, build_type_psymtabs_1, print_tu_stats)
(create_all_comp_units): Update.
* dwarf2/index-write.c (check_dwarf64_offsets, write_gdbindex)
(write_debug_names): Update.
Tom Tromey [Fri, 30 Apr 2021 20:07:58 +0000 (14:07 -0600)]
Allocate dwarf2_per_cu_data with 'new'
In a patch series I am working on, I'd like to have a non-POD member
in dwarf2_per_cu_data. This currently can't be done because
dwarf2_per_cu_data is allocated on an obstack and initialized with
memset.
This patch changes the DWARF reader to allocate objects of this type
with 'new'. The various "subclasses" of this type (signatured_type in
particular) are now changed to derive from dwarf2_per_cu_data, and
also use 'new' for allocation.
Regression tested on x86-64 Fedora 32.
gdb/ChangeLog
2021-04-30 Tom Tromey <tom@tromey.com>
* dwarf2/read.h (struct dwarf2_per_bfd) <allocate_per_cu,
allocate_signatured_type>: Change return type.
<all_comp_units, all_type_units>: Hold unique pointers.
(struct dwarf2_per_cu_data): Add constructor and initializers.
(struct signatured_type): Derive from dwarf2_per_cu_data.
* dwarf2/read.c (type_unit_group): Derive from
dwarf2_per_cu_data.
(dwarf2_per_bfd::get_cutu, dwarf2_per_bfd::get_cu)
(dwarf2_per_bfd::get_tu)
(dwarf2_per_bfd::allocate_signatured_type)
(dwarf2_per_bfd::allocate_signatured_type)
(create_cu_from_index_list, create_cus_from_index_list)
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(create_addrmap_from_aranges)
(dwarf2_base_index_functions::find_last_source_symtab)
(dw_expand_symtabs_matching_file_matcher)
(dwarf2_gdb_index::expand_symtabs_matching)
(dwarf2_base_index_functions::map_symbol_filenames)
(create_cus_from_debug_names_list)
(dw2_debug_names_iterator::next)
(dwarf2_debug_names_index::expand_symtabs_matching)
(create_debug_type_hash_table, add_type_unit)
(fill_in_sig_entry_from_dwo_entry, lookup_dwo_signatured_type):
Update.
(allocate_type_unit_groups_table): Use delete.
(create_type_unit_group): Change return type. Use new.
(get_type_unit_group, build_type_psymtabs_1)
(build_type_psymtab_dependencies)
(process_skeletonless_type_unit, set_partial_user)
(dwarf2_build_psymtabs_hard, read_comp_units_from_section)
(create_cus_hash_table, queue_and_load_dwo_tu, follow_die_sig_1)
(read_signatured_type): Update.
(dwarf2_find_containing_comp_unit): Change type of
'all_comp_units'.
(run_test): Update.
(dwarf2_per_bfd::allocate_per_cu)
(dwarf2_per_bfd::allocate_signatured_type): Change return type.
Use new.
(add_signatured_type_cu_to_table): Update.
* dwarf2/index-write.c (write_one_signatured_type)
(check_dwarf64_offsets, psyms_seen_size, write_gdbindex)
(write_debug_names): Update.
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Make get_image_name static
The only callers of get_image_name are nat/windows-nat.c, so make it
static.
gdb/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* nat/windows-nat.h (get_image_name): Don't declare.
* nat/windows-nat.c (get_image_name): Now static.
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Share DLL code between gdb and gdbserver
This moves the new DLL-loading code into nat/windows-nat.c, and
changes both gdb and gdbserver to use the shared code. One
client-provided callback, handle_load_dll, is changed to allow the
code to be shared. This callback was actually never called from
nat/windows-nat.c; maybe I had planned to share more here and then
didn't finish... I'm not sure.
gdb/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* windows-nat.c (windows_nat::handle_load_dll): Update.
(windows_nat_target::get_windows_debug_event): Call
dll_loaded_event.
(windows_add_all_dlls, windows_add_dll): Move to
nat/windows-nat.c.
* nat/windows-nat.h (handle_load_dll): Change parameters.
(dll_loaded_event, windows_add_all_dlls): Declare.
* nat/windows-nat.c (windows_add_dll, windows_add_all_dlls): Move
from windows-nat.c.
(dll_loaded_event): New function.
gdbserver/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* win32-low.cc (do_initial_child_stuff): Update.
(windows_nat::handle_load_dll): Rename from win32_add_one_solib.
Change parameter type.
(win32_add_dll, win32_add_all_dlls)
(windows_nat::handle_load_dll): Remove.
(get_child_debug_event): Call dll_loaded_event.
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Use nat/windows-nat function indirection code
This changes gdbserver to use the function indirection code that was
just moved into nat/windows-nat.[ch]. One additional function is used
by gdbserver that was not used by gdb.
gdb/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* nat/windows-nat.h (GenerateConsoleCtrlEvent): New define.
(GenerateConsoleCtrlEvent_ftype, GenerateConsoleCtrlEvent):
Declare.
* nat/windows-nat.c (GenerateConsoleCtrlEvent): Define.
(initialize_loadable): Initialize GenerateConsoleCtrlEvent.
gdbserver/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* win32-low.cc (GETPROCADDRESS): Remove.
(winapi_DebugActiveProcessStop, winapi_DebugSetProcessKillOnExit)
(winapi_DebugBreakProcess, winapi_GenerateConsoleCtrlEvent)
(winapi_Wow64SetThreadContext, win32_Wow64GetThreadContext)
(win32_Wow64SetThreadContext): Remove.
(win32_set_thread_context, do_initial_child_stuff)
(win32_process_target::attach, win32_process_target::detach):
Update.
(winapi_EnumProcessModules, winapi_EnumProcessModulesEx)
(winapi_GetModuleInformation, winapi_GetModuleInformationA):
Remove.
(win32_EnumProcessModules, win32_EnumProcessModulesEx)
(win32_GetModuleInformation, win32_GetModuleInformationA):
Remove.
(load_psapi): Remove.
(win32_add_dll, win32_process_target::request_interrupt): Update.
(initialize_low): Call initialize_loadable.
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Move function indirection code to nat/windows-nat
gdb and gdbserver both look for functions in some Windows DLLs at
runtime. This patch moves this code out of gdb and into
nat/windows-nat, so it can be shared by both programs.
gdb/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* windows-nat.c: Move code to nat/windows-nat.[ch].
(_initialize_windows_nat): Call initialize_loadable.
* nat/windows-nat.h (AdjustTokenPrivileges)
(DebugActiveProcessStop, DebugBreakProcess)
(DebugSetProcessKillOnExit, EnumProcessModules)
(EnumProcessModulesEx, GetModuleInformation)
(GetModuleFileNameExA, GetModuleFileNameExW)
(LookupPrivilegeValueA, OpenProcessToken, GetConsoleFontSize)
(GetCurrentConsoleFont, Wow64SuspendThread)
(Wow64GetThreadContext, Wow64SetThreadContext)
(Wow64GetThreadSelectorEntry): Move from windows-nat.c.
(AdjustTokenPrivileges_ftype)
(DebugActiveProcessStop_ftype, DebugBreakProcess_ftype)
(DebugSetProcessKillOnExit_ftype, EnumProcessModules_ftype)
(EnumProcessModulesEx_ftype, GetModuleInformation_ftype)
(GetModuleFileNameExA_ftype, GetModuleFileNameExW_ftype)
(LookupPrivilegeValueA_ftype, OpenProcessToken_ftype)
(GetConsoleFontSize_ftype)
(GetCurrentConsoleFont_ftype, Wow64SuspendThread_ftype)
(Wow64GetThreadContext_ftype, Wow64SetThreadContext_ftype)
(Wow64GetThreadSelectorEntry_ftype): Likewise.
(initialize_loadable): Declare.
* nat/windows-nat.c (AdjustTokenPrivileges)
(DebugActiveProcessStop, DebugBreakProcess)
(DebugSetProcessKillOnExit, EnumProcessModules)
(EnumProcessModulesEx, GetModuleInformation, GetModuleFileNameExA)
(GetModuleFileNameExW, LookupPrivilegeValueA, OpenProcessToken)
(GetCurrentConsoleFont, GetConsoleFontSize, Wow64SuspendThread)
(Wow64GetThreadContext, Wow64SetThreadContext)
(Wow64GetThreadSelectorEntry): Define.
(bad, bad_GetCurrentConsoleFont, bad_GetConsoleFontSize): Move
from windows-nat.c.
(initialize_loadable): Likewise, and rename.
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Use template functions in windows-nat.c
windows-nat.c defines a number of replacement functions that simply
return zero. This patch removes these in favor of a couple of
template functions.
gdb/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* windows-nat.c (bad_GetModuleFileNameEx): Remove define.
(bad_DebugActiveProcessStop, bad_DebugBreakProcess)
(bad_DebugSetProcessKillOnExit, bad_EnumProcessModules)
(bad_GetModuleFileNameExW, bad_GetModuleFileNameExA)
(bad_GetModuleInformation, bad_OpenProcessToken): Remove.
(bad): New template functions.
(_initialize_loadable): Update.
Tom Tromey [Fri, 30 Apr 2021 16:04:56 +0000 (10:04 -0600)]
Use rvalue reference in thread_pool::post_task
Tankut's recent patches made me realize that thread_pool::post_task
should have used an rvalue reference for its parameter. This patch
makes this change.
gdbsupport/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* thread-pool.cc (thread_pool::post_task): Update.
* thread-pool.h (class thread_pool) <post_task>: Take rvalue
reference to function.
Tom Tromey [Thu, 15 Apr 2021 14:54:06 +0000 (08:54 -0600)]
Fix crash with GNAT minimal encodings
Running the AdaCore internal test suite with -fgnat-encodings=minimal
found a gdb crash. The bug is that GDB ends up with a typedef in
ada_index_type, resulting in a NULL dereference.
This crash can be reproduced using GCC 11 with the included test case.
Tested on x86-64 Fedora 32. Because this is Ada-specific, and was
already reviewed by Joel, I am going to check it in.
2021-04-30 Tom Tromey <tromey@adacore.com>
* ada-lang.c (ada_index_type): Use ada_check_typedef.
gdb/testsuite/ChangeLog
2021-04-30 Tom Tromey <tromey@adacore.com>
* gdb.ada/enum_idx_packed/pck.ads (My_Enum, My_Array_Type)
(Confused_Array): New types.
* gdb.ada/enum_idx_packed/foo.adb (Confused_Array): New variable.
* gdb.ada/enum_idx_packed.exp: Add new tests.
Nick Clifton [Fri, 30 Apr 2021 13:31:03 +0000 (14:31 +0100)]
Fix illegal memory access parsing a corrupt MACH-O format file.
PR 27801
* mach-o.c (bfd_mach_o_core_fetch_environment): Use bfd_get_32 to
read 32-bit value.
Nick Clifton [Fri, 30 Apr 2021 13:19:24 +0000 (14:19 +0100)]
Fix an illegal memory access when parsing a corrupt core note.
PR 27799
* elf32-xtensa.c (elf_xtensa_grok_prstatus): Check for core notes
that are too small.
Nick Clifton [Fri, 30 Apr 2021 13:04:08 +0000 (14:04 +0100)]
Fix a double free when re-allocating a buffer to size 0.
PR 27797
* libbfd.c (bfd_realloc_or_free): Do not free a pointer than has
been realloc'ed to size 0.
Nick Clifton [Fri, 30 Apr 2021 11:28:39 +0000 (12:28 +0100)]
Fix attempt to free non-allocated pointer when parsing .debug_sup sections.
PR 27796
* dwarf.c (load_debug_sup_file): Allocate memory for filename in
.debug_sup section.
Nick Clifton [Fri, 30 Apr 2021 11:11:35 +0000 (12:11 +0100)]
Fix illegal memory access when parsing a corrupt PE format file.
PR 27795
* coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Check for invalid name
lengths.
Tom de Vries [Fri, 30 Apr 2021 09:25:47 +0000 (11:25 +0200)]
[gdb/testsuite] Make gdb.mi/mi-sym-info.exp more robust against timeouts
Once in a while, I run into this timeout:
...
FAIL: gdb.mi/mi-sym-info.exp: List all variables from debug information \
only (timeout)
...
I can make the timeout reproducible by setting timeout to 8s (instead of the
default 10s) for the duration of that test.
Make the test-case more stable by fixing all timeouts caused by setting
timeout to 5, either by adding with_timeout_factor, or increasing its factor.
Tested on x86_64-linux. Also tested in parallel with stress -c 5, to simulate
a busy system in another way.
gdb/testsuite/ChangeLog:
2021-04-30 Tom de Vries <tdevries@suse.de>
* gdb.mi/mi-sym-info.exp: Add with_timeout_factor, and increase
existing timeout factors.
Tom de Vries [Fri, 30 Apr 2021 09:25:47 +0000 (11:25 +0200)]
[gdb/testsuite] Fix duplicate test name in gdb.mi/mi-sym-info.exp
Since commit
2d61316c32a "[gdb/testsuite] Fix buffer full errors in
gdb.mi/mi-sym-info.exp", we have a duplicate test name:
...
Running src/gdb/testsuite/gdb.mi/mi-sym-info.exp ...
DUPLICATE: gdb.mi/mi-sym-info.exp: List all variables
...
This is caused by a copy-paste accident: the idea was to copy the test, edit
it, and then remove the old test, but I forgot to remove the old one.
Remove it now.
Tested on x86_64-linux.
gdb/testsuite/ChangeLog:
2021-04-30 Tom de Vries <tdevries@suse.de>
* gdb.mi/mi-sym-info.exp: Remove duplicate test.
GDB Administrator [Fri, 30 Apr 2021 00:00:29 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom de Vries [Thu, 29 Apr 2021 21:32:20 +0000 (23:32 +0200)]
[gdb/testsuite] Fix timeout in gdb.base/valgrind-infcall-2.exp
Since commit
6d5702a5eb3 "Fix test case gdb.base/valgrind-bt.exp" I run into:
...
FAIL: gdb.base/valgrind-infcall-2.exp: target remote for vgdb (timeout)
FAIL: gdb.base/valgrind-infcall-2.exp: monitor v.set gdb_output (timeout)
...
The commit adds this line in proc vgdb_start:
...
set vgdbcmd "set remotetimeout 3"
...
which has no effect given that the value of var vgdbcmd is not used before
it's overwritten. We can fix this by doing instead:
...
set_remotetimeout 3
...
The FAIL I'm observing is fixed by increasing the remotetimeout value to 4.
Tested on x86_64-linux.
gdb/testsuite/ChangeLog:
2021-04-29 Tom de Vries <tdevries@suse.de>
PR testsuite/27786
* lib/valgrind.exp (vgdb_start): Use set_remotetimeout. Increase
remotetimeout to 4.
Simon Marchi [Thu, 29 Apr 2021 20:24:19 +0000 (16:24 -0400)]
gdb: don't use C++17 namespace declaration style
In a review, I suggested to use "namespace gdb::observers" instead of
two separate namespace declarations. I didn't realize that this was a
C++17 feature, which breaks compilers that default to an earlier version
of the language, like g++ 4.8. Change it back to two separate
declarations.
gdb/ChangeLog:
* auto-load.h: Split namespace declaration.
Change-Id: I701537161967fbd9fcc298ff600bd072aab1251d
Nick Clifton [Thu, 29 Apr 2021 16:55:43 +0000 (17:55 +0100)]
Fix an access through a null pointer when parsing a corrupt SOM format fle.
PR 27793
* som.c (som_slurp_symbol_table): Assign symbols without any scope
to the undefined section.
(som_decode_symclass): Check for a missing symbol section.
* syms.c (bfd_decode_symclass): Likewise.
Nick Clifton [Thu, 29 Apr 2021 16:41:43 +0000 (17:41 +0100)]
Fix illegal memory accesses when parsing a corrupt SOM format file.
PR 27792
* som.c (som_slurp_string_table): Place a terminating NUL byte at
the end of the table.
(som_slurp_symbol_table): Check for an over-large offset into the
string string table.
Simon Marchi [Thu, 29 Apr 2021 14:16:28 +0000 (10:16 -0400)]
gdb: move some variables to an inner scope in save_waitstatus
These two variables:
struct regcache *regcache = get_thread_regcache (tp);
const address_space *aspace = regcache->aspace ();
are only needed inside the "if". Getting a thread's regcache is a
somewhat expensive operation, so it's good to avoid it if not necessary.
Move the variable declarations and their initialization to the "if"
scope.
gdb/ChangeLog:
* infrun.c (save_waitstatus): Move variables to inner scope.
Change-Id: Ief1463728755b4dcc142c0a0a76896e9d594ae84
Jan Beulich [Thu, 29 Apr 2021 13:02:25 +0000 (15:02 +0200)]
x86-64: adjust recently added tests
Five of them fail for Cygwin and MingW. Adjust four and move one to the
ELF-only section.
Nick Clifton [Thu, 29 Apr 2021 12:11:29 +0000 (13:11 +0100)]
Correct the text describing windres's --processor option.
PR 27594
* doc/binutils.texi (windres): Correct the description of the
default value of the --preprocessor argument.
Jan Beulich [Thu, 29 Apr 2021 09:45:10 +0000 (11:45 +0200)]
x86: relax when/how @size can be used
Allow a few more expression forms when the entire expression can be
resolved at assembly time. For this, i386_validate_fix() needs to
arrange for all processing of the relocation to be deferred to
tc_gen_reloc().
Jan Beulich [Thu, 29 Apr 2021 09:43:53 +0000 (11:43 +0200)]
x86: allow @size to also (sensibly) apply to sections
So far this (counter-intuitively) produced the size as recorded in the
(section) symbol. Obtain the section's size instead for section symbols.
(I wonder whether STT_SECTION symbols couldn't properly hold the
section's size in their st_size field, which in turn would likely mean
the internal symbol would also have its size properly updated.)
Note that this is not the same as the .sizeof.() pseudo-operator: @size
yields the local file's contribution to a section, while .sizeof.() gets
resolved by the linker to produce the final full section's size.
As to the 3rd each of the expected output lines in the changed testcase:
I can't find justification for zzz to come after yyy despite them being
defined in the opposite order in source. Therefore I think it's better
to permit both possible outcomes.
Andrew Burgess [Thu, 29 Apr 2021 09:29:41 +0000 (10:29 +0100)]
gdb/NEWS: Fix typo and stray full stop
Some errors introduced in commit:
commit
edeaceda7b2f33b2c3bf78c732e67f3188e7f0b9
Date: Thu Aug 27 16:53:13 2020 +0100
gdb: startup commands to control Python extension language
gdb/ChangeLog:
* NEWS: Fix typo and stray full stop.
GDB Administrator [Thu, 29 Apr 2021 00:00:33 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Tue, 27 Apr 2021 13:35:23 +0000 (07:35 -0600)]
Fix Ada overloading with 'null'
Currently, the Ada expression parser treats 'null' as an integer 0.
However, this causes overloading to fail in certain cases.
This patch changes the Ada expression parser to use a special type for
'null'. I chose pointer-to-int0, because I think that's not likely to
be needed for any other Ada expression. Note this works because a
"mod 1" type has an underlying non-zero byte size; the test includes a
check for this.
The output is changed so that "print null", by default, shows "null".
And, ada_type_match is changed both to recognize the special null type
and to remove a bit of weird code related to how pointers are treated
for overload type matching.
Tested on x86-64 Fedora 32. Because this only touches Ada, and Joel
already approved it internally at AdaCore, I am checking it in.
gdb/ChangeLog
2021-04-28 Tom Tromey <tromey@adacore.com>
* ada-exp.y (primary): Use new type for null pointer.
* ada-lang.c (ada_type_match): Remove "may_deref"
parameter. Handle null pointer.
(ada_args_match): Update.
* ada-valprint.c (ada_value_print_ptr, ada_value_print):
Handle null pointer.
gdb/testsuite/ChangeLog
2021-04-28 Tom Tromey <tromey@adacore.com>
* gdb.ada/null_overload.exp: New file.
* gdb.ada/null_overload/foo.adb: New file.
Andrew Burgess [Wed, 28 Apr 2021 09:16:48 +0000 (10:16 +0100)]
gdb/doc: use @env to reference environment variables
Clean up a few places where we are not using @env{...} to reference
environment variables.
gdb/doc/ChangeLog:
* gdb.texinfo (Initialization Files): Use @env when referencing
environment variables.
(Shell Commands): Likewise.
(Starting): Likewise.
(Arguments): Likewise.
(Environment): Likewise.
(Edit): Likewise.
(Compiling and Injecting Code): Likewise.
(Files): Likewise.
(Command History): Likewise.
(Screen Size): Likewise.
(Emacs): Likewise.
Nick Clifton [Wed, 28 Apr 2021 10:49:09 +0000 (11:49 +0100)]
Stop the BFD library from treating annobin symbols as potential function symbols.
bfd * elf.c (_bfd_elf_maybe_function_sym): Do not accept annobin
symbols as potential function symbols.
* elfnn-aarch64.c (elfNN_aarch64_maybe_function_sym): Likewise.
* elf64-ppc.c (ppc64_elf_maybe_function_sym): Likewise.
* elf32-arm.c (elf32_arm_maybe_function_sym): Likewise.
ld * testsuite/ld-elf/anno-sym.s: New test source file.
* testsuite/ld-elf/anno-sym.d: New test driver.
* testsuite/ld-elf/anno-sym.l: New test error output.
Andrew Burgess [Thu, 27 Aug 2020 15:53:13 +0000 (16:53 +0100)]
gdb: startup commands to control Python extension language
Add two new commands to GDB that can be placed into the early
initialization to control how Python starts up. The new options are:
set python ignore-environment on|off
set python dont-write-bytecode auto|on|off
show python ignore-environment
show python dont-write-bytecode
These can be used from GDB's startup file to control how the Python
extension language behaves. These options are equivalent to the -E
and -B flags to python respectively, their descriptions from the
Python man page:
-E Ignore environment variables like PYTHONPATH and PYTHONHOME
that modify the behavior of the interpreter.
-B Don't write .pyc files on import.
gdb/ChangeLog:
* NEWS: Mention new commands.
* python/python.c (python_ignore_environment): New static global.
(show_python_ignore_environment): New function.
(set_python_ignore_environment): New function.
(python_dont_write_bytecode): New static global.
(show_python_dont_write_bytecode): New function.
(set_python_dont_write_bytecode): New function.
(_initialize_python): Register new commands.
gdb/doc/ChangeLog:
* python.texinfo (Python Commands): Mention new commands.
gdb/testsuite/ChangeLog:
* gdb.python/py-startup-opt.exp: New file.
Andrew Burgess [Thu, 22 Apr 2021 17:26:15 +0000 (18:26 +0100)]
gdb: extension languages finish_initialization to initialize
Now that both Python and Guile are fully initialized from their
respective finish_initialization methods, the "finish" in the method
name doesn't really make sense; initialization starts _and_ finishes
with that method.
As such, this commit renames finish_initialization to just initialize.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* extension-priv.h (struct extension_language_ops): Rename
'finish_initialization' to 'initialize'.
* extension.c (finish_ext_lang_initialization): Renamed to...
(ext_lang_initialization): ...this, update comment, and updated
the calls to reflect the change in struct extension_language_ops.
* extension.h (finish_ext_lang_initialization): Renamed to...
(ext_lang_initialization): ...this.
* guile/guile.c (gdbscm_finish_initialization): Renamed to...
(gdbscm_initialize): ...this, update comment at definition.
(guile_extension_ops): Update.
* main.c (captured_main_1): Update call to
finish_ext_lang_initialization.
* python/python.c (gdbpy_finish_initialization): Rename to...
(gdbpy_initialize): ...this, update comment at definition, and
update call to do_finish_initialization.
(python_extension_ops): Update.
(do_finish_initialization): Rename to...
(do_initialize): ...this, and update comment.
Andrew Burgess [Wed, 26 Aug 2020 16:31:12 +0000 (17:31 +0100)]
gdb: initialise extension languages after processing early startup files
Now (thanks to the last few commits) all extension languages are
fully initialised in their finish_initialization method, this commit
delays the call to this method until after the early initialization
files have been processed.
Right now there's no benefit from doing this, but in a later commit I
plan to add new options for Python that will control how Python is
initialized.
With this commit in place, my next commits will allow the user to add
options to their early initialization file and alter how Python starts
up.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* main.c (captured_main_1): Add a call to
finish_ext_lang_initialization.
* top.c (gdb_init): Remove call to finish_ext_lang_initialization.
Andrew Burgess [Thu, 22 Apr 2021 17:17:01 +0000 (18:17 +0100)]
gdb delay guile initialization until gdbscm_finish_initialization
Like with the previous commit, this commit delays the initialisation
of the guile extension language until gdbscm_finish_initialization.
This is mostly about splitting the existing gdbscm_initialize_*
functions in two, all the calls to register_objfile_data_with_cleanup,
gdbarch_data_register_post_init, etc are moved into new _initialize_*
functions, but everything else is left in the gdbscm_initialize_*
functions.
Then the call to code previously in _initialize_guile is moved into
gdbscm_finish_initialization.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* guile/guile.c (gdbscm_set_backtrace): Add declaration.
(gdbscm_finish_initialization): Add code moved from
_initialize_guile.
(_initialize_guile): Move code to gdbscm_finish_initialization.
* guile/scm-arch.c (gdbscm_initialize_arches): Move some code into
_initialize_scm_arch.
(_initialize_scm_arch): New function.
* guile/scm-block.c (gdbscm_initialize_blocks): Move some code
into _initialize_scm_block.
(_initialize_scm_block): New function.
* guile/scm-frame.c (gdbscm_initialize_frames): Move some code
into _initialize_scm_frame.
(_initialize_scm_frame): New function.
* guile/scm-objfile.c (gdbscm_initialize_objfiles): Move some code
into _initialize_scm_objfile.
(_initialize_scm_objfile): New function.
* guile/scm-progspace.c (gdbscm_initialize_pspaces): Move some
code into _initialize_scm_progspace.
(_initialize_scm_progspace): New function.
* guile/scm-symbol.c (gdbscm_initialize_symbols): Move some code
into _initialize_scm_symbol.
(_initialize_scm_symbol): New function.
* guile/scm-symtab.c (gdbscm_initialize_symtabs): Move some code
into _initialize_scm_symtab.
(_initialize_scm_symtab): New function.
* guile/scm-type.c (gdbscm_initialize_types): Move some code into
_initialize_scm_type.
(_initialize_scm_type): New function.
Andrew Burgess [Thu, 22 Apr 2021 16:11:25 +0000 (17:11 +0100)]
gdb: delay python initialisation until gdbpy_finish_initialization
Delay Python initialisation until gdbpy_finish_initialization.
This is mostly about splitting the existing gdbpy_initialize_*
functions in two, all the calls to register_objfile_data_with_cleanup,
gdbarch_data_register_post_init, etc are moved into new _initialize_*
functions, but everything else is left in the gdbpy_initialize_*
functions.
Then the call to do_start_initialization (in python/python.c) is moved
from the _initialize_python function into gdbpy_finish_initialization.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* python/py-arch.c (_initialize_py_arch): New function.
(gdbpy_initialize_arch): Move code to _initialize_py_arch.
* python/py-block.c (_initialize_py_block): New function.
(gdbpy_initialize_blocks): Move code to _initialize_py_block.
* python/py-inferior.c (_initialize_py_inferior): New function.
(gdbpy_initialize_inferior): Move code to _initialize_py_inferior.
* python/py-objfile.c (_initialize_py_objfile): New function.
(gdbpy_initialize_objfile): Move code to _initialize_py_objfile.
* python/py-progspace.c (_initialize_py_progspace): New function.
(gdbpy_initialize_pspace): Move code to _initialize_py_progspace.
* python/py-registers.c (_initialize_py_registers): New function.
(gdbpy_initialize_registers): Move code to
_initialize_py_registers.
* python/py-symbol.c (_initialize_py_symbol): New function.
(gdbpy_initialize_symbols): Move code to _initialize_py_symbol.
* python/py-symtab.c (_initialize_py_symtab): New function.
(gdbpy_initialize_symtabs): Move code to _initialize_py_symtab.
* python/py-type.c (_initialize_py_type): New function.
(gdbpy_initialize_types): Move code to _initialize_py_type.
* python/py-unwind.c (_initialize_py_unwind): New function.
(gdbpy_initialize_unwind): Move code to _initialize_py_unwind.
* python/python.c (_initialize_python): Move call to
do_start_initialization to gdbpy_finish_initialization.
(gdbpy_finish_initialization): Add call to
do_start_initialization.
Andrew Burgess [Thu, 22 Apr 2021 16:05:44 +0000 (17:05 +0100)]
gdb: ensure SIGINT is set to SIG_DFL during initialisation
In order for our SIGINT handling to work correctly with Python we
require that SIGINT be set to SIG_DFL during Python's initialisation.
Currently this is the case, but, in a later commit I plan to delay the
initialisation of Python until after the point where GDB's own SIGINT
handler has been installed.
The consequence of this is that our SIGINT handling would become
broken.
In this commit I propose adding an RAII class that will ensure SIGINT
is set to SIG_DFL during the call to each extension languages
finish_initialization method.
At this point this change should have not effect.
gdb/ChangeLog:
* extension.c (struct scoped_default_signal): New struct.
(scoped_default_sigint): New typedef.
(finish_ext_lang_initialization): Make use of
scoped_default_sigint.
Andrew Burgess [Thu, 22 Apr 2021 15:46:23 +0000 (16:46 +0100)]
gdb: remove unused argument from gdb_init
The argument to gdb_init is not used, remove it.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* main.c (captured_main_1): Don't pass argument to gdb_init.
* top.c (gdb_init): Remove unused argument, and add header
comment.
* top.h (gdb_init): Remove argument.
Jan Beulich [Wed, 28 Apr 2021 08:53:00 +0000 (10:53 +0200)]
x86: honor signedness of PC-relative relocations
PR gas/27763
While the comment in output_jump() was basically correct prior to the
introduction of 64-bit mode, both that and the not-JMP-like behavior of
XBEGIN require adjustments: Branches with 32-bit displacement do not
wrap at 4G in 64-bit mode, and XBEGIN with 16-bit operand size doesn't
wrap at 64k. Similarly %rip-relative addressing doesn't wrap at 4G.
The new testcase points out that for PE/COFF object_64bit didn't get
set so far, preventing in particular the check at the end of
md_convert_frag() to take effect.
For Mach-O the new testcase fails (bogusly), in that only the first two
of the expected errors get raised. Since for Mach-O many testcases
already fail, and since an x86_64-darwin target can't even be configured
for, I didn't think I need to bother.
Note that there are further issues in this area, in particular for
branches with operand size overrides. Such branches, which truncate
%rip / %eip, can't be correctly expressed with ordinary PC-relative
relocations. It's not really clear what to do with them - perhaps the
best we can do is to carry through all associated relocations, leaving
it to the linker (or even loader) to decide (once the final address
layout is known). Same perhaps goes for relocations associated with
32-bit addressing in 64-bit mode.
GDB Administrator [Wed, 28 Apr 2021 00:00:32 +0000 (00:00 +0000)]
Automatic date update in version.in
Luis Machado [Thu, 1 Apr 2021 20:00:43 +0000 (17:00 -0300)]
Fix timeout with maint print objfiles
I'm seeing timeouts from gdb.rust/traits.exp when we attempt to print
things with "maint print objfiles".
This happens for two reasons:
1 - GDB does not explicitly split each entry into its own line, but rather
relies on the terminal's width to insert line breaks.
2 - When running the GDB testsuite, such width may be unlimited, which will
prevent GDB from inserting any line breaks.
As a result, the output may be too lengthy and will come in big lines. Tweak
the support library to match the patterns line-by-line, which gives us more
time to match things. Also fix GDB's output to print one entry per line,
regardless of the terminal width.
A similar approach was used in another testcase using the same command (commit
eaeaf44cfdc9a4096a0dd52fa0606f29d4bfd48e). With the new line breaks, we don't
need a particular pattern, so clean up that test as well.
gdb/ChangeLog:
2021-04-27 Luis Machado <luis.machado@linaro.org>
* psymtab.c (psymbol_functions::dump): Output newline.
* symmisc.c (dump_objfile): Likewise.
gdb/testsuite/ChangeLog:
2021-04-27 Luis Machado <luis.machado@linaro.org>
* gdb.base/maint.exp: Drop a pattern that is not needed.
* lib/gdb.exp (readnow): Match line-by-line.
Luis Machado [Thu, 1 Apr 2021 17:31:24 +0000 (14:31 -0300)]
Fix timeout for gdb.xml/tdesc-reload.exp
For aarch64, the "info all-registers" output is very verbose. If you run
this test using read1, it will timeout before the command output is done being
read.
Read line-by-line so we don't run into timeouts.
gdb/testsuite/ChangeLog:
2021-04-27 Luis Machado <luis.machado@linaro.org>
* gdb.xml/tdesc-reload.exp: Pass -lbl.
Michael Weghorn [Tue, 27 Apr 2021 14:02:42 +0000 (10:02 -0400)]
gdb: do autoload before notifying Python side in new_objfile event
Without any explicit dependencies specified, the observers attached
to the 'gdb::observers::new_objfile' observable are always notified
in the order in which they have been attached.
The new_objfile observer callback to auto-load scripts is attached in
'_initialize_auto_load'.
The new_objfile observer callback that propagates the new_objfile event
to the Python side is attached in 'gdbpy_initialize_inferior', which is
called via '_initialize_python'.
With '_initialize_python' happening before '_initialize_auto_load',
the consequence was that the new_objfile event was emitted on the Python
side before autoloaded scripts had been executed when a new objfile was
loaded.
As a result, trying to access the objfile's pretty printers (defined in
the autoloaded script) from a handler for the Python-side
'new_objfile' event would fail. Those would only be initialized later on
(when the 'auto_load_new_objfile' callback was called).
To make sure that the objfile passed to the Python event handler
is properly initialized (including its 'pretty_printers' member),
make sure that the 'auto_load_new_objfile' observer is notified
before the 'python_new_objfile' one that propagates the event
to the Python side.
To do this, make use of the mechanism to explicitly specify
dependencies between observers (introduced in a preparatory commit).
Add a corresponding testcase that involves a test library with an autoloaded
Python script and a handler for the Python 'new_objfile' event.
(The real world use case where I came across this issue was in an attempt
to extend handling for GDB pretty printers for dynamically loaded
objfiles in the Qt Creator IDE, s. [1] and [2] for more background.)
[1] https://bugreports.qt.io/browse/QTCREATORBUG-25339
[2] https://codereview.qt-project.org/c/qt-creator/qt-creator/+/333857/1
Tested on x86_64-linux (Debian testing).
gdb/ChangeLog:
* gdb/auto-load.c (_initialize_auto_load): 'Specify token
when attaching the 'auto_load_new_objfile' observer, so
other observers can specify it as a dependency.
* gdb/auto-load.h (struct token): Declare
'auto_load_new_objfile_observer_token' as token to be used
for the 'auto_load_new_objfile' observer.
* gdb/python/py-inferior.c (gdbpy_initialize_inferior): Make
'python_new_objfile' observer depend on 'auto_load_new_objfile'
observer, so it gets notified after the latter.
gdb/testsuite/ChangeLog:
* gdb.python/libpy-autoloaded-pretty-printers-in-newobjfile-event.so-gdb.py: New test.
* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.cc: New test.
* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.h: New test.
* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-main.cc: New test.
* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.exp: New test.
* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py: New test.
Change-Id: I8275b3f4c3bec32e56dd7892f9a59d89544edf89
Michael Weghorn [Tue, 27 Apr 2021 13:55:27 +0000 (09:55 -0400)]
gdbsupport: allow to specify dependencies between observers
Previously, the observers attached to an observable were always notified
in the order in which they had been attached. That order is not easily
controlled, because observers are typically attached in _initialize_*
functions, which are called in an undefined order.
However, an observer may require that another observer attached only
later is called before itself is.
Therefore, extend the 'observable' class to allow explicitly specifying
dependencies when attaching observers, by adding the possibility to
specify tokens for observers that it depends on.
To make sure dependencies are notified before observers depending on
them, the vector holding the observers is sorted in a way that
dependencies come before observers depending on them. The current
implementation for sorting uses the depth-first search algorithm for
topological sorting as described at [1].
Extend the observable unit tests to cover this case as well. Check that
this works for a few different orders in which the observers are
attached.
This newly introduced mechanism to explicitly specify dependencies will
be used in a follow-up commit.
[1] https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search
Tested on x86_64-linux (Debian testing).
gdb/ChangeLog:
* unittests/observable-selftests.c (dependency_test_counters):
New.
(observer_token0, observer_token1, observer_token2,
observer_token3, observer_token4, observer_token5): New.
(struct dependency_observer_data): New struct.
(observer_dependency_test_callback): New function.
(test_observers): New.
(run_dependency_test): New function.
(test_dependency): New.
(_initialize_observer_selftest): Register dependency test.
gdbsupport/ChangeLog:
* observable.h (class observable): Extend to allow specifying
dependencies between observers, keep vector holding observers
sorted so that dependencies are notified before observers
depending on them.
Change-Id: I5399def1eeb69ca99e28c9f1fdf321d78b530bdb
H.J. Lu [Tue, 27 Apr 2021 15:16:55 +0000 (08:16 -0700)]
x86: Add () to silence GCC 5
Add () to !i.prefix[ADDR_PREFIX] to silence GCC 5:
gas/config/tc-i386.c:4152:31: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
&& !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))
^
* config/tc-i386.c (optimize_encoding): Add () to silence GCC 5.
Nick Clifton [Tue, 27 Apr 2021 14:19:41 +0000 (15:19 +0100)]
Reject debuglink sections with no associated filename.
PR 27779
* dwarf.c (parse_gnu_debuglink): Reject empty names.
(parse_gnu_debugaltlink): Likewise.
Mike Frysinger [Tue, 27 Apr 2021 03:28:04 +0000 (23:28 -0400)]
sim: riscv: switch MIN/MAX to common min/max
The common sim-basics.h defines min/max already, so use them.
Mike Frysinger [Sun, 25 Apr 2021 22:11:35 +0000 (18:11 -0400)]
sim: nltvals: unify common syscall tables
Since libgloss provides a default syscall table for arches, use that
to provide the default syscall table for ports. Only the exceptions
need to be enumerated now with the common logic as the default.
Mike Frysinger [Fri, 23 Apr 2021 20:24:27 +0000 (16:24 -0400)]
sim: enable hardware support by default
Force this on for all ports. We have a few common models that can
be used, so make them generally available. If the port doesn't use
any hardware (the default), then behavior is unchanged.
Mike Frysinger [Mon, 19 Apr 2021 01:18:11 +0000 (21:18 -0400)]
bfd: add stdlib.h when using abort
Since this file calls abort() now, we need to include stdlib.h for
its prototype.
GDB Administrator [Tue, 27 Apr 2021 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in
Nick Clifton [Mon, 26 Apr 2021 16:16:20 +0000 (17:16 +0100)]
Fix a bug in the ARM emulator which would not allow 4 byte alignment for double word stores.
PR 22790
* armemu.c (Handle_Store_Double): Allow 4 byte alignment when
running in v6 mode.
Tom Tromey [Mon, 26 Apr 2021 15:53:32 +0000 (09:53 -0600)]
Add test case for gdb 10 crash
PR gdb/27743 points out a gdb crash when expanding partial symtabs,
where one of the compilation units uses DW_TAG_imported_unit.
This crash happens for gdb 10, but not git trunk. This patch pulls
over the new test case only.
gdb/testsuite/ChangeLog
2021-04-26 Tom Tromey <tromey@adacore.com>
PR gdb/27743:
* gdb.dwarf2/imported-unit-bp.exp: New file.
* gdb.dwarf2/imported-unit-bp-main.c: New file.
* gdb.dwarf2/imported-unit-bp-alt.c: New file.
Simon Marchi [Mon, 26 Apr 2021 15:27:07 +0000 (11:27 -0400)]
gdb: check result of gdb_fopen_cloexec in dump_binary_file
Bug 27773 shows that passing a filename in a non-existent directory to
the "dump binary" command leads to a gdb crash. This is because the
gdb_fopen_cloexec in dump_binary_file fails (returns nullptr) and the
return value is not checked. Fix that by erroring out if
gdb_fopen_cloexec fails.
gdb/ChangeLog:
PR gdb/27773
* cli/cli-dump.c (dump_binary_file): Check result of
gdb_fopen_cloexec.
gdb/testsuite/ChangeLog:
PR gdb/27773
* gdb.base/dump.exp: Test dump to non-existent dir.
Change-Id: Iea89a3bf9e6b9dcc31142faa5ae17bc855759328
Luis Machado [Thu, 8 Apr 2021 18:32:29 +0000 (15:32 -0300)]
Fix gdb.arch/aarch64-dbreg-contents.exp FAIL
The test checks for a particular ARCH level, but it needs to check for
ARCH levels from a minimum and upwards.
gdb/testsuite/ChangeLog:
2021-04-26 Luis Machado <luis.machado@linaro.org>
* gdb.arch/aarch64-dbreg-contents.c (set_watchpoint): Fix arch level
comparison.
Jan Beulich [Mon, 26 Apr 2021 08:41:35 +0000 (10:41 +0200)]
x86: correct overflow checking for 16-bit PC-relative relocs
The only insn requiring a truly 16-bit PC-relative relocation outside of
16-bit mode is XBEGIN (with an operand size override). For it, the
relocation generated should behave similar to 8- and (for 64-bit) 32-bit
PC-relatives ones, i.e. be checked for a signed value to fit the field.
This same mode is also correct for 16-bit code. Outside of 16-bit code,
branches with operand size overrides act in a truly PC-relative way only
when living in the low 32k of address space, as they truncate rIP to 16
bits. This can't be expressed by a PC-relative relocation.
Putting in place a new testcase, I'd like to note that the two existing
ones (pcrel16 and pcrel16abs) appear to be pretty pointless: They don't
expect any error despite supposedly checking for overflow, and in fact
there can't possibly be any error for the
- former since gas doesn't emit any relocation in the first place there,
- latter because the way the relocation gets expressed by gas doesn't
allow the linker to notice the overflow; it should be detected by gas
if at all, but see above (an error would be reported here for x86-64
afaict, but this test doesn't get re-used there).
Jan Beulich [Mon, 26 Apr 2021 08:39:45 +0000 (10:39 +0200)]
x86: add IS_ELF to check whether to resolve @size reloc
This may not be strictly needed, as BFD_RELOC_SIZE* shouldn't appear
from elsewhere for non-ELF, but let's be on the safe side.
Jan Beulich [Mon, 26 Apr 2021 08:39:11 +0000 (10:39 +0200)]
x86: limit 32-bit @size overflow checks to 64-bit objects
For 32-bit objects the behavior should not be dependent upon the build
being a BFD64 one.
Jan Beulich [Mon, 26 Apr 2021 08:37:30 +0000 (10:37 +0200)]
x86: optimize LEA
Over the years I've seen a number of instances where people used
lea (%reg1), %reg2
or
lea symbol, %reg
despite the same thing being expressable via MOV. Since additionally
LEA often has restrictions towards the ports it can be issued to, while
MOV typically gets dealt with simply by register renaming, transform to
MOV when possible (without growing opcode size and without altering
involved relocation types).
Note that for Mach-O the new 64-bit testcases would fail (for
BFD_RELOC_X86_64_32S not having a representation), and hence get skipped
there.
Jan Beulich [Mon, 26 Apr 2021 08:35:51 +0000 (10:35 +0200)]
x86-64: have value properly checked when resolving fixup
Constants not known at the time an individual insn gets assembled and
going into a sign-extended field still shouldn't be silently truncated
at the time the respective fixup gets resolved.
Sergei Trofimovich [Sun, 25 Apr 2021 19:50:38 +0000 (20:50 +0100)]
gdb: fix sparc build failure of linux-nat
On sparc build failed as:
```
gdb/sparc-linux-nat.c: In member function
'virtual void sparc_linux_nat_target::fetch_registers(regcache*, int)':
gdb/sparc-linux-nat.c:36:37:
error: cannot convert 'regcache*' to 'process_stratum_target*'
36 | { sparc_fetch_inferior_registers (regcache, regnum); }
| ^~~~~~~~
| |
| regcache*
```
The fix adopts gdb/sparc-nat.h API change in
d1e93af64a6
("gdb: set current thread in sparc_{fetch,collect}_inferior_registers").
gdb/ChangeLog:
* sparc-linux-nat.c (sparc_linux_nat_target): fix sparc build
by passing `process_stratum_target*` parameter.
GDB Administrator [Mon, 26 Apr 2021 00:00:16 +0000 (00:00 +0000)]
Automatic date update in version.in
Lancelot SIX [Sat, 17 Apr 2021 11:10:23 +0000 (12:10 +0100)]
[PR gdb/22640] ptype: add option to use hexadecimal notation
This commit adds a flag to the ptype command in order to print the
offsets and sizes of struct members using the hexadecimal notation. The
'x' flag ensures use of the hexadecimal notation while the 'd' flag
ensures use of the decimal notation. The default is to use decimal
notation.
Before this patch, gdb only uses decimal notation, as pointed out in PR
gdb/22640.
Here is an example of this new behavior with hex output turned on:
(gdb) ptype /ox struct type_print_options
/* offset | size */ type = struct type_print_options {
/* 0x0000: 0x0 | 0x0004 */ unsigned int raw : 1;
/* 0x0000: 0x1 | 0x0004 */ unsigned int print_methods : 1;
/* 0x0000: 0x2 | 0x0004 */ unsigned int print_typedefs : 1;
/* 0x0000: 0x3 | 0x0004 */ unsigned int print_offsets : 1;
/* 0x0000: 0x4 | 0x0004 */ unsigned int print_in_hex : 1;
/* XXX 3-bit hole */
/* XXX 3-byte hole */
/* 0x0004 | 0x0004 */ int print_nested_type_limit;
/* 0x0008 | 0x0008 */ typedef_hash_table *local_typedefs;
/* 0x0010 | 0x0008 */ typedef_hash_table *global_typedefs;
/* 0x0018 | 0x0008 */ ext_lang_type_printers *global_printers;
/* total size (bytes): 32 */
}
This patch also adds the 'set print type hex' and 'show print type hex'
commands in order to set and inspect the default behavior regarding the
use of decimal or hexadecimal notation when printing struct sizes and
offsets.
Tested using on x86_64.
gdb/ChangeLog:
PR gdb/22640
* typeprint.h (struct type_print_options): Add print_in_hex
flag.
(struct print_offset_data): Add print_in_hex flag, add a
constructor accepting a type_print_options* argument.
* typeprint.c (type_print_raw_options, default_ptype_flags): Set
default value for print_in_hex.
(print_offset_data::indentation): Allow more horizontal space.
(print_offset_data::print_offset_data): Add ctor.
(print_offset_data::maybe_print_hole, print_offset_data::update):
Handle the print_in_hex flag.
(whatis_exp): Handle 'x' and 'd' flags.
(print_offsets_and_sizes_in_hex): Declare.
(set_print_offsets_and_sizes_in_hex): Create.
(show_print_offsets_and_sizes_in_hex): Create.
(_initialize_typeprint): Update help message for the ptype
command, register the 'set print type hex' and 'show print type
hex' commands.
* c-typeprint.c (c_print_type, c_type_print_base_struct_union)
(c_type_print_base): Construct the print_offset_data
object using the type_print_optons parameter.
* rust-lang.c (rust_language::print_type): Construct the
print_offset_data object using the type_print_optons parameter.
* NEWS: Mention the new flags of the ptype command.
gdb/doc/ChangeLog:
PR gdb/22640
* gdb.texinfo (Symbols): Describe the 'x' and 'd' flags of the
ptype command, describe 'set print type hex' and 'show print
type hex' commands. Update 'ptype/o' examples.
gdb/testsuite/ChangeLog:
PR gdb/22640
* gdb.base/ptype-offsets.exp: Add tests to verify the behavior
of 'ptype/ox' and 'ptype/od'. Check that 'set print type hex'
changes the default behavior of 'ptype/o'. Update to take into
account new horizontal layout.
* gdb.rust/simple.exp: Update ptype test to check new horizontal
layout.
* gdb.rust/union.exp: Same.