binutils-gdb.git
7 years ago[ARC] Enhance enter/leave mnemonics.
Claudiu Zissulescu [Tue, 25 Apr 2017 15:07:00 +0000 (17:07 +0200)]
[ARC] Enhance enter/leave mnemonics.

enter/leave mnemonics are enhanced to not only accept register ranges
but also single register (i.e., r13) or even no GPR register at all.

gas/
2017-04-25  Claudiu Zissulescu  <claziss@synopsys.com>

* testsuite/gas/arc/leave_enter.d: Update test.
* testsuite/gas/arc/leave_enter.s: Likewise.

opcodes/
2017-04-25  Claudiu Zissulescu  <claziss@synopsys.com>

* arc-dis.c (print_insn_arc): Smartly print enter/leave mnemonics.
* arc-opc.c (insert_r13el): New function.
(R13_EL): Define.
* arc-tbl.h: Add new enter/leave variants.

7 years ago[ARC] Prefer NOP instead of MOV 0,0
Claudiu Zissulescu [Tue, 25 Apr 2017 15:07:00 +0000 (17:07 +0200)]
[ARC] Prefer NOP instead of MOV 0,0

NOP and MOV 0,0 are having the same encoding. As MOV mnemonic is
located before NOP in the instruction table, the disassembler prints
MOV 0,0 for NOP. Reorder the instructions such that NOP is first.

gas/
2017-04-25  Claudiu Zissulescu  <claziss@synopsys.com>

* testsuite/gas/arc/b.d: Update test.
* testsuite/gas/arc/noargs_hs.d: Likewise.

opcode/
2017-04-25  Claudiu Zissulescu  <claziss@synopsys.com>

* arc-tbl.h: Reorder NOP entry to be before MOV instructions.

7 years agoChange gdbarch_wchar_bit for AArch64 and ARM
Yao Qi [Tue, 25 Apr 2017 14:15:54 +0000 (15:15 +0100)]
Change gdbarch_wchar_bit for AArch64 and ARM

The size of wchar_t on AArch64 and ARM is 4-byte, so we can use the
default value (4*TARGET_CHAR_BIT).

This patch fixes some fails in gdb.cp/wide_char_types.exp on
aarch64-linux.

gdb:

2017-04-25  Yao Qi  <yao.qi@linaro.org>

* aarch64-tdep.c (aarch64_gdbarch_init): Don't call
set_gdbarch_wchar_bit.
* arm-tdep.c (arm_gdbarch_init): Likewise.

7 years agoMIPS16/opcodes: Add `-M no-aliases' disassembler option help text
Maciej W. Rozycki [Tue, 25 Apr 2017 10:49:37 +0000 (11:49 +0100)]
MIPS16/opcodes: Add `-M no-aliases' disassembler option help text

