binutils-gdb.git
7 years agoDistinguish some of the registers different on ARC700 and HS38 cpus
Vineet Gupta [Wed, 15 Feb 2017 08:52:53 +0000 (08:52 +0000)]
Distinguish some of the registers different on ARC700 and HS38 cpus

opcodes * arc-regs.h: Distinguish some of the registers different on
ARC700 and HS38 cpus.

gas * testsuite/gas/arc/st.d: Update for 0xe having a name now

7 years agoImproved support for --icf=safe when used with -pie.
Rahul Chaudhry [Wed, 15 Feb 2017 08:37:10 +0000 (00:37 -0800)]
Improved support for --icf=safe when used with -pie.

gold/
* x86_64.cc (Target_x86_64::do_can_check_for_function_pointers):
Return true even when building pie binaries.
(Target_x86_64::possible_function_pointer_reloc): Check opcode
for R_X86_64_PC32 relocations.
(Target_x86_64::local_reloc_may_be_function_pointer): Pass
extra arguments to local_reloc_may_be_function_pointer.
(Target_x86_64::global_reloc_may_be_function_pointer): Likewise.
* gc.h (gc_process_relocs): Add check for STT_FUNC.
* testsuite/Makefile.am (icf_safe_pie_test): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/icf_safe_pie_test.sh: New shell script.

7 years agoAdd missing ChangeLog entries.
Tim Wiederhake [Wed, 15 Feb 2017 07:08:17 +0000 (08:08 +0100)]
Add missing ChangeLog entries.

This adds the missing ChangeLog entries for the "Python bindings" patch series.

