Commit Graph

94136 Commits

Author SHA1 Message Date
Alan Modra b4560c7d15 PR23148, Heap buffer overflow in pe_print_edata
PR 23148
	* peXXigen.c (pe_print_edata): Correct minimum size.
2018-05-09 14:14:10 +09:30
Alan Modra 53db9cf9fc PR23147, Heap buffer overflow in pe_print_idata
PR 23147
	* peXXigen.c (pe_print_idata): Bound check hint_addr.
2018-05-09 14:12:56 +09:30
GDB Administrator 937d92afc3 Automatic date update in version.in 2018-05-09 00:00:31 +00:00
Jim Wilson e6f372ba66 RISC-V: Add missing hint instructions from RV128I.
gas/
	* testsuite/gas/riscv/c-zero-imm.d: Add more tests.
	* testsuite/gas/riscv/c-zero-imm.s: Likewise.
	* testsuite/gas/riscv/c-zero-reg.d: Fix typo in test.  Add disabled
	future test for RV128 support.
	* testsuite/gas/riscv/c-zero-reg.s: Likewise.

	include/
	* opcode/riscv-opc.h (MATCH_C_SRLI64, MASK_C_SRLI64): New.
	(MATCH_C_SRAI64, MASK_C_SRAI64): New.
	(MATCH_C_SLLI64, MASK_C_SLLI64): New.

	opcodes/
	* riscv-opc.c (match_c_slli, match_slli_as_c_slli): New.
	(match_c_slli64, match_srxi_as_c_srxi): New.
	(riscv_opcodes) <slli, sll>: Use match_slli_as_c_slli.
	<srli, srl, srai, sra>: Use match_srxi_as_c_srxi.
	<c.slli, c.srli, c.srai>: Use match_s_slli.
	<c.slli64, c.srli64, c.srai64>: New.
2018-05-08 15:46:19 -07:00
Simon Marchi 7402fbcae1 Define GNULIB_NAMESPACE in unittests/string_view-selftests.c
When building with x86_64-w64-mingw32-g++ (to test cross-compiling for
Windows), I get this error:

