Commit Graph

92346 Commits

Author SHA1 Message Date
Thomas Preud'homme 852735806a [ARM] Help wince objdump on coproc tests
Object files other than ELF do not have mapping symbols to indicate the
type of data for objdump to work reliably. This is why the following
tests FAIL on arm-wince-pe targets:
ARMv6T2 Thumb CoProcessor Instructions (1)
ARMv6T2 Thumb CoProcessor Instructions (2)

This patch adds the force-thumb disassembler option to objdump for this
test to PASS on these targets as well.

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

gas/
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v6t2-1.d: Add
	--disassembler-options=force-thumb to objdump options.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v6t2-2.d: Likewise.
2017-11-02 14:16:22 +00:00
James Bowman dcc31d286a FT32: support for FT32B processor - part 2/2
FT32B is a new FT32 family member.
This patch adds support for the compressed instructions to gdb and sim.

gdb/ChangeLog:
        * ft32-tdep.c (ft32_fetch_instruction): New function.
        (ft32_analyze_prologue): Use ft32_fetch_instruction().

sim/ChangeLog:
        * ft32/interp.c (step_once): Add ft32 shortcode decoder.
2017-11-01 18:36:51 -07:00
GDB Administrator 89f3c4b6b9 Automatic date update in version.in 2017-11-02 00:00:15 +00:00
James Bowman 81b42bcab1 FT32B is a new FT32 family member. It has a code compression scheme, which requires the use of linker relaxations. The change is quite large, so submission is in several parts.
Part 2 adds a relaxation pass, which actually implements the code compression scheme.

bfd	* archures.c: Add bfd_mach_ft32b.
	* cpu-ft32.c: Add arch_info_struct.
	* elf32-ft32.c: Add R_FT32_RELAX, SC0, SC1,
	DIFF32. (ft32_elf_relocate_section): Add clauses
	for R_FT32_SC0, SC1, DIFF32.  (ft32_reloc_shortable,
	elf32_ft32_is_diff_reloc, elf32_ft32_adjust_diff_reloc_value,
	elf32_ft32_adjust_reloc_if_spans_insn,
	elf32_ft32_relax_delete_bytes, elf32_ft32_relax_is_branch_target,
	ft32_elf_relax_section): New function.
	* reloc.c: Add BFD_RELOC_FT32_RELAX, SC0, SC1, DIFF32.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

gas	* config/tc-ft32.c (md_assemble): add relaxation reloc
	BFD_RELOC_FT32_RELAX.  (md_longopts): Add "norelax" and
	"no-relax". (md_apply_fix): Add reloc BFD_RELOC_FT32_DIFF32.
	(relaxable_section, ft32_validate_fix_sub, ft32_force_relocation,
	ft32_allow_local_subtract): New function.
	* config/tc-ft32.h: remove unused MD_PCREL_FROM_SECTION.
	* testsuite/gas/ft32/insnsc.s: New test exercising all FT32B
	shortcodes.

include	* elf/ft32.h: Add R_FT32_RELAX, SC0, SC1, DIFF32.
2017-11-01 15:33:24 +00:00
Nick Clifton a67d66eb97 Prevent illegal memory accesses when attempting to read excessively large COFF line number tables.
PR 22376
	* coffcode.h (coff_slurp_line_table): Check for an excessively
	large line number count.
2017-11-01 15:21:46 +00:00
Nick Clifton e0115a8446 Update check for invalid values in pe_bfd_read_buildid function.
PR 22373
	* peicode.h (pe_bfd_read_buildid): Revise check for invalid size
	and offset in light of further possible bogus values.
2017-11-01 12:37:33 +00:00
Nick Clifton ee357486aa Fix an invalid free called when attempting to link a COFF object against an ELF archive with --no-keep-memory enabled.
PR 22369
	* coffgen.c (_bfd_coff_free_symbols): Fail if called on a non-COFF
	file.
	* cofflink.c (coff_link_check_archive_element): Skip non-COFF
	members of an archive.
2017-11-01 11:35:42 +00:00
Thomas Preud'homme 4070243b5c [ARM] Fix Coprocessor instructions availability
A few coprocessor instructions introduced in ARMv2 are currently
accepted by GAS when targeting ARMv1 due to a typo in the code. This
patch fixes the issue and introduce a more fine grained testing for
coprocessor instructions availability. Coprocessor instructions are
grouped as follows:

* ARM coprocessor instructions introduced in ARMv2
  Includes: ldc, stc, mcr, mrc, cdp, ldcl, stcl
  Guarded by: ARM_EXT_V2
  Tests: copro-arm_v2plus-arm_v*.d

