Commit Graph

41198 Commits

Author SHA1 Message Date
Tom Tromey 26a57c9256 Remove ptid_match
This removes ptid_match in favor of the ptid_t::matches method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_match): Remove.
	* common/ptid.h (ptid_match): Don't declare.
	* fbsd-nat.c: Update.
	* infcmd.c: Update.
	* infrun.c: Update.
	* linux-nat.c: Update.
	* record-btrace.c: Update.
	* regcache.c: Update.
	* remote.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* server.c: Update.
2018-07-03 11:36:45 -06:00
Tom Tromey d2a107e3f9 Remove ptid_tid_p
This removes ptid_tid_p in favor of the ptid_t::tid_p method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_tid_p): Remove.
	* common/ptid.h (ptid_tid_p): Don't declare.
	* sol-thread.c: Update.
2018-07-03 11:36:45 -06:00
Tom Tromey 15a9e13e52 Remove ptid_lwp_p
This removes ptid_lwp_p in favor of the ptid_t::lwp_p method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_lwp_p): Remove.
	* common/ptid.h (ptid_lwp_p): Don't declare.
	* fbsd-nat.c: Update.
	* linux-nat.c: Update.
	* nat/linux-procfs.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* sol-thread.c: Update.
2018-07-03 11:36:45 -06:00
Tom Tromey 0e998d966b Remove ptid_is_pid
This removes ptid_is_pid in favor of the ptid_t::is_pid method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_is_pid): Remove.
	* common/ptid.h (ptid_is_pid): Don't declare.
	* infrun.c: Update.
	* linux-nat.c: Update.
	* mi/mi-interp.c: Update.
	* remote.c: Update.
	* thread.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
2018-07-03 11:36:44 -06:00
Tom Tromey cc6bcb548d Remove ptid_get_tid
This removes ptid_get_tid in favor of calling the ptid_t::tid method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_tid): Remove.
	* common/ptid.h (ptid_get_tid): Don't declare.
	* ada-tasks.c: Update.
	* aix-thread.c: Update.
	* bsd-uthread.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* i386-darwin-nat.c: Update.
	* infrun.c: Update.
	* linux-tdep.c: Update.
	* nto-procfs.c: Update.
	* ppc-ravenscar-thread.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* sol-thread.c: Update.
	* sparc-ravenscar-thread.c: Update.
	* windows-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* target.c: Update.
2018-07-03 11:36:44 -06:00
Tom Tromey e38504b392 Remove ptid_get_lwp
This removes ptid_get_lwp in favor of calling the ptid_t::lwp method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_lwp): Remove.
	* common/ptid.h (ptid_get_lwp): Don't declare.
	* aarch64-linux-nat.c: Update.
	* ada-tasks.c: Update.
	* aix-thread.c: Update.
	* amd64-linux-nat.c: Update.
	* arm-linux-nat.c: Update.
	* corelow.c: Update.
	* fbsd-nat.c: Update.
	* fbsd-tdep.c: Update.
	* gnu-nat.c: Update.
	* i386-cygwin-tdep.c: Update.
	* i386-gnu-nat.c: Update.
	* i386-linux-nat.c: Update.
	* ia64-linux-nat.c: Update.
	* inf-ptrace.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-tdep.c: Update.
	* linux-thread-db.c: Update.
	* mips-linux-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/aarch64-linux.c: Update.
	* nat/linux-btrace.c: Update.
	* nat/linux-osdata.c: Update.
	* nat/linux-procfs.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* obsd-nat.c: Update.
	* ppc-fbsd-nat.c: Update.
	* ppc-linux-nat.c: Update.
	* procfs.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* remote.c: Update.
	* s390-linux-nat.c: Update.
	* sol-thread.c: Update.
	* sol2-tdep.c: Update.
	* spu-linux-nat.c: Update.
	* x86-linux-nat.c: Update.
	* xtensa-linux-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-mips-low.c: Update.
	* lynx-low.c: Update.
	* nto-low.c: Update.
	* remote-utils.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* target.c: Update.
	* thread-db.c: Update.
2018-07-03 11:36:43 -06:00
Tom Tromey e99b03dcf4 Remove ptid_get_pid
This removes ptid_get_pid in favor of calling the ptid_t::pid method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_pid): Remove.
	* common/ptid.h (ptid_get_pid): Don't declare.
	* aarch64-linux-nat.c: Update.
	* ada-lang.c: Update.
	* aix-thread.c: Update.
	* alpha-bsd-nat.c: Update.
	* amd64-fbsd-nat.c: Update.
	* amd64-linux-nat.c: Update.
	* arm-linux-nat.c: Update.
	* arm-nbsd-nat.c: Update.
	* auxv.c: Update.
	* break-catch-syscall.c: Update.
	* breakpoint.c: Update.
	* bsd-uthread.c: Update.
	* corelow.c: Update.
	* ctf.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* fbsd-tdep.c: Update.
	* gcore.c: Update.
	* gnu-nat.c: Update.
	* hppa-nbsd-nat.c: Update.
	* hppa-obsd-nat.c: Update.
	* i386-fbsd-nat.c: Update.
	* ia64-linux-nat.c: Update.
	* inf-ptrace.c: Update.
	* infcmd.c: Update.
	* inferior.c: Update.
	* inferior.h: Update.
	* inflow.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-tdep.c: Update.
	* linux-thread-db.c: Update.
	* m68k-bsd-nat.c: Update.
	* mi/mi-interp.c: Update.
	* mi/mi-main.c: Update.
	* mips-linux-nat.c: Update.
	* mips-nbsd-nat.c: Update.
	* mips64-obsd-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/aarch64-linux.c: Update.
	* nat/linux-btrace.c: Update.
	* nat/linux-osdata.c: Update.
	* nat/linux-procfs.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* nto-procfs.c: Update.
	* obsd-nat.c: Update.
	* ppc-linux-nat.c: Update.
	* ppc-nbsd-nat.c: Update.
	* ppc-obsd-nat.c: Update.
	* proc-service.c: Update.
	* procfs.c: Update.
	* python/py-inferior.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* record.c: Update.
	* remote-sim.c: Update.
	* remote.c: Update.
	* rs6000-nat.c: Update.
	* s390-linux-nat.c: Update.
	* sh-nbsd-nat.c: Update.
	* sol-thread.c: Update.
	* sparc-nat.c: Update.
	* sparc64-tdep.c: Update.
	* spu-linux-nat.c: Update.
	* spu-tdep.c: Update.
	* target-debug.h: Update.
	* target.c: Update.
	* thread.c: Update.
	* tid-parse.c: Update.
	* tracefile-tfile.c: Update.
	* vax-bsd-nat.c: Update.
	* windows-nat.c: Update.
	* x86-linux-nat.c: Update.
	* x86-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-mips-low.c: Update.
	* lynx-low.c: Update.
	* mem-break.c: Update.
	* nto-low.c: Update.
	* remote-utils.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* target.c: Update.
	* tracepoint.c: Update.
2018-07-03 11:36:42 -06:00
Tom Tromey f2907e4991 Remove pid_to_ptid
This removes pid_to_ptid in favor of calling the ptid_t constructor
directly.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (pid_to_ptid): Remove.
	* common/ptid.h (pid_to_ptid): Don't declare.
	* aix-thread.c: Update.
	* arm-linux-nat.c: Update.
	* common/ptid.c: Update.
	* common/ptid.h: Update.
	* corelow.c: Update.
	* ctf.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* fork-child.c: Update.
	* gnu-nat.c: Update.
	* go32-nat.c: Update.
	* inf-ptrace.c: Update.
	* infcmd.c: Update.
	* inferior.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/fork-inferior.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* nto-procfs.c: Update.
	* obsd-nat.c: Update.
	* procfs.c: Update.
	* progspace.c: Update.
	* remote.c: Update.
	* rs6000-nat.c: Update.
	* s390-linux-nat.c: Update.
	* sol-thread.c: Update.
	* spu-linux-nat.c: Update.
	* target.c: Update.
	* top.c: Update.
	* tracefile-tfile.c: Update.
	* windows-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-ppc-low.c: Update.
	* linux-x86-low.c: Update.
	* proc-service.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* thread-db.c: Update.
	* win32-low.c: Update.