unittests/string_view-selftests.o: In function `selftests::string_view::inserters_2::test05(unsigned long long)':
/home/emaisin/src/binutils-gdb/gdb/unittests/basic_string_view/inserters/char/2.cc:60: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::rpl_close()'

This is caused by gnulib redefining "close" as "rpl_close", and
therefore messing up the declaration of basic_ofstream in the libstdc++
header.  The solution would be to use gnulib namespaces [1].  Until we
use them across GDB, we can use them locally in files that are
problematic, like this one.

gdb/ChangeLog:

	* unittests/string_view-selftests.c: Define GNULIB_NAMESPACE.
2018-05-08 16:45:02 -04:00
Jim Wilson 10d9808829 RISC-V: New emulations to make path searches follow glibc ABI.
ld/
	PR ld/22962
	* Makefile.am (ALL_EMULATION_SOURCES): Add eelf32lriscv_ilp32f.c,
	eelf32lriscv_ilp32.c, eelf64lriscv_lp64f.c, eelf64lriscv_lp64.c.
	(eelf32lriscv_ilp32f.c, eelf32lriscv_ilp32.c): New build rules.
	(eelf64lriscv_lp64f.c, eelf64lriscv_lp64.c): New build rules.
	* Makefile.in: Regenerated.
	* configure.tgt (riscv32*-*-linux*, riscv64*-*-linux*): New.
	* ld/emulparams/elf32lriscv.sh: Set LIBPATH_SUFFIX.
	* ld/emulparams/elf32lriscv_ilp32.sh: New.
	* ld/emulparams/elf32lriscv_ilp32f.sh: New.
	* ld/emulparams/elf64lriscv-defs.sh: Don't set LIBPATH_SUFFIX here.
	* ld/emulparams/elf64lriscv.sh: Set LIBPATH_SUFFIX.
	* ld/emulparams/elf64lriscv_lp64.sh: New.
	* ld/emulparams/elf64lriscv_lp64f.sh: New.
	* ld/genscripts.sh (append_to_lib_path): Change LIBPATH_SUFFIX test to
	a for.  Inside loop, change LIBPATH_SUFFIX uses to libpath_suffix.
	(LIB_PATH): In LIB_PATH if, add loop for LIBPATH_SUFFIX, changes uses
	inside loop to libpath_suffix.
2018-05-08 13:34:03 -07:00
Andrew Burgess 8ee22052f6 gdb/x86: Handle kernels using compact xsave format
For GNU/Linux on x86-64, if the target is using the xsave format for
passing the floating-point information from the inferior then there
currently exists a bug relating to the x87 control registers, and the
mxcsr register.

The xsave format allows different floating-point features to be lazily
enabled, a bit in the xsave format tells GDB which floating-point
features have been enabled, and which have not.

Currently in GDB, when reading the floating point state, we check the
xsave bit flags, if the feature is enabled then we read the feature
from the xsave buffer, and if the feature is not enabled, then we
supply the default value from within GDB.

Within GDB, when writing the floating point state, we first fetch the
xsave state from the target and then, for any feature that is not yet
enabled, we write the default values into the xsave buffer.  Next we
compare the regcache value with the value in the xsave buffer, and, if
the value has changed we update the value in the xsave buffer, and
mark the feature enabled in the xsave bit flags.

The problem then, is that the x87 control registers were not following
this pattern.  We assumed that these registers were always written out
by the kernel, and we always wrote them out to the xsave buffer (but
didn't enabled the feature).  The result of this is that if the kernel
had not yet enabled the x87 feature then within GDB we would see
random values for the x87 floating point control registers, and if the
user tried to modify one of these register, that modification would be
lost.

Finally, the mxcsr register was also broken in the same way as the x87
control registers.  The added complexity with this case is that the
mxcsr register is part of both the avx and sse floating point feature
set.  When reading or writing this register we need to check that at
least one of these features is enabled.

This bug was present in native GDB, and within gdbserver.  Both are
fixed with this commit.

gdb/ChangeLog:

	* common/x86-xstate.h (I387_FCTRL_INIT_VAL): New constant.
	(I387_MXCSR_INIT_VAL): New constant.
	* amd64-tdep.c (amd64_supply_xsave): Only read state from xsave
	buffer if it was supplied by the inferior.
	* i387-tdep.c (i387_supply_fsave): Use I387_MXCSR_INIT_VAL.
	(i387_xsave_get_clear_bv): New function.
	(i387_supply_xsave): Only read x87 control registers from the
	xsave buffer if the feature is enabled, and the state will have
	been written, otherwise, provide a suitable default.
	(i387_collect_xsave): Pre-clear all registers in xsave buffer,
	including x87 control registers.  Update control registers if they
	have changed from the default value, and mark features as enabled
	as required.
	* i387-tdep.h (i387_xsave_get_clear_bv): Declare.

gdb/gdbserver/ChangeLog:

	* i387-fp.c (i387_cache_to_xsave): Only write x87 control
	registers to the cache if their values have changed.
	(i387_xsave_to_cache): Provide default values for x87 control
	registers when these features are available, but disabled.
	* regcache.c (supply_register_by_name_zeroed): New function.
	* regcache.h (supply_register_by_name_zeroed): Declare new
	function.

gdb/testsuite/ChangeLog:

	* gdb.arch/amd64-init-x87-values.S: New file.
	* gdb.arch/amd64-init-x87-values.exp: New file.
2018-05-08 18:03:46 +01:00
Alan Modra 886d542809 PR23141, SIGSEGV in bfd_elf_set_group_contents
Another fuzzing fix.  I think it's reasonable to simply strip out any
group section that is too weird for objcopy to handle.

	PR 23141
	* objcopy.c (is_strip_section): Strip groups without a valid
	signature symbol.
2018-05-08 22:29:39 +09:30
Alan Modra f413a91378 Correct powerpc spe opcode lookup
Defining SPE2_OPCD_SEGS as 13 discounts the possibility that we'd
ever look up spe2_opcd_indices[14..16], which I think is possible.
Extend that array to size 16+1, using the macros we use to index the
array.  Similarly use the index macros for PPC_OPCD_SEGS and
VLE_OPCD_SEGS.

	* ppc-dis.c (PPC_OPCD_SEGS): Define using PPC_OP.
	(VLE_OPCD_SEGS, SPE2_OPCD_SEGS): Similarly, using macros used to
	partition opcode space for index lookup.
2018-05-08 22:28:44 +09:30
Jan Kratochvil 7785df4880 watchpoint-unaligned.exp: Use skip_hw_watchpoint_tests
gdb/testsuite/ChangeLog
2018-05-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/watchpoint-unaligned.exp: Use skip_hw_watchpoint_tests.
2018-05-08 14:26:19 +02:00
Ulrich Weigand 968ae51bac [spu] Fix "info spu event" output formatting
The formatting of the output of the "info spu event" command changed, causing
spurious test suite failures.  Use phex instead of phex_nz to get back the
expected format, and fix emission of new line characters.

gdb/ChangeLog:
2018-05-08  Ulrich Weigand  <uweigand@de.ibm.com>

	* spu-tdep.c (info_spu_event_command): Fix output formatting.
2018-05-08 14:13:12 +02:00
Nick Clifton 95a6d23566 Prevent a memory exhaustion failure when running objdump on a fuzzed input file with corrupt string and attribute sections.
PR 22809
	* elf.c (bfd_elf_get_str_section): Check for an excessively large
	string section.
	* elf-attrs.c (_bfd_elf_parse_attributes): Issue an error if the
	attribute section is larger than the size of the file.
2018-05-08 12:51:06 +01:00
Peter Bergner a87a64780f Simplify VLE handling in print_insn_powerpc().
opcodes/
	* ppc-dis.c (print_insn_powerpc) <insn_is_short>: Replace this...
	<insn_length>: ...with this.  Update usage.
	Remove duplicate call to *info->memory_error_func.
2018-05-07 20:47:54 -05:00
H.J. Lu c0a30a9f0a Enable Intel MOVDIRI, MOVDIR64B instructions
gas/

	* config/tc-i386.c (cpu_arch): Add .movdir, .movdir64b.
	(cpu_noarch): Likewise.
	(process_suffix): Add check for register size.
	* doc/c-i386.texi: Document movdiri, movdir64b.
	* testsuite/gas/i386/i386.exp: Run MOVDIR{I,64B} tests.
	* testsuite/gas/i386/movdir-intel.d: New file.
	* testsuite/gas/i386/movdir.d: Likewise.
	* testsuite/gas/i386/movdir.s: Likewise.
	* testsuite/gas/i386/movdir64b-reg.s: Likewise.
	* testsuite/gas/i386/movdir64b-reg.l: Likewise.
	* testsuite/gas/i386/x86-64-movdir-intel.d: Likewise.
	* testsuite/gas/i386/x86-64-movdir.d: Likewise.
	* testsuite/gas/i386/x86-64-movdir.s: Likewise.
	* testsuite/gas/i386/x86-64-movdir64b-reg.s: Likewise.
	* testsuite/gas/i386/x86-64-movdir64b-reg.l: Likewise.

opcodes/

	* i386-dis.c (Gva): New.
	(enum): Add PREFIX_0F38F8, PREFIX_0F38F9,
	MOD_0F38F8_PREFIX_2, MOD_0F38F9_PREFIX_0.
	(prefix_table): New instructions (see prefix above).
	(mod_table): New instructions (see prefix above).
	(OP_G): Handle va_mode.
	* i386-gen.c (cpu_flag_init): Add CPU_MOVDIRI_FLAGS,
	CPU_MOVDIR64B_FLAGS.
	(cpu_flags): Add CpuMOVDIRI and CpuMOVDIR64B.
	* i386-opc.h (enum): Add CpuMOVDIRI, CpuMOVDIR64B.
	(i386_cpu_flags): Add cpumovdiri and cpumovdir64b.
	* i386-opc.tbl: Add movidir{i,64b}.
	* i386-init.h: Regenerated.
	* i386-tbl.h: Likewise.
2018-05-07 16:57:48 -07:00
H.J. Lu 75c0a43899 x86: Replace AddrPrefixOp0 with AddrPrefixOpReg
This patch replaces AddrPrefixOp0 with AddrPrefixOpReg to indicate that
the size of register operand is controlled by the address size prefix.
This will be used by Intel MOVDIRI and MOVDIR64B instructions later.

gas/

	* config/tc-i386.c (process_suffix): Check addrprefixopreg
	instead of addrprefixop0.

opcodes/

	* i386-gen.c (opcode_modifiers): Replace AddrPrefixOp0 with
	AddrPrefixOpReg.
	* i386-opc.h (AddrPrefixOp0): Renamed to ...
	(AddrPrefixOpReg): This.
	(i386_opcode_modifier): Rename addrprefixop0 to addrprefixopreg.
	* i386-opc.tbl: Replace AddrPrefixOp0 with AddrPrefixOpReg.
2018-05-07 09:57:06 -07:00
Tom Tromey aff689d36d Add -Wduplicated-cond
This adds -Wduplicated-cond to warnings.m4.  This caught one bug.

I tried adding -Wduplicated-branches as well, but it results in some
spurious failures from code like this in cgen.h:

    #define CGEN_ATTR_TYPE(n) \
    struct { unsigned int bool_; \
	     CGEN_ATTR_VALUE_TYPE nonbool[(n) ? (n) : 1]; }

This will trigger a warning if passed n==1, which seems like a
perfectly valid thing to do; and there were other issues like this as
well.

ChangeLog
2018-05-07  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Add -Wduplicated-cond.

gdbserver/ChangeLog
2018-05-07  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2018-05-07 08:47:38 -06:00
Tom Tromey ce887586b4 Fix decoding of ARM VFP instructions
-Wduplicated-cond pointed out that arm_record_vfp_data_proc_insn
checks "opc1 == 0x0b" twice.  I filed this a while ago as
PR tdep/20362.

Based on the ARM instruction manual at
https://www.scss.tcd.ie/~waldroj/3d1/arm_arm.pdf, I think the
instruction decoding in this function has two bugs.

First, opc1 is computed as:

  opc1 = bits (arm_insn_r->arm_insn, 20, 23);
[...]
  opc1 = opc1 & 0x04;

This means that tests like:

  else if (opc1 == 0x01)

can never be true.

In the ARM manual, "opc1" corresponds to these bits:

    name   bit
    r      20
    q      21
    D      22
    p      23

... where the D bit is not used for VFP instruction decoding.

So, I believe this code should use ~0x04 instead.

Second, VDIV is recognized by the bits "pqrs" being equal to "1000".
This tranlates to opc1 == 0x08 -- not 0x0b.  Note that pqrs==1001 is
an undefined encoding, which is probably why opc2 is not checked here;
this code doesn't seem to really deal with undefined encodings in
general, so I've left that as is.

I don't have an ARM machine or any reasonable way to test this.

ChangeLog
2018-05-07  Tom Tromey  <tom@tromey.com>

	PR tdep/20362:
	* arm-tdep.c (arm_record_vfp_data_proc_insn): Properly mask off D
	bit.  Use correct value for VDIV.
2018-05-07 08:47:37 -06:00
Peter Bergner 2ceb7719f7 Cleanup ppc code dealing with opcode dumps.
include/
	* opcode/ppc.h (powerpc_num_opcodes): Change type to unsigned.
	(vle_num_opcodes): Likewise.
	(spe2_num_opcodes): Likewise.

opcodes/
	* ppc-opc.c (powerpc_num_opcodes): Likewise.
	(vle_num_opcodes): Likewise.
	(spe2_num_opcodes): Likewise.
	* ppc-dis.c (disassemble_init_powerpc) <powerpc_opcd_indices>: Rewrite
	initialization loop.
	(disassemble_init_powerpc) <vle_opcd_indices>: Likewise.
	(disassemble_init_powerpc) <spe2_opcd_indices>: Likewise.  Initialize
	only once.

gas/
	* config/tc-ppc.c (ppc_setup_opcodes) <powerpc_opcodes>: Rewrite code
	to dump the entire opcode table.
	(ppc_setup_opcodes) <spe2_opcodes>: Likewise.
	(ppc_setup_opcodes) <vle_opcodes>: Likewise.  Fix calculation of
	opcode index.
2018-05-07 09:40:59 -05:00
Alan Modra ce4ec1a9b6 Bug 23142, SIGSEGV in is_strip_section
PR 23142
	* objcopy.c (group_signature): Don't accept groups that use a
	symbol table other than the one we've read.
2018-05-07 22:50:31 +09:30
Alan Modra 7bd8862c3a Replace uses of strncmp with memcmp
Avoids gcc pr85623 for these calls.

	* cofflink.c (_bfd_coff_link_input_bfd): Use memcmp rather than
	strncmp when checking for ".bf" special symbol.
	* prXXigen.c (_bfd_XXi_swap_scnhdr_out): Make pe_required_section_flags
	section name a char array, remove sentinal known_sections entry,
	and adjust loop over known_sections to suit.  Use memcmp rather
	than strncmp.
2018-05-07 12:33:26 +09:30
H.J. Lu fe5bc53b24 gas/i386/xmmhi32.d: Also allow dir32 relocation
Also allow dir32 relocation to support mingw targets.

	* testsuite/gas/i386/xmmhi32.d: Also allow dir32 relocation.
2018-05-06 19:16:47 -07:00
H.J. Lu 57930ca905 i386: Append ".p2align 4,0" to gas tests
Append ".p2align 4,0" to i386 assembler tests to support mingw targets.

	* testsuite/gas/i386/avx512f-plain.s: Append ".p2align 4,0".
	* testsuite/gas/i386/avx512vl-plain.s: Likewise.
	* testsuite/gas/i386/bnd.s: Likewise.
	* testsuite/gas/i386/stN.s: Likewise.
	* testsuite/gas/i386/avx512f-plain.l: Updated.
	* testsuite/gas/i386/avx512vl-plain.l: Likewise.
	* testsuite/gas/i386/bnd.l: Likewise.
	* testsuite/gas/i386/stN.l: Likewise.
2018-05-06 19:09:12 -07:00
GDB Administrator 6ec91bb19f Automatic date update in version.in 2018-05-07 00:00:38 +00:00
GDB Administrator 82cd47d5d1 Automatic date update in version.in 2018-05-06 00:01:01 +00:00
Tom Tromey 85e26832a0 Add -Wimplicit-fallthrough
This adds -Wimplicit-fallthrough to the set of default warnings.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Add -Wimplicit-fallthrough.

gdbserver/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2018-05-04 22:04:46 -06:00
Tom Tromey 449b1ac7ad Add a missing break in record_linux_system_call
This adds a "break" at the end of the RECORD_SYS_RECVFROM case in
record_linux_system_call.  This seemed correct to me.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* linux-record.c (record_linux_system_call) <case
	RECORD_SYS_RECVFROM>: Add "break".
2018-05-04 22:04:46 -06:00
Tom Tromey 15c9ffd697 Add missing "breaks"
This adds a "break" to a couple of spots where it was erroneously
omitted.  I think these are the two (potential) real bugs caught by
this series.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* mi/mi-main.c (mi_cmd_trace_frame_collected) <REGISTERS_FORMAT>:
	Add missing "break".
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_locals) <NO_FRAME_FILTERS>:
	Add missing "break".
2018-05-04 22:04:46 -06:00
Tom Tromey e3829d13f6 Add two fall-through comments in rs6000-tdep.c
This adds two fall-through comments in rs6000-tdep.c.  I looked at the
PPC instruction manual and convinced myself that this was correct.
And, this isn't a semantic change.  However, close review would still
be good.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* rs6000-tdep.c (ppc_process_record_op4)
	(ppc_process_record_op63): Add fall-through comment.
2018-05-04 22:04:46 -06:00
Tom Tromey da0e15638d Add fall-through comment to i386-tdep.c
This adds a fall-through comment in i386-tdep.c.  I was not sure what
to do here, so I elected to preserve the status quo.  In review, John
Baldwin pointed out that: "I believe this is correct based on the diff
that added the special cases for xgetbv and xsetbv as previously ldgt
and lidt were treated the same".

gdb/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* i386-tdep.c (i386_process_record): Add fall-through comment.
2018-05-04 22:04:46 -06:00
Tom Tromey 0019cd49ca Add a fall-through comment to stabsread.c
This adds a fall-through comment to stabsread.c.  I skimmed the stabs
manual a bit and it seems that 'p' and 'P' are similar enough that
this makes sense.  Also, stabs is mostly deprecated, and the code has
been this way for a long time, so it seemed safest to keep the status
quo.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* stabsread.c (define_symbol) <case 'p'>: Add fall-through
	comment.
2018-05-04 22:04:46 -06:00
Tom Tromey 565e0edacc Fix "obvious" fall-through warnings
This patch fixes the subset of -Wimplicit-fallthrough warnings that I
considered obvious.  In most cases it was obvious from context that
falling through was desired; here I added the appropriate comment.  In
a couple of cases it seemed clear that a "break" was missing.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* riscv-tdep.c (riscv_isa_xlen): Add fall-through comment.
	* utils.c (can_dump_core) <LIMIT_CUR>: Add fall-through comment.
	* eval.c (fetch_subexp_value) <MEMORY_ERROR>: Add fall-through
	comment.
	* d-valprint.c (d_val_print) <TYPE_CODE_STRUCT>: Add fall-through
	comment.
	* coffread.c (coff_symtab_read) <C_LABEL>: Add fall-through
	comment.
2018-05-04 22:04:46 -06:00
Tom Tromey 621846f4e2 Add missing ATTRIBUTE_NORETURNs
This patch adds a missing ATTRIBUTE_NORETURN.  This lets
-Wimplicit-fallthrough recognize that a given case does not fall
through.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* dwarf2loc.c (unimplemented): Add ATTRIBUTE_NORETURN.
2018-05-04 22:04:46 -06:00
Tom Tromey 86a7300762 Fix "fall through" comments
This patch updates existing "fall through" comments so that they can
be recognized by gcc's -Wimplicit-fallthrough comment-parsing
heuristic.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* s390-tdep.c (s390_process_record): Fix fall-through comments.
	* xcoffread.c (scan_xcoff_symtab): Move comment later.
	* symfile.c (section_is_mapped): Fix fall-through comment.
	* stabsread.c (define_symbol, read_member_functions): Fix
	fall-through comment.
	* s390-linux-tdep.c (s390_process_record): Fix fall-through
	comment.
	* remote.c (remote_wait_as): Fix fall-through comment.
	* p-exp.y (yylex): Fix fall-through comment.
	* nat/x86-dregs.c (x86_length_and_rw_bits): Fix fall-through
	comment.
	* msp430-tdep.c (msp430_gdbarch_init): Fix fall-through comment.
	* mdebugread.c (parse_partial_symbols): Fix fall-through comment.
	* jv-exp.y (yylex): Fix fall-through comment.
	* go-exp.y (lex_one_token): Fix fall-through comment.
	* gdbtypes.c (get_discrete_bounds, rank_one_type): Fix
	fall-through comment.
	* f-exp.y (yylex): Fix fall-through comment.
	* dwarf2read.c (process_die): Fix fall-through comments.
	* dbxread.c (process_one_symbol): Fix fall-through comment.
	* d-exp.y (lex_one_token): Fix fall-through comment.
	* cp-name-parser.y (yylex): Fix fall-through comment.
	* coffread.c (coff_symtab_read): Fix fall-through comment.
	* c-exp.y (lex_one_token): Fix fall-through comment.
	* arm-tdep.c (arm_decode_miscellaneous): Fix fall-through
	comment.
	* arch/arm.c (arm_instruction_changes_pc): Fix fall-through
	comment.
2018-05-04 22:04:46 -06:00
GDB Administrator 4e6fe7477a Automatic date update in version.in 2018-05-05 00:00:43 +00:00
Tom Tromey 56bcdbea2b Let gdb.execute handle multi-line commands
This changes the Python API so that gdb.execute can now handle
multi-line commands, like "commands" or "define".

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22730:
	* NEWS: Mention gdb.execute change.
	* gdbcmd.h (execute_control_command): Don't declare.
	* python/python.c (execute_gdb_command): Use read_command_lines_1,
	execute_control_commands, execute_control_commands_to_string.
	* cli/cli-script.h (execute_control_commands)
	(execute_control_commands_to_string): Declare.
	(execute_control_command): Add from_tty parameter.
	* cli/cli-script.c (execute_control_commands)
	(execute_control_commands_to_string): New functions.
	(execute_user_command): Use execute_control_commands.
	(execute_control_command_1): Add "from_tty" parameter.  Update.
	(execute_control_command): Likewise.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22730:
	* gdb.python/python.exp: Test multi-line execute.
2018-05-04 15:58:09 -06:00
Tom Tromey a913fffbde Allow breakpoint commands to be set from Python
This changes the Python API so that breakpoint commands can be set by
writing to the "commands" attribute.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* NEWS: Mention that breakpoint commands are writable.
	* python/py-breakpoint.c (bppy_set_commands): New function.
	(breakpoint_object_getset) <"commands">: Use it.

doc/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* python.texi (Breakpoints In Python): Mention that "commands" is
	writable.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* gdb.python/py-breakpoint.exp: Test setting breakpoint commands.
2018-05-04 15:58:09 -06:00
Tom Tromey 60b3cef2e4 Use function_view in cli-script.c
This changes some functions in cli-script.c to use function_view
rather than a function pointer and closure argument.  This simplifies
the code a bit and is useful in a subsequent patch.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (actions_command): Update.
	* mi/mi-cmd-break.c (mi_command_line_array)
	(mi_command_line_array_cnt, mi_command_line_array_ptr)
	(mi_read_next_line): Remove.
	(mi_cmd_break_commands): Update.
	* cli/cli-script.h (read_command_lines, read_command_lines_1): Use
	function_view.
	* cli/cli-script.c (get_command_line): Update.
	(process_next_line): Use function_view.  Constify.
	(recurse_read_control_structure, read_command_lines)
	(read_command_lines_1): Change argument types to function_view.
	(do_define_command, document_command): Update.
	* breakpoint.h (check_tracepoint_command): Don't declare.
	* breakpoint.c (check_tracepoint_command): Remove.
	(commands_command_1, create_tracepoint_from_upload): Update.
2018-05-04 15:58:08 -06:00
Tom Tromey 7a2c85f259 Allow defining a user command inside a user command
PR gdb/11750 concerns defining a command inside a user commnad, like:

    define outer
      define inner
	echo hi\n
      end
    end

This patch adds this capability to gdb.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/11750:
	* cli/cli-script.h (enum command_control_type) <define_control>:
	New constant.
	* cli/cli-script.c (multi_line_command_p): Handle define_control.
	(build_command_line, execute_control_command_1)
	(process_next_line): Likewise.
	(do_define_command): New function, extracted from define_command.
	(define_command): Use it.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/11750:
	* gdb.base/define.exp: Test defining a user command inside a user
	command.
	* gdb.base/commands.exp (define_if_without_arg_test): Test "define".
2018-05-04 15:58:07 -06:00
Tom Tromey 295dc222a7 Constify prompt argument to read_command_lines
The prompt argument to read_command_lines can be const.  This patch
makes this change, and also removes some fixed-sized buffers in favor
of using string_printf.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (actions_command): Update.
	* cli/cli-script.h (read_command_lines): Update.
	* cli/cli-script.c (read_command_lines): Constify prompt_arg.
	(MAX_TMPBUF): Remove define.
	(define_command): Use string_printf.
	(document_command): Likewise.
	* breakpoint.c (commands_command_1): Update.
2018-05-04 15:58:07 -06:00
Tom Tromey 1263a9d5f1 Make print_command_trace varargs
I noticed some code in execute_control_command_1 that could be
simplified by making print_command_trace a printf-like function.  This
patch makes this change.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* top.c (execute_command): Update.
	* cli/cli-script.h (print_command_lines): Now varargs.
	* cli/cli-script.c (print_command_lines): Now varargs.
	(execute_control_command_1) <case while_control, case if_control>:
	Update.
2018-05-04 15:58:06 -06:00
Tom Tromey 12973681f5 Use counted_command_line everywhere
Currently command lines are reference counted using shared_ptr only
when attached to breakpoints.  This patch changes gdb to use
shared_ptr in commands as well.  This allows for the removal of
copy_command_lines.

Note that the change to execute_user_command explicitly makes a new
reference to the command line.  This will be used in a later patch.

This simplifies struct command_line based on the observation that a
given command can have at most two child bodies: an "if" can have both
"then" and "else" parts.  Perhaps the names I've chosen for the
replacements here are not very good -- your input requested.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (all_tracepoint_actions): Rename from
	all_tracepoint_actions_and_cleanup.  Change return type.
	(actions_command, encode_actions_1, encode_actions)
	(trace_dump_actions, tdump_command): Update.
	* remote.c (remote_download_command_source): Update.
	* python/python.c (gdbpy_eval_from_control_command)
	(python_command, python_interactive_command): Update.
	* mi/mi-cmd-break.c (mi_cmd_break_commands): Update.
	* guile/guile.c (guile_command)
	(gdbscm_eval_from_control_command, guile_command): Update.
	* compile/compile.c (compile_code_command)
	(compile_print_command, compile_to_object): Update.
	* cli/cli-script.h (struct command_lines_deleter): New.
	(counted_command_line): New typedef.
	(struct command_line): Add constructor, destructor.
	<body_list>: Remove.
	<body_list_0, body_list_1>: New members.
	(command_line_up): Remove typedef.
	(read_command_lines, read_command_lines_1, get_command_line):
	Update.
	(copy_command_lines): Don't declare.
	* cli/cli-script.c (build_command_line): Use "new".
	(get_command_line): Return counted_command_line.
	(print_command_lines, execute_user_command)
	(execute_control_command_1, while_command, if_command): Update.
	(realloc_body_list): Remove.
	(process_next_line, recurse_read_control_structure): Update.
	(read_command_lines, read_command_lines_1): Return counted_command_line.
	(free_command_lines): Use "delete".
	(copy_command_lines): Remove.
	(define_command, document_command, show_user_1): Update.
	* cli/cli-decode.h (struct cmd_list_element) <user_commands>: Now
	a counted_command_line.
	* breakpoint.h (counted_command_line): Remove typedef.
	(breakpoint_set_commands): Update.
	* breakpoint.c (check_no_tracepoint_commands)
	(validate_commands_for_breakpoint): Update.
	(breakpoint_set_commands): Change commands to be a
	counted_command_line.
	(commands_command_1, update_dprintf_command_list)
	(create_tracepoint_from_upload): Update.
2018-05-04 15:58:06 -06:00
Tom Tromey e2fc72e2c5 Allocate cmd_list_element with new
This adds a constructor and destructor to cmd_list_element and changes
it to be allocated with new.  This will be useful in a subsequent
patch.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* cli/cli-decode.h (cmd_list_element): New constructor.
	(~cmd_list_element): New destructor.
	(struct cmd_list_element): Add initializers.
	* cli/cli-decode.c (do_add_cmd): Use "new".
	(delete_cmd): Use "delete".
2018-05-04 15:58:05 -06:00
Jan Kratochvil a3b60e4588 aarch64: PR 19806: watchpoints: false negatives + PR 20207 contiguous ones
Some unaligned watchpoints were currently missed.

On old kernels as specified in
	kernel RFE: aarch64: ptrace: BAS: Support any contiguous range (edit)
	https://sourceware.org/bugzilla/show_bug.cgi?id=20207
after this patch some other unaligned watchpoints will get reported as false
positives.

With new kernels all the watchpoints should work exactly.

There may be a regresion that it now less merges watchpoints so that with
multiple overlapping watchpoints it may run out of the 4 hardware watchpoint
registers.  But as discussed in the original thread GDB needs some generic
watchpoints merging framework to be used by all the target specific code.
Even current FSF GDB code does not merge it perfectly.  Also with the more
precise watchpoints one can technically merge them less.  And I do not think
it matters too much to improve mergeability only for old kernels.
Still even on new kernels some better merging logic would make sense.

There remains one issue:
	kernel-4.15.14-300.fc27.armv7hl
	FAIL: gdb.base/watchpoint-unaligned.exp: continue
	FAIL: gdb.base/watchpoint-unaligned.exp: continue
	(gdb) continue
	Continuing.
	Unexpected error setting watchpoint: Invalid argument.
	(gdb) FAIL: gdb.base/watchpoint-unaligned.exp: continue
But that looks as a kernel bug to me.
(1) It is not a regression by this patch.
(2) It is unrelated to this patch.

gdb/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves <palves@redhat.com>

	PR breakpoints/19806 and support for PR external/20207.
	* NEWS: Mention Aarch64 watchpoint improvements.
	* aarch64-linux-nat.c (aarch64_linux_stopped_data_address): Fix missed
	watchpoints and PR external/20207 watchpoints.
	* nat/aarch64-linux-hw-point.c
	(kernel_supports_any_contiguous_range): New.
	(aarch64_watchpoint_offset): New.
	(aarch64_watchpoint_length): Support PR external/20207 watchpoints.
	(aarch64_point_encode_ctrl_reg): New parameter offset, new asserts.
	(aarch64_point_is_aligned): Support PR external/20207 watchpoints.
	(aarch64_align_watchpoint): New parameters aligned_offset_p and
	next_addr_orig_p.  Support PR external/20207 watchpoints.
	(aarch64_downgrade_regs): New.
	(aarch64_dr_state_insert_one_point): New parameters offset and
	addr_orig.
	(aarch64_dr_state_remove_one_point): Likewise.
	(aarch64_handle_breakpoint): Update caller.
	(aarch64_handle_aligned_watchpoint): Likewise.
	(aarch64_handle_unaligned_watchpoint): Support addr_orig and
	aligned_offset.
	(aarch64_linux_set_debug_regs): Remove const from state.  Call
	aarch64_downgrade_regs.
	(aarch64_show_debug_reg_state): Print also dr_addr_orig_wp.
	* nat/aarch64-linux-hw-point.h (DR_CONTROL_LENGTH): Rename to ...
	(DR_CONTROL_MASK): ... this.
	(struct aarch64_debug_reg_state): New field dr_addr_orig_wp.
	(unsigned int aarch64_watchpoint_offset): New prototype.
	(aarch64_linux_set_debug_regs): Remove const from state.
	* utils.c (align_up, align_down): Move to ...
	* common/common-utils.c (align_up, align_down): ... here.
	* utils.h (align_up, align_down): Move to ...
	* common/common-utils.h (align_up, align_down): ... here.

gdb/gdbserver/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves <palves@redhat.com>

	* linux-aarch64-low.c (aarch64_stopped_data_address):
	Likewise.

gdb/testsuite/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves <palves@redhat.com>

	PR breakpoints/19806 and support for PR external/20207.
	* gdb.base/watchpoint-unaligned.c: New file.
	* gdb.base/watchpoint-unaligned.exp: New file.
2018-05-04 22:26:46 +02:00
Andrew Burgess 45fe4a03b4 gdb: Make test names unique in gdb.base/maint.exp
Add prefixes or suffixes to some test names to make them unique.

Replace a send_gdb/gdb_expect with a gdb_test, and make the test name
unique.

Remove test of 'help maint' as this is already covered by a later call
to test_prefix_command_help.

Removed test of 'help maint info' and add a new call to
test_prefix_command_help instead.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Make test names unique, use
	test_prefix_command_help to test 'help maint info', and remove
	repeated test of 'help maint'.
2018-05-04 20:19:19 +01:00
Joel Brobecker 05bc7456b8 (SPARC/LEON) fix incorrect array return value printed by "finish"
Consider the code in the gdb.ada/array_return.exp testcase, which
defines a function returning an array of 2 integers:

   type Data_Small is array (1 .. 2) of Integer;
   function Create_Small return Data_Small;

When doing a "finish" from inside function Create_Small, we expect
GDB to tell us that the return value was "(1, 1)". However, it currently
prints the wrong value:

    (gdb) finish
    Run till exit from #0  pck.create_small () at /[...]/pck.adb:5
    p () at /[...]/p.adb:10
    10         Large := Create_Large;
    Value returned is $1 = (0, 0)

This is a regression which I traced back to the following commit...

    | commit 1933fd8ee0
    | Date:   Fri May 19 03:06:19 2017 -0700
    | Subject: gdb: fix TYPE_CODE_ARRAY handling in sparc targets

... which, despite what the subject says, is not really about
TYPE_CODE_ARRAY handling, which is a bit of an implementation detail,
but about the GNU vectors extension.

The author of the patch equated TYPE_CODE_ARRAY with vectors, which
is not correct. Vectors are TYPE_CODE_ARRAY types with the TYPE_VECTOR
flag set. So at the very minimum, the patch should have been checking
for both TYPE_CODE_ARRAY and TYPE_VECTOR.

But, that's not the only thing that did not seem right to me. When
looking at the ABI, and at the summary of the implementation in GCC
of the calling conventions for that architecture:

                                size      argument     return value

      small integer              <4       int. reg.      int. reg.
      word                        4       int. reg.      int. reg.
      double word                 8       int. reg.      int. reg.

      _Complex small integer     <8       int. reg.      int. reg.
      _Complex word               8       int. reg.      int. reg.
      _Complex double word       16        memory        int. reg.

      vector integer            <=8       int. reg.       FP reg.
      vector integer             >8        memory         memory

      float                       4       int. reg.       FP reg.
      double                      8       int. reg.       FP reg.
      long double                16        memory         memory

      _Complex float              8        memory         FP reg.
      _Complex double            16        memory         FP reg.
      _Complex long double       32        memory         FP reg.

      vector float              any        memory         memory

      aggregate                 any        memory         memory

The nice thing about the patch above is that it nicely factorized
the code that determines how arguments are passed/returns. The bad
news is that the implementation, particularly for the handling of
arrays and vectors, doesn't seem to match the summary above. Hence,
the regression we observed.

So what I did was review and re-implement some of the predicate functions
according to the summary above. Because dejagnu crashes all our Solaris
machines real bad, I can't run the dejagnu testsuite there. So what I did
was test the patch with AdaCore's testsuite against leon3-elf, no
regression. I verified that this fixes the regression above while
at the same time still passing gdb.base/gnu_vector.exp (I transposed
that testcase to our testsuite), which is the testcase that was cited
in the commit above as seeing some FAIL->PASS improvements.

This patch also removes one assertion...

      gdb_assert (sparc_integral_or_pointer_p (type)
                  || (TYPE_CODE (type) == TYPE_CODE_ARRAY && len <= 8));

... because that assertion is really the "negative" of the other conditions
written in the same "if, else if, else [assert]" block in this function.
To me, this assertion forces us to maintain two versions of the same code,
and is an unnecessary burden. In particular, the above is not the
correct condition, and the ABI summary table above shows that we need
a more complex condition to describe the situations where we expect
arguments to be passed by register.

gdb/ChangeLog:

        * sparc-tdep.c (sparc_structure_return_p): Re-implement to
        match the ABI as summarized in GCC's gcc/config/sparc/sparc.c.
        (sparc_arg_by_memory_p): Renamed from sparc_arg_on_registers_p.
        Re-implement to match the ABI as summarized in GCC's
        gcc/config/sparc/sparc.c.  All callers updated.
        (sparc32_store_arguments): Remove assertion.
2018-05-04 14:33:19 -04:00
Tom Tromey 2f433492bd Minor cleanups in printcmd.c
This changes decode_format to use skip_spaces, and changes printcmd.c
not to include tui.h, which apparently is not needed.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* printcmd.c: Don't include tui.h.
	(decode_format): Use skip_spaces.
2018-05-04 12:22:44 -06:00
Tom Tromey 9be2ae8fc6 Use previous count when 'x' command is repeated
About the 'x' command, the manual says:

    If you use <RET> to repeat the 'x' command, the repeat count N is
    used again; the other arguments default as for successive uses of
    'x'.

However, PR gdb/22619 points out that this does not work.

This patch fixes the problem.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/22619:
	* printcmd.c (last_count): New global.
	(x_command): Use saved count when repeating.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/22619:
	* gdb.base/long_long.exp (gdb_test_long_long): Add test for repeat
	behavior.
2018-05-04 12:22:37 -06:00
Tom Tromey f0b3976bdc Remove do_closedir_cleanup
This removes both copies of do_closedir_cleanup in favor of a new
unique_ptr specialization.

Tested by the buildbot, though I'm not sure that these code paths are
exercised there.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* nto-procfs.c (do_closedir_cleanup): Remove.
	(procfs_pidlist): Use gdb_dir_up.
	* procfs.c (do_closedir_cleanup): Remove.
	(proc_update_threads): Use gdb_dir_up.
	* common/filestuff.h (struct gdb_dir_deleter): New.
	(gdb_dir_up): New typedef.
2018-05-04 12:20:37 -06:00
Tom Tromey 862d101ada Remove cleanup from print_mention_exception
This removes a cleanup from print_mention_exception by using
string_printf.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (print_mention_exception): Use std::string.
2018-05-04 12:12:16 -06:00
Tom Tromey cb7de75eb3 Return std::string from ada_exception_catchpoint_cond_string
This changes ada_exception_catchpoint_cond_string to return a
std::string, allowing for the removal of a cleanup in
create_excep_cond_exprs.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (create_excep_cond_exprs): Update.
	(ada_exception_catchpoint_cond_string): Use std::string.
2018-05-04 12:12:16 -06:00