* ARM coprocessor instructions introduced in ARMv5
  Includes: ldc2, ldc2l, stc2, stc2l, cdp2, mcr2, mrc2
  Guarded by: ARM_EXT_V5
  Tests: copro-arm_v5plus-arm_v*.d

* ARM coprocessor instructions introduced in ARMv5TE
  Includes: mcrr, mrrc
  Guarded by: ARM_EXT_V5E
  Tests: copro-arm_v5teplus-arm_v*.d

* ARM coprocessor instructions introduced in ARMv6
  Includes: mcrr2, mrrc2
  Guarded by: ARM_EXT_V6
  Tests: copro-arm_v6plus-arm_v*.d

* Thumb coprocessor instructions introduced in ARMv6T2
  Includes: ldc, ldcl, stc, stcl, mcr, mrc, mcrr, mrrc, cdp, ldc2,
  ldc2l, stc2, stc2l, cdp2, mcr2, mrc2, mcrr2, mrrc2
  Guarded by: ARM_EXT_V6T2
  Tests: copro-thumb_v6t2plus-thumb_v*.d

For each of these groups, at least 2 tests are performed:
* instructions are not available in earlier architecture
* instructions are available in architecture where they were introduced
More tests need to be performed when instructions in a group span
several assembly files.

Note that an instruction in the original coprocessor testcase is
changed to unified syntax to allow the testcase to be assembled for ARM
and Thumb state. Correct processing of legacy syntax is covered in other
testcases.

2017-11-01  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gas/
	* config/tc-arm.c (arm_ext_v2): Define to ARM_EXT_V2 feature bit.
	* testsuite/gas/arm/copro.s: Split into ...
	* testsuite/gas/arm/copro-arm_v2plus-thumb_v6t2plus.s: This while
	changing it to unified syntax and ...
	* testsuite/gas/arm/copro-arm_v5plus-thumb_v6t2plus.s: this and ...
	* testsuite/gas/arm/copro-arm_v5teplus-thumb_v6t2plus.s: This and ...
	* testsuite/gas/arm/copro-arm_v6plus-thumb_v6t2plus.s: This.
	* testsuite/gas/arm/copro.d: Split into ...
	* testsuite/gas/arm/copro-arm_v2plus-arm_v2.d: This but target ARMv2
	and ...
	* testsuite/gas/arm/copro-arm_v5plus-arm_v5.d: this but target ARMv5
	and ...
	* testsuite/gas/arm/copro-arm_v5teplus-arm_v5te.d: This but target
	ARMv5TE and ...
	* testsuite/gas/arm/copro-arm_v6plus-arm_v6.d: This but target ARMv6.
	* testsuite/gas/arm/copro-arm_v2plus-arm_v1.d: New testcase.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v4t-1.d: New testcase.
	* testsuite/gas/arm/copro-arm_v2plus-thumb_v6t2plus-unavail.l: Expected
	errors for the above two testcases.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v6t2-1.d: New testcase.
	* testsuite/gas/arm/copro-arm_v5plus-arm_v4.d: New testcase.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v4t-2.d: New testcase.
	* testsuite/gas/arm/copro-arm_v5plus-thumb_v6t2plus-unavail.l:
	Expected errors for the above two testcases.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v6t2-2.d: New testcase.
	* testsuite/gas/arm/copro-arm_v5teplus-arm_v5.d: New testcase.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v4t-3.d: New testcase.
	* testsuite/gas/arm/copro-arm_v5teplus-thumb_v6t2plus-unavail.l:
	Expected errors for the above two testcases.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v6t2-3.d: New testcase.
	* testsuite/gas/arm/copro-arm_v6plus-arm_v5te.d: New testcase.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v4t-4.d: New testcase.
	* testsuite/gas/arm/copro-arm_v6plus-thumb_v6t2plus-unavail.l:
	Expected errors for the above two testcases.
	* testsuite/gas/arm/copro-thumb_v6t2plus-thumb_v6t2-4.d: New testcase.
2017-11-01 09:49:13 +00:00
Alan Modra 3988aed54a PR22374, PowerPC unnecessary PLT entries
We don't need a PLT entry when function pointer initialization in a
read/write section is the only reference to a given function symbol.
This patch prevents the unnecessary PLT entry, and ensures no dynamic
relocs are emitted when UNDEFWEAK_NO_DYNAMIC_RELOC says so.

bfd/
	PR 22374
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Don't create a plt
	entry when just a dynamic reloc can serve.  Ensure no dynamic
	relocations when UNDEFWEAK_NO_DYNAMIC_RELOC by setting non_got_ref.
	Expand and move the non_got_ref comment.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