2018-07-03 11:36:42 -06:00
Tom Tromey fd79271bd9 Remove ptid_build
This removes ptid_build in favor of simply calling the ptid_t
constructor directly.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.h (ptid_build): Don't declare.
	* common/ptid.c (ptid_build): Remove.
	* aix-thread.c: Update.
	* bsd-kvm.c: Update.
	* bsd-uthread.c: Update.
	* common/agent.c: Update.
	* common/ptid.c: Update.
	* common/ptid.h: Update.
	* corelow.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* gnu-nat.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-thread-db.c: Update.
	* nat/linux-osdata.c: Update.
	* nat/linux-procfs.c: Update.
	* nto-procfs.c: Update.
	* obsd-nat.c: Update.
	* proc-service.c: Update.
	* procfs.c: Update.
	* ravenscar-thread.c: Update.
	* remote-sim.c: Update.
	* remote.c: Update.
	* sol-thread.c: Update.
	* target.c: Update.
	* windows-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* lynx-low.c: Update.
	* nto-low.c: Update.
	* remote-utils.c: Update.
	* spu-low.c: Update.
	* thread-db.c: Update.
	* win32-low.c: Update.
2018-07-03 11:36:41 -06:00
Tom Tromey 057302ceb3 Remove exit_inferior_num_silent
The sole caller of exit_inferior_num_silent was getting the inferior's
number to then use the number to look up the inferior again.  I think
it's better to simply not have exit_inferior_num_silent; any potential
callers that only have the inferior's number should probably be
converted to pass the inferior itself around instead.

Tested by the buildbot.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* infrun.c (follow_exec): Use exit_inferior_silent.
	* inferior.c (exit_inferior_num_silent): Remove.
	* inferior.h (exit_inferior_num_silent): Don't declare.
2018-07-03 09:49:30 -06:00
Tom Tromey a50c11c666 Fix crash in "run" on macOS when gdb is not signed
On macOS, when gdb is not code-signed, it will throw an exception from
darwin_attach_pid.  However, gdb also then crashes:

