Commit Graph

29864 Commits

Author SHA1 Message Date
Andrew Burgess ed69cbc8ef gdb/riscv: Take CSR names from target description
First, consider the RISC-V register $x1.  This register has an alias
$ra.  When GDB processes an incoming target description we allow the
target to use either register name to describe the target.

However, within GDB's UI we want to use the $ra alias in preference to
the $x1 architecture name.

To achieve this GDB overrides the tdesc_register_name callback with
riscv_register_name.  In riscv_register_name we ensure that we always
return the preferred name, so in this case "ra".

To ensure the user can still access the register as $x1 if they want
to, when in riscv_check_tdesc_feature we spot that the target has
supplied the register, we add aliases for every name except the
preferred one, so in this case we add the alias "x1".

This scheme seems to work quite well, the targets have the flexibility
to be architecture focused if they wish (using x0 - x31) while GDB is
still using the ABI names ra, sp, gp, etc.

When this code was originally added there was an attempt made to
include the CSRs in the same scheme.  At the time the CSRs only had
two names, one pulled from riscv-opc.h, and one generated in GDB that
had the pattern csr%d.

The idea was that if the remote targets description described the CSRs
as csr%d then GDB would rename these back to the real CSR name.  This
code was only included because if followed the same pattern as the
x-regs and f-regs, not because I was actually aware of any target that
did this.

However, recent changes to add additional CSR aliases has made me
rethink the position here.

Lets consider the CSR $dscratch0.  This register has an alias
'csr1970' (1970 is 0x7b2, which is the offset of the CSR register into
the CSR address space).  However, this register was originally called
just 'dscratch', and so, after recent commits, this register also has
the alias 'dscratch'.

As the riscv-opc.h file calls this register 'dscratch0' GDB's
preferred name for this register is 'dscratch0'.

So, if the remote target description includes the register
'dscratch0', then GDB will add the aliases 'dscratch', and 'csr1970'.
In the UI GDB will describe the register as 'dscratch0', and all it
good.

The problem I see in this case is where the target describes the
register as 'dscratch'.  In this case GDB will still spot the register
and add the aliases 'dscratch', and 'csr1970', GDB will then give the
register the preferred name 'dscratch0'.

I don't like this.  For the CSRs I think that we should stick with the
naming scheme offered by the remote target description.  As the RISC-V
specification evolves and CSR register names evolve, insisting on
referring to registers by the most up to date name makes it harder for
a target to provide a consistent target description for an older
version of the RISC-V architecture spec.

In this precise case the target offers 'dscratch', which is from an
older version of the RISC-V specification, the newer version of the
spec has two registers 'dscratch0' and 'dscratch1'.  If we insist on
using 'dscratch0' it is then a little "weird" (or seems so to me) when
'dscratch1' is missing.

This patch makes a distinction between the x and f registers and the
other register sets.  For x and f we still make use of the renaming
scheme, forcing GDB to prefer the ABI name.  But after this patch the
CSR register group, and also the virtual register group, will always
prefer to use the name given in the target description, adding other
names as aliases, but not making any other name the preferred name.

gdb/ChangeLog:

	* riscv-tdep.c (struct riscv_register_feature::register_info): Fix
	whitespace error for declaration of names member variable.
	(struct riscv_register_feature): Add new prefer_first_name member
	variable, and fix whitespace error in declaration of registers.
	(riscv_xreg_feature): Initialize prefer_first_name field.
	(riscv_freg_feature): Likewise.
	(riscv_virtual_feature): Likewise.
	(riscv_csr_feature): Likewise.
	(riscv_register_name): Expand on comments.  Remove register name
	modifications for CSR and virtual registers.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-tdesc-regs.exp: Extend test case.
2020-06-25 18:07:30 +01:00
Andrew Burgess 4445e8f59a gdb/riscv: Fix whitespace error
Should be 'std::vector<type>' not 'std::vector <type>'.

gdb/ChangeLog:

	* riscv-tdep.c (struct riscv_register_feature): Fix whitespace
	errors.
2020-06-25 18:07:29 +01:00
Andrew Burgess 767a879e31 gdb/riscv: Improved register alias name creation
This commit does two things:

 1. Makes use of the DECLARE_CSR_ALIAS definitions in riscv-opc.h to
 add additional aliases for CSRs.

 2. Only creates aliases for registers that are actually present on
 the target (as announced in the target XML description).

