Commit Graph

100820 Commits

Author SHA1 Message Date
H.J. Lu 74e10d1742 x86: Check static link of dynamic objects
On Linux/x86, when -static is passed to gcc, gcc passes it to linker
before all input files suitable for creating static executable.  X86
linker will report error for dynamic input objects if -static is passed
at command-line before all input files without --dynamic-linker unless
--no-dynamic-linker is used.

bfd/

	PR ld/24920
	* elf-linker-x86.h (elf_linker_x86_params): Add
	static_before_all_inputs and has_dynamic_linker.
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Report
	dynamic input objects if -static is passed at command-line
	before all input files without --dynamic-linker unless
	--no-dynamic-linker is used.

ld/

	PR ld/24920
	* emulparams/elf32_x86_64.sh: Use static.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/static.sh: New file.
	* emultempl/elf-x86.em: Include "ldlex.h".
	* testsuite/ld-elf/pr24920.err: New file.
	* testsuite/ld-elf/linux-x86.exp: Run ld/24920 tests.
2020-03-13 07:39:06 -07:00
Tom de Vries 2d61316c32 [gdb/testsuite] Fix buffer full errors in gdb.mi/mi-sym-info.exp
With debug info packages for system libs installed, I run into buffer full
errors with test-case gdb.mi/mi-sym-info.exp.  Fix these using exp_continue.

This exposes timeouts due to gdb taking a long time before starting to print
output.  Fix these using with_timeout_factor.

Tested on x86_64-linux, with make targets check and check-read1.

gdb/testsuite/ChangeLog:

2020-03-13  Tom de Vries  <tdevries@suse.de>

	* gdb.mi/mi-sym-info.exp: Fix buffer full errors, and timeouts.
2020-03-13 15:38:19 +01:00
Tom de Vries 2e9145ace2 [gdb/testsuite] Fix mi-sym-info.exp matching FAILs (2)
With debug info packages for system libraries installed, I currently run into
some "internal buffer is full" errors with test-case gdb.mi/mi-sym-info.exp,
but if I disable the corresponding tests, I get further-on:
...
FAIL: gdb.mi/mi-sym-info.exp: List all functions matching pattern f3 \
  (unexpected output)
FAIL: gdb.mi/mi-sym-info.exp: List all functions matching type void \
  (unexpected output)
FAIL: gdb.mi/mi-sym-info.exp: List all variables matching type float \
  (unexpected output)
FAIL: gdb.mi/mi-sym-info.exp: -symbol-info-functions --max-results 1 \
  (unexpected output)
FAIL: gdb.mi/mi-sym-info.exp: -symbol-info-functions --max-results 2 \
  (unexpected output)
...

Fix this by making the matching more precise.

Tested on x86_64-linux.

Also tested with an extra:
...
mi_gdb_test "set debug-file-directory"
...
to prevent gdb from finding the debug info for system libraries.

gdb/testsuite/ChangeLog:

2020-03-13  Tom de Vries  <tdevries@suse.de>

	* gdb.mi/mi-sym-info.exp: Make matching more precise.
2020-03-13 14:43:03 +01:00
Andre Vieira 66d1f7cc12 gas, arm: PR25660L Fix vadd/vsub with lt and le condition codes for MVE
As explained in the PR, the addition of MVE makes the parser strip 't' and 'e'
as suffixes when MVE is enabled.  This leads to vadd and vsub in it blocks with
lt and le conditions to be initially parsed as vaddl and vsubl.  This means the
operand parsing for these must allow for the same operands as the scalar vadd
and vsub.  I had forgotten to do this and this patch remedies that oversight.

gas/ChangeLog:
2020-03-13  Andre Vieira  <andre.simoesdiasvieira@arm.com>

	PR 25660
	*  config/tc-arm.c (operand_parse_code): Add OP_RNSDMQR and OP_oRNSDMQ.
	(parse_operands): Handle new operand codes.
	(do_neon_dyadic_long): Make shape check accept the scalar variants.
	(asm_opcode_insns): Fix operand codes for vaddl and vsubl.
	* testsuite/gas/arm/mve-vaddsub-it.s: New test.
	* testsuite/gas/arm/mve-vaddsub-it.d: New test.
	* testsuite/gas/arm/mve-vaddsub-it-bad.s: New test.
	* testsuite/gas/arm/mve-vaddsub-it-bad.l: New test.
	* testsuite/gas/arm/mve-vaddsub-it-bad.d: New test.
	* testsuite/gas/arm/nomve-vaddsub-it.d: New test.
2020-03-13 13:35:04 +00:00
Kamil Rytarowski 015ec493d8 Recognize aarch64 PT_GETREGS and PT_GETFPREGS notes on NetBSD
* elf.c (elfcore_grok_netbsd_note): Add support for aarch64.
2020-03-13 14:16:35 +01:00
Jan Beulich 1673df3278 x86-64: correct mis-named X86_64_0D enumerator
This is for major opcode 0E, so name it accordingly.
2020-03-13 09:57:10 +01:00
Tom de Vries 96c7f87394 [gdb/symtab] Fix partial unit psymtabs
Consider test-case gdb.dwarf2/imported-unit.exp.

It contains a CU with type int:
...
 <0><129>: Abbrev Number: 2 (DW_TAG_compile_unit)
    <12a>   DW_AT_language    : 4       (C++)
    <12b>   DW_AT_name        : imported_unit.c
 <1><13b>: Abbrev Number: 3 (DW_TAG_base_type)
    <13c>   DW_AT_byte_size   : 4
    <13d>   DW_AT_encoding    : 5       (signed)
    <13e>   DW_AT_name        : int
...
which is imported in another CU:
...
 <0><d2>: Abbrev Number: 2 (DW_TAG_compile_unit)
    <d3>   DW_AT_language    : 4        (C++)
    <d4>   DW_AT_name        : <artificial>
 <1><e1>: Abbrev Number: 3 (DW_TAG_imported_unit)
    <e2>   DW_AT_import      : <0x129>  [Abbrev Number: 2]
...

However, if we print the partial symbols:
...
$ gdb -batch imported-unit  -ex "maint print psymbols"
...
we see type int both in the importing CU:
...
Partial symtab for source file <artificial>@0xc7 (object 0x29f9b80)
  ...
  Depends on 1 other partial symtabs.
    0 0x2a24240 imported_unit.c
  Global partial symbols:
    `main', function, 0x4004b2
  Static partial symbols:
    `int', type, 0x0
