Commit Graph

101689 Commits

Author SHA1 Message Date
Rainer Orth 7f20433998 Remove unused ps_lgetLDT etc. on Solaris/x86 [PR25981]
As reported in PR build/25981, a future Solaris 11.4 update will soon
remove the short i386 register names like SS etc. from <sys/regset.h>.
They could leak into user code (e.g. via <signal.h> -> <sys/signal.h> ->
<sys/ucontext.h>) and pollute the user namespace.  Affected code would
have a hard time avoiding the issue: LLVM is one of those.

While the short names are required to be present by the i386 psABI, that
document only demands that they exist in <ucontext.h>, which is what the
upcoming update assures.

With this change, in a 64-bit-default configuration, procfs.c fails to
compile on Solaris/x86:

/vol/src/gnu/gdb/hg/master/git/gdb/procfs.c: In function 'ssd* procfs_find_LDT_entry(ptid_t)':
/vol/src/gnu/gdb/hg/master/git/gdb/procfs.c:1643:18: error: 'GS' was not declared in this scope
 1643 |   key = (*gregs)[GS] & 0xffff;
      |                  ^~
make[2]: *** [Makefile:1607: procfs.o] Error 1

Initially I meant to provide a definition using the planned replacement
macro, but closer inspection revealed a better way.  procfs_find_LDT_entry
and its helper proc_get_LDT_entry are only used to implement ps_lgetLDT,
one of the callback functions required by libthread_db.so.1
(cf. <proc_service.h>).  While that function is still documented as being
required even in Solaris 11.4, I found that calls to it had been removed
long ago in Solaris 9, so just removing the three functions above is the
easiest fix.

The following patch does just that.  It compiled successfully on
amd64-pc-solaris2.11, however, as reported in PR gdb/25939, master is
completely broken on Solaris since the multi-target patch.  The patch
applies cleanly to the gdb-9 branch and there I could test it
successfully.

	PR build/25981
	* procfs.c [(__i386__ || __x86_64__) && sun] (proc_get_LDT_entry,
	procfs_find_LDT_entry): Remove.
	* procfs.h [(__i386__ || __x86_64__) && sun] (struct ssd,
	procfs_find_LDT_entry): Remove.
	* sol-thread.c [(__i386__ || __x86_64__) && sun] (ps_lgetLDT):
	Remove.
2020-05-18 17:56:00 +02:00
Nick Clifton ed02cdb5b7 Fix a use-after-free bug in the BFD library when scanning a corrupt ELF file.
PR 26005
	* elf.c (bfd_section_from_shdr): Use bfd_malloc to allocate memory
	for the sections_being_created array.
2020-05-18 15:52:03 +01:00
Tom de Vries 1d72769534 [gdb/testsuite] Use with_test_prefix in gdb.base/gdb-caching-proc.exp
When running test-case gdb.base/gdb-caching-proc.exp all passes are unique,
but fails might not be.

Fix this by using with_test_prefix.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-18  Tom de Vries  <tdevries@suse.de>

	* gdb.base/gdb-caching-proc.exp: Use with_test_prefix.
2020-05-18 16:33:37 +02:00
Douglas B Rupp 3edf7b9f2c Show AIX gc'd symbol address adjustments in map file
* ldemul.h (ldemul_print_symbol): New.
	(ld_emulation_xfer_type) <print_symbol): Likewise.
	* ldemul.c (ldemul_print_symbol): New.
	* ldlang.c (SECTION_NAME_MAP_LANGTH): Move to ...
	(print_one_symbol): Make global and move declaration to ...
	(print_all_symbols): Rename print_one_symbol to ldemul_print_symbol
	(print_input_section): Likewise
	* ldlang.h: ... here.
	* emultempl/aix.em (gld${EMULATION_NAME}_print_symbol): New.
	(ld_emulation_xfer_struct): Use it.
	* emultempl/armcoff.em (ld_emulation_xfer_struct): Add print_symbol
	and default to NULL.
	* emultempl/beos.em (ld_emulation_xfer_struct): Likewise
	* emultempl/elf.em (ld_emulation_xfer_struct): Likewise
	* emultempl/generic.em (ld_emulation_xfer_struct): Likewise
	* emultempl/linux.em (ld_emulation_xfer_struct): Likewise
	* emultempl/msp430.em (ld_emulation_xfer_struct): Likewise
	* emultempl/pe.em (ld_emulation_xfer_struct): Likewise
	* emultempl/pep.em (ld_emulation_xfer_struct): Likewise
	* emultempl/ticoff.em (ld_emulation_xfer_struct): Likewise
	* emultempl/vanilla.em (ld_emulation_xfer_struct): Likewise
2020-05-18 22:41:32 +09:30
Sergei Trofimovich 6e0c75f7c4 [PATCH] ld: fix s/claimi/claim/ typo
* ldmain.c (add_archive_element): Fix s/claimi/claim/ typo
	in info message.
2020-05-18 13:51:23 +01:00
Nick Clifton e6ddf2af20 Updated translations for the gprof and ld sub-directories 2020-05-18 13:47:11 +01:00
Alan Modra 7a87e9c805 ECOFF slurp_relocs thinko
In git commit 806470a219 I swapped the order of internal vs. external
relocs memory allocation in ecoff_slurp_reloc_table, the idea being
that the external reloc size can be sanity checked against file size.
However, that fails badly with bfd_alloc memory where releasing any
block also releases all more recently allocated blocks.

	* ecoff.c (ecoff_slurp_reloc_table): Malloc external_relocs so
	they can be freed without also freeing internal_relocs.
2020-05-18 20:56:39 +09:30
Jaydeep Chauhan ca859a8939 Fix the BFD library to handle Windows pathnames with more than 260 characters and UNIX style directory separators.
PR 25713
	* bfdio.c (_bfd_real_fopen): Convert UNIX style sirectory
	separators into DOS style when creating a WIN32 fullpath.
2020-05-18 11:36:26 +01:00
Nick Clifton 5e365e474b Prevent a potential use-after-fee memory corruption bug in the linker (for PE format files).
PR 25993
	* emultempl/pe.em (_after_open): Check for duplicate filename
	pointers before renaming the dll.
	* emultempl/pep.em (_after_open): Likewise.
2020-05-18 10:28:52 +01:00
Alan Modra d402189f2f Re: Fix tight loop on recursively-defined symbols
sy_resolving ought to not be set for a struct local_symbol, but it is
apparent from local_symbol_make that the field is not initialised.

	* symbols.c (resolve_symbol_value): Invoke LOCAL_SYMBOL_CHECK
	before looking at add_symbol->sy_flags.sy_resolving.
2020-05-18 13:46:27 +09:30
liuhongt 503648e41e Don't handle lret/iret when -mlfence-before-ret=[or|not|shl|yes] since they are invalid in SGX enclaves.
gas/ChangeLog
	* gas/config/tc-i386.c: Not handle lret/iret.
	* gas/testsuite/gas/i386/lfence-ret-a.d: Adjust testcase.
	* gas/testsuite/gas/i386/lfence-ret-b.d: Ditto.
	* gas/testsuite/gas/i386/lfence-ret-c.d: Ditto.
	* gas/testsuite/gas/i386/lfence-ret-d.d: Ditto.
	* gas/testsuite/gas/i386/lfence-ret.s: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-a.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-b.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-c.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-d.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-e.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret.s: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret.e: Deleted.
2020-05-18 10:23:59 +08:00
GDB Administrator 07a78c5956 Automatic date update in version.in 2020-05-18 00:00:14 +00:00
Stafford Horne 83d27139ca binutils: Add myself as maintainer for OpenRISC
binutils/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

	* MAINTAINERS (OR1K): Add myself as maintainer.