This means that the 'csr%d' aliases that exist will only be created
for those CSRs the target actually has, which is a nice improvement,
as accessing one of the CSRs that didn't exist would cause GDB to
crash with this error:

  valprint.c:1560: internal-error: bool maybe_negate_by_bytes(const gdb_byte*, unsigned int, bfd_endian, gdb::byte_vector*): Assertion `len > 0' failed.

When we look at the DECLARE_CSR_ALIAS lines in riscv-opc.h, these can
be split into three groups:

 DECLARE_CSR_ALIAS(misa, 0xf10, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9, PRIV_SPEC_CLASS_1P9P1)

The 'misa' register used to exist of offset 0xf10, but was moved to
its current offset (0x301) in with privilege spec 1.9.1.  We don't
want GDB to create an alias called 'misa' as we will already have a
'misa' register created by the DECLARE_CSR(misa ....) call earlier in
riscv-opc.h

 DECLARE_CSR_ALIAS(ubadaddr, CSR_UTVAL, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9, PRIV_SPEC_CLASS_1P10)
 DECLARE_CSR_ALIAS(sbadaddr, CSR_STVAL, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9, PRIV_SPEC_CLASS_1P10)
 DECLARE_CSR_ALIAS(sptbr, CSR_SATP, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9, PRIV_SPEC_CLASS_1P10)
 DECLARE_CSR_ALIAS(mbadaddr, CSR_MTVAL, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9, PRIV_SPEC_CLASS_1P10)
 DECLARE_CSR_ALIAS(mucounteren, CSR_MCOUNTINHIBIT, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9, PRIV_SPEC_CLASS_1P10)

These aliases are all CSRs that were removed in privilege spec 1.10,
and whose addresses were reused by new CSRs.  The names meaning of the
old names is totally different to the new CSRs that have taken their
place.  I don't believe we should add these as aliases into GDB.  If
the new CSR exists in the target then that should be enough.

 DECLARE_CSR_ALIAS(dscratch, CSR_DSCRATCH0, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9, PRIV_SPEC_CLASS_1P11)

In privilege spec 1.11 the 'dscratch' register was renamed to
'dscratch0', however the meaning of the register didn't change.
Adding the 'dscratch' alias makes sense I think.

Looking then at the final PRIV_SPEC_CLASS_* field for each alias then
we can see that currently we only want to take the alias from
PRIV_SPEC_CLASS_1P11.  For now then this is what I'm using to filter
the aliases within GDB.

In the future there's no telling how DECLARE_CSR_ALIAS will be used.
I've heard it said that future RISC-V privilege specs will not reuse
CSR offsets again.  But it could happen.  We just don't know.

If / when it does we may need to revisit how aliases are created for
GDB, but for now this seems to be OK.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_create_csr_aliases): Handle csr aliases from
	riscv-opc.h.
	(class riscv_pending_register_alias): New class.
	(riscv_check_tdesc_feature): Take vector of pending aliases and
	populate it as appropriate.
	(riscv_setup_register_aliases): Delete.
	(riscv_gdbarch_init): Create vector of pending aliases and pass it
	to riscv_check_tdesc_feature in all cases.  Use the vector to
	create the register aliases.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-tdesc-regs-32.xml: New file.
	* gdb.arch/riscv-tdesc-regs-64.xml: New file.
	* gdb.arch/riscv-tdesc-regs.c: New file.
	* gdb.arch/riscv-tdesc-regs.exp: New file.
2020-06-25 18:07:29 +01:00
Rainer Orth bb6e55f3ee Remove obsolete gdbarch_static_transform_name
gdbarch_static_transform_name is completely Solaris-specific or rather
specific to the Studio compilers.  Studio cc has deprecated Stabs support
in the 12.4 release back in 2015, GCC has defaulted to DWARF-2 on Solaris
7+ since 2004 and Stabs themselves are pretty much obsolete, so the whole
code can go.

Tested on sparcv9-sun-solaris2.11 and x86_64-pc-linux-gnu with
--enable-targets=all.

	* sol2-tdep.c (sol2_static_transform_name): Remove.
	(sol2_init_abi): Don't register it.
	* gdbarch.sh (static_transform_name): Remove.
	* gdbarch.c, gdbarch.h: Regenerate.

	* dbxread.c (read_dbx_symtab) <'S'>: Remove call to
	gdbarch_static_transform_name.
	* mdebugread.c (parse_partial_symbols) <'S'>: Likewise.
	* stabsread.c (define_symbol) <'X'>: Remove.
	(define_symbol) <'S'>: Remove gdbarch_static_transform_name
	handling.
	<'V'>: Likewise.
	* xcoffread.c (scan_xcoff_symtab): Remove gdbarch.
	<'S'>: Remove call to gdbarch_static_transform_name.
2020-06-25 17:56:12 +02:00
Rainer Orth c6d3683661 Use fork instead of vfork on Solaris
The gdb.mi/mi-exec-run.exp test never completed/timed out on Solaris for
quite some time:

FAIL: gdb.mi/mi-exec-run.exp: inferior-tty=main: mi=main: force-fail=1: run failure detected (timeout)

This is for gdb trying to exec mi-exec-run.nox, a copy of mi-exec-run
with execute permissions removed.

The process tree at this point looks like this:

          21254 /vol/gcc/bin/expect -- /vol/gcc/share/dejagnu/runtest.exp GDB_PARALLEL=yes --outdir=outputs/gdb.mi/mi-exec-run-vfork gdb.mi/mi-exec-run.exp
            21300 <defunct>
            21281 <defunct>
            21294 $obj/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory $obj/gdb/testsuite/../data-directory -i=mi
              21297 $obj/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory $obj/gdb/testsuite/../data-directory -i=mi

The parent gdb hangs here:

21294:  $obj/gdb/testsuite/../../gdb/gdb -nw
------------  lwp# 1 / thread# 1  ---------------
 0000000000000000 SYS#0    ()
 0000000000daeccd procfs_target::create_inferior(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, int) () + 97 (procfs.c:2853)
 0000000000ca63a7 run_command_1(char const*, int, run_how) () + 349 (basic_string.h:187)
 0000000000ca6516 start_command(char const*, int) () + 26 (infcmd.c:584)
 0000000000b3ca8e do_const_cfunc(cmd_list_element*, char const*, int) () + f (cli-decode.c:96)
 0000000000b3ed77 cmd_func(cmd_list_element*, char const*, int) () + 32 (cli-decode.c:2113)
 0000000000f2d219 execute_command(char const*, int) () + 455 (top.c:657)
 0000000000d4ad77 mi_execute_cli_command(char const*, int, char const*) () + 242 (basic_string.h:187)
 0000000000d4ae80 mi_cmd_exec_run(char const*, char**, int) () + ba (mi-main.c:473)

with these process flags

21294:	$obj/gdb/testsuite/../../gdb/gdb -nw
	data model = _LP64  flags = VFORKP|ORPHAN|MSACCT|MSFORK
	sigpend = 0x00004103,0x00000000,0x00000000
 /1:	flags = 0
	sigmask = 0xffbffeff,0xffffffff,0x000000ff
	cursig = SIGKILL
 /2:	flags = DETACH|STOPPED|ASLEEP  lwp_park(0x0,0x0,0x0)
	why = PR_SUSPENDED
	sigmask = 0x000a2002,0x00000000,0x00000000
[...]

while the child sits at

21297:  $obj/gdb/testsuite/../../gdb/gdb -nw
 00007fffbf078a0b execve   (7fffbffff756, 7fffbfffec58, 7fffbfffec90, 0)
 00007fffbef84cf6 execvpex () + f6
 00007fffbef84f45 execvp () + 15
 0000000000d60a44 fork_inferior(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, void (*)(), gdb::function_view<void (int)>, void (*)(), char const*, void (*)(char const*, char* const*, char* const*)) () + 47f (fork-inferior.c:423)
 0000000000daeccd procfs_target::create_inferior(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, int) () + 97 (procfs.c:2853)
 0000000000ca63a7 run_command_1(char const*, int, run_how) () + 349 (basic_string.h:187)
 0000000000ca6516 start_command(char const*, int) () + 26 (infcmd.c:584)
 0000000000b3ca8e do_const_cfunc(cmd_list_element*, char const*, int) () + f (cli-decode.c:96)
 0000000000b3ed77 cmd_func(cmd_list_element*, char const*, int) () + 32 (cli-decode.c:2113)
 0000000000f2d219 execute_command(char const*, int) () + 455 (top.c:657)
 0000000000d4ad77 mi_execute_cli_command(char const*, int, char const*) () + 242 (basic_string.h:187)
 0000000000d4ae80 mi_cmd_exec_run(char const*, char**, int) () + ba (mi-main.c:473)

with

21297:	$obj/gdb/testsuite/../../gdb/gdb -nw
	data model = _LP64  flags = MSACCT|MSFORK
	exitset  = 0x00000000 0x04000000 0x00000000 0x00000000
	           0x00000000 0x00000000 0x00000000 0x00000000
 /1:	flags = STOPPED|ISTOP  execve(0x7fffbffff756,0x7fffbfffec58,0x7fffbfffec90,0x0)
	why = PR_SYSEXIT  what = execve

We have a deadlock here: the execve in the child cannot return until the
parent has handled the PR_SYSEXIT while the parent cannot run with a
vfork'ed child as documented in proc(4):

       The child of a vfork(2) borrows the  parent's  address  space.  When  a
       vfork(2) is executed by a traced process, all watched areas established
       for the parent are suspended until the child terminates or performs  an
       exec(2).  Any  watched areas established independently in the child are
       cancelled when the parent resumes  after  the  child's  termination  or
       exec(2).  PCWATCH  fails  with  EBUSY  if  applied  to  the parent of a
       vfork(2) before the child has terminated or performed an  exec(2).  The
       PR_VFORKP  flag  is  set  in  the  pstatus  structure for such a parent
       process.

In that situation, the parent cannot be killed even with SIGKILL (as
runtest will attempt once the timeout occurs; the pending signal can be
seen in the pflags output above), so the whole test hangs until one
manually kills the child process.

Fortunately, there's an easy way out: when using fork instead of vfork,
the problem doesn't occur, and this is what the current patch does: it
calls fork_inferior with a dummy pre_trace_fun arg.

Tested on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11.

	* procfs.c (procfs_pre_trace): New function.
	(procfs_target::create_inferior): Pass it to fork_inferior.
2020-06-25 17:48:14 +02:00
Rainer Orth a7e6196bb8 Don't include *sol2-tdep.o on Linux/sparc*
Linux/sparc* currently links Solaris-specific files (sparc-sol2-tdep.o,
sparc64-sol2-tdep.o, sol2-tdep.o) for no apparent reason.  It has no
business doing so, and none of the functions/variables defined there are
used explicitly.  If support for the Solaris OSABI were desired, this
should be done using --enable-targets instead.

Since neither sparc{32,64}_sol2_init_abi currently declared in common
headers (sparc*-tdep.h) are used outside their source files, they are made
static and the declarations removed.

Tested on sparcv9-sun-solaris2.11 and sparc64-unknown-linux-gnu.

	* configure.tgt <sparc-*-linux*> (gdb_target_obs): Remove
	sparc-sol2-tdep.o, sol2-tdep.o, sparc64-sol2-tdep.o.
	<sparc64-*-linux*> (gdb_target_obs): Remove sparc64-sol2-tdep.o,
	sol2-tdep.o, sparc-sol2-tdep.o.
	* sparc-sol2-tdep.c (sparc32_sol2_init_abi): Make static.
	* sparc-tdep.h (sparc32_sol2_init_abi): Remove.
	* sparc64-sol2-tdep.c (sparc64_sol2_init_abi): Make static.
	* sparc64-tdep.h (sparc64_sol2_init_abi): Remove.
2020-06-25 13:54:42 +02:00
Rainer Orth d412e69677 Move common handlers to sol2_init_abi
There's some overlap and duplication between 32 and 64-bit Solaris/SPARC
and x86 tdep files, in particular

        sol2_core_pid_to_str
	*_sol2_sigtramp_p
        sol2_skip_solib_resolver
        *_sol2_static_transform_name (forgotten on amd64)
        set_gdbarch_sofun_address_maybe_missing (likewise)

This patch avoids this by centralizing common code in sol2-tdep.c.
While sparc_sol2_pc_in_sigtramp and sparc_sol2_static_transform_name
were declared in the shared sparc-tdep.h, they were only used in Solaris
files.

Tested on amd64-pc-solaris2.11, i386-pc-solaris2.11,
sparcv9-sun-solaris2.11, and sparc-sun-solaris2.11, and
sparc64-unknown-linux-gnu.

	* amd64-sol2-tdep.c (amd64_sol2_sigtramp_p): Remove.
	(amd64_sol2_init_abi): Use sol2_sigtramp_p.
	Call sol2_init_abi.
 	Remove calls to set_gdbarch_skip_solib_resolver,
	set_gdbarch_core_pid_to_str.
	* i386-sol2-tdep.c (i386_sol2_sigtramp_p): Remove.
	(i386_sol2_static_transform_name): Remove.
	(i386_sol2_init_abi): Call sol2_init_abi.
	Remove calls to set_gdbarch_sofun_address_maybe_missing,
	set_gdbarch_static_transform_name,
	set_gdbarch_skip_solib_resolver, set_gdbarch_core_pid_to_str.
	Use sol2_sigtramp_p.
	* sol2-tdep.c (sol2_pc_in_sigtramp): New function.
	(sol2_sigtramp_p): New function.
	(sol2_static_transform_name): New function.
	(sol2_skip_solib_resolver, sol2_core_pid_to_str): Make static.
	(sol2_init_abi): New function.
	* sol2-tdep.h (sol2_sigtramp_p, sol2_init_abi): Declare.
	(sol2_skip_solib_resolver, sol2_core_pid_to_str): Remove.
	* sparc-sol2-tdep.c (sparc_sol2_pc_in_sigtramp): Remove.
	(sparc32_sol2_sigtramp_frame_sniffer): Just call sol2_sigtramp_p.
	(sparc_sol2_static_transform_name): Remove.
	(sparc32_sol2_init_abi): Call sol2_init_abi.
	Remove calls to set_gdbarch_sofun_address_maybe_missing,
	set_gdbarch_static_transform_name,
	set_gdbarch_skip_solib_resolver,
	set_gdbarch_core_pid_to_str.
	* sparc-tdep.h (sparc_sol2_pc_in_sigtramp)
	(sparc_sol2_static_transform_name): Remove
	* sparc64-sol2-tdep.c (sparc64_sol2_sigtramp_frame_sniffer): Just
	call sol2_sigtramp_p.
	(sparc64_sol2_init_abi): Call sol2_init_abi.
	Remove calls to set_gdbarch_sofun_address_maybe_missing,
	set_gdbarch_static_transform_name,
	set_gdbarch_skip_solib_resolver, set_gdbarch_core_pid_to_str.
2020-06-25 13:43:46 +02:00
Philippe Waroquiers a8654e7d78 Fixes PR 25475: ensure exec-file-mismatch "ask" always asks in case of mismatch.
As explained in https://sourceware.org/bugzilla/show_bug.cgi?id=25475,
when the currently loaded file has no debug symbol,
symbol_file_add_with_addrs does not ask a confirmation to the user
before loading the new symbol file.  The behaviour is not consistent
when symbol_file_add_with_addrs is called due to exec-file-mismatch "ask"
setting.

The PR discusses several solutions/approaches.
The preferred approach (suggested by Joel) is to ensure that GDB always asks
a confirmation when it loads a new symbol file due to exec-file-mismatch,
using a new SYMFILE add-flag.

I tested this manually.  If OK, we can remove the bypass introduced by Tom
in 6b9374f1, in order to always answer to the 'load' question.

gdb/ChangeLog
2020-06-24  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* symfile-add-flags.h: New flag SYMFILE_ALWAYS_CONFIRM.
	* exec.c (validate_exec_file): If from_tty, set both
	SYMFILE_VERBOSE (== from_tty) and SYMFILE_ALWAYS_CONFIRM.
	* symfile.c (symbol_file_add_with_addrs): if always_confirm
	and from_tty, unconditionally ask a confirmation.
2020-06-24 22:21:07 +02:00
Andrew Burgess caa7fd04f6 gdb: New maintenance command to print XML target description
This commit adds a new maintenance command that dumps the current
target description as an XML document.  This is a maintenance command
as I currently only see this being useful for GDB developers, or for
people debugging a new remote target.

By default the command will print whatever the current target
description is, whether this was delivered by the remote, loaded by
the user from a file, or if it is a built in target within GDB.

The command can also take an optional filename argument.  In this case
GDB loads a target description from the file, and then reprints it.
This could be useful for testing GDB's parsing of target descriptions,
or to check that GDB can successfully parse a particular XML
description.

It is worth noting that the XML description printed will not be an
exact copy of the document fed into GDB.  For example this minimal
input file:

  <target>
    <feature name="abc">
      <reg name="r1" bitsize="32"/>
    </feature>
  </target>

Will produce this output:

  (gdb) maint print xml-tdesc path/to/file.xml
  <?xml version="1.0"?>
  <!DOCTYPE target SYSTEM "gdb-target.dtd">
  <target>
    <feature name="abc">
      <reg name="r1" bitsize="32" type="int" regnum="0"/>
    </feature>
  </target>

Notice that GDB filled in both the 'type' and 'regnum' fields of the
<reg>.  I think this is actually a positive as it means we get to
really understand how GDB processed the document, if GDB made some
assumptions that differ to those the user expected then hopefully this
will bring those issues to the users attention.

To implement this I have tweaked the output produced by the
print_xml_feature which is defined within the gdbsupport/ directory.
The changes I have made to this class are:

  1. The <architecture>...</architecture> tags are now not produced if
  the architecture name is NULL.

  2. The <osabi>...</osabi> tags get a newline at the end.

  3. And, the whole XML document is indented using white space in a
  nested fashion (as in the example output above).

I think that these changes should be fine, the print_xml_feature class
is used:

  1. In gdbserver to generate an XML document to send as the target
  description to GDB.

  2. In GDB as part of a self-check function, a target_desc is
  converted to XML then parsed back into a target_desc.  We then check
  the before and after target_desc objects are the same.

  3. In the new 'maint print xml-tdesc' command.

In all of these use cases adding the extra white space should be fine.

gdbsupport/ChangeLog:

	* tdesc.cc (print_xml_feature::visit_pre): Use add_line to add
	output content, and call indent as needed in all overloaded
	variants.
	(print_xml_feature::visit_post): Likewise.
	(print_xml_feature::visit): Likewise.
	(print_xml_feature::add_line): Two new overloaded functions.
	* tdesc.h (print_xml_feature::indent): New member function.
	(print_xml_feature::add_line): Two new overloaded member
	functions.
	(print_xml_feature::m_depth): New member variable.

gdb/ChangeLog:

	* target-descriptions.c (tdesc_architecture_name): Protect against
	NULL pointer dereference.
	(maint_print_xml_tdesc_cmd): New function.
	(_initialize_target_descriptions): Register new 'maint print
	xml-tdesc' command and give it the filename completer.
	* NEWS: Mention new 'maint print xml-tdesc' command.

gdb/testsuite/ChangeLog:

	* gdb.xml/tdesc-reload.c: New file.
	* gdb.xml/tdesc-reload.exp: New file.
	* gdb.xml/maint-xml-dump-01.xml: New file.
	* gdb.xml/maint-xml-dump-02.xml: New file.
	* gdb.xml/maint-xml-dump.exp: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Document new 'maint print
	xml-desc' command.
2020-06-23 22:17:20 +01:00
Andrew Burgess fbf42f4e6d gdb: Print compatible information within print_xml_feature
The gdbsupport directory contains a helper class print_xml_feature
that is shared between gdb and gdbserver.  This class is used for
printing an XML representation of a target_desc object.

Currently this class doesn't have the ability to print the
<compatible> entities that can appear within a target description, I
guess no targets have needed that functionality yet.

The print_xml_feature classes API is based around operating on the
target_desc class, however, the sharing between gdb and gdbserver is
purely textural, we rely on their being a class called target_desc in
both gdb and gdbserver, but there is no shared implementation.  We
then have a set of functions declared that operate on an object of
type target_desc, and again these functions have completely separate
implementations.

Currently then the gdb version of target_desc contains a vector of
bfd_arch_info pointers which represents the compatible entries from a
target description.  The gdbserver version of target_desc has no such
information.  Further, the gdbserver code doesn't seem to include the
bfd headers, and so doesn't know about the bfd types.

I was reluctant to include the bfd headers into gdbserver just so I
can reference the compatible information, which isn't (currently) even
needed in gdbserver.

So, the approach I take in this patch is to wrap the compatible
information into a new helper class.  This class is declared in the
gdbsupport library, but implemented separately in both gdb and
gdbserver.

In gdbserver the class is empty.  The compatible information within
the gdbserver is an empty list, of empty classes.

In gdb the class contains a pointer to the bfd_arch_info object.

With this in place we can now add support to print_xml_feature for
printing the compatible information if it is present.  In the
gdbserver code this will never happen, as the gdbserver never has any
compatible information.  But in gdb, this code will trigger when
appropriate.

gdb/ChangeLog:

	* target-descriptions.c (class tdesc_compatible_info): New class.
	(struct target_desc): Change type of compatible vector.
	(tdesc_compatible_p): Update for change in type of
	target_desc::compatible.
	(tdesc_compatible_info_list): New function.
	(tdesc_compatible_info_arch_name): New function.
	(tdesc_add_compatible): Update for change in type of
	target_desc::compatible.
	(print_c_tdesc::visit_pre): Likewise.

gdbserver/ChangeLog:

	* tdesc.cc (struct tdesc_compatible_info): New struct.
	(tdesc_compatible_info_list): New function.
	(tdesc_compatible_info_arch_name): New function.

gdbsupport/ChangeLog:

	* tdesc.cc (print_xml_feature::visit_pre): Print compatible
	information.
	* tdesc.h (struct tdesc_compatible_info): Declare new struct.
	(tdesc_compatible_info_up): New typedef.
	(tdesc_compatible_info_list): Declare new function.
	(tdesc_compatible_info_arch_name): Declare new function.
2020-06-23 22:17:19 +01:00
Andrew Burgess 20821f4ed1 gdb: Allow target description to be dumped even when it is remote
The maintenance command 'maintenance print c-tdesc' can only print the
target description if it was loaded from a local file, or if the local
filename is passed to the maintenance command as an argument.

Sometimes it would be nice to know what target description GDB was
given by the remote, however, if I connect to a remote target and try
this command I see this:

  (gdb) maintenance print c-tdesc
  The current target description did not come from an XML file.
  (gdb)

Which is not very helpful.

This commit changes things so that if the description came from the
remote end then GDB will use a fake filename 'fetched from target' as
the filename for the description, GDB will then create the C
description of the target as though it came from this file.  Example
output would look like this (I snipped the feature creation from the
middle as that hasn't changed):

  (gdb) maintenance print c-tdesc
  /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
    Original: fetched from target */

  #include "defs.h"
  #include "osabi.h"
  #include "target-descriptions.h"

  struct target_desc *tdesc_fetched_from_target;
  static void
  initialize_tdesc_fetched_from_target (void)
  {
    struct target_desc *result = allocate_target_description ();
    struct tdesc_feature *feature;

    /* ... features created here ... */

    tdesc_fetched_from_target = result;
  }
  (gdb)

In order to support using 'fetched from target' I had to update the
print_c_tdesc code to handle filenames that include a space.  This has
the benefit that we can now print out real files with spaces in the
name, for example the file 'with space.xml':

  (gdb) maint print c-tdesc with space.xml

I originally added this functionality so I could inspect the
description passed to GDB by the remote target.  After using this for
a while I realised that actually having GDB recreate the XML would be
even better, so a later commit will add that functionality too.

Still, given how small this patch is I thought it might be nice to
include this in GDB anyway.

While I was working on this anyway I've added filename command
completion to this command.

gdb/ChangeLog:

	* target-descriptions.c (print_c_tdesc::print_c_tdesc): Change
	whitespace to underscore.
	(maint_print_c_tdesc_cmd): Use fake filename for target
	descriptions that came from the target.
	(_initialize_target_descriptions): Add filename command completion
	for 'maint print c-tdesc'.
2020-06-23 22:17:18 +01:00
Simon Marchi 1fb5ee6203 gdb: add some more empty lines in loc.c
Add some empty lines at places I forgot in the previous patch.

gdb/ChangeLog:

	* dwarf2/loc.c (decode_debug_loclists_addresses): Add empty
	lines.

Change-Id: I8a9f3766ede1ce750e0703023285dca873bce0da
2020-06-23 15:40:24 -04:00
Simon Marchi fc3ecb3e61 gdb: add empty lines in loc.c
I always found that some switch statements in this file were a bit too
packed.  I think having empty lines between each case helps with
reading.  I'm pushing this as obvious, I hope it won't be too
controversial.

gdb/ChangeLog:

	* dwarf2/loc.c (decode_debug_loc_dwo_addresses): Add empty
	lines.
	(dwarf2_find_location_expression): Likewise.
	(call_site_parameter_matches): Likewise.
	(dwarf2_compile_expr_to_ax): Likewise.
	(disassemble_dwarf_expression): Likewise.
	(loclist_describe_location): Likewise.

Change-Id: I381366a0468ff1793faa612c46ef48a9d4773192
2020-06-23 15:34:45 -04:00
Pedro Alves 236ef0346d Fix "maint selftest" regression, add struct scoped_mock_context
This commit:

 commit 3922b30264
 Author:     Pedro Alves <palves@redhat.com>
 AuthorDate: Thu Jun 18 21:28:37 2020 +0100

    Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR 25412)

caused a regression for gdb.gdb/unittest.exp when GDB is configured
with --enable-targets=all.  The failure is:

  gdb/thread.c:95: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed.

The problem is in this line in regcache.c:cooked_read_test:

  /* Switch to the mock thread.  */
  scoped_restore restore_inferior_ptid
    = make_scoped_restore (&inferior_ptid, mock_ptid);

Both gdbarch-selftest.c and regcache.c set up a similar mock context,
but the series the patch above belongs to only updated the
gdbarch-selftest.c context to not write to inferior_ptid directly, and
missed updating regcache.c's.

Instead of copying the fix over to regcache.c, share the mock context
setup code in a new RAII class, based on gdbarch-selftest.c's version.

Also remove the "target already pushed" error from regcache.c, like it
had been removed from gdbarch-selftest.c in the multi-target series.
That check is unnecessary because each inferior now has its own target
stack, and the unit test pushes a target on a separate (mock)
inferior, not the current inferior on entry.

gdb/ChangeLog:
2020-06-23  Pedro Alves  <palves@redhat.com>

	* gdbarch-selftests.c: Don't include inferior.h, gdbthread.h or
	progspace-and-thread.h.  Include scoped-mock-context.h instead.
	(register_to_value_test): Use scoped_mock_context.
	* regcache.c: Include "scoped-mock-context.h".
	(cooked_read_test): Don't error out if a target is already pushed.
	Use scoped_mock_context.  Adjust.
	* scoped-mock-context.h: New file.
2020-06-23 18:57:03 +01:00
Andrew Burgess 39e7eccae6 gdb: Convert language la_is_string_type_p field to a method
This commit changes the language_data::la_is_string_type_p function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_is_string_type_p
	initializer.
	(ada_language::is_string_type_p): New member function.
	* c-lang.c (c_language_data): Delete la_is_string_type_p
	initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_is_string_type_p): Delete function, implementation
	moved to f_language::is_string_type_p.
	(f_language_data): Delete la_is_string_type_p initializer.
	(f_language::is_string_type_p): New member function,
	implementation from f_is_string_type_p.
	* go-lang.c (go_is_string_type_p): Delete function, implementation
	moved to go_language::is_string_type_p.
	(go_language_data): Delete la_is_string_type_p initializer.
	(go_language::is_string_type_p): New member function,
	implementation from go_is_string_type_p.
	* language.c (language_defn::is_string_type_p): Define new member
	function.
	(default_is_string_type_p): Make static, add comment copied from
	header file.
	(unknown_language_data): Delete la_is_string_type_p initializer.
	(unknown_language::is_string_type_p): New member function.
	(auto_language_data): Delete la_is_string_type_p initializer.
	(auto_language::is_string_type_p): New member function.
	* language.h (language_data): Delete la_is_string_type_p field.
	(language_defn::is_string_type_p): Declare new function.
	(default_is_string_type_p): Delete desclaration, move comment to
	definition.
	* m2-lang.c (m2_is_string_type_p): Delete function, implementation
	moved to m2_language::is_string_type_p.
	(m2_language_data): Delete la_is_string_type_p initializer.
	(m2_language::is_string_type_p): New member function,
	implementation from m2_is_string_type_p.
	* objc-lang.c (objc_language_data): Delete la_is_string_type_p
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_is_string_type_p): Delete function,
	implementation moved to pascal_language::is_string_type_p.
	(pascal_language_data): Delete la_is_string_type_p initializer.
	(pascal_language::is_string_type_p): New member function,
	implementation from pascal_is_string_type_p.
	* rust-lang.c (rust_is_string_type_p): Delete function,
	implementation moved to rust_language::is_string_type_p.
	(rust_language_data): Delete la_is_string_type_p initializer.
	(rust_language::is_string_type_p): New member function,
	implementation from rust_is_string_type_p.
	* valprint.c (val_print_scalar_or_string_type_p): Update call to
	is_string_type_p.
2020-06-23 13:34:11 +01:00
Andrew Burgess 4ffc13fb0e gdb: Convert language la_print_typedef field to a method
This commit changes the language_data::la_print_typedef function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_print_typedef
	initializer.
	(ada_language::print_typedef): New member function.
	* c-lang.c (c_language_data): Delete la_print_typedef initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	(f_language::print_typedef): New member function.
	* go-lang.c (go_language_data): Delete la_print_typedef
	initializer.
	* language.c (language_defn::print_typedef): Define member
	function.
	(unknown_language_data): Delete la_print_typedef initializer.
	(unknown_language::print_typedef): New member function.
	(auto_language_data): Delete la_print_typedef initializer.
	(auto_language::print_typedef): New member function.
	* language.h (language_data): Delete la_print_typedef field.
	(language_defn::print_typedef): Declare new member function.
	(LA_PRINT_TYPEDEF): Update call to print_typedef.
	(default_print_typedef): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_print_typedef
	initializer.
	(m2_language::print_typedef): New member function.
	* objc-lang.c (objc_language_data): Delete la_print_typedef
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	(pascal_language::print_typedef): New member function.
	* rust-lang.c (rust_print_typedef): Delete function,
	implementation moved to rust_language::print_typedef.
	(rust_language): Delete la_print_typedef initializer.
	(rust_language::print_typedef): New member function,
	implementation from rust_print_typedef.
	* typeprint.c (default_print_typedef): Delete.
2020-06-23 13:34:11 +01:00
Andrew Burgess d711ee67ac gdb: Convert language la_printstr field to a method
This commit changes the language_data::la_printstr function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_printstr initializer.
	(ada_language::printstr): New member function.
	* c-lang.c (c_language_data): Delete la_printstr initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_printstr): Rename to f_language::printstr.
	(f_language_data): Delete la_printstr initializer.
	(f_language::printstr): New member function, implementation from
	f_printstr.
	* go-lang.c (go_language_data): Delete la_printstr initializer.
	* language.c (language_defn::printstr): Define new member
	function.
	(unk_lang_printstr): Delete.
	(unknown_language_data): Delete la_printstr initializer.
	(unknown_language::printstr): New member function.
	(auto_language_data): Delete la_printstr initializer.
	(auto_language::printstr): New member function.
	* language.h (language_data): Delete la_printstr field.
	(language_defn::printstr): Declare new member function.
	(LA_PRINT_STRING): Update call to printstr.
	* m2-lang.c (m2_printstr): Rename to m2_language::printstr.
	(m2_language_data): Delete la_printstr initializer.
	(m2_language::printstr): New member function, implementation from
	m2_printstr.
	* objc-lang.c (objc_language_data): Delete la_printstr
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_printstr): Rename to pascal_language::printstr.
	(pascal_language_data): Delete la_printstr initializer.
	(pascal_language::printstr): New member function, implementation
	from pascal_printstr.
	* p-lang.h (pascal_printstr): Delete declaration.
	* rust-lang.c (rust_printstr): Update header comment.
	(rust_language_data): Delete la_printstr initializer.
	(rust_language::printstr): New member function.
2020-06-23 13:34:11 +01:00
Andrew Burgess 52b50f2c1b gdb: Convert language la_printchar field to a method
This commit changes the language_data::la_printchar function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_printchar initializer.
	(ada_language::printchar): New member function.
	* c-lang.c (c_language_data): Delete la_printchar initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_printchar): Rename to f_language::printchar.
	(f_language_data): Delete la_printchar initializer.
	(f_language::printchar): New member function, implementation from
	f_printchar.
	* go-lang.c (go_language_data): Delete la_printchar initializer.
	* language.c (unk_lang_printchar): Delete.
	(language_defn::printchar): Define new member function.
	(unknown_language_data): Delete la_printchar initializer.
	(unknown_language::printchar): New member function.
	(auto_language_data): Delete la_printchar initializer.
	(auto_language::printchar): New member function.
	* language.h (language_data): Delete la_printchar field.
	(language_defn::printchar): Declare new member function.
	(LA_PRINT_CHAR): Update call to printchar.
	* m2-lang.c (m2_language_data): Delete la_printchar initializer.
	(m2_language::printchar): New member function.
	* objc-lang.c (objc_language_data): Delete la_printchar
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Delete la_printchar
	initializer.
	(pascal_language::printchar): New member function.
	* rust-lang.c (rust_printchar): Rename to
	rust_language::printchar.
	(rust_language_data): Delete la_printchar initializer.
	(rust_language::printchar): New member function, implementation
	from rust_printchar.
2020-06-23 13:34:11 +01:00
Andrew Burgess ec8cec5b96 gdb: Convert language la_emitchar field to a method
This commit changes the language_data::la_emitchar function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (emit_char): Renamed to ada_language::emitchar.
	(ada_language_data): Delete la_emitchar initializer.
	(ada_language::emitchar): New member function, implementation from
	emit_char.
	* c-lang.c (c_language_data): Delete la_emitchar initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_emit_char): Rename to f_language::emitchar.
	(f_language_data): Delete la_emitchar initializer.
	(f_language::emitchar): New member function, implementation from
	f_emit_char.
	* go-lang.c (go_language_data): Delete la_emitchar initializer.
	* language.c (unk_lang_emit_char): Delete.
	(language_defn::emitchar): New member function definition.
	(unknown_language_data): Delete la_emitchar initializer.
	(unknown_language::emitchar): New member function.
	(auto_language_data): Delete la_emitchar initializer.
	(auto_language::emitchar): New member function.
	* language.h (language_data): Delete la_emitchar field.
	(language_defn::emitchar): New member field declaration.
	(LA_EMIT_CHAR): Update call to emitchar.
	* m2-lang.c (m2_emit_char): Rename to m2_language::emitchar.
	(m2_language_data): Delete la_emitchar initializer.
	(m2_language::emitchar): New member function, implementation from
	m2_emit_char.
	* objc-lang.c (objc_language_data): Delete la_emitchar
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_emit_char): Rename to pascal_language::emitchar.
	(pascal_language_data): Delete la_emitchar initializer.
	(pascal_language::emitchar): New member function, implementation
	from pascal_emit_char.
	* rust-lang.c (rust_emitchar): Rename to rust_language::emitchar.
	(rust_language_data): Delete la_emitchar initializer.
	(rust_language::emitchar): New member function, implementation
	from rust_emitchar.
2020-06-23 13:34:11 +01:00
Andrew Burgess 1bf9c36374 gdb: Convert language la_post_parser field to a method
This commit changes the language_data::la_post_parser function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (resolve): Rename to ada_language::post_parser.
	(ada_language_data): Delete la_post_parser initializer.
	(ada_language::post_parser): New member function.
	* c-lang.c (c_language_data): Delete la_post_parser initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_post_parser field.
	(language_defn::post_parser): New member function.
	* m2-lang.c (m2_language_data): Delete la_post_parser initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* parse.c (parse_exp_in_context): Update call to post_parser.
	(null_post_parser): Delete definition.
	* parser-defs.h (null_post_parser): Delete declaration.
	* rust-lang.c (rust_language_data): Delete la_post_parser
	initializer.
2020-06-23 13:34:11 +01:00
Andrew Burgess 87afa6523b gdb: Convert language la_parser field to a method
This commit changes the language_data::la_parser function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (parse): Rename to ada_language::parser.
	(ada_language_data): Delete la_parser initializer.
	(ada_language::parser): New member function, implementation from
	parse.
	* c-lang.c (c_language_data): Delete la_parser initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	(d_language::parser): New member function.
	* f-lang.c (f_language_data): Delete la_parser initializer.
	(f_language::parser): New member function.
	* go-lang.c (go_language_data): Delete la_parser initializer.
	(go_language::parser): New member function.
	* language.c (unk_lang_parser): Delete.
	(language_defn::parser): Define new member function.
	(unknown_language_data): Delete la_parser initializer.
	(unknown_language::parser): New member function.
	(auto_language_data): Delete la_parser initializer.
	(auto_language::parser): New member function.
	* language.h (language_data): Delete la_parser field.
	(language_defn::parser): Declare new member function.
	* m2-lang.c (m2_language_data): Delete la_parser initializer.
	(m2_language::parser): New member function.
	* objc-lang.c (objc_language_data): Delete la_parser initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	(pascal_language::parser): New member function.
	* parse.c (parse_exp_in_context): Update call to parser.
	* rust-lang.c (rust_language_data): Delete la_parser initializer.
	(rust_language::parser): New member function.
2020-06-23 13:34:10 +01:00
Andrew Burgess 378258006c gdb: Add --with-python-libdir to gdb's --configuration output
Commit:

  commit d13c7322fe
  Date:   Fri Jan 17 00:10:22 2020 +0000

      gdb: Allow more control over where to find python libraries

Added a new configuration option --with-python-libdir, but failed to
add this option to the output of 'gdb --configuration'.  This commit
fixes this mistake.

gdb/ChangeLog:

	* top.c (print_gdb_configuration): Print --with-python-libdir
	configuration value.
2020-06-23 10:06:20 +01:00
Philippe Waroquiers 5b860c93e3 NEWS and documentation for alias default-args related concept and commands.
gdb/ChangeLog
2020-06-22  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Mention change to the alias command.

gdb/doc/ChangeLog
2020-06-22  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Command aliases default args): New node documenting
	how to use default args for a command using aliases.
	(Aliases): Document the new 'DEFAULT-ARGS...' option.
	(Help): Update help aliases text and describe when full alias
	definition is provided.
2020-06-22 21:16:25 +02:00
Philippe Waroquiers cf00cd6faf default-args: allow to define default arguments for aliases
Currently, a user can define an alias, but cannot have default
arguments for this alias.

This patch modifies the 'alias' command so that default args can
be provided.
    (gdb) h alias
    Define a new command that is an alias of an existing command.
    Usage: alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...]
    ALIAS is the name of the alias command to create.
    COMMAND is the command being aliased to.

    Options:
      -a
        Specify that ALIAS is an abbreviation of COMMAND.
        Abbreviations are not used in command completion..

    GDB will automatically prepend the provided DEFAULT-ARGS to the list
    of arguments explicitly provided when using ALIAS.
    Use "help aliases" to list all user defined aliases and their default args.

    Examples:
    Make "spe" an alias of "set print elements":
      alias spe set print elements
    Make "elms" an alias of "elements" in the "set print" command:
      alias -a set print elms set print elements
    Make "btf" an alias of "backtrace -full -past-entry -past-main" :
      alias btf = backtrace -full -past-entry -past-main
    Make "wLapPeu" an alias of 2 nested "with":
      alias wLapPeu = with language pascal -- with print elements unlimited --
    (gdb)

The way 'default-args' is implemented makes it trivial to set default
args also for GDB commands (such as "backtrace") and for GDB pre-defined
aliases (such as "bt").  It was however deemed better to not allow to
define default arguments for pre-defined commands and aliases, to avoid
users believing that e.g. default args for "backtrace" would apply to "bt".

If needed, default-args could be allowed for GDB predefined commands
and aliases by adding a command
'set default-args GDB_COMMAND_OR_PREDEFINED_ALIAS [DEFAULT-ARGS...]'.

* 'alias' command now has a completer that helps to complete:
     - ALIAS (if the user defines an alias after a prefix),
     - the aliased COMMAND
     - the possible options for the aliased COMMAND.

* Help and apropos commands show the definitions of the aliases
  that have default arguments, e.g.
        (gdb) help backtrace
        backtrace, btf, where, bt
          alias btf = backtrace -full -past-entry -past-main
        Print backtrace of all stack frames, or innermost COUNT frames.
        Usage: backtrace [OPTION]... [QUALIFIER]... [COUNT | -COUNT]

        Options:
          -entry-values no|only|preferred|if-needed|both|compact|default
            Set printing of function arguments at function entry.
        ...

gdb/ChangeLog
2020-06-22  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-cmds.c (lookup_cmd_for_default_args)
	(alias_command_completer)
	(make_alias_options_def_group): New functions.
	(alias_opts, alias_option_defs): New struct and array.
	(alias_usage_error): Update usage.
	(alias_command): Handles optional DEFAULT-ARGS... arguments.
	Use option framework.
	(_initialize_cli_cmds): Update alias command help.
	Update aliases command help.
	(show_user):
	Add NULL for new default_args lookup_cmd argument.
	(valid_command_p): Rename to validate_aliased_command.
	Add NULL for new default_args lookup_cmd argument.  Verify that the
	aliased_command has no default args.
	* cli/cli-decode.c (help_cmd): Show aliases definitions.
	(lookup_cmd_1, lookup_cmd): New argument default_args.
	(add_alias_cmd):
	Add NULL for new default_args lookup_cmd argument.
	(print_help_for_command): Show default args under the layout
	 alias some_alias = some_aliased_cmd some_alias_default_arg.
	* cli/cli-decode.h (struct cmd_list_element): New member default_args.
	xfree default_args in destructor.
	* cli/cli-script.c (process_next_line, do_define_command):
	Add NULL for new default_args lookup_cmd argument.
	* command.h: Declare new default_args argument in lookup_cmd
	and lookup_cmd_1.
	* completer.c (complete_line_internal_1):
	Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument.
	* guile/scm-cmd.c (gdbscm_parse_command_name): Likewise.
	* guile/scm-param.c (add_setshow_generic, pascm_parameter_defined_p):
	Likewise.
	* infcmd.c (_initialize_infcmd): Likewise.
	* python/py-auto-load.c (gdbpy_initialize_auto_load): Likewise.
	* python/py-cmd.c (gdbpy_parse_command_name): Likewise.
	* python/py-param.c (add_setshow_generic): Likewise.
	* remote.c (_initialize_remote): Likewise.
	* top.c (execute_command): Prepend default_args if command has some.
	(set_verbose):
	Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument.
	* tracepoint.c (validate_actionline, encode_actions_1):
	Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument.
2020-06-22 21:14:13 +02:00
Tankut Baris Aktemur bd920864f3 gdb/jit: return bool in jit_breakpoint_re_set_internal and jit_read_descriptor
This is a minor refactoring that converts the return type of
jit_read_descriptor and jit_breakpoint_re_set_internal functions
from 'int' to 'bool'.

The return value logic of jit_breakpoint_re_set_internal has been
reversed.  With this patch it now returns true if the jit breakpoint
has been successfully initialized.

gdb/ChangeLog:
2020-06-22  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* jit.c (jit_read_descriptor): Use bool as the return type.
	(jit_breakpoint_re_set_internal): Use bool as the return type.
	Invert the return value logic; return true if the jit breakpoint
	has been successfully initialized.
	(jit_inferior_init): Update the call to
	jit_breakpoint_re_set_internal.
2020-06-22 14:03:33 +02:00
Pedro Alves f809832224 Solaris, target_wait(), don't rely on inferior_ptid
Debugging on Solaris is broken, with the procfs target backend failing
with:

 procfs: couldn't find pid 0 in procinfo list.

as soon as you start a program.

The problem is procfs_target::wait assuming that inferior_ptid is
meaningful on entry, but, since the multi-target series, inferior_ptid
is null_ptid before we call target_wait, in infrun.c:

  static ptid_t
  do_target_wait_1 (inferior *inf, ptid_t ptid,
		    target_waitstatus *status, int options)
  {
...
    /* We know that we are looking for an event in the target of inferior
       INF, but we don't know which thread the event might come from.  As
       such we want to make sure that INFERIOR_PTID is reset so that none of
       the wait code relies on it - doing so is always a mistake.  */
    switch_to_inferior_no_thread (inf);

This patch tweaks the backend to remove the assumption that
inferior_ptid points at something.  sol-thread.c (the thread_stratum
that sits on top of procfs.c) also has the same issue.

Some spots in procfs_target::wait were returning
TARGET_WAITKIND_SPURIOUS+inferior_ptid.  This commit replaces those
with waiting again without returning to the core.  This fixes the
relying on inferior_ptid, and also should fix the issue discussed
here:
  https://sourceware.org/pipermail/gdb/2020-May/048616.html
  https://sourceware.org/pipermail/gdb/2020-June/048660.html

gdb/ChangeLog:
2020-06-22  Pedro Alves  <palves@redhat.com>

	PR gdb/25939
	* procfs.c (procfs_target::wait): Don't reference inferior_ptid.
	Use the current inferior instead.  Don't return
	TARGET_WAITKIND_SPURIOUS/inferior_ptid -- instead continue and
	wait again.
	* sol-thread.c (sol_thread_target::wait): Don't reference
	inferior_ptid.
	(ps_lgetregs, ps_lsetregs, ps_lgetfpregs, ps_lsetfpregs)
	(sol_update_thread_list_callback): Use the current inferior's pid
	instead of inferior_ptid.
2020-06-22 11:10:49 +01:00
Rainer Orth 196535a69c Various procfs.c cleanups
While reading through procfs.c, I noticed a couple of cleanup
opportunities:

* Some comments and code allowed for portability across different
  targets.  Since procfs.c is Solaris-only for some time now, those can
  go.

* Likewise, there were some references to the old ioctl-based /proc left.

* The code still allowed for SYS_exec.  However, it is no longer present
  in either Solaris 11.3, 11.4, or Illumos.  Checking the OpenSolaris
  sources, I found that it had already been removed in 2010 well before
  the Solaris 11 release.

* Some blocks of #if 0 code can go:

** References to struct procinfo.{g,fp}regs_dirty which are no longer
   defined.

** Code handling the PR_ASLWP flag where <sys/procfs.h> has

#define	PR_ASLWP   0x00000040	/* obsolete flag; never set */

Tested on amd64-pc-solaris2.11.

	* procfs.c: Cleanup many comments.

	(READ_WATCHFLAG, WRITE_WATCHFLAG, EXEC_WATCHFLAG)
	(AFTER_WATCHFLAG): Replace by value.

	(MAIN_PROC_NAME_FORMAT): Inline ...
	(create_procinfo): ... here.

	(procfs_debug_inferior): Remove SYS_exec handling.
	(syscall_is_exec): Likewise.
	(procfs_set_exec_trap): Likewise.

	(syscall_is_lwp_exit): Inline in callers.
	(syscall_is_exit): Likewise.
	(syscall_is_exec): Likewise.
	(syscall_is_lwp_create): Likewise.

	(invalidate_cache): Remove #if 0 code.

	(make_signal_thread_runnable):  Remove.
	(procfs_target::resume): Remove #if 0 code.
2020-06-21 18:51:58 +02:00
Rainer Orth cf6f3e86de [PR gdb/25939] Move push_target call earlier in procfs.c
Since the multi-target patch, the run command fails on Solaris with an
assertion failure even for a trivial program:

$ ./gdb -D ./data-directory ./hello
GNU gdb (GDB) 10.0.50.20200106-git
[...]
Reading symbols from ./hello...
(gdb) run
Starting program: /vol/obj/gnu/gdb/gdb/reghunt/no-resync/122448/gdb/hello
/vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:336: internal-error:
thread_info::thread_info(inferior*, ptid_t): Assertion `inf_ != NULL'
failed.