ld/
	* testsuite/ld-powerpc/ambiguousv2.d: Remove FIXME.
2017-11-01 18:46:34 +10:30
Alan Modra e48f0c8f1b PR22374 testcase, function pointer references in .data
Function pointer references in .data ought to use a dynamic reloc.
There shouldn't be any need for a PLT entry and definitely no copy
reloc.

This test fails on quite a few targets, but isn't something that
anyone should worry about too much.  It's really just a missed
optimization.

	PR 22374
	* testsuite/ld-elf/pr22374a.s,
	* testsuite/ld-elf/pr22374b.s,
	* testsuite/ld-elf/pr22374-1.r,
	* testsuite/ld-elf/pr22374-2.r: New test.
	* testsuite/ld-elf/elf.exp: Run it.
2017-11-01 18:45:34 +10:30
Alan Modra 46b06a98d1 Tidy elf.exp
* testsuite/ld-elf/elf.exp: Merge some conditionals, a better
	name than "shared library for next test", and use xfail arg
	of run_ld_link_tests in a few places.
2017-11-01 15:14:44 +10:30
Simon Marchi 3a87ae656c Use console uiout when executing breakpoint commands
As reported here

  https://sourceware.org/ml/gdb/2017-10/msg00020.html

the output of certain commands, like backtrace, doesn't appear anywhere
when it is run as a breakpoint command and when using MI.

The reason is that the current_uiout is set to the mi_ui_out while these
commands run, whereas we want the output as CLI output.  Some commands
like "print" work, because they use printf_filtered (gdb_stdout, ...)
directly, bypassing the current ui_out.

The fix I did is to force setting the cli_uiout as the current_uiout
when calling execute_control_command.  I am not sure if this is the
right way to fix the problem, comments about the approach would be
appreciated.

I enhanced gdb.mi/mi-break.exp to test the backtrace command.

Regtested on the buildbot.

gdb/ChangeLog:

	* cli/cli-script.c (execute_control_command): Rename to ...
	(execute_control_command_1): ... this.
	(execute_control_command): New function.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-break.exp (test_breakpoint_commands): Test backtrace
	as a breakpoint command.
2017-10-31 21:34:24 -04:00
GDB Administrator 4d01dee480 Automatic date update in version.in 2017-11-01 00:00:19 +00:00
Simon Marchi 09b847f3a8 tracepoint: Remove unnecessary const_cast
We are passing a const char * to a const char * parameter, the
const_cast is not necessary.

gdb/ChangeLog:

	* tracepoint.c (tfind_command): Remove const_cast.
2017-10-31 14:29:25 -04:00
Nick Clifton 0bb6961f18 Fix illegal memory access triggered when parsing a PE binary with a corrupt data dictionary.
PR 22373
	* peicode.h (pe_bfd_read_buildid): Check for invalid size and data
	offset values.
2017-10-31 14:29:40 +00:00
Nick Clifton 45ac8f4f10 Remind users to use the --use-dynamic command line option to dump dynamic relocations.
* readelf.c (process_relocs): Tell users if no static relocs were
	found, but if they had added --use-dynamic to the command line
	then relocs would have been displayed.
2017-10-31 13:48:03 +00:00
Mike Gulick f871c4853a gdb/Makefile.in: fix 'make tags' failure
'make tags' fails with the following error:

  make[2]: Entering directory '/local-ssd/mgulick/gdb/git/binutils-gdb/gdb'
  make[2]: *** No rule to make target 'gdb.h', needed by 'TAGS'.  Stop.
  make[2]: Leaving directory '/local-ssd/mgulick/gdb/git/binutils-gdb/gdb'

The file gdb/gdb.h was removed in commit
65630365f7.

gdb/ChangeLog:

2017-10-30  Mike Gulick  <mgulick@mathworks.com>

	* Makefile.in (HFILES_NO_SRCDIR): Remove reference to gdb.h.
2017-10-30 21:30:10 -04:00
GDB Administrator 916296ccea Automatic date update in version.in 2017-10-31 00:00:40 +00:00
Simon Marchi b020ff8074 Introduce in_inclusive_range, fix -Wtautological-compare warnings
When compiling with clang or gcc 8, we see warnings like this:

/home/emaisin/src/binutils-gdb/gdb/arm-tdep.c:10013:13: error: comparison of 0 <= unsigned expression is always true [-Werror,-Wtautological-compare]
      if (0 <= insn_op1 && 3 >= insn_op1)
          ~ ^  ~~~~~~~~