2020-05-18 05:27:13 +09:00
Pedro Alves 7f32a4d5ae Stop considering hw and sw breakpoint locations duplicates (PR gdb/25741)
In the following conditions:

  - A target with hardware breakpoints available, and
  - A target that uses software single stepping,
  - An instruction at ADDRESS loops back to itself,

Now consider the following steps:

  1. The user places a hardware breakpoint at ADDRESS (an instruction
  that loops to itself),

  2. The inferior runs and hits the breakpoint at ADDRESS,

  3. The user tells GDB to 'continue'.

In #3 when the user tells GDB to continue, GDB first disables the
hardware breakpoint at ADDRESS, and then inserts a software
single-step breakpoint at ADDRESS.  The original user-created
breakpoint was a hardware breakpoint, while the single-step breakpoint
will be a software breakpoint.

GDB continues and immediately hits the software single-step
breakpoint.

GDB then deletes the software single-step breakpoint by calling
delete_single_step_breakpoints, which eventually calls
delete_breakpoint, which, once the breakpoint (and its locations) are
deleted, calls update_global_location_list.

During update_global_location_list GDB spots that we have an old
location (the software single step breakpoint location) that is
inserted, but being deleted, and a location (the original hardware
breakpoint) at the same address which we are keeping, but which is not
currently inserted, GDB then calls breakpoint_locations_match on these
two locations.

Currently the locations do match, and so GDB calls swap_insertion
which swaps the "inserted" state of the two locations.  The user
created hardware breakpoint is marked as inserted, while the GDB
internal software single step breakpoint is now marked as not
inserted.  After this GDB returns through the call stack and leaves
delete_single_step_breakpoints.

After this GDB continues with its normal "stopping" process, as part
of this stopping process GDB removes all the breakpoints from the
target.  Due to the swap it is now the user-created hardware
breakpoint that is marked as inserted, so it is this breakpoint GDB
tries to remove.

The problem is that GDB inserted the software single-step breakpoint
as a software breakpoint, but is now trying to remove the hardware
breakpoint.  The problem is removing a software breakpoint is very
different to removing a hardware breakpoint, this could result is some
undetected undefined behaviour, or as in the original bug report (PR
gdb/25741), could result in the target throwing an error.

With "set breakpoint always-inserted on", we can easily reproduce this
against GDBserver.  E.g.:

  (gdb) hbreak main
  Sending packet: $m400700,40#28...Packet received: 89e58b....
  Sending packet: $m400736,1#fe...Packet received: 48
  Hardware assisted breakpoint 1 at 0x400736: file threads.c, line 57.
  Sending packet: $Z1,400736,1#48...Packet received: OK
  Packet Z1 (hardware-breakpoint) is supported

  (gdb) b main
  Note: breakpoint 1 also set at pc 0x400736.
  Sending packet: $m400736,1#fe...Packet received: 48
  Breakpoint 2 at 0x400736: file threads.c, line 57.

  (gdb) del
  Delete all breakpoints? (y or n) y
  Sending packet: $z0,400736,1#67...Packet received: E01
  warning: Error removing breakpoint 2

This patch adds a testcase that does exactly that.

Trying to enhance GDB to handle this scenario while continuing to
avoid inserting redundant software and hardware breakpoints at the
same address turns out futile, because, given non-stop and breakpoints
always-inserted, if the user:

 #1 - inserts a hw breakpoint, then
 #2 - inserts a sw breakpoint at the same address, and then
 #3 - removes the original hw breakpoint,

GDB would have to make sure to insert the sw breakpoint before
removing the hw breakpoint, to avoid running threads missing the
breakpoint.  I.e., there's always going to be a window where a target
needs to be able to handle both sw and a hw breakpoints installed at
the same address.  You can see more detailed description of that issue
here:
https://sourceware.org/pipermail/gdb-patches/2020-April/167738.html

So the fix here is to just stop considering software breakpoints and
hw breakpoints duplicates, and let GDB insert sw and hw breakpoints at
the same address.

The central change is to make breakpoint_locations_match consider the
location's type too.  There are several other changes necessary to
actually make that that work correctly, however:

- We need to handle the duplicates detection better.  Take a look at
  the loop at the tail end of update_global_location_list.  Currently,
  because breakpoint locations aren't sorted by type, we can end up
  with, at the same address, a sw break, then a hw break, then a sw
  break, etc.  The result is that that second sw break won't be
  considered a duplicate of the first sw break.  Seems like we already
  handle that incorrectly for range breakpoints.

- The "set breakpoint auto-hw on" handling is moved out of
  insert_bp_location to update_global_location_list, before the
  duplicates determination.

  Moving "set breakpoint auto-hw off" handling as well and downgrading
  it to a warning+'disabling the location' was considered too, but in
  the end discarded, because we want to error out with internal and
  momentary breakpoints, like software single-step breakpoints.
  Disabling such locations at update_global_location_list time would
  make GDB lose control of the inferior.

- In update_breakpoint_locations, the logic of matching old locations
  with new locations, in the have_ambiguous_names case, is updated to
  still consider sw vs hw locations the same.

- Review all ALL_BP_LOCATIONS_AT_ADDR uses, and update those that
  might need to be updated, and update comments for those that don't.
  Note that that macro walks all locations at a given address, and
  doesn't call breakpoint_locations_match.

The result against GDBserver (with "set breakpoint
condition-evaluation host" to avoid seeing confusing reinsertions) is:

 (gdb) hbreak main
 Sending packet: $m400736,1#fe...Packet received: 48
 Hardware assisted breakpoint 1 at 0x400736: file main.c, line 57.
 Sending packet: $Z1,400736,1#48...Packet received: OK

 (gdb) b main
 Note: breakpoint 1 also set at pc 0x400736.
 Sending packet: $m400736,1#fe...Packet received: 48
 Breakpoint 4 at 0x400736: file main.c, line 57.
 Sending packet: $Z0,400736,1#47...Packet received: OK

 (gdb) del 3
 Sending packet: $z1,400736,1#68...Packet received: OK

gdb/ChangeLog:
2020-05-17  Pedro Alves  <palves@redhat.com>
	    Andrew Burgess  <andrew.burgess@embecosm.com>
	    Keno Fischer  <keno@juliacomputing.com>

	PR gdb/25741
	* breakpoint.c (build_target_condition_list): Update comments.
	(build_target_command_list): Update comments and skip matching
	locations.
	(insert_bp_location): Move "set breakpoint auto-hw on" handling to
	a separate function.  Simplify "set breakpoint auto-hw off"
	handling.
	(insert_breakpoints): Update comment.
	(tracepoint_locations_match): New parameter.  For breakpoints,
	compare location types too, if the caller wants to.
	(handle_automatic_hardware_breakpoints): New functions.
	(bp_location_is_less_than): Also sort by location type and
	hardware breakpoint length.
	(update_global_location_list): Handle "set breakpoint auto-hw on"
	here.
	(update_breakpoint_locations): Ask breakpoint_locations_match to
	ignore location types.

gdb/testsuite/ChangeLog:
2020-05-17  Pedro Alves  <palves@redhat.com>

	PR gdb/25741
	* gdb.base/hw-sw-break-same-address.exp: New file.
2020-05-17 19:17:56 +01:00
GDB Administrator 966dc1a27c Automatic date update in version.in 2020-05-17 00:00:06 +00:00
Pedro Alves 7cfd74cfc6 Fix gdb.multi/multi-re-run.exp with native-gdbserver
The new exec-file-mismatch feature reveals that when running
gdb.multi/multi-re-run.exp against --target_board=native-gdbserver,
we've been starting gdbserver with the wrong program:

 (gdb) spawn /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/../../gdbserver/gdbserver --once localhost:2347 /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/te
 stsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2
 Process /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2 created; pid = 6280
 Listening on port 2347
 target remote localhost:2347
 Remote debugging using localhost:2347
 warning: Mismatch between current exec-file /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-1
 and automatically determined exec-file /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2
 exec-file-mismatch handling is currently "ask"
 Load new symbol table from "/home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2"? (y or n) Quit
 (gdb) FAIL: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=1: running to all_started in runto

The problem is that gdb_reload uses the last loaded file as binary to
spawn, but we load the program for inferior 2 and then switch to
inferior 1 and run it, so the last loaded file is the program for
inferior 2.

Fix this by tweaking last_loaded_file.

gdb/testsuite/ChangeLog:
2020-05-16  Pedro Alves  <palves@redhat.com>

	* gdb.multi/multi-re-run.exp (test_re_run): Switch
	LAST_LOADED_FILE accordingly.
2020-05-16 18:59:10 +01:00
Simon Marchi 7d93a1e0b6 gdb: remove TYPE_NAME macro
Remove `TYPE_NAME`, changing all the call sites to use `type::name`
directly.  This is quite a big diff, but this was mostly done using sed
and coccinelle.  A few call sites were done by hand.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_NAME): Remove.  Change all cal sites to use
	type::name instead.
