Jan Beulich [Wed, 4 Dec 2019 09:45:17 +0000 (10:45 +0100)]
x86-64: accept 64-bit LFS/LGS/LSS forms with suffix or operand size specifier
Since we accept these without suffix / operand size specifier, we should
also do so with one. (The fact that we unilaterally accept these, other
than far branches, rather than limiting them to Intel64 mode, will be
taken care of later on.)
Also take the opportunity and make sure "lfs <reg>, tbyte ptr <mem>"
et al get rejected outside of 64-bit mode. This became broken by
dc2be329b950 ("i386: Only check suffix in instruction mnemonic").
Furthermore cover lgdt et al in the Intel syntax handling as well, which
continued to work after said commit just by coincidence.
Jan Beulich [Wed, 4 Dec 2019 09:44:27 +0000 (10:44 +0100)]
x86-64/Intel: fix CALL/JMP with dword operand
While
dc2be329b950 ("i386: Only check suffix in instruction mnemonic")
has made the assembler accept these in the first place (they were wrongly
rejected before), the generated code was still wrong in that it lacked
an operand size override. (In 64-bit code, other than in 16- and 32-bit
ones, CALL and JMP with memory operands are all entirely unambiguous: No
operand size can have two meanings.)
Jan Beulich [Wed, 4 Dec 2019 09:43:50 +0000 (10:43 +0100)]
x86: consolidate tracking of MMX register use
Just like for XMM/YMM/ZMM don't key this to any Cpu* flags. Instead
include the two special insns (not having register operands) explicitly.
Jan Beulich [Wed, 4 Dec 2019 09:41:43 +0000 (10:41 +0100)]
x86/Intel: extend MOVDIRI testing
Test also memory operands with operand size specifier, which was broken
prior to
dc2be329b950 ("i386: Only check suffix in instruction
mnemonic"), due to the template not permitting any suffixes. Note that
this uncovered a disassembler issue, which is being fixed here as well.
Jan Beulich [Wed, 4 Dec 2019 09:40:40 +0000 (10:40 +0100)]
x86: make sure all PUSH/POP honor DefaultSize
While segment registers are registers, their use doesn't allow sizing
of insns without suffix / explicit operand size specifier. Prevent
PUSH and POP of segment registers from entering that path, instead
allowing them to observe the stackop_size setting just like other
PUSH/POP and alike do.
Jan Beulich [Wed, 4 Dec 2019 09:40:02 +0000 (10:40 +0100)]
x86: drop some stray/bogus DefaultSize
Insns permitting only GPR operands (and hence implicit sizing when
there's no suffix) don't ever have their DefaultSize attribute
inspected, so it shouldn't be there in the first place.
Additionally XBEGIN is like JMP, not CALL, and hence shouldn't be
converted to 32-bit operand size in .code16gcc mode. While the same is
true for SYSRET, it permitting more than one suffix makes it FLDENV-
like, and hence rather than dropping the attribute, for now add it to
the exclusion list to avoid it getting an operand size prefix emitted
in .code16gcc mode. (This will be dealt with later, perhaps together
with FLDENV and friends.)
GDB Administrator [Wed, 4 Dec 2019 00:00:50 +0000 (00:00 +0000)]
Automatic date update in version.in
Christian Biesinger [Tue, 3 Dec 2019 00:58:35 +0000 (18:58 -0600)]
Replace hash function from bcache with fast_hash
This function is not just slower than xxhash, it is slower than
even libiberty's iterative_hash, so there does not seem to be
a reason for it to exist.
------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------
BM_xxh3 11 ns 11 ns
66127192
BM_xxh32 19 ns 19 ns
36792609
BM_xxh64 16 ns 16 ns
42941328
BM_city32 26 ns 26 ns
27028370
BM_city64 17 ns 17 ns
40472793
BM_iterative_hash 77 ns 77 ns
9088854
BM_bcache_hash 125 ns 125 ns
5599232
gdb/ChangeLog:
2019-12-03 Christian Biesinger <cbiesinger@google.com>
* bcache.c (hash): Remove.
(hash_continue): Remove.
* bcache.h (hash): Remove.
(hash_continue): Remove.
(struct bcache) <ctor>: Update.
* psymtab.c (psymbol_hash): Update.
* stabsread.c (hashname): Update.
* utils.h (fast_hash): Add an argument for a start value,
defaulting to zero.
Change-Id: I107f013eda5fdd3293326b5a206be43155dae0f8
Philippe Waroquiers [Sun, 1 Dec 2019 16:24:41 +0000 (17:24 +0100)]
Fix leak of symbol name in block_symbol_cache
A symbol not found inserted in the cache has a xstrdup-ed name
that must be freed, but only the struct block_symbol_cache is freed.
Add a function destroy_block_symbol_cache that clears all slots
before releasing the cache.
2019-12-03 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* symtab.c (symbol_cache_clear_slot): Move close to cleared type.
(destroy_block_symbol_cache): New function.
(symbol_cache:~symbol_cache) Call destroy_block_symbol_cache.
(resize_symbol_cache): Likewise.
Alan Modra [Mon, 2 Dec 2019 13:07:34 +0000 (23:37 +1030)]
PR25230, addr2line fails on dwz output
This patch remedies the following DW_FORM_GNU_ref_alt related problem:
/* FIXME: Do we need to locate the correct CU, in a similar
fashion to the code in the DW_FORM_ref_addr case above ? */
Without the correct CU the wrong abbrevs are used, resulting in
errors and/or wrong file names.
There is scope for further work here. Parsing of CUs should be a two
step process, with the first stage just finding the bounds of the CU.
This would allow find_abstract_instance to quickly find the CU
referenced by DW_FORM_ref_addr or DW_FORM_GNU_ref_alt, then take the
second stage of CU parsing where abbrevs, ranges and suchlike consume
time and memory. As it is, we just process CUs from the start of
.debug_info until we find the one of interest. The testcase in the PR
takes 98G of virtual memory.
PR 25230
* dwarf2.c (struct dwarf2_debug_file): Add line_table and
abbrev_offsets.
(struct abbrev_offset_entry): New.
(hash_abbrev, eq_abbrev, del_abbrev): New functions.
(read_abbrevs): Check whether we have already read abbrevs at
given offset, and add new offset/abbrev to hash table.
(decode_line_info): Keep line table at offset zero in file struct.
Return this for a cu reusing the same dir/file list.
(find_abstract_instance): Find cu for DW_FORM_GNU_ref_alt.
(_bfd_dwarf2_slurp_debug_info): Create offset/abbrev hash tables.
(_bfd_dwarf2_cleanup_debug_info): Adjust deletion of lines and
abbrevs.
Alan Modra [Sat, 30 Nov 2019 06:27:55 +0000 (16:57 +1030)]
PR25230, dwarf2.c per file stash
This is just moving things around, in preparation for parsing alt
file debug_info.
PR 25230
* dwarf2.c (struct dwarf2_debug_file): New struct.
(struct dwarf2_debug): Delete fields now in dwarf2_debug_file.
Add f, alt fields.
(struct comp_unit): Add file field.
(read_indirect_string, read_indirect_line_string): Adjust to suit.
(read_alt_indirect_string, read_alt_indirect_ref): Likewise.
(read_debug_ranges, find_abstract_instance, read_rangelist): Likewise.
(_bfd_dwarf2_stash_syms, place_sections): Likewise.
(stash_maybe_update_info_hash_tablse): Likewise.
(stash_verify_info_hash_table): Likewise.
(_bfd_dwarf2_slurp_debug_info): Likewise.
(_bfd_dwarf2_find_symbol_bias): Likewise.
(_bfd_dwarf2_find_nearest_line): Likewise.
(_bfd_dwarf2_cleanup_debug_info): Likewise.
(read_abbrevs): Add file param and adjust. Update calls.
(stash_comp_unit): Likewise.
(decode_line_info): Delete stash param and adjust. Update calls.
(comp_unit_find_nearest_line): Likewise.
(comp_unit_maybe_decode_line_info): Likewise.
(comp_unit_find_line): Likewise.
(parse_comp_unit): Add file and info_ptr param and adjust. Update
calls.
Alan Modra [Fri, 29 Nov 2019 22:42:29 +0000 (09:12 +1030)]
dwarf2.c: read_abbrevs fail cleanup, and offset checking
read_section does offset checking, reporting an error on out of
bounds. There's no need to duplicate the check in functions calling
read_section. Also, I spotted a place where a pointer difference
expression was being cast to unsigned int, possibly truncating
relevant bits on a 64-bit host.
* dwarf2.c (read_indirect_string): Don't duplicate offset check
done in read_section.
(read_indirect_line_string): Likewise.
(read_alt_indirect_string): Likewise.
(read_alt_indirect_ref): Likewise.
(read_abbrevs): Likewise. Free memory on all failure paths.
Use correct unsigned type for pointer difference comparison.
Alan Modra [Tue, 3 Dec 2019 03:00:33 +0000 (13:30 +1030)]
dwarf2.c stash->sec_info_ptr and stash->sec
These are unused. Remove them. Also fix the wrong sort of 0 being
returned from read_alt_indirect_ref.
* dwarf2.c (struct dwarf2_debug): Update comments. Remove sec
and sec_info_ptr.
(_bfd_dwarf2_slurp_debug_info): Don't set sec or sec_info_ptr.
(stash_comp_unit): Likewise.
(read_alt_indirect_ref): Return NULL not FALSE.
Alan Modra [Sat, 30 Nov 2019 07:38:09 +0000 (18:08 +1030)]
_bfd_dwarf2_find_nearest_line comment fix
These lines should have been removed along with the addr_size parameter.
* dwarf2.c (_bfd_dwarf2_find_nearest_line): Correct function comment.
GDB Administrator [Tue, 3 Dec 2019 00:00:26 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Mon, 2 Dec 2019 23:12:19 +0000 (16:12 -0700)]
Fix build breakage with --disable-tui
An earlier patch introduced a unit test for tui_copy_source_line.
However if the TUI is not built (as is apparently the case on some of
the buildbot builders), then this will fail to link.
This patch fixes the problem. Tested by rebuilding with the TUI
disabled.
gdb/ChangeLog
2019-12-02 Tom Tromey <tom@tromey.com>
* unittests/tui-selftests.c (run_tests): Make conditional.
(_initialize_tui_selftest): Make conditional.
Change-Id: I964811c7635be24cf6c53920e74e920914503674
Christian Biesinger [Mon, 2 Dec 2019 18:33:38 +0000 (12:33 -0600)]
Change type of debug_aix_thread to bool
This fixes AIX build breakage from commit
491144b5e21bbfd41969c175aebb663976f59058
Thanks to Sangamesh Mallayya for pointing this out to me.
gdb/ChangeLog:
2019-12-02 Christian Biesinger <cbiesinger@google.com>
* aix-thread.c (debug_aix_thread): Change type to bool.
Change-Id: Ie7b2eab97b75b48067ef77e414e7510d1f79a525
Luis Machado [Wed, 27 Nov 2019 20:25:05 +0000 (17:25 -0300)]
Remove stale FIXME comment
While debugging something, i noticed this odd FIXME comment. It seems stale
and therefore here's a patch removing it.
gdb/ChangeLog:
2019-12-02 Luis Machado <luis.machado@linaro.org>
* infrun.c (follow_fork_inferior): Remove outdated FIXME comment.
Change-Id: I2436ca4ae4a6741012cafe8123325f738b692c9c
GDB Administrator [Mon, 2 Dec 2019 00:00:21 +0000 (00:00 +0000)]
Automatic date update in version.in
Andrew Burgess [Fri, 29 Nov 2019 00:14:35 +0000 (00:14 +0000)]
gdb: Dynamic string length support
Add support for strings with dynamic length using the DWARF attribute
DW_AT_string_length.
Currently gFortran generates DWARF for some strings that make use of
DW_AT_string_length like this:
<1><2cc>: Abbrev Number: 20 (DW_TAG_string_type)
<2cd> DW_AT_string_length: 5 byte block: 99 bd 1 0 0 (DW_OP_call4: <0x1bd>)
<2d3> DW_AT_byte_size : 4
<2d4> DW_AT_sibling : <0x2e2>
In this type entry the DW_AT_string_length attribute references a
second DW_TAG_formal_parameter that contains the string length. The
DW_AT_byte_size indicates that the length is a 4-byte value.
This commit extends GDB's DWARF parsing for strings so that we can
create dynamic types as well as static types, based on the attribute
the DWARF contains.
I then extend the dynamic type resolution code in gdbtypes.c to add
support for resolving dynamic strings.
gdb/ChangeLog:
* dwarf2read.c (read_tag_string_type): Read the fields required to
make a dynamic string, and possibly create a dynamic range for the
string.
(attr_to_dynamic_prop): Setup is_reference based on the type of
attribute being processed.
* gdbtypes.c (is_dynamic_type_internal): Handle TYPE_CODE_STRING.
(resolve_dynamic_array): Rename to...
(resolve_dynamic_array_or_string): ...this, update header comment,
and accept TYPE_CODE_STRING.
(resolve_dynamic_type_internal): Handle TYPE_CODE_STRING.
gdb/testsuite/ChangeLog:
* gdb.fortran/array-slices.exp: Add test for dynamic strings.
Change-Id: I03f2d181b26156f48f27a03c8a59f9bd4d71ac17
Andrew Burgess [Fri, 29 Nov 2019 00:13:19 +0000 (00:13 +0000)]
gdb/dwarf: Introduce dwarf2_per_cu_int_type function
This is a minor refactor in preparation for the next commit. Splits
the core of dwarf2_per_cu_addr_sized_int_type out into a separate
function. There should be no user visible changes after this commit.
gdb/ChangeLog:
* dwarf2read.c (dwarf2_per_cu_int_type): New function, takes most
of its implementation from...
(dwarf2_per_cu_addr_sized_int_type): ...here, which now just calls
the new function.
Change-Id: I8b849dd338012ec033b3f0a57d65cec0d7a3bd97
Andrew Burgess [Thu, 24 Oct 2019 10:12:11 +0000 (11:12 +0100)]
gdb/fortran: array stride support
Currently GDB supports a byte or bit stride on arrays, in DWARF this
would be DW_AT_bit_stride or DW_AT_byte_stride on DW_TAG_array_type.
However, DWARF can also support DW_AT_byte_stride or DW_AT_bit_stride
on DW_TAG_subrange_type, the tag used to describe each dimension of an
array.
Strides on subranges are used by gFortran to represent Fortran arrays,
and this commit adds support for this to GDB.
I've extended the range_bounds struct to include the stride
information. The name is possibly a little inaccurate now, but this
still sort of makes sense, the structure represents information about
the bounds of the range, and also how to move from the lower to the
upper bound (the stride).
I've added initial support for bit strides, but I've never actually
seen an example of this being generated. Further, I don't really see
right now how GDB would currently handle a bit stride that was not a
multiple of the byte size as the code in, for example,
valarith.c:value_subscripted_rvalue seems geared around byte
addressing. As a consequence if we see a bit stride that is not a
multiple of 8 then GDB will give an error.
gdb/ChangeLog:
* dwarf2read.c (read_subrange_type): Read bit and byte stride and
create a range with stride where appropriate.
* f-valprint.c: Include 'gdbarch.h'.
(f77_print_array_1): Take the stride into account when walking the
array. Also convert the stride into addressable units.
* gdbtypes.c (create_range_type): Initialise the stride to
constant zero.
(create_range_type_with_stride): New function, initialise the
range as normal, and then setup the stride.
(has_static_range): Include the stride here. Also change the
return type to bool.
(create_array_type_with_stride): Consider the range stride if the
array isn't given its own stride.
(resolve_dynamic_range): Resolve the stride if needed.
* gdbtypes.h (struct range_bounds) <stride>: New member variable.
(struct range_bounds) <flag_is_byte_stride>: New member variable.
(TYPE_BIT_STRIDE): Define.
(TYPE_ARRAY_BIT_STRIDE): Define.
(create_range_type_with_stride): Declare.
* valarith.c (value_subscripted_rvalue): Take range stride into
account when walking the array.
gdb/testsuite/ChangeLog:
* gdb.fortran/derived-type-striding.exp: New file.
* gdb.fortran/derived-type-striding.f90: New file.
* gdb.fortran/array-slices.exp: New file.
* gdb.fortran/array-slices.f90: New file.
Change-Id: I9af2bcd1f2d4c56f76f5f3f9f89d8f06bef10d9a
Tom Tromey [Wed, 20 Nov 2019 23:02:29 +0000 (16:02 -0700)]
Treat inactive TUI specially in "info win"
I noticed that "info win" will print the table header, but no windows,
when the TUI is inactive. This patch changes this to print a message
instead.
gdb/ChangeLog
2019-12-01 Tom Tromey <tom@tromey.com>
* tui/tui-win.c (tui_all_windows_info): Treat inactive TUI
specially.
Change-Id: Ia860be8c786a71289da6609aa14d86b8365424db
Tom Tromey [Sun, 17 Nov 2019 22:50:31 +0000 (15:50 -0700)]
Fix latent bug in tui_copy_source_line
tui_copy_source_line has a bug, where it can advance past the
terminating \0 in its input string. This patch fixes the bug and adds
a test case for this function.
gdb/ChangeLog
2019-12-01 Tom Tromey <tom@tromey.com>
* tui/tui-winsource.c (tui_copy_source_line): Don't advance past
\0.
* unittests/tui-selftests.c: New file.
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add tui-selftests.c.
Change-Id: I46cdabe6e57549983149b8f640cda5edd16fa260
Tom Tromey [Sun, 10 Nov 2019 16:11:42 +0000 (09:11 -0700)]
Re-highlight windows when needed during TUI startup
I noticed that "tui enable" did not correctly show the source window
as having the focus. Debugging showed that the problem was that
tui_update_variables was called after the windows were drawn, and its
result was being ignored. This changed the code to re-highlight the
windows if the value changed.
gdb/ChangeLog
2019-12-01 Tom Tromey <tom@tromey.com>
* tui/tui.c (tui_enable): Call tui_update_variables earlier.
Change-Id: I1a4563fb431833dd3211a224c9e2df3b936fe9ce
Tom Tromey [Sat, 9 Nov 2019 21:13:13 +0000 (14:13 -0700)]
Add TUI border colors
This adds the ability to change the color of the TUI borders, both
ordinary and active. Unlike other styling options, this doesn't allow
setting the intensity, because that is already done by the TUI in a
different way.
gdb/ChangeLog
2019-12-01 Tom Tromey <tom@tromey.com>
* NEWS: Document new settings.
* tui/tui-wingeneral.c (box_win): Apply appropriate border style.
* tui/tui-win.c (_initialize_tui_win): Add border style
observers.
* tui/tui-io.h (tui_apply_style): Declare.
* tui/tui-io.c (tui_apply_style): Rename from apply_style. No
longer static.
(apply_ansi_escape, tui_set_reverse_mode): Update.
* cli/cli-style.h (class cli_style_option) <add_setshow_commands>:
Add "skip_intensity" parameter.
<changed>: New member.
<do_set_value>: Declare.
(tui_border_style, tui_active_border_style): Declare.
* cli/cli-style.c (tui_border_style, tui_active_border_style): New
globals.
(cli_style_option): Initialize "changed".
(cli_style_option::do_set_value): New function.
(cli_style_option::add_setshow_commands): Add "skip_intensity"
parameter. Update.
(STYLE_ADD_SETSHOW_COMMANDS): Add "SKIP" parameter.
(_initialize_cli_style): Update. Create TUI border style
commands.
gdb/doc/ChangeLog
2019-12-01 Tom Tromey <tom@tromey.com>
* gdb.texinfo (TUI Configuration): Mention TUI border styles.
(Output Styling): Document new settings.
Change-Id: Id13e2af0af2a0bde61282752f2c379db3220c9fc
Tom Tromey [Thu, 11 Jul 2019 23:06:00 +0000 (17:06 -0600)]
Allow using less horizontal space in TUI source window
The source window currently uses a field width of 6 for line numbers,
and it further aligns to the next tab stop. This seemed a bit
wasteful of horizontal space to me, so I changed that in an earlier
patch.
However, that change wasn't universally popular. This patch instead
adds the option to use less horizontal space in the TUI source window.
gdb/ChangeLog
2019-12-01 Tom Tromey <tom@tromey.com>
* tui/tui-winsource.h (tui_copy_source_line): Add "ndigits"
parameter.
* tui/tui-winsource.c (tui_copy_source_line): Add "ndigits"
parameter.
* tui/tui-win.h (compact_source): Declare.
* tui/tui-win.c (compact_source): New global.
(tui_set_compact_source, tui_show_compact_source): New functions.
(_initialize_tui_win): Add "compact-source" setting.
* tui/tui-source.c (tui_source_window::set_contents): Handle
compact_source setting.
* tui/tui-disasm.c (tui_disasm_window::set_contents): Update.
* NEWS: Document new setting.
gdb/doc/ChangeLog
2019-12-01 Tom Tromey <tom@tromey.com>
* gdb.texinfo (TUI Configuration): Document new setting.
Change-Id: I46ce9a68b12c9c79332d510f9c14b3c84b7efadd
Tom Tromey [Sat, 30 Nov 2019 17:05:23 +0000 (10:05 -0700)]
Correctly compute length of DW_TAG_variant_part union
Currently, gdb internally transforms DW_TAG_variant_part into a union
(with some special attbributes). When doing so, it computes the
length of this union from the length of the fields. However, this
computation didn't include the offset of these fields, resulting in
the length being too short.
This is not a problem given the way the code currently works.
However, I have a patch series to switch gdb to value-based printing,
where this does have an impact.
Tested on x86-64 Fedora 28; and, considering that this only affects
Rust, I am checking it in.
gdb/ChangeLog
2019-11-30 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_add_field): Include field offset when
computing variant part length.
Change-Id: I25d84fc237eb3c1e7f11f6eaf35ffe198efde6cc
GDB Administrator [Sun, 1 Dec 2019 00:01:06 +0000 (00:01 +0000)]
Automatic date update in version.in
Philippe Waroquiers [Sat, 28 Sep 2019 17:30:08 +0000 (19:30 +0200)]
Document define-prefix command and the use of . in command names.
gdb/ChangeLog
2019-11-30 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* NEWS: Mention define-prefix. Tell that command names can now
contain a . character.
gdb/doc/ChangeLog
2019-11-30 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.texinfo (Define): Indicate that user-defined prefix can
be used in 'define' command. Document 'define-prefix' command.
Philippe Waroquiers [Sun, 8 Sep 2019 19:54:18 +0000 (21:54 +0200)]
Allow . character as part of command names.
This patch adds . as an allowed character for user defined commands.
Combined with 'define-prefix', this allows to e.g. define a set of Valgrind
specific user command corresponding to the Valgrind monitor commands
(such as check_memory, v.info, v.set, ...).
gdb/ChangeLog
2019-11-30 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* command.h (valid_cmd_char_p): Declare.
* cli/cli-decode.c (valid_cmd_char_p): New function factorizing
the check of valid command char.
(find_command_name_length, valid_user_defined_cmd_name_p): Use
valid_cmd_char_p.
* cli/cli-script.c (validate_comname): Likewise.
* completer.c (gdb_completer_command_word_break_characters):
Do not remove . from the word break char, update comments.
(complete_line_internal_1): Use valid_cmd_char_p.
* guile/scm-cmd.c (gdbscm_parse_command_name): Likewise.
* python/py-cmd.c (gdbpy_parse_command_name): Likewise.
gdb/testsuite/ChangeLog
2019-11-30 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.base/define.exp: Test . in command names.
* gdb.base/setshow.exp: Update test, as . is now part of
command name.
Philippe Waroquiers [Sun, 8 Sep 2019 17:22:35 +0000 (19:22 +0200)]
Test define-prefix.
Adds a test testing the new define-prefix command.
2019-11-30 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.base/define-prefix.exp: New file.
Philippe Waroquiers [Sun, 8 Sep 2019 13:48:32 +0000 (15:48 +0200)]
Implement user defined prefix.
This patch adds the new 'define-prefix' command that creates (or mark an
existing user defined command) as a prefix command.
This approach was preferred compared to add a -prefix option to
'define' command : with define-prefix, a command can be defined and
afterwards marked as a prefix. Also, it is easier to define a
'prefix' only command in one operation.
This patch also adds completers for the 'define' and 'document' commands.
This makes it easier for the user to type the prefixes for 'define'
and type the documented command name for 'document'.
gdb/ChangeLog
2019-11-30 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* cli/cli-script.c (do_define_command): Ensure a redefined
prefix command is kept as a prefix command.
(define_prefix_command): New function.
(show_user_1): Report user defined prefixes.
(_initialize_cli_script): Create the new 'define-prefix' command.
Add completers for 'define' and 'document'.
* top.c (execute_command): If command is a user-defined prefix only
command, report the list of commands for this prefix command.
GDB Administrator [Sat, 30 Nov 2019 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in
Tankut Baris Aktemur [Fri, 29 Nov 2019 11:17:36 +0000 (12:17 +0100)]
gdb: improve debug output of function overload resolution
Function overload resolution prints debug output if turned on via the
'set debug overload' command. The output includes the badness vector
(BV). For each function, this vector contains a badness value of the
length of parameters as its first element. So, BV[0] does not
correspond to a parameter. The badness values of parameters start
with BV[1].
A badness value is a pair; it contains a rank and a subrank. Printing
both fields provides useful information.
Improve printing the badness vector along these lines.
gdb/ChangeLog:
2019-11-29 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* valops.c (find_oload_champ): Improve debug output.
Change-Id: I771017e7afbbaf4809e2238a9b23274f55c61f55
Tankut Baris Aktemur [Fri, 29 Nov 2019 11:17:36 +0000 (12:17 +0100)]
gdb: fix segfault in overload resolution debug output
A segfault occurs if overload resolution debug mode is turned on via
the 'set debug overload' command. E.g.:
~~~
$ gdb ./a.out
...
(gdb) start
...
(gdb) set debug overload 1
(gdb) print foo(5)
-- Arg is int [8], parm is double [9]
Overloaded function instance (null) # of parms 1
Segmentation fault
$
~~~
The problem is, GDB tries to print the badness vector after it has
been std::move'd. Fix the problem by printing the vector before it is
moved.
gdb/ChangeLog:
2019-11-29 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* valops.c (find_oload_champ): Print part of debug messages
before the badness vector is std::move'd.
Change-Id: Ia623f9637e82ec332bfeac23eb6b0f2ffdcdde27
GDB Administrator [Fri, 29 Nov 2019 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Wed, 27 Nov 2019 01:49:32 +0000 (18:49 -0700)]
Fix creal_internal_fn comment
I noticed that the comment before creal_internal_fn refers to $_cimag,
but should refer to $_creal.
gdb/ChangeLog
2019-11-28 Tom Tromey <tom@tromey.com>
* value.c (creal_internal_fn): Fix comment.
Change-Id: I5665aceb4be5aae7014e914cfb39db184c65d5ea
Tom Tromey [Thu, 28 Nov 2019 03:42:57 +0000 (20:42 -0700)]
Make two range_bounds bitfields unsigned
While debugging gdb, I noticed that the bitfields in a range_bounds
were signed, causing the values of these fields to be -1.
I think this is odd; and while we haven't yet committed to boolean
bitfields, I think it is a small improvement to change these types to
unsigned.
gdb/ChangeLog
2019-11-28 Tom Tromey <tom@tromey.com>
* gdbtypes.h (struct range_bounds) <flag_upper_bound_is_count,
flag_bound_evaluated>: Now unsigned.
Change-Id: Ia377fd931594bbf8653180d4dcb4e60354d90139
Tom Tromey [Wed, 27 Nov 2019 18:18:15 +0000 (11:18 -0700)]
Remove unused declaratoin from guile
guile-internal.h declares a function that is never defined. This
removes the declaration.
gdb/ChangeLog
2019-11-28 Tom Tromey <tom@tromey.com>
* guile/guile-internal.h (vlscm_scm_from_value_unsafe): Don't
declare.
Change-Id: I2dca228534bc1325d2d4bb319c31328121edecc4
Mihails Strasuns [Thu, 28 Nov 2019 08:59:23 +0000 (09:59 +0100)]
jit: minor improvement to debug logging
gdb/ChangeLog:
2019-11-28 Mihails Strasuns <mihails.strasuns@intel.com>
* jit.c (jit_bfd_try_read_symtab): Fix printed function name in the
debug output.
* jit.c (jit_unregister_code): Add debug print to match
`jit_register_code`.
Change-Id: Ie66064f3aaa1c74facfc025c8d87f3a057869779
Andrew Burgess [Mon, 18 Nov 2019 18:08:50 +0000 (18:08 +0000)]
gdb/testsuite: Fix minor bug in skip_btrace*tests procs
The two guard functions skip_btrace_tests and skip_btrace_pt_tests
have a minor bug, if the check function fails to compile then surely
we should skip the btrace tests - currently we return 0 to indicate
don't skip.
gdb/testsuite/ChangeLog:
* lib/gdb.exp (skip_btrace_tests): Return 1 if the test fails to
compile.
(skip_btrace_pt_tests): Likewise.
Change-Id: I6dfc04b4adcf5b9424fb542ece7ddbe751bee301
Andrew Burgess [Mon, 4 Nov 2019 23:03:10 +0000 (23:03 +0000)]
gas/riscv: Produce version 3 DWARF CIE by default
The flag controlling the default DWARF CIE version to produce now
starts with the value -1. This can be modified with the command line
flag as before, but after command line flag processing, in
md_after_parse_args targets can, if the global still has the value -1,
override this value. This gives a target specific default.
If a CIE version is not select either by command line flag, or a
target specific default, then some new code in dwarf2_init now select
a global default. This remains as version 1 to match previous
behaviour.
This RISC-V has a target specific default of version provided, this
make the return column uleb128, which means we can use all DWARF
registers include CSRs.
I chose to switch to version 3 rather than version 4 as this is most
similar to the global default (version 1). Switching to version 4
adds additional columns to the CIE header.
gas/ChangeLog:
* as.c (flag_dwarf_cie_version): Change initial value to -1, and
update comment.
* config/tc-riscv.c (riscv_after_parse_args): Set
flag_dwarf_cie_version if it has not already been set.
* dwarf2dbg.c (dwarf2_init): Initialise flag_dwarf_cie_version if
needed.
* testsuite/gas/riscv/default-cie-version.d: New file.
* testsuite/gas/riscv/default-cie-version.s: New file.
ld/ChangeLog:
* testsuite/ld-elf/eh5.d: Accept version 3 DWARF CIE.
Change-Id: Ibbfe8f0979fba480bf0a359978b09d2b3055555e
Andrew Burgess [Mon, 4 Nov 2019 22:44:48 +0000 (22:44 +0000)]
gas: Check for overflow on return column in version 1 CIE DWARF
In version 1 of DWARF CIE format, the return register column is just a
single byte. For targets with large numbers of DWARF registers, any
use of a register with a high number for the return column
will (currently) silently overflow giving incorrect DWARF.
This commit adds an error when the overflow occurs.
gas/ChangeLog:
* dw2gencfi.c (output_cie): Error on return column overflow.
* testsuite/gas/riscv/cie-rtn-col-1.d: New file.
* testsuite/gas/riscv/cie-rtn-col-3.d: New file.
* testsuite/gas/riscv/cie-rtn-col.s: New file.
Change-Id: I1809f739ba7771737ec012807f0260e1a3ed5e64
Andrew Burgess [Mon, 18 Nov 2019 16:00:59 +0000 (16:00 +0000)]
binutils/gas/riscv: Add DWARF register numbers for CSRs
This commit gives DWARF register numbers to the RISC-V CSRs inline
with the RISC-V ELF specification here:
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md
The CSRs are defined being numbered from 4096 to 8191.
This adds support to the assembler, required in order to reference
CSRs in, for example .cfi directives.
I have then extended dwarf.c in order to support printing CSR names in
the dumped DWARF output. As the CSR name space is quite large and
only sparsely populated, I have provided a new function to perform
RISC-V DWARF register name lookup which uses a switch statement rather
than the table base approach that other architectures use.
Any CSR that does not have a known name will return a name based on
'csr%d' with the %d being replaced by the offset of the CSR from 4096.
gas/ChangeLog:
* config/tc-riscv.c (tc_riscv_regname_to_dw2regnum): Lookup CSR
names too.
* testsuite/gas/riscv/csr-dw-regnums.d: New file.
* testsuite/gas/riscv/csr-dw-regnums.s: New file.
binutils/ChangeLog:
* dwarf.c (regname_internal_riscv): New function.
(init_dwarf_regnames_riscv): Use new function.
Change-Id: I3f70bc24fa8b3c75744e6775eeeb87db70c7ecfb
Andrew Burgess [Mon, 18 Nov 2019 15:28:20 +0000 (15:28 +0000)]
binutils: Make DWARF register name lookup be via a function pointer
Add a layer of indirection for DWARF register name lookup by
introducing a function pointer. Right now all targets use the same
table based implementation that they always have, however, this will
change in a later commit.
binutils/ChangeLog:
* dwarf.c (typedef dwarf_regname_lookup_ftype): New typedef.
(dwarf_regnames_lookup_func): New static global.
(init_dwarf_regnames_i386): Set dwarf_regnames_lookup_func.
(init_dwarf_regnames_iamcu): Likewise.
(init_dwarf_regnames_x86_64): Likewise.
(init_dwarf_regnames_aarch64): Likewise.
(init_dwarf_regnames_s390): Likewise.
(init_dwarf_regnames_riscv): Likewise.
(init_dwarf_regnames_by_elf_machine_code): Reset
dwarf_regnames_lookup_func to NULL.
(init_dwarf_regnames_by_bfd_arch_and_mach): Likewise.
(regname_internal_by_table_only): New function.
(regname): Make use of dwarf_regnames_lookup_func.
Change-Id: Ibbff61c0abea32927f35c9e478793039ab8bb57d
Andrew Burgess [Mon, 18 Nov 2019 12:13:24 +0000 (12:13 +0000)]
binutils: Make some functions static in dwarf.c
The architecture specific register name initialisation routines no
longer need to be externally visible, so make them static.
binutils/ChangeLog:
* dwarf.c (init_dwarf_regnames_i386): Make static.
(init_dwarf_regnames_iamcu): Make static.
(init_dwarf_regnames_x86_64): Make static.
(init_dwarf_regnames_aarch64): Make static.
(init_dwarf_regnames_s390): Make static.
(init_dwarf_regnames_riscv): Make static.
* dwarf.h (init_dwarf_regnames_i386): Delete declaration.
(init_dwarf_regnames_iamcu): Delete declaration.
(init_dwarf_regnames_x86_64): Delete declaration.
(init_dwarf_regnames_aarch64): Delete declaration.
(init_dwarf_regnames_s390): Delete declaration.
(init_dwarf_regnames_riscv): Delete declaration.
Change-Id: I9e350f76f98f46e9e3dd88d502f2a2a83e44cb36
Andrew Burgess [Mon, 18 Nov 2019 12:09:04 +0000 (12:09 +0000)]
binutils: Add a new function to initialise DWARF register name state
Adds a new API function init_dwarf_regnames_by_bfd_arch_and_mach to
initialise the register name state from a BFD architecture and machine
type.
There should be no user visible changes after this commit.
binutils/ChangeLog:
* dwarf.c (init_dwarf_regnames_by_bfd_arch_and_mach): New
function.
* dwarf.h (init_dwarf_regnames_by_bfd_arch_and_mach): Declare.
* objdump.c (dump_dwarf): Call new function instead of calling
specific initialization routines. Restrucure so that eh_addr_size
is still calculated correctly.
Change-Id: I346d665d2079a18ec4d04bd41893d0e9dc05e4b3
Andrew Burgess [Mon, 18 Nov 2019 11:56:51 +0000 (11:56 +0000)]
binutils: Rename init_dwarf_regnames
As part of a process to change how dwarf.c figures out the correct
name for a register I wanted to clean up how we initialise the
register name tracking state.
As part of this I rename init_dwarf_regnames to
init_dwarf_regnames_by_elf_machine_code, later commits will add a
different entry point to initialise the register name state.
There should be no user visible changes after this commit.
binutils/ChangeLog:
* dwarf.c (init_dwarf_regnames): Renamed to...
(init_dwarf_regnames_by_elf_machine_code): ...this.
* dwarf.h (init_dwarf_regnames): Renamed to...
(init_dwarf_regnames_by_elf_machine_code): ...this.
* readelf.c (process_file_header): Update call to use new name.
Change-Id: Ic8d2ef5fb62a8590ecd8cbb7e6258e11c6263594
Andrew Burgess [Tue, 29 Oct 2019 14:50:46 +0000 (14:50 +0000)]
binutils: Be more forgiving of targets with large numbers of registers
Currently if a target has a large ( > 1024 ) number of registers then
we get a warning when dumping the DWARF whenever a register over the
1024 limit is referenced, this occurs in dwarf.c:frame_need_space.
This check was initially introduced to guard against corrupted DWARF
referencing stupidly large numbers of registers.
The frame_need_space function already has a check in place so that, if
a target specifies a set of known DWARF register names then we must
only reference a register within this set, it is only after this check
that we check for the 1024 limit.
What this means is that if a target DOES NOT define a set of known
register names and if we reference more than 1024 registers
frame_need_space will give a warning.
If a target DOES define a set of known registers and there are more
than 1024 defined registers, and we try to reference a register beyond
1024 we will again get an error.
This second case feels wrong to me. My thinking is that if a target
defines a set of registers then it is not unreasonable to assume the
tools can cope with that number of registers. And so, if the target
defines 2000 named DWARF registers, frame_need_space should allow
access to all of these registers.
If a target does not define a set of named registers then the 1024
limit should remain. This is pretty arbitrary, but we do need to have
some limit in place I think, so for now that seems as good as any.
This is an entirely theoretical fix - there are no targets that define
such large numbers of registers, but while experimenting with adding
support for RISC-V CSRs I ran into this issue and felt like it was a
good improvement.
binutils/ChangeLog:
* dwarf.c (frame_need_space): Compare dwarf_regnames_count against
0, and only warn about large numbers of registers if the number is
more than the dwarf_regnames_count.
Change-Id: Ifac1a999ff0677676e81ee373c4c044b6a700827
Andrew Burgess [Tue, 29 Oct 2019 12:56:50 +0000 (12:56 +0000)]
gas/riscv: Remove unneeded structure
We build a hash table of all register classes and numbers. The hash
key is the register name and the hash value is the class and number
encoded into a single value, which is of type 'void *'.
When we pull the values out of the hash we cast them to be a pointer
to a structure, however, we never access the fields of that structure,
we just decode the register class and number from the pointer value
itself.
This commit removes the structure and treats the encoded class and
number as a 'void *' during hash lookup.
gas/ChangeLog:
* config/tc-riscv.c (struct regname): Delete.
(hash_reg_names): Handle value as 'void *'.
Change-Id: Ie7d8f46ca3798f56f4af94395279de684f87f9cc
GDB Administrator [Thu, 28 Nov 2019 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in
Christian Biesinger [Wed, 27 Nov 2019 21:41:25 +0000 (15:41 -0600)]
Add missing ChangeLog entry for the previous commit
Change-Id: Ibc5788e1879ece9cac637d5c99f92ff4084c8ba1
Christian Biesinger [Tue, 26 Nov 2019 21:59:36 +0000 (15:59 -0600)]
Add a NEWS entry for multithreaded symbol loading
Just to let people know that this is available and how to use it.
Also updates the description of the setting to say the default is 0.
gdb/ChangeLog:
2019-11-26 Christian Biesinger <cbiesinger@google.com>
* NEWS: Mention the new multithreaded symbol loading.
Change-Id: I263add6aae03b523f0870ad4d1e972eada4b382a
Christian Biesinger [Tue, 19 Nov 2019 02:48:36 +0000 (20:48 -0600)]
Turn off threaded minsym demangling by default
Per discussion on gdb-patches with Joel, this patch turns off multihreaded
symbol loading by default. It can be turned on using:
maint set worker-threads unlimited
To keep the behavior as close as possible to the old code, it still
calls symbol_set_names in the old place if n_worker_threads is 0.
gdb/ChangeLog:
2019-11-27 Christian Biesinger <cbiesinger@google.com>
* maint.c (n_worker_threads): Default to 0.
(worker_threads_disabled): New function.
* maint.h (worker_threads_disabled): New function.
* minsyms.c (minimal_symbol_reader::record_full): Call symbol_set_names
here if worker_threads_disabled () is true.
(minimal_symbol_reader::install): Skip all threading if
worker_threads_disabled () is true.
Change-Id: I92ba4f6bbf07363189666327cad452d6b9c8e01d
Christian Biesinger [Mon, 30 Sep 2019 21:47:37 +0000 (16:47 -0500)]
Compute msymbol hash codes in parallel
This is for the msymbol_hash and msymbol_demangled_hash hashtables
in objfile_per_bfd_storage. This basically computes those hash
codes together with the demangled symbol name in the background,
before it inserts the symbols in the hash table.
gdb/ChangeLog:
2019-11-27 Christian Biesinger <cbiesinger@google.com>
* minsyms.c (add_minsym_to_hash_table): Use a previously computed
hash code if possible.
(add_minsym_to_demangled_hash_table): Likewise.
(minimal_symbol_reader::install): Compute the hash codes for msymbol
on the background thread.
* symtab.h (struct minimal_symbol) <hash_value, demangled_hash_value>:
Add these fields.
Change-Id: Ifaa3346e9998f05743bff9e2eaad3f83b954d071
Christian Biesinger [Thu, 3 Oct 2019 18:05:06 +0000 (13:05 -0500)]
Precompute hash value for symbol_set_names
We can also compute the hash for the mangled name on a background
thread so make this function even faster (about a 7% speedup).
gdb/ChangeLog:
2019-11-27 Christian Biesinger <cbiesinger@google.com>
* minsyms.c (minimal_symbol_reader::install): Also compute the hash
of the mangled name on the background thread.
* symtab.c (symbol_set_names): Allow passing in the hash of the
linkage_name.
* symtab.h (symbol_set_names): Likewise.
Change-Id: I044449e7eb60cffc1c43efd3412f2b485bd9faac
Andrew Burgess [Wed, 27 Nov 2019 21:18:38 +0000 (21:18 +0000)]
gdb/testsuite: Fix race condition compiling fortran test
The Fortran test gdb.fortran/info-modules compiles the files
info-types.f90 and info-types-2.f90 in that order. Unfortunately
info-types.f90 makes use of a module defined in info-types-2.f90.
This currently doesn't cause a problem if you run all of the Fortran
tests as the info-types.exp test already compiles info-types-2.f90 and
so the module description file 'mod2.mod' will be created, and can
then be found by info-modules.exp during its compile.
If however you try to run just info-modules.exp in a clean build
directory, the test will fail to compile.
Fix this by compiling the source files in the reverse order so that
the module is compiled first, then the test program that uses the
module.
gdb/testsuite/ChangeLog:
* gdb.fortran/info-modules.exp: Compile source files in correct
order.
Change-Id: Ic3a1eded0486f6264ebe3066cf1beafbd2534a91
Kevin Buettner [Sun, 13 Oct 2019 06:12:29 +0000 (23:12 -0700)]
Test case for BZ 25065
Running a GDB with the fix for BZ 25065 should cause these new tests
to all pass.
When run against a GDB without the fix, there will be 2 unresolved
testcases. This is what I see in the gdb.sum file when I try it using
a GDB without the fix:
ERROR: GDB process no longer exists
UNRESOLVED: gdb.dwarf2/imported-unit.exp: ptype main::Foo
ERROR: Couldn't send ptype main::foo to GDB.
UNRESOLVED: gdb.dwarf2/imported-unit.exp: ptype main::foo
These are "unresolved" versus outright failures due to the fact that
GDB dies (segfaults) during the running of the test.
gdb/testsuite/ChangeLog:
* gdb.dwarf2/imported-unit.exp: New file.
* gdb.dwarf2/imported-unit.c: New file.
Change-Id: I073fe69b81bd258951615f752df8e95b6e33a271
Kevin Buettner [Sat, 12 Oct 2019 21:35:56 +0000 (14:35 -0700)]
Fix BZ 25065 - Ensure that physnames are computed for inherited DIEs
This is a fix for BZ 25065.
GDB segfaults when running either gdb.cp/subtypes.exp or
gdb.cp/local.exp in conjunction with using the -flto compiler/linker
flag.
A much simpler program, which was used to help create the test for
this fix, is:
-- doit.cc --
int main()
{
class Foo {
public:
int doit ()
{
return 0;
}
};
Foo foo;
return foo.doit ();
}
-- end doit.cc --
gcc -o doit -flto -g doit.cc
gdb -q doit
Reading symbols from doit...
(gdb) ptype main::Foo
type = class Foo {
Segmentation fault (core dumped)
The segfault occurs due to a NULL physname in
c_type_print_base_struct_union in c-typeprint.c. Specifically,
calling is_constructor_name() eventually causes the SIGSEGV is this
code in c-typeprint.c:
const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
int is_full_physname_constructor =
TYPE_FN_FIELD_CONSTRUCTOR (f, j)
|| is_constructor_name (physname)
|| is_destructor_name (physname)
|| method_name[0] == '~';
However, looking at compute_delayed_physnames(), we see that
the TYPE_FN_FIELD_PHYSNAME field should never be NULL. This
field will be set to "" for NULL physnames:
physname = dwarf2_physname (mi.name, mi.die, cu);
TYPE_FN_FIELD_PHYSNAME (fn_flp->fn_fields, mi.index)
= physname ? physname : "";
For this particular case, it turns out that compute_delayed_physnames
wasn't being called, which left TYPE_FN_FIELD_PHYSNAME set to the NULL
value that it started with when that data structure was allocated.
The place to fix it, I think, is towards the end of
inherit_abstract_dies().
My first attempt at fix caused the origin CU's method_list (which is
simply the list of methods whose physnames still need to be computed)
to be added to the CU which is doing the inheriting. One drawback
with this approach is that compute_delayed_physnames is (eventually)
called with a CU that's different than the CU in which the methods
were found. It's not clear whether this will cause problems or not.
A safer approach, which is what I ultimately settled on, is to call
compute_delayed_physnames() from inherit_abstract_dies(). One
potential drawback is that all needed types might not be known at that
point. However, in my testing, I haven't seen a problem along these
lines.
gdb/ChangeLog:
* dwarf2read.c (inherit_abstract_dies): Ensure that delayed
physnames are computed for inherited DIEs.
Change-Id: I6c6ffe96b301a9daab9f653956b89e3a33fa9445
Tom Tromey [Wed, 27 Nov 2019 18:38:56 +0000 (11:38 -0700)]
Remove some unnecessary backslashes
I found a couple of unnecessary backslashes in gdb. This removes
them.
Offhand, I wonder whether this abstract_to_concrete thing could be
done some other way? This seems possibly expensive.
Anyway, tested by rebuilding. I'm going to check this in as obvious.
gdb/ChangeLog
2019-11-27 Tom Tromey <tromey@adacore.com>
* dwarf2read.h (struct dwarf2_per_objfile): Remove unnecessary
backslashes.
* cp-support.c: Remove unnecessary backslashes.
Change-Id: I956c91ae24407eeafec8a731545b45f5222e6a9d
Christian Biesinger [Tue, 26 Nov 2019 20:41:30 +0000 (14:41 -0600)]
Replace SYMBOL_SET_LINKAGE_NAME with a member function
Easier to read, shorter, and will later make it possible to make the
name field private.
gdb/ChangeLog:
2019-11-27 Christian Biesinger <cbiesinger@google.com>
* ada-exp.y (write_ambiguous_var): Replace SYMBOL_SET_LINKAGE_NAME
with sym->set_linkage_name.
* coffread.c (coff_read_enum_type): Likewise.
* mdebugread.c (parse_symbol): Likewise.
* stabsread.c (patch_block_stabs): Likewise.
(define_symbol): Likewise.
(read_enum_type): Likewise.
(common_block_end): Likewise.
* symtab.h (struct general_symbol_info) <set_linkage_name>: New
function.
(SYMBOL_SET_LINKAGE_NAME): Remove.
* xcoffread.c (process_xcoff_symbol): Replace SYMBOL_SET_LINKAGE_NAME
with sym->set_linkage_name.
Change-Id: I174a0542c014f1b035070068076308bb8ae79abb
Andrew Burgess [Thu, 3 Oct 2019 21:12:09 +0000 (22:12 +0100)]
gdb/mi: Add -symbol-info-modules command
Add '-symbol-info-modules', an MI version of the CLI 'info modules'
command.
gdb/ChangeLog:
* mi/mi-cmds.c (mi_cmds): Add 'symbol-info-modules' entry.
* mi/mi-cmds.h (mi_cmd_symbol_info_modules): Declare.
* mi/mi-symbol-cmds.c (mi_cmd_symbol_info_modules): New function.
* NEWS: Mention new MI command.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-fortran-modules-2.f90: New file.
* gdb.mi/mi-fortran-modules.exp: New file.
* gdb.mi/mi-fortran-modules.f90: New file.
gdb/doc/ChangeLog:
* doc/gdb.texinfo (GDB/MI Symbol Query): Document new MI command
-symbol-info-modules.
Change-Id: Ibc618010d1d5f36ae8a8baba4fb9d9d724e62b0f
Andrew Burgess [Tue, 24 Sep 2019 22:35:47 +0000 (23:35 +0100)]
gdb/mi: Add new commands -symbol-info-{functions,variables,types}
Add new MI commands -symbol-info-functions, -symbol-info-variables,
and -symbol-info-types which correspond to the CLI commands 'info
functions', 'info variables', and 'info types' respectively.
gdb/ChangeLog:
* mi/mi-cmds.c (mi_cmds): Add '-symbol-info-functions',
'-symbol-info-types', and '-symbol-info-variables'.
* mi/mi-cmds.h (mi_cmd_symbol_info_functions): Declare.
(mi_cmd_symbol_info_types): Declare.
(mi_cmd_symbol_info_variables): Declare.
* mi/mi-symbol-cmds.c: Add 'source.h' and 'mi-getopt.h' includes.
(output_debug_symbol): New function.
(output_nondebug_symbol): New function.
(mi_symbol_info): New function.
(mi_info_functions_or_variables): New function.
(mi_cmd_symbol_info_functions): New function.
(mi_cmd_symbol_info_types): New function.
(mi_cmd_symbol_info_variables): New function.
* NEWS: Mention new commands.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-sym-info-1.c: New file.
* gdb.mi/mi-sym-info-2.c: New file.
* gdb.mi/mi-sym-info.exp: New file.
gdb/doc/ChangeLog:
* doc/gdb.texinfo (GDB/MI Symbol Query): Document new MI command
-symbol-info-functions, -symbol-info-types, and
-symbol-info-variables.
Change-Id: Ic2fc6a6750bbce91cdde2344791014e5ef45642d
Andrew Burgess [Tue, 24 Sep 2019 22:22:05 +0000 (23:22 +0100)]
gdb: Split print_symbol_info into two parts
Split the function print_symbol_info into two parts, the new worker
core returns a string, which print_symbol_info then prints. This will
be useful in a later commit when some new MI commands will be added
which will use the worker core to fill some MI output fields.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* symtab.c (symbol_to_info_string): New function, most content
moved from print_symbol_info, but updated to return a std::string.
(print_symbol_info): Update to use symbol_to_info_string and print
returned string.
* symtab.h (symbol_to_info_string): Declare new function.
Change-Id: I6454ce43cacb61d32fbadb9e3655e70823085777
Andrew Burgess [Thu, 10 Oct 2019 09:48:01 +0000 (10:48 +0100)]
gdb: Introduce global_symbol_searcher
Introduce a new class to wrap up the parameters needed for the
function search_symbols, which has now become a member function of
this new class.
The motivation is that search_symbols already takes a lot of
parameters, and a future commit is going to add even more. This
commit hopefully makes collecting the state required for a search
easier.
As part of this conversion the list of filenames in which to search
has been converted to a std::vector.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* python/python.c (gdbpy_rbreak): Convert to using
global_symbol_searcher.
* symtab.c (file_matches): Convert return type to bool, change
file list to std::vector, update header comment.
(search_symbols): Rename to...
(global_symbol_searcher::search): ...this and update now its
a member function of global_symbol_searcher. Take account of the
changes to file_matches.
(symtab_symbol_info): Convert to using global_symbol_searcher.
(rbreak_command): Likewise.
(search_module_symbols): Likewise.
* symtab.h (enum symbol_search): Update comment.
(search_symbols): Remove declaration.
(class global_symbol_searcher): New class.
Change-Id: I488ab292a892d9e9e84775c632c5f198b6ad3710
Alan Modra [Wed, 27 Nov 2019 07:30:59 +0000 (18:00 +1030)]
PR23652, Use symbols from debug bfd for _bfd_elf_find_function properly
There were a number of problems with the previous patch. Firstly,
_bfd_dwarf2_stash_syms didn't do anything when the original file had
dynamic symbols, and secondly, info found by the symbol search didn't
make it out of _bfd_elf_find_nearest_line except in the case of DWARF
functions without external linkage.
PR 23652
* dwarf2.c (_bfd_dwarf2_stash_syms): Break out of loop on finding
matching section.
(_bfd_dwarf2_find_nearest_line): Return an int, with value 2 when
returning info from the symbol table. Do the _bfd_elf_find_function
search also when !found. Call _bfd_dwarf2_stash_syms regardless of
symbols.
* elf64-alpha.c (elf64_alpha_find_nearest_line): Accept dwarf2
result of 1 only.
* elfxx-mips.c (_bfd_mips_elf_find_nearest_line): Likewise.
* libbfd-in.h (_bfd_dwarf2_find_nearest_line): Update prototype.
* libbfd.h: Regenerate.
Alan Modra [Tue, 26 Nov 2019 12:02:51 +0000 (22:32 +1030)]
PR23652, Use symbols from debug bfd for _bfd_elf_find_function
Sometimes DWARF info for a function is incomplete, and the function
can be retrieved by examining symbols. However, when separate debug
files are used it may be that the original file is completely
stripped of symbols. This patch teaches BFD to look at symbols from
the debug file in that case.
The patch also removes arm_elf_find_function, instead implementing
elf_backend_maybe_function_sym. arm_elf_find_function was written
before the generic _bfd_elf_find_function called maybe_function_sym.
aarch64 copied arm, so that file gets the same treatment. There is
some chance this will speed up arm and aarch64 lookup of function/line.
PR 23652
* dwarf2.c (_bfd_dwarf2_stash_syms): New function.
(_bfd_dwarf2_find_nearest_line): Use it here, passing syms to
_bfd_elf_find_function. Call _bfd_elf_find_function in cases
where _bfd_elf_find_nearest_line would do so.
* elf.c (_bfd_elf_find_nearest_line): Omit _bfd_elf_find_function
for dwarf2.
* elfxx-mips.c (_bfd_mips_elf_find_nearest_line): Similarly. Tidy.
* elf32-arm.c (elf32_arm_maybe_function_sym): New function.
(elf_backend_maybe_function_sym): Define.
(arm_elf_find_function, elf32_arm_find_nearest_line): Delete.
(bfd_elf32_find_nearest_line): Don't define.
* elfnn-aarch64.c (elfNN_aarch64_maybe_function_sym): New function.
(elf_backend_maybe_function_sym): Define.
(aarch64_elf_find_function, elfNN_aarch64_find_nearest_line): Delete.
(bfd_elfNN_find_nearest_line): Don't define.
Alan Modra [Wed, 27 Nov 2019 00:21:27 +0000 (10:51 +1030)]
Correct R_SH_IND12W handling
Using bfd_vma for insn is to avoid having to worry about sign
propagation in expressions involving insn and sym_value when bfd_vma
is not the same as unsigned long.
* elf32-sh.c (sh_reloc): Use a bfd_vma insn.
(sh_reloc <R_SH_IND12W>): Divide calculated relocation value
by two before applying to insn. Correct overflow test.
* coff-sh.c (sh_reloc): Likewise.
GDB Administrator [Wed, 27 Nov 2019 00:00:30 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Tue, 26 Nov 2019 22:14:57 +0000 (15:14 -0700)]
Fix mingw build of gdb
Christian pointed out on irc that the threading series broke the build
on mingw. This patch fixes the problem, by moving the initialization
of gdb_demangle_attempt_core_dump into the appropriate #if.
gdb/ChangeLog
2019-11-26 Tom Tromey <tromey@adacore.com>
* cp-support.c (_initialize_cp_support): Conditionally initialize
gdb_demangle_attempt_core_dump.
Change-Id: I9ace0bea75a51f317ea933b607f6b5a94d651eea
Tom Tromey [Fri, 15 Nov 2019 23:56:20 +0000 (16:56 -0700)]
Let commands free "name"
This adds a "name_allocated" field to cmd_list_element, so that
commands can own their "name" when necessary. Then, this changes a
few spots in gdb that currently free the name by hand to instead use
this facility.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* python/py-function.c (fnpy_init): Update.
* value.h (add_internal_function): Adjust declaration.
* value.c (function_destroyer): Remove.
(do_add_internal_function): Don't set destroyer or copy name.
(add_internal_function): Take unique_xmalloc_ptr<char> for name.
Set name_allocated.
* python/py-cmd.c (cmdpy_destroyer): Don't free "name".
(cmdpy_init): Set name_allocated.
* cli/cli-decode.h (struct cmd_list_element) <name_allocated>: New
member.
(~cmd_list_element): Free "name" if needed.
Change-Id: Ie1435cea5bbf4bd92056125f112917c607cbb761
Tom Tromey [Fri, 15 Nov 2019 23:49:17 +0000 (16:49 -0700)]
Add add_internal_function overload
add_internal_function sets a command destroyer that frees the doc
string. However, many callers do not pass in an allocated doc string.
This adds a new overload to clearly differentiate the two cases,
fixing the latent bug.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* value.h (add_internal_function): Add new overload. Move
documentation from value.h.
* value.c (do_add_internal_function): New function.
(add_internal_function): Use it. Add new overload.
(function_destroyer): Don't free doc.
* python/py-function.c (fnpy_init): Update.
Change-Id: I3f6df925bc6b3e1bccbad9eeebc487b908bb5a2a
Tom Tromey [Fri, 15 Nov 2019 23:41:12 +0000 (16:41 -0700)]
Use cmd_list_element::doc_allocated for Python commands
Python commands manage their "doc" string manually, but
cmd_list_element already has doc_allocated to handle this case. This
changes the Python code to use the existing facility.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* python/py-cmd.c (cmdpy_destroyer): Don't free "doc".
(cmdpy_init): Set "doc_allocated".
Change-Id: I0014edc117b051bba1f4db267687d231e7fe9b56
Tom Tromey [Sat, 12 Oct 2019 19:06:18 +0000 (13:06 -0600)]
Set names of worker threads
This adds some configury so that gdb can set the names of worker
threads. This makes them show up more nicely when debugging gdb
itself.
2019-11-26 Tom Tromey <tom@tromey.com>
* gdbsupport/thread-pool.c (thread_pool::set_thread_count): Set
name of worker thread.
* gdbsupport/common.m4 (GDB_AC_COMMON): Check for
pthread_setname_np.
* configure, config.in: Rebuild.
gdb/gdbserver/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* configure, config.in: Rebuild.
Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35
Tom Tromey [Sat, 8 Jun 2019 14:15:57 +0000 (08:15 -0600)]
Use run_on_main_thread in gdb.post_event
This changes gdb.post_event to use the new run_on_main_thread
function. This is somewhat tricky because the Python GIL must be held
while manipulating reference counts.
2019-11-26 Tom Tromey <tom@tromey.com>
* python/python.c (class gdbpy_gil): New.
(struct gdbpy_event): Add constructor, destructor, operator().
(gdbpy_post_event): Use run_on_main_thread.
(gdbpy_initialize_events): Remove.
(do_start_initialization): Update.
Change-Id: Ie4431e60f328dae48bd96b6c6a8e875e70bda1de
Tom Tromey [Sat, 16 Mar 2019 20:36:57 +0000 (14:36 -0600)]
Add maint set/show worker-threads
This adds maint commands to control the number of worker threads that
gdb can use.
2019-11-26 Tom Tromey <tom@tromey.com>
* NEWS: Add entry.
* maint.c (_initialize_maint_cmds): Add "worker-threads" maint
commands. Call update_thread_pool_size.
(update_thread_pool_size, maintenance_set_worker_threads): New
functions.
(n_worker_threads): New global.
gdb/doc/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* gdb.texinfo (Maintenance Commands): Document new maint
commands.
Change-Id: I4fb514faa05879d8afe62c77036a4469d57dca2a
Tom Tromey [Sun, 3 Mar 2019 17:15:30 +0000 (10:15 -0700)]
Demangle minsyms in parallel
This patch introduces a simple parallel for_each and changes the
minimal symbol reader to use it when computing the demangled name for
a minimal symbol. This yields a speedup when reading minimal symbols.
2019-11-26 Christian Biesinger <cbiesinger@google.com>
Tom Tromey <tom@tromey.com>
* minsyms.c (minimal_symbol_reader::install): Use
parallel_for_each.
* gdbsupport/parallel-for.h: New file.
* Makefile.in (HFILES_NO_SRCDIR): Add gdbsupport/parallel-for.h.
Change-Id: I220341f70e94dd02df5dd424272c50a5afb64978
Christian Biesinger [Tue, 1 Oct 2019 23:38:35 +0000 (18:38 -0500)]
Implement a thread pool
This adds a simple thread pool to gdb. In the end, this seemed
preferable to the approach taken in an earlier version of this series;
namely, starting threads in the parallel-foreach implementation. This
approach reduces the overhead of starting new threads, and also lets
the user control (in a subsequent patch) exactly how many worker
threads are running.
gdb/ChangeLog
2019-11-26 Christian Biesinger <cbiesinger@google.com>
Tom Tromey <tom@tromey.com>
* gdbsupport/thread-pool.h: New file.
* gdbsupport/thread-pool.c: New file.
* Makefile.in (COMMON_SFILES): Add thread-pool.c.
(HFILES_NO_SRCDIR): Add thread-pool.h.
Change-Id: I597bb642780cb9d578ca92373d2a638efb44fe52
Tom Tromey [Mon, 4 Mar 2019 22:12:04 +0000 (15:12 -0700)]
Introduce thread-safe way to handle SIGSEGV
The gdb demangler installs a SIGSEGV handler in order to protect gdb
from demangler bugs. However, this is not thread-safe, as signal
handlers are global to the process.
This patch changes gdb to always install a global SIGSEGV handler, and
then lets threads indicate their interest in handling the signal by
setting a thread-local variable.
This patch then arranges for the demangler code to use this; being
sure to arrange for calls to warning and the like to be done on the
main thread.
One thing I wondered while writing this patch is if there are any
systems that do not have "sigaction". If gdb could assume this, it
would simplify this code.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* event-top.h (thread_local_segv_handler): Declare.
* event-top.c (thread_local_segv_handler): New global.
(install_handle_sigsegv, handle_sigsegv): New functions.
(async_init_signals): Install SIGSEGV handler.
* cp-support.c (gdb_demangle_jmp_buf): Change type. Now
thread-local.
(report_failed_demangle): New function.
(gdb_demangle): Make core_dump_allowed atomic. Remove signal
handler-setting code, instead use segv_handler. Run warning code
on main thread.
Change-Id: Ic832bbb033b64744e4b44f14b41db7e4168ce427
Tom Tromey [Fri, 8 Mar 2019 22:51:06 +0000 (15:51 -0700)]
Introduce run_on_main_thread
This introduces a way for a callback to be run on the main thread.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* run-on-main-thread.c: New file.
* run-on-main-thread.h: New file.
* unittests/main-thread-selftests.c: New file.
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
main-thread-selftests.c.
(HFILES_NO_SRCDIR): Add run-on-main-thread.h.
(COMMON_SFILES): Add run-on-main-thread.c.
Change-Id: I16ef82f0564e9f8a524bdc64cb31df79a988ad9f
Tom Tromey [Sun, 29 Sep 2019 15:27:11 +0000 (09:27 -0600)]
Introduce alternate_signal_stack RAII class
This introduces a new RAII class that temporarily installs an
alternate signal stack (on systems that have sigaltstack); then
changes the one gdb use of sigaltstack to use this class instead.
This will be used in a later patch, when creating new threads that may
want to handle SIGSEGV.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* main.c (setup_alternate_signal_stack): Remove.
(captured_main_1): Use gdb::alternate_signal_stack.
* gdbsupport/alt-stack.h: New file.
Change-Id: I721c047ae9d51a35fd274a6dbc00a58c6440dae6
Tom Tromey [Sun, 29 Sep 2019 14:50:15 +0000 (08:50 -0600)]
Add RAII class for blocking gdb signals
This adds configury support and an RAII class that can be used to
temporarily block signals that are used by gdb. (This class is not
used in this patch, but it split out for easier review.)
The idea of this patch is that these signals should only be delivered
to the main thread. So, when creating a background thread, they are
temporarily blocked; the blocked state is inherited by the new thread.
The sigprocmask man page says:
The use of sigprocmask() is unspecified in a multithreaded
process; see pthread_sigmask(3).
This patch changes gdb to use pthread_sigmask when appropriate, by
introducing a convenience define.
I've updated gdbserver as well, because I had to touch gdbsupport, and
because the threading patches will make it link against the thread
library.
I chose not to touch the NTO code, because I don't know anything about
that platform and because I cannot test it.
Finally, this modifies an existing spot in the Guile layer to use the
new facility.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* gdbsupport/signals-state-save-restore.c (original_signal_mask):
Remove comment.
(save_original_signals_state, restore_original_signals_state): Use
gdb_sigmask.
* linux-nat.c (block_child_signals, restore_child_signals_mask)
(_initialize_linux_nat): Use gdb_sigmask.
* guile/guile.c (_initialize_guile): Use block_signals.
* Makefile.in (HFILES_NO_SRCDIR): Add gdb-sigmask.h.
* gdbsupport/gdb-sigmask.h: New file.
* event-top.c (async_sigtstp_handler): Use gdb_sigmask.
* cp-support.c (gdb_demangle): Use gdb_sigmask.
* gdbsupport/common.m4 (GDB_AC_COMMON): Check for
pthread_sigmask.
* configure, config.in: Rebuild.
* gdbsupport/block-signals.h: New file.
gdb/gdbserver/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* remote-utils.c (block_unblock_async_io): Use gdb_sigmask.
* linux-low.c (linux_wait_for_event_filtered, linux_async): Use
gdb_sigmask.
* configure, config.in: Rebuild.
Change-Id: If3f37dc57dd859c226e9e4d79458a0514746e8c6
Tom Tromey [Fri, 15 Mar 2019 23:38:06 +0000 (17:38 -0600)]
Add configure check for std::thread
This adds a configure check for std::thread. This is needed because
std::thread is not available on some systems, like some versions of
mingw and DJGPP.
This also adds configury to make sure that a threaded gdb links
against the correct threading library (-lpthread or the like), and
passes the right flags (e.g., -pthread) to the compilations.
Note that this also links gdbserver against the thread library. This
is not strictly necessary at this point in the series, but a later
patch will change gdbsupport to use pthread_sigmask, at which point
this will be needed.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* acinclude.m4: Include ax_pthread.m4.
* Makefile.in (PTHREAD_CFLAGS, PTHREAD_LIBS): New variables.
(INTERNAL_CFLAGS_BASE): Use PTHREAD_CFLAGS.
(CLIBS): Use PTHREAD_LIBS.
(aclocal_m4_deps): Add ax_pthread.m4.
* config.in, configure: Rebuild.
* gdbsupport/common.m4 (GDB_AC_COMMON): Check for std::thread.
gdb/gdbserver/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* Makefile.in (PTHREAD_CFLAGS, PTHREAD_LIBS): New variables.
(INTERNAL_CFLAGS_BASE): Use PTHREAD_CFLAGS.
(GDBSERVER_LIBS): Use PTHREAD_LIBS.
* acinclude.m4: Include ax_pthread.m4.
* config.in, configure: Rebuild.
Change-Id: I00ec55db6077f2615421a93461fc3be57e916aa0
Tom Tromey [Sat, 2 Mar 2019 20:19:44 +0000 (13:19 -0700)]
Defer minimal symbol name-setting
Currently the demangled name of a minimal symbol is set when creating
the symbol. However, there is no intrinsic need to do this. This
patch instead arranges for the demangling to be done just before the
minsym hash tables are filled. This will be useful in a later patch.
gdb/ChangeLog
2019-11-26 Tom Tromey <tom@tromey.com>
* symtab.h (struct minimal_symbol) <name_set>: New member.
* minsyms.c (minimal_symbol_reader::record_full): Copy name.
Don't call symbol_set_names.
(minimal_symbol_reader::install): Call symbol_set_names.
Change-Id: I4fe3993b99fb3a43968067806e294d48e377fd76
Philippe Waroquiers [Sat, 23 Nov 2019 10:08:12 +0000 (11:08 +0100)]
Fix crashes due to python GIL released too early
When running GDB tests under Valgrind, various tests are failing due
to invalid memory access.
Here is the stack trace reported by Valgrind, for gdb.base/freebpcmd.exp :
==18658== Invalid read of size 8
==18658== at 0x7F9107: is_main (signalmodule.c:195)
==18658== by 0x7F9107: PyOS_InterruptOccurred (signalmodule.c:1730)
==18658== by 0x3696E2: check_quit_flag() (extension.c:829)
==18658== by 0x36980B: restore_active_ext_lang(active_ext_lang_state*) (extension.c:782)
==18658== by 0x48F617: gdbpy_enter::~gdbpy_enter() (python.c:235)
==18658== by 0x47BB71: add_thread_object(thread_info*) (object.h:470)
==18658== by 0x53A84D: operator() (std_function.h:687)
==18658== by 0x53A84D: notify (observable.h:106)
==18658== by 0x53A84D: add_thread_silent(ptid_t) (thread.c:311)
==18658== by 0x3CD954: inf_ptrace_target::create_inferior(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&
, char**, int) (inf-ptrace.c:139)
==18658== by 0x3FE644: linux_nat_target::create_inferior(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&,
char**, int) (linux-nat.c:1094)
==18658== by 0x3D5727: run_command_1(char const*, int, run_how) (infcmd.c:633)
==18658== by 0x2C05D1: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1948)
==18658== by 0x53F29F: execute_command(char const*, int) (top.c:639)
==18658== by 0x3638EB: command_handler(char const*) (event-top.c:586)
==18658== by 0x36468C: command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) (event-top.c:771)
==18658== by 0x36407C: gdb_rl_callback_handler(char*) (event-top.c:217)
==18658== by 0x5B2A1F: rl_callback_read_char (callback.c:281)
==18658== by 0x36346D: gdb_rl_callback_read_char_wrapper_noexcept() (event-top.c:175)
==18658== by 0x363F70: gdb_rl_callback_read_char_wrapper(void*) (event-top.c:192)
==18658== by 0x3633AF: stdin_event_handler(int, void*) (event-top.c:514)
==18658== by 0x362504: gdb_wait_for_event (event-loop.c:857)
==18658== by 0x362504: gdb_wait_for_event(int) (event-loop.c:744)
==18658== by 0x362676: gdb_do_one_event() [clone .part.11] (event-loop.c:321)
==18658== by 0x3627AD: gdb_do_one_event (event-loop.c:303)
==18658== by 0x3627AD: start_event_loop() (event-loop.c:370)
==18658== by 0x41D35A: captured_command_loop() (main.c:381)
==18658== by 0x41F2A4: captured_main (main.c:1224)
==18658== by 0x41F2A4: gdb_main(captured_main_args*) (main.c:1239)
==18658== by 0x227D0A: main (gdb.c:32)
==18658== Address 0x10 is not stack'd, malloc'd or (recently) free'd
The problem seems to be created by gdbpy_enter::~gdbpy_enter () releasing the GIL lock
too early:
~gdbpy_enter () does:
...
PyGILState_Release (m_state);
python_gdbarch = m_gdbarch;
python_language = m_language;
restore_active_ext_lang (m_previous_active);
}
So, it releases the GIL lock, does 2 assignments and then leads to the following
call sequence:
restore_active_ext_lang => check_quit_flag => python.c gdbpy_check_quit_flag
=> PyOS_InterruptOccurred => is_main.
is_main code is:
static int
is_main(_PyRuntimeState *runtime)
{
unsigned long thread = PyThread_get_thread_ident();
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
return (thread == runtime->main_thread
&& interp == runtime->interpreters.main);
}
The macros and functions to access the thread state are documented as:
/* Variable and macro for in-line access to current thread
and interpreter state */
#define _PyRuntimeState_GetThreadState(runtime) \
((PyThreadState*)_Py_atomic_load_relaxed(&(runtime)->gilstate.tstate_current))
/* Get the current Python thread state.
Efficient macro reading directly the 'gilstate.tstate_current' atomic
variable. The macro is unsafe: it does not check for error and it can
return NULL.
The caller must hold the GIL.
See also PyThreadState_Get() and PyThreadState_GET(). */
#define _PyThreadState_GET() _PyRuntimeState_GetThreadState(&_PyRuntime)
So, we see that GDB releases the GIL and then potentially calls
_PyRuntimeState_GetThreadState that needs the GIL.
It is not very clear why the problem is only observed when running under
Valgrind. Probably caused by the slowdown due to Valgrind and/or to the 'single
thread' scheduling by Valgrind.
This patch fixes the crashes by releasing the GIT lock later.
2019-11-26 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* python/python.c (gdbpy_enter::~gdbpy_enter): Release GIL after
restore_active_ext_lang, as GIL is needed for (indirectly)
called PyOS_InterruptOccurred.
Simon Marchi [Tue, 26 Nov 2019 17:12:04 +0000 (12:12 -0500)]
Fix declaration of sparc_xfer_wcookie
When building sparc-nat.c with -Wmissing-declarations, we get:
CXX sparc-nat.o
/home/smarchi/src/binutils-gdb/gdb/sparc-nat.c: In function ‘target_xfer_status sparc_xfer_wcookie(target_ops*, target_object, const char*, gdb_byte*, const gdb_byte*, ULONGEST, ULONGEST, ULONGEST*)’:
/home/smarchi/src/binutils-gdb/gdb/sparc-nat.c:255:1: error: no previous declaration for ‘target_xfer_status sparc_xfer_wcookie(target_ops*, target_object, const char*, gdb_byte*, const gdb_byte*, ULONGEST, ULONGEST, ULONGEST*)’ [-Werror=missing-declarations]
sparc_xfer_wcookie (struct target_ops *ops, enum target_object object,
^~~~~~~~~~~~~~~~~~
Indeed, the declaration is not in sync with the definition, fix that.
sparc_xfer_wcookie is used in sparc_target::xfer_partial. sparc_target
is only used in the BSD sparc native files. The error above was
obtained by running "make sparc-nat.o" on Linux with a cross-compiler
for sparc64-linux-gnu. But I presume that if we were to build for real
with a BSD/sparc compiler, we would end up with an undefined symbol.
gdb/ChangeLog:
* sparc-nat.c (sparc_xfer_wcookie): Sync declaration with
definition.
Change-Id: Id41e706e5516968ff6a49469ddc48eceb29dd3ea
Simon Marchi [Tue, 26 Nov 2019 17:12:04 +0000 (12:12 -0500)]
Remove simulator_command declaration, make static
The simulator_command function is not used outside its file, so make it
static. Remove the declaration, which is not needed and not even in
sync with the definition.
gdb/ChangeLog:
* remote-sim.c (simulator_command): Make static, remove
declaration.
Change-Id: I40bd1e3662f849c4c9970443931ab9ee0ccccea1
Simon Marchi [Tue, 26 Nov 2019 17:12:03 +0000 (12:12 -0500)]
Make functions static in unittests
Enabling -Wmissing-declarations points out that a bunch of function in
the unittests can be made static, do that.
gdb/ChangeLog:
* unittests/array-view-selftests.c (check_ptr_size_ctor2): Make
static.
* unittests/basic_string_view/capacity/1.cc (test01): Likewise.
* unittests/basic_string_view/cons/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/cons/char/2.cc (test03): Likewise.
(main): Likewise.
* unittests/basic_string_view/cons/char/3.cc (test05): Likewise.
(main): Likewise.
* unittests/basic_string_view/element_access/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/element_access/char/empty.cc (main): Likewise.
* unittests/basic_string_view/element_access/char/front_back.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/inserters/char/2.cc (test05): Likewise.
(main): Likewise.
* unittests/basic_string_view/modifiers/remove_prefix/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/modifiers/remove_suffix/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/modifiers/swap/char/1.cc (test01): Likewise.
* unittests/basic_string_view/operations/compare/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/compare/char/13650.cc (test01): Likewise.
* unittests/basic_string_view/operations/copy/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/data/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/find/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/find/char/2.cc (test02): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/find/char/3.cc (test03): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/find/char/4.cc (main): Likewise.
* unittests/basic_string_view/operations/rfind/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/rfind/char/2.cc (test02): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/rfind/char/3.cc (test03): Likewise.
(main): Likewise.
* unittests/basic_string_view/operations/substr/char/1.cc (test01): Likewise.
(main): Likewise.
* unittests/basic_string_view/operators/char/2.cc (main): Likewise.
* unittests/optional/assignment/1.cc (test): Likewise.
* unittests/optional/assignment/2.cc (test): Likewise.
* unittests/optional/assignment/3.cc (test): Likewise.
* unittests/optional/assignment/4.cc (test): Likewise.
* unittests/optional/assignment/5.cc (test): Likewise.
* unittests/optional/assignment/6.cc (test): Likewise.
* unittests/optional/assignment/7.cc (test): Likewise.
* unittests/optional/cons/copy.cc (test): Likewise.
* unittests/optional/cons/default.cc (test): Likewise.
* unittests/optional/cons/move.cc (test): Likewise.
* unittests/optional/cons/value.cc (test): Likewise.
* unittests/optional/in_place.cc (test): Likewise.
* unittests/optional/observers/1.cc (test): Likewise.
* unittests/optional/observers/2.cc (test): Likewise.
Change-Id: I66626db864cb877cacc570d4660df633530554f5
Simon Marchi [Tue, 26 Nov 2019 17:12:03 +0000 (12:12 -0500)]
Remove declaration of tui_set_var_cmd, make definition static
The declaration of tui_set_var_cmd is not in sync with the definition.
Since tui_set_var_cmd is only used in the file where it's defined,
remove the declaration and make the definition static.
gdb/ChangeLog:
* tui-win.h (tui_set_var_cmd): Remove.
* tui-win.c (tui_set_var_cmd): Make static.
Change-Id: If4bddbfb573347fb7254fb6f1a940052a72f464f
Simon Marchi [Tue, 26 Nov 2019 17:12:03 +0000 (12:12 -0500)]
Remove unused rbreak_command_wrapper and other declarations
rbreak_command_wrapper is unused, so remove it. And while at it, remove
other declarations around it.
gdb/ChangeLog:
* breakpoint.h (hbreak_command_wrapper, thbreak_command_wrapper,
rbreak_command_wrapper): Remove.
* symtab.c (rbreak_command_wrapper): Remove.
Change-Id: If9782f205e4913f8dfc5beeaa526544f25e099c6
Simon Marchi [Tue, 26 Nov 2019 17:12:02 +0000 (12:12 -0500)]
Remove info_terminal_command declaration, make definition static
The info_terminal_command declaration in inflow.h does not match the
current definition. It is not needed anyway, as info_terminal_command
is only used locally, so remove it and make the definition static.
gdb/ChangeLog:
* inferior.h (info_terminal_command): Remove declaration.
* inflow.c (info_terminal_command): Make static.
Change-Id: I22c3fcc44244e3cf877b5e27eff189af11c39503
Simon Marchi [Tue, 26 Nov 2019 17:12:02 +0000 (12:12 -0500)]
Remove unused overload of exit_inferior_silent
This function is not used in the code base.
gdb/ChangeLog:
* inferior.c (exit_inferior_silent): Remove.
Change-Id: Ib2b7662744da079185ceac2a165b47590bd3113c
Simon Marchi [Tue, 26 Nov 2019 17:12:01 +0000 (12:12 -0500)]
Remove dict_empty/mdict_empty
These functions are not used in the code base, remove them.
gdb/ChangeLog:
* dictionary.c (dict_empty, mdict_empty): Remove.
* dictionary.c (mdict_empty): Remove.
Change-Id: I4c1b08c730f6790b2f3d28b680607618e3c08e48
Simon Marchi [Tue, 26 Nov 2019 17:12:01 +0000 (12:12 -0500)]
Make a bunch of functions static
All these functions are only used in their respective files, they are
missing the static keyword, add them.
gdb/ChangeLog:
* arc-tdep.c (arc_insn_get_memory_base_reg): Make static.
(arc_insn_get_memory_offset): Likewise.
(arc_insn_dump): Likewise.
* cp-support.c (test_cp_symbol_name_matches): Likewise.
* csky-linux-tdep.c (csky_supply_fregset): Likewise.
* dictionary.c (dict_iterator_next): Likewise.
(dict_iter_match_first): Likewise.
(dict_iter_match_next): Likewise.
* f-lang.c (evaluate_subexp_f): Likewise.
* hppa-tdep.c (hppa_read_pc): Likewise.
* i386-tdep.c (i386_floatformat_for_type): Likewise.
* parse.c (write_exp_elt_msym): Likewise.
* ppc-linux-tdep.c (ppc_floatformat_for_type): Likewise.
* remote.c (remote_packet_size): Likewise.
(remote_notif_stop_parse): Likewise.
* rs6000-aix-tdep.c (aix_sighandle_frame_sniffer): Likewise.
* s12z-tdep.c (s12z_disassemble_info): Likewise.
* source.c (prepare_path_for_appending): Likewise.
* sparc64-linux-tdep.c
(sparc64_linux_handle_segmentation_fault); Likewise.
* stack.c (frame_selection_by_function_completer): Likewise.
Change-Id: I18e187ad279075b961e3e22e5b034f5c0f6188f0
Simon Marchi [Tue, 26 Nov 2019 17:12:01 +0000 (12:12 -0500)]
Remove unused function set_gdb_completion_word_break_characters
gdb/ChangeLog:
* completer.c (set_gdb_completion_word_break_characters):
Remove.
Change-Id: If39b8d01f215a42ea3d01fb8290014613ec0bb8b
Simon Marchi [Tue, 26 Nov 2019 17:12:00 +0000 (12:12 -0500)]
Add missing includes in dwarf-index-write.c and mi/mi-interp.c
The following errors show that these files are missing the include of
their matching header, add them.
CXX dwarf-index-write.o
/home/smarchi/src/binutils-gdb/gdb/dwarf-index-write.c: In function ‘void write_psymtabs_to_index(dwarf2_per_objfile*, const char*, const char*, const char*, dw_index_kind)’:
/home/smarchi/src/binutils-gdb/gdb/dwarf-index-write.c:1670:1: error: no previous declaration for ‘void write_psymtabs_to_index(dwarf2_per_objfile*, const char*, const char*, const char*, dw_index_kind)’ [-Werror=missing-declarations]
write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
^~~~~~~~~~~~~~~~~~~~~~~
CXX mi/mi-interp.o
/home/smarchi/src/binutils-gdb/gdb/mi/mi-interp.c: In function ‘void mi_output_solib_attribs(ui_out*, so_list*)’:
/home/smarchi/src/binutils-gdb/gdb/mi/mi-interp.c:1030:1: error: no previous declaration for ‘void mi_output_solib_attribs(ui_out*, so_list*)’ [-Werror=missing-declarations]
mi_output_solib_attribs (ui_out *uiout, struct so_list *solib)
^~~~~~~~~~~~~~~~~~~~~~~
gdb/ChangeLog:
* dwarf-index-write.c: Include dwarf-index-write.h.
* mi/mi-interp.c: Include mi/mi-interp.h.
Change-Id: I0103b8669e16e0fcaa476f8c5e96f49608157745
Simon Marchi [Tue, 26 Nov 2019 17:12:00 +0000 (12:12 -0500)]
Include aarch32-tdep.h in aarch32-tdep.c
The error below shows that aarch32-tdep.c is missing an include for
aarch32-tdep.h, add it.
CXX aarch32-tdep.o
/home/smarchi/src/binutils-gdb/gdb/aarch32-tdep.c: In function ‘const target_desc* aarch32_read_description()’:
/home/smarchi/src/binutils-gdb/gdb/aarch32-tdep.c:27:1: error: no previous declaration for ‘const target_desc* aarch32_read_description()’ [-Werror=missing-declarations]
aarch32_read_description ()
^~~~~~~~~~~~~~~~~~~~~~~~
Putting the include of aarch32-tdep.h early in aarch32-tdep.c gives us
an error about target_desc not being defined. Indeed, aarch32-tdep.h
uses target_desc without forward-declaring it or including the proper
header. Add a forward-declaration for it.
gdb/ChangeLog:
* aarch32-tdep.c: Include aarch32-tdep.h.
* aarch32-tdep.h: Forward-declare struct target_desc.
Change-Id: Ica4be4de0fbd7f22d56a29a40fbf0a31b5abdb16
Christian Biesinger [Fri, 22 Nov 2019 20:31:35 +0000 (14:31 -0600)]
Use safe_strerror instead of strerror where possible
This provides threadsafety. Unfortunately, since libinproctrace.so
does not link to gnulib, we can't use it there, especially since it
still includes the gnulib headers (so it is difficult to directly
call the system strerror_r).
gdb/ChangeLog:
2019-11-26 Christian Biesinger <cbiesinger@google.com>
* linux-nat.c (detach_one_lwp): Call safe_strerror instead of
strerror.
* nto-procfs.c (nto_procfs_target::create_inferior): Likewise.
* windows-nat.c (windows_nat_target::create_inferior): Likewise.
gdb/gdbserver/ChangeLog:
2019-11-26 Christian Biesinger <cbiesinger@google.com>
* debug.c (debug_set_output): Call safe_strerror instead of
strerror.
* linux-low.c (attach_proc_task_lwp_callback): Likewise.
(linux_kill_one_lwp): Likewise.
(linux_detach_one_lwp): Likewise.
(linux_wait_for_event_filtered): Likewise.
(store_register): Likewise.
* lynx-low.c (lynx_attach): Likewise.
* mem-break.c (insert_memory_breakpoint): Likewise.
(remove_memory_breakpoint): Likewise.
(delete_fast_tracepoint_jump): Likewise.
(set_fast_tracepoint_jump): Likewise.
(uninsert_fast_tracepoint_jumps_at): Likewise.
(reinsert_fast_tracepoint_jumps_at): Likewise.
* nto-low.c (nto_xfer_memory): Likewise.
(nto_resume): Likewise.
Change-Id: I9e259cdcaa6e11bbcc4ee6bdc5b7127d73e11abe
Tom Tromey [Tue, 26 Nov 2019 17:50:01 +0000 (10:50 -0700)]
Fix gdbserver ChangeLog entry
Christian pointed out that I had accidentally put a ChangeLog entry
into gdbserver that was meant for testsuite.
I'm checking in this patch to fix it.
Change-Id: Iba6124cea6f63539ad66494d3355fb657b78a66d