thread.c:93: internal-error: struct thread_info *inferior_thread(): Assertion `tp' failed.

I think the problem here is that darwin_attach_pid does not clean up
inferior_ptid and inf->pid on failure.  This leads to a situation
where gdb tries to find a thread, but cannot.

In other cases, gdb would mourn the inferior at this point; but here
this is not possible because the target has not been pushed.  Instead
this patch works by simply updating the inferior and inferior_ptid on
failure.

Tested by building an unsigned gdb on macOS and trying to run an
inferior.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	PR cli/23340:
	* darwin-nat.c (darwin_attach_pid): Reset inferior and
	inferior_ptid on error.
2018-07-03 09:28:26 -06:00
Maciej W. Rozycki 471b9d1507 GDB PR tdep/8282: MIPS: Wire in `set disassembler-options'
Implement MIPS target support for passing options to the disassembler,
complementing commit 65b48a8140 ("GDB: Add support for the new
set/show disassembler-options commands.").

This includes options that expect an argument, so adjust the generic
code and data structures used so as to handle such options.  So as to
give backends syntax flexibility no specific delimiter has been defined
to separate options from their respective arguments, so it has to be
included as the last character of the option name.  Completion code
however has not been adjusted and consequently option arguments cannot
be completed at this time.

Also the MIPS target has non-empty defaults for the options, so that ABI
names for the general-purpose registers respect our `set mips abi ...'
setting rather than always being determined from the ELF headers of the
binary file selected.  Handle these defaults as implicit options, never
shown to the user and always prepended to the user-specified options, so
that the latters can override the defaults.

The resulting output for the MIPS target is as follows:

(gdb) show disassembler-options
The current disassembler options are ''

The following disassembler options are supported for use with the
'set disassembler-options <option>[,<option>...]' command:

  no-aliases      Use canonical instruction forms.

  msa             Recognize MSA instructions.

  virt            Recognize the virtualization ASE instructions.

  xpa             Recognize the eXtended Physical Address (XPA) ASE
                  instructions.

  ginv            Recognize the Global INValidate (GINV) ASE instructions.

  gpr-names=ABI   Print GPR names according to specified ABI.
                  Default: based on binary being disassembled.

  fpr-names=ABI   Print FPR names according to specified ABI.
                  Default: numeric.

  cp0-names=ARCH  Print CP0 register names according to specified architecture.
                  Default: based on binary being disassembled.

  hwr-names=ARCH  Print HWR names according to specified architecture.
                  Default: based on binary being disassembled.

  reg-names=ABI   Print GPR and FPR names according to specified ABI.

  reg-names=ARCH  Print CP0 register and HWR names according to specified
                  architecture.

  For the options above, the following values are supported for "ABI":
    numeric 32 n32 64

  For the options above, the following values are supported for "ARCH":
    numeric r3000 r3900 r4000 r4010 vr4100 vr4111 vr4120 r4300 r4400 r4600
    r4650 r5000 vr5400 vr5500 r5900 r6000 rm7000 rm9000 r8000 r10000 r12000
    r14000 r16000 mips5 mips32 mips32r2 mips32r3 mips32r5 mips32r6 mips64
    mips64r2 mips64r3 mips64r5 mips64r6 interaptiv-mr2 sb1 loongson2e
    loongson2f loongson3a octeon octeon+ octeon2 octeon3 xlr xlp
(gdb)

which corresponds to what `objdump --help' used to print for the MIPS
target, with minor formatting changes, most notably option argument
lists being wrapped, but also the amount of white space separating
options from the respective descriptions.  The relevant part the new
code is now also used by `objdump --help', which means these formatting
changes apply to both outputs, except for argument list wrapping, which
is GDB-specific.

This also adds a separating new line between the heading and option
lists where descriptions are provided, hence:

(gdb) set architecture s390:31-bit
(gdb) show disassembler-options
The current disassembler options are ''

The following disassembler options are supported for use with the
'set disassembler-options <option>[,<option>...]' command:

  esa         Disassemble in ESA architecture mode
  zarch       Disassemble in z/Architecture mode
  insnlength  Print unknown instructions according to length from first two bits
(gdb)

but:

(gdb) set architecture powerpc:common
(gdb) show disassembler-options
The current disassembler options are ''

The following disassembler options are supported for use with the
'set disassembler-options <option>[,<option>...]' command:
  403, 405, 440, 464, 476, 601, 603, 604, 620, 7400, 7410, 7450, 7455, 750cl,
  821, 850, 860, a2, altivec, any, booke, booke32, cell, com, e200z4, e300,
  e500, e500mc, e500mc64, e5500, e6500, e500x2, efs, efs2, power4, power5,
  power6, power7, power8, power9, ppc, ppc32, 32, ppc64, 64, ppc64bridge,
  ppcps, pwr, pwr2, pwr4, pwr5, pwr5x, pwr6, pwr7, pwr8, pwr9, pwrx, raw, spe,
  spe2, titan, vle, vsx
(gdb)

Existing affected target backends have been adjusted accordingly.

This has been verified manually with:

(gdb) set architecture arm
(gdb) set architecture powerpc:common
(gdb) set architecture s390:31-bit

to cause no issues with the `show disassembler-options' and `set
disassembler-options' commands.  A test case for the MIPS target has
also been provided, covering the default settings with ABI overrides as
well as disassembler option overrides.

2018-07-02  Maciej W. Rozycki  <macro@mips.com>
            Simon Marchi  <simon.marchi@polymtl.ca>

	include/
	PR tdep/8282
	* dis-asm.h (disasm_option_arg_t): New typedef.
	(disasm_options_and_args_t): Likewise.
	(disasm_options_t): Add `arg' member, document members.
	(disassembler_options_mips): New prototype.
	(disassembler_options_arm, disassembler_options_powerpc)
	(disassembler_options_s390): Update prototypes.

	opcodes/
	PR tdep/8282
	* mips-dis.c (mips_option_arg_t): New enumeration.
	(mips_options): New variable.
	(disassembler_options_mips): New function.
	(print_mips_disassembler_options): Reimplement in terms of
	`disassembler_options_mips'.
	* arm-dis.c (disassembler_options_arm): Adapt to using the
	`disasm_options_and_args_t' structure.
	* ppc-dis.c (disassembler_options_powerpc): Likewise.
	* s390-dis.c (disassembler_options_s390): Likewise.

	gdb/
	PR tdep/8282
	* disasm.h (gdb_disassembler): Add
	`m_disassembler_options_holder'. member
	* disasm.c (get_all_disassembler_options): New function.
	(gdb_disassembler::gdb_disassembler): Use it.
	(gdb_buffered_insn_length_init_dis): Likewise.
	(gdb_buffered_insn_length): Adjust accordingly.
	(set_disassembler_options): Handle options with arguments.
	(show_disassembler_options_sfunc): Likewise.  Add a leading new
	line if showing options with descriptions.
	(disassembler_options_completer): Adapt to using the
	`disasm_options_and_args_t' structure.
	* mips-tdep.c (mips_disassembler_options): New variable.
	(mips_disassembler_options_o32): Likewise.
	(mips_disassembler_options_n32): Likewise.
	(mips_disassembler_options_n64): Likewise.
	(gdb_print_insn_mips): Don't set `disassembler_options'.
	(gdb_print_insn_mips_n32, gdb_print_insn_mips_n64): Remove
	functions.
	(mips_gdbarch_init): Always set `gdbarch_print_insn' to
	`gdb_print_insn_mips'.  Set `gdbarch_disassembler_options',
	`gdbarch_disassembler_options_implicit' and
	`gdbarch_valid_disassembler_options'.
	* arm-tdep.c (_initialize_arm_tdep): Adapt to using the
	`disasm_options_and_args_t' structure.
	* gdbarch.sh (disassembler_options_implicit): New `gdbarch'
	method.
	(valid_disassembler_options): Switch from `disasm_options_t' to
	the `disasm_options_and_args_t' structure.
	* NEWS: Document `set disassembler-options' support for the MIPS
	target.
	* gdbarch.h: Regenerate.
	* gdbarch.c: Regenerate.

	gdb/doc/
	PR tdep/8282
	* gdb.texinfo (Source and Machine Code): Document `set
	disassembler-options' support for the MIPS target.

	gdb/testsuite/
	PR tdep/8282
	* gdb.arch/mips-disassembler-options.exp: New test.
	* gdb.arch/mips-disassembler-options.s: New test source.
2018-07-02 23:57:21 +01:00
Sebastian Huber 41823f29a8 gdb: Prefer RISC-V register name "s0" over "fp"
The "fp" register name is an alias for "s0" which is an alias for "x8".
The "fp" name is only understood by very recent Binutils and thus not
used by GCC.  GCC does not emit a frame pointer with common optimization
options such as -Og or -O2.

It is still possible to use the "fp" register name, e.g.

  (gdb) p/x $fp
  $1 = 0x800367c8

works.

However, in the register dump you see now:

  (gdb) info registers
  ...
  t2             0xffffffffffffffff       18446744073709551615
  s0             0x800367c8       0x800367c8
  s1             0x80033280       2147693184
  ...

gdb/

	* riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0"
	entries.
2018-07-02 15:27:53 +02:00
Sergio Durigan Junior c0867626d2 Add missing parameter to 'amd64_create_target_description' (and unbreak build)
While building gdbserver on GNU/Linux, the build failed with:

  ../../../binutils-gdb/gdb/gdbserver/linux-x86-tdesc.c: In function ‘const target_desc* amd64_linux_read_description(uint64_t, bool)’:
  ../../../binutils-gdb/gdb/gdbserver/linux-x86-tdesc.c:121:67: error: too few arguments to function ‘target_desc* amd64_create_target_description(uint64_t, bool, bool, bool)’
         *tdesc = amd64_create_target_description (xcr0, is_x32, true);
                                                                     ^
  In file included from ../../../binutils-gdb/gdb/gdbserver/linux-x86-tdesc.c:26:0:
  ../../../binutils-gdb/gdb/gdbserver/../arch/amd64.h:21:14: note: declared here
   target_desc *amd64_create_target_description (uint64_t xcr0, bool is_x32,
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

According to Joel Brobecker:

> I think the parameter should be set to "true". Otherwise, it will
> not include the fs_base and gs_base register in the list of registers.
> Although the name of the source file says x86, the code itself is
> protected by...
>
>     #ifdef __x86_64__
>
> ... and is inside a function called amd64_linux_read_description.
> I also verified that this file gets compiled on amd64-linux platforms.
> See gdb/gdbserver/configure.srv:
>
>   x86_64-*-linux*)      srv_regobj="$srv_amd64_linux_regobj $srv_i386_linux_regobj"
>
> The last piece of confirmation is that setting the parameter to "true"
> provides the behavior before the parameter was added; and the reason
> for adding the parameter was to remove the {fs,gs}_base registers
> from the list for Windows only.

Therefore I'm pushing the patch to unbreak the build.

gdb/gdbserver/ChangeLog:
2018-06-29  Joel Brobecker  <brobecker@adacore.com>

	* linux-x86-tdesc.c (amd64_linux_read_description): Add missing
	parameter in call to 'amd64_create_target_description'.
2018-06-29 21:38:46 -04:00
Joel Brobecker 41206e32fb fix GDB build failure for various amd64 targets
The following patch caused some amd64-*-tdep files to fail to compile:

  | commit de52b9607d
  | Date:   Tue Jun 26 16:33:27 2018 +0100
  | Subject: x86_64-windows GDB crash due to fs_base/gs_base registers

This is because we added one additional "segments" argument to
function amd64_target_description and forgot to update all the callers.
This patch fixes the omissions.

gdb/ChangeLog:

        * amd64-darwin-tdep.c (x86_darwin_init_abi_64): Add missing
        parameter in call to amd64_target_description.
        * amd64-dicos-tdep.c (amd64_dicos_init_abi): Likewise.
        * amd64-fbsd-tdep.c (amd64fbsd_core_read_description)
        (amd64fbsd_init_abi): Likewise.
        * amd64-nbsd-tdep.c (amd64nbsd_init_abi): Likewise.
        * amd64-obsd-tdep.c (amd64obsd_init_abi): Likewise.
        * amd64-sol2-tdep.c (amd64_sol2_init_abi): Likewise.
        * amd64-fbsd-nat.c (amd64_fbsd_nat_target): Likewise.

The change to amd64-fbsd-nat.c was done "blind" (no access to system),
but is reasonably straightforward. The changes to the -tdep.c files
were verify by rebuilding GDB on x86_64-linux when configured with
--enable-targets=all.
2018-06-29 18:51:18 -04:00
Pedro Alves de52b9607d x86_64-windows GDB crash due to fs_base/gs_base registers
GDB is currently crashing anytime we try to access the fs_base/gs_base
registers, either to read them, or to write them. This can be observed
under various scenarios:
  - Explicit reference to those registers (eg: print $fs_base) --
    probably relatively rare;
  - Calling a function in the inferior, with the crash happening
    because we are trying to read those registers in order to save
    their value ahead of making the function call;
  - Just a plain "info registers";

The crash was introduced by the following commit:

    | commit 48aeef91c2
    | Date:   Mon Jun 26 18:14:43 2017 -0700
    | Subject: Include the fs_base and gs_base registers in amd64 target descriptions.

The Windows-nat implementation was unfortunately not prepared to deal
with those new registers. In particular, the way it fetches registers
is done by using a table where the index is the register number, and
the value at that index is the offset in the area in the thread's CONTEXT
data where the corresponding register value is stored.

For instance, in amd64-windows-nat.c, we can find the mappings static
array containing the following 57 elements in it:

    #define context_offset(x) (offsetof (CONTEXT, x))
    static const int mappings[] =
    {
      context_offset (Rax),
      [...]
      context_offset (FloatSave.MxCsr)
    };

That array is then used by windows_fetch_one_register via:

    char *context_offset = ((char *) &th->context) + mappings[r];

The problem is that fs_base's register number is 172, which is
well past the end of the mappings array (57 elements in total).
We end up getting an undefined offset, which happens to be so large
that it then causes the address where we try to read the register
value (a little bit later) to be invalid, thus crashing GDB with
a SEGV.

This patch side-steps the issue entirely by removing support for
those registers in GDB on x86_64-windows, because a look at the
CONTEXT structure indicates no support for getting those registers.

A more comprehensive fix would patch the potential buffer overflow
of the mappings array, but this can be done as a separate commit.

gdb/ChangeLog:

        * gdb/amd64-tdep.h (amd64_create_target_description): Add
        "segments" parameter.
        * gdb/amd64-tdep.c (amd64_none_init_abi, amd64_x32_none_init_abi)
        (_initialize_amd64_tdep): Update call to
        amd64_create_target_description.
        (amd64_target_description): Add "segments" parameter.  Adjust
        the implementation to use it.
        * gdb/amd64-linux-tdep.c (amd64_linux_read_description): Update
        call to amd64_create_target_description.
        * gdb/amd64-windows-tdep.c (amd64_windows_init_abi): Likewise.
        * gdb/arch/amd64.h (amd64_create_target_description): Add
        "segments" register.
        * gdb/arch/amd64.c (amd64_create_target_description): Add
        "segments" parameter.  Call create_feature_i386_64bit_segments
        only if SEGMENTS is true.
        * gdb/gdbserver/win32-i386-low.c (i386_arch_setup): Update
        call to amd64_create_target_description.

Tested on x86_64-windows using AdaCore's testsuite (by Joel Brobecker
<brobecker at adacore dot com>).
2018-06-29 15:05:20 -07:00
Pedro Alves 75acb4867d Improve alignment of "info threads" output, align "Target Id" column
It's long annoyed me that "info threads"'s columns are misaligned.