2020-05-16 12:36:05 -04:00
Simon Marchi d0e39ea27c gdb: add type::name / type::set_name
Add the `name` and `set_name` methods on `struct type`, in order to
remove the `TYPE_NAME` macro.  In this patch, the `TYPE_NAME` macro is
changed to use `type::name`, so all the call sites that are used to set
the type name are changed to use `type::set_name`.  The next patch will
remove `TYPE_NAME` completely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <name, set_name>: New methods.
	(TYPE_CODE): Use type::name.  Change all call sites used to set
	the name to use type::set_name instead.
2020-05-16 12:36:05 -04:00
Tom Tromey 2dab0c7ba0 Remove ALL_UIS
Continuing my goal of removing the "ALL_*" iterator macros, this
removes ALL_UIS, replacing it with an iterator adaptor.

gdb/ChangeLog
2020-05-16  Tom Tromey  <tom@tromey.com>

	* top.c (quit_force): Update.
	* infrun.c (handle_no_resumed): Update.
	* top.h (all_uis): New function.
	(ALL_UIS): Remove.
2020-05-16 09:58:46 -06:00
Simon Marchi 59f7bd8d2b gdb: fix -Wtautological-overlap-compare warning in mips-linux-tdep.c
When building with clang 11, I get:

  CXX    mips-linux-tdep.o
/home/smarchi/src/binutils-gdb/gdb/mips-linux-tdep.c:643:30: error: overlapping comparisons always evaluate to true [-Werror,-Wtautological-overlap-compare]
      if (insn != 0x03e07821 || insn != 0x03e07825)
          ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/home/smarchi/src/binutils-gdb/gdb/mips-linux-tdep.c:636:30: error: overlapping comparisons always evaluate to true [-Werror,-Wtautological-overlap-compare]
      if (insn != 0x03e0782d || insn != 0x03e07825)
          ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

Indeed, given two different values, `insn` will always be different to
one of them, and these conditions always be true.

This code is meant to return if `insn` isn't one of these two values, so
the `||` should be replaced with `&&`.

gdb/ChangeLog:

	* mips-linux-tdep.c (mips_linux_in_dynsym_stub): Fix condition.
2020-05-16 11:21:41 -04:00
H.J. Lu 56770bdab2 Sync config with GCC
Sync with GCC
	2020-05-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR bootstrap/95147
	* cet.m4 (GCC_CET_FLAGS): Also check if -fcf-protection works
	when defaulting to auto.

	2020-05-14  H.J. Lu  <hongjiu.lu@intel.com>

	* cet.m4 (GCC_CET_FLAGS): Change default to auto.
2020-05-16 06:07:12 -07:00
Pedro Alves 9bf058f094 Fix IA64 GNU/Linux build
This commit should fix:

 ../../gdb/ia64-linux-nat.c: In function ‘void enable_watchpoints_in_psr(ptid_t)’:
 ../../gdb/ia64-linux-nat.c:535:56: error: no matching function for call to ‘get_thread_regcache(ptid_t&)’
    struct regcache *regcache = get_thread_regcache (ptid);
							 ^
 In file included from ../../gdb/ia64-linux-nat.c:25:0:
 ../../gdb/regcache.h:35:25: note: candidate: regcache* get_thread_regcache(process_stratum_target*, ptid_t)
  extern struct regcache *get_thread_regcache (process_stratum_target *target,
			  ^
 ../../gdb/regcache.h:35:25: note:   candidate expects 2 arguments, 1 provided
 ../../gdb/regcache.h:39:25: note: candidate: regcache* get_thread_regcache(thread_info*)
  extern struct regcache *get_thread_regcache (thread_info *thread);
			  ^
 ../../gdb/regcache.h:39:25: note:   no known conversion for argument 1 from ‘ptid_t’ to ‘thread_info*’

gdb/ChangeLog:
2020-05-16  Pedro Alves  <palves@redhat.com>

	* ia64-linux-nat.c
	(ia64_linux_nat_target) <enable_watchpoints_in_psr(ptid_t)>:
	Declare method.
	(enable_watchpoints_in_psr): Now a method of ia64_linux_nat_target.
2020-05-16 12:26:56 +01:00
Tankut Baris Aktemur 8bbf03947d gdbserver/linux-ia64-low: fix a build-breaking typo
During the gdbserver c++'ification refactoring, I apparently made a
typo that broke build in ia64 targets.

gdbserver/ChangeLog:
2020-05-16  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* linux-ia64-low.cc (ia64_target::sw_breakpoint_from_kind):
	Fix incorrect 'gdb_assert_no_reached' to 'gdb_assert_not_reached'.
	(ia64_target::low_breakpoint_at): Ditto.
2020-05-16 10:45:40 +02:00
Simon Marchi 8f86ae1a18 gdb: remove unnecessary struct typedef in sparc64-tdep.c
When building with clang 11, I get:

      CXX    sparc64-tdep.o
    /home/smarchi/src/binutils-gdb/gdb/sparc64-tdep.c:89:15: error: anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here [-Werror,-Wnon-c-typedef-for-linkage]
    typedef struct
                  ^
                   adi_stat_t
    /home/smarchi/src/binutils-gdb/gdb/sparc64-tdep.c:103:16: note: type is not C-compatible due to this default member initializer
      int tag_fd = 0;
                   ^
    /home/smarchi/src/binutils-gdb/gdb/sparc64-tdep.c:111:3: note: type is given name 'adi_stat_t' for linkage purposes by this typedef declaration
    } adi_stat_t;
      ^

The typedef is not needed in C++ anyway, just remove them.

gdb/ChangeLog:

	* sparc64-tdep.c (adi_stat_t): Remove typedef (leaving struct).
	(sparc64_adi_info): Likewise.
2020-05-15 22:17:40 -04:00
GDB Administrator 1c5dd7a572 Automatic date update in version.in 2020-05-16 00:00:09 +00:00
Tom Tromey d6bc0792ed Remove lookup_objfile_from_block
lookup_objfile_from_block mostly duplicates the functionality of
block_objfile, but in a less efficient way.  This patch removes this
function and changes the callers to use block_objfile instead.

Tested by the buildbot.

gdb/ChangeLog
2020-05-15  Tom Tromey  <tom@tromey.com>

	* symtab.c (lookup_language_this, lookup_symbol_aux): Use
	block_objfile.
	(lookup_objfile_from_block): Remove.
	(lookup_symbol_in_block, lookup_symbol_in_static_block)
	(lookup_global_symbol): Use block_objfile.
	* symtab.h (lookup_objfile_from_block): Don't declare.
	* printcmd.c (clear_dangling_display_expressions): Use
	block_objfile.
	* parse.c (operator_check_standard): Use block_objfile.
2020-05-15 16:24:07 -06:00
Tom Tromey 8c14c3a373 Remove allocate_symbol et al
This removes allocate_symbol, allocate_template_symbol, and
initialize_objfile_symbol in favor of changing the default values for
symbol members, and updating the one per-arch caller.

