Tom Tromey [Mon, 2 Jul 2018 15:20:40 +0000 (09:20 -0600)]
Remove exit_inferior_num_silent
The sole caller of exit_inferior_num_silent was getting the inferior's
number to then use the number to look up the inferior again. I think
it's better to simply not have exit_inferior_num_silent; any potential
callers that only have the inferior's number should probably be
converted to pass the inferior itself around instead.
Tested by the buildbot.
gdb/ChangeLog
2018-07-03 Tom Tromey <tom@tromey.com>
I think the problem here is that darwin_attach_pid does not clean up
inferior_ptid and inf->pid on failure. This leads to a situation
where gdb tries to find a thread, but cannot.
In other cases, gdb would mourn the inferior at this point; but here
this is not possible because the target has not been pushed. Instead
this patch works by simply updating the inferior and inferior_ptid on
failure.
Tested by building an unsigned gdb on macOS and trying to run an
inferior.
gdb/ChangeLog
2018-07-03 Tom Tromey <tom@tromey.com>
PR cli/23340:
* darwin-nat.c (darwin_attach_pid): Reset inferior and
inferior_ptid on error.
Alan Modra [Tue, 3 Jul 2018 08:27:36 +0000 (17:57 +0930)]
Correct removal of .gnu.attributes
Setting SEC_EXCLUDE for empty .gnu.attributes is too late in the link
process for the linker to remove the section. That must be done in
bfd_elf_final_link, as we do for removed group sections.
* elflink.c (bfd_elf_final_link): Remove zero size .gnu.attributes
sections.
Alan Modra [Tue, 3 Jul 2018 05:20:38 +0000 (14:50 +0930)]
GNU attribute output on errors
.gnu.attributes entries from linker input files are merged to the
output file, the output having the union of compatible input
attributes. Incompatible attributes generally cause a linker error
and no output. However in some cases only a warning is emitted, and
one of the incompatible input attributes is passed on to the output.
PowerPC tends to emit warnings rather than errors, and the output
takes the first input attribute. For example, if we have two input
files with Tag_GNU_Power_ABI_FP, the first with a value signifying
"double-precision hard float, IBM long double", the second with a
value signifying "double-precision hard float, IEEE long double",
we'll get a warning about incompatible long double types and the
output will say "double-precision hard float, IBM long double".
The output attribute of course isn't correct. It would be correct to
specify "IBM and IEEE long double", but we don't have a way to
represent that currently. While it would be possible to extend the
encoding, there isn't much gain in doing so. A shared library
providing support for both long double types should link against
objects using either long double type without warning or error. That
is what you'd get if such a shared library had no Tag_GNU_Power_ABI_FP
attribute.
So this patch provides a way for the backend to omit .gnu.attributes
tags from the output.
Alan Modra [Tue, 3 Jul 2018 02:48:10 +0000 (12:18 +0930)]
Hide dynamic symbols in discarded sections
This is a followup to git commit 97196564c7 "Strip global symbol
defined in discarded section". If a symbol defined in a discarded
section was dynamic, that patch left .dynsym with holes (ie. all zero
entries). For example, the following from libstdc++.so:
Symbol table '.dynsym' contains 6090 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000000a74e0 0 SECTION LOCAL DEFAULT 10
2: 0000000000264180 0 SECTION LOCAL DEFAULT 17
3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_addUserCommitAction
4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_memcpyRtWn
5: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
readelf: Warning: local symbol 5 found at index >= .dynsym's sh_info value of 3
6: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
readelf: Warning: local symbol 6 found at index >= .dynsym's sh_info value of 3
[snip]
observed with `mips-elf', `tx39-elf', `mipsisa32-elf', `mipsisa64-elf',
`mipsel-elf', `mipsisa32el-elf', `mipsisa64el-elf', `mips64vr-elf',
`mips64vrel-elf', `mips64vr4300-elf', `mips64vr4300el-elf',
`mips-sgi-irix5' and `mips-rtems' targets, among others. This fix makes
section GC usable with the affected targets.
bfd/
* elfxx-mips.c (_bfd_mips_elf_create_dynamic_sections): Set
`mark' for symbols created from `mips_elf_dynsym_rtproc_names'
list.
microMIPS/GAS: Handle several percent-ops with macros
In the microMIPS mode also accept %half, %got, %call, %got_hi, %got_lo,
%call_hi, %call_lo, %neg, %got_page, %highest, %got_disp, %tlsgd,
%tlsldm, %dtprel_hi, %dtprel_lo, %gottprel, %tprel_hi and %tprel_lo
percent-ops with macros, so that they can be used with instructions that
expand into sequences if relocation is required due to their limited
offset span, such as LL, LWL, etc., fixing GAS assertions:
.../gas/testsuite/gas/mips/elf-rel28.s: Assembler messages:
.../gas/testsuite/gas/mips/elf-rel28.s:17: Internal error in macro_build at .../gas/config/tc-mips.c:8854.
Please report this bug.
observed if an attempt is made to assemble the `elf-rel28.s' test case
modified to use one of the affected instructions to microMIPS code.
gas/
* config/tc-mips.c (macro_build) <'i', 'j'>: Also accept
BFD_RELOC_16, BFD_RELOC_MIPS_GOT16, BFD_RELOC_MIPS_CALL16,
BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MIPS_GOT_LO16,
BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MIPS_CALL_LO16,
BFD_RELOC_MIPS_SUB, BFD_RELOC_MIPS_GOT_PAGE,
BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MIPS_GOT_DISP,
BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MIPS_TLS_LDM,
BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MIPS_TLS_DTPREL_LO16,
BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MIPS_TLS_TPREL_HI16 and
BFD_RELOC_MIPS_TLS_TPREL_LO16 relocations if in the microMIPS
mode.
* testsuite/gas/mips/elf-rel28-lldscd-n32.d: New test.
* testsuite/gas/mips/elf-rel28-lldscd-micromips-n32.d: New test.
* testsuite/gas/mips/elf-rel28-lldscd-n64.d: New test.
* testsuite/gas/mips/elf-rel28-lldscd-micromips-n64.d: New test.
* testsuite/gas/mips/elf-rel28.s: Add instruction selection.
* testsuite/gas/mips/mips.exp: Run the new tests.
microMIPS/BFD: Add missing NewABI TLS and miscellaneous relocations
Complement commit df58fc944dbc ("MIPS: microMIPS ASE support"),
<https://sourceware.org/ml/binutils/2011-07/msg00198.html>, and add TLS
and a few miscellaneous relocations to NewABI microMIPS support, fixing
GAS assertion failures:
.../gas/testsuite/gas/mips/elf-rel28.s: Assembler messages:
.../gas/testsuite/gas/mips/elf-rel28.s:19: Internal error in append_insn at .../gas/config/tc-mips.c:7660.
Please report this bug.
observed if an attempt is made to assemble the `elf-rel28.s' test case
to microMIPS code. The relocations are the same as with o32 support,
except for `partial_inplace' and `src_mask' updates for the respective
RELA variants.
gas/
* testsuite/gas/mips/elf-rel28-micromips-n32.d: New test.
* testsuite/gas/mips/elf-rel28-micromips-n64.d: New test.
* testsuite/gas/mips/mips.exp: Run the new tests.
GDB PR tdep/8282: MIPS: Wire in `set disassembler-options'
Implement MIPS target support for passing options to the disassembler,
complementing commit 65b48a81404c ("GDB: Add support for the new
set/show disassembler-options commands.").
This includes options that expect an argument, so adjust the generic
code and data structures used so as to handle such options. So as to
give backends syntax flexibility no specific delimiter has been defined
to separate options from their respective arguments, so it has to be
included as the last character of the option name. Completion code
however has not been adjusted and consequently option arguments cannot
be completed at this time.
Also the MIPS target has non-empty defaults for the options, so that ABI
names for the general-purpose registers respect our `set mips abi ...'
setting rather than always being determined from the ELF headers of the
binary file selected. Handle these defaults as implicit options, never
shown to the user and always prepended to the user-specified options, so
that the latters can override the defaults.
The resulting output for the MIPS target is as follows:
(gdb) show disassembler-options
The current disassembler options are ''
The following disassembler options are supported for use with the
'set disassembler-options <option>[,<option>...]' command:
no-aliases Use canonical instruction forms.
msa Recognize MSA instructions.
virt Recognize the virtualization ASE instructions.
xpa Recognize the eXtended Physical Address (XPA) ASE
instructions.
ginv Recognize the Global INValidate (GINV) ASE instructions.
gpr-names=ABI Print GPR names according to specified ABI.
Default: based on binary being disassembled.
fpr-names=ABI Print FPR names according to specified ABI.
Default: numeric.
cp0-names=ARCH Print CP0 register names according to specified architecture.
Default: based on binary being disassembled.
hwr-names=ARCH Print HWR names according to specified architecture.
Default: based on binary being disassembled.
reg-names=ABI Print GPR and FPR names according to specified ABI.
reg-names=ARCH Print CP0 register and HWR names according to specified
architecture.
For the options above, the following values are supported for "ABI":
numeric 32 n32 64
For the options above, the following values are supported for "ARCH":
numeric r3000 r3900 r4000 r4010 vr4100 vr4111 vr4120 r4300 r4400 r4600
r4650 r5000 vr5400 vr5500 r5900 r6000 rm7000 rm9000 r8000 r10000 r12000
r14000 r16000 mips5 mips32 mips32r2 mips32r3 mips32r5 mips32r6 mips64
mips64r2 mips64r3 mips64r5 mips64r6 interaptiv-mr2 sb1 loongson2e
loongson2f loongson3a octeon octeon+ octeon2 octeon3 xlr xlp
(gdb)
which corresponds to what `objdump --help' used to print for the MIPS
target, with minor formatting changes, most notably option argument
lists being wrapped, but also the amount of white space separating
options from the respective descriptions. The relevant part the new
code is now also used by `objdump --help', which means these formatting
changes apply to both outputs, except for argument list wrapping, which
is GDB-specific.
This also adds a separating new line between the heading and option
lists where descriptions are provided, hence:
(gdb) set architecture s390:31-bit
(gdb) show disassembler-options
The current disassembler options are ''
The following disassembler options are supported for use with the
'set disassembler-options <option>[,<option>...]' command:
esa Disassemble in ESA architecture mode
zarch Disassemble in z/Architecture mode
insnlength Print unknown instructions according to length from first two bits
(gdb)
but:
(gdb) set architecture powerpc:common
(gdb) show disassembler-options
The current disassembler options are ''
Existing affected target backends have been adjusted accordingly.
This has been verified manually with:
(gdb) set architecture arm
(gdb) set architecture powerpc:common
(gdb) set architecture s390:31-bit
to cause no issues with the `show disassembler-options' and `set
disassembler-options' commands. A test case for the MIPS target has
also been provided, covering the default settings with ABI overrides as
well as disassembler option overrides.
2018-07-02 Maciej W. Rozycki <macro@mips.com>
Simon Marchi <simon.marchi@polymtl.ca>
opcodes/
PR tdep/8282
* mips-dis.c (mips_option_arg_t): New enumeration.
(mips_options): New variable.
(disassembler_options_mips): New function.
(print_mips_disassembler_options): Reimplement in terms of
`disassembler_options_mips'.
* arm-dis.c (disassembler_options_arm): Adapt to using the
`disasm_options_and_args_t' structure.
* ppc-dis.c (disassembler_options_powerpc): Likewise.
* s390-dis.c (disassembler_options_s390): Likewise.
gdb/
PR tdep/8282
* disasm.h (gdb_disassembler): Add
`m_disassembler_options_holder'. member
* disasm.c (get_all_disassembler_options): New function.
(gdb_disassembler::gdb_disassembler): Use it.
(gdb_buffered_insn_length_init_dis): Likewise.
(gdb_buffered_insn_length): Adjust accordingly.
(set_disassembler_options): Handle options with arguments.
(show_disassembler_options_sfunc): Likewise. Add a leading new
line if showing options with descriptions.
(disassembler_options_completer): Adapt to using the
`disasm_options_and_args_t' structure.
* mips-tdep.c (mips_disassembler_options): New variable.
(mips_disassembler_options_o32): Likewise.
(mips_disassembler_options_n32): Likewise.
(mips_disassembler_options_n64): Likewise.
(gdb_print_insn_mips): Don't set `disassembler_options'.
(gdb_print_insn_mips_n32, gdb_print_insn_mips_n64): Remove
functions.
(mips_gdbarch_init): Always set `gdbarch_print_insn' to
`gdb_print_insn_mips'. Set `gdbarch_disassembler_options',
`gdbarch_disassembler_options_implicit' and
`gdbarch_valid_disassembler_options'.
* arm-tdep.c (_initialize_arm_tdep): Adapt to using the
`disasm_options_and_args_t' structure.
* gdbarch.sh (disassembler_options_implicit): New `gdbarch'
method.
(valid_disassembler_options): Switch from `disasm_options_t' to
the `disasm_options_and_args_t' structure.
* NEWS: Document `set disassembler-options' support for the MIPS
target.
* gdbarch.h: Regenerate.
* gdbarch.c: Regenerate.
gdb/doc/
PR tdep/8282
* gdb.texinfo (Source and Machine Code): Document `set
disassembler-options' support for the MIPS target.
gdb/testsuite/
PR tdep/8282
* gdb.arch/mips-disassembler-options.exp: New test.
* gdb.arch/mips-disassembler-options.s: New test source.
int
main (int argc, char **argv)
{
bfd *file = bfd_openr (argv[1], NULL);
if (file == NULL)
die ("couldn't open");
if (!bfd_check_format (file, bfd_archive))
die ("not an archive");
printf ("yay\n");
bfd_close (file);
return 0;
}
Then I built a simple universal binary. With git master BFD, I get:
$ ./doit ./universal-exe
die: not an archive
Jeff Muizelaar tracked this down to the BFD change for PR binutils/21787.
This patch changed bfd_generic_archive_p to sometimes reset the BFD's
"format" field.
However, simply changing bfd_generic_archive_p regressed the test case
in that bug.
Debugging PR binutils/21787 again, what I saw is that the mach-o
universal binary support acts like a bfd_archive but does not provide
a _close_and_cleanup function. However, if a BFD appears as an
archive member, it must always remove its own entry from its parent's
map. Otherwise, when the parent is destroyed, the already-destroyed
child BFD will be referenced. mach-o does not use the usual archive
member support, so simply using _bfd_archive_close_and_cleanup (as
other targets do) will not work.
This patch fixes the problem by introducing a new
_bfd_unlink_from_archive_parent function, then arranging for it to be
called in the mach-o case.
Ok?
bfd/ChangeLog
2018-07-02 Jeff Muizelaar <jrmuizel@gmail.com>
Tom Tromey <tom@tromey.com>
PR 13157
PR 21787
* mach-o.c (bfd_mach_o_fat_close_and_cleanup): New function.
(bfd_mach_o_close_and_cleanup): Redefine.
* archive.c (_bfd_unlink_from_archive_parent): New function,
extracted from..
(_bfd_archive_close_and_cleanup): ..here.
(bfd_generic_archive_p): Do not clear archive's format.
* libbfd-in.h (_bfd_unlink_from_archive_parent): Declare.
* libbfd.h: Regenerate.
Sebastian Huber [Fri, 29 Jun 2018 08:50:11 +0000 (10:50 +0200)]
gdb: Prefer RISC-V register name "s0" over "fp"
The "fp" register name is an alias for "s0" which is an alias for "x8".
The "fp" name is only understood by very recent Binutils and thus not
used by GCC. GCC does not emit a frame pointer with common optimization
options such as -Og or -O2.
It is still possible to use the "fp" register name, e.g.
BFD's bfd_get_mach () function returns a bfd specific value representing
the architecture of the target which is populated from the Tag_CPU_arch
build attribute value of that target. Among other users of that
interfacem, objdump which uses it to print the architecture version of
the binary being examinated and to decide what instruction is available
if run with "-m arm" via its own mapping from bfd_mach_arm_X values to
feature bits available.
However, both BFD and objdump's most recent known architecture is
Armv5TE. When encountering a newer architecture bfd_get_mach will return
bfd_mach_arm_unknown. This is unfortunate since objdump uses that value
to allow all instructions on all architectures which is already what it
does by default, making the "-m arm" trick useless.
This patch updates BFD and objdump's knowledge of Arm architecture
versions up to the latest Armv8-M Baseline and Mainline, Armv8-R and
Armv8.4-A architectures. Since several architecture versions (eg. 8.X-A)
share the same Tag_CPU_arch build attribute value and
bfd_mach_arm values, the mapping from bfd machine value to feature bits
need to return the most featureful feature bits that would yield the
given bfd machine value otherwise some instruction would not disassemble
under "-m arm" mode. The patch rework that mapping to make this clearer
and simplify writing the mapping rules. In particular, for simplicity
all FPU instructions are allowed in all cases.
Finally, the patch also rewrite the cpu_arch_ver table in GAS to use the
TAG_CPU_ARCH_X macros rather than hardcode their value.
2018-07-02 Thomas Preud'homme <thomas.preudhomme@arm.com>
bfd/
* archures.c (bfd_mach_arm_5TEJ, bfd_mach_arm_6, bfd_mach_arm_6KZ,
bfd_mach_arm_6T2, bfd_mach_arm_6K, bfd_mach_arm_7, bfd_mach_arm_6M,
bfd_mach_arm_6SM, bfd_mach_arm_7EM, bfd_mach_arm_8, bfd_mach_arm_8R,
bfd_mach_arm_8M_BASE, bfd_mach_arm_8M_MAIN): Define.
* bfd-in2.h: Regenerate.
* cpu-arm.c (arch_info_struct): Add entries for above new
bfd_mach_arm values.
* elf32-arm.c (bfd_arm_get_mach_from_attributes): Add Tag_CPU_arch to
bfd_mach_arm mapping logic for pre Armv4 and Armv5TEJ and later
architectures. Force assert failure for any new Tag_CPU_arch value.
gas/
* config/tc-arm.c (cpu_arch_ver): Use symbolic TAG_CPU_ARCH macros
rather than hardcode their values.
ld/
* arm-dis.c (select_arm_features): Fix typo in heading comment. Allow
all FPU features and add mapping from new bfd_mach_arm values to
allowed CPU feature bits.
opcodes/
* testsuite/ld-arm/tls-descrelax-be8.d: Add architecture version in
expected result.
* testsuite/ld-arm/tls-descrelax-v7.d: Likewise.
* testsuite/ld-arm/tls-longplt-lib.d: Likewise.
* testsuite/ld-arm/tls-longplt.d: Likewise.
Binutils documentation uses a mix of spelling for the compound word
"command-line X". According to [1]:
"Sometimes compound words are written separately (nail polish),
sometimes with a hyphen (short-sighted) and sometimes as one word
(eyelashes). Often new compounds are written as two separate words and,
as they become more familiar, they are either connected with a hyphen
(-) or made into one word."
I think command-line X is common enough in our industry that the two
workds command and line should be connected. Since command-line is more
common than commandline, I propose to update binutils documentation to
consistently use "command-line" when this is used as an adjective to a
noun (eg. command-line argument, command-line switch, command-line
option and command-line flag). I've left occurences of "the command
line" as is. I've also left gdb, sim and readline alone and have only
touched public documentation (texi and NEWS files).
Alexandre Oliva [Sat, 30 Jun 2018 02:49:28 +0000 (23:49 -0300)]
Introduce @unless/@endunless and postbootstrap Makefile targets
This patch turns dependencies of non-bootstrap targets on bootstrap
targets for bootstrap builds into dependencies on stage_last. This
arrangement gets stage1-bubble to run from stage_last if we haven't
started a bootstrap yet, and to use the current stage otherwise. This
was already the case of target libs, just not of non-bootstrapped host
modules.
In order to retain preexisting dependencies in non-bootstrap builds,
or in gcc-less builds, this introduces support for @unless/@endunless
pairs in Makefile.in.
There is a remaining possibility of problem if activating, in a tree
configured for bootstrap, a parallel build of two or more modules, at
least one bootstrapped and one not. In this case, make might decide
to build stage_current and stage_last in parallel, the latter will
start a submake to build stage1 while the initial make, having
satisfied stage_current, proceeds to build the bootstrapped module in
non-bootstrapped configurations. The two builds will overlap and will
likely conflict. This situation does NOT arise in normal settings,
however: a post-bootstrap build of all-host all-target will indeed
activate such targets concurrently, but only after building all
bootstrapped modules successfully, and it will have both stage_last
and stage_current targets already satisfied, so the potential race
between builds will not arise.
Another remaining problem, that is slightly expanded with this patch,
is that of an interrupted build in a tree configured for bootstrap,
continued with a non-bootstrapped target. Target modules that were
not bootstrapped would already fail to complete the current stage when
activated explicitly in the command line for a retry; host modules,
however, would attempt to build their bootstrapped dependencies, which
is what led to the problem of concurrent builds addressed with this
patch. An interrupted or failed build might still recover correctly,
if the non-bootstrapped target is activated in both builds, because
then make will remove stage_last when its build command is
interrupted, so that it will attempt to recreate it with stage1-bubble
in the second try. A bootstrap build, however, will not be attempting
to build stage_last, so the file will remain and the retry won't go
through stage1-bubble. We have lived with that for target modules, so
we can probably live with that for host modules too.
Another undesirable consequence of this change is that non-boostrapped
host modules, in a tree configured for bootstrap, when activated as
make all-<module>, will build all of stage1 instead of only the
module's usual dependencies. This is intentional and necessary to fix
the parallel-build problem. If it's not desirable, disabling the
unnecessary bootstrap configuration will suffice to restore the
original set of dependencies.
for ChangeLog
* configure.ac: Introduce support for @unless/@endunless.
* Makefile.tpl (dep-kind): Rewrite with cond; return
postbootstrap in some cases.
(make-postboot-dep, postboot-targets): New.
(dependencies): Do not output postbootstrap dependencies at
first. Output non-target ones changed for configure to depend
on stage_last @if gcc-bootstrap, and the original deps @unless
gcc-bootstrap.
* configure.in, Makefile.in: Rebuilt.
Add missing parameter to 'amd64_create_target_description' (and unbreak build)
While building gdbserver on GNU/Linux, the build failed with:
../../../binutils-gdb/gdb/gdbserver/linux-x86-tdesc.c: In function ‘const target_desc* amd64_linux_read_description(uint64_t, bool)’:
../../../binutils-gdb/gdb/gdbserver/linux-x86-tdesc.c:121:67: error: too few arguments to function ‘target_desc* amd64_create_target_description(uint64_t, bool, bool, bool)’
*tdesc = amd64_create_target_description (xcr0, is_x32, true);
^
In file included from ../../../binutils-gdb/gdb/gdbserver/linux-x86-tdesc.c:26:0:
../../../binutils-gdb/gdb/gdbserver/../arch/amd64.h:21:14: note: declared here
target_desc *amd64_create_target_description (uint64_t xcr0, bool is_x32,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
According to Joel Brobecker:
> I think the parameter should be set to "true". Otherwise, it will
> not include the fs_base and gs_base register in the list of registers.
> Although the name of the source file says x86, the code itself is
> protected by...
>
> #ifdef __x86_64__
>
> ... and is inside a function called amd64_linux_read_description.
> I also verified that this file gets compiled on amd64-linux platforms.
> See gdb/gdbserver/configure.srv:
>
> x86_64-*-linux*) srv_regobj="$srv_amd64_linux_regobj $srv_i386_linux_regobj"
>
> The last piece of confirmation is that setting the parameter to "true"
> provides the behavior before the parameter was added; and the reason
> for adding the parameter was to remove the {fs,gs}_base registers
> from the list for Windows only.
Therefore I'm pushing the patch to unbreak the build.
gdb/gdbserver/ChangeLog:
2018-06-29 Joel Brobecker <brobecker@adacore.com>
* linux-x86-tdesc.c (amd64_linux_read_description): Add missing
parameter in call to 'amd64_create_target_description'.
This is because we added one additional "segments" argument to
function amd64_target_description and forgot to update all the callers.
This patch fixes the omissions.
The change to amd64-fbsd-nat.c was done "blind" (no access to system),
but is reasonably straightforward. The changes to the -tdep.c files
were verify by rebuilding GDB on x86_64-linux when configured with
--enable-targets=all.
Pedro Alves [Tue, 26 Jun 2018 15:33:27 +0000 (16:33 +0100)]
x86_64-windows GDB crash due to fs_base/gs_base registers
GDB is currently crashing anytime we try to access the fs_base/gs_base
registers, either to read them, or to write them. This can be observed
under various scenarios:
- Explicit reference to those registers (eg: print $fs_base) --
probably relatively rare;
- Calling a function in the inferior, with the crash happening
because we are trying to read those registers in order to save
their value ahead of making the function call;
- Just a plain "info registers";
The crash was introduced by the following commit:
| commit 48aeef91c248291dd03583798904612426b1f40a
| Date: Mon Jun 26 18:14:43 2017 -0700
| Subject: Include the fs_base and gs_base registers in amd64 target descriptions.
The Windows-nat implementation was unfortunately not prepared to deal
with those new registers. In particular, the way it fetches registers
is done by using a table where the index is the register number, and
the value at that index is the offset in the area in the thread's CONTEXT
data where the corresponding register value is stored.
For instance, in amd64-windows-nat.c, we can find the mappings static
array containing the following 57 elements in it:
The problem is that fs_base's register number is 172, which is
well past the end of the mappings array (57 elements in total).
We end up getting an undefined offset, which happens to be so large
that it then causes the address where we try to read the register
value (a little bit later) to be invalid, thus crashing GDB with
a SEGV.
This patch side-steps the issue entirely by removing support for
those registers in GDB on x86_64-windows, because a look at the
CONTEXT structure indicates no support for getting those registers.
A more comprehensive fix would patch the potential buffer overflow
of the mappings array, but this can be done as a separate commit.
gdb/ChangeLog:
* gdb/amd64-tdep.h (amd64_create_target_description): Add
"segments" parameter.
* gdb/amd64-tdep.c (amd64_none_init_abi, amd64_x32_none_init_abi)
(_initialize_amd64_tdep): Update call to
amd64_create_target_description.
(amd64_target_description): Add "segments" parameter. Adjust
the implementation to use it.
* gdb/amd64-linux-tdep.c (amd64_linux_read_description): Update
call to amd64_create_target_description.
* gdb/amd64-windows-tdep.c (amd64_windows_init_abi): Likewise.
* gdb/arch/amd64.h (amd64_create_target_description): Add
"segments" register.
* gdb/arch/amd64.c (amd64_create_target_description): Add
"segments" parameter. Call create_feature_i386_64bit_segments
only if SEGMENTS is true.
* gdb/gdbserver/win32-i386-low.c (i386_arch_setup): Update
call to amd64_create_target_description.
Tested on x86_64-windows using AdaCore's testsuite (by Joel Brobecker
<brobecker at adacore dot com>).
Pedro Alves [Fri, 29 Jun 2018 19:45:35 +0000 (20:45 +0100)]
Improve alignment of "info threads" output, align "Target Id" column
It's long annoyed me that "info threads"'s columns are misaligned.
Particularly the "Target Id" column's content is usually longer than
the specified column width, so the table ends up with the "Frame"
column misaligned. For example, currently we get this:
(gdb) info threads
Id Target Id Frame
1 Thread 0x7ffff7fb5740 (LWP 9056) "threads" 0x00007ffff7bc28ad in __pthread_join (threadid=140737345763072, thread_return=0x7fffffffd3e8) at pthread_join.c:90
2 Thread 0x7ffff7803700 (LWP 9060) "function0" thread_function0 (arg=0x0) at threads.c:90
* 3 Thread 0x7ffff7002700 (LWP 9061) "threads" thread_function1 (arg=0x1) at threads.c:106
The fact that the "Frame" heading is in a weird spot is particularly
annoying.
This commit turns the above into into this:
(gdb) info threads
Id Target Id Frame
1 Thread 0x7ffff7fb5740 (LWP 7548) "threads" 0x00007ffff7bc28ad in __pthread_join (threadid=140737345763072, thread_return=0x7fffffffd3e8) at pthread_join.c:90
2 Thread 0x7ffff7803700 (LWP 7555) "function0" thread_function0 (arg=0x0) at threads.c:91
* 3 Thread 0x7ffff7002700 (LWP 7557) "threads" thread_function1 (arg=0x1) at threads.c:104
It does that by computing the max width of the "Target Id" column and
using that as column width when creating the table.
This results in calling target_pid_to_str / target_extra_thread_info /
target_thread_name twice for each thread, but I think that it doesn't
matter in practice performance-wise, because the remote target caches
the info, and with native targets it shouldn't be noticeable. It
could matter if we have many threads (say, thousands), but then "info
threads" is practically useless in such a scenario anyway -- better
thread filtering and aggregation would be necessary.
(Note: I have an old branch somewhere where I attempted at making
gdb's "info threads"-like tables follow a model/view design, so that a
general framework took care of issues like these, but it's incomplete
and a much bigger change. This patch doesn't prevent going in that
direction in the future, of course.)
gdb/ChangeLog:
2018-06-29 Pedro Alves <palves@redhat.com>
* thread.c (thread_target_id_str): New, factored out from ...
(print_thread_info_1): ... here. Use it to compute the max
"Target Id" column width.
gdb/testsuite/ChangeLog:
2018-06-29 Pedro Alves <palves@redhat.com>
Pedro Alves [Fri, 29 Jun 2018 19:45:34 +0000 (20:45 +0100)]
remote & target_extra_thread_info, use cache w/ qThreadExtraInfo and qP too
The following patch will make "info threads" call target_extra_thread_info
more frequently. When I looked at the remote implementation, I noticed
that if we're not using qXfer:threads:read, then we'd be increasing the
remote protocol traffic. This commit prevents that from happening.
Also, it removes a gratuitous local static buffer, which seems good on
its own.
gdb/ChangeLog:
2018-06-29 Pedro Alves <palves@redhat.com>
* remote.c (remote_target::extra_thread_info): Delete
'display_buf' and 'n' locals. from the cache, regardless of
packet mechanims is in use. Use cache for qThreadExtra and qP
methods too.
Pedro Alves [Fri, 29 Jun 2018 18:31:49 +0000 (19:31 +0100)]
"break LINENO/*ADDRESS", inline functions and "info break" output
While experimenting with the previous patch, I noticed this inconsistency
in GDB's output:
(gdb) b 32
Breakpoint 1 at 0x40062f: file inline-break.c, line 32. (1)
(gdb) r
....
Breakpoint 1, func1 (x=1) at inline-break.c:32 (2)
32 return x * 23; /* break here */
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x40062f in main at inline-break.c:32 (3)
breakpoint already hit 1 time
(gdb)
Notice that when the breakpoint as set, GDB showed "inline-break.c,
line 32" (1), the same line number that was specified in the command.
When we run to the breakpoint, we present the stop at the same line
number, and correctly show "func1" as the function name (2).
But in "info break" output (3), notice that we say "in main", not "in
func1".
The same thing happens if you set a breakpoint by address. I.e.:
(gdb) b *0x40062f
Breakpoint 2 at 0x40062f: file inline-break.c, line 32.
(gdb) info breakpoints
Num Type Disp Enb Address What
2 breakpoint keep y 0x000000000040062f in main at inline-break.c:32
(gdb) r
....
Breakpoint 2, func1 (x=1) at inline-break.c:32
32 return x * 23; /* break here */
The problem is that the breakpoints were set at an inline function,
but when we set such a breakpoint by line number or address, we don't
record the functions symbol in the sal, and as consequence the
breakpoint location does not have an associated symbol either.
Then, in print_breakpoint_location, if the location does not have a
symbol, we call find_pc_sect_function to find one, and this is what
finds "main", because find_pc_sect_function uses
block_linkage_function:
/* Return the symbol for the function which contains a specified
lexical block, described by a struct block BL. The return value
will not be an inlined function; the containing function will be
returned instead. */
struct symbol *
block_linkage_function (const struct block *bl)
To fix this, this commit adds an alternative to find_pc_sect_function
that uses block_containing_function instead:
/* Return the symbol for the function which contains a specified
block, described by a struct block BL. The return value will be
the closest enclosing function, which might be an inline
function. */
struct symbol *
block_containing_function (const struct block *bl)
(It seems odd to me that block_linkage_function says "the CONTAINING
function will be returned", and then block_containing_function says it
returns "the closest enclosing function". Something seems reversed
here. Still, I've kept the same nomenclature and copied the comments,
so that at least there's consistency. Maybe we should fix that up
somehow.)
Then I wondered, why make print_breakpoint_location look up the symbol
every time it is called, instead of just always storing the symbol
when the location is created, since the location already stores the
symbol in some cases. So to find which cases might be missing setting
the symbol in the sal which is used to create the breakpoint location,
I added an assertion to print_breakpoint_location, and ran the
testsuite. That caught a few places, unsurprisingly:
- setting a breakpoint by line number
- setting a breapoint by address
- ifunc resolving
Those are all fixed by this commit. I decided not to add the
assertion to block_linkage_function and leave the existing "if (sym)"
check in place, because it's plausible that we have symtabs with line
info but no symbols. I.e., that would not be a GDB bug, but
a peculiarity of debug info input.
gdb/ChangeLog:
2018-06-29 Pedro Alves <palves@redhat.com>
* blockframe.c (find_pc_sect_containing_function): New function.
* breakpoint.c (print_breakpoint_location): Don't call
find_pc_sect_function.
* linespec.c (create_sals_line_offset): Record the location's
symbol in the sal.
* linespec.c (convert_address_location_to_sals): Fill in sal's
symbol with find_pc_sect_containing_function.
* symtab.c (find_function_start_sal): Rename to ...
(find_function_start_sal_1): ... this.
(find_function_start_sal): Reimplement as wrapper around
find_function_start_sal_1, and use
find_pc_sect_containing_function to fill in the sal's symbol.
(find_function_start_sal(symbol*, bool)): Adjust.
* symtab.h (find_pc_function, find_pc_sect_function): Adjust
comments.
(find_pc_sect_containing_function): Declare.
gdb/testsuite/ChangeLog:
2018-06-29 Pedro Alves <palves@redhat.com>
Pedro Alves [Fri, 29 Jun 2018 18:31:49 +0000 (19:31 +0100)]
Fix running to breakpoint set in inline function by lineno/address
Commit 61b04dd04ac2 ("Change inline frame breakpoint skipping logic
(fix gdb.gdb/selftest.exp)") caused a GDB crash when you set a
breakpoint by line number in an inline function, and then run to the
breakpoint:
$ gdb -q test Reading symbols from test...done.
(gdb) b inline-break.c:32
Breakpoint 1 at 0x40062f: file inline-break.c, line 32.
(gdb) run
Starting program: /[...]/test
[1] 75618 segmentation fault /[...]/gdb -q test
The problem occurs because we assume that a bp_location's symbol is
not NULL, which is not true when we set the breakpoint with a linespec
location:
Program received signal SIGSEGV, Segmentation fault.
0x00000000006f42bb in stopped_by_user_bp_inline_frame (
stop_chain=<optimized out>, frame_block=<optimized out>)
at gdb/inline-frame.c:305
305 && frame_block == SYMBOL_BLOCK_VALUE (loc->symbol))
(gdb) p loc->symbol
$1 = (const symbol *) 0x0
The same thing happens if you run to a breakpoint set in an inline
function by address:
(gdb) b *0x40062f
Breakpoint 3 at 0x40062f: file inline-break.c, line 32.
To fix this, add a null pointer check, to avoid the crash, and make it
so that if there's no symbol for the location, then we present the
stop at the inline function. This preserves the previous behavior
when e.g., setting a breakpoint by address, with "b *ADDRESS".
gdb/ChangeLog:
2018-06-29 Pedro Alves <palves@redhat.com>
* inline-frame.c (stopped_by_user_bp_inline_frame): Return
true if the the location has no symbol.
gdb/testsuite/ChangeLog:
2018-06-29 Pedro Alves <palves@redhat.com>
* gdb.opt/inline-break.c (func1): Add "break here" marker.
* gdb.opt/inline-break.exp: Test setting breakpoints by line
number and address and running to them.
MIPS/BFD: Remove extraneous undefined weak symbol visibility check
Remove an extraneous symbol visibility check made for undefined weak
symbols in determination whether an R_MIPS_REL32 dynamic relocation has
to be placed in output, complementing commit ad9512030937 ("mips: Check
UNDEFWEAK_NO_DYNAMIC_RELOC"). That check duplicates one already made by
the UNDEFWEAK_NO_DYNAMIC_RELOC macro as a part of a broader condition
used to decide if to enter undefined weak symbols to the dynamic symbol
table or not.
bfd/
* elfxx-mips.c (allocate_dynrelocs): Remove extraneous symbol
visibility check made for undefined weak symbols.
Tamar Christina [Fri, 29 Jun 2018 11:12:27 +0000 (12:12 +0100)]
Fix AArch64 encodings for by element instructions.
Some instructions in Armv8-a place a limitation on FP16 registers that can be
used as the register from which to select an element from.
e.g. fmla restricts Rm to 4 bits when using an FP16 register. This restriction
does not apply for all instructions, e.g. fcmla does not have this restriction
as it gets an extra bit from the M field.
Unfortunately, this restriction to S_H was added for all _Em operands before,
meaning for a large number of instructions you couldn't use the full register
file.
This fixes the issue by introducing a new operand _Em16 which applies this
restriction only when paired with S_H and leaves the _Em and the other
qualifiers for _Em16 unbounded (i.e. using the full 5 bit range).
Also the patch updates all instructions that should be affected by this.
Pedro Alves [Thu, 28 Jun 2018 19:18:24 +0000 (20:18 +0100)]
gdb: Eliminate the 'stop_pc' global
In my multi-target work, I need to add a few more
scoped_restore_current_thread and switch_to_thread calls in some
places, and in some lower-level places I was fighting against the fact
that switch_to_thread reads/refreshes the stop_pc global.
Instead of piling on workarounds, let's just finally eliminate the
stop_pc global. We already have the per-thread
thread_info->suspend.stop_pc field, so it's mainly a matter of using
that more/instead.
gdb/ChangeLog:
2018-06-28 Pedro Alves <palves@redhat.com>
* gdbthread.h (struct thread_suspend_state) <stop_pc>: Extend
comments.
(switch_to_thread_no_regs): Adjust comment.
* infcmd.c (stop_pc): Delete.
(post_create_inferior, info_program_command): Replace references
to stop_pc with references to thread_info->suspend.stop_pc.
* inferior.h (stop_pc): Delete declaration.
* infrun.c (proceed, handle_syscall_event, fill_in_stop_func)
(handle_inferior_event_1, handle_signal_stop)
(process_event_stop_test, keep_going_stepped_thread)
(handle_step_into_function, handle_step_into_function_backward)
(print_stop_location): Replace references to stop_pc with
references to thread_info->suspend.stop_pc.
(struct infcall_suspend_state) <stop_pc>: Delete field.
(save_infcall_suspend_state, restore_infcall_suspend_state):
Remove references to inf_stat->stop_pc.
* linux-fork.c (fork_load_infrun_state): Likewise.
* record-btrace.c (record_btrace_set_replay): Likewise.
* record-full.c (record_full_goto_entry): Likewise.
* remote.c (print_one_stopped_thread): Likewise.
* target.c (target_resume): Extend comment.
* thread.c (set_executing_thread): New.
(set_executing): Use it.
(switch_to_thread_no_regs, switch_to_no_thread, switch_to_thread):
Remove references to stop_pc.
Pedro Alves [Thu, 28 Jun 2018 15:57:18 +0000 (16:57 +0100)]
Fix follow-exec regression / crash
After commit 00431a78b28f ("Use thread_info and inferior pointers more
throughout"), following an exec can result in gdb crashing. On some
systems, this is visible with gdb.multi/multi-arch-exec.exp and
gdb.base/foll-exec-mode.exp. E.g.:
$ make check TESTS="gdb.multi/multi-arch-exec.exp gdb.base/foll-exec-mode.exp"
[snip]
FAIL: gdb.multi/multi-arch-exec.exp: first_arch=1: selected_thread=1: follow_exec_mode=new: continue across exec that changes architecture (GDB internal error)
ERROR: : spawn id exp10 not open
while executing
Running multi-arch-exec under Valgrind we easily spot the problem:
process 16305 is executing new program: ..../gdb.multi/multi-arch-exec/1-multi-arch-exec-hello
[New inferior 2 (process 0)]
[New process 16305]
==16129== Invalid read of size 8
==16129== at 0x7FA14D: get_thread_regcache(thread_info*) (regcache.c:399)
==16129== by 0x75E54B: handle_inferior_event_1(execution_control_state*) (infrun.c:5292)
==16129== by 0x75E82D: handle_inferior_event(execution_control_state*) (infrun.c:5382)
==16129== by 0x75BC6A: fetch_inferior_event(void*) (infrun.c:3918)
==16129== by 0x748DA3: inferior_event_handler(inferior_event_type, void*) (inf-loop.c:43)
==16129== by 0x464B5D: handle_target_event(int, void*) (linux-nat.c:4359)
==16129== by 0x7047E0: handle_file_event(file_handler*, int) (event-loop.c:733)
==16129== by 0x704D83: gdb_wait_for_event(int) (event-loop.c:859)
==16129== by 0x703BF6: gdb_do_one_event() (event-loop.c:322)
==16129== by 0x703CA2: start_event_loop() (event-loop.c:371)
==16129== by 0x791D95: captured_command_loop() (main.c:330)
==16129== by 0x79311C: captured_main(void*) (main.c:1157)
==16129== Address 0x15a5bad0 is 32 bytes inside a block of size 600 free'd
==16129== at 0x4C2E1E8: operator delete(void*) (vg_replace_malloc.c:576)
==16129== by 0x8A15D0: delete_thread_1(thread_info*, bool) (thread.c:465)
==16129== by 0x8A15FA: delete_thread(thread_info*) (thread.c:476)
==16129== by 0x8A0D43: add_thread_silent(ptid_t) (thread.c:291)
==16129== by 0x8A0DF0: add_thread_with_info(ptid_t, private_thread_info*) (thread.c:317)
==16129== by 0x8A0E79: add_thread(ptid_t) (thread.c:331)
==16129== by 0x75764C: follow_exec(ptid_t, char*) (infrun.c:1233)
==16129== by 0x75E534: handle_inferior_event_1(execution_control_state*) (infrun.c:5290)
==16129== by 0x75E82D: handle_inferior_event(execution_control_state*) (infrun.c:5382)
==16129== by 0x75BC6A: fetch_inferior_event(void*) (infrun.c:3918)
==16129== by 0x748DA3: inferior_event_handler(inferior_event_type, void*) (inf-loop.c:43)
==16129== by 0x464B5D: handle_target_event(int, void*) (linux-nat.c:4359)
The problem is that handle_inferior_event_1 is reading the stop_pc off
of a thread that was deleted by follow_exec. Before commit 00431a78b28f, we didn't crash because we were passing down a ptid to
get_thread_regcache instead of ecs->event_thread.
Fix this by simply moving the stop_pc reading until after
ecs->event_thread is refreshed.
gdb/ChangeLog:
2018-06-28 Pedro Alves <palves@redhat.com>
* infrun.c (handle_inferior_event_1) <TARGET_WAITKIND_EXECD>:
Moving fetching stop_pc until after ecs->event_thread is refreshed.
Tom Tromey [Tue, 5 Jun 2018 15:42:15 +0000 (09:42 -0600)]
Make dwarf2_free_objfile static
I noticed that dwarf2_free_objfile can be made static, by changing it
to be a registry cleanup function. This simplifies the code, as well,
because now symbol readers don't have to explicitly call it.
Tested by the buildbot.
gdb/ChangeLog
2018-06-28 Tom Tromey <tom@tromey.com>
Jan Kratochvil [Thu, 28 Jun 2018 14:09:37 +0000 (16:09 +0200)]
Remove 2 excessive executable permission flags
Fedora rpmbuild has been complaining:
*** WARNING: ./usr/src/debug/gdb-8.1.50.20180618-24.fc28.x86_64/gdb/gdbserver/x86-tdesc.h is executable but has empty or no shebang, removing executable bit
gdb/gdbserver/ChangeLog
2018-06-28 Jan Kratochvil <jan.kratochvil@redhat.com>
* x86-tdesc.h: Remove executable permission flag.
gdb/testsuite/ChangeLog
2018-06-28 Jan Kratochvil <jan.kratochvil@redhat.com>
Richard Bunt [Thu, 28 Jun 2018 07:59:59 +0000 (08:59 +0100)]
Fixed top frame assumption in watchpoint-hw-attach
watchpoint-hw-attach.exp was noticed to fail on some machines.
Thanks to the input from sergiodj and palves on the IRC channel,
it was concluded that the test case incorrectly assumed that on
attach it was landed in the top-most frame of the inferior. This
was fixed by running to a break point in main by explicitly
defining the source file name before continuing with the test.
Tested on the following architectures x86_64, aarch64 and ppc64le.
Petr Tesarik [Thu, 28 Jun 2018 06:33:17 +0000 (08:33 +0200)]
Add an optional offset option to the "add-symbol-file" command
If all sections of a symbol file are loaded with a fixed offset, it
is easier to specify that offset than listing all sections
explicitly. There is also a similar option for "symbol-file".
gdb/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
* symfile.c (add_symbol_file_command, _initialize_symfile): Add
option "-o" to add-symbol-file-load to add an offset to each
section's load address.
* symfile.c (set_objfile_default_section_offset): New function.
gdb/doc/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
Petr Tesarik [Thu, 28 Jun 2018 06:32:27 +0000 (08:32 +0200)]
Make sure that sorting does not change section order
Symbol files may contain multiple sections with the same name.
Section addresses specified by add-symbol-file are assigned to the
corresponding BFD sections in addr_info_make_relative using sorted
indexes of both vectors. Since the sort algorithm is not inherently
stable, the comparison function uses sectindex to maintain the
original order. However, add_symbol_file_command uses zero for all
sections, so if the user specifies multiple sections with the same
name, they will be assigned randomly to symbol file sections with
the same name.
gdb/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
* symfile.c (add_symbol_file_command): Make sure that sections
Petr Tesarik [Thu, 28 Jun 2018 06:30:42 +0000 (08:30 +0200)]
Make add-symbol-file's address argument optional
The (first) .text section must be always specified as the second
non-option argument. The documentation states that GDB cannot
figure out this address by itself. This is true if the object file
was indeed relocated, but it is also confusing, because all other
sections can be omitted and will use the address provided by BFD.
gdb/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
* symfile.c (add_symbol_file_command, _initialize_symfile): Do not
require the second argument. If omitted, load sections at the
addresses specified in the file.
gdb/doc/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
* gdb.texinfo (Files): The address argument for "add-symbol-file"
is no longer mandatory.
gdb/testsuite/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
* gdb.base/relocate.exp: Test add-symbol-file behavior when the
address argument is omitted.
Petr Tesarik [Thu, 28 Jun 2018 06:01:33 +0000 (08:01 +0200)]
Add an optional offset option to the "symbol-file" command
If the main file is relocated at runtime, all symbols are offset by
a fixed amount. Let the user specify this offset when loading a
symbol file.
gdb/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
* symfile.c (symbol_file_command, symbol_file_add_main_1)
(_initialize_symfile): Add option "-o" to symbol-file to add an
offset to each section of the symbol file.
gdb/doc/ChangeLog:
2018-06-28 Petr Tesarik <ptesarik@suse.cz>
Tom Tromey [Tue, 5 Jun 2018 15:23:48 +0000 (09:23 -0600)]
Update "func" help text to GNU standards
In my earlier series to change help text to follow the GNU standards
for metasyntactic variables, I missed one: the "func" command. This
patch updates its help text.
Tested by the buildbot.
gdb/ChangeLog
2018-06-27 Tom Tromey <tom@tromey.com>
* stack.c (_initialize_stack): Update "func" help text.
Tom Tromey [Tue, 5 Jun 2018 16:02:45 +0000 (10:02 -0600)]
Remove a VEC from py-unwind.c
This removes a use of VEC from py-unwind.c, replacing it wit
std::vector. It also changes saved_regs to hold a gdbpy_ref<>,
simplifying the memory management.
Tested against gdb.python on x86-64 Fedora 26.
gdb/ChangeLog
2018-06-27 Tom Tromey <tom@tromey.com>
* python/py-unwind.c (unwind_info_object) <saved_regs>: Now a
std::vector.
(unwind_infopy_str, pyuw_create_unwind_info)
(unwind_infopy_add_saved_register, pyuw_sniffer)
(unwind_infopy_dealloc, unwind_infopy_add_saved_register):
Update.
(struct saved_reg): Add constructor.
<value>: Now a gdbpy_ref<>.
Tom Tromey [Wed, 27 Jun 2018 19:06:33 +0000 (13:06 -0600)]
Fix crash in machoread.c
"./gdb ./gdb" was crashing for me on macOS. Investigating showed that
macho_symfile_read was crashing because "symbol_table" was being freed
too soon. This was introduced by my earlier patch to change
macho_symfile_read to use a std::vector.
Tested on macOS 10.13.5 using "./gdb ./gdb". This should un-break
various already existing tests (testsuite/gdb.gdb at least), so no new
test case.
I'm checking this in as obvious.
gdb/ChangeLog
2018-06-27 Tom Tromey <tom@tromey.com>
Simon Marchi [Wed, 27 Jun 2018 18:32:02 +0000 (14:32 -0400)]
Copy gdb-gdb.py to build dir
I have thought for a long time how nice it would be to have cool pretty
printers for GDB's internal types. Well, turns out there are few
already in gdb-gdb.py! Unfortunately, if you build GDB outside of the
source directory, that file never gets loaded. top-gdb will look for a
file called
../path/to/build/gdb/gdb-gdb.py
but that file is in the source directory at
../path/to/src/gdb/gdb-gdb.py
This patch makes it so we copy it to the build directory, just like we
do for gdb-gdb.gdb. With this, I can at least see the file getting
automatically loaded:
(top-gdb) info pretty-printer
global pretty-printers:
builtin
mpx_bound128
objfile /home/emaisin/build/binutils-gdb/gdb/gdb pretty-printers:
type_lookup_function
I noticed that running "make" didn't re-generate gdb-gdb.py from
gdb-gdb.py.in. That's because it's copied when running the configure
script and that's it. I added a rule in the Makefile for that (and for
gdb-gdb.gdb too) and added them as a dependency to the "all" target.
gdb/ChangeLog:
* gdb-gdb.py: Move to...
* gdb-gdb.py.in: ... here.
* configure.ac (AC_CONFIG_FILES): Add gdb-gdb.py.
* Makefile.in (all): Add gdb-gdb.gdb and gdb-gdb.py as
dependencies.
(distclean): Remove gdb-gdb.py when cleaning.
(gdb-gdb.py, gdb-gdb.gdb): New rules.
* configure: Re-generate.
Pedro Alves [Wed, 27 Jun 2018 16:19:32 +0000 (17:19 +0100)]
Fix Cell debugging regression
Commit 00431a78b28f ("Use thread_info and inferior pointers more
throughout") broke Cell multi-arch debugging, because it made the
proc-service routines (ps_lgetregs etc.) access registers using the
SPU architecture if GDB happens to interrupt SPU code. The
proc-service routines must always operate on the "main" (in this case
PowerPC) architecture, because that's the register set libthread_db
expects to be using.
Restore the previous behavior, but wrapped in a new
get_ps_regcache function with a describing comment.
Also, the ps_l*regs routines have an explicit lwpid parameter that
said commit missed; with the commit mentioned above, we started always
reading the registers off of the current thread, which is incorrect.
That is fixed by this commit too.
gdb/ChangeLog:
2018-06-27 Pedro Alves <palves@redhat.com>
* proc-service.c (get_ps_regcache): New.
(ps_lgetregs, ps_lsetregs, ps_lgetfpregs)
(ps_lsetfpregs): Use it.
Omair Javaid [Tue, 15 May 2018 14:04:21 +0000 (19:04 +0500)]
Fix lost line info for symbol at addr zero
This patch fixes a unique condition where GDB fails to provide line
information of symbol at address zero when code is compiled with text
address zero but loaded at an offset > 0.
add-symbol-file file.out 0xffff0000
info line main
GDB will return error saying no line info is available for the symbol.
This is a direct consequence of the fix for PR 12528 where GDB tries to ignore
line table for a function which has been garbage collected by the linker.
As the garbage collected symbols are sent to address zero GDB assumes a symbol
actually placed at address zero as garbage collected.
This was fixed with an additional check address < lowpc. But when symbol is
loaded at an offset lowpc becomes lowpc + offset while no offset is added to
address rather final symbol address is calculated based on baseaddr and address
added together. So in case where symbols are loaded at an offset the condition
address < lowpc will always return true.
This patch fixes this by comparing address against a non offset lowpc.
This patch also adds a GDB test case to replicate this behavior.
Simon Marchi [Wed, 27 Jun 2018 14:52:57 +0000 (10:52 -0400)]
Add overrides, fix FreeBSD build
Fix this:
CXX fbsd-nat.o
In file included from fbsd-nat.c:44:
./fbsd-nat.h:40:7: error: 'find_memory_regions' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
int find_memory_regions (find_memory_region_ftype func, void *data);
^
./target.h:702:17: note: overridden virtual function is here
virtual int find_memory_regions (find_memory_region_ftype func, void *data)
^
In file included from fbsd-nat.c:44:
./fbsd-nat.h:42:8: error: 'info_proc' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
bool info_proc (const char *, enum info_proc_what);
^
./target.h:950:18: note: overridden virtual function is here
virtual bool info_proc (const char *, enum info_proc_what);
^
Alan Modra [Wed, 27 Jun 2018 03:17:13 +0000 (12:47 +0930)]
gas object file locations
With the update to newer autotools, some gas object files are now
built in config/, breaking xtensa-elf and ia64-vms. This patch fixes
the dependencies.
* configure.ac: Specify extra_objects with leading "config/"
for xtensa-relax.o and te-vms.o. Use case statements to unique
extra_objects. Formatting.
* configure: Regenerate.
Joel Brobecker [Tue, 26 Jun 2018 21:38:32 +0000 (14:38 -0700)]
Minor reorganization of fetch_registers/store_registers in windows-nat.c
This patch is a small reorganizational patch that splits
do_windows_fetch_inferior_registers into two parts:
(a) One part that first reloads the thread's context when needed,
and then decides based on the given register number whether
one register needs to be fetched or all of them.
This part is moved to windows_nat_target::fetch_registers.
(b) The rest of the code, which actually fetches the register value
and supplies it to the regcache.
A similar treatment is applied to do_windows_store_inferior_registers.
This change is preparation work for changing the way we calculate
the location of a given register in the thread context structure,
and should be a no op.
gdb/ChangeLog:
* windows-nat.c (do_windows_fetch_inferior_registers): Rename
to windows_fetch_one_register, and only handle the case of
fetching one register. Move the code that reloads the context
and iterates over all registers if R is negative to...
(windows_nat_target::fetch_registers): ... here.
(do_windows_store_inferior_registers): Rename to
windows_store_one_register, and only handle the case of storing
one register. Move the code that handles the case where r is
negative to...
(windows_nat_target::store_registers) ... here.
Tested on x86-windows and x86_64-windows using AdaCore's testsuite.
Tom Tromey [Fri, 8 Jun 2018 19:18:25 +0000 (13:18 -0600)]
Support ptype/o in Rust
This adds support for ptype/o to the Rust language code.
By default, the Rust compiler reorders fields to reduce padding. So,
the Rust language code sorts the fields by offset before printing.
This may yield somewhat odd-looking results, but it is faithful to
"what really happens", and might be useful when doing lower-level
debugging.
The reordering can be disabled using #[repr(c)]; ptype/o might be more
useful in this case.
gdb/ChangeLog
2018-06-26 Tom Tromey <tom@tromey.com>
Tom Tromey [Fri, 8 Jun 2018 18:43:47 +0000 (12:43 -0600)]
Move ptype/o printing code to typeprint.c
This moves the hole-printing support code for ptype/o from
c-typeprint.c to be methods on print_offset_data. This allows the
code to be used from non-C languages.
gdb/ChangeLog
2018-06-26 Tom Tromey <tom@tromey.com>
* typeprint.h (struct print_offset_data) <update, finish,
maybe_print_hole>: New methods.
<indentation>: New constant.
* typeprint.c (print_offset_data::indentation): Define.
(print_offset_data::maybe_print_hole, print_offset_data::update)
(print_offset_data::finish): Move from c-typeprint.c and rename.
* c-typeprint.c (OFFSET_SPC_LEN): Remove.
(print_spaces_filtered_with_print_options): Update.
(c_print_type_union_field_offset, maybe_print_hole)
(c_print_type_struct_field_offset): Move to typeprint.c and
rename.
(c_type_print_base_struct_union): Update.
Nick Clifton [Tue, 26 Jun 2018 12:40:13 +0000 (13:40 +0100)]
Fix the MSP430 assembler's parsing of register names.
PR 23335
* config/tc-msp430.c (check_reg): Only accept register name
strings that do not end in an alphanumeric character.
* testsuite/gas/msp430/msp430x.d: Update expected disassembly.
Pedro Alves [Mon, 25 Jun 2018 16:18:18 +0000 (17:18 +0100)]
gdb: For macOS, s/thread_info/struct thread_info/
The macOS build currently fails with several instances of this problem:
In file included from ../../src/gdb/darwin-nat.h:22:0,
from ../../src/gdb/i386-darwin-nat.c:37:
../../src/gdb/gdbthread.h:376:59: error: type/value mismatch at argument 1 in template parameter list for 'template<class T, class Policy> class gdb::ref_ptr'
= gdb::ref_ptr<thread_info, refcounted_object_ref_policy>;
^
../../src/gdb/gdbthread.h:376:59: note: expected a type, got 'thread_info'
../../src/gdb/gdbthread.h:396:28: error: variable or field 'delete_thread' declared void
extern void delete_thread (thread_info *thread);
^
(...)
This is because there's a thread_info function in the Darwin/XNU/mach API:
Pedro Alves [Mon, 25 Jun 2018 16:42:22 +0000 (17:42 +0100)]
gdb: Fix build on several hosts/ports
Commit 00431a78b28f ("Use thread_info and inferior pointers more
throughout") missed updating some callers, like e.g.,:
gdb/remote-sim.c: In member function 'virtual void gdbsim_target::mourn_inferior()':
gdb/remote-sim.c:1198:50: error: cannot convert 'ptid_t' to 'thread_info*' for argument '1' to 'void delete_thread_silent(thread_info*)'
delete_thread_silent (sim_data->remote_sim_ptid);
gdb/mygit/src/gdb/procfs.c: In member function ‘virtual void procfs_target::detach(inferior*, int)’:
gdb/mygit/src/gdb/procfs.c:1931:23: error: invalid conversion from ‘int’ to ‘inferior*’ [-fpermissive]
detach_inferior (pid);
^
In file included from gdb/mygit/src/gdb/procfs.c:24:0:
gdb/mygit/src/gdb/inferior.h:476:13: note: initializing argument 1 of ‘void detach_inferior(inferior*)’
etc.
This fixes it.
The delete_thread_silent calls in both go32-nat.c and remote-sim.c are
unnecessary because generic_mourn_inferior calls exit_inferior, which
deletes the inferior's threads.
gdb/ChangeLog:
2018-06-25 Pedro Alves <palves@redhat.com>
* windows-nat.c (windows_delete_thread): Use find_thread_ptid and
pass thread_info pointer to delete_thread.
(windows_nat_target::detach): Pass inferior pointer to
detach_inferior.
* aix-thread.c (sync_threadlists): Pass thread_info pointer to
delete_thread.
* bsd-kvm.c (bsd_kvm_target::close): Use discard_all_inferiors.
* darwin-nat.c (darwin_check_new_threads): Use find_thread_ptid
and pass a thread_info pointer to delete_thread.
* fbsd-nat.c (fbsd_nat_target::wait): Use find_thread_ptid and
pass thread_info pointer to delete_thread.
* go32-nat.c (go32_nat_target::mourn_inferior): Remove
delete_thread_silent call.
* procfs.c (procfs_target::detach): Pass inferior pointer to
detach_inferior.
(procfs_target::wait): Pass thread_info pointer to delete_thread.
* remote-sim.c (gdbsim_target::mourn_inferior): Remove
delete_thread_silent call.
* windows-nat.c (windows_delete_thread): Use find_thread_ptid and
pass thread_info pointer to delete_thread.
(windows_nat_target::detach): Pass inferior pointer to
delete_inferior.
Tom Tromey [Mon, 25 Jun 2018 03:25:44 +0000 (21:25 -0600)]
Add a syntax table to dwarf-mode.el
This adds a syntax table for dwarf-mode to dwarf-mode.el. I noticed
the need for this when trying to use mark-sexp (C-M-SPC) on a hex
number -- it copied the trailing ">" as well, which isn't desirable.
I've also bumped the version number to make this simpler to install
via the Emacs package system.
Tested locally. I'm checking this in.
binutils/ChangeLog
2018-06-25 Tom Tromey <tom@tromey.com>
* dwarf-mode.el (dwarf-mode-syntax-table): New variable.
Bump version number.
Cary Coutant [Sat, 23 Jun 2018 00:28:05 +0000 (17:28 -0700)]
Add x86-64 support for Indirect Branch Tracking (IBT).
gold/
PR gold/22915
* x86_64.cc (Output_data_plt_x86_64_ibt): New class.
(Target_x86_64::do_make_data_plt): (All instantiations) Check for
IBT feature bit and create IBT PLTs.
Cary Coutant [Sat, 23 Jun 2018 06:36:50 +0000 (23:36 -0700)]
Update support for .note.gnu.property sections.
The original patch did not give the target enough hooks to discover that
an input object file does not have a particular property. For the
GNU_PROPERTY_X86_FEATURE_1_AND property, for example, where a missing
property should be assumed to be all zeroes, and ANDed with other
object modules, this is essential. We now store the target-specific
properties locally in the Target structure as native uint32_t fields,
then AND the per-object feature bits with the program's feature bits
when we're finished processing each input object file. The target-specific
properties are then added back to the output note section during
finalization.
gold/
PR gold/22914
* layout.cc (read_sized_value): Fix spelling of section name.
(Layout::layout_gnu_property): Call Sized_target::record_gnu_property
for target-specific properties;
don't store them with target-independent properties yet.
(Layout::merge_gnu_properties): New method.
(Layout::add_gnu_property): New method.
(Layout::create_gnu_properties_note): Call target to finalize
target-specific properties. Fix spelling of output section name.
* layout.h (Layout::merge_gnu_properties): New method.
(Layout::add_gnu_property): New method.
* object.cc (Sized_relobj_file::do_layout): Call
Layout::merge_gnu_properties.
* target.h (Target::merge_gnu_property): Remove.
(Target::finalize_gnu_properties): New method.
(Target::do_merge_gnu_property): Move to Sized_target and rename.
(Target::do_finalize_gnu_properties): New virtual method.
(Sized_target::record_gnu_property): Moved and renamed from
Target::do_merge_gnu_property.
(Sized_target::merge_gnu_properties): New virtual method.
* x86_64.cc (Target_x86_64::isa_1_used_, isa_1_needed_)
(feature_1_, object_feature_1_, seen_first_object_): New data members.
(Target_x86_64::do_merge_gnu_property): Rename to ...
(Target_x86_64::record_gnu_property): ... this. Save target-specific
properties in Target class object.
(Target_x86_64::merge_gnu_properties): New method.
(add_property): New static inline function.
(Target_x86_64::do_finalize_gnu_properties): New method.
* testsuite/Makefile.am (gnu_property_test): Remove C source file;
link directly without compiler driver.
* testsuite/Makefile.in: Regenerate.
* testsuite/gnu_property_a.S: Add _start.
Cary Coutant [Sat, 23 Jun 2018 01:19:51 +0000 (18:19 -0700)]
Silence GCC 9 error about deprecated implicit copy constructor.
Replacing push_back() with emplace_back() eliminates the calls to the
copy constructor, but I still had to provide explicit copy constructors
because of the call to vector::reserve(), which tries to instantiate them
even though they'll never actually be called when reserve() is called
on an empty vector.
gold/
* incremental.cc (Sized_incremental_binary::setup_readers): Use
emplace_back for GCC 5 and later.
* incremental.h (Incremental_binary::Input_reader): Provide copy
constructor.
(Sized_incremental_binary::Sized_input_reader): Likewise.
Cary Coutant [Fri, 22 Jun 2018 16:27:39 +0000 (09:27 -0700)]
Add support for .note.gnu.property sections.
elfcpp/
PR gold/22914
* elfcpp.h (NT_GNU_PROPERTY_TYPE_0): New note type.
(GNU_PROPERTY_*): New Gnu property types.
* x86_64.h (GNU_PROPERTY_X86_FEATURE_1_IBT)
(GNU_PROPERTY_X86_FEATURE_1_SHSTK): New x86 feature bits.
gold/
PR gold/22914
* layout.cc (Layout::Layout): Initialize gnu_properties_.
(read_sized_value, write_sized_value): New functions.
(Layout::layout_gnu_property): New method.
(Layout::create_notes): Call create_gnu_properties_note.
(Layout::create_gnu_properties_note): New method.
* layout.h (Layout::layout_gnu_property): New method.
(Layout::create_gnu_properties_note): New method.
(Layout::Gnu_property, Layout::Gnu_properties): New types.
(Layout::gnu_properties_): New data member.
* object.cc (Sized_relobj_file::layout_gnu_property_section): New
method.
(Sized_relobj_file::do_layout): Handle .note.gnu.property sections.
* object.h (Sized_relobj_file::layout_gnu_property_section): New
method.
* target.h (Target::merge_gnu_property): New method.
(Target::do_merge_gnu_property): New virtual method.
* x86_64.cc (Target_x86_64::do_merge_gnu_property): New method.
* testsuite/Makefile.am (gnu_property_test): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/gnu_property_a.S: New source file.
* testsuite/gnu_property_b.S: New source file.
* testsuite/gnu_property_c.S: New source file.
* testsuite/gnu_property_main.c: New source file.
* testsuite/gnu_property_test.sh: New test script.
Alan Hayward [Wed, 20 Jun 2018 17:19:05 +0000 (18:19 +0100)]
Use partial register read/writes in transfer_regset
This avoids assert failures when the register is bigger than the
slot size. This happens on Aarch64 when truncating Z registers
into an fpsimd structure. This can be triggered by running
gdb command "generate-core-file".
Also, when the register is smaller then the slot size, then
zero pad when writing to the slot, and truncate when writing
to the regcache. This happens on Aarch64 with the CPSR register.
Continue to ensure registers are invalidated when both buffers
are null.
gdb/
* regcache.c (readable_regcache::read_part): Fix asserts.
(reg_buffer::raw_collect_part): New function.
(regcache::write_part): Fix asserts.
(reg_buffer::raw_supply_part): New function.
(regcache::transfer_regset_register): New helper function.
(regcache::transfer_regset): Call new functions.
(regcache_supply_regset): Use gdb_byte*.
(regcache::supply_regset): Likewise.
(regcache_collect_regset): Likewise.
(regcache::collect_regset): Likewise.
* regcache.h (reg_buffer::raw_collect_part): New declaration.
(reg_buffer::raw_supply_part): Likewise.
(regcache::transfer_regset_register): Likewise.
(regcache::transfer_regset): Use gdb_byte*.
Tamar Christina [Fri, 22 Jun 2018 11:27:53 +0000 (12:27 +0100)]
Correct negs aliasing on AArch64.
This patch fixes a disassembly issue with the aliases to subs with a shifted
register. The subs instruction with the zero register as destination is
supposed to alias to cmp and when the first input register is the zero register
the subs is supposed to be aliased to negs.
This means that a subs with destination and first input registers the zero
register is supposed to be a cmp.
This is done by raising the priority of the cmp alias.
opcodes/
* aarch64-tbl.h (aarch64_opcode_table): Fix alias flag for negs
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Likewise.
gas/
* testsuite/gas/aarch64/addsub.s: Add negs to zero reg test.
* testsuite/gas/aarch64/addsub.d: Likewise.
Cary Coutant [Thu, 21 Jun 2018 20:51:16 +0000 (13:51 -0700)]
Fix treatment of symbol versions with unused as-needed libraries.
When we have a weak reference to a symbol defined in an
as-needed library, and that library ends up not-needed, gold
simply clears the version information in the symbol table, even
if the symbol could have been resolved by a needed library later
in the link order. This results in a loss of version information,
which can cause the program to bind to the wrong version at run
time.
This patch lets a dynamic definition override an earlier one if
the earlier one is from a not-needed library, so that we can
retain the version information from the binding to the needed
library. In order to do that, the tracking of needed/not-needed
had to be moved up to symbol resolution time, instead of during
Symbol_table::set_dynsym_indexes().
In cases where we still end up discarding version information,
I've added a warning.
For the original problem report and discussion, see:
gold/
* resolve.cc (Symbol_table::resolve): Rename tobinding to
orig_tobinding. Call set_is_needed() for objects that resolve
non-weak references.
(Symbol_table::should_override): Allow a dynamic definition to
override an earlier one in a not-needed library.
* symtab.cc (Symbol_table::set_dynsym_indexes): Remove separate
processing for as-needed symbols. Add warning when discarding
version informatin.
* testsuite/Makefile.am (weak_as_needed): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/weak_as_needed.sh: New test script.
* testsuite/weak_as_needed_a.c: New source file.
* testsuite/weak_as_needed_b.c: New source file.
* testsuite/weak_as_needed_b.script: New version script.
* testsuite/weak_as_needed_c.c: New source file.
* testsuite/weak_as_needed_c.script: New version script.
Shuffle code in `_bfd_mips_post_process_headers' so that the setting of
the EI_ABIVERSION ELF file header field is complete before calling
`_bfd_elf_post_process_headers'. This used to be the case, but was
changed with commit 351cdf24d223 ("[MIPS] Implement O32 FPXX, FP64 and
FP64A ABI extensions") for no reason.
MIPS/BFD: Use enumeration constants for EI_ABIVERSION
Define enumeration constants based on generated `libc-abis.h' from GNU
libc, adding a MIPS_ prefix as these are port-specific. Use them to
replace magic numbers stored in the EI_ABIVERSION field of the ELF file
header.
bfd/
* elfxx-mips.c (MIPS_LIBC_ABI_DEFAULT, MIPS_LIBC_ABI_MIPS_PLT)
(MIPS_LIBC_ABI_UNIQUE, MIPS_LIBC_ABI_MIPS_O32_FP64)
(MIPS_LIBC_ABI_MAX): New enumeration constants.
(_bfd_mips_post_process_headers): Use them in place of magic
numbers.