...
and in the imported CU:
...
Partial symtab for source file imported_unit.c (object 0x2a24240)
  ...
  Depends on 0 other partial symtabs.
  Shared partial symtab with user 0x29f9b80
  Static partial symbols:
    `int', type, 0x0
...

This is an artefact resulting from the fact that all CUs in an objfile
share the same storage array for static partial symbols (and another array for
global partial symbols), using a range to describe their symbols.

Then when scanning the partial symbols of a CU and encountering an import, either:
- the referred CU has not been parsed yet, and will be parsed, and the range of
  static partial symbols of the referred CU will be a subrange of the range of
  static partial symbols of this CU, or
- the referred CU has already been parsed, and the range of static partial
  symbols of the referred CU will not be a subrange of the range of static
  partial symbols of this CU.

This is inconsistent handling, and confuses the notion of a symbol belonging to
a single symtab.

Furthermore, it might slow down searches, given that the symbol needs to be
skipped twice.

Finally, the same issue holds for global partial symbols, where the range of a
CU is sorted after parsing is finished.  Obviously sorting the range of a CU
may invalidate subranges, effectively moving symbols in and out of imported
CUs.

Fix this for both static and global partial symbols, by gathering partial
symbols in a per-CU vector, and adding those symbols to the per-objfile
storage only once complete.

Tested on x86_64-linux, with native and board cc-with-dwz and cc-with-dwz-m.

gdb/ChangeLog:

2020-03-13  Tom de Vries  <tdevries@suse.de>

	PR symtab/25646
	* psymtab.c (partial_symtab::partial_symtab): Don't set
	globals_offset and statics_offset.  Push element onto
	current_global_psymbols and current_static_psymbols stacks.
	(concat): New function.
	(end_psymtab_common): Set globals_offset and statics_offset.  Pop
	element from current_global_psymbols and current_static_psymbols
	stacks.  Concat popped elements to global_psymbols and
	static_symbols.
	(add_psymbol_to_list): Use current_global_psymbols and
	current_static_psymbols stacks.
	* psymtab.h (class psymtab_storage): Add current_global_psymbols and
	current_static_psymbols fields.

gdb/testsuite/ChangeLog:

2020-03-13  Tom de Vries  <tdevries@suse.de>

	PR symtab/25646
	* gdb.dwarf2/imported-unit.exp: Add test.
2020-03-13 08:50:51 +01:00
Christian Eggers 666318230c Fix several mix up between octets and bytes in ELF program headers
Fixes additional locations not handled in the first patch.

When converting between addresses in ELF headers [octets] and bfd
LMA/VMA [bytes], the number of octets per byte needs to be incorporated.

include/
	* bfdlink.h (struct bfd_link_order): Add unit (bytes/octets) to
	offset and size members.
	* elf/internal.h (struct elf_internal_phdr): Likewise for
	p_align member.
	(struct elf_segment_map): Likewise for p_paddr and p_size
	members
bfd/
	* bfd.c (bfd_record_phdr): New local "opb".  Fix assignment of
	"p_paddr" from "at".
	* elfcode.h (bfd_from_remote_memory): Add units to several
	parameters.  New local "opb".  Fix usage of p_align.  Fix
	calculation of "localbase" from "ehdr_vma" and "p_vaddr".  Fix
	call of target_read_memory.
	* elflink.c (elf_fixup_link_order): Fix scope of "s" local.  Fix
	calculation of "offset" and "output_offset".
	(bfd_elf_final_link): New local "opb".  Fix calculation of "size"
	from "offset" and fix calculation of "end" from "vma+size".  Fix
	comparison between "sh_addr" and "vma"/"output_offset".
	(bfd_elf_discard_info): Fix calculation of "eh_alignment".
	* elf-bfd.h (struct elf_link_hash_table): Add unit to tls_size
	member.
	* elf.c (_bfd_elf_map_sections_to_segments): Add unit (bytes/
	octets) to "wrap_to2 and "phdr_size" locals.  Fix calculation of
	"wrap_to" value.  Add unit (bytes) to phdr_lma variable.  Fix
	assignment of p_paddr from phdr_lma.  Fix comparison between
	"lma+size" and "next->lma".
	(elf_sort_segments): Fix assignment from p_paddr to lma.
	(assign_file_positions_for_load_sections): Add unit (bytes) to
	local "align".  Fix calculation of local "off_adjust".  Fix
	calculation of local "filehdr_vaddr".
	(assign_file_positions_for_non_load_sections): New local "opb".
	Fix calculation of "end" from "p_size". Fix comparison between
	"vma+SECTION_SIZE" and "start".  Fix calculation of "p_memsz"
	from "end" and "p_vaddr".
	(rewrite_elf_program_header): Fix comparison between p_vaddr and
	vma.  Fix assignment to p_paddr from lma.  Fix comparison between
	p_paddr and lma.  Fix assignment to p_paddr from lma.
	* merge.c (sec_merge_emit): New local "opb". Convert
	"alignment_power" to octets.
	(_bfd_add_merge_section): New locals "alignment_power" and
	"opb".  Fix comparison between "alignment_power" and
	"sizeof(align)".
	(_bfd_merge_sections): New local "opb".  Divide size by opb
	before checking align mask.
2020-03-13 15:48:01 +10:30
Christian Eggers 502794d432 Fix several mix up between octets and bytes in ELF program headers
When converting between addresses in ELF headers [octets] and bfd
LMA/VMA [bytes], the number of octets per byte needs to be
incorporated.

In ld, the SIZEOF_HEADERS linker script statement must be resolved to
bytes instead of octets.

include/
	* elf/internal.h (struct elf_internal_phdr): Add unit (octets)
	to several member field comments.
	(Elf_Internal_Shdr): likewise.
bfd/
	* elf.c (_bfd_elf_make_section_from_shdr): Introduce new temp
	opb.  Divide Elf_Internal_Shdr::sh_addr by opb when setting
	section LMA/VMA.
	(_bfd_elf_make_section_from_phdr): Similarly.
	(elf_fake_sections): Fix calculation of
	Elf_Internal_shdr::sh_addr from section VMA.
	(_bfd_elf_map_sections_to_segments): Fix mixup between octets
	and bytes.
	(assign_file_positions_for_load_sections): Fix calculations of
	Elf_Internal_shdr::p_vaddr and p_paddr from section LMA/VMA.  Fix
	comparison between program header address and section LMA.
	(assign_file_positions_for_non_load_sections): Likewise.
	(rewrite_elf_program_header): Likewise.  Introduce new temp opb.
	(IS_CONTAINED_BY_VMA): Add parameter opb.
	(IS_CONTAINED_BY_LMA,IS_SECTION_IN_INPUT_SEGMENT,
	INCLUDE_SECTION_IN_SEGMENT): Likewise.
	(copy_elf_program_header): Update call to ELF_SECTION_IN_SEGMENT.
	Fix calculations of p_addr_valid and p_vaddr_offset.
	* elflink.c (elf_link_add_object_symbols): Multiply section VMA
	with octets per byte when comparing against p_vaddr.
ld/
	* ldexp.c (fold_name): Return SIZEOF_HEADERS in bytes.
2020-03-13 15:37:11 +10:30
Alan Modra fd486f32d1 asan: more readelf leaks
* elfcomm.c (get_archive_member_name): Always return malloc'd
	string or NULL.
	* elfedit.c (process_archive): Tidy memory on all return paths.
	* readelf.c (process_archive): Likewise.
	(process_symbol_table): Likewise.
	(ba_cache): New, replacing ..
	(get_symbol_for_build_attribute): ..static vars here.  Free
	strtab and symtab before loading new ones.  Reject symtab without
	valid strtab in loop, breaking out of loop on valid symtab.
	(process_file): Free ba_cache symtab and strtab here, resetting
	ba_cache.
2020-03-13 14:26:24 +10:30
Tom de Vries 49ba92c0a6 [gdb/testsuite] Fix mi-sym-info.exp matching FAILs
When running gdb.mi/mi-sym-info.exp on openSUSE Leap 15.1, I get:
...
FAIL: gdb.mi/mi-sym-info.exp: List all functions matching type void \
  (unexpected output)
FAIL: gdb.mi/mi-sym-info.exp: -symbol-info-variables --max-results 3 \
  (unexpected output)
FAIL: gdb.mi/mi-sym-info.exp: -symbol-info-types --max-results 4 \
  (unexpected output)
...

The executable contains debug info from files other than the source files:
...
$ readelf -wi mi-sym-info | grep "DW_AT_name.*\.[cS]$" | awk '{print $8}'
../sysdeps/x86_64/start.S
init.c
../sysdeps/x86_64/crti.S
src/gdb/testsuite/gdb.mi/mi-sym-info-1.c
src/gdb/testsuite/gdb.mi/mi-sym-info-2.c
elf-init.c
../sysdeps/x86_64/crtn.S
...

The test does not expect this extra info, resulting in matching failures.

Fix this by restricting the failing commands using --name.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-13  Tom de Vries  <tdevries@suse.de>

	* gdb.mi/mi-sym-info-2.c (another_char_t, another_short_t): New typedef.
	(var1, var2): New variable.
	* gdb.mi/mi-sym-info.exp: Add --name to various commands to restrict
	matching symbols.
2020-03-13 00:41:44 +01:00
Tom de Vries 301b21e0df [gdb/testsuite] Fix check-read1 FAIL in gdb.tui/corefile-run.exp
With test-case gdb.tui/corefile-run.exp and make target check-read1, I run
into:
...
FAIL: gdb.tui/corefile-run.exp: run until the end
...

In more detail, using -v:
...
PASS: gdb.tui/corefile-run.exp: load corefile
^M+++ _ctl_0x0d
^[[17d+++ _csi_d <<<17>>>
^[[M+++ _csi_M <<<>>>
^[[24d+++ _csi_d <<<24>>>
(INSERT <<(>>
gINSERT <<g>>
dINSERT <<d>>
bINSERT <<b>>
)INSERT <<)>>
 INSERT << >>
FAIL: gdb.tui/corefile-run.exp: run until the end
...

With some debugging code added in wait_for, what happens becomes more clear:
...
	    if {[regexp -- $wait_for $prev]} {
+		verbose -log "\nwait_for: MATCHED line ($_cur_y): \"$prev\""
+		verbose -log "wait_for: AGAINST regexp: \"$wait_for\""
...

In corefile-run.exp, we execute:
...
Term::command "run"
...
and in proc Term::command, we send the command, and then call wait_for:
...
    proc command {cmd} {
        send_gdb "$cmd\n"
        wait_for [string_to_regexp $cmd]
    }
...
which first waits for the command string, and then for the prompt.

In this case however, the matching of the command string triggers on a
previous line:
...
wait_for: MATCHED line (16): \
  "(gdb) core-file corefile-run.core[New LWP 6426] <lots-of-spaces>"
wait_for: AGAINST regexp: "run"
...
and from there on things go out of sync, eventually resulting in the FAIL.

Fix this in proc command by more precisely specifying the expected pattern:
adding a ^$gdb_prompt prefix.

Add a command_no_prompt_prefix variant to use for initial terminal commands
where there's no prompt yet.

Tested gdb.tui/*.exp on x86_64-linux, with make target check and check-read1.

gdb/testsuite/ChangeLog:

2020-03-13  Tom de Vries  <tdevries@suse.de>

	* lib/tuiterm.exp (Term::command_no_prompt_prefix): New proc.
	(Term::command): Use prompt prefix.
	(Term::enter_tui): Use command_no_prompt_prefix instead of prefix.
	* gdb.tui/tui-layout-asm-short-prog.exp: Use
	command_no_prompt_prefix instead of prefix.
	* gdb.tui/tui-layout-asm.exp: Same.
2020-03-13 00:31:15 +01:00
Christian Biesinger 6ba0a32103 Remove deprecated core file functions
There are no more callers to deprecated_add_core_fns, now that I have
removed the usage from CRIS and ARM/NetBSD.  So this patch cleans up
all the related code and makes corelow.c a lot more readable.

gdb/ChangeLog:

2020-03-12  Christian Biesinger  <cbiesinger@google.com>

	* corelow.c (sniff_core_bfd): Remove.
	(class core_target) <m_core_vec>: Remove.
	(core_target::core_target): Update.
	(core_file_fns): Remove.
	(deprecated_add_core_fns): Remove.
	(default_core_sniffer): Remove.
	(sniff_core_bfd): Remove.
	(default_check_format): Remove.
	(gdb_check_format): Remove.
	(core_target_open): Update.
	(core_target::get_core_register_section): Update.
	(get_core_registers_cb): Update.
	(core_target::fetch_registers): Update.
	* gdbcore.h (struct core_fns): Remove.
	(deprecated_add_core_fns): Remove.
	(default_core_sniffer): Remove.
	(default_check_format): Remove.
2020-03-12 16:28:40 -05:00
Tom Tromey 4635ff9753 Change gdbserver to use existing gdbsupport
This changes the gdbserver build to use the gdbsupport that was built
for gdb.

gdbserver and gdbreplay now must use WIN32APILIBS (aka -lws2_32).
Before this change, gdbserver did not define USE_WIN32API when
building gdbsupport, but now this is always done.

ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* Makefile.in: Rebuild.
	* Makefile.def (gdbserver): Depend on gdbsupport.

gdbserver/ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac (GDBSERVER_DEPFILES): Remove srv_selftest_objs.
	(WIN32APILIBS): New subst.
	* Makefile.in (SFILES, OBS, TAGS, GDBREPLAY_OBS): Remove
	gdbsupport files.
	(gdbsupport/%.o): Remove target.
	(GDBSUPPORT_BUILDDIR, GDBSUPPORT): New variables.
	(gdbserver$(EXEEXT), gdbreplay$(EXEEXT)): Add GDBSUPPORT.
	(WIN32APILIBS): New variable.
	(gdbserver$(EXEEXT)): Add WIN32APILIBS.
	(gdbreplay$(EXEEXT)): Likewise.
2020-03-12 13:32:16 -06:00
Tom Tromey 213291361b Change gdbsupport not to rely on BFD
This changes gdbsupport so that it no longer relies on BFD.  This is a
precursor to making gdbserver use the already-built gdbsupport,
because building gdbserver should not require BFD to be built.

The most notable change here is that CORE_ADDR is always a 64-bit
type.  This makes it so that gdb acts as if it were always built in
64-bit mode.

ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* Makefile.in: Rebuild.
	* Makefile.def (gdbsupport): Don't depend on bfd.

gdbsupport/ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* common-types.h: Remove GDBSERVER code.
	(gdb_byte, CORE_ADDR, LONGEST, ULONGEST): Redefine.
	* common-defs.h: Remove GDBSERVER code.
2020-03-12 13:32:16 -06:00
Tom Tromey 9a665d6226 Fix gdbserver build when intl already built
gdbserver uses gdb's alloc.c, and this in turn can include headers
from intl via gdbsupport/gdb_locale.h.  This can cause build failures
in some situations, for example if you build gdb and gdbserver on
mingw.

This patch restores the gdbsupport dependency on intl, and changes
gdbserver to use ZW_GNU_GETTEXT_SISTER_DIR.  This fixes this build
problem.

ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* Makefile.in: Rebuild.
	* Makefile.def (gdbsupport): Depend on intl.

gdbserver/ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* config.in, configure: Rebuild.
	* configure.ac: Call ZW_GNU_GETTEXT_SISTER_DIR.
	* acinclude.m4: Include gettext-sister.m4.
	* Makefile.in (top_builddir, INTL, INTL_DEPS, INTL_CFLAGS): New
	variables.
	(INCLUDE_CFLAGS): Add INTL_CFLAGS.
	(gdbserver$(EXEEXT), gdbreplay$(EXEEXT)): Use INTL_DEPS, INTL.
2020-03-12 13:32:15 -06:00
Tom Tromey 227031b2bf Cast to bfd_vma in arm-tdep.c
Some arm-tdep.c data structures use a bfd_vma.  A couple of spots will
warn about an implicit narrowing cast when building a gdb where
CORE_ADDR is 64-bit but bfd_vma is 32-bit.

This patch silences these warnings by changing the types in question
to CORE_ADDR.

gdb/ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* arm-tdep.c (struct arm_mapping_symbol) <value>: Now a
	CORE_ADDR.
	(struct arm_exidx_entry) <addr>: Now a CORE_ADDR.
2020-03-12 13:32:15 -06:00
Tom Tromey 53807e9f3d Don't use sprintf_vma for CORE_ADDR
A few spots in gdb use sprintf_vma to print a CORE_ADDR.  This will
fail on a 32-bit build once CORE_ADDR is always a 64-bit type.

This patch replaces these calls with phex instead.

gdb/ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_target::download_tracepoint)
	(remote_target::enable_tracepoint)
	(remote_target::disable_tracepoint): Use phex, not sprintf_vma.
	* breakpoint.c (print_recreate_masked_watchpoint): Use phex, not
	sprintf_vma.
2020-03-12 13:32:15 -06:00
Tom Tromey 64f251023b Fix CORE_ADDR size assertion in symfile-mem.c
symfile-mem.c has some assertions about the size of various types, to
ensure that gdb and BFD don't get out of sync in a way that would
cause bugs.

Once CORE_ADDR is always 64-bit, one of these assertions can fail for
a 32-bit BFD build.  However, the real requirement here is just that
CORE_ADDR is wider -- because this code promotes a bfd_vma to a
CORE_ADDR.

This patch corrects the assert.

gdb/ChangeLog
2020-03-12  Tom Tromey  <tom@tromey.com>

	* symfile-mem.c: Update CORE_ADDR size assert.
2020-03-12 13:32:15 -06:00
Simon Marchi 3f512721a8 gdb: use foreach_with_prefix in gdb.base/break-interp.exp
Use foreach_with_prefix, instead of foreach and with_test_prefix
separately.  Since allows removing some indentation levels, and formats
the test names a bit nicer, in my opinion (or at least, it's more
consistent with the rest of the testsuite):

    - PASS: gdb.base/break-interp.exp: LDprelinkNOdebugNO: BINprelinkNOdebugNOpieNO: INNER: core: set verbose on
    + PASS: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=NO: binpie=NO: INNER: set verbose on

Note: this patch is better viewed with "git show -w" to ignore
whitespace changes.

gdb/testsuite/ChangeLog:

	* gdb.base/break-interp.exp: Use foreach_with_prefix.
2020-03-12 14:34:22 -04:00
Simon Marchi 40310f30a5 gdb: make gdb.arch/amd64-disp-step-avx.exp actually test displaced stepping
The test gdb.arch/amd64-disp-step-avx.exp is meant to test that doing a
displaced step of an AVX instruction works correctly.  However, I found
(by pure coincidence) that the test instructions are not actually
displaced stepped.  Rather, they are inline-stepped, so the test is not
actually testing what it's meant to test.

This is what a portion of the test binary looks like:

    0000000000400180 <_start>:
      400180:       90                      nop

    0000000000400181 <main>:
      400181:       90                      nop

    0000000000400182 <test_rip_vex2>:
      400182:       c5 fb 10 05 0e 00 00    vmovsd 0xe(%rip),%xmm0        # 400198 <ro_var>
      400189:       00

    000000000040018a <test_rip_vex2_end>:
      40018a:       90                      nop

The instruction at 0x400182 is the one we want to test a displaced step
for.  A breakpoint is placed at 0x400182 and ran to.  The execution is
then resumed from there, forcing a step-over (which should normally be a
displaced step) of the breakpoint.

However, the displaced stepping buffer is at the _start label, and that
means a breakpoint is present in the displaced stepping buffer.  The
breakpoint_in_range_p check in displaced_step_prepare_throw evaluates to
true, which makes displaced_step_prepare_throw fail, forcing GDB to fall
back on an in-line step.

This can be easily observed by placing a `gdb_assert (false)` inside the
breakpoint_in_range_p condition, in displaced_step_prepare_throw, and
running gdb.arch/amd64-disp-step-avx.exp.  The assertion will make the
test fail.

The proposed fix is to pad `_start` with a bunch of nops so that the
test instruction is out of the displaced step buffer.

I also think it would be good to enhance the test to make sure that we
are testing displaced stepping as intended.  I did that by enabling "set
debug displaced on" while we step over the interesting instruction, and
matching a message printed only when a displaced step is executed.

gdb/testsuite/ChangeLog:

	* gdb.arch/amd64-disp-step-avx.S: Add nops after _start.
	* gdb.arch/amd64-disp-step-avx.exp: Enable "set debug displaced
	on" while stepping over the test instruction, match printed
	message.
2020-03-12 14:23:12 -04:00
Simon Marchi 272cd5a31e Move gdb/selftest.m4 to gdbsupport/selftest.m4
The selftest.m4 file is used by gdb, gdbserver and gdbsupport, I think
it belongs in gdbsupport.

gdb/ChangeLog:

	* selftest.m4: Move to gdbsupport/.
	* acinclude.m4: Update path to selftest.m4.

gdbserver/ChangeLog:

	* acinclude.m4: Update path to selftest.m4.

gdbsupport/ChangeLog:

	* selftest.m4: Moved from gdb/.
	* acinclude.m4: Update path to selftest.m4.
2020-03-12 14:19:38 -04:00
Simon Marchi 74cd3f9d7e Don't include selftests objects in build when unit tests are disabled
While working on the preceding selftests patches, I noticed that some
selftests-specific files are included in the build even when selftests
are disabled, namely disasm-selftest.c and gdbarch-selftests.c.  These
files are entirely #if'ed out when building with selftests disabled.

This is not a huge problem, but I think it would make more sense if
these files were simply not built.

With this patch, I propose to put all the selftests-specific source
files into a SELFTESTS_SRCS Makefile variable (even selftest-arch.c,
which is currently added by the configure script).

gdb/ChangeLog:

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Rename to...
	(SELFTESTS_SRCS): ... this.  Add disasm-selftests.c,
	gdbarch-selfselftests.c and selftest-arch.c.
	(SUBDIR_UNITTESTS_OBS): Rename to...
	(SELFTESTS_OBS): ... this.
	(COMMON_SFILES): Remove disasm-selftests.c and
	gdbarch-selftests.c.
	* configure.ac: Don't add selftest-arch.{c,o} to
	CONFIG_{SRCS,OBS}.
	* disasm-selftests.c, gdbarch-selftests.c: Remove GDB_SELF_TEST
	preprocessor conditions.
2020-03-12 14:18:36 -04:00
Simon Marchi db6878ac55 Move sourcing of development.sh to GDB_AC_COMMON
The same is done for gdb, gdbserver and gdbsupport.  I therefore think
it makes sense to move that to GDB_AC_COMMON.

It is required to move the call to GDB_AC_COMMON so it is before
GDB_AC_SELFTEST in gdbserver/configure.ac, otherwise the $development
variable isn't set when the code behind GDB_AC_SELFTEST executes.

gdb/ChangeLog:

	* configure.ac: Don't source bfd/development.sh.
	* selftest.m4: Modify comment.
	* configure: Re-generate.

gdbserver/ChangeLog:

	* configure.ac: Don't source bfd/development.sh, move
	GDB_AC_COMMON higher.
	* configure: Re-generate.

gdbsupport/ChangeLog:

	* configure.ac: Don't source bfd/development.sh.
	* common.m4: Source bfd/development.sh.
	* configure: Re-generate.
2020-03-12 14:18:00 -04:00
Simon Marchi 4d696a5c68 gdb/selftest.m4: ensure $development is set
Before commit 3d1e5a43cb ("gdbsupport/configure.ac: source
development.sh"), the GDB build in non-development mode (turn
development to false in bfd/development.sh if you want to try) was
broken because the gdbsupport configure script didn't source
bfd/development.sh to set the development variable.

Since the GDB_AC_SELFTEST macro relies on the `development` variable, I
propose to modify it such that it errors out if $development does not
have an expected value of "true" or "false".  This could prevent a
future similar problem from happening while refactoring the configure
scripts.  It would have caught the problem fixed by the patch mentioned
earlier.

gdb/ChangeLog:

	* selftest.m4 (GDB_AC_SELFTEST): Error out if $development is
	not "true" or "false".
	* configure: Re-generate.

gdbserver/ChangeLog:

	* configure: Re-generate.

gdbsupport/ChangeLog:

	* configure: Re-generate.
2020-03-12 14:17:57 -04:00
Christian Biesinger 8dd8e1c722 Remove use of deprecated core functions (in NetBSD/ARM)
This is in preparation for deleting deprecated_add_core_fns and
related code.

As a side-effect, this makes it possible to read NetBSD/ARM
core files on non-NetBSD/ARM platforms, subject to PR corefiles/25638.

I have removed this comment:
-  /* This is ok: we're running native...  */
Since we are using the gdbarch from the regcache, we should be
guaranteed to be calling the right function here, so it shouldn't
matter whether we are running native.

Tested by reading a NetBSD/ARM core file on Linux/x86-64 and NetBSD/ARM;
the "info registers" output matches the one from the system GDB.

gdb/ChangeLog:

2020-03-12  Christian Biesinger  <cbiesinger@google.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add new arm-nbsd-tdep.h file.
	* arm-nbsd-nat.c (arm_supply_gregset): Moved to arm-nbsd-tdep and
	renamed to arm_nbsd_supply_gregset.
	(fetch_register): Update to call arm_nbsd_supply_gregset.
	(fetch_regs): Remove in favor of fetch_register with a -1 regno.
	(arm_netbsd_nat_target::fetch_registers): Update.
	(fetch_elfcore_registers): Removed.
	(_initialize_arm_netbsd_nat): Removed call to deprecated_add_core_fns.
	* arm-nbsd-tdep.c (struct arm_nbsd_reg): New struct.
	(arm_nbsd_supply_gregset): Moved from arm-nbsd-nat.c and updated to
	not require NetBSD system headers.
	(arm_nbsd_regset): New struct.
	(arm_nbsd_iterate_over_regset_sections): New function.
	(arm_netbsd_init_abi_common): Updated to call
	set_gdbarch_iterate_over_regset_sections.
	* arm-nbsd-tdep.h: New file.
2020-03-12 12:23:17 -05:00
Kamil Rytarowski 7a20f753ef sim: ppc: netbsd: Sync signal names with NetBSD 9.99.49
sim/ppc/ChangeLog:

	* emul_netbsd.c (netbsd_signal_names): Sync with NetBSD 9.99.49.
2020-03-12 16:07:37 +01:00
Kamil Rytarowski 607c693210 sim: ppc: netbsd: Sync errno codes with NetBSD 9.99.49
sim/ppc/ChangeLog:

	* emul_netbsd.c (netbsd_error_names): Sync with NetBSD 9.99.49.
2020-03-12 16:07:37 +01:00
Tom de Vries 0925214029 [gdb/testsuite] Fix internal buffer full error in gdb.base/info-types.exp
With test-case gdb.base/info-types.exp, I run into:
...
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/info-types.exp: l=c: info types
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/info-types.exp: l=c++: info types
...

Fix this by using exp_continue while matching the output of "info types".

Tested on x86_64-linux, using make targets check and check-read1.

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* gdb.base/info-types.exp: Use exp_continue during matching of output
	of "info types".
2020-03-12 14:58:57 +01:00
Tom de Vries 14e9c72c33 [gdb/testsuite] Avoid breakpoint in GLIBC in gdb.threads/execl.exp
When running the gdb.threads/execl.exp test-case, we run into this FAIL:
...
(gdb) continue^M
Continuing.^M
^M
Thread 1 "execl" hit Breakpoint 2, __GI_execl (path=0x6024a0 \
  "build/gdb/testsuite/outputs/gdb.threads/execl/execl1", \
  arg=<optimized out>) at execl.c:51^M
51        if (execl (new_image, new_image, NULL) == -1) \
  /* set breakpoint here */^M
(gdb) FAIL: gdb.threads/execl.exp: continue across exec
...
The fail is due to the continue command hitting a breakpoint in __GI_execl
rather than main.

This problem originates from where we execute the "b 51" command, and get two
breakpoint locations:
...
(gdb) run ^M
Starting program: build/gdb/testsuite/outputs/gdb.threads/execl/execl ^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
^M
Breakpoint 1, main (argc=1, argv=0x7fffffffd3f8) at gdb.threads/execl.c:44^M
44        pthread_create (&thread1, NULL, thread_function, NULL);^M
(gdb) b 51^M
Breakpoint 2 at 0x400787: gdb.threads/execl.c:51. (2 locations)^M
(gdb) PASS: gdb.threads/execl.exp: set breakpoint at execl
...

Adding a "info breakpoints" command, we can see the locations:
...
(gdb) info breakpoints^M
Num     Type           Disp Enb Address            What^M
1       breakpoint     keep y   0x00000000004006ee in main at \
  gdb.threads/execl.c:44^M
        breakpoint already hit 1 time^M
2       breakpoint     keep y   <MULTIPLE>         ^M
2.1                         y   0x0000000000400787 in main at \
  gdb.threads/execl.c:51^M
2.2                         y   0x00007ffff758d925 in __GI_execl at \
  execl.c:51^M
(gdb) PASS: gdb.threads/execl.exp: info breakpoints
...

The fact that the __GI_execl breakpoint location is there, is a bug, filed as
PR25656.  Without debug info for GLIBC though, the bug is not triggered.

Fix the FAIL by working around the bug, and deleting the breakpoint after
hitting the first breakpoint location.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* gdb.threads/execl.exp: Delete breakpoint after hitting it.
2020-03-12 14:37:15 +01:00
Tom de Vries e515d67ed6 [gdb/testsuite] Fix internal buffer full error in gdb.fortran/module.exp
With test-case gdb.fortran/module.exp, I run into:
...
PASS: gdb.fortran/module.exp: fully qualified name of DW_TAG_constant
ERROR: internal buffer is full.
UNRESOLVED: gdb.fortran/module.exp: info variables -n
...

Fix this by using exp_continue while matching the output of "info variable
-n".

Tested on x86_64-linux, using make targets check and check-read1.

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* gdb.fortran/module.exp: Use exp_continue during matching of output
	of "info variable -n".
2020-03-12 13:51:46 +01:00
Tom de Vries 307eafd8df [gdb/testsuite] Fix dw2-ranges-base.exp FAIL with lib debuginfo
When running test-case gdb.dwarf2/dw2-ranges-base.exp with debuginfo for
various libs installed, I run into:
...
(gdb) maint info line-table^M
  ...
objfile: /usr/lib/debug/lib64/ld-2.26.so-2.26-lp151.18.7.x86_64.debug \
  ((struct objfile *) 0x1a9d7f0)^M
compunit_symtab: ((struct compunit_symtab *) 0x2061090)^M
symtab: /usr/src/debug/glibc-2.26-lp151.18.7.x86_64/sysdeps/generic/\
  dl-fcntl.h ((struct symtab *) 0x2182660)^M
linetable: ((struct linetable *) 0x0):^M
No line table.^M
(gdb) FAIL: gdb.dwarf2/dw2-ranges-base.exp: count END markers in line table
...

The test-case intends to count 3 END markers in the line table for
gdb.dwarf2/dw2-ranges-base.c:
...
symtab: /data/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.dwarf2/\
  dw2-ranges-base.c ((struct symtab *) 0x2a7e8c0)^M
linetable: ((struct linetable *) 0x2a7ea60):^M
INDEX    LINE ADDRESS IS-STMT^M
0          31 0x00000000004004a7 Y^M
1          21 0x00000000004004ae Y^M
2         END 0x00000000004004ae Y^M
3          11 0x00000000004004ba Y^M
4         END 0x00000000004004ba Y^M
5         END 0x00000000004004c6 Y^M
...
but ends up counting 70+ END markers for all line tables.

Fix this by limiting the line tables emitted by the maint info line-table
command.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/dw2-ranges-base.exp: Limit "maint info line-table" to
	gdb.dwarf2/dw2-ranges-base.c.
2020-03-12 11:58:20 +01:00
Tom de Vries 9a2de3fc7f [gdb/testsuite] Fix gdb.linespec/explicit.exp FAIL with glibc debug info
When running test-case gdb.linespec/explicit.exp with GLIBC debuginfo
installed, I run into:
...
(gdb) break -source exp^GlFAIL: gdb.linespec/explicit.exp: complete \
  non-unique file name (timeout)
...

The regexp that times out is:
...
           -re "break -source exp\\\x07licit" {
...
and the reason it times out is that gdb only outputs an "l" after the tab, while
the regexp expect a futher "icit".

This is a regression since commit 507dd60e28 "[gdb/testsuite, 1/2] Fix
gdb.linespec/explicit.exp with check-read1", where I merged the matching for
the two cases where GLIBC debuginfo is either installed or not, as it turns
out incorrectly, presumably because even though I tested with GLIBC debuginfo
info installed and deinstalled, that didn't make a difference because I didn't
use configure flag --with-separate-debug-dir=/usr/lib/debug.

Fix this by not explictly matching the "icit" part.

Tested on x86_64-linux, with and without GLIBC debuginfo installed, both with
make targets check and check-read1.

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* gdb.linespec/explicit.exp: Fix "complete non-unique file name" test
	in presence of GLIBC debuginfo.
2020-03-12 11:34:45 +01:00
Tom de Vries 3217502e1b [gdb/testsuite] Use string_to_regexp on core filename in gdb_core_cmd
In commit 1281424ccf "[gdb/testsuite] Fix core file load FAIL in
tls-core.exp", I've made this change:
...
-       -re ": No such file or directory.*\r\n$gdb_prompt $" {
+       -re "$core: No such file or directory.*\r\n$gdb_prompt $" {
...

However, the $core variable contains a filename which needs to be matched
as a literal string, not as a regexp.

Fix this by using string_to_regexp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (gdb_core_cmd): Use string_to_regexp for regexp-matching
	$core.
2020-03-12 11:03:07 +01:00
Tom de Vries 1281424ccf [gdb/testsuite] Fix core file load FAIL in tls-core.exp
After deinstalling package glibc-debugsource, I run into the following FAIL
with test-case gdb.threads/tls-core.exp:
...
(gdb) core gdb/testsuite/outputs/gdb.threads/tls-core/tls-core.core^M
[New LWP 30081]^M
[New LWP 30080]^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
Core was generated by `gdb/testsuite/outputs/gdb.threads/tls-core/tls-c'.^M
Program terminated with signal SIGABRT, Aborted.^M
51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.^M
[Current thread is 1 (Thread 0x7fb568d4b700 (LWP 30081))]^M
(gdb) FAIL: gdb.threads/tls-core.exp: native: load core file (file not found)
...