gdb/ChangeLog
2020-05-15  Tom Tromey  <tom@tromey.com>

	* language.c (language_alloc_type_symbol): Set
	SYMBOL_SECTION.
	* symtab.c (initialize_objfile_symbol): Remove.
	(allocate_symbol): Remove.
	(allocate_template_symbol): Remove.
	* dwarf2/read.c (fixup_go_packaging): Use "new".
	(new_symbol): Use "new".
	(read_variable): Don't call initialize_objfile_symbol.  Use
	"new".
	(read_func_scope): Use "new".
	* xcoffread.c (process_xcoff_symbol): Don't call
	initialize_objfile_symbol.
	(SYMBOL_DUP): Remove.
	* coffread.c (process_coff_symbol, coff_read_enum_type): Use
	"new".
	* symtab.h (allocate_symbol, initialize_objfile_symbol)
	(allocate_template_symbol): Don't declare.
	(struct symbol): Add copy constructor.  Change defaults.
	* jit.c (finalize_symtab): Use "new".
	* ctfread.c (ctf_add_enum_member_cb, new_symbol, ctf_add_var_cb):
	Use "new".
	* stabsread.c (patch_block_stabs, define_symbol, read_enum_type)
	(common_block_end): Use "new".
	* mdebugread.c (parse_symbol): Use "new".
	(new_symbol): Likewise.
2020-05-15 16:11:34 -06:00
Philippe Waroquiers 5b4a1a8dbe Update NEWS and documentation for help and apropos changes.
gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Mention changes to help and apropos.

gdb/doc/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Help): Document the help and apropos changes.
	(Aliases): Document new meaning of -a abbreviation flag.
2020-05-15 22:17:46 +02:00
Philippe Waroquiers 57b4f16e49 Ensure class_alias is only used for user-defined aliases.
This commit finally does the (small) change that started this patch
series.

It ensures that the class_alias is only used for user-defined aliases.
So, the few GDB pre-defined aliases that were using the 'class_alias'
class are now using a real help class, typically the class of
the aliased command.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* command.h (enum command_class): Improve comments, document
	that class_alias is for user-defined aliases, give the class
	name for each class, remove unused class_xdb.
	* cli/cli-decode.c (add_com_alias): Document THECLASS intended usage.
	* breakpoint.c (_initialize_breakpoint): Replace class_alias
	by a precise class.
	* infcmd.c (_initialize_infcmd): Likewise.
	* reverse.c (_initialize_reverse): Likewise.
	* stack.c (_initialize_stack): Likewise.
	* symfile.c (_initialize_symfile): Likewise.
	* tracepoint.c (_initialize_tracepoint): Likewise.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/alias.exp: Verify 'help aliases' shows user defined aliases.
2020-05-15 22:17:46 +02:00
Philippe Waroquiers 7c05caf72d Fix/improve 'apropos' output
Similarly to 'help CLASS', apropos possibly shows several
times the same help (for the command and for each of its aliases).

This patch changes 'apropos' so that the help for a command and
all its aliases is shown once.

So, apropos_cmd now skips all aliases/abbreviations, as these are printed
as part of the help of the aliased command.

When 'apropos' prints the help of a command, function 'help_cmd' now
unconditionally print the command name and its possible aliases (as we must
indicate to the user the command/aliases for which the help is printed).

When 'help somecommand' prints the help of a command, if the command is not
aliased, the command name is not printed (to avoid a useless first line), but if
it has aliases, then the command name and all its aliases are now printed.
In addition to provide to the user the choice of the best way to
type a command, it also avoids the strange behaviour that the output
of 'help somealias' does not mention somealias.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.c (apropos_cmd): Produce output for aliases
	when their aliased command is traversed.
	(help_cmd): Add fput_command_names_styled call to
	output command name and aliases when command has an alias.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/help.exp: Test apropos and help for commands
	having aliases.  Fixed comments not starting with an
	upper-case letter or not finishing with a dot.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 3b3aaacba1 Fix/improve 'help CLASS' output
Currently, help CLASS possibly shows several times the same help,
as it shows it once for the command, and once for each alias.

The final objective of this patch series is to have class_alias used only
for user defined aliases, not anymore for aliases predefined by GDB.
The command 'help aliases' will then only show the user defined aliases.
So, the idea is that GDB predefined aliases will be shown together
with their aliased command.

This commit changes 'help CLASS' so that a command is shown once in the output,
with all its aliases.
This ensures:
  * that the user has only to read once the same help text
  * and sees the command and all its aliases in a glance, a.o. allowing
    the user to choose the preferred way (e.g. the shortest one,
    or the most mnemonic one) to type the command.

For example, the old output:
   (gdb) help stack
   ...
   List of commands:

   backtrace -- Print backtrace of all stack frames, or innermost COUNT frames.
   bt -- Print backtrace of all stack frames, or innermost COUNT frames.
   ...
(note that 'where' is not shown in this output)

becomes
   (gdb) help stack
   ...
   List of commands:

   backtrace, where, bt -- Print backtrace of all stack frames, or innermost COUNT frames.
   ...

The output layout chosen is to have the command first, followed by all its
aliases separated by a comma.  Note that the command and alias names are
title-styled.  For sure, other layouts could be discussed, but this one is IMO
readable and compact.

The function 'help_cmd_list' can be simplified by removing the prefix argument,
as the prefixname of a command can now be retrieved in the GDB command tree
structure.

This also fixes the fact that 'help aliases' wrongly shows a long
list of (non-alias) when defining an alias for a prefix command.
For example, after:
    (gdb) alias montre = show
  then
    (gdb) help aliases
  shows hundreds of sub-commands starting with the non aliased command,
  such as:
    montre -- Generic command for showing things about the debugger.
    show ada -- Generic command for showing Ada-specific settings.
    show ada print-signatures -- Show whether the output of formal ...
    ....

'help_cmd_list' is also made static, as it is only used inside cli-decode.c.

Note that the 'help CLASS' is somewhat broken, in the sense that it
sometimes shows too many commands (commands not belonging to CLASS)
and sometimes shows not enough commands (not showing some commands
belonging to CLASS).
For example, 'help breakpoints' shows the command
'disable pretty-printer' and 'disable unwinder', not related to breakpoints.
On the other end, 'help stack' does not show 'disable unwinder'
while 'disable unwinder' is defined in unwinders.py as belonging to class_stack.
Fixing the missing commands is easy to do,
but fixing the excess commands is not straightforward, as many
subcommands have a class 'no_class' or 'all_class'.
Possibly, some of this might be improved/fixed in another patch series.

With this patch series, the 'abbrev flag' has as only remaining purpose
to avoid having the abbreviation alias appearing in the completion list,
so change 'help alias' accordingly.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.h (help_cmd_list): Remove declaration.
	* cli/cli-decode.c (help_cmd_list): Declare as static,
	remove prefix argument, use bool for recurse arg, rework to show the aliases of
	a command together with the command.
	(fput_command_name_styled, fput_command_names_styled): New functions.
	(print_help_for_command): Remove prefix arg, use bool for recurse arg, use
	fput_command_name_styled.
	(help_list, help_all): Update callers to remove prefix arg and use bool recurse.
	* cli/cli-cmds.c (_initialize_cli_cmds): Update alias_command doc.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/alias.exp: Update help output check.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 7aa1b46f43 Fix inconsistent output of prefix and bugs in 'show' command
cmd_show_list function implements the 'show' command.

cmd_show_list output is inconsistent: it sometimes shows a prefix
and sometimes does not.
For example, in the below, you see that there is a prefix before
each value, except for 'enabled'.

    (gdb) show style
    style address background:  The "address" style background color is: none
    style address foreground:  The "address" style foreground color is: blue
    style address intensity:  The "address" style display intensity is: normal
    enabled:  CLI output styling is enabled.
    style filename background:  The "filename" style background color is: none
    ...