Here's the start of the corresponding stack trace:

#0  internal_error (
    file=file@entry=0x966150
"/vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c", line=line@entry=336,
fmt=0x9ddb94 "%s: Assertion `%s' failed.")
    at /vol/src/gnu/gdb/hg/master/reghunt/gdb/gdbsupport/errors.c:51
#1  0x0000000000ef81f4 in thread_info::thread_info (this=0x1212020,
    inf_=<optimized out>, ptid_=...)
    at /vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:344
#2  0x0000000000ef82cd in new_thread (inf=inf@entry=0x0, ptid=...)
    at /vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:239
#3  0x0000000000efac3c in add_thread_silent (
    targ=targ@entry=0x11b0940 <the_procfs_target>, ptid=...)
    at /vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:304
#4  0x0000000000d90692 in procfs_target::create_inferior (
    this=0x11b0940 <the_procfs_target>,
    exec_file=0x13dbef0
"/vol/obj/gnu/gdb/gdb/reghunt/no-resync/122448/gdb/hello", allargs="",
env=0x13c48f0, from_tty=<optimized out>)
    at /vol/src/gnu/gdb/hg/master/reghunt/gdb/gdbsupport/ptid.h:47
#5  0x0000000000c84e64 in run_command_1 (args=<optimized out>, from_tty=1,
    run_how=run_how@entry=RUN_NORMAL)
    at /vol/gcc-9/include/c++/9.1.0/bits/basic_string.h:263