Particularly the "Target Id" column's content is usually longer than
the specified column width, so the table ends up with the "Frame"
column misaligned.  For example, currently we get this:

 (gdb) info threads
   Id   Target Id         Frame
   1    Thread 0x7ffff7fb5740 (LWP 9056) "threads" 0x00007ffff7bc28ad in __pthread_join (threadid=140737345763072, thread_return=0x7fffffffd3e8) at pthread_join.c:90
   2    Thread 0x7ffff7803700 (LWP 9060) "function0" thread_function0 (arg=0x0) at threads.c:90
 * 3    Thread 0x7ffff7002700 (LWP 9061) "threads" thread_function1 (arg=0x1) at threads.c:106

The fact that the "Frame" heading is in a weird spot is particularly
annoying.

This commit turns the above into into this:

 (gdb) info threads
   Id   Target Id                                    Frame
   1    Thread 0x7ffff7fb5740 (LWP 7548) "threads"   0x00007ffff7bc28ad in __pthread_join (threadid=140737345763072, thread_return=0x7fffffffd3e8) at pthread_join.c:90
   2    Thread 0x7ffff7803700 (LWP 7555) "function0" thread_function0 (arg=0x0) at threads.c:91
 * 3    Thread 0x7ffff7002700 (LWP 7557) "threads"   thread_function1 (arg=0x1) at threads.c:104

It does that by computing the max width of the "Target Id" column and
using that as column width when creating the table.

This results in calling target_pid_to_str / target_extra_thread_info /
target_thread_name twice for each thread, but I think that it doesn't
matter in practice performance-wise, because the remote target caches
the info, and with native targets it shouldn't be noticeable.  It
could matter if we have many threads (say, thousands), but then "info
threads" is practically useless in such a scenario anyway -- better
thread filtering and aggregation would be necessary.

(Note: I have an old branch somewhere where I attempted at making
gdb's "info threads"-like tables follow a model/view design, so that a
general framework took care of issues like these, but it's incomplete
and a much bigger change.  This patch doesn't prevent going in that
direction in the future, of course.)

gdb/ChangeLog:
2018-06-29  Pedro Alves  <palves@redhat.com>

	* thread.c (thread_target_id_str): New, factored out from ...
	(print_thread_info_1): ... here.  Use it to compute the max
	"Target Id" column width.

gdb/testsuite/ChangeLog:
2018-06-29  Pedro Alves  <palves@redhat.com>

	* gdb.threads/names.exp: Adjust expected "info threads" output.
2018-06-29 20:47:15 +01:00
Pedro Alves c76a8ea36c remote & target_extra_thread_info, use cache w/ qThreadExtraInfo and qP too
The following patch will make "info threads" call target_extra_thread_info
more frequently.  When I looked at the remote implementation, I noticed
that if we're not using qXfer:threads:read, then we'd be increasing the
remote protocol traffic.  This commit prevents that from happening.

Also, it removes a gratuitous local static buffer, which seems good on
its own.

gdb/ChangeLog:
2018-06-29  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_target::extra_thread_info): Delete
	'display_buf' and 'n' locals.  from the cache, regardless of
	packet mechanims is in use.  Use cache for qThreadExtra and qP
	methods too.
2018-06-29 20:45:34 +01:00
Pedro Alves cd2bb70994 "break LINENO/*ADDRESS", inline functions and "info break" output
While experimenting with the previous patch, I noticed this inconsistency
in GDB's output:

  (gdb) b 32
  Breakpoint 1 at 0x40062f: file inline-break.c, line 32.                  (1)
  (gdb) r
  ....
  Breakpoint 1, func1 (x=1) at inline-break.c:32                           (2)
  32        return x * 23; /* break here */
  (gdb) info breakpoints
  Num     Type           Disp Enb Address    What
  1       breakpoint     keep y   0x40062f   in main at inline-break.c:32  (3)
	  breakpoint already hit 1 time
  (gdb)

Notice that when the breakpoint as set, GDB showed "inline-break.c,
line 32" (1), the same line number that was specified in the command.

When we run to the breakpoint, we present the stop at the same line
number, and correctly show "func1" as the function name (2).

But in "info break" output (3), notice that we say "in main", not "in
func1".

The same thing happens if you set a breakpoint by address.  I.e.:

  (gdb) b *0x40062f
  Breakpoint 2 at 0x40062f: file inline-break.c, line 32.
  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  2       breakpoint     keep y   0x000000000040062f in main at inline-break.c:32
   (gdb) r
   ....
  Breakpoint 2, func1 (x=1) at inline-break.c:32
  32        return x * 23; /* break here */

The problem is that the breakpoints were set at an inline function,
but when we set such a breakpoint by line number or address, we don't
record the functions symbol in the sal, and as consequence the
breakpoint location does not have an associated symbol either.

Then, in print_breakpoint_location, if the location does not have a
symbol, we call find_pc_sect_function to find one, and this is what
finds "main", because find_pc_sect_function uses
block_linkage_function:

  /* Return the symbol for the function which contains a specified
     lexical block, described by a struct block BL.  The return value
     will not be an inlined function; the containing function will be
     returned instead.  */

  struct symbol *
  block_linkage_function (const struct block *bl)

To fix this, this commit adds an alternative to find_pc_sect_function
that uses block_containing_function instead:

  /* Return the symbol for the function which contains a specified
     block, described by a struct block BL.  The return value will be
     the closest enclosing function, which might be an inline
     function.  */

  struct symbol *
  block_containing_function (const struct block *bl)

(It seems odd to me that block_linkage_function says "the CONTAINING
function will be returned", and then block_containing_function says it
returns "the closest enclosing function".  Something seems reversed
here.  Still, I've kept the same nomenclature and copied the comments,
so that at least there's consistency.  Maybe we should fix that up
somehow.)

Then I wondered, why make print_breakpoint_location look up the symbol
every time it is called, instead of just always storing the symbol
when the location is created, since the location already stores the
symbol in some cases.  So to find which cases might be missing setting
the symbol in the sal which is used to create the breakpoint location,
I added an assertion to print_breakpoint_location, and ran the
testsuite.  That caught a few places, unsurprisingly:

 - setting a breakpoint by line number
 - setting a breapoint by address
 - ifunc resolving

Those are all fixed by this commit.  I decided not to add the
assertion to block_linkage_function and leave the existing "if (sym)"
check in place, because it's plausible that we have symtabs with line
info but no symbols.  I.e., that would not be a GDB bug, but
a peculiarity of debug info input.

