This changes gdb_bfd_data to use std::vector rather than VEC.
ChangeLog
2017-10-20 Tom Tromey <tom@tromey.com>
* gdb_bfd.c (struct gdb_bfd_data) <included_bfds>: Now a
std::vector.
(gdb_bfd_record_inclusion): Update.
(bfdp): Remove typedef.
This changes gdb_bfd_data to be allocated with new and destroyed with
delete.
ChangeLog
2017-10-20 Tom Tromey <tom@tromey.com>
* gdb_bfd.c (gdb_bfd_ref): Use new.
(struct gdb_bfd_data): Add constructor, destructor, and member
initializers.
(gdb_bfd_unref): Use delete.
This introduces a helper function, new_bfd_ref, that calls gdb_bfd_ref
and returns a gdb_bfd_ref_ptr. Then it updates several places to use
this.
ChangeLog
2017-10-20 Tom Tromey <tom@tromey.com>
* exec.c (exec_file_attach): Use new_bfd_ref.
* symfile-mem.c (symbol_file_add_from_memory): Use new_bfd_ref.
* gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr)
(gdb_bfd_openw, gdb_bfd_openr_iovec, gdb_bfd_fdopenr): Use
new_bfd_ref.
* gdb_bfd.h (new_bfd_ref): New function.
The [wait -i $gdb_spawn_id] in the test is dangerous in the sense that
it won't be subject to timeout logic. So if GDB fails quiting, this
testcase hangs forever, hanging the test run with it. See:
https://sourceware.org/ml/gdb-patches/2016-10/msg00728.html
Instead of 'wait'ing directly, use gdb_test_multiple and expect 'eof'.
Tested that the testcase no longer hangs by hacking the test to send
"info threads" instead of "quit".
Tested with
--target_board={unix, native-gdbserver,native-extended-gdbserver}
and tested with
--host_board=local-remote-host
as well.
gdb/testsuite/ChangeLog:
2017-10-20 Pedro Alves <palves@redhat.com>
* gdb.base/quit.exp: Use gdb_test_multiple and expect 'eof' before
'wait -i'. Use gdb_assert and remote_close.
After commit bf46927112 ("Eliminate catch_errors"), GCC started
inlining captured_command_loop in captured_main. And setting a
breakpoint on captured_command_loop makes the inferior GDB stop in
captured_main, _after_ captured_command_loop's call to
interp_pre_command_loop, which prints the inferior GDB's prompt, has
already executed, confusing the gdb.gdb/ selftest tests:
(gdb) FAIL: gdb.gdb/complaints.exp: run until breakpoint at captured_command_loop
WARNING: Couldn't test self
Debugging GDB with GDB manually, we see:
(top-gdb) b captured_command_loop
Breakpoint 1 at 0x71ee60: file src/gdb/main.c, line 324.
(top-gdb) r
[....]
(gdb) <<<<<< PROMPT HERE
Thread 1 "gdb" hit Breakpoint 1, captured_main (data=<optimized out>) at src/gdb/main.c:1147
1147 captured_command_loop ();
(top-gdb)
Note the stop at 'captured_main', and the "PROMPT HERE" line. That
prompt does not show up when debugging a non-optimized build of GDB.
Fix this by preventing inlining of captured_command_loop.
Ref: https://sourceware.org/ml/gdb-patches/2017-10/msg00522.html
gdb/ChangeLog:
2017-10-20 Pedro Alves <palves@redhat.com>
* main.c (captured_command_loop): Add attribute noinline.
PR 22324
* read.c (s_rept): Use size_t type for count parameter.
(do_repeat): Change type of count parameter to size_t.
Issue an error is the count parameter is negative.
(do_repeat_with_expression): Likewise.
* read.h: Update prototypes for do_repeat and
do_repeat_with_expression.
* doc/as.texinfo (Rept): Document that a zero count is allowed but
negative counts are not.
* config/tc-rx.c (rx_rept): Use size_t type for count parameter.
* config/tc-tic54x.c (tic54x_loop): Cast count parameter to size_t
type.
* testsuite/gas/macros/end.s: Add a test using a negative repeat
count.
* testsuite/gas/macros/end.l: Add expected error message.
gold/
* arm.cc (Stub::do_fixed_endian_write):Far call stubs support for arm
in the be8 mode.
* testsuite/Makefile.am: New test cases.
* testsuite/Makefile.in: Regenerate.
* testsuite/arm_farcall_arm_arm_be8.sh: New script for arm to arm far
call stubs.
* testsuite/arm_farcall_thumb_thumb_be8.sh: New script for thumb to
thumb far call stubs.
This removes the remaining cleanups from break-catch-syscall.c by
storing temporary strings in a vector.
ChangeLog
2017-10-19 Tom Tromey <tom@tromey.com>
* break-catch-syscall.c (catch_syscall_completer): Use
std::string, gdb::unique_xmalloc_ptr.
This changes call_function_by_hand_dummy to use std::string, removing
a cleanup.
ChangeLog
2017-10-19 Tom Tromey <tom@tromey.com>
* infcall.c (call_function_by_hand_dummy): Use std::string.
Removes the use of a hard-coded line number from a test.
gdb/testsuite/ChangeLog:
* gdb.linespec/ls-errs.exp (do_test): Update comment, use line
number from variable rather than hard-coded.
The buildbots are showing that the previous change to
xml_fetch_content_from_file causes __wur warnings/errors:
../../binutils-gdb/gdb/xml-support.c: In function gdb::unique_xmalloc_ptr<char> xml_fetch_content_from_file(const char*, void*):
../../binutils-gdb/gdb/xml-support.c:1028:43: error: ignoring return value of size_t fread(void*, size_t, size_t, FILE*), declared with attribute warn_unused_result [-Werror=unused-result]
fread (text.get (), 1, len, file.get ());
^
This commit fixes it.
gdb/ChangeLog:
2017-10-19 Pedro Alves <palves@redhat.com>
* xml-support.c (xml_fetch_content_from_file): Check fread's
return.
In the medany code model the compiler generates PCREL_HI20+PCREL_LO12
relocation pairs against local symbols because HI20+LO12 relocations
can't reach high addresses. We relax HI20+LO12 pairs to GPREL
relocations when possible, which is an important optimization for
Dhrystone. Without this commit we are unable to relax
PCREL_HI20+PCREL_LO12 pairs to GPREL when possible, causing a 10%
permormance hit on Dhrystone on Rocket.
Note that we'll now relax
la gp, __global_pointer$
to
mv gp, gp
which probably isn't what you want in your entry code. Users who want
gp-relative symbols to continue to resolve should add ".option norelax"
accordingly. Due to this, the assembler now pairs PCREL relocations
with RELAX relocations when they're expected to be relaxed just like
every other relaxable relocation.
bfd/ChangeLog
2017-10-19 Palmer Dabbelt <palmer@dabbelt.com>
* elfnn-riscv.c (riscv_pcgp_hi_reloc): New structure.
(riscv_pcgp_lo_reloc): Likewise.
(riscv_pcgp_relocs): Likewise.
(riscv_init_pcgp_relocs): New function.
(riscv_free_pcgp_relocs): Likewise.
(riscv_record_pcgp_hi_reloc): Likewise.
(riscv_record_pcgp_lo_reloc): Likewise.
(riscv_delete_pcgp_hi_reloc): Likewise.
(riscv_use_pcgp_hi_reloc): Likewise.
(riscv_record_pcgp_lo_reloc): Likewise.
(riscv_find_pcgp_lo_reloc): Likewise.
(riscv_delete_pcgp_lo_reloc): Likewise.
(_bfd_riscv_relax_pc): Likewise.
(_bfd_riscv_relax_section): Handle R_RISCV_PCREL_* relocations
via the new functions above.
gas/ChangeLog
2017-10-19 Palmer Dabbelt <palmer@dabbelt.com>
* config/tc-riscv.c (md_apply_fix): Mark
BFD_RELOC_RISCV_PCREL_HI20 as relaxable when relaxations are
enabled.
We currently delete bytes by shifting an entire BFD backwards to
overwrite the bytes we no longer need. The result is that relaxing a
BFD is quadratic time.
This patch adds an additional relocation that specifies a byte range
that will be deleted from the final object file, and adds a relaxation
pass (between the existing passes that delete bytes and the alignment
pass) that actually deletes the bytes. Note that deletion is still
quadratic time, and nothing uses R_RISCV_DELETE yet.
I've been meaning to go convert all the other relaxations to use
R_RISCV_DELETE and then make it faster, but this patch has been sitting
around for months so it looks like that won't happen for a bit. The
PCREL->GPREL relaxation that comes next uses this, and since we've been
using these two patches out of tree since I wrote them months ago I
figure it's better to just get them in now. I (or someone else :)) can
convert all the relocations later...
R_RISCV_DELETE will never be emitted into ELF objects, so therefor isn't
exposed to the rest of binutils. As such, we're not considering this as
part of the ABI.
bfd/ChangeLog
2017-10-19 Palmer Dabbelt <palmer@dabbelt.com>
* elfnn-riscv (R_RISCV_DELETE): New define.
(_bfd_riscv_relax_delete): New function.
(perform_relocation): Handle R_RISCV_DELETE.
(_bfd_riscv_relax_section): Likewise.
ld/ChangeLog
2017-10-19 Palmer Dabbelt <palmer@dabbelt.com>
* emultempl/riscvelf.em (riscv_elf_before_allocation): Add a
third relaxation pass.
PR 21621
* config/tc-avr.h (struct avr_frag_data): Add prev_opcode field.
(TC_FRAG_INIT): Define.
(avr_frag_init): Add prototype.
* config/tc-avr.c (avr_frag_init): New function.
(avr_operands): Replace static local 'prev' variable with
prev_opcode field in current frag.
* testsuite/gas/avr/pr21621.s: New test source file.
* testsuite/gas/avr/pr21621.d: New test driver file.
* testsuite/gas/avr/pr21621.s: New test error output file.
Comparing test results between
--target_board=native-gdbserver
--target_board=native-stdio-gdbserver
I noticed that gdb.base/bigcore.exp is failing with native-stdio-gdbserver:
Running src/gdb/testsuite/gdb.base/bigcore.exp ...
FAIL: gdb.base/bigcore.exp: continue (timeout)
...
The problem is that:
1. When debugging with "target remote | CMD", the inferior's
stdout/stderr streams are connected to a pipe.
2. The bigcore.c program prints a lot to the screen before it
reaches the breakpoint location that the "continue" shown above
wants to reach.
3. GDB is not flushing the inferior's output pipe while the inferior
is running.
4. The pipe becomes full.
5. The inferior thus deadlocks.
The bug is #3 above, which is what this commit fixes. A new test is
added, that specifically exercises this scenario. The test fails
before the fix, and passes after, and gdb.base/bigcore.exp also starts
passing.
gdb/ChangeLog:
2017-10-19 Pedro Alves <palves@redhat.com>
* ser-base.c (ser_base_read_error_fd): Delete the file handler if
async.
(handle_error_fd): New function.
(ser_base_async): Add/delete an event loop file handler for
error_fd.
gdb/testsuite/ChangeLog:
2017-10-19 Pedro Alves <palves@redhat.com>
* gdb.base/long-inferior-output.c: New file.
* gdb.base/long-inferior-output.exp: New file.
There doesn't seem to be a good reason we're reading the file one
chunk at a time.
gdb/ChangeLog:
2017-10-19 Pedro Alves <palves@redhat.com>
* xml-support.c (xml_fetch_content_from_file): Don't read in
chunks. Instead use fseek to determine the file's size, and read
it in one go.
Copied from x86, check bfd_link_executable, instead of bfd_link_pic,
for TLS transition check. Not sure if it works correctly. All usages
of bfd_link_pic should be audited.
PR ld/22263
* elfxx-tilegx.c (tilegx_elf_tls_transition): Replace
bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
bfd_link_executable for TLS check.
(tilegx_elf_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
(tilegx_elf_relocate_section): Likewise.
Copied from x86, check bfd_link_executable, instead of bfd_link_pic,
for TLS transition check. Not sure if it works correctly. All usages
of bfd_link_pic should be audited.
PR ld/22263
* elf32-tilepro.c (tilepro_elf_tls_transition): Replace
bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
bfd_link_executable for TLS check.
(tilepro_elf_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
(tilepro_elf_relocate_section): Likewise.
Copied from x86, check bfd_link_executable, instead of bfd_link_pic,
for TLS transition check. Not sure if it works correctly. All usages
of bfd_link_pic should be audited.
PR ld/22263
* elfxx-sparc.c (sparc_elf_tls_transition): Replace
bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
bfd_link_executable for TLS check.
(_bfd_sparc_elf_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
(_bfd_sparc_elf_relocate_section): Likewise.
This fixes various issues with the fill-1 testcase causing fails on a
couple of targets.
gas/ChangeLog:
2017-10-19 Andreas Krebbel <krebbel@linux.vnet.ibm.com>
* testsuite/gas/all/fill-1.s: Use normal labels. Change .text to
.data. Pick different values. Use .dc.w instead of .word.
* testsuite/gas/all/fill-1.d: New objdump output check.
* testsuite/gas/all/gas.exp: Use run_dump_test to execute fill-1
testcase.
TLS_GD_CALL relocations implicitly reference __tls_get_addr. Since
elf_gc_mark_hook is called before check_relocs now, we need to call
_bfd_generic_link_add_one_symbol to mark __tls_get_addr for garbage
collection.
* elf32-tilepro.c (tilepro_elf_gc_mark_hook): Call
_bfd_generic_link_add_one_symbol to mark __tls_get_addr.
* elfxx-tilegx.c (tilegx_elf_gc_mark_hook): Likewise.
There are individual comments that explain why each test isn't
supported, but the vast majority of them are due to RISC-V's aggressive
linker relaxation. The SLEB test cases should eventually be supported,
but the remaining ones probably won't ever be.
2017-10-18 Palmer Dabbelt <palmer@dabbelt.com>
* testsuite/gas/all/align.d: Mark as unsupported on RISC-V.
testsuite/gas/all/relax.d: Likewise.
testsuite/gas/all/sleb128-2.d: Likewise.
testsuite/gas/all/sleb128-4.d: Likewise.
testsuite/gas/all/sleb128-5.d: Likewise.
testsuite/gas/all/sleb128-7.d: Likewise.
testsuite/gas/elf/section11.d: Likewise.
testsuite/gas/all/gas.exp (diff1.s): Likewise.
Consider a conversion operator such as:
operator foo const* const* ();
There are two small parser problems, highlighted by this test:
(gdb) p operator foo const* const*
There is no field named operatorfoo const* const *
GDB is looking up the symbol "operatorfoo const* const*" -- it is missing a
space between the keyword "operator" and the type name "foo const* const*".
Additionally, this input of the user-defined type needs to be canonicalized
so that different "spellings" of the type are recognized:
(gdb) p operator const foo* const *
There is no field named operator const foo* const *
gdb/ChangeLog:
* c-exp.y (oper): Canonicalize conversion operators of user-defined
types.
Add whitespace to front of type name.
gdb/testsuite/ChangeLog:
* gdb.cp/cpexprs.cc (base) <operator fluff const* const*>: New
method.
(main): Call it.
* gdb.cp/cpexprs.exp: Add new conversion operator to test matrix.
Add additional user-defined conversion operator tests.
A previous patch called gdb_assert_not_reached whenever reading
the accessibility of a nested typedef definition. Wisely, Pedro has asked me
not do this.
This patch changes the previous one so that it issues a complaint instead.
gdb/ChangeLog:
* dwarf2read.c (dwarf2_add_typedef): Issue a complaint on unhandled
DW_AT_accessibility.
The print_core_note change here fixes the PR, the rest is making
readelf a little more bombproof against maliciously crafted binaries.
PR 22303
* readelf.c (print_core_note): Ensure "count" sanity check
calculation doesn't overflow.
(process_notes_at): Perform note namesz and descsz checks
using unsigned comparisons against data remaining. Catch
alignment overflow of namesz and descsz too. Don't allocate a
temp for terminating "name" when there is space available
before descdata.
Relocations against indirect and warning symbols should be applied to real
symbols.
* elf32-microblaze.c (microblaze_elf_check_relocs): Check for
indirect and warning symbols.
Fixes a thinko. Given code that puts variables into the TOC (a bad
idea, but some see the TOC as a small data section) this bug could
result in an attempt to optimize a sequence that should not be
optimized.
* powerpc.cc (Target_powerpc::Scan::local): Correct dst_off
calculation for TOC16 relocs.
(Target_powerpc::Scan::global): Likewise.
I've noticed now that due to a last-minute change, commit 739b3f1d8f
("Make native gdbserver boards no longer be "remote" (in DejaGnu
terms)") managed to miss loading "local-board" in the
native-stdio-gdbserver board...
gdb/testsuite/ChangeLog:
2017-10-17 Pedro Alves <palves@redhat.com>
* boards/native-stdio-gdbserver.exp: Load "local-board".
In https://sourceware.org/ml/binutils/2017-10/msg00160.html, Nick said I
should update MAINTAINERS to mention that I'm the dwarf-mode.el
maintainer. So, I'm checking this in.
2017-10-17 Tom Tromey <tom@tromey.com>
* MAINTAINERS: Add myself as dwarf-mode.el maintainer.
In my multi-target branch, I had managed to break GDB exiting
successfuly in response to "quit" or SIGHUP/SIGTERM when:
- you're debugging with "target extended-remote",
- have more than one inferior loaded in gdb, some running, and at
least one not running, and,
- quit gdb with the inferior that is not running yet selected.
The testsuite still passed cleanly anyway. I only noticed because I
was left with a bunch of core dumps in the gdb/testsuite/ directory --
the testsuite infrastructure closes GDB's pty after running each
testcase, which results in GDB getting a SIGHUP and should make GDB
exit gracefully. If GDB crashes at that point though, there's no
indication about it in gdb.sum/gdb.log.
This commit adds a multitude of tests exercising quitting GDB with
live inferiors, some of which would have caught the problem.
gdb/testsuite/ChangeLog:
2017-10-17 Pedro Alves <palves@redhat.com>
* gdb.base/quit-live.c: New file.
* gdb.base/quit-live.exp: New file.
This changes the remaining spots in disasm.c to use the RAII ui-out
emitters, removing a few cleanups. This also fixes a regression that
Simon pointed out.
2017-10-17 Tom Tromey <tom@tromey.com>
* disasm.c (do_mixed_source_and_assembly_deprecated): Use
gdb::optional, ui_out_emit_list, ui_out_emit_tuple.
(do_mixed_source_and_assembly): Likewise.
When building I got:
../../binutils-gdb/gdb/regcache.c:935:24: error: the address of ‘ssize_t read(int, void*, size_t)’ will never be NULL [-Werror=address]
This happens because "read" used to be a parameter to this function,
which was then removed; but the assertion wasn't updated.
I don't think the assertion is relevant any more, to this removes it.
I'm checking it in as obvious.
2017-10-17 Tom Tromey <tom@tromey.com>
* regcache.c (regcache::xfer_part): Remove assertion.
When adding an unbounded increment to a pointer, you can't just check
against the end of the buffer but also must check that overflow
doesn't result in "negative" pointer movement. Pointer comparisons
are signed. Better, check the increment against the space left using
an unsigned comparison.
PR 22307
* elf-properties.c (_bfd_elf_parse_gnu_properties): Compare datasz
against size left rather than comparing pointers. Reorganise loop.
Fixes a double-free regression introduced by commit b7b030adc4
("Return unique_xmalloc_ptr from target_read_stralloc"):
gdb.sum:
Running src/gdb/testsuite/gdb.base/catch-syscall.exp ...
ERROR: Process no longer exists
Valgrind shows:
(gdb) catch syscall
==3687== Thread 1:
==3687== Invalid free() / delete / delete[] / realloc()
==3687== at 0x4C29CF0: free (vg_replace_malloc.c:530)
==3687== by 0x610862: xfree(void*) (common-utils.c:101)
==3687== by 0x440D5D: gdb::xfree_deleter<char>::operator()(char*) const (gdb_unique_ptr.h:34)
==3687== by 0x446CC6: std::unique_ptr<char, gdb::xfree_deleter<char> >::reset(char*) (unique_ptr.h:344)
==3687== by 0x81BE50: xml_fetch_content_from_file(char const*, void*) (xml-support.c:1042)
==3687== by 0x81DA86: xml_init_syscalls_info(char const*) (xml-syscall.c:366)
==3687== by 0x81DBDD: init_syscalls_info(gdbarch*) (xml-syscall.c:398)
==3687== by 0x81E131: get_syscall_by_number(gdbarch*, int, syscall*) (xml-syscall.c:599)
==3687== by 0x5BE86F: catch_syscall_command_1(char*, int, cmd_list_element*) (break-catch-syscall.c:481)
==3687== by 0x4B46B1: do_sfunc(cmd_list_element*, char*, int) (cli-decode.c:138)
==3687== by 0x4B76B8: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1952)
==3687== by 0x7E91C7: execute_command(char*, int) (top.c:615)
==3687== Address 0x14332ae0 is 0 bytes inside a block of size 4,096 free'd
==3687== at 0x4C2AB8B: realloc (vg_replace_malloc.c:785)
==3687== by 0x610792: xrealloc (common-utils.c:62)
==3687== by 0x81BE3E: xml_fetch_content_from_file(char const*, void*) (xml-support.c:1042)
==3687== by 0x81DA86: xml_init_syscalls_info(char const*) (xml-syscall.c:366)
==3687== by 0x81DBDD: init_syscalls_info(gdbarch*) (xml-syscall.c:398)
==3687== by 0x81E131: get_syscall_by_number(gdbarch*, int, syscall*) (xml-syscall.c:599)
==3687== by 0x5BE86F: catch_syscall_command_1(char*, int, cmd_list_element*) (break-catch-syscall.c:481)
==3687== by 0x4B46B1: do_sfunc(cmd_list_element*, char*, int) (cli-decode.c:138)
==3687== by 0x4B76B8: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1952)
==3687== by 0x7E91C7: execute_command(char*, int) (top.c:615)
==3687== by 0x6A422D: command_handler(char*) (event-top.c:583)
==3687== by 0x6A45F2: command_line_handler(char*) (event-top.c:773)
[...]
The problem is that if xrealloc decides it needs a new memory block,
it frees the previous block/pointer, and then text.reset() frees it
again.
gdb/ChangeLog:
2017-10-17 Pedro Alves <palves@redhat.com>
* xml-support.c (xml_fetch_content_from_file): Call
unique_ptr::release() instead unique_ptr::get() when passing
through xrealloc.
Since xfer_part is already a class method, and only
{raw,cooked}_{read,write} are passed to it. We can remove these two
arguments, but add a bool argument is_raw, indicating raw registers or
cooked registers are accessed.
gdb:
2017-10-17 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache::xfer_part): Remove parameters read and
write, add parameter is_raw. All callers are updated.
gdb/gdbserver:
2017-10-17 Yao Qi <yao.qi@linaro.org>
* configure.srv: Rename arm-linux.o with arch/arm-linux.o.
Rename arm-get-next-pcs.o with arch/arm-get-next-pcs.o.
Similar to f38307f5 (Replicate src dir in build dir), this patch change
configure and Makefile to generate object files in arch/ directory.
gdb/gdbserver:
2017-10-17 Yao Qi <yao.qi@linaro.org>
* Makefile.in (CONFIG_SRC_SUBDIR): New variable.
(clean): Remove .o files in CONFIG_SRC_SUBDIR.
(distclean): Remove DEPDIR in CONFIG_SRC_SUBDIR.
(arch-i386.o, arch-amd64.o): Remove rules.
(arch/%.o): New rule.
Update POSTCOMPILE and COMPILE.pre.
* configure.ac: Invoke AC_CONFIG_COMMANDS.
* configure: Re-generated.
* configure.srv: Replace arch-i386.o with arch/i386.o.
Replace arch-amd64.o with arch/amd64.o.