There are other inconsistencies or bugs e.g. in
the below we see twice insn-number-max, once with a prefix
and once without prefix : last line, just before the value of
instruction-history-size which is itself without prefix.

    (gdb) show record
    record btrace bts buffer-size:  The record/replay bts buffer size is 65536.
    record btrace cpu:  btrace cpu is 'auto'.
    record btrace pt buffer-size:  The record/replay pt buffer size is 16384.
    record btrace replay-memory-access:  Replay memory access is read-only.
    record full insn-number-max:  Record/replay buffer limit is 200000.
    record full memory-query:  Whether query if PREC cannot record memory change of next instruction is off.
    record full stop-at-limit:  Whether record/replay stops when record/replay buffer becomes full is on.
    function-call-history-size:  Number of functions to print in "record function-call-history" is 10.
    insn-number-max:  instruction-history-size:  Number of instructions to print in "record instruction-history" is 10.
    (gdb)

Also, some values are output several times due to some aliases, so avoid outputting duplicated
values by skipping all aliases.

Now that the command structure has a correct 'back-pointer' from a command
to its prefix command, we can simplify cmd_show_list by removing its prefix argument
and at the same time fix the output inconsistencies and bugs.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-setshow.h (cmd_show_list): Remove prefix argument.
	* cli/cli-decode.c (do_show_prefix_cmd): Likewise.
	* command.h (cmd_show_list): Likewise.
	* dwarf2/index-cache.c (show_index_cache_command): Likewise.
	* cli/cli-setshow.c (cmd_show_list): Use the prefix to produce the output.  Skip aliases.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/default.exp: Update output following fixes.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 89bcba74f8 command-def-selftests.c: detect missing or wrong prefix cmd in subcommands.
This test revealed a number of problems that are fixed in the previous commit.

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* unittests/command-def-selftests.c (traverse_command_structure):
	Verify all commands of a list have the same prefix command and
	that only the top cmdlist commands have a null prefix.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 3f4d92ebdf Fix the problems reported by prefix check of command-def-selftests.c
The next commit updates command-def-selftests.c to detect missing
or wrong prefix commands in a list of subcommands.
This command structure selftest detects a series of problems
that are fixed by this commit.

Many commands have a null prefix command, e.g.
    (gdb) maintenance selftest command_str
    Running selftest command_structure_invariants.
    list 0x560417949cb8 reachable via prefix 'append binary '.  command 'memory' has null prefixcmd
    list 0x560417949cb8 reachable via prefix 'append binary '.  command 'value' has null prefixcmd
    ...

Most of these are fixed by the following changes:
  * do_add_cmd searches the prefix command having the list
    in which the command is added.
    This ensures that a command defined after its prefix command
    gets the correct prefix command.
  * Due to the GDB initialization order, a GDB file can define
    a subcommand before the prefix command is defined.
    So, have add_prefix_cmd calling a new recursive function
    'update_prefix_field_of_prefix_commands' to set the prefix
    command of all sub-commands that are now reachable from
    this newly defined prefix command.  Note that this recursive
    call replaces the function 'set_prefix_cmd' that was providing
    a partial solution to this problem.

Following that, 2 python commands (defined after all the other GDB
commands) got a wrong prefix command, e.g. "info frame-filter" has
as prefix command the "i" alias of "info".  This is fixed by having
lookup_cmd_for_prefixlist returning the aliased command rather than
the alias.

After that, one remaining problem:
    (gdb) maintenance selftest command_str
    Running selftest command_structure_invariants.
    list 0x55f320272298 reachable via prefix 'set remote '.  command 'system-call-allowed' has null prefixcmd
    Self test failed: self-test failed at ../../classfix/gdb/unittests/command-def-selftests.c:196
    Ran 1 unit tests, 1 failed
    (gdb)

Caused by initialize_remote_fileio that was taking the address of
its arguments remote_set_cmdlist and remote_show_cmdlist instead
of receiving the correct values to use as list.

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.c (lookup_cmd_for_prefix): Return the aliased command
	as prefix, not one of its aliases.
	(set_cmd_prefix): Remove.
	(do_add_cmd): Centralize the setting of the prefix of a command, when
	command is defined after its full chain of prefix commands.
	(add_alias_cmd): Remove call to set_cmd_prefix, as do_add_cmd does it.
	(add_setshow_cmd_full): Likewise.
	(update_prefix_field_of_prefixed_commands): New function.
	(add_prefix_cmd): Replace non working call to set_cmd_prefix by
	update_prefix_field_of_prefixed_commands.
	* gdb/remote-fileio.c (initialize_remote_fileio): Use the real
	addresses of remote_set_cmdlist and remote_show_cmdlist given
	as argument, not the address of an argument.
	* gdb/remote-fileio.h (initialize_remote_fileio): Likewise.
	* gdb/remote.c (_initialize_remote): Likewise.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 0605465feb Fix problem that alias can be defined or not depending on the order.
When an alias name starts with the name of another alias,
GDB was accepting to define the aliases in one order (short first, long after),
but refused it the other way around.

So, fix the logic to recognise an already existing alias by using
lookup_cmd_composition.

Also, this revealed a bug in lookup_cmd_composition:
when the searched command is a prefix command, lookup_cmd_composition
was not returning the fact that a command was found even if the
TEXT to parse was fully consumed.

gdb/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-cmds.c (alias_command): Check for an existing alias
	using lookup_cmd_composition, as valid_command_p is too strict
	and forbids aliases that are the prefix of an existing alias
	or command.
	* cli/cli-decode.c (lookup_cmd_composition): Ensure a prefix
	command is properly recognised as a valid command.

gdb/testsuite/ChangeLog
2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/alias.exp: Test aliases starting with a prefix of
	another alias.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 58e6ac7006 Add a selftest that detects a 'corrupted' command tree structure in GDB.
The GDB data structure that records the GDB commands is made of
'struct cmd_list_element' defined in cli-decode.h.

A cmd_list_element has various pointers to other cmd_list_element structures,
All these pointers are together building a graph of commands.

However, when following the 'next' and '*prefixlist' pointers of
cmd_list_element, the structure must better be a tree.

If such pointers do not form a tree, then some other elements of
cmd_list_element cannot get a correct semantic.  In particular, the prefixname
has no correct meaning if the same prefix command can be reached via 2 different
paths.

This commit introduces a selftest that detects (at least some cases of) errors
leading to 'next' and '*prefixlist' not giving a tree structure.

The new 'command_structure_invariants' selftest detects one single case where
the command structure is not a tree:

  (gdb) maintenance selftest command_structure_invariants
  Running selftest command_structure_invariants.
  list 0x56362e204b98 duplicated, reachable via prefix 'show ' and 'info set '.  Duplicated list first command is 'ada'
  Self test failed: self-test failed at ../../classfix/gdb/unittests/command-def-selftests.c:160
  Ran 1 unit tests, 1 failed
  (gdb)

This was fixed by the previous commit.

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* unittests/help-doc-selftests.c: Rename to
	unittests/command-def-selftests.c
	* unittests/command-def-selftests.c (help_doc_tests): Update some
	comments.
	(command_structure_tests, traverse_command_structure): New namespace
	and function.
	(command_structure_invariants_tests): New function.
	(_initialize_command_def_selftests) Renamed from
	_initialize_help_doc_selftests, register command_structure_invariants
	selftest.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers a7b9ceb8b4 Fix the only incorrect case found by command_structure_invariants selftest.
The next commit introduces a selftest that detects when the GDB
command structure does not define a tree when using the pointers
'next/*prefixlist'.  This test detects one such case, fixed
by this commit.