The problem is that this gdb_test_multiple clause in gdb_core_cmd:
...
       -re ": No such file or directory.*\r\n$gdb_prompt $" {
           fail "$test (file not found)"
           return -1
       }
...
triggers on the message about raise.c, while it is intended to catch:
...
$ gdb
(gdb) core bla
/home/vries/bla: No such file or directory.
...

Fix this by making the regexp more precise:
...
-       -re ": No such file or directory.*\r\n$gdb_prompt $" {
+       -re "$core: No such file or directory.*\r\n$gdb_prompt $" {
...

Tested on x86_64-linux.

Also tested the test-case with this patch in place to verify that the regexp
still triggers:
...
-       set core_loaded [gdb_core_cmd $corefile $test]
+       set core_loaded [gdb_core_cmd $corefile/bla $test]
...

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (gdb_core_cmd): Make "No such file or directory" regexp
	more precise.
2020-03-12 09:50:04 +01:00
Alan Modra 8fb879cd16 asan: readelf leaks
* readelf.c (process_section_headers): Don't just set
	filedata->section_headers NULL, free it first.  Similarly for
	dynamic_symbols, dynamic_strings, dynamic_syminfo and
	symtab_shndx_list.  Zero associated counts too.
	(process_object): Free symtab_shndx_list.
	(process_file): Free various allocated filedata tables.
2020-03-12 17:00:40 +10:30
Kevin Buettner dd69bf7a78 Avoid infinite recursion in find_pc_sect_line
A patch somewhat like this patch has been in Fedora GDB for well over
a decade.  The Fedora patch was written by Jan Kratochvil.  The Fedora
version prints a warning and attempts to continue.  This version will
error out, fatally.  An earlier version of this patch was more like
the Fedora version than this one.  Simon Marchi recommended use of an
assertion to test for the infinite recursion; I decided to use an
explicit test (with an "if" statement) along with a call to
internal_error() if the condition is met.  This way, I could include
a plea to file a bug report.

It was motivated by a customer reported bug (back in 2006!) which
showed infinite mutual recursion between find_pc_sect_line and
find_pc_line.  Here is a portion of the backtrace from the bug report:

    (gdb) bt
    #0  0x00000000004450a4 in lookup_minimal_symbol_by_pc_section (
	pc=251700325328, section=0x570f500) at gdb/minsyms.c:484
    #1  0x00000000004bbfb2 in find_pc_sect_line (pc=251700325328,
	section=0x570f500, notcurrent=0) at gdb/symtab.c:2057
    #2  0x00000000004bc480 in find_pc_line (pc=251700325328, notcurrent=0)
	at gdb/symtab.c:2232
    #3  0x00000000004bc1ff in find_pc_sect_line (pc=251700325328,
	section=0x570f500, notcurrent=0) at gdb/symtab.c:2081

    ...   (lots and lots of the same two functions with the same parameters)

    #1070 0x00000000004bc480 in find_pc_line (pc=251700325328, notcurrent=0)
	at gdb/symtab.c:2232
    #1071 0x00000000004bc1ff in find_pc_sect_line (pc=251700325328,
	section=0x570f500, notcurrent=0) at gdb/symtab.c:2081
    #1072 0x00000000004bc480 in find_pc_line (pc=251700325328, notcurrent=0)
	at gdb/symtab.c:2232
    #1073 0x00000000004bc1ff in find_pc_sect_line (pc=251700325328,
	section=0x570f500, notcurrent=0) at gdb/symtab.c:2081
    #1074 0x00000000004bc480 in find_pc_line (pc=251700325328, notcurrent=0)
	at gdb/symtab.c:2232
    #1075 0x00000000004bc1ff in find_pc_sect_line (pc=251696794399,
	section=0x59b0df8, notcurrent=0) at gdb/symtab.c:2081
    #1076 0x00000000004bc480 in find_pc_line (pc=251696794399, notcurrent=0)
	at gdb/symtab.c:2232
    #1077 0x000000000055550e in find_frame_sal (frame=0xb3f3e0, sal=0x7fff1d1a8200)
	at gdb/frame.c:1392
    #1078 0x00000000004d86fd in set_current_sal_from_frame (frame=0x1648, center=1)
	at gdb/stack.c:379
    #1079 0x00000000004cf137 in normal_stop () at gdb/infrun.c:3147
    ...