7 years agoAutomatic date update in version.in
GDB Administrator [Wed, 15 Feb 2017 00:00:23 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAdd self to aarch64 maintainers. Fix mla instruction.
Jim Wilson [Tue, 14 Feb 2017 23:23:12 +0000 (15:23 -0800)]
Add self to aarch64 maintainers.  Fix mla instruction.

sim/
* MAINTAINTERS (aarch64): Add myself.

sim/aarch64/
* simulator.c (do_vec_MLA): Rewrite switch body.

sim/testsuite/sim/aarch64/
* mla.s: New.

7 years agoFix bit/bif instructions.
Jim Wilson [Tue, 14 Feb 2017 22:35:57 +0000 (14:35 -0800)]
Fix bit/bif instructions.

sim/aarch64/
* simulator.c (do_vec_bit): Change loop limits from 16 and 8 to 4 and
2.  Move test_false if inside loop.  Fix logic for computing result
stored to vd.

sim/testsuite/sim/aarch64
* bit.s: New.

7 years agoAdd ldn/stn single support, fix ldnr support.
Jim Wilson [Tue, 14 Feb 2017 22:31:03 +0000 (14:31 -0800)]
Add ldn/stn single support, fix ldnr support.

sim/aarch64/
* simulator.c: (LDn_STn_SINGLE_LANE_AND_SIZE): New.
(do_vec_LDn_single, do_vec_STn_single): New.
(do_vec_LDnR): Add and set new nregs var.  Replace switch on nregs with
loop over nregs using new var n.  Add n times size to address in loop.
Add n to vd in loop.
(do_vec_load_store): Add comment for instruction bit 24.  New var
single to hold instruction bit 24.  Add new code to use single.  Move
ldnr support inside single if statements.  Fix ldnr register counts
inside post if statement.  Change HALT_NYI calls to HALT_UNALLOC.

sim/testsuite/sim/aarch64/
* ldn_single.s: New.
* ldnr.s: New.
* stn_single.s: New.

7 years agoPR python/13598 - add before_prompt event
Tom Tromey [Wed, 29 Apr 2015 15:44:24 +0000 (09:44 -0600)]
PR python/13598 - add before_prompt event

This adds an event that is emitted just before GDB presents a prompt
to the user.  This provides Python code a way to react to whatever
changes might have been made by the previous command.  For example, in
my GUI I use this to track changes to the selected frame and reflect
them in the UI.

Built and regtested on x86-64 Fedora 23.

gdb/ChangeLog
2017-02-14  Tom Tromey  <tom@tromey.com>

PR python/13598:
* python/python.c (gdbpy_before_prompt_hook): Emit before_prompt
event.
* python/py-evts.c (gdbpy_initialize_py_events): Add
before_prompt registry.
* python/py-events.h (events_object) <before_prompt>: New field.

gdb/doc/ChangeLog
2017-02-14  Tom Tromey  <tom@tromey.com>

PR python/13598:
* python.texi (Events In Python): Document events.before_prompt.

gdb/testsuite/ChangeLog
2017-02-14  Tom Tromey  <tom@tromey.com>

PR python/13598:
* gdb.python/py-events.exp: Add before_prompt event tests.

7 years agoBig-endian targets: Fix implptrpiece.exp
Andreas Arnez [Tue, 14 Feb 2017 17:17:19 +0000 (18:17 +0100)]
Big-endian targets: Fix implptrpiece.exp

The test case implptrpiece.exp accesses the second byte of the short
integer number 1 and expects it to be zero.  This is valid for
little-endian targets, but fails on big-endian targets.

This is fixed by distinguishing the expected value by endianness.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/implptrpiece.exp: Fix check for big-endian targets.

7 years agoFix invalid memory access displayiing contents of sections.
Nick Clifton [Tue, 14 Feb 2017 15:10:34 +0000 (15:10 +0000)]
Fix invalid memory access displayiing contents of sections.

PR binutils/21159
* readelf.c (dump_section_as_strings): Reset the start address if
no decompression is perfromed.
(dump_section_as_bytes): Likewise.

7 years agoFix an illegal memory access parsing corrupt STABD debug information.
Nick Clifton [Tue, 14 Feb 2017 14:17:09 +0000 (14:17 +0000)]
Fix an illegal memory access parsing corrupt STABD debug information.

PR binutils/21158
* rddbg.c (read_symbol_stabs_debugging_info): Check for a null or
empty symbol name.

7 years agoFix handling of corrupt STABS enum type strings.
Nick Clifton [Tue, 14 Feb 2017 14:07:29 +0000 (14:07 +0000)]
Fix handling of corrupt STABS enum type strings.

PR binutils/21157
* stabs.c (parse_stab_enum_type): Check for corrupt NAME:VALUE
pairs.
(parse_number): Exit early if passed an empty string.

7 years agoFix illegal memory access problems with readelf processing corrupt RL78 binaries.
Nick Clifton [Tue, 14 Feb 2017 13:24:09 +0000 (13:24 +0000)]
Fix illegal memory access problems with readelf processing corrupt RL78 binaries.

PR binutils/21155
* readelf.c (IN_RANGE): New macro.  Tests for an address + offset
being within a given range.
(target_specific_reloc_handling): Use macro to test for underflow
as well as overflow of reloc offset.

7 years agoPowerPC register expression checks
Alan Modra [Tue, 14 Feb 2017 10:08:21 +0000 (20:38 +1030)]
PowerPC register expression checks

This stops powerpc gas blithely accepting such nonsense as
"addi %f4,%cr3,%r31".

PR 21118
gas/
* NEWS: Mention powerpc register checks.
* config/tc-ppc.c (struct pd_reg): Make value a short.  Add flags.
(pre_defined_registers): Delete fpscr and pmr entries.  Set
register type in flags.
(cr_names): Set type in flags.
(reg_name_search): Return pointer to struct pd_reg rather than value.
(register_name): Adjust to suit.  Set X_md from flags.
(ppc_parse_name): Likewise.
(ppc_optimize_expr): New function.
(md_assemble): Verify expresion reg flags match operand.
* config/tc-ppc.h (md_optimize_expr): Define.
(ppc_optimize_expr): Declare.
include/
* opcode/ppc.h (PPC_OPERAND_*): Reassign values, regs first.
(PPC_OPERAND_SPR, PPC_OPERAND_GQR): Define.
opcodes/
* ppc-opc.c (powerpc_operands): Flag SPR, SPRG and TBR entries
with PPC_OPERAND_SPR.  Flag PSQ and PSQM with PPC_OPERAND_GQR.

7 years agoFix powerpc testsuite source errors
Alan Modra [Tue, 14 Feb 2017 10:00:27 +0000 (20:30 +1030)]
Fix powerpc testsuite source errors

PR 21118 work exposed these errors in the testsuite.

* testsuite/gas/ppc/cell.s: Correct invalid registers.
* testsuite/gas/ppc/vle-simple-1.s: Likewise.
* testsuite/gas/ppc/vle-simple-2.s: Likewise.

7 years agoUpdate ppc64_elf_gc_mark_dynamic_ref
Alan Modra [Tue, 14 Feb 2017 05:29:13 +0000 (15:59 +1030)]
Update ppc64_elf_gc_mark_dynamic_ref

* elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Support
--gc-keep-exported, and test versioned field of sym rather than
looking for @ in name.

7 years agoAdd documentation for new record Python bindings.
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
Add documentation for new record Python bindings.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog:

* NEWS: Add record Python bindings entry.

gdb/doc/ChangeLog:

* python.texi (Recordings In Python): New section.

Change-Id: Ibacb5930085bff36b0003fde30db9a8178cb280b

7 years agopython: Add tests for record Python bindings
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
python: Add tests for record Python bindings

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/testsuite/ChangeLog:

        * gdb.python/py-record-btrace.c, gdb.python/py-record-btrace.exp,
gdb.python/py-record-full.c, gdb.python/py-record-full.exp: New file.

Change-Id: Icd919b4e1d5642f5cbc097a6aede1416eba402e5

7 years agopython: Implement btrace Python bindings for record history.
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
python: Implement btrace Python bindings for record history.

This patch implements the gdb.Record Python object methods and fields for
record target btrace.  Also, implement a stub for record target full.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog:

* Makefile.in (SUBDIR_PYTHON_OBS): Add py-record-btrace.o,
py-record-full.o.
(SUBDIR_PYTHON_SRCS): Add py-record-btrace.c, py-record-full.c.
* python/py-record-btrace.c, python/py-record-btrace.h,
python/py-record-full.c, python/py-record-full.h: New file.
* python/py-record.c: Add include for py-record-btrace.h and
py-record-full.h.
(recpy_method, recpy_format, recpy_goto, recpy_replay_position,
recpy_instruction_history, recpy_function_call_history, recpy_begin,
recpy_end): Use functions from py-record-btrace.c and py-record-full.c.
* python/python-internal.h (PyInt_FromSsize_t, PyInt_AsSsize_t):
New definition.
(gdbpy_initialize_btrace): New export.
* python/python.c (_initialize_python): Add gdbpy_initialize_btrace.

Change-Id: I8bd893672ffc7e619cc1386767897249e125973a

7 years agopython: Create Python bindings for record history.
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
python: Create Python bindings for record history.

This patch adds three new functions to the gdb module in Python:
- start_recording
- stop_recording
- current_recording
start_recording and current_recording return an object of the new type
gdb.Record, which can be used to access the recorded data.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog

* Makefile.in (SUBDIR_PYTHON_OBS): Add python/py-record.o.
(SUBDIR_PYTHON_SRCS): Add python/py-record.c.
* python/py-record.c: New file.
* python/python-internal.h (gdbpy_start_recording,
gdbpy_current_recording, gdpy_stop_recording,
gdbpy_initialize_record): New export.
* python/python.c (_initialize_python): Add gdbpy_initialize_record.
(python_GdbMethods): Add gdbpy_start_recording,
gdbpy_current_recording and gdbpy_stop_recording.

Change-Id: I772aa9aa068621443f10a330b11dc7dc9a63face

7 years agoAdd method to query current recording method to target_ops.
Tim Wiederhake [Tue, 13 Dec 2016 10:24:56 +0000 (11:24 +0100)]
Add method to query current recording method to target_ops.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog

* record-btrace.c (record_btrace_record_method): New function.
(init_record_btrace_ops): Initialize to_record_method.
* record-full.c (record_full_record_method): New function.
(init_record_full_ops, init_record_full_core_ops): Add
record_full_record_method.
* record.h (enum record_method): New enum.
* target-debug.h (target_debug_print_enum_record_method: New define.
* target-delegates.c: Regenerate.
* target.c (target_record_method): New function.
* target.h: Include record.h.
(struct target_ops) <to_record_method>: New field.
(target_record_method): New export.

Change-Id: I05daa70e4e08a19901e848c731bb7d60cd87cc5a

7 years agoAdd record_start and record_stop functions.
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
Add record_start and record_stop functions.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog

* record.h (record_start, record_stop): New export.
* record.c (record_start, record_stop): New function.

Change-Id: If235d4bde8ec61dab6dbd23e087430e66d2e91a7

7 years agobtrace: Use binary search to find instruction.
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
btrace: Use binary search to find instruction.

Currently, btrace_find_insn_by_number will iterate over all function call
segments to find the one that contains the needed instruction.  This linear
search is too slow for the upcoming Python bindings that will use this
function to access instructions.  This patch introduces a vector in struct
btrace_thread_info that holds pointers to all recorded function segments and
allows to use binary search.

The proper solution is to turn the underlying tree into a vector of objects
and use indices for access.  This requires more work.  A patch set is
currently being worked on and will be published later.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog:
* btrace.c (btrace_fetch): Copy function call segments pointer
into a vector.
(btrace_clear): Clear the vector.
(btrace_find_insn_by_number): Use binary search to find the correct
function call segment.
* btrace.h (brace_fun_p): New typedef.
(struct btrace_thread_info) <functions>: New field.

Change-Id: I8a7f67e80bfe4ff62c4192f74a2153a70bf2a035

7 years agobtrace: Export btrace_decode_error function.
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
btrace: Export btrace_decode_error function.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog:

* record-btrace.c (btrace_ui_out_decode_error): Move most of it ...
* btrace.c (btrace_decode_error): ... here.  New function.
* btrace.h (btrace_decode_error): New export.

Change-Id: I2b4b43a55dbfd9f526a540d2ad52a6708f31feba

7 years agobtrace: Count gaps as one instruction explicitly.
Tim Wiederhake [Mon, 21 Nov 2016 15:39:57 +0000 (16:39 +0100)]
btrace: Count gaps as one instruction explicitly.

This gives all instructions, including gaps, a unique number.  Add a function
to retrieve the error code if a btrace instruction iterator points to an
invalid instruction.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog:

* btrace.c (ftrace_call_num_insn, btrace_insn_get_error): New function.
(ftrace_new_function, btrace_insn_number, btrace_insn_cmp,
btrace_find_insn_by_number): Remove special case for gaps.
* btrace.h (btrace_insn_get_error): New export.
(btrace_insn_number, btrace_find_insn_by_number): Adjust comment.
* record-btrace.c (btrace_insn_history): Print number for gaps.
(record_btrace_info, record_btrace_goto): Handle gaps.

Change-Id: I8eb0e48a95f4278522fea74ea13526bfe6898ecc

7 years agobtrace: preserve call stack on function switch
Markus Metzger [Mon, 30 Jan 2017 08:16:27 +0000 (09:16 +0100)]
btrace: preserve call stack on function switch

On 64-bit FC25, the _dl_runtime_resolve function uses a conditional branch to
'call' a particular variant optimized for that system:

    (gdb) disas _dl_runtime_resolve_avx_opt
    Dump of assembler code for function _dl_runtime_resolve_avx_opt:
       0x00007ffff7deeb60 <+0>: push   %rax
       0x00007ffff7deeb61 <+1>: push   %rcx
       0x00007ffff7deeb62 <+2>: push   %rdx
       0x00007ffff7deeb63 <+3>: mov    $0x1,%ecx
       0x00007ffff7deeb68 <+8>: xgetbv
       0x00007ffff7deeb6b <+11>: mov    %eax,%r11d
       0x00007ffff7deeb6e <+14>: pop    %rdx
       0x00007ffff7deeb6f <+15>: pop    %rcx
       0x00007ffff7deeb70 <+16>: pop    %rax
       0x00007ffff7deeb71 <+17>: and    $0x4,%r11d
       0x00007ffff7deeb75 <+21>: bnd je 0x7ffff7def4a0 <_dl_runtime_resolve_sse_vex>
    End of assembler dump.

When computing the function-level trace, btrace treats this as a switch from
_dl_runtime_resolve_avx_opt to _dl_runtime_resolve_sse_vex.  We know that we
switched functions but we can't really say in which caller/callee relationship
those two functions are.

In addition to preserving the indentaion level, also preserve the caller
information.  This is a heuristic since we don't really know.  But at least in
this case, this seems to be the right thing to do.

This fixes a fail in gdb.btrace/rn-dl-bind.exp on 64-bit FC25.

gdb/
* btrace.c (ftrace_new_switch): Preserve up link and flags.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 14 Feb 2017 00:00:30 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoDon't use "_gp" on RISC-V, use "_global_pointer$" instead
Palmer Dabbelt [Wed, 8 Feb 2017 19:26:07 +0000 (11:26 -0800)]
Don't use "_gp" on RISC-V, use "_global_pointer$" instead

"_gp" could conflict with ABI-complient code.  While it's probably OK
because MIPS uses this name, we figured it'd be good to clean this up
before a release with RISC-V in it.

ld/ChangeLog:

2017-02-13  Palmer Dabbelt  <palmer@dabbelt.com>

        * emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Change
        _gp to __global_pointer$.

bfd/ChangeLog:

2017-02-13  Palmer Dabbelt  <palmer@dabbelt.com>

        * elfnn-riscv.c (riscv_global_pointer_value): Change _gp to
        __global_pointer$.

7 years agoFix invalid memory access in the BFD library's DWARF parser.
Nick Clifton [Mon, 13 Feb 2017 17:51:27 +0000 (17:51 +0000)]
Fix invalid memory access in the BFD library's DWARF parser.

PR binutils/21151
* dwarf2.c (_bfd_dwarf2_find_nearest_line): Check for an invalid
unit length field.

7 years ago[ARM] Allow immediate without prefix in unified syntax for VCMP
Thomas Preud'homme [Mon, 13 Feb 2017 17:46:59 +0000 (17:46 +0000)]
[ARM] Allow immediate without prefix in unified syntax for VCMP

2017-02-13  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gas/
* config/tc-arm.c (parse_ifimm_zero): Make prefix optional in unified
syntax.
* testsuite/gas/arm/vcmp-noprefix-imm.d: New file.
* testsuite/gas/arm/vcmp-noprefix-imm.s: New file.

7 years agoFix illegal memory access bug in nm when run on a corrupt binary.
Nick Clifton [Mon, 13 Feb 2017 17:23:10 +0000 (17:23 +0000)]
Fix illegal memory access bug in nm when run on a corrupt binary.

PR binutils/21150
* nm.c (file_symbol): Add test of string length before testing
string characters.

7 years agoExtend previous patch to cover uncompress_section_contents returning FALSE to other...
Nick Clifton [Mon, 13 Feb 2017 15:19:48 +0000 (15:19 +0000)]
Extend previous patch to cover uncompress_section_contents returning FALSE to other callers.

PR binutils/21135
(dump_section_as_bytes, load_specific_debug_section): Likewise.

7 years agoFix invalid read of section contents whilst processing a corrupt binary.
Nick Clifton [Mon, 13 Feb 2017 15:04:37 +0000 (15:04 +0000)]
Fix invalid read of section contents whilst processing a corrupt binary.

PR binutils/21135
* readelf.c (dump_section_as_bytes): Handle the case where
uncompress_section_contents returns false.

7 years agoFix invalid memory access attempting to read the compression header of a too-small...
Nick Clifton [Mon, 13 Feb 2017 14:52:48 +0000 (14:52 +0000)]
Fix invalid memory access attempting to read the compression header of a too-small compressed section.

PR binutils/21149
* readelf.c (get_compression_header): Add size parameter.  Check
size against sizeof compression header before attempting to
extract the header.
(process_section_headers): Pass size to get_compression_header.
(dump_section_as_strings): Likewise.
(dump_section_as_bytes): Likewise.
(load_specific_debug_section): Likewise.

7 years agoFix check for buffer overflow when processing version information.
Nick Clifton [Mon, 13 Feb 2017 14:35:24 +0000 (14:35 +0000)]
Fix check for buffer overflow when processing version information.

PR binutils/21148
* readelf.c (process_version_sections): Include size of auxillary
version information when checking for buffer overflow.

7 years agoFix access violation when reporting sections that could not be dumped.
Nick Clifton [Mon, 13 Feb 2017 14:17:07 +0000 (14:17 +0000)]
Fix access violation when reporting sections that could not be dumped.

PR binutils/21147
* readelf.c (process_section_contents): Fix off by one error
reporting un-dumped sections.

7 years agoFix read-after-free error in readelf when processing multiple, relocated sections...
Nick Clifton [Mon, 13 Feb 2017 14:03:22 +0000 (14:03 +0000)]
Fix read-after-free error in readelf when processing multiple, relocated sections in an MSP430 binary.

PR binutils/21139
* readelf.c (target_specific_reloc_handling): Add num_syms
parameter.  Check for symbol table overflow before accessing
symbol value.  If reloc pointer is NULL, discard all saved state.
(apply_relocations): Pass num_syms to target_specific_reloc_handling.
Call target_specific_reloc_handling with a NULL reloc pointer
after processing all of the relocs.

7 years agoImprove load command's help text
Luis Machado [Mon, 13 Feb 2017 13:29:30 +0000 (07:29 -0600)]
Improve load command's help text

This fairly obvious patch adds usage text to the load command's help text.

Originally it did not have usage and mentioned things like FILE and OFFSET
without explaining how those should be passed in the command.

gdb/ChangeLog:

2017-02-13  Luis Machado  <lgustavo@codesourcery.com>

* symfile (_initialize_symfile): Add usage text to the load command's
help text.

gdb/doc/ChangeLog:

2017-02-13  Luis Machado  <lgustavo@codesourcery.com>

* gdb.texinfo (Target Commands): Document the optional offset
argument for the load command.

7 years agoFix gdb.linespec/explicit.exp
Luis Machado [Mon, 13 Feb 2017 13:16:34 +0000 (07:16 -0600)]
Fix gdb.linespec/explicit.exp

This patch addresses timeout failures i noticed while testing aarch64-elf.

FAIL: gdb.linespec/explicit.exp: complete unique function name (timeout)
FAIL: gdb.linespec/explicit.exp: complete non-unique function name (timeout)
FAIL: gdb.linespec/explicit.exp: complete non-existant function name (timeout)
FAIL: gdb.linespec/explicit.exp: complete unique file name (timeout)
FAIL: gdb.linespec/explicit.exp: complete non-unique file name (timeout)

The timeouts were caused by an attempt to match a bell character (x07) that
doesn't show up on my particular test setup.

The bell character is output whenever one tries to complete a pattern and there
are multiple possible matches. When there is only one possible match, GDB will
complete the input pattern without outputting the bell character.

The reason for the discrepancy in this test's behavior is due to the use of
"main" for a unique name test.

On glibc-based systems, GDB may notice the "main_arena" symbol, which is
a data global part of glibc's malloc implementation. Therefore a bell character
will be output because we have a couple possible completion matches.

GDB should not be outputting such a data symbol as a possible match, but this
problem may/will be addressed in a future change and is besides the point of
this particular change.

On systems that are not based on glibc, GDB will not see any other possible
matches for completing "main", so there will be no bell characters.

The use of main is a bit fragile though, so the patch adds a new local function
with a name that has a greater chance of being unique and adjusts the test to
iuse it.

I've also added the regular expression switch (-re) to all the
gdb_test_multiple calls that were missing it. Hopefully this will reduce the
chances of someone wasting time trying to match a regular expression (a much
more common use case) when, in reality, the pattern is supposed to be matched
literally.

gdb/testsuite/ChangeLog

2017-02-13  Luis Machado  <lgustavo@codesourcery.com>

* gdb.linespec/explicit.c (my_unique_function_name): New function.
(main): Call my_unique_function_name.
* gdb.linespec/explicit.exp: Use my_unique_function_name to test
completion of patterns with a single match.
Add missing -re switches to gdb_test_multiple calls.

7 years agoMake gdb.arch/i386-biarch-core.exp more robust
Luis Machado [Mon, 13 Feb 2017 13:12:17 +0000 (07:12 -0600)]
Make gdb.arch/i386-biarch-core.exp more robust

This test attempts to load a x86 core file no matter what target
architectures the tested GDB supports. If GDB doesn't know how to handle
a i386 target, it is very likely the core file will not be recognized.

In this case we should still attempt to load a core file to make sure GDB
doesn't crash or throws an internal error.  But we should not proceed to
try to read memory unconditionally.

This patch makes the test check for proper i386 arch support in GDB and bails
out if i386 is not supported and the core file format is not recognized.

This addresses the spurious aarch64-elf failures i'm seeing for this test.

gdb/testsuite/ChangeLog:

2017-02-13  Luis Machado  <lgustavo@codesourcery.com>

* gdb.arch/i386-biarch-core.exp: Check for i386 arch support and
return if core file is not recognized.

7 years agoFix readelf writing to illegal addresses whilst processing corrupt input files contai...
Nick Clifton [Mon, 13 Feb 2017 13:08:32 +0000 (13:08 +0000)]
Fix readelf writing to illegal addresses whilst processing corrupt input files containing symbol-difference relocations.

PR binutils/21137
* readelf.c (target_specific_reloc_handling): Add end parameter.
Check for buffer overflow before writing relocated values.
(apply_relocations): Pass end to target_specific_reloc_handling.

7 years agosim: use ARRAY_SIZE instead of ad-hoc sizeof calculations
Mike Frysinger [Mon, 13 Feb 2017 05:12:35 +0000 (00:12 -0500)]
sim: use ARRAY_SIZE instead of ad-hoc sizeof calculations

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 13 Feb 2017 00:00:29 +0000 (00:00 +0000)]
Automatic date update in version.in

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

7 years agoFix use after free in cgen instruction lookup
Alan Modra [Sat, 11 Feb 2017 06:47:59 +0000 (17:17 +1030)]
Fix use after free in cgen instruction lookup

* cgen-opc.c (cgen_lookup_insn): Delete buf and base_insn temps.
Use insn_bytes_value and insn_int_value directly instead.  Don't
free allocated memory until function exit.

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 11 Feb 2017 00:00:30 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoDo not send queries on secondary UIs
Simon Marchi [Fri, 10 Feb 2017 21:29:50 +0000 (16:29 -0500)]
Do not send queries on secondary UIs

This is a follow-up to

  https://sourceware.org/ml/gdb-patches/2017-02/msg00261.html

This patch restricts queries to the main UI, which allows to avoid two
different problems.

The first one is that GDB is issuing queries on secondary MI channels
for which a TTY is allocated.  The second one is that GDB is not able to
handle queries on two (CLI) UIs simultaneously.  Restricting queries to
the main UI allows to bypass these two problems.

More details on how/why these two problems happen:

1. Queries on secondary MI UI

  The current criterion to decide if we should query the user is whether
  the input stream is a TTY.  The original way to start GDB in MI mode
  from a front-end was to create a subprocess with pipes to its
  stdin/stdout.  In this case, the input was considered non-interactive
  and queries were auto-answered.  Now that front-ends can create the MI
  channel as a separate UI connected to a dedicated TTY, GDB now
  considers this input stream as interactive and sends queries to it.
  By restricting queries to the main UI, we make sure we never query on
  the secondary MI UI.

2. Simultaneous queries

  As Pedro stated it, when you have two queries on two different CLI UIs
  at the same time, you end up with the following pseudo stack:

  #0 gdb_readline_wrapper
  #1 defaulted_query                 // for UI #2
  #2 handle_command
  #3 execute_command ("handle SIGTRAP" ....
  #4 stdin_event_handler             // input on UI #2
  #5 gdb_do_one_event
  #7 gdb_readline_wrapper
  #8 defaulted_query                 // for UI #1
  #9 handle_command
  #10 execute_command ("handle SIGINT" ....
  #11 stdin_event_handler            // input on UI #1
  #12 gdb_do_one_event
  #13 gdb_readline_wrapper

  trying to answer the query on UI #1 will therefore answer for UI #2.

  By restricting the queries to the main UI, we ensure that there will
  never be more than one pending query, since you can't have two queries
  on a UI at the same time.

I added a snippet to gdb.base/new-ui.exp to verify that we get a query
on the main UI, but that we don't on the secondary one (or, more
precisely, that it gets auto-answered).