The command 'info set' was defined as a specific prefix command,
but re-using the command list already used for the 'show' command.
This leads to the command tree 'next/*prefixlist' to not be a tree.

This change defines 'info set ' as an alias, thereby fixing the selftest.

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-cmds.c (_initialize_cli_cmds): Define 'info set' as
	an alias of 'show'.
2020-05-15 22:17:45 +02:00
Joel Brobecker b2188a06e4 update name of several Ada fixed-point type handling functions
The purpose of this patch is to prepare for the future where
fixed point types become described using standard DWARF info,
rather than GNAT encodings. For that, we rename a number of
routines manipulating Ada fixed point types to make it explicit
from their new names that they rely on the GNAT encodings to work.
This will allow us, when we introduce support for fixed point types
from standard DWARF to use names that are not ambiguous with
the functions that do similar work, but only for GNAT encodings.

gdb/ChangeLog:

        * ada-lang.h: (ada_is_gnat_encoded_fixed_point_type): Renames
        ada_is_fixed_point_type.  Update all callers.
        (gnat_encoded_fixed_point_delta): Renames ada_delta.  Update
        all callers.
        * ada-lang.c (gnat_encoded_fixed_type_info): Renames fixed_type_info.
        Update all callers.
        * ada-typeprint.c (print_gnat_encoded_fixed_point_type): Renames
        print_fixed_point_type.  Update all callers.
        * ada-valprint.c (ada_value_print_num): Replace call to
        ada_is_fixed_point_type by ada_is_gnat_encoded_fixed_point_type.
2020-05-15 16:06:42 -04:00
Gary Benson 86e4e63d7c Fix "control reaches end of non-void function" errors in testsuite
When running the testsuite with clang, a number of testcases fail to
build with the following errors:
  warning: control reaches end of non-void function [-Wreturn-type]
  warning: control may reach end of non-void function [-Wreturn-type]

This prevents a number of testcases from executing.  This commit fixes.

gdb/testsuite/ChangeLog:

	* gdb.base/info-os.c (main): Add return statement.
	* gdb.base/info_minsym.c (minsym_fun): Likewise.
	* gdb.base/large-frame-2.c (func): Likewise.
	* gdb.base/pr10179-a.c (foo1, bar1): Likewise.
	* gdb.base/pr10179-b.c (foo2): Likewise.
	* gdb.base/valgrind-disp-step.c (foo): Likewise.
	* gdb.base/watch-cond.c (func): Likewise.
	* gdb.multi/goodbye.c (verylongfun): Likewise.
	* gdb.multi/hello.c (commonfun): Likewise.
	* gdb.python/py-finish-breakpoint.c (call_longjmp): Likewise.
	* gdb.threads/fork-plus-threads.c (thread_func): Likewise.
	* gdb.threads/forking-threads-plus-breakpoint.c (thread_forks):
	Likewise.
	* gdb.threads/hand-call-new-thread.c (foo): Likewise.
	* gdb.threads/interrupt-while-step-over.c (child_function):
	Likewise.
	* gdb.trace/actions-changed.c (end): Likewise.
2020-05-15 15:03:42 +01:00
Gary Benson 163df4df08 Don't silently skip tests if OpenCL is unsupported
A number of tests silently exit if OpenCL support is not detected.
This commit fixes.

gdb/testsuite/ChangeLog:

	* gdb.opencl/callfuncs.exp: Report when test skipped.
	* gdb.opencl/convs_casts.exp: Likewise.
	* gdb.opencl/datatypes.exp: Likewise.
	* gdb.opencl/operators.exp: Likewise.
	* gdb.opencl/vec_comps.exp: Likewise.
2020-05-15 14:25:32 +01:00
Tom de Vries 6dbc505a74 [gdb/testsuite] Rename *.exp.in to *.exp.tcl
Say we have some common tcl code that we want to include in test-cases
t1.exp and t1.exp.

We could put the common code into a file common.exp alongside the test-cases,
but that will make dejagnu treat that file as another test-case.  To prevent
this, we use a suffix, currently .in, in other words we put the common code in
a file common.exp.in.

The .in suffix however is also used in autoconf, which might cause confusion.

Change the suffix from .in to .tcl.

gdb/testsuite/ChangeLog:

2020-05-15  Tom de Vries  <tdevries@suse.de>

	* gdb.base/align.exp.in: Rename to ...
	* gdb.base/align.exp.tcl: ... this.
	* gdb.base/align-c++.exp: Update.
	* gdb.base/align-c.exp: Update.
	* gdb.base/all-architectures.exp.in: Rename to ...
	* gdb.base/all-architectures.exp: ... this.
	* gdb.base/all-architectures-0.exp: Update.
	* gdb.base/all-architectures-1.exp: Update.
	* gdb.base/all-architectures-2.exp: Update.
	* gdb.base/all-architectures-3.exp: Update.
	* gdb.base/all-architectures-4.exp: Update.
	* gdb.base/all-architectures-5.exp: Update.
	* gdb.base/all-architectures-6.exp: Update.
	* gdb.base/all-architectures-7.exp: Update.
	* gdb.base/infcall-nested-structs.exp.in: Rename to ...
	* gdb.base/infcall-nested-structs.exp.tcl: ... this.
	* gdb.base/infcall-nested-structs-c++.exp: Update.
	* gdb.base/infcall-nested-structs-c.exp: Update.
	* gdb.base/info-types.exp.in: Rename to ...
	* gdb.base/info-types.exp.tcl: ... this.
	* gdb.base/info-types-c++.exp: Update.
	* gdb.base/info-types-c.exp: Update.
	* gdb.base/max-depth.exp.in: Rename to ...
	* gdb.base/max-depth.exp.tcl: ... this.
	* gdb.base/max-depth-c++.exp: Update.
	* gdb.base/max-depth-c.exp: Update.
	* gdb.cp/cpexprs.exp.in: Rename to ...
	* gdb.cp/cpexprs.exp.tcl: ... this.
	* gdb.cp/cpexprs-debug-types.exp: Update.
	* gdb.cp/cpexprs.exp: Update.
	* gdb.cp/infcall-nodebug.exp.in: Rename to ...
	* gdb.cp/infcall-nodebug.exp.tcl: ... this.
	* gdb.cp/infcall-nodebug-c++-d0.exp: Update.
	* gdb.cp/infcall-nodebug-c++-d1.exp: Update.
	* gdb.cp/infcall-nodebug-c-d0.exp: Update.
	* gdb.cp/infcall-nodebug-c-d1.exp: Update.
	* gdb.dwarf2/clang-debug-names.exp.in: Rename to ...
	* gdb.dwarf2/clang-debug-names.exp.tcl: ... this.
	* gdb.dwarf2/clang-debug-names-2.exp: Update.
	* gdb.dwarf2/clang-debug-names.exp: Update.
2020-05-15 14:49:48 +02:00
Andrew Burgess d1034d7878 gdb/testsuite: Revert commit 843f4d9357
Revert this commit:

  commit 843f4d9357
  Date:   Tue May 12 17:38:17 2020 +0100

      gdb/testsuite: Disable path and duplicate checks when parallel testing

Now that this commit has landed:

  commit c959562d9b
  Date:   Fri May 15 11:23:59 2020 +0100

      contrib: Update dg-extract-results.* from gcc

We can now make use of the mechanism for detecting paths in test names
and duplicate test names, even when we run tests in parallel.

gdb/testsuite/ChangeLog:

	* lib/check-test-names.exp: Remove code that prevents this file
	loading when tests are run in parallel.