#6  0x0000000000c85007 in run_command (args=<optimized out>,
    from_tty=<optimized out>)
    at /vol/src/gnu/gdb/hg/master/reghunt/gdb/infcmd.c:687

Looking closer, I found that in add_thread_silent as called from
procfs.c (procfs_target::create_inferior) find_inferior_ptid returns
NULL.  The all_inferiors (targ) iterator comes up empty.

Going from there, I see that in add_thread_silent

m_target_stack = {m_top = file_stratum, m_stack = {0x20190e0
<the_dummy_target>, 0x200b8c0 <exec_ops>, 0x0, 0x0, 0x0, 0x0, 0x0}}}

i.e. the_procfs_target is missing compared to the_amd64_linux_nat_target
on Linux/x86_64.

Moving the push_target call earlier allows debugging to get over the
initial assertion failure.  I run instead into

procfs: couldn't find pid 0 in procinfo list.

which is fixed by

	https://sourceware.org/pipermail/gdb-patches/2020-June/169674.html

Both patches tested together on amd64-pc-solaris2.11.

	PR gdb/25939
	* procfs.c (procfs_target::procfs_init_inferior): Move push_target
	call ...
	(procfs_target::create_inferior): ... here.
2020-06-21 18:32:27 +02:00
Philippe Waroquiers 48e9cc8405 Ensure 'exec-file has changed' check has priority over 'exec-file-mismatch' check
Following the implementation of exec-file-mismatch based on build-id,
an attach to a process that runs a modified exec-file was triggering
the exec-file-mismatch handling, giving a warning such as:
  warning: Mismatch between current exec-file /bd/home/philippe/gdb/git/build_termours/gdb/testsuite/outputs/gdb.base/attach/attach
  and automatically determined exec-file /bd/home/philippe/gdb/git/build_termours/gdb/testsuite/outputs/gdb.base/attach/attach
  exec-file-mismatch handling is currently "ask"