gdb/ChangeLog:

* utils.c (defaulted_query): Don't query on secondary UIs.

gdb/testsuite/ChangeLog:

* gdb.base/new-ui.exp (do_test): Test queries behavior on main
and extra UIs.

7 years agonew-ui.exp: Use proc_with_prefix
Simon Marchi [Fri, 10 Feb 2017 21:29:45 +0000 (16:29 -0500)]
new-ui.exp: Use proc_with_prefix

gdb/testsuite/ChangeLog:

* gdb.base/new-ui.exp (do_test, do_test_invalid_args): Use
proc_with_prefix.

7 years agoRemove unused variable in rust-lang.c
Tom Tromey [Fri, 10 Feb 2017 20:09:23 +0000 (13:09 -0700)]
Remove unused variable in rust-lang.c

I found another unused "cleanup" local variable, this time in
rust-lang.c.  This patch removes it.  Committing as obvious.

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* rust-lang.c (rust_get_disr_info): Remove unused variable.

7 years agoFix Python test to use lowercase command
Tom Tromey [Thu, 9 Feb 2017 20:39:32 +0000 (13:39 -0700)]
Fix Python test to use lowercase command

While testing this series I saw some errors from the Python test
suite.  There were a couple of tests using "P" as a command; this
changes them to "p".