Complement commit 986e18a5a9fd ("Add a second 'pinfo' member to
mips_opcode to extend number of available bits"),
<https://sourceware.org/ml/binutils/2005-01/msg00261.html>, and add a
help text for the `-M no-aliases' disassembler option.

opcodes/
* mips-dis.c (print_mips_disassembler_options): Add
`no-aliases'.

7 years agoMIPS16/opcodes: Annotate instruction aliases
Maciej W. Rozycki [Tue, 25 Apr 2017 10:44:29 +0000 (11:44 +0100)]
MIPS16/opcodes: Annotate instruction aliases

Complement commit 986e18a5a9fd ("Add a second 'pinfo' member to
mips_opcode to extend number of available bits"),
<https://sourceware.org/ml/binutils/2005-01/msg00261.html>, and annotate
MIPS16 NOP, LA, DLA and the synthetic forms of LD and LW instructions as
aliases.  These correspond to MOVE, and the PC-relative ADDIU, DADDIU,
LD and LW hardware instructions respectively.

binutils/
* testsuite/binutils-all/mips/mips16-alias.d: New test.
* testsuite/binutils-all/mips/mips16-noalias.d: New test.
* testsuite/binutils-all/mips/mips16-alias.s: New test source.
* testsuite/binutils-all/mips/mips.exp: Run the new tests.

opcodes/
* mips16-opc.c (AL): New macro.
(mips16_opcodes): Mark "nop", "la", "dla", and synthetic forms
of "ld" and "lw" as aliases.

7 years agoMIPS/GAS: Correct BFD_RELOC_MIPS16_16_PCREL_S1 fixup size
Maciej W. Rozycki [Tue, 25 Apr 2017 09:20:14 +0000 (10:20 +0100)]
MIPS/GAS: Correct BFD_RELOC_MIPS16_16_PCREL_S1 fixup size

Correct the size of a BFD_RELOC_MIPS16_16_PCREL_S1 fixup made in
`md_convert_frag', fixing a bug introduced with commit c9775dde3277
("MIPS16: Add R_MIPS16_PC16_S1 branch relocation support)".  Add test
cases to verify that the overflow of this fixup's in-place addend is
still correctly detected.

gas/
* config/tc-mips.c (md_convert_frag): Correct
BFD_RELOC_MIPS16_16_PCREL_S1 fixup size.
* testsuite/gas/mips/mips16-branch-addend-4.d: New test.
* testsuite/gas/mips/mips16-branch-addend-5.d: New test.
* testsuite/gas/mips/mips16-branch-addend-5.l: New stderr
output.
* testsuite/gas/mips/mips16-branch-addend-4.s: New test source.
* testsuite/gas/mips/mips16-branch-addend-5.s: New test source.
* testsuite/gas/mips/mips.exp: Run the new tests.

7 years agoFix build on gcc < 5 (std::is_trivially_copyable missing)
Pedro Alves [Tue, 25 Apr 2017 09:58:57 +0000 (10:58 +0100)]
Fix build on gcc < 5 (std::is_trivially_copyable missing)

Ref: https://sourceware.org/ml/gdb-patches/2017-04/msg00660.html

Simply skip the poisoning on older compilers.

gdb/ChangeLog:
2017-04-25  Pedro Alves  <palves@redhat.com>

* common/poison.h [!HAVE_IS_TRIVIALLY_COPYABLE] (IsRelocatable)
(BothAreRelocatable, memcopy, memmove): Don't define.
* common/traits.h (__has_feature, HAVE_IS_TRIVIALLY_COPYABLE): New
macros.

7 years agogas: sparc: fix relaxation of CALL instruction into branches in a.out targets
Jose E. Marchesi [Tue, 25 Apr 2017 09:40:43 +0000 (02:40 -0700)]
gas: sparc: fix relaxation of CALL instruction into branches in a.out targets

This patch avoids CALL instructions to be optimized into branches if
the symbols referred to in the CALL instruction are not fully resolved
at the time the assembler writes its output.

Tested in sparc64-linux-gnu and sparc-sun-sunos4.1.3 targets.
No regressions.

gas/ChangeLog:

2017-04-25  Jose E. Marchesi  <jose.marchesi@oracle.com>

PR gas/21407
* config/tc-sparc.c (md_apply_fix): Do not transform `call'
instructions into branch instructions in fixups generating
additional relocations.
* testsuite/gas/sparc/call-relax.s: New file.
* testsuite/gas/sparc/call-relax.d: Likewise.
* testsuite/gas/sparc/call-relax-aout.d: Likewise.
* testsuite/gas/sparc/sparc.exp: Test call-relax and call-relax-aout.

7 years agoPoison non-POD memset & non-trivially-copyable memcpy/memmove
Pedro Alves [Tue, 25 Apr 2017 00:27:41 +0000 (01:27 +0100)]
Poison non-POD memset & non-trivially-copyable memcpy/memmove

This patch catches invalid initialization of non-POD types with
memset, at compile time.

This is what I used to catch the problems fixed by the previous
patches in the series:

  $ make -k 2>&1 | grep "deleted function"
  src/gdb/breakpoint.c:951:53: error: use of deleted function ‘void* memset(T*, int, size_t) [with T = bp_location; <template-parameter-1-2> = void; size_t = long unsigned int]’
  src/gdb/breakpoint.c:7325:32: error: use of deleted function ‘void* memset(T*, int, size_t) [with T = bp_location; <template-parameter-1-2> = void; size_t = long unsigned int]’
  src/gdb/btrace.c:1153:42: error: use of deleted function ‘void* memset(T*, int, size_t) [with T = btrace_insn; <template-parameter-1-2> = void; size_t = long unsigned int]’
...

gdb/ChangeLog:
2017-04-25  Pedro Alves  <palves@redhat.com>

* common/common-defs.h: Include "common/poison.h".
* common/function-view.h: (Not, Or, Requires): Move to traits.h
and adjust.
* common/poison.h: New file.
* common/traits.h: Include <type_traits>.
(Not, Or, Requires): New, moved from common/function-view.h.

7 years agoDon't memset non-POD types: struct breakpoint
Pedro Alves [Tue, 25 Apr 2017 00:27:42 +0000 (01:27 +0100)]
Don't memset non-POD types: struct breakpoint

Eh, struct breakpoint was made non-POD just today, with commit
d28cd78ad820e3 ("Change breakpoint event locations to
event_location_up").  :-)

  src/gdb/breakpoint.c: In function ‘void init_raw_breakpoint_without_location(breakpoint*, gdbarch*, bptype, const breakpoint_ops*)’:
  src/gdb/breakpoint.c:7447:28: error: use of deleted function ‘void* memset(T*, int, size_t) [with T = breakpoint; <template-parameter-1-2> = void; size_t = long unsigned int]’
     memset (b, 0, sizeof (*b));
      ^
  In file included from src/gdb/common/common-defs.h:85:0,
   from src/gdb/defs.h:28,
   from src/gdb/breakpoint.c:20:
  src/gdb/common/poison.h:56:7: note: declared here
   void *memset (T *s, int c, size_t n) = delete;
 ^

gdb/ChangeLog:
2017-04-25  Pedro Alves  <palves@redhat.com>

* breakpoint.h (struct breakpoint): In-class initialize all
fields.  Make boolean fields "bool".
* breakpoint.c (init_raw_breakpoint_without_location): Remove
memset call and initializations no longer necessary.

7 years agoDon't memset non-POD types: struct btrace_insn
Pedro Alves [Tue, 25 Apr 2017 00:27:42 +0000 (01:27 +0100)]
Don't memset non-POD types: struct btrace_insn

struct btrace_insn is not a POD [1] so we shouldn't be using memset to
initialize it [2].

Use list-initialization instead, wrapped in a "pt insn to btrace insn"
function, which looks like just begging to be added next to the
existing pt_reclassify_insn/pt_btrace_insn_flags functions.

[1] - because its field "flags" is not POD, because enum_flags has a
non-trivial default ctor.

gdb/ChangeLog:
2017-04-25  Pedro Alves  <palves@redhat.com>

* btrace.c (pt_btrace_insn_flags): Change parameter type to
reference.
(pt_btrace_insn): New function.
(ftrace_add_pt): Remove memset call and use pt_btrace_insn.

7 years agoDon't memset non-POD types: struct bp_location
Pedro Alves [Tue, 25 Apr 2017 00:27:42 +0000 (01:27 +0100)]
Don't memset non-POD types: struct bp_location

struct bp_location is not a POD, so we shouldn't be using memset to
initialize it.

Caught like this:

  src/gdb/breakpoint.c: In function ‘bp_location** get_first_locp_gte_addr(CORE_ADDR)’:
  src/gdb/breakpoint.c:950:53: error: use of deleted function ‘void* memset(T*, int, size_t) [with T = bp_location; <template-parameter-1-2> = void; size_t = long unsigned int]’
     memset (&dummy_loc, 0, sizeof (struct bp_location));
       ^
  In file included from src/gdb/defs.h:28:0,
   from src/gdb/breakpoint.c:20:
  src/gdb/common/common-defs.h:126:7: note: declared here
   void *memset (T *s, int c, size_t n) = delete;
 ^

gdb/ChangeLog:
2017-04-25  Pedro Alves  <palves@redhat.com>

* ada-lang.c (ada_catchpoint_location): Now a "class".  Remove
"base" field and inherit from "bp_location" instead.  Add
non-default ctor.
(allocate_location_exception): Use new non-default ctor.
* breakpoint.c (get_first_locp_gte_addr): Remove memset call.
(init_bp_location): Convert to ...
(bp_location::bp_location): ... this new ctor, and remove memset
call.
(base_breakpoint_allocate_location): Use the new non-default ctor.
* breakpoint.h (bp_location): Now a class.  Declare default and
non-default ctors.  In-class initialize all members.
(init_bp_location): Remove declaration.

7 years agoDon't memcpy non-trivially-copyable types: Make enum_flags triv. copyable
Pedro Alves [Tue, 25 Apr 2017 00:27:42 +0000 (01:27 +0100)]
Don't memcpy non-trivially-copyable types: Make enum_flags triv. copyable

The delete-memcpy-with-non-trivial-types patch exposed many instances
of this problem:

  src/gdb/btrace.h: In function ‘btrace_insn_s* VEC_btrace_insn_s_quick_insert(VEC_btrace_insn_s*, unsigned int, const btrace_insn_s*, const char*, unsigned int)’:
  src/gdb/common/vec.h:948:62: error: use of deleted function ‘void* memmove(T*, const U*, size_t) [with T = btrace_insn; U = btrace_insn; <template-parameter-1-3> = void; size_t = long unsigned int]’
     memmove (slot_ + 1, slot_, (vec_->num++ - ix_) * sizeof (T));    \
^
  src/gdb/common/vec.h:436:1: note: in expansion of macro ‘DEF_VEC_FUNC_O’
   DEF_VEC_FUNC_O(T)         \
   ^
  src/gdb/btrace.h:84:1: note: in expansion of macro ‘DEF_VEC_O’
   DEF_VEC_O (btrace_insn_s);
   ^
[...]
  src/gdb/common/vec.h:1060:31: error: use of deleted function ‘void* memcpy(T*, const U*, size_t) [with T = btrace_insn; U = btrace_insn; <template-parameter-1-3> = void; size_t = long unsigned int]’
  sizeof (T) * vec2_->num);       \
 ^
  src/gdb/common/vec.h:437:1: note: in expansion of macro ‘DEF_VEC_ALLOC_FUNC_O’
   DEF_VEC_ALLOC_FUNC_O(T)         \
   ^
  src/gdb/btrace.h:84:1: note: in expansion of macro ‘DEF_VEC_O’
   DEF_VEC_O (btrace_insn_s);
   ^

So, VECs (given it's C roots) rely on memcpy/memcpy of VEC elements to
be well defined, in order to grow/reallocate its internal elements
array.  This means that we can only put trivially copyable types in
VECs.  E.g., if a type requires using a custom copy/move ctor to
relocate, then we can't put it in a VEC (so we use std::vector
instead).  But, as shown above, we're violating that requirement.

btrace_insn is currently not trivially copyable, because it contains
an enum_flags field, and that is itself not trivially copyable.  This
patch corrects that, by simply removing the user-provided copy
constructor and assignment operator.  The compiler-generated versions
work just fine.

Note that std::vector relies on std::is_trivially_copyable too to know
whether it can reallocate its elements with memcpy/memmove instead of
having to call copy/move ctors and dtors, so if we have types in
std::vectors that weren't trivially copyable because of enum_flags,
this will make such vectors more efficient.

gdb/ChangeLog:
2017-04-25  Pedro Alves  <palves@redhat.com>

* common/enum-flags.h (enum_flags): Don't implement copy ctor and
assignment operator.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 25 Apr 2017 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agox86-64: Force symbol dynamic if it isn't undefined weak
H.J. Lu [Mon, 24 Apr 2017 21:37:12 +0000 (14:37 -0700)]
x86-64: Force symbol dynamic if it isn't undefined weak

Force symbol dynamic if it isn't undefined weak.  Generate relative
relocation for GOT reference against non-dynamic symbol in PIC to
avoid unnecessary dynamic symbols.

bfd/

* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add
no_finish_dynamic_symbol.
(elf_x86_64_link_hash_newfunc): Set no_finish_dynamic_symbol to
0.
(elf_x86_64_allocate_dynrelocs): If a symbol isn't undefined
weak symbol, don't make it dynamic.
(elf_x86_64_relocate_section): If a symbol isn't dynamic in PIC,
set no_finish_dynamic_symbol and generate R_X86_64_RELATIVE
relocation for GOT reference.
(elf_x86_64_finish_dynamic_symbol): Abort if
no_finish_dynamic_symbol isn't 0.

ld/

* testsuite/ld-x86-64/no-plt.exp: Also check no-plt-1e.nd.
* testsuite/ld-x86-64/no-plt-1e.nd: New file.

7 years agoi386: Force symbol dynamic if it isn't undefined weak
H.J. Lu [Mon, 24 Apr 2017 20:42:33 +0000 (13:42 -0700)]
i386: Force symbol dynamic if it isn't undefined weak

Force symbol dynamic if it isn't undefined weak.  Generate R_386_RELATIVE
relocation for R_386_GOT32 relocation against non-dynamic symbol in PIC.

PR ld/21402
* elf32-i386.c (elf_i386_allocate_dynrelocs): If a symbol isn't
undefined weak symbol, don't make it dynamic.
(elf_i386_relocate_section): If a symbol isn't dynamic in PIC,
set no_finish_dynamic_symbol and generate R_386_RELATIVE
relocation for R_386_GOT32.

7 years agoUse floatformat_totalsize_bytes
Yao Qi [Mon, 24 Apr 2017 20:29:12 +0000 (21:29 +0100)]
Use floatformat_totalsize_bytes

The code can be replaced by floatformat_totalsize_bytes.

gdb:

2017-04-24  Yao Qi  <yao.qi@linaro.org>

* doublest.c (convert_doublest_to_floatformat): Call
floatformat_totalsize_bytes.

7 years agoi386: Skip pr12570 tests for nacl targets
H.J. Lu [Mon, 24 Apr 2017 16:46:04 +0000 (09:46 -0700)]
i386: Skip pr12570 tests for nacl targets

commit f129e49f4d07f4d36319ac757fdcf3a8ce7d605b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jan 10 11:30:25 2017 -0800

    Don't use elf_i386_eh_frame_plt directly

fixed i386 PLT eh_frame generation.  Skip pr12570 tests since they are
for non-nacl targets.

* testsuite/ld-i386/pr12570a.d: Skip for nacl targets.
* testsuite/ld-i386/pr12570b.d: Likewise.

7 years agoi386: Set ELF_MAXPAGESIZE to 0x1000 for VxWorks
H.J. Lu [Mon, 24 Apr 2017 16:37:10 +0000 (09:37 -0700)]
i386: Set ELF_MAXPAGESIZE to 0x1000 for VxWorks

commit a27e437177412e5b52999723f3c5d5d0d37b9087
Author: Roland McGrath <roland@gnu.org>
Date:   Thu Jul 28 22:35:15 2011 +0000

    BFD vector for elf32-i386-nacl:

changed ELF_MAXPAGESIZE to 0x10000 for VxWorks.  This patch fixes it
and updated testsuite/ld-i386/vxworks2.sd to add space for program
headers.

bfd/

PR ld/21425
* elf32-i386.c (ELF_MAXPAGESIZE): Set to 0x1000 for VxWorks.

ld/

PR ld/20815
* testsuite/ld-i386/vxworks2.sd: Add space for program headers.

7 years ago[GAS/ARM] Fix expansion of ldr pseudo instruction
Thomas Preud'homme [Mon, 24 Apr 2017 13:49:48 +0000 (14:49 +0100)]
[GAS/ARM] Fix expansion of ldr pseudo instruction

The LDR rX, =cst pseudo-instruction suffers from two issues for loading
integer constants in Thumb mode:

- movs is used if the constant and register can be encoded using that
  instruction which leads to unexpected behavior due to its flag-setting
  behavior
- mov.w, movw and mvn are used for r13 (sp) and r15 (pc) but these
  encoding are marked as UNPREDICTABLE

This patch fixes those issues and update testing accordingly.

2017-04-24  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gas/
* config/tc-arm.c (move_or_literal_pool): Remove code generating MOVS.
Forbid MOV.W and MOVW if destination is SP or PC.
* testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.s: Explain
expectation of LDR not generating a MOVS for low registers and small
constants.  Add tests of MOVW generation.
* testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.d: Update
expected disassembly.

7 years agold: fix regressions with rett instructions in sparc tests.
Jose E. Marchesi [Mon, 24 Apr 2017 12:31:31 +0000 (05:31 -0700)]
ld: fix regressions with rett instructions in sparc tests.

A few tests in the ld testsuite were expecting the disassembler to
emit `rett' instructions in V9.  This patch updates the tests to
expect `return' instead.

ld/ChangeLog:

2017-04-24  Jose E. Marchesi  <jose.marchesi@oracle.com>

* testsuite/ld-sparc/tlssunbin64.dd: Expect `return' instructions
instead of `rett' in V9.
* testsuite/ld-sparc/tlssunnopic64.dd: Likewise.
* testsuite/ld-sparc/tlssunpic64.dd: Likewise.

7 years agoFix snafu in aarch64 opcodes debugging statement.
Tamar Christina [Mon, 24 Apr 2017 10:55:44 +0000 (11:55 +0100)]
Fix snafu in aarch64 opcodes debugging statement.

* aarch64-opc.c (aarch64_logical_immediate_p): Update DEBUG_TRACE
arguments.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 24 Apr 2017 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoPR 21418, ar -N lacks arg check
Alan Modra [Sun, 23 Apr 2017 08:09:48 +0000 (17:39 +0930)]
PR 21418, ar -N lacks arg check

PR 21418
* ar.c (main): Check -a, -b, -i and -N args are given.

7 years agoPR 21417, ar arg check failure
Alan Modra [Sun, 23 Apr 2017 07:58:14 +0000 (17:28 +0930)]
PR 21417, ar arg check failure

PR 21417
* ar.c (main): Check that an archive file is given after options.

7 years agoPR 21415, objdump fails to check bfd_get_section_contents status
Alan Modra [Sun, 23 Apr 2017 09:01:40 +0000 (18:31 +0930)]
PR 21415, objdump fails to check bfd_get_section_contents status

PR 21415
* objdump.c (disassemble_section): Check bfd_get_section_contents
status.

7 years agoPR 21414, null pointer deref of _bfd_elf_large_com_section sym
Alan Modra [Sun, 23 Apr 2017 05:51:11 +0000 (15:21 +0930)]
PR 21414, null pointer deref of _bfd_elf_large_com_section sym

PR 21414
* section.c (GLOBAL_SYM_INIT): Make available in bfd.h.
* elf.c (lcomm_sym): New.
(_bfd_elf_large_com_section): Use lcomm_sym section symbol.
* bfd-in2.h: Regenerate.

7 years agoPR 21412, get_reloc_section assumes .rel/.rela name for SHT_REL/RELA.
Alan Modra [Sun, 23 Apr 2017 01:33:34 +0000 (11:03 +0930)]
PR 21412, get_reloc_section assumes .rel/.rela name for SHT_REL/RELA.

This patch fixes an assumption made by code that runs for objcopy and
strip, that SHT_REL/SHR_RELA sections are always named starting with a
.rel/.rela prefix.  I'm also modifying the interface for
elf_backend_get_reloc_section, so any backend function just needs to
handle name mapping.

PR 21412
* elf-bfd.h (struct elf_backend_data <get_reloc_section>): Change
parameters and comment.
(_bfd_elf_get_reloc_section): Delete.
(_bfd_elf_plt_get_reloc_section): Declare.
* elf.c (_bfd_elf_plt_get_reloc_section, elf_get_reloc_section):
New functions.  Don't blindly skip over assumed .rel/.rela prefix.
Extracted from..
(_bfd_elf_get_reloc_section): ..here.  Delete.
(assign_section_numbers): Call elf_get_reloc_section.
* elf64-ppc.c (elf_backend_get_reloc_section): Define.
* elfxx-target.h (elf_backend_get_reloc_section): Update.

7 years agoPR 21409, segfault in _bfd_dwarf2_find_nearest_line
Alan Modra [Sun, 23 Apr 2017 04:25:49 +0000 (13:55 +0930)]
PR 21409, segfault in _bfd_dwarf2_find_nearest_line

PR 21409
* dwarf2.c (_bfd_dwarf2_find_nearest_line): Don't segfault when
no symbols.

7 years agoPR 21408, segfault in display_debug_lines_decoded
Alan Modra [Sun, 23 Apr 2017 04:19:50 +0000 (13:49 +0930)]
PR 21408, segfault in display_debug_lines_decoded

PR 21408
* dwarf.c (display_debug_lines_decoded): Don't segfault on NULL
file_table.

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 23 Apr 2017 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoFix ldn/stn multiple instructions. Fix testcases with unaligned data.
Jim Wilson [Sat, 22 Apr 2017 23:36:01 +0000 (16:36 -0700)]
Fix ldn/stn multiple instructions.  Fix testcases with unaligned data.

sim/aarch64/
* simulator.c (vec_load): Add M argument.  Rewrite to iterate over
registers based on structure size.
(LD4, LD3, LD2, LD1_2, LD1_3, LD1_4): Pass new arg to vec_load.
(LD1_1): Replace with call to vec_load.
(vec_store): Add new M argument.  Rewrite to iterate over registers
based on structure size.
(ST4, ST3, ST2, ST1_2, ST1_3, ST1_4): Pass new arg to vec_store.
(ST1_1): Replace with call to vec_store.

sim/testsuite/sim/aarch64/
* fcvtz.s, fstur.s, ldn_single.s, ldnr.s, mla.s, mls.s, uzp.s: Align
data.
* sumulh.s: Delete unnecessary data alignment.
* stn_single.s: Align data.  Fix unaligned ldr insns.  Adjust cmp
arguments to match change.
* ldn_multiple.s, stn_multiple.s: New.

7 years agoUse ui_out_emit_list
Tom Tromey [Wed, 12 Apr 2017 22:30:21 +0000 (16:30 -0600)]
Use ui_out_emit_list

This changes some spots to use ui_out_emit_list.  This only touches
"easy" cases, where the cleanup was used in a block-structured way.
There's also one more use of ui_out_emit_tuple in here.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Use
ui_out_emit_list.
* stack.c (print_frame): Use ui_out_emit_list.
* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
ui_out_emit_list.
* mi/mi-main.c (print_one_inferior)
(mi_cmd_data_list_register_names)
(mi_cmd_data_list_register_values, mi_cmd_list_features)
(mi_cmd_list_target_features, mi_cmd_trace_frame_collected): Use
ui_out_emit_list.
* mi/mi-interp.c (mi_on_normal_stop_1): Use ui_out_emit_list.
(mi_output_solib_attribs): Use ui_out_emit_list,
ui_out_emit_tuple.
* mi/mi-cmd-var.c (varobj_update_one): Use ui_out_emit_list.
* mi/mi-cmd-stack.c (mi_cmd_stack_list_frames)
(mi_cmd_stack_list_args, list_args_or_locals): Use
ui_out_emit_list.
* disasm.c (do_assembly_only): Use ui_out_emit_list.
* breakpoint.c (print_solib_event, output_thread_groups): Use
ui_out_emit_list.

7 years agoUse ui_out_emit_tuple in more places in MI
Tom Tromey [Wed, 12 Apr 2017 22:16:10 +0000 (16:16 -0600)]
Use ui_out_emit_tuple in more places in MI

This patch changes a few more spots in MI to use ui_out_emit_tuple.
These changes required the use of gdb::optional.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

* mi/mi-main.c (print_variable_or_computed): Use ui_out_emit_tuple.
* mi/mi-cmd-var.c (varobj_update_one): Use ui_out_emit_tuple.
* mi/mi-cmd-stack.c (list_arg_or_local): Use ui_out_emit_tuple.

7 years agoUse ui_out_emit_tuple in tracepoint.c
Tom Tromey [Wed, 12 Apr 2017 22:15:14 +0000 (16:15 -0600)]
Use ui_out_emit_tuple in tracepoint.c

This changes some code in tracepoint.c to use ui_out_emit_tuple.  One
of these involved removing an otherwise unrelated cleanup (changing
type to std::string) and the other involved introducing a new block.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

* tracepoint.c (tvariables_info_1)
(print_one_static_tracepoint_marker): Use ui_out_emit_tuple.

7 years agoMore uses of ui_out_emit_tuple
Tom Tromey [Wed, 12 Apr 2017 22:10:02 +0000 (16:10 -0600)]
More uses of ui_out_emit_tuple

This patch adds a few more uses of ui_out_emit_tuple.  In these cases
a slightly more complicated change was needed.  This also adds
annotate_arg_emitter, for use in stack.c, to avoid having to introduce
a new scope and reindent the code for a single call.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

* stack.c (print_frame_arg): Use ui_out_emit_tuple,
annotate_arg_emitter.
* breakpoint.c (print_mention_watchpoint)
(print_mention_masked_watchpoint): Use ui_out_emit_tuple.
* annotate.h (struct annotate_arg_emitter): New.

7 years agoUse ui_out_emit_tuple
Tom Tromey [Wed, 12 Apr 2017 14:23:08 +0000 (08:23 -0600)]
Use ui_out_emit_tuple

This patch changes various places to use ui_out_emit_tuple,
eliminating a number of cleanups.  This patch only tackles "easy"
cases, which are ones where the cleanups in question were
block-structured and did not involve any changes other than the
obvious replacement.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

* record-btrace.c (record_btrace_insn_history)
(record_btrace_insn_history_range, record_btrace_call_history)
(record_btrace_call_history_range): Use ui_out_emit_tuple.
* thread.c (do_captured_list_thread_ids, print_thread_info_1): Use
ui_out_emit_tuple.
* stack.c (print_frame_info): Use ui_out_emit_tuple.
* solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple.
* skip.c (skip_info): Use ui_out_emit_tuple.
* remote.c (show_remote_cmd): Use ui_out_emit_tuple.
* progspace.c (print_program_space): Use ui_out_emit_tuple.
* probe.c (info_probes_for_ops): Use ui_out_emit_tuple.
* osdata.c (info_osdata): Use ui_out_emit_tuple.
* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
ui_out_emit_tuple.
* mi/mi-main.c (print_one_inferior, list_available_thread_groups)
(output_register, mi_cmd_data_read_memory)
(mi_cmd_data_read_memory_bytes, mi_load_progress)
(mi_cmd_trace_frame_collected): Use ui_out_emit_tuple.
* mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one):
Use ui_out_emit_tuple.
* mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use
ui_out_emit_tuple.
* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
(mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple.
* linux-thread-db.c (info_auto_load_libthread_db): Use
ui_out_emit_tuple.
* inferior.c (print_inferior): Use ui_out_emit_tuple.
* gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple.
* disasm.c (do_mixed_source_and_assembly_deprecated)
(do_mixed_source_and_assembly): Use ui_out_emit_tuple.
* cp-abi.c (list_cp_abis): Use ui_out_emit_tuple.
* cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple.
* breakpoint.c (print_one_breakpoint_location)
(print_one_breakpoint): Use ui_out_emit_tuple.
* auto-load.c (print_script, info_auto_load_cmd): Use
ui_out_emit_tuple.
* ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.

7 years agoPowerPC VLE insn set additions
Alan Modra [Sat, 22 Apr 2017 04:39:21 +0000 (14:09 +0930)]
PowerPC VLE insn set additions

opcodes/
* ppc-opc.c (ELEV): Define.
(vle_opcodes): Add se_rfgi and e_sc.
(powerpc_opcodes): Enable lbdx, lhdx, lwdx, stbdx, sthdx, stwdx
for E200Z4.
gas/
* testsuite/gas/ppc/vle.s: Format.  Add se_rfgi and e_sc.
* testsuite/gas/ppc/vle.d: Update.

7 years agodoc: Improve documentation about MI thread output
Simon Marchi [Sat, 22 Apr 2017 01:50:22 +0000 (21:50 -0400)]
doc: Improve documentation about MI thread output

I noticed that the documentation on how the info about threads is output
in MI is duplicated and not up to date.  The duplication is between the
"GDB/MI Thread Information" page and the -thread-info result
description.

I improved the "GDB/MI Thread Information" page a bit and referred to it
in the -thread-info doc.  This way, the -thread-info doc is more precise
(it did not mention the "threads" and "current-thread-id" attributes)
and concise.

gdb/doc/ChangeLog:

* gdb.texinfo (GDB/MI Thread Information): Add missing
fields, re-word some things.
(GDB/MI Thread Commands): Describe fields found in the output of
-thread-info, remove description of fields in the
thread output tuple, replace with a cross-reference to "GDB/MI
Thread Information".

7 years agoRemove dead code and "current" field from MI thread output doc
Simon Marchi [Sat, 22 Apr 2017 01:45:15 +0000 (21:45 -0400)]
Remove dead code and "current" field from MI thread output doc

The MI documentation says that -thread-info output contains a "current"
field in the current thread tuple, with the value "*".  Current GDB
master does not do this, and I couldn't find any GDB version that did.
I suspect that it was never the case.

The code that would correspond to this in print_thread_info_1 is
essentially dead code.  The calls to uiout->text end up in
mi_out::do_text, which is empty.

This patch removes the documentation bit and the dead code.  This
"current" field is not necessary, since -thread-info outputs a
"current-thread-id" field.

gdb/ChangeLog:

* thread.c (print_thread_info_1): Remove dead code.

gdb/doc/ChangeLog:

* gdb.texinfo (GDB/MI Thread Commands): Remove "current" field
from -thread-info output.

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 22 Apr 2017 00:00:47 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoi386: Avoid dynamic symbol with GOT reference in PIE
H.J. Lu [Fri, 21 Apr 2017 19:03:14 +0000 (12:03 -0700)]
i386: Avoid dynamic symbol with GOT reference in PIE

GOT reference to global symbol in PIE will lead to dynamic symbol.  It
becomes a problem when "time" or "times" is defined as a variable in
an executable, clashing with functions of the same name in libc.  If
a symbol isn't undefined weak symbol, don't make it dynamic in PIE and
generate R_386_RELATIVE relocation.

bfd/

PR ld/21402
* elf32-i386.c (elf_i386_link_hash_entry): Add
no_finish_dynamic_symbol.
(elf_i386_link_hash_newfunc): Set no_finish_dynamic_symbol to 0.
(elf_i386_allocate_dynrelocs): If a symbol isn't undefined weak
symbol, don't make it dynamic in PIE.
(elf_i386_relocate_section): If a symbol isn't dynamic in PIE,
set no_finish_dynamic_symbol and generate R_386_RELATIVE
relocation for R_386_GOT32
(elf_i386_finish_dynamic_symbol): Abort if no_finish_dynamic_symbol
isn't 0.

ld/

PR ld/21402
* testsuite/ld-elf/indirect.exp: Don't skip PIE indirect5 and
indirect6 tests on i386.

7 years agoRequire --no-dynamic-linker with -static -E/--dynamic-list
H.J. Lu [Fri, 21 Apr 2017 19:00:55 +0000 (12:00 -0700)]
Require --no-dynamic-linker with -static -E/--dynamic-list

When -static -E/--dynamic-list are passed to linker, linker may create
executable with dynamic sections which aren't supported by run-time.
We require --no-dynamic-linker together with -static -E/--dynamic-list
before adding dynamic symbol table to static executable.

bfd/

PR ld/19617
PR ld/21086
* elflink.c (elf_link_add_object_symbols): Require
--no-dynamic-linker with -E/--dynamic-list when creating
dynamic sections.

ld/

PR ld/19617
PR ld/21086
* testsuite/ld-elf/pr19617a.d: Pass --no-dynamic-linker to ld.
* testsuite/ld-elf/pr19617b.d: Likewise.
* testsuite/ld-elf/pr19617c.d: Likewise.
*testsuite/ld-i386/pr19636-4d.d: Likewise.
* testsuite/ld-elf/readelf.exp: Pass --no-dynamic-linker to ld
with --export-dynamic.
* testsuite/ld-elf/shared.exp: Pass --no-dynamic-linker to ld
with -E.

7 years agorelease branch: Fix: --enable-werror
Jan Kratochvil [Fri, 21 Apr 2017 14:14:37 +0000 (16:14 +0200)]
release branch: Fix: --enable-werror

gdb-8.0-branch
./configure --enable-werror --enable-targets=all
aarch64-tdep.c:3045:13: error: ‘void selftests::aarch64_process_record_test()’ declared ‘static’ but never defined [-Werror=unused-function]
arm-tdep.c:9601:13: error: ‘void selftests::arm_record_test()’ declared ‘static’ but never defined [-Werror=unused-function]

gdb/ChangeLog
2017-04-21  Jan Kratochvil  <jan.kratochvil@redhat.com>

* aarch64-tdep.c (selftests::aarch64_process_record_test): Make it #if
GDB_SELF_TEST.
* arm-tdep.c (selftests::arm_record_test): Likewise.

7 years agoSimplify regcache_restore
Yao Qi [Fri, 21 Apr 2017 13:59:27 +0000 (14:59 +0100)]
Simplify regcache_restore

This patches removes the 2nd argument of regcache_restore, because it
is only called by regcache_cpy.  In regcache_cpy, if regcache_restore
is called, dst is not readonly, but src is readonly.  So this patch
adds an assert that src is readonly in regcache_restore.
regcache_cook_read read everything from a readonly regcache cache
(src)'s register_buffer, and register status is from ->register_status.

gdb:

2017-04-21  Yao Qi  <yao.qi@linaro.org>

* regcache.c (regcache_restore): Remove argument 2.  Replace
argument 3 with regcache.  Get register status from
src->register_status and get register contents from
register_buffer (src, regnum).
(regcache_cpy): Update.

7 years agoopcodes: mark SPARC RETT instructions as v6notv9.
Jose E. Marchesi [Fri, 21 Apr 2017 12:19:06 +0000 (05:19 -0700)]
opcodes: mark SPARC RETT instructions as v6notv9.

This prevents the disassembler to show `return' instructions as
`rett' in V9 and later architectures.

opcodes/ChangeLog:

2017-04-21  Jose E. Marchesi  <jose.marchesi@oracle.com>

* sparc-opc.c (sparc_opcodes): Mark RETT instructions as v6notv9.

7 years agoFix shift overflow when parsing an overlarge note value.
Nick Clifton [Fri, 21 Apr 2017 11:31:59 +0000 (12:31 +0100)]
Fix shift overflow when parsing an overlarge note value.

PR binutils/21378
* readelf.c (print_gnu_build_attribute_name): Check for an
overlarge name field.

7 years agoFix detection of illegal AArch64 opcodes that resemble LD1R, LD2R, LD3R and LD4R.
Nick Clifton [Fri, 21 Apr 2017 11:18:06 +0000 (12:18 +0100)]
Fix detection of illegal AArch64 opcodes that resemble LD1R, LD2R, LD3R and LD4R.

PR binutils/21380
opcodes * aarch64-tbl.h (aarch64_opcode_table): Fix masks for LD1R, LD2R,
LD3R and LD4R.

gas * testsuite/gas/aarch64/illegal-3.s: New file.
* testsuite/gas/aarch64/illegal-3.d: New file.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 21 Apr 2017 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoSkip PIE indirect5 and indirect6 tests on i386
H.J. Lu [Thu, 20 Apr 2017 19:33:55 +0000 (12:33 -0700)]
Skip PIE indirect5 and indirect6 tests on i386

On i386, since GOT reference is needed to access global symbols in PIE,
those symbols are made dynamic.  Crash happens when there is a reference
to the same global symbol with a different symbol type in a shared
object.  Since mixing different types of the same symbol doesn't work in
general, this patch skips those tests on i386 as well as compiles non-PIE
indirect5 and indirect6 tests with $NOPIE_LDFLAGS and $NOPIE_CFLAGS.

PR ld/21402
* testsuite/ld-elf/indirect.exp: Pass $NOPIE_LDFLAGS and
$NOPIE_CFLAGS to non-PIE indirect5 and indirect6 tests.  Skip
PIE indirect5 and indirect6 tests on i386.

7 years agoELF/LD: Always consider STB_LOCAL symbols local
Maciej W. Rozycki [Thu, 13 Apr 2017 09:26:05 +0000 (10:26 +0100)]
ELF/LD: Always consider STB_LOCAL symbols local

Do not require forced local (STB_LOCAL) symbols to have a definition in
a regular file to be considered to resolve local to the current module,
matching `elf_link_renumber_local_hash_table_dynsyms'.  In the absence
of a regular definition any reference to a STB_LOCAL symbol will have to
be garbage collected along with the undefined symbol itself, or the link
will eventually fail.  Either way the symbol concerned is not going to
be external.

bfd/
* elflink.c (_bfd_elf_symbol_refs_local_p): Always return TRUE
if forced local.

7 years agoMIPS/LD/testsuite: Join `__ehdr_start' tests
Maciej W. Rozycki [Thu, 20 Apr 2017 00:39:30 +0000 (01:39 +0100)]
MIPS/LD/testsuite: Join `__ehdr_start' tests

Complement commit 3807734dbe48 ("PR ld/15428: MIPS/LD/testsuite:
Un-KFAIL `__ehdr_start' test 2") and join tests that do not need to be
split anymore.

ld/
* testsuite/ld-mips-elf/mips-elf.exp: Join `__ehdr_start' tests.

7 years agoMIPS/BFD: Reorder comment about dynamic symbol sorting
Maciej W. Rozycki [Wed, 19 Apr 2017 15:51:17 +0000 (16:51 +0100)]
MIPS/BFD: Reorder comment about dynamic symbol sorting

Move the comment about dynamic symbol sorting next to where it happens.

bfd/
* elfxx-mips.c (_bfd_mips_elf_final_link): Reorder comment about
dynamic symbol sorting.

7 years agoHandle symbol defined in IR and referenced in DSO
H.J. Lu [Thu, 20 Apr 2017 14:48:24 +0000 (07:48 -0700)]
Handle symbol defined in IR and referenced in DSO

We need to make an IR symbol visible if it is defined in an IR object
and referenced in a dynamic object.  When --as-needed is used, since
linker removes the IR symbol reference of the dynamic object if the
dynamic object isn't needed in the first pass, the IR definition isn't
visible to the dynamic object even if the dynamic object becomes needed
in the second pass.  Add dynamic_ref_after_ir_def to bfd_link_hash_entry
to track IR symbol which is defined in an IR object and later referenced
in a dynamic object.  dynamic_ref_after_ir_def is preserved when restoring
the symbol table for unneeded dynamic object.

bfd/

PR ld/21382
* elflink.c (elf_link_add_object_symbols): Preserve
dynamic_ref_after_ir_def when restoring the symbol table for
unneeded dynamic object.

include/

PR ld/21382
* bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def.

ld/

PR ld/21382
* plugin.c (is_visible_from_outside): Symbol may be visible
from outside if dynamic_ref_after_ir_def is set.
(plugin_notice): Set dynamic_ref_after_ir_def if the symbol is
defined in an IR object and referenced in a dynamic object.
* testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests.
* testsuite/ld-plugin/pr21382a.c: New file.
* testsuite/ld-plugin/pr21382b.c: Likewise.

7 years agoAutomatic date update in version.in
GDB Administrator [Thu, 20 Apr 2017 00:00:41 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agox86-64: Handle undefined IFUNC symbol with -z now
H.J. Lu [Wed, 19 Apr 2017 16:59:14 +0000 (09:59 -0700)]
x86-64: Handle undefined IFUNC symbol with -z now

Since undefined IFUNC symbol is treated as normal FUNC symbol, don't
abort on undefined IFUNC symbol in the second PLT.

bfd/

PR ld/21401
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Don't abort
on on undefined IFUNC symbol in the second PLT.

ld/

PR ld/21401
* testsuite/ld-ifunc/ifunc.exp: Add a libtest-2-now.so test with
-z now.

7 years agogdbthread.h: Fix comment typo
Pedro Alves [Wed, 19 Apr 2017 12:16:05 +0000 (13:16 +0100)]
gdbthread.h: Fix comment typo

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

* gdbthread.h (thread): Add missing closing parenthesis in
comment.

7 years agoFix removing inferiors from within "thread apply" commands
Pedro Alves [Wed, 19 Apr 2017 12:12:23 +0000 (13:12 +0100)]
Fix removing inferiors from within "thread apply" commands

This patch fixes an internal error exposed by a test that does
something like:

  define kill-and-remove
    kill inferiors 2
    remove-inferiors 2
  end

  # Start one inferior.
  start

  # Start another inferior.
  add-inferior 2
  inferior 2
  start

  # Kill and remove inferior 1 while inferior 2 is selected.
  thread apply 1.1 kill-and-remove

The internal error looks like this:

 Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)):
 [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)]
 [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))]
 #0  main () at src/gdb/testsuite/gdb.threads/threadapply.c:38
 38          for (i = 0; i < NUM; i++)
 src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error)

There are several problems around this area of the code.  One is that
in do_restore_current_thread_cleanup, we do a look up of inferior by
ptid, which can find the wrong inferior if the previously selected
inferior exited and some other inferior was started with a reused pid
(rare, but still...).

The other problem is that the "remove-inferiors" command rejects
attempts to remove the current inferior, but when we get to
"remove-inferiors" in a "thread apply THR remove-inferiors 2" command,
the current inferior is the inferior of thread THR, not the previously
selected inferior, so if the previously selected inferior was inferior
2, that command still manages to wipe it, and then gdb restores the
old selected inferior, which is now a dangling pointer...

So the fix here is:

- Make make_cleanup_restore_current_thread store a pointer to the
  previously selected inferior directly, and use it directly instead
  of doing ptid look ups.

- Add a refcount to inferiors, very similar to thread_info's refcount,
  that is incremented/decremented by
  make_cleanup_restore_current_thread, and checked before deleting an
  inferior.  To avoid duplication, a new refcounted_object type is
  added, that both thread_info and inferior inherit from.

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

* common/refcounted-object.h: New file.
* gdbthread.h: Include "common/refcounted-object.h".
(thread_info): Inherit from refcounted_object and add comments.
(thread_info::incref, thread_info::decref)
(thread_info::m_refcount): Delete.
(thread_info::deletable): Use the refcounted_object::refcount()
method.
* inferior.c (current_inferior_): Add comment.
(set_current_inferior): Increment/decrement refcounts.
(prune_inferiors, remove_inferior_command): Skip inferiors marked
not-deletable instead of comparing with the current inferior.
(initialize_inferiors): Increment the initial inferior's refcount.
* inferior.h (struct inferior): Forward declare.
Include "common/refcounted-object.h".
(current_inferior, set_current_inferior): Move declaration to
before struct inferior's definition, and fix comment.
(inferior): Inherit from refcounted_object.  Add comments.
* thread.c (switch_to_thread_no_regs): Reference the thread's
inferior pointer directly instead of doing a ptid lookup.
(switch_to_no_thread): New function.
(switch_to_thread(thread_info *)): New function, factored out
from ...
(switch_to_thread(ptid_t)): ... this.
(restore_current_thread): Delete.
(current_thread_cleanup): Remove 'inf_id' and 'was_removable'
fields, and add 'inf' field.
(do_restore_current_thread_cleanup): Check whether old->inf is
alive instead of looking up an inferior by ptid.  Use
switch_to_thread and switch_to_no_thread.
(restore_current_thread_cleanup_dtor): Use old->inf directly
instead of lookup up an inferior by id.  Decref the inferior.
Don't restore 'removable'.
(make_cleanup_restore_current_thread): Same the inferior pointer
in old, instead of the inferior number.  Incref the inferior.
Don't save/clear 'removable'.

gdb/testsuite/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

* gdb.threads/threadapply.exp (kill_and_remove_inferior): New
procedure.
(top level): Call it.
* lib/gdb.exp (gdb_define_cmd): New procedure.

7 years agoMake inferior::detaching a bool, and introduce scoped_restore::release()
Pedro Alves [Wed, 19 Apr 2017 12:12:23 +0000 (13:12 +0100)]
Make inferior::detaching a bool, and introduce scoped_restore::release()

I left making inferior::detaching a bool to a separate patch, because
doing that makes a make_cleanup_restore_integer call in
infrun.c:prepare_for_detach no longer compile (passing a 'bool *' when
an 'int *' is expected).  Since we want to get rid of cleanups anyway,
I looked at converting that to a scoped_restore.  However,
prepare_for_detach wants to discard the cleanup on success, and
scoped_restore doesn't have an equivalent for that.  So I added one --
I called it "release()" because it seems like a natural fit in the way
standard components call similarly-spirited methods, and, it's also
what the proposal for a generic scope guard calls it too, AFAICS:

  http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189.pdf

I've added some scoped_guard unit tests, while at it.

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
unittests/scoped_restore-selftests.c.
(SUBDIR_UNITTESTS_OBS): Add scoped_restore-selftests.o.
* common/scoped_restore.h (scoped_restore_base): Make "class".
(scoped_restore_base::release): New public method.
(scoped_restore_base::scoped_restore_base): New protected ctor.
(scoped_restore_base::m_saved_var): New protected field.
(scoped_restore_tmpl::scoped_restore_tmpl(T*)): Initialize the
scoped_restore_base base class instead of m_saved_var directly.
(scoped_restore_tmpl::scoped_restore_tmpl(T*, T2)): Likewise.
(scoped_restore_tmpl::scoped_restore_tmpl(const
scoped_restore_tmpl<T>&)): Likewise.
(scoped_restore_tmpl::~scoped_restore_tmpl): Use the saved_var
method.
(scoped_restore_tmpl::saved_var): New method.
(scoped_restore_tmpl::m_saved_var): Delete.
* inferior.h (inferior::detaching): Now a bool.
* infrun.c (prepare_for_detach): Use a scoped_restore instead of a
cleanup.
* unittests/scoped_restore-selftests.c: New file.

7 years agogdb/Makefile.in: Re-sort SUBDIR_UNITTESTS_SRCS/SUBDIR_UNITTESTS_OBS
Pedro Alves [Wed, 19 Apr 2017 12:06:20 +0000 (13:06 +0100)]
gdb/Makefile.in: Re-sort SUBDIR_UNITTESTS_SRCS/SUBDIR_UNITTESTS_OBS

Note to self: 'o' before 'p'.

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

* Makefile.in (SUBDIR_UNITTESTS_SRCS, SUBDIR_UNITTESTS_OBS):
Re-sort in alphabetic order.

7 years agoCorrect PE reloc display
Wedson Almeida Filho [Wed, 19 Apr 2017 08:32:53 +0000 (18:02 +0930)]
Correct PE reloc display

* peXXigen.c (pe_print_reloc): Correct chunk_end.

7 years agoImplement -z dynamic-undefined-weak
Alan Modra [Tue, 18 Apr 2017 15:56:57 +0000 (01:26 +0930)]
Implement -z dynamic-undefined-weak

-z nodynamic-undefined-weak is only implemented for x86.  (The sparc
backend has some support code but doesn't enable the option by
including ld/emulparams/dynamic_undefined_weak.sh, and since the
support looks like it may be broken I haven't enabled it.)  This patch
adds the complementary -z dynamic-undefined-weak, extends both options
to affect building of shared libraries as well as executables, and
adds support for the option on powerpc.

include/
* bfdlink.h (struct bfd_link_info <dynamic_undefined_weak>):
Revise comment.
bfd/
* elflink.c (_bfd_elf_adjust_dynamic_symbol): Hide undefweak
or make dynamic for info->dynamic_undefined_weak 0 and 1.
* elf32-ppc.c:Formatting.
(ensure_undefweak_dynamic): Don't make dynamic when
info->dynamic_undefined_weak is zero.
(allocate_dynrelocs): Discard undefweak dyn_relocs for
info->dynamic_undefined_weak.  Discard undef dyn_relocs when
not default visibility.  Discard undef and undefweak
dyn_relocs earlier.
(ppc_elf_relocate_section): Adjust to suit.
* elf64-ppc.c: Formatting.
(ensure_undefweak_dynamic): Don't make dynamic when
info->dynamic_undefined_weak is zero.
(allocate_dynrelocs): Discard undefweak dyn_relocs for
info->dynamic_undefined_weak.  Discard them earlier.
ld/
* ld.texinfo (dynamic-undefined-weak): Document.
(nodynamic-undefined-weak): Document that this option now can
be used with shared libs.
* emulparams/dynamic_undefined_weak.sh: Support -z
dynamic-undefined-weak.
* emulparams/elf32ppccommon.sh: Include dynamic_undefined_weak.sh.
* testsuite/ld-undefined/weak-undef.exp (undef_weak_so),
(undef_weak_exe): New.  Use them.  Add -z dynamic-undefined-weak
and -z nodynamic-undefined-weak tests.
* Makefile.am: Update powerpc dependencies.
* Makefile.in: Regenerate.

7 years agoAutomatic date update in version.in
GDB Administrator [Wed, 19 Apr 2017 00:00:40 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoEliminate obstack_printf
Pedro Alves [Tue, 18 Apr 2017 20:39:25 +0000 (21:39 +0100)]
Eliminate obstack_printf

Not used anywhere.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

* xml-support.c (obstack_xml_printf): Delete.
* xml-support.h (obstack_xml_printf): Delete.

7 years agogdb_xml_parser: make data fields private and make more functions methods
Pedro Alves [Tue, 18 Apr 2017 20:39:25 +0000 (21:39 +0100)]
gdb_xml_parser: make data fields private and make more functions methods

This patch makes the data fields of gdb_xml_parser private, and makes
more functions be gdb_xml_parser methods.  This is mostly for better
encapsulation.

Some free functions have their parsing-related guts converted to
methods, while the free functions remain, as they're used as expat
callbacks.  Now their only job is to be small shims that restore back
the gdb_xml_parser type, defer work to the corresponding method, and
make sure C++ exceptions don't cross expat.

More C++-fycation of the XML parsers built on top of gdb_xml_parser
could follow, but this was my stopping point.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

* xml-support.c (gdb_xml_parser) <use_dtd, dtd_name, parse,
vdebug, verror, body_text, start_element, end_element, name,
user_data, set_is_xinclude, set_error, expat_parser>: New methods.
<name, user_data, expat_parser, scopes, error, last_line, dtd_name,
is_xinclude>: Make private and add m_ prefix.
(gdb_xml_parser::body_text): New method, based on ...
(gdb_xml_body_text): ... this.  Adjust.
(gdb_xml_parser::vdebug): New method, based on ...
(gdb_xml_debug): ... this.  Adjust.
(gdb_xml_parser::verror): New method, based on ...
(gdb_xml_error): ... this.  Adjust.
(gdb_xml_parser::start_element): New method, based on ...
(gdb_xml_start_element): ... this.  Adjust.
(gdb_xml_start_element_wrapper): Defer to
gdb_xml_parser::start_element and gdb_xml_parser::set_error.
(gdb_xml_parser::end_element): New method, based on ...
(gdb_xml_end_element_wrapper): ... this.  Adjust.
(gdb_xml_parser::~gdb_xml_parser): Adjust.
(gdb_xml_parser::gdb_xml_parser): Adjust to field renames.
(gdb_xml_parser::use_dtd): New method, based on ...
(gdb_xml_use_dtd): ... this.  Adjust.
(gdb_xml_parser::parse): New method, based on ...
(gdb_xml_parse): ... this.  Adjust.
(gdb_xml_parse_quick): Adjust to call the parser's parse method.
(xinclude_start_include): Adjust to call the parser's name method.
(xml_xinclude_default, xml_xinclude_start_doctype)
(xml_xinclude_end_doctype): Adjust to call the parser's user_data
method.
(xml_process_xincludes): Adjust to call parser methods.
* xml-support.h (gdb_xml_use_dtd, gdb_xml_parse): Delete
declarations.

7 years agoxml-support.c: Use std::string for growing string buffer
Pedro Alves [Tue, 18 Apr 2017 20:39:25 +0000 (21:39 +0100)]
xml-support.c: Use std::string for growing string buffer

This main idea behind this patch is this change to xml-support.c:scope_level

  -  /* Body text accumulation.  This is an owning pointer.  */
  -  struct obstack *body;
  +  /* Body text accumulation.  */
  +  std::string body;

... which allows simplifying other parts of the code.

In target_fetch_description_xml, we want to distinguish between
returning "success + empty std::string" and "no success", and
gdb::optional is a natural fit for that.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

* tracefile-tfile.c (tfile_write_tdesc): Adjust to use
gdb::optional<std::string>.
* xml-support.c: Include <string>.
(scope_level::scope_level(scope_level &&))
(scope_level::~scope_level): Delete.
(scope_level::body): Now a std::string.
(gdb_xml_body_text, gdb_xml_end_element): Adjust.
(xinclude_parsing_data::xinclude_parsing_data): Add 'output'
parameter.
(xinclude_parsing_data::~xinclude_parsing_data): Delete.
(xinclude_parsing_data::output): Now a std::string reference.
(xinclude_start_include): Adjust.
(xml_xinclude_default): Adjust.
(xml_process_xincludes): Add 'output' parameter, and return bool.
* xml-support.h (xml_process_xincludes): Add 'output' parameter,
and return bool.
* xml-tdesc.c: Include <unordered_map> and <string>.
(tdesc_xml_cache): Delete.
(tdesc_xml_cache_s): Delete.
(xml_cache): Now an std::unordered_map.
(tdesc_parse_xml): Adjust to use std::string and unordered_map.
(target_fetch_description_xml): Change return type to
gdb::optional<std::string>, and adjust.
* xml-tdesc.h: Include "common/gdb_optional.h" and <string>.
(target_fetch_description_xml): Change return type to
gdb::optional<std::string>.

7 years agogdb::optional unit tests
Pedro Alves [Tue, 18 Apr 2017 20:39:24 +0000 (21:39 +0100)]
gdb::optional unit tests

I thought I'd add some unit tests to make sure gdb::optional behaved
correctly, and started writing some, but then thought/realized that
libstdc++ already has extensive testing for C++17 std::optional, which
gdb::optional is a subset of, and thought why bother writing something
from scratch.  So I tried copying over a subset of libstdc++'s tests
(that ones that cover the subset supported by gdb::optional), and was
positively surprised that they mostly work OOTB.  This did help shake
out a few bugs from what I was implementing in the previous patch to
gdb::optional.  Still, it's a good chunk of code being copied over, so
if people dislike this copying/duplication, I can drop this patch.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
unittests/optional-selftests.c.
(SUBDIR_UNITTESTS_OBS): Add optional-selftests.o.
* unittests/optional-selftests.c: New file.
* unittests/optional/assignment/1.cc: New file.
* unittests/optional/assignment/2.cc: New file.
* unittests/optional/assignment/3.cc: New file.
* unittests/optional/assignment/4.cc: New file.
* unittests/optional/assignment/5.cc: New file.
* unittests/optional/assignment/6.cc: New file.
* unittests/optional/assignment/7.cc: New file.
* unittests/optional/cons/copy.cc: New file.
* unittests/optional/cons/default.cc: New file.
* unittests/optional/cons/move.cc: New file.
* unittests/optional/cons/value.cc: New file.
* unittests/optional/in_place.cc: New file.
* unittests/optional/observers/1.cc: New file.
* unittests/optional/observers/2.cc: New file.

7 years agoMore gdb::optional features
Pedro Alves [Tue, 18 Apr 2017 20:39:24 +0000 (21:39 +0100)]
More gdb::optional features

Currently we can't use gdb::optional<T> as function return type,
because gdb::optional's copy ctor is deleted.  For example, with:

  gdb::optional<int> function ()
  {
    gdb::optional<int> opt;
    ....
    return opt;

we get:

  src/gdb/foo.c: In function ‘gdb::optional<int> foo()’:
  src/gdb/foo.c:75:10: error: use of deleted function ‘gdb::optional<T>::optional(const gdb::optional<T>&) [with T = int]’
     return opt;
    ^
  In file included from src/gdb/foo.c:68:0:
  src/gdb/common/gdb_optional.h:53:3: note: declared here
     optional (const optional &other) = delete;
     ^

I started by fixing that, and then ran into another missing feature,
also fixed by this patch.

The next feature I'm missing most from gdb::optional<T> compared to
std::optional<T> is construction/move/assignment from a T, instead of
having to default construct an gdb::optional and then use
optional::emplace(....).

For example:
  gdb::optional<std::string> function ()
  {
    gdb::optional<std::string> opt;
    std::string str;
    ...
    opt.emplace (std::move (str));
    return opt;
vs
  gdb::optional<std::string> function ()
  {
    std::string str;
    ...
    return str;

The copy/move ctor/assign methods weren't initialy implemented because
std::optional supports construction from a type U if U is convertible
to T too, and has rules to decide whether the ctors are
explicit/implicit based on that, and rules for whether the ctor should
be trivial or not, etc., which leads to a much more complicated
implementation.

If we stick to supporting copy/move construction/assignment of/to an
optional<T> from exactly only optional<T> and T, then all that
conversion-related complication disappears, and we still gain
convenience in most use cases.

The patch also makes emplace return a reference to the constructor
object, per C++17 std::optional, and adds a reset method, againt
because std::optional has one and it's trivial to support it.  These
two changes are a requirement of the gdb::optional unit testing patch
that will follow.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

* common/gdb_optional.h: Include common/traits.h.
(in_place_t): New type.
(in_place): New constexpr variable.
(optional::optional): Remove member initialization of
m_instantiated.
(optional::optional(in_place_t...)): New constructor.
(optional::~optional): Use reset.
(optional::optional(const optional&)): New.
(optional::optional(const optional&&)): New.
(optional::optional(T &)): New.
(optional::optional(T &&)): New.
(operator::operator=(const optional &)): New.
(operator::operator=(optional &&)): New.
(operator::operator= (const T &))
(operator::operator= (T &&))
(operator::emplace (Args &&... args)): Return a T&.  Use reset.
(operator::reset): New.
(operator::m_instantiated):: Add in-class initializer.
* common/traits.h: Include <type_traits>.
(struct And): New types.

7 years agoxml-support.c: Use std::vector
Pedro Alves [Tue, 18 Apr 2017 20:39:24 +0000 (21:39 +0100)]
xml-support.c: Use std::vector

scope_level::scope_level needed both a move ctor and a dtor explicitly
coded, but those will be eliminated in a following patch.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

* xml-support.c: Include <vector>.
(scope_level::scope_level(const gdb_xml_element *))
(scope_level::scope_level(scope_level&&)): New.
(scope_level::~scope_level): New.
(scope_level_s): Delete.
(gdb_xml_parser::scopes): Now a std::vector.
(gdb_xml_body_text, gdb_xml_start_element, gdb_xml_end_element):
Use std::vector.
(gdb_xml_parser::~gdb_xml_parser): Remove now unnecessary
scope cleanup code.
(gdb_xml_parser::gdb_xml_parser): Remove explicit initialization
of the scopes member.  Use std::vector::emplace_back.

7 years agoC++-ify gdb/xml-support.c a bit to eliminate cleanups
Pedro Alves [Tue, 18 Apr 2017 20:39:24 +0000 (21:39 +0100)]
C++-ify gdb/xml-support.c a bit to eliminate cleanups

Basically convert cleanups to destructors in gdb_xml_parser and
xinclude_parsing_data, and then allocate objects of those types on the
stack.

More C++-ification is possible / will follow, but this removes a few
make_cleanup calls already.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

* xml-support.c (gdb_xml_parser): Add ctor/dtor.  Make is_xinclude
a bool.
(gdb_xml_end_element): Change type of first parameter.
(gdb_xml_cleanup): Rename to ...
(gdb_xml_parser::~gdb_xml_parser): ... this.
(gdb_xml_create_parser_and_cleanup): Delete with ...
(gdb_xml_parser::gdb_xml_parser): ... creation parts factored out
to this new ctor.
(gdb_xml_parse_quick): Create a local gdb_xml_parser instead of
using gdb_xml_create_parser_and_cleanup.
(xinclude_parsing_data): Add ctor/dtor.
(xml_xinclude_cleanup): Delete.
(xml_process_xincludes): Create a local xinclude_parsing_data
instead of heap-allocating one.  Create a local gdb_xml_parser
instead of heap-allocating one with
gdb_xml_create_parser_and_cleanup.

7 years agoPR threads/20743: Don't attempt to suspend or resume exited threads.
John Baldwin [Tue, 18 Apr 2017 16:44:32 +0000 (09:44 -0700)]
PR threads/20743: Don't attempt to suspend or resume exited threads.

When resuming a native FreeBSD process, ignore exited threads when
suspending/resuming individual threads prior to continuing the process.

gdb/ChangeLog:

PR threads/20743
* fbsd-nat.c (resume_one_thread_cb): Remove.
(resume_all_threads_cb): Remove.
(fbsd_resume): Use ALL_NON_EXITED_THREADS instead of
iterate_over_threads.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 18 Apr 2017 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoPut soname in the version definition section
H.J. Lu [Mon, 17 Apr 2017 14:47:17 +0000 (07:47 -0700)]
Put soname in the version definition section

commit 902e9fc76a0ec9f642cefa71ef88cca1c675ad54
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Tue Feb 21 01:46:42 2017 +0000

    PR ld/20828: Move symbol version processing ahead of GC symbol sweep

breaks version definition with --version-script --soname.  This patch
fixes it by getting soname index before generating the version definition
section.

bfd/

PR ld/21389
* elflink.c (bfd_elf_size_dynamic_sections): Get soname index
before generating the version definition section.

ld/

PR ld/21389
* testsuite/ld-elf/pr21389.map: New file.
* testsuite/ld-elf/pr21389.s: Likewise.
* testsuite/ld-elf/pr21389a.d: Likewise.
* testsuite/ld-elf/pr21389b.d: Likewise.
* testsuite/ld-elf/pr21389c.d: Likewise.

7 years agoUpdate NEWS post GDB 8.0 branch creation.
Joel Brobecker [Mon, 17 Apr 2017 14:30:29 +0000 (07:30 -0700)]
Update NEWS post GDB 8.0 branch creation.

gdb/ChangeLog:

* NEWS: Create a new section for the next release branch.
Rename the section of the current branch, now that it has
been cut.

7 years agoBump version to 8.0.50.DATE-git
Joel Brobecker [Mon, 17 Apr 2017 14:20:49 +0000 (07:20 -0700)]
Bump version to 8.0.50.DATE-git

Now that the GDB 8.0 branch has been created, we should bump
the GDB version accordingly.

gdb/ChangeLog:

GDB 8.0 branch created (725bf5cf125783c2a7ca4ab63d3768e220bab2db):
* version.in: Bump version to 7.99.90.DATE-git.

7 years agoUndo dynamic symbol state after regular object sym type mismatch
Alan Modra [Mon, 17 Apr 2017 09:03:52 +0000 (18:33 +0930)]
Undo dynamic symbol state after regular object sym type mismatch

We already handle the case of an object file first defining a symbol
that a later shared library also defines where the symbol types are
incompatible.  This patch handles the reverse, when a later object
file defines an incompatible symbol defined by an earlier shared
library.

bfd/
* elflink.c (_bfd_elf_merge_symbol): Undo dynamic linking
state when a regular object file defines a symbol with
incompatible type to that defined by an earlier shared lib.
ld/
* testsuite/ld-elf/indirect5a.c,
* testsuite/ld-elf/indirect5b.c,
* testsuite/ld-elf/indirect5.map,
* testsuite/ld-elf/indirect5.out: New test.
* testsuite/ld-elf/indirect6a.c: Likewise.
* testsuite/ld-elf/indirect.exp (check_dynamic_syms): New proc.
Run new tests and check dynsyms.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 17 Apr 2017 00:00:33 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 16 Apr 2017 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 15 Apr 2017 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoFix build breakage on Cygwin (PR gdb/21385)
Sergio Durigan Junior [Fri, 14 Apr 2017 01:01:53 +0000 (21:01 -0400)]
Fix build breakage on Cygwin (PR gdb/21385)

On gdb/windows-nat.c:windows_create_inferior, ALLARGS needs to be
declared independently of the host that we're building for.  This
fixes a build breakage on Cygwin.

2017-04-13  Sergio Durigan Junior  <sergiodj@redhat.com>

PR gdb/21385
* windows-nat.c (windows_create_inferior): Declare 'allargs'
independently of the host, and fix build breakage on Cygwin.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 14 Apr 2017 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoMake inferior a class with cdtors, and use new/delete
Pedro Alves [Thu, 13 Apr 2017 15:15:35 +0000 (16:15 +0100)]
Make inferior a class with cdtors, and use new/delete

struct inferior became a non-POD when enum_flags was made a non-POD,
so we should be allocating/destroying inferiors with new/delete, etc.
That's what this commit does.

Note: this commit makes all boolean fields of inferior be "bool",
except the "detaching" field.  That'll require more work, so I split
it to a separate patch.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* inferior.c (free_inferior): Convert to ...
(inferior::~inferior): ... this dtor.
(inferior::inferior): New ctor, factored out from ...
(add_inferior_silent): ... here.  Allocate the inferior with a new
expression.
(delete_inferior): Call delete instead of free_inferior.
* inferior.h (gdb_environ, continuation): Forward declare.
(inferior): Now a class.  Add in-class initialization to all
members.  Make boolean fields bool, except 'detaching'.
(inferior::inferior): New explicit ctor.
(inferior::~inferior): New.

7 years agoGC inferior.c:init_inferior_list
Pedro Alves [Thu, 13 Apr 2017 15:15:34 +0000 (16:15 +0100)]
GC inferior.c:init_inferior_list

Not used anywhere.  This was actually never used.  It came in because
I originally created inferior.c by copying thread.c, and doing
s/thread/inferior/g, and missed that nothing needs this.  :-)

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* inferior.c (init_inferior_list): Delete.
* inferior.h (init_inferior_list): Delete.

7 years agoImprove coverage of the PR threads/13217 regression test
Pedro Alves [Thu, 13 Apr 2017 15:15:34 +0000 (16:15 +0100)]
Improve coverage of the PR threads/13217 regression test

- Make sure we end up with no thread selected after the detach.

- Test both "thread apply all" and "thread apply $some_threads", for
  completeness.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

PR threads/13217
* gdb.threads/threadapply.exp (thr_apply_detach): New procedure.
(top level): Call it twice, with different thread sets.

7 years agoC++fy thread_apply_all_command
Pedro Alves [Thu, 13 Apr 2017 15:15:34 +0000 (16:15 +0100)]
C++fy thread_apply_all_command

This eliminates a couple cleanups.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* thread.c: Include <algorithm>.
(thread_array_cleanup): Delete.
(scoped_inc_dec_ref): New class.
(live_threads_count): New function.
(set_thread_refcount): Delete.
(tp_array_compar_ascending): Now a bool.
(tp_array_compar): Convert to a std::sort comparison function.
(thread_apply_all_command): Use std::vector and scoped_inc_dec_ref
and live_threads_count.

7 years agoFix follow-fork latent bug
Pedro Alves [Thu, 13 Apr 2017 15:15:34 +0000 (16:15 +0100)]
Fix follow-fork latent bug

A later patch in the series adds an assertion to switch_to_thread that
the resulting inferior_ptid always matches the "current_inferior()"
inferior.  This exposed a latent bug in the follow-fork code, where
we're building the fork child inferior.  We're switching
inferior_ptid, but not the current inferior object...

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* infrun.c (follow_fork_inferior): Also switch the current
inferior.

7 years agowatch_command_1: Fix dangling frame access
Pedro Alves [Thu, 13 Apr 2017 15:15:34 +0000 (16:15 +0100)]
watch_command_1: Fix dangling frame access

While working on some changes to switch_to_thread, I inadvertently
make switch_to_thread call reinit_frame_cache more frequently, even
when the thread didn't change.  This exposed a latent bug in
watch_command_1, where we're referencing a frame after
creating/inserting breakpoints, which potentially calls
reinit_frame_cache if it needs to install breakpoints with a different
thread selected.

Handle this similarly to how it's already handled in other similar
cases.  I.e., save any frame-related information we might need before
creating a breakpoint.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* breakpoint.c (watch_command_1): Save watchpoint-frame info
before calling create_internal_breakpoint.

7 years agoreadelf: fix out of range subtraction, seg fault from a NULL pointer and memory exhau...
Nick Clifton [Thu, 13 Apr 2017 15:06:30 +0000 (16:06 +0100)]
readelf: fix out of range subtraction, seg fault from a NULL pointer and memory exhaustion, all from parsing corrupt binaries.

PR binutils/21379
* readelf.c (process_dynamic_section): Detect over large section
offsets in the DT_SYMTAB entry.

PR binutils/21345
* readelf.c (process_mips_specific): Catch an unfeasible memory
allocation before it happens and print a suitable error message.

7 years agoAdd note merging to strip and add code to merge stack size notes.
Nick Clifton [Thu, 13 Apr 2017 13:50:56 +0000 (14:50 +0100)]
Add note merging to strip and add code to merge stack size notes.

* objcopy.c: Add --no-merge-notes option to disable note merging.
Add --[no-]merge-notes option to strip, and enable it by default.
(num_bytes): New function.
(merge_gnu_build_notes): Add code to merge stack size notes.
* binutils.texi: Update strip and objcopy documentation.
* readelf.c (print_gnu_build_attribute_name): Use defined
constants for note types.

7 years agoRegen cgen files
Alan Modra [Thu, 13 Apr 2017 01:03:53 +0000 (10:33 +0930)]
Regen cgen files

* epiphany-desc.c: Regenerate.
* fr30-desc.c: Regenerate.
* frv-desc.c: Regenerate.
* ip2k-desc.c: Regenerate.
* iq2000-desc.c: Regenerate.
* lm32-desc.c: Regenerate.
* m32c-desc.c: Regenerate.
* m32r-desc.c: Regenerate.
* mep-desc.c: Regenerate.
* mt-desc.c: Regenerate.
* or1k-desc.c: Regenerate.
* xc16x-desc.c: Regenerate.
* xstormy16-desc.c: Regenerate.

7 years agofork-child.c: Avoid unnecessary heap-allocation / string copying
Pedro Alves [Thu, 13 Apr 2017 10:46:07 +0000 (11:46 +0100)]
fork-child.c: Avoid unnecessary heap-allocation / string copying

The previous change to fork-child.c converted the argv building from
an alloca-allocated array of non-owning arg pointers, to a std::vector
of owning pointers, which results in N string dups, with N being the
number of arguments in the vector, and then requires manually
releasing the pointers owned by the vector.

This patch makes the vector hold non-owning pointers, and avoids the
string dups, by doing one single string copy of the arguments upfront,
and replacing separators with NULL terminators in place, like we used
to.  All the logic to do that is encapsulated in a new class.

With this, there's no need to remember to manually release the argv
elements with free_vector_argv either.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* fork-child.c (execv_argv): New class.
(breakup_args): Refactored as ...
(execv_argv::init_for_no_shell): .. this method of execv_argv.
Copy arguments to storage and replace separators with NULL
terminators in place.
(escape_bang_in_quoted_argument): Adjust to return bool.
(execv_argv::execv_argv): New ctor.
(execv_argv::init_for_shell): New method, factored out from
fork_inferior.  Don't strdup strings into the vector.
(fork_inferior): Eliminate "shell" local and use execv_argv.  Use
Remove free_vector_argv call.

7 years ago * config.sub: Sync with master version in config project.
Andrew Jenner [Thu, 13 Apr 2017 09:34:19 +0000 (02:34 -0700)]
* config.sub: Sync with master version in config project.

7 years agoAdd ChangeLog entries
Iain Buclaw [Thu, 13 Apr 2017 08:39:13 +0000 (10:39 +0200)]
Add ChangeLog entries

ChangeLog entries were left unstaged in my previous commit on March 30th.

7 years agoWrap long lines
Alan Modra [Thu, 13 Apr 2017 03:54:18 +0000 (13:24 +0930)]
Wrap long lines

Not a comprehensive change, just some split out from fixes made for
the %A and %B changes.

* coffcode.h: Wrap some overly long _bfd_error_handler args.
* elf.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-i386.c: Likewise.
* elf32-mep.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.

7 years agoUse %A and %B in more error messages
Alan Modra [Thu, 13 Apr 2017 03:50:15 +0000 (13:20 +0930)]
Use %A and %B in more error messages

* aoutx.h: Use %B and %A in error messages throughout file.
* aout-cris.c: Likewise.
* archive.c: Likewise.
* binary.c: Likewise.
* coff-rs6000.c: Likewise.
* coff-tic4x.c: Likewise.
* coffcode.h: Likewise.
* coffgen.c: Likewise.
* cofflink.c: Likewise.
* coffswap.h: Likewise.
* cpu-arm.c: Likewise.
* elf-eh-frame.c: Likewise.
* elf-m10300.c: Likewise.
* elf.c: Likewise.
* elf32-arc.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-bfin.c: Likewise.
* elf32-frv.c: Likewise.
* elf32-iq2000.c: Likewise.
* elf32-m32c.c: Likewise.
* elf32-microblaze.c: Likewise.
* elf32-nds32.c: Likewise.
* elf32-rl78.c: Likewise.
* elf32-rx.c: Likewise.
* elf32-score.c: Likewise.
* elf32-score7.c: Likewise.
* elf32-sh64.c: Likewise.
* elf32-v850.c: Likewise.
* elf32-vax.c: Likewise.
* elf32-visium.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-mmix.c: Likewise.
* elf64-sh64.c: Likewise.
* elfcode.h: Likewise.
* elfnn-aarch64.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.
* hpux-core.c: Likewise.
* ieee.c: Likewise.
* ihex.c: Likewise.
* linker.c: Likewise.
* merge.c: Likewise.
* mmo.c: Likewise.
* oasys.c: Likewise.
* pdp11.c: Likewise.
* peXXigen.c: Likewise.
* rs6000-core.c: Likewise.
* vms-alpha.c: Likewise.
* xcofflink.c: Likewise.

7 years agoRewrite bfd error handler
Alan Modra [Thu, 13 Apr 2017 01:28:40 +0000 (10:58 +0930)]
Rewrite bfd error handler

This steals _doprnt from libiberty, extended to handle %A and %B.
Which lets us do away with the current horrible %A and %B handling
that requires all %A and %B arguments to be passed first, rather than
in the natural order.

* bfd.c (PRINT_TYPE): Define.
(_doprnt): New function.
(error_handler_internal): Use _doprnt.
* coff-arm.c: Put %A and %B arguments to _bfd_error_handler
calls in their natural order, throughout file.
* coff-mcore.c: Likewise.
* coff-ppc.c: Likewise.
* coff-tic80.c: Likewise.
* cofflink.c: Likewise.
* elf-s390-common.c: Likewise.
* elf.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-i386.c: Likewise.
* elf32-m32r.c: Likewise.
* elf32-msp430.c: Likewise.
* elf32-spu.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-sparc.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c: Likewise.
* elfnn-aarch64.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.

7 years agoMissing _bfd_error_handler args
Alan Modra [Thu, 13 Apr 2017 01:14:20 +0000 (10:44 +0930)]
Missing _bfd_error_handler args

* elf32-arm.c (arm_type_of_stub): Supply missing args to "long
branch veneers" error.  Fix double space and format message.
* elf32-avr.c (avr_add_stub): Do not pass NULL as %B arg.
* elf64-ppc.c (tocsave_find): Supply missing %B arg.

7 years agoRegen bfd-in2.h
Alan Modra [Thu, 13 Apr 2017 01:03:11 +0000 (10:33 +0930)]
Regen bfd-in2.h

* bfd-in2.h: Regenerate.

7 years agoFix a typo in rx_fpsw_type
Yao Qi [Thu, 13 Apr 2017 07:29:44 +0000 (08:29 +0100)]
Fix a typo in rx_fpsw_type

gdb:

2017-04-13  Yao Qi  <yao.qi@linaro.org>

* rx-tdep.c (rx_fpsw_type): Check tdep->rx_fpsw_type instead of
tdep->rx_psw_type.

7 years agoXCNEW gdbarch_tdep in rl78 and rx
Yao Qi [Thu, 13 Apr 2017 07:29:43 +0000 (08:29 +0100)]
XCNEW gdbarch_tdep in rl78 and rx

"struct gdbarch_tdep" is XNEW'ed in rl78 and rx, so the memory is not
cleared.  As the result, tdep->rl78_psw_type is never initialized
properly.

  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  if (tdep->rl78_psw_type == NULL)
    {
      tdep->rl78_psw_type = arch_flags_type (gdbarch,
     "builtin_type_rl78_psw", 1);

The bug is found by my unit test in the following patch.

gdb:

2017-04-13  Yao Qi  <yao.qi@linaro.org>

* rl78-tdep.c (rl78_gdbarch_init): Use XCNEW instead of XNEW.
* rx-tdep.c (rx_gdbarch_init): Likewise.