as the build-ids differ when an exec-file is recompiled.

This patch ensures that the exec-file-mismatch check is done with an up to date
build-id.  With this, exec-file-mismatch check will only trigger when the
PID file really differs from the (build-id refreshed) current exec-file.
Note that the additional check does not (yet) reload the symbols if
the exec-file is changed: this reload will happen later if needed.

gdb/ChangeLog
2020-06-21  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* exec.c (validate_exec_file): Ensure the build-id is up to
	date by calling reopen_exec_file (that checks file timestamp
	to decide to re-read the file).

gdb/testsuite/ChangeLog

2020-06-21  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/attach.exp: Test priority of 'exec-file' changed
	over 'exec-file-mismatch'.
	* gdb.base/attach.c: Mark should_exit volatile.
	* gdb.base/attach2.c: Likewise.  Add a comment explaining
	why the sleep cannot be big.
	* gdb.base/attach3.c: New file.
2020-06-21 12:48:18 +02:00
Pedro Alves 3922b30264 Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR 25412)
In PR 25412, Simon noticed that after the multi-target series, the
tid-reuse.exp testcase manages to create a duplicate thread in the
thread list.  Or rather, two threads with the same PTID.

add_thread_silent has code in place to detect the case of a new thread
reusing some older thread's ptid, but it doesn't work correctly
anymore when the old thread is NOT the current thread and it has a
refcount higher than 0.  Either condition prevents a thread from being
deleted, but the refcount case wasn't being considered.  I think the
reason that case wasn't considered is that that code predates
thread_info refcounting.  Back when it was originally written,
delete_thread always deleted the thread.