/home/emaisin/src/binutils-gdb/gdb/arm-tdep.c:11722:20: error: comparison of unsigned expression >= 0 is always true [-Werror,-Wtautological-compare]
      else if (opB >= 0 && opB <= 2)
               ~~~ ^  ~

This is because an unsigned integer (opB in this case) will always be >=
0.  It is still useful to keep both bounds of the range in the
expression, even if one is at the edge of the data type range.  This
patch introduces a utility function in_inclusive_range that gets rid of
the warning while conveying that we are checking for a range.

Tested by rebuilding.

gdb/ChangeLog:

	* common/common-utils.h (in_inclusive_range): New function.
	* arm-tdep.c (arm_record_extension_space): Use
	in_inclusive_range.
	(thumb_record_ld_st_reg_offset): Use in_inclusive_range.
	* cris-tdep.c (cris_spec_reg_applicable): Use
	in_inclusive_range.
2017-10-30 14:27:38 -04:00
Pedro Alves 1b81856f5b remote.c, QCatchSyscalls: Build std::string instead of unique_xmalloc_ptr
Simplify the code a little bit using std::string + string_appendf.

gdb/ChangeLog:
2017-10-30  Pedro Alves  <palves@redhat.com>
	    Simon Marchi <simon.marchi@ericsson.com>

	* remote.c (remote_set_syscall_catchpoint): Build a std::string
	instead of a gdb::unique_xmalloc_ptr, using string_appendf.
2017-10-30 11:41:34 +00:00
Pedro Alves 31b833b3ea Introduce string_appendf/string_vappendf
string_appendf is like string_printf, but instead of allocating a new
string, it appends to an existing string.  This allows reusing a
std::string's memory buffer across several calls, for example.

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

	* common/common-utils.c (string_appendf, string_vappendf): New
	functions.
	* common/common-utils.h (string_appendf, string_vappendf): New
	declarations.
	* unittests/common-utils-selftests.c (string_appendf_func)
	(test_appendf_func, string_vappendf_wrapper, string_appendf_tests)
	(string_vappendf_tests): New functions.
	(_initialize_common_utils_selftests): Register "string_appendf" and
	"string_vappendf tests".
2017-10-30 11:41:34 +00:00
Pedro Alves 4a25033455 Merge/shared string_printf and string_vprintf unit tests
Merge the string_printf and string_vprintf tests, running them all
against both functions.

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

	* unittests/common-utils-selftests.c (format_func): New typedef.
	(string_printf_tests, string_vprintf_tests): Tests factored out
	and merged to ...
	(test_format_func): ... this new function.
	(string_printf_tests, string_vprintf_tests): Reimplement on top of
	test_format_func.
2017-10-30 11:41:34 +00:00
Simon Marchi 16c5c17e43 darwin-nat: Remove gdb.h include
gdb.h has been removed in

  Eliminate catch_exceptions/catch_exceptions_with_msg
  65630365f7

Remove the include in darwin-nat.c.  Tested by rebuilding.

gdb/ChangeLog:

	* darwin-nat.c: Remove include of gdb.h.
2017-10-29 22:40:01 -04:00
Alan Modra 7f9cb5d275 frv-elf --gc-sections failures
git commit 81742b83e9 exposed an frv-elf bug, with the object id not
matching the hash table id.

	* elf32-frv.c (ELF_TARGET_ID): Don't define for generic
	elf target.
2017-10-30 12:08:26 +10:30
Alan Modra 81742b83e9 relocs_compatible test for gc-sections
I noticed when looking at pr22300 that before calling check_relocs we
have an elf_object_id test (added for pr11933) as well as the
relocs_compatible test.  I believe backend gc_mark_hook and
gc_sweep_hook ought to be protected similarly from being confused by
unexpected relocations (for example, both elf64-ppc.c and elf32-ppc.c
use _bfd_elf_relocs_compatible, so I think it would be possible for
the ppc64 gc_mark_hook to be presented with a ppc32 relocatable
object).

	* elflink.c (elf_gc_sweep): Test elf_object_id in addition to
	relocs_compatible.
	(bfd_elf_gc_sections): Likewise.