2020-05-15 11:48:57 +01:00
Andrew Burgess c959562d9b contrib: Update dg-extract-results.* from gcc
Pull the latest version of the dg-extract-results.* scripts from the
gcc repository.  This picks up this commit from gcc:

  commit c9a41202b272b0b3a3c64a96ef4a5a97579eb017
  Date:   Mon May 11 22:32:35 2020 +0100

  contrib: Handle GDB specific test result types

  This commit is for the benefit of GDB, but as the binutils-gdb
  repository shares the contrib/ directory with gcc, this commit must
  first be applied to gcc then copied back to binutils-gdb.

  This commit extends the two scripts contrib/dg-extract-results.{py,sh}
  to handle some new, GDB specific test result types.  These test
  results types should never appear in GCC, or any other tool that
  shares the contrib/ directly, so this change should be harmless.

  In this patch series:
    https://sourceware.org/pipermail/gdb-patches/2020-April/167847.html
  changes were made in GDB's use of Dejagnu so that two additional
  conditions could be detected, these are:

    1. Test names that contain either the build or source paths.  Such
    test names make it difficult to compare the results of two test runs
    of GDB from two different directories, and

    2. Duplicate test names.  Duplicates make it difficult to track down
    exactly which test has failed.

  When running Dejagnu on GDB we can now (sometimes) see two additional
  test result types matching the above conditions, these are '# of paths
  in test names' and '# of duplicate test names'.

  If the test is run in parallel mode (make -j...) then these extra test
  results will appear in the individual test summary files, but are not
  merged into the final summary file.

  Additionally, within the summary file there are now two new types of
  test summary line, these are 'PATH: ...' and 'DUPLICATE: ...', these
  allow users to quickly search the test summary to track down where the
  offending test names are.  These lines are similarly not merged into
  the unified gdb.sum file after a parallel test run.

  This commit extends the dg-extract-results.* scripts to calculate the
  totals for the two new result types, and to copy the new test summary
  lines into the unified summary file.

contrib/ChangeLog:

	* dg-extract-results.py: Update from gcc repo.
	* dg-extract-results.sh: Likewise.
2020-05-15 11:41:22 +01:00
Pedro Alves 3c5c364972 Fix gdb.multi/multi-kill.exp
The previous patch misssed declaring the 'testpid' array as namespace
variable.  While it at, might as well go back to having start_inferior
refer to the "global" testpid, using "variable" too.

gdb/testsuite/ChangeLog:
2020-05-15  Pedro Alves  <palves@redhat.com>

	* gdb.multi/multi-kill.exp (start_inferior): Remove
	'testpid' parameter.  Refer to namespace variable directly.
	(testpid): Declare as namespace variable.
2020-05-15 11:22:47 +01:00
Pedro Alves 272c36b87f Fix global variable collision in gdb.multi/multi-kill.exp
The new gdb.multi/multi-kill.exp testcase added an 'testpid' array,
which may conflict with other global 'testpid' variables used by other
testcases, resulting in:

 ...
 ERROR: tcl error sourcing
 /data/gdb_versions/devel/src/gdb/testsuite/gdb.multi/multi-kill.exp.
 ERROR: can't set "testpid(1)": variable isn't array
     while executing
 "set testpid($num) [get_integer_valueof "pid" -1]"

or

 $ runtest gdb.threads/check-libthread-db.exp gdb.multi/multi-kill.exp
 ...
 Running /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.multi/multi-kill.exp ...
 Running /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.threads/check-libthread-db.exp ...
 ERROR: tcl error sourcing /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.threads/check-libthread-db.exp.
 ERROR: can't set "testpid": variable is array
     while executing
 "set testpid [spawn_id_get_pid $test_spawn_id]"
     ("uplevel" body line 8)

Fix this with a namespace, like gdb.linespec/explicit.exp does.

gdb/testsuite/ChangeLog:
2020-05-15  Pedro Alves  <palves@redhat.com>

	* gdb.multi/multi-kill.exp: Wrap in namespace.
	(start_inferior): Add TESTPID parameter.  Use it instead of the
	testpid global.
	(top level): Define empty TESTPID array, and pass it down to
	start_inferior.
2020-05-15 11:09:51 +01:00
Hannes Domani 013707794a Enable hardware breakpoints for gdbserver on Windows
When trying to use hardware breakpoints with gdbserver you get this error:

(gdb) hbreak main
Hardware assisted breakpoint 2 at 0x40162d: file gdb-9493.c, line 5.
(gdb) c
Continuing.
Warning:
Cannot insert hardware breakpoint 2.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

It turns out the respective types just needed to be added to the
appropriate callback functions, because x86_dr_(insert|remove)_watchpoint
already handles them.

gdbserver/ChangeLog:

2020-05-15  Hannes Domani  <ssbssa@yahoo.de>

	* win32-i386-low.cc (i386_supports_z_point_type): Handle
	Z_PACKET_HW_BP z_type.
	(i386_insert_point): Handle raw_bkpt_type type.
	(i386_remove_point): Likewise.
2020-05-15 10:55:21 +02:00
Alan Modra 2a50b40146 Fix tight loop on recursively-defined symbols
This patch fixes a bug in GAS where the assembler enters a tight loop
when attempting to resolve recursively-defined symbols, e.g. when
trying to assemble "a=a".

This is a regression introduced between binutils 2.32 and 2.33,
by commit 1903f1385b

	* symbols.c (struct local_symbol): Update comment.
	(resolve_symbol_value): For resolved symbols equated to other
	symbols, verify that the referenced symbol is not a local_symbol
	before accessing sy_value.  Don't leave symbol loops during
	finalize_syms resolution.
	* testsuite/gas/all/assign-bad-recursive.d: New test.
	* testsuite/gas/all/assign-bad-recursive.l: Error output for test.
	* testsuite/gas/all/assign-bad-recursive.s: Assembly for test.
	* testsuite/gas/all/gas.exp: Run it.
2020-05-15 18:21:07 +09:30
Kevin Buettner a51951c258 Disable record btrace bts support for AMD processors
Some Intel processors implement a Branch Trace Store (BTS) which GDB
uses for reverse execution support via the "record btrace bts"
command.

I have been unable to find a description of a similar feature in a
recent (April 2020) AMD64 architecture reference:

    https://www.amd.com/system/files/TechDocs/40332.pdf

While it is the case that AMD processors have an LBR (last branch
record) bit in the DebugCtl MSR, it seems that it affects only four
MSRs when enabled.  The names of these MSRs are LastBranchToIP,
LastBranchFromIP, LastIntToIP, and LastIntFromIP.  I can find no
mention of anything more extensive.  While looking at an Intel
architecture document, I noticed that Intel's P6 family from the
mid-90s had registers of the same name.

Therefore...

This commit disables "record btrace bts" support in GDB for AMD
processors.

Using the test case from gdb.base/break.exp, the sessions
below show the expected behavior (run on a machine with an
Intel processor) versus that on a machine with an AMD processor.
The AMD processor in question is reported as follows by "lscpu":
AMD Ryzen Threadripper 2950X 16-Core Processor .  Finally, I'll
note that the AMD machine is actually a VM, but I see similar
behavior on both the virtualization host and the VM.

Intel machine - Desired behavior:

[kevinb@mohave gdb]$ ./gdb -q testsuite/outputs/gdb.base/break/break
Reading symbols from testsuite/outputs/gdb.base/break/break...
(gdb) start
Temporary breakpoint 1 at 0x401179: file /home/kevinb/sourceware-git/native-build/bld/../../binutils-gdb/gdb/testsuite/gdb.base/break.c, line 43.
Starting program: /home/kevinb/sourceware-git/native-build/bld/gdb/testsuite/outputs/gdb.base/break/break

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd748, envp=0x7fffffffd758)
    at /home/kevinb/sourceware-git/native-build/bld/../../binutils-gdb/gdb/testsuite/gdb.base/break.c:43
43	    if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
(gdb) record btrace
(gdb) b factorial
Breakpoint 2 at 0x40121b: file /home/kevinb/sourceware-git/native-build/bld/../../binutils-gdb/gdb/testsuite/gdb.base/break.c, line 63.
(gdb) c
Continuing.