That add_thread_silent code in question has some now-unnecessary
warts, BTW.  For instance, this:

  /* Make switch_to_thread not read from the thread.  */
  new_thr->state = THREAD_EXITED;

... used to be required because switch_to_thread would update
'stop_pc' otherwise.  I.e., it would read registers from an exited
thread otherwise.  switch_to_thread no longer reads the stop_pc, since:

  commit f2ffa92bbc
  Author:     Pedro Alves <palves@redhat.com>
  AuthorDate: Thu Jun 28 20:18:24 2018 +0100

      gdb: Eliminate the 'stop_pc' global

Also, if the ptid of the now-gone current thread is reused, we
currently return from add_thread_silent with the current thread
pointing at the _new_ thread.  Either pointing at the old thread, or
at no thread selected would be reasonable.  But pointing at an
unrelated thread (the new thread that happens to reuse the ptid) is
just broken.  Seems like I was the one who wrote it like that but I
have no clue why, FWIW.

Currently, an exited thread kept in the thread list still holds its
original ptid.  The idea was that we need the ptid to be able to
temporarily switch to another thread and then switch back to the
original thread, because thread switching is really inferior_ptid
switching.  Switching back to the original thread requires a ptid
lookup.

Now, in order to avoid exited threads with the same ptid as a live
thread in the same thread list, one thing I considered (and tried) was
to change an exited thread's ptid to minus_one_ptid.  However, with
that, there's a case that we won't handle well, which is if we end up
with more than one exited thread in the list, since then all exited
threads will all have the same ptid.  Since inferior_thread() relies
on inferior_ptid, may well return the wrong thread.

