binutils-gdb.git
6 years agoMake find_separate_debug_file* return std::string
Simon Marchi [Thu, 8 Mar 2018 23:56:23 +0000 (18:56 -0500)]
Make find_separate_debug_file* return std::string

This patch makes the find_separate_debug_file* functions return
std::string, which allows to get rid of some manual memory management
and one cleanup.

gdb/ChangeLog:

* build-id.c (find_separate_debug_file_by_buildid): Return
std::string.
* build-id.h (find_separate_debug_file_by_buildid): Return
std::string.
* coffread.c (coff_symfile_read): Adjust to std::string.
* elfread.c (elf_symfile_read): Adjust to std::string.
* symfile.c (separate_debug_file_exists): Change parameter to
std::string.
(find_separate_debug_file): Return std::string.
(find_separate_debug_file_by_debuglink): Return std::string.
* symfile.h (find_separate_debug_file_by_debuglink): Return
std::string.

6 years agoAdd xml_escape_text_append and use it
Simon Marchi [Thu, 8 Mar 2018 23:04:46 +0000 (18:04 -0500)]
Add xml_escape_text_append and use it

[This patch should go on top of "linux_qxfer_libraries_svr4: Use
 std::string", I should have sent them together as a series.]

I noticed that linux_qxfer_libraries_svr4 used xml_escape_text, which
returns an std::string.  That string is then copied into a larger
buffer.  It would be more efficient if we had a version of
xml_escape_text which appended to an existing string instead of
returning a new one.  This is what this patch does.

I manually verified that the output of linux_qxfer_libraries_svr4 didn't
change before/after the patch.

gdb/ChangeLog:

* common/xml-utils.c (xml_escape_text): Move code to...
(xml_escape_text_append): ... this new function.
* common/xml-utils.h (xml_escape_text_append): New declaration.
* unittests/xml-utils-selftests.c (test_xml_escape_text_append):
New function.
(_initialize_xml_utils): register test_xml_escape_text_append as
a selftest.

gdb/gdbserver/ChangeLog:

* linux-low.c (linux_qxfer_libraries_svr4): Use
xml_escape_text_append.

6 years agolinux_qxfer_libraries_svr4: Use std::string
Simon Marchi [Thu, 8 Mar 2018 23:04:07 +0000 (18:04 -0500)]
linux_qxfer_libraries_svr4: Use std::string

Use std::string, removing some manual memory management.

gdb/gdbserver/ChangeLog:

* linux-low.c (linux_qxfer_libraries_svr4): Use std::string.

6 years agoremote-stdio-gdbserver: Pass "target" to remote_exec to delete file
Simon Marchi [Thu, 8 Mar 2018 22:54:25 +0000 (17:54 -0500)]
remote-stdio-gdbserver: Pass "target" to remote_exec to delete file

As described here

  https://sourceware.org/bugzilla/show_bug.cgi?id=22841

there seems to be situations where the remote-stdio-gdbserver board
fails to delete the uploaded binary file.  Passing "target" fixes the
issue for Christian who reported the bug.

I did not experience this problem, but passing "target" to remote_exec
still works for me, so I'm fine with changing it.

Any objection?

gdb/testsuite/ChangeLog:

PR gdb/22841
* boards/remote-stdio-gdbserver.exp (${board}_file): Pass
"target" to remote_exec.

6 years agoDon't redefine upload/download/file in gdbserver-base
Simon Marchi [Thu, 8 Mar 2018 22:53:57 +0000 (17:53 -0500)]
Don't redefine upload/download/file in gdbserver-base

Before patch

  Make native gdbserver boards no longer be "remote" (in DejaGnu terms)
  739b3f1d8ff7072dcc66240c25b026c6433bda1a

the local gdbserver boards (except native-extended-gdbserver...) were
considered as remote by DejaGNU.  To avoid DejaGNU trying to use ssh/scp
to download the files to the target (which is actually local), the
gdbserver-base.exp file defined some _download, _upload and _file board
operations to override the default behavior, and instead just use local
operations.

The same patch also changed remote-stdio-gdbserver.exp to make it
inherit from gdbserver-base.exp.  Since then, this board (which is
actually remote) uses the overrides with local file operations.  As a
result, files are never actually copied to the target.

I think we can simply remove the overrides from gdbserver-base.exp.
Because all boards should be properly considered local or remote by
DejaGNU, it should by default use the right method for transferring
files.

gdb/testsuite/ChangeLog:

PR gdb/22841
* boards/gdbserver-base.exp (${board}_file, ${board}_download,
${board}_upload): Remove.

6 years agox86-64: Also optimize "clr reg64"
H.J. Lu [Thu, 8 Mar 2018 14:41:34 +0000 (06:41 -0800)]
x86-64: Also optimize "clr reg64"

"clr reg" is an alias of "xor reg, reg".  We can encode "clr reg64" as
"xor reg32, reg32".

gas/

* config/tc-i386.c (optimize_encoding): Also encode "clr reg64"
as "xor reg32, reg32".
* testsuite/gas/i386/x86-64-optimize-1.s: Add "clr reg64" tests.
* testsuite/gas/i386/x86-64-optimize-1.d: Updated.

opcodes/

* i386-opc.tbl: Add Optimize to clr.
* i386-tbl.h: Regenerated.

6 years agox86: Treat relocation against IFUNC symbol as FUNC
H.J. Lu [Thu, 8 Mar 2018 14:36:40 +0000 (06:36 -0800)]
x86: Treat relocation against IFUNC symbol as FUNC

When resolving a relocation against IFUNC symbol in a SHT_NOTE section
without SHF_ALLOC, we treat it as relocation against FUNC symbol since
it needs the address of IFUNC symbol, not the address returned by IFUNC
function.

bfd/

PR ld/22929
* elf32-i386.c (elf_i386_relocate_section): Treat relocation
against IFUNC symbol in SHT_NOTE section without SHF_ALLOC as
relocation against FUNC symbol.
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.

ld/

PR ld/22929
* testsuite/ld-i386/i386.exp: Run PR ld/22929 test.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr22929.d: New file.
* testsuite/ld-i386/pr22929.s: Likewise.
* testsuite/ld-x86-64/pr22929.d: Likewise.
* testsuite/ld-x86-64/pr22929.s: Likewise.

6 years agox86: Remove support for old (<= 2.8.1) versions of gcc
H.J. Lu [Thu, 8 Mar 2018 14:31:32 +0000 (06:31 -0800)]
x86: Remove support for old (<= 2.8.1) versions of gcc

Old (<= 2.8.1) versions of gcc generate broken fsubp, fsubrp, fdivp and
fdivrp instructions.  Assembler translates them to correct ones with a
warning:

[hjl@gnu-cfl-1 gas]$ cat x.s
fsubp %st(3),%st
[hjl@gnu-cfl-1 gas]$ gcc -c x.s
x.s: Assembler messages:
x.s:1: Warning: translating to `fsubp %st,%st(3)'
[hjl@gnu-cfl-1 gas]$

This patch removes support for old (<= 2.8.1) versions of gcc:

[hjl@gnu-cfl-1 gas]$ ./as-new -o x.o x.s
x.s: Assembler messages:
x.s:1: Error: operand type mismatch for `fsubp'
[hjl@gnu-cfl-1 gas]$

gas/

* NEWS: Mention -mold-gcc removal.
* config/tc-i386.c (i386_error): Remove old_gcc_only.
(old_gcc): Removed.
(match_template): Remove old gcc support.
(OPTION_MOLD_GCC): Removed.
(OPTION_MRELAX_RELOCATIONS): Updated.
(md_longopts): Remove OPTION_MOLD_GCC.
(md_parse_option): Likewise.
(md_show_usage): Remove -mold-gcc.
* testsuite/gas/i386/general.s: Convert fsub/fdiv tests for old
(<= 2.8.1) versions of gcc.
* testsuite/gas/i386/intel.s: Likewise.
* testsuite/gas/i386/general.l: Updated.
* testsuite/gas/i386/intel-intel.d: Likewise.
* testsuite/gas/i386/intel.d: Likewise.
* testsuite/gas/i386/intel.e: Likewise.
* testsuite/gas/i386/i386.exp: Don't pass -mold-gcc to general.

include/

* opcode/i386 (OLDGCC_COMPAT): Removed.

opcodes/

* i386-gen.c (opcode_modifiers): Remove OldGcc.
* i386-opc.h (OldGcc): Removed.
(i386_opcode_modifier): Remove oldgcc.
* i386-opc.tbl: Remove fsubp, fsubrp, fdivp and fdivrp
instructions for old (<= 2.8.1) versions of gcc.
* i386-tbl.h: Regenerated.

6 years agoRemove MAX_REGISTER_SIZE define
Alan Hayward [Thu, 8 Mar 2018 09:42:21 +0000 (09:42 +0000)]
Remove MAX_REGISTER_SIZE define

gdb/
* defs.h: Remove MAX_REGISTER_SIZE.
* regcache.c (init_regcache_descr): Remove MAX_REGISTER_SIZE
asserts.
* python/py-unwind.c (pyuw_sniffer): Likewise.

6 years agox86: fold several AVX512VL templates
Jan Beulich [Thu, 8 Mar 2018 07:58:55 +0000 (08:58 +0100)]
x86: fold several AVX512VL templates

The differences between some of the register and memory forms of the
same insn often don't really require the templates to be separate. For
example, Disp8MemShift is simply irrelevant to register forms. Fold
these as far as possible, and also fold register-only forms. Further
folding is possible, but needs other prereq work done first.

A note regarding EVEXDYN: This is intended to be used only when no other
properties of the template would make is_evex_encoding() return true. In
all "normal" cases I think it is preferable to omit this indicator, to
keep the table half way readable.

6 years agox86: fold certain AVX512 rotate and shift templates
Jan Beulich [Thu, 8 Mar 2018 07:58:05 +0000 (08:58 +0100)]
x86: fold certain AVX512 rotate and shift templates

Their memory forms were bogusly using VexLWP instead of VexNDD. Adjust
VexNDD handling to cope with these, allowing their register and memory
forms to be folded.

6 years agox86: fold VEX-encoded GFNI templates
Jan Beulich [Thu, 8 Mar 2018 07:57:19 +0000 (08:57 +0100)]
x86: fold VEX-encoded GFNI templates

6 years agox86: fold a few AVX512F templates
Jan Beulich [Thu, 8 Mar 2018 07:56:47 +0000 (08:56 +0100)]
x86: fold a few AVX512F templates

The differences between some of the register and memory forms of the
same insn often don't really require the templates to be separate. For
example, Disp8MemShift is simply irrelevant to register forms. Fold them
as far as possible. Further folding is possible, but needs other prereq
work done first.

6 years agox86: fold LWP templates
Jan Beulich [Thu, 8 Mar 2018 07:56:08 +0000 (08:56 +0100)]
x86: fold LWP templates

Also drop the no longer necessary explicit Disp<N> from them.

6 years agox86: fold FMA and FMA4 templates
Jan Beulich [Thu, 8 Mar 2018 07:55:37 +0000 (08:55 +0100)]
x86: fold FMA and FMA4 templates

6 years agox86: drop {X,Y,Z}MMWORD_MNEM_SUFFIX
Jan Beulich [Thu, 8 Mar 2018 07:52:27 +0000 (08:52 +0100)]
x86: drop {X,Y,Z}MMWORD_MNEM_SUFFIX

They aren't really useful (anymore?): The conflicting operand size check
isn't applicable to any insn validly using respective memory operand
sizes (and if they're used wrongly, another error would result), and the
logic in process_suffix() can be easily changed to work without them.

While re-structuring conditionals in process_suffix() also drop the
CMPXCHG8B special case in favor of a NoRex64 attribute in the opcode
table.

6 years agox86: correct operand size match checks for BMI/BMI2 insns
Jan Beulich [Thu, 8 Mar 2018 07:51:18 +0000 (08:51 +0100)]
x86: correct operand size match checks for BMI/BMI2 insns

Some BMI/BMI2 insns allow their middle operands to be a memory one. In
such a case, matching register types between operands 0 and 1 as well as
1 and 2 won't help - operands 0 and 2 also need to be checked.

6 years agox86: fold redundant expressions in process_suffix()
Jan Beulich [Thu, 8 Mar 2018 07:50:13 +0000 (08:50 +0100)]
x86: fold redundant expressions in process_suffix()

There's no point repeatedly evaluating i.types[op].bitfield.reg.

6 years agox86: simplify result processing of cpu_flags_match()
Jan Beulich [Thu, 8 Mar 2018 07:48:10 +0000 (08:48 +0100)]
x86: simplify result processing of cpu_flags_match()

Make more obvious what the success and failure paths are, and in
particular that what used to be at the "skip" label can't be reached
by what used to be straight line code.

6 years agox86: add GFNI, VAES, and VPCLMUL checking to cpu_flags_match()
Jan Beulich [Thu, 8 Mar 2018 07:47:32 +0000 (08:47 +0100)]
x86: add GFNI, VAES, and VPCLMUL checking to cpu_flags_match()

Just like for the AVX/AES and AVX/PCLMUL combinations, AVX/GFN,
AVX512F/GFNI, AVX512F/VAES, and AVX512F/PCLMUL need special handling to
deal with the pair of required checks specified in the templates.

6 years agox86: change AVX512VL handling in cpu_flags_match()
Jan Beulich [Thu, 8 Mar 2018 07:45:56 +0000 (08:45 +0100)]
x86: change AVX512VL handling in cpu_flags_match()

In order to add an AVX512F counterpart to the present AVX checking, it
is better to move the AVX512VL check out of the conditional it's
currently in.

6 years agox86: drop CPU_FLAGS_32BIT_MATCH
Jan Beulich [Thu, 8 Mar 2018 07:45:25 +0000 (08:45 +0100)]
x86: drop CPU_FLAGS_32BIT_MATCH

It has become a plain alias of CPU_FLAGS_ARCH_MATCH now.

6 years agox86: simplify AVX checks in cpu_flags_match()
Jan Beulich [Thu, 8 Mar 2018 07:44:52 +0000 (08:44 +0100)]
x86: simplify AVX checks in cpu_flags_match()

No caller cares about the specifics of CPU_FLAGS_{AES,AVX,PCLMUL}_MATCH,
so drop those and fold the nested if()-s.

6 years agox86: avoid cpu_flags_match() bogusly setting CPU_FLAGS_ARCH_MATCH
Jan Beulich [Thu, 8 Mar 2018 07:44:12 +0000 (08:44 +0100)]
x86: avoid cpu_flags_match() bogusly setting CPU_FLAGS_ARCH_MATCH

6 years agox86: drop bogus NoAVX
Jan Beulich [Thu, 8 Mar 2018 07:36:41 +0000 (08:36 +0100)]
x86: drop bogus NoAVX

These are meaningful only for insns with CpuSSE* (and a few other Cpu*)
attribute.

6 years agox86: avoid SSE check for LDMXCSR/STMXCSR
Jan Beulich [Thu, 8 Mar 2018 07:35:48 +0000 (08:35 +0100)]
x86: avoid SSE check for LDMXCSR/STMXCSR

Neither touches any XMM register, so the check is pointless. It is imo
even questionable whether in SSE2AVX mode the two should be converted to
their AVX counterparts.

6 years agox86: extend SSE check to PCLMULQDQ, AES, and GFNI insns
Jan Beulich [Thu, 8 Mar 2018 07:35:01 +0000 (08:35 +0100)]
x86: extend SSE check to PCLMULQDQ, AES, and GFNI insns

When aiming at not mixing SSE and AVX insns, these should be warned
about the same way other non-AVX ones are treated.

6 years agox86: drop FloatD
Jan Beulich [Thu, 8 Mar 2018 07:34:09 +0000 (08:34 +0100)]
x86: drop FloatD

It can be expressed by D, when making the consumer look at operand size
to tell apart both uses.

6 years agox86/Intel: correct disassembly of fsub*/fdiv*
Jan Beulich [Thu, 8 Mar 2018 07:33:06 +0000 (08:33 +0100)]
x86/Intel: correct disassembly of fsub*/fdiv*

fsub/fsubr/fsubp/fsubrp as well as fdiv/fdivr/fdivp/fdivrp disassembly
should match (a) the Intel SDM and (b) respective input fed to gas (both
of course with the exception of when we intentionally convert bogus
insns, accompanied by a warning).

6 years agox86: adjust 4-XMM-register-group related warning
Jan Beulich [Thu, 8 Mar 2018 07:27:28 +0000 (08:27 +0100)]
x86: adjust 4-XMM-register-group related warning

Drop "second": For one there's no other source register (the other
source operand is in memory), and in Intel syntax such numbering would
also be wrong.

Take the opportunity and also
- properly place declarations ahead of statements
- use %u format for unsigned int arguments
- fix indentation

6 years agox86: bogus VMOVD with 64-bit operands should only allow for registers
Jan Beulich [Thu, 8 Mar 2018 07:26:35 +0000 (08:26 +0100)]
x86: bogus VMOVD with 64-bit operands should only allow for registers

These templates exist solely to satisfy gcc's needs, and gcc only
produces these with register operands.

6 years agox86: fold AVX vcvtpd2ps memory forms
Jan Beulich [Thu, 8 Mar 2018 07:25:31 +0000 (08:25 +0100)]
x86: fold AVX vcvtpd2ps memory forms

This requires a change to ModR/M handling: Recording of displacement
types must not discard operand size information. Change the respective
code to alter only .disp<N>.

6 years agoReally remove unnecessary power9 group terminating nop
Alan Modra [Thu, 8 Mar 2018 04:04:09 +0000 (14:34 +1030)]
Really remove unnecessary power9 group terminating nop

Oops, not tested well enough.  -mpower9 sets all the PPC_OPCODE_POWERn
for n <= 9.

* config/tc-ppc.c (ppc_handle_align): Correct last patch.  Really
don't emit a group terminating nop for power9.  Simplify cpu
tests.

6 years agoRemove unnecessary power9 group terminating nop
Alan Modra [Wed, 7 Mar 2018 23:47:41 +0000 (10:17 +1030)]
Remove unnecessary power9 group terminating nop

Power9 doesn't have a group terminating nop, so we may as well emit a
normal nop for power9.  Not that it matters a great deal, I believe
ori 2,2,0 will be treated exactly as ori 0,0,0 by the hardware.

* config/tc-ppc.c (ppc_handle_align): Don't emit a group
terminating nop for power9.

6 years agoFix PR binutils/22923.
Paul Pluzhnikov [Thu, 8 Mar 2018 02:16:34 +0000 (18:16 -0800)]
Fix PR binutils/22923.

A static buffer in get_ver_flags may overflow when e.g. German translation
is longer than English original. Avoid that by expanding the buffer.

6 years agoAutomatic date update in version.in
GDB Administrator [Thu, 8 Mar 2018 00:00:42 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoReturn gdb::optional<std::string> from target_fileio_readlink
Tom Tromey [Thu, 23 Nov 2017 06:37:38 +0000 (23:37 -0700)]
Return gdb::optional<std::string> from target_fileio_readlink

This changes to_fileio_readlink and target_fileio_readlink to return a
gdb::optional<std::sring>, and then fixes up the callers and
implementations.  This allows the removal of some cleanups.

Regression tested by the buildbot.

gdb/ChangeLog
2018-03-07  Tom Tromey  <tom@tromey.com>

* linux-tdep.c (linux_info_proc): Update.
* target.h (struct target_ops) <to_fileio_readlink>: Return
optional<string>.
(target_fileio_readlink): Return optional<string>.
* remote.c (remote_hostio_readlink): Return optional<string>.
* inf-child.c (inf_child_fileio_readlink): Return
optional<string>.
* target.c (target_fileio_readlink): Return optional<string>.

6 years agoxtensa: ld: support -z relro
Max Filippov [Tue, 6 Mar 2018 05:49:35 +0000 (21:49 -0800)]
xtensa: ld: support -z relro

ld/
2018-03-07  Max Filippov  <jcmvbkbc@gmail.com>

* emulparams/elf32xtensa.sh (COMMONPAGESIZE): Define.

6 years agoNew option -z,keep-text-section prefix.
Sriraman Tallam [Wed, 7 Mar 2018 20:15:49 +0000 (12:15 -0800)]
New option -z,keep-text-section prefix.

This option does not merge certain text sections with prefixes
.text.hot, .text.unlikely, .text.startup and .text.exit.

* layout.cc (Layout::default_section_order): Check for text section
prefixes.
(Layout::text_section_name_mapping): New static member.
(Layout::text_section_name_mapping_count): New static member.
(Layout::match_section_name): New static function.
(Layout::output_section_name): Check for text section prefixes.
* layout.h (Output_section_order::ORDER_TEXT_HOT): New enum value.
(Output_section_order::ORDER_TEXT_STARTUP): New enum value.
(Output_section_order::ORDER_TEXT_EXIT): New enum value.
(Output_section_order::ORDER_TEXT_UNLIKELY): New enum value.
(Layout::text_section_name_mapping): New static member.
(Layout::text_section_name_mapping_count): New static member.
(Layout::match_section_name): New static function.
* options.h (keep_text_section_prefix): New -z option.
* testsuite/Makefile.am (keep_text_section_prefix): New test.
* testsuite/Makefile.in: Regenerate.
* testsuite/keep_text_section_prefix.cc: New test source.
* testsuite/keep_text_section_prefix.sh: New test script.

6 years agogdb: Add riscv to list of architectures with a save_reggroup
Andrew Burgess [Tue, 6 Mar 2018 16:27:13 +0000 (16:27 +0000)]
gdb: Add riscv to list of architectures with a save_reggroup

The regcache cooked_read test needs to know which architectures have a
save_reggroup, riscv does and needs adding to the list.

gdb/ChangeLog:

* regcache.c (cooked_read_test): Add riscv to the list of
architectures that have a save_reggroup.

6 years ago[PR20402][LD][AARCH64]Don't emit RELATIVE relocation for absolute symbols which are...
Renlin Li [Wed, 7 Mar 2018 09:27:45 +0000 (09:27 +0000)]
[PR20402][LD][AARCH64]Don't emit RELATIVE relocation for absolute symbols which are resolved at static linking time.

For absolute symbols which are forced local or not dynamic, the ABS relocation
should be resolved at static linking time.

Originally, an RELATIVE/ABS relocation will be generated even for absolution
symbols for the dynamic linker to resolve.

bfd/

2018-03-07  Renlin Li  <renlin.li@arm.com>

PR ld/20402
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Check absolute symbol,
and don't emit relocation in specific case.

ld/

2018-03-07  Renlin Li  <renlin.li@arm.com>

PR ld/20402
* testsuite/ld-aarch64/aarch64-elf.exp: Run new test.
* testsuite/ld-aarch64/pr20402.s: New.
* testsuite/ld-aarch64/pr20402.d: New.

6 years agoFix watching structs in C++
Andreas Arnez [Wed, 7 Mar 2018 13:29:19 +0000 (14:29 +0100)]
Fix watching structs in C++

Some of the watchpoint logic depends on the fact that the head of the
value chain represents the user-specified value to watch.  Thus no
additional values should be added to the value chain after that.  However,
if a watchpoint is defined for a C++ structure/class object, then run-time
type information (RTTI) may be present.  Thus, while constructing the
value chain for the watchpoint, the dynamic type is fetched by
gnuv3_rrti_type, which invokes value_addr, which then adds a new value to
the head of the value chain.  This new value represents the pointer to the
structure instead of the structure itself.

With such a "polluted" value chain the watchpoint logic does not recognize
when the user intended to watch a struct, and can_use_hardware_watchpoint
returns zero.  Instead of a hardware watchpoint, a software watchpoint
will then be set for no apparent reason.

This is fixed by adding an early exit to gnuv3_rtti_type when the input
value is not a dynamic class object.

gdb/testsuite/ChangeLog:

* gdb.cp/watch-cp.cc: New test.
* gdb.cp/watch-cp.exp: New file.

gdb/ChangeLog:

* gnu-v3-abi.c (gnuv3_rtti_type): Add early exit if the given
value is not a dynamic class object.

6 years agox86: Rewrite NOP generation for fill and alignment
H.J. Lu [Wed, 7 Mar 2018 12:18:45 +0000 (04:18 -0800)]
x86: Rewrite NOP generation for fill and alignment

Rewrite NOP generation for fill and code alignment by:

1. Add a 11-byte NOP with another 0x66 prefix.
2. Remove the multi-byte NOP entries which consist of 2 instructions.
3. Select proper NOPs based on ISA and processor tuning.
4. Generate multiple NOPs with the longer NOPs first followed by the
shorter NOP.
5. Use jump for larger NOP padding:
   a. > 8 bytes (2 NOPs) in 16-bit mode.
   b. > 14 bytes (2 NOPs) for older processors.
   c. > 77 bytes (7 NOPs) for newer processors.
6. Update MAX_MEM_FOR_RS_ALIGN_CODE to 4095.

PR gas/22874
* config/tc-i386.c (f32_5): Removed.
(f32_8): Likewise.
(f32_9): Likewise.
(f32_10): Likewise.
(f32_11): Likewise.
(f32_12): Likewise.
(f32_13): Likewise.
(f32_14): Likewise.
(f16_5): Likewise.
(f16_6): Likewise.
(f16_7): Likewise.
(f16_8): Likewise.
(jump_31): Likewise.
(alt64_11): Likewise.
(alt64_patt): Likewise.
(jump_disp8): New.
(jump32_disp32): Likewise.
(jump16_disp32): Likewise.
(alt_11): Likewise.
(f32_patt): Updated.
(f16_patt): Likewise.
(alt_patt): Add alt_11.
(i386_align_code): Merged with ...
(i386_generate_nops): This.  Rewritten.
(fits_in_imm7): Moved before i386_generate_nops.
(fits_in_imm31): Likewise.
* config/tc-i386.h (MAX_MEM_FOR_RS_ALIGN_CODE): Updated to
4095.
(i386_align_code): Removed.
(HANDLE_ALIGN): Rewritten with i386_generate_nops.
* doc/as.texinfo: Update limits of control byte for x86 .nops
directive.
* testsuite/gas/i386/i386.exp: Run nops-7 and x86-64-nops-7.
* gas/testsuite/gas/i386/noavx-3.l: Updated.
* gas/testsuite/gas/i386/nop-1.d: Likewise.
* gas/testsuite/gas/i386/nop-1.s: Likewise.
* gas/testsuite/gas/i386/nop-2.d: Likewise.
* gas/testsuite/gas/i386/nop-2.s: Likewise.
* gas/testsuite/gas/i386/nop-3.d: Likewise.
* gas/testsuite/gas/i386/nop-4.d: Likewise.
* gas/testsuite/gas/i386/nop-5.d: Likewise.
* gas/testsuite/gas/i386/nop-5.s: Likewise.
* gas/testsuite/gas/i386/nop-6.d: Likewise.
* gas/testsuite/gas/i386/nop-bad-1.l: Likewise.
* gas/testsuite/gas/i386/nops-1-core2.d: Likewise.
* gas/testsuite/gas/i386/nops-1-i386-i686.d: Likewise.
* gas/testsuite/gas/i386/nops-1-i386.d: Likewise.
* gas/testsuite/gas/i386/nops-1-i686.d: Likewise.
* gas/testsuite/gas/i386/nops-1-k8.d: Likewise.
* gas/testsuite/gas/i386/nops-1.d: Likewise.
* gas/testsuite/gas/i386/nops-2-core2.d: Likewise.
* gas/testsuite/gas/i386/nops-2-i386.d: Likewise.
* gas/testsuite/gas/i386/nops-2.d: Likewise.
* gas/testsuite/gas/i386/nops-3-i386.d: Likewise.
* gas/testsuite/gas/i386/nops-3-i686.d: Likewise.
* gas/testsuite/gas/i386/nops-3.d: Likewise.
* gas/testsuite/gas/i386/nops-4-i386.d: Likewise.
* gas/testsuite/gas/i386/nops-4-i686.d: Likewise.
* gas/testsuite/gas/i386/nops-4.d: Likewise.
* gas/testsuite/gas/i386/nops-4a-i686.d: Likewise.
* gas/testsuite/gas/i386/nops-5-i686.d: Likewise.
* gas/testsuite/gas/i386/nops-5.d: Likewise.
* gas/testsuite/gas/i386/nops-6.d: Likewise.
* gas/testsuite/gas/i386/nops16-1.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nop-1.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nop-2.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nop-5.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-1-core2.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-1-g64.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-1-k8.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-1-pentium.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-1.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-2.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-3.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-4-core2.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-4-k8.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-4.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-5-k8.d: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-5.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-1-core2.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-1-k8.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-1-pentium.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-1.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-2.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-3.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-4-core2.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-4-k8.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-4.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-5-k8.d: Likewise.
* gas/testsuite/gas/i386/ilp32/x86-64-nops-5.d: Likewise.
* gas/testsuite/gas/i386/nops-7.d: New file.
* gas/testsuite/gas/i386/nops-7.s: Likewise.
* gas/testsuite/gas/i386/x86-64-nops-7.d: Likewise.

6 years agoXCOFF disassembler
Alan Modra [Wed, 7 Mar 2018 00:36:15 +0000 (11:06 +1030)]
XCOFF disassembler

xcoff (32-bit) objdump accepted but ignored -M options unless
-mpowerpc was also given.  This patch fixes that, leaving the default
as -Mpwr for xcoff.  I've also enabled more tests for xcoff targets.

binutils/
* configure.ac: Add objdump_private_desc_xcoff for rs6000.
* configure: Regenerate.
gas/
* testsuite/gas/ppc/aix.exp: Run for rs6000 too.
* testsuite/gas/ppc/ppc.exp: Run more tests for non-ELF targets.
* testsuite/gas/ppc/machine.d: Don't run for PE targets.
opcodes/
* disassemble.c (disassembler): Use bfd_arch_powerpc entry for
bfd_arch_rs6000.
* disassemble.h (print_insn_rs6000): Delete.
* ppc-dis.c (powerpc_init_dialect): Handle rs6000.
(disassemble_init_powerpc): Call powerpc_init_dialect for rs6000.
(print_insn_rs6000): Delete.

6 years agomips64 rtype_to_howto error status
Alan Modra [Mon, 5 Mar 2018 04:01:05 +0000 (14:31 +1030)]
mips64 rtype_to_howto error status

* elf64-mips.c (mips_elf64_rtype_to_howto): Return NULL on error.
(mips_elf64_slurp_one_reloc_table): Pass on error.

6 years agoAutomatic date update in version.in
GDB Administrator [Wed, 7 Mar 2018 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoFormatting fixes in rust-exp.y
Tom Tromey [Tue, 6 Mar 2018 20:27:12 +0000 (13:27 -0700)]
Formatting fixes in rust-exp.y

I noticed a few formatting buglets in rust-exp.y: A couple of lines
were too long, and a couple of parser rules did not follow the same
formatting as the rest of the code.

I'm checking this in as obvious.  Tested by rebuilding.

2018-03-06  Tom Tromey  <tom@tromey.com>

* rust-exp.y: Formatting fixes.

6 years agoRISC-V: Disallow output format changes.
Jim Wilson [Tue, 6 Mar 2018 20:01:04 +0000 (12:01 -0800)]
RISC-V: Disallow output format changes.

PR 22920
* emultempl/riscvelf.em (riscv_create_output_section_statements): New.
(LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS): New.
* testsuite/ld-elf/pr21884.d (#notarget): Add riscv*-*-*.
* testsuite/ld-unique/pr21529.d (#notarget): Likewise.
* testsuite/ld-srec/srec.exp (run_srec_test): For riscv*-*-* target,
call setup_xfail.

6 years agogdb/riscv: Remove partial target description support
Andrew Burgess [Tue, 6 Mar 2018 16:57:41 +0000 (16:57 +0000)]
gdb/riscv: Remove partial target description support

Some parts of the target description support were committed with the
initial riscv patch.  As target descriptions are not currently supported
on riscv this commit removes the two pieces for code that relate to
target description support.

It is expected that target description support will be added in the
future, at which point this, or similar code will be added back.

gdb/ChangeLog:

* riscv-tdep.c (riscv_register_name): Remove target description
support.
(riscv_gdbarch_init): Remove target description check.

6 years agogdb/riscv: Remove 'Contributed by....' comments
Andrew Burgess [Tue, 6 Mar 2018 16:31:40 +0000 (16:31 +0000)]
gdb/riscv: Remove 'Contributed by....' comments

The GDB coding standard states these lines should never have been
added.

gdb/ChangeLog:

* riscv-tdep.c: Remove 'Contributed by ...' lines from header
comment.
* riscv-tdep.h: Likewise.

6 years agogdb/riscv: Remove use of pseudo registers
Andrew Burgess [Tue, 6 Mar 2018 16:19:52 +0000 (16:19 +0000)]
gdb/riscv: Remove use of pseudo registers

The code making use of pseudo registers was initially intended to
support running 32-bit ABI files on 64-bit riscv targets.  However, the
implementation was incomplete, and broken.

For now I've removed all reference to pseudo registers from the riscv
target, we've not lost any functionality, and this cleans up failures in
the selftests.

Once the riscv target has matured a little we'll probably end up
bringing back some of the use of pseudo registers in order to better
support running 32-bit executables on a 64-bit target.

gdb/ChangeLog:

* riscv-tdep.c (riscv_pseudo_register_read): Delete.
(riscv_pseudo_register_write): Delete.
(riscv_gdbarch_init): Remove all use of pseudo registers.

6 years agobtrace: Remove ui_out cleanups
Simon Marchi [Tue, 6 Mar 2018 14:51:33 +0000 (09:51 -0500)]
btrace: Remove ui_out cleanups

This patch replaces the cleanups that close the list and tuple of the
btrace instruction history output with ui_out_emit_tuple and
ui_out_emit_list.

This allows removing make_cleanup_ui_out_tuple_begin_end and
make_cleanup_ui_out_list_begin_end.

This patch (along with the previous ones in the series) was regtested on
the buildbot.

gdb/ChangeLog:

* record-btrace.c (btrace_print_lines): Replace cleanup
parameter with RAII equivalents.
(btrace_insn_history): Replace cleanup with RAII equivalents.
* ui-out.h (make_cleanup_ui_out_list_begin_end,
make_cleanup_ui_out_tuple_begin_end): Remove.
* ui-out.c (struct ui_out_end_cleanup_data, do_cleanup_end,
make_cleanup_ui_out_end, make_cleanup_ui_out_tuple_begin_end,
make_cleanup_ui_out_list_begin_end): Remove.

6 years agobtrace: Remove VEC cleanups
Simon Marchi [Tue, 6 Mar 2018 14:51:33 +0000 (09:51 -0500)]
btrace: Remove VEC cleanups

This patch replaces two VEC(tp_t) with std::vector<thread_info *>, which
allows to remove two cleanups.  To make it easier to map the old code to
the new code, I added the ordered_remove and unordered_remove functions,
which operate on std::vector and do the same as VEC's
ordered_remove/unordered_remove.

gdb/ChangeLog:

* record-btrace.c (record_btrace_maybe_mark_async_event): Change
parameter types to std::vector.  Use bool.
(record_btrace_wait): Replace VEC(tp_t) with
std::vector<thread_info *>.
* common/gdb_vecs.h (unordered_remove, ordered_remove): New.

6 years agobtrace: Remove btrace disable cleanup
Simon Marchi [Tue, 6 Mar 2018 14:51:32 +0000 (09:51 -0500)]
btrace: Remove btrace disable cleanup

This patch removes a cleanup that disables btrace on threads in case of
failure, so we don't leave it enabled for some the threads and disabled
for the rest.

gdb/ChangeLog:

* record-btrace.c (record_btrace_disable_callback): Remove.
(struct scoped_btrace_disable): New.
(record_btrace_open): Use scoped_btrace_disable.

6 years agogdb/riscv: Fix type when reading register from regcache
Andrew Burgess [Tue, 6 Mar 2018 13:20:14 +0000 (13:20 +0000)]
gdb/riscv: Fix type when reading register from regcache

Should use a ULONGEST when reading from the regcache.

gdb/ChangeLog:

* riscv-tdep.c (riscv_return_value): Change type to ULONGEST for
reading values from registers.

6 years agogdb/riscv: Additional print format string fixes
Andrew Burgess [Tue, 6 Mar 2018 13:05:34 +0000 (13:05 +0000)]
gdb/riscv: Additional print format string fixes

Another riscv format string fix.

gdb/ChangeLog:

* riscv-tdep.c (riscv_push_dummy_call): Use core_addr_to_string_nz
where appropriate.

6 years agogdb/riscv: Fixes to printf format strings
Andrew Burgess [Tue, 6 Mar 2018 12:31:07 +0000 (12:31 +0000)]
gdb/riscv: Fixes to printf format strings

Some of the format strings used in the new riscv target were incorrect,
resulting in build failures on some hosts.  This commit does the
following:

  1. Uses core_addr_to_string for formatting CORE_ADDR types.
  2. Fixes legacy use of stderr for logging in one place that got
     missed, instead gdb_stdlog is used.
  3. Re-indent a few printf related lines that were wrong.

This should resolve some (but not all) of the build failures the new
riscv target introduced.

gdb/ChangeLog:

* riscv-tdep.c (riscv_print_arg_location): Add header comment,
change parameter type.  Use GDB's print functions, and use
core_addr_to_string where appropriate.
(riscv_push_dummy_call): Use core_addr_to_string where
appropriate, update call to riscv_print_arg_location, and reindent
a few lines.
(riscv_return_value): Update call to riscv_print_arg_location.

6 years agogdb: Initial baremetal riscv support
Andrew Burgess [Thu, 9 Nov 2017 20:59:13 +0000 (20:59 +0000)]
gdb: Initial baremetal riscv support

This commit introduces basic support for baremetal RiscV as a GDB
target.  This target is currently only tested against the RiscV software
simulator, which is not included as part of this commit.  The target has
been tested against the following RiscV variants: rv32im, rv32imc,
rv32imf, rv32imfc, rv64im, rv64imc, rv64imfd, rv64imfdc.

Across these variants we pass on average 34858 tests, and fail 272
tests, which is ~0.8%.

The RiscV has a feature of its ABI where structures with a single
floating point field, a single complex float field, or one float and
one integer field are treated differently for argument passing.  The
new test gdb.base/infcall-nested-structs.exp is added to cover this
feature.  As passing these structures should work on all targets then
I've made the test as a generic one, even though, for most targets,
there's probably nothing special about any of these cases.

gdb/ChangeLog:

* Makefile.in (ALL_TARGET_OBS): Add riscv-tdep.o
(HFILES_NO_SRCDIR): Add riscv-tdep.h.
(ALLDEPFILES): Add riscv-tdep.c
* configure.tgt: Add riscv support.
* riscv-tdep.c: New file.
* riscv-tdep.h: New file.
* NEWS: Mention new target.
* MAINTAINERS: Add entry for riscv.

gdb/testsuite/ChangeLog:

* gdb.base/infcall-nested-structs.exp: New file.
* gdb.base/infcall-nested-structs.c: New file.
* gdb.base/float.exp: Add riscv support.

6 years agogdb/amd64: Ignore zero sized fields when calling functions
Andrew Burgess [Fri, 2 Mar 2018 15:48:23 +0000 (15:48 +0000)]
gdb/amd64: Ignore zero sized fields when calling functions

In some cases passing an argument to a function on amd64, or attempting
to fetch the return value, can trigger an assertion failure within GDB.
An example of a type that would trigger such an error is:

  struct foo_t
  {
    long double a;
    struct {
      struct {
        /* Empty.  */
      } es1;
    } s1;
  };

GCC does permit empty structures, so we should probably support this.

The test that exposes this bug is in the next commit along with the
RiscV support.

gdb/ChangeLog:

* amd64-tdep.c (amd64_classify_aggregate): Ignore zero sized
fields within aggregates.

6 years agoAutomatic date update in version.in
GDB Administrator [Tue, 6 Mar 2018 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoUse binary search on dynamic relocations
H.J. Lu [Mon, 5 Mar 2018 11:44:46 +0000 (03:44 -0800)]
Use binary search on dynamic relocations

Replace linear search with binary search on dynamic relocations.  After
finding a match, scan backward to the first matching relocation, then
scan forward for a matching relocation with non-absolute symbol.

On Fedora 27 x86-64, time for "objdump -d" on libxul.so from RHEL 7.4
x86-64 went from

134.46user 0.12system 2:15.03elapsed

to

8.49user 0.14system 0:08.64elapsed

PR binutils/22911
* objdump.c (is_significant_symbol_name): Return TRUE for all
.plt* sections.
(find_symbol_for_address): Replace linear search with binary
search on dynamic relocations.

6 years agoPropagate gdb_disassembly_flags to btrace_print_lines
Simon Marchi [Mon, 5 Mar 2018 01:02:35 +0000 (20:02 -0500)]
Propagate gdb_disassembly_flags to btrace_print_lines

This function can take the flags as the gdb_disassembly_flags type
instead of int.

gdb/ChangeLog:

* record-btrace.c (btrace_print_lines): Change type of flags to
gdb_disassembly_flags.

6 years agoAutomatic date update in version.in
GDB Administrator [Mon, 5 Mar 2018 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoUse signal information to determine SIGTRAP type for FreeBSD.
John Baldwin [Sun, 4 Mar 2018 05:25:33 +0000 (21:25 -0800)]
Use signal information to determine SIGTRAP type for FreeBSD.

Use the signal code from siginfo_t to distinguish SIGTRAP events due
to trace traps (TRAP_TRACE) and software breakpoints (TRAP_BRKPT).
For software breakpoints, adjust the PC when the event is reported as
part of the API when supplying "stopped_by_sw_breakpoint".  Currently
FreeBSD only supports hardware watchpoints and breakpoints on x86
which are reported as trace traps.  Signal information is not used on
MIPS and sparc64 kernels which do not reliably report TRAP_BRKPT for
software breakpoints.

gdb/ChangeLog:

* fbsd-nat.c: Include "inf-ptrace.h".
(USE_SIGTRAP_SIGINFO): Conditionally define.
[USE_SIGTRAP_SIGINFO] (fbsd_handle_debug_trap): New function.
(fbsd_wait) [USE_SIGTRAP_SIGINFO]: Call "fbsd_handle_debug_trap".
[USE_SIGTRAP_SIGINFO] (fbsd_stopped_by_sw_breakpoint): New
function.
[USE_SIGTRAP_SIGINFO] (fbsd_supports_stopped_by_sw_breakpoint):
Likewise.
[USE_SIGTRAP_SIGINFO] (fbsd_supports_stopped_by_hw_breakpoint):
Likewise.
(fbsd_nat_add_target) [USE_SIGTRAP_SIGINFO]: Set
"stopped_by_sw_breakpoint", "supports_stopped_by_sw_breakpoint",
"supports_stopped_by_hw_breakpoint" target methods.

6 years agoAdd a new debug knob for the FreeBSD native target.
John Baldwin [Sun, 4 Mar 2018 05:25:33 +0000 (21:25 -0800)]
Add a new debug knob for the FreeBSD native target.

For now this just logs information about the state of the current LWP
for each STOPPED event in fbsd_wait().

gdb/ChangeLog:

* NEWS (Changes since GDB 8.1): Add "set/show debug fbsd-nat".
* fbsd-nat.c (debug_fbsd_nat): New variable.
(show_fbsd_nat_debug): New function.
(fbsd_wait): Log LWP info if "debug_fbsd_nat" is enabled.
(_initialize_fbsd_nat): Add "fbsd-nat" debug boolean command.

gdb/doc/ChangeLog:

* gdb.texinfo (Debugging Output): Document "set/show debug
fbsd-nat".

6 years agoImplement "to_stopped_by_hw_breakpoint" for x86 debug registers.
John Baldwin [Sun, 4 Mar 2018 05:25:33 +0000 (21:25 -0800)]
Implement "to_stopped_by_hw_breakpoint" for x86 debug registers.

Report that a thread is stopped by a hardware breakpoint if a non-data
watchpoint is set in DR6.  This change should be a no-op since a target
still needs to implement the "to_supports_stopped_by_hw_breakpoint"
method before this function is used.

gdb/ChangeLog:

* nat/x86-dregs.c (x86_dr_stopped_by_hw_breakpoint): New function.
* nat/x86-dregs.h (x86_dr_stopped_by_hw_breakpoint): New
prototype.
* x86-nat.c (x86_stopped_by_hw_breakpoint): New function.
(x86_use_watchpoints): Set "stopped_by_hw_breakpoint" target
method.

6 years agoAutomatic date update in version.in
GDB Administrator [Sun, 4 Mar 2018 00:00:48 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoPR ld/21900: MIPS: Fix relocation processing with undefined symbols
James Cowgill [Sat, 3 Mar 2018 15:49:21 +0000 (15:49 +0000)]
PR ld/21900: MIPS: Fix relocation processing with undefined symbols

Currently, when `mips_elf_calculate_relocation' is asked to relocate an
undefined symbol, it reports an error or a warning and immediately
returns without performing the relocation.  This is fine if the link
fails, but if unresolved_syms_in_objects == RM_GENERATE_WARNING, the
link will continue and output some unrelocated code, which is a
regression from commit e7e2196da3f0 ("MIPS/BFD: Correctly report
undefined relocations").

Fix this by continuing after calling the `undefined_symbol' hook unless
this is an error condition.

bfd/
PR ld/21900
* elfxx-mips.c (mips_elf_calculate_relocation): Only return
after calling `undefined_symbol' hook if this is an error
condition.  Assume the value of 0 for the symbol requested
otherwise.

ld/
PR ld/21900
* testsuite/ld-mips-elf/undefined-warn.d: New test.
* testsuite/ld-mips-elf/undefined.s: Add padding at the end.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.

6 years agohandle_general_set: Remove useless xstrdup
Simon Marchi [Sat, 3 Mar 2018 04:27:46 +0000 (23:27 -0500)]
handle_general_set: Remove useless xstrdup

Unless I'm missing something very obvious, this xstrdup seems
unnecessary to me.  We can pass "mode" directly to sprintf.

gdb/gdbserver/ChangeLog:

* server.c (handle_general_set): Remove unnecessary xstrdup.

6 years agoRemove free_char_ptr_vec
Simon Marchi [Sat, 3 Mar 2018 04:22:10 +0000 (23:22 -0500)]
Remove free_char_ptr_vec

Nothing is using it anymore.

gdb/ChangeLog:

* common/gdb_vecs.c (free_char_ptr_vec): Remove.
* common/gdb_vecs.h (free_char_ptr_vec): Remove.

6 years agoC++ify charsets
Simon Marchi [Sat, 3 Mar 2018 04:22:09 +0000 (23:22 -0500)]
C++ify charsets

This patch makes the charset list an std::vector instead of a VEC.
Because we must have access to the raw pointers as a simple array, we
can't use a vector of unique_ptr/unique_xmalloc_ptr.  Therefore, wrap
the vector in a simple class to facilitate the cleanup.  This allows
removing one usage of free_char_ptr_vec.

gdb/ChangeLog:

* charset.c (struct charset_vector): New.
(charsets): Change type to charset_vector.
(find_charset_names): Adjust.
(add_one): Adjust.
(_initialize_charset): Adjust.

6 years agoMake program_space::deleted_solibs a vector of std::string
Simon Marchi [Sat, 3 Mar 2018 04:22:08 +0000 (23:22 -0500)]
Make program_space::deleted_solibs a vector of std::string

This allows removing a usage of free_char_ptr_vec.

gdb/ChangeLog:

* progspace.h (struct program_space) <deleted_solibs>: Change
type to std::vector<std::string>.
* progspace.c (clear_program_space_solib_cache): Adjust.
* breakpoint.c (print_solib_event): Adjust.
(check_status_catch_solib): Adjust.
* solib.c (update_solib_list): Adjust.
* ui-out.h (class ui_out) <field_string>: New overload.
* ui-out.c (ui_out::field_string): New overload.

6 years agoC++ify program_space
Simon Marchi [Sat, 3 Mar 2018 04:22:08 +0000 (23:22 -0500)]
C++ify program_space

This patch makes program_space a C++ object by adding a
constructor/destructor, giving default values to fields, and using
new/delete.

gdb/ChangeLog:

* progspace.h (struct program_space): Add constructor and
destructor, initialize fields.
(add_program_space): Remove.
* progspace.c (add_program_space): Rename to...
(program_space::program_space): ... this.
(release_program_space): Rename to...
(program_space::~program_space): ... this.
(delete_program_space): Use delete to delete program_space.
(initialize_progspace): Use new to allocate program_space.
* inferior.c (add_inferior_with_spaces): Likewise.
(clone_inferior_command): Likewise.
* infrun.c (follow_fork_inferior): Likewise.
(handle_vfork_child_exec_or_exit): Likewise.

6 years agoMake delim_string_to_char_ptr_vec return an std::vector
Simon Marchi [Sat, 3 Mar 2018 04:22:06 +0000 (23:22 -0500)]
Make delim_string_to_char_ptr_vec return an std::vector

This patch makes delim_string_to_char_ptr_vec and all related functions
use std::vector of gdb::unique_xmalloc_ptr.  This allows getting rid of
make_cleanup_free_char_ptr_vec.  Returning a vector of
unique_xmalloc_ptr instead of std::string allows to minimize the impacts
on the calling code.  We can evaluate later whether we could/should
return a vector of std::strings instead.

gdb/ChangeLog:

* common/gdb_vecs.h (make_cleanup_free_char_ptr_vec): Remove.
(delim_string_to_char_ptr_vec): Return std::vector of
gdb::unique_xmalloc_ptr.
(dirnames_to_char_ptr_vec_append): Take std::vector of
gdb::unique_xmalloc_ptr.
(dirnames_to_char_ptr_vec): Return std::vector of
gdb::unique_xmalloc_ptr.
* common/gdb_vecs.c (delim_string_to_char_ptr_vec_append):
Take std::vector of gdb::unique_xmalloc_ptr, adjust the code.
(delim_string_to_char_ptr_vec): Return an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
(dirnames_to_char_ptr_vec_append): Take an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
(dirnames_to_char_ptr_vec): Return an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
* auto-load.c (auto_load_safe_path_vec): Change type to
std::vector of gdb::unique_xmalloc_ptr.
(auto_load_expand_dir_vars): Return an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
(auto_load_safe_path_vec_update): Adjust.
(filename_is_in_auto_load_safe_path_vec): Adjust.
(auto_load_objfile_script_1): Adjust.
* build-id.c (build_id_to_debug_bfd): Adjust.
* linux-thread-db.c (thread_db_load_search): Adjust.
* source.c (add_path): Adjust.
(openp): Adjust.
* symfile.c (find_separate_debug_file): Adjust.
* utils.c (do_free_char_ptr_vec): Remove.
(make_cleanup_free_char_ptr_vec): Remove.

gdb/gdbserver/ChangeLog:

* server.c (parse_debug_format_options): Adjust to
delim_string_to_char_ptr_vec changes.
* thread-db.c (thread_db_load_search): Adjust to
dirnames_to_char_ptr_vec changes.

6 years agoopcodes error messages
Alan Modra [Thu, 1 Mar 2018 21:53:50 +0000 (08:23 +1030)]
opcodes error messages

Another patch aimed at making binutils comply with the GNU coding
standard.  The generated files require
https://sourceware.org/ml/cgen/2018-q1/msg00004.html

cpu/
* frv.opc: Include opintl.h.
(add_next_to_vliw): Use opcodes_error_handler to print error.
Standardize error message.
(fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise.
opcodes/
* sysdep.h (opcodes_error_handler): Define.
(_bfd_error_handler): Declare.
* Makefile.am: Remove stray #.
* opc2c.c (main): Remove bogus -l arg handling.  Print "DO NOT
EDIT" comment.
* aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c,
* d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c,
* riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use
opcodes_error_handler to print errors.  Standardize error messages.
* msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise,
and include opintl.h.
* nds32-asm.c: Likewise, and include sysdep.h and opintl.h.
* i386-gen.c: Standardize error messages.
* msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate.
* Makefile.in: Regenerate.
* epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c,
* epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c,
* fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c,
* frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c,
* iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c,
* lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c,
* m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c,
* m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c,
* mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c,
* mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c,
* or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c,
* xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c,
* xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.

6 years agoAutomatic date update in version.in
GDB Administrator [Sat, 3 Mar 2018 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoConditionally include "<windows.h>" on common/pathstuff.c (and unbreak build on mingw*)
Sergio Durigan Junior [Thu, 1 Mar 2018 20:11:44 +0000 (15:11 -0500)]
Conditionally include "<windows.h>" on common/pathstuff.c (and unbreak build on mingw*)

commit b4987c956dfa44ca9fd8552f63e15f5fa094b2a4
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date:   Fri Feb 9 18:44:59 2018 -0500

    Create new common/pathstuff.[ch]

Introduced a regression when compiling for mingw*:

  /gdb/common/pathstuff.c: In function 'gdb::unique_xmalloc_ptr<char>
  gdb_realpath(const char*)':
  /gdb/common/pathstuff.c:56:14: error: 'MAX_PATH' was not declared in this scope
       char buf[MAX_PATH];
^
  /gdb/common/pathstuff.c:57:5: error: 'DWORD' was not declared in this scope
       DWORD len = GetFullPathName (filename, MAX_PATH, buf, NULL);
       ^
  /gdb/common/pathstuff.c:57:11: error: expected ';' before 'len'
       DWORD len = GetFullPathName (filename, MAX_PATH, buf, NULL);
     ^
  /gdb/common/pathstuff.c:63:9: error: 'len' was not declared in this scope
       if (len > 0 && len < MAX_PATH)
   ^
  /gdb/common/pathstuff.c:64:54: error: 'buf' was not declared in this scope
 return gdb::unique_xmalloc_ptr<char> (xstrdup (buf));
^
  make[2]: *** [pathstuff.o] Error 1

The proper fix is to conditionally include "<windows.h>".  This commit
does that, without introducing any regressions as per tests made by
our BuildBot.

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

PR gdb/22907
* common/pathstuff.c: Conditionally include "<windows.h>".

6 years ago[GDB/testsuite] Use %progbits in watch-loc.c
Thomas Preud'homme [Fri, 2 Mar 2018 11:51:34 +0000 (11:51 +0000)]
[GDB/testsuite] Use %progbits in watch-loc.c

While using @progbits in .pushsection work on some targets, it does not
work on arm target where this introduces a comment. This patch replaces
its use in gdb.dlang/watch-loc.c and gdb.mi/dw2-ref-missing-frame-func.c
by %progbits which should work on all targets since it is used in
target-independent elf/section7.s GAS test.

2018-03-02  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gdb/testsuite/
* gdb.dlang/watch-loc.c: Use %progbits instead of @progbits.
* gdb.mi/dw2-ref-missing-frame-func.c: Likewise.

6 years agoEnsure 8-byte alignment for AArch64 stubs.
Jim Wilson [Fri, 2 Mar 2018 10:47:25 +0000 (10:47 +0000)]
Ensure 8-byte alignment for AArch64 stubs.

PR 22903
bfd * elfnn-aarch64.c (_bfd_aarch64_resize_stubs): Add 8 bytes for branch
and nop instead of 4.
(elfNN_arch64_build_stubs): Add nop after branch.  Increase size by
8 instead of 4.

ld * emultempl/aarch64elf.em (elf${ELFSIZE}_aarch64_add_stub_section):
Give stub_sec 8 byte alignment.
* emulparams/aarch64cloudabi.sh (NOP): Set to 0x1f2003d5.
* emulparams/aarch64elf.sh (NOP): Likewise.
* emulparams/aarch64elf32.sh (NOP): Likewise.
* emulparams/aarch64fbsd.sh (NOP): Likewise.
* emulparams/aarch64linux.sh (NOP): Likewise.
* emulparams/aarch64linux32.sh (NOP): Likewise.
* testsuite/ld-aarch64/erratum835769.d: Adjust for added nop.
* testsuite/ld-aarch64/erratum843419.d: Likewise.
* testsuite/ld-aarch64/farcall-b-defsym.d: Likewise.
* testsuite/ld-aarch64/farcall-b-none-function.d: Likewise.
* testsuite/ld-aarch64/farcall-b-plt.d: Likewise.
* testsuite/ld-aarch64/farcall-b-section.d: Likewise.
* testsuite/ld-aarch64/farcall-b.d: Likewise.
* testsuite/ld-aarch64/farcall-back.d: Likewise.
* testsuite/ld-aarch64/farcall-bl-defsym.d: Likewise.
* testsuite/ld-aarch64/farcall-bl-none-function.d: Likewise.
* testsuite/ld-aarch64/farcall-bl-plt.d: Likewise.
* testsuite/ld-aarch64/farcall-bl-section.d: Likewise.
* testsuite/ld-aarch64/farcall-bl.d: Likewise.

6 years ago[ARM] Fix NULL dereference of march_ext_opt
Thomas Preud'homme [Fri, 2 Mar 2018 10:46:32 +0000 (10:46 +0000)]
[ARM] Fix NULL dereference of march_ext_opt

Commit 4d354d8b8932d450c77fd52f3501662827523014 introduced a NULL
pointer dereference by replacing a pointer assignment by a pointer
dereference assignment without adding a NULL pointer check. This patch
fixes it.

2018-03-02  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gas/
* config/tc-arm.c (md_begin): Add NULL pointer check before
dereferencing march_ext_opt.

6 years agoAutomatic date update in version.in
GDB Administrator [Fri, 2 Mar 2018 00:00:32 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoImprove gcore shell quoting and portability
Georg Sauthoff [Thu, 1 Mar 2018 22:23:31 +0000 (17:23 -0500)]
Improve gcore shell quoting and portability

The gcore shell script (gdb/gcore.in) doesn't quote its variables
enough.

For example, trying to write a core file with - say - a space
ungraciously fails like this:

    $ gcore -o 'foo bar' 6270
    /usr/bin/gcore: line 92: [: foo: binary operator expected
    gcore: failed to create foo bar.6270

Similarly, one can inject meta characters like * (by accident)
that may yield unexpected results, e.g. as in:

    $ gcore -o foobar '*'

This change fixes these issues in several places.

Aso, since the script uses array syntax, the patch changes the
the shell in the first line from `/bin/sh` to /bin/bash`.

POSIX doesn't specify the array syntax for shell, thus, the
script doesn't work on systems where /bin/sh is linked to - say -
dash.

Since the source gcore.in already is processed by a pre-processor
one could even auto-detect the path to bash and thus dynamically
generate the first line. For systems where bash isn't available
via /bin/bash. But I think this would be overkill and /bin/bash
is good enough as most systems probably have it.

gdb/ChangeLog:

PR gdb/22888
* gcore.in: Quote variables and switch interpreter to bash.

6 years agoRISC-V: Fix symbol size bug when relaxation deletes bytes.
Jim Wilson [Thu, 1 Mar 2018 22:17:57 +0000 (14:17 -0800)]
RISC-V: Fix symbol size bug when relaxation deletes bytes.

bfd/
PR 22756
* elfnn-riscv.c (riscv_relax_delete_bytes): When adjust st_size, use
else if instead of if.

6 years agoFix Rust enum test failures
Tom Tromey [Wed, 28 Feb 2018 15:49:51 +0000 (08:49 -0700)]
Fix Rust enum test failures

Pedro pointed out that some Rust tests were failing after the recent
enum change.  I was able to reproduce this even with the most current
Rust compiler -- no test was failing, but rather the gdb internal
error was causing an "untested" result, which I didn't notice.

The internal error is caused by a bad assertion in
alloc_discriminant_info.  This happened because, in an earlier version
of the patch, the discriminant could only appear at index 0.  However,
it can now appear anywhere.  This patch fixes the assertion in the
obvious way, and adds a second assertion to ensure that the
discriminant is also correct.

Fixing this revealed a real failure, which was caused by using the
wrong base name when computing the name of a univariant enum's sole
member.  This is also fixed here.

Tested by running the gdb.rust tests with rustc 1.23 and
double-checking the summary:

    # of expected passes 276

Note that if you try this yourself, it is still possible to get an
"untested" result from traits.exp if your Rust compiler is old enough.

2018-03-01  Tom Tromey  <tom@tromey.com>

* dwarf2read.c (alloc_discriminant_info): Fix default_index
assertion.  Add assertion for discriminant_index.
(quirk_rust_enum): Use correct base type name in univariant case.

6 years ago[ARM] Clean up selection of feature bits
Thomas Preud'homme [Thu, 1 Mar 2018 16:22:28 +0000 (16:22 +0000)]
[ARM] Clean up selection of feature bits

I've always found the code in ARM backend of gas to control what
CPU/architecture and FPU are selected by the user and to support
autodetection of features complex and confusing. Chief among the
issues I have with that code is the lack of comments to explain
the meaning of the various variables. This patch addresses that
and much more:

- add comments to explain meaning of all arm_feature_set variables
- keep track of currently selected CPU, extensions and FPU in a separate
  set of new variables
- make naming of variable more consistent
- remove dead code
- simplify handling of extensions

The overall approach is as follows:

* restrict m*_opt variable to hold the feature bits of the
  corresponding mcpu/march/mfpu command-line options
* record selected CPU, extensions and FPU in new selected_* during
  md_begin
* whenever a .cpu/.arch/.arch_extension/.fpu directive is met, update
  the corresponding selected_* variables (eg. selected_arch, then
  selected_cpu for a .cpu or .arch directive) and then finally
  cpu_variant from them
* pass extension feature set pointer by value to arm_parse_extension
  since it's only ever called from arm_parse_cpu and arm_parse_arch
  which allocate the extension feature set themselves
* likewise, remove allocation from s_arm_arch_extension since the use
  of arm_feature_set structure for selected_ext rather than a pointer
  alleviate the need for it
* in autodetection mode, only set all CPU fits in cpu_variant but leave
  selected_cpu* variables unset
* in md_begin, remove dead "else if" to set a default FPU when no FPU
  was selected. Setting a default FPU based on CPU as did the code
  before it turn dead should be based on the default FPU field of the
  CPU and architecture table as will be done in a separate patch. Logic
  is wrong anyway since it sets VFP2 as default FPU for Armv6-M and
  Armv7-M

Hopefully that should be enough to understand the change but if not feel
free to ask questions about the patch. While I believe the new code is
easier to understand, it remains complex and the old one was even more
complex so the change is difficult to understand.

2018-03-01  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gas/
* config/tc-arm.c (cpu_variant, arm_arch_used, thumb_arch_used,
legacy_cpu, legacy_fpu, mcpu_cpu_opt, dyn_mcpu_ext_opt,
mcpu_fpu_opt, march_cpu_opt, dyn_march_ext_opt, march_fpu_opt,
mfpu_opt, object_arch, selected_cpu): Comment meaning of variables.
(dyn_mcpu_ext_opt): Also rename into ...
(mcpu_ext_opt): This.
(dyn_march_ext_opt): Also rename into ...
(march_ext_opt): This.
(object_arch): Also rename into ...
(selected_object_arch): This and make it a plain arm_feature_set
structure.
(selected_arch, selected_ext, selected_fpu): New static variables.
(mark_feature_used): Fix comments, feature is marked as used iff it is
currently allowed.
(do_bx): Adapt to change in name and type of object_arch.
(md_begin): Set selected_arch rather than mcpu_cpu_opt, selected_ext
rather than dyn_mcpu_ext_opt and selected_fpu rather than mfpu_opt.
Remove dead code to set default FPU if architecture version is greater
than 5.  Set all CPU bits of cpu_variant directly in autodection
leaving mcpu_cpu_opt, selected_arch and selected_cpu unset.
(arm_parse_extension): Take extension feature set pointer parameter by
value rather than by pointer.  Remove allocation code.  Adapt code
accordingly.
(arm_parse_cpu): Adapt to variable renaming and changes in
arm_parse_extension () signature.
(arm_parse_arch): Likewise.
(aeabi_set_public_attributes): Also set selected_arch and selected_ext
in addition to selected_cpu.  Set flags_arch and flags_ext from them
instead of selected_cpu.  Adapt to variables renaming and type change.
(arm_md_post_relax): Adapt to variable renaming.
(s_arm_cpu): Set selcted_cpu_cpu and selected_ext instead of
mcpu_cpu_opt and dyn_mcpu_ext_opt.  Set selected_cpu from them and
cpu_variant from selected_cpu and selected_fpu.
(s_arm_arch): Likewise.
(s_arm_object_arch): Adapt to variable renaming.
(s_arm_arch_extension): Use ARM_CPU_IS_ANY instead of checking feature
set against arm_any.  Check selected_arch rather than *mcpu_cpu_opt.
Set selected_ext rather than *dyn_mcpu_ext_opt and remove allocation
code.
(s_arm_fpu): Set selected_fpu instead of mfpu_opt.  Set all CPU feature
bits if in autodetection mode.

6 years agoPrevent illegal memory accesses triggerd by intger overflow when parsing corrupt...
Nick Clifton [Thu, 1 Mar 2018 16:14:08 +0000 (16:14 +0000)]
Prevent illegal memory accesses triggerd by intger overflow when parsing corrupt DWARF information on a 32-bit host.

PR 22905
* dwarf.c (display_debug_ranges): Check that the offset loaded
from the range_entry structure is valid.

6 years agoPropagate record_print_flags
Simon Marchi [Thu, 1 Mar 2018 15:51:21 +0000 (10:51 -0500)]
Propagate record_print_flags

These flags are returned as an int by get_call_history_modifiers, and
get cast back to record_print_flags in the btrace code.  Instead, we can
make the arguments of that type from start to end.

gdb/ChangeLog:

* record.c (get_call_history_modifiers): Return a
record_print_flags.
(cmd_record_call_history): Adjust.
* record-btrace.c (record_btrace_call_history): Adjust.
(record_btrace_call_history_range): Adjust.
(record_btrace_call_history_from): Adjust.
* target-debug.h (target_debug_print_record_print_flags): New.
* target-delegates.c: Re-generate.
* target.c (target_call_history): Change flags type.
(target_call_history_from): Likewise.
(target_call_history_range): Likewise.
* target.h (struct target_ops) <target_call_history>: Likewise.
(target_call_history_from): Likewise.
(target_call_history_range): Likewise.

6 years agox86: Encode AVX256/AVX512 vpsub[bwdq] with VEX128/EVEX128
H.J. Lu [Thu, 1 Mar 2018 14:08:04 +0000 (06:08 -0800)]
x86: Encode AVX256/AVX512 vpsub[bwdq] with VEX128/EVEX128

When 2 source registers are identical, AVX256 and AVX512 vpsub[bwdq]
instructions can be encoded with VEX128 or EVEX128 encodings.

gas/

* config/tc-i386.c (optimize_encoding): Optimize AVX256 and
AVX512 vpsub[bwdq] instructions.
* testsuite/gas/i386/optimize-1.s: Add tests for AVX256 and
AVX512 vpsub[bwdq] instructions.
* testsuite/gas/i386/x86-64-optimize-2.s: Likewise.
* testsuite/gas/i386/optimize-1.d: Updated.
* testsuite/gas/i386/x86-64-optimize-2.d: Likewise.

opcodes/

* * i386-opc.tbl: Add "Optimize" to AVX256 and AVX512
vpsub[bwdq] instructions.
* i386-tbl.h: Regenerated.

6 years agobtrace, gdbserver: check btrace target pointers
Markus Metzger [Mon, 26 Feb 2018 10:59:43 +0000 (11:59 +0100)]
btrace, gdbserver: check btrace target pointers

By removing the supports_btrace gdbserver target method we relied on GDB
trying to enable branch tracing and failing on the attempt.

For targets that do not provide the btrace methods, however, an initial
request from GDB for the branch trace configuration to detect whether
gdbserver is already recording resulted in a protocol error.

Have the btrace target methods throw a "Target does not suppor branch
tracing" error and be prepared to handle exceptions in all functions that
call btrace target methods.  We therefore turn the target_* macros into
static inline functions.

Also remove the additional btrace target method checks that resulted in
the above protocol error.

Thanks to Maciej W. Rozycki <macro@mips.com> for reporting this.

gdbserver/
* target.h (target_enable_btrace, target_disable_btrace)
(target_read_btrace, target_read_btrace_conf): Turn macro into
inline function.  Throw error if target method is not defined.
* server.c (handle_qxfer_btrace, handle_qxfer_btrace_conf): Remove
check for btrace target method.  Be prepared to handle exceptions
from btrace target methods.

6 years agoAutomatic date update in version.in
GDB Administrator [Thu, 1 Mar 2018 00:00:38 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoAdd missing translations to ALL_LINGUAS
Alan Modra [Wed, 28 Feb 2018 21:56:51 +0000 (08:26 +1030)]
Add missing translations to ALL_LINGUAS

binutils/
* configure.ac (ALL_LINGUAS): Add sr.  Sort.
* configure: Regenerate.
gas/
* configure.ac (ALL_LINGUAS): Add uk.  Sort.
* configure: Regenerate.
gprof/
* configure.ac (ALL_LINGUAS): Add it, ro, ru, uk.  Sort.
* configure: Regenerate.
ld/
* configure.ac (ALL_LINGUAS): Add ja.  Sort.
* configure: Regenerate.
opcodes/
* configure.ac (ALL_LINGUAS): Sort.
* configure: Regenerate.

6 years agocorrect ft32 reloc range test
Alan Modra [Wed, 28 Feb 2018 21:51:11 +0000 (08:21 +1030)]
correct ft32 reloc range test

* elf32-ft32.c (ft32_info_to_howto_rela): Correct range test.

6 years agoChange order of error message printed when gdbserver can't find CWD
Sergio Durigan Junior [Wed, 28 Feb 2018 16:43:48 +0000 (11:43 -0500)]
Change order of error message printed when gdbserver can't find CWD

I forgot to address Pedro's comment about my last patch and change the
order of the message printed when getcwd returns NULL on gdbserver.
This obvious commit does it.

gdb/gdbserver/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>

* server.c (captured_main): Change order of error message printed
when the current working directory cannot be found.

6 years agoMake gdbserver work with filename-only binaries
Sergio Durigan Junior [Fri, 9 Feb 2018 23:54:41 +0000 (18:54 -0500)]
Make gdbserver work with filename-only binaries

Simon mentioned on IRC that, after the startup-with-shell feature has
been implemented on gdbserver, it is not possible to specify a
filename-only binary, like:

  $ gdbserver :1234 a.out
  /bin/bash: line 0: exec: a.out: not found
  During startup program exited with code 127.
  Exiting

This happens on systems where the current directory "." is not listed
in the PATH environment variable.  Although including "." in the PATH
variable is a possible workaround, this can be considered a regression
because before startup-with-shell it was possible to use only the
filename (due to reason that gdbserver used "exec*" directly).

The idea of the patch is to verify if the program path provided by the
user (or by the remote protocol) contains a directory separator
character.  If it doesn't, it means we're dealing with a filename-only
binary, so we call "gdb_abspath" to properly expand it and transform
it into a full path.  Otherwise, we leave the program path untouched.
This mimicks the behaviour seen on GDB (look at "openp" and
"attach_inferior", for example).

I am also submitting a testcase which exercises the scenario described
above.  This test requires gdbserver to be executed in a different CWD
than the original, so I also created a helper function, "with_cwd" (on
testsuite/lib/gdb.exp), which takes care of cd'ing into and out of the
specified dir.

Built and regtested on BuildBot, without regressions.

gdb/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>
    Simon Marchi  <simon.marchi@polymtl.ca>

* common/common-utils.c: Include "sys/stat.h".
(is_regular_file): Move here from "source.c"; change return
type to "bool".
* common/common-utils.h (is_regular_file): New prototype.
* common/pathstuff.c (contains_dir_separator): New function.
* common/pathstuff.h (contains_dir_separator): New prototype.
* source.c: Don't include "sys/stat.h".
(is_regular_file): Move to "common/common-utils.c".

gdb/gdbserver/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>

* server.c: Include "filenames.h" and "pathstuff.h".
(program_name): Delete variable.
(program_path): New anonymous class.
(get_exec_wrapper): Use "program_path" instead of
"program_name".
(handle_v_run): Likewise.
(captured_main): Likewise.
(process_serial_event): Likewise.

gdb/testsuite/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>

* gdb.server/abspath.exp: New file.
* lib/gdb.exp (with_cwd): New procedure.

6 years agoCreate new common/pathstuff.[ch]
Sergio Durigan Junior [Fri, 9 Feb 2018 23:44:59 +0000 (18:44 -0500)]
Create new common/pathstuff.[ch]

This commit moves the path manipulation routines found on utils.c to a
new common/pathstuff.c, and updates the Makefile.in's accordingly.
The routines moved are "gdb_realpath", "gdb_realpath_keepfile" and
"gdb_abspath".

This will be needed because gdbserver will have to call "gdb_abspath"
on my next patch, which implements a way to expand the path of the
inferior provided by the user in order to allow specifying just the
binary name when starting gdbserver, like:

  $ gdbserver :1234 a.out

With the recent addition of the startup-with-shell feature on
gdbserver, this scenario doesn't work anymore if the user doesn't have
the current directory listed in the PATH variable.

I had to do a minor adjustment on "gdb_abspath" because we don't have
access to "tilde_expand" on gdbserver, so now the function is using
"gdb_tilde_expand" instead.  Otherwise, the code is the same.

Regression tested on the BuildBot, without regressions.

gdb/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (COMMON_SFILES): Add "common/pathstuff.c".
(HFILES_NO_SRCDIR): Add "common/pathstuff.h".
* auto-load.c: Include "common/pathstuff.h".
* common/common-def.h (current_directory): Move here.
* common/gdb_tilde_expand.c (gdb_tilde_expand_up): New
function.
* common/gdb_tilde_expand.h (gdb_tilde_expand_up): New
prototype.
* common/pathstuff.c: New file.
* common/pathstuff.h: New file.
* compile/compile.c: Include "common/pathstuff.h".
* defs.h (current_directory): Move to "common/common-defs.h".
* dwarf2read.c: Include "common/pathstuff.h".
* exec.c: Likewise.
* guile/scm-safe-call.c: Likewise.
* linux-thread-db.c: Likewise.
* main.c: Likewise.
* nto-tdep.c: Likewise.
* objfiles.c: Likewise.
* source.c: Likewise.
* symtab.c: Likewise.
* utils.c: Include "common/pathstuff.h".
(gdb_realpath): Move to "common/pathstuff.c".
(gdb_realpath_keepfile): Likewise.
(gdb_abspath): Likewise.
* utils.h (gdb_realpath): Move to "common/pathstuff.h".
(gdb_realpath_keepfile): Likewise.
(gdb_abspath): Likewise.

gdb/gdbserver/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (SFILES): Add "$(srcdir)/common/pathstuff.c".
(OBJS): Add "pathstuff.o".
* server.c (current_directory): New global variable.
(captured_main): Initialize "current_directory".

6 years agotestsuite: Restore gdb_is_target_remote_prompt
Simon Marchi [Wed, 28 Feb 2018 13:58:25 +0000 (08:58 -0500)]
testsuite: Restore gdb_is_target_remote_prompt

In patch

  Add test for load command
  3275ef477498e0500d7ea440f1bc51787acf4610

I removed gdb_is_target_remote_prompt, but did not realize it was used
in mi_is_target_remote.  This makes the gdb.mi/mi-nonstop.exp crash, for
example:

  ERROR: (DejaGnu) proc "gdb_is_target_remote_prompt {[(]gdb[)]
  }" does not exist.
  The error code is TCL LOOKUP COMMAND gdb_is_target_remote_prompt
  The info on the error is:
  invalid command name "gdb_is_target_remote_prompt"
      while executing
  "::tcl_unknown gdb_is_target_remote_prompt {[(]gdb[)]
  }"
      ("uplevel" body line 1)
      invoked from within
  "uplevel 1 ::tcl_unknown $args"

This patch restores it.

gdb/testsuite/ChangeLog:

* lib/gdb.exp (gdb_is_target_1): Add prompt_regexp parameter and
use it.
(gdb_is_target_remote_prompt): New proc.
(gdb_is_target_remote): Use gdb_is_target_remote_prompt.
(gdb_is_target_native): Pass prompt parameter to
gdb_is_target_1.

6 years agoCatch integer overflows/underflows when parsing corrupt DWARF FORM blocks.
Nick Clifton [Wed, 28 Feb 2018 11:50:49 +0000 (11:50 +0000)]
Catch integer overflows/underflows when parsing corrupt DWARF FORM blocks.

PR 22895
PR 22893
* dwarf2.c (read_n_bytes): Replace size parameter with dwarf_block
pointer.  Drop unused abfd parameter.  Check the size of the block
before initialising the data field.  Return the end pointer if the
size is invalid.
(read_attribute_value): Adjust invocations of read_n_bytes.

6 years agoPR22887, null pointer dereference in aout_32_swap_std_reloc_out
Alan Modra [Wed, 28 Feb 2018 11:39:50 +0000 (22:09 +1030)]
PR22887, null pointer dereference in aout_32_swap_std_reloc_out

PR 22887
* aoutx.h (swap_std_reloc_in): Correct r_index bound check.

6 years agoRemove any trailing directory separator from ld_canon_sysroot and adjust ld_canon_sys...
Douglas B Rupp [Wed, 28 Feb 2018 11:44:26 +0000 (11:44 +0000)]
Remove any trailing directory separator from ld_canon_sysroot and adjust ld_canon_sysroot_len.

The problem was the ld expect libiberty/lrealpath() to always return a
path, but in some cases it returns a prefix. It seemed like too much of
an earthquake to propose a fix to lrealpath.

* ldmain.c (main): Remove directory separator, if any, from the
end of the canonicalized sysroot.

6 years agoFix potential integer overflow when reading corrupt dwarf1 debug information.
Nick Clifton [Wed, 28 Feb 2018 10:13:54 +0000 (10:13 +0000)]
Fix potential integer overflow when reading corrupt dwarf1 debug information.

PR 22894
* dwarf1.c (parse_die): Check the length of form blocks before
advancing the data pointer.