Breakpoint 2, factorial (value=6)
    at /home/kevinb/sourceware-git/native-build/bld/../../binutils-gdb/gdb/testsuite/gdb.base/break.c:63
63	  if (value > 1) {  /* set breakpoint 7 here */
(gdb) info record
Active record target: record-btrace
Recording format: Branch Trace Store.
Buffer size: 64kB.
Recorded 768 instructions in 22 functions (0 gaps) for thread 1 (process 19215).
(gdb) record function-call-history
13	do_lookup_x
14	_dl_lookup_symbol_x
15	_dl_fixup
16	_dl_runtime_resolve_xsavec
17	atoi
18	strtoq
19	____strtoll_l_internal
20	atoi
21	main
22	factorial
(gdb) record instruction-history
759	   0x00007ffff7ce0917 <____strtoll_l_internal+647>:	pop    %r15
760	   0x00007ffff7ce0919 <____strtoll_l_internal+649>:	retq
761	   0x00007ffff7cdd064 <atoi+20>:	add    $0x8,%rsp
762	   0x00007ffff7cdd068 <atoi+24>:	retq
763	   0x00000000004011b1 <main+75>:	mov    %eax,%edi
764	   0x00000000004011b3 <main+77>:	callq  0x401210 <factorial>
765	   0x0000000000401210 <factorial+0>:	push   %rbp
766	   0x0000000000401211 <factorial+1>:	mov    %rsp,%rbp
767	   0x0000000000401214 <factorial+4>:	sub    $0x10,%rsp
768	   0x0000000000401218 <factorial+8>:	mov    %edi,-0x4(%rbp)

AMD machine - Wrong behavior:

[kev@f32-1 gdb]$ ./gdb -q testsuite/outputs/gdb.base/break/break
Reading symbols from testsuite/outputs/gdb.base/break/break...
(gdb) start
Temporary breakpoint 1 at 0x401179: file /ironwood1/sourceware-git/f32-master/bld/../../worktree-master/gdb/testsuite/gdb.base/break.c, line 43.
Starting program: /mesquite2/sourceware-git/f32-master/bld/gdb/testsuite/outputs/gdb.base/break/break

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd5b8, envp=0x7fffffffd5c8)
    at /ironwood1/sourceware-git/f32-master/bld/../../worktree-master/gdb/testsuite/gdb.base/break.c:43
43	    if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
(gdb) record btrace
(gdb) b factorial
Breakpoint 2 at 0x40121b: file /ironwood1/sourceware-git/f32-master/bld/../../worktree-master/gdb/testsuite/gdb.base/break.c, line 63.
(gdb) c
Continuing.

Breakpoint 2, factorial (value=6)
    at /ironwood1/sourceware-git/f32-master/bld/../../worktree-master/gdb/testsuite/gdb.base/break.c:63
63	  if (value > 1) {  /* set breakpoint 7 here */
(gdb) info record
Active record target: record-btrace
Recording format: Branch Trace Store.
Buffer size: 64kB.
warning: Recorded trace may be incomplete at instruction 7737 (pc = 0x405000).
warning: Recorded trace may be incomplete at instruction 7739 (pc = 0x0).
Recorded 7740 instructions in 46 functions (2 gaps) for thread 1 (process 1402911).
(gdb) record function-call-history
37	??
38	values
39	some_enum_global
40	??
41	some_union_global
42	some_variable
43	??
44	[decode error (2): unknown instruction]
45	??
46	[decode error (2): unknown instruction]
(gdb) record instruction-history
7730	   0x0000000000404ff3:	add    %al,(%rax)
7731	   0x0000000000404ff5:	add    %al,(%rax)
7732	   0x0000000000404ff7:	add    %al,(%rax)
7733	   0x0000000000404ff9:	add    %al,(%rax)
7734	   0x0000000000404ffb:	add    %al,(%rax)
7735	   0x0000000000404ffd:	add    %al,(%rax)
7736	   0x0000000000404fff:	.byte 0x0
7737	   0x0000000000405000:	Cannot access memory at address 0x405000

Lastly, I'll note that I see a lot of gdb.btrace failures without
this commit.  Worse still, the results aren't always the same which
causes a lot of noise when comparing test results.

gdbsupport/ChangeLog:

	* btrace-common.h (btrace_cpu_vendor): Add CV_AMD.

gdb/ChangeLog:

	* nat/linux-btrace.c (btrace_this_cpu): Add check for AMD
	processors.
	(cpu_supports_bts): Add CV_AMD case.
2020-05-14 17:56:33 -07:00
Laurent Morichetti 29d6859f09 gdb: infrun: consume multiple events at each pass in stop_all_threads
[Simon: I send this patch on behalf of Laurent Morichetti, I added the
 commit message and performance measurement stuff.

 Also, this patch is better viewed with "git show -w".]

stop_all_threads, in infrun.c, is used to stop all running threads on
targets that are always non-stop.  It's used, for example, when the
program hits a breakpoint while GDB is set to "non-stop off".  It sends
a stop request for each running thread, then collects one wait event for
each.

Since new threads can spawn while we are stopping the threads, it's
written in a way where it makes multiple such "send stop requests to
running threads & collect wait events" passes.  The function completes
when it has made two passes where it hasn't seen any running threads.

With the way it's written right now is, it iterates on the thread list,
sending a stop request for each running thread.  It then waits for a
single event, after which it iterates through the thread list again.  It
sends stop requests for any running threads that's been created since
the last iteration.  It then consumes another single wait event.

This makes it so we iterate on O(n^2) threads in total, where n is the
number of threads.  This patch changes the function to reduce it to
O(n).  This starts to have an impact when dealing with multiple
thousands of threads (see numbers below).  At each pass, we know the
number of outstanding stop requests we have sent, for which we need to
collect a stop event.  We can therefore loop to collect this many stop
events before proceeding to the next pass and iterate on the thread list
again.

To check the performance improvements with this patch, I made an
x86/Linux program with a large number of idle threads (varying from 1000
to 10000).  The program's main thread hits a breakpoint once all these
threads have started, which causes stop_all_threads to be called to stop
all these threads.  I measured (by patching stop_all_threads):

- the execution time of stop_all_threads
- the total number of threads we iterate on during the complete
  execution of the function (the total number of times we execute the
  "for (thread_info *t : all_non_exited_threads ())" loop)

These are the execution times, in milliseconds:

    # threads  before  after
         1000     226    106
         2000     997    919
         3000    3461   2323
         4000    4330   3570
         5000    8642   6600
         6000    9918   8039
         7000   12662  10930
         8000   16652  11222
         9000   21561  15875
        10000   26613  20019

Note that I very unscientifically executed each case only once.

These are the number of loop executions:

    # threads     before  after
         1000    1003002   3003
         2000    4006002   6003
         3000    9009002   9003
         4000   16012002  12003
         5000   25015002  15003
         6000   36018002  18003
         7000   49021002  21003
         8000   64024002  24003
         9000   81027002  27003
        10000  100030002  30003

This last table shows pretty well the O(n^2) vs O(n) behaviors.

Reg-tested on x86 GNU/Linux (Ubuntu 16.04).

gdb/ChangeLog:

YYYY-MM-DD  Laurent Morichetti  <Laurent.Morichetti@amd.com>
YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

	* infrun.c (stop_all_threads): Collect multiple wait events at
	each pass.
2020-05-14 19:59:16 -04:00
Nikita Ermakov 6a31512fd4 gold: powerpc: Test whether sym is not a plugin in do_gc_mark_symbol
sym->object() could be either a Plugin or Powerpc_relobj. There could
be a situation when Pluginobj would be proccessed in
ppc_object->get_opd_ent(dst_off) as Powerpc_relobj and it leads to the
segmentation fault.

	* powerpc.cc (do_gc_mark_symbol): Don't segfault on plugin symbols.
2020-05-15 08:30:33 +09:30