My next attempt to address this, was to switch an exited thread's ptid
to a globally unique "exited" ptid, which is a ptid with pid == -1 and
tid == 'the thread's global GDB thread number'.  Note that GDB assumes
that the GDB global thread number is monotonically increasing and
doesn't wrap around.  (We should probably make GDB thread numbers
64-bit to prevent that happening in practice; they're currently signed
32-bit.)  This attempt went a long way, but still ran into a number of
issues.  It was a major hack too, obviously.

My next attempt is the one that I'm proposing, which is to bite the
bullet and break the connection between inferior_ptid and
inferior_thread(), aka the current thread.  I.e., make the current
thread be a global thread_info pointer that is written to directly by
switch_to_thread, etc., and making inferior_thread() return that
pointer, instead of having inferior_thread() lookup up the
inferior_ptid thread, by ptid_t.  You can look at this as a
continuation of the effort of using more thread_info pointers instead
of ptids when possible.

By making the current thread a global thread_info pointer, we can make
switch_to_thread simply write to the global thread pointer, which
makes scoped_restore_current_thread able to restore back to an exited
thread without relying on unrelyable ptid look ups.  I.e., this makes
it not a real problem to have more than one thread with the same ptid
in the thread list.  There will always be only one live thread with a
given ptid, so code that looks up a live thread by ptid will always be
able to find the right one.

This change required auditing the whole codebase for places where we
were writing to inferior_ptid directly to change the current thread,
and change them to use switch_to_thread instead or one of its
siblings, because otherwise inferior_thread() would return a thread
unrelated to the changed-to inferior_ptid.  That was all (hopefully)
done in previous patches.

After this, inferior_ptid is mainly used by target backend code.  It
is also relied on by a number of target methods.  E.g., the
target_resume interface and the memory reading routines -- we still
need it there because we need to be able to access memory off of
processes for which we don't have a corresponding inferior/thread
object, like when handling forks.  Maybe we could pass down a context
explicitly to target_read_memory, etc.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	PR gdb/25412
	* gdbthread.h (delete_thread, delete_thread_silent)
	(find_thread_ptid): Update comments.
	* thread.c (current_thread_): New global.
	(is_current_thread): Move higher, and reimplement.
	(inferior_thread): Reimplement.
	(set_thread_exited): Use bool.  Add assertions.
	(add_thread_silent): Simplify thread-reuse handling by always
	calling delete_thread.
	(delete_thread): Remove intro comment.
	(find_thread_ptid): Skip exited threads.
	(switch_to_thread_no_regs): Write to current_thread_.
	(switch_to_no_thread): Check CURRENT_THREAD_ instead of
	INFERIOR_PTID.  Clear current_thread_.
2020-06-18 23:18:36 +01:00
Pedro Alves 6dbdab44e5 Don't write to inferior_ptid in aix-thread.c
There are other writes in the file, but they seem more harmless.  This
one is changing the current thread permanently.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* aix-thread.c (pd_update): Use switch_to_thread.
2020-06-18 23:18:08 +01:00
Pedro Alves 2da4b788f7 Don't write to inferior_ptid in ravenscar-thread.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* ravenscar-thread.c (ravenscar_thread_target): Update.
	(ravenscar_thread_target::update_inferior_ptid): Rename to ...
	(ravenscar_thread_target::add_active_thread): ... this.  Don't
	set m_base_ptid here.  Update to avoid referencing inferior_ptid.
	(ravenscar_thread_target::wait): Don't write to inferior_ptid.
2020-06-18 23:17:31 +01:00
Pedro Alves 50838d1be7 Don't write to inferior_ptid in windows-nat.c, part II
Writing to inferior_ptid in
windows_nat_target::get_windows_debug_event is just incorrect and not
necessary.  We'll report the event to GDB's core, which then takes
care of switching inferior_ptid / current thread.

Related (see windows_nat_target::get_windows_debug_event), there's
also a "current_windows_thread" global that is just begging to get out
of sync with core GDB's current thread.  This patch removes it.
gdbserver already does not have an equivalent global in win32-low.cc.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* nat/windows-nat.c (current_windows_thread): Remove.
	* nat/windows-nat.h (current_windows_thread): Remove.
	* windows-nat.c (windows_nat_target::stopped_by_sw_breakpoint):
	Adjust.
	(display_selectors): Adjust to fetch the current
	windows_thread_info based on inferior_ptid.
	(fake_create_process): No longer write to current_windows_thread.
	(windows_nat_target::get_windows_debug_event):
	Don't set inferior_ptid or current_windows_thread.
	(windows_nat_target::wait): Adjust to not rely on
	current_windows_thread.
	(do_initial_windows_stuff): Now a method of windows_nat_target.
	Switch to the last_ptid thread.
	(windows_nat_target::attach): Adjust.
	(windows_nat_target::detach): Use switch_to_no_thread instead of
	writing to inferior_ptid directly.
	(windows_nat_target::create_inferior): Adjust.