gdb/ChangeLog:
2018-06-29  Pedro Alves  <palves@redhat.com>

	* blockframe.c (find_pc_sect_containing_function): New function.
	* breakpoint.c (print_breakpoint_location): Don't call
	find_pc_sect_function.
	* linespec.c (create_sals_line_offset): Record the location's
	symbol in the sal.
	* linespec.c (convert_address_location_to_sals): Fill in sal's
	symbol with find_pc_sect_containing_function.
	* symtab.c (find_function_start_sal): Rename to ...
	(find_function_start_sal_1): ... this.
	(find_function_start_sal): Reimplement as wrapper around
	find_function_start_sal_1, and use
	find_pc_sect_containing_function to fill in the sal's symbol.
	(find_function_start_sal(symbol*, bool)): Adjust.
	* symtab.h (find_pc_function, find_pc_sect_function): Adjust
	comments.
	(find_pc_sect_containing_function): Declare.

gdb/testsuite/ChangeLog:
2018-06-29  Pedro Alves  <palves@redhat.com>

	* gdb.opt/inline-break.exp (line number, address): Add "info
	break" tests.
2018-06-29 19:37:20 +01:00
Pedro Alves 991ff2922a Fix running to breakpoint set in inline function by lineno/address
Commit 61b04dd04a ("Change inline frame breakpoint skipping logic
(fix gdb.gdb/selftest.exp)") caused a GDB crash when you set a
breakpoint by line number in an inline function, and then run to the
breakpoint:

    $ gdb -q test Reading symbols from test...done.
    (gdb) b inline-break.c:32
    Breakpoint 1 at 0x40062f: file inline-break.c, line 32.
    (gdb) run
    Starting program: /[...]/test
    [1]    75618 segmentation fault  /[...]/gdb -q test

The problem occurs because we assume that a bp_location's symbol is
not NULL, which is not true when we set the breakpoint with a linespec
location:

    Program received signal SIGSEGV, Segmentation fault.
    0x00000000006f42bb in stopped_by_user_bp_inline_frame (
        stop_chain=<optimized out>, frame_block=<optimized out>)
        at gdb/inline-frame.c:305
    305		      && frame_block == SYMBOL_BLOCK_VALUE (loc->symbol))
    (gdb) p loc->symbol
    $1 = (const symbol *) 0x0

The same thing happens if you run to a breakpoint set in an inline
function by address:

  (gdb) b *0x40062f
  Breakpoint 3 at 0x40062f: file inline-break.c, line 32.

To fix this, add a null pointer check, to avoid the crash, and make it
so that if there's no symbol for the location, then we present the
stop at the inline function.  This preserves the previous behavior
when e.g., setting a breakpoint by address, with "b *ADDRESS".

gdb/ChangeLog:
2018-06-29  Pedro Alves  <palves@redhat.com>

	* inline-frame.c (stopped_by_user_bp_inline_frame): Return
	true if the the location has no symbol.

gdb/testsuite/ChangeLog:
2018-06-29  Pedro Alves  <palves@redhat.com>

	* gdb.opt/inline-break.c (func1): Add "break here" marker.
	* gdb.opt/inline-break.exp: Test setting breakpoints by line
	number and address and running to them.
2018-06-29 19:35:13 +01:00
Pedro Alves 356819b6bc Fix format of last gdb/testsuite/ChangeLog entry 2018-06-29 19:32:57 +01:00
Richard Bunt 49af4b7012 Remove unstable test output
Changed test output from:
PASS: gdb.base/watchpoint-hw-attach.exp: attach 25501
to
PASS: gdb.base/watchpoint-hw-attach.exp: attach

gdb/testsuite/ChangeLog:

	* gdb.base/watchpoint-hw-attach.exp: Remove unstable output.
2018-06-29 17:34:58 +01:00
Tom Tromey 44cee4fdf4 Add --enable-codesign to gdb's configure
macOS requires that the gdb executable be signed in order to be able
to successfully use ptrace.  This must be done after each link.

This patch adds a new --enable-codesign configure option so that this
step can be automated.

gdb/ChangeLog
2018-06-28  Tom Tromey  <tom@tromey.com>

	* NEWS: Mention --enable-codesign.
	* silent-rules.mk (ECHO_SIGN): New variable.
	* configure.ac: Add --enable-codesign.
	* configure: Rebuild.
	* Makefile.in (CODESIGN, CODESIGN_CERT): New variables.
	(gdb$(EXEEXT)): Optionally invoke codesign.
2018-06-28 15:13:43 -06:00
Pedro Alves f2ffa92bbc gdb: Eliminate the 'stop_pc' global
In my multi-target work, I need to add a few more
scoped_restore_current_thread and switch_to_thread calls in some
places, and in some lower-level places I was fighting against the fact
that switch_to_thread reads/refreshes the stop_pc global.

Instead of piling on workarounds, let's just finally eliminate the
stop_pc global.  We already have the per-thread
thread_info->suspend.stop_pc field, so it's mainly a matter of using
that more/instead.

gdb/ChangeLog:
2018-06-28  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (struct thread_suspend_state) <stop_pc>: Extend
	comments.
	(switch_to_thread_no_regs): Adjust comment.
	* infcmd.c (stop_pc): Delete.
	(post_create_inferior, info_program_command): Replace references
	to stop_pc with references to thread_info->suspend.stop_pc.
	* inferior.h (stop_pc): Delete declaration.
	* infrun.c (proceed, handle_syscall_event, fill_in_stop_func)
	(handle_inferior_event_1, handle_signal_stop)
	(process_event_stop_test, keep_going_stepped_thread)
	(handle_step_into_function, handle_step_into_function_backward)
	(print_stop_location): Replace references to stop_pc with
	references to thread_info->suspend.stop_pc.
	(struct infcall_suspend_state) <stop_pc>: Delete field.
	(save_infcall_suspend_state, restore_infcall_suspend_state):
	Remove references to inf_stat->stop_pc.
	* linux-fork.c (fork_load_infrun_state): Likewise.
	* record-btrace.c (record_btrace_set_replay): Likewise.
	* record-full.c (record_full_goto_entry): Likewise.
	* remote.c (print_one_stopped_thread): Likewise.
	* target.c (target_resume): Extend comment.
	* thread.c (set_executing_thread): New.
	(set_executing): Use it.
	(switch_to_thread_no_regs, switch_to_no_thread, switch_to_thread):
	Remove references to stop_pc.