gdb/testsuite/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* gdb.python/py-xmethods.exp: Use "p" command, not "P".

7 years agoRemove unnecessary local variables
Tom Tromey [Thu, 9 Feb 2017 20:32:48 +0000 (13:32 -0700)]
Remove unnecessary local variables

I found an unused local variables in a couple of places in the Python
code; this removes them.

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* python/py-value.c (valpy_richcompare_throw): Remove unnecessary
"cleanup" local.
* python/py-type.c (typy_legacy_template_argument): Remove
unnecessary "cleanup" local.

7 years agoRemove some gotos from Python
Tom Tromey [Thu, 12 Jan 2017 15:59:26 +0000 (08:59 -0700)]
Remove some gotos from Python

This patch slightly refactors a couple of spots in the Python code to
avoid some gotos.

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* python/python.c (do_start_initialization): New function, from
_initialize_python.
(_initialize_python): Call do_start_initialization.
* python/py-linetable.c (ltpy_iternext): Use explicit returns, not
goto.

7 years agoChange one more spot to use gdbpy_ref
Tom Tromey [Thu, 12 Jan 2017 14:46:07 +0000 (07:46 -0700)]
Change one more spot to use gdbpy_ref

This patch changes one more spot in the Python layer to use gdbpy_ref.

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* python/py-prettyprint.c (pretty_print_one_value): Use
gdbpy_ref.

7 years agoUse gdbpy_ref to simplify some logic
Tom Tromey [Wed, 11 Jan 2017 23:28:43 +0000 (16:28 -0700)]
Use gdbpy_ref to simplify some logic

This uses the new gdbpy_ref template to simplify logic in various
parts of the Python layer; for example removing repeated error code or
removing gotos.

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* python/py-cmd.c (cmdpy_destroyer): Use gdbpy_ref.
* python/py-breakpoint.c (gdbpy_breakpoint_deleted): Use
gdbpy_ref.
* python/py-type.c (field_new): Use gdbpy_ref.
* python/py-symtab.c (symtab_and_line_to_sal_object): Use
gdbpy_ref.
* python/py-progspace.c (pspy_new): Use gdbpy_ref.
(py_free_pspace): Likewise.
(pspace_to_pspace_object): Likewise.
* python/py-objfile.c (objfpy_new): Use gdbpy_ref.
(py_free_objfile): Likewise.
(objfile_to_objfile_object): Likewise.
* python/py-inferior.c (delete_thread_object): Use
gdbpy_ref.
(infpy_read_memory): Likewise.
(py_free_inferior): Likewise.
* python/py-evtregistry.c (create_eventregistry_object): Use
gdbpy_ref.
* python/py-event.c (create_event_object): Use gdbpy_ref.

7 years agoTurn gdbpy_ref into a template
Tom Tromey [Thu, 9 Feb 2017 20:16:36 +0000 (13:16 -0700)]
Turn gdbpy_ref into a template

This turns gdbpy_ref into a template class, so that it can be used to
wrap subclasses of PyObject.  The default argument remains PyObject;
and this necessitated renaming uses of "gdbpy_ref" to "gdbpy_ref<>".

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* python/py-ref.h (gdbpy_ref_policy): Now a template.
(gdbpy_ref): Now a template; allow subclasses of PyObject to be
used.
* python/py-arch.c, python/py-bpevent.c, python/py-breakpoint.c,
python/py-cmd.c, python/py-continueevent.c, python/py-event.c,
python/py-exitedevent.c, python/py-finishbreakpoint.c,
python/py-framefilter.c, python/py-function.c,
python/py-inferior.c, python/py-infevents.c,
python/py-linetable.c, python/py-newobjfileevent.c,
python/py-param.c, python/py-prettyprint.c, python/py-ref.h,
python/py-signalevent.c, python/py-stopevent.c,
python/py-symbol.c, python/py-threadevent.c, python/py-type.c,
python/py-unwind.c, python/py-utils.c, python/py-value.c,
python/py-varobj.c, python/py-xmethods.c, python/python.c,
varobj.c: Change gdbpy_ref to gdbpy_ref<>.

7 years agoRemove some ui_out-related cleanups from Python
Tom Tromey [Wed, 11 Jan 2017 06:34:22 +0000 (23:34 -0700)]
Remove some ui_out-related cleanups from Python

This patch introduces a bit of infrastructure -- namely, a minimal
std::optional analogue called gdb::optional, and an RAII template
class that works like make_cleanup_ui_out_tuple_begin_end or
make_cleanup_ui_out_list_begin_end -- and then uses these in the
Python code.  This removes a number of cleanups and generally
simplifies this code.

std::optional is only available in C++17.  Normally I would have had
this code check __cplusplus, but my gcc apparently isn't new enough to
find <optional>, even with -std=c++1z; so, because I could not test
it, the patch does not do this.

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

* ui-out.h (ui_out_emit_type): New class.
(ui_out_emit_tuple, ui_out_emit_list): New typedefs.
* python/py-framefilter.c (py_print_single_arg): Use gdb::optional
and ui_out_emit_tuple.
(enumerate_locals): Likewise.
(py_mi_print_variables, py_print_locals, py_print_args): Use
ui_out_emit_list.
(py_print_frame): Use gdb::optional, ui_out_emit_tuple,
ui_out_emit_list.
* common/gdb_optional.h: New file.

7 years agogdb/MAINTAINERS: Update my e-mail address
Martin Galvan [Fri, 10 Feb 2017 16:46:56 +0000 (13:46 -0300)]
gdb/MAINTAINERS: Update my e-mail address

gdb/ChangeLog:

2017-02-10  Martin Galvan  <martingalvan@sourceware.org>

        * MAINTAINERS (Write After Approval): Update my e-mail address.

7 years agoPR gdb/21122: Fix documentation mistakes for breakpoint commands
Martin Galvan [Fri, 10 Feb 2017 16:37:31 +0000 (13:37 -0300)]
PR gdb/21122: Fix documentation mistakes for breakpoint commands

Currently, the breakpoint documentation refers to some commands taking breakpoint
"ranges" as arguments. We discussed this with Pedro and concluded that it would
be more accurate to speak in terms of breakpoint "lists", whose elements can optionally
be ranges. I also fixed a couple of minor mistakes in the docs.

gdb/ChangeLog:

* breakpoint.c (_initialize_breakpoint): Update the help description
of the 'commands' command to indicate that it takes a list argument.

gdb/doc/ChangeLog:

* gdb.texinfo (Breakpoints): Reword documentation to speak in terms of
space-separated breakpoint lists.  Also add a missing @table command
and @cindex for breakpoint lists.

gdb/testsuite/ChangeLog:

* gdb.base/help.exp: Update match pattern for testing 'help commands'.

7 years agoPOWER9 add scv/rfscv instruction support
Nicholas Piggin [Fri, 10 Feb 2017 04:18:23 +0000 (14:18 +1000)]
POWER9 add scv/rfscv instruction support

opcodes/
* ppc-opc.c (powerpc_opcodes) <scv, rfscv>: New mnemonics.

gas/
* testsuite/gas/ppc/power9.d <scv, rfscv>: New tests.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 10 Feb 2017 00:00:16 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoRemove return in function returning void
Simon Marchi [Thu, 9 Feb 2017 21:24:40 +0000 (16:24 -0500)]
Remove return in function returning void

gdb/ChangeLog:

* interps.c (current_interp_set_logging): Remove "return".

7 years agoFix NULL pointer dereference
Gary Benson [Thu, 9 Feb 2017 15:35:33 +0000 (15:35 +0000)]
Fix NULL pointer dereference

This commit fixes a segmentation fault on tab completion when
certain debuginfo is installed:

  https://bugzilla.redhat.com/show_bug.cgi?id=1398387

gdb/ChangeLog:

* symtab.c (add_symtab_completions): Prevent NULL pointer
dereference.

