Commit Graph

42987 Commits

Author SHA1 Message Date
Tom Tromey
22a20dca3a Change dbxread.c to use type-safe registry
This changes dbxread.c to use the type-safe registry.  In a couple of
spots, you'll see that dbx_objfile_data_key.emplace is called but the
result is not used; this is because those functions refer to the key
via the various DBX_* macros.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* gdb-stabs.h (struct dbx_symfile_info): Add initializers and
	destructor.
	(dbx_objfile_data_key): Change type and declare later.
	(DBX_SYMFILE_INFO): Rewrite.
	* dbxread.c (dbx_objfile_data_key): Change type.
	(dbx_symfile_init): Update.
	(~dbx_symfile_info): Rename from dbx_free_symfile_info.  Update.
	(coffstab_build_psymtabs, elfstab_build_psymtabs)
	(stabsect_build_psymtabs, _initialize_dbxread): Update.
2019-07-10 12:43:38 -06:00
Tom Tromey
cb60f4208b Change jit.c to use type-safe registry
This changes jit.c to use the type-safe registry.  Only one of the
registry keys in jit.c is converted; the other is trickier and so I've
left it be for now.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* jit.c (jit_program_space_key): Change type.  Move lower.
	(get_jit_program_space_data): Update.
	(jit_program_space_data_cleanup): Remove.
	(jit_breakpoint_deleted, free_objfile_data, _initialize_jit):
	Update.
	(struct jit_program_space_data): Add initializers.
2019-07-10 12:43:35 -06:00
Tom Tromey
51df2ae302 Change solib-darwin.c to use type-safe registry
This changes solib-darwin.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-darwin.c (struct darwin_info): Add initializers.
	(solib_darwin_pspace_data): Change type.
	(darwin_pspace_data_cleanup): Remove.
	(get_darwin_info, _initialize_darwin_solib): Update.
2019-07-10 12:42:16 -06:00
Tom Tromey
18101a3525 Change remote-sim.c to use type-safe registry
This changes remote-sim.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* remote-sim.c (struct sim_inferior_data): Add initializers,
	constructor, and destructor.
	(sim_inferior_data_key): Change type.  Move lower.
	(check_for_duplicate_sim_descriptor): Update.
	(get_sim_inferior_data): Use new.  Update.
	(~sim_inferior_data_cleanup): Rename from
	sim_inferior_data_cleanup.  Simplify.
	(gdbsim_close_inferior, simulator_command)
	(sim_command_completer, _initialize_remote_sim): Update.
	(next_pid, INITIAL_PID): Move earlier.
2019-07-10 12:42:16 -06:00
Tom Tromey
05b08ac160 Reduce manual reference counting in py-inferior.c
This patch changes py-inferior.c to use gdbpy_ref<> when possible,
reducing the amount of manual reference counting.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* python/python-internal.h (create_thread_object): Return
	gdbpy_ref.
	* python/py-infthread.c (create_thread_object): Return gdbpy_ref.
	* python/py-inferior.c (struct threadlist_entry): Add
	constructor.
	<thread_obj>: Now a gdbpy_ref.
	(thread_to_thread_object): Update.
	(add_thread_object): Use new.
	(delete_thread_object): Use delete.
	(infpy_threads): Update.
	(py_free_inferior): Update.  Construct "inf_obj" after acquiring
	GIL.
2019-07-10 12:24:22 -06:00
Tom Tromey
32372d80ca Specialize value_cast error message for Ada
In Ada, the term for a cast is "type conversion".  AdaCore has been
carrying a local patch to specialize the error message in value_cast,
but it seemed fine to me for this to be part of gdb.  This also
removes a dead "return" statement.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* valops.c (value_cast): Specialize error message for Ada.
2019-07-10 12:18:39 -06:00
Simon Marchi
5c458ae8f5 Update breakpoint_1's documentation
I noticed the documentation of breakpoint_1 way way out of date, so this
is an attempt to update it.  I have changed the parameter names to
something that seems clearer to me.

gdb/ChangeLog:

	* breakpoint.c (breakpoint_1): Update doc and parameter names.
2019-07-10 12:12:37 -04:00
Simon Marchi
4c462cb0ef Make some bpstat functions use bool
Change return type to bool and adjust function comments.

gdb/ChangeLog:

	* breakpoint.h (bpstat_explains_signal, bpstat_causes_stop,
	bpstat_should_step): Return bool, adjust comments.
	* breakpoint.c (bpstat_explains_signal, bpstat_causes_stop,
	bpstat_should_step): Likewise.
2019-07-10 12:10:51 -04:00
Alan Hayward
89abbcc26d Arm: Create feature files for Arm target descriptions
Add Arm to the list of feature target description targets and generate the
relevant C files.

Add arm-m-profile-with-fpa.xml as the feature version of the exisiting
arm-with-m-fpa-layout.xml.

Add extra comments to the Makefile for readability.

New files are not yet used.

gdb/ChangeLog:

	* features/Makefile: Use feature target descriptions for Arm.
	* features/arm/arm-core.c: Generate new file.
	* features/arm/arm-fpa.c: Likewise.
	* features/arm/arm-m-profile-with-fpa.xml: Likewise.
	* features/arm/arm-m-profile.c: Likewise.
	* features/arm/arm-vfpv2.c: Likewise.
	* features/arm/arm-vfpv3.c: Likewise.
	* features/arm/xscale-iwmmxt.c: Likewise.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Add Arm.
2019-07-10 14:20:49 +01:00
Richard Bunt
b863685d70 Restore original GDB prompt in define.exp
define.exp will fail on a GDB which has set a custom prompt to identify
itself.  This is because the test resets the prompt to a hard coded
"(gdb)" but then verifies the success of this against the value in
$gdb_prompt, which is set to the custom prompt.

The original approach to fix this involved resetting the prompt to
$gdb_prompt rather than a hard coded "(gdb)". However it was noted during
review that $gdb_prompt is a regular expression rather than a string.
This is problematic because in general the prompt would be reset to a
regular expression rather than an instance of a string accepted by said
regular expression.

The fix used in this commit avoids the above issue by capturing the
literal prompt from running "show prompt" and uses this literal to
restore the previous prompt.

Regression tested with GCC 7.3.0 on x86_64, ppc64le, aarch64.

gdb/testsuite/ChangeLog:
2019-07-10  Richard Bunt  <richard.bunt@arm.com>
	Stephen Roberts  <stephen.roberts@arm.com>

	* gdb.base/define.exp: Restore original prompt.
2019-07-10 14:14:16 +01:00
Alan Hayward
166a82be89 Arm: Minor style cleanups
*When reading a target description, do the ptrace check before picking the
 target description.

*In wmmxregset functions, declare the counter inside the for.

*Call arm_linux_init_hwbp_cap from in arm_arch_setup - it doesn't belong in
 arm_read_description.

gdb/ChangeLog:

	* arm-linux-nat.c (arm_linux_nat_target::read_description): Check
	ptrace earlier,

gdb/gdbserver/ChangeLog:

	* linux-arm-low.c (arm_fill_wmmxregset, arm_store_wmmxregset):
	Move counter inside for.
	(arm_read_description): Check ptrace earlier.
	(arm_arch_setup): Call arm_linux_init_hwbp_cap here.
2019-07-10 11:59:34 +01:00
Alan Hayward
9fb4c7e9f0 Regenerate aarch64-pauth.c
aarch64-pauth.c was slightly out of sync with the generated version.
Regenerate it.

gdb/ChangeLog:

	* features/aarch64-pauth.c: Regenerate.
2019-07-10 11:47:13 +01:00
Simon Marchi
e2d0f9803e Make bpstat_what::is_longjmp a bool
gdb/ChangeLog:

	* breakpoint.h (struct bpstat_what) <is_longjmp>: Change type to
	bool.
	(bpstat_what): Use false instead of 0.
2019-07-09 21:20:16 -04:00
Pedro Alves
a38118e5d1 Make "maint info breakpoints" show "catch catch/throw/rethrow" locations
This commit makes "maint info breakpoints" show the internal locations
of C++ exception catchpoints:

 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch

With multiple locations:

 (gdb) maint info breakpoints
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch
 2.1                         y   0x000000000040545f <__cxa_begin_catch+95> inf 1
 2.2                         y   0x00007ffff71dbe0f <__cxxabiv1::__cxa_begin_catch(void*)+95> inf 1
 (gdb)

With a single location:

 (gdb) maint info breakpoints 2
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch inf 1
 2.1                         y   0x00007ffff7bc0b7f <__cxa_begin_catch+95> inf 1

With no locations:

 (gdb) maint info breakpoints 2
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch inf 1


Other catchpoints still show the same way, here a catch signal:

 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 3       catchpoint     keep y                      signal "<standard signals>"

 (gdb) maint info breakpoints
 Num     Type           Disp Enb Address            What
 3       catchpoint     keep y                      signal "<standard signals>"  inf 1
 (gdb)

Note: I considered making the locations be printed from within
breakpoint_ops::print_one(), but gave up given the handling for the
broken MI v2 output:

 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
     are outside.  */
  if (!use_fixed_output)
    bkpt_tuple_emitter.reset ();

in print_one_breakpoint.