2018-06-28 17:12:07 +01:00
Pedro Alves ecdc3a72c8 Fix follow-exec regression / crash
After commit 00431a78b2 ("Use thread_info and inferior pointers more
throughout"), following an exec can result in gdb crashing.  On some
systems, this is visible with gdb.multi/multi-arch-exec.exp and
gdb.base/foll-exec-mode.exp.  E.g.:

  $ make check TESTS="gdb.multi/multi-arch-exec.exp gdb.base/foll-exec-mode.exp"
  [snip]
  FAIL: gdb.multi/multi-arch-exec.exp: first_arch=1: selected_thread=1: follow_exec_mode=new: continue across exec that changes architecture (GDB internal error)
  ERROR: : spawn id exp10 not open
      while executing

Running multi-arch-exec under Valgrind we easily spot the problem:

  process 16305 is executing new program: ..../gdb.multi/multi-arch-exec/1-multi-arch-exec-hello
  [New inferior 2 (process 0)]
  [New process 16305]
  ==16129== Invalid read of size 8
  ==16129==    at 0x7FA14D: get_thread_regcache(thread_info*) (regcache.c:399)
  ==16129==    by 0x75E54B: handle_inferior_event_1(execution_control_state*) (infrun.c:5292)
  ==16129==    by 0x75E82D: handle_inferior_event(execution_control_state*) (infrun.c:5382)
  ==16129==    by 0x75BC6A: fetch_inferior_event(void*) (infrun.c:3918)
  ==16129==    by 0x748DA3: inferior_event_handler(inferior_event_type, void*) (inf-loop.c:43)
  ==16129==    by 0x464B5D: handle_target_event(int, void*) (linux-nat.c:4359)
  ==16129==    by 0x7047E0: handle_file_event(file_handler*, int) (event-loop.c:733)
  ==16129==    by 0x704D83: gdb_wait_for_event(int) (event-loop.c:859)
  ==16129==    by 0x703BF6: gdb_do_one_event() (event-loop.c:322)
  ==16129==    by 0x703CA2: start_event_loop() (event-loop.c:371)
  ==16129==    by 0x791D95: captured_command_loop() (main.c:330)
  ==16129==    by 0x79311C: captured_main(void*) (main.c:1157)
  ==16129==  Address 0x15a5bad0 is 32 bytes inside a block of size 600 free'd
  ==16129==    at 0x4C2E1E8: operator delete(void*) (vg_replace_malloc.c:576)
  ==16129==    by 0x8A15D0: delete_thread_1(thread_info*, bool) (thread.c:465)
  ==16129==    by 0x8A15FA: delete_thread(thread_info*) (thread.c:476)
  ==16129==    by 0x8A0D43: add_thread_silent(ptid_t) (thread.c:291)
  ==16129==    by 0x8A0DF0: add_thread_with_info(ptid_t, private_thread_info*) (thread.c:317)
  ==16129==    by 0x8A0E79: add_thread(ptid_t) (thread.c:331)
  ==16129==    by 0x75764C: follow_exec(ptid_t, char*) (infrun.c:1233)
  ==16129==    by 0x75E534: handle_inferior_event_1(execution_control_state*) (infrun.c:5290)
  ==16129==    by 0x75E82D: handle_inferior_event(execution_control_state*) (infrun.c:5382)
  ==16129==    by 0x75BC6A: fetch_inferior_event(void*) (infrun.c:3918)
  ==16129==    by 0x748DA3: inferior_event_handler(inferior_event_type, void*) (inf-loop.c:43)
  ==16129==    by 0x464B5D: handle_target_event(int, void*) (linux-nat.c:4359)

The problem is that handle_inferior_event_1 is reading the stop_pc off
of a thread that was deleted by follow_exec.  Before commit
00431a78b2, we didn't crash because we were passing down a ptid to
get_thread_regcache instead of ecs->event_thread.

Fix this by simply moving the stop_pc reading until after
ecs->event_thread is refreshed.

gdb/ChangeLog:
2018-06-28  Pedro Alves  <palves@redhat.com>

	* infrun.c (handle_inferior_event_1) <TARGET_WAITKIND_EXECD>:
	Moving fetching stop_pc until after ecs->event_thread is refreshed.
2018-06-28 16:57:18 +01:00
Tom Tromey d95d3aef9e Make dwarf2_free_objfile static
I noticed that dwarf2_free_objfile can be made static, by changing it
to be a registry cleanup function.  This simplifies the code, as well,
because now symbol readers don't have to explicitly call it.

Tested by the buildbot.

gdb/ChangeLog
2018-06-28  Tom Tromey  <tom@tromey.com>

	* coffread.c (coff_symfile_finish): Update.
	* xcoffread.c (xcoff_symfile_finish): Update.
	* elfread.c (elf_symfile_finish): Update.
	* symfile.h (dwarf2_free_objfile): Don't declare.
	* dwarf2read.c (_initialize_dwarf2_read): Use
	register_objfile_data_with_cleanup.
	(dwarf2_free_objfile): Now static.  Change signature.
2018-06-28 08:20:59 -06:00
Jan Kratochvil 2512d7efdf Remove 2 excessive executable permission flags
Fedora rpmbuild has been complaining:
	*** WARNING: ./usr/src/debug/gdb-8.1.50.20180618-24.fc28.x86_64/gdb/gdbserver/x86-tdesc.h is executable but has empty or no shebang, removing executable bit

gdb/gdbserver/ChangeLog
2018-06-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* x86-tdesc.h: Remove executable permission flag.

gdb/testsuite/ChangeLog
2018-06-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* lib/compiler.c: Remove executable permission flag.
2018-06-28 16:09:37 +02:00
Richard Bunt be1b6474f0 Fixed top frame assumption in watchpoint-hw-attach
watchpoint-hw-attach.exp was noticed to fail on some machines.
Thanks to the input from sergiodj and palves on the IRC channel,
it was concluded that the test case incorrectly assumed that on
attach it was landed in the top-most frame of the inferior. This
was fixed by running to a break point in main by explicitly
defining the source file name before continuing with the test.

Tested on the following architectures x86_64, aarch64 and ppc64le.

gdb/testsuite/ChangeLog:

	* gdb.base/watchpoint-hw-attach.c (main): Remove unneeded
	code.
	* gdb.base/watchpoint-hw-attach.exp: Break in outermost frame.
2018-06-28 08:59:59 +01:00
Petr Tesarik 291f9a9643 Add an optional offset option to the "add-symbol-file" command
If all sections of a symbol file are loaded with a fixed offset, it
is easier to specify that offset than listing all sections
explicitly.  There is also a similar option for "symbol-file".

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* symfile.c (add_symbol_file_command, _initialize_symfile): Add
	option "-o" to add-symbol-file-load to add an offset to each
	section's load address.
	* symfile.c (set_objfile_default_section_offset): New function.

gdb/doc/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.texinfo (Files): Document "add-symbol-file -o offset".

gdb/testsuite/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.base/relocate.exp: Add test for "add-symbol-file -o ".
2018-06-28 08:35:34 +02:00
Petr Tesarik d81a3eaff3 Make sure that sorting does not change section order
Symbol files may contain multiple sections with the same name.
Section addresses specified by add-symbol-file are assigned to the
corresponding BFD sections in addr_info_make_relative using sorted
indexes of both vectors.  Since the sort algorithm is not inherently
stable, the comparison function uses sectindex to maintain the
original order.  However, add_symbol_file_command uses zero for all
sections, so if the user specifies multiple sections with the same
name, they will be assigned randomly to symbol file sections with
the same name.

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* symfile.c (add_symbol_file_command): Make sure that sections
2018-06-28 08:35:34 +02:00
Petr Tesarik ed6dfe517e Make add-symbol-file's address argument optional
The (first) .text section must be always specified as the second
non-option argument.  The documentation states that GDB cannot
figure out this address by itself.  This is true if the object file
was indeed relocated, but it is also confusing, because all other
sections can be omitted and will use the address provided by BFD.

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* symfile.c (add_symbol_file_command, _initialize_symfile): Do not
	require the second argument.  If omitted, load sections at the
	addresses specified in the file.

gdb/doc/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.texinfo (Files): The address argument for "add-symbol-file"
	is no longer mandatory.

gdb/testsuite/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.base/relocate.exp: Test add-symbol-file behavior when the
	address argument is omitted.
2018-06-28 08:35:34 +02:00
Petr Tesarik d4d429d589 Add an optional offset option to the "symbol-file" command
If the main file is relocated at runtime, all symbols are offset by
a fixed amount.  Let the user specify this offset when loading a
symbol file.

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* symfile.c (symbol_file_command, symbol_file_add_main_1)
	(_initialize_symfile): Add option "-o" to symbol-file to add an
	offset to each section of the symbol file.

gdb/doc/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.texinfo (Files): Document "symbol-file -o offset".

gdb/testsuite/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.base/relocate.exp: Add test for "symbol-file -o ".
2018-06-28 08:35:34 +02:00
Petr Tesarik 39b27ab6ae Add myself as a write-after-approval GDB maintainer.
gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* MAINTAINERS (Write After Approval): Add Petr Tesarik.
2018-06-28 08:01:33 +02:00
Tom Tromey 41827fc34d Update "func" help text to GNU standards
In my earlier series to change help text to follow the GNU standards
for metasyntactic variables, I missed one: the "func" command.  This
patch updates its help text.

Tested by the buildbot.

gdb/ChangeLog
2018-06-27  Tom Tromey  <tom@tromey.com>

	* stack.c (_initialize_stack): Update "func" help text.
2018-06-27 15:09:05 -06:00
Tom Tromey 0c6aef226e Remove a VEC from py-unwind.c
This removes a use of VEC from py-unwind.c, replacing it wit
std::vector.  It also changes saved_regs to hold a gdbpy_ref<>,
simplifying the memory management.

Tested against gdb.python on x86-64 Fedora 26.

gdb/ChangeLog
2018-06-27  Tom Tromey  <tom@tromey.com>

	* python/py-unwind.c (unwind_info_object) <saved_regs>: Now a
	std::vector.
	(unwind_infopy_str, pyuw_create_unwind_info)
	(unwind_infopy_add_saved_register, pyuw_sniffer)
	(unwind_infopy_dealloc, unwind_infopy_add_saved_register):
	Update.
	(struct saved_reg): Add constructor.
	<value>: Now a gdbpy_ref<>.
2018-06-27 14:50:10 -06:00
Tom Tromey 6317728958 Fix crash in machoread.c
"./gdb ./gdb" was crashing for me on macOS.  Investigating showed that
macho_symfile_read was crashing because "symbol_table" was being freed
too soon.  This was introduced by my earlier patch to change
macho_symfile_read to use a std::vector.

Tested on macOS 10.13.5 using "./gdb ./gdb".  This should un-break
various already existing tests (testsuite/gdb.gdb at least), so no new
test case.

I'm checking this in as obvious.

gdb/ChangeLog
2018-06-27  Tom Tromey  <tom@tromey.com>

	* machoread.c (macho_symfile_read): Define "symbol_table" earlier.
2018-06-27 14:36:42 -06:00
Simon Marchi e76f78a052 Format gdb-gdb.py.in with autopep8
Format using "autopep8 -i".

gdb/ChangeLog:

	* gdb-gdb.py.in: Format using autopep8.
2018-06-27 15:31:05 -04:00
Simon Marchi 9a14af7b1a Add pretty-printer for CORE_ADDR
Add a pretty-printer that prints CORE_ADDR values in hex.

gdb/ChangeLog:

	* gdb-gdb.py.in (CoreAddrPrettyPrinter): New class.
	(type_lookup_function): Recognize CORE_ADDR values.
2018-06-27 15:21:47 -04:00
Simon Marchi 189366cd86 gdb-gdb.py.in: Don't print value's tag_name
This has been removed recently.

gdb/ChangeLog:

	* gdb-gdb.py.in (StructMainTypePrettyPrinter) <to_string>: Don't
	print tag_name.
2018-06-27 14:32:08 -04:00
Simon Marchi 68ad5fb9aa gdb-gdb.py.in: Fix ordering of TypeFlags objects with Python 3
Python 3 doesn't use __cmp__ to order objects, it uses __lt__.  Because
of this, we get this exception when trying to pretty-print "type"
objects:

I tested it with Python 2.7 as well.

gdb/ChangeLog:

	* gdb-gdb.py.in (TypeFlag) <__cmp__>: Remove.
	<__lt__>: Add.
2018-06-27 14:32:05 -04:00
Simon Marchi 141ec9f67f Copy gdb-gdb.py to build dir
I have thought for a long time how nice it would be to have cool pretty
printers for GDB's internal types.  Well, turns out there are few
already in gdb-gdb.py!  Unfortunately, if you build GDB outside of the
source directory, that file never gets loaded.  top-gdb will look for a
file called

  ../path/to/build/gdb/gdb-gdb.py

but that file is in the source directory at

  ../path/to/src/gdb/gdb-gdb.py

This patch makes it so we copy it to the build directory, just like we
do for gdb-gdb.gdb.  With this, I can at least see the file getting
automatically loaded:

(top-gdb) info pretty-printer
global pretty-printers:
  builtin
    mpx_bound128
  objfile /home/emaisin/build/binutils-gdb/gdb/gdb pretty-printers:
  type_lookup_function

I noticed that running "make" didn't re-generate gdb-gdb.py from
gdb-gdb.py.in.  That's because it's copied when running the configure
script and that's it.  I added a rule in the Makefile for that (and for
gdb-gdb.gdb too) and added them as a dependency to the "all" target.