2020-06-18 23:17:01 +01:00
Pedro Alves 31ce04e9e0 Don't write to inferior_ptid in windows-nat.c, part I
The inferior_ptid hack in do_initial_win32_stuff, added back in 2008:

  https://sourceware.org/ml/gdb-patches/2008-10/msg00012.html

with:

  commit 9f9d052e60
  Author:     Pierre Muller <muller@sourceware.org>
  AuthorDate: Thu Oct 2 14:20:07 2008 +0000

	      * win32-nat.c (do_initial_win32_stuff): Set inferior_ptid.

is no longer needed.  Back then, current_inferior looked like this:

  struct inferior*
  current_inferior (void)
  {
    struct inferior *inf = find_inferior_pid (ptid_get_pid (inferior_ptid));
    gdb_assert (inf);
    return inf;
  }

Nowadays, current_inferior() just returns the global current_inferior_
pointer, which didn't exist back then.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* windows-nat.c (do_initial_windows_stuff): No longer set inferior_ptid.
2020-06-18 23:16:25 +01:00
Pedro Alves 1ee1a36345 Don't write to inferior_ptid in go32-nat.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* go32-nat.c (go32_nat_target::create_inferior): Switch to thread
	after creating it, instead of writing to inferior_ptid.  Don't
	write to inferior_ptid.
2020-06-18 23:15:48 +01:00
Pedro Alves 6d350754a3 Don't write to inferior_ptid in fork-child.c
This is no longer necessary.  All targets that call fork_inferior now
also call switch_to_thread as soon as they add the main thread.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* fork-child.c (postfork_hook): Don't write to inferior_ptid.
2020-06-18 23:15:16 +01:00
Pedro Alves 5d971d48b9 Don't write to inferior_ptid in bsd-kvm.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* bsd-kvm.c (bsd_kvm_target_open): Switch to thread after adding
	it, instead of writing to inferior_ptid.
2020-06-18 23:14:40 +01:00
Pedro Alves 86e57d1b23 Don't write to inferior_ptid in btrace_fetch
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* btrace.c (btrace_fetch): Use switch_to_thread instead of writing
	to inferior_ptid.
2020-06-18 23:14:15 +01:00
Pedro Alves f2e1c129f8 Don't write to inferior_ptid in bsd-kvm.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* bsd-kvm.c (bsd_kvm_target::close): Use switch_to_no_thread
	instead of writing to inferior_ptid directly.
2020-06-18 23:13:47 +01:00
Pedro Alves 60db1b8565 Don't write to inferior_ptid in corelow.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* corelow.c (core_target::close): Use switch_to_no_thread instead
	of writing to inferior_ptid directly.
	(add_to_thread_list, core_target_open): Use switch_to_thread
	instead of writing to inferior_ptid directly.
2020-06-18 23:12:43 +01:00
Pedro Alves fe7d6a8db0 Don't write to inferior_ptid in darwin-nat.c
Untested.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* darwin-nat.c (darwin_nat_target::decode_message): Don't write to
	inferior_ptid.
	(darwin_nat_target::stop_inferior, darwin_nat_target::kill): Avoid
	inferior_ptid.
	(darwin_attach_pid): Use switch_to_no_thread instead of writing to
	inferior_ptid directly.
	(darwin_nat_target::init_thread_list): Switch to thread, instead
	of writing to inferior_ptid.
	(darwin_nat_target::attach): Don't write to inferior_ptid.
	(darwin_nat_target::get_ada_task_ptid): Avoid inferior_ptid.
2020-06-18 23:11:57 +01:00
Pedro Alves 975f8708de Don't write to inferior_ptid in gnu-nat.c
Untested.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* gnu-nat.c (gnu_nat_target::create_inferior): Switch to the added
	thread.
	(gnu_nat_target::attach): Don't write to inferior_ptid directly.
	Instead use switch_to_thread.
	(gnu_nat_target::detach): Use switch_to_no_thread
	instead of writing to inferior_ptid directly.  Used passed-in
	inferior instead of looking up the inferior by pid.
2020-06-18 23:11:23 +01:00
Pedro Alves 1a20473059 Don't write to inferior_ptid in go32-nat.c
generic_mourn_inferior already takes care of switching to no thread.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* go32-nat.c (go32_nat_target::create_inferior): Don't write to
	inferior_ptid.
2020-06-18 23:10:53 +01:00
Pedro Alves ebe84f23d2 Don't write to inferior_ptid in nto-procfs.c
A best effort patch, which fixes some bit rot and removes some
inferior_ptid references -- this port clearly hasn't been built in a
long while.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* nto-procfs.c (nto_procfs_target::update_thread_list): Avoid
	inferior_ptid.
	(nto_procfs_target::attach): Avoid inferior_ptid.  Switch to
	thread.
	(nto_procfs_target::detach): Avoid referencing
	inferior_ptid.  Use switch_to_no_thread instead of writing to
	inferior_ptid directly.
	(nto_procfs_target::mourn_inferior): Use switch_to_no_thread
	instead of writing to inferior_ptid directly.
	(nto_procfs_target::create_inferior): Avoid inferior_ptid.  Switch
	to thread.
2020-06-18 23:10:09 +01:00
Pedro Alves 191f02e593 Don't write to inferior_ptid in remote-sim.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* remote-sim.c (gdbsim_target::create_inferior): Switch to thread
	after creating it, instead of writing to inferior_ptid.
	(gdbsim_target_open): Use switch_to_no_thread instead of writing
	to inferior_ptid directly.
	(gdbsim_target::wait): Don't write to inferior_ptid.
2020-06-18 23:09:05 +01:00
Pedro Alves 0ac553107c Don't write to inferior_ptid in remote.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_target::remote_notice_new_inferior): Use
	switch_to_thread instead of writing to inferior_ptid directly.
	(remote_target::add_current_inferior_and_thread): Use
	switch_to_no_thread instead of writing to inferior_ptid directly.
	(extended_remote_target::attach): Use switch_to_inferior_no_thread
	and switch_to_thread instead of using set_current_inferior or
	writing to inferior_ptid directly.
2020-06-18 23:08:14 +01:00
Pedro Alves 5233f39b8b Don't write to inferior_ptid in tracectf.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* tracectf.c (ctf_target_open): Switch to added thread instead of
	writing to inferior_ptid directly.
	(ctf_target::close): Use switch_to_no_thread instead of writing to
	inferior_ptid directly.
2020-06-18 23:07:35 +01:00
Pedro Alves 087e161b3c Don't write to inferior_ptid in tracefile-tfile.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* tracefile-tfile.c (tfile_target_open): Don't write to
	inferior_ptid directly, instead switch to added thread.
	(tfile_target::close): Use switch_to_no_thread instead of writing
	to inferior_ptid directly.
2020-06-18 23:06:57 +01:00
Pedro Alves 7fb43e53d5 Don't write to inferior_ptid in procfs.c
The inferior_ptid write in procfs_do_thread_registers should be
unnecessary because the target_fetch_registers method should (and
does) extract the ptid from the regcache.

Not tested.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* procfs.c (procfs_target::attach): Don't write to inferior_ptid.
	(procfs_target::detach): Use switch_to_no_thread
	instead of writing to inferior_ptid directly.
	(do_attach): Change return type to void.  Switch to the added
	thread.
	(procfs_target::create_inferior): Switch to the added thread.
	(procfs_do_thread_registers): Don't write to inferior_ptid.
2020-06-18 23:06:03 +01:00
Pedro Alves 18493a005a Don't write to inferior_ptid in infrun.c
gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

	* infrun.c (generic_mourn_inferior): Use switch_to_thread instead
	of writing to inferior_ptid.
	(scoped_restore_exited_inferior): Delete.
	(handle_vfork_child_exec_or_exit): Simplify using
	scoped_restore_current_pspace_and_thread.  Use switch_to_thread
	instead of writing to inferior_ptid.
	(THREAD_STOPPED_BY): Delete.
	(thread_stopped_by_watchpoint, thread_stopped_by_sw_breakpoint)
	(thread_stopped_by_hw_breakpoint): Delete.
	(save_waitstatus): Use
	scoped_restore_current_thread+switch_to_thread, and call
	target_stopped_by_watchpoint instead of
	thread_stopped_by_watchpoint, target_stopped_by_sw_breakpoint
	instead of thread_stopped_by_sw_breakpoint, and
	target_stopped_by_hw_breakpoint instead of
	thread_stopped_by_hw_breakpoint.
	(handle_inferior_event)
	<TARGET_WAITKIND_EXITED/TARGET_WAITKIND_SIGNALLED>: Don't write to
	inferior_ptid directly, nor
	set_current_inferior/set_current_program_space.  Use
	switch_to_thread / switch_to_inferior_no_thread instead.
2020-06-18 23:05:18 +01:00