2017-10-30 11:03:50 +10:30
Alan Modra d336fa6d82 Fix hppa-linux pr22269-1 fail
Adds UNDEFWEAK_NO_DYNAMIC_RELOC in the rest of places needed in this
file, reduces dynamic relocations in a number of cases, and removes
some bogus code that was attempting to handle dynamic common symbols
specially.

	PR 22269
	* elf32-hppa.c (elf32_hppa_check_relocs): Move SEC_ALLOC test to
	ensure non_got_ref is not set due to debug references.
	(elf32_hppa_adjust_dynamic_symbol): Tidy plabel handling.  Use
	SYMBOL_CALLS_LOCAL and UNDEFWEAK_NO_DYNAMIC_RELOC when determining
	need for a plt entry.
	(allocate_dynrelocs): Similarly for got entries.  Tidy code discarding
	dynamic relocs when pic.  Remove bogus code attempting to handle
	commons.
	(elf32_hppa_relocate_section): Similarly.  Delete resolved_to_zero
	and simplify.
	(elf32_hppa_finish_dynamic_symbol): Use UNDEFWEAK_NO_DYNAMIC_RELOC
	and SYMBOL_REFERENCES_LOCAL in GOT handling.
2017-10-30 11:03:50 +10:30
GDB Administrator 2b2d167607 Automatic date update in version.in 2017-10-30 00:00:32 +00:00
Simon Marchi 7ca51576b9 xtensa-xtregs: Fix formatting issues
Fix a few formatting issues in that file.

gdb/ChangeLog:

	* xtensa-xtregs.c: Fix formatting issues.
2017-10-29 13:02:29 -04:00
Simon Marchi c1342859dc xtensa-xtregs: Constify field
Fix:

In file included from /home/emaisin/src/binutils-gdb/gdb/xtensa-linux-nat.c:46:0:
/home/emaisin/src/binutils-gdb/gdb/xtensa-xtregs.c:37:1: error: ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings]
 };
 ^

gdb/ChangeLog:

	* xtensa-xtregs.c (xtensa_regtable_t) <name>: Constify.
2017-10-29 01:13:33 -04:00
GDB Administrator 692af22719 Automatic date update in version.in 2017-10-29 00:00:25 +00:00
Maksim Dzabraev 484d8d361d Make gdb.selected_thread().inferior return a new reference
thpy_get_inferior function should return a new reference to the
existing inferior object, and therefore should increment its refcount.

Fixed bug looks like this.
If multiple time call gdb.selected_thread ().inferior, gdb throws exception:

(gdb) pi gdb.selected_thread().inferior
<gdb.Inferior object at 0x7f1952bea698>
(gdb) pi gdb.selected_thread().inferior
Python Exception <type 'exceptions.AttributeError'> 'NoneType' object
has no attribute 'inferior':
Error while executing Python code.
(gdb) info threads
  Id   Target Id         Frame
* 1    Thread 0x7f54f0474740 (LWP 584) "mc" 0x00007f54ef055c33 in
2017-10-28 14:19:08 -04:00
Alan Modra d91f0b20e5 PR22361 readelf buffer overflow on fuzzed archive header
PR 22361
	* readelf.c (process_archive_index_and_symbols): Ensure ar_size
	field is zero terminated for strtoul.
	(setup_archive, get_archive_member_name): Likewise.
2017-10-28 22:12:46 +10:30
Alan Modra c0e331c794 PR22300, Abort in elf32_hppa_relocate_section building polyml
polyml produces object files with the wrong OS/ABI for hppa-linux.
This, along with the fact that elf32-hppa.c is using the strictest
backend relocs_compatible, results in wrong merging of ELF symbols.

So, remove the relocs_compatible check in _bfd_elf_merge_symbol.
_bfd_elf_merge_symbol is only called nowadays from within blocks
protected by is_elf_hash_table, so "we are doing an ELF link" as the
removed comment says, is true.

Also relax relocs_compatible for hppa and powerpc.  relocs_compatible
is used for more than just merging symbols, as the name suggests.
This allows objects that are in fact reasonably compatible to be
linked.

	PR 22300
	* elflink.c (_bfd_elf_merge_symbol): Remove relocs_compatible check.
	* elf32-hppa.c (elf_backend_relocs_compatible): Define.
	* elf32-ppc.c (elf_backend_relocs_compatible): Define.
	* elf64-ppc.c (elf_backend_relocs_compatible): Define.
2017-10-28 22:11:40 +10:30
Simon Marchi bac608e7e1 Remove find_inferior usage for thread_search
Replace it with for_each_thread.  While at it, we can inline the
callback code.  One little change is that I am using the
prev_general_thread variable instead of current_gen_ptid, since they
should have the same value.

gdb/gdbserver/ChangeLog:

	* target.c (struct thread_search): Remove.
	(thread_search_callback): Remove.
	(prepare_to_access_memory): Use for_each_thread instead of
	find_inferior.  Inline code from thread_search_callback.
2017-10-27 23:44:12 -04:00
Simon Marchi eaddb42592 Remove usage of find_inferior in resume
Change find_inferior with find_thread.  Since we can now pass arguments
directly instead of through a void pointer, we don't need the
visit_actioned_threads_data structure anymore.