gdb/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* break-catch-throw.c (is_exception_catchpoint): New.
	* breakpoint.c (print_one_breakpoint_location): New parameter
	'raw_loc'.  Handle it.  Use
	is_watchpoint/is_catchpoint/is_exception_catchpoint instead of
	looking at the breakpoint's type.
	(print_one_breakpoint): If handling "maint info breakpoints", also
	print locations of exception catchpoints.
	* breakpoint.h (is_exception_catchpoint): Declare.
2019-07-09 20:00:07 +01:00
Pedro Alves
cb1e4e32c2 "catch catch/throw/rethrow", breakpoint -> catchpoint
Currently, with:

 (gdb) catch catch
 Catchpoint 1 (catch)
 (gdb) catch throw
 Catchpoint 2 (throw)
 (gdb) catch rethrow
 Catchpoint 3 (rethrow)

You get:

(gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 1       breakpoint     keep y   0x0000000000b122af exception catch
 2       breakpoint     keep y   0x0000000000b1288d exception throw
 3       breakpoint     keep y   0x0000000000b12931 exception rethrow

I think it doesn't make much sense usability-wise, to show a
catchpoint as a breakpoint.  The fact that GDB sets a breakpoint at
some magic address in the C++ run time is an implementation detail,
IMO.  And as seen in the previous patch, such a catchpoint can end up
with more than one location/address even, so showing a single address
isn't entirely accurate.

This commit hides the addresses from view, and makes GDB show
"catchpoint" for type as well:

  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  1       catchpoint     keep y                      exception catch
  2       catchpoint     keep y                      exception throw
  3       catchpoint     keep y                      exception rethrow

This comment in the code seems telling:

  /* We need to reset 'type' in order for code in breakpoint.c to do
     the right thing.  */
  cp->type = bp_breakpoint;

It kind of suggests that the reason catchpoints end up shown as
breakpoints was that it was easier to implement them that way, rather
than a desired property.

This commit fixes things up to make it possible to have bp_catch
breakpoints have software/hardware breakpoint locations, thus
eliminating the need for that hack:

 - redo breakpoint_address_is_meaningful in terms of the location's
   type rather than breakpoint type.
 - teach bpstat_what about stepping over the catchpoint locations.
 - install a allocate_location method for "catch catch/throw/rethrow",
   one that forces the location type.

Note that this also reverts the gdb hunk from:

  commit 2a8be20359
  Commit:     Tom Tromey <tom@tromey.com>
  CommitDate: Sat Oct 6 22:17:45 2018 -0600

      Fix Python gdb.Breakpoint.location crash

because now "catch throw" catchpoints hit the

   if (obj->bp->type != bp_breakpoint)
     Py_RETURN_NONE;

check above, and, adjusts the testcase to no longer expect to see the
catchpoint in the gdb.breakpoints() list.

(Note: might make sense to do the same to Ada exception catchpoints.)

gdb/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* break-catch-throw.c (print_one_exception_catchpoint): Skip the
	"addr" field.
	(allocate_location_exception_catchpoint): New.
	(handle_gnu_v3_exceptions): Don't reset 'type' to bp_breakpoint.
	(initialize_throw_catchpoint_ops): Install
	allocate_location_exception_catchpoint as allocate_location
	method.
	* breakpoint.c (bpstat_what) <bp_catch>: Set action to
	BPSTAT_WHAT_SINGLE if not stopping and the location's type is not
	bp_loc_other.
	(breakpoint_address_is_meaningful): Delete.
	(bl_address_is_meaningful): New.
	(breakpoint_locations_match): Adjust comment.
	(bp_location_from_bp_type): New, factored out of...
	(bp_location::bp_location(breakpoint *)): ... this.
	(bp_location::bp_location(breakpoint *, bp_loc_type)): New,
	factored out of...
	(bp_location::bp_location(breakpoint *)): ... this.  Reimplement.
	(bp_loc_is_permanent): Use bl_address_is_meaningful instead of
	breakpoint_address_is_meaningful.
	(bp_locations_compare): Adjust comment.
	(update_global_location_list): Use bl_address_is_meaningful
	instead of breakpoint_address_is_meaningful.
	* breakpoint.h (bp_location::bp_location(breakpoint *)): New
	explicit.
	(bp_location::bp_location(breakpoint *, bp_loc_type)): Declare.
	* python/py-breakpoint.c (bppy_get_location): No longer check
	whether location is null.

gdb/doc/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (C++ Exception GDB/MI Catchpoint Commands): Adjust
	examples to show type=catchpoint instead of type=breakpoint and an
	address.

gdb/testsuite/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* gdb.cp/catch-multi-stdlib.exp: Adjust expected "info
	breakpoints" output.
	* gdb.cp/exception.exp: Adjust expected "info breakpoints" output.
	* gdb.python/py-breakpoint.exp: No longer expect that "catch
	throw" creates breakpoint.
	* gdb.mi/mi-catch-cpp-exceptions.exp (setup_catchpoint): Expect
	'type="catchpoint"'.
2019-07-09 19:34:18 +01:00
Pedro Alves
b58a68fe57 Fix "info break" + "catch catch" + -static-{libstdc++,libgcc}
If you debug current GDB, set a "catch catch/throw/rethrow"
catchpoint, and then do "info breakpoints", the top GDB hits an
internal error:

 (top-gdb) catch catch
 Catchpoint 1 (catch)
 (top-gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 1       breakpoint     keep y   src/gdb/breakpoint.c:6040: internal-error: void print_one_breakpoint_location(breakpoint*, bp_location*, int, bp_location**, int): Assertion `b->loc == NULL || b->loc->next == NULL' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n)

The assertion in question is asserting that a breakpoint with a
print_one method only has one location, and it fails because this
catchpoint ends up with two locations.

Internally, "catch catch" sets a breakpoint at __cxa_begin_catch.  If
we do that manually, we see the locations:

  (top-gdb) b -qualified __cxa_begin_catch
  Breakpoint 2 at 0xb122b0 (2 locations)
  (top-gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  2       breakpoint     keep y   <MULTIPLE>
  2.1                         y   0x0000000000b122b0 <__cxa_begin_catch>
  2.2                         y   0x00007ffff2f4ddb0 in __cxxabiv1::__cxa_begin_catch(void*) at ../../../../libstdc++-v3/libsupc++/eh_catch.cc:41

Note that I had used -qualified.  It seems strange that we get a
location for a namespaced symbol, but that happens because the minimal
symbol for that address is indeed called __cxa_begin_catch.

The real issue is that gdb is linked with
-static-libgcc/-static-libstdc++.  And then, it _also_ ends up with
shared libstc++ loaded:

  (top-gdb) info sharedlibrary stdc++
  From                To                  Syms Read   Shared Object Library
  0x00007ffff2f4b380  0x00007ffff2ffc018  Yes         /lib64/libstdc++.so.6

Location 2.2 is set within libstdc++.so.6's range:

  (top-gdb) p 0x00007ffff2f4b380 <= 0x00007ffff2f4ddb0 && 0x00007ffff2f4ddb0 < 0x00007ffff2ffc018
  $1 = true

So due to -static-lib*, we end up with _two_ copies of the
__cxa_begin_catch code:

  (top-gdb) disassemble 0x0000000000b122b0
  Dump of assembler code for function __cxa_begin_catch:
     0x0000000000b122b0 <+0>:     push   %rbx
     0x0000000000b122b1 <+1>:     mov    %rdi,%rbx
     0x0000000000b122b4 <+4>:     callq  0xb11a80 <__cxa_get_globals>
     0x0000000000b122b9 <+9>:     movabs $0xb8b1aabcbcd4d500,%rdx
  ...

  (top-gdb) disassemble 0x00007ffff2f4ddb0
  Dump of assembler code for function __cxxabiv1::__cxa_begin_catch(void*):
     0x00007ffff2f4ddb0 <+0>:     push   %rbx
     0x00007ffff2f4ddb1 <+1>:     mov    %rdi,%rbx
     0x00007ffff2f4ddb4 <+4>:     callq  0x7ffff2f4a090 <__cxa_get_globals@plt>
     0x00007ffff2f4ddb9 <+9>:     movabs $0xb8b1aabcbcd4d500,%rdx
  ...

I think we end up with libstdc++.so.6 loaded because
libsource-highlight.so depends on it.

Irrespective of whether it's a good idea to use
-static-libgcc/-static-libstdc++, GDB should not crash.  Since there
are two copies of the code, it seems right to have more than one
location.  So the fix is just to remove the assertion.

A testcase is included, which mimics the scenerio described above,
with binary linked with -static-lib{stdc++,gcc} and a shared library
that is linked normally, along with other combinations for good
measure.

gdb/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	PR c++/15468
	* breakpoint.c (print_one_breakpoint_location): Remove
	single-location assert.

gdb/testsuite/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	PR c++/15468
	* gdb.cp/except-multi-location-lib.cc: New.
	* gdb.cp/except-multi-location-main.cc: New.
	* gdb.cp/except-multi-location.exp: New.
2019-07-09 19:26:15 +01:00
Philippe Waroquiers
0826779b99 Fix printcmds.exp failure for wide strings tests.
wchar_t type must be known to create wide strings.
As this type is predefined when current GDB language is C++,
switch to c++ for the wide strings tests.

Problem analysis and fix by Sergio.
2019-07-09 19:36:17 +02:00
Tom Tromey
268a13a5a3 Rename common to gdbsupport
This is the next patch in the ongoing series to move gdbsever to the
top level.

This patch just renames the "common" directory.  The idea is to do
this move in two parts: first rename the directory (this patch), then
move the directory to the top.  This approach makes the patches a bit
more tractable.

I chose the name "gdbsupport" for the directory.  However, as this
patch was largely written by sed, we could pick a new name without too
much difficulty.

Tested by the buildbot.

gdb/ChangeLog
2019-07-09  Tom Tromey  <tom@tromey.com>

	* contrib/ari/gdb_ari.sh: Change common to gdbsupport.
	* configure: Rebuild.
	* configure.ac: Change common to gdbsupport.
	* gdbsupport: Rename from common.
	* acinclude.m4: Change common to gdbsupport.
	* Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES)
	(HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to
	gdbsupport.
	* aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c,
	amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c,
	amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c,
	amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c,
	amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c,
	arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c,
	arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c,
	arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c,
	arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c,
	auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h,
	btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c,
	charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c,
	cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c,
	coff-pe-read.c, command.h, compile/compile-c-support.c,
	compile/compile-c.h, compile/compile-cplus-symbols.c,
	compile/compile-cplus-types.c, compile/compile-cplus.h,
	compile/compile-loc2c.c, compile/compile.c, completer.c,
	completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c,
	cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c,
	darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c,
	disasm.h, dtrace-probe.c, dwarf-index-cache.c,
	dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c,
	dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c,
	event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c,
	features/aarch64-core.c, features/aarch64-fpu.c,
	features/aarch64-pauth.c, features/aarch64-sve.c,
	features/i386/32bit-avx.c, features/i386/32bit-avx512.c,
	features/i386/32bit-core.c, features/i386/32bit-linux.c,
	features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c,
	features/i386/32bit-segments.c, features/i386/32bit-sse.c,
	features/i386/64bit-avx.c, features/i386/64bit-avx512.c,
	features/i386/64bit-core.c, features/i386/64bit-linux.c,
	features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c,
	features/i386/64bit-segments.c, features/i386/64bit-sse.c,
	features/i386/x32-core.c, features/riscv/32bit-cpu.c,
	features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c,
	features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c,
	features/riscv/64bit-fpu.c, features/tic6x-c6xp.c,
	features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h,
	findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h,
	gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c,
	gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c,
	go32-nat.c, guile/guile.c, guile/scm-ports.c,
	guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c,
	i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c,
	i386-linux-tdep.c, i386-tdep.c, i387-tdep.c,
	ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c,
	inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h,
	inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h,
	inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c,
	linux-tdep.c, linux-thread-db.c, location.c, machoread.c,
	macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h,
	mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c,
	mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h,
	minsyms.c, mips-linux-tdep.c, namespace.h,
	nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h,
	nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c,
	nat/amd64-linux-siginfo.c, nat/fork-inferior.c,
	nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c,
	nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c,
	nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h,
	nat/linux-waitpid.c, nat/mips-linux-watch.c,
	nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c,
	nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c,
	nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h,
	obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c,
	parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c,
	procfs.c, producer.c, progspace.h, psymtab.h,
	python/py-framefilter.c, python/py-inferior.c, python/py-ref.h,
	python/py-type.c, python/python.c, record-btrace.c, record-full.c,
	record.c, record.h, regcache-dump.c, regcache.c, regcache.h,
	remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c,
	riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c,
	selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c,
	ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c,
	source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c,
	stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h,
	symtab.c, symtab.h, target-descriptions.c, target-descriptions.h,
	target-memory.c, target.c, target.h, target/waitstatus.c,
	target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c,
	top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c,
	tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h,
	unittests/array-view-selftests.c,
	unittests/child-path-selftests.c, unittests/cli-utils-selftests.c,
	unittests/common-utils-selftests.c,
	unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c,
	unittests/format_pieces-selftests.c,
	unittests/function-view-selftests.c,
	unittests/lookup_name_info-selftests.c,
	unittests/memory-map-selftests.c, unittests/memrange-selftests.c,
	unittests/mkdir-recursive-selftests.c,
	unittests/observable-selftests.c,
	unittests/offset-type-selftests.c, unittests/optional-selftests.c,
	unittests/parse-connection-spec-selftests.c,
	unittests/ptid-selftests.c, unittests/rsp-low-selftests.c,
	unittests/scoped_fd-selftests.c,
	unittests/scoped_mmap-selftests.c,
	unittests/scoped_restore-selftests.c,
	unittests/string_view-selftests.c, unittests/style-selftests.c,
	unittests/tracepoint-selftests.c, unittests/unpack-selftests.c,
	unittests/utils-selftests.c, unittests/xml-utils-selftests.c,
	utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c,
	value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c,
	xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c,
	xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport.

gdb/gdbserver/ChangeLog
2019-07-09  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac: Change common to gdbsupport.
	* acinclude.m4: Change common to gdbsupport.
	* Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS)
	(version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change
	common to gdbsupport.
	* ax.c, event-loop.c, fork-child.c, gdb_proc_service.h,
	gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c,
	inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c,
	linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c,
	linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c,
	linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h,
	nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c,
	server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h,
	thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change
	common to gdbsupport.
2019-07-09 07:45:38 -06:00
Andrew Burgess
5b0e2db4fa gdb: Don't skip prologue for explicit line breakpoints in assembler
It was observed that in some cases, placing a breakpoint in an
assembler file using filename:line-number syntax would result in the
breakpoint being placed at a different line within the file.

For example, consider this x86-64 assembler:

    test:
            push   %rbp		/* Break here.  */
            mov    %rsp, %rbp
            nop			/* Stops here.  */

The user places the breakpoint using file:line notation targeting the
line marked 'Break here', GDB actually stops at the line marked 'Stops
here'.

The reason is that the label 'test' is identified as the likely start
of a function, and the call to symtab.c:skip_prologue_sal causes GDB
to skip forward over the instructions that GDB believes to be part of
the prologue.

I believe however, that when debugging assembler code, where the user
has instruction-by-instruction visibility, if they ask for a specific
line, GDB should (as far as possible) stop on that line, and not
perform any prologue skipping.  I don't believe that the behaviour of
higher level languages should change, in these cases skipping the
prologue seems like the correct thing to do.

In order to implement this change I needed to extend our current
tracking of when the user has requested an explicit line number.  We
already tracked this in some cases, but not in others (see the changes
in linespec.c).  However, once I did this I started to see some
additional failures (in tests gdb.base/break-include.exp
gdb.base/ending-run.exp gdb.mi/mi-break.exp gdb.mi/mi-reverse.exp
gdb.mi/mi-simplerun.exp) where we currently expected a breakpoint
placed at one file and line number to be updated to reference a
different line number, this was fixed by removing some code in
symtab.c:skip_prologue_sal.  My concern here is that removing this
check didn't cause anything else to fail.

I have a new test that covers my original case, this is written for
x86-64 as most folk have access to such a target, however, any
architecture that has a prologue scanner can be impacted by this
change.

gdb/ChangeLog:

	* linespec.c (decode_digits_list_mode): Set explicit_line to a
	bool value.
	(decode_digits_ordinary): Set explicit_line field in sal.
	* symtab.c (skip_prologue_sal): Don't skip prologue for a
	symtab_and_line that was set on an explicit line number in
	assembler code.  Do always update the recorded symtab and line if
	we do skip the prologue.

gdb/testsuite/ChangeLog:

	* gdb.arch/amd64-break-on-asm-line.S: New file.
	* gdb.arch/amd64-break-on-asm-line.exp: New file.
2019-07-09 10:31:21 +01:00
Andrew Burgess
0ba852ab41 gdb: Remove unneeded parameter from set_breakpoint_location_function
The explicit_loc parameter in set_breakpoint_location_function is not
useful.  This parameter is set from two possible fields of the
symtab_and_line used to create the breakpoint; the explicit_pc field,
and the explicit_line field.

First, the explicit_line field, this is not currently set for any
breakpoint command, so will never be true.

Next, the explicit_pc field.  This can be true but will never be true
at the same time that the sal->msymbol field is also true - the
sal->msymbol is only ever set in linespec.c:minsym_found, which
doesn't allow for explicitly setting the pc.

The result of this is that if we are setting a breakpoint on an
msymbol that could turn out to be an ifunc, then we will not also have
either an explicit_pc or an explicit_line, this check can therefore be
removed.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* breakpoint.c (set_breakpoint_location_function): Remove
	explicit_loc parameter.
	(momentary_breakpoint_from_master): Update call to
	set_breakpoint_location_function.
	(add_location_to_breakpoint): Likewise.
2019-07-09 10:31:20 +01:00
Andrew Burgess
b3a7d1711e gdb/riscv: Don't use default bfd to define required features
When we initialise a gdbarch object we perform a check to try and
detect if the user is doing something silly; trying to run an RV64
binary on an RV32 target.  To perform this check we compare the xlen
from the target description with the xlen specified in the headers on
the ELF being debugged.

If there is no ELF being debugged then we (currently) try to use the
bfd_arch_info from the gdbarch_info object, which will have been set
to the default architecture if no bfd is currently being debugged.
For RISC-V the default architecture is RV64.

What this means is that if a user tries to connect to an RV32 target
without specifying the BFD to debug then GDB will assume RV64.  The
sanity check mentioned above will failed (xlen difference) and GDB
will throw an error.  The error causes GDB to disconnect from the
remote target.

After this commit GDB no longer relies on the default bfd
architecture.  If the user tries to connect without specifying the bfd
then GDB will simply make use of the xlen extracted from the target
description in order to find or create a suitable gdbarch object.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_features_from_gdbarch_info): Don't modify
	required features based on default bfd type when no specific bfd
	is present.
2019-07-09 09:41:55 +01:00
Philippe Waroquiers
1f6f6e21fa Ensure GDB printf command can print convenience var strings without a target.
Without this patch, GDB printf command calls malloc on the target,
writes the convenience var content to the target,
re-reads the content from the target, and then locally printf the string.

This implies inferior calls, and does not work when there is no running
inferior, or when the inferior is a core dump.

With this patch, printf command can printf string convenience variables
without inferior function calls.
Ada string convenience variables can also be printed.

gdb/ChangeLog
2019-07-08  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Mention that GDB printf and eval commands can now print
	C-style and Ada-style convenience var strings without
	calling the inferior.
	* printcmd.c (printf_c_string): Locally print GDB internal var
	instead of transiting via the inferior.
	(printf_wide_c_string): Likewise.

gdb/testsuite/ChangeLog
2019-07-08  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/printcmds.exp: Test printing C string and
	C wide string convenience vars without transiting via the inferior.
	Also make test names unique.
2019-07-08 23:31:54 +02:00
Alan Hayward
ea142fbfc9 Fix breakpoints on file reloads for PIE binaries
When a binary is built using PIE, reloading the file will cause GDB to error
on restart.  For example:
gdb ./a.out
(gdb) break main
(gdb) run
(gdb) file ./a.out
(gdb) continue

Will cause GDB to error with:
Continuing.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x9e0
Command aborted.

This is due to the symbol offsets not being relocated after reloading the file.

Fix is to ensure solib_create_inferior_hook is called, in the same manner as
infrun.c:follow_exec().

Expand the idempotent test to cover PIE scenarios.

gdb/ChangeLog:

	* symfile.c (symbol_file_command): Call solib_create_inferior_hook.

gdb/testsuite/ChangeLog:

	* gdb.base/break-idempotent.exp: Test both PIE and non PIE.
2019-07-08 10:13:46 +01:00
Tom Tromey
0598af4880 Fix TUI use of "has_break" field
The TUI uses the "has_break" in two different ways: sometimes as a
boolean, and sometimes as flags.

This patch changes the TUI to be more type-safe here, and fixes the
code.  I could not find a bug that this caused, so apparently this is
just cosmetic.

This deletes some code from tui_set_disassem_content.  Whenver this is
called, I believe the TUI updates the breakpoint information
afterward, so this assignment is redundant; which is good because it
is also incorrect.

gdb/ChangeLog
2019-07-04  Tom Tromey  <tom@tromey.com>

	PR tui/24724:
	* tui/tui-winsource.c (tui_clear_source_content): Update.
	(tui_source_window_base::set_is_exec_point_at): Fix comment.
	(tui_update_breakpoint_info): Update.
	(tui_set_exec_info_content): Update.
	* tui/tui-source.c (tui_set_source_content_nil): Update.
	* tui/tui-disasm.c (tui_set_disassem_content): Don't set
	has_break.
	* tui/tui-data.h (enum tui_bp_flag): New.
	(tui_bp_flags): New enum flags type.
	(struct tui_source_element) <break_mode>: Change type.  Rename
	from has_break.
	(TUI_BP_ENABLED, TUI_BP_DISABLED, TUI_BP_HIT)
	(TUI_BP_CONDITIONAL, TUI_BP_HARDWARE): Don't define.  Now enum
	constants.
	* tui/tui-winsource.h: Fix comment.
2019-07-04 10:36:31 -06:00
Pedro Alves
213fd9faf5 Fix foreach_with_prefix regression
Fix a silly bug in commit a26c8de0ee ("Fix early return in
foreach_with_prefix").

That patch made foreach_with_prefix always return after the first
iteration, making ~10k tests disappear from test runs...

This fixes it, and as penance, adds a testcase that exercises all
kinds of different returns possible (ok, error, return, break,
continue).  I've written it with regular "foreach", and then switched
to foreach_with_prefix and made sure we get the same results.  I put
the testcase in a new gdb.testsuite/ subdir, since this is exercising
the testsuite harness bits.  We can move this elsewhere if people
prefer a different place, but I'm going ahead in order to unbreak the
testsuite ASAP.

gdb/testsuite/ChangeLog:
2019-07-04  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (foreach_with_prefix): Don't return early if
	body returned ok(0), break(3) or continue(4).
	* gdb.testsuite/foreach_with_prefix.exp: New file.
2019-07-04 16:45:23 +01:00
Alan Hayward
350fab5416 Arm/AArch64: Use a single set of Arm register set size defines
Both targets were using a mixture of defines and hardcoded values.
Add a standard set in arch/arm.h and use throughout, ensuring that
none of the existing sizes change.

No functionality changes.

gdb/ChangeLog:

	* aarch32-linux-nat.h (VFP_REGS_SIZE): Remove define.
	* aarch64-linux-nat.c (fetch_fpregs_from_thread)
	(store_fpregs_to_thread)
	(aarch64_linux_nat_target::read_description): Use ARM_VFP3_REGS_SIZE.
	* arch/arm.h (IWMMXT_VEC_REGISTER_SIZE, ARM_CORE_REGS_SIZE)
	(ARM_FP_REGS_SIZE, ARM_VFP2_REGS_SIZE, ARM_VFP3_REGS_SIZE)
	(IWMMXT_REGS_SIZE): Add define.
	* arm-linux-nat.c (IWMMXT_REGS_SIZE): Remove define.
	(fetch_vfp_regs, store_vfp_regs)
	(arm_linux_nat_target::read_description): Use ARM_VFP3_REGS_SIZE.
	* arm-tdep.c (arm_register_g_packet_guesses): Use new defines.

gdb/gdbserver/ChangeLog:

	* linux-aarch32-low.c (arm_read_description, arm_regsets): Use new
	defines.
	* linux-arm-low.c (arm_read_description, arm_regsets): Likewise.
2019-07-04 12:47:42 +01:00
Alan Hayward
f0452268d6 Arm: Prefix register sizes with ARM_
Add ARM_ to the front of INT_REGISTER_SIZE, FP_REGISTER_SIZE and
ARM_VFP_REGISTER_SIZE to make it obvious they are for the Arm target.
Move the defines to arch/arm.h

No functionality changes.

gdb/ChangeLog:

	* arch/arm-get-next-pcs.c (thumb_get_next_pcs_raw): Use ARM_
	defines.
	* arch/arm-linux.c (arm_linux_sigreturn_next_pc_offset): Likewise.
	* arch/arm.h (INT_REGISTER_SIZE) Rename from...
	(ARM_INT_REGISTER_SIZE): ...to this.
	(ARM_FP_REGISTER_SIZE) (ARM_VFP_REGISTER_SIZE): Add define.
	* arm-linux-tdep.c (ARM_LINUX_JB_ELEMENT_SIZE)
	(ARM_LINUX_SIZEOF_GREGSET, arm_linux_supply_gregset)
	(arm_linux_collect_gregset, supply_nwfpe_register)
	(collect_nwfpe_register, arm_linux_collect_nwfpe): Use ARM_
	defines.
	* arm-linux-tdep.h (ARM_LINUX_SIZEOF_NWFPE, NWFPE_FPSR_OFFSET)
	(NWFPE_FPCR_OFFSET, NWFPE_TAGS_OFFSET): Likewise
	* arm-nbsd-tdep.c (ARM_NBSD_JB_ELEMENT_SIZE): Likewise.
	* arm-tdep.c (arm_push_dummy_call, arm_extract_return_value)
	(arm_return_in_memory, arm_store_return_value)
	(arm_get_longjmp_target, arm_register_g_packet_guesses)
	(arm_record_ld_st_multiple): Likewise.
	* arm-tdep.h (FP_REGISTER_SIZE, VFP_REGISTER_SIZE): Remove.
	* arm-wince-tdep.c (ARM_WINCE_JB_ELEMENT_SIZE): Use ARM_ defines.
2019-07-04 12:47:30 +01:00
Alan Hayward
e935475cb6 Arm/AArch64: Split DISPLACED_MODIFIED_INSNS name clash
Both targets define DISPLACED_MODIFIED_INSNS, each with different values.
Add ARM_ and AARCH64_ to the start of the name to prevent confusion.

No functionality changes.

gdb/ChangeLog:

	* aarch64-linux-tdep.c (aarch64_linux_init_abi): Use
	AARCH64_DISPLACED_MODIFIED_INSNS.
	* aarch64-tdep.c (struct aarch64_displaced_step_data)
	(aarch64_displaced_step_copy_insn): Likewise.
	* aarch64-tdep.h (DISPLACED_MODIFIED_INSNS): Rename from..
	(AARCH64_DISPLACED_MODIFIED_INSNS): ...to this.
	* arm-linux-tdep.c (arm_linux_cleanup_svc): Use
	ARM_DISPLACED_MODIFIED_INSNS.
	* arm-tdep.c (arm_gdbarch_init): Likewise.
	* arm-tdep.h (DISPLACED_MODIFIED_INSNS): Rename from..
	(ARM_DISPLACED_MODIFIED_INSNS): ...to this.
	(struct arm_displaced_step_closure): Use
	ARM_DISPLACED_MODIFIED_INSNS.
2019-07-04 12:47:26 +01:00
Alan Hayward
df0bb381e2 i386/AArch64: Remove unused xml files
Remove all the xml files that are no longer used by gdbserver,
and remove their entries from the makefile.

gdb/ChangeLog:

	* features/Makefile: Remove unused xml files.
	* features/aarch64.xml: Remove.
	* features/i386/amd64-avx-avx512-linux.xml: Remove.
	* features/i386/amd64-avx-avx512.xml: Remove.
	* features/i386/amd64-avx-linux.xml: Remove.
	* features/i386/amd64-avx-mpx-avx512-pku-linux.xml: Remove.
	* features/i386/amd64-avx-mpx-avx512-pku.xml: Remove.
	* features/i386/amd64-avx-mpx-linux.xml: Remove.
	* features/i386/amd64-avx-mpx.xml: Remove.
	* features/i386/amd64-avx.xml: Remove.
	* features/i386/amd64-linux.xml: Remove.
	* features/i386/amd64-mpx-linux.xml: Remove.
	* features/i386/amd64-mpx.xml: Remove.
	* features/i386/amd64.xml: Remove.
	* features/i386/i386-avx-avx512-linux.xml: Remove.
	* features/i386/i386-avx-avx512.xml: Remove.
	* features/i386/i386-avx-linux.xml: Remove.
	* features/i386/i386-avx-mpx-avx512-pku-linux.xml: Remove.
	* features/i386/i386-avx-mpx-avx512-pku.xml: Remove.
	* features/i386/i386-avx-mpx-linux.xml: Remove.
	* features/i386/i386-avx-mpx.xml: Remove.
	* features/i386/i386-avx.xml: Remove.
	* features/i386/i386-linux.xml: Remove.
	* features/i386/i386-mmx-linux.xml: Remove.
	* features/i386/i386-mmx.xml: Remove.
	* features/i386/i386-mpx-linux.xml: Remove.
	* features/i386/i386-mpx.xml: Remove.
	* features/i386/i386.xml: Remove.
	* features/i386/x32-avx-avx512-linux.xml: Remove.
	* features/i386/x32-avx-linux.xml: Remove.
	* features/i386/x32-linux.xml: Remove.
2019-07-04 11:55:21 +01:00
Alan Hayward
edd6266ab1 i386/AArch64: Remove unused .dat files
Remove all the dat files that are no longer used by gdbserver.

gdb/ChangeLog:

	* regformats/aarch64.dat: Remove.
	* regformats/i386/amd64-avx-avx512-linux.dat: Remove.
	* regformats/i386/amd64-avx-linux.dat: Remove.
	* regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat: Remove.
	* regformats/i386/amd64-avx-mpx-linux.dat: Remove.
	* regformats/i386/amd64-linux.dat: Remove.
	* regformats/i386/amd64-mpx-linux.dat: Remove.
	* regformats/i386/amd64.dat: Remove.
	* regformats/i386/i386-avx-avx512-linux.dat: Remove.
	* regformats/i386/i386-avx-linux.dat: Remove.
	* regformats/i386/i386-avx-mpx-avx512-pku-linux.dat: Remove.
	* regformats/i386/i386-avx-mpx-linux.dat: Remove.
	* regformats/i386/i386-linux.dat: Remove.
	* regformats/i386/i386-mmx-linux.dat: Remove.
	* regformats/i386/i386-mpx-linux.dat: Remove.
	* regformats/i386/i386.dat: Remove.
	* regformats/i386/x32-avx-avx512-linux.dat: Remove.
	* regformats/i386/x32-avx-linux.dat: Remove.
	* regformats/i386/x32-linux.dat: Remove.
2019-07-04 11:55:20 +01:00
Alan Hayward
2b40fda74b i386/AArch64: Remove old xml tests
Both the i386, X86_64 and AArch64 builds of gdbserver include a bunch of legacy
xml files, dat files and auto generated C files, when building for unit test.

These tests exists back from when feature target descriptions were added to
prove that the new target descriptions were identical to the original
older versions. The old files are not used for anything other than these tests.

Now that this has been proven, we are not gaining anything by keeping the
original files and tests. Should new functionality be added, it would break
the tests, unless the functionality was backported to the xml. There is no
requirement that we must match the exact xml from N releases ago.  It adds
obfuscation, where as the feature target descriptions were meant to simplify
the code.

In addition, there are a bunch of xml and dat files which are completely unused.

This patch removes the selftests and the target descriptions from gdbserver.

Update the unittest to allow 0 tests (note, this failed on other targets that
never had any tests).

gdb/ChangeLog:

	* aarch64-tdep.c: Remove xml self tests.
	* amd64-linux-tdep.c: Likewise.
	* amd64-tdep.c: Likewise.
	* i386-linux-tdep.c: Likewise.
	* i386-tdep.c: Likewise.

gdb/gdbserver/ChangeLog:

	* configure.srv: Remove legacy xml.
	* linux-aarch64-low.c (initialize_low_arch): Remove
	initialize_low_tdesc call.
	* linux-aarch64-tdesc-selftest.c: Remove file.
	* linux-aarch64-tdesc.h (initialize_low_tdesc): Remove.
	* linux-x86-low.c (initialize_low_arch): Remove
	initialize_low_tdesc call.
	* linux-x86-tdesc-selftest.c: Remove file.
	* linux-x86-tdesc.h (initialize_low_tdesc): Remove.

gdb/testsuite/ChangeLog:

	* gdb.server/unittest.exp: Allow 0 unit tests to run.
2019-07-04 11:55:20 +01:00
Pedro Alves
a26c8de0ee Fix early return in foreach_with_prefix
I noticed that an early return in a foreach_with_prefix block does not
cause the outer scope to return, like:

  foreach_with_prefix var {"foo" "bar"} {
     return
  }
  # Control continues here, but it should not.

The problem is that we're missing the usual "return -code" treatment.
This commit fixes it.

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (foreach_with_prefix): Use "catch" and
	"return -code".
2019-07-03 18:05:20 +01:00
Pedro Alves
5f4ba3e701 pipe command completer
This commit adds a completer for the "pipe" command.  It can complete
"pipe"'s options, and the specified GDB command.

To make the completer aware of the "-d" option, this converts the
option processing to use gdb::option.

Tests included.

gdb/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	PR cli/24732
	* cli/cli-cmds.c (struct pipe_cmd_opts): New.
	(pipe_cmd_option_defs): New.
	(make_pipe_cmd_options_def_group): New.
	(pipe_command): Use gdb::option::process_options.
	(pipe_command_completer): New function.
	(_initialize_cli_cmds): Install completer for "pipe" command.

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	PR cli/24732
	* gdb.base/shell.exp: Load completion-support.exp.
	Adjust expected error output.  Add completion tests.
2019-07-03 17:18:54 +01:00
Pedro Alves
a994424fa1 Fix latent bug in test_gdb_complete_cmd_multiple
A following patch will add the following to a testcase:

  test_gdb_completion_offers_commands "| "

And that tripped on a latent testsuite bug:

 (gdb) | PASS: gdb.base/shell.exp: tab complete "| "
 ^CQuit
 (gdb) complete |
 | !
 | +
 PASS: gdb.base/shell.exp: cmd complete "| "
 |  *** List may be truncated, max-completions reached. ***
 (gdb) FAIL: gdb.base/shell.exp: set max-completions 200
 set max-completions 200

The issue is that "|" ends up as part of a regexp, and "|" in regexps
has a special meaning...

Fix this with string_to_regexp.

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* lib/completion-support.exp (test_gdb_complete_cmd_multiple): Use
	string_to_regexp.
2019-07-03 17:09:16 +01:00
Pedro Alves
3d9be6f531 Teach gdb::option about string options
A following patch will make the "pipe" command use the gdb::option
framework for option processing.  However, "pipe"'s only option today
is a string option, "-d DELIM", and gdb::option does not support
string options yet.

This commit adds support for string options, mapped to var_string.
For now, a string is parsed up until the first whitespace.  I imagine
that we'll need to add support for quoting so that we could do:

 (gdb) cmd -option 'some -string'

without gdb confusing the "-string" for an option.

This doesn't seem important for pipe, so I'm leaving it for another
day.

One thing I'm not happy with, is that the string data is managed as a
raw malloc-allocated char *, which means that we need to xfree it
manually.  This is because var_string settings work that way too.
Although with var_string settings we're leaking the strings at gdb
exit, that was never really a problem.  For options though, leaking is
undesirable.

I think we should tackle that for both settings and options at the
same time, so for now I'm just managing the malloced data manually.
It's a bit ugly in option_def_and_value, but at least that's hidden
from view.

For testing, this adds a new "-string" option to "maint
test-settings", and then tweaks gdb.base/options.exp to exercise it.

gdb/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* cli/cli-option.c (union option_value) <string>: New field.
	(struct option_def_and_value): Add ctor, move ctor, dtor and
	use DISABLE_COPY_AND_ASSIGN.
	(option_def_and_value::clear_value): New.
	(parse_option, save_option_value_in_ctx, get_val_type_str)
	(add_setshow_cmds_for_options): Handle var_string.
	* cli-option.h (union option_def::var_address) <string>: New
	field.
	(struct string_option_def): New.
	* maint-test-options.c (struct test_options_opts): Add default
	ctor and use DISABLE_COPY_AND_ASSIGN.
	<string_opt>: New field.
	(test_options_opts::~test_options_opts): New.
	(test_options_opts::dump): Also dump "-string".
	(test_options_option_defs): Install "string.

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* gdb.base/options.exp (expect_none, expect_flag, expect_bool)
	(expect_integer): Adjust to expect "-string".
	(expect_string): New.
	(all_options): Expect "-string".
	(test-flag, test-boolean): Adjust to expect "-string".
	(test-string): New proc.
	(top level): Call it.
2019-07-03 16:59:24 +01:00
Pedro Alves
41fc454c91 Make gdb::option::complete_options save processed arguments too
Currently, gdb::option::complete_options just discards any processed
option argument, because no completer needs that data.

When completing "pipe -d XXX gdbcmd XXX" however, the completer needs
to know about -d's argument (XXX), in order to know where input is
already past the gdb command and the delimiter.

In this commit, the fix for that is the factoring out of the
save_option_value_in_ctx function and calling it in complete_options.

For testing, this makes "maint show test-options-completion-result"
show the processed options too, like what the "maint test-options"
subcommands output when run.  Then, of course, gdb.base/options.exp is
adjusted.

Doing this exposed a couple latent bugs, which is what the other gdb
changes in the patch are for:

 - in the var_enum case, without the change, we'd end up with a null
   enum argument, and print:

     "-enum (null)"

 - The get_ulongest change is necessary to avoid advancing PP in a
   case where we end up throwing an error, e.g., when parsing "11x".
   Without the change the operand pointer shown by "maint show
   test-options-completion-result" would be left pointing at "x"
   instead of "11x".

gdb/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* cli/cli-option.c (parse_option) <var_enum>: Don't return an
	option_value with a null enumeration.
	(complete_options): Save the option values in the context.
	(save_option_value_in_ctx): New, factored out from ...
	(process_options): ... here.
	* cli/cli-utils.c (get_ulongest): Don't advance PP until the end
	of the function.
	* maint-test-options.c (test_options_opts::dump): New, factored
	out from ...
	(maintenance_test_options_command_mode): ... here.
	(maintenance_test_options_command_completion_result): Delete.
	(maintenance_test_options_command_completion_text): Update
	comment.
	(maintenance_show_test_options_completion_result): Change
	prototype.  Just print
	maintenance_test_options_command_completion_text.
	(save_completion_result): New.
	(maintenance_test_options_completer_mode): Pass options context to
	complete_options, and then save a dump.
	(_initialize_maint_test_options): Use add_cmd to install "maint
	show test-options-completion-result".

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* gdb.base/options.exp (test-misc, test-flag, test-boolean)
	(test-uinteger, test-enum): Adjust res_test_gdb_... calls to pass
	the expected output in the success.
2019-07-03 16:58:30 +01:00
Pedro Alves
b2b2a21598 Fix test_gdb_complete_tab_multiple race
Running 'make check-read1 TESTS="gdb.base/options.exp"' revealed a
race in test_gdb_complete_tab_multiple.  There's a gdb_test_multiple
call that expects a prompt in the middle of the regexp.  That's racy
because gdb_test_multiple includes a built-in FAIL pattern for the
prompt, which may match if gdb is slow enough to produce the rest of
the output after the prompt.

Fix this in the usual way of splitting the matching in two.

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* lib/completion-support.exp (test_gdb_complete_tab_multiple):
	Split one gdb_test_multiple call in two to avoid a race.
2019-07-03 16:57:48 +01:00
Pedro Alves
fdbc98707b Introduce the "with" command
( See original discussion and prototype here:
   https://sourceware.org/ml/gdb-patches/2019-05/msg00570.html )

 (gdb) help with
 Temporarily set SETTING to VALUE, run COMMAND, and restore SETTING.
 Usage: with SETTING [VALUE] [-- COMMAND]
 Usage: w SETTING [VALUE] [-- COMMAND]
 With no COMMAND, repeats the last executed command.
 SETTING is any setting you can change with the "set" subcommands.
 E.g.:
   with language pascal -- print obj
   with print elements unlimited -- print obj

As can be seen above, the "with" command is just like "set", but
instead of setting the setting permanently, it sets the setting, runs
a command and then restores the setting.

 (gdb) p g_s
 $1 = {a = 1, b = 2, c = 3}
 (gdb) with language ada -- print g_s
 $2 = (a => 1, b => 2, c => 3)
 Warning: the current language does not match this frame.
 (gdb) show language
 The current source language is "auto; currently c".
 (gdb) with print elements 100 -- with print object on -- print 1
 $3 = 1

You can shorten things a bit though, as long as unambiguous.  So this:

 (gdb) with print elements 100 -- with print object off -- print 1

is the same as:

 (gdb) w p el 100 -- w p o 0 -- p 1

Note that the patch adds a "w" alias for "with", as "w" is not
currently taken:

 (gdb) w
 Ambiguous command "w": watch, wh, whatis, where, while, while-stepping, winheight, ws.

Let me know if you'd prefer to reserve "w" for one of the other
commands above.  IMHO, this command will end up being used frequently
enough that it deserves the "w" shorthand.

A nice feature is that this is fully integrated with TAB-completion:

 (gdb) with p[TAB]
 pagination  print       prompt      python
 (gdb) with print [TAB]
 address                max-depth              static-members
 array                  max-symbolic-offset    symbol
 array-indexes          null-stop              symbol-filename
 asm-demangle           object                 symbol-loading
 demangle               pascal_static-members  thread-events
 elements               pretty                 type
 entry-values           raw                    union
 frame-arguments        repeats                vtbl
 inferior-events        sevenbit-strings
 (gdb) with print [TAB]

 (gdb) with print elements unlimited -- thread apply all -[TAB]
 -ascending  -c          -q          -s

 (gdb) with print elements unlimited -- print -[TAB]
 -address         -max-depth       -repeats         -vtbl
 -array           -null-stop       -static-members
 -array-indexes   -object          -symbol
 -elements        -pretty          -union

The main advantage of this new command compared to command options,
like the new "print -OPT", is that this command works with any
setting, and, it works nicely when you want to override a setting
while running a user-defined command, like:

 (gdb) with print pretty -- usercmd

The disadvantage is that it isn't as compact or easy to type.  I think
of command options and this command as complementary.  I think that
even with this new command, it makes sense to continue developing the
command options in the direction of exposing most-oft-used settings as
command options.

Inspired by Philippe's "/" command proposal, if no command is
specified, then the last command is re-invoked, under the overridden
setting:

 (gdb) p g_s
 $1 = {a = 1, b = 2, c = 3}
 (gdb) with language ada
 $2 = (a => 1, b => 2, c => 3)
 Warning: the current language does not match this frame.

Note: "with" requires "--" to separate the setting from the command.
It might be possible to do without that, but, I haven't tried it yet,
and I think that this can go in without it.  We can always downgrade
to making "--" optional if we manage to make it work.

On to the patch itself, the implementation of the command is simpler
than one might expect.  A few details:

- I factored out a bit from pipe_command into repeat_previous
  directly, because otherwise I'd need to copy&paste the same code and
  same error message in the with command.

- The parse_cli_var_uinteger / parse_cli_var_zuinteger_unlimited /
  do_set_command changes are necessary since we can now pass an empty
  string as argument.

- do_show_command was split in two, as a FIXME comment suggests, but
  for a different reason: we need to get a string version of a "set"
  command's value, and we already had code for that in
  do_show_command.  That code is now factored out to the new
  get_setshow_command_value_string function.

- There's a new "maint with" command added too:

   (gdb) help maint with
   Like "with", but works with "maintenance set" variables.
   Usage: maintenance with SETTING [VALUE] [-- COMMAND]
   With no COMMAND, repeats the last executed command.
   SETTING is any setting you can change with the "maintenance set"
   subcommands.

  "with" and "maint with" share 99% of the implementation.

  This might be useful on its own, but it's also useful for testing,
  since with this, we can use the "maint set/show test-settings"
  settings for exercising the "with" machinery with all the command
  type variants (all enum var_types).  This is done in the new
  gdb/base/with.exp testcase.

The documentation bits are originally based on Philippe's docs for the
"/" command, hence the attribution in the ChangeLog.

gdb/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* NEWS (New commands): Mention "with" and "maint with".
	* cli/cli-cmds.c (with_command_1, with_command_completer_1)
	(with_command, with_command_completer): New.
	(pipe_command): Adjust to new repeat_previous
	interface.
	(_initialize_cli_cmds): Install the "with" command and its "w"
	alias.
	* cli/cli-cmds.h (with_command_1, with_command_completer_1): New
	declarations.
	* cli/cli-setshow.c (parse_cli_var_uinteger)
	(parse_cli_var_zuinteger_unlimited, do_set_command): Handle empty
	argument strings for all var_types.
	(get_setshow_command_value_string): New, factored out from ...
	(do_show_command): ... this.
	* cli/cli-setshow.h: Include <string>.
	(get_setshow_command_value_string): Declare.
	* command.h (repeat_previous): Now returns const char *.  Adjust
	comment.
	* maint.c: Include "cli/cli-cmds.h".
	(maintenance_with_cmd, maintenance_with_cmd_completer): New.
	(_initialize_maint_cmds): Register the "maintenance with" command.
	* top.c (repeat_previous): Move bits from pipe_command here:
	Return the saved command line, if any; error out if there's no
	command to relaunch.

gdb/doc/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Command Settings): New node documenting the general
	concept of settings, how to change them, and the new "with"
	command.
	(Maintenance Commands): Document "maint with".

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* gdb.base/with.c: New file.
	* gdb.base/with.exp: New file.
2019-07-03 13:35:45 +01:00
Pedro Alves
c6ac893109 "maint test-settings set/show" -> "maint set/show test-settings"
This commit renames "maint test-settings set/show" to "maint set/show
test-settings".

This helps the following patch, which introduce a "maint with" command
what works with all "maint set" settings.

gdb/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* NEWS (New commands): Mention "maint set/show test-settings"
	instead of "maint test-settings".
	* maint-test-settings.c (maintenance_test_settings_list): Delete.
	(maintenance_test_settings_set_list): Rename to ...
	(maintenance_set_test_settings_list): ... this.
	(maintenance_test_settings_show_list): Rename to  ...
	(maintenance_show_test_settings_list): ... this.
	(maintenance_test_settings_cmd): Delete.
	(maintenance_test_settings_set_cmd): ...
	(maintenance_set_test_settings_cmd): ... this.
	(maintenance_test_settings_show_cmd): ...
	(maintenance_show_test_settings_cmd): ... this.
	(maintenance_test_settings_show_value_cmd):
	(maintenance_show_test_settings_value_cmd): ... this.
	(_initialize_maint_test_settings): No longer install the "maint
	test-settings" prefix command.  Rename "maint test-settings set"
	to "maint set test-settings", and "maint test-settings show" to
	"maint show test-settings".  Adjust all subcommands.

gdb/doc/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Maintenance Commands): Document "maint set/show
	test-settings" instead of "maint test-settings set/show".

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* gdb.base/settings.exp: Replace all references to "maint
	test-settings set" with references to "maint set test-settings",
	and all references to "maint test-settings show" with references
	to "maint show test-settings".
2019-07-03 13:35:03 +01:00
Pedro Alves
d1fcf2fded Fix a few comments in maint-test-settings.c
Fix the file's intro comment, and s/test-options/test-settings/.

gdb/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* maint-test-settings.c: Fix file's intro comment.  Replace all
	references to "test-options" with references to "test-settings",
	in comments.
2019-07-03 13:34:50 +01:00
Pedro Alves
970f9d091d Fix defaults of some "maint test-settings" subcommands
New tests added later for the incoming "with" command exposed a couple
invalid-default-value bugs in the "maint test-settings" commands:

- var_filename commands don't allow setting the filename to the empty
  string (unlike var_optional_filename commands), yet, "maint
  test-settings filename"'s control variable was not initialized, so
  on startup, "maint test-settings show filename" shows an empty
  string.

- "maint test-settings enum"'s control variable was not initialized,
  so on startup, "maint test-settings show enum" shows an empty value
  instead of a valid enum value.

Both issues are fixed by initializing the control variables.

gdb/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* maint-test-settings.c (maintenance_test_settings_xxx)
	(maintenance_test_settings_yyy, maintenance_test_settings_zzz):
	New.
	(maintenance_test_settings_enums): Use them.
	(maintenance_test_settings_enum): Default to
	maintenance_test_settings_xxx.
	(_initialize_maint_test_settings): Initialize
	MAINTENANCE_TEST_SETTINGS_FILENAME.

gdb/testsuite/ChangeLog:
2019-07-03  Pedro Alves  <palves@redhat.com>

	* gdb.base/settings.exp (test-string): Adjust expected out when
	testing "maint test-settings show filename"
2019-07-03 13:34:17 +01:00
Simon Marchi
f3869b1a41 Remove return value from remove_breakpoints_inf
... since nobody uses it.

gdb/ChangeLog:

	* breakpoint.h (remove_breakpoints_inf): Change return type to
	void, move function documentation here.
	* breakpoint.c (remove_breakpoints_inf): Change return type to
	void, move function documentation to header.
2019-07-02 22:03:09 -04:00
Pedro Alves
54d6600669 Make "info threads" use the gdb::option framework
This makes "info threads" use the gdb::option framework to process
options.  There's only one option today (-gid), and it isn't used much
frequently unless you're looking at matching MI output.  Still, this
was in the neighborhood of "thread apply" so I had converted it.

The main advantage is that TAB completion now shows you the available
options, and gives you a hint to what the command accepts as operand
argument, including showing a metasyntactic variable:

  (gdb) info threads [TAB]
  -gid  ID

  (gdb) help info threads
  Display currently known threads.
  Usage: info threads [OPTION]... [ID]...

  Options:
    -gid
      Show global thread IDs.

  If ID is given, it is a space-separated list of IDs of threads to display.
  Otherwise, all threads are displayed.
  (gdb)

gdb/ChangeLog:
2019-07-02  Pedro Alves  <palves@redhat.com>

	* NEWS (Completion improvements): Mention "info threads".
	* thread.c (struct info_threads_opts, info_threads_option_defs)
	(make_info_threads_options_def_group): New.
	(info_threads_command): Use gdb::option::process_options.
	(info_threads_command_completer): New.
	(_initialize_thread): Use gdb::option::build_help to build the
	help text for "info threads".

gdb/testsuite/ChangeLog:
2019-07-02  Pedro Alves  <palves@redhat.com>

	* gdb.base/options.exp (test-info-threads): New procedure.
	(top level): Call it.
2019-07-02 16:34:31 +01:00
Simon Marchi
854f60884c Move generic_load declaration to symfile.h
... since the implementation is in symfile.c.

At the same time, add some documentation and make sure the first
parameter's name in the declaration matches the definition.

gdb/ChangeLog:

	* defs.h (generic_load): Move from here...
	* symfile.h (generic_load): ... to here.  Rename name parameter
	to args.
	* symfile.c (generic_load): Add comment.
2019-07-02 10:31:00 -04:00
Tom Tromey
54ee425275 Avoid use-after-free in DWARF debug names code
A static analyzer pointed out that find_vec_in_debug_names will use
the contents of a unique_ptr after it has been destroyed.  This patch
fixes the bug by hoisting the declaration into the appropriate
enclosing block.

I'm checking this in as obvious.

gdb/ChangeLog
2019-07-01  Tom Tromey  <tromey@adacore.com>

	* dwarf2read.c
	(dw2_debug_names_iterator::find_vec_in_debug_names): Hoist
	declaration of without_params.  Fix formatting.
2019-07-01 09:36:30 -06:00
Tom Tromey
65392b3edd Remove is_a_field_of_this from ada_lookup_symbol
All callers of ada_lookup_symbol pass NULL for the
"is_a_field_of_this" parameter, so remove it.

gdb/ChangeLog
2019-07-01  Tom Tromey  <tromey@adacore.com>

	* ada-exp.y (find_primitive_type): Update.
	* ada-lang.h (ada_lookup_symbol): Update.
	* ada-lang.c (ada_lookup_symbol): Remove "is_a_field_of_this"
	parameter.
	(ada_lookup_encoded_symbol, ada_lookup_symbol_nonlocal): Update.
2019-07-01 06:29:04 -06:00
Sergio Durigan Junior
7d7571f0c1 Adjust i386 registers on SystemTap probes' arguments (PR breakpoints/24541)
This bug has been reported on PR breakpoints/24541, but it is possible
to reproduce it easily by running:

  make check-gdb TESTS=gdb.base/stap-probe.exp RUNTESTFLAGS='--target_board unix/-m32'

The underlying cause is kind of complex, and involves decisions made
by GCC and the sys/sdt.h header file about how to represent a probe
argument that lives in a register in 32-bit programs.  I'll use
Andrew's example on the bug to illustrate the problem.

libstdc++ has a probe named "throw" with two arguments.  On i386, the
probe is:

  stapsdt              0x00000028       NT_STAPSDT (SystemTap probe descriptors)
    Provider: libstdcxx
    Name: throw
    Location: 0x00072c96, Base: 0x00133d64, Semaphore: 0x00000000
    Arguments: 4@%si 4@%di

I.e., the first argument is an unsigned 32-bit value (represented by
the "4@") that lives on %si, and the second argument is an unsigned
32-bit value that lives on %di.  Note the discrepancy between the
argument size reported by the probe (32-bit) and the register size
being used to store the value (16-bit).

However, if you take a look at the disassemble of a program that uses
this probe, you will see:

    00072c80 <__cxa_throw@@CXXABI_1.3>:
       72c80:       57                      push   %edi
       72c81:       56                      push   %esi
       72c82:       53                      push   %ebx
       72c83:       8b 74 24 10             mov    0x10(%esp),%esi
       72c87:       e8 74 bf ff ff          call   6ec00 <__cxa_finalize@plt+0x980>
       72c8c:       81 c3 74 e3 10 00       add    $0x10e374,%ebx
       72c92:       8b 7c 24 14             mov    0x14(%esp),%edi
       72c96:       90                      nop                      <----------------- PROBE IS HERE
       72c97:       e8 d4 a2 ff ff          call   6cf70 <__cxa_get_globals@plt>
       72c9c:       83 40 04 01             addl   $0x1,0x4(%eax)
       72ca0:       83 ec 04                sub    $0x4,%esp
       72ca3:       ff 74 24 1c             pushl  0x1c(%esp)
       72ca7:       57                      push   %edi
       72ca8:       56                      push   %esi
       72ca9:       e8 62 a3 ff ff          call   6d010 <__cxa_init_primary_exception@plt>
       72cae:       8d 70 40                lea    0x40(%eax),%esi
       72cb1:       c7 00 01 00 00 00       movl   $0x1,(%eax)
       72cb7:       89 34 24                mov    %esi,(%esp)
       72cba:       e8 61 96 ff ff          call   6c320 <_Unwind_RaiseException@plt>
       72cbf:       89 34 24                mov    %esi,(%esp)
       72cc2:       e8 c9 84 ff ff          call   6b190 <__cxa_begin_catch@plt>
       72cc7:       e8 d4 b3 ff ff          call   6e0a0 <_ZSt9terminatev@plt>
       72ccc:       66 90                   xchg   %ax,%ax
       72cce:       66 90                   xchg   %ax,%ax

Note how the program is actually using %edi, and not %di, to store the
second argument.  This is the problem here.

GDB will basically read the probe argument, then read the contents of
%di, and then cast this value to uint32_t, which causes the wrong
value to be obtained.  In the gdb.base/stap-probe.exp case, this makes
GDB read the wrong memory location, and not be able to display a test
string.  In Andrew's example, this causes GDB to actually stop at a
"catch throw" when it should actually have *not* stopped.

After some discussion with Frank Eigler and Jakub Jelinek, it was
decided that this bug should be fixed on the client side (i.e., the
program that actually reads the probes), and this is why I'm proposing
this patch.

The idea is simple: we will have a gdbarch method, which, for now, is
only used by i386.  The generic code that deals with register operands
on gdb/stap-probe.c will call this method if it exists, passing the
current parse information, the register name and its number.

The i386 method will then verify if the register size is greater or
equal than the size reported by the stap probe (the "4@" part).  If it
is, we're fine.  Otherwise, it will check if we're dealing with any of
the "extendable" registers (like ax, bx, si, di, sp, etc.).  If we
are, it will change the register name to include the "e" prefix.

I have tested the patch here in many scenarios, and it fixes Andrew's
bug and also the regressions I mentioned before, on
gdb.base/stap-probe.exp.  No regressions where found on other tests.

Comments?

gdb/ChangeLog:
2019-06-27  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR breakpoints/24541
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbarch.sh: Add 'stap_adjust_register'.
	* i386-tdep.c: Include '<unordered_set>'.
	(i386_stap_adjust_register): New function.
	(i386_elf_init_abi): Register 'i386_stap_adjust_register'.
	* stap-probe.c (stap_parse_register_operand): Call
	'gdbarch_stap_adjust_register'.
2019-06-28 16:28:21 -04:00
Sergio Durigan Junior
5af5392a3d Fix crash when using PYTHONMALLOC=debug (PR python/24742)
This bug was originally reported against Fedora GDB:

  https://bugzilla.redhat.com/show_bug.cgi?id=1723564

The problem is that GDB will crash in the following scenario:

- PYTHONMALLOC=debug or PYTHONDEVMODE=1 is set.

- The Python debuginfo is installed.

- GDB is used to debug Python.

The crash looks like this:

  $ PYTHONMALLOC=debug gdb -args python3 -c pass
  GNU gdb (GDB) Fedora 8.3-3.fc30
  Reading symbols from python3...
  Reading symbols from /usr/lib/debug/usr/bin/python3.7m-3.7.3-3.fc30.x86_64.debug...
  (gdb) run
  Starting program: /usr/bin/python3 -c pass
  Missing separate debuginfos, use: dnf debuginfo-install glibc-2.29-9.fc30.x86_64
  Debug memory block at address p=0x5603977bf330: API ''
      8098648152243306496 bytes originally requested
      The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfb):
	  at p-7: 0x03 *** OUCH
	  at p-6: 0x00 *** OUCH
	  at p-5: 0x00 *** OUCH
	  at p-4: 0x00 *** OUCH
	  at p-3: 0x00 *** OUCH
	  at p-2: 0x00 *** OUCH
	  at p-1: 0x00 *** OUCH
      Because memory is corrupted at the start, the count of bytes requested
	 may be bogus, and checking the trailing pad bytes may segfault.
      The 8 pad bytes at tail=0x706483999ad1f330 are Segmentation fault (core dumped)

It's hard to determine what happens, but after doing some
investigation and talking to Victor Stinner I found that GDB should
not use the Python memory allocation functions before the Python
interpreter is initialized (which makes sense).  However, we do just
that on python/python.c:do_start_initialization:

  ...
  progsize = strlen (progname.get ());
  progname_copy = (wchar_t *) PyMem_Malloc ((progsize + 1) * sizeof (wchar_t));
  ...
  /* Note that Py_SetProgramName expects the string it is passed to
     remain alive for the duration of the program's execution, so
     it is not freed after this call.  */
  Py_SetProgramName (progname_copy);
  ...
  Py_Initialize ();
  PyEval_InitThreads ();

Upon reading the Python 3 C API documentation, I
found (https://docs.python.org/3.5/c-api/memory.html):

  To avoid memory corruption, extension writers should never try to
  operate on Python objects with the functions exported by the C
  library: malloc(), calloc(), realloc() and free(). This will result in
  mixed calls between the C allocator and the Python memory manager with
  fatal consequences, because they implement different algorithms and
  operate on different heaps. However, one may safely allocate and
  release memory blocks with the C library allocator for individual
  purposes[...]

And Py_SetProgramName seems like a very simple call that doesn't need
a Python-allocated memory to work on.  So I'm proposing this patch,
which simply replaces PyMem_Malloc by xmalloc.

Testing this is more complicated.  First, the crash is completely
non-deterministic; I was able to reproduce it 10 times in a row, and
then I wasn't able to reproduce it anymore.  I found that if you
completely remove your build directory and rebuild GDB from scratch,
you can reproduce it again confidently.  And with my patch, I
confirmed that the bug doesn't manifest even in this situation.

No regressions found.

OK to apply?

gdb/ChangeLog:
2019-06-28  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR python/24742
	https://bugzilla.redhat.com/show_bug.cgi?id=1723564
	* python/python.c (do_start_initialization): Use 'xmalloc'
	instead of 'PyMem_Malloc'.
2019-06-28 16:28:07 -04:00
Tom Tromey
10d06d8219 Handle either order of name and linkage name
We discovered that the Ada support in gdb depends on the order of the
DW_AT_name and DW_AT_linkage_name attributes in the DWARF.  In
particular, if they are emitted in the "wrong" order for some system
symbols, "catch exception" will not work.

This patch fixes this problem by arranging to always prefer the
linkage name if both exist.  This seems to be what the full symbol
reader already does -- that is, this is another bug arising from
having two different DWARF readers.

Another possible issue here is that gdb still doesn't really preserve
mangled names properly.  There's a PR open about this.  However, this
seems to be somewhat involved to fix, which is why this patch
continues to work around the bigger issue.

gdb/ChangeLog
2019-06-28  Tom Tromey  <tromey@adacore.com>

	* dwarf2read.c (partial_die_info::read): Prefer the linkage name
	for Ada.

gdb/testsuite/ChangeLog
2019-06-28  Tom Tromey  <tromey@adacore.com>

	* gdb.dwarf2/ada-linkage-name.c: New file.
	* gdb.dwarf2/ada-linkage-name.exp: New file.
2019-06-28 08:37:38 -06:00
Tom Tromey
1b7f24cd6b Change arm_objfile_data_key to use type-safe registry
After seeing Simon's patch to change arm_per_objfile to use new and
delete, I realized it is now simple to change arm_objfile_data_key to
use the type-safe registry.

gdb/ChangeLog
2019-06-27  Tom Tromey  <tromey@adacore.com>

	* arm-tdep.c (arm_objfile_data_key): Move lower.  Change type to
	objfile_key.
	(arm_find_mapping_symbol, arm_record_special_symbol)
	(_initialize_arm_tdep): Update.
	(arm_objfile_data_free): Remove.
2019-06-27 08:01:18 -06:00