deliverable/binutils-gdb.git
4 years agoPR25645, readelf segfault reading fuzzed alpha-vms binary
Alan Modra [Mon, 9 Mar 2020 10:56:05 +0000 (21:26 +1030)] 
PR25645, readelf segfault reading fuzzed alpha-vms binary

PR 25645
* readelf.c (dump_ia64_vms_dynamic_fixups): Pass size and nmemb
to get_data rather than multiplying.
(dump_ia64_vms_dynamic_relocs): Likewise.
(process_version_sections): Correct order of size and nmemb args
in get_data call.
(process_mips_specific): Likewise.

4 years agox86: use template for AVX512 integer comparison insns
Jan Beulich [Mon, 9 Mar 2020 09:14:55 +0000 (10:14 +0100)] 
x86: use template for AVX512 integer comparison insns

These all follow a common pattern.

4 years agox86: use template for XOP integer comparison, shift, and rotate insns
Jan Beulich [Mon, 9 Mar 2020 09:14:17 +0000 (10:14 +0100)] 
x86: use template for XOP integer comparison, shift, and rotate insns

These all follow common patterns.

4 years agox86: use template for AVX/AVX512 floating point comparison insns
Jan Beulich [Mon, 9 Mar 2020 09:13:43 +0000 (10:13 +0100)] 
x86: use template for AVX/AVX512 floating point comparison insns

These all follow an almost common pattern, again with the exception of
being commutative, which can be easily taken care of.

Note that, as an intended side effect (and in fact one of the reason to
introduce templates), AVX long-form pseudo-ops get introduced alongside
the already existing AVX512 ones.

4 years agox86: use template for SSE floating point comparison insns
Jan Beulich [Mon, 9 Mar 2020 09:13:04 +0000 (10:13 +0100)] 
x86: use template for SSE floating point comparison insns

These all follow an almost common pattern, with the exception of being
commutative. This exception can be easily taken care of.

4 years agox86: allow opcode templates to be templated
Jan Beulich [Mon, 9 Mar 2020 09:12:14 +0000 (10:12 +0100)] 
x86: allow opcode templates to be templated

In order to reduce redundancy as well as the chance of things going out
of sync (see a later patch for an example), make the opcode table
generator capable of recognizing and expanding templated templates. Use
the new capability for compacting the general purpose conditional insns.

4 years agoreadelf.c: Fix a typo in comments
H.J. Lu [Mon, 9 Mar 2020 01:43:42 +0000 (18:43 -0700)] 
readelf.c: Fix a typo in comments

* readelf.c (get_dynamic_data): Replace "memory chekers" with
"memory checkers" in comments.

4 years agoasan: wasm: Out-of-memory
Alan Modra [Sun, 8 Mar 2020 23:03:49 +0000 (09:33 +1030)] 
asan: wasm: Out-of-memory

* wasm-module.c (wasm_scan): Sanity check file name length
before allocating memory.  Move common section setup code.  Do
without bfd_tell to calculate section size.

4 years agoFix two typos in gdb_binary_search.h
Tom Tromey [Sun, 8 Mar 2020 17:05:43 +0000 (11:05 -0600)] 
Fix two typos in gdb_binary_search.h

I noticed a couple of typos in gdb_binary_search.h.  This fixes them.

gdbsupport/ChangeLog
2020-03-08  Tom Tromey  <tom@tromey.com>

* gdb_binary_search.h: Fix two typos.

4 years ago[gdb/testsuite] Fix testing build_executable result
Tom de Vries [Sat, 7 Mar 2020 21:46:07 +0000 (22:46 +0100)] 
[gdb/testsuite] Fix testing build_executable result

When running with target board unix/-feliminate-dwarf2-dups, we run into these
FAILs:
...
FAIL: gdb.cp/rvalue-ref-params.exp: print value of f1 on Child&& in f2
FAIL: gdb.cp/ref-params.exp: print value of f1 on Child in main
FAIL: gdb.cp/ref-params.exp: print value of f2 on Child in main
FAIL: gdb.cp/ref-params.exp: print value of f1 on Child& in f2
FAIL: gdb.cp/ref-params.exp: print mf1(MQ)
FAIL: gdb.cp/ref-params.exp: print mf2(MQ)
FAIL: gdb.cp/ref-params.exp: print f1(MQR)
FAIL: gdb.cp/ref-params.exp: print mf1(MQR)
FAIL: gdb.cp/ref-params.exp: print mf2(MQR)
...

This is due to comparing the result of build_executable to 1, while
build_executable returns either 0 for success, or -1 for failure.

Fix this by comparing with -1 instead.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-07  Tom de Vries  <tdevries@suse.de>

* gdb.cp/ref-params.exp: Compare build_executable result with -1.
* gdb.cp/rvalue-ref-params.exp: Same.

4 years ago[gdb] Support anonymous typedef generated by gcc -feliminate-dwarf2-dups
Tom de Vries [Sat, 7 Mar 2020 15:33:45 +0000 (16:33 +0100)] 
[gdb] Support anonymous typedef generated by gcc -feliminate-dwarf2-dups

Gcc supports an option -feliminate-dwarf2-dups (up until gcc-7, removed in
gcc-8).