The test case was a large application.  Attempts were made to make a
small(er) test case, but those attempts were not successful.
Therefore, I cannot provide a new test for this patch.

That said, we ought to guard against recursively calling
find_pc_sect_line (via find_pc_line) with the identical PC value that
it had been called with.  Should this happen, infinite recursion (as
shown in the above backtrace) is the result.  This patch prevents
that from happening.

If this should happens, there is a bug somewhere, perhaps in GDB, perhaps
in some other part of the toolchain or a library.  We error out fatally
with a message briefly describing the condition along with a plea to file
a bug report.

I spent some time looking at the surrounding code and commentary which
handle the case of PC being in a stub/trampoline.  It first appeared
in the public GDB repository in April, 1999.  The ChangeLog entry for
this commit is from 1998-12-31.  The relevant portion is:

	(find_pc_sect_line): Return correct information if pc is in import
	or export stub (trampoline).

What's remarkable about the overall ChangeLog entry is that it's over
2500+ lines long!  I believe that this was part of the infamous "HP
merge" (in which insufficient due diligence was given in accepting
a large batch of changes from an outside source).  In the years that
followed, much of this code was either significantly revised or
outright removed.

For this particular case, I'm grateful that extensive comments were
provided by "RT".  (I haven't been able to figure out who RT is/was.)
I've decided against attempting to revise this stub/trampoline handling
code any further than adding Jan's test which prevents an obvious case
of infinite recursion.

I've tested on Fedora 31, x86-64.  I see no regressions.  I've also
searched the logfile for the new message, but as expected, no message
was found (which is good).

gdb/ChangeLog:

	* symtab.c (find_pc_sect_line): Add check which prevents infinite
	recursion.

Change-Id: I595470be6ab5f61ca7e4e9e70c61a252c0deaeaa
2020-03-11 22:56:51 -07:00
Simon Marchi 038b97fcd7 testsuite: use `pwd -W` to convert from Unix to Windows paths
When on a MinGW host, standard_output_file uses a regular expression to
convert Unix-style paths of the form "/c/foo" to "c:/foo".  This is
needed because the paths we pass to GDB (for example, with the "file"
command) need to be in the Windows form.

However, the regexp only works if your binutils-gdb repo is under a
`/[a-z]/...` path (the Unix paths mapping to Windows drives).
Presumably, that works if you clone the repo in Windows, then access it
through `/c/...`.

In my case, I've cloned the repository directly inside my MinGW shell,
so in /home/smarchi.  The regexp therefore doesn't work for me.  The
path doesn't get transformed, and the file command fails when running
any test:

    (gdb) file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent
    /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent: No such file or directory.

A safer way to do this is to execute `pwd -W` while in the directory we
want the path for, this is what this patch does.

I have also considered using the using the cygpath utility to do the
conversion.  It can be used to convert any MinGW path into its Windows
equivalent.  Despite originally coming from Cygwin, the cygpath utility
is distributed by MinGW-w64 and can be used in that environment.
However, it's not distributed with the non-MinGW-w64 MinGW.

The `pwd -W` trick only works with directories that exist, which is the
case here, so it's sufficient.

With this, the file command in the test succeeds:

    (gdb) file C:/msys64/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent
    Reading symbols from C:/msys64/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent...

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (standard_output_file): Use `pwd -W` to convert
	from Unix to Windows path.
2020-03-11 15:21:19 -04:00
Simon Marchi a0761e34f0 gdb: enable -Wmissing-prototypes warning
While compiling with clang, I noticed it didn't catch cases where my
function declaration didn't match my function definition.  This is
normally caught by gcc with -Wmissing-declarations.

On clang, this is caught by -Wmissing-prototypes instead.

Note that on gcc, -Wmissing-prototypes also exists, but is only valid
for C and Objective-C.  It gets correctly rejected by the configure
script since gcc rejects it with:

    cc1plus: error: command line option '-Wmissing-prototypes' is valid for C/ObjC but not for C++ -Werror

So this warning flag ends up not used for gcc (which is what we want).

gdb/ChangeLog:

	* configure: Re-generate.

gdbserver/ChangeLog:

	* configure: Re-generate.

gdbsupport/ChangeLog:

	* configure: Re-generate.
	* warning.m4: Enable -Wmissing-prototypes.
2020-03-11 15:15:12 -04:00
Tom de Vries 5308d1e771 [gdb/testsuite] Set language in gdb.ada/minsym.exp
When building gdb using configure flag
--with-separate-debug-dir=/usr/lib/debug, and running test-case
gdb.ada/minsyms.exp, I run into:
...
(gdb) PASS: gdb.ada/minsyms.exp: print some_minsym
print integer(some_minsym)^M
A syntax error in expression, near `some_minsym)'.^M
(gdb) FAIL: gdb.ada/minsyms.exp: print integer(some_minsym)
...
and 2 other FAILs.

This is due to the fact that the language after arriving at the ada main
function turns out to be auto/c.  [ This has been filed as PR25655 -
"Language is not auto/ada in main ada function for exec without debug info". ]

When building gdb without the configure flag mentioned above, we have instead
auto/ada in the ada main function, and all tests pass.

Fix the FAILs by working around PR25655 in the test-case, and manually setting
the language to ada.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-11  Tom de Vries  <tdevries@suse.de>

	* gdb.ada/minsyms.exp: Set language to ada.
2020-03-11 19:37:01 +01:00
H.J. Lu 9e8f1c9000 NEWS: Mention x86 assembler options for CVE-2020-0551
* NEWS: Mention x86 assembler options for CVE-2020-0551.
2020-03-11 09:57:35 -07:00
Tom de Vries f870f78fb2 [gdb/testsuite] Fix printf regexp in gdb.server/sysroot.exp
When running gdb.server/sysroot.exp, I run into this FAIL:
...
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2, __printf (format=0x4005c4 "Hello World!\n") at printf.c:28^M
28      {^M
(gdb) FAIL: gdb.server/sysroot.exp: sysroot=local: continue to printf
...
for this test:
...
    gdb_test "continue" "Breakpoint $decimal.* printf .*" "continue to printf"
...

Without debug info for glibc installed, we have instead:
...
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2, 0x00007ffff773c550 in printf () from /lib64/libc.so.6^M
(gdb) PASS: gdb.server/sysroot.exp: sysroot=local: continue to printf
...

Fix this by allowing for GLIBC's printf alias __printf to be printed:
...
    gdb_test "continue" "Breakpoint $decimal.* (__)?printf .*" \
      "continue to printf"
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-11  Tom de Vries  <tdevries@suse.de>

	* gdb.server/sysroot.exp: Allow GLIBC's printf alias __printf.
2020-03-11 17:57:02 +01:00
H.J. Lu 97b4a8f744 i386: Add tests for lfence with load/indirect branch/ret
Add tests for -mlfence-after-load=, -mlfence-before-indirect-branch=
and -mlfence-before-ret=.

	* testsuite/gas/i386/i386.exp: Run new tests.
	* testsuite/gas/i386/lfence-byte.d: New file.
	* testsuite/gas/i386/lfence-byte.e: Likewise.
	* testsuite/gas/i386/lfence-byte.s: Likewise.
	* testsuite/gas/i386/lfence-indbr-a.d: Likewise.
	* testsuite/gas/i386/lfence-indbr-b.d: Likewise.
	* testsuite/gas/i386/lfence-indbr-c.d: Likewise.
	* testsuite/gas/i386/lfence-indbr.e: Likewise.
	* testsuite/gas/i386/lfence-indbr.s: Likewise.
	* testsuite/gas/i386/lfence-load.d: Likewise.
	* testsuite/gas/i386/lfence-load.s: Likewise.
	* testsuite/gas/i386/lfence-ret-a.d: Likewise.
	* testsuite/gas/i386/lfence-ret-b.d: Likewise.
	* testsuite/gas/i386/lfence-ret.s: Likewise.
	* testsuite/gas/i386/x86-64-lfence-byte.d: Likewise.
	* testsuite/gas/i386/x86-64-lfence-byte.e: Likewise.
	* testsuite/gas/i386/x86-64-lfence-byte.s: Likewise.
	* testsuite/gas/i386/x86-64-lfence-indbr-a.d: Likewise.
	* testsuite/gas/i386/x86-64-lfence-indbr-b.d: Likewise.
	* testsuite/gas/i386/x86-64-lfence-indbr-c.d: Likewise.
	* testsuite/gas/i386/x86-64-lfence-indbr.e: Likewise.
	* testsuite/gas/i386/x86-64-lfence-indbr.s: Likewise.
	* testsuite/gas/i386/x86-64-lfence-load.d: Likewise.
	* testsuite/gas/i386/x86-64-lfence-load.s: Likewise.
	* testsuite/gas/i386/x86-64-lfence-ret-a.d: Likewise.
	* testsuite/gas/i386/x86-64-lfence-ret-b.d: Likewise.
2020-03-11 09:49:13 -07:00
H.J. Lu ae531041c7 i386: Generate lfence with load/indirect branch/ret [CVE-2020-0551]
Add 3 command-line options to generate lfence for load, indirect near
branch and ret to help mitigate:

https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00334.html
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-0551

1. -mlfence-after-load=[no|yes]:
  -mlfence-after-load=yes generates lfence after load instructions.
2. -mlfence-before-indirect-branch=[none|all|memory|register]:
  a. -mlfence-before-indirect-branch=all generates lfence before indirect
  near branches via register and a warning before indirect near branches
  via memory.
  b. -mlfence-before-indirect-branch=memory issue a warning before
  indirect near branches via memory.
  c. -mlfence-before-indirect-branch=register generates lfence before
  indirect near branches via register.
Note that lfence won't be generated before indirect near branches via
register with -mlfence-after-load=yes since lfence will be generated
after loading branch target register.
3. -mlfence-before-ret=[none|or|not]
  a. -mlfence-before-ret=or generates or with lfence before ret.
  b. -mlfence-before-ret=not generates not with lfence before ret.

A warning will be issued and lfence won't be generated before indirect
near branch and ret if the previous item is a prefix or a constant
directive, which may be used to hardcode an instruction, since there
is no clear instruction boundary.

	* config/tc-i386.c (lfence_after_load): New.
	(lfence_before_indirect_branch_kind): New.
	(lfence_before_indirect_branch): New.
	(lfence_before_ret_kind): New.
	(lfence_before_ret): New.
	(last_insn): New.
	(load_insn_p): New.
	(insert_lfence_after): New.
	(insert_lfence_before): New.
	(md_assemble): Call insert_lfence_before and insert_lfence_after.
	Set last_insn.
	(OPTION_MLFENCE_AFTER_LOAD): New.
	(OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH): New.
	(OPTION_MLFENCE_BEFORE_RET): New.
	(md_longopts): Add -mlfence-after-load=,
	-mlfence-before-indirect-branch= and -mlfence-before-ret=.
	(md_parse_option): Handle -mlfence-after-load=,
	-mlfence-before-indirect-branch= and -mlfence-before-ret=.
	(md_show_usage): Display -mlfence-after-load=,
	-mlfence-before-indirect-branch= and -mlfence-before-ret=.
	(i386_cons_align): New.
	* config/tc-i386.h (i386_cons_align): New.
	(md_cons_align): New.
	* doc/c-i386.texi: Document -mlfence-after-load=,
	-mlfence-before-indirect-branch= and -mlfence-before-ret=.
2020-03-11 09:46:19 -07:00
Tom de Vries 5a13315d1c [gdb/testsuite] Fix stepi pattern in gdb.btrace/reconnect.exp
When running gdb.btrace/reconnect.exp, I run into the follow FAIL:
...
(gdb) stepi 19^M
0x00007ffff7dd8b67      59        return (ElfW(Addr)) &_DYNAMIC - \
  elf_machine_dynamic ();^M
(gdb) FAIL: gdb.btrace/reconnect.exp: first: stepi 19
...

The corresponding test looks like:
...
  gdb_test "stepi 19" "0x.* in .* from .*"
...
which matches the usual:
...
(gdb) stepi 19^M
0x00007ffff7dd8b67 in _dl_start () from target:/lib64/ld-linux-x86-64.so.2^M
(gdb) PASS: gdb.btrace/reconnect.exp: first: stepi 19
...
which I also get when removing configure flag
--with-separate-debug-dir=/usr/lib/debug.

Fix this by allowing the source line pattern in the test regexp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-11  Tom de Vries  <tdevries@suse.de>

	* gdb.btrace/reconnect.exp: Allow source line pattern after stepi.
2020-03-11 16:51:54 +01:00
Tom Tromey e7a82140af Fix comment in ada-typeprint.c
A comment in ada-typeprint.c mentions the Unchecked_Variant pragma.
However, this does not exist, and the comment should actually mention
Unchecked_Union.

gdb/ChangeLog
2020-03-11  Tom Tromey  <tromey@adacore.com>

	* ada-typeprint.c (print_choices): Fix comment.
2020-03-11 08:29:51 -06:00
Tom Tromey 976862ed56 Mark discriminants as artificial in gdb.dwarf2/variant.exp
While working on a variant part patch, I notcied that
gdb.dwarf2/variant.exp does not mark the discriminant members as
DW_AT_artificial.  However, it should, as this is what the real Rust
compiler does, and how the Rust language support is supposed to work.

gdb/testsuite/ChangeLog
2020-03-11  Tom Tromey  <tromey@adacore.com>

	* gdb.dwarf2/variant.exp: Mark discriminants as artificial.
2020-03-11 07:59:37 -06:00
Tom de Vries 7462c383f9 [gdb/testsuite] Fix FAILs due to verbose in foll-fork.exp
When running test-case gdb.base/foll-fork.exp, I see:
...
(gdb) catch fork^M
Catchpoint 2 (fork)^M
Reading in symbols for ../sysdeps/x86/libc-start.c...^M
(gdb) FAIL: gdb.base/foll-fork.exp: explicit child follow, set catch fork
...

The problem is that the test regexp does not expect the "Reading in symbols"
message:
...
    gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" \
        "explicit child follow, set catch fork"
...
which is generated due to the verbose setting.

Fix this by allowing the message in the regexp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-11  Tom de Vries  <tdevries@suse.de>

	* gdb.base/foll-fork.exp: Allow "Reading in symbols" messages.
2020-03-11 14:58:59 +01:00
Tom de Vries 1c6c46a012 [gdb/testsuite] Limit verbose scope in gdb.base/break-interp.exp
I'm running into the following failure (and 17 more like it) in
gdb.base/break-interp.exp:
...
 (gdb) bt^M
 #0  0x00007fde85a3b0c1 in __GI___nanosleep \
   (requested_time=requested_time@entry=0x7ffe5044ee70, \
   remaining=remaining@entry=0x7ffe5044ee70) at nanosleep.c:27^M
 #1  0x00007fde85a3affa in __sleep (seconds=0) at sleep.c:55^M
 #2  0x00007fde8606789c in libfunc (Reading in symbols for libc-start.c...^M
 action=0x7ffe5044fa12 "sleep") at gdb.base/break-interp-lib.c:41^M
 #3  0x0000000000400708 in main ()^M
 Reading in symbols for ../sysdeps/x86_64/start.S...^M
 (gdb) FAIL: gdb.base/break-interp.exp: LDprelinkNOdebugNO: \
   BINprelinkNOdebugNOpieNO: INNER: attach: attach main bt
...

The problem is that the test uses verbose mode to detect the "PIE (Position
Independent Executable) displacement" messages, but the verbose mode also
triggers "Reading in symbols for" messages, which may appear in the middle of
a backtrace (or not, depending on whether debug info is available).

[ In fact, the messages appear in the middle of a backtrace line, which is
PR25613. ]

Fix these FAILs by limiting the scope of verbose to the parts of the test that
need it.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-11  Tom de Vries  <tdevries@suse.de>

	* gdb.base/break-interp.exp: Limit verbose scope.
2020-03-11 14:25:02 +01:00
Alan Modra 8248d21a5b asan: som: unknown read
* som.c (setup_sections): Sanity check subspace.name.
2020-03-11 23:02:51 +10:30