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.
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.
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: 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>
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`.
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.
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.
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.
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.
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.
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.
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.
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.
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 *'.
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.
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.
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.
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.
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.
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:
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:
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.
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.
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.
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.
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.
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>
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.
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.
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".
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>
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.
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.
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.
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.
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.
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.
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.
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>
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 */
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.
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.
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.
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.
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.
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.
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>
This does not touch "int from_tty" and a couple of other instances
that require a bigger change.
gdb/ChangeLog:
2019-11-25 Christian Biesinger <cbiesinger@google.com>
* solib.c (solib_find_1): Change int to bool.
(exec_file_find): Change int to bool.
(solib_find): Change int to bool.
(solib_read_symbols): Change int to bool.
(solib_used): Change int to bool.
(solib_add): Change int to bool.
(info_sharedlibrary_command): Change int to bool.
(solib_contains_address_p): Change int to bool.
(solib_keep_data_in_core): Change int to bool.
(in_solib_dynsym_resolve_code): Change int to bool.
(reload_shared_libraries_1): Change int to bool.
(gdb_sysroot_changed): Change int to bool.
* solib.h (solib_read_symbols): Change int to bool.
(solib_contains_address_p): Change int to bool.
(solib_keep_data_in_core): Change int to bool.
(in_solib_dynsym_resolve_code): Change int to bool.
(libpthread_name_p): Change int to bool.
Andrew Pinski [Thu, 21 Nov 2019 20:53:02 +0000 (12:53 -0800)]
Fix "psb CSYNC" and "bti C".
psb CYSNC was not finding that CSYNC was a correct spelling.
The problem was upper case version was being put in the
wrong hashtable. This fixes the problem by using the
correct hashtable.
Also adds testcases for the upper case versions.
* config/tc-aarch64.c (md_begin): Use correct
hash table for uppercase version of hint.
* testsuite/gas/aarch64/system-2.s: Extend psb case to uppercase.
* testsuite/gas/aarch64/system-2.d: Update.
Luis Machado [Mon, 25 Nov 2019 15:27:44 +0000 (12:27 -0300)]
[Debugging output] Make remote packet truncation length adjustable
While debugging, i felt the need to adjust the truncation length of remote
packets so i could see more or less data as needed. The default is currently
set to 512 bytes.
This patch makes this option adjustable through the new "set debug
remote-packet-max-chars" command. It can be set to unlimited if we want to
completely disable truncation.
Update on v5:
- Adjusted function and variable documentation, NEWS entry and GDB manual.
gdb/ChangeLog:
2019-11-25 Luis Machado <luis.machado@linaro.org>
* NEWS (New Commands): Mention "set debug remote-packet-max-chars".
* remote.c (REMOTE_DEBUG_MAX_CHAR): Remove.
(remote_packet_max_chars): New static global.
(show_remote_packet_max_chars): New function.
(remote_target::putpkt_binary): Adjust to use new
remote_packet_max_chars option.
(remote_target::getpkt_or_notif_sane_1): Likewise.
(_initialize_remote): Register new remote-packet-max-chars option.
gdb/doc/ChangeLog:
2019-11-25 Luis Machado <luis.machado@linaro.org>
* gdb.texinfo (Debugging Output): Document set debug
remote-packet-max-chars.
Alan Modra [Sun, 24 Nov 2019 23:37:40 +0000 (10:07 +1030)]
Pass section when available to bfd_octets_per_byte
and other tidies. I think it's better to default to passing the
section to bfd_octets_per_byte, even in cases where we know it won't
make a difference.
A number of the coff reloc functions used bfd_octets_per_byte wrongly,
not factoring it into the offset into the data buffer. As it happens,
the targets using those files always had bfd_octets_per_byte equal to
one, so there wasn't any detectable wrong behaviour. However, it is
wrong in the source and might cause trouble for anyone creating a new
target. Besides fixing that, the patch also defines OCTETS_PER_BYTE
as one in target files where that is appropriate.
Christian Eggers [Thu, 21 Nov 2019 21:17:29 +0000 (22:17 +0100)]
Introduce new section flag: SEC_ELF_OCTETS
All symbols, sizes and relocations in this section are octets instead of
bytes. Required for DWARF debug sections as DWARF information is
organized in octets, not bytes.
bfd/
* section.c (struct bfd_section): New flag SEC_ELF_OCTETS.
* archures.c (bfd_octets_per_byte): New parameter sec.
If section is not NULL and SEC_ELF_OCTETS is set, one octet es
returned [ELF targets only].
* bfd.c (bfd_get_section_limit): Provide section parameter to
bfd_octets_per_byte.
* bfd-in2.h: regenerate.
* binary.c (binary_set_section_contents): Move call to
bfd_octets_per_byte into section loop. Provide section parameter
to bfd_octets_per_byte.
* coff-arm.c (coff_arm_reloc): Provide section parameter
to bfd_octets_per_byte.
* coff-i386.c (coff_i386_reloc): likewise.
* coff-mips.c (mips_reflo_reloc): likewise.
* coff-x86_64.c (coff_amd64_reloc): likewise.
* cofflink.c (_bfd_coff_link_input_bfd): likewise.
(_bfd_coff_reloc_link_order): likewise.
* elf.c (_bfd_elf_section_offset): likewise.
(_bfd_elf_make_section_from_shdr): likewise.
Set SEC_ELF_OCTETS for sections with names .gnu.build.attributes,
.debug*, .zdebug* and .note.gnu*.
* elf32-msp430.c (rl78_sym_diff_handler): Provide section parameter
to bfd_octets_per_byte.
* elf32-nds.c (nds32_elf_get_relocated_section_contents): likewise.
* elf32-ppc.c (ppc_elf_addr16_ha_reloc): likewise.
* elf32-pru.c (pru_elf32_do_ldi32_relocate): likewise.
* elf32-s12z.c (opru18_reloc): likewise.
* elf32-sh.c (sh_elf_reloc): likewise.
* elf32-spu.c (spu_elf_rel9): likewise.
* elf32-xtensa.c (bfd_elf_xtensa_reloc): likewise
* elf64-ppc.c (ppc64_elf_brtaken_reloc): likewise.
(ppc64_elf_addr16_ha_reloc): likewise.
(ppc64_elf_toc64_reloc): likewise.
* elflink.c (bfd_elf_final_link): likewise.
(bfd_elf_perform_complex_relocation): likewise.
(elf_fixup_link_order): likewise.
(elf_link_input_bfd): likewise.
(elf_link_sort_relocs): likewise.
(elf_reloc_link_order): likewise.
(resolve_section): likewise.
* linker.c (_bfd_generic_reloc_link_order): likewise.
(bfd_generic_define_common_symbol): likewise.
(default_data_link_order): likewise.
(default_indirect_link_order): likewise.
* srec.c (srec_set_section_contents): likewise.
(srec_write_section): likewise.
* syms.c (_bfd_stab_section_find_nearest_line): likewise.
* reloc.c (_bfd_final_link_relocate): likewise.
(bfd_generic_get_relocated_section_contents): likewise.
(bfd_install_relocation): likewise.
For section which have SEC_ELF_OCTETS set, multiply output_base
and output_offset with bfd_octets_per_byte.
(bfd_perform_relocation): likewise.
include/
* coff/ti.h (GET_SCNHDR_SIZE, PUT_SCNHDR_SIZE, GET_SCN_SCNLEN),
(PUT_SCN_SCNLEN): Adjust bfd_octets_per_byte calls.
binutils/
* objdump.c (disassemble_data): Provide section parameter to
bfd_octets_per_byte.
(dump_section): likewise
(dump_section_header): likewise. Show SEC_ELF_OCTETS flag if set.
gas/
* as.h: Define SEC_OCTETS as SEC_ELF_OCTETS if OBJ_ELF.
* dwarf2dbg.c: (dwarf2_finish): Set section flag SEC_OCTETS for
.debug_line, .debug_info, .debug_abbrev, .debug_aranges, .debug_str
and .debug_ranges sections.
* write.c (maybe_generate_build_notes): Set section flag
SEC_OCTETS for .gnu.build.attributes section.
* frags.c (frag_now_fix): Don't divide by OCTETS_PER_BYTE if
SEC_OCTETS is set.
* symbols.c (resolve_symbol_value): Likewise.
ld/
* ldexp.c (fold_name): Provide section parameter to
bfd_octets_per_byte.
* ldlang (init_opb): New argument s. Set opb_shift to 0 if
SEC_ELF_OCTETS for the current section is set.
(print_input_section): Pass current section to init_opb.
(print_data_statement,print_reloc_statement,
print_padding_statement): Likewise.
(lang_check_section_addresses): Call init_opb for each
section.
(lang_size_sections_1,lang_size_sections_1,
lang_do_assignments_1): Likewise.
(lang_process): Pass NULL to init_opb.
Simon Marchi [Sun, 24 Nov 2019 20:04:21 +0000 (15:04 -0500)]
Include gdbarch.h in m68k-linux-nat.c
Fix this compilation error, and a bunch of similar ones:
CXX m68k-linux-nat.o
/home/smarchi/src/binutils-gdb/gdb/m68k-linux-nat.c: In function ‘void fetch_register(regcache*, int)’:
/home/smarchi/src/binutils-gdb/gdb/m68k-linux-nat.c:133:9: error: ‘gdbarch_register_name’ was not declared in this scope
gdbarch_register_name (gdbarch, regno),
^~~~~~~~~~~~~~~~~~~~~
Tom Tromey [Thu, 21 Nov 2019 00:04:22 +0000 (17:04 -0700)]
Restore parameter names in observable.h
Ages ago, when we switched observables to be templates, Joel asked me
to restore the parameter names that were used in the old
observer.texi.
I've finally done this, putting the names into comments. I also
updated the comments in this file to use the GNU metasyntactic
variable convention as well.
gdb/ChangeLog
2019-11-22 Tom Tromey <tom@tromey.com>
Tom Tromey [Thu, 21 Nov 2019 16:05:10 +0000 (09:05 -0700)]
Avoid crash in print_ada_task_info
In MI mode, print_ada_task_info can crash in find_thread_ptid when
trying to print an Ada task that is no longer alive. This patch
avoids the problem by checking for this case.
Because this is Ada-specific, and because Joel approved it internally,
I am checking it in.
gdb/ChangeLog
2019-11-22 Tom Tromey <tromey@adacore.com>
* ada-tasks.c (ada_task_is_alive): Make parameter const.
(print_ada_task_info): Don't try to fetch thread id if task is not
alive.
gdb/gdbserver/ChangeLog
2019-11-22 Tom Tromey <tromey@adacore.com>
Create a correctly-sized demangled names hashtable
If we have a minsym count, we know the demangled names hashtable will
be at least that big. So use that count to size it, so we don't
have to resize/rehash it as much.
This is a 6% improvement in minsym loading time.
2019-11-22 Christian Biesinger <cbiesinger@google.com>
* symtab.c (create_demangled_names_hash): Use per_bfd->
minimal_symbol_count for computing the initial size, if greater
than our default size.
Tom de Vries [Fri, 22 Nov 2019 15:23:22 +0000 (16:23 +0100)]
[gdb/contrib] Combine sed invocations in words.sh script
Currently running words.sh on all the c source and header files in the repo
takes ~16s in user time:
...
$ time ./gdb/contrib/words.sh \
$(find -type f -name "*.c" -o -name "*.h") \
>/dev/null
real 0m7,787s
user 0m16,349s
sys 0m0,367s
...
Rewrite the sed invocations using the -e option from this:
...
| sed <sedprog1>
| sed <sedprog2>
...
into this:
...
| sed \
-e <sedprog1>
-e <sedprog2>
...
and reduce user time to ~11s:
...
$ time ./gdb/contrib/words.sh \
$(find -type f -name "*.c" -o -name "*.h") \
>/dev/null
Mihail Ionescu [Fri, 22 Nov 2019 13:44:17 +0000 (13:44 +0000)]
Arm: Change CRC from fpu feature to archititectural extension
This patch changes the CRC extension to use the core feature bits instead
of the coproc/fpu feature bits.
CRC is not an fpu feature and it causes issues with the new fpu reset
patch (f439988037a589de3798f44e7268301adaec21a9). CRC can be set using
the '.arch_extension' directive, which sets bits in the coproc bitfield. When
a '.fpu' directive is encountered, the CRC feature bit gets removed and
there is no way to set it back using '.fpu'.
With this patch, CRC will be marked in the feature core bits, which prevents
it from getting removed when setting/changing the fpu options.
gas/ChangeLog:
* config/tc-arm.c (arm_ext_crc): New.
(crc_ext_armv8): Remove.
(insns): Rename crc_ext_armv8 to arm_ext_crc.
(arm_cpus): Replace CRC_EXT_ARMV8 with ARM_EXT2_CRC.
(armv8a_ext_table, armv8r_ext_table,
arm_option_extension_value_table): Redefine the crc
extension in terms of ARM_EXT2_CRC.
* gas/testsuite/gas/arm/crc-ext.s: New.
* gas/testsuite/gas/arm/crc-ext.d: New.
include/ChangeLog:
* opcode/arm.h (ARM_EXT2_CRC): New extension feature
to replace CRC_EXT_ARMV8.
(CRC_EXT_ARMV8): Remove and mark bit as unused.
(ARM_ARCH_V8A_CRC, ARM_ARCH_V8_1A, ARM_ARCH_V8_2A,
ARM_ARCH_V8_3A, ARM_ARCH_V8_4A, ARM_ARCH_V8_5A,
ARM_ARCH_V8_6A): Redefine using ARM_EXT2_CRC instead of
CRC_EXT_ARMV8.
opcodes/ChangeLog:
* opcodes/arm-dis.c (arm_opcodes, thumb32_opcodes):
Change the coproc CRC conditions to use the extension
feature set, second word, base on ARM_EXT2_CRC.
Rename demangle.c to gdb-demangle.c, and some cleanup
In addition to renaming demangle.c to match the header file naming,
this also makes is_cplus_marker return a bool and removes a duplicate
declaration of "bool demangle" from symtab.h.
gdb/ChangeLog:
2019-11-21 Christian Biesinger <cbiesinger@google.com>
* Makefile.in: Update.
* demangle.c: Rename to...
* gdb-demangle.c: ..this.
(is_cplus_marker): Change return type to bool.
(_initialize_demangler): Rename to...
(_initialize_gdb_demangle): ...this.
* gdb-demangle.h (is_cplus_marker): Change return type to bool.
* symtab.h (demangle): Remove declaration; instead include
gdb-demangle.h.
Tom Tromey [Thu, 14 Nov 2019 22:00:19 +0000 (15:00 -0700)]
Handle %I64d in format_pieces
We found a bug internally where gdb would crash while disassembling a
certain instruction. This was tracked down to the handling of %I64d
in format_pieces.
format_pieces will convert %ll to %I64d on mingw -- so format_pieces
should also handle parsing this format. In this patch, I've made the
parsing unconditional, since I think it is harmless to accept extra
formats. I've also taken the opportunity to convert the length
modifier test to a "switch".
Tested internally using our failing test case.
gdb/ChangeLog
2019-11-21 Tom Tromey <tromey@adacore.com>
* gdbsupport/format.c (format_pieces): Parse %I64d.
* unittests/format_pieces-selftests.c (test_windows_formats): New
function.
(run_tests): Call it.