gdb/ChangeLog:

	* gdb-gdb.py: Move to...
	* gdb-gdb.py.in: ... here.
	* configure.ac (AC_CONFIG_FILES): Add gdb-gdb.py.
	* Makefile.in (all): Add gdb-gdb.gdb and gdb-gdb.py as
	dependencies.
	(distclean): Remove gdb-gdb.py when cleaning.
	(gdb-gdb.py, gdb-gdb.gdb): New rules.
	* configure: Re-generate.
2018-06-27 14:32:02 -04:00
Pedro Alves 4c4e7ad46e Fix Cell debugging regression
Commit 00431a78b2 ("Use thread_info and inferior pointers more
throughout") broke Cell multi-arch debugging, because it made the
proc-service routines (ps_lgetregs etc.) access registers using the
SPU architecture if GDB happens to interrupt SPU code.  The
proc-service routines must always operate on the "main" (in this case
PowerPC) architecture, because that's the register set libthread_db
expects to be using.

Restore the previous behavior, but wrapped in a new
get_ps_regcache function with a describing comment.

Also, the ps_l*regs routines have an explicit lwpid parameter that
said commit missed; with the commit mentioned above, we started always
reading the registers off of the current thread, which is incorrect.
That is fixed by this commit too.

gdb/ChangeLog:
2018-06-27  Pedro Alves  <palves@redhat.com>

	* proc-service.c (get_ps_regcache): New.
	(ps_lgetregs, ps_lsetregs, ps_lgetfpregs)
	(ps_lsetfpregs): Use it.
2018-06-27 17:19:32 +01:00
Omair Javaid 7ab6656f27 Fix lost line info for symbol at addr zero
This patch fixes a unique condition where GDB fails to provide line
information of symbol at address zero when code is compiled with text
address zero but loaded at an offset > 0.

For example lets compile following code snippet:

int main() {
  return 0;
}

gcc -O0 -g3 -nostdlib -emain -Wl,-Ttext=0x00 -o file.out file.c

Start gdb and run:

add-symbol-file file.out 0xffff0000
info line main

GDB will return error saying no line info is available for the symbol.

This is a direct consequence of the fix for PR 12528 where GDB tries to ignore
line table for a function which has been garbage collected by the linker.

As the garbage collected symbols are sent to address zero GDB assumes a symbol
actually placed at address zero as garbage collected.

This was fixed with an additional check address < lowpc. But when symbol is
loaded at an offset lowpc becomes lowpc + offset while no offset is added to
address rather final symbol address is calculated based on baseaddr and address
added together. So in case where symbols are loaded at an offset the condition
address < lowpc will always return true.

This patch fixes this by comparing address against a non offset lowpc.

This patch also adds a GDB test case to replicate this behavior.

gdb:

2018-06-27  Omair Javaid  <omair.javaid@linaro.org>

	PR gdb/21695
	* dwarf2read.c (lnp_state_machine::check_line_address): Update declaration.
	(dwarf_decode_lines_1): Adjust.

gdb/testsuite:

2018-06-27  Omair Javaid  <omair.javaid@linaro.org>

	PR gdb/21695
	* gdb.base/infoline-reloc-main-from-zero.exp: New test.
	* gdb.base/infoline-reloc-main-from-zero.c: New file.
2018-06-27 20:12:49 +05:00
Simon Marchi bd583225a5 Add overrides, fix FreeBSD build
Fix this:

  CXX    fbsd-nat.o
In file included from fbsd-nat.c:44:
./fbsd-nat.h:40:7: error: 'find_memory_regions' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
  int find_memory_regions (find_memory_region_ftype func, void *data);
      ^
./target.h:702:17: note: overridden virtual function is here
    virtual int find_memory_regions (find_memory_region_ftype func, void *data)
                ^
In file included from fbsd-nat.c:44:
./fbsd-nat.h:42:8: error: 'info_proc' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
  bool info_proc (const char *, enum info_proc_what);
       ^
./target.h:950:18: note: overridden virtual function is here
    virtual bool info_proc (const char *, enum info_proc_what);
                 ^

gdb/ChangeLog:

	* fbsd-nat.h (class fbsd_nat_target) <find_memory_regions>: Add
	override.
	<info_proc>: Likewise.
2018-06-27 10:53:29 -04:00
Joel Brobecker 9a325b7b3f Minor reorganization of fetch_registers/store_registers in windows-nat.c
This patch is a small reorganizational patch that splits
do_windows_fetch_inferior_registers into two parts:

  (a) One part that first reloads the thread's context when needed,
      and then decides based on the given register number whether
      one register needs to be fetched or all of them.

      This part is moved to windows_nat_target::fetch_registers.

  (b) The rest of the code, which actually fetches the register value
      and supplies it to the regcache.

A similar treatment is applied to do_windows_store_inferior_registers.

This change is preparation work for changing the way we calculate
the location of a given register in the thread context structure,
and should be a no op.

gdb/ChangeLog:

        * windows-nat.c (do_windows_fetch_inferior_registers): Rename
        to windows_fetch_one_register, and only handle the case of
        fetching one register.  Move the code that reloads the context
        and iterates over all registers if R is negative to...
        (windows_nat_target::fetch_registers): ... here.
        (do_windows_store_inferior_registers): Rename to
        windows_store_one_register, and only handle the case of storing
        one register.  Move the code that handles the case where r is
        negative to...
        (windows_nat_target::store_registers) ... here.

Tested on x86-windows and x86_64-windows using AdaCore's testsuite.
2018-06-26 14:38:32 -07:00
Tom Tromey a33ccfc7af Support ptype/o in Rust
This adds support for ptype/o to the Rust language code.

By default, the Rust compiler reorders fields to reduce padding.  So,
the Rust language code sorts the fields by offset before printing.
This may yield somewhat odd-looking results, but it is faithful to
"what really happens", and might be useful when doing lower-level
debugging.

The reordering can be disabled using #[repr(c)]; ptype/o might be more
useful in this case.

gdb/ChangeLog
2018-06-26  Tom Tromey  <tom@tromey.com>

	PR rust/22574:
	* typeprint.c (whatis_exp): Allow ptype/o for Rust.
	* rust-lang.c (rust_print_struct_def): Add podata parameter.
	Update.
	(rust_internal_print_type): Add podata parameter.
	(rust_print_type): Update.

gdb/testsuite/ChangeLog
2018-06-26  Tom Tromey  <tom@tromey.com>

	PR rust/22574:
	* gdb.rust/simple.exp (test_one_slice): Add ptype/o tests.
	* gdb.rust/simple.rs (struct SimpleLayout): New.
2018-06-26 14:53:17 -06:00
Tom Tromey e0c547d14a Move ptype/o printing code to typeprint.c
This moves the hole-printing support code for ptype/o from
c-typeprint.c to be methods on print_offset_data.  This allows the
code to be used from non-C languages.

gdb/ChangeLog
2018-06-26  Tom Tromey  <tom@tromey.com>

	* typeprint.h (struct print_offset_data) <update, finish,
	maybe_print_hole>: New methods.
	<indentation>: New constant.
	* typeprint.c (print_offset_data::indentation): Define.
	(print_offset_data::maybe_print_hole, print_offset_data::update)
	(print_offset_data::finish): Move from c-typeprint.c and rename.
	* c-typeprint.c (OFFSET_SPC_LEN): Remove.
	(print_spaces_filtered_with_print_options): Update.
	(c_print_type_union_field_offset, maybe_print_hole)
	(c_print_type_struct_field_offset): Move to typeprint.c and
	rename.
	(c_type_print_base_struct_union): Update.
2018-06-26 14:53:17 -06:00
Pedro Alves 75cbc781e3 gdb: For macOS, s/thread_info/struct thread_info/
The macOS build currently fails with several instances of this problem:

  In file included from ../../src/gdb/darwin-nat.h:22:0,
		   from ../../src/gdb/i386-darwin-nat.c:37:
  ../../src/gdb/gdbthread.h:376:59: error: type/value mismatch at argument 1 in template parameter list for 'template<class T, class Policy> class gdb::ref_ptr'
     = gdb::ref_ptr<thread_info, refcounted_object_ref_policy>;
							     ^
  ../../src/gdb/gdbthread.h:376:59: note:   expected a type, got 'thread_info'
  ../../src/gdb/gdbthread.h:396:28: error: variable or field 'delete_thread' declared void
   extern void delete_thread (thread_info *thread);
			      ^
(...)

This is because there's a thread_info function in the Darwin/XNU/mach API:

 http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/thread_info.html

Fix this in the same way it had been fixed in commit 7aabaf9d4a
("Create private_thread_info hierarchy"), by adding an explicit
"struct" keyword.

gdb/ChangeLog:
2018-06-25  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (thread_info_ref, delete_thread)
	(delete_thread_silent, first_thread_of_inferior)
	(any_thread_of_inferior, switch_to_thread)
	(enable_thread_stack_temporaries)
	(thread_stack_temporaries_enabled_p, push_thread_stack_temporary)
	(get_last_thread_stack_temporary)
	(value_in_thread_stack_temporaries, can_access_registers_thread):
	Spell out "struct thread_info" instead of just "thread_info".
	* inferior.h (notice_new_inferior): Likewise.
2018-06-25 17:43:14 +01:00
Pedro Alves b7a08269ca gdb: Fix build on several hosts/ports
Commit 00431a78b2 ("Use thread_info and inferior pointers more
throughout") missed updating some callers, like e.g.,:

 gdb/remote-sim.c: In member function 'virtual void gdbsim_target::mourn_inferior()':
 gdb/remote-sim.c:1198:50: error: cannot convert 'ptid_t' to 'thread_info*' for argument '1' to 'void delete_thread_silent(thread_info*)'
   delete_thread_silent (sim_data->remote_sim_ptid);

 gdb/mygit/src/gdb/procfs.c: In member function ‘virtual void procfs_target::detach(inferior*, int)’:
 gdb/mygit/src/gdb/procfs.c:1931:23: error: invalid conversion from ‘int’ to ‘inferior*’ [-fpermissive]
    detach_inferior (pid);
			 ^
 In file included from gdb/mygit/src/gdb/procfs.c:24:0:
 gdb/mygit/src/gdb/inferior.h:476:13: note:   initializing argument 1 of ‘void detach_inferior(inferior*)’

 etc.

This fixes it.

The delete_thread_silent calls in both go32-nat.c and remote-sim.c are
unnecessary because generic_mourn_inferior calls exit_inferior, which
deletes the inferior's threads.

gdb/ChangeLog:
2018-06-25  Pedro Alves  <palves@redhat.com>

	* windows-nat.c (windows_delete_thread): Use find_thread_ptid and
	pass thread_info pointer to delete_thread.
	(windows_nat_target::detach): Pass inferior pointer to
	detach_inferior.
	* aix-thread.c (sync_threadlists): Pass thread_info pointer to
	delete_thread.
	* bsd-kvm.c (bsd_kvm_target::close): Use discard_all_inferiors.
	* darwin-nat.c (darwin_check_new_threads): Use find_thread_ptid
	and pass a thread_info pointer to delete_thread.
	* fbsd-nat.c (fbsd_nat_target::wait): Use find_thread_ptid and
	pass thread_info pointer to delete_thread.
	* go32-nat.c (go32_nat_target::mourn_inferior): Remove
	delete_thread_silent call.
	* procfs.c (procfs_target::detach): Pass inferior pointer to
	detach_inferior.
	(procfs_target::wait): Pass thread_info pointer to delete_thread.
	* remote-sim.c (gdbsim_target::mourn_inferior): Remove
	delete_thread_silent call.
	* windows-nat.c (windows_delete_thread): Use find_thread_ptid and
	pass thread_info pointer to delete_thread.
	(windows_nat_target::detach): Pass inferior pointer to
	delete_inferior.
2018-06-25 17:42:22 +01:00
Simon Marchi 6d72d289c4 Fix "info registers" regexes in gdb.base/jit-reader.exp
Commit

  e813d34 ("Align natural-format register values to the same column")

changed the output of "info registers" (tabs to spaces), but didn't
update gdb.base/jit-reader.exp.  Update the regexes to expect spaces
instead.

gdb/testsuite/ChangeLog:

	* gdb.base/jit-reader.exp (jit_reader_test): Expect spaces in
	"info registers" output.
2018-06-22 13:40:47 -04:00