gdb/gdbserver/ChangeLog:

	* server.c (struct visit_actioned_threads_data): Remove.
	(visit_actioned_threads): Change prototype to take arguments
	directly.
	(resume): Use find_thread instead of find_inferior.
2017-10-27 23:43:11 -04:00
Simon Marchi 99078d344d Remove usages of find_inferior in handle_status
Replace one with find_thread, the other with for_each_thread.

gdb/gdbserver/ChangeLog:

	* server.c (queue_stop_reply_callback): Change prototype, return
	void.
	(find_status_pending_thread_callback): Remove.
	(handle_status): Replace find_inferior with find_thread and
	for_each_thread.
2017-10-27 23:41:49 -04:00
Simon Marchi b5540b5f2b common-utils-selftests.c: Add ATTRIBUTE_PRINTF
Fix this, when building with clang:

/home/emaisin/src/binutils-gdb/gdb/unittests/common-utils-selftests.c:50:40: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
  std::string result = string_vprintf (fmt, vp);
                                       ^~~
gdb/ChangeLog:

	* unittests/common-utils-selftests.c (format): Add
	ATTRIBUTE_PRINTF.
2017-10-27 23:36:45 -04:00
Simon Marchi 5a9dcda14c C++ify xml-syscall.c
This patch C++ifies the structures in xml-syscall.c, by using
std::vector instead of VEC, and std::string instead of char*.
Using a unique_ptr in syscall_parse_xml allows to remove a cleanup.

Something that seems strange with the existing code, if you look at
syscalls_info_free_syscalls_desc and
syscalls_info_free_syscall_group_desc, they free the structure elements
(the strings and vectors), but they don't free the syscall_desc and
syscall_group_desc structure themselves.  I don't see anything freeing
those currently.  Any idea why?  According to the comment above
syscalls_info_free_syscall_group_desc, it kinda looks like it's on
purpose.  With this patch, those structures are deleted when the vector
that contains them gets deleted.

The only time I'm aware a syscalls_info structure gets deleted is in the
case the data directory changes during runtime, in init_syscalls_info.
If tried that use case (including under valgrind):

 (gdb) catch syscall
 (gdb) set data-directory another-data-directory
 (gdb) catch syscall

I confirmed that the syscalls_info structure got deleted and recreated,
and everything seemed fine.

Regtested on the buildbot.

gdb/ChangeLog:

	* xml-syscall.c (struct syscall_desc): Add constructor.
	<name>: Change type to std::string.
	(syscall_desc_up): New typedef.
	(syscall_desc_p): Remove typeder.
	(DEF_VEC_P(syscall_desc_p)): Remove.
	(struct syscall_group_desc): Add constructor.
	<name>: Change type to std::string.
	<syscalls>: Change type to std::vector.
	(syscall_group_desc_up): New typedef.
	(syscall_group_desc_p): Remove typedef.
	(DEF_VEC_P(syscall_group_desc_p)): Remove.
	(struct syscalls_info) <syscalls>: Change type to std::vector of
	unique_ptr.
	<groups>: Likewise.
	<my_gdb_datadir>: Change type to std::string.
	(syscalls_info_up): New typedef.
	(allocate_syscalls_info): Remove.
	(syscalls_info_free_syscalls_desc): Remove.
	(syscalls_info_free_syscall_group_desc): Remove.
	(free_syscalls_info): Remove.
	(make_cleanup_free_syscalls_info): Remove.
	(syscall_group_create_syscall_group_desc): Adjust.
	(syscall_group_add_syscall): Adjust.
	(syscall_create_syscall_desc): Adjust.
	(syscall_parse_xml): Adjust, use unique_ptr instead of cleanup.
	(init_syscalls_info): Adjust.
	(syscall_group_get_group_by_name): Adjust.
	(xml_get_syscall_number): Adjust.
	(xml_get_syscall_name): Adjust.
	(xml_list_of_syscalls): Adjust.
	(xml_list_syscalls_by_group): Adjust.
	(xml_list_of_groups): Adjust.
2017-10-27 22:23:48 -04:00
Simon Marchi 45461e0dca Get rid of VEC(probe_p)
Replace the remaining usages of VEC(probe_p) with std::vector.

Regtested on the buildbot.