When running tests with target board unix/-feliminate-dwarf2-dups, we run
into:
...
(gdb) PASS: gdb.ada/arraydim.exp: print m'length(3)
ptype global_3dim_for_gdb_testing^M
type = array (Unexpected type in ada_discrete_type_low_bound.^M
(gdb) FAIL: gdb.ada/arraydim.exp: ptype global_3dim_for_gdb_testing
...

The DWARF for the variable global_3dim_for_gdb_testing looks as follows:
...
 <0><824>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <825>   DW_AT_name        : src/gdb/testsuite/gdb.ada/arraydim/inc.c
 <1><832>: Abbrev Number: 2 (DW_TAG_array_type)
    <833>   DW_AT_type        : <0x874>
 <2><837>: Abbrev Number: 3 (DW_TAG_subrange_type)
    <838>   DW_AT_type        : <0x84a>
    <83c>   DW_AT_upper_bound : 0
 <2><83d>: Abbrev Number: 3 (DW_TAG_subrange_type)
    <83e>   DW_AT_type        : <0x84a>
    <842>   DW_AT_upper_bound : 1
 <2><843>: Abbrev Number: 3 (DW_TAG_subrange_type)
    <844>   DW_AT_type        : <0x84a>
    <848>   DW_AT_upper_bound : 2
 <2><849>: Abbrev Number: 0
 <1><84a>: Abbrev Number: 4 (DW_TAG_typedef)
    <84b>   DW_AT_type        : <0x86d>
 <1><84f>: Abbrev Number: 0
 <0><85b>: Abbrev Number: 5 (DW_TAG_compile_unit)
    <861>   DW_AT_name        : src/gdb/testsuite/gdb.ada/arraydim/inc.c
 <1><86d>: Abbrev Number: 6 (DW_TAG_base_type)
    <86e>   DW_AT_byte_size   : 8
    <86f>   DW_AT_encoding    : 7       (unsigned)
    <870>   DW_AT_name        : long unsigned int
 <1><874>: Abbrev Number: 7 (DW_TAG_base_type)
    <875>   DW_AT_byte_size   : 4
    <876>   DW_AT_encoding    : 5       (signed)
    <877>   DW_AT_name        : int
 <1><87b>: Abbrev Number: 8 (DW_TAG_variable)
    <87c>   DW_AT_name        : global_3dim_for_gdb_testing
    <882>   DW_AT_type        : <0x832>
    <886>   DW_AT_external    : 1
...

The DWARF contains an anonymous typedef at 0x84a, referring to 0x86d.
Strictly speaking, the anonymous typedef is illegal DWARF, because a
DW_TAG_typedef is defined to have an DW_AT_name attribute containing the name
of the typedef as it appears in the source program.

The DWARF reading code creates a corresponding type for this typedef, which
goes on to confuse the code handling arrays.

Rather than trying to support the type representing this anonymous typedef in
all the locations where it causes problems, fix this by treating the anonymous
typedef as a forwarder DIE in the DWARF reader.

Tested on x86_64-linux, with target boards unix and
unix/-feliminate-dwarf2-dups.

This fixes ~85 failures for unix/-feliminate-dwarf2-dups.

gdb/ChangeLog:

2020-03-07  Tom de Vries  <tdevries@suse.de>

* dwarf2/read.c (read_typedef): Treat anonymous typedef as forwarder
DIE.

4 years agoRemove some obsolete comments
Tom Tromey [Sat, 7 Mar 2020 14:53:42 +0000 (07:53 -0700)] 
Remove some obsolete comments

While working on complex number support, I found a couple of
apparently obsolete coments.  This removes them.

2020-03-07  Tom Tromey  <tom@tromey.com>

* valops.c (value_literal_complex): Remove obsolete comment.
* gdbtypes.h (enum type_code) <TYPE_CODE_FLT>: Remove obsolete
comment.

4 years agoRe: Add support for a ".file 0" directive if supporting DWARF 5 or higher.
Alan Modra [Sat, 7 Mar 2020 09:39:57 +0000 (20:09 +1030)] 
Re: Add support for a ".file 0" directive if supporting DWARF 5 or higher.

Fixes a fail on hppa64-hp-hpux, where anything in the first column is
a label.

* testsuite/gas/elf/dwarf-5-file0.s: Don't start directives in
first column.

4 years agobinutils: doc: move artifacts back to MAINTAINERCLEANFILES
Simon Marchi [Sat, 7 Mar 2020 03:06:34 +0000 (22:06 -0500)] 
binutils: doc: move artifacts back to MAINTAINERCLEANFILES

In commit 2b44a6a237 (" binutils: doc: make `make clean` clean more
things"), I moved the doc build artifacts to MOSTLYCLEANFILES, which
made them get removed by "make clean".

Because generating binutils.info requires makeinfo, and we do not want
to require makeinfo when building from the tarball, binutils.info should
not get removed by "make clean" (otherwise, it won't be included in the
tarball).

And to be consistent with other projects (e.g. ld and gas), we also want
to ship the built man pages in the tarball.

This patch puts back all these in MAINTAINERCLEANFILES, so that they are
bundled in the tarball, and only cleaned if you use "make
maintainer-clean".

Tested by building a source release and confirming they are present.

binutils/ChangeLog:

PR 25491
* doc/Makefile.am: Rename MOSTLYCLEANFILES to MAINTAINERCLEANFILES.
* doc/Makefile.in: Re-generate.

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 7 Mar 2020 00:00:44 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoPass thread_info pointer to various inferior control functions
Simon Marchi [Fri, 6 Mar 2020 23:04:52 +0000 (18:04 -0500)] 
Pass thread_info pointer to various inferior control functions

[ Migrating this from Gerrit: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/321 ]

I noticed that some functions in infcmd and infrun call each other and
all call inferior_thread, while they could just get the thread_info
pointer from their caller.  That means less calls to inferior_thread, so
less reliance on global state, since inferior_thread reads
inferior_ptid.

The paths I am unsure about are:

  - fetch_inferior_event calls...
  - step_command_fsm::should_stop calls...
  - prepare_one_step

and

 - process_event_stop_test calls...
 - set_step_info

Before this patch, prepare_one_step gets the thread pointer using
inferior_thread.  After this patch, it gets it from the
execution_control_state structure in fetch_inferior_event.  Are we sure
that the thread from the execution_control_state structure is the same
as the one inferior_thread would return?  This code path is used when a
thread completes a step, but the user had specified a step count (e.g.
"step 5") so we decide to do one more step.  It would be strange (and
even a bug I suppose) if the thread in the ecs structure in
fetch_inferior_event was not the same thread that is prepared to stepped
by prepare_one_step.  So I believe passing the ecs thread is fine.

The same logic applies to process_event_stop_test calling
set_step_info.

gdb/ChangeLog:

* infrun.h: Forward-declare thread_info.
(set_step_info): Add thread_info parameter, add doc.
* infrun.c (set_step_info): Add thread_info parameter, move doc
to header.
* infrun.c (process_event_stop_test): Pass thread to
set_step_info call.
* infcmd.c (set_step_frame): Add thread_info pointer, pass it to
set_step_info.
(prepare_one_step): Add thread_info parameter, pass it to
set_step_frame and prepare_one_step (recursive) call.
(step_1): Pass thread to prepare_one_step call.
(step_command_fsm::should_stop): Pass thread to
prepare_one_step.
(until_next_fsm): Pass thread to set_step_frame call.
(finish_command): Pass thread to set_step_info call.

4 years agoDon't try to get the TIB address without an inferior
Hannes Domani [Wed, 4 Mar 2020 20:20:31 +0000 (21:20 +0100)] 
Don't try to get the TIB address without an inferior

The target_get_tib_address call always fails in this case, and there is an
error when changing the program with the file command:

(gdb) file allocer64.exe
Reading symbols from allocer64.exe...
You can't do that when your target is `exec'

Now it will skip this part, there is no need to rebase the executable without
an inferior anyways.

gdb/ChangeLog:

2020-03-06  Hannes Domani  <ssbssa@yahoo.de>

* windows-tdep.c (windows_solib_create_inferior_hook):
Check if inferior is running.

4 years agoAdd support for a ".file 0" directive if supporting DWARF 5 or higher.
Nick Clifton [Fri, 6 Mar 2020 17:13:22 +0000 (17:13 +0000)] 
Add support for a ".file 0" directive if supporting DWARF 5 or higher.

PR 25614
* dwarf2dbg.c (dwarf2_directive_filename): Allow a file number of
0 if the dwarf_level is 5 or more.  Complain if a filename follows
a file 0.
* testsuite/gas/elf/dwarf-5-file0.s: New test.
* testsuite/gas/elf/dwarf-5-file0.d: New test driver.
* testsuite/gas/elf/elf.exp: Run the new test.

PR 25612
* config/tc-ia64.h (DWARF2_VERISION): Fix typo.
* doc/as.texi: Fix another typo.

4 years ago[gdb/testsuite] Fix "text file busy" errors with cc-with-tweaks.exp
Tom de Vries [Fri, 6 Mar 2020 17:03:01 +0000 (18:03 +0100)] 
[gdb/testsuite] Fix "text file busy" errors with cc-with-tweaks.exp

When using target board cc-with-gdb-index.exp and running tests in parallel,
we run into:
...
gdb compile failed, gdb/contrib/gdb-add-index.sh: line 86: \
  build/gdb/testsuite/gdb.sh: Text file busy
...

The problem is that because of the parallel test run, gdb.sh is created for
every single test-case, and eventually gdb.sh is overwritten while being
executed.

Fix this by creating gdb.sh only once.

Tested on x86_64-linux with target board cc-with-gdb-index.exp, using both a
serial and parallel -j 5 test run.

gdb/testsuite/ChangeLog:

2020-03-06  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (tentative_rename, cached_file): New proc.
* boards/cc-with-tweaks.exp: Use cached_file to create gdb.sh.

4 years agoAdd support for --dwarf-[3|4|5] to assembler command line.
Nick Clifton [Fri, 6 Mar 2020 14:52:14 +0000 (14:52 +0000)] 
Add support for --dwarf-[3|4|5] to assembler command line.

PR 25612
* as.c (dwarf_level): Define.
(show_usage): Add --gdwarf-3, --gdwarf-4 and --gdwarf-5.
(parse_args): Add support for the new options.
as.h (dwarf_level): Prototype.
* dwarf2dbg.c (DWARF2_VERSION): Use dwarf_level as default version
value.
* config/tc-ia64.h (DWARF2_VERISION): Update definition.
(DWARF2_LINE_VERSION): Remove definition.
* doc/as.texi: Document the new options.

4 years ago[gdb,testsuite,doc,NEWS] Fix "the the".
Tom de Vries [Fri, 6 Mar 2020 14:22:23 +0000 (15:22 +0100)] 
[gdb,testsuite,doc,NEWS] Fix "the the".

Replace "the the" by "the".

gdb/ChangeLog:

2020-03-06  Tom de Vries  <tdevries@suse.de>

* NEWS: Fix "the the".
* ctfread.c: Same.

gdb/doc/ChangeLog:

2020-03-06  Tom de Vries  <tdevries@suse.de>

* gdb.texinfo: Fix "the the".

gdb/testsuite/ChangeLog:

2020-03-06  Tom de Vries  <tdevries@suse.de>

* README: Fix "the the".
* gdb.base/dprintf.exp: Same.

4 years ago[gdb] Remove trailing "done" after "Reading symbols from" message
Tom de Vries [Fri, 6 Mar 2020 11:51:59 +0000 (12:51 +0100)] 
[gdb] Remove trailing "done" after "Reading symbols from" message

Using verbose, we get some detail on symbol loading:
...
$ gdb a.out -iex "set verbose on"
Reading symbols from a.out...
Reading in symbols for /home/vries/hello.c...done.
(gdb)
...

And using debug symtab-create, much more detail:
...
$ gdb a.out -iex "set verbose on" -iex "set debug symtab-create 1"
Reading symbols from a.out...
Reading minimal symbols of objfile /data/gdb_versions/devel/lto/a.out ...
Installing 30 minimal symbols of objfile /data/gdb_versions/devel/lto/a.out.
Done reading minimal symbols.
Creating one or more psymtabs for objfile /data/gdb_versions/devel/lto/a.out ...
Created psymtab 0x35a3de0 for module ../sysdeps/x86_64/start.S.
Created psymtab 0x353e4e0 for module init.c.
Created psymtab 0x353e560 for module ../sysdeps/x86_64/crti.S.
Created psymtab 0x353e5e0 for module /home/vries/hello.c.
Created psymtab 0x35bd530 for module elf-init.c.
Created psymtab 0x35bd5b0 for module ../sysdeps/x86_64/crtn.S.
Reading in symbols for /home/vries/hello.c...Created compunit symtab 0x354bd20 for hello.c.
done.
(gdb)
...

The "Created compunit symtab" message gets inbetween the "Reading in symbols"
and the trailing "done.". [ Strictly speaking this is a regression since
commit faa17681cc "Make gdb_flush also flush the wrap buffer", but the
same problem happens when using -batch before this commit. ]

Fix this by removing the trailing "done." altogether, such that we get:
...
Created psymtab 0x3590520 for module ../sysdeps/x86_64/crtn.S.
Reading in symbols for /home/vries/hello.c...
Created compunit symtab 0x359dd20 for hello.c.
(gdb)
...

[ Alternatively, we could fix this emitting a "Done reading in symbols" line
or some such, like is done for minimal symbols.  See above. ]

[ Note: Removing the trailing "done." for the "Reading symbols from" message
was done in commit 3453e7e409 'Clean up "Reading symbols" output'. ]

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-03-06  Tom de Vries  <tdevries@suse.de>

* psymtab.c (psymtab_to_symtab): Don't print "done.".

4 years agogdbserver/gdbsupport: Add .dir-locals.el file
Andrew Burgess [Fri, 28 Feb 2020 18:08:08 +0000 (18:08 +0000)] 
gdbserver/gdbsupport: Add .dir-locals.el file

Copy the .dir-locls.el file from gdb/ to gdbserver/ and gdbsupport/ so
that we get the GNU/GDB style when editing these files in Emacs.

I initially wanted to remove the (c-mode . ((mode . c++))) that
switches c-mode files into c++-mode as we store C++ code in *.cc files
in the gdbserver/ directory, unlike gdb/ where we use *.c, however, I
was forgetting about the header files - we still use *.h for our C++
header files, so for now I left the settings in place to open all C
files in c++-mode.

We now have three copies of this file, which are all identical.  It
would be nice if we could remove this duplication, however, for now we
haven't found a good way to do this.

Some options considered were:

  1. Use symlinks to only have one copy of the file.  This was
  rejected as not all targets support symlinks in the way.

  2. Have two of the .dir-locals.el files contain some mechanism by
  which the third copy of the file is sourced.  Though this would, in
  theory, be possible, it would involve some advanced Emacs scripting,
  would be fragile, and a maintenance burdon.

  3. Move the .dir-locals up into top level src/ directory, then use
  Emacs dir-locals directory pattern matching to only apply the rules
  for the three directories we care about.  The problem is that each
  directory has to be listed separately, so we still end up having to
  duplicate all the rules.

In the end, it was decided that having three copies of the file,
though not ideal, is probably easiest for now.  This was all discussed
in this mailing list thread:

  https://sourceware.org/ml/gdb-patches/2020-03/msg00024.html

The copyright date in the new files is left as for gdb/.dir-locals.el,
as the new files are a copy of the old, this is inline with this rule:

  https://sourceware.org/gdb/wiki/ContributionChecklist#Copyright_Header

gdb/ChangeLog:

* .dir-locals.el: Add a comment referencing the other copies of
this file.

gdbserver/ChangeLog:

* .dir-locals.el: New file.

gdbsupport/ChangeLog:

* .dir-locals.el: New file.

4 years agoStop the assembler from complaining that the input and output files are the same...
Nick Clifton [Fri, 6 Mar 2020 10:44:12 +0000 (10:44 +0000)] 
Stop the assembler from complaining that the input and output files are the same, if neither of them are regular files.

PR 25572
* as.c (main): Allow matching input and outputs when they are
not regular files.

4 years agoFix an abort triggered when objcopy is used to set the "share" section flag on an...
Nick Clifton [Fri, 6 Mar 2020 10:09:22 +0000 (10:09 +0000)] 
Fix an abort triggered when objcopy is used to set the "share" section flag on an ELF section.

binutils* objcopy.c (check_new_section_flags): New function.  Reject the
SEC_COFF_SHARED flag if the target is not a COFF binary.
(copy_object): Call check_new_section_flags.
(setup_section): Likewise.
* doc/binutils.texi (objcopy): Add a note that the 'share' section
flag cannot be applied to ELF binaries.

bfd * elf.c (_bfd_elf_set_section_contents): Replace call to abort
with error messages and failure return values.

4 years agox86: reduce amount of various VCVT* templates
Jan Beulich [Fri, 6 Mar 2020 07:56:47 +0000 (08:56 +0100)] 
x86: reduce amount of various VCVT* templates

Presumably as a result of various changes over the last several months,
and - for some of them - with a generalization of logic in
match_mem_size() plus mirroring of this generalization into the
broadcast handling logic of check_VecOperands(), various register-only
templates can be foled into their respective memory forms. This in
particular then also allows dropping a few more instances of IgnoreSize.

4 years agox86: drop/replace IgnoreSize
Jan Beulich [Fri, 6 Mar 2020 07:55:52 +0000 (08:55 +0100)] 
x86: drop/replace IgnoreSize

Even after commit dc2be329b950 ("i386: Only check suffix in instruction
mnemonic"), by which many of its uses have become unnecessary (some were
unnecessary even before), IgnoreSize is still used for various slightly
different purposes:
- to suppress emission of an operand size prefix,
- in Intel syntax mode to zap "derived" suffixes in certain cases and to
  skip certain checks of remaining "derived" suffixes,
- to suppress ambiguous operand size / missing suffix diagnostics,
- for prefixes to suppress the "stand-alone ... prefix" warning.
Drop entirely unnecessary ones and where possible also replace instances
by the more focused (because of having just a single purpose) NoRex64.

To further restrict when IgnoreSize is needed, also generalize the logic
when to skip a template because of a present or derived L or Q suffix,
by skipping immediate operands. Additionally consider mask registers and
VecSIB there.

Note that for the time being the attribute needs to be kept in place on
MMX/SSE/etc insns (but not on VEX/EVEX encoded ones unless an operand
template of them allows for only non-SIMD-register actuals) allowing for
Dword operands - the logic when to emit a data size prefix would need
further adjustment first.

Note also that the memory forms of {,v}pinsrw get their permission for
an L or Q suffix dropped. I can only assume that it being this way was a
cut-and-paste mistake from the register forms, as the latter
specifically have NoRex64 set, and the {,v}pextrw counterparts don't
allow these suffixes either.

Convert VexW= again to their respective VexW* on lines touched anyway.

4 years agox86: fold (supposed to be) identical code
Jan Beulich [Fri, 6 Mar 2020 07:55:03 +0000 (08:55 +0100)] 
x86: fold (supposed to be) identical code

The Q and L suffix exclusion checks in match_template() ought to be
(kept) in sync as far as their FPU and SIMD aspects go. This was
already violated by only the Q one checking for active broadcast.
Convert the code such that there'll be only one instance of the logic,
the more that subsequently the logic is liable to need further
refinement / extension. (The alternative would be to drop all SIMD-ness
from the L part, but it is in principle possible to enable all sorts of
SIMD support with just a pre-386 CPU, via suitable .arch directives.)

4 years agox86: don't accept FI{LD,STP,STTP}LL in Intel syntax mode
Jan Beulich [Fri, 6 Mar 2020 07:53:56 +0000 (08:53 +0100)] 
x86: don't accept FI{LD,STP,STTP}LL in Intel syntax mode

As of commit dc2be329b950 ("i386: Only check suffix in instruction
mnemonic") these have been accepted even with "qword ptr" operand size
specifier, but in 64-bit mode they're now wrongly having a REX prefix
(with REX.W set) emitted in this case. These aren't Intel syntax
mnemonics, so rather than fixing code generation, let's simply reject
them. As a result, the Qword attribute can then be dropped, too.

4 years agox86: replace NoRex64 on VEX-encoded insns
Jan Beulich [Fri, 6 Mar 2020 07:53:18 +0000 (08:53 +0100)] 
x86: replace NoRex64 on VEX-encoded insns

When the template specifies any of the possible VexW settings, we can
use this instead of a separate NoRex64 to suppress the setting of REX_W.
Note that this ends up addressing an inconsistency between VEX- and
EVEX-encoded VEXTRACTPS, VPEXTR{B,W}, and VPINSR{B,W} - while the former
avoided setting VEX.W, the latter pointlessly set EVEX.W when there is a
64-bit GPR operand. Adjust the testcase to cover both cases.

Convert VexW= to their respective VexW* on lines touched anyway.

4 years agox86: drop Rex64 attribute
Jan Beulich [Fri, 6 Mar 2020 07:52:12 +0000 (08:52 +0100)] 
x86: drop Rex64 attribute

It is almost entirely redundant with Size64, and the sole case (CRC32)
where direct replacement isn't possible can easily be taken care of in
another way.

4 years agox86: correct MPX insn w/o base or index encoding in 16-bit mode
Jan Beulich [Fri, 6 Mar 2020 07:50:56 +0000 (08:50 +0100)] 
x86: correct MPX insn w/o base or index encoding in 16-bit mode

Since 16-bit addressing isn't allowed, Disp32 needs to be forced; Disp16
fails to match the templates.

The SDM leaves open whether BNDC[LNU] with a GPR operand require an
operand size override; this aspect is therefore left untouched here.

4 years agox86: add missing IgnoreSize
Jan Beulich [Fri, 6 Mar 2020 07:49:45 +0000 (08:49 +0100)] 
x86: add missing IgnoreSize

For proper code generation in 16-bit mode (or to avoid the "same type of
prefix used twice" diagnostic there), IgnoreSize is needed on certain
templates allowing for just 32-(and maybe 64-)bit operands.

Beyond adding tests for the previously broken cases, also add ones for
the previously working cases where IgnoreSize is needed for the same
reason (leaving out MPX for now, as that'll require an assembler change
first). Some minor adjustments to tests get done such that re-use of the
same code for 16-bit code generation testing becomes easier.

4 years agox86: refine TPAUSE and UMWAIT
Jan Beulich [Fri, 6 Mar 2020 07:48:48 +0000 (08:48 +0100)] 
x86: refine TPAUSE and UMWAIT

Allowing 64-bit registers is misleading here: Elsewhere these get allowed
when there's no difference between either variant, because of 32-bit
destination registers having their upper halves zeroed in 64-bit mode.
Here, however, they're source registers, and hence specifying 64-bit
registers would lead to the ambiguity of whether the upper 32 bits
actually matter.

Additionally, for proper code generation in 16-bit mode, IgnoreSize is
needed on both.

And finally, just like for e.g. MONITOR/MWAIT, add variants with all
input registers explicitly specified.

4 years agobfd: xtensa: fix PR ld/25630
Max Filippov [Wed, 4 Mar 2020 22:54:27 +0000 (14:54 -0800)] 
bfd: xtensa: fix PR ld/25630

bfd/
2020-03-05  Max Filippov  <jcmvbkbc@gmail.com>

* elf32-xtensa.c (shrink_dynamic_reloc_sections): Shrink dynamic
relocation sections for any removed reference to a dynamic symbol.

4 years agoPR25637, objcopy : SIGSEGV in copy_object
Alan Modra [Fri, 6 Mar 2020 00:03:10 +0000 (10:33 +1030)] 
PR25637, objcopy : SIGSEGV in copy_object

PR 25637
* objcopy.c (filter_symbols): Correct rem_leading_char logic.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 6 Mar 2020 00:00:49 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoUse std::string for 'psargs'.
John Baldwin [Thu, 5 Mar 2020 23:02:45 +0000 (15:02 -0800)] 
Use std::string for 'psargs'.

fbsd_make_corefile_notes leaked the memory for psargs previously.

gdb/ChangeLog:

* fbsd-tdep.c (fbsd_make_corefile_notes): Use std::string for
psargs.

4 years agogdbsupport/configure.ac: source development.sh
Vyacheslav Petrishchev [Wed, 26 Feb 2020 06:32:03 +0000 (12:32 +0600)] 
gdbsupport/configure.ac: source development.sh

[Commit message by Simon Marchi]

The GDB build in non-development mode (turn development to false in
bfd/development.sh if you want to try) is currently broken:

      CXXLD  gdb
    /home/smarchi/src/binutils-gdb/gdb/disasm-selftests.c:218: error: undefined reference to 'selftests::register_test_foreach_arch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(gdbarch*))'
    /home/smarchi/src/binutils-gdb/gdb/disasm-selftests.c:220: error: undefined reference to 'selftests::register_test_foreach_arch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(gdbarch*))'
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/frame.c:2310: error: undefined reference to 'selftests::register_test_foreach_arch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(gdbarch*))'
    /home/smarchi/src/binutils-gdb/gdb/gdbarch-selftests.c:168: error: undefined reference to 'selftests::register_test_foreach_arch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(gdbarch*))'
    /home/smarchi/src/binutils-gdb/gdbsupport/selftest.cc:96: error: undefined reference to 'selftests::reset()'

This is because the gdbsupport configure script doesn't source
bfd/development.sh to set the development variable.  When $development
is unset, GDB_AC_SELFTEST defaults to enabling selftests.  I don't think
the macro was written with this intention in mind, it just happens to be
that way.

So gdbsupport thinks selftests are enabled, while gdb thinks they are
disabled.  gdbsupport compiles in code that calls selftests:: functions,
which are normally provided by gdb, but gdb doesn't provide them, hence
the undefined references.

Fix this by sourcing bfd/development.sh in gdbsupport/configure.ac, so
that the development variable is set.

gdbsupport/ChangeLog:

        * configure.ac: Added call development.sh.
        * configure: Regenerate.

4 years agoAdd support for ELF files which contain multiple reloc sections which all target...
Nick Clifton [Thu, 5 Mar 2020 15:47:15 +0000 (15:47 +0000)] 
Add support for ELF files which contain multiple reloc sections which all target the same section.

* elf-bfd.h (struct elf_backend_data): Add new fields:
init_secondary_reloc_section, slurp_secondary_reloc_section,
write_secondary_reloc_section.
(_bfd_elf_init_secondary_reloc_section): Prototype.
(_bfd_elf_slurp_secondary_reloc_section): Prototype.
(_bfd_elf_write_secondary_reloc_section): Prototype.
* elf.c ( bfd_section_from_shdr): Invoke the new
init_secondary_reloc_section backend function, if defined, when a
second reloc section is encountered.
(swap_out_syms): Invoke the new symbol_section_index function, if
defined, when computing the section index of an OS/PROC specific
symbol.
(_bfd_elf_init_secondary_reloc_section): New function.
(_bfd_elf_slurp_secondary_reloc_section): New function.
(_bfd_elf_write_secondary_reloc_section): New function.
(_bfd_elf_copy_special_section_fields): New function.
* elfcode.h (elf_write_relocs): Invoke the new
write_secondary_relocs function, if defined, in order to emit
secondary relocs.
(elf_slurp_reloc_table): Invoke the new slurp_secondary_relocs
function, if defined, in order to read in secondary relocs.
* elfxx-target.h (elf_backend_copy_special_section_fields):
Provide a non-NULL default definition.
(elf_backend_init_secondary_reloc_section): Likewise.
(elf_backend_slurp_secondary_reloc_section): Likewise.
(elf_backend_write_secondary_reloc_section): Likewise.
(struct elf_backend_data elfNN_bed): Add initialisers for the new
fields.
        * configure.ac (score_elf32_[bl]e_vec): Add elf64.lo
        * configure: Regenerate.

4 years agogdb, gdbserver, gdbsupport: add .gitattributes files
Tankut Baris Aktemur [Thu, 5 Mar 2020 14:59:22 +0000 (15:59 +0100)] 
gdb, gdbserver, gdbsupport: add .gitattributes files

Create .gitattributes files in gdb/, gdbserver/, and gdbsupport/.

The files specify cpp-style diffs for .h and .c files.  This is
particularly helpful if a class in a header file is modified.
For instance, if the `stop_requested` field of `thread_info` in
gdb/gdbthread.h is modified, we get the following diff with
'git diff' (using git version 2.17.1):

   @@ -379,7 +379,7 @@ public:
      struct target_waitstatus pending_follow;

      /* True if this thread has been explicitly requested to stop.  */
   -  int stop_requested = 0;
   +  bool stop_requested = 0;

      /* The initiating frame of a nexting operation, used for deciding
         which exceptions to intercept.  If it is null_frame_id no

Note that the context of the change shows up as 'public:'; not so
useful.  With the .gitattributes file, we get:

   @@ -379,7 +379,7 @@ class thread_info : public refcounted_object
      struct target_waitstatus pending_follow;

      /* True if this thread has been explicitly requested to stop.  */
   -  int stop_requested = 0;
   +  bool stop_requested = 0;

      /* The initiating frame of a nexting operation, used for deciding
         which exceptions to intercept.  If it is null_frame_id no

The context is successfully shown as 'class thread_info'.

This patch creates a .gitattributes file per each of gdb, gdbserver,
and gdbsupport folders.  An alternative would be to define the
attributes in the root folder -- this would impact all the top-level
folders, though.  I opted for the more conservative approach.

gdb/ChangeLog:
2020-03-05  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* .gitattributes: New file.

gdbserver/ChangeLog:
2020-03-05  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* .gitattributes: New file.

gdbsupport/ChangeLog:
2020-03-05  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* .gitattributes: New file.

4 years agoReduce --warn-section-align output
Alan Modra [Thu, 5 Mar 2020 11:04:23 +0000 (21:34 +1030)] 
Reduce --warn-section-align output

PR 25570
* ldlang.c (lang_size_sections_1): Don't report changes on
second and subsequent iterations that make no change in
alignment from that already reported.

4 years ago[gdb/testsuite] Update maint.exp for string cache
Tom de Vries [Thu, 5 Mar 2020 09:08:31 +0000 (10:08 +0100)] 
[gdb/testsuite] Update maint.exp for string cache

When running gdb.base/maint.exp, I see:
...
FAIL: gdb.base/maint.exp: maint print statistics
...

This is due to commit be1e3d3eab "Introduce objfile::intern", which replaces
the macro and filename caches with a string cache.

Update maint.exp accordingly.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-05  Tom de Vries  <tdevries@suse.de>

* gdb.base/maint.exp: Update "main print statistics" expected output.

4 years agoPR25629, objcopy : SIGSEGV in filter_symbols
Alan Modra [Thu, 5 Mar 2020 04:27:47 +0000 (14:57 +1030)] 
PR25629, objcopy : SIGSEGV in filter_symbols

PR 25629
* objcopy.c (filter_symbols): Don't segfault on NULL
prefix_symbols_string.

4 years agoRISC-V: Support assembler modifier %got_pcrel_hi.
Nelson Chu [Wed, 4 Mar 2020 05:08:05 +0000 (21:08 -0800)] 
RISC-V: Support assembler modifier %got_pcrel_hi.

gas/
* config/tc-riscv.c: Support the modifier %got_pcrel_hi.
* doc/c-riscv.texi: Add documentation.
* testsuite/gas/riscv/no-relax-reloc.d: Add test case for the new
modifier %got_pcrel_hi.
* testsuite/gas/riscv/no-relax-reloc.s: Likewise.
* testsuite/gas/riscv/relax-reloc.d: Likewise.
* testsuite/gas/riscv/relax-reloc.s: Likewise.

4 years agoRISC-V: Add description for RISC-V Modifiers to as doc.
Nelson Chu [Wed, 4 Mar 2020 05:08:04 +0000 (21:08 -0800)] 
RISC-V: Add description for RISC-V Modifiers to as doc.

gas/
* doc/c-riscv.texi (relocation modifiers): Add documentation.
(RISC-V-Formats): Update the section name from "Instruction Formats"
to "RISC-V Instruction Formats".

4 years agoLarge memory allocation reading fuzzed 64-bit archive
Alan Modra [Wed, 4 Mar 2020 23:12:41 +0000 (09:42 +1030)] 
Large memory allocation reading fuzzed 64-bit archive

This patch adds a sanity check for the size of an armap.

* archive64.c (_bfd_archive_64_bit_slurp_armap): Check parsed_size
against file size before allocating memory.  Use bfd_alloc rather
than bfd_zalloc for carsym/strings memory.

4 years agoAutomatic date update in version.in
GDB Administrator [Thu, 5 Mar 2020 00:00:26 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoIntroduce objfile::intern
Tom Tromey [Wed, 4 Mar 2020 23:34:49 +0000 (16:34 -0700)] 
Introduce objfile::intern

This introduces a string cache on the per-BFD object, replacing the
macro and filename caches.  Both of these caches just store strings,
so this consolidation by itself saves a little memory (about the size
of a bcache per objfile).

Then this patch switches some allocations on the objfile obstack to
use this bcache instead.  This saves more space; and turns out to be a
bit faster as well.

Here are the before and after "maint time" + "maint space" results of
"file ./gdb":

    Command execution time: 4.664021 (cpu), 4.728518 (wall)
    Space used: 39190528 (+29212672 for this command)

    Command execution time: 4.216209 (cpu), 4.107023 (wall)
    Space used: 36667392 (+26689536 for this command)

The main interface to the string cache is a new pair of overloaded
methods, objfile::intern.

gdb/ChangeLog
2020-03-04  Tom Tromey  <tom@tromey.com>

* symmisc.c (print_symbol_bcache_statistics)
(print_objfile_statistics): Update.
* symfile.c (allocate_symtab): Use intern.
* psymtab.c (partial_symtab::partial_symtab): Use intern.
* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
macro_cache>: Remove.
<string_cache>: New member.
(struct objfile) <intern>: New methods.
* elfread.c (elf_symtab_read): Use intern.
* dwarf2/read.c (fixup_go_packaging): Intern package name.
(dwarf2_compute_name, dwarf2_physname)
(create_dwo_unit_in_dwp_v1, create_dwo_unit_in_dwp_v2): Intern
names.
(guess_partial_die_structure_name): Update.
(partial_die_info::fixup): Intern name.
(dwarf2_canonicalize_name): Change parameter to objfile.  Intern
name.
(dwarf2_name): Intern name.  Update.
* buildsym.c (buildsym_compunit::get_macro_table): Use
string_cache.

4 years agoMake "gnutarget" const
Tom Tromey [Wed, 4 Mar 2020 23:24:08 +0000 (16:24 -0700)] 
Make "gnutarget" const

I noticed that gnutarget was not "const".  Since writing through this
pointer would probably be a bug, I think it ought to be.  This patch
makes the change.

gdb/ChangeLog
2020-03-04  Tom Tromey  <tom@tromey.com>

* jit.c (bfd_open_from_target_memory): Make "target" const.
* corefile.c (gnutarget): Now const.
* gdbcore.h (gnutarget): Now const.

4 years agoPR25570, ld duplicate "warning: changing start of section"
Alan Modra [Wed, 4 Mar 2020 10:44:19 +0000 (21:14 +1030)] 
PR25570, ld duplicate "warning: changing start of section"

Note that because we should report a signed delta from the previous
VMA it isn't possible to use ngettext.  ngettext only supports
unsigned long values.  So byte/bytes goes from the message.

PR 25570
* ldlang.c (lang_sizing_iteration): New static var.
(lang_size_sections_1): Warn about no memory region only on first
iteration.  Warn about changing start address on first iteration
then any delta from that on subsequent iterations.  Report a signed
delta.
(one_lang_size_sections_pass): Increment lang_sizing_iteration.

4 years agoImplement debugging of WOW64 processes
Hannes Domani [Sun, 26 Jan 2020 21:04:04 +0000 (22:04 +0100)] 
Implement debugging of WOW64 processes

For WOW64 processes, the Wow64* variants of SuspendThread,
GetThreadContext, SetThreadContext, and GetThreadSelectorEntry have to
be used instead.
And instead of EnumProcessModules, EnumProcessModulesEx with
LIST_MODULES_32BIT is necessary.

gdb/ChangeLog:

2020-03-04  Hannes Domani  <ssbssa@yahoo.de>

* NEWS: Mention support for WOW64 processes.
* amd64-windows-nat.c (amd64_mappings): Rename and remove static.
(amd64_windows_segment_register_p): Remove static.
(_initialize_amd64_windows_nat): Update.
* configure.nat <windows> (NATDEPFILES): Add i386-windows-nat.o.
* i386-windows-nat.c (context_offset): Update.
(i386_mappings): Rename and remove static.
(i386_windows_segment_register_p): Remove static.
(_initialize_i386_windows_nat): Update.
* windows-nat.c (STATUS_WX86_BREAKPOINT): New macro.
(STATUS_WX86_SINGLE_STEP): New macro.
(EnumProcessModulesEx): New macro.
(Wow64SuspendThread): New macro.
(Wow64GetThreadContext): New macro.
(Wow64SetThreadContext): New macro.
(Wow64GetThreadSelectorEntry): New macro.
(windows_set_context_register_offsets): Add static.
(windows_set_segment_register_p): Likewise.
(windows_add_thread): Adapt for WOW64 processes.
(windows_fetch_one_register): Likewise.
(windows_nat_target::fetch_registers): Likewise.
(windows_store_one_register): Likewise.
(display_selector): Likewise.
(display_selectors): Likewise.
(handle_exception): Likewise.
(windows_continue): Likewise.
(windows_nat_target::resume): Likewise.
(windows_add_all_dlls): Likewise.
(do_initial_windows_stuff): Likewise.
(windows_nat_target::attach): Likewise.
(windows_get_exec_module_filename): Likewise.
(windows_nat_target::create_inferior): Likewise.
(windows_xfer_siginfo): Likewise.
(_initialize_loadable): Initialize Wow64SuspendThread,
Wow64GetThreadContext, Wow64SetThreadContext,
Wow64GetThreadSelectorEntry and EnumProcessModulesEx.
* windows-nat.h (windows_set_context_register_offsets):
Remove declaration.
(windows_set_segment_register_p): Likewise.
(i386_windows_segment_register_p): Add declaration.
(amd64_windows_segment_register_p): Likewise.

4 years agoGenerate a warning in the ARM assembler if a PC-relative thumb load instruction is...
Alexandre Oliva [Wed, 4 Mar 2020 17:28:46 +0000 (17:28 +0000)] 
Generate a warning in the ARM assembler if a PC-relative thumb load instruction is detected in a section with insufficient alignment.

* config/tc-arm.c (md_apply_fix): Warn if a PC-relative load is
detected in a section which does not have at least 4 byte
alignment.
* testsuite/gas/arm/armv8-ar-it-bad.s: Add alignment directive.
* testsuite/gas/arm/ldr-t.s: Likewise.
* testsuite/gas/arm/sp-pc-usage-t.s: Likewise.
* testsuite/gas/arm/sp-pc-usage-t.d: Finish test at end of
disassembly, ignoring any NOPs that may have been inserted because
of section alignment.
* testsuite/gas/arm/ldr-t.d: Likewise.

4 years agoRevert "gdb: Do not print empty-group regs when printing general ones"
Luis Machado [Wed, 4 Mar 2020 16:08:13 +0000 (13:08 -0300)] 
Revert "gdb: Do not print empty-group regs when printing general ones"

Revert the change since it breaks existing behavior of "info registers"
for some architectures. At least AArch64 and ARM are impacted by this change.

gdb/ChangeLog:

2020-03-04  Luis Machado  <luis.machado@linaro.org>

Revert aa66aac47b4dd38f9524ddb5546c08cc09930d37 due to regressions
in "info registers" for AArch64/ARM.

The change caused "info registers" to not print GPR's.

gdb/ChangeLog:

2020-02-01  Shahab Vahedi  <shahab@synopsys.com>

* target-descriptions.c (tdesc_register_in_reggroup_p): Return 0
when reg->group is empty and reggroup is not.

4 years ago[gdb/doc] Remove trailing done from "Reading symbols from" lines
Tom de Vries [Wed, 4 Mar 2020 15:27:56 +0000 (16:27 +0100)] 
[gdb/doc] Remove trailing done from "Reading symbols from" lines

Since commit 3453e7e409 'Clean up "Reading symbols" output' we no longer print
"done." after the "Reading symbols from" message:
...
$ gdb -q a.out
Reading symbols from a.out...
(gdb)
...

Update docs accordingly.

Build on x86_64-linux.

gdb/doc/ChangeLog:

2020-03-04  Tom de Vries  <tdevries@suse.de>

* gdb.texinfo: Remove trailing "done." in "Reading symbols from" lines.
* python.texi: Same.

4 years agogdb.fortran: Allow Flang kind printing in fortran testing
Alok Kumar Sharma [Wed, 4 Mar 2020 11:46:52 +0000 (17:16 +0530)] 
gdb.fortran: Allow Flang kind printing in fortran testing

In lib/fortran.exp, in the helper function fortran_int4, kind
parameter is expected to be printed as (kind=4) for the LLVM
Fortran compiler, Flang along with gfortran.  And in the helper
function fortran_int8 kind parameter is expected to be printed
as (kind=8).  But for the Flang compiler default kind is not
printed and non default kind is printed differently than gfortran
as below.
  integer(kind=4) => integer
  integer(kind=8) => integer*8
  real(kind=4) => real
  real(kind=8) => double precision
  complex(kind=4) => complex
  logical(kind=4) => logical
  character(kind=1) => character
This commit adds support for printing of kind parameter for the
Flang.  There should be no change when testing with gfortran.

Note: The current patch overrides earlier patch with below details.
  commit c3b149eb7697b376df1b3a47d0102afda389ee6d
  Author Alok Kumar Sharma (alokkumar.sharma@amd.com)
Earlier patch was incomplete and based on assumption that flang
should be changed to dump a type with kind like the way gfortan does.
Later it was realized that the way flang dumps this info is not
incorrect but different. And changes in gdb test framework are
finalized.

gdb/testsuite/ChangeLog:

* lib/fortran.exp (fortran_int4): Handle flang kind printing.
(fortran_int8): Likewise.
(fortran_real4): Likewise.
(fortran_real8): Likewise.
(fortran_complex4): Likewise.
(fortran_logical4): Likewise.
(fortran_character1): Likewise.

4 years agox86: support VMGEXIT
Jan Beulich [Wed, 4 Mar 2020 07:58:13 +0000 (08:58 +0100)] 
x86: support VMGEXIT

It has been publicly documented for quite some time, albeit not in the
"General-Purpose and System Instructions" volume:
https://www.amd.com/system/files/TechDocs/24593.pdf.

4 years agoRevert "PR25570, ld duplicate "warning: changing start of section""
Alan Modra [Wed, 4 Mar 2020 06:08:59 +0000 (16:38 +1030)] 
Revert "PR25570, ld duplicate "warning: changing start of section""

This reverts commit 91114f7583fac8fdf57c58a1f632839da62e43da.

4 years agoPR25570, ld duplicate "warning: changing start of section"
Alan Modra [Wed, 4 Mar 2020 05:03:26 +0000 (15:33 +1030)] 
PR25570, ld duplicate "warning: changing start of section"

PR 25570
* ldlang.c (lang_size_sections_1): Delay emitting non-fatal
errors/warnings until final pass.
* ldexp.c (fold_name): Likewise.

4 years agosh_addralign inconsistent with sh_addr
Alan Modra [Wed, 4 Mar 2020 04:56:00 +0000 (15:26 +1030)] 
sh_addralign inconsistent with sh_addr

The ELF gABI says in part of sh_addralign:  "The value of sh_addr must
be congruent to 0, modulo the value of sh_addralign."

* elf.c (elf_fake_sections): Ensure sh_addralign is such that
sh_addr mod sh_addalign is zero.

4 years agoCall cleanup on bfd_check_format_matches error exit
Alan Modra [Wed, 4 Mar 2020 00:57:29 +0000 (11:27 +1030)] 
Call cleanup on bfd_check_format_matches error exit

* format.c (bfd_check_format_matches): Call cleanup on error exit.

4 years agoobjcopy: Fix for pr19005 on machines with more than one octet per byte.
Christian Eggers [Mon, 2 Mar 2020 21:08:20 +0000 (22:08 +0100)] 
objcopy: Fix for pr19005 on machines with more than one octet per byte.

On machines with more than one octet per byte, objcopy fills only a part
of the gap between sections.

* objcopy.c (copy_object): Convert from bytes to octets for
--gap-fill and --pad-to.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 4 Mar 2020 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoFind tailcall frames before inline frames
Tom Tromey [Tue, 3 Mar 2020 22:27:04 +0000 (15:27 -0700)] 
Find tailcall frames before inline frames

A customer reported a failure to unwind in a certain core dump.  A
lengthy investigation showed that the problem came from the
interaction between the tailcall and inline frame sniffers.

Normally, the regular DWARF unwinder may discover a chain of tail
calls ending in the current frame.  In this case, it sets a member on
the dwarf2_frame_cache object, so that a subsequent call into the
tailcall sniffer will create the tailcall frames.

However, in this scenario, what happened is that the DWARF unwinder
did find tailcall frames -- but then the PC of the first such frame
was recognized and claimed by the inline frame sniffer.

This then caused unwinding to go astray further up the stack.

This patch fixes the problem by arranging for the tailcall sniffer to
be called before the inline sniffer.  This way, if a DWARF frame has
tailcall information, the tailcalls will always be processed first.
This is safe to do, because the tailcall sniffer can only claim a
frame if the previous frame did in fact find this information.  (So,
for example, if no DWARF frame is ever found, then this sniffer will
never trigger.)

This patch also partially reverts:

    commit 1ec56e88aa9b052ab10b806d82fbdbc8d153d977
    Author: Pedro Alves <palves@redhat.com>
    Date:   Fri Nov 22 13:17:46 2013 +0000

Eliminate dwarf2_frame_cache recursion, don't unwind from the dwarf2 sniffer (move dwarf2_tailcall_sniffer_first elsewhere).

That patch moved the call to dwarf2_tailcall_sniffer_first out of
dwarf2_frame_cache, and into dwarf2_frame_prev_register.  However, in
this situation, this is too late -- by the time
dwarf2_frame_prev_register is called, the frame in question is already
recognized by the inline frame sniffer.

Rather than fully revert that patch, though, this just arranges to
call dwarf2_tailcall_sniffer_first from dwarf2_frame_cache -- which is
called shortly after the DWARF frame sniffer succeeds, via
compute_frame_id.

I don't know how to write a test case for this.

gdb/ChangeLog
2020-03-03  Tom Tromey  <tromey@adacore.com>

* dwarf2/frame.c (struct dwarf2_frame_cache)
<checked_tailcall_bottom, entry_cfa_sp_offset,
entry_cfa_sp_offset_p>: Remove members.
(dwarf2_frame_cache): Call dwarf2_tailcall_sniffer_first.
(dwarf2_frame_prev_register): Don't call
dwarf2_tailcall_sniffer_first.
(dwarf2_append_unwinders): Don't append tailcall unwinder.
* frame-unwind.c (add_unwinder): New fuction.
(frame_unwind_init): Use it.  Add tailcall unwinder.

4 years agogdbsupport: re-generate Makefile.in
Simon Marchi [Tue, 3 Mar 2020 22:11:12 +0000 (17:11 -0500)] 
gdbsupport: re-generate Makefile.in

It looks like after doing last minute changes to Makefile.am in commit
06b3c5bdb ("gdbsupport: rename source files to .cc"), I forgot to
re-generate Makefile.in.  This patch fixes it.

gdbsupport/ChangeLog:

* Makefile.in: Re-generate.

4 years agox86: Replace IgnoreSize/DefaultSize with MnemonicSize
H.J. Lu [Tue, 3 Mar 2020 19:24:16 +0000 (11:24 -0800)] 
x86: Replace IgnoreSize/DefaultSize with MnemonicSize

Since an instruction template can't have both IgnoreSize and DefaultSize,
this patch replaces IgnoreSize and DefaultSize with MnemonicSize.

gas/

* config/tc-i386.c (match_template): Replace ignoresize and
defaultsize with mnemonicsize.
(process_suffix): Likewise.

opcodes/

* i386-gen.c (opcode_modifiers): Replace IgnoreSize/DefaultSize
with MnemonicSize.
* i386-opc.h (IGNORESIZE): New.
(DEFAULTSIZE): Likewise.
(IgnoreSize): Removed.
(DefaultSize): Likewise.
(MnemonicSize): New.
(i386_opcode_modifier): Replace ignoresize/defaultsize with
mnemonicsize.
* i386-opc.tbl (IgnoreSize): New.
(DefaultSize): Likewise.
* i386-tbl.h: Regenerated.

4 years agogdb/fortran: Fix printing of logical true values for Flang
Andrew Burgess [Mon, 2 Mar 2020 18:08:49 +0000 (18:08 +0000)] 
gdb/fortran: Fix printing of logical true values for Flang

GDB is not able to print logical true values for Flang compiler.

Actual result:

  (gdb) p l
  $1 = 4294967295

Expected result:

  (gdb) p l
  $1 = .TRUE.

This is due to GDB expecting representation of true value being 1.
The Fortran standard doesnt specify how LOGICAL types are represented.
Different compilers use different non-zero values to represent logical
true. The gfortran compiler uses 1 to represent logical true and the
flang compiler uses -1. GDB should accept all the non-zero values as
true.

This is achieved by handling TYPE_CODE_BOOL in f_val_print and
printing any non-zero value as true.

gdb/ChangeLog:

* f-valprint.c (f_val_print): Handle TYPE_CODE_BOOL, any non-zero
value should be printed as true.

gdb/testsuite/ChangeLog:

* gdb.fortran/logical.exp: Add tests that any non-zero value is
printed as true.

4 years agoRebase executable to match relocated base address
Hannes Domani [Wed, 12 Feb 2020 16:53:32 +0000 (17:53 +0100)] 
Rebase executable to match relocated base address

Windows executables linked with -dynamicbase get a new base address
when loaded, which makes debugging impossible if the executable isn't
also rebased in gdb.

The new base address is read from the Process Environment Block.

gdb/ChangeLog:

2020-03-03  Hannes Domani  <ssbssa@yahoo.de>

* windows-tdep.c (windows_solib_create_inferior_hook): New function.
(windows_init_abi): Set and use windows_so_ops.

4 years agoThe patch fixed invalid compilation of instruction LD IY,(HL) and disassemble of...
Sergey Belyashov [Tue, 3 Mar 2020 16:31:42 +0000 (16:31 +0000)] 
The patch fixed invalid compilation of instruction LD IY,(HL) and disassemble of this and LD (HL),IX instruction. Also it update testsuit.

PR 25627
opcodes * z80-dis.c: Fix disassembly of LD IY,(HL) and D (HL),IX
instructions.

gas * config/tc-z80.c (emit_ld_rr_m): Fix invalid compilation of
instruction LD IY,(HL).
* testsuite/gas/z80/ez80_adl_all.d: Update expected disassembly.
* testsuite/gas/z80/ez80_adl_all.s: Add tests of the instruction.
* testsuite/gas/z80/ez80_z80_all.d: Update expected disassembly.
* testsuite/gas/z80/ez80_z80_all.s: Add tests of the instruction.

4 years agoFix printf of a convenience variable holding an inferior address
Sergio Durigan Junior [Sun, 1 Mar 2020 23:15:53 +0000 (18:15 -0500)] 
Fix printf of a convenience variable holding an inferior address

Back at:

commit 1f6f6e21fa86dc3411a6498608f32e9eb24b7851
Author: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Date:   Mon Jun 10 21:41:51 2019 +0200

    Ensure GDB printf command can print convenience var strings without a target.

GDB was extended in order to allow the printing of convenience
variables that are strings without a target.  However, this introduced
a regression that hasn't been caught by our testsuite (because there
were no tests for it).

The problem happens when we try to print a convenience variable that
holds the address of a string in the inferior.  The following
two-liners can reproduce the issue:

$ echo -e 'int main(){const char a[]="test";return 0;}' | gcc -x c - -O0-g3
$ ./gdb/gdb --data-directory ./gdb/data-directory -q ./a.out -ex 'start' -ex 'set $x = (const char *) (&a[0] + 2)' -ex 'printf "%s\n", $x'

After some investigation, I found that the problem happens on
printcmd.c:printf_c_string.  In the case above, we're taking the first
branch of the 'if' condition, which assumes that there will be a value
to be printed at "value_contents (value)".  There isn't.  We actually
need to obtain the address that the variable points to, and read the
contents from memory.

It seems to me that we should avoid this branch if the TYPE_CODE of
"value_type (value)" is TYPE_CODE_PTR (i.e., a pointer to the
inferior's memory).  This is what this patch does.

I took the liberty to extend the current testcase under
gdb.base/printcmds.exp and create a test that exercises this scenario.

No regressions have been found on Buildbot.

gdb/ChangeLog:
2020-03-03  Sergio Durigan Junior  <sergiodj@redhat.com>

* printcmd.c (print_c_string): Check also for TYPE_CODE_PTR
when verifying if dealing with a convenience variable.

gdb/testsuite/ChangeLog:
2020-03-03  Sergio Durigan Junior  <sergiodj@redhat.com>

* gdb.base/printcmds.exp: Add test to verify printf of a
variable holding an address.

4 years agoRemove a call to abort which can be triggered by running objdump on a corrupt input...
Nick Clifton [Tue, 3 Mar 2020 16:11:12 +0000 (16:11 +0000)] 
Remove a call to abort which can be triggered by running objdump on a corrupt input file.

PR 25625
* prdbg.c (pr_tag_type): Remove call to abort.

4 years agox86: Allow integer conversion without suffix in AT&T syntax
H.J. Lu [Tue, 3 Mar 2020 15:39:18 +0000 (07:39 -0800)] 
x86: Allow integer conversion without suffix in AT&T syntax

According to gas manual, suffix in instruction mnemonics isn't always
required:

When there is no sizing suffix and no (suitable) register operands to
deduce the size of memory operands, with a few exceptions and where long
operand size is possible in the first place, operand size will default
to long in 32- and 64-bit modes.

This includes cvtsi2sd, cvtsi2ss, vcvtsi2sd, vcvtsi2ss, vcvtusi2sd and
vcvtusi2ss.  Since they are used in GCC 8 and older GCC releases, they
must be allowed without suffix in AT&T syntax.

gas/

PR gas/25622
* testsuite/gas/i386/i386.exp: Run x86-64-default-suffix and
x86-64-default-suffix-avx.
* testsuite/gas/i386/noreg64.s: Remove cvtsi2sd, cvtsi2ss,
vcvtsi2sd, vcvtsi2ss, vcvtusi2sd and vcvtusi2ss entries.
* testsuite/gas/i386/noreg64.d: Updated.
* testsuite/gas/i386/noreg64.l: Likewise.
* testsuite/gas/i386/x86-64-default-suffix-avx.d: New file.
* testsuite/gas/i386/x86-64-default-suffix.d: Likewise.
* testsuite/gas/i386/x86-64-default-suffix.s: Likewise.

opcodes/

PR gas/25622
* i386-opc.tbl: Add IgnoreSize to cvtsi2sd, cvtsi2ss, vcvtsi2sd,
vcvtsi2ss, vcvtusi2sd and vcvtusi2ss for AT&T syntax.
* i386-tbl.h: Regenerated.

4 years agox86: Improve -malign-branch
Hongtao Liu [Tue, 3 Mar 2020 14:21:37 +0000 (06:21 -0800)] 
x86: Improve -malign-branch

According to intel SDM manual, not all compare flag-modifying instructions
are marcro-fusible with subsequent jcc instructions. For those non-fusible
instructions, -malign-branch doesn't need to align them, only jcc itself
needs to be aligned.

Here are 2 restrictions which separate macro-fusible instruction from not

Restriction 1:
If TEST/AND/CMP/ADD/SUB/INC/DEC is one of the following format:

   cmp m, imm
   add m, imm
   sub m, imm
   test m, imm
   and m, imm
   inc m
   dec m

it is unfusible with any jcc instruction.

Restriction 2:

/* Table 3-2. Macro-Fusible Instructions in Haswell Microarchitecture
   Note it also works for Skylake and Cascadelake.
---------------------------------------------------------------------
|   JCC   | ADD/SUB/CMP | INC/DEC | TEST/AND |
| ------  | ----------- | ------- | -------- |
|   Jo    |      N      |    N    |     Y    |
|   Jno   |      N      |    N    |     Y    |
|  Jc/Jb  |      Y      |    N    |     Y    |
| Jae/Jnb |      Y      |    N    |     Y    |
|  Je/Jz  |      Y      |    Y    |     Y    |
| Jne/Jnz |      Y      |    Y    |     Y    |
| Jna/Jbe |      Y      |    N    |     Y    |
| Ja/Jnbe |      Y      |    N    |     Y    |
|   Js    |      N      |    N    |     Y    |
|   Jns   |      N      |    N    |     Y    |
|  Jp/Jpe |      N      |    N    |     Y    |
| Jnp/Jpo |      N      |    N    |     Y    |
| Jl/Jnge |      Y      |    Y    |     Y    |
| Jge/Jnl |      Y      |    Y    |     Y    |
| Jle/Jng |      Y      |    Y    |     Y    |
| Jg/Jnle |      Y      |    Y    |     Y    |

Update maybe_fused_with_jcc_p to check if operands of CMP like instructions
can be fused with condition jump.

* gas/config/tc-i386.h (i386_tc_frag_data): Add member mf_type.
(TC_FRAG_INIT): Init mf_type.
* gas/config/tc-i386.c (enum mf_jcc_kind): New enum.
(enum mf_cmp_kind): Ditto.
(maybe_fused_with_jcc_p): Add argument mf_cmp_p to get
mf_type of corresponding instructons, exclude unfusible
instructions.
(add_fused_jcc_padding_frag_p): Likewise.
(add_branch_padding_frag_p): Likewise.
(output_insn): Record mf_type for corresponding instructions.
(i386_macro_fusible_p): New function.
(i386_next_fusible_jcc_frag): Rename from i386_next_jcc_frag,
add argument cmp_fragP to return next fusible jcc frag only.
(i386_classify_machine_dependant_frag): Seperate macro-fusible
instructions from condition jump.
* gas/testsuite/gas/i386/align-branch-9.s: New file.
* gas/testsuite/gas/i386/align-branch-9.d: Ditto.
* gas/testsuite/gas/i386/x86-64-align-branch-9.s: Ditto.
* gas/testsuite/gas/i386/x86-64-align-branch-9.d: Ditto.
* gas/testsuite/gas/i386/i386.exp: Run new tests.

4 years agoUpdate GDB to use new AUXV entry types
Luis Machado [Tue, 25 Feb 2020 00:04:05 +0000 (21:04 -0300)] 
Update GDB to use new AUXV entry types

I noticed GDB didn't know a particular AT tag (51) when doing some debugging.
Turns out we're missing a few entries compared to glibc's headers.

This patch adds them to GDB and fixes a failure in gdb.base/auxv.exp as
a result.

gdb/ChangeLog:

2020-03-03  Luis Machado  <luis.machado@linaro.org>

* auxv.c (default_print_auxv_entry): Add new AUXV entries.

4 years agoAdd missing AT tags to the ELF common header.
Luis Machado [Tue, 3 Mar 2020 13:13:53 +0000 (13:13 +0000)] 
Add missing AT tags to the ELF common header.

* elf/common.h (AT_L1I_CACHESIZE, AT_L1I_CACHEGEOMETRY)
(AT_L1D_CACHESIZE, AT_L1D_CACHEGEOMETRY, AT_L2_CACHESIZE)
(AT_L2_CACHEGEOMETRY, AT_L3_CACHESIZE, AT_L3_CACHEGEOMETRY)
(AT_MINSIGSTKSZ): New defines, imported from glibc.

4 years agoFix a potential illegal memory access in the Z80 assembler.
Sergey Belyashov [Tue, 3 Mar 2020 13:09:19 +0000 (13:09 +0000)] 
Fix a potential illegal memory access in the Z80 assembler.

PR 25604
* config/tc-z80.c (contains_register): Prevent an illegal memory
access when checking an expression for a register name.

4 years agoNote that the --rpath-link command line option will search the contents of the SEARCH...
Nick Clifton [Tue, 3 Mar 2020 12:53:00 +0000 (12:53 +0000)] 
Note that the --rpath-link command line option will search the contents of the SEARCH_DIR linker script directive, if one is provided.

PR 25588
* ld.texi (Options): Update the description of the --rpath-link
option.

4 years agobfd_check_format_matches preserving matches vs. cleanups
Alan Modra [Tue, 3 Mar 2020 09:57:36 +0000 (20:27 +1030)] 
bfd_check_format_matches preserving matches vs. cleanups

It didn't take long for oss-fuzz to find double frees due to a bug in
the cleanup logic.  It's seen when reading in any alpha-vms object
file except when alpha_vms_vec is the default.  But alpha_vms_vec is
of course the default when building for --target=alpha-dec-vms (and
naturally what I used to  test the cleanup support since that is the
only target with a cleanup that does anything currently).

Anyway, the bug is that if bfd_check_format_matches is to preserve a
match the cleanup for that match can't be run.  Quite obviously that
would destroy part of the match state.

* format.c (struct bfd_preserve): Add cleanup field.
(bfd_preserve_save): Add cleanup param and save.
(bfd_preserve_restore): Return cleanup.
(bfd_preserve_finish): Call the cleanup for the discarded match.
(bfd_check_format_matches): Pass cleanup to bfd_preserve_save,
and clear when preserving a match.  Restore cleanup too when
restoring that match.

4 years ago[gdb/testsuite] Fix gdb.mi/gdb2549.exp with check-read1
Tom de Vries [Tue, 3 Mar 2020 10:34:53 +0000 (11:34 +0100)] 
[gdb/testsuite] Fix gdb.mi/gdb2549.exp with check-read1

When running gdb.mi/gdb2549.exp with check-read1, we get:
...
Running src/gdb/testsuite/gdb.mi/gdb2549.exp ...
FAIL: gdb.mi/gdb2549.exp: register values t (timeout)
...

The problem is that the command generates a lot of output, which is matched by
a single '.*':
...
mi_gdb_test "666-data-list-register-values t" \
  "666\\^done,register-values=\\\[\{number=\"$decimal\",value=\"$binary\"\}.*\\\]" \
  "register values t"
...

Fix this by splitting up the matching and calling exp_continue after each
number/value pair.

Tested on x86_64-linux with make targets check and check-read1.

gdb/testsuite/ChangeLog:

2020-03-03  Tom de Vries  <tdevries@suse.de>

* gdb.mi/gdb2549.exp: Fix "register values t" check-read1 timeout.

4 years ago[gdb/testsuite] Fix tcl error in gdb.mi/list-thread-groups-available.exp
Tom de Vries [Tue, 3 Mar 2020 09:50:07 +0000 (10:50 +0100)] 
[gdb/testsuite] Fix tcl error in gdb.mi/list-thread-groups-available.exp

When running gdb.mi/list-thread-groups-available.exp, we get:
...
Running gdb.mi/list-thread-groups-available.exp ...
ERROR: tcl error sourcing gdb.mi/list-thread-groups-available.exp.
ERROR: Too many arguments to gdb_test_multiple
...

The problem is that the gdb_test_multiple call has as last argument a
$mi_gdb_prompt, which is no longer supported syntax since 590003dc0e
"[gdb/testsuite] Add -lbl option in gdb_test_multiple".

Fix this by using the new -prompt syntax.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-03  Tom de Vries  <tdevries@suse.de>

* gdb.mi/list-thread-groups-available.exp: Use -prompt syntax for
gdb_test_multiple call.

4 years ago[gdb/testsuite] Fix mi-sym-info.exp with check-read1
Tom de Vries [Tue, 3 Mar 2020 09:33:49 +0000 (10:33 +0100)] 
[gdb/testsuite] Fix mi-sym-info.exp with check-read1

When running gdb.mi/mi-sym-info.exp with check-read1, we run into:
...
FAIL: gdb.mi/mi-sym-info.exp: List all functions
FAIL: gdb.mi/mi-sym-info.exp: List all variables
...

The problem is that while the $mi_gdb_prompt is active, gdb_test_multiple is
used without -prompt "$mi_gdb_prompt$", so it defaults to matching $gdb_prompt.

Fix this by adding the missing gdb_test_multiple arguments.

Reg-tested on x86_64-linux with make targets check and check-read1.

gdb/testsuite/ChangeLog:

2020-03-03  Tom de Vries  <tdevries@suse.de>

* gdb.mi/mi-sym-info.exp: Add missing -prompt "$mi_gdb_prompt$" to
gdb_test_multiple calls.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 3 Mar 2020 00:00:46 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoTidy obj-coff.h
Alan Modra [Mon, 2 Mar 2020 22:14:26 +0000 (08:44 +1030)] 
Tidy obj-coff.h

* config/obj-coff.h: Remove vestiges of coff-m68k and pe-mips
support.

4 years agoSmall clean up of use_displaced_stepping
Simon Marchi [Mon, 2 Mar 2020 20:47:04 +0000 (15:47 -0500)] 
Small clean up of use_displaced_stepping

This function returns the result of a quite big condition.  I think it
would be more readeable if it was broken up in smaller pieces and
commented.  This is what this patch does.

I also introduced gdbarch_supports_displaced_stepping, since it shows
the intent better than checking for gdbarch_displaced_step_copy_insn_p.
I also used that new function in displaced_step_prepare_throw.

I also updated the comment on top of can_use_displaced_stepping, which
seemed a bit outdated with respect to non-stop.  The comment likely
dates from before it was possible to have targets that always operate
non-stop under the hood, even when the user-visible mode is all-stop.

No functional changes intended.

gdb/ChangeLog:

* infrun.c (gdbarch_supports_displaced_stepping): New.
(use_displaced_stepping): Break up conditions in smaller pieces.
Use gdbarch_supports_displaced_stepping.
(displaced_step_prepare_throw): Use
gdbarch_supports_displaced_stepping.

4 years agogdb: Allow GDB to _not_ load a previous command history
Andrew Burgess [Wed, 22 Jan 2020 18:21:58 +0000 (18:21 +0000)] 
gdb: Allow GDB to _not_ load a previous command history

This commit aims to give a cleaner mechanism by which the user can
prevent GDB from trying to load any previous command history.

Currently the user can change the path to the history file, either
using a command line flag, or by setting the GDBHISTFILE environment
variable, and if the path is set to a non-existent file, then
obviously GDB wont load any command history.  However, this feels like
a bit of a bodge, I'd like to add an official mechanism by which we
can disable command history loading.

Why would we want to prevent command history loading?  The specific
use case I have is GDB starting with a CWD that is a network mounted
directory, and there is no command history present.  Still GDB will
access the network in order to check for the file.  In my particular
use case I'm actually starting a large number of GDB instances in
parallel, all in the same network mounted directory, the large number
of network accesses looking for this file introduces a noticeable
delay at GDB startup.

The approach I'm proposing here is a slight adjustment to the current
rules for setting up the history filename.  Currently, if a user does
this, they see an error:

  (gdb) set history filename
  Argument required (filename to set it to.).

However, if a user does this:

  $ GDBHISTFILE= gdb --quiet
  (gdb) set history save on
  (gdb) q
  warning: Could not rename -gdb18416~ to : No such file or directory

So, we already have a bug in this area.  My plan is to allow the empty
filename to be accepted, and for this to mean, neither load, nor save
the command history.

This does mean that we now have two mechanisms to prevent saving the
command history:

  (gdb) set history filename

or

  (gdb) set history save off

But the only way to prevent loading the command history is to set the
filename to the empty string _before_ you get to a GDB prompt, either
using a command line option, or the environment variable.

I've updated some of the show commands, for example this session:

  (gdb) set history filename
  (gdb) show history filename
  There is no filename currently set for recording the command history in.
  (gdb) show history save
  Saving of the history record on exit is off.
  (gdb) set history save on
  (gdb) show history save
  Saving of the history is disabled due to the value of 'history filename'.
  (gdb) set history filename /tmp/hist
  (gdb) show history save
  Saving of the history record on exit is on.

I've updated the manual, and added some tests.

gdb/ChangeLog:

* NEWS: Mention new behaviour of the history filename.
* top.c (write_history_p): Add comment.
(show_write_history_p): Add header comment, give a different
message when history writing is on, but the history filename is
empty.
(history_filename): Add comment.
(history_filename_empty): New function.
(show_history_filename): Add header comment, give a different
message when the filename is empty.
(init_history): Compare history_filename against nullptr, and only
read history if the filename is not empty.
(set_history_filename): Add header comment, and only make
non-empty filenames absolute.
(init_main): Make the filename argument to 'set history filename'
optional.

gdb/doc/ChangeLog:

* gdb.texinfo (Command History): Extend description for
GDBHISTFILE and GDBHISTSIZE, add detail about the filename for
'set history filename' being optional.  Describe the effect of an
empty history filename on 'set history save on'.

gdb/testsuite/ChangeLog:

* gdb.base/default.exp: Remove test of 'set history filename'.
* gdb.base/gdbinit-history.exp: Add tests for setting the history
filename to the empty string.
* lib/gdb.exp (gdb_init): Unset environment variables GDBHISTFILE
and GDBHISTSIZE.

Change-Id: Ia586e4311182fac99113b60f11ef8a11fbd5450b

4 years agoFix arm-netbsd build error: convert from FPA to VFP
Christian Biesinger [Mon, 2 Mar 2020 17:28:14 +0000 (11:28 -0600)] 
Fix arm-netbsd build error: convert from FPA to VFP

The floating point register interface has changed to this:
https://github.com/NetBSD/src/blob/trunk/sys/arch/arm/include/reg.h

It now uses VFP instead of FPA registers. This patch updates
arm-nbsd-nat.c accordingly.

Also implements read_description so that these registers are correctly
printed by "info registers" et al.

Tested by compiling & running on arm-netbsd on qemu.

gdb/ChangeLog:

2020-03-02  Christian Biesinger  <cbiesinger@google.com>

* arm-nbsd-nat.c (arm_supply_fparegset): Rename to...
(arm_supply_vfpregset): ...this, and update to use VFP registers.
(fetch_fp_register): Update.
(fetch_fp_regs): Update.
(store_fp_register): Update.
(store_fp_regs): Update.
(arm_netbsd_nat_target::read_description): New function.
(fetch_elfcore_registers): Update.

4 years agogdb/remote: Restore support for 'S' stop reply packet
Andrew Burgess [Thu, 30 Jan 2020 14:35:40 +0000 (14:35 +0000)] 
gdb/remote: Restore support for 'S' stop reply packet

With this commit:

  commit 5b6d1e4fa4fc6827c7b3f0e99ff120dfa14d65d2
  Date:   Fri Jan 10 20:06:08 2020 +0000

      Multi-target support

There was a regression in GDB's support for older aspects of the
remote protocol.  Specifically, when a target sends the 'S' stop reply
packet (which doesn't include a thread-id) then GDB has to figure out
which thread actually stopped.

Before the above commit GDB figured this out by using inferior_ptid in
process_stop_reply, which contained the ptid of the current
process/thread.  This would be fine for single threaded
targets (which is the only place using an S packet makes sense), but
in the general case, relying on inferior_ptid for processing a stop is
wrong - there's no reason to believe that what was GDB's current
thread will be the same thread that just stopped in the target.

With the above commit the inferior_ptid now has the value null_ptid
inside process_stop_reply, this can be seen in do_target_wait, where
we call switch_to_inferior_no_thread before calling do_target_wait_1.

The problem this causes can be seen in the new test that runs
gdbserver using the flag --disable-packet=T, and causes GDB to throw
this assertion:

  inferior.c:279: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

A similar problem was fixed in this commit:

  commit 3cada74087687907311b52781354ff551e10a0ed
  Date:   Thu Jan 11 00:23:04 2018 +0000

      Fix backwards compatibility with old GDBservers (PR remote/22597)

However, this commit deals with the case where the T packet doesn't
include a thread-id, not the S packet case.  This commit solves the
problem providing a thread-id at the GDB side if the remote target
doesn't provide one.  The thread-id provided comes from
remote_state::general_thread, however, though this does work, I don't
think it is the ideal solution.

The remote_state tracks two threads, the continue_thread and the
general_thread, these are updated when GDB asks the remote target to
switch threads.  The general_thread is set before performing things
like register or memory accesses, and the continue_thread is set
before things like continue or step commands.  Further, the
general_thread is updated after a target stops to reference the thread
that stopped.

The first thing to note from the above description is that we have a
cycle of dependency, when a T packet arrives without a thread-id we
fill in the thread-id from the general_thread data.  The thread-id
from the stop event is then used to set the general_thread.  This in
itself feels a little weird.

The second question is why use the general_thread at all? You'd think
given how they are originally set that the continue thread would be a
better choice.  The problem with this is that the continue_thread, if
the user just does "continue", will be set to the minus_one_ptid, in
the remote protocol this means all threads.  When the stop arrives
with no thread-id and we use continue_thread we end up with a very
similar assertion to before because we now end up trying to lookup a
thread using the minus_one_ptid.  By contrast, once GDB has connected
to a remote target the general_thread will be set to a valid
thread-id, after which, if the target is single threaded, and stop
events arrive without a thread-id, everything works fine.

There is one slight weirdness with the above behaviour though.  When
GDB first connects to the remote target inferior_ptid is null_ptid,
however, upon connecting we query the remote for its threads.  As the
thread information arrives GDB adds the threads to its internal
database, and this process involves setting inferior_ptid to the id of
each new thread in turn.  Once we know about all the threads we wait
for a stop event from the remote target to indicate that GDB is now in
control of the target.

The problem is that after adding the new threads we don't reset
inferior_ptid, and the code path we use to wait for a stop event from
the target also doesn't reset inferior_ptid, so it turns out that
during the initial connection inferior_ptid is not null_ptid.  This is
lucky, because during the initial connection the general_thread
variable _is_ set to null_ptid.

So, during the initial connection, if the first stop event is missing
a thread-id then we "provide" a thead-id from general_thread.  This
turns out to be null_ptid meaning no thread-id is known, and then
during process_stop_reply we fill in the missing thread-id using
inferior_ptid.

This was all discussed on the mailing list here:

  https://sourceware.org/ml/gdb-patches/2020-02/msg01011.html

My proposal for a fix then is:

 1. Move the call to switch_to_inferior_no_thread into
 do_target_wait_1, this means that in all cases where we are waiting
 for an inferior the inferior_ptid will be set to null_ptid.  This is
 good as no wait code should rely on inferior_ptid.

 2. Remove the use of general_thread from the 'T' packet processing.
 The general_thread read here was only ever correct by chance, and we
 shouldn't be using it this way.

 3. Remove use of inferior_ptid from process_stop_event as this is
 wrong, and will always be null_ptid now anyway.

 4. When a stop_event has null_ptid due to a lack of thread-id (either
 from a T packet or an S packet) then pick the first non exited thread
 in the target and use that.  This will be fine for single threaded
 targets.  A multi-thread or multi-inferior aware remote target
 should be using T packets with a thread-id, so we give a warning if
 the target is multi-threaded, and we are still missing a thread-id.

 5. Extend the existing test that covered the T packet with missing
 thread-id to also cover the S packet.

gdb/ChangeLog:

* remote.c (remote_target::remote_parse_stop_reply): Don't use the
general_thread if the stop reply is missing a thread-id.
(remote_target::process_stop_reply): Use the first non-exited
thread if the target didn't pass a thread-id.
* infrun.c (do_target_wait): Move call to
switch_to_inferior_no_thread to ....
(do_target_wait_1): ... here.

gdb/testsuite/ChangeLog:

* gdb.server/stop-reply-no-thread.exp: Add test where T packet is
disabled.

4 years agogdbserver: Add mechanism to prevent sending T stop packets
Andrew Burgess [Fri, 28 Feb 2020 21:33:26 +0000 (21:33 +0000)] 
gdbserver: Add mechanism to prevent sending T stop packets

There is a developer only feature in gdbserver that provides a
command line option --disable-packet that prevents some packets from
being sent, which is used to increase test coverage within GDB.

This commit extends this mechanism to prevent GDBserver from sending
the T stop reply packets, instead limiting GDBserver to only send the
S stop reply packets.

The S stop reply packet is part of the older target control mechanism,
which has design flaws that were worked around with the introduction
of the newer target control mechanism, which uses the T stop reply
packet.

Limiting GDBserver to use S stop packets instead of T stop packets
will, inevitably, mean that GDBserver doesn't function correctly in
many cases involving multiple threads, however, I don't think this is
too important, this is a developer only feature, intended to allow us
to test GDB.

A new test that makes use of this feature will be added in the next
commit.

gdbserver/ChangeLog:

* remote-utils.cc (prepare_resume_reply): Add ability to convert T
reply into an S reply.
* server.cc (disable_packet_T): New global.
(captured_main): Set new global when appropriate.
* server.h (disable_packet_T): Declare.

4 years ago[gdb/testsuite] Add -lbl option in gdb_test_multiple
Tom de Vries [Mon, 2 Mar 2020 13:47:27 +0000 (14:47 +0100)] 
[gdb/testsuite] Add -lbl option in gdb_test_multiple

Add gdb_test_multiple option -lbl, that adds a regexp after the user code that
reads one line, and discards it:
...
           -re "\r\n\[^\r\n\]*(?=\r\n)" {
               exp_continue
           }
...

In order to be able to write:
...
gdb_test_multiple "command" "testname" -lbl {
  ...
}
...
rewrite the promp_regexp argument usage into the similar:
...
gdb_test_multiple "command" "testname" -prompt $prompt_regexp {
  ...
}
...

Build and reg-tested on x86_64-linux.

Tested gdb.base/corefile-buildid.exp with both make targets check and
check-read1.

gdb/testsuite/ChangeLog:

2020-03-02  Pedro Alves  <palves@redhat.com>
      Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_test_multiple): Handle prompt_regexp option using
-prompt prefix, before user_code argument.  Add -lbl option likewise.
(skip_python_tests_prompt, skip_libstdcxx_probe_tests_prompt)
(gdb_is_target_1): Add -prompt prefix and move to before user_code
argument.
* gdb.base/corefile-buildid.exp: Use -lbl option.  Rewrite regexps to
have "\r\n" at start-of-line, instead of at end-of-line.

4 years agoRe: bfd_cleanup for object_p
Alan Modra [Mon, 2 Mar 2020 13:38:42 +0000 (00:08 +1030)] 
Re: bfd_cleanup for object_p

I hate files that you can't compile.

* cisco-core.c (cisco_core_file_p): Return bfd_cleanup.
* hpux-core.c (hpux_core_core_file_p): Update prototype.
* sco5-core.c (sco5_core_file_p): Return bfd_cleanup.
(core_sco5_vec): Correct initialisers.

4 years agoRe: bfd_cleanup for object_p
Alan Modra [Mon, 2 Mar 2020 13:12:08 +0000 (23:42 +1030)] 
Re: bfd_cleanup for object_p

More missing core file support changes.

* aix386-core.c (aix386_core_file_p): Return bfd_cleanup.
* aix5ppc-core.c (xcoff64_core_p): Likewise.
* cisco-core.c (cisco_core_file_validate): Likewise.
* hppabsd-core.c (hppabsd_core_core_file_p): Likewise.
* hpux-core.c (hpux_core_core_file_p): Likewise.
* irix-core.c (irix_core_core_file_p): Likewise.
* lynx-core.c (lynx_core_file_p): Likewise.
* netbsd-core.c (netbsd_core_file_p): Likewise.
* osf-core.c (osf_core_core_file_p): Likewise.
* ptrace-core.c (ptrace_unix_core_file_p): Likewise.
* sco5-core.c (sco5_core_file_p): Likewise.

4 years agogdb: Move defs.h before any system header in debuginfod-support.c
Jon Turney [Sat, 29 Feb 2020 13:33:35 +0000 (13:33 +0000)] 
gdb: Move defs.h before any system header in debuginfod-support.c

* defs.h includes config.h
* config.h may define _GNU_SOURCE
* if _GNU_SOURCE is defined, that must be before including any system
header (see feature_test_macro(7))

This is necessary to ensure that a prototype for mkostemp() is brought
into scope by <stdlib.h> when compiling filestuff.h, on platforms where
_GNU_SOURCE isn't unconditionally defined for C++.

In file included from ../../gdb/../gdbsupport/scoped_fd.h:24,
                 from ../../gdb/debuginfod-support.c:22:
../../gdb/../gdbsupport/filestuff.h: In function ‘int gdb_mkostemp_cloexec(char*, int)’:
../../gdb/../gdbsupport/filestuff.h:59:10: error: ‘mkostemp’ was not declared in this scope; did you mean ‘mkstemp’?

gdb/ChangeLog:

2020-02-29  Jon Turney  <jon.turney@dronecode.org.uk>

* debuginfod-support.c: Include defs.h first.

4 years agoThe procedure to find an unused port for the debuginfod tests is susceptible to a...
Aaron Merey [Mon, 2 Mar 2020 12:46:47 +0000 (12:46 +0000)] 
The procedure to find an unused port for the debuginfod tests is susceptible to a TOCTOU failure.  Change port finding in order to avoid this. Also use 'expect' to interact with the server process since we now use the server's output to determine whether a port is in use.

* binutils/testsuite/binutils-all/debuginfod.exp: Improve port
selection.

4 years agotrad_unix_core_file_p: Return bfd_cleanup
H.J. Lu [Mon, 2 Mar 2020 12:35:23 +0000 (04:35 -0800)] 
trad_unix_core_file_p: Return bfd_cleanup

* trad-core.c (trad_unix_core_file_p): Return bfd_cleanup.

4 years agoImport latest fixes to libiberty from GCC
H.J. Lu [Mon, 2 Mar 2020 11:56:36 +0000 (03:56 -0800)] 
Import latest fixes to libiberty from GCC

lto: Also copy .note.gnu.property section

When generating the separate file with LTO debug sections, we should
also copy .note.gnu.property section.

PR lto/93966
* simple-object.c (handle_lto_debug_sections): Also copy
.note.gnu.property section.

4 years agoRestore readelf's string dump to previous behaviour where newlines were caused line...
Nick Clifton [Mon, 2 Mar 2020 10:02:02 +0000 (10:02 +0000)] 
Restore readelf's string dump to previous behaviour where newlines were caused line breaks.

PR 25543
* readelf.c (dump_section_as_strings): Display new-line characters
as \n and then insert a line break.
* testsuite/binutils-all/pr25543.s: New test.
* testsuite/binutils-all/pr25543.d: Test driver.
* testsuite/binutils-all/readelf.exp: Run the new test.

4 years agobfd_cleanup for object_p
Alan Modra [Mon, 2 Mar 2020 04:51:09 +0000 (15:21 +1030)] 
bfd_cleanup for object_p

The object_p (and archive_p, core_file_p) functions are not supposed
to have any target specific malloc'd memory attached to the bfd on
their return.  This should be obvious on a failure return, but it's
also true for a successful return.  The reason is that even though the
object_p recognises the file, that particular target may not be used
and thus the bfd won't be closed calling close_and_cleanup for the
target that allocated the memory.

It turns out that the object_p bfd_target* return value isn't needed.
In all cases except ld/plugin.c the target is abfd->xvec and with
ld/plugin.c the target isn't used.  So this patch returns a cleanup
function from object_p instead, called in bfd_check_format_matches to
tidy the bfd before trying a different target match.  The only cleanup
that does anything at this stage is the alpha-vms one.

bfd/
* targets.c (bfd_cleanup): New typedef.
(struct bfd <_bfd_check_format>): Return a bfd_cleanup.
* libbfd-in.h (_bfd_no_cleanup): Define.
* format.c (bfd_reinit): Add cleanup parameter, call it.
(bfd_check_format_matches): Set cleanup from _bfd_check_format
call and pass to bfd_reinit.  Delete temp, use abfd->xvec instead.
* aout-target.h (callback, object_p): Return bfd_cleanup.
* aout-tic30.c (tic30_aout_callback, tic30_aout_object_p): Likewise.
* archive.c (bfd_generic_archive_p): Likewise.
* binary.c (binary_object_p): Likewise.
* coff-alpha.c (alpha_ecoff_object_p): Likewise.
* coff-ia64.c (ia64coff_object_p): Likewise.
* coff-rs6000.c (_bfd_xcoff_archive_p, rs6000coff_core_p): Likewise.
* coff-sh.c (coff_small_object_p): Likewise.
* coff-stgo32.c (go32_check_format): Likewise.
* coff64-rs6000.c (xcoff64_archive_p, rs6000coff_core_p),
(xcoff64_core_p): Likewise.
* coffgen.c (coff_real_object_p, coff_object_p): Likewise.
* elf-bfd.h (bfd_elf32_object_p, bfd_elf32_core_file_p),
(bfd_elf64_object_p, bfd_elf64_core_file_p): Likewise.
* elfcode.h (elf_object_p): Likewise.
* elfcore.h (elf_core_file_p): Likewise.
* i386msdos.c (msdos_object_p): Likewise.
* ihex.c (ihex_object_p): Likewise.
* libaout.h (some_aout_object_p): Likewise.
* libbfd-in.h (bfd_generic_archive_p, _bfd_dummy_target),
(_bfd_vms_lib_alpha_archive_p, _bfd_vms_lib_ia64_archive_p): Likewise.
* libbfd.c (_bfd_dummy_target): Likewise.
* libcoff-in.h (coff_object_p): Likewise.
* mach-o-aarch64.c (bfd_mach_o_arm64_object_p),
(bfd_mach_o_arm64_core_p): Likewise.
* mach-o-arm.c (bfd_mach_o_arm_object_p),
(bfd_mach_o_arm_core_p): Likewise.
* mach-o-i386.c (bfd_mach_o_i386_object_p),
(bfd_mach_o_i386_core_p): Likewise.
* mach-o-x86-64.c (bfd_mach_o_x86_64_object_p),
(bfd_mach_o_x86_64_core_p): Likewise.
* mach-o.c (bfd_mach_o_header_p, bfd_mach_o_gen_object_p),
(bfd_mach_o_gen_core_p, bfd_mach_o_fat_archive_p): Likewise.
* mach-o.h (bfd_mach_o_object_p, bfd_mach_o_core_p),
(bfd_mach_o_fat_archive_p, bfd_mach_o_header_p): Likewise.
* mmo.c (mmo_object_p): Likewise.
* pef.c (bfd_pef_object_p, bfd_pef_xlib_object_p): Likewise.
* peicode.h (coff_real_object_p, pe_ILF_object_p),
(pe_bfd_object_p): Likewise.
* plugin.c (ld_plugin_object_p, bfd_plugin_object_p): Likewise.
* ppcboot.c (ppcboot_object_p): Likewise.
* rs6000-core.c (rs6000coff_core_p): Likewise.
* som.c (som_object_setup, som_object_p): Likewise.
* srec.c (srec_object_p, symbolsrec_object_p): Likewise.
* tekhex.c (tekhex_object_p): Likewise.
* vms-alpha.c (alpha_vms_object_p): Likewise.
* vms-lib.c (_bfd_vms_lib_archive_p, _bfd_vms_lib_alpha_archive_p),
(_bfd_vms_lib_ia64_archive_p, _bfd_vms_lib_txt_archive_p): Likewise.
* wasm-module.c (wasm_object_p): Likewise.
* xsym.c (bfd_sym_object_p): Likewise.
* xsym.h (bfd_sym_object_p): Likewise.
* aoutx.h (some_aout_object_p): Likewise, and callback parameter
return type.
* pdp11.c (some_aout_object_p): Likewise.
* plugin.c (register_ld_plugin_object_p): Update object_p
parameter type.
* plugin.h (register_ld_plugin_object_p): Likewise.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.
* libcoff.h: Regenerate.
ld/
* plugin.c (plugin_object_p): Return a bfd_cleanup.
(plugin_cleanup): New function.

4 years agoplugin: Copy the no_export field to the IR dummy object
H.J. Lu [Mon, 2 Mar 2020 01:07:12 +0000 (17:07 -0800)] 
plugin: Copy the no_export field to the IR dummy object

Copy the no_export field to the IR dummy object when claiming an IR
object.

PR ld/25618
* plugin.c (plugin_object_p): Copy the no_export field to the IR
dummy object.
* testsuite/ld-plugin/lto.exp (lto_link_elf_tests): Add
PR ld/25618 tests.
* testsuite/ld-plugin/pr25618.d: New file.
* testsuite/ld-plugin/pr25618a.cc: Likewise.
* testsuite/ld-plugin/pr25618a.h: Likewise.
* testsuite/ld-plugin/pr25618b.cc: Likewise.
* testsuite/ld-plugin/pr25618b.h: Likewise.

4 years agomiscellaneous SEC_SMALL_DATA
Alan Modra [Sun, 1 Mar 2020 23:47:18 +0000 (10:17 +1030)] 
miscellaneous SEC_SMALL_DATA

This patch arranges for symbols defined in .sdata and .sbss to be
reported by nm with 'g' and 's' flags, for coff targets that support
.sdata and .sbss.

The assembler changes regarding SEC_SMALL_DATA are really just
documentation.  As far as I'm aware, this won't change any assembler
output.

bfd/
* coff-alpha.c (alpha_ecoff_le_vec): Add SEC_SMALL_DATA to
applicable section flags.
* coff-mips.c (mips_ecoff_le_vec, mips_ecoff_be_vec): Likewise.
(mips_ecoff_bele_vec): Likewise.
* coffcode.h (sec_to_styp_flags): Set SEC_SMALL_DATA for .sdata
and .sbss sections.
* ecoff.c (_bfd_ecoff_new_section_hook): Likewise.
(_bfd_ecoff_styp_to_sec_flags): Likewise.
gas/
* config/tc-m32r.c (md_begin): Set SEC_SMALL_DATA on .scommon section.
* config/tc-mips.c (s_change_sec): Set SEC_SMALL_DATA for .sdata
and .sbss sections.
* config/tc-score.c: Delete !BFD_ASSEMBLER code throughout.
(s3_s_change_sec): Set SEC_SMALL_DATA for .sbss section.
(s3_s_score_lcomm): Likewise.
* config/tc-score7.c: Similarly.
* read.c (bss_alloc): Set SEC_SMALL_DATA for .sbss section.

4 years agoELF SEC_SMALL_DATA
Alan Modra [Sun, 1 Mar 2020 23:46:39 +0000 (10:16 +1030)] 
ELF SEC_SMALL_DATA

For those ELF targets that have .sdata or .sbss sections, or similar
sections, arrange to mark the sections with the SEC_SMALL_DATA flag.
This fixes regressions in nm symbol type caused by removing .sdata
and .sbss from coff_section_type with commit 49d9fd42ac.

* elf32-m32r.c (m32r_elf_section_flags): New function.
(elf_backend_section_flags): Define.
* elf32-nds32.c (nds32_elf_section_flags): New function.
(elf_backend_section_flags): Define.
* elf32-ppc.c (ppc_elf_section_from_shdr): Set SEC_SMALL_DATA for
.sbss and .sdata sections.
* elf32-v850.c (v850_elf_section_from_shdr): Set SEC_SMALL_DATA
for SHF_V850_GPREL sections.
* elf64-alpha.c (elf64_alpha_section_from_shdr): Delete outdated
FIXME.
* elf64-hppa.c (elf64_hppa_section_from_shdr): Set SEC_SMALL_DATA
for SHF_PARISC_SHORT sections.
* elf64-ppc.c (ppc64_elf_section_flags): New function.
(elf_backend_section_flags): Define.
* elfxx-mips.c (_bfd_mips_elf_section_from_shdr): Set SEC_SMALL_DATA
for SHF_MIPS_GPREL sections.  Delete FIXME.

This page took 0.054431 seconds and 4 git commands to generate.