7 years agoAutomatic date update in version.in
GDB Administrator [Thu, 9 Feb 2017 00:00:27 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agold/arc: Change default linker emulation for nps400
Andrew Burgess [Thu, 26 Jan 2017 10:33:23 +0000 (10:33 +0000)]
ld/arc: Change default linker emulation for nps400

If we are configuring for an arc/linux target, and --with-cpu=nps400 is
used at configure time then change the default linker emulation to the
nps specific version.  All of the alternative linker emulations are
still available using the -mNAME option for ld.

ld/ChangeLog:

* configure.tgt (arc*-*-linux*): Change the default linker
emulation based on --with-cpu selection.
* NEWS: Mention new configuration option.

7 years agoEliminate interp::quiet_p
Pedro Alves [Wed, 8 Feb 2017 18:08:18 +0000 (18:08 +0000)]
Eliminate interp::quiet_p

This commit removes interp::quiet_p / interp_quiet_p /
interp_set_quiet, because AFAICS, it doesn't really do anything.

interp_quiet is only ever checked inside interp_set nowadays:

  if (!first_time && !interp_quiet_p (interp))
    {
      xsnprintf (buffer, sizeof (buffer),
 "Switching to interpreter \"%.24s\".\n", interp->name);
      current_uiout->text (buffer);
    }

I did a bit of archaelogy, and found that back in 4a8f6654 (2003), it
was also called in another place, to decide whether to print the CLI
prompt.

AFAICS, that condition is always false today, making that if/then
block always dead code.  If we remove that code, then there are no
interp_quiet_p uses left in the tree, so we can remove it all.

There are two paths that lead to interp_set calls:

#1 - When installing the top level interpreter.  In this case,
FIRST_TIME is true.

#2 - In interpreter_exec_cmd.  In this case, the interpreter is always
set quiet before interp_set is called.

Grepping a gdb.log of an x86_64 GNU/Linux run for "Switching to
interpreter" (before this patch) doesn't find any hits.

I suspect the intention of this message was to support something like
a "set interpreter ..." command that would change the interpreter
permanently.  But there's no such command.

Tested on x86_64 Fedora 23.

gdb/ChangeLog:
2017-02-08  Pedro Alves  <palves@redhat.com>

* interps.c (interp::interp): Remove reference to quiet_p.
(interp_set): Make static.  Remove dead "Switching to" output
code.
(interp_quiet_p, interp_set_quiet): Delete.
(interpreter_exec_cmd): Don't set the interpreter quiet.
* interps.h (interp_quiet_p): Make static.
(class interp) <quiet_p>: Remove field

7 years agoCommand abbreviation in define
Jerome Guitton [Tue, 10 Jan 2017 14:15:53 +0000 (15:15 +0100)]
Command abbreviation in define

When defining a new macro, "command" is not recognized as an alias for
"commands":

 (gdb) define breakmain
 Type commands for definition of "breakmain".
 End with a line saying just "end".
 >break main
 >command
 >echo "IN MAIN\n"
 >end
 (gdb)

There is a special case for while-stepping, where 'ws' and 'stepping' are
recognized explicitely. Instead of adding more special cases, this change
uses cli-decode.

gdb/ChangeLog:
* cli/cli-decode.c (find_command_name_length): Make it extern.
* cli/cli-decode.h (find_command_name_length): Declare.
* cli/cli-script.c (command_name_equals, line_first_arg):
New functions.
(process_next_line): Use cli-decode to parse command names.
(build_command_line): Make args a constant pointer.

gdb/testsuite/ChangeLog:

* gdb.base/define.exp: Add test for command abbreviations
in define.

7 years agoCommand names: make them case sensitive
Jerome Guitton [Fri, 27 Jan 2017 16:06:32 +0000 (17:06 +0100)]
Command names: make them case sensitive

Case-insensitive search for command names is an obscure undocumented
feature, which seems to be unused, is not tested and not quite
consistent. Remove it.

gdb/ChangeLog:

* cli-decode.c (lookup_cmd_1, lookup_cmd_composition):
Remove case-insensitive search.

7 years agoFix segfault when .plt section does not exist
Andrew Waterman [Mon, 23 Jan 2017 20:58:30 +0000 (12:58 -0800)]
Fix segfault when .plt section does not exist

bfd/ChangeLog

2017-02-07  Andrew Waterman  <andrew@sifive.com>

* elfnn-riscv.c (riscv_elf_finish_dynamic_sections): Only write PLT
entry size if PLT header is written.

7 years agoAutomatic date update in version.in
GDB Administrator [Wed, 8 Feb 2017 00:00:23 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agogdb: fix ARI warning in sparc-tdep.c
Jose E. Marchesi [Tue, 7 Feb 2017 21:21:54 +0000 (13:21 -0800)]
gdb: fix ARI warning in sparc-tdep.c

gdb/ChangeLog:

2017-02-07  Jose E. Marchesi  <jose.marchesi@oracle.com>

* sparc-tdep.c (sparc32_gdbarch_init): Do not place a + operator
at the end of the line.

7 years agobfd: Fix objdump --dynamic-reloc for SPARC 64-bit to show symbol names.
Sheldon Lobo [Tue, 7 Feb 2017 14:05:59 +0000 (06:05 -0800)]
bfd: Fix objdump --dynamic-reloc for SPARC 64-bit to show symbol names.

Fixes ld/testsuite/ld-elf/shared.exp "Build libpr16496b.so".

The root cause is in bfd/elf64-sparc.c, elf64_sparc_slurp_one_reloc_table(),
bfd_get_symcount() was used for dynamic mode as well. The fix is to use
bfd_get_dynamic_symcount().

This has been tested with sparc64-linux-gnu, and it does not introduce any
regressions.

bfd/ChangeLog:

2017-02-06  Sheldon Lobo  <sheldon.lobo@oracle.com>

Fix sparc64 dynamic relocation processing to use the dynamic
        symbol count.
* elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Use 'dynamic'
to determine if bfd_get_symcount() or bfd_get_dynamic_symcount()
should be used.

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

7 years ago[ld, testsuite] Don't print to stdout for "readelf -w" to avoid buffer overflow
Jiong Wang [Thu, 2 Feb 2017 17:15:26 +0000 (17:15 +0000)]
[ld, testsuite] Don't print to stdout for "readelf -w" to avoid buffer overflow

ld/
* testsuite/ld-elf/compress.exp: Don't print to stdout for all
"readelf -w".

7 years ago[ARC] Provide an interface to decode ARC instructions.
Claudiu Zissulescu [Mon, 6 Feb 2017 10:26:13 +0000 (11:26 +0100)]
[ARC] Provide an interface to decode ARC instructions.

gas/
2017-02-06  Claudiu Zissulescu  <claziss@synopsys.com>

* config/tc-arc.c (parse_opcode_flags): Ignore implicit flags.

include/
2017-02-06  Claudiu Zissulescu  <claziss@synopsys.com>
    Anton Kolesov  <anton.kolesov@synopsys.com>

* opcode/arc.h (insn_class_t): Add ENTER, LEAVE, POP, PUSH, BBIT0,
BBIT1, BI, BIH, BRCC, EI, JLI, and SUB instruction classes.
(flag_class_t): Add F_CLASS_WB, F_CLASS_ZZ, and F_CLASS_IMPLICIT
flag classes.

opcode/
2017-02-06  Claudiu Zissulescu  <claziss@synopsys.com>
    Anton Kolesov  <anton.kolesov@synopsys.com>

* arc-dis.c (arc_disassemble_info): New structure.
(init_arc_disasm_info): New function.
(find_format_from_table): Ignore implicit flags.
(find_format): Update dissassembler private data.
(print_flags): Likewise.
(print_insn_arc): Likewise.
(arc_opcode_to_insn_type): Consider the new added instruction
classes.
(arcAnalyzeInstr): Remove.
(arc_insn_decode): New function.
* arc-dis.h (arc_ldst_writeback_mode): New enum.
(arc_ldst_data_size): Likewise.
(arc_condition_code): Likewise.
(arc_operand_kind): Likewise.
(arc_insn_kind): New struct.
(arc_instruction): Likewise.
(arc_insn_decode): Declare function.
(ARC_Debugger_OperandType): Deleted.
(Flow): Likewise.
(NullifyMode): Likewise.
(allOperandsSize): Likewise.
(arcDisState): Likewise.
(arcAnalyzeInstr): Likewise.
* arc-dis.c (arc_opcode_to_insn_type): Handle newly introduced
insn_class_t enums.
* arc-opc.c (F_SIZED): New define.
(C_CC_EQ, C_CC_GE, C_CC_GT, C_CC_HI, C_CC_HS): Likewise.
(C_CC_LE, C_CC_LO, C_CC_LS, C_CC_LT, C_CC_NE): Likewise.
(C_CC_NE, C_AA_AB, C_AA_AW, C_ZZ_D, C_ZZ_H, C_ZZ_B): Likewise.
(arc_flag_classes): Add F_CLASS_COND/F_CLASS_IMPLICIT flags.
* opcodes/arc-tbl.h: Update instructions to include new
F_CLASS_IMPLICIT flags.
(bbit0, lp): Change class.
(bbit1, bi, bih, br*, ei_s, jli_s): Likewsie

7 years ago[BZ 21005] Add support for Intel 64 rdrand and rdseed record/replay
Luis Machado [Mon, 6 Feb 2017 09:12:00 +0000 (03:12 -0600)]
[BZ 21005] Add support for Intel 64 rdrand and rdseed record/replay

This patch addresses BZ 21005, which is gdb failing to recognize an rdrand
instruction.

It enables support for both rdrand and rdseed and handles extended register
addressing (R8~R15) for 16-bit, 32-bit and 64-bit.

gdb/ChangeLog
2017-02-06  Luis Machado  <lgustavo@codesourcery.com>

* NEWS: Mention support for record/replay of Intel 64 rdrand and
rdseed instructions.
i386-tdep.c (i386_process_record): Handle Intel 64 rdrand and rseed.

gdb/testsuite/ChangeLog:
2017-02-06  Luis Machado  <lgustavo@codesourcery.com>

* gdb.reverse/insn-reverse.c: Include insn-reverse-x86.c.
* gdb.reverse/insn-reverse-x86.c: New file.

7 years agogdb: provide and use sparc{32,64} target description XML files.
Ivo Raisr [Mon, 6 Feb 2017 07:44:03 +0000 (23:44 -0800)]
gdb: provide and use sparc{32,64} target description XML files.

gdb/ChangeLog:

2017-02-06  Ivo Raisr  <ivo.raisr@oracle.com>

PR tdep/20936
Provide and use sparc32 and sparc64 target description XML files.
* features/sparc/sparc32-cp0.xml, features/sparc/sparc32-cpu.xml,
features/sparc/sparc32-fpu.xml: New files for sparc 32-bit.
* features/sparc/sparc64-cp0.xml, features/sparc/sparc64-cpu.xml,
features/sparc/sparc64-fpu.xml: New files for sparc 64-bit.
* features/sparc/sparc32-solaris.xml: New file.
* features/sparc/sparc64-solaris.xml: New file.
* features/sparc/sparc32-solaris.c: Generated.
* features/sparc/sparc64-solaris.c: Generated.
* sparc-tdep.h: Account for differences in target descriptions.
* sparc-tdep.c (sparc32_register_name): Use target provided registers.
(sparc32_register_type): Use target provided registers.
(validate_tdesc_registers): New function.
(sparc32_gdbarch_init): Use tdesc_has_registers.
Set pseudoregister functions.
* sparc64-tdep.c (sparc64_register_name): Use target provided registers.
(sparc64_register_type): Use target provided registers.
(sparc64_init_abi): Set pseudoregister functions.

gdb/doc/ChangeLog:

2017-02-06  Ivo Raisr  <ivo.raisr@oracle.com>

PR tdep/20936
* gdb.texinfo: (Standard Target Features): Document SPARC features.
(Sparc Features): New node.

gdb/testsuite/ChangeLog:

2017-02-06  Ivo Raisr  <ivo.raisr@oracle.com>

PR tdep/20936
* gdb.xml/tdesc-regs.exp: Provide sparc core registers for the tests.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 6 Feb 2017 00:00:21 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 5 Feb 2017 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoFix ptype of single-member Rust enums
Tom Tromey [Sat, 4 Feb 2017 05:11:46 +0000 (22:11 -0700)]
Fix ptype of single-member Rust enums

While looking into PR rust/21097, I found that ptype of a
single-element enum in Rust did not always format the result properly.
In particular, it would leave out the members of a tuple struct.
Further testing showed that it also did the wrong thing for ordinary
struct members as well.

This patch fixes these problems.  I'm marking it as being associated
with the PR, since that is where the discovery was made; but this
doesn't actually fix that PR (which I think ultimately is due to a
Rust compiler bug).

Built and regtested on x86-64 Fedora 25, using the system Rust
compiler.  I'm checking this in.

2017-02-03  Tom Tromey  <tom@tromey.com>

PR rust/21097:
* rust-lang.c (rust_print_type) <TYPE_CODE_UNION>: Handle enums
with a single member.

2017-02-03  Tom Tromey  <tom@tromey.com>

PR rust/21097:
* gdb.rust/simple.exp: Add new tests.

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 4 Feb 2017 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoC++-fy struct interp/cli_interp/tui_interp/mi_interp
Pedro Alves [Fri, 3 Feb 2017 16:30:04 +0000 (16:30 +0000)]
C++-fy struct interp/cli_interp/tui_interp/mi_interp

- The interp->data field disappears, since we can put data in the
  interpreter directly now.  The "init" method remains in place, but
  it now returns void.

- A few places check if the interpreter method is NULL before calling
  it, and also check whether the method returns true/false.  For some
  of those methods, all current implementations always return true.
  In those cases, this commit makes the C++-fied method return void
  instead and cleans up the callers.

Tested on x86_64 Fedora 23.

gdb/ChangeLog:
2017-02-03  Pedro Alves  <palves@redhat.com>

* cli/cli-interp.c (cli_interp_base::cli_interp_base)
(cli_interp_base::~cli_interp_base): New.
(cli_interp): New struct.
(as_cli_interp): Cast the interp itself to cli_interp.
(cli_interpreter_pre_command_loop): Rename to ...
(cli_interp_base::pre_command_loop): ... this.  Remove 'self'
parameter.
(cli_interpreter_init): Rename to ...
(cli_interp::init): ... this.  Remove 'self' parameter.  Use
boolean.  Make extern.
(cli_interpreter_resume): Rename to ...
(cli_interp::resume): ... this.  Remove 'data' parameter.  Make
extern.
(cli_interpreter_suspend): Rename to ...
(cli_interp::suspend): ... this.  Remove 'data' parameter.  Make
extern.
(cli_interpreter_exec): Rename to ...
(cli_interp::exec): ... this.  Remove 'data' parameter.  Make
extern.
(cli_interpreter_supports_command_editing): Rename to ...
(cli_interp_base::supports_command_editing): ... this.  Remove
'interp' parameter.  Make extern.
(cli_ui_out): Rename to ...
(cli_interp::interp_ui_out): ... this.  Remove 'interp' parameter.
Make extern.
(cli_set_logging): Rename to ...
(cli_interp_base::set_logging): ... this.  Remove 'interp'
parameter.  Make extern.
(cli_interp_procs): Delete.
(cli_interp_factory): Adjust to use "new".
* cli/cli-interp.h: Include "interps.h".
(struct cli_interp_base): New struct.
* interps.c (struct interp): Delete.  Fields moved to interps.h.
(interp_new): Delete.
(interp::interp, interp::~interp): New.
(interp_set): Use bool, and return void.  Assume the interpreter
has suspend, init and resume methods, and that the all return
void.
(set_top_level_interpreter): interp_set returns void.
(interp_ui_out): Adapt.
(current_interp_set_logging): Adapt.
(interp_data): Delete.
(interp_pre_command_loop, interp_supports_command_editing): Adapt.
(interp_exec): Adapt.
(top_level_interpreter_data): Delete.
* interps.h (interp_init_ftype, interp_resume_ftype)
(interp_suspend_ftype, interp_exec_ftype)
(interp_pre_command_loop_ftype, interp_ui_out_ftype): Delete.
(class interp): New.
(interp_new): Delete.
(interp_set): Now returns void.  Use bool.
(interp_data, top_level_interpreter_data): Delete.
* mi/mi-common.h: Include interps.h.
(class mi_interp): Inherit from interp.  Define a ctor.  Declare
init, resume, suspect, exec, interp_ui_out, set_logging and
pre_command_loop methods.
* mi/mi-interp.c (as_mi_interp): Cast the interp itself.
(mi_interpreter_init): Rename to ...
(mi_interp::init): ... this.  Remove the 'interp' parameter, use
bool, return void and make extern.  Adjust.
(mi_interpreter_resume): ... Rename to ...
(mi_interp::resume): ... this.  Remove the 'data' parameter,
return void and make extern.  Adjust.
(mi_interpreter_suspend): ... Rename to ...
(mi_interp::suspend): ... this.  Remove the 'data' parameter,
return void and make extern.  Adjust.
(mi_interpreter_exec): ... Rename to ...
(mi_interp::exec): ... this.  Remove the 'data' parameter and make
extern.  Adjust.
(mi_interpreter_pre_command_loop): ... Rename to ...
(mi_interp::pre_command_loop): ... this.  Remove the 'self'
parameter and make extern.
(mi_on_normal_stop_1): Adjust.
(mi_ui_out): Rename to ...
(mi_interp::interp_ui_out): ... this.  Remove the 'interp'
parameter and make extern.  Adjust.
(mi_set_logging): Rename to ...
(mi_interp::set_logging): ... this.  Remove the 'interp'
parameter and make extern.  Adjust.
(mi_interp_procs): Delete.
(mi_interp_factory): Adjust to use 'new'.
* mi/mi-main.c (mi_cmd_gdb_exit, captured_mi_execute_command)
(mi_print_exception, mi_execute_command, mi_load_progress):
Adjust.
* tui/tui-interp.c (tui_interp): New class.
(as_tui_interp): Return a tui_interp pointer.
(tui_on_normal_stop, tui_on_signal_received)
(tui_on_end_stepping_range, tui_on_signal_exited, tui_on_exited)
(tui_on_no_history, tui_on_user_selected_context_changed): Adjust
to use interp::interp_ui_out.
(tui_init): Rename to ...
(tui_interp::init): ... this.  Remove the 'self' parameter, use
bool, return void and make extern.  Adjust.
(tui_resume): Rename to ...
(tui_interp::resume): ... this.  Remove the 'data' parameter,
return void and make extern.  Adjust.
(tui_suspend): Rename to ...
(tui_interp::suspend): ... this.  Remove the 'data' parameter,
return void and make extern.  Adjust.
(tui_ui_out): Rename to ...
(tui_interp::interp_ui_out): ... this.  Remove the 'self'
parameter, and make extern.  Adjust.
(tui_exec): Rename to ...
(tui_interp::exec): ... this.  Remove the 'data' parameter and
make extern.
(tui_interp_procs): Delete.
(tui_interp_factory): Use "new".

7 years ago[GOLD] PowerPC64 TOC indirect to TOC relative segfault
Alan Modra [Fri, 3 Feb 2017 08:48:37 +0000 (19:18 +1030)]
[GOLD] PowerPC64 TOC indirect to TOC relative segfault

* powerpc.cc (Powerpc_relobj::make_toc_relative): Don't crash
when no .toc section exists.

7 years agoFix compile time warning messages when compiling binutils with gcc 7.0.1.
Nick Clifton [Fri, 3 Feb 2017 09:04:21 +0000 (09:04 +0000)]
Fix compile time warning messages when compiling binutils with gcc 7.0.1.

PR 21096
bfd * coffcode.h (coff_write_object_contents): Enlarge size of
s_name_buf in order to avoid compile time warning about possible
integer truncation.
* elf32-nds32.c (nds32_elf_ex9_import_table): Mask off lower
32-bits of insn value before printing into buffer.

opcodes * aarch64-opc.c (print_register_list): Ensure that the register
list index will fir into the tb buffer.
(print_register_offset_address): Likewise.
* tic6x-dis.c (print_insn_tic6x): Increase size of func_unit_buf.

7 years agoUse bool in Rust code
Tom Tromey [Fri, 3 Feb 2017 04:21:19 +0000 (21:21 -0700)]
Use bool in Rust code

This changes various functions in the Rust code to use a bool rather
than an int when a boolean is intended.

2017-02-02  Tom Tromey  <tom@tromey.com>

* rust-exp.y (ends_raw_string, space_then_number)
(rust_identifier_start_p): Return bool.
* rust-lang.c (rust_tuple_type_p, rust_underscore_fields)
(rust_tuple_struct_type_p, rust_tuple_variant_type_p)
(rust_slice_type_p, rust_range_type_p, rust_u8_type_p)
(rust_chartype_p): Return bool.
(val_print_struct, rust_print_struct_def, rust_print_type):
Update.
* rust-lang.h (rust_tuple_type_p, rust_tuple_struct_type_p):
Return bool.

7 years agoReindent rust-lang.c
Tom Tromey [Fri, 3 Feb 2017 04:01:11 +0000 (21:01 -0700)]
Reindent rust-lang.c

I noticed a few spots in rust-lang.c had incorrect indentation.  This
patch fixes this.

2017-02-02  Tom Tromey  <tom@tromey.com>

* rust-lang.c: Reindent.

7 years agoUse std::string in Rust code
Tom Tromey [Fri, 3 Feb 2017 03:58:12 +0000 (20:58 -0700)]
Use std::string in Rust code

This changes a couple of spots in the Rust support to use std::string.
In one spot this removes some manual memory management; in the other
spot this allows the removal of a call to xstrdup.

2017-02-02  Tom Tromey  <tom@tromey.com>

* rust-lang.h (rust_crate_for_block): Update.
* rust-lang.c (rust_crate_for_block): Return std::string.
(rust_get_disr_info): Use std:;string, not
gdb::unique_xmalloc_ptr.
* rust-exp.y (crate_name): Update.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 3 Feb 2017 00:00:23 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoFix "maintenance selftest" printing stray instructions
Pedro Alves [Thu, 2 Feb 2017 23:36:29 +0000 (23:36 +0000)]
Fix "maintenance selftest" printing stray instructions

The "maintenance selftest" command is printing odd bits of stray
instructions like:

~~~
brkwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default HS settings.

brkmov  r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov   r0, #0mov       r0, #0mov       r0, #0mov       r0, #0breakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakM3.L = 0xffff;/* ( -1) M3=0x0xffff(65535) */break 8break 8warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default cris:common_v10_v32 settings.
~~~

etc.  Those appear because here:

  class gdb_disassembler_test : public gdb_disassembler
  {
  public:

    const bool verbose = false;

    explicit gdb_disassembler_test (struct gdbarch *gdbarch,
    const gdb_byte *insn,
    size_t len)
      : gdb_disassembler (gdbarch,
  (verbose ? gdb_stdout : &null_stream),
  gdb_disassembler_test::read_memory),

specifically in this line:

  (verbose ? gdb_stdout : &null_stream),

"verbose" has not been initialized yet, because the order of
initialization is base classes first, then members.  I.e. "verbose" is
only initialized after the base constructor is called.  Since the
gdb_disassembler_test object is created on the stack, "verbose" has
garbage at that point.  If the gargage is non-zero, then we end up
with the gdb_disassembler_test's stream incorrectly pointing to
gdb_stdout.

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

* disasm-selftests.c (print_one_insn_test): Move the "verbose"
field out of gdb_disassembler_test and make it static.

7 years agoFix "maintenance selftest" printing stray instructions
Pedro Alves [Thu, 2 Feb 2017 23:27:57 +0000 (23:27 +0000)]
Fix "maintenance selftest" printing stray instructions

The "maintenance selftest" command is printing odd bits of stray
instructions like:

~~~
brkwarning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default HS settings.

brkmov  r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov       r0, #0mov   r0, #0mov       r0, #0mov       r0, #0mov       r0, #0breakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakbreakM3.L = 0xffff;/* ( -1) M3=0x0xffff(65535) */break 8break 8warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default cris:common_v10_v32 settings.
~~~

etc.  Those appear because here:

  class gdb_disassembler_test : public gdb_disassembler
  {
  public:

    const bool verbose = false;

    explicit gdb_disassembler_test (struct gdbarch *gdbarch,
    const gdb_byte *insn,
    size_t len)
      : gdb_disassembler (gdbarch,
  (verbose ? gdb_stdout : &null_stream),
  gdb_disassembler_test::read_memory),

specifically in this line:

  (verbose ? gdb_stdout : &null_stream),

"verbose" has not been initialized yet, because the order of
initialization is base classes first, then members.  I.e. "verbose" is
only initialized after the base constructor is called.  Since the
gdb_disassembler_test object is created on the stack, "verbose" has
garbage at that point.  If the gargage is non-zero, then we end up
with the gdb_disassembler_test's stream incorrectly pointing to
gdb_stdout.

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

* disasm-selftests.c (print_one_insn_test): Move the "verbose"
field out of gdb_disassembler_test and make it static.

7 years agostruct mi_interp: Remove unused fields
Pedro Alves [Thu, 2 Feb 2017 23:08:12 +0000 (23:08 +0000)]
struct mi_interp: Remove unused fields

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

* mi/mi-common.h (struct mi_interp): Delete the mi2_interp,
mi1_interp and mi_interp fields.

7 years agoMIPS/BFD: Respect the ELF gABI dynamic symbol table sort requirement
Maciej W. Rozycki [Thu, 2 Feb 2017 22:05:46 +0000 (22:05 +0000)]
MIPS/BFD: Respect the ELF gABI dynamic symbol table sort requirement

Ensure all local symbols precede external symbols in the dynamic symbol
table.

No local symbols are expected to make it to the dynamic symbol table
except for section symbols already taken care of, so this is really a
safeguard only against a potential BFD bug otherwise not so harmful,
which may become a grave one due to a symbol table sorting requirement
violation (see PR ld/20828 for an example).  This means however that no
test suite coverage is possible for this change as code introduced here
is not normally expected to trigger.

Logically split then the part of the dynamic symbol table which is not
global offset table mapped, into a local area at the beginning and an
external area following.  By the time `mips_elf_sort_hash_table' is
called we have the number of local dynamic symbol table entries (section
and non-section) already counted in `local_dynsymcount', so use it to
offset the external area from the beginning.

bfd/
* elfxx-mips.c (mips_elf_hash_sort_data): Add
`max_local_dynindx'.
(mips_elf_sort_hash_table): Handle it.
(mips_elf_sort_hash_table_f) <GGA_NONE>: For forced local
symbols bump up `max_local_dynindx' rather than
`max_non_got_dynindx'.

7 years agoMIPS/BFD: Use `bfd_size_type' for dynamic symbol table indices
Maciej W. Rozycki [Thu, 2 Feb 2017 21:43:26 +0000 (21:43 +0000)]
MIPS/BFD: Use `bfd_size_type' for dynamic symbol table indices

Use the `bfd_size_type' data type for dynamic symbol table indices in
the MIPS backend, in line with generic code and removing the need to use
a cast.

bfd/
* elfxx-mips.c (mips_elf_hash_sort_data): Convert the
`min_got_dynindx', `max_unref_got_dynindx' and
`max_non_got_dynindx' members to the `bfd_size_type' data type.
(mips_elf_sort_hash_table): Adjust accordingly.

7 years agoMIPS/BFD: Streamline hash table references in `mips_elf_sort_hash_table'
Maciej W. Rozycki [Thu, 2 Feb 2017 21:30:27 +0000 (21:30 +0000)]
MIPS/BFD: Streamline hash table references in `mips_elf_sort_hash_table'

Make all hash table references throughout `mips_elf_sort_hash_table' use
`htab', simplifying code and improving readability.

bfd/
* elfxx-mips.c (mips_elf_sort_hash_table): Use `htab' throughout
to access the hash table.

7 years agoMIPS/BFD: Fix assertion in `mips_elf_sort_hash_table'
Maciej W. Rozycki [Thu, 2 Feb 2017 20:53:16 +0000 (20:53 +0000)]
MIPS/BFD: Fix assertion in `mips_elf_sort_hash_table'

Move the assertion on non-NULL `htab' in `mips_elf_sort_hash_table' to
the beginning, before the pointer is dereferenced (`mips_elf_hash_table
(info)' and `elf_hash_table (info)' both point to the same memory
location, differently typed).

bfd/
* elfxx-mips.c (mips_elf_sort_hash_table): Move assertion on
non-NULL `htab' to the beginning.

7 years agoCRIS/LD/testsuite: tls-err-20x.d: Fix a typo, s/n/\n/
Maciej W. Rozycki [Thu, 2 Feb 2017 20:44:41 +0000 (20:44 +0000)]
CRIS/LD/testsuite: tls-err-20x.d: Fix a typo, s/n/\n/

ld/
* testsuite/ld-cris/tls-err-20x.d: Fix a typo, s/n/\n/.

7 years agoLD/testsuite: ld-lib.exp: Fix a typo, s/regexp/regex/
Maciej W. Rozycki [Thu, 2 Feb 2017 19:09:57 +0000 (19:09 +0000)]
LD/testsuite: ld-lib.exp: Fix a typo, s/regexp/regex/

Match `$check_ld(source)' against "regex" rather than "regexp" in
reporting, correcting test framework diagnostics, e.g.:

tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
failed with: <tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'>, no expected output
tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
PASS: MIPS undefined reference

(current) vs:

tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
failed with: <tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'>, expected: <\A[^\n]*\.o: In function `foo':\n\(\.text\+0x0\): undefined reference to `bar'\Z>
tmpdir/undefined.o: In function `foo':
(.text+0x0): undefined reference to `bar'
PASS: MIPS undefined reference

(corrected).  No functional change.

ld/
* ld/testsuite/lib/ld-lib.exp (run_dump_test): Fix a typo,
s/regexp/regex/.

7 years agoBFD: Wrap overlong error handler call line in `elf_gc_sweep'
Maciej W. Rozycki [Thu, 2 Feb 2017 16:44:09 +0000 (16:44 +0000)]
BFD: Wrap overlong error handler call line in `elf_gc_sweep'

bfd/
* elflink.c (elf_gc_sweep): Wrap overlong line.

7 years agoMIPS/GAS/doc: Include MIPS options in the man page
Maciej W. Rozycki [Thu, 2 Feb 2017 16:23:21 +0000 (16:23 +0000)]
MIPS/GAS/doc: Include MIPS options in the man page

Include the detailed MIPS option description in the man page along with
other target descriptions and complementing the terse list earlier on.

gas/
* doc/as.texinfo (Overview): Select MIPS options for man page
inclusion.

7 years agoMove "tee" building down to interpreter::set_logging_proc
Pedro Alves [Thu, 2 Feb 2017 22:00:43 +0000 (22:00 +0000)]
Move "tee" building down to interpreter::set_logging_proc

This patch gets rid of this hack in mi_set_logging:

      /* The tee created already is based on gdb_stdout, which for MI
 is a console and so we end up in an infinite loop of console
 writing to ui_file writing to console etc.  So discard the
 existing tee (it hasn't been used yet, and MI won't ever use
 it), and create one based on raw_stdout instead.  */

By pushing down responsibility for the tee creation to the
interpreter.  I.e., pushing the CLI bits out of handle_redirections
down to the CLI interpreter's set_logging_proc method.

This fixes a few leaks that I spotted, and then confirmed with
"valgrind --leak-check=full":

[...]
  ==21429== 56 (32 direct, 24 indirect) bytes in 1 blocks are definitely lost in loss record 30,243 of 34,980
  ==21429==    at 0x4C29216: operator new(unsigned long) (vg_replace_malloc.c:334)
  ==21429==    by 0x62D9A9: mi_set_logging(interp*, int, ui_file*, ui_file*) (mi-interp.c:1395)
  ==21429==    by 0x810B8A: current_interp_set_logging(int, ui_file*, ui_file*) (interps.c:360)
  ==21429==    by 0x61C537: handle_redirections(int) (cli-logging.c:162)
  ==21429==    by 0x61C6EC: set_logging_on(char*, int) (cli-logging.c:190)
  ==21429==    by 0x6163BE: do_cfunc(cmd_list_element*, char*, int) (cli-decode.c:105)
  ==21429==    by 0x6193C1: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1913)
  ==21429==    by 0x8DB790: execute_command(char*, int) (top.c:674)
  ==21429==    by 0x632AE6: mi_execute_cli_command(char const*, int, char const*) (mi-main.c:2343)
  ==21429==    by 0x6329BA: mi_cmd_execute(mi_parse*) (mi-main.c:2306)
  ==21429==    by 0x631E19: captured_mi_execute_command(ui_out*, mi_parse*) (mi-main.c:1998)
  ==21429==    by 0x632389: mi_execute_command(char const*, int) (mi-main.c:2163)
  ==21429==
[...]
  ==26635== 24 bytes in 1 blocks are definitely lost in loss record 20,740 of 34,995
  ==26635==    at 0x4C29216: operator new(unsigned long) (vg_replace_malloc.c:334)
  ==26635==    by 0x61C355: handle_redirections(int) (cli-logging.c:131)
  ==26635==    by 0x61C6EC: set_logging_on(char*, int) (cli-logging.c:190)
  ==26635==    by 0x6163BE: do_cfunc(cmd_list_element*, char*, int) (cli-decode.c:105)
  ==26635==    by 0x6193C1: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1913)
  ==26635==    by 0x8DB7BC: execute_command(char*, int) (top.c:674)
  ==26635==    by 0x7B9132: command_handler(char*) (event-top.c:590)
  ==26635==    by 0x7B94F7: command_line_handler(char*) (event-top.c:780)
  ==26635==    by 0x7B8ABB: gdb_rl_callback_handler(char*) (event-top.c:213)
  ==26635==    by 0x933CE9: rl_callback_read_char (callback.c:220)
  ==26635==    by 0x7B89ED: gdb_rl_callback_read_char_wrapper_noexcept() (event-top.c:175)
  ==26635==    by 0x7B8A49: gdb_rl_callback_read_char_wrapper(void*) (event-top.c:192)

One is fixed by transfering ownership of the log file to the tee.  In
pseudo-patch, since the code was moved at the same time:

 -     out = new tee_file (curr_output, false, logfile.get (), false);
 +     out = new tee_file (curr_output, false, logfile.get (), true);

The other is this bit in mi_set_logging:

    else
      {
 +      delete mi->raw_stdout;

I tried to split the leak fixes to a smaller preparatory patch, but
that was difficult exactly because of the tee hack in
handle_redirections -> mi_set_logging.

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

* cli/cli-interp.c (struct saved_output_files, saved_output):
Moved from cli/cli-logging.c.
(cli_set_logging): New function.
(cli_interp_procs): Install cli_set_logging.
* cli/cli-interp.h (make_logging_output, cli_set_logging):
Declare.
* cli/cli-logging.c (struct saved_output_files, saved_output):
Moved to cli/cli-interp.c.
(pop_output_files): Don't save outputs here.
(make_logging_output): New function.
(handle_redirections): Don't build tee nor save previous outputs
here.
* interps.c (current_interp_set_logging): Change prototype.
Assume there's always a set_logging_proc method installed.
* interps.h (interp_set_logging_ftype): Change prototype.
(current_interp_set_logging): Change prototype and adjust comment.
* mi/mi-interp.c (mi_set_logging): Change protototype.  Adjust to
use make_logging_output.
* tui/tui-interp.c (tui_interp_procs): Install cli_set_logging.

7 years agoFix "-gdb-set logging redirect on" crash
Pedro Alves [Thu, 2 Feb 2017 19:07:08 +0000 (19:07 +0000)]
Fix "-gdb-set logging redirect on" crash

This commit fixes a "-gdb-set logging redirect on" crash by not
handling "logging redirect on" on the fly.

Previous discussion here:
 https://sourceware.org/ml/gdb-patches/2017-01/msg00467.html

Code for handling "logging redirect on" on the fly was added here:
 https://sourceware.org/ml/gdb-patches/2010-08/msg00202.html

Meanwhile, MI gained support for logging, but flipping redirect "on"
on the fly was not considered.  The result is that this sequence of
commands crashes GDB:

 -gdb-set logging on
 -gdb-set logging redirect on

 Program received signal SIGSEGV, Segmentation fault.
 0x00000000008dd7bc in gdb_flush (file=0x2a097f0) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/ui-file.c:95
 194       file->to_flush (file);
 (top-gdb) bt
 #0  0x00000000008dd7bc in gdb_flush(ui_file*) (file=0x2a097f0) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/ui-file.c:95
 #1  0x00000000007b5f34 in gdb_wait_for_event(int) (block=0) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/event-loop.c:752
 #2  0x00000000007b52b6 in gdb_do_one_event() () at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/event-loop.c:322
 #3  0x00000000007b5362 in start_event_loop() () at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/event-loop.c:371
 #4  0x000000000082704a in captured_command_loop(void*) (data=0x0) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/main.c:325
 #5  0x00000000007b8d7c in catch_errors(int (*)(void*), void*, char*, return_mask) (func=0x827008 <captured_command_loop(void*)>, func_args=0x0, errstring=0x11dee51 "", mask=RETURN_MASK_ALL) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/exceptions.c:236
 #6  0x000000000082839b in captured_main(void*) (data=0x7fffffffd820) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/main.c:1148
 During symbol reading, cannot get low and high bounds for subprogram DIE at 24065.
 #7  0x00000000008283c4 in gdb_main(captured_main_args*) (args=0x7fffffffd820) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/main.c:1158
 #8  0x0000000000412d4d in main(int, char**) (argc=4, argv=0x7fffffffd928) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/gdb.c:32

The handling of redirect on the fly is not really a use case we need
to handle, IMO.  Its inconsistent (other "set logging foo" commands
aren't handled on the fly), and complicates the code significantly.
Instead of complicating it further for MI, go back to the original
idea of warning, only:

  https://sourceware.org/ml/gdb-patches/2010-08/msg00083.html

New test included.

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

* cli/cli-logging.c (maybe_warn_already_logging): New factored out
from ...
(set_logging_overwrite): ... here.
(logging_no_redirect_file): Delete.
(set_logging_redirect): Don't handle redirection on the fly.
Instead warn that "logging off" / "logging on" is necessary.
(pop_output_files): Delete references to logging_no_redirect_file.
(show_logging_command): Always speak in terms of what will happen
once logging is reenabled.

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

* gdb.mi/mi-logging.exp: Add "redirect while already logging"
tests.