I happened to notice that add_symbol_file_command leaks "sect_opts".
This patch fixes the leak by changing sect_opts to be a std::vector.
I had to change the logic in the loop a little bit. Previously, it
was incrementing section_index after completing an entry; but this
changes it to push a new entry when the name is seen.
I believe the argument parsing here is mildly incorrect, in that
nothing checks whether the -s option actually had any arguments.
Maybe gdb can crash if "-s NAME" is given without an argument. I
didn't try to fix this in this patch, but I do have another patch I
can send later that fixes it up.
Regression tested on the buildbot.
ChangeLog
2017-08-11 Tom Tromey <tom@tromey.com>
* symfile.c (add_symbol_file_command): Use std::vector.
This patch adds std::move to few spots where it seems to be missing.
Regression tested by the buildbot.
ChangeLog
2017-08-14 Tom Tromey <tom@tromey.com>
* break-catch-throw.c (handle_gnu_v3_exceptions): Use std::move.
* break-catch-syscall.c (create_syscall_event_catchpoint): Use
std::move.
* break-catch-sig.c (create_signal_catchpoint): Use std::move.
Until all .eh_frame sections have been edited we don't know their
sizes. So it isn't possible to properly decide whether a non-empty
.eh_frame section follows a given section until editing is complete.
bfd/
PR 21441
* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't add
alignment padding here.
* elflink.c (bfd_elf_discard_info): Add .eh_frame padding here
in a reverse pass over sections.
ld/
PR 21441
* testsuite/ld-x86-64/pr21038a.d: Adjust.
* testsuite/ld-x86-64/pr21038a-now.d: Adjust.
OUTPUT_FORMAT in linker script of PR ld/21884 tests is needed to trigger
PR ld/21884. Restore linker scripts and add nacl versions of the same
tests.
* testsuite/ld-i386/i386.exp: Run pr21884-nacl.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr21884.d: Don't run on nacl targets.
* testsuite/ld-x86-64/pr21884.d: Likewise.
* testsuite/ld-i386/pr21884.t: Revert the last change.
* testsuite/ld-x86-64/pr21884.t: Likewise.
* testsuite/ld-i386/pr21884-nacl.d: New file.
* testsuite/ld-i386/pr21884-nacl.t: Likewise.
* testsuite/ld-x86-64/pr21884-nacl.d: Likewise.
* testsuite/ld-x86-64/pr21884-nacl.t: Likewise.
OUTPUT_FORMAT in the script results in "./ld-new: target elf32-i386
not found" and similarly for the x86_64 test.
* testsuite/ld-i386/pr21884.t: Remove unneeded format, arch and entry.
* testsuite/ld-x86-64/pr21884.t: Likewise.
The documentation was erroneously saying that there is a command named
"show set startup-with-shell", while the correct version is "show
startup-with-shell". This commit fixes obvious mistake.
gdb/doc/ChangeLog:
2017-08-12 Sergio Durigan Junior <sergiodj@redhat.com>
PR gdb/21925
* gdb.texinfo (Starting) <startup-with-shell>: Fix typo ("show
set...").
The get_valueof procedure allows tests to conveniently make gdb evaluate
an expression an return the value as a string. However, it includes an
end-of-line character in its result. I stumbled on this when trying to
use that result as part of a regex further in a test.
You can see this for example by adding a puts in
gdb.dwarf2/implref-struct.exp:get_members:
set members [get_valueof "" ${var} ""]
puts "<$members>"
The output is
<{a = 0, b = 1, c = 2}
>
This is because the regex in get_valueof is too greedy, the captured
portion matches anything up to the gdb_prompt, including the end of line
characters. This patch changes it to capture everything but end of line
characters.
The output of the puts becomes:
<{a = 0, b = 1, c = 2}>
I tested this by running gdb.dwarf2/implref-array.exp and
gdb.dwarf2/implref-struct.exp, the two only current users of that
procedure.
gdb/testsuite/ChangeLog:
* lib/gdb.exp (get_valueof): Don't capture end-of-line
characters.
When synthesizing symbols for PLT entries, allocate space for symbol
names with @plt suffixes together with symbol table so that all memory
is returned when symbol table is freed.
PR binutils/21943
* elf32-i386.c (elf_i386_get_synthetic_symtab): Allocate space
for @plt suffixes first.
* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
* emultempl/elf32.em (handle_option): Accept the -z globalaudit
command line option.
* lexsup.c (elf_static_list_options): Add -z globalaudit.
* ld.texinfo: Document the support for the new command line
option.
* NEWS: Mention the new feature.
* testsuite/ld-elf/audit.exp: Add a test of the -z globalaudit
command line option.
* testsuite/ld-elf/globalaudit.rd: New file: Expected output from
readelf.
We can't create alias of common symbol. Local alias of common symbol has
been disallowed. But global alias of common symbol is disallowed when the
common symbol is seen first and silently dropped otherwise. This patch
disallows alias of common symbol in all cases.
gas/
PR gas/21667
* read.c (pseudo_set): Update error message for alias of common
symbol.
* write.c (write_object_file): Disallow both local and global
aliases of common symbol.
* testsuite/gas/elf/common5a.d: New file.
* testsuite/gas/elf/common5a.l: Likewise.
* testsuite/gas/elf/common5a.s: Likewise.
* testsuite/gas/elf/common5b.d: Likewise.
* testsuite/gas/elf/common5b.l: Likewise.
* testsuite/gas/elf/common5b.s: Likewise.
* testsuite/gas/elf/common5c.d: Likewise.
* testsuite/gas/elf/common5c.s: Likewise.
* testsuite/gas/elf/common5d.d: Likewise.
* testsuite/gas/elf/common5d.s: Likewise.
* testsuite/gas/elf/elf.exp: Run common5a, common5b, common5c
and common5d.
- Make skiplist_entry a class with private data members.
- Move all construction logic to the ctor.
- Make skip_file_p etc be methods of skiplist_entry.
- Use std::list for the skip entries chain. Make the list own its
elements.
- Get rid of the ALL_SKIPLIST_ENTRIES/ALL_SKIPLIST_ENTRIES_SAFE
macros, use range-for / iterators instead.
- function_name_is_marked_for_skip 'function_sal' argument must be
non-NULL, so make it a reference instead.
All skiplist_entry invariants are now controlled by skiplist_entry
methods/internals. Some gdb_asserts disappear for being redundant.
gdb/ChangeLog:
2017-08-11 Pedro Alves <palves@redhat.com>
* infrun.c (process_event_stop_test): Adjust
function_name_is_marked_for_skip call.
* skip.c: Include <list>.
(skiplist_entry): Make it a class with private fields, and
getters/setters.
(skiplist_entry_chain): Delete.
(skiplist_entries): New.
(skiplist_entry_count): Delete.
(highest_skiplist_entry_num): New.
(ALL_SKIPLIST_ENTRIES, ALL_SKIPLIST_ENTRIES_SAFE): Delete.
(add_skiplist_entry): Delete.
(skiplist_entry::skiplist_entry): New.
(skiplist_entry::add_entry): New.
(skip_file_command, skip_function): Adjust.
(compile_skip_regexp): Delete.
(skip_command): Don't compile regexp here. Adjust to use
skiplist_entry::add_entry.
(skip_info): Adjust to use range-for and getters.
(skip_enable_command, skip_disable_command): Adjust to use
range-for and setters.
(skip_delete_command): Adjust to use std::list.
(add_skiplist_entry): Delete.
(skip_file_p): Delete, refactored as ...
(skiplist_entry::do_skip_file_p): ... this new method.
(skip_gfile_p): Delete, refactored as ...
(skiplist_entry::do_gskip_file_p): ... this new method.
(skip_function_p, skip_rfunction_p): Delete, refactored as ...
(skiplist_entry::skip_function_p): ... this new method.
(function_name_is_marked_for_skip): Now returns bool, and takes
the function sal by const reference. Adjust to use range-for and
skiplist_entry methods.
(_initialize_step_skip): Remove references to
skiplist_entry_chain, skiplist_entry_count.
* skip.h (function_name_is_marked_for_skip): Now returns bool, and
takes the function sal by const reference.
It is required that unwinder->sniffer should set *this_cache to NULL if
the unwinder is not applicable or exception is thrown, so
78ac5f8316 adds clear_pointer_cleanup to set
*this_cache to NULL in case of exception in order to fix PR 14100.
https://sourceware.org/ml/gdb-patches/2012-08/msg00075.html
This patch removes that clear_pointer_cleanup, and catch all exception in
the caller of unwinder->sniffer. In case of exception, reset *this_case.
gdb:
2017-08-11 Yao Qi <yao.qi@linaro.org>
* dwarf2-frame.c (clear_pointer_cleanup): Remove.
(dwarf2_frame_cache): Remove reset_cache_cleanup.
(dwarf2_frame_cache):
* frame-unwind.c (frame_unwind_try_unwinder): Catch
RETURN_MASK_ALL and set *this_case to NULL.
* frame-unwind.h: Update comments.
This patch adds ctor and dtor to dwarf2_frame_state, so that we can
remove one cleanup "old_chain".
gdb:
2017-08-11 Yao Qi <yao.qi@linaro.org>
* dwarf2-frame.c (dwarf2_frame_state_free): Remove.
(dwarf2_frame_state::dwarf2_frame_state): New.
(dwarf2_frame_state::~dwarf2_frame_state): New.
(dwarf2_fetch_cfa_info): Update.
(dwarf2_frame_cache): Remove old_chain. Change 'fs' to an object
rather than a pointer. Update code.
* dwarf2-frame.h (struct dwarf2_frame_state): Declare ctor and
dtor.
<data_align, code_align, retaddr_column>: Change them to const.
<armcc_cfa_offsets_sf, armcc_cfa_offsets_reversed>: Change them
to bool.
dwarf2_frame_state_reg.exp_len is only used together with .loc.exp, so
it makes more sense to exp_len to the union as well.
gdb:
2017-08-11 Yao Qi <yao.qi@linaro.org>
* dwarf2-frame.h (struct dwarf2_frame_state_reg) <exp_len>: Remove.
<loc.exp>: New field.
* dwarf2-frame.c (execute_cfa_program): Update.
(dwarf2_frame_prev_register): Update.
Currently, if you try to use the array version of
gdb::unique_xmalloc_ptr (i.e., std::unique_ptr) in order to have
access to operator[], like:
gdb::unique_xmalloc_ptr<char[]> buf ((char *) xmalloc (10));
return buf[0];
then the build fails, like:
/usr/include/c++/5.3.1/bits/unique_ptr.h: In instantiation of ‘std::unique_ptr<_Tp [], _Dp>::~unique_ptr() [with _Tp = char; _Dp = gdb::xfree_deleter<char []>]’:
main.c:30:61: required from here
/usr/include/c++/5.3.1/bits/unique_ptr.h:484:17: error: no match for call to ‘(std::unique_ptr<char [], gdb::xfree_deleter<char []> >::deleter_type {aka gdb::xfree_deleter<char []>}) (char*&)’
get_deleter()(__ptr);
^
In file included from src/gdb/common/common-defs.h:92:0,
from src/gdb/defs.h:28,
from src/gdb/main.c:20:
src/gdb/common/gdb_unique_ptr.h:34:8: note: candidate: void gdb::xfree_deleter<T>::operator()(T*) const [with T = char []]
void operator() (T *ptr) const { xfree (ptr); }
^
src/gdb/common/gdb_unique_ptr.h:34:8: note: no known conversion for argument 1 from ‘char*’ to ‘char (*)[]’
Makefile:1911: recipe for target 'main.o' failed
make: *** [main.o] Error 1
The problem is that we're missing an xfree_deleter specialization for
arrays.
gdb/ChangeLog:
2017-08-10 Pedro Alves <palves@redhat.com>
* common/gdb_unique_ptr.h (xfree_deleter<T[]>): Define.
* scripttempl/pep.sc: Enclose __CTOR_LIST__, ___CTOR_LIST__,
__DTOR_LIST__ and ___DTOR_LIST__ in PROVIDE statements so that
they can be overrridden by crt input files.
* scripttempl/pe.sc: Likewise.
PR gas/21939
* config/obj-macho.c (obj_mach_o_set_indirect_symbols): Increase
size of indirect_syms array so that it is large enough to hold
every symbol if necessary.
When --enable-shared is used, ./ld-new may be a shell script and the
real linker is .libs/ld-new. We should check .libs/ld-new first.
* testsuite/config/default.exp (LD_CLASS): Check .libs/ld-new
for linker first.
FreeBSD's native target uses linked-lists to keep track of pending fork
events and fake vfork done events. Replace the first list with std::list
and the second with std::forward_list.
gdb/ChangeLog:
* fbsd-nat.c (struct fbsd_fork_info): Remove.
(fbsd_pending_children): Use std::list.
(fbsd_remember_child): Likewise.
(fbsd_is_child_pending): Likewise.
(fbsd_pending_vfork_done): Use std::forward_list.
(fbsd_add_vfork_done): Likewise.
(fbsd_is_vfork_done_pending): Likewise.
(fbsd_next_vfork_done): Likewise.
- Use a custom deleter with std::unique_ptr to free() memory returned
by kinfo_getvmmap().
- Use std::string with string_printf() to generate the pathname of the
procfs 'map' file.
- Use gdb::byte_vector to manage the dynamic buffer for
TARGET_OBJECT_AUXV and the dynamically allocated array of LWP IDs.
gdb/ChangeLog:
* fbsd-nat.c [HAVE_KINFO_GETVMMAP] (struct free_deleter): New.
(fbsd_find_memory_regions): Use free_deleter with std::unique_ptr.
[!HAVE_KINFO_GETVMMAP] (fbsd_find_memory_regions): Use std::string
for `mapfilename'.
(fbsd_xfer_partial): Use gdb::byte_vector.
(fbsd_add_threads): Likewise.
PR ld/17618 test requires 64-bit linker to run. Set LD_CLASS to "64bit"
for 64-bit ELF linker and run PR ld/17618 test only if $LD_CLASS is
"64bit". More checks can be added to support 64-bit linkers in non-ELF
format.
* testsuite/config/default.exp (LD_CLASS): New. Set to "64bit"
for 64-bit ELF linker.
* testsuite/ld-x86-64/pr17618.d (#notarget): Removed.
* testsuite/ld-x86-64/x86-64.exp: Run pr17618 only for 64-bit
linker.
The documentation for the cmd_list field of the Z0 packet refers to its
content as a conditional expression, which seems like a copy-paste error
from the cond_list field.
gdb/doc/ChangeLog:
* gdb.texinfo (Packets): Fix Z0 cmd_list doc referring to
conditional expression.
I happened to notice that skiplist_entry, in skip.c, contains a
gdb::optional<compiled_regex> -- but that this object's destructor is
never run. This can result in a memory leak.
This patch fixes the bug by applying a bit more C++: changing this
code to use new and delete, and std::unique_ptr; and removing cleanups
in the process.
Built and regression tested on x86-64 Fedora 25.
ChangeLog
2017-08-09 Tom Tromey <tom@tromey.com>
* skip.c (skiplist_entry): New constructor.
(skiplist_entry::enabled, skiplist_entry::function_is_regexp)
(skiplist_entry::file_is_glob): Now bool.
(skiplist_entry::file, skiplist_entry::function): Now
std::string.
(make_skip_entry): Return a unique_ptr. Use new.
(free_skiplist_entry, free_skiplist_entry_cleanup)
(make_free_skiplist_entry_cleanup): Remove.
(skip_command, skip_disable_command, add_skiplist_entry)
(skip_form_bytes, compile_skip_regexp, skip_command, skip_info)
(skip_file_p, skip_gfile_p, skip_function_p, skip_rfunction_p)
(function_name_is_marked_for_skip): Update.
(skip_delete_command): Update. Use delete.
According to ARMv8-A architecture manual, REG_SP is allowed in CRC32
instructions in Thumb mode. It is REG_PC that will cause unpredictable
behaviours on both ARM and Thumb.
This patch removes the incorrect warning on Thumb mode.
Meanwhile the disassembler is updated to use format "<bitfield>R" instead of
"<bitfield>S". "<bitfield>S" is not used elsewhere. so I have deleted related
code from the disassembler.
gas/
* config/tc-arm.c (do_crc32_1): Remove warning on REG_SP for thumb_mode.
* testsuite/gas/arm/crc32-armv8-a-bad.d: Update exepcted result.
* testsuite/gas/arm/crc32-armv8-r-bad.d: Likewise.
* testsuite/gas/arm/crc32-armv8-a.d: Likewise.
* testsuite/gas/arm/crc32-armv8-r.d: Likewise.
* testsuite/gas/arm/crc32-armv8-ar-bad.s: Update test case.
* testsuite/gas/arm/crc32-armv8-ar.s: Likewise.
* testsuite/gas/arm/crc32-bad.l: Update expected error message.
opcode/
* arm-dis.c (thumb32_opcodes): Use format 'R' instead of 'S' for
register operands in CRC instructions.
(print_insn_thumb32): Remove "<bitfield>S" support. Updated the
comments.
Recommit with missing header files added.
gdb/
* aarch64-linux-tdep.c: Include "auxv.h" and "elf/common.h".
(aarch64_linux_core_read_description): New function.
(aarch64_linux_init_abi): Register gdbarch_core_read_description.
Currently, AArch64 only have one target description which is tdesc_aarch64. So,
we haven't implemented any target description detection mechanism for core file.
This patch is an initial implementation of core_read_description method. Future
features can use this to return selected description.
gdb/
* aarch64-linux-tdep.c (aarch64_linux_core_read_description): New
function.
(aarch64_linux_init_abi): Register gdbarch_core_read_description.
To help avoid issues like the one fixed by e88e8651cf ("Fix memory
leak in cp-support.c").
gdb/ChangeLog:
2017-08-09 Pedro Alves <palves@redhat.com>
* cp-name-parser.y (cp_comp_to_string): Return a
gdb::unique_xmalloc_ptr<char>.
* cp-support.c (replace_typedefs_qualified_name)
(replace_typedefs): Adjust to use gdb::unique_xmalloc_ptr<char>.
(cp_canonicalize_string_full): Use op= instead of explicit
convertion.
(cp_class_name_from_physname, method_name_from_physname)
(cp_func_name, cp_remove_params): Adjust to use
gdb::unique_xmalloc_ptr<char>.
* cp-support.h (cp_comp_to_string): Return a
gdb::unique_xmalloc_ptr<char>.
* python/py-type.c (typy_lookup_type): Adjust to use
gdb::unique_xmalloc_ptr<char>.
The return value of cp_comp_to_string was never freed, creating a
sizable memory leak detectable with valgrind.
==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M
==21225== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21225== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21225== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21225== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21225== by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M
==21225== by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M
==21225== by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M
==21225== by 0x5D6CF6: linespec_parse_basic (linespec.c:1907)
==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M
==21279== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21279== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21279== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21279== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21279== by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M
==21279== by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159)
This patch fixes the leak. It is a regression by 2f408ecb.
gdb:
2017-08-09 Alex Lindsay <alexlindsay239@gmail.com>
Yao Qi <yao.qi@linaro.org>
* cp-support.c (cp_canonicalize_string_full): Use
gdb::unique_xmalloc_ptr<char>.
(cp_canonicalize_string): Likewise.
Require GCC 5 or above for 3 x86 tests which fail with GCC 4.9.3.
PR ld/21924
* testsuite/ld-i386/i386.exp: Require GCC 5 or above for
"weakundef1 with PIE" test.
* testsuite/ld-x86-64/tls.exp: Require GCC 5 or above for
"tlsdesc1" and "tlsdesc1 with PIE" tests.
"--rpath ../bfd/.libs ../bfd/.libs/libbfd.so" isn't a valid compiler
command-line option. We should use -Wl,--rpath instead of --rpath.
PR ld/21923
* configure.ac (TESTBFDLIB): Replace --rpath with -Wl,--rpath
for --disable-static.
* configure: Regenerated.
PR 21916
* elf-attrs.c (_bfd_elf_parse_attributes): Complain about very
small section lengths.
* elf.c (_bfd_elf_setup_sections): Skip empty entries in the group
table.
(elfcore_grok_freebsd_prstatus): Add checks to make sure that
there is enough data present in the note.