gdb/ChangeLog:

	* probe.h: Don't include gdb_vecs.h.
	(DEF_VEC_P (probe_p)): Remove.
	(find_probes_in_objfile): Return an std::vector.
	* probe.c (find_probes_in_objfile): Likewise.
	* breakpoint.c (breakpoint_objfile_data)
	<longjmp_probes>: Change type to std::vector.
	<exception_probes>: Likewise.
	(free_breakpoint_probes): Don't manually free vectors.
	(create_longjmp_master_breakpoint): Adjust.
	(create_exception_master_breakpoint): Adjust.
	* solib-svr4.c (svr4_create_probe_breakpoints): Change
	parameter type, adjust.
	(svr4_create_solib_event_breakpoints): Adjust.
2017-10-27 22:12:01 -04:00
Simon Marchi 43dce43945 Allocate breakpoint_objfile_data with new
Allocate with new and free with delete.  This allows using an
std::vector in the following patch.

I renamed free_breakpoint_probes to free_breakpoint_objfile_data,
because it now doesn't only free the probes vector, but also the
breakpoint_objfile_data structure itself.

gdb/ChangeLog:

	* breakpoint.c (breakpoint_objfile_data): Initialize fields.
	(get_breakpoint_objfile_data): Allocate breakpoint_objfile_data
	with new.
	(free_breakpoint_probes): Rename to ...
	(free_breakpoint_objfile_data): ... this, and call delete on
	bp_objfile_data..
2017-10-27 22:01:21 -04:00
Simon Marchi 6a1b9516d8 Get rid of VEC(loaded_script_ptr)
Direct replacement with std::vector.  This allows removing a cleanup as
well.

Regtested on the buildbot.

gdb/ChangeLog:

	* auto-load.c: Don't include gdb_vecs.h, include algorithm.
	(loaded_script_ptr): Remove typedef.
	(DEF_VEC_P (loaded_script_ptr)): Remove.
	(struct collect_matching_scripts_data): Add constructor.
	<scripts_p>: Change type to (pointer to) std::vector.
	(collect_matching_scripts_data): Adjust.
	(sort_scripts_by_name): Make suitable for std::sort.
	(print_scripts): Don't sort vector, adjust to std::vector.
	(auto_load_info_scripts): Sort vectors, adjust to std::vector.
2017-10-27 21:55:43 -04:00
Simon Marchi 593e3209f3 Get rid of VEC(filename_language)
This patch removes VEC(filename_language), replacing its usage with
std::vector.  filename_language::ext is changed to an std::string at the
same time.

Regtested on the buildbot.

gdb/ChangeLog:

	* symfile.c (filename_language): Make struct, not typedef.  Add
	constructor.
	<ext>: Change type to std::string.
	(DEF_VEC_O (filename_language)): Remove.
	(filename_language_table): Change type to std::vector.
	(add_filename_language): Adjust.
	(set_ext_lang_command): Adjust.
	(info_ext_lang_command): Adjust.
	(deduce_language_from_filename): Adjust.
	(class scoped_restore_filename_language_table): Remove.
	(test_filename_language): Use scoped_restore.
	(test_set_ext_lang_command): Use scoped_restore, adjust to
	std::vector change.
2017-10-27 21:47:30 -04:00
Simon Marchi 32fa66eb88 Add tests for filename_language
The next patch touches the filename_language area, but I noticed there
is no test exercising that.  This patch adds some selftests for
add_filename_language, deduce_language_from_filename and
set_ext_lang_command.  Because these tests add entries to the global
filename_language_table vector, it is not possible to run them
successfully multiple times in a same GDB instance.  They can
potentially interfere with each other for the same reason.  I therefore
added the scoped_restore_filename_language_table class that is used to
make sure tests leave that global vector in the same state they found it
(it is replaced in the following patch by a simple scoped_restore).

gdb/ChangeLog:

	* symfile.c: Include selftest.h.
	(class scoped_restore_filename_language_table): New.
	(test_filename_language): New test.
	(test_set_ext_lang_command): New test.
	(_initialize_symfile): Register tests.
2017-10-27 21:46:49 -04:00
GDB Administrator af5f32f82b Automatic date update in version.in 2017-10-28 00:00:30 +00:00
Keith Seitz 4a27f119f5 Use SaL symbol name when reporting breakpoint locations
Currently, "info break" can show some (perhaps) unexpected results when
setting a breakpoint on an inlined function:

(gdb) list
1	#include <stdio.h>
2
3	static inline void foo()
4	{
5	        printf("Hello world\n");
6	}
7
8	int main()
9	{
10	        foo();
11	        return 0;
12	}
13
(gdb) b foo
Breakpoint 1 at 0x400434: file foo.c, line 5.
(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000400434 in main at foo.c:5

GDB reported that we understood what "foo" was, but we then report that the
breakpoint is actually set in main. While that is literally true, we can
do a little better.

This is accomplished by copying the symbol for which the breakpoint was set
into the bp_location.  From there, print_breakpoint_location can use this
information to print out symbol information (if available) instead of calling
find_pc_sect_function.

With the patch installed,

(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000400434 in foo at foo.c:5

gdb/ChangeLog:

	* breakpoint.c (print_breakpoint_location): Use the symbol saved
	in the bp_location, falling back to find_pc_sect_function when
	needed.
	(add_location_to_breakpoint): Save sal->symbol.
	* breakpoint.h (struct bp_location) <symbol>: New field.
	* symtab.c (find_function_start_sal): Save the symbol into the SaL.
	* symtab.h (struct symtab_and_line) <symbol>: New field.

gdb/testsuite/ChangeLog:

	* gdb.opt/inline-break.exp (break_info_1): New procedure.
	Test "info break" for every inlined function breakpoint.
2017-10-27 10:57:23 -07:00
Yao Qi bb11dd5839 [AArch64] Mark LR clobbered by BL in inline asm
LR is a caller-save register, so, if inline asm does BL (which touches
LR), we should mark LR clobbered.

gdb/testsuite:

2017-10-27  Yao Qi  <yao.qi@linaro.org>

	* gdb.arch/insn-reloc.c (can_relocate_bl): Mark "x30" clobbered.
2017-10-27 15:29:24 +01:00
Simon Marchi 32ef30002c dwarf: Read register number as unsigned in DW_CFA_def_cfa*
When displaying the .debug_frame section, the register numbers in the
DW_CFA_def_cfa* statements are read as signed numbers.  I have come
across a target that has register 121, encoded as 0x79 in unsigned LEB128.
Interpreting this as signed results in -7, which makes readelf display
"r-7".

The DWARF5 standard (6.4.2.2) states that the register numbers should be
treated as unsigned LEB128.

Simply replacing READ_SLEB with READ_ULEB resulted in warnings like
these:

/home/emaisin/src/binutils-gdb/binutils/dwarf.c: In function ‘display_debug_frames’:
/home/emaisin/src/binutils-gdb/binutils/dwarf.c:355:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
       if ((var) != _val)     \
                 ^
/home/emaisin/src/binutils-gdb/binutils/dwarf.c:7866:8: note: in expansion of macro ‘READ_ULEB’
        READ_ULEB (fc->cfa_reg);
        ^
... so I also changed Frame_Chunk::cfa_reg to an unsigned int.

binutils/ChangeLog:

	* dwarf.c (struct Frame_Chunk) <cfa_reg>: Change type to
	unsigned int.
	(display_debug_frames): Read CFA reg as an unsigned number.
2017-10-27 09:01:36 -04:00
Simon Marchi 7453e6b2ea Add PR mention to previous commit 2017-10-27 08:58:43 -04:00
Patrick Frants a43f3893f6 Fix broken recursion detection when printing static members
Recursion detection for static members was broken.  The implementation
uses a growing (and shrinking) obstack object to simulate a stack of
addresses (CORE_ADDR).  Pushing addresses is implemented by calling
obstack_grow(), while popping is implemented by calling obstack_free().
The latter is problematic because obstack_free() expects a pointer to
the base of an object.  When popping elements of the stack however,
obstack_free() was called with the new top, which potentially is not the
same as the base of the stack.  This is unintended use and the effect is
that obstack->next_free and obstack->object_base members are assigned
the value of the new top, which equals an empty stack.  Summary: popping
elements would always result in an empty stack, which breaks the
recursion detection.

The fix shrinks the stack using obstack_blank_fast() with a negative
value as described at the bottom of this page:
https://gcc.gnu.org/onlinedocs/libiberty/Extra-Fast-Growing.html "You
can use obstack_blank_fast with a “negative” size argument to make the
current object smaller.  Just don’t try to shrink it beyond zero
length—there’s no telling what will happen if you do that. Earlier
versions of obstacks allowed you to use obstack_blank to shrink objects.
This will no longer work."

The reproducer is added to gdb.cp/classes.exp, which fails without this
patch.

gdb/ChangeLog:

	* cp-valprint.c (cp_print_value_fields): Use obstack_blank_fast
	to rewind obstack.

gdb/testsuite/ChangeLog:

	* gdb.cp/classes.exp (test_static_members): Test printing
	Outer::instance.
	* gdb.cp/classes.c (struct Inner, struct Outer): New.
	(Inner::instance, Outer::instance): New.
2017-10-26 22:26:08 -04:00
GDB Administrator 95904ac43c Automatic date update in version.in 2017-10-27 00:00:28 +00:00