Commit Graph

41198 Commits

Author SHA1 Message Date
Tom Tromey 716b8bc52e Change the as_*_interp functions to use dynamic_cast
This changes the various as_*_interp functions to be implemented using
dynamic_cast.  I believe this is a small improvement, because it is
more typesafe -- the C++ runtime does the type-checking for us.

ChangeLog
2018-05-25  Tom Tromey  <tom@tromey.com>

	* tui/tui-interp.c (as_tui_interp): Use dynamic_cast.
	* mi/mi-interp.c (as_mi_interp): Use dynamic_cast.
	* cli/cli-interp.c (as_cli_interp): Use dynamic_cast.
2018-05-25 12:41:00 -06:00
Tom Tromey 753ff9bd83 Use scoped_restore in a couple of interp-related places
While looking through the "interp" code I found a couple of spots that
could use scoped_restore.

ChangeLog
2018-05-25  Tom Tromey  <tom@tromey.com>

	* cli/cli-interp.c (safe_execute_command): Use scoped_restore.
	* interps.c (interp_exec): Use scoped_restore.
2018-05-25 12:41:00 -06:00
Tom Tromey 5ca3b2605c Use gdb::byte_vector in remote.c
This changes a couple of spots in remote.c to use gdb::byte_vector,
allowing for some cleanup removal.

ChangeLog
2018-05-25  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_target::remote_file_get): Use
	gdb::byte_vector.
	(remote_target::remote_file_put): Likewise.
2018-05-25 10:49:22 -06:00
Tom Tromey 3173aa2fc2 Remove cleanups from coff-pe-read.c
This removes cleanups from coff-pe-read.c, using std::string,
std::vector, and gdb::def_vector.

Tested by the buildbot, though I'm not sure these code paths are
exercised there.

ChangeLog
2018-05-25  Tom Tromey  <tom@tromey.com>

	* coff-pe-read.c (struct read_pe_section_data) <section_name>: Now
	a std::string.
	(get_pe_section_index, add_pe_exported_sym): Update.
	(read_pe_exported_syms): Use gdb::def_vector.
2018-05-25 09:08:14 -06:00
Tom Tromey 09a5e1b570 Use TRY/CATCH in remove_prev_frame
This changes remove_prev_frame to use TRY/CATCH instead of a cleanup.
TRY/CATCH seemed appropriate here because the cleanup is only needed
in the case where an exception is thrown.

Tested by the buildbot.

ChangeLog
2018-05-25  Tom Tromey  <tom@tromey.com>

	* frame.c (remove_prev_frame): Remove.
	(get_prev_frame_if_no_cycle): Use TRY/CATCH.
2018-05-25 08:58:36 -06:00
Maciej W. Rozycki d8dab6c3bb MIPS/Linux: Correct o32 core file FGR interpretation
Our interpretation of the layout of floating-point general registers
(FGRs) in o32 MIPS/Linux core files is different from how the kernel
makes them, affecting the CP0 Status.FR=0 aka FP32 mode (we don't
currently support the CP0 Status.FR=1 aka FP64 mode with the o32 ABI).

In the FP32 mode pairs of consecutive even/odd-numbered 32-bit registers
are placed together as 64-bit values in even-indexed 64-bit slots
corresponding to the even index, leaving the odd-indexed 64-bit slots
unused.  These 64-bit values are stored according to the endianness in
effect, which is how the MIPS II SDC1 instruction would store them.

It has always been like that with the Linux kernel for MIPS II and
higher ISA processors, which are the vast majority ever supported, as it
is indeed SDC1 that the kernel uses to store FGRs in a floating-point
context.

With MIPS I processors, which lack the SDC1 instruction, a layout that
we expect used to be used long ago, but it was corrected for consistency
with newer processors back in 2002, with `linux-mips.org' (LMO) commit
42533948caac ("Major pile of FP emulator changes."), the fix corrected
with LMO commit 849fa7a50dff ("R3k FPU ptrace() handling fixes."), and
then broken and fixed over and over again, until last time fixed with
commit 80cbfad79096 ("MIPS: Correct MIPS I FP context layout").

Consequently the values we see in FP32 core files or produce with the
`gcore' command are different from those obtained from the same FP
context of a live process, e.g. with a big-endian configuration these
live values:

(gdb) info registers float
f0:  0x4b5c6d7e flt: 14445950          dbl: 1.7446153562345001e-274
f1:  0x0718293a flt: 1.14473244e-34
f2:  0xc3d4e5f6 flt: -425.79657        dbl: -1.046160437414959e-233
f3:  0x8f90a1b2 flt: -1.42617791e-29
f4:  0x4c5d6e7f flt: 58046972          dbl: 1.1908587841220294e-269
f5:  0x08192a3b flt: 4.60914044e-34
f6:  0xc4d5e6f7 flt: -1711.21765       dbl: -6.2784661835068965e-306
f7:  0x8091a2b3 flt: -1.33745124e-38
f8:  0x45566778 flt: 3430.4668         dbl: 1.6530355595710607e-303
f9:  0x01122334 flt: 2.68412219e-38
f10: 0xcddeeff0 flt: -467533312        dbl: -2.1174864564135575e-262
f11: 0x899aabbc flt: -3.72356497e-33
f12: 0x46576879 flt: 13786.1182        dbl: 1.143296486773654e-298
f13: 0x02132435 flt: 1.08102453e-37
f14: 0xcedfe0f1 flt: -1.87803046e+09   dbl: -1.4399511533369862e-257
f15: 0x8a9bacbd flt: -1.4990934e-32
f16: 0x4758697a flt: 55401.4766        dbl: 7.8856820439568725e-294
f17: 0x03142536 flt: 4.3536007e-37
f18: 0xcfd0e1f2 flt: -7.00893696e+09   dbl: -9.7791926757340559e-253
f19: 0x8b9cadbe flt: -6.03504325e-32
f20: 0x48596a7b flt: 222633.922        dbl: 5.4255001483306113e-289
f21: 0x04152637 flt: 1.75324132e-36
f22: 0xc0d1e2f3 flt: -6.55895376       dbl: -6.6332401002310683e-248
f23: 0x8c9daebf flt: -2.42948516e-31
f24: 0x495a6b7c flt: 894647.75         dbl: 3.7244369058749787e-284
f25: 0x05162738 flt: 7.06016945e-36
f26: 0xc1d2e3f4 flt: -26.3613052       dbl: -4.4941535759306202e-243
f27: 0x8d9eafb0 flt: -9.77979703e-31
f28: 0x4a5b6c7d flt: 3595039.25        dbl: 2.5514593711161396e-279
f29: 0x06172839 flt: 2.84294945e-35
f30: 0xc2d3e4f5 flt: -105.947182       dbl: -3.035646690850097e-238
f31: 0x8e9fa0b1 flt: -3.93512664e-30
fcsr: 0x0
fir: 0xf30000
(gdb)

show up in a core file as these:

(gdb) info registers float
f0:  0x0718293a flt: 1.14473244e-34    dbl: nan
f1:  0x7ff80000 flt: nan
f2:  0x8f90a1b2 flt: -1.42617791e-29   dbl: nan
f3:  0x7ff80000 flt: nan
f4:  0x08192a3b flt: 4.60914044e-34    dbl: nan
f5:  0x7ff80000 flt: nan
f6:  0x8091a2b3 flt: -1.33745124e-38   dbl: nan
f7:  0x7ff80000 flt: nan
f8:  0x01122334 flt: 2.68412219e-38    dbl: nan
f9:  0x7ff80000 flt: nan
f10: 0x899aabbc flt: -3.72356497e-33   dbl: nan
f11: 0x7ff80000 flt: nan
f12: 0x02132435 flt: 1.08102453e-37    dbl: nan
f13: 0x7ff80000 flt: nan
f14: 0x8a9bacbd flt: -1.4990934e-32    dbl: nan
f15: 0x7ff80000 flt: nan
f16: 0x03142536 flt: 4.3536007e-37     dbl: nan
f17: 0x7ff80000 flt: nan
f18: 0x8b9cadbe flt: -6.03504325e-32   dbl: nan
f19: 0x7ff80000 flt: nan
f20: 0x04152637 flt: 1.75324132e-36    dbl: nan
f21: 0x7ff80000 flt: nan
f22: 0x8c9daebf flt: -2.42948516e-31   dbl: nan
f23: 0x7ff80000 flt: nan
f24: 0x05162738 flt: 7.06016945e-36    dbl: nan
f25: 0x7ff80000 flt: nan
f26: 0x8d9eafb0 flt: -9.77979703e-31   dbl: nan
f27: 0x7ff80000 flt: nan
f28: 0x06172839 flt: 2.84294945e-35    dbl: nan
f29: 0x7ff80000 flt: nan
f30: 0x8e9fa0b1 flt: -3.93512664e-30   dbl: nan
f31: 0x7ff80000 flt: nan
(gdb)

Notice how values from odd-numbered registers are shown in corresponding
even-numbered registers and how dummy 0x7ff80000 NaN values, which the
kernel places in unused slots, are reported in odd-numbered registers.

Correct our intepretation then, to match the kernel's.  As it happens
the o32 FGR core file representation matches that used by the `ptrace'
PTRACE_GETFPREGS request, which means our 64-bit handlers can be readily
used, as they already correctly handle the differences between o32 FP32
mode vs n32/n64 representations.

Adjust comments accordingly throughout, in particular remove a reference
to the r3000/tx39 MIPS I processor peculiarity, long irrelevant.

Add a test case to verify correctness.  Avoid GCC bugs and limitations
in the test case where possible; the test case still fails to build with
GCC 8 and the o32 FP64 mode (i.e. with `-mips32r2 -mfp64' options)
giving:

mips-fpregset-core.c: In function 'main':
mips-fpregset-core.c:66:3: error: inconsistent operand constraints in an 'asm'
   asm (
   ^~~

(GCC PR target/85909), but that is not a concern for us as yet, because
as noted above we do not currently support the o32 FP64 mode anyway.

	gdb/
	* mips-linux-tdep.h (mips_supply_fpregset, mips_fill_fpregset):
	Remove prototypes.
	* mips-linux-nat.c (supply_fpregset): Always call
	`mips64_supply_fpregset' rather than `mips_supply_fpregset'.
	(fill_fpregset): Always call `mips64_fill_fpregset' rather than
	`mips_fill_fpregset'.
	* mips-linux-tdep.c (mips_supply_fpregset)
	(mips_supply_fpregset_wrapper, mips_fill_fpregset)
	(mips_fill_fpregset_wrapper): Remove functions.
	(mips64_supply_fpregset, mips64_fill_fpregset): Update comments.
	(mips_linux_fpregset): Remove variable.
	(mips_linux_iterate_over_regset_sections): Use
	`mips64_linux_fpregset' in place of `mips_linux_fpregset'.
	(mips_linux_o32_sigframe_init): Remove comment.

	gdb/testsuite/
	* gdb.arch/mips-fpregset-core.exp: New test.
	* gdb.arch/mips-fpregset-core.c: New test source.
2018-05-25 12:37:45 +01:00
Pedro Alves 3c69da406c remote_target::m_remote_state, pointer -> object
The only reason remote_target::m_remote_state is a pointer is that
struct remote_state is incomplete when struct remote_target is
defined.

This commit thus moves struct remote_state (and its dependencies)
higher up and makes remote_target::m_remote_state an object instead of
a pointer.

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

	* remote.c (struct vCont_action_support, MAXTHREADLISTRESULTS)
	(struct readahead_cache, struct packet_reg, struct
	remote_arch_state, class remote_state): Move higher up in the
	file.
	(remote_target::m_remote_state): Now an object instead of a pointer.
	(remote_target::get_remote_state): Adjust.
2018-05-25 11:58:58 +01:00
Andrew Burgess 39f0c2040f gdb: Split func_command into two parts.
The func_command function is used to emulate the dbx 'func' command.
However, finding a stack frame based on function name might be a useful
feature, and so the core of func_command is now split out into a
separate function.

gdb/ChangeLog:

	* stack.c (select_and_print_frame): Delete.
	(struct function_bounds): Move struct within function.
	(func_command): Most content moved into new function
	find_frame_for_function, use new function, print result, add
	function comment.
	(find_frame_for_function): New function, now returns a result.
2018-05-24 22:39:03 +01:00
Philippe Waroquiers d392224a09 PATCH (obvious): Fix a comment, and pass stream to cb_data.
iterate_over_block_arg_vars is a void function, so does
not return 1 or 0.
print_frame_arg_vars tells it prints on STREAM,
so pass STREAM in the cb_data, not gdb_stdout.

gdb/ChangeLog

2018-05-24  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* stack.c (iterate_over_block_arg_vars): Fix comment.
	(print_frame_arg_vars): Pass stream in cb_data, not gdb_stdout.
2018-05-24 23:19:05 +02:00
Tom Tromey a974b5ec9a Update help text in record.c
This updates some help text in record.c to conform to GNU standards.
I also added a "Usage" line to "record save".

2018-04-29  Tom Tromey  <tom@tromey.com>

	* record.c (_initialize_record): Update help text.
2018-05-24 12:29:23 -06:00
Tom Tromey c8a15b78e6 Update help text in linux-fork.c
This updates some help text in linux-fork.c to conform to GNU
standards.

2018-04-29  Tom Tromey  <tom@tromey.com>

	* linux-fork.c (_initialize_linux_fork): Update help text.
2018-05-24 12:29:23 -06:00
Tom Tromey 55063ddb8e Update help text in record-btrace.c
This updates the help text in record-btrace.c to conform to GNU
standards.

2018-04-29  Tom Tromey  <tom@tromey.com>

	* record-btrace.c (_initialize_record_btrace): Update help text.
2018-05-24 12:29:22 -06:00
Tom Tromey 02d016b71f Update help text in tracepoint.c
This changes the help text of a couple of commands in tracepoint.c to
follow the GNU style.

ChangeLog
2018-04-29  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (_initialize_tracepoint): Update help text.

testsuite/ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* gdb.trace/tfind.exp: Update help tests.
2018-05-24 12:29:22 -06:00
Tom Tromey 7c9ee61b9f Update help text in disasm.c
This changes some help text in disasm.c to follow the GNU style.

2018-04-29  Tom Tromey  <tom@tromey.com>

	* disasm.c (_initialize_disasm): Update help text.
2018-05-24 12:29:22 -06:00
Tom Tromey 0a8ba311d0 Update help text for "jump" command
This updates the usage text for the "jump" command to conform to the
GNU style.

2018-04-29  Tom Tromey  <tom@tromey.com>

	* infcmd.c (_initialize_infcmd): Update help text.
2018-05-24 12:29:21 -06:00
Tom Tromey ffb2b66cab Update help text in dcache.c
This updates some text in dcache.c to follow GNU standards.
Here, I found a couple of spots needing an update.

2018-04-29  Tom Tromey  <tom@tromey.com>

	* dcache.c (dcache_info_1): Update usage text.
	(_initialize_dcache): Update help text.
2018-05-24 12:29:21 -06:00
Tom Tromey bf212be198 Update help strings in TUI
This updates some help strings in the TUI to more closely follow GNU
standards.  In this case I chose to reuse some existing "usage" macros
in the help text.  Also, I found that XDBWIN_HEIGHT_USAGE is unused,
so I removed it.

ChangeLog
2018-04-29  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (_initialize_tui_layout): Update help text.
	* tui/tui-win.c (WIN_HEIGHT_USAGE, FOCUS_USAGE): Update
	(XDBWIN_HEIGHT_USAGE): Remove.
	(_initialize_tui_win): Use macros.  Update help text.
2018-05-24 12:29:21 -06:00
Tom Tromey 99806209a4 Update memattr.c help strings
This changes memattr.c to use the GNU style for help strings.

2018-04-29  Tom Tromey  <tom@tromey.com>

	* memattr.c (_initialize_mem): Update help string.
2018-05-24 12:29:20 -06:00
Tom Tromey 0cab2f1e91 Update core-related help strings
This updates some help strings in corefile.c and gcore.c.

2018-04-27  Tom Tromey  <tom@tromey.com>

	* corefile.c (_initialize_core): Update help string.
	* gcore.c (_initialize_gcore): Update help string.
2018-05-24 12:29:20 -06:00
Tom Tromey 784e4b3e80 Update help strings in skip.c
This changes help strings in skip.c to follow the GNU style.

2018-04-27  Tom Tromey  <tom@tromey.com>

	* skip.c (_initialize_step_skip): Update help strings.
2018-05-24 12:29:20 -06:00
Tom Tromey a3c25011e4 Fix help and documentation for inferior commands
This changes inferior.c to add Usage lines for all commands, and to
change how "metasyntactic variables" are written to conform to GNU
style.

While doing this I noticed that the manual doesn't document the
argument to "info inferiors", so I've added that as well.

ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* inferior.c (initialize_inferiors): Update help strings.

doc/ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Inferiors and Programs): Document argument to "info
	inferiors".
2018-05-24 12:29:19 -06:00
Andrew Burgess 45f25d6c83 gdb: Restore selected frame in print_frame_local_vars
PR gdb/23203 reports 'bt full' causing the currently selected frame to
change, this issue is fixed in this commit.

Add a new class scoped_restore_selected_frame that saves and restores
the selected frame.  Make use of this in print_frame_local_vars to
restore the selected frame on exit.

gdb/ChangeLog:

	PR gdb/23203
	* frame.c
	(scoped_restore_selected_frame::scoped_restore_selected_frame):
	Define.
	(scoped_restore_selected_frame::~scoped_restore_selected_frame):
	Define.
	* frame.h (class scoped_restore_selected_frame): New class.
	* stack.c (print_frame_local_vars): Remove catching and rethrowing
	of any exception, use scoped_restore_selected_frame to restore the
	frame instead.

gdb/testsuite/ChangeLog:

	PR gdb/23203
	* gdb.base/bt-selected-frame.c: New file.
	* gdb.base/bt-selected-frame.exp: New file.
	* lib/gdb.exp (get_current_frame_number): New function.
2018-05-24 18:01:31 +01:00
Maciej W. Rozycki d9f6d7f8b6 testsuite: Extend TLS core file testing with an OS-generated dump
Complementing commit 280ca31f4d ("Add test for fetching TLS from
core file") extend gdb.threads/tls-core.exp with an OS-generated dump
where supported.

This verifies not only that our core dump interpreter is consistent
with our producer, but that it matches the OS verified as well,
avoiding a possible case where our interpreter would be bug-compatible
with our producer but not the OS and it would go unnoticed in testing.

This results in:

 PASS: gdb.threads/tls-core.exp: native: load core file
 PASS: gdb.threads/tls-core.exp: native: print thread-local storage variable
 PASS: gdb.threads/tls-core.exp: gcore: load core file
 PASS: gdb.threads/tls-core.exp: gcore: print thread-local storage variable

with local testing and:

 UNSUPPORTED: gdb.threads/tls-core.exp: native: load core file
 UNSUPPORTED: gdb.threads/tls-core.exp: native: print thread-local storage variable
 PASS: gdb.threads/tls-core.exp: gcore: load core file
 PASS: gdb.threads/tls-core.exp: gcore: print thread-local storage variable

with remote testing, or for testing on ports that don't supports
cores.

gdb/testsuite/ChangeLog:
2018-05-24  Maciej W. Rozycki  <macro@mips.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.threads/tls-core.c: Include <stdlib.h>
	(thread_proc): Call `abort'.
	* gdb.threads/tls-core.exp: Generate a core with core_find too.
	(tls_core_test): New procedure, bits factored out from ...
	(top level): ... here.  Test both native cores and gcore cores.
2018-05-24 15:31:32 +01:00
Pedro Alves da05d921f0 Fix macOS build, missing override
Fixes:

In file included from ../../src/gdb/darwin-nat.c:63:0:
../../src/gdb/darwin-nat.h:28:8: error: 'virtual void darwin_nat_target::create_inferior(const char*, const string&, char**, int)' can be marked override [-Werror=suggest-override]
   void create_inferior (const char *exec_file,
        ^

gdb/ChangeLog:
2018-05-24  Pedro Alves  <palves@redhat.com>

	* darwin-nat.h (darwin_nat_target::create_inferior): Mark with
	override.
2018-05-24 13:21:55 +01:00
Tom Tromey a8be540e8a Remove struct complaints
struct complaints now just holds a single enum value, so remove it and
symfile_complaint_book and replace it with a global variable.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (struct complaints): Remove.
	(symfile_complaint_book): Remove.
	(series): New global.
	(complaint_internal): Update.
	(clear_complaints): Update.
2018-05-23 09:17:03 -06:00
Tom Tromey ff1cf532db Remove struct complain
At this point, struct complain is just holds a key, a value, and a
"next" pointer to form a linked list.  It's simpler to replace this
with an unordered map.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (counters): New global.
	(struct complain): Remove.
	(struct complaints) <root>: Remove.
	(complaint_sentinel): Remove.
	(symfile_complaint_book): Update.
	(find_complaint) Remove.
	(complaint_internal, clear_complaints): Update.

gdb/testsuite/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/complaints.exp (test_initial_complaints): Simplify.
2018-05-23 09:17:03 -06:00
Tom Tromey 7ff8817441 Remove file and line from struct complain
The file and line handling in complaints.c wasn't used once
internal_complaint was removed.  This patch removes all the related
code.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (struct complain) <file, line>: Remove.
	(find_complaint): Remove file, line parameters.
	(complaint_internal): Update.
2018-05-23 09:17:02 -06:00
Tom Tromey de54e1a5d2 Remove vcomplaint
vcomplaint now has a single caller, so merge it with that caller.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (vcomplaint): Remove.
	(complaint_internal) Merge in contents of vcomplaint.
2018-05-23 09:17:02 -06:00
Tom Tromey 2ac237e52b Remove struct explanation
Now that there's only a single reason for a complaint to be emitted,
this removes "struct explanation" and changes vcomplaint to emit the
desired messages directly.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (struct complaints) <explanation>: Remove.
	(symfile_explanations): Remove.
	(symfile_complaint_book): Update.
	(vcomplaint): Update.
	(struct explanation): Remove.
2018-05-23 09:17:01 -06:00
Tom Tromey b98664d386 Remove symfile_complaints
The complaint system seems to allow for multiple different complaint
topics.  However, in practice only symfile_complaints has ever been
defined.  Seeing that complaints.c dates to 1992, and that no new
complaints have been added in the intervening years, I think it is
reasonable to admit that complaints are specifically related to
debuginfo reading.

This patch removes symfile_complaints and updates all the callers.
Some of these spots should perhaps be calls to warning instead, but I
did not make that change.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (symfile_complaints): Remove.
	(complaint_internal): Remove "complaints" parameter.
	(clear_complaints, vcomplaint): Remove "c" parameter.
	(get_complaints): Remove.
	* dwarf2read.c (dwarf2_statement_list_fits_in_line_number_section_complaint)
	(dwarf2_debug_line_missing_file_complaint)
	(dwarf2_debug_line_missing_end_sequence_complaint)
	(dwarf2_complex_location_expr_complaint)
	(dwarf2_const_value_length_mismatch_complaint)
	(dwarf2_section_buffer_overflow_complaint)
	(dwarf2_macro_malformed_definition_complaint)
	(dwarf2_invalid_attrib_class_complaint)
	(create_addrmap_from_index, dw2_symtab_iter_next)
	(dw2_expand_marked_cus)
	(dw2_debug_names_iterator::find_vec_in_debug_names)
	(dw2_debug_names_iterator::next, dw2_debug_names_iterator::next)
	(create_debug_type_hash_table, init_cutu_and_read_dies)
	(partial_die_parent_scope, add_partial_enumeration)
	(skip_one_die, fixup_go_packaging, quirk_rust_enum, process_die)
	(dwarf2_compute_name, dwarf2_physname, read_namespace_alias)
	(read_import_statement, read_file_scope, create_dwo_cu_reader)
	(create_cus_hash_table, create_dwp_hash_table)
	(inherit_abstract_dies, read_func_scope, read_call_site_scope)
	(dwarf2_rnglists_process, dwarf2_ranges_process)
	(dwarf2_add_type_defn, dwarf2_attach_fields_to_type)
	(dwarf2_add_member_fn, get_alignment, maybe_set_alignment)
	(handle_struct_member_die, process_structure_scope)
	(read_array_type, read_common_block, read_module_type)
	(read_tag_pointer_type, read_typedef, read_base_type)
	(read_subrange_type, load_partial_dies, partial_die_info::read)
	(partial_die_info::read, partial_die_info::read)
	(partial_die_info::read, read_checked_initial_length_and_offset)
	(dwarf2_string_attr, read_formatted_entries)
	(dwarf_decode_line_header)
	(lnp_state_machine::check_line_address, dwarf_decode_lines_1)
	(new_symbol, dwarf2_const_value_attr, lookup_die_type)
	(read_type_die_1, determine_prefix, dwarf2_get_ref_die_offset)
	(dwarf2_get_attr_constant_value, dwarf2_fetch_constant_bytes)
	(get_signatured_type, get_DW_AT_signature_type)
	(decode_locdesc, file_file_name, consume_improper_spaces)
	(skip_form_bytes, skip_unknown_opcode, dwarf_parse_macro_header)
	(dwarf_decode_macro_bytes, dwarf_decode_macros)
	(dwarf2_symbol_mark_computed, set_die_type)
	(read_attribute_value): Update.
	* stap-probe.c (handle_stap_probe, get_stap_base_address):
	Update.
	* dbxread.c (unknown_symtype_complaint)
	(lbrac_mismatch_complaint, repeated_header_complaint)
	(set_namestring, function_outside_compilation_unit_complaint)
	(read_dbx_symtab, process_one_symbol): Update.
	* gdbtypes.c (stub_noname_complaint): Update.
	* windows-nat.c (handle_unload_dll): Update.
	* coffread.c (coff_symtab_read, enter_linenos, decode_type)
	(decode_base_type): Update.
	* xcoffread.c (bf_notfound_complaint, ef_complaint)
	(eb_complaint, record_include_begin, record_include_end)
	(enter_line_range, xcoff_next_symbol_text, read_xcoff_symtab)
	(process_xcoff_symbol, read_symbol)
	(function_outside_compilation_unit_complaint)
	(scan_xcoff_symtab): Update.
	* machoread.c (macho_symtab_read, macho_add_oso_symfile): Update.
	* buildsym.c (finish_block_internal, make_blockvector)
	(end_symtab_get_static_block, augment_type_symtab): Update.
	* dtrace-probe.c (dtrace_process_dof)
	(dtrace_static_probe_ops::get_probes): Update.
	* complaints.h (struct complaint): Don't declare.
	(symfile_complaints): Remove.
	(complaint_internal): Remove "complaints" parameter.
	(complaint): Likewise.
	(clear_complaints): Likewise.
	* symfile.c (syms_from_objfile_1, finish_new_objfile)
	(reread_symbols): Update.
	* dwarf2-frame.c (dwarf2_restore_rule, execute_cfa_program)
	(dwarf2_frame_cache, decode_frame_entry): Update.
	* dwarf2loc.c (dwarf_reg_to_regnum): Update.
	* objc-lang.c (lookup_objc_class, lookup_child_selector)
	(info_selectors_command): Update.
	* macrotab.c (macro_include, check_for_redefinition)
	(macro_undef): Update.
	* objfiles.c (filter_overlapping_sections): Update.
	* stabsread.c (invalid_cpp_abbrev_complaint)
	(reg_value_complaint, stabs_general_complaint, dbx_lookup_type)
	(define_symbol, error_type, read_type, rs6000_builtin_type)
	(stabs_method_name_from_physname, read_member_functions)
	(read_cpp_abbrev, read_baseclasses, read_tilde_fields)
	(attach_fields_to_type, complain_about_struct_wipeout)
	(read_range_type, read_args, common_block_start)
	(common_block_end, cleanup_undefined_types_1, scan_file_globals):
	Update.
	* mdebugread.c (index_complaint, unknown_ext_complaint)
	(basic_type_complaint, bad_tag_guess_complaint)
	(bad_rfd_entry_complaint, unexpected_type_code_complaint)
	(reg_value_complaint, parse_symbol, parse_type, upgrade_type)
	(parse_procedure, parse_lines)
	(function_outside_compilation_unit_complaint)
	(parse_partial_symbols, psymtab_to_symtab_1, cross_ref)
	(bad_tag_guess_complaint, reg_value_complaint): Update.
	* cp-support.c (demangled_name_complaint): Update.
	* macroscope.c (sal_macro_scope): Update.
	* dwarf-index-write.c (class debug_names): Update.

gdb/testsuite/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/complaints.exp (test_initial_complaints): Don't mention
	symfile_complaints.
	(test_short_complaints): Likewise.
	(test_empty_complaints): Likewise.
	(test_initial_complaints): Update.
2018-05-23 09:17:01 -06:00
Tom Tromey 4e9668d0d1 Remove "noisy" parameter from clear_complaints
After the previous patch, the "noisy" parameter to clear_complaints is
no longer used, so this patch removes it.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (clear_complaints): Remove "noisy" parameter.
	* complaints.h (clear_complaints): Update.
	* symfile.c (syms_from_objfile_1, finish_new_objfile)
	(reread_symbols): Update.

gdb/testsuite/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/complaints.exp (test_empty_complaints): Update.
2018-05-23 09:17:00 -06:00
Tom Tromey 43ba33c768 Remove elements from complaint_series
I couldn't find a way to get complaints to use a couple of cases, and
the difference between the actual printed output for these cases was
minimal anyway.  So, this patch removes a couple of constants from
complaint_series, plus the associated code.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (enum complaint_series): Remove FIRST_MESSAGE,
	SUBSEQUENT_MESSAGE.
	(vcomplaint, clear_complaints): Update.
	(symfile_explanations): Remove some messages.

gdb/testsuite/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/complaints.exp (test_serial_complaints): Remove.
	(test_short_complaints): Update.
2018-05-23 09:16:59 -06:00
Tom Tromey 2b9496b2b4 Remove internal_complaint
I happened to notice that gdb has both complaint_internal and
internal_complaint.  The latter is unused, so this patch removes it.

gdb/ChangeLog
2018-05-23  Tom Tromey  <tom@tromey.com>

	* complaints.c (internal_complaint): Remove.
	* complaints.h (internal_complaint): Remove.
2018-05-23 09:16:59 -06:00
Erik Kurzinger 81e25b7c91 Improve File I/O overflow detection in gdbserver (PR server/23198)
Currently, the function used by gdbserver to parse integers from
received File I/O commands will detect overflow and fail for any value
over 0xfffffff.  Among other things, this has the effect of limiting
the file offsets for reading or writing to about 268MB which can be
insufficient for particularly large libraries.

This change allows the parsing of integers up to the true maximum
positive value of 0x7fffffff, increasing the file size limit to about
2GB.

gdb/gdbserver/ChangeLog:
2018-05-23  Erik Kurzinger  <ekurzinger@nvidia.com>

	PR server/23198
	* hostio.c (require_int): Do not report overflow for integers
	between 0xfffffff and 0x7fffffff.
2018-05-23 12:04:39 +01:00
Pedro Alves 035522c022 Fix gdb.base/remote.exp with native-extended-gdbserver board
This fixes gdb.base/remote.exp regressions caused by the previous
commit to the testcase, when tested with
--target_board=native-extended-gdbserver.  For example:

  ...
  show remote memory-write-packet-size
  The memory-write-packet-size is 0 (default). Packets are limited to 16383 bytes.
  (gdb) FAIL: gdb.base/remote.exp: write-packet default
  ...

With that board, GDB connects to GDBserver at gdb_start time, so GDB
is showing the actual remote/gdbserver packet size limits.

Fix it using the usual "disconnect" pattern.  While at it, there's no
need to start GDB before compiling the testcase.

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

	* gdb.base/remote.exp: Only gdb_start after compiling the
	testcase.  Issue "disconnect" before testing "set remote" command
	defaults.  Issue clean_restart before running to main.
2018-05-22 23:26:46 +01:00
Maciej W. Rozycki 35f1fea3fc gdb/x86: Fix `-Wstrict-overflow' build error in `i387_collect_xsave'
Make `i' defined within `i387_collect_xsave' unsigned, removing a
`-Werror=strict-overflow' compilation error:

.../gdb/i387-tdep.c: In function 'void i387_collect_xsave(const regcache*, int, void*, int)':
.../gdb/i387-tdep.c:1348:1: error: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Werror=strict-overflow]
 i387_collect_xsave (const struct regcache *regcache, int regnum,
 ^
cc1plus: all warnings being treated as errors
Makefile:1610: recipe for target 'i387-tdep.o' failed
make: *** [i387-tdep.o] Error 1

seen with GCC 5.4.0, a commit 8ee22052f6 ("gdb/x86: Handle kernels
using compact xsave format") regression.  While `regnum' can be -1 on
entry to the function, to mean all registers, `i' is only used with
non-negative register numbers.

	gdb/
	* i387-tdep.c (i387_collect_xsave): Make `i' unsigned.
2018-05-22 22:52:14 +01:00
Maciej W. Rozycki 7e947ad343 MIPS/gdbserver: Correctly handle narrow big-endian register transfers
Fix an issue with `gdbserver' on big-endian n64 MIPS targets, where
$dspctl is 32-bit while the `ptrace' transfer data type is 64-bit.

Such register data is held in the low order 32 bits of the 64-bit data
quantity exchanged with the buffer used by `fetch_register' and
`store_register', however `supply_register' and `collect_register'
access the same data as a 32-bit quantity.  Consequently the register is
presented and written as all-zeros held in the most-significant part of
the big-endian 64-bit data quantity represented in the buffer:

(gdb) info registers
                  zero               at               v0               v1
 R0   0000000000000000 0000000000000001 0000000000000001 0000000000000000
                    a0               a1               a2               a3
 R4   00000001200212b0 0000000000000000 0000000000000021 000000012001a260
                    a4               a5               a6               a7
 R8   000000012001a260 0000000000000004 800000010c60c000 fffffffffffffff8
                    t0               t1               t2               t3
 R12  0000000000000000 000000fff7edab68 0000000000000001 0000000000000000
                    s0               s1               s2               s3
 R16  000000fff7ee2068 0000000120008b80 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  000000000052e5c8 000000000052f008 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000000 00000001200027c0 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  00000001200212b0 000000ffffffc850 000000ffffffc850 0000000120005ee8
                status               lo               hi         badvaddr
      0000000000109cf3 0000000000943efe 000000000000000e 000000012001a008
                 cause               pc
      0000000000800024 0000000120005ee8
                  fcsr              fir              hi1              lo1
              0e800000         00f30000 0000000000000000 0101010101010101
                   hi2              lo2              hi3              lo3
      0202020202020202 0303030303030303 0404040404040404 0505050505050505
                dspctl          restart
              00000000 0000000000000000
(gdb)

Correct this problem then by using the `mips_supply_register'
`mips_collect_register' accessors for 32-bit registers where the
`ptrace' data type is 64-bit.  These accessors already operate on 32-bit
data quantities held in 64-bit containers:

(gdb) info registers
                  zero               at               v0               v1
 R0   0000000000000000 0000000000000001 0000000000000001 0000000000000000
                    a0               a1               a2               a3
 R4   00000001200212b0 0000000000000000 0000000000000021 000000012001a260
                    a4               a5               a6               a7
 R8   000000012001a260 0000000000000004 800000010d82e900 fffffffffffffff8
                    t0               t1               t2               t3
 R12  0000000000000000 000000fff7edab68 0000000000000001 0000000000000000
                    s0               s1               s2               s3
 R16  000000fff7ee2068 0000000120008b80 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  000000000052e5c8 000000000052f008 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000000 00000001200027c0 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  00000001200212b0 000000ffffffc850 000000ffffffc850 0000000120005ee8
                status               lo               hi         badvaddr
      0000000000109cf3 0000000000943efe 000000000000000e 000000012001a008
                 cause               pc
      0000000000800024 0000000120005ee8
                  fcsr              fir              hi1              lo1
              0e800000         00f30000 0000000000000000 0101010101010101
                   hi2              lo2              hi3              lo3
      0202020202020202 0303030303030303 0404040404040404 0505050505050505
                dspctl          restart
              55aa33cc 0000000000000000
(gdb)

	gdb/gdbserver/
	* linux-mips-low.c [HAVE_PTRACE_GETREGS] (mips_collect_register)
	(mips_supply_register): Move outside HAVE_PTRACE_GETREGS.
	(mips_collect_ptrace_register, mips_supply_ptrace_register): New
	functions.
	(the_low_target): Wire them.
2018-05-22 22:52:14 +01:00
Pedro Alves 6b8edb5101 remote: one struct remote_state per struct remote_target
'struct remote_state' today contains per-connection state, however
there's only a single global instance of that type.  In order to
support multiple connections, we must have one such object per
connection.

Thus this patch eliminates the 'remote_state' global in favor of
having a remote_state instance per remote_target instance.

The get_remote_state free function is eliminated as well, by making it
a remote_target method instead.

The patch then fixes the fallout by making all free functions that
refer to get_remote_state() directly or indirectly be methods of
remote_target too.

Likewise, remote-fileio.c and remote-notif.c routines are
parameterized with a remote_target pointer too, so they can call into
the right remote_target instance.

References to the global 'get_remote_state ()->remote_desc' to tell
whether the remote target is open (!= nullptr) must be replaced with
something else:

 - Command implementations use a new get_current_remote_target free
 function.

 - remote_target::open_1 checks the exception type instead.

Finally, remote_target and extended_remote_target are made
heap-allocated targets.  As with the earlier core target patches, it
still won't be possible to have more than one remote_target instance
in practice, but this puts us closer.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote-fileio.c (remote_fileio_reply, remote_fileio_ioerror)
	(remote_fileio_badfd, remote_fileio_return_errno)
	(remote_fileio_return_success, remote_fileio_func_open)
	(remote_fileio_func_open, remote_fileio_func_close)
	(remote_fileio_func_read, remote_fileio_func_write)
	(remote_fileio_func_lseek, remote_fileio_func_rename)
	(remote_fileio_func_unlink, remote_fileio_func_stat)
	(remote_fileio_func_fstat, remote_fileio_func_gettimeofday)
	(remote_fileio_func_isatty, remote_fileio_func_system): Add
	remote_target parameter.
	(remote_fio_func_map) <func>: Add remote_target parameter.
	(do_remote_fileio_request, remote_fileio_request):
	* remote-fileio.h (remote_fileio_request):
	* remote-notif.c (remote_notif_ack, remote_notif_parse, ): Add
	remote_target parameter.
	(remote_notif_process, handle_notification): Adjust to pass down
	the remote.
	(remote_notif_state_allocate): Add remote_target parameter.  Save
	it.
	* remote-notif.h (struct remote_target): Forward declare.
	(struct notif_client) <parse, ack, can_get_pending_events>: Add
	remote_target parameter.
	(struct remote_notif_state) <remote>: New field.
	(remote_notif_ack, remote_notif_parse): Add remote_target
	parameter.
	(remote_notif_state_allocate, remote_notif_state_allocate): Add
	remote_target parameter.
	* remote.c (OPAQUETHREADBYTES, threadref, gdb_ext_thread_info)
	(threads_listing_context, rmt_thread_action, protocol_feature)
	(packet_reg, stop_reply, stop_reply_p, enum packet_support)
	(packet_result, struct threads_listing_context, remote_state):
	Move definitions and declarations higher up.
	(remote_target) <~remote_target>: Declare.
	(remote_download_command_source, remote_file_put, remote_file_get)
	(remote_file_delete, remote_hostio_pread, remote_hostio_pwrite)
	(remote_hostio_pread_vFile, remote_hostio_send_command)
	(remote_hostio_set_filesystem, remote_hostio_open)
	(remote_hostio_close, remote_hostio_unlink, remote_state)
	(get_remote_state, get_remote_packet_size, get_memory_packet_size)
	(get_memory_write_packet_size, get_memory_read_packet_size)
	(append_pending_thread_resumptions, remote_detach_1)
	(append_resumption, remote_resume_with_vcont)
	(add_current_inferior_and_thread, wait_ns, wait_as)
	(process_stop_reply, remote_notice_new_inferior)
	(process_initial_stop_replies, remote_add_thread)
	(btrace_sync_conf, remote_btrace_maybe_reopen)
	(remove_new_fork_children, kill_new_fork_children)
	(discard_pending_stop_replies, stop_reply_queue_length)
	(check_pending_events_prevent_wildcard_vcont)
	(discard_pending_stop_replies_in_queue, stop_reply)
	(remote_notif_remove_queued_reply, stop_reply *queued_stop_reply)
	(peek_stop_reply, remote_parse_stop_reply, remote_stop_ns)
	(remote_interrupt_as, remote_interrupt_ns)
	(remote_get_noisy_reply, remote_query_attached)
	(remote_add_inferior, remote_current_thread, get_current_thread)
	(set_thread, set_general_thread, set_continue_thread)
	(set_general_process, write_ptid)
	(remote_unpack_thread_info_response, remote_get_threadinfo)
	(parse_threadlist_response, remote_get_threadlist)
	(remote_threadlist_iterator, remote_get_threads_with_ql)
	(remote_get_threads_with_qxfer)
	(remote_get_threads_with_qthreadinfo, extended_remote_restart)
	(get_offsets, remote_check_symbols, remote_supported_packet)
	(remote_query_supported, remote_packet_size)
	(remote_serial_quit_handler, remote_detach_pid)
	(remote_vcont_probe, remote_resume_with_hc)
	(send_interrupt_sequence, interrupt_query)
	(remote_notif_get_pending_events, fetch_register_using_p)
	(send_g_packet, process_g_packet, fetch_registers_using_g)
	(store_register_using_P, store_registers_using_G)
	(set_remote_traceframe, check_binary_download)
	(remote_write_bytes_aux, remote_write_bytes, remote_read_bytes_1)
	(remote_xfer_live_readonly_partial, remote_read_bytes)
	(remote_send_printf, remote_flash_write, readchar)
	(remote_serial_write, putpkt, putpkt_binary, skip_frame)
	(read_frame, getpkt, getpkt_or_notif_sane_1, getpkt_sane)
	(getpkt_or_notif_sane, remote_vkill, remote_kill_k)
	(extended_remote_disable_randomization, extended_remote_run)
	(send_environment_packet, extended_remote_environment_support)
	(extended_remote_set_inferior_cwd, remote_write_qxfer)
	(remote_read_qxfer, push_stop_reply, vcont_r_supported)
	(packet_command): Now methods of ...
	(remote_target): ... this class.
	(m_remote_state) <remote_target>: New field.
	(struct remote_state) <stop_reply_queue,
	remote_async_inferior_event_token, wait_forever_enabled_p>: New
	fields.
	(remote_state::remote_state): Allocate stop_reply_queue.
	(remote_state): Delete global.
	(get_remote_state_raw): Delete.
	(remote_target::get_remote_state): Allocate m_remote_state on
	demand.
	(get_current_remote_target): New.
	(remote_ops, extended_remote_ops): Delete.
	(wait_forever_enabled_p, remote_async_inferior_event_token):
	Delete, moved to struct remote_state.
	(remote_target::close): Delete self.  Destruction bits split to
	...
	(remote_target::~remote_target): ... this.
	(show_memory_packet_size): Adjust to use
	get_current_remote_target.
	(struct protocol_feature) <func>: Add remote_target parameter.
	All callers adjusted.
	(curr_quit_handler_target): New.
	(remote_serial_quit_handler): Reimplement.
	(remote_target::open_1): Adjust to use get_current_remote_target.
	Heap-allocate remote_target/extended_remote_target instances.
	(vcont_builder::vcont_builder): Add remote_target parameter, and
	save it in m_remote.  All callers adjusted.
	(vcont_builder::m_remote): New field.
	(vcont_builder::restart, vcont_builder::flush)
	(vcont_builder::push_action): Use it.
	(remote_target::commit_resume): Use it.
	(struct queue_iter_param) <remote>: New field.
	(remote_target::remove_new_fork_children): Fill in 'remote' field.
	(check_pending_event_prevents_wildcard_vcont_callback_data): New.
	(check_pending_event_prevents_wildcard_vcont_callback)
	(remote_target::check_pending_events_prevent_wildcard_vcont)
	(remote_target::discard_pending_stop_replies)
	(remote_target::discard_pending_stop_replies_in_queue)
	(remote_target::remote_notif_remove_queued_reply): Fill in
	'remote' field.
	(remote_notif_get_pending_events): New.
	(remote_target::readchar, remote_target::remote_serial_write):
	Save/restore curr_quit_handler_target.
	(putpkt): New.
	(kill_new_fork_children): Fill in 'remote' field.
	(packet_command): Use get_current_remote_target, defer to
	remote_target method of same name.
	(scoped_remote_fd::scoped_remote_fd): Add 'remote_target'
	parameter, and save it in m_remote.  All callers adjusted.
	(scoped_remote_fd::release): Use m_remote.
	(scoped_remote_fd::m_remote): New field.
	(remote_file_put, remote_file_get, remote_file_delete): Use
	get_current_remote_target, defer to remote_target method of same
	name.
	(remote_btrace_reset): Add remote_state paremeter.  Update all
	callers.
	(remote_async_inferior_event_handler). Pass down 'data'.
	(remote_new_objfile): Use get_current_remote_target.
	(remote_target::vcont_r_supported): New.
	(set_range_stepping): Use get_current_remote_target and
	remote_target::vcont_r_supported.
	(_initialize_remote): Don't allocate 'remote_state' and
	'stop_reply_queue' globals.
	* remote.h (struct remote_target): Forward declare.
	(getpkt, putpkt, remote_notif_get_pending_events): Add
	'remote_target' parameter.
2018-05-22 18:35:20 +01:00
Pedro Alves f5db4863f5 remote: Make vcont_builder a class
gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c (vcont_builder): Now a class.  Make all data members
	private.
	(vcont_builder) <vcont_builder, restart, flush, push_action>:
	Declare methods.
	(vcont_builder_restart): Rename to ...
	(vcont_builder::restart): ... this.
	(vcont_builder_flush): Rename to ...
	(vcont_builder::flush): ... this.
	(vcont_builder_push_action): Rename to ...
	(vcont_builder::push_action): ... this.
	(remote_target::commit_resume): Adjust.
2018-05-22 18:34:39 +01:00
Pedro Alves cc0be08f80 Handle "show remote memory-write-packet-size" when not connected
Currently "show remote memory-write-packet-size" says that the packet
size is limited to whatever is stored in the remote_state global, even
if not connected to a target.

When we get to support multiple instances of remote targets, there
won't be a remote_state global anymore, so that must be replaced by
something else.

Since it doesn't make sense to print the limit of the packet size of a
non-existing connection, this patch makes us say that the limit will
be further reduced when we connect.

The text is taken from the command's online help, which says:

 "The actual limit is further reduced dependent on the target."

Note that a value of "0" is special, as per "help set remote
memory-write-packet-size":

 ~~~
 Specify the number of bytes in a packet or 0 (zero) for the
 default packet size.
 ~~~

I've tweaked "show remote memory-write-packet-size" to include
"(default)" in the output in that case, like this:

 (gdb) show remote memory-write-packet-size
 The memory-write-packet-size is 0 (default). The actual limit will be further reduced dependent on the target.

While working on this, I noticed that an explicit "set remote
write-packet-size 0" does not makes GDB go back to the exact same
state as the default state when GDB starts up:

 (gdb) show remote memory-write-packet-size
 The memory-write-packet-size is 0. [...]
                                 ^^

 (gdb) set remote memory-write-packet-size 0
 (gdb) show remote memory-write-packet-size
 The memory-write-packet-size is 16384. [...]
                                 ^^^^^

The "16384" number comes from DEFAULT_MAX_MEMORY_PACKET_SIZE.

This happens because git commit a5c0808e22 ("gdb: remove packet size
limit") at
<https://sourceware.org/ml/gdb-patches/2015-08/msg00743.html>, added
this:

  /* So that the query shows the correct value.  */
  if (size <= 0)
    size = DEFAULT_MAX_MEMORY_PACKET_SIZE;

to set_memory_packet_size, but despite what the comment suggests, that
also has the side-effect of recording DEFAULT_MAX_MEMORY_PACKET_SIZE
in config->size.

Finally, DEFAULT_MAX_MEMORY_PACKET_SIZE only makes sense for "set
remote memory-write-packet-size fixed", so I've renamed it
accordingly, to make it a little bit clearer.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c (DEFAULT_MAX_MEMORY_PACKET_SIZE): Rename to ...
	(DEFAULT_MAX_MEMORY_PACKET_SIZE_FIXED): ... this.
	(get_fixed_memory_packet_size): New.
	(get_memory_packet_size): Use it.
	(set_memory_packet_size): Don't override the config size with
	DEFAULT_MAX_MEMORY_PACKET_SIZE.
	(show_memory_packet_size): Use get_fixed_memory_packet_size.
	Don't refer to get_memory_packet_size if not connected to a remote
	target.  Show "(default)" if configured size is 0.

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

	* gdb.base/remote.exp: Adjust expected output of "show remote
	memory-write-packet-size".  Add tests for "set remote
	memory-write-packet-size 0" and "set remote
	memory-write-packet-size fixed/limit".
2018-05-22 18:34:03 +01:00
Pedro Alves 9607784ac0 remote: Move discard_pending_stop_replies call
This helps because discard_pending_stop_replies will later become a
method of remote_target.  Otherwise, when we have multiple instances
of remote_target, we'd have to make discard_pending_stop_replies find
the inferior's target_ops, and upcast it to remote_target (if indeed a
remote) to find the pending stop replies queue to clear.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_target::mourn_inferior): Move
	discard_pending_stop_replies call here from ...
	(_initialize_remote): ... here.
2018-05-22 18:33:44 +01:00
Pedro Alves 0e9a6b2f04 remote: Small cleanup in compare_section_command
The set_general_process call in compare_sections_command isn't
actually needed.  remote_target::verify_memory and
remote_target::xfer_partial already handle making sure the remote is
pointing at the right process or thread.

Getting this out of the way helps a bit with further elimination of
the remote_state global, because we have to handle the case of a user
invoking the command even if not connect to a remote target.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c (compare_section_command): Remove set_general_process
	call.
2018-05-22 18:33:21 +01:00
Pedro Alves 43c3a0e473 remote: remote_arch_state pointers -> remote_arch_state objects
The previous patch made the map store pointers to remote_arch_state
instead of objects directly, simply because struct remote_arch_state
is still incomplete where struct remote_state is declared.  This patch
thus moves the remote_arch_state declaration higher up in the file,
and makes the map store remote_arch_state objects directly instead of
pointers to objects.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c (struct packet_reg, struct remote_arch_state):
	Move higher up in the file.
	(remote_state) <m_arch_states>: Store remote_arch_state values
	instead of remote_arch_state pointers.
	(remote_state::get_remote_arch_state): Adjust.
2018-05-22 18:32:49 +01:00
Pedro Alves 9d6eea3132 remote: multiple remote_arch_state instances per arch
Currently, we associate gdbarch-related remote protocol state on a
per-gdbarch data object.  Things like the size of the g/G packet, and
the max remote packet size.  If we'll support being connected to
different remote servers at the same time, then we need to cope with
each having their own packet sizes, even if they are each debugging
programs of the same architecture.  I.e., a single instance of
remote_arch_state per arch is not sufficient.

This patch moves the remote_arch_state object to a map of
gdbarch-to-remote_arch_state saved in the remote_state structure.
Usually there will only be one entry in the map, though we may see
more with stubs that support multi-process and/or archs with multiple
ABIs (e.g, one remote_arch_state for 64-bit inferiors and another for
32-bit inferiors).

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c: Include <unordered_map>.
	(remote_state): Now a class.
	(remote_state) <get_remote_arch_state>: Declare method.
	<get_remote_arch_state>: New field.
	(remote_arch_state) <remote_arch_state>: Declare ctor.
	<regs>: Now a unique_ptr.
	(remote_gdbarch_data_handle): Delete.
	(get_remote_arch_state): Delete.
	(remote_state::get_remote_arch_state): New.
	(get_remote_state): Adjust to call remote_state's
	get_remote_arch_state method.
	(init_remote_state): Delete, bits factored out to ...
	(remote_arch_state::remote_arch_state): ... this new method.
	(get_remote_packet_size, get_memory_packet_size)
	(process_g_packet, remote_target::fetch_registers)
	(remote_target::prepare_to_store, store_registers_using_G)
	(remote_target::store_registers, remote_target::get_trace_status):
	Adjust to call remote_state's method.
	(_initialize_remote): Remove reference to
	remote_gdbarch_data_handle.
2018-05-22 18:32:12 +01:00
Pedro Alves dd194f6b36 remote: Make readahead_cache a C++ class
The idea here is eliminate the get_remote_state calls from within
readahead_cache_invalidate, readahead_cache_invalidate_fd,
remote_hostio_pread_from_cache by making those functions be class
methods instead.  Later on we'll have one readahead_cache instance per
remote connection, and this change makes that easier.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c (struct readahead_cache) <invalidate, invalidate_fd,
	pread>: New method declarations.
	(remote_target::open_1): Adjust.
	(readahead_cache_invalidate): Rename to ...
	(readahead_cache::invalidate): ... this, and adjust to be a class
	method.
	(readahead_cache_invalidate_fd): Rename to ...
	(readahead_cache::invalidate_fd): ... this, and adjust to be a
	class method.
	(remote_hostio_pwrite): Adjust.
	(remote_hostio_pread_from_cache): Rename to ...
	(readahead_cache::pread): ... this, and adjust to be a class
	method.
	(remote_hostio_close): Adjust.
2018-05-22 18:31:47 +01:00
Pedro Alves 440b7aece4 remote: Eliminate remote_hostio_close_cleanup
gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_hostio_close_cleanup): Delete.
	(class scoped_remote_fd): New.
	(remote_file_put, remote_file_get): Use it.
2018-05-22 18:31:14 +01:00
Pedro Alves de44f5a735 remote: struct remote_state, use op new, fix leaks
A bit of C++ification.  Also plugs a few leaks, since currently
nothing is freeing a few fields of remote_state.  They're now freed in
the added destructor.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>

	(struct vCont_action_support): Use bool and initialize all fields.
	(struct readahead_cache): Initialize all fields.
	(remote_state): Use bool and initialize all fields.
	(remote_state::remote_state, remote_state::~remote_state): New.
	(new_remote_state): Delete.
	(_initialize_remote): Use new to allocate remote_state.
2018-05-22 18:22:06 +01:00
Pedro Alves b1b60145ae Support UTF-8 identifiers in C/C++ expressions (PR gdb/22973)
Factor out cp_ident_is_alpha/cp_ident_is_alnum out of
gdb/cp-name-parser.y and use it in the C/C++ expression parser too.

New test included.

gdb/ChangeLog:
2018-05-22  Pedro Alves  <palves@redhat.com>
	    張俊芝  <zjz@zjz.name>

	PR gdb/22973
	* c-exp.y: Include "c-support.h".
	(parse_number, c_parse_escape, lex_one_token): Use TOLOWER instead
	of tolower.  Use c_ident_is_alpha to scan names.
	* c-lang.c: Include "c-support.h".
	(convert_ucn, convert_octal, convert_hex, convert_escape): Use
	ISXDIGIT instead of isxdigit and ISDIGIT instead of isdigit.
	* c-support.h: New file, with bits factored out from ...
	* cp-name-parser.y: ... this file.
	Include "c-support.h".
	(cp_ident_is_alpha, cp_ident_is_alnum): Deleted, moved to
	c-support.h and renamed.
	(symbol_end, yylex): Adjust.

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

	PR gdb/22973
	* gdb.base/utf8-identifiers.c: New file.
	* gdb.base/utf8-identifiers.exp: New file.
2018-05-22 17:35:38 +01:00
Pedro Franco de Carvalho 0ec848ad25 [PowerPC] Recognize isa205 in linux core files
Currently the ppc linux core file target doesn't return target
descriptions with the lager FPSCR introduced in isa205.

This patch changes the core file target so that the auxv is read from
the core file to determine the size of FPSCR, so that the appropriate
target description is selected.

gdb/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* arch/ppc-linux-common.c (ppc_linux_has_isa205): Change the
	parameter type to CORE_ADDR.
	* arch/ppc-linux-common.h (ppc_linux_has_isa205): Change the
	parameter type in declaration to CORE_ADDR.
	* ppc-linux-tdep.c (ppc_linux_core_read_description): Call
	target_auxv_search to get AT_HWCAP and use the result to get the
	target description.
	* ppc-linux-nat.c (ppc_linux_get_hwcap): Change the return type
	to CORE_ADDR. Remove the cast of the return value to unsigned
	long. Fix error predicate of target_auxv_search.
	(ppc_linux_nat_target::read_description): Change the type of the
	hwcap variable to CORE_ADDR.

gdb/testsuite/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* gdb.arch/powerpc-fpscr-gcore.exp: New file.
2018-05-22 11:52:03 -03:00
Pedro Franco de Carvalho 0fb2aaa15e [PowerPC] Fix inclusion of dfp pseudoregs in tdep
Previously, decimal floating point pseudoregisters were always included
in the target if it had a floating point unit.

This patch changes this to only include them if the target description
indicates that they are present, i.e. if the FPSCR register has more
than 32 bits.

gdb/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* rs6000-tdep.c (rs6000_gdbarch_init): Assign 1 to have_dfp only
	if the size of fpscr is larger than 32 bits.
2018-05-22 11:52:03 -03:00
Pedro Franco de Carvalho 2c3305f6b0 [PowerPC] Fix VSX registers in linux core files
The functions used by the VSX regset to collect and supply registers
from core files where incorrect. This patch changes the regset to use
the standard regset collect/supply functions to fix this. The native
target is also changed to use the same regset.

gdb/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* ppc-linux-tdep.c (ppc_linux_vsxregset): New function.
	(ppc32_linux_vsxregmap): New global.
	(ppc32_linux_vsxregset): Initialize with ppc32_linux_vsxregmap,
	regcache_supply_regset, and regcache_collect_regset.
	* ppc-linux-tdep.h (ppc_linux_vsxregset): Declare.
	* ppc-linux-nat.c (supply_vsxregset, fill_vsxregset): Remove.
	(fetch_vsx_register, store_vsx_register): Remove.
	(fetch_vsx_registers): Add regno parameter. Get regset using
	ppc_linux_vsxregset. Use regset to supply registers.
	(store_vsx_registers): Add regno parameter. Get regset using
	ppc_linux_vsxregset. Use regset to collect registers.
	(fetch_register): Call fetch_vsx_registers instead of
	fetch_vsx_register.
	(store_register): Call store_vsx_registers instead of
	store_vsx_register.
	(fetch_ppc_registers): Call fetch_vsx_registers with -1 for the
	new regno parameter.
	(store_ppc_registers): Call store_vsx_registers with -1 for the
	new regno parameter.
	* rs6000-tdep.c (ppc_vsx_support_p, ppc_supply_vsxreget)
	(ppc_collect_vsxregset): Remove.

gdb/testsuite/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* gdb.arch/powerpc-vsx-gcore.exp: New file.
2018-05-22 11:52:03 -03:00
Pedro Franco de Carvalho 1d75a65809 [PowerPC] Fix access to VSCR in linux targets
The 4-byte VSCR register is found inside a 16-byte field in the regset
returned by ptrace and in core files. The position of VSCR depends on
the endianess of the target, which was previously assumed to be
big-endian for the purpose of getting VSCR. This patch removes this
assumption to fix access to VSCR in little-endian mode.

gdb/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* ppc-tdep.h (struct ppc_reg_offsets): Remove vector register
	offset fields.
	* ppc-fbsd-tdep.c (ppc32_fbsd_reg_offsets): Remove initializers
	for vector register offset fields.
	(ppc64_fbsd_reg_offsets): Likewise.
	* ppc-nbsd-tdep.c (_initialize_ppcnbsd_tdep): Remove assignment
	to vector register offset fields.
	* ppc-obsd-tdep.c (_initialize_ppcnbsd_tdep): Remove assignment
	to vector register offset fields.
	* ppc-obsd-nat.c (_initialize_ppcobsd_nat): Remove assignment to
	vector register offset fields.
	* rs6000-aix-tdep.c (rs6000_aix32_reg_offsets): Remove
	initializers for vector register offset fields.
	(rs6000_aix64_reg_offsets): Likewise.
	* rs6000-tdep.c (ppc_vrreg_offset): Remove.
	(ppc_supply_vrregset): Remove.
	(ppc_collect_vrregset): Remove.
	* ppc-linux-tdep.c (ppc_linux_collect_vrregset): New function.
	(ppc_linux_vrregset) : New function.
	(ppc32_le_linux_vrregmap, ppc32_be_linux_vrregmap)
	(ppc32_le_linux_vrregset, ppc32_be_linux_vrregset): New globals.
	(ppc32_linux_vrregset): Remove.
	(ppc_linux_iterate_over_regset_sections): Call ppc_linux_vrregset
	and use result instead of ppc32_linux_vrregset.
	(ppc32_linux_reg_offsets): Remove initializers for vector register
	offset fields.
	(ppc64_linux_reg_offsets): Likewise.
	* ppc-linux-tdep.h (ppc_linux_vrregset): New declaration.
	* ppc-linux-nat.c: Include regset.h.
	(gdb_vrregset_t): Adjust comment to account for little-endian
	mode.
	(supply_vrregset, fill_vrregset): Remove.
	(fetch_altivec_register, store_altivec_register): Remove.
	(fetch_altivec_registers): Add regno parameter. Get regset using
	ppc_linux_vrregset. Use regset to supply registers.
	(store_altivec_registers): Add regno parameter. Get regset using
	ppc_linux_vrregset. Use regset to collect registers.
	(fetch_register): Call fetch_altivec_registers instead of
	fetch_altivec_register.
	(store_register): Call store_altivec_registers instead of
	store_altivec_register.
	(fetch_ppc_registers): Call fetch_altivec_registers with -1 for
	the new regno parameter.
	(store_ppc_registers): Call store_altivec_registers with -1 for
	the new regno parameter.

gdb/gdbserver/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* linux-ppc-low.c (ppc_fill_vrregset): Add vscr_offset variable.
	Set vscr_offset to 0 in little-endian mode and 12 in big-endian
	mode. Call collect_register_by_name with vscr using
	vscr_offset. Zero-pad vscr and vrsave fields in collector buffer.
	(ppc_store_vrregset): Add and set vscr_offset variable as in
	ppc_fill_vrregset. Call supply_register_by_name with vscr using
	vscr_offset.
2018-05-22 11:52:03 -03:00
Pedro Franco de Carvalho d078308a2e [PowerPC] Consolidate linux vector regset sizes
This patch defines constants for the sizes of the two vector
regsets (vector-scalar registers and regular vector registers).

The native, gdbserver and core file targets are changed to use these
constants.

The Linux ptrace calls return (or read) a smaller regset than the one
found in core files for vector registers, because ptrace uses a single
4-byte quantity for vrsave at the end of the regset, while the
core-file regset uses a full 16-byte field for vrsave. For simplicity,
the larger size is used in both cases, and so a buffer with 12 unused
additional bytes is passed to ptrace in the native target.

gdb/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* arch/ppc-linux-common.h (PPC_LINUX_SIZEOF_VRREGSET)
	(PPC_LINUX_SIZEOF_VSXREGSET): Define.
	* ppc-linux-nat.c (SIZEOF_VSXREGS, SIZEOF_VRREGS): Remove.
	(gdb_vrregset_t): Change array type size to
	PPC_LINUX_SIZEOF_VRREGSET.
	(gdb_vsxregset_t): Change array type size to
	PPC_LINUX_SIZEOF_VSXREGSET.
	* ppc-linux-tdep.c (ppc_linux_iterate_over_regset_sections):
	Change integer literals to PPC_LINUX_SIZEOF_VRREGSET and
	PPC_LINUX_SIZEOF_VSXREGSET.

gdb/gdbserver/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* linux-ppc-low.c (SIZEOF_VSXREGS, SIZEOF_VRREGS): Remove.
	(ppc_arch_setup): Change SIZEOF_VRREGS and SIZEOF_VSXREGS to
	PPC_LINUX_SIZEOF_VRREGSET and PPC_LINUX_SIZEOF_VSXREGSET.
2018-05-22 11:52:02 -03:00
Pedro Franco de Carvalho 7273b5fc4b [PowerPC] Disable regsets using zero sizes in gdbserver
Currently the linux-ppc-low.c fill/store functions for extended
regsets check whether they should execute by using the global hwcap
variable.

This patch explicitly sets the regset sizes to zero when needed to
disable them instead, so that the fill/store functions are not called
in the first place by regsets_fetch_inferior_registers in linux-low.c.

gdb/gdbserver/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* linux-ppc-low.c (ppc_fill_vsxregset): Remove ppc_hwcap check.
	(ppc_store_vsxregset): Likewise.
	(ppc_fill_vrregset): Likewise.
	(ppc_store_vrregset): Likewise.
	(ppc_fill_evrregset): Likewise.
	(ppc_store_evrregset): Likewise.
	(ppc_regsets): Set VSX/VR/EVR regset sizes to 0.
	(ppc_arch_setup): Iterate through ppc_regsets and set sizes when
	needed.
2018-05-22 11:52:02 -03:00
Pedro Franco de Carvalho 2e077f5e67 [PowerPC] Consolidate wordsize getter between native and gdbserver
This patch moves the native target wordsize getter for ppc linux to
nat/ so that it can be used to simplify ppc_arch_setup in
gdbserver. The ptrace call used to get MSR for this is ultimately the
same as before, but it is no longer necessary to create a temporary
regcache to call fetch_inferior_registers.

gdb/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* configure.nat <linux powerpc>: Add ppc-linux.o to NATDEPFILES.
	* ppc-linux-nat.c (ppc_linux_target_wordsize): Move to
	nat/ppc-linux.c.
	(ppc_linux_nat_target::auxv_parse): Get thread id tid. Call
	ppc_linux_target_wordsize with tid.
	(ppc_linux_nat_target::read_description): Call ppc_linux_target
	wordsize with tid.
	* nat/ppc-linux.c: Include nat/gdb_ptrace.h.
	(ppc64_64bit_inferior_p): Add static and inline specifiers.
	(ppc_linux_target_wordsize): Move here from ppc-linux-nat.c. Add
	tid parameter. Remove static specifier.
	* nat/ppc-linux.h (ppc64_64bit_inferior_p): Remove declaration.
	(ppc_linux_target_wordsize): New declaration.

gdb/gdbserver/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* linux-ppc-low.c (ppc_arch_setup): Remove code for getting the
	wordsize of the inferior. Call ppc_linux_target_wordsize.
2018-05-22 11:52:02 -03:00
Pedro Franco de Carvalho bd64614eb7 [PowerPC] Consolidate linux target description selection
Share target description declarations and selection among ppc linux
native targets, core files, gdbserver and IPA.

To avoid complicated define guards, gdbserver and IPA now have
declarations for all descriptions, including 64-bit generated
descriptions when compiled in 32-bit mode. These have always been
linked into the gdbserver and IPA binaries. Because they might be
uninitialized, the selection function checks that the selected
description is initialized.

gdb/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* arch/ppc-linux-common.c: New file.
	* arch/ppc-linux-common.h: New file.
	* arch/ppc-linux-tdesc.h: New file.
	* configure.tgt (powerpc*-*-linux*): Add arch/ppc-linux-common.o.
	* Makefile.in (ALL_TARGET_OBS): Add arch/ppc-linux-common.o.
	(HFILES_NO_SRCDIR): Add arch/ppc-linux-common.h and
	arch/ppc-linux-tdesc.h.
	* ppc-linux-nat.c: Include arch/ppc-linux-common.h and
	arch/ppc-linux-tdesc.h.
	(ppc_linux_nat_target::read_description): Remove target
	description matching code. Fill a ppc_linux_features struct and
	call ppc_linux_match_description with it. Move comment about ISA
	2.05 to ppc-linux-common.c.
	* ppc-linux-tdep.c: Include arch/ppc-linux-common.h and
	arch/ppc-linux-tdesc.h.
	(ppc_linux_core_read_description): Remove target description
	matching code. Fill a ppc_linux_features struct and call
	ppc_linux_match_description with it.
	* ppc-linux-tdep.h (tdesc_powerpc_32l, tdesc_powerpc_64l)
	(tdesc_powerpc_altivec32l, tdesc_powerpc_altivec64l)
	(tdesc_powerpc_cell32l, tdesc_powerpc_cell64l)
	(tdesc_powerpc_vsx32l, tdesc_powerpc_vsx64l)
	(tdesc_powerpc_isa205_32l, tdesc_powerpc_isa205_64l)
	(tdesc_powerpc_isa205_altivec32l, tdesc_powerpc_isa205_altivec64l)
	(tdesc_powerpc_isa205_vsx32l, tdesc_powerpc_isa205_vsx64l)
	(tdesc_powerpc_e500l): Remove.

gdb/gdbserver/ChangeLog:
2018-05-22  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* configure.srv (srv_tgtobj): Add arch/ppc-linux-common.o.
	* Makefile.in (SFILES): Add arch/ppc-linux-common.c.
	* linux-ppc-tdesc.h: Rename to linux-ppc-tdesc-init.h.
	* linux-ppc-tdesc-init.h (tdesc_powerpc_32l, tdesc_powerpc_64l)
	(tdesc_powerpc_altivec32l, tdesc_powerpc_altivec64l)
	(tdesc_powerpc_cell32l, tdesc_powerpc_cell64l)
	(tdesc_powerpc_vsx32l, tdesc_powerpc_vsx64l)
	(tdesc_powerpc_isa205_32l, tdesc_powerpc_isa205_64l)
	(tdesc_powerpc_isa205_altivec32l, tdesc_powerpc_isa205_altivec64l)
	(tdesc_powerpc_isa205_vsx32l, tdesc_powerpc_isa205_vsx64l)
	(tdesc_powerpc_e500l): Remove.
	* linux-ppc-ipa.c: Include arch/ppc-linux-tdesc.h and
	linux-ppc-tdesc-init.h. Don't include linux-ppc-tdesc.h.
	* linux-ppc-low.c: Include arch/ppc-linux-common.h,
	arch/ppc-linux-tdesc.h, and linux-ppc-tdesc-init.h. Don't include
	linux-ppc-tdesc.h.
	(ppc_arch_setup): Remove target description matching code. Fill a
	ppc_linux_features struct and call ppc_linux_match_description
	with it.
2018-05-22 11:52:02 -03:00
Joel Brobecker 241db429d5 fix "stale cleanup" internal-warning when using "catch assert" command
Trying to insert a catchpoint on all Ada assertions now triggers
the following internal warning regardless of the situation. For
instance, not even debugging any program:

    (gdb) catch assert
    /[...]/gdb/common/cleanups.c:264: internal-warning:
    restore_my_cleanups has found a stale cleanup

This is due to a small bug in the following C++-ification commit:

    commit bc18fbb575
    Author: Tom Tromey <tom@tromey.com>
    Date:   Fri May 18 15:58:50 2018 -0600
    Subject: Change ada_catchpoint::excep_string to be a std::string

The stale cleanup in question is the following one in top.c:execute_command:

    cleanup_if_error = make_bpstat_clear_actions_cleanup ();

This cleanup is expected to be discarded if there are no exception.
There were no GDB exception; however, a C++ exception was triggered,
because we passed NULL as the excep_string argument when calling
create_ada_exception_catchpoint, which is a reference to a const
string. So we get a C++ exception during the std::string constructor,
which propagates up, causing the cleanup to unexpectedly remain
in the cleanup chain.

This patch fixes the immediate issue of the incorrect call to
create_ada_exception_catchpoint.

gdb/ChangeLog:

        * ada-lang.c (catch_assert_command): Pass empty string instead
        of NULL for excep_string argument.

Tested on x86_64-linux, fixes the following failures:

  * catch_assert_if.exp: insert catchpoint on failed assertions with condition
  * catch_ex.exp: insert catchpoint on failed assertions

This also fixes about a dozen UNRESOLVED tests that are a consequence
of the two tests above failing and crashing GDB.
2018-05-22 10:25:50 -04:00
Maciej W. Rozycki 75d74ccace MIPS/Linux: Disable n32 USR `ptrace' accesses to 64-bit registers
On the MIPS target DSP ASE registers can only be accessed with the
PTRACE_PEEKUSR and PTRACE_POKEUSR `ptrace' requests.  With the n32 ABI
these requests only pass 32-bit data quantities, which are narrower than
the width of DSP accumulator registers, which are 64-bit.

Generic code is prepared to transfer registers wider than the `ptrace'
data type by offsetting into the USR address space, by the data width
transferred.  That however does not work with the MIPS target, because
of how the API has been defined, where USR register addresses are
actually indices rather than offsets.  Consequently given address `a'
using `a + 4' accesses the fourth next register rather than the upper
half of the original register.

With native debugging this causes clobbered register contents, as well
as access failures as locations beyond the available USR space are
addressed:

(gdb) info registers
                  zero               at               v0               v1
 R0   0000000000000000 0000000000000001 0000000000000001 0000000000000000
                    a0               a1               a2               a3
 R4   0000000010019158 0000000000000000 0000000000000011 0000000010019160
                    a4               a5               a6               a7
 R8   0000000010019160 fffffffffff00000 fffffffffffffff8 0000000000000000
                    t0               t1               t2               t3
 R12  0000000010019150 0000000000000001 0000000000000001 000000000000000f
                    s0               s1               s2               s3
 R16  0000000077ee6f20 0000000010007bb0 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  000000000052e668 000000000052f008 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000001 0000000010019010 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  0000000010020280 000000007fff4c10 000000007fff4c10 0000000010004f48
                status               lo               hi         badvaddr
      0000000000109cf3 0000000000943efe 000000000000000e 000000001001900c
                 cause               pc
      0000000000800024 0000000010004f48
                  fcsr              fir              hi1              lo1
              0e800000         00f30000 0000000004040404 0101010105050505
                   hi2              lo2              hi3              lo3
      0202020255aa33cc Couldn't read register  (#75): Input/output error.
(gdb)

With `gdbserver' this makes debugging impossible due to a fatal failure:

(gdb) target remote :2346
Remote debugging using :2346
Reading symbols from .../sysroot/mips-r2-hard/lib32/ld.so.1...done.
0x77fc3d50 in __start () from .../sysroot/mips-r2-hard/lib32/ld.so.1
(gdb) continue
Continuing.
warning: Remote failure reply: E01
Remote communication error.  Target disconnected.: Connection reset by peer.
(gdb)

Correct the problem by marking any register in the MIPS backend whose
width exceeds the width of the `ptrace' data type unavailable for the
purpose of PTRACE_PEEKUSR and PTRACE_POKEUSR requests:

(gdb) info registers
                  zero               at               v0               v1
 R0   0000000000000000 0000000000000001 0000000000000001 0000000000000000
                    a0               a1               a2               a3
 R4   0000000010019158 0000000000000000 0000000000000011 0000000010019160
                    a4               a5               a6               a7
 R8   0000000010019160 fffffffffff00000 fffffffffffffff8 0000000000000000
                    t0               t1               t2               t3
 R12  0000000010019150 0000000000000001 0000000000000001 000000000000000f
                    s0               s1               s2               s3
 R16  0000000077ee6f20 0000000010007bb0 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  000000000052e5c8 000000000052f008 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000001 0000000010019010 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  0000000010020280 000000007fff4be0 000000007fff4be0 0000000010004f48
                status               lo               hi         badvaddr
      0000000000109cf3 0000000000943efe 000000000000000e 000000001001900c
                 cause               pc
      0000000000800024 0000000010004f48
                  fcsr              fir              hi1              lo1
              0e800000         00f30000    <unavailable>    <unavailable>
                   hi2              lo2              hi3              lo3
         <unavailable>    <unavailable>    <unavailable>    <unavailable>
                dspctl          restart
              55aa33cc 0000000000000000
(gdb)

as there is no way to access full contents of these registers with the
limited API available anyway.

This obviously does not affect general-purpose registers (which use the
PTRACE_GETREGS and PTRACE_SETREGS requests for access) or floating-point
general registers (which use PTRACE_GETFPREGS and PTRACE_SETFPREGS).
And $dspctl, being 32-bit, remains accessible too, which is important
for BPOSGE32 branch decoding in single-stepping.

For DSP accumulator access with the n32 ABI a new `ptrace' API is required
on the kernel side.

	gdb/
	* mips-linux-nat.c (mips64_linux_register_addr): Return -1 if
	the width of the requested register exceeds the width of the
	`ptrace' data type.

	gdb/gdbserver/
	* linux-mips-low.c (mips_cannot_fetch_register): Return 1 if the
	width of the requested register exceeds the width of the
	`ptrace' data type.
	(mips_cannot_store_register): Likewise.
2018-05-22 01:52:35 +01:00
Maciej W. Rozycki e4439e4346 MIPS/gdbserver: Fix issues with $zero register reads
Consistently supply hardwired $zero as a zeroed register, correcting
issues with the PTRACE_GETREGS path that currently copies the value of
$restart into $zero as illustrated by this program:

$ cat read.c

int
main (void)
{
  char buf[1024];
  ssize_t size;

  size = read (0, buf, sizeof (buf));

  return size;
}
$

and this corresponding debug session:

(gdb) break main
Breakpoint 1 at 0x120000970: file read.c, line 9.
(gdb) target remote :2346
Remote debugging using :2346
Reading symbols from .../sysroot/mips-r2-hard/lib64/ld.so.1...done.
0x000000fff7fca5a0 in __start ()
   from .../sysroot/mips-r2-hard/lib64/ld.so.1
(gdb) continue
Continuing.

Breakpoint 1, main () at read.c:9
9	  size = read (0, buf, sizeof (buf));
(gdb) info registers
                  zero               at               v0               v1
 R0   0000000000000000 0000000000000001 000000fff7ffe710 0000000000000000
                    a0               a1               a2               a3
 R4   0000000000000001 000000ffffffeb88 000000ffffffeb98 0000000000000000
                    a4               a5               a6               a7
 R8   000000fff7fc8800 000000fff7fc38f0 000000ffffffeb80 2f2f2f2f2f2f2f2f
                    t0               t1               t2               t3
 R12  0000000000000437 0000000000000002 000000fff7ffd000 0000000120000a00
                    s0               s1               s2               s3
 R16  000000fff7fc7068 0000000120000b90 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  0000000000521d88 0000000000522608 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000000 0000000120000970 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  000000fff7fc8800 000000ffffffea50 0000000000000000 000000fff7e4088c
                status               lo               hi         badvaddr
      0000000000109cf3 0000000000005ea5 0000000000000211 000000fff7eadf00
                 cause               pc
      0000000000800024 0000000120000970
                  fcsr              fir          restart
              00000000         00f30000 0000000000000000
(gdb) continue
Continuing.
^C

Program received signal SIGINT, Interrupt.
0x000000fff7f084ac in __GI___libc_read (fd=0, buf=0xffffffe640, nbytes=1024)
    at ../sysdeps/unix/sysv/linux/read.c:27
27	  return SYSCALL_CANCEL (read, fd, buf, nbytes);
(gdb) info registers
                  zero               at               v0               v1
 R0   0000000000001388 0000000000000001 0000000000000200 000000fff7ffe710
                    a0               a1               a2               a3
 R4   0000000000000000 000000ffffffe640 0000000000000400 0000000000000001
                    a4               a5               a6               a7
 R8   000000fff7fc8800 000000fff7fc38f0 000000ffffffeb80 2f2f2f2f2f2f2f2f
                    t0               t1               t2               t3
 R12  00000000000005e3 0000000000000002 000000fff7ffd000 000000012000099c
                    s0               s1               s2               s3
 R16  000000fff7fc7068 0000000120000b90 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  0000000000521d88 0000000000522608 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000000 000000fff7f2da20 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  000000fff7fc8800 000000ffffffe600 0000000000000000 000000012000099c
                status               lo               hi         badvaddr
      0000000000109cf3 00000000000001e6 00000000000000be 000000fff7f08470
                 cause               pc
      0000000000800020 000000fff7f084ac
                  fcsr              fir          restart
              00000000         00f30000 0000000000001388
(gdb)

and with the PTRACE_PEEKUSR path that does not supply this register at
all, causing issues analogous to ones addressed for the native MIPS
backend with commit 4e6ff0e1b8 ("MIPS/Linux/native: Supply $zero for
the !PTRACE_GETREGS case"):

(gdb) info registers
                  zero               at               v0               v1
 R0      <unavailable> 0000000000000001 0000000000000001 0000000000000000
                    a0               a1               a2               a3
 R4   00000001200212b0 0000000000000000 0000000000000021 000000012001a260
                    a4               a5               a6               a7
 R8   000000012001a260 0000000000000004 800000010cab1680 fffffffffffffff8
                    t0               t1               t2               t3
 R12  0000000000000000 000000fff7edab68 0000000000000001 0000000000000000
                    s0               s1               s2               s3
 R16  000000fff7ee2068 0000000120008b80 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  000000000052e5c8 000000000052f008 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000000 00000001200027c0 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  00000001200212b0 000000ffffffc880 000000ffffffc880 0000000120005ee8
                status               lo               hi         badvaddr
         <unavailable> 0000000000943efe 000000000000000e 000000012001a008
                 cause               pc
      0000000000800024 0000000120005ee8
                  fcsr              fir          restart
              0e800000         00f30000 0000000000000000
(gdb)

and (under certain circumstances):

(gdb) next
Register 0 is not available
(gdb)

The problem with PTRACE_GETREGS happens because `mips_store_gregset'
supplies the contents of register slot #0, occupied by $restart, to
$zero.  The problem with PTRACE_PEEKUSR happens because for $zero
`mips_cannot_fetch_register' returns one, and no alternative way to
supply that register has been defined.

Correct `mips_store_gregset' then for the PTRACE_GETREGS case and add
`mips_fetch_register' for the PTRACE_PEEKUSR case.

	gdb/gdbserver/
	* linux-mips-low.c (mips_fetch_register): New function.  Update
	preceding comment.
	(mips_store_gregset): Supply 0 rather than $restart for $zero.
	(the_low_target): Wire `mips_fetch_register'.
2018-05-22 00:55:08 +01:00
Tom Tromey 122b53ea6a Remove output_command_const
I happened to notice that output_command_const still exists, but is
not needed any more -- commands are always const-correct now.  This
patch removes this leftover.

2018-05-21  Tom Tromey  <tom@tromey.com>

	* printcmd.c (output_command): Remove.
	(output_command_const): Rename to output_command.
	* valprint.h (output_command): Rename from output_command_const.
	* tracepoint.c (trace_dump_actions): Call output_command.
2018-05-21 13:29:10 -06:00
Tom Tromey bc18fbb575 Change ada_catchpoint::excep_string to be a std::string
This changes ada_catchpoint::excep_string to be a std::string and then
fixes up all t he users.

This found a memory leak in catch_ada_exception_command_split, where
"cond" was copied but never freed.

I changed the type of the "cond_string" argument to
catch_ada_exception_command_split to follow the rule that out
parameters should be pointers and not references.

This patch enables the removal of some cleanups and also the function
ada_get_next_arg.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* mi/mi-cmd-catch.c (mi_cmd_catch_assert)
	(mi_cmd_catch_exception, mi_cmd_catch_handlers): Update.
	* ada-lang.h (create_ada_exception_catchpoint): Update.
	* ada-lang.c (struct ada_catchpoint) <excep_string>: Now a
	std::string.
	(create_excep_cond_exprs, ~ada_catchpoint)
	(should_stop_exception, print_one_exception)
	(print_mention_exception, print_recreate_exception): Update.
	(ada_get_next_arg): Remove.
	(catch_ada_exception_command_split): Use std::string.  Change type
	of "excep_string", "cond_string".
	(catch_ada_exception_command): Update.
	(create_ada_exception_catchpoint): Change type of excep_string.
	(ada_exception_sal): Remove excep_string parameter.
	(~ada_catchpoint): Remove.
2018-05-21 10:01:15 -06:00
Tom Tromey 790217f673 Remove cleanup from ada_collect_symbol_completion_matches
ada_collect_symbol_completion_matches installs a null_cleanup but not
any other cleanups.  This patch removes it.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_collect_symbol_completion_matches): Remove
	cleanup.
2018-05-21 10:01:15 -06:00
Tom Tromey 6f46ac8531 Remove cleanup from ada-lang.c
This removes a cleanup from ada-lang.c by having
ada_exception_message_1 return a unique_xmalloc_ptr.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_exception_message_1, ada_exception_message):
	Return unique_xmalloc_ptr.
	(print_it_exception): Update.
2018-05-21 10:01:14 -06:00
Tom Tromey 15b6611c69 Remove a cleanup from trace_dump_actions
This changes trace_dump_actions to use std::string, removing a
cleanup.

Tested by the buildbot.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (trace_dump_actions): Use std::string.
2018-05-21 09:53:15 -06:00
Tom Tromey c0c9f665d9 Use std::string in reread_symbols
This removes a cleanup from reread_symbols by using std::string.  This
fixes a memory leak, because this cleanup is ordinarily discarded, not
run.

Tested by the buildbot.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* symfile.c (reread_symbols): Use std::string for original_name.
2018-05-21 09:38:36 -06:00
Tom Tromey 22ca247e9e Use std::unique_ptr in dwarf2_read_debug_names
This changes dwarf2_read_debug_names to use std::unique_ptr from the
outset.  This simplifies the code that installs the resulting map into
dwarf2_per_objfile.

Tested by the buildbot.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_read_debug_names): Use std::unique_ptr.
	(mapped_index_base): Use DISABLE_COPY_AND_ASSIGN.  Default
	constructor.
2018-05-21 09:36:33 -06:00
Simon Marchi 184cde7552 Fix copy-pasto, allocate objfile_per_bfd_storage with obstack_new
I realized after pushing that I made a copy-pasto, I had:

  # define HAVE_IS_TRIVIALLY_COPYABLE 1

instead of

  # define HAVE_IS_TRIVIALLY_CONSTRUCTIBLE 1

with the consequence that IsMallocable was always std::true_type (and
was therefore not enforcing anything).  Fixing that mistake triggered a
build failure:

/home/simark/src/binutils-gdb/gdb/objfiles.c:150:12:   required from here
/home/simark/src/binutils-gdb/gdb/common/poison.h:228:3: error: static assertion failed: Trying to use XOBNEW with a non-POD data type.

I am not sure why I did not see this when I originally wrote the patch
(but I saw and fixed other failures).  In any case, I swapped XOBNEW
with obstack_new to get rid of it.

Regtested on the buildbot.

gdb/ChangeLog:

	* common/traits.h (HAVE_IS_TRIVIALLY_COPYABLE): Rename the wrong
	instance to...
	(HAVE_IS_TRIVIALLY_CONSTRUCTIBLE): ... this.
	* objfiles.c (get_objfile_bfd_data): Allocate
	objfile_per_bfd_storage with obstack_new when allocating on
	obstack.
2018-05-20 23:19:35 -04:00
Simon Marchi e39db4db7c Use XOBNEW/XOBNEWVEC/OBSTACK_ZALLOC when possible
Since XOBNEW/XOBNEWVEC/OBSTACK_ZALLOC are now poisoned to prevent using
them with non-trivially-constructible objects, it is worth using them
over plain obstack_alloc.  This patch changes the locations I could find
where we can do that change easily.

gdb/ChangeLog:

	* ada-lang.c (cache_symbol): Use XOBNEW and/or XOBNEWVEC and/or
	OBSTACK_ZALLOC.
	* dwarf2-frame.c (dwarf2_build_frame_info): Likewise.
	* hppa-tdep.c (hppa_init_objfile_priv_data): Likewise.
	* mdebugread.c (mdebug_build_psymtabs): Likewise.
	(add_pending): Likewise.
	(parse_symbol): Likewise.
	(parse_partial_symbols): Likewise.
	(psymtab_to_symtab_1): Likewise.
	(new_psymtab): Likewise.
	(elfmdebug_build_psymtabs): Likewise.
	* minsyms.c (terminate_minimal_symbol_table): Likewise.
	* objfiles.c (get_objfile_bfd_data): Likewise.
	(objfile_register_static_link): Likewise.
	* psymtab.c (allocate_psymtab): Likewise.
	* stabsread.c (read_member_functions): Likewise.
	* xcoffread.c (xcoff_end_psymtab): Likewise.
2018-05-20 21:07:03 -04:00
Simon Marchi 284a0e3cbf Introduce obstack_new, poison other "typed" obstack functions
Since we use obstacks with objects that are not default constructible,
we sometimes need to manually call the constructor by hand using
placement new:

  foo *f = obstack_alloc (obstack, sizeof (foo));
  f = new (f) foo;

It's possible to use allocate_on_obstack instead, but there are types
that we sometimes want to allocate on an obstack, and sometimes on the
regular heap.  This patch introduces a utility to make this pattern
simpler if allocate_on_obstack is not an option:

  foo *f = obstack_new<foo> (obstack);

Right now there's only one usage (in tdesc_data_init).

To help catch places where we would forget to call new when allocating
such an object on an obstack, this patch also poisons some other methods
of allocating an instance of a type on an obstack:

  - OBSTACK_ZALLOC/OBSTACK_CALLOC
  - XOBNEW/XOBNEW
  - GDBARCH_OBSTACK_ZALLOC/GDBARCH_OBSTACK_CALLOC

Unfortunately, there's no way to catch wrong usages of obstack_alloc.

By pulling on that string though, it tripped on allocating struct
template_symbol using OBSTACK_ZALLOC.  The criterion currently used to
know whether it's safe to "malloc" an instance of a struct is whether it
is a POD.  Because it inherits from struct symbol, template_symbol is
not a POD.  This criterion is a bit too strict however, it should still
safe to allocate memory for a template_symbol and memset it to 0.  We
didn't use is_trivially_constructible as the criterion in the first
place only because it is not available in gcc < 5.  So here I considered
two alternatives:

1. Relax that criterion to use std::is_trivially_constructible and add a
   bit more glue code to make it work with gcc < 5
2. Continue pulling on the string and change how the symbol structures
   are allocated and initialized

I managed to do both, but I decided to go with #1 to keep this patch
simpler and more focused.  When building with a compiler that does not
have is_trivially_constructible, the check will just not be enforced.

gdb/ChangeLog:

	* common/traits.h (HAVE_IS_TRIVIALLY_COPYABLE): Define if
	compiler supports std::is_trivially_constructible.
	* common/poison.h: Include obstack.h.
	(IsMallocable): Define to is_trivially_constructible if the
	compiler supports it, define to true_type otherwise.
	(xobnew): New.
	(XOBNEW): Redefine.
	(xobnewvec): New.
	(XOBNEWVEC): Redefine.
	* gdb_obstack.h (obstack_zalloc): New.
	(OBSTACK_ZALLOC): Redefine.
	(obstack_calloc): New.
	(OBSTACK_CALLOC): Redefine.
	(obstack_new): New.
	* gdbarch.sh: Include gdb_obstack in gdbarch.h.
	(gdbarch_obstack): New declaration in gdbarch.h, definition in
	gdbarch.c.
	(GDBARCH_OBSTACK_CALLOC, GDBARCH_OBSTACK_ZALLOC): Use
	obstack_calloc/obstack_zalloc.
	(gdbarch_obstack_zalloc): Remove.
	* target-descriptions.c (tdesc_data_init): Use obstack_new.
2018-05-20 21:06:36 -04:00
Philippe Waroquiers 59f66be3ac Remove useless variable int i in backtrace_command_1
value of int i was not used in the loop or after the loop.
Pushed as obvious.
2018-05-19 08:54:44 +02:00
Philippe Waroquiers 50c65c2d60 Fix reference in comment: SRC_AND_LOC instead of LOC_AND_SRC
Pushed as obvious
2018-05-19 08:38:57 +02:00
Tom Tromey 7ff8cb8c51 Allocate dwz_file with new
This adds a constructor to struct dwz_file and arranges for it to be
allocated with "new" and wrapped in a unique_ptr.  This cuts down on
the amount of manual memory management that must be done.

Regression tested by the buildbot.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct dwz_file): Add constructor, initializers.
	<dwz_bfd>: Now a gdb_bfd_ref_ptr.
	(~dwarf2_per_objfile): Update
	(dwarf2_get_dwz_file): Use new.
	* dwarf2read.h (struct dwarf2_per_objfile) <dwz_file>: Now a
	unique_ptr.
2018-05-18 15:12:14 -06:00
Tom Tromey 400174b12a Allocate dwp_file with new
This adds a constructor and initializer to dwp_file and changes it to
be allocated with "new".  This removes a bit of manual refcount
management.

Tested by the buildbot.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (struct dwarf2_per_objfile) <dwp_file>: Now a
	unique_ptr.
	* dwarf2read.c (struct dwp_file): Add constructor and
	initializers.
	(open_and_init_dwp_file): Return a unique_ptr.
	(dwarf2_per_objfile, create_dwp_hash_table)
	(create_dwo_unit_in_dwp_v1, create_dwo_unit_in_dwp_v2)
	(lookup_dwo_unit_in_dwp): Update.
	(open_and_init_dwp_file, get_dwp_file): Update.
2018-05-18 14:33:24 -06:00
Tom Tromey 3063847f29 Use new to allocate mapped_index
This changes struct mapped_index to be allocated with new.  This
simplifies the creation a bit (see dwarf2_read_index) and also removes
a somewhat ugly explicit destructor call from ~dwarf2_per_objfile.

Tested by the buildbot.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_per_objfile): Update.
	(struct mapped_index): Add initializers.
	(dwarf2_read_index): Use new.
	(dw2_symtab_iter_init): Update.
	* dwarf2read.h (struct dwarf2_per_objfile) <index_table>: Now a
	unique_ptr.
2018-05-18 14:10:09 -06:00
Simon Marchi d3d02dee8d Remove mapped_index::total_size
It is unused.

gdb/ChangeLog:

	* dwarf2read.c (mapped_index) <total_size>: Remove.
2018-05-18 16:02:44 -04:00
Simon Marchi 1d143c36ee format_pieces-selftests.c: Silence ARI warnings
Silence this:

unittests/format_pieces-selftests.c:51: warning: code: Do not use printf("%ll"), instead use printf("%s",phex()) to dump a `long long' value
unittests/format_pieces-selftests.c:56: warning: code: Do not use printf("%ll"), instead use printf("%s",phex()) to dump a `long long' value

gdb/ChangeLog:

	* unittests/format_pieces-selftests.c (test_format_specifier):
	Add ARI comments.
2018-05-18 15:47:56 -04:00
Tom Tromey ce1e8424c6 Show padding in ptype/o output
I was recently using ptype/o to look at the layout of some objects in
gdb.  I noticed that trailing padding was not shown -- but I wanted to
be able to look at that, too.

This patch changes ptype/o to also print trailing holes.

Tested on x86-64 Fedora 26.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* c-typeprint.c (maybe_print_hole): New function.
	(c_print_type_struct_field_offset): Update.
	(c_type_print_base_struct_union): Call maybe_print_hole.

gdb/testsuite/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* gdb.base/ptype-offsets.exp: Update.
2018-05-18 13:20:39 -06:00
Keith Seitz ddfe970e6b Don't elide all inlined frames
This patch essentially causes GDB to treat inlined frames like "normal"
frames from the user's perspective.  This means, for example, that when a
user sets a breakpoint in an inlined function, GDB will now actually stop
"in" that function.

Using the test case from breakpoints/17534,

3	static inline void NVIC_EnableIRQ(int IRQn)
4	{
5	  volatile int y;
6	  y = IRQn;
7	}
8
9	__attribute__( ( always_inline ) ) static inline void __WFI(void)
10	{
11	    __asm volatile ("nop");
12	}
13
14	int main(void) {
15
16	    x= 42;
17
18	    if (x)
19	      NVIC_EnableIRQ(16);
20	    else
21	      NVIC_EnableIRQ(18);
(gdb) b NVIC_EnableIRQ
Breakpoint 1 at 0x4003e4: NVIC_EnableIRQ. (2 locations)
(gdb) r
Starting program: 17534

Breakpoint 1, main () at 17534.c:19
19	      NVIC_EnableIRQ(16);

Because skip_inline_frames currently skips every inlined frame, GDB "stops"
in the caller.  This patch adds a new parameter to skip_inline_frames
that allows us to pass in a bpstat stop chain.  The breakpoint locations
on the stop chain can be used to determine if we've stopped inside an inline
function (due to a user breakpoint).  If we have, we do not elide the frame.

With this patch, GDB now reports that the inferior has stopped inside the
inlined function:

(gdb) r
Starting program: 17534

Breakpoint 1, NVIC_EnableIRQ (IRQn=16) at 17534.c:6
6	  y = IRQn;

Many thanks to Jan and Pedro for guidance on this.

gdb/ChangeLog:

	* breakpoint.c (build_bpstat_chain): New function, moved from
	bpstat_stop_status.
	(bpstat_stop_status): Add optional parameter, `stop_chain'.
	If no stop chain is passed, call build_bpstat_chain to build it.
	* breakpoint.h (build_bpstat_chain): Declare.
	(bpstat_stop_status): Move documentation here from breakpoint.c.
	* infrun.c (handle_signal_stop): Before eliding inlined frames,
	build the stop chain and pass it to skip_inline_frames.
	Pass this stop chain to bpstat_stop_status.
	* inline-frame.c: Include breakpoint.h.
	(stopped_by_user_bp_inline_frame): New function.
	(skip_inline_frames): Add parameter `stop_chain'.
	Move documention to inline-frame.h.
	If non-NULL, use stopped_by_user_bp_inline_frame to determine
	whether the frame should be elided.
	* inline-frame.h (skip_inline_frames): Add parameter `stop_chain'.
	Add moved documentation and update for new parameter.

gdb/testsuite/ChangeLog:

	* gdb.ada/bp_inlined_func.exp: Update inlined frame locations
	in expected breakpoint stop locations.
	* gdb.dwarf2/implptr.exp (implptr_test_baz): Use up/down to
	move to proper scope to test variable values.
	* gdb.opt/inline-break.c (inline_func1, not_inline_func1)
	(inline_func2, not_inline_func2, inline_func3, not_inline_func3):
	New functions.
	(main): Call not_inline_func3.
	* gdb.opt/inline-break.exp: Start inferior and set breakpoints at
	inline_func1, inline_func2, and inline_func3.  Test that when each
	breakpoint is hit, GDB properly reports both the stop location
	and the backtrace. Repeat tests for temporary breakpoints.
2018-05-17 12:15:11 -07:00
Simon Marchi b17992c1c0 Make format_pieces recognize the \e escape sequence
I noticed that the printf command did not recognize the \e escape
sequence, used amongst other things to use colors:

  (gdb) printf "This is \e[32mgreen\e[m!\n"
  Unrecognized escape character \e in format string.

This patch makes format_pieces recognize it, which makes that command
print the expected result in glorious color.

I wrote a really simple unit test for format_pieces.
format_pieces::operator[] is unused so I removed it.  I added
format_piece::operator==, which is needed to compare vectors of
format_piece.

gdb/ChangeLog:

	PR cli/14975
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/format_pieces-selftests.c.
	* common/format.h (format_piece) <operator==>: New.
	(format_pieces) <operator[]>: Remove.
	* common/format.c (format_pieces::format_pieces): Handle \e.
	* unittests/format_pieces-selftests.c: New.
2018-05-17 13:06:11 -04:00
Tom Tromey 58f0c71853 Fix for dwz-related crash
PR symtab/23010 reports a crash that occurs when using -readnow
on a dwz-generated debuginfo file.

The crash occurs because the DWARF has a partial CU with no language
set, and then a full CU that references this partial CU using
DW_AT_abstract_origin.

In this case, the partial CU is read by dw2_expand_all_symtabs using
language_minimal; but then this conflicts with the creation of the
block's symbol table in the C++ CU.

This patch fixes the problem by arranging for partial CUs not to be
read by -readnow.  I tend to think that it doesn't make sense to read
a partial CU in isolation -- they should only be read when imported
into some other CU.

In conjunction with some other patches I am going to post, this also
fixes the Rust -readnow crash that Jan reported.

There are two problems with this patch:

1. It is difficult to reason about.  There are many cases where I've
   patched the code to call init_cutu_and_read_dies with the flag set
   to "please do read partial units" -- but I find it difficult to be
   sure that this is always correct.

2. It is still missing a standalone test case.  This seemed hard.

2018-05-17  Tom Tromey  <tom@tromey.com>

	PR symtab/23010:
	* dwarf2read.c (load_cu, dw2_do_instantiate_symtab)
	(dw2_instantiate_symtab): Add skip_partial parameter.
	(dw2_find_last_source_symtab, dw2_map_expand_apply)
	(dw2_lookup_symbol, dw2_expand_symtabs_for_function)
	(dw2_expand_all_symtabs, dw2_expand_symtabs_with_fullname)
	(dw2_expand_symtabs_matching_one)
	(dw2_find_pc_sect_compunit_symtab)
	(dw2_debug_names_lookup_symbol)
	(dw2_debug_names_expand_symtabs_for_function): Update.
	(init_cutu_and_read_dies): Add skip_partial parameter.
	(process_psymtab_comp_unit, build_type_psymtabs_1)
	(process_skeletonless_type_unit, load_partial_comp_unit)
	(psymtab_to_symtab_1): Update.
	(load_full_comp_unit): Add skip_partial parameter.
	(process_imported_unit_die, dwarf2_read_addr_index)
	(follow_die_offset, dwarf2_fetch_die_loc_sect_off)
	(dwarf2_fetch_constant_bytes, dwarf2_fetch_die_type_sect_off)
	(read_signatured_type): Update.
2018-05-17 10:25:02 -06:00
Simon Marchi 3e6188349f value.c: Remove unused variables
Obvious patch to remove unused local variables (found by adding
-Wunused).  I didn't touch this one in value_fetch_lazy, because
check_typedef could have a desired side-effect.

  3743  struct type *type = check_typedef (value_type (val));

gdb/ChangeLog:

	* value.c (release_value): Remove unused variable.
	(record_latest_value): Likewise.
	(access_value_history): Likewise.
	(preserve_values): Likewise.
2018-05-17 09:52:08 -04:00
Tom Tromey fe10fe3131 Initialize py_type_printers in ext_lang_type_printers
When running gdb in the build directory without passing
--data-directory, I noticed I could provoke a crash by:

    $ ./gdb -nx ./gdb
    (gdb) ptype/o struct dwarf2_per_objfile

... and then trying to "q" out at the pagination prompt.

valgrind complained about an uninitialized use of py_type_printers.
Initializing this member fixes the bug.

I believe this bug can occur even when the gdb Python libraries are
available, for example if get_type_recognizers fails.

Tested by hand on x86-64 Fedora 26.  No test case because it seemed
difficult to guarantee failures.

gdb/ChangeLog
2018-05-17  Tom Tromey  <tom@tromey.com>

	* extension.h (struct ext_lang_type_printers) <py_type_printers>:
	Initialize.
2018-05-17 07:29:12 -06:00
Maciej W. Rozycki 1d7611244c PR gdb/22286: linux-nat-trad: Support arbitrary register widths
Update `fetch_register' and `store_register' code to support arbitrary
register widths rather than only ones that are a multiply of the size of
the `ptrace' data type used with PTRACE_PEEKUSR and PTRACE_POKEUSR
requests to access registers.  Remove associated assertions, correcting
an issue with accessing the DSPControl (`$dspctl') register on n64 MIPS
native targets:

(gdb) print /x $dspctl
.../gdb/linux-nat-trad.c:50: internal-error: void linux_nat_trad_target::fetch_register(regcache*, int): Assertion `(size % sizeof (PTRACE_TYPE_RET)) == 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.

.../gdb/linux-nat-trad.c:50: internal-error: void linux_nat_trad_target::fetch_register(regcache*, int): Assertion `(size % sizeof (PTRACE_TYPE_RET)) == 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n
Command aborted.
(gdb)

All registers are now reported correctly and their architectural
hardware widths respected:

(gdb) print /x $dspctl
$1 = 0x55aa33cc
(gdb) info registers
                  zero               at               v0               v1
 R0   0000000000000000 0000000000000001 000000fff7ffeb20 0000000000000000
                    a0               a1               a2               a3
 R4   0000000000000001 000000ffffffeaf8 000000ffffffeb08 0000000000000000
                    a4               a5               a6               a7
 R8   000000fff7ee3800 000000fff7ede8f0 000000ffffffeaf0 2f2f2f2f2f2f2f2f
                    t0               t1               t2               t3
 R12  0000000000000437 0000000000000002 000000fff7ffd000 0000000120000ad0
                    s0               s1               s2               s3
 R16  000000fff7ee2068 0000000120000e60 0000000000000000 0000000000000000
                    s4               s5               s6               s7
 R20  0000000000521ec8 0000000000522608 0000000000000000 0000000000000000
                    t8               t9               k0               k1
 R24  0000000000000000 0000000120000d9c 0000000000000000 0000000000000000
                    gp               sp               s8               ra
 R28  0000000120019030 000000ffffffe990 000000ffffffe990 000000fff7d5b88c
                status               lo               hi         badvaddr
      0000000000109cf3 0000000000005ea5 0000000000000211 000000fff7fc6fe0
                 cause               pc
      0000000000800024 0000000120000dbc
                  fcsr              fir              hi1              lo1
              00000000         00f30000 0000000000000000 0101010101010101
                   hi2              lo2              hi3              lo3
      0202020202020202 0303030303030303 0404040404040404 0505050505050505
                dspctl          restart
              55aa33cc 0000000000000000
(gdb)

NB due to the lack of access to 64-bit DSP hardware all DSP register
values in the dumps are artificial and have been created with a debug
change applied to the kernel handler of the `ptrace' syscall.

The use of `store_unsigned_integer' and `extract_unsigned_integer'
unconditionally in all cases rather than when actual data occupies a
part of the data quantity exchanged with `ptrace' makes code perhaps
marginally slower, however I think avoiding it is not worth code
obfuscation it would cause.  If this turns out unfounded, then there
should be no problem with optimizing this code later.

	gdb/
	PR gdb/22286
	* linux-nat-trad.c (linux_nat_trad_target::fetch_register):
	Also handle registers whose width is not a multiple of
	PTRACE_TYPE_RET.
	(linux_nat_trad_target::store_register): Likewise.
2018-05-16 20:43:30 +01:00
Tom Tromey 06333fea76 Make "cbfd" a gdb_bfd_ref_ptr
This changes program_space::cbfd to be a gdb_bfd_ref_ptr.  This makes
it somewhat less error-prone to use, because now it manages the
reference counting automatically.

Tested by the buildbot.

2018-05-16  Tom Tromey  <tom@tromey.com>

	* gdbcore.h (core_bfd): Redefine.
	* corelow.c (core_target::close): Update.
	(core_target_open): Update.
	* progspace.h (struct program_space) <cbfd>: Now a
	gdb_bfd_ref_ptr.
2018-05-16 11:45:03 -06:00
Tom Tromey 921222e2e8 Use a distinguishing name for minidebug objfile
One part of PR cli/19551 is that the mini debug info objfile reuses the
name of the main objfile from which it comes.  This can be seen because
gdb claims to be reading symbols from the same file two times, like:

Reading symbols from /bin/gdb...Reading symbols from /bin/gdb...(no debugging symbols found)...done.

I think this would be less confusing if the minidebug objfile were given
a different name.  That is what this patch implements.  It also arranges
for the minidebug objfile to be marked OBJF_NOT_FILENAME.

After this patch the output looks like:

Reading symbols from /bin/gdb...Reading symbols from .gnu_debugdata for /usr/libexec/gdb...(no debugging symbols found)...done.

Tested by the buildbot.

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

	PR cli/19551:
	* symfile-add-flags.h (enum symfile_add_flags)
	<SYMFILE_NOT_FILENAME>: New constant.
	* symfile.c (read_symbols): Use SYMFILE_NOT_FILENAME.  Get
	objfile name from BFD.
	(symbol_file_add_with_addrs): Check SYMFILE_NOT_FILENAME.
	* minidebug.c (find_separate_debug_file_in_section): Put
	".gnu_debugdata" into BFD's file name.
2018-05-16 11:15:25 -06:00
Simon Marchi 3acb7083a6 regcache.c: Remove unused typedefs
gdb/ChangeLog:

	* regcache.c (regcache_read_ftype, regcache_write_ftype):
	Remove.
2018-05-16 12:41:19 -04:00
Tamar Christina 561a72d4dd Modify AArch64 Assembly and disassembly functions to be able to fail and report why.
This patch if the first patch in a series to add the ability to add constraints
to system registers that an instruction must adhere to in order for the register
to be usable with that instruction.

These constraints can also be used to disambiguate between registers with the
same encoding during disassembly.

This patch adds a new flags entry in the sysreg structures and ensures it is
filled in and read out during assembly/disassembly. It also adds the ability for
the assemble and disassemble functions to be able to gracefully fail and re-use
the existing error reporting infrastructure.

The return type of these functions are changed to a boolean to denote success or
failure and the error structure is passed around to them. This requires
aarch64-gen changes so a lot of the changes here are just mechanical.

gas/

	PR binutils/21446
	* config/tc-aarch64.c (parse_sys_reg): Return register flags.
	(parse_operands): Fill in register flags.

gdb/

	PR binutils/21446
	* aarch64-tdep.c (aarch64_analyze_prologue,
	aarch64_software_single_step, aarch64_displaced_step_copy_insn):
	Indicate not interested in errors.

include/

	PR binutils/21446
	* opcode/aarch64.h (aarch64_opnd_info): Change sysreg to struct.
	(aarch64_decode_insn): Accept error struct.

opcodes/

	PR binutils/21446
	* aarch64-asm.h (aarch64_insert_operand, aarch64_##x): Return boolean
	and take error struct.
	* aarch64-asm.c (aarch64_ext_regno, aarch64_ins_reglane,
	aarch64_ins_reglist, aarch64_ins_ldst_reglist,
	aarch64_ins_ldst_reglist_r, aarch64_ins_ldst_elemlist,
	aarch64_ins_advsimd_imm_shift, aarch64_ins_imm, aarch64_ins_imm_half,
	aarch64_ins_advsimd_imm_modified, aarch64_ins_fpimm,
	aarch64_ins_imm_rotate1, aarch64_ins_imm_rotate2, aarch64_ins_fbits,
	aarch64_ins_aimm, aarch64_ins_limm_1, aarch64_ins_limm,
	aarch64_ins_inv_limm, aarch64_ins_ft, aarch64_ins_addr_simple,
	aarch64_ins_addr_regoff, aarch64_ins_addr_offset, aarch64_ins_addr_simm,
	aarch64_ins_addr_simm10, aarch64_ins_addr_uimm12,
	aarch64_ins_simd_addr_post, aarch64_ins_cond, aarch64_ins_sysreg,
	aarch64_ins_pstatefield, aarch64_ins_sysins_op, aarch64_ins_barrier,
	aarch64_ins_prfop, aarch64_ins_hint, aarch64_ins_reg_extended,
	aarch64_ins_reg_shifted, aarch64_ins_sve_addr_ri_s4xvl,
	aarch64_ins_sve_addr_ri_s6xvl, aarch64_ins_sve_addr_ri_s9xvl,
	aarch64_ins_sve_addr_ri_s4, aarch64_ins_sve_addr_ri_u6,
	aarch64_ins_sve_addr_rr_lsl, aarch64_ins_sve_addr_rz_xtw,
	aarch64_ins_sve_addr_zi_u5, aarch64_ext_sve_addr_zz,
	aarch64_ins_sve_addr_zz_lsl, aarch64_ins_sve_addr_zz_sxtw,
	aarch64_ins_sve_addr_zz_uxtw, aarch64_ins_sve_aimm,
	aarch64_ins_sve_asimm, aarch64_ins_sve_index, aarch64_ins_sve_limm_mov,
	aarch64_ins_sve_quad_index, aarch64_ins_sve_reglist,
	aarch64_ins_sve_scale, aarch64_ins_sve_shlimm, aarch64_ins_sve_shrimm,
	aarch64_ins_sve_float_half_one, aarch64_ins_sve_float_half_two,
	aarch64_ins_sve_float_zero_one, aarch64_opcode_encode): Likewise.
	* aarch64-dis.h (aarch64_extract_operand, aarch64_##x): Likewise.
	* aarch64-dis.c (aarch64_ext_regno, aarch64_ext_reglane,
	aarch64_ext_reglist, aarch64_ext_ldst_reglist,
	aarch64_ext_ldst_reglist_r, aarch64_ext_ldst_elemlist,
	aarch64_ext_advsimd_imm_shift, aarch64_ext_imm, aarch64_ext_imm_half,
	aarch64_ext_advsimd_imm_modified, aarch64_ext_fpimm,
	aarch64_ext_imm_rotate1, aarch64_ext_imm_rotate2, aarch64_ext_fbits,
	aarch64_ext_aimm, aarch64_ext_limm_1, aarch64_ext_limm, decode_limm,
	aarch64_ext_inv_limm, aarch64_ext_ft, aarch64_ext_addr_simple,
	aarch64_ext_addr_regoff, aarch64_ext_addr_offset, aarch64_ext_addr_simm,
	aarch64_ext_addr_simm10, aarch64_ext_addr_uimm12,
	aarch64_ext_simd_addr_post, aarch64_ext_cond, aarch64_ext_sysreg,
	aarch64_ext_pstatefield, aarch64_ext_sysins_op, aarch64_ext_barrier,
	aarch64_ext_prfop, aarch64_ext_hint, aarch64_ext_reg_extended,
	aarch64_ext_reg_shifted, aarch64_ext_sve_addr_ri_s4xvl,
	aarch64_ext_sve_addr_ri_s6xvl, aarch64_ext_sve_addr_ri_s9xvl,
	aarch64_ext_sve_addr_ri_s4, aarch64_ext_sve_addr_ri_u6,
	aarch64_ext_sve_addr_rr_lsl, aarch64_ext_sve_addr_rz_xtw,
	aarch64_ext_sve_addr_zi_u5, aarch64_ext_sve_addr_zz,
	aarch64_ext_sve_addr_zz_lsl, aarch64_ext_sve_addr_zz_sxtw,
	aarch64_ext_sve_addr_zz_uxtw, aarch64_ext_sve_aimm,
	aarch64_ext_sve_asimm, aarch64_ext_sve_index, aarch64_ext_sve_limm_mov,
	aarch64_ext_sve_quad_index, aarch64_ext_sve_reglist,
	aarch64_ext_sve_scale, aarch64_ext_sve_shlimm, aarch64_ext_sve_shrimm,
	aarch64_ext_sve_float_half_one, aarch64_ext_sve_float_half_two,
	aarch64_ext_sve_float_zero_one, aarch64_opcode_decode): Likewise.
	(determine_disassembling_preference, aarch64_decode_insn,
	print_insn_aarch64_word, print_insn_data): Take errors struct.
	(print_insn_aarch64): Use errors.
	* aarch64-asm-2.c: Regenerate.
	* aarch64-dis-2.c: Regenerate.
	* aarch64-gen.c (print_operand_inserter): Use errors and change type to
	boolean in aarch64_insert_operan.
	(print_operand_extractor): Likewise.
	* aarch64-opc.c (aarch64_print_operand): Use sysreg struct.
2018-05-15 17:17:36 +01:00
Maciej W. Rozycki 4e6ff0e1b8 MIPS/Linux/native: Supply $zero for the !PTRACE_GETREGS case
With native MIPS/Linux targets the $zero register is inaccessible, with
its supposed context slot provided by the OS occupied by the $restart
register.  The PTRACE_GETREGS path takes care of it by artificially
supplying the hardwired contents of $zero in `mips_supply_gregset' or
`mips64_supply_gregset', as applicable, however the PTRACE_PEEKUSER
fallback does not, making the register unavailable, e.g.:

(gdb) info registers
         zero       at       v0       v1       a0       a1       a2       a3
R0    <unavl> 00000001 00000001 d2f1a9fc 00000000 00000000 00417158 00417150
           t0       t1       t2       t3       t4       t5       t6       t7
R8   00000004 00000000 fffffff8 00000000 00000000 00000000 00000001 00000007
           s0       s1       s2       s3       s4       s5       s6       s7
R16  00000000 00405e30 00000000 00500000 00000000 0052ec08 00000000 00000000
           t8       t9       k0       k1       gp       sp       s8       ra
R24  00000000 00417008 00000000 00000000 0041e220 7fff4ce0 7fff4ce0 00405d0c
       status       lo       hi badvaddr    cause       pc
      <unavl> 00441cf1 00000017 00417004 00800024 00405d10
         fcsr      fir  restart
     00800000 00f30000 00000000
(gdb)

or (under certain circumstances):

(gdb) stepi
Register 0 is not available
(gdb)

This is specifically because `mips_linux_register_addr' and
`mips64_linux_register_addr', both correctly return -1 for
MIPS_ZERO_REGNUM, and therefore `linux_nat_trad_target::fetch_registers'
faithfully marks this register as unavailable.

Supply this register artificially then in the PTRACE_PEEKUSER case as
well, correcting this issue.

	gdb/
	* mips-linux-nat.c (mips_linux_nat_target::fetch_registers):
	Supply the MIPS_ZERO_REGNUM register.
2018-05-15 16:26:07 +01:00
Maciej W. Rozycki ea33cd9290 MIPS: Make `mask_address_var' static
Make the `mask_address_var' variable static, it is not used outside
mips-tdep.c and having no target name embedded within it causes a risk
of a namespace clash.

	gdb/
	* mips-tdep.c (mask_address_var): Make variable static.
2018-05-15 16:02:59 +01:00
Maciej W. Rozycki 0726fcc61a testsuite: Fix a `server_pid' access crash in gdb.server/server-kill.exp
Fix a commit f90183d7e3 ("Get GDBserver pid on remote target") bug and
correctly handle the case where the PID of `gdbserver' could not have
been retrieved.  If that happens, $server_pid is unset causing:

FAIL: gdb.server/server-kill.exp: p server_pid
ERROR: tcl error sourcing .../gdb/testsuite/gdb.server/server-kill.exp.
ERROR: can't read "server_pid": no such variable
    while executing
"if {$server_pid == "" } {
    return -1
}"
    (file ".../gdb/testsuite/gdb.server/server-kill.exp" line 49)
    invoked from within
"source .../gdb/testsuite/gdb.server/server-kill.exp"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 source .../gdb/testsuite/gdb.server/server-kill.exp"
    invoked from within
"catch "uplevel #0 source $test_file_name""

Verify that the variable exists then rather than trying to access it.

	gdb/testsuite/
	* gdb.server/server-kill.exp: Verify whether `server_pid' exists
	rather then trying to access it in determining whether the PID
	of `gdbserver' could have been retrieved.
2018-05-15 15:54:36 +01:00
Tom Tromey 2d79090eab Clear rust_unions in rust_union_quirks
It turns out that a dwarf2_cu can remain allocated after psymtab
expansion is done, and so it makes sense to clear rust_unions when
done processing it.

Tested on x86-64 Fedora 27.

2018-05-14  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (rust_union_quirks): Clear rust_unions.
2018-05-14 09:36:56 -06:00
Andrew Burgess cf4912ae57 gdb/x86: Fix write out of mxcsr register for xsave targets
In commit:

  commit 8ee22052f6
  Author: Andrew Burgess <andrew.burgess@embecosm.com>
  Date:   Thu May 3 17:46:14 2018 +0100

      gdb/x86: Handle kernels using compact xsave format

in two places FXSAVE_ADDR was used instead of FXSAVE_MXCSR_ADDR to get
the address of the mxcsr register within the xsave buffer.  This will
mean we are potentially accessing the wrong location within the xsave
buffer.

There are no tests included with this patch.  The first mistake would
only trigger an issue if/when the user tries to manually set the mxcsr
register to a value that matches the random (value off stack) value
that is in the xsave buffer, in this case the change by the user will
go unnoticed by GDB, and the default value of mxcsr will be preserved.

The second mistake only happens on the code path where all x87
registers are being written out of the register cache.  I'm not sure
how to trigger that code path.

gdb/ChangeLog:

	* i387-tdep.c (i387_collect_xsave): Use FXSAVE_MXCSR_ADDR not
	FXSAVE_ADDR for the mxcsr register.
2018-05-11 20:57:05 +01:00
Max Filippov 67e6f569eb gdb: xtensa: drop gdb_target definition
gdb_target definitions were removed from configure.tgt in 2007, before
xtensa port was merged. Remove it from the xtensa target as well.

gdb/
2018-05-11  Max Filippov  <jcmvbkbc@gmail.com>

	* configure.tgt (xtensa*-*-linux*): Drop gdb_target definition.
2018-05-11 11:25:26 -07:00
Pedro Alves 3afc23a681 Fix email address in ChangeLog entry
tromey@redhat.com -> palves@redhat.com
2018-05-11 19:22:26 +01:00
Pedro Alves 1524450719 Heap-allocate core_target instances
This gets rid of the core_ops global, and replaces it with
heap-allocated core_target instances.  In practice, there will only be
one such instance, though that will change further ahead as more
pieces of multi-target support are merged.

Notice that this replaces one heap-allocated object for another, the
number of allocations is the same.  Specifically, currently we
heap-allocate the 'core_data' object, which holds the core's section
table.  With this patch, that object is made a field of the
core_target class, and no longer allocated separately.

Note that this bit:

  -  /* Looks semi-reasonable.  Toss the old core file and work on the
  -     new.  */
  -
  -  unpush_target (&core_ops);

does not need a replacement, because by the time we get here, the
target_preopen call at the top of core_target_open has already
unpushed any previous target.

gdb/ChangeLog:
2018-05-11  Pedro Alves  <palves@redhat.com>

	* corelow.c (core_target) <core_target>: No longer inline.
	Initialize m_core_gdbarch, m_core_vec and build the section table
	here.
	<~core_target>: New.
	<core_gdbarch, get_core_register_section>: New methods.
	<m_core_section_table, m_core_vec, m_core_gdbarch>: New fields,
	factored out from ...
	<core_data, core_vec, core_gdbarch>: ... these deleted globals.
	(core_ops): Delete.
	(sniff_core_bfd): Add gdbarch parameter.
	(core_close): Delete, merged into ...
	(core_target::close): ... here.  Delete self.
	(core_close_cleanup): Delete.
	(core_target_open): Allocate a core_target on the heap.  Use a
	unique_ptr instead of a cleanup.  Bits moved into the core_target
	ctor.  Adjust to use core_target methods instead of globals.
	(get_core_register_section): Rename to ...
	(core_target::get_core_register_section): ... this and adjust.
	(struct get_core_registers_cb_data): New.
	(get_core_registers_cb): Use it.  Use bool.
	(core_target::fetch_registers, core_target::files_info)
	(core_target::xfer_partial, core_target::read_description)
	(core_target::pid_to, core_target::thread_name): Adjust to
	reference class fields instead of globals.
	* target.h (struct target_ops_deleter, target_ops_up): New.
2018-05-11 19:12:21 +01:00
Pedro Alves 451953fa44 Eliminate the 'the_core_target' global
(previously called 'core_target', but since renamed because
'core_target' is the name of the target_ops class now.)

This eliminates the "the_core_target" global, as preparation for being
able to have more than one core loaded.  When we get there, we will
instantiate one core_target object per core instead.

Essentially, this replaces the reference to the_core_target in
core_file_command by a reference to core_bfd, which is per
program_space.

Currently, core_file_command calls 'the_core_target->detach()' even if
the core target is not open and pushed on the target stack.  If it is
indeed not open, then the practical effect is that
core_target::detach() prints "No core file now.".  That is preserved
by printing that directly from within core_file_command if not
debugging a core.

gdb/ChangeLog:
2018-05-11  Pedro Alves  <palves@redhat.com>

	* corefile.c (core_file_command): Move to corelow.c.
	* corelow.c (the_core_target): Delete.
	(core_file_command): Moved from corefile.c.  Check exec_bfd
	instead of the_core_target.  Use target_detach instead of calling
	into the_core_target directly.
	(maybe_say_no_core_file_now): New.
	(core_target::detach): Use it.
	(_initialize_corelow): Remove references to the_core_target.
	* gdbcore.h (the_core_target): Delete.
2018-05-11 19:11:55 +01:00
Tom Tromey e540a5a223 Move core_bfd to program space
This moves the core_bfd global to be a field of the program space.  It
then replaces core_bfd with a macro to avoid a massive patch -- the
same approach taken for various other program space fields.

This is a basic transformation for multi-target work.

2018-05-11  Tom Tromey  <tromey@redhat.com>
	    Pedro Alves  <tromey@redhat.com>

	* corefile.c (core_bfd): Remove.
	* gdbcore.h (core_bfd): Now a macro.
	* progspace.h (struct program_space) <cbfd>: New field.
2018-05-11 19:10:13 +01:00
Tom Tromey 633cf2548b Remove cleanups from mdebugread.c
This removes the remaining cleanups from mdebugread.c, replacing them
with gdb::def_vector.

Tested by the buildbot, though I doubt this exercises mdebugread.

gdb/ChangeLog
2018-05-11  Tom Tromey  <tom@tromey.com>

	* mdebugread.c (parse_partial_symbols, psymtab_to_symtab_1): Use
	gdb::def_vector.
2018-05-11 11:18:16 -06:00
Joel Brobecker 55271bf969 x86 LynxOS-178: Adjust floating-point context structure
The floating point context structure on x86 LynxOS-178 is not
the same as on LynxOS 5.x. As a consequence, trying to print
the return value of a function returning a float, for instance,
yields incorrect results.

This patch fixes the issue by providing an updated definition
for LynxOS-178 (the reason why we cannot access the actual definition
provided by the system still remains true).

gdb/gdbserver/ChangeLog:

        * lynx-i386-low.c (LYNXOS_178): New macro.
        [LYNXOS_178] (usr_fcontext_t): Provide a definition that matches
        the layout on LynxOS-178.
        (lynx_i386_fill_fpregset, lynx_i386_store_fpregset): Do not
        handle floating point registers that are not supported by
        LynxOS-178.
2018-05-10 13:01:39 -04:00
Tom Tromey 1a34f210bb Fix the clang build
Simon pointed out that gdb would not build with clang, due to the
addition of -Wimplicit-fallthrough.  This patch fixes the problem by
using -Wimplicit-fallthrough=3 -- this does not work with clang,
bypassing the issue.

Tested by rebuilding with both gcc and clang; and also by verifying
that -Wimplicit-fallthrough=3 is used in the gcc build.

I will file a follow-up bug to convert the fall-through comments to a
form that can be used by both clang and gcc.

gdb/ChangeLog
2018-05-10  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Use -Wimplicit-fallthrough=3.

gdb/gdbserver/ChangeLog
2018-05-10  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2018-05-10 10:05:35 -06:00
Joel Brobecker 190852c8ac gdbserver/Windows: crash during connection establishment phase
On Windows, starting a new process with GDBserver seems to work,
in the sense that the program does get started, and GDBserver
confirms that it is listening for GDB to connect. However, as soon as
GDB establishes the connection with GDBserver, and starts discussing
with it, GDBserver crashes, with a SEGV.

This SEGV occurs in remote-utils.c::prepare_resume_reply...

  | regp = current_target_desc ()->expedite_regs;
  | [...]
  | while (*regp)

... because, in our case, REGP is NULL.

This patches fixes the issues by adding a parameter to init_target_desc,
in order to make sure that we always provide the list of registers when
we initialize a target description.

gdb/ChangeLog:

        PR server/23158:
        * regformats/regdat.sh: Adjust script, following the addition
        of the new expedite_regs parameter to init_target_desc.

gdb/gdbserver/ChangeLog:

        PR server/23158:
        * tdesc.h (init_target_desc) <expedite_regs>: New parameter.
        * tdesc.c (init_target_desc) <expedite_regs>: New parameter.
        Use it to set the expedite_regs field in the given tdesc.
        * x86-tdesc.h: New file.
        * linux-aarch64-tdesc.c (aarch64_linux_read_description):
        Adjust following the addition of the new expedite_regs parameter
        to init_target_desc.
        * linux-tic6x-low.c (tic6x_read_description): Likewise.
        * linux-x86-tdesc.c: #include "x86-tdesc.h".
        (i386_linux_read_description, amd64_linux_read_description):
        Adjust following the addition of the new expedite_regs parameter
        to init_target_desc.
        * lynx-i386-low.c: #include "x86-tdesc.h".
        (lynx_i386_arch_setup): Adjust following the addition of the new
        expedite_regs parameter to init_target_desc.
        * nto-x86-low.c: #include "x86-tdesc.h".
        (nto_x86_arch_setup): Adjust following the addition of the new
        expedite_regs parameter to init_target_desc.
        * win32-i386-low.c: #include "x86-tdesc.h".
        (i386_arch_setup): Adjust following the addition of the new
        expedite_regs parameter to init_target_desc.
2018-05-10 11:27:13 -04:00
Joel Brobecker 7dbac825b0 gdbserver/Windows: Fix "no program to debug" error
Trying to start a program with GDBserver on Windows yields
the following error:

    $ gdbserver.exe --once :4444 simple_main.exe
    Killing process(es): 5008
    No program to debug
    Exiting

The error itself comes from the following code shortly after
create_inferior gets called (in server.c::main):

    /* Wait till we are at first instruction in program.  */
    create_inferior (program_path.get (), program_args);
    [...]

    if (last_status.kind == TARGET_WAITKIND_EXITED
        || last_status.kind == TARGET_WAITKIND_SIGNALLED)
      was_running = 0;
    else
      was_running = 1;

    if (!was_running && !multi_mode)
      error ("No program to debug");

What happens is that the "last_status" global starts initialized
as zeroes, which means last_status.kind == TARGET_WAITKIND_EXITED,
and we expect create_inferior to be waiting for the inferior to
start until reaching the SIGTRAP, and to set the "last_status"
global to match that last event we received.

I suspect this is an unintended side-effect of the following change...

    commit 2090129c36
    Date:   Thu Dec 22 21:11:11 2016 -0500
    Subject: Share fork_inferior et al with gdbserver

... which removes some code in server.c that was responsible for
starting the inferior in a functin that was named start_inferior,
and looked like this:

   signal_pid = create_inferior (new_argv[0], &new_argv[0]);
   [...]
   /* Wait till we are at 1st instruction in program, return new pid
      (assuming success).  */
   last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);

The code has been transitioned to using fork_inferior, but sadly,
only for the targets that support it. On Windows, the calls to wait
setting "last_status" simply disappeared.

This patch adds it back in the Windows-specific implementation of
create_inferior.

gdb/gdbserver/ChangeLog:

        PR server/23158:
        * win32-low.c (win32_create_inferior): Add call to my_wait
        setting last_status global.
2018-05-10 11:24:33 -04:00
Joel Brobecker 906994d9d5 [gdbserver/win32] fatal "glob could not process pattern '(null)'" error
Trying to start GDBserver on Windows currently yields the following
error...

    $ gdbserver.exe --once :4444 simple_main.exe
    glob could not process pattern '(null)'.
    Exiting

... after which GDB terminates with a nonzero status.

This is because create_process in win32-low.c calls gdb_tilde_expand
with the result of a call to get_inferior_cwd without verifying that
the returned directory is not NULL:

    | static BOOL
    | create_process (const char *program, char *args,
    |                 DWORD flags, PROCESS_INFORMATION *pi)
    | {
    |   const char *inferior_cwd = get_inferior_cwd ();
    |   std::string expanded_infcwd = gdb_tilde_expand (inferior_cwd);

This patch avoids this by only calling gdb_tilde_expand when
INFERIOR_CWD is not NULL, which is similar to what is done on
GNU/Linux for instance.

gdb/gdbserver/ChangeLog:

        PR server/23158:
        * win32-low.c (create_process): Only call gdb_tilde_expand if
        inferior_cwd is not NULL.
2018-05-10 11:23:10 -04:00
Omair Javaid 8727de56b0 Fix tagged pointer support
This patch fixes tagged pointer support for AArch64 GDB. Linux kernel
debugging failure was reported after tagged pointer support was committed.

After a discussion around best path forward to manage tagged pointers
on GDB side we are going to disable tagged pointers support for
aarch64-none-elf-gdb because for non-linux applications we cant be
sure if tagged pointers will be used by MMU or not.

Also for aarch64-linux-gdb we are going to sign extend user-space
address after clearing tag bits. This will help debug both kernel
and user-space addresses based on information from linux kernel
documentation given below:

According to AArch64 memory map:
https://www.kernel.org/doc/Documentation/arm64/memory.txt

"User addresses have bits 63:48 set to 0 while the kernel addresses have
the same bits set to 1."

According to AArch64 tagged pointers document:
https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt

The kernel configures the translation tables so that translations made
via TTBR0 (i.e. userspace mappings) have the top byte (bits 63:56) of
the virtual address ignored by the translation hardware. This frees up
this byte for application use.

Running gdb testsuite after applying this patch introduces no regressions
and tagged pointer test cases still pass.

gdb/ChangeLog:
2018-05-10  Omair Javaid  <omair.javaid@linaro.org>

	PR gdb/23127
	* aarch64-linux-tdep.c (aarch64_linux_init_abi): Add call to
	set_gdbarch_significant_addr_bit.
	* aarch64-tdep.c (aarch64_gdbarch_init): Remove call to
	set_gdbarch_significant_addr_bit.
	* utils.c (address_significant): Update to sign extend addr.
2018-05-10 14:37:31 +05:00
Max Filippov 37d9e06231 gdb: xtensa: handle privileged registers
xtensa GDB may be used with both bare-metal and linux-based
applications. In case of bare-metal application gdbserver is able to
provide information about all CPU registers: both unprivileged and
privileged. In case of linux-based application only a small subset of
privileged state is available. Currently xtensa GDB only expects
unprivileged registers in 'g' packets and it fails to communicate with
server that sends both privileged and unprivileged registers.

Allow bare-metal xtensa GDB to deal with both privileged and
unprivileged registers by initializing tdep->num_regs with the total
number of target CPU registers. Keep linux-based xtensa GDB
functionality as is by copying tdep->num_nopriv_regs to tdep->num_regs.

gdb/
2018-05-09  Max Filippov  <jcmvbkbc@gmail.com>

	* xtensa-linux-tdep.c (xtensa-tdep.h): New include.
	(xtensa_linux_init_abi): Limit tdep->num_regs by
	tdep->num_nopriv_regs.
	* xtensa-tdep.c (xtensa_derive_tdep): Calculate
	tdep->num_nopriv_regs and only copy it to tdep->num_regs if it's
	not initialized.
2018-05-09 09:30:06 -07:00
Simon Marchi 7402fbcae1 Define GNULIB_NAMESPACE in unittests/string_view-selftests.c
When building with x86_64-w64-mingw32-g++ (to test cross-compiling for
Windows), I get this error:

unittests/string_view-selftests.o: In function `selftests::string_view::inserters_2::test05(unsigned long long)':
/home/emaisin/src/binutils-gdb/gdb/unittests/basic_string_view/inserters/char/2.cc:60: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::rpl_close()'

This is caused by gnulib redefining "close" as "rpl_close", and
therefore messing up the declaration of basic_ofstream in the libstdc++
header.  The solution would be to use gnulib namespaces [1].  Until we
use them across GDB, we can use them locally in files that are
problematic, like this one.

gdb/ChangeLog:

	* unittests/string_view-selftests.c: Define GNULIB_NAMESPACE.
2018-05-08 16:45:02 -04:00
Andrew Burgess 8ee22052f6 gdb/x86: Handle kernels using compact xsave format
For GNU/Linux on x86-64, if the target is using the xsave format for
passing the floating-point information from the inferior then there
currently exists a bug relating to the x87 control registers, and the
mxcsr register.

The xsave format allows different floating-point features to be lazily
enabled, a bit in the xsave format tells GDB which floating-point
features have been enabled, and which have not.

Currently in GDB, when reading the floating point state, we check the
xsave bit flags, if the feature is enabled then we read the feature
from the xsave buffer, and if the feature is not enabled, then we
supply the default value from within GDB.

Within GDB, when writing the floating point state, we first fetch the
xsave state from the target and then, for any feature that is not yet
enabled, we write the default values into the xsave buffer.  Next we
compare the regcache value with the value in the xsave buffer, and, if
the value has changed we update the value in the xsave buffer, and
mark the feature enabled in the xsave bit flags.

The problem then, is that the x87 control registers were not following
this pattern.  We assumed that these registers were always written out
by the kernel, and we always wrote them out to the xsave buffer (but
didn't enabled the feature).  The result of this is that if the kernel
had not yet enabled the x87 feature then within GDB we would see
random values for the x87 floating point control registers, and if the
user tried to modify one of these register, that modification would be
lost.

Finally, the mxcsr register was also broken in the same way as the x87
control registers.  The added complexity with this case is that the
mxcsr register is part of both the avx and sse floating point feature
set.  When reading or writing this register we need to check that at
least one of these features is enabled.

This bug was present in native GDB, and within gdbserver.  Both are
fixed with this commit.

gdb/ChangeLog:

	* common/x86-xstate.h (I387_FCTRL_INIT_VAL): New constant.
	(I387_MXCSR_INIT_VAL): New constant.
	* amd64-tdep.c (amd64_supply_xsave): Only read state from xsave
	buffer if it was supplied by the inferior.
	* i387-tdep.c (i387_supply_fsave): Use I387_MXCSR_INIT_VAL.
	(i387_xsave_get_clear_bv): New function.
	(i387_supply_xsave): Only read x87 control registers from the
	xsave buffer if the feature is enabled, and the state will have
	been written, otherwise, provide a suitable default.
	(i387_collect_xsave): Pre-clear all registers in xsave buffer,
	including x87 control registers.  Update control registers if they
	have changed from the default value, and mark features as enabled
	as required.
	* i387-tdep.h (i387_xsave_get_clear_bv): Declare.

gdb/gdbserver/ChangeLog:

	* i387-fp.c (i387_cache_to_xsave): Only write x87 control
	registers to the cache if their values have changed.
	(i387_xsave_to_cache): Provide default values for x87 control
	registers when these features are available, but disabled.
	* regcache.c (supply_register_by_name_zeroed): New function.
	* regcache.h (supply_register_by_name_zeroed): Declare new
	function.

gdb/testsuite/ChangeLog:

	* gdb.arch/amd64-init-x87-values.S: New file.
	* gdb.arch/amd64-init-x87-values.exp: New file.
2018-05-08 18:03:46 +01:00
Jan Kratochvil 7785df4880 watchpoint-unaligned.exp: Use skip_hw_watchpoint_tests
gdb/testsuite/ChangeLog
2018-05-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/watchpoint-unaligned.exp: Use skip_hw_watchpoint_tests.
2018-05-08 14:26:19 +02:00
Ulrich Weigand 968ae51bac [spu] Fix "info spu event" output formatting
The formatting of the output of the "info spu event" command changed, causing
spurious test suite failures.  Use phex instead of phex_nz to get back the
expected format, and fix emission of new line characters.

gdb/ChangeLog:
2018-05-08  Ulrich Weigand  <uweigand@de.ibm.com>

	* spu-tdep.c (info_spu_event_command): Fix output formatting.
2018-05-08 14:13:12 +02:00
Tom Tromey aff689d36d Add -Wduplicated-cond
This adds -Wduplicated-cond to warnings.m4.  This caught one bug.

I tried adding -Wduplicated-branches as well, but it results in some
spurious failures from code like this in cgen.h:

    #define CGEN_ATTR_TYPE(n) \
    struct { unsigned int bool_; \
	     CGEN_ATTR_VALUE_TYPE nonbool[(n) ? (n) : 1]; }

This will trigger a warning if passed n==1, which seems like a
perfectly valid thing to do; and there were other issues like this as
well.

ChangeLog
2018-05-07  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Add -Wduplicated-cond.

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

	* configure: Rebuild.
2018-05-07 08:47:38 -06:00
Tom Tromey ce887586b4 Fix decoding of ARM VFP instructions
-Wduplicated-cond pointed out that arm_record_vfp_data_proc_insn
checks "opc1 == 0x0b" twice.  I filed this a while ago as
PR tdep/20362.

Based on the ARM instruction manual at
https://www.scss.tcd.ie/~waldroj/3d1/arm_arm.pdf, I think the
instruction decoding in this function has two bugs.

First, opc1 is computed as:

  opc1 = bits (arm_insn_r->arm_insn, 20, 23);
[...]
  opc1 = opc1 & 0x04;

This means that tests like:

  else if (opc1 == 0x01)

can never be true.

In the ARM manual, "opc1" corresponds to these bits:

    name   bit
    r      20
    q      21
    D      22
    p      23

... where the D bit is not used for VFP instruction decoding.

So, I believe this code should use ~0x04 instead.

Second, VDIV is recognized by the bits "pqrs" being equal to "1000".
This tranlates to opc1 == 0x08 -- not 0x0b.  Note that pqrs==1001 is
an undefined encoding, which is probably why opc2 is not checked here;
this code doesn't seem to really deal with undefined encodings in
general, so I've left that as is.

I don't have an ARM machine or any reasonable way to test this.

ChangeLog
2018-05-07  Tom Tromey  <tom@tromey.com>

	PR tdep/20362:
	* arm-tdep.c (arm_record_vfp_data_proc_insn): Properly mask off D
	bit.  Use correct value for VDIV.
2018-05-07 08:47:37 -06:00
Tom Tromey 85e26832a0 Add -Wimplicit-fallthrough
This adds -Wimplicit-fallthrough to the set of default warnings.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Add -Wimplicit-fallthrough.

gdbserver/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2018-05-04 22:04:46 -06:00
Tom Tromey 449b1ac7ad Add a missing break in record_linux_system_call
This adds a "break" at the end of the RECORD_SYS_RECVFROM case in
record_linux_system_call.  This seemed correct to me.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* linux-record.c (record_linux_system_call) <case
	RECORD_SYS_RECVFROM>: Add "break".
2018-05-04 22:04:46 -06:00
Tom Tromey 15c9ffd697 Add missing "breaks"
This adds a "break" to a couple of spots where it was erroneously
omitted.  I think these are the two (potential) real bugs caught by
this series.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* mi/mi-main.c (mi_cmd_trace_frame_collected) <REGISTERS_FORMAT>:
	Add missing "break".
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_locals) <NO_FRAME_FILTERS>:
	Add missing "break".
2018-05-04 22:04:46 -06:00
Tom Tromey e3829d13f6 Add two fall-through comments in rs6000-tdep.c
This adds two fall-through comments in rs6000-tdep.c.  I looked at the
PPC instruction manual and convinced myself that this was correct.
And, this isn't a semantic change.  However, close review would still
be good.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* rs6000-tdep.c (ppc_process_record_op4)
	(ppc_process_record_op63): Add fall-through comment.
2018-05-04 22:04:46 -06:00
Tom Tromey da0e15638d Add fall-through comment to i386-tdep.c
This adds a fall-through comment in i386-tdep.c.  I was not sure what
to do here, so I elected to preserve the status quo.  In review, John
Baldwin pointed out that: "I believe this is correct based on the diff
that added the special cases for xgetbv and xsetbv as previously ldgt
and lidt were treated the same".

gdb/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* i386-tdep.c (i386_process_record): Add fall-through comment.
2018-05-04 22:04:46 -06:00
Tom Tromey 0019cd49ca Add a fall-through comment to stabsread.c
This adds a fall-through comment to stabsread.c.  I skimmed the stabs
manual a bit and it seems that 'p' and 'P' are similar enough that
this makes sense.  Also, stabs is mostly deprecated, and the code has
been this way for a long time, so it seemed safest to keep the status
quo.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* stabsread.c (define_symbol) <case 'p'>: Add fall-through
	comment.
2018-05-04 22:04:46 -06:00
Tom Tromey 565e0edacc Fix "obvious" fall-through warnings
This patch fixes the subset of -Wimplicit-fallthrough warnings that I
considered obvious.  In most cases it was obvious from context that
falling through was desired; here I added the appropriate comment.  In
a couple of cases it seemed clear that a "break" was missing.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* riscv-tdep.c (riscv_isa_xlen): Add fall-through comment.
	* utils.c (can_dump_core) <LIMIT_CUR>: Add fall-through comment.
	* eval.c (fetch_subexp_value) <MEMORY_ERROR>: Add fall-through
	comment.
	* d-valprint.c (d_val_print) <TYPE_CODE_STRUCT>: Add fall-through
	comment.
	* coffread.c (coff_symtab_read) <C_LABEL>: Add fall-through
	comment.
2018-05-04 22:04:46 -06:00
Tom Tromey 621846f4e2 Add missing ATTRIBUTE_NORETURNs
This patch adds a missing ATTRIBUTE_NORETURN.  This lets
-Wimplicit-fallthrough recognize that a given case does not fall
through.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* dwarf2loc.c (unimplemented): Add ATTRIBUTE_NORETURN.
2018-05-04 22:04:46 -06:00
Tom Tromey 86a7300762 Fix "fall through" comments
This patch updates existing "fall through" comments so that they can
be recognized by gcc's -Wimplicit-fallthrough comment-parsing
heuristic.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* s390-tdep.c (s390_process_record): Fix fall-through comments.
	* xcoffread.c (scan_xcoff_symtab): Move comment later.
	* symfile.c (section_is_mapped): Fix fall-through comment.
	* stabsread.c (define_symbol, read_member_functions): Fix
	fall-through comment.
	* s390-linux-tdep.c (s390_process_record): Fix fall-through
	comment.
	* remote.c (remote_wait_as): Fix fall-through comment.
	* p-exp.y (yylex): Fix fall-through comment.
	* nat/x86-dregs.c (x86_length_and_rw_bits): Fix fall-through
	comment.
	* msp430-tdep.c (msp430_gdbarch_init): Fix fall-through comment.
	* mdebugread.c (parse_partial_symbols): Fix fall-through comment.
	* jv-exp.y (yylex): Fix fall-through comment.
	* go-exp.y (lex_one_token): Fix fall-through comment.
	* gdbtypes.c (get_discrete_bounds, rank_one_type): Fix
	fall-through comment.
	* f-exp.y (yylex): Fix fall-through comment.
	* dwarf2read.c (process_die): Fix fall-through comments.
	* dbxread.c (process_one_symbol): Fix fall-through comment.
	* d-exp.y (lex_one_token): Fix fall-through comment.
	* cp-name-parser.y (yylex): Fix fall-through comment.
	* coffread.c (coff_symtab_read): Fix fall-through comment.
	* c-exp.y (lex_one_token): Fix fall-through comment.
	* arm-tdep.c (arm_decode_miscellaneous): Fix fall-through
	comment.
	* arch/arm.c (arm_instruction_changes_pc): Fix fall-through
	comment.
2018-05-04 22:04:46 -06:00
Tom Tromey 56bcdbea2b Let gdb.execute handle multi-line commands
This changes the Python API so that gdb.execute can now handle
multi-line commands, like "commands" or "define".

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22730:
	* NEWS: Mention gdb.execute change.
	* gdbcmd.h (execute_control_command): Don't declare.
	* python/python.c (execute_gdb_command): Use read_command_lines_1,
	execute_control_commands, execute_control_commands_to_string.
	* cli/cli-script.h (execute_control_commands)
	(execute_control_commands_to_string): Declare.
	(execute_control_command): Add from_tty parameter.
	* cli/cli-script.c (execute_control_commands)
	(execute_control_commands_to_string): New functions.
	(execute_user_command): Use execute_control_commands.
	(execute_control_command_1): Add "from_tty" parameter.  Update.
	(execute_control_command): Likewise.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22730:
	* gdb.python/python.exp: Test multi-line execute.
2018-05-04 15:58:09 -06:00
Tom Tromey a913fffbde Allow breakpoint commands to be set from Python
This changes the Python API so that breakpoint commands can be set by
writing to the "commands" attribute.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* NEWS: Mention that breakpoint commands are writable.
	* python/py-breakpoint.c (bppy_set_commands): New function.
	(breakpoint_object_getset) <"commands">: Use it.

doc/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* python.texi (Breakpoints In Python): Mention that "commands" is
	writable.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* gdb.python/py-breakpoint.exp: Test setting breakpoint commands.
2018-05-04 15:58:09 -06:00
Tom Tromey 60b3cef2e4 Use function_view in cli-script.c
This changes some functions in cli-script.c to use function_view
rather than a function pointer and closure argument.  This simplifies
the code a bit and is useful in a subsequent patch.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (actions_command): Update.
	* mi/mi-cmd-break.c (mi_command_line_array)
	(mi_command_line_array_cnt, mi_command_line_array_ptr)
	(mi_read_next_line): Remove.
	(mi_cmd_break_commands): Update.
	* cli/cli-script.h (read_command_lines, read_command_lines_1): Use
	function_view.
	* cli/cli-script.c (get_command_line): Update.
	(process_next_line): Use function_view.  Constify.
	(recurse_read_control_structure, read_command_lines)
	(read_command_lines_1): Change argument types to function_view.
	(do_define_command, document_command): Update.
	* breakpoint.h (check_tracepoint_command): Don't declare.
	* breakpoint.c (check_tracepoint_command): Remove.
	(commands_command_1, create_tracepoint_from_upload): Update.
2018-05-04 15:58:08 -06:00
Tom Tromey 7a2c85f259 Allow defining a user command inside a user command
PR gdb/11750 concerns defining a command inside a user commnad, like:

    define outer
      define inner
	echo hi\n
      end
    end

This patch adds this capability to gdb.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/11750:
	* cli/cli-script.h (enum command_control_type) <define_control>:
	New constant.
	* cli/cli-script.c (multi_line_command_p): Handle define_control.
	(build_command_line, execute_control_command_1)
	(process_next_line): Likewise.
	(do_define_command): New function, extracted from define_command.
	(define_command): Use it.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/11750:
	* gdb.base/define.exp: Test defining a user command inside a user
	command.
	* gdb.base/commands.exp (define_if_without_arg_test): Test "define".
2018-05-04 15:58:07 -06:00
Tom Tromey 295dc222a7 Constify prompt argument to read_command_lines
The prompt argument to read_command_lines can be const.  This patch
makes this change, and also removes some fixed-sized buffers in favor
of using string_printf.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (actions_command): Update.
	* cli/cli-script.h (read_command_lines): Update.
	* cli/cli-script.c (read_command_lines): Constify prompt_arg.
	(MAX_TMPBUF): Remove define.
	(define_command): Use string_printf.
	(document_command): Likewise.
	* breakpoint.c (commands_command_1): Update.
2018-05-04 15:58:07 -06:00
Tom Tromey 1263a9d5f1 Make print_command_trace varargs
I noticed some code in execute_control_command_1 that could be
simplified by making print_command_trace a printf-like function.  This
patch makes this change.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* top.c (execute_command): Update.
	* cli/cli-script.h (print_command_lines): Now varargs.
	* cli/cli-script.c (print_command_lines): Now varargs.
	(execute_control_command_1) <case while_control, case if_control>:
	Update.
2018-05-04 15:58:06 -06:00
Tom Tromey 12973681f5 Use counted_command_line everywhere
Currently command lines are reference counted using shared_ptr only
when attached to breakpoints.  This patch changes gdb to use
shared_ptr in commands as well.  This allows for the removal of
copy_command_lines.

Note that the change to execute_user_command explicitly makes a new
reference to the command line.  This will be used in a later patch.

This simplifies struct command_line based on the observation that a
given command can have at most two child bodies: an "if" can have both
"then" and "else" parts.  Perhaps the names I've chosen for the
replacements here are not very good -- your input requested.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (all_tracepoint_actions): Rename from
	all_tracepoint_actions_and_cleanup.  Change return type.
	(actions_command, encode_actions_1, encode_actions)
	(trace_dump_actions, tdump_command): Update.
	* remote.c (remote_download_command_source): Update.
	* python/python.c (gdbpy_eval_from_control_command)
	(python_command, python_interactive_command): Update.
	* mi/mi-cmd-break.c (mi_cmd_break_commands): Update.
	* guile/guile.c (guile_command)
	(gdbscm_eval_from_control_command, guile_command): Update.
	* compile/compile.c (compile_code_command)
	(compile_print_command, compile_to_object): Update.
	* cli/cli-script.h (struct command_lines_deleter): New.
	(counted_command_line): New typedef.
	(struct command_line): Add constructor, destructor.
	<body_list>: Remove.
	<body_list_0, body_list_1>: New members.
	(command_line_up): Remove typedef.
	(read_command_lines, read_command_lines_1, get_command_line):
	Update.
	(copy_command_lines): Don't declare.
	* cli/cli-script.c (build_command_line): Use "new".
	(get_command_line): Return counted_command_line.
	(print_command_lines, execute_user_command)
	(execute_control_command_1, while_command, if_command): Update.
	(realloc_body_list): Remove.
	(process_next_line, recurse_read_control_structure): Update.
	(read_command_lines, read_command_lines_1): Return counted_command_line.
	(free_command_lines): Use "delete".
	(copy_command_lines): Remove.
	(define_command, document_command, show_user_1): Update.
	* cli/cli-decode.h (struct cmd_list_element) <user_commands>: Now
	a counted_command_line.
	* breakpoint.h (counted_command_line): Remove typedef.
	(breakpoint_set_commands): Update.
	* breakpoint.c (check_no_tracepoint_commands)
	(validate_commands_for_breakpoint): Update.
	(breakpoint_set_commands): Change commands to be a
	counted_command_line.
	(commands_command_1, update_dprintf_command_list)
	(create_tracepoint_from_upload): Update.
2018-05-04 15:58:06 -06:00
Tom Tromey e2fc72e2c5 Allocate cmd_list_element with new
This adds a constructor and destructor to cmd_list_element and changes
it to be allocated with new.  This will be useful in a subsequent
patch.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* cli/cli-decode.h (cmd_list_element): New constructor.
	(~cmd_list_element): New destructor.
	(struct cmd_list_element): Add initializers.
	* cli/cli-decode.c (do_add_cmd): Use "new".
	(delete_cmd): Use "delete".
2018-05-04 15:58:05 -06:00
Jan Kratochvil a3b60e4588 aarch64: PR 19806: watchpoints: false negatives + PR 20207 contiguous ones
Some unaligned watchpoints were currently missed.

On old kernels as specified in
	kernel RFE: aarch64: ptrace: BAS: Support any contiguous range (edit)
	https://sourceware.org/bugzilla/show_bug.cgi?id=20207
after this patch some other unaligned watchpoints will get reported as false
positives.

With new kernels all the watchpoints should work exactly.

There may be a regresion that it now less merges watchpoints so that with
multiple overlapping watchpoints it may run out of the 4 hardware watchpoint
registers.  But as discussed in the original thread GDB needs some generic
watchpoints merging framework to be used by all the target specific code.
Even current FSF GDB code does not merge it perfectly.  Also with the more
precise watchpoints one can technically merge them less.  And I do not think
it matters too much to improve mergeability only for old kernels.
Still even on new kernels some better merging logic would make sense.

There remains one issue:
	kernel-4.15.14-300.fc27.armv7hl
	FAIL: gdb.base/watchpoint-unaligned.exp: continue
	FAIL: gdb.base/watchpoint-unaligned.exp: continue
	(gdb) continue
	Continuing.
	Unexpected error setting watchpoint: Invalid argument.
	(gdb) FAIL: gdb.base/watchpoint-unaligned.exp: continue
But that looks as a kernel bug to me.
(1) It is not a regression by this patch.
(2) It is unrelated to this patch.

gdb/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves <palves@redhat.com>

	PR breakpoints/19806 and support for PR external/20207.
	* NEWS: Mention Aarch64 watchpoint improvements.
	* aarch64-linux-nat.c (aarch64_linux_stopped_data_address): Fix missed
	watchpoints and PR external/20207 watchpoints.
	* nat/aarch64-linux-hw-point.c
	(kernel_supports_any_contiguous_range): New.
	(aarch64_watchpoint_offset): New.
	(aarch64_watchpoint_length): Support PR external/20207 watchpoints.
	(aarch64_point_encode_ctrl_reg): New parameter offset, new asserts.
	(aarch64_point_is_aligned): Support PR external/20207 watchpoints.
	(aarch64_align_watchpoint): New parameters aligned_offset_p and
	next_addr_orig_p.  Support PR external/20207 watchpoints.
	(aarch64_downgrade_regs): New.
	(aarch64_dr_state_insert_one_point): New parameters offset and
	addr_orig.
	(aarch64_dr_state_remove_one_point): Likewise.
	(aarch64_handle_breakpoint): Update caller.
	(aarch64_handle_aligned_watchpoint): Likewise.
	(aarch64_handle_unaligned_watchpoint): Support addr_orig and
	aligned_offset.
	(aarch64_linux_set_debug_regs): Remove const from state.  Call
	aarch64_downgrade_regs.
	(aarch64_show_debug_reg_state): Print also dr_addr_orig_wp.
	* nat/aarch64-linux-hw-point.h (DR_CONTROL_LENGTH): Rename to ...
	(DR_CONTROL_MASK): ... this.
	(struct aarch64_debug_reg_state): New field dr_addr_orig_wp.
	(unsigned int aarch64_watchpoint_offset): New prototype.
	(aarch64_linux_set_debug_regs): Remove const from state.
	* utils.c (align_up, align_down): Move to ...
	* common/common-utils.c (align_up, align_down): ... here.
	* utils.h (align_up, align_down): Move to ...
	* common/common-utils.h (align_up, align_down): ... here.

gdb/gdbserver/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves <palves@redhat.com>

	* linux-aarch64-low.c (aarch64_stopped_data_address):
	Likewise.

gdb/testsuite/ChangeLog
2018-05-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves <palves@redhat.com>

	PR breakpoints/19806 and support for PR external/20207.
	* gdb.base/watchpoint-unaligned.c: New file.
	* gdb.base/watchpoint-unaligned.exp: New file.
2018-05-04 22:26:46 +02:00
Andrew Burgess 45fe4a03b4 gdb: Make test names unique in gdb.base/maint.exp
Add prefixes or suffixes to some test names to make them unique.

Replace a send_gdb/gdb_expect with a gdb_test, and make the test name
unique.

Remove test of 'help maint' as this is already covered by a later call
to test_prefix_command_help.

Removed test of 'help maint info' and add a new call to
test_prefix_command_help instead.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Make test names unique, use
	test_prefix_command_help to test 'help maint info', and remove
	repeated test of 'help maint'.
2018-05-04 20:19:19 +01:00
Joel Brobecker 05bc7456b8 (SPARC/LEON) fix incorrect array return value printed by "finish"
Consider the code in the gdb.ada/array_return.exp testcase, which
defines a function returning an array of 2 integers:

   type Data_Small is array (1 .. 2) of Integer;
   function Create_Small return Data_Small;

When doing a "finish" from inside function Create_Small, we expect
GDB to tell us that the return value was "(1, 1)". However, it currently
prints the wrong value:

    (gdb) finish
    Run till exit from #0  pck.create_small () at /[...]/pck.adb:5
    p () at /[...]/p.adb:10
    10         Large := Create_Large;
    Value returned is $1 = (0, 0)

This is a regression which I traced back to the following commit...

    | commit 1933fd8ee0
    | Date:   Fri May 19 03:06:19 2017 -0700
    | Subject: gdb: fix TYPE_CODE_ARRAY handling in sparc targets

... which, despite what the subject says, is not really about
TYPE_CODE_ARRAY handling, which is a bit of an implementation detail,
but about the GNU vectors extension.

The author of the patch equated TYPE_CODE_ARRAY with vectors, which
is not correct. Vectors are TYPE_CODE_ARRAY types with the TYPE_VECTOR
flag set. So at the very minimum, the patch should have been checking
for both TYPE_CODE_ARRAY and TYPE_VECTOR.

But, that's not the only thing that did not seem right to me. When
looking at the ABI, and at the summary of the implementation in GCC
of the calling conventions for that architecture:

                                size      argument     return value

      small integer              <4       int. reg.      int. reg.
      word                        4       int. reg.      int. reg.
      double word                 8       int. reg.      int. reg.

      _Complex small integer     <8       int. reg.      int. reg.
      _Complex word               8       int. reg.      int. reg.
      _Complex double word       16        memory        int. reg.

      vector integer            <=8       int. reg.       FP reg.
      vector integer             >8        memory         memory

      float                       4       int. reg.       FP reg.
      double                      8       int. reg.       FP reg.
      long double                16        memory         memory

      _Complex float              8        memory         FP reg.
      _Complex double            16        memory         FP reg.
      _Complex long double       32        memory         FP reg.

      vector float              any        memory         memory

      aggregate                 any        memory         memory

The nice thing about the patch above is that it nicely factorized
the code that determines how arguments are passed/returns. The bad
news is that the implementation, particularly for the handling of
arrays and vectors, doesn't seem to match the summary above. Hence,
the regression we observed.

So what I did was review and re-implement some of the predicate functions
according to the summary above. Because dejagnu crashes all our Solaris
machines real bad, I can't run the dejagnu testsuite there. So what I did
was test the patch with AdaCore's testsuite against leon3-elf, no
regression. I verified that this fixes the regression above while
at the same time still passing gdb.base/gnu_vector.exp (I transposed
that testcase to our testsuite), which is the testcase that was cited
in the commit above as seeing some FAIL->PASS improvements.

This patch also removes one assertion...

      gdb_assert (sparc_integral_or_pointer_p (type)
                  || (TYPE_CODE (type) == TYPE_CODE_ARRAY && len <= 8));

... because that assertion is really the "negative" of the other conditions
written in the same "if, else if, else [assert]" block in this function.
To me, this assertion forces us to maintain two versions of the same code,
and is an unnecessary burden. In particular, the above is not the
correct condition, and the ABI summary table above shows that we need
a more complex condition to describe the situations where we expect
arguments to be passed by register.

gdb/ChangeLog:

        * sparc-tdep.c (sparc_structure_return_p): Re-implement to
        match the ABI as summarized in GCC's gcc/config/sparc/sparc.c.
        (sparc_arg_by_memory_p): Renamed from sparc_arg_on_registers_p.
        Re-implement to match the ABI as summarized in GCC's
        gcc/config/sparc/sparc.c.  All callers updated.
        (sparc32_store_arguments): Remove assertion.
2018-05-04 14:33:19 -04:00
Tom Tromey 2f433492bd Minor cleanups in printcmd.c
This changes decode_format to use skip_spaces, and changes printcmd.c
not to include tui.h, which apparently is not needed.

2018-05-04  Tom Tromey  <tom@tromey.com>

	* printcmd.c: Don't include tui.h.
	(decode_format): Use skip_spaces.
2018-05-04 12:22:44 -06:00
Tom Tromey 9be2ae8fc6 Use previous count when 'x' command is repeated
About the 'x' command, the manual says:

    If you use <RET> to repeat the 'x' command, the repeat count N is
    used again; the other arguments default as for successive uses of
    'x'.

However, PR gdb/22619 points out that this does not work.

This patch fixes the problem.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/22619:
	* printcmd.c (last_count): New global.
	(x_command): Use saved count when repeating.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR gdb/22619:
	* gdb.base/long_long.exp (gdb_test_long_long): Add test for repeat
	behavior.
2018-05-04 12:22:37 -06:00
Tom Tromey f0b3976bdc Remove do_closedir_cleanup
This removes both copies of do_closedir_cleanup in favor of a new
unique_ptr specialization.

Tested by the buildbot, though I'm not sure that these code paths are
exercised there.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* nto-procfs.c (do_closedir_cleanup): Remove.
	(procfs_pidlist): Use gdb_dir_up.
	* procfs.c (do_closedir_cleanup): Remove.
	(proc_update_threads): Use gdb_dir_up.
	* common/filestuff.h (struct gdb_dir_deleter): New.
	(gdb_dir_up): New typedef.
2018-05-04 12:20:37 -06:00
Tom Tromey 862d101ada Remove cleanup from print_mention_exception
This removes a cleanup from print_mention_exception by using
string_printf.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (print_mention_exception): Use std::string.
2018-05-04 12:12:16 -06:00
Tom Tromey cb7de75eb3 Return std::string from ada_exception_catchpoint_cond_string
This changes ada_exception_catchpoint_cond_string to return a
std::string, allowing for the removal of a cleanup in
create_excep_cond_exprs.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (create_excep_cond_exprs): Update.
	(ada_exception_catchpoint_cond_string): Use std::string.
2018-05-04 12:12:16 -06:00
Tom Tromey 49d83361cd Remove cleanup from old_renaming_is_invisible
This removes a cleanup from ada-lang.c by changing xget_renaming_scope
to return a std::string.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (xget_renaming_scope): Return std::string.
	(old_renaming_is_invisible): Update.
2018-05-04 12:12:16 -06:00
Tom Tromey ade72a3453 Use gdb_bfd_ref_ptr in target_bfd
I noticed that target_bfd was using manual reference counting for the
BFD it held.  This patch changes it to use gdb_bfd_ref_ptr instead.

Tested by the buildbot.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* bfd-target.c (target_bfd::m_bfd): Now a gdb_bfd_ref_ptr.
	(target_bfd::target_bfd, target_bfd::~target_bfd): Update.
2018-05-04 12:10:43 -06:00
Ulrich Weigand 2be4d7f0e0 [spu] Fix build break
gdb/ChangeLog:
2018-05-04  Ulrich Weigand  <uweigand@de.ibm.com>

	* spu-linux-nat.c (spu_linux_nat_target::wait): Fix syntax error.
2018-05-04 19:20:18 +02:00
Tom Tromey 69b6ecb049 Remove a cleanup from remote.c
This removes a cleanup from remote.c by using std::string to construct
the qSupported packet.

Tested by the buildbot.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_query_supported_append): Change type.
	(remote_check_symbols): Update.
2018-05-04 09:11:55 -06:00
Andrew Burgess 11859c310c gdb/testsuite: Handle targets with lots of registers
In gdb.base/maint.exp a test calls 'maint print registers'.  If the
target has lots of registers this may overflow expect's buffers,
causing the test to fail.

After this commit we process the output line at a time until we get back
to the GDB prompt, this should prevent buffer overrun while still
testing that the command works as required.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Process output from 'maint print registers'
	line at a time.
2018-05-04 15:38:18 +01:00
Paul Pluzhnikov bf27f0e2c7 configure uses incorrect link order when testing libpython
References:

https://stackoverflow.com/a/49868387
https://sourceware.org/bugzilla/show_bug.cgi?id=11420

Configure uses "gcc -o conftest -g ... conftest.c -ldl -lncurses -lm -ldl
... -lpthread ... -lpython2.7" when deciding whether give libpython is
usable.

That of course is the wrong link order, and only works for shared libraries
(mostly by accident), and only on some systems.

gdb/ChangeLog:

	PR gdb/11420
	* configure.ac: Prepend libpython.
	* python/python-config.py: Likewise.
	* configure: Regenerate.
2018-05-04 10:08:09 -04:00
Andrew Burgess 089a949083 gdb/testsuite: Fix broken regexp in gdbstub case
When $use_gdb_stub is true then, when we start an MI target there's a
regexp to match GDB's startup pattern.  Unfortunately the pattern is
broken, and we're also missing a timeout case in the match list (which
would have helped point out that the regexp was broken).

The changes to the regexp are:

  1. Remove '${run_match}' prefix, the issued command doesn't include
  '${run_prefix}' so expecting '${run_match}' is wrong.

  2. Replaced '\\n' with '\\\\n' in order to match literal '\n' in
  GDBs output (that is, match a backslash followed by 'n', not a
  newline character).

  3. Replaced a '.' (matching any character) with '\.' to match a '.'
  and moved the '\.' into the correct place in the regexp.

  4. Replaced '\r\n' with '[\r\n]+' to match the end of a line.  This
  change isn't esential, but matches the other end of line patterns
  within this regexp.

Here's an example of the output that the regexp should match taken
from a testfile log, the first line is the command sent to GDB, and
the remaining lines are the response from GDB:

  jump *_start
  &"jump *_start\n"
  ~"Continuing at 0x10074.\n"
  ^running
  *running,thread-id="all"
  (gdb)

gdb/testsuite/ChangeLog:

	* lib/mi-support.exp (mi_run_cmd_full): Fix regexp and add a
	timeout.
2018-05-04 11:11:45 +01:00
Simon Marchi 4ea17de8f1 Use flex's -t option instead of --stdout
As reported in

  https://sourceware.org/ml/gdb-patches/2018-05/msg00042.html

some old versions of flex (2.5.4) don't support the --stdout switch.
Use -t, which is an alias.

gdb/ChangeLog:

	* Makefile.in (%.c: %.l): Use -t instead of --stdout.
2018-05-03 17:33:08 -04:00
Andrew Burgess 9b0797e268 gdb/testsuite: Filter out some registers for riscv
On riscv the cycle counter, and instructions retired counter CSRs are
read only, this causes problems in the gdb.base/callfuncs.exp test, as
the values in these CSRs change after an inferior call, the check that
no target registers have been modified then fails.

Luckily the test already has a mechanism in place for filtering out
registers that are modified (and can't be restored) by an inferior call,
so this commit adds the problem registers into this list for riscv.

In the future we may end up needing to filter out more CSRs, but right
now, for the targets I have access too, these are the only ones causing
problems.

gdb/testsuite/ChangeLog:

	* gdb.base/callfuncs.exp (fetch_all_registers): Add riscv register
	filter pattern.
2018-05-03 22:31:48 +01:00
Pedro Alves bd732259bd Fix s390 GNU/Linux build
- Fixes this compile error:

  ../../src/gdb/s390-linux-nat.c:125:8: error: ‘virtual bool s390_linux_nat_target::have_continuable_watchpoint()’ can be marked override [-Werror=suggest-override]
     bool have_continuable_watchpoint () { return 1; }
	  ^~~~~~~~~~~~~~~~~~~~~~~~~~~

  s390 never implemented that hook.  The declaration of the method got
  there simply via copy/paste from some other target.

  Return 'true' instead of '1' while at it.

- Fixes this link error:

  s390-linux-nat.o:(.rodata._ZTV21s390_linux_nat_target[_ZTV21s390_linux_nat_target]+0x120): undefined reference to `s390_linux_nat_target::watchpoint_addr_within_range(unsigned long, unsigned long, int)'

gdb/ChangeLog:
2018-05-03  Pedro Alves  <palves@redhat.com>

	* s390-linux-nat.c
	(s390_linux_nat_target::have_continuable_watchpoint): Mark with
	override.  Write 'true' instead of '1'.
	(s390_linux_nat_target::watchpoint_addr_within_range): Remove
	declaration.
2018-05-03 11:31:38 +01:00
Pedro Alves d9f719f1ad target factories, target open and multiple instances of targets
Currently, to open a target, with "target TARGET_NAME", GDB finds the
target_ops instance with "TARGET_NAME" as short name, and then calls
its target_ops::open virtual method.  In reality, there's no actual
target/name lookup, a pointer to the target_ops object was associated
with the "target TARGET_NAME" command at add_target time (when GDB is
initialized), as the command's context.

This creates a chicken and egg situation.  Consider the case of
wanting to open multiple remote connections.  We want to be able to
have one remote target_ops instance per connection, but, if we're not
connected yet, so we don't yet have an instance to call target->open()
on...

This patch fixes this by separating out common info about a target_ops
to a separate structure (shortname, longname, doc), and changing the
add_target routine to take a reference to such an object instead of a
pointer to a target_ops, and a pointer to a factory function that is
responsible to open an instance of the corresponding target when the
user types "target TARGET_NAME".

 -extern void add_target (struct target_ops *);
 +extern void add_target (const target_info &info, target_open_ftype *func);

I.e. this factory function replaces the target_ops::open virtual
method.

For static/singleton targets, nothing changes, the target_open_ftype
function pushes the global target_ops instance on the target stack.
At target_close time, the connection is tor down, but the global
target_ops object remains live.

However, targets that support being open multiple times will make
their target_open_ftype routine allocate a new target_ops instance on
the heap [e.g., new remote_target()], and push that on the stack.  At
target_close time, the new object is destroyed (by the
target_ops::close virtual method).

Both the core target and the remote targets will support being open
multiple times (others could/should too, but those were my stopping
point), but not in this patch yet.  We need to get rid of more globals
first before that'd be useful.

Native targets are somewhat special, given find_default_run_target &
friends.  Those routines also expect to return a target_ops pointer,
even before we've open the target.  However, we'll never need more
than one instance of the native target, so we can assume/require that
native targets are global/simpletons, and have the backends register a
pointer to the native target_ops.  Since all native targets inherit
inf_child_target, we can centralize that registration.  See
add_inf_child_target, get_native_target/set_native_target and
find_default_run_target.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* aarch64-fbsd-nat.c (_initialize_aarch64_fbsd_nat): Use
	add_inf_child_target.
	* aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Use
	add_inf_child_target.
	* aix-thread.c (aix_thread_target_info): New.
	(aix_thread_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* alpha-bsd-nat.c (_initialize_alphabsd_nat): Use
	add_inf_child_target.
	* alpha-linux-nat.c (_initialize_alpha_linux_nat): Use
	add_inf_child_target.
	* amd64-fbsd-nat.c (_initialize_amd64fbsd_nat): Use
	add_inf_child_target.
	* amd64-linux-nat.c (_initialize_amd64_linux_nat): Use
	add_inf_child_target.
	* amd64-nbsd-nat.c (_initialize_amd64nbsd_nat): Use
	add_inf_child_target.
	* amd64-obsd-nat.c (_initialize_amd64obsd_nat): Use
	add_inf_child_target.
	* arm-fbsd-nat.c (_initialize_arm_fbsd_nat): Use
	add_inf_child_target.
	* arm-linux-nat.c (_initialize_arm_linux_nat): Use
	add_inf_child_target.
	* arm-nbsd-nat.c (_initialize_arm_netbsd_nat): Use
	add_inf_child_target.
	* bfd-target.c (target_bfd_target_info): New.
	(target_bfd) <shortname, longname, doc>: Delete.
	<info>: New.
	* bsd-kvm.c (bsd_kvm_target_info): New.
	(bsd_kvm_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(bsd_kvm_target::open): Rename to ...
	(bsd_kvm_target_open): ... this.  Adjust.
	* bsd-uthread.c (bsd_uthread_target_info): New.
	(bsd_uthread_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	* corefile.c (core_file_command): Adjust.
	* corelow.c (core_target_info): New.
	(core_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(core_target::open): Rename to ...
	(core_target_open): ... this.  Adjust.
	* ctf.c (ctf_target_info): New.
	(ctf_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	(ctf_target::open): Rename to ...
	(ctf_target_open): ... this.
	(_initialize_ctf): Adjust.
	* exec.c (exec_target_info): New.
	(exec_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	(exec_target::open): Rename to ...
	(exec_target_open): ... this.
	* gdbcore.h (core_target_open): Declare.
	* go32-nat.c (_initialize_go32_nat): Use add_inf_child_target.
	* hppa-linux-nat.c (_initialize_hppa_linux_nat): Use
	add_inf_child_target.
	* hppa-nbsd-nat.c (_initialize_hppanbsd_nat): Use
	add_inf_child_target.
	* hppa-obsd-nat.c (_initialize_hppaobsd_nat): Use
	add_inf_child_target.
	* i386-darwin-nat.c (_initialize_i386_darwin_nat): Use
	add_inf_child_target.
	* i386-fbsd-nat.c (_initialize_i386fbsd_nat): Use
	add_inf_child_target.
	* i386-gnu-nat.c (_initialize_i386gnu_nat): Use
	add_inf_child_target.
	* i386-linux-nat.c (_initialize_i386_linux_nat): Use
	add_inf_child_target.
	* i386-nbsd-nat.c (_initialize_i386nbsd_nat): Use
	add_inf_child_target.
	* i386-obsd-nat.c (_initialize_i386obsd_nat): Use
	add_inf_child_target.
	* ia64-linux-nat.c (_initialize_ia64_linux_nat): Use
	add_inf_child_target.
	* inf-child.c (inf_child_target_info): New.
	(inf_child_target::info): New.
	(inf_child_open_target): Remove 'target' parameter.  Use
	get_native_target instead.
	(inf_child_target::open): Delete.
	(add_inf_child_target): New.
	* inf-child.h (inf_child_target) <shortname, longname, doc, open>:
	Delete.
	<info>:	New.
	(add_inf_child_target): Declare.
	(inf_child_open_target): Declare.
	* linux-thread-db.c (thread_db_target_info): New.
	(thread_db_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	* m32r-linux-nat.c (_initialize_m32r_linux_nat): Use
	add_inf_child_target.
	* m68k-bsd-nat.c (_initialize_m68kbsd_nat): Use
	add_inf_child_target.
	* m68k-linux-nat.c (_initialize_m68k_linux_nat): Use
	add_inf_child_target.
	* m88k-bsd-nat.c (_initialize_m88kbsd_nat): Use
	add_inf_child_target.
	* make-target-delegates (print_class): Adjust.
	* mips-fbsd-nat.c (_initialize_mips_fbsd_nat): Use
	add_inf_child_target.
	* mips-linux-nat.c (_initialize_mips_linux_nat): Use
	add_inf_child_target.
	* mips-nbsd-nat.c (_initialize_mipsnbsd_nat): Use
	add_inf_child_target.
	* mips64-obsd-nat.c (_initialize_mips64obsd_nat): Use
	add_inf_child_target.
	* nto-procfs.c (nto_native_target_info): New.
	(nto_procfs_target_native) <shortname, longname, doc>:
	Delete.
	<info>:	New.
	(nto_procfs_target_info): New.
	(nto_procfs_target_procfs) <shortname, longname, doc>:
	Delete.
	<info>:	New.
	(init_procfs_targets): Adjust.
	* ppc-fbsd-nat.c (_initialize_ppcfbsd_nat): Use
	add_inf_child_target.
	* ppc-linux-nat.c (_initialize_ppc_linux_nat): Use
	add_inf_child_target.
	* ppc-nbsd-nat.c (_initialize_ppcnbsd_nat): Use
	add_inf_child_target.
	* ppc-obsd-nat.c (_initialize_ppcobsd_nat): Use
	add_inf_child_target.
	* ravenscar-thread.c (ravenscar_target_info): New.
	(ravenscar_thread_target) <shortname, longname, doc>:
	Delete.
	<info>:	New.
	* record-btrace.c (record_btrace_target_info):
	(record_btrace_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(record_btrace_target::open): Rename to ...
	(record_btrace_target_open): ... this.  Adjust.
	* record-full.c (record_longname, record_doc): New.
	(record_full_base_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(record_full_target_info): New.
	(record_full_target): <shortname>: Delete.
	<info>: New.
	(record_full_core_open_1, record_full_open_1): Update comments.
	(record_full_base_target::open): Rename to ...
	(record_full_open): ... this.
	(cmd_record_full_restore): Update.
	(_initialize_record_full): Update.
	* remote-sim.c (remote_sim_target_info): New.
	(gdbsim_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(gdbsim_target::open): Rename to ...
	(gdbsim_target_open): ... this.
	(_initialize_remote_sim): Adjust.
	* remote.c (remote_doc): New.
	(remote_target_info): New.
	(remote_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(extended_remote_target_info): New.
	(extended_remote_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(remote_target::open_1): Make static.  Adjust.
	* rs6000-nat.c (_initialize_rs6000_nat): Use add_inf_child_target.
	* s390-linux-nat.c (_initialize_s390_nat): Use
	add_inf_child_target.
	* sh-nbsd-nat.c (_initialize_shnbsd_nat): Use
	add_inf_child_target.
	* sol-thread.c (thread_db_target_info): New.
	(sol_thread_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* sparc-linux-nat.c (_initialize_sparc_linux_nat): Use
	add_inf_child_target.
	* sparc-nbsd-nat.c (_initialize_sparcnbsd_nat): Use
	add_inf_child_target.
	* sparc64-fbsd-nat.c (_initialize_sparc64fbsd_nat): Use
	add_inf_child_target.
	* sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use
	add_inf_child_target.
	* sparc64-nbsd-nat.c (_initialize_sparc64nbsd_nat): Use
	add_inf_child_target.
	* sparc64-obsd-nat.c (_initialize_sparc64obsd_nat): Use
	add_inf_child_target.
	* spu-linux-nat.c (_initialize_spu_nat): Use
	add_inf_child_target.
	* spu-multiarch.c (spu_multiarch_target_info): New.
	(spu_multiarch_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* target-delegates.c: Regenerate.
	* target.c: Include <unordered_map>.
	(target_ops_p): Delete.
	(DEF_VEC_P(target_ops_p)): Delete.
	(target_factories): New.
	(test_target_info): New.
	(test_target_ops::info): New.
	(open_target): Adjust to use target_factories.
	(add_target_with_completer): Rename to ...
	(add_target): ... this.  Change prototype.  Register target_info
	and open callback in target_factories.  Register target_info in
	command context instead of target_ops.
	(add_target): Delete old implementation.
	(add_deprecated_target_alias): Change prototype.  Adjust.
	(the_native_target): New.
	(set_native_target, get_native_target): New.
	(find_default_run_target): Use the_native_target.
	(find_attach_target, find_run_target): Simplify.
	(target_ops::open): Delete.
	(dummy_target_info): New.
	(dummy_target::shortname, dummy_target::longname)
	(dummy_target::doc): Delete.
	(dummy_target::info): New.
	(debug_target::shortname, debug_target::longname)
	(debug_target::doc): Delete.
	(debug_target::info): New.
	* target.h (struct target_info): New.
	(target_ops::~target_ops): Add comment.
	(target_ops::info): New.
	(target_ops::shortname, target_ops::longname, target_ops::doc): No
	longer virtual.  Implement in terms of target_info.
	(set_native_target, get_native_target): Declare.
	(target_open_ftype): New.
	(add_target, add_target_with_completer)
	(add_deprecated_target_alias): Change prototype.
	(test_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* tilegx-linux-nat.c (_initialize_tile_linux_nat): Use
	add_inf_child_target.
	* tracefile-tfile.c (tfile_target_info): New.
	(tfile_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(tfile_target::open): Rename to ...
	(tfile_target_open): ... this.
	(_initialize_tracefile_tfile): Adjust.
	* vax-bsd-nat.c (_initialize_vaxbsd_nat): Use
	add_inf_child_target.
	* windows-nat.c (_initialize_windows_nat): Use
	add_inf_child_target.
	* xtensa-linux-nat.c (_initialize_xtensa_linux_nat): Use
	add_inf_child_target.
2018-05-03 00:53:12 +01:00
Pedro Alves 135340afdf linux_nat_target: More low methods
This converts the remaining linux-nat.c hooks low_ methods like had
been started in a previous patch.  The linux_nat_set_foo routines are
all gone with this.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* linux-nat.h (linux_nat_target) <low_new_thread,
	low_delete_thread, low_new_fork, low_forget_process,
	low_prepare_to_resume, low_siginfo_fixup, low_status_is_event>:
	New virtual methods.
	(linux_nat_set_new_thread, linux_nat_set_delete_thread)
	(linux_nat_new_fork_ftype, linux_nat_set_new_fork)
	(linux_nat_forget_process_ftype, linux_nat_set_forget_process)
	(linux_nat_forget_process, linux_nat_set_siginfo_fixup)
	(linux_nat_set_prepare_to_resume, linux_nat_set_status_is_event):
	Delete.
	* linux-fork.c (delete_fork): Adjust to call low method.
	* linux-nat.c (linux_nat_new_thread, linux_nat_delete_thread)
	(linux_nat_new_fork, linux_nat_forget_process_hook)
	(linux_nat_prepare_to_resume, linux_nat_siginfo_fixup)
	(linux_nat_status_is_event):
	(linux_nat_target::follow_fork, lwp_free, add_lwp, detach_one_lwp)
	(linux_resume_one_lwp_throw, linux_handle_extended_wait): Adjust
	to call low method.
	(sigtrap_is_event): Rename to ...
	(linux_nat_target::low_status_is_event): ... this.
	(linux_nat_set_status_is_event): Delete.
	(save_stop_reason, linux_nat_wait_1)
	(linux_nat_target::mourn_inferior, siginfo_fixup): Adjust to call
	low methods.
	(linux_nat_set_new_thread, linux_nat_set_delete_thread)
	(linux_nat_set_new_fork, linux_nat_set_forget_process)
	(linux_nat_forget_process, linux_nat_set_siginfo_fixup)
	(linux_nat_set_prepare_to_resume): Delete.
	* aarch64-linux-nat.c: All linux_nat_set_* callbacks converted to
	low virtual methods.
	* amd64-linux-nat.c: Likewise.
	* arm-linux-nat.c: Likewise.
	* i386-linux-nat.c: Likewise.
	* ia64-linux-nat.c: Likewise.
	* mips-linux-nat.c: Likewise.
	* ppc-linux-nat.c: Likewise.
	* s390-linux-nat.c: Likewise.
	* sparc64-linux-nat.c: Likewise.
	* x86-linux-nat.c: Likewise.
	* x86-linux-nat.h: Include "nat/x86-linux.h".
	(x86_linux_nat_target) <low_new_fork, low_forget_process,
	low_prepare_to_resume, low_new_thread, low_delete_thread>:
	Override methods.
2018-05-03 00:52:17 +01:00
Pedro Alves 57810aa7e8 target_ops: Use bool throughout
After the previous target_ops/C++ patches are all squashed and merged,
this one can go in separately.

This patch adjusts all the target methods to return bool instead of int
when they're returning a boolean.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* target.h (target_ops)
	<stopped_by_sw_breakpoint, supports_stopped_by_sw_breakpoint,
	stopped_by_hw_breakpoint, supports_stopped_by_hw_breakpoint,
	stopped_by_watchpoint, have_continuable_watchpoint,
	stopped_data_address, watchpoint_addr_within_range,
	can_accel_watchpoint_condition, can_run, thread_alive,
	has_all_memory, has_memory, has_stack, has_registers,
	has_execution, can_async_p, is_async_p, supports_non_stop,
	always_non_stop_p, can_execute_reverse, supports_multi_process,
	supports_enable_disable_tracepoint,
	supports_disable_randomization, supports_string_tracing,
	supports_evaluation_of_breakpoint_conditions,
	can_run_breakpoint_commands, filesystem_is_local,
	can_download_tracepoint, get_trace_state_variable_value,
	set_trace_notes, get_tib_address, use_agent, can_use_agent,
	record_is_replaying, record_will_replay,
	augmented_libraries_svr4_read>: Adjust to return bool.
	* aarch64-linux-nat.c: All implementations adjusted.
	* aix-thread.c: All implementations adjusted.
	* arm-linux-nat.c: All implementations adjusted.
	* breakpoint.c: All implementations adjusted.
	* bsd-kvm.c: All implementations adjusted.
	* bsd-uthread.c: All implementations adjusted.
	* corelow.c: All implementations adjusted.
	* ctf.c: All implementations adjusted.
	* darwin-nat.c: All implementations adjusted.
	* darwin-nat.h: All implementations adjusted.
	* exec.c: All implementations adjusted.
	* fbsd-nat.c: All implementations adjusted.
	* fbsd-nat.h: All implementations adjusted.
	* gnu-nat.c: All implementations adjusted.
	* gnu-nat.h: All implementations adjusted.
	* go32-nat.c: All implementations adjusted.
	* ia64-linux-nat.c: All implementations adjusted.
	* inf-child.c: All implementations adjusted.
	* inf-child.h: All implementations adjusted.
	* inf-ptrace.c: All implementations adjusted.
	* inf-ptrace.h: All implementations adjusted.
	* linux-nat.c: All implementations adjusted.
	* linux-nat.h: All implementations adjusted.
	* mips-linux-nat.c: All implementations adjusted.
	* nto-procfs.c: All implementations adjusted.
	* ppc-linux-nat.c: All implementations adjusted.
	* procfs.c: All implementations adjusted.
	* ravenscar-thread.c: All implementations adjusted.
	* record-btrace.c: All implementations adjusted.
	* record-full.c: All implementations adjusted.
	* remote-sim.c: All implementations adjusted.
	* remote.c: All implementations adjusted.
	* s390-linux-nat.c: All implementations adjusted.
	* sol-thread.c: All implementations adjusted.
	* spu-multiarch.c: All implementations adjusted.
	* target-delegates.c: All implementations adjusted.
	* target.c: All implementations adjusted.
	* target.h: All implementations adjusted.
	* tracefile-tfile.c: All implementations adjusted.
	* tracefile.c: All implementations adjusted.
	* tracefile.h: All implementations adjusted.
	* windows-nat.c: All implementations adjusted.
	* x86-linux-nat.h: All implementations adjusted.
	* x86-nat.h: All implementations adjusted.
2018-05-03 00:51:30 +01:00
Pedro Alves ad6a4e2dd6 make-target-delegates: line break between return type and function name
Before the target_ops C++ification, this wasn't necessary simply
because the methods were wrapped in ()'s, like
  '(*to_my_long_method_name) (target_ops *)',
so
  std::vector<long_type_name>(*to_my_long_method_name) ()TARGET_DEFAULT_IGNORE ()

still parsed correctly.  With the (*) gone, we need this.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* make-target-delegates (scan_target_h): Don't trim lines here.
	Replace sequences of tabs and/or whitespace with a single
	whitespace.
	(top level, parsing methods): Trim each line before processing it
	here.
2018-05-03 00:51:08 +01:00
Pedro Alves f6ac5f3d63 Convert struct target_ops to C++
I.e., use C++ virtual methods and inheritance instead of tables of
function pointers.

Unfortunately, there's no way to do a smooth transition.  ALL native
targets in the tree must be converted at the same time.  I've tested
all I could with cross compilers and with help from GCC compile farm,
but naturally I haven't been able to test many of the ports.  Still, I
made a best effort to port everything over, and while I expect some
build problems due to typos and such, which should be trivial to fix,
I don't expect any design problems.

* Implementation notes:

- The flattened current_target is gone.  References to current_target
  or current_target.beneath are replaced with references to
  target_stack (the top of the stack) directly.

- To keep "set debug target" working, this adds a new debug_stratum
  layer that sits on top of the stack, prints the debug, and delegates
  to the target beneath.

  In addition, this makes the shortname and longname properties of
  target_ops be virtual methods instead of data fields, and makes the
  debug target defer those to the target beneath.  This is so that
  debug code sprinkled around that does "if (debugtarget) ..."  can
  transparently print the name of the target beneath.

  A patch later in the series actually splits out the
  shortname/longname methods to a separate structure, but I preferred
  to keep that chance separate as it is associated with changing a bit
  the design of how targets are registered and open.

- Since you can't check whether a C++ virtual method is overridden,
  the old method of checking whether a target_ops implements a method
  by comparing the function pointer must be replaced with something
  else.

  Some cases are fixed by adding a parallel "can_do_foo" target_ops
  methods.  E.g.,:

    +  for (t = target_stack; t != NULL; t = t->beneath)
	 {
    -      if (t->to_create_inferior != NULL)
    +      if (t->can_create_inferior ())
	    break;
	 }

  Others are fixed by changing void return type to bool or int return
  type, and have the default implementation return false or -1, to
  indicate lack of support.

- make-target-delegates was adjusted to generate C++ classes and
  methods.

  It needed tweaks to grok "virtual" in front of the target method
  name, and for the fact that methods are no longer function pointers.
  (In particular, the current code parsing the return type was simple
  because it could simply parse up until the '(' in '(*to_foo)'.

  It now generates a couple C++ classes that inherit target_ops:
  dummy_target and debug_target.

  Since we need to generate the class declarations as well, i.e., we
  need to emit methods twice, we now generate the code in two passes.

- The core_target global is renamed to avoid conflict with the
  "core_target" class.

- ctf/tfile targets

  init_tracefile_ops is replaced by a base class that is inherited by
  both ctf and tfile.

- bsd-uthread

  The bsd_uthread_ops_hack hack is gone.  It's not needed because
  nothing was extending a target created by bsd_uthread_target.

- remote/extended-remote targets

  This is a first pass, just enough to C++ify target_ops.

  A later pass will convert more free functions to methods, and make
  remote_state be truly per remote instance, allowing multiple
  simultaneous instances of remote targets.

- inf-child/"native" is converted to an actual base class
  (inf_child_target), that is inherited by all native targets.

- GNU/Linux

  The old weird double-target linux_ops mechanism in linux-nat.c, is
  gone, replaced by adding a few virtual methods to linux-nat.h's
  target_ops, called low_XXX, that the concrete linux-nat
  implementations override.  Sort of like gdbserver's
  linux_target_ops, but simpler, for requiring only one
  target_ops-like hierarchy, which spares implementing the same method
  twice when we need to forward the method to a low implementation.
  The low target simply reimplements the target_ops method directly in
  that case.

  There are a few remaining linux-nat.c hooks that would be better
  converted to low_ methods like above too.  E.g.:

   linux_nat_set_new_thread (t, x86_linux_new_thread);
   linux_nat_set_new_fork (t, x86_linux_new_fork);
   linux_nat_set_forget_process

  That'll be done in a follow up patch.

- We can no longer use functions like x86_use_watchpoints to install
  custom methods on an arbitrary base target.

  The patch replaces instances of such a pattern with template mixins.
  For example memory_breakpoint_target defined in target.h, or
  x86_nat_target in x86-nat.h.

- linux_trad_target, MIPS and Alpha GNU/Linux

  The code in the new linux-nat-trad.h/c files which was split off of
  inf-ptrace.h/c recently, is converted to a C++ base class, and used
  by the MIPS and Alpha GNU/Linux ports.

- BSD targets

  The

    $architecture x NetBSD/OpenBSD/FreeBSD

  support matrix complicates things a bit.  There's common BSD target
  code, and there's common architecture-specific code shared between
  the different BSDs.  Currently, all that is stiched together to form
  a final target, via the i386bsd_target, x86bsd_target,
  fbsd_nat_add_target functions etc.

  This introduces new fbsd_nat_target, obsd_nat_target and
  nbsd_nat_target classes that serve as base/prototype target for the
  corresponding BSD variant.

  And introduces generic i386/AMD64 BSD targets, to be used as
  template mixin to build a final target.  Similarly, a generic SPARC
  target is added, used by both BSD and Linux ports.

- bsd_kvm_add_target, BSD libkvm target

  I considered making bsd_kvm_supply_pcb a virtual method, and then
  have each port inherit bsd_kvm_target and override that method, but
  that was resulting in lots of unjustified churn, so I left the
  function pointer mechanism alone.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>
	    John Baldwin  <jhb@freebsd.org>

	* target.h (enum strata) <debug_stratum>: New.
	(struct target_ops) <all delegation methods>: Replace by C++
	virtual methods, and drop "to_" prefix.  All references updated
	throughout.
	<to_shortname, to_longname, to_doc, to_data,
	to_have_steppable_watchpoint, to_have_continuable_watchpoint,
	to_has_thread_control, to_attach_no_wait>: Delete, replaced by
	virtual methods.  All references updated throughout.
	<can_attach, supports_terminal_ours, can_create_inferior,
	get_thread_control_capabilities, attach_no_wait>: New
	virtual methods.
	<insert_breakpoint, remove_breakpoint>: Now
	TARGET_DEFAULT_NORETURN methods.
	<info_proc>: Now returns bool.
	<to_magic>: Delete.
	(OPS_MAGIC): Delete.
	(current_target): Delete.  All references replaced by references
	to ...
	(target_stack): ... this.  New.
	(target_shortname, target_longname): Adjust.
	(target_can_run): Now a function declaration.
	(default_child_has_all_memory, default_child_has_memory)
	(default_child_has_stack, default_child_has_registers)
	(default_child_has_execution): Remove target_ops parameter.
	(complete_target_initialization): Delete.
	(memory_breakpoint_target): New template class.
	(test_target_ops): Refactor as a C++ class with virtual methods.
	* make-target-delegates (NAME_PART): Tighten.
	(POINTER_PART, CP_SYMBOL): New.
	(SIMPLE_RETURN_PART): Reimplement.
	(VEC_RETURN_PART): Expect less.
	(RETURN_PART, VIRTUAL_PART): New.
	(METHOD): Adjust to C++ virtual methods.
	(scan_target_h): Remove reference to C99.
	(dname): Output "target_ops::" prefix.
	(write_function_header): Adjust to output a C++ class method.
	(write_declaration): New.
	(write_delegator): Adjust to output a C++ class method.
	(tdname): Output "dummy_target::" prefix.
	(write_tdefault, write_debugmethod): Adjust to output a C++ class
	method.
	(tdefault_names, debug_names): Delete.
	(return_types, tdefaults, styles, argtypes_array): New.
	(top level): All methods are delegators.
	(print_class): New.
	(top level): Print dummy_target and debug_target classes.
	* target-delegates.c: Regenerate.
	* target-debug.h (target_debug_print_enum_info_proc_what)
	(target_debug_print_thread_control_capabilities)
	(target_debug_print_thread_info_p): New.
	* target.c (dummy_target): Delete.
	(the_dummy_target, the_debug_target): New.
	(target_stack): Now extern.
	(set_targetdebug): Push/unpush debug target.
	(default_child_has_all_memory, default_child_has_memory)
	(default_child_has_stack, default_child_has_registers)
	(default_child_has_execution): Remove target_ops parameter.
	(complete_target_initialization): Delete.
	(add_target_with_completer): No longer call
	complete_target_initialization.
	(target_supports_terminal_ours): Use regular delegation.
	(update_current_target): Delete.
	(push_target): No longer check magic number.  Don't call
	update_current_target.
	(unpush_target): Don't call update_current_target.
	(target_is_pushed): No longer check magic number.
	(target_require_runnable): Skip for all stratums over
	process_stratum.
	(target_ops::info_proc): New.
	(target_info_proc): Use find_target_at and
	find_default_run_target.
	(target_supports_disable_randomization): Use regular delegation.
	(target_get_osdata): Use find_target_at.
	(target_ops::open, target_ops::close, target_ops::can_attach)
	(target_ops::attach, target_ops::can_create_inferior)
	(target_ops::create_inferior, target_ops::can_run)
	(target_can_run): New.
	(default_fileio_target): Use regular delegation.
	(target_ops::fileio_open, target_ops::fileio_pwrite)
	(target_ops::fileio_pread, target_ops::fileio_fstat)
	(target_ops::fileio_close, target_ops::fileio_unlink)
	(target_ops::fileio_readlink): New.
	(target_fileio_open_1, target_fileio_unlink)
	(target_fileio_readlink): Always call the target method.  Handle
	FILEIO_ENOSYS.
	(return_zero, return_zero_has_execution): Delete.
	(init_dummy_target): Delete.
	(dummy_target::dummy_target, dummy_target::shortname)
	(dummy_target::longname, dummy_target::doc)
	(debug_target::debug_target, debug_target::shortname)
	(debug_target::longname, debug_target::doc): New.
	(target_supports_delete_record): Use regular delegation.
	(setup_target_debug): Delete.
	(maintenance_print_target_stack): Skip debug_stratum.
	(initialize_targets): Instantiate the_dummy_target and
	the_debug_target.
	* auxv.c (target_auxv_parse): Remove 'ops' parameter.  Adjust to
	use target_stack.
	(target_auxv_search, fprint_target_auxv): Adjust.
	(info_auxv_command): Adjust to use target_stack.
	* auxv.h (target_auxv_parse): Remove 'ops' parameter.
	* exceptions.c (print_flush): Handle a NULL target_stack.
	* regcache.c (target_ops_no_register): Refactor as class with
	virtual methods.

	* exec.c (exec_target): New class.
	(exec_ops): Now an exec_target.
	(exec_open, exec_close_1, exec_get_section_table)
	(exec_xfer_partial, exec_files_info, exec_has_memory)
	(exec_make_note_section): Refactor as exec_target methods.
	(exec_file_clear, ignore, exec_remove_breakpoint, init_exec_ops):
	Delete.
	(exec_target::find_memory_regions): New.
	(_initialize_exec): Don't call init_exec_ops.
	* gdbcore.h (exec_file_clear): Delete.

	* corefile.c (core_target): Delete.
	(core_file_command): Adjust.
	* corelow.c (core_target): New class.
	(the_core_target): New.
	(core_close): Remove target_ops parameter.
	(core_close_cleanup): Adjust.
	(core_target::close): New.
	(core_open, core_detach, get_core_registers, core_files_info)
	(core_xfer_partial, core_thread_alive, core_read_description)
	(core_pid_to_str, core_thread_name, core_has_memory)
	(core_has_stack, core_has_registers, core_info_proc): Rework as
	core_target methods.
	(ignore, core_remove_breakpoint, init_core_ops): Delete.
	(_initialize_corelow): Initialize the_core_target.
	* gdbcore.h (core_target): Delete.
	(the_core_target): New.

	* ctf.c: (ctf_target): New class.
	(ctf_ops): Now a ctf_target.
	(ctf_open, ctf_close, ctf_files_info, ctf_fetch_registers)
	(ctf_xfer_partial, ctf_get_trace_state_variable_value)
	(ctf_trace_find, ctf_traceframe_info): Refactor as ctf_target
	methods.
	(init_ctf_ops): Delete.
	(_initialize_ctf): Don't call it.
	* tracefile-tfile.c (tfile_target): New class.
	(tfile_ops): Now a tfile_target.
	(tfile_open, tfile_close, tfile_files_info)
	(tfile_get_tracepoint_status, tfile_trace_find)
	(tfile_fetch_registers, tfile_xfer_partial)
	(tfile_get_trace_state_variable_value, tfile_traceframe_info):
	Refactor as tfile_target methods.
	(tfile_xfer_partial_features): Remove target_ops parameter.
	(init_tfile_ops): Delete.
	(_initialize_tracefile_tfile): Don't call it.
	* tracefile.c (tracefile_has_all_memory, tracefile_has_memory)
	(tracefile_has_stack, tracefile_has_registers)
	(tracefile_thread_alive, tracefile_get_trace_status): Refactor as
	tracefile_target methods.
	(init_tracefile_ops): Delete.
	(tracefile_target::tracefile_target): New.
	* tracefile.h: Include "target.h".
	(tracefile_target): New class.
	(init_tracefile_ops): Delete.

	* spu-multiarch.c (spu_multiarch_target): New class.
	(spu_ops): Now a spu_multiarch_target.
	(spu_thread_architecture, spu_region_ok_for_hw_watchpoint)
	(spu_fetch_registers, spu_store_registers, spu_xfer_partial)
	(spu_search_memory, spu_mourn_inferior): Refactor as
	spu_multiarch_target methods.
	(init_spu_ops): Delete.
	(_initialize_spu_multiarch): Remove references to init_spu_ops,
	complete_target_initialization.

	* ravenscar-thread.c (ravenscar_thread_target): New class.
	(ravenscar_ops): Now a ravenscar_thread_target.
	(ravenscar_resume, ravenscar_wait, ravenscar_update_thread_list)
	(ravenscar_thread_alive, ravenscar_pid_to_str)
	(ravenscar_fetch_registers, ravenscar_store_registers)
	(ravenscar_prepare_to_store, ravenscar_stopped_by_sw_breakpoint)
	(ravenscar_stopped_by_hw_breakpoint)
	(ravenscar_stopped_by_watchpoint, ravenscar_stopped_data_address)
	(ravenscar_mourn_inferior, ravenscar_core_of_thread)
	(ravenscar_get_ada_task_ptid): Refactor as ravenscar_thread_target
	methods.
	(init_ravenscar_thread_ops): Delete.
	(_initialize_ravenscar): Remove references to
	init_ravenscar_thread_ops and complete_target_initialization.

	* bsd-uthread.c (bsd_uthread_ops_hack): Delete.
	(bsd_uthread_target): New class.
	(bsd_uthread_ops): Now a bsd_uthread_target.
	(bsd_uthread_activate): Adjust to refer to bsd_uthread_ops.
	(bsd_uthread_close, bsd_uthread_mourn_inferior)
	(bsd_uthread_fetch_registers, bsd_uthread_store_registers)
	(bsd_uthread_wait, bsd_uthread_resume, bsd_uthread_thread_alive)
	(bsd_uthread_update_thread_list, bsd_uthread_extra_thread_info)
	(bsd_uthread_pid_to_str): Refactor as bsd_uthread_target methods.
	(bsd_uthread_target): Delete function.
	(_initialize_bsd_uthread): Remove reference to
	complete_target_initialization.

	* bfd-target.c (target_bfd_data): Delete.  Fields folded into ...
	(target_bfd): ... this new class.
	(target_bfd_xfer_partial, target_bfd_get_section_table)
	(target_bfd_close): Refactor as target_bfd methods.
	(target_bfd::~target_bfd): New.
	(target_bfd_reopen): Adjust.
	(target_bfd::close): New.

	* record-btrace.c (record_btrace_target): New class.
	(record_btrace_ops): Now a record_btrace_target.
	(record_btrace_open, record_btrace_stop_recording)
	(record_btrace_disconnect, record_btrace_close)
	(record_btrace_async, record_btrace_info)
	(record_btrace_insn_history, record_btrace_insn_history_range)
	(record_btrace_insn_history_from, record_btrace_call_history)
	(record_btrace_call_history_range)
	(record_btrace_call_history_from, record_btrace_record_method)
	(record_btrace_is_replaying, record_btrace_will_replay)
	(record_btrace_xfer_partial, record_btrace_insert_breakpoint)
	(record_btrace_remove_breakpoint, record_btrace_fetch_registers)
	(record_btrace_store_registers, record_btrace_prepare_to_store)
	(record_btrace_to_get_unwinder)
	(record_btrace_to_get_tailcall_unwinder, record_btrace_resume)
	(record_btrace_commit_resume, record_btrace_wait)
	(record_btrace_stop, record_btrace_can_execute_reverse)
	(record_btrace_stopped_by_sw_breakpoint)
	(record_btrace_supports_stopped_by_sw_breakpoint)
	(record_btrace_stopped_by_hw_breakpoint)
	(record_btrace_supports_stopped_by_hw_breakpoint)
	(record_btrace_update_thread_list, record_btrace_thread_alive)
	(record_btrace_goto_begin, record_btrace_goto_end)
	(record_btrace_goto, record_btrace_stop_replaying_all)
	(record_btrace_execution_direction)
	(record_btrace_prepare_to_generate_core)
	(record_btrace_done_generating_core): Refactor as
	record_btrace_target methods.
	(init_record_btrace_ops): Delete.
	(_initialize_record_btrace): Remove reference to
	init_record_btrace_ops.
	* record-full.c (RECORD_FULL_IS_REPLAY): Adjust to always refer to
	the execution_direction global.
	(record_full_base_target, record_full_target)
	(record_full_core_target): New classes.
	(record_full_ops): Now a record_full_target.
	(record_full_core_ops): Now a record_full_core_target.
	(record_full_target::detach, record_full_target::disconnect)
	(record_full_core_target::disconnect)
	(record_full_target::mourn_inferior, record_full_target::kill):
	New.
	(record_full_open, record_full_close, record_full_async): Refactor
	as methods of the record_full_base_target class.
	(record_full_resume, record_full_commit_resume): Refactor
	as methods of the record_full_target class.
	(record_full_wait, record_full_stopped_by_watchpoint)
	(record_full_stopped_data_address)
	(record_full_stopped_by_sw_breakpoint)
	(record_full_supports_stopped_by_sw_breakpoint)
	(record_full_stopped_by_hw_breakpoint)
	(record_full_supports_stopped_by_hw_breakpoint): Refactor as
	methods of the record_full_base_target class.
	(record_full_store_registers, record_full_xfer_partial)
	(record_full_insert_breakpoint, record_full_remove_breakpoint):
	Refactor as methods of the record_full_target class.
	(record_full_can_execute_reverse, record_full_get_bookmark)
	(record_full_goto_bookmark, record_full_execution_direction)
	(record_full_record_method, record_full_info, record_full_delete)
	(record_full_is_replaying, record_full_will_replay)
	(record_full_goto_begin, record_full_goto_end, record_full_goto)
	(record_full_stop_replaying): Refactor as methods of the
	record_full_base_target class.
	(record_full_core_resume, record_full_core_kill)
	(record_full_core_fetch_registers)
	(record_full_core_prepare_to_store)
	(record_full_core_store_registers, record_full_core_xfer_partial)
	(record_full_core_insert_breakpoint)
	(record_full_core_remove_breakpoint)
	(record_full_core_has_execution): Refactor
	as methods of the record_full_core_target class.
	(record_full_base_target::supports_delete_record): New.
	(init_record_full_ops): Delete.
	(init_record_full_core_ops): Delete.
	(record_full_save): Refactor as method of the
	record_full_base_target class.
	(_initialize_record_full): Remove references to
	init_record_full_ops and init_record_full_core_ops.

	* remote.c (remote_target, extended_remote_target): New classes.
	(remote_ops): Now a remote_target.
	(extended_remote_ops): Now an extended_remote_target.
	(remote_insert_fork_catchpoint, remote_remove_fork_catchpoint)
	(remote_insert_vfork_catchpoint, remote_remove_vfork_catchpoint)
	(remote_insert_exec_catchpoint, remote_remove_exec_catchpoint)
	(remote_pass_signals, remote_set_syscall_catchpoint)
	(remote_program_signals, )
	(remote_thread_always_alive): Remove target_ops parameter.
	(remote_thread_alive, remote_thread_name)
	(remote_update_thread_list, remote_threads_extra_info)
	(remote_static_tracepoint_marker_at)
	(remote_static_tracepoint_markers_by_strid)
	(remote_get_ada_task_ptid, remote_close, remote_start_remote)
	(remote_open): Refactor as methods of remote_target.
	(extended_remote_open, extended_remote_detach)
	(extended_remote_attach, extended_remote_post_attach):
	(extended_remote_supports_disable_randomization)
	(extended_remote_create_inferior): : Refactor as method of
	extended_remote_target.
	(remote_set_permissions, remote_open_1, remote_detach)
	(remote_follow_fork, remote_follow_exec, remote_disconnect)
	(remote_resume, remote_commit_resume, remote_stop)
	(remote_interrupt, remote_pass_ctrlc, remote_terminal_inferior)
	(remote_terminal_ours, remote_wait, remote_fetch_registers)
	(remote_prepare_to_store, remote_store_registers)
	(remote_flash_erase, remote_flash_done, remote_files_info)
	(remote_kill, remote_mourn, remote_insert_breakpoint)
	(remote_remove_breakpoint, remote_insert_watchpoint)
	(remote_watchpoint_addr_within_range)
	(remote_remove_watchpoint, remote_region_ok_for_hw_watchpoint)
	(remote_check_watch_resources, remote_stopped_by_sw_breakpoint)
	(remote_supports_stopped_by_sw_breakpoint)
	(remote_stopped_by_hw_breakpoint)
	(remote_supports_stopped_by_hw_breakpoint)
	(remote_stopped_by_watchpoint, remote_stopped_data_address)
	(remote_insert_hw_breakpoint, remote_remove_hw_breakpoint)
	(remote_verify_memory): Refactor as methods of remote_target.
	(remote_write_qxfer, remote_read_qxfer): Remove target_ops
	parameter.
	(remote_xfer_partial, remote_get_memory_xfer_limit)
	(remote_search_memory, remote_rcmd, remote_memory_map)
	(remote_pid_to_str, remote_get_thread_local_address)
	(remote_get_tib_address, remote_read_description): Refactor as
	methods of remote_target.
	(remote_target::fileio_open, remote_target::fileio_pwrite)
	(remote_target::fileio_pread, remote_target::fileio_close): New.
	(remote_hostio_readlink, remote_hostio_fstat)
	(remote_filesystem_is_local, remote_can_execute_reverse)
	(remote_supports_non_stop, remote_supports_disable_randomization)
	(remote_supports_multi_process, remote_supports_cond_breakpoints)
	(remote_supports_enable_disable_tracepoint)
	(remote_supports_string_tracing)
	(remote_can_run_breakpoint_commands, remote_trace_init)
	(remote_download_tracepoint, remote_can_download_tracepoint)
	(remote_download_trace_state_variable, remote_enable_tracepoint)
	(remote_disable_tracepoint, remote_trace_set_readonly_regions)
	(remote_trace_start, remote_get_trace_status)
	(remote_get_tracepoint_status, remote_trace_stop)
	(remote_trace_find, remote_get_trace_state_variable_value)
	(remote_save_trace_data, remote_get_raw_trace_data)
	(remote_set_disconnected_tracing, remote_core_of_thread)
	(remote_set_circular_trace_buffer, remote_traceframe_info)
	(remote_get_min_fast_tracepoint_insn_len)
	(remote_set_trace_buffer_size, remote_set_trace_notes)
	(remote_use_agent, remote_can_use_agent, remote_enable_btrace)
	(remote_disable_btrace, remote_teardown_btrace)
	(remote_read_btrace, remote_btrace_conf)
	(remote_augmented_libraries_svr4_read, remote_load)
	(remote_pid_to_exec_file, remote_can_do_single_step)
	(remote_execution_direction, remote_thread_handle_to_thread_info):
	Refactor as methods of remote_target.
	(init_remote_ops, init_extended_remote_ops): Delete.
	(remote_can_async_p, remote_is_async_p, remote_async)
	(remote_thread_events, remote_upload_tracepoints)
	(remote_upload_trace_state_variables): Refactor as methods of
	remote_target.
	(_initialize_remote): Remove references to init_remote_ops and
	init_extended_remote_ops.

	* remote-sim.c (gdbsim_target): New class.
	(gdbsim_fetch_register, gdbsim_store_register, gdbsim_kill)
	(gdbsim_load, gdbsim_create_inferior, gdbsim_open, gdbsim_close)
	(gdbsim_detach, gdbsim_resume, gdbsim_interrupt)
	(gdbsim_wait, gdbsim_prepare_to_store, gdbsim_xfer_partial)
	(gdbsim_files_info, gdbsim_mourn_inferior, gdbsim_thread_alive)
	(gdbsim_pid_to_str, gdbsim_has_all_memory, gdbsim_has_memory):
	Refactor as methods of gdbsim_target.
	(gdbsim_ops): Now a gdbsim_target.
	(init_gdbsim_ops): Delete.
	(gdbsim_cntrl_c): Adjust.
	(_initialize_remote_sim): Remove reference to init_gdbsim_ops.

	* amd64-linux-nat.c (amd64_linux_nat_target): New class.
	(the_amd64_linux_nat_target): New.
	(amd64_linux_fetch_inferior_registers)
	(amd64_linux_store_inferior_registers): Refactor as methods of
	amd64_linux_nat_target.
	(_initialize_amd64_linux_nat): Adjust.  Set linux_target.
	* i386-linux-nat.c: Don't include "linux-nat.h".
	(i386_linux_nat_target): New class.
	(the_i386_linux_nat_target): New.
	(i386_linux_fetch_inferior_registers)
	(i386_linux_store_inferior_registers, i386_linux_resume): Refactor
	as methods of i386_linux_nat_target.
	(_initialize_i386_linux_nat): Adjust.  Set linux_target.
	* inf-child.c (inf_child_ops): Delete.
	(inf_child_fetch_inferior_registers)
	(inf_child_store_inferior_registers): Delete.
	(inf_child_post_attach, inf_child_prepare_to_store): Refactor as
	methods of inf_child_target.
	(inf_child_target::supports_terminal_ours)
	(inf_child_target::terminal_init)
	(inf_child_target::terminal_inferior)
	(inf_child_target::terminal_ours_for_output)
	(inf_child_target::terminal_ours, inf_child_target::interrupt)
	(inf_child_target::pass_ctrlc, inf_child_target::terminal_info):
	New.
	(inf_child_open, inf_child_disconnect, inf_child_close)
	(inf_child_mourn_inferior, inf_child_maybe_unpush_target)
	(inf_child_post_startup_inferior, inf_child_can_run)
	(inf_child_pid_to_exec_file): Refactor as methods of
	inf_child_target.
	(inf_child_follow_fork): Delete.
	(inf_child_target::can_create_inferior)
	(inf_child_target::can_attach): New.
	(inf_child_target::has_all_memory, inf_child_target::has_memory)
	(inf_child_target::has_stack, inf_child_target::has_registers)
	(inf_child_target::has_execution): New.
	(inf_child_fileio_open, inf_child_fileio_pwrite)
	(inf_child_fileio_pread, inf_child_fileio_fstat)
	(inf_child_fileio_close, inf_child_fileio_unlink)
	(inf_child_fileio_readlink, inf_child_use_agent)
	(inf_child_can_use_agent): Refactor as methods of
	inf_child_target.
	(return_zero, inf_child_target): Delete.
	(inf_child_target::inf_child_target): New.
	* inf-child.h: Include "target.h".
	(inf_child_target): Delete function prototype.
	(inf_child_target): New class.
	(inf_child_open_target, inf_child_mourn_inferior)
	(inf_child_maybe_unpush_target): Delete.
	* inf-ptrace.c (inf_ptrace_target::~inf_ptrace_target): New.
	(inf_ptrace_follow_fork, inf_ptrace_insert_fork_catchpoint)
	(inf_ptrace_remove_fork_catchpoint, inf_ptrace_create_inferior)
	(inf_ptrace_post_startup_inferior, inf_ptrace_mourn_inferior)
	(inf_ptrace_attach, inf_ptrace_post_attach, inf_ptrace_detach)
	(inf_ptrace_detach_success, inf_ptrace_kill, inf_ptrace_resume)
	(inf_ptrace_wait, inf_ptrace_xfer_partial)
	(inf_ptrace_thread_alive, inf_ptrace_files_info)
	(inf_ptrace_pid_to_str, inf_ptrace_auxv_parse): Refactor as
	methods of inf_ptrace_target.
	(inf_ptrace_target): Delete function.
	* inf-ptrace.h: Include "inf-child.h".
	(inf_ptrace_target): Delete function declaration.
	(inf_ptrace_target): New class.
	(inf_ptrace_trad_target, inf_ptrace_detach_success): Delete.
	* linux-nat.c (linux_target): New.
	(linux_ops, linux_ops_saved, super_xfer_partial): Delete.
	(linux_nat_target::~linux_nat_target): New.
	(linux_child_post_attach, linux_child_post_startup_inferior)
	(linux_child_follow_fork, linux_child_insert_fork_catchpoint)
	(linux_child_remove_fork_catchpoint)
	(linux_child_insert_vfork_catchpoint)
	(linux_child_remove_vfork_catchpoint)
	(linux_child_insert_exec_catchpoint)
	(linux_child_remove_exec_catchpoint)
	(linux_child_set_syscall_catchpoint, linux_nat_pass_signals)
	(linux_nat_create_inferior, linux_nat_attach, linux_nat_detach)
	(linux_nat_resume, linux_nat_stopped_by_watchpoint)
	(linux_nat_stopped_data_address)
	(linux_nat_stopped_by_sw_breakpoint)
	(linux_nat_supports_stopped_by_sw_breakpoint)
	(linux_nat_stopped_by_hw_breakpoint)
	(linux_nat_supports_stopped_by_hw_breakpoint, linux_nat_wait)
	(linux_nat_kill, linux_nat_mourn_inferior)
	(linux_nat_xfer_partial, linux_nat_thread_alive)
	(linux_nat_update_thread_list, linux_nat_pid_to_str)
	(linux_nat_thread_name, linux_child_pid_to_exec_file)
	(linux_child_static_tracepoint_markers_by_strid)
	(linux_nat_is_async_p, linux_nat_can_async_p)
	(linux_nat_supports_non_stop, linux_nat_always_non_stop_p)
	(linux_nat_supports_multi_process)
	(linux_nat_supports_disable_randomization, linux_nat_async)
	(linux_nat_stop, linux_nat_close, linux_nat_thread_address_space)
	(linux_nat_core_of_thread, linux_nat_filesystem_is_local)
	(linux_nat_fileio_open, linux_nat_fileio_readlink)
	(linux_nat_fileio_unlink, linux_nat_thread_events): Refactor as
	methods of linux_nat_target.
	(linux_nat_wait_1, linux_xfer_siginfo, linux_proc_xfer_partial)
	(linux_proc_xfer_spu, linux_nat_xfer_osdata): Remove target_ops
	parameter.
	(check_stopped_by_watchpoint): Adjust.
	(linux_xfer_partial): Delete.
	(linux_target_install_ops, linux_target, linux_nat_add_target):
	Delete.
	(linux_nat_target::linux_nat_target): New.
	* linux-nat.h: Include "inf-ptrace.h".
	(linux_nat_target): New.
	(linux_target, linux_target_install_ops, linux_nat_add_target):
	Delete function declarations.
	(linux_target): Declare global.
	* linux-thread-db.c (thread_db_target): New.
	(thread_db_target::thread_db_target): New.
	(thread_db_ops): Delete.
	(the_thread_db_target): New.
	(thread_db_detach, thread_db_wait, thread_db_mourn_inferior)
	(thread_db_update_thread_list, thread_db_pid_to_str)
	(thread_db_extra_thread_info)
	(thread_db_thread_handle_to_thread_info)
	(thread_db_get_thread_local_address, thread_db_get_ada_task_ptid)
	(thread_db_resume): Refactor as methods of thread_db_target.
	(init_thread_db_ops): Delete.
	(_initialize_thread_db): Remove reference to init_thread_db_ops.
	* x86-linux-nat.c: Don't include "linux-nat.h".
	(super_post_startup_inferior): Delete.
	(x86_linux_nat_target::~x86_linux_nat_target): New.
	(x86_linux_child_post_startup_inferior)
	(x86_linux_read_description, x86_linux_enable_btrace)
	(x86_linux_disable_btrace, x86_linux_teardown_btrace)
	(x86_linux_read_btrace, x86_linux_btrace_conf): Refactor as
	methods of x86_linux_nat_target.
	(x86_linux_create_target): Delete.  Bits folded ...
	(x86_linux_add_target): ... here.  Now takes a linux_nat_target
	pointer.
	* x86-linux-nat.h: Include "linux-nat.h" and "x86-nat.h".
	(x86_linux_nat_target): New class.
	(x86_linux_create_target): Delete.
	(x86_linux_add_target): Now takes a linux_nat_target pointer.
	* x86-nat.c (x86_insert_watchpoint, x86_remove_watchpoint)
	(x86_region_ok_for_watchpoint, x86_stopped_data_address)
	(x86_stopped_by_watchpoint, x86_insert_hw_breakpoint)
	(x86_remove_hw_breakpoint, x86_can_use_hw_breakpoint)
	(x86_stopped_by_hw_breakpoint): Remove target_ops parameter and
	make extern.
	(x86_use_watchpoints): Delete.
	* x86-nat.h: Include "breakpoint.h" and "target.h".
	(x86_use_watchpoints): Delete.
	(x86_can_use_hw_breakpoint, x86_region_ok_for_hw_watchpoint)
	(x86_stopped_by_watchpoint, x86_stopped_data_address)
	(x86_insert_watchpoint, x86_remove_watchpoint)
	(x86_insert_hw_breakpoint, x86_remove_hw_breakpoint)
	(x86_stopped_by_hw_breakpoint): New declarations.
	(x86_nat_target): New template class.

	* ppc-linux-nat.c (ppc_linux_nat_target): New class.
	(the_ppc_linux_nat_target): New.
	(ppc_linux_fetch_inferior_registers)
	(ppc_linux_can_use_hw_breakpoint)
	(ppc_linux_region_ok_for_hw_watchpoint)
	(ppc_linux_ranged_break_num_registers)
	(ppc_linux_insert_hw_breakpoint, ppc_linux_remove_hw_breakpoint)
	(ppc_linux_insert_mask_watchpoint)
	(ppc_linux_remove_mask_watchpoint)
	(ppc_linux_can_accel_watchpoint_condition)
	(ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint)
	(ppc_linux_stopped_data_address, ppc_linux_stopped_by_watchpoint)
	(ppc_linux_watchpoint_addr_within_range)
	(ppc_linux_masked_watch_num_registers)
	(ppc_linux_store_inferior_registers, ppc_linux_auxv_parse)
	(ppc_linux_read_description): Refactor as methods of
	ppc_linux_nat_target.
	(_initialize_ppc_linux_nat): Adjust.  Set linux_target.

	* procfs.c (procfs_xfer_partial): Delete forward declaration.
	(procfs_target): New class.
	(the_procfs_target): New.
	(procfs_target): Delete function.
	(procfs_auxv_parse, procfs_attach, procfs_detach)
	(procfs_fetch_registers, procfs_store_registers, procfs_wait)
	(procfs_xfer_partial, procfs_resume, procfs_pass_signals)
	(procfs_files_info, procfs_kill_inferior, procfs_mourn_inferior)
	(procfs_create_inferior, procfs_update_thread_list)
	(procfs_thread_alive, procfs_pid_to_str)
	(procfs_can_use_hw_breakpoint, procfs_stopped_by_watchpoint)
	(procfs_stopped_data_address, procfs_insert_watchpoint)
	(procfs_remove_watchpoint, procfs_region_ok_for_hw_watchpoint)
	(proc_find_memory_regions, procfs_info_proc)
	(procfs_make_note_section): Refactor as methods of procfs_target.
	(_initialize_procfs): Adjust.
	* sol-thread.c (sol_thread_target): New class.
	(sol_thread_ops): Now a sol_thread_target.
	(sol_thread_detach, sol_thread_resume, sol_thread_wait)
	(sol_thread_fetch_registers, sol_thread_store_registers)
	(sol_thread_xfer_partial, sol_thread_mourn_inferior)
	(sol_thread_alive, solaris_pid_to_str, sol_update_thread_list)
	(sol_get_ada_task_ptid): Refactor as methods of sol_thread_target.
	(init_sol_thread_ops): Delete.
	(_initialize_sol_thread): Adjust.  Remove references to
	init_sol_thread_ops and complete_target_initialization.

	* windows-nat.c (windows_nat_target): New class.
	(windows_fetch_inferior_registers)
	(windows_store_inferior_registers, windows_resume, windows_wait)
	(windows_attach, windows_detach, windows_pid_to_exec_file)
	(windows_files_info, windows_create_inferior)
	(windows_mourn_inferior, windows_interrupt, windows_kill_inferior)
	(windows_close, windows_pid_to_str, windows_xfer_partial)
	(windows_get_tib_address, windows_get_ada_task_ptid)
	(windows_thread_name, windows_thread_alive): Refactor as
	windows_nat_target methods.
	(do_initial_windows_stuff): Adjust.
	(windows_target): Delete function.
	(_initialize_windows_nat): Adjust.

	* darwin-nat.c (darwin_resume, darwin_wait_to, darwin_interrupt)
	(darwin_mourn_inferior, darwin_kill_inferior)
	(darwin_create_inferior, darwin_attach, darwin_detach)
	(darwin_pid_to_str, darwin_thread_alive, darwin_xfer_partial)
	(darwin_pid_to_exec_file, darwin_get_ada_task_ptid)
	(darwin_supports_multi_process): Refactor as darwin_nat_target
	methods.
	(darwin_resume_to, darwin_files_info): Delete.
	(_initialize_darwin_inferior): Rename to ...
	(_initialize_darwin_nat): ... this.  Adjust to C++ification.
	* darwin-nat.h: Include "inf-child.h".
	(darwin_nat_target): New class.
	(darwin_complete_target): Delete.
	* i386-darwin-nat.c (i386_darwin_nat_target): New class.
	(darwin_target): New.
	(i386_darwin_fetch_inferior_registers)
	(i386_darwin_store_inferior_registers): Refactor as methods of
	darwin_nat_target.
	(darwin_complete_target): Delete, with ...
	(_initialize_i386_darwin_nat): ... bits factored out here.

	* alpha-linux-nat.c (alpha_linux_nat_target): New class.
	(the_alpha_linux_nat_target): New.
	(alpha_linux_register_u_offset): Refactor as
	alpha_linux_nat_target method.
	(_initialize_alpha_linux_nat): Adjust.
	* linux-nat-trad.c (inf_ptrace_register_u_offset): Delete.
	(inf_ptrace_fetch_register, inf_ptrace_fetch_registers)
	(inf_ptrace_store_register, inf_ptrace_store_registers): Refact as
	methods of linux_nat_trad_target.
	(linux_trad_target): Delete.
	* linux-nat-trad.h (linux_trad_target): Delete function.
	(linux_nat_trad_target): New class.
	* mips-linux-nat.c (mips_linux_nat_target): New class.
	(super_fetch_registers, super_store_registers, super_close):
	Delete.
	(the_mips_linux_nat_target): New.
	(mips64_linux_regsets_fetch_registers)
	(mips64_linux_regsets_store_registers)
	(mips64_linux_fetch_registers, mips64_linux_store_registers)
	(mips_linux_register_u_offset, mips_linux_read_description)
	(mips_linux_can_use_hw_breakpoint)
	(mips_linux_stopped_by_watchpoint)
	(mips_linux_stopped_data_address)
	(mips_linux_region_ok_for_hw_watchpoint)
	(mips_linux_insert_watchpoint, mips_linux_remove_watchpoint)
	(mips_linux_close): Refactor as methods of mips_linux_nat.
	(_initialize_mips_linux_nat): Adjust to C++ification.

	* aix-thread.c (aix_thread_target): New class.
	(aix_thread_ops): Now an aix_thread_target.
	(aix_thread_detach, aix_thread_resume, aix_thread_wait)
	(aix_thread_fetch_registers, aix_thread_store_registers)
	(aix_thread_xfer_partial, aix_thread_mourn_inferior)
	(aix_thread_thread_alive, aix_thread_pid_to_str)
	(aix_thread_extra_thread_info, aix_thread_get_ada_task_ptid):
	Refactor as methods of aix_thread_target.
	(init_aix_thread_ops): Delete.
	(_initialize_aix_thread): Remove references to init_aix_thread_ops
	and complete_target_initialization.
	* rs6000-nat.c (rs6000_xfer_shared_libraries): Delete.
	(rs6000_nat_target): New class.
	(the_rs6000_nat_target): New.
	(rs6000_fetch_inferior_registers, rs6000_store_inferior_registers)
	(rs6000_xfer_partial, rs6000_wait, rs6000_create_inferior)
	(rs6000_xfer_shared_libraries): Refactor as rs6000_nat_target methods.
	(super_create_inferior): Delete.
	(_initialize_rs6000_nat): Adjust to C++ification.

	* arm-linux-nat.c (arm_linux_nat_target): New class.
	(the_arm_linux_nat_target): New.
	(arm_linux_fetch_inferior_registers)
	(arm_linux_store_inferior_registers, arm_linux_read_description)
	(arm_linux_can_use_hw_breakpoint, arm_linux_insert_hw_breakpoint)
	(arm_linux_remove_hw_breakpoint)
	(arm_linux_region_ok_for_hw_watchpoint)
	(arm_linux_insert_watchpoint, arm_linux_remove_watchpoint)
	(arm_linux_stopped_data_address, arm_linux_stopped_by_watchpoint)
	(arm_linux_watchpoint_addr_within_range): Refactor as methods of
	arm_linux_nat_target.
	(_initialize_arm_linux_nat): Adjust to C++ification.

	* aarch64-linux-nat.c (aarch64_linux_nat_target): New class.
	(the_aarch64_linux_nat_target): New.
	(aarch64_linux_fetch_inferior_registers)
	(aarch64_linux_store_inferior_registers)
	(aarch64_linux_child_post_startup_inferior)
	(aarch64_linux_read_description)
	(aarch64_linux_can_use_hw_breakpoint)
	(aarch64_linux_insert_hw_breakpoint)
	(aarch64_linux_remove_hw_breakpoint)
	(aarch64_linux_insert_watchpoint, aarch64_linux_remove_watchpoint)
	(aarch64_linux_region_ok_for_hw_watchpoint)
	(aarch64_linux_stopped_data_address)
	(aarch64_linux_stopped_by_watchpoint)
	(aarch64_linux_watchpoint_addr_within_range)
	(aarch64_linux_can_do_single_step): Refactor as methods of
	aarch64_linux_nat_target.
	(super_post_startup_inferior): Delete.
	(_initialize_aarch64_linux_nat): Adjust to C++ification.

	* hppa-linux-nat.c (hppa_linux_nat_target): New class.
	(the_hppa_linux_nat_target): New.
	(hppa_linux_fetch_inferior_registers)
	(hppa_linux_store_inferior_registers): Refactor as methods of
	hppa_linux_nat_target.
	(_initialize_hppa_linux_nat): Adjust to C++ification.

	* ia64-linux-nat.c (ia64_linux_nat_target): New class.
	(the_ia64_linux_nat_target): New.
	(ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint)
	(ia64_linux_stopped_data_address)
	(ia64_linux_stopped_by_watchpoint, ia64_linux_fetch_registers)
	(ia64_linux_store_registers, ia64_linux_xfer_partial): Refactor as
	ia64_linux_nat_target methods.
	(super_xfer_partial): Delete.
	(_initialize_ia64_linux_nat): Adjust to C++ification.

	* m32r-linux-nat.c (m32r_linux_nat_target): New class.
	(the_m32r_linux_nat_target): New.
	(m32r_linux_fetch_inferior_registers)
	(m32r_linux_store_inferior_registers): Refactor as
	m32r_linux_nat_target methods.
	(_initialize_m32r_linux_nat): Adjust to C++ification.

	* m68k-linux-nat.c (m68k_linux_nat_target): New class.
	(the_m68k_linux_nat_target): New.
	(m68k_linux_fetch_inferior_registers)
	(m68k_linux_store_inferior_registers): Refactor as
	m68k_linux_nat_target methods.
	(_initialize_m68k_linux_nat): Adjust to C++ification.

	* s390-linux-nat.c (s390_linux_nat_target): New class.
	(the_s390_linux_nat_target): New.
	(s390_linux_fetch_inferior_registers)
	(s390_linux_store_inferior_registers, s390_stopped_by_watchpoint)
	(s390_insert_watchpoint, s390_remove_watchpoint)
	(s390_can_use_hw_breakpoint, s390_insert_hw_breakpoint)
	(s390_remove_hw_breakpoint, s390_region_ok_for_hw_watchpoint)
	(s390_auxv_parse, s390_read_description): Refactor as methods of
	s390_linux_nat_target.
	(_initialize_s390_nat): Adjust to C++ification.

	* sparc-linux-nat.c (sparc_linux_nat_target): New class.
	(the_sparc_linux_nat_target): New.
	(_initialize_sparc_linux_nat): Adjust to C++ification.
	* sparc-nat.c (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers): Remove target_ops parameter.
	* sparc-nat.h (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers): Remove target_ops parameter.
	* sparc64-linux-nat.c (sparc64_linux_nat_target): New class.
	(the_sparc64_linux_nat_target): New.
	(_initialize_sparc64_linux_nat): Adjust to C++ification.

	* spu-linux-nat.c (spu_linux_nat_target): New class.
	(the_spu_linux_nat_target): New.
	(spu_child_post_startup_inferior, spu_child_post_attach)
	(spu_child_wait, spu_fetch_inferior_registers)
	(spu_store_inferior_registers, spu_xfer_partial)
	(spu_can_use_hw_breakpoint): Refactor as spu_linux_nat_target
	methods.
	(_initialize_spu_nat): Adjust to C++ification.

	* tilegx-linux-nat.c (tilegx_linux_nat_target): New class.
	(the_tilegx_linux_nat_target): New.
	(fetch_inferior_registers, store_inferior_registers):
	Refactor as methods.
	(_initialize_tile_linux_nat): Adjust to C++ification.

	* xtensa-linux-nat.c (xtensa_linux_nat_target): New class.
	(the_xtensa_linux_nat_target): New.
	(xtensa_linux_fetch_inferior_registers)
	(xtensa_linux_store_inferior_registers): Refactor as
	xtensa_linux_nat_target methods.
	(_initialize_xtensa_linux_nat): Adjust to C++ification.

	* fbsd-nat.c (USE_SIGTRAP_SIGINFO): Delete.
	(fbsd_pid_to_exec_file, fbsd_find_memory_regions)
	(fbsd_find_memory_regions, fbsd_info_proc, fbsd_xfer_partial)
	(fbsd_thread_alive, fbsd_pid_to_str, fbsd_thread_name)
	(fbsd_update_thread_list, fbsd_resume, fbsd_wait)
	(fbsd_stopped_by_sw_breakpoint)
	(fbsd_supports_stopped_by_sw_breakpoint, fbsd_follow_fork)
	(fbsd_insert_fork_catchpoint, fbsd_remove_fork_catchpoint)
	(fbsd_insert_vfork_catchpoint, fbsd_remove_vfork_catchpoint)
	(fbsd_post_startup_inferior, fbsd_post_attach)
	(fbsd_insert_exec_catchpoint, fbsd_remove_exec_catchpoint)
	(fbsd_set_syscall_catchpoint)
	(super_xfer_partial, super_resume, super_wait)
	(fbsd_supports_stopped_by_hw_breakpoint): Delete.
	(fbsd_handle_debug_trap): Remove target_ops parameter.
	(fbsd_nat_add_target): Delete.
	* fbsd-nat.h: Include "inf-ptrace.h".
	(fbsd_nat_add_target): Delete.
	(USE_SIGTRAP_SIGINFO): Define.
	(fbsd_nat_target): New class.

	* amd64-bsd-nat.c (amd64bsd_fetch_inferior_registers)
	(amd64bsd_store_inferior_registers): Remove target_ops parameter.
	(amd64bsd_target): Delete.
	* amd64-bsd-nat.h: New file.
	* amd64-fbsd-nat.c: Include "amd64-bsd-nat.h" instead of
	"x86-bsd-nat.h".
	(amd64_fbsd_nat_target): New class.
	(the_amd64_fbsd_nat_target): New.
	(amd64fbsd_read_description): Refactor as method of
	amd64_fbsd_nat_target.
	(amd64_fbsd_nat_target::supports_stopped_by_hw_breakpoint): New.
	(_initialize_amd64fbsd_nat): Adjust to C++ification.
	* amd64-nat.h (amd64bsd_target): Delete function declaration.
	* i386-bsd-nat.c (i386bsd_fetch_inferior_registers)
	(i386bsd_store_inferior_registers): Remove target_ops parameter.
	(i386bsd_target): Delete.
	* i386-bsd-nat.h (i386bsd_target): Delete function declaration.
	(i386bsd_fetch_inferior_registers)
	(i386bsd_store_inferior_registers): Declare.
	(i386_bsd_nat_target): New class.
	* i386-fbsd-nat.c (i386_fbsd_nat_target): New class.
	(the_i386_fbsd_nat_target): New.
	(i386fbsd_resume, i386fbsd_read_description): Refactor as
	i386_fbsd_nat_target methods.
	(i386_fbsd_nat_target::supports_stopped_by_hw_breakpoint): New.
	(_initialize_i386fbsd_nat): Adjust to C++ification.
	* x86-bsd-nat.c (super_mourn_inferior): Delete.
	(x86bsd_mourn_inferior, x86bsd_target): Delete.
	(_initialize_x86_bsd_nat): Adjust to C++ification.
	* x86-bsd-nat.h: Include "x86-nat.h".
	(x86bsd_target): Delete declaration.
	(x86bsd_nat_target): New class.

	* aarch64-fbsd-nat.c (aarch64_fbsd_nat_target): New class.
	(the_aarch64_fbsd_nat_target): New.
	(aarch64_fbsd_fetch_inferior_registers)
	(aarch64_fbsd_store_inferior_registers): Refactor as methods of
	aarch64_fbsd_nat_target.
	(_initialize_aarch64_fbsd_nat): Adjust to C++ification.
	* alpha-bsd-nat.c (alpha_bsd_nat_target): New class.
	(the_alpha_bsd_nat_target): New.
	(alphabsd_fetch_inferior_registers)
	(alphabsd_store_inferior_registers): Refactor as
	alpha_bsd_nat_target methods.
	(_initialize_alphabsd_nat): Refactor as methods of
	alpha_bsd_nat_target.
	* amd64-nbsd-nat.c: Include "amd64-bsd-nat.h".
	(the_amd64_nbsd_nat_target): New.
	(_initialize_amd64nbsd_nat): Adjust to C++ification.
	* amd64-obsd-nat.c: Include "amd64-bsd-nat.h".
	(the_amd64_obsd_nat_target): New.
	(_initialize_amd64obsd_nat): Adjust to C++ification.
	* arm-fbsd-nat.c (arm_fbsd_nat_target): New.
	(the_arm_fbsd_nat_target): New.
	(arm_fbsd_fetch_inferior_registers)
	(arm_fbsd_store_inferior_registers, arm_fbsd_read_description):
	(_initialize_arm_fbsd_nat): Refactor as methods of
	arm_fbsd_nat_target.
	(_initialize_arm_fbsd_nat): Adjust to C++ification.
	* arm-nbsd-nat.c (arm_netbsd_nat_target): New class.
	(the_arm_netbsd_nat_target): New.
	(armnbsd_fetch_registers, armnbsd_store_registers): Refactor as
	arm_netbsd_nat_target.
	(_initialize_arm_netbsd_nat): Adjust to C++ification.
	* hppa-nbsd-nat.c (hppa_nbsd_nat_target): New class.
	(the_hppa_nbsd_nat_target): New.
	(hppanbsd_fetch_registers, hppanbsd_store_registers): Refactor as
	hppa_nbsd_nat_target methods.
	(_initialize_hppanbsd_nat): Adjust to C++ification.
	* hppa-obsd-nat.c (hppa_obsd_nat_target): New class.
	(the_hppa_obsd_nat_target): New.
	(hppaobsd_fetch_registers, hppaobsd_store_registers): Refactor as
	methods of hppa_obsd_nat_target.
	(_initialize_hppaobsd_nat): Adjust to C++ification.  Use
	add_target.
	* i386-nbsd-nat.c (the_i386_nbsd_nat_target): New.
	(_initialize_i386nbsd_nat): Adjust to C++ification.  Use
	add_target.
	* i386-obsd-nat.c (the_i386_obsd_nat_target): New.
	(_initialize_i386obsd_nat): Use add_target.
	* m68k-bsd-nat.c (m68k_bsd_nat_target): New class.
	(the_m68k_bsd_nat_target): New.
	(m68kbsd_fetch_inferior_registers)
	(m68kbsd_store_inferior_registers): Refactor as methods of
	m68k_bsd_nat_target.
	(_initialize_m68kbsd_nat): Adjust to C++ification.
	* mips-fbsd-nat.c (mips_fbsd_nat_target): New class.
	(the_mips_fbsd_nat_target): New.
	(mips_fbsd_fetch_inferior_registers)
	(mips_fbsd_store_inferior_registers): Refactor as methods of
	mips_fbsd_nat_target.
	(_initialize_mips_fbsd_nat): Adjust to C++ification.  Use
	add_target.
	* mips-nbsd-nat.c (mips_nbsd_nat_target): New class.
	(the_mips_nbsd_nat_target): New.
	(mipsnbsd_fetch_inferior_registers)
	(mipsnbsd_store_inferior_registers): Refactor as methods of
	mips_nbsd_nat_target.
	(_initialize_mipsnbsd_nat): Adjust to C++ification.
	* mips64-obsd-nat.c (mips64_obsd_nat_target): New class.
	(the_mips64_obsd_nat_target): New.
	(mips64obsd_fetch_inferior_registers)
	(mips64obsd_store_inferior_registers): Refactor as methods of
	mips64_obsd_nat_target.
	(_initialize_mips64obsd_nat): Adjust to C++ification.  Use
	add_target.
	* nbsd-nat.c (nbsd_pid_to_exec_file): Refactor as method of
	nbsd_nat_target.
	* nbsd-nat.h: Include "inf-ptrace.h".
	(nbsd_nat_target): New class.
	* obsd-nat.c (obsd_pid_to_str, obsd_update_thread_list)
	(obsd_wait): Refactor as methods of obsd_nat_target.
	(obsd_add_target): Delete.
	* obsd-nat.h: Include "inf-ptrace.h".
	(obsd_nat_target): New class.
	* ppc-fbsd-nat.c (ppc_fbsd_nat_target): New class.
	(the_ppc_fbsd_nat_target): New.
	(ppcfbsd_fetch_inferior_registers)
	(ppcfbsd_store_inferior_registers): Refactor as methods of
	ppc_fbsd_nat_target.
	(_initialize_ppcfbsd_nat): Adjust to C++ification.  Use
	add_target.
	* ppc-nbsd-nat.c (ppc_nbsd_nat_target): New class.
	(the_ppc_nbsd_nat_target): New.
	(ppcnbsd_fetch_inferior_registers)
	(ppcnbsd_store_inferior_registers): Refactor as methods of
	ppc_nbsd_nat_target.
	(_initialize_ppcnbsd_nat): Adjust to C++ification.
	* ppc-obsd-nat.c (ppc_obsd_nat_target): New class.
	(the_ppc_obsd_nat_target): New.
	(ppcobsd_fetch_registers, ppcobsd_store_registers): Refactor as
	methods of ppc_obsd_nat_target.
	(_initialize_ppcobsd_nat): Adjust to C++ification.  Use
	add_target.
	* sh-nbsd-nat.c (sh_nbsd_nat_target): New class.
	(the_sh_nbsd_nat_target): New.
	(shnbsd_fetch_inferior_registers)
	(shnbsd_store_inferior_registers): Refactor as methods of
	sh_nbsd_nat_target.
	(_initialize_shnbsd_nat): Adjust to C++ification.
	* sparc-nat.c (sparc_xfer_wcookie): Make extern.
	(inf_ptrace_xfer_partial): Delete.
	(sparc_xfer_partial, sparc_target): Delete.
	* sparc-nat.h (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers, sparc_xfer_wcookie): Declare.
	(sparc_target): Delete function declaration.
	(sparc_target): New template class.
	* sparc-nbsd-nat.c (the_sparc_nbsd_nat_target): New.
	(_initialize_sparcnbsd_nat): Adjust to C++ification.
	* sparc64-fbsd-nat.c (the_sparc64_fbsd_nat_target): New.
	(_initialize_sparc64fbsd_nat): Adjust to C++ification.  Use
	add_target.
	* sparc64-nbsd-nat.c (the_sparc64_nbsd_nat_target): New.
	(_initialize_sparc64nbsd_nat): Adjust to C++ification.
	* sparc64-obsd-nat.c (the_sparc64_obsd_nat_target): New.
	(_initialize_sparc64obsd_nat): Adjust to C++ification.  Use
	add_target.
	* vax-bsd-nat.c (vax_bsd_nat_target): New class.
	(the_vax_bsd_nat_target): New.
	(vaxbsd_fetch_inferior_registers)
	(vaxbsd_store_inferior_registers): Refactor as vax_bsd_nat_target
	methods.
	(_initialize_vaxbsd_nat): Adjust to C++ification.

	* bsd-kvm.c (bsd_kvm_target): New class.
	(bsd_kvm_ops): Now a bsd_kvm_target.
	(bsd_kvm_open, bsd_kvm_close, bsd_kvm_xfer_partial)
	(bsd_kvm_files_info, bsd_kvm_fetch_registers)
	(bsd_kvm_thread_alive, bsd_kvm_pid_to_str): Refactor as methods of
	bsd_kvm_target.
	(bsd_kvm_return_one): Delete.
	(bsd_kvm_add_target): Adjust to C++ification.

	* nto-procfs.c (nto_procfs_target, nto_procfs_target_native)
	(nto_procfs_target_procfs): New classes.
	(procfs_open_1, procfs_thread_alive, procfs_update_thread_list)
	(procfs_files_info, procfs_pid_to_exec_file, procfs_attach)
	(procfs_post_attach, procfs_wait, procfs_fetch_registers)
	(procfs_xfer_partial, procfs_detach, procfs_insert_breakpoint)
	(procfs_remove_breakpoint, procfs_insert_hw_breakpoint)
	(procfs_remove_hw_breakpoint, procfs_resume)
	(procfs_mourn_inferior, procfs_create_inferior, procfs_interrupt)
	(procfs_kill_inferior, procfs_store_registers)
	(procfs_pass_signals, procfs_pid_to_str, procfs_can_run): Refactor
	as methods of nto_procfs_target.
	(nto_procfs_ops): Now an nto_procfs_target_procfs.
	(nto_native_ops): Delete.
	(procfs_open, procfs_native_open): Delete.
	(nto_native_ops): Now an nto_procfs_target_native.
	(init_procfs_targets): Adjust to C++ification.
	(procfs_can_use_hw_breakpoint, procfs_remove_hw_watchpoint)
	(procfs_insert_hw_watchpoint, procfs_stopped_by_watchpoint):
	Refactor as methods of nto_procfs_target.

	* go32-nat.c (go32_nat_target): New class.
	(the_go32_nat_target): New.
	(go32_attach, go32_resume, go32_wait, go32_fetch_registers)
	(go32_store_registers, go32_xfer_partial, go32_files_info)
	(go32_kill_inferior, go32_create_inferior, go32_mourn_inferior)
	(go32_terminal_init, go32_terminal_info, go32_terminal_inferior)
	(go32_terminal_ours, go32_pass_ctrlc, go32_thread_alive)
	(go32_pid_to_str): Refactor as methods of go32_nat_target.
	(go32_target): Delete.
	(_initialize_go32_nat): Adjust to C++ification.

	* gnu-nat.c (gnu_wait, gnu_resume, gnu_kill_inferior)
	(gnu_mourn_inferior, gnu_create_inferior, gnu_attach, gnu_detach)
	(gnu_stop, gnu_thread_alive, gnu_xfer_partial)
	(gnu_find_memory_regions, gnu_pid_to_str): Refactor as methods of
	gnu_nat_target.
	(gnu_target): Delete.
	* gnu-nat.h (gnu_target): Delete.
	(gnu_nat_target): New class.
	* i386-gnu-nat.c (gnu_base_target): New.
	(i386_gnu_nat_target): New class.
	(the_i386_gnu_nat_target): New.
	(_initialize_i386gnu_nat): Adjust to C++ification.

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

	* gdb.base/breakpoint-in-ro-region.exp: Adjust to to_resume and
	to_log_command renames.
	* gdb.base/sss-bp-on-user-bp-2.exp: Likewise.
2018-05-03 00:48:36 +01:00
Pedro Alves 3fffc0701a Eliminate target_ops::to_xclose
In the multi-target branch, I found no need for the target_close vs
target_xclose distinction.  Heap-allocated targets simply delete
themselves in their target_close implementation, while
singleton/static targets don't.

The target_ops C++ification patches will add more commentary around
target_ops's destructor, but there's no destructor yet...

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* bfd-target.c (target_bfd_xclose): Rename to ...
	(target_bfd_close): ... this.
	(target_bfd_reopen): Adjust.
	* target.c (target_close): Remove references to to_xclose.
	* target.h (target_ops::to_xclose): Delete.
	(target_ops::to_close): Update comments.
2018-05-03 00:48:05 +01:00
Pedro Alves 6798487f5b Make inf_ptrace_trad Linux-only, move to separate file
There are only two inf_ptrace_trad_target users, MIPS GNU/Linux and
Alpha GNU/Linux.  They both call it via linux_trad_target.

Move this code out of inf-ptrace.c to a GNU/Linux-specific new file.

Making this code be GNU/Linux-specific simplifies C++ification of
target_ops, because we can make the trad target inherit linux_nat
instead of inheriting inf_ptrace.  That'll be visible in a later patch.

Note this makes linux_target_install_ops an extern function, but that
is temporary -- the function will disappear once target_ops is made a
C++ class with virtual methods, later in the series.  Also, I did not
rename the functions in the new file for a similar reason.  They'll be
renamed again anyway in a couple of patches.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* alpha-linux-nat.c: Include "linux-nat-trad.h" instead of
	"linux-nat.h".
	* configure.nat (alpha-linux, linux-mips): Add linux-nat-trad.o.
	* inf-ptrace.c (inf_ptrace_register_u_offset)
	(inf_ptrace_fetch_register, inf_ptrace_fetch_registers)
	(inf_ptrace_store_register, inf_ptrace_store_registers)
	(inf_ptrace_trad_target): Move to ...
	* linux-nat-trad.c: ... this new file.
	* linux-nat-trad.h: New file.
	* linux-nat.c (linux_target_install_ops): Make extern.
	(linux_trad_target): Delete.
	* linux-nat.h (linux_trad_target): Delete declaration.
	(linux_target_install_ops): Declare.
	* mips-linux-nat.c: Include "linux-nat-trad.h" instead of
	"linux-nat.h".
2018-05-03 00:47:32 +01:00
Pedro Alves c1955e1792 More procfs.c simplification
There are only two architectures using procfs.c (i386/SPARC), and none
of their corresponding nat files overrides any target method.  Move
the add_target calls to procfs.c directly.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* i386-sol2-nat.c (_initialize_amd64_sol2_nat): Don't call
	procfs_target/add_target here.
	* procfs.c (procfs_target): Make static.
	(_initialize_procfs): Call add_target here.
	* procfs.h (struct target_ops): Remove forward declaration.
	(procfs_target): Remove declaration.
	* sparc-sol2-nat.c (_initialize_sparc_sol2_nat): Delete.
2018-05-03 00:47:01 +01:00
Pedro Alves b5c8fcb1b4 Eliminate procfs.c:procfs_use_watchpoints
Now that procfs.c is only ever used by Solaris, and, both x86 and
SPARC Solaris support watchpoints (*), we don't need the separate
procfs_use_watchpoints function.  Getting rid of it simplifies
C++ification of target_ops.

(*) and I assume that any other Solaris port would use the same kernel
debug API interfaces for watchpoints.  Otherwise, we can worry about
it if it ever happens.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>

	* procfs.c (procfs_stopped_by_watchpoint)
	(procfs_insert_watchpoint, procfs_remove_watchpoint)
	(procfs_region_ok_for_hw_watchpoint, procfs_stopped_data_address):
	Forward declare.
	(procfs_use_watchpoints): Delete, move contents...
	(procfs_target): ... here.
	* procfs.h (procfs_use_watchpoints): Delete declaration.
	* i386-sol2-nat.c (_initialize_amd64_sol2_nat): Don't call
	procfs_use_watchpoints.
	* sparc-sol2-nat.c (_initialize_sparc_sol2_nat): Don't call
	procfs_use_watchpoints.
2018-05-03 00:37:07 +01:00
Tom Tromey 77d3c63b0d Set test message in py-parameter.exp
Pedro pointed out that a test in py-parameter.exp had an empty
message.  This fixes it.

testsuite/ChangeLog
2018-05-02  Tom Tromey  <tom@tromey.com>

	* gdb.python/py-parameter.exp: Set test message.
2018-05-02 16:37:57 -06:00
Tom Tromey 0489430a0e Handle var_zuinteger and var_zuinteger_unlimited from Python
PR python/20084 points out that the Python API doesn't handle the
var_zuinteger and var_zuinteger_unlimited parameter types.

This patch adds support for these types.

Regression tested on x86-64 Fedora 26.

ChangeLog
2018-05-02  Tom Tromey  <tom@tromey.com>

	PR python/20084:
	* python/python.c (gdbpy_parameter_value): Handle var_zuinteger
	and var_zuinteger_unlimited.
	* python/py-param.c (struct parm_constant): Add PARAM_ZUINTEGER
	and PARAM_ZUINTEGER_UNLIMITED.
	(set_parameter_value): Handle var_zuinteger and
	var_zuinteger_unlimited.
	(add_setshow_generic): Likewise.
	(parmpy_init): Likewise.

doc/ChangeLog
2018-05-02  Tom Tromey  <tom@tromey.com>

	PR python/20084:
	* python.texi (Parameters In Python): Document PARAM_ZUINTEGER and
	PARAM_ZUINTEGER_UNLIMITED.

testsuite/ChangeLog
2018-05-02  Tom Tromey  <tom@tromey.com>

	PR python/20084:
	* gdb.python/py-parameter.exp: Add PARAM_ZUINTEGER and
	PARAM_ZUINTEGER_UNLIMITED tests.
2018-05-02 10:31:55 -06:00
Dan Robertson 1632f8baf0 rust: Fix null deref when casting (PR 23124)
Fix a null dereference when casting a value to a unit type.

ChangeLog
2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>

	PR rust/23124
	* gdb/rust-exp.y (convert_params_to_types): Ensure that the params
	pointer is not null before dereferencing it.

testsuite/ChangeLog
2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>

	PR rust/23124
	* gdb.rust/expr.exp: Test that the unit type is correctly parsed
	when casting.
2018-04-30 23:02:01 -06:00
Joel Brobecker 0ca1fc2913 [Ada/ravenscar] error during "continue" after task/thread switch
When debugging a program using the Ada ravenscar profile, resuming
a program's execution after having switched to a different task
sometimes yields the following error:

     (gdb) cont
     Continuing.
     Cannot execute this command while the target is running.
     Use the "interrupt" command to stop the target
     and then try again.

In short, the Ravenscar profile is a standardized subset of Ada which
allows tasking (often mapped to threads). We often use it on baremetal
targets where there is no OS support. Thread support is implemented
as a thread target_ops layer. It sits on top of the "remote" layer,
so we can do thread debugging against baremetal targets to which GDB
is connected via "target remote".

What happens, when the user request the program to resume execution,
is the following:

  - the ravenscar-thread target_ops layer gets the order to resume
    the program's execution. The current thread is not the active
    thread in the inferior, and the "remote" layer doesn't know
    about that thread anyway. So what we do is (see ravenscar_resume):

       + switch inferior_ptid to the ptid of the actually active thread;
       + ask the layer beneath us to actually do the resume.

  - Once that's done, the resuming itself is done. But execute_command
    (in top.c) actually does a bit more. More precisely, it unconditionally
    checks to see if the language may no longer be matching the current
    frame:

        check_frame_language_change ();

The problem, here, is that we haven't received the "stop" event
from the inferior, yet. This part will be handled by the event loop,
which is done later. So, checking for the language-change here
doesn't make sense, since we don't really have a frame. In our
case, the error comes from the fact that we end up trying to read
the registers, which causes the error while the remote protocol
is waiting for the event showing the inferior stopped.

This apparently used to work, but it is believed that this was only
accidental. In other words, we had enough information already cached
within GDB that we were able to perform the entire call to
check_frame_language_change without actually querying the target.
On PowerPC targets, this started to fail as a side-effect of a minor
change in the way we get to the regcache during the handling of
software-single-step (which seems fine).

This patch fixes the issue by only calling check_frame_language_change
in cases the inferior isn't running. Otherwise, it skips it, knowing
that the event loop should eventually get to it.

gdb/ChangeLog:

        * top.c (execute_command): Do not call check_frame_language_change
        if the inferior is running.

Tested on x86_64-linux, no regression. Also tested on aarch64-elf,
arm-elf, leon3-elf, and ppc-elf, but using AdaCore's testsuite.
2018-04-30 18:13:23 -04:00
Tom Tromey 7676193654 Remove a use of is_mi_like_p from darwin-nat-info.c
This removes a use of is_mi_like_p from darwin-nat-info.c.
This is not needed because MI already ignores ui_out::text.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* darwin-nat-info.c (darwin_debug_regions_recurse): Remove use of
	is_mi_like_p.
2018-04-30 12:59:06 -06:00
Tom Tromey 2d33446d4d Remove some is_mi_like_p from breakpoint code
This removes some uses of is_mi_like_p from the breakpoint code.  The
break-catch-throw.c change brings it into line with what other
breakpoint classes do.  The other changes simply replace printf calls
with ui_out::text or ui_out::message calls.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (mention): Remove use of is_mi_like_p.
	(print_mention_ranged_breakpoint): Likewise.
	* break-catch-throw.c (print_it_exception_catchpoint): Remove use
	of is_mi_like_p.
2018-04-30 12:59:05 -06:00
Tom Tromey f3c6ababac Remove a use of is_mi_like_p from tracepoint.c
This removes a use of is_mi_like_p and changes a printf_filtered into
a call to ui_out::text.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (tvariables_info_1): Remove use of is_mi_like_p.
2018-04-30 12:59:05 -06:00
Tom Tromey 40c03530b1 Remove some uses of is_mi_like_p from spu-tdep.c
There were a few spots in spu-tdep.c where a use of is_mi_like_p was
not needed.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* spu-tdep.c (info_spu_mailbox_list, info_spu_dma_cmdlist)
	(info_spu_event_command): Remove some uses of is_mi_like_p.
2018-04-30 12:59:04 -06:00
Tom Tromey 2038b7fdf3 Remove some uses of is_mi_like_p from py-framefilter.c
Some uses of is_mi_like_p in py-framefilter.c were not needed.  In
general a call to ui_out::text, ui_out::message, or ui_out::spaces
does not need to be guarded -- these are already ignored by MI.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (py_print_single_arg)
	(enumerate_locals, py_print_args, py_print_frame): Remove some
	uses of is_mi_like_p.
2018-04-30 12:59:04 -06:00
Tom Tromey 4904c3c6b6 Make do_is_mi_like_p const.
This changes ui_out to make is_mi_like_p and do_is_mi_like_p "const".

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* ui-out.c: Update.
	* cli-out.h (cli_ui_out::do_is_mi_like_p): Update.
	* ui-out.h (ui_out::is_mi_like_p): Now const.
	(ui_out::do_is_mi_like_p): Now const.
	* mi/mi-out.h (mi_ui_out::do_is_mi_like_p): Update.
2018-04-30 12:59:03 -06:00
Tom Tromey 7c66fffc1f Change Python code to use new_reference
This changes a few spots in the Python code to use new_reference
rather than the manual incref+constructor that was previously being
done.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* varobj.c (varobj_set_visualizer): Use new_reference.
	* python/python.c (gdbpy_decode_line): Use new_reference.
	* python/py-cmd.c (cmdpy_function, cmdpy_completer_helper): Use
	new_reference.
2018-04-30 11:33:12 -06:00
Tom Tromey bbfa6f0086 Use new_reference for struct value
value_incref returned its argument just as a convenience, which in the
end turned out to only be used in precisely the cases where
new_reference helps.  So, this patch changes value_incref to return
void and changes some value-using code to use new_reference.

I also noticed that the comments for value_incref and value_decref
were swapped, so this patch fixes those.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* varobj.c (install_new_value): Use new_reference.
	* value.h (value_incref): Return void.  Swap intro comment with
	value_decref.
	* value.c (set_value_parent): Use new_reference.
	(value_incref): Return void.  Update intro comment.
	(release_value): Use new_reference.
	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Use new_reference.
2018-04-30 11:33:11 -06:00
Tom Tromey 1831a9f9d3 Remove new_bfd_ref
For gdb_bfd_ref_ptr, gdb already had a convenience function like the
new gdb_ref_ptr::new_reference -- called new_bfd_ref.  This patch
removes it in favor of the new common function.

While doing this I also noticed that the comment for gdb_bfd_open was
incorrect (in a way related to reference counting), so this patch
updates the comment as well.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* symfile-mem.c (symbol_file_add_from_memory): Use new_reference.
	* gdb_bfd.h (new_bfd_ref): Remove.
	(gdb_bfd_open): Update comment.
	* gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr)
	(gdb_bfd_openw, gdb_bfd_openr_iovec, gdb_bfd_record_inclusion)
	(gdb_bfd_fdopenr): Use new_reference.
	* exec.c (exec_file_attach): Use new_reference.
2018-04-30 11:33:11 -06:00
Tom Tromey 7c1b5f3db7 Introduce ref_ptr::new_reference
I noticed a common pattern with gdb::ref_ptr, where callers would
"incref" and then create a new wrapper object, like:

    Py_INCREF (obj);
    gdbpy_ref<> ref (obj);

The ref_ptr constructor intentionally does not acquire a new
reference, but it seemed to me that it would be reasonable to add a
static member function that does so.

In this patch I chose to call the function "new_reference".  I
considered "acquire_reference" as well, but "new" seemed less
ambiguous than "acquire" to me.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* common/gdb_ref_ptr.h (ref_ptr::new_reference): New static
	method.
2018-04-30 11:33:11 -06:00
Tom Tromey e11fb955fb Remove long_long_align_bit gdbarch attribute
This removes the long_long_align_bit gdbarch attribute in favor of
type_align.  This uncovered two possible issues.

First, arc-tdep.c claimed that long long alignment was 32 bits, but as
discussed on the list, ARC has a maximum alignment of 32 bits, so I've
added an arc_type_align function to account for this.

Second, jit.c, the sole user of long_long_align_bit, was confusing
"long long" with uint64_t.  The relevant structure is defined in the
JIT API part of the manual as:

     struct jit_code_entry
     {
       struct jit_code_entry *next_entry;
       struct jit_code_entry *prev_entry;
       const char *symfile_addr;
       uint64_t symfile_size;
     };

I've changed this code to use uint64_t.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* jit.c (jit_read_code_entry): Use type_align.
	* i386-tdep.c (i386_gdbarch_init): Don't call
	set_gdbarch_long_long_align_bit.
	* gdbarch.sh: Remove long_long_align_bit.
	* gdbarch.c, gdbarch.h: Rebuild.
	* arc-tdep.c (arc_type_align): New function.
	(arc_gdbarch_init): Use arc_type_align.  Don't call
	set_gdbarch_long_long_align_bit.
2018-04-30 11:25:32 -06:00
Tom Tromey 2fff16dd8c Remove rust_type_alignment
rust_type_alignment is not needed now that gdb has type alignment
code.  So, this removes it.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_type_alignment): Remove.
	(rust_composite_type): Use type_align.
2018-04-30 11:25:32 -06:00
Tom Tromey 6d7bb8246b Expose type alignment on gdb.Type
This adds an "alignof" attribute to gdb.Type in the Python API.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* NEWS: Mention Type.align.
	* python/py-type.c (typy_get_alignof): New function.
	(type_object_getset): Add "alignof".

2018-04-30  Tom Tromey  <tom@tromey.com>

	* python.texi (Types In Python): Document Type.align.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* gdb.python/py-type.exp: Check align attribute.
	* gdb.python/py-type.c: New "aligncheck" global.
2018-04-30 11:25:31 -06:00
Tom Tromey 007e153034 Handle alignof and _Alignof
This adds alignof and _Alignof to the C/C++ expression parser, and
adds new tests to test the features.  The tests are written to try to
ensure that gdb's knowledge of alignment rules stays in sync with the
compiler's.

2018-04-30  Tom Tromey  <tom@tromey.com>

	PR exp/17095:
	* NEWS: Update.
	* std-operator.def (UNOP_ALIGNOF): New operator.
	* expprint.c (dump_subexp_body_standard) <case UNOP_ALIGNOF>:
	New.
	* eval.c (evaluate_subexp_standard) <case UNOP_ALIGNOF>: New.
	* c-lang.c (c_op_print_tab): Add alignof.
	* c-exp.y (ALIGNOF): New token.
	(exp): Add "ALIGNOF" production.
	(ident_tokens): Add _Alignof and alignof.

2018-04-30  Tom Tromey  <tom@tromey.com>

	PR exp/17095:
	* gdb.dwarf2/dw2-align.exp: New file.
	* gdb.cp/align.exp: New file.
	* gdb.base/align.exp: New file.
	* lib/gdb.exp (gdb_int128_helper): New proc.
	(has_int128_c, has_int128_cxx): New caching procs.
2018-04-30 11:25:31 -06:00
Tom Tromey 2b4424c35b Add initial type alignment support
This adds some basic type alignment support to gdb.  It changes struct
type to store the alignment, and updates dwarf2read.c to handle
DW_AT_alignment.  It also adds a new gdbarch method and updates
i386-tdep.c.

None of this new functionality is used anywhere yet, so tests will
wait until the next patch.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* i386-tdep.c (i386_type_align): New function.
	(i386_gdbarch_init): Update.
	* gdbarch.sh (type_align): New method.
	* gdbarch.c, gdbarch.h: Rebuild.
	* arch-utils.h (default_type_align): Declare.
	* arch-utils.c (default_type_align): New function.
	* gdbtypes.h (TYPE_ALIGN_BITS): New define.
	(struct type) <align_log2>: New field.
	<instance_flags>: Now a bitfield.
	(TYPE_RAW_ALIGN): New macro.
	(type_align, type_raw_align, set_type_align): Declare.
	* gdbtypes.c (type_align, type_raw_align, set_type_align): New
	functions.
	* dwarf2read.c (quirk_rust_enum): Set type alignment.
	(get_alignment, maybe_set_alignment): New functions.
	(read_structure_type, read_enumeration_type, read_array_type)
	(read_set_type, read_tag_pointer_type, read_tag_reference_type)
	(read_subrange_type, read_base_type): Set type alignment.
2018-04-30 11:25:30 -06:00
Simon Marchi d33bc52e51 Use bool in read_index_from_section
gdb/ChangeLog:

	* dwarf2read.c (read_index_from_section): Use bool.
2018-04-30 11:06:57 -04:00
Fabian Groffen e28b63a989 proc-events.c: fix compilation on Solaris
This patch adds a guard around the usage of SYS_uuidsys, which is
not available on (at least) Solaris 10 and OpenIndiana.

gdb/ChangeLog:

	PR gdb/22950
	* proc-events.c (init_syscall_table): Guard usage os SYS_uuidsys
	with #ifdef.
2018-04-29 12:05:10 -04:00
John Reiser cd8c76e410 Fix race when building ada-lex.c
Prevent a race when building ada-lex.c, and any target of rules .c:.l or
.c:.y.  The target should be written only at the last step, else SIGINT
(^C) can leave an inconsistent state.  Being .PRECIOUS makes it even
worse.

gdb/ChangeLog:

	PR build/22873
	* gdb/Makefile.in: (.c:.l, .c:.y): Write the target only in the
	last step, and do it atomically.
2018-04-29 11:57:38 -04:00
Alexandre Oliva 476d250ee8 Add libcc1 v1 compatibility to C compile feature
This patch adds v1 compatibiltiy to the C compile feature.  The only change
in v1 concerns the handling of integer types, which permits GDB to specify
the built-in name for the type.

As far as I know, the C frontend is still on v0, so this patch is purely
precautionary. [By default C++ compile uses the equivalent of the C
frontend's int_type and float_type (aka the "v1" versions).]

gdb/ChangeLog:

	* compile/compile-c-types.c (convert_int, convert_float):
	Update for C FE v1.
2018-04-27 12:36:19 -07:00
Tom Tromey 6873858b7e Add inclusive range support for Rust
This is version 2 of the patch to add inclusive range support for
Rust.  I believe it addresses all review comments.

Rust recently stabilized the inclusive range feature:

    https://github.com/rust-lang/rust/issues/28237

An inclusive range is an expression like "..= EXPR" or "EXPR ..=
EXPR".  It is like an ordinary range, except the upper bound is
inclusive, not exclusive.

This patch adds support for this feature to gdb.

Regression tested on x86-64 Fedora 27.

2018-04-27  Tom Tromey  <tom@tromey.com>

	PR rust/22545:
	* rust-lang.c (rust_inclusive_range_type_p): New function.
	(rust_range): Handle inclusive ranges.
	(rust_compute_range): Likewise.
	* rust-exp.y (struct rust_op) <inclusive>: New field.
	(DOTDOTEQ): New constant.
	(range_expr): Add "..=" productions.
	(operator_tokens): Add "..=" token.
	(ast_range): Add "inclusive" parameter.
	(convert_ast_to_expression) <case OP_RANGE>: Handle inclusive
	ranges.
	* parse.c (operator_length_standard) <case OP_RANGE>: Handle new
	bounds values.
	* expression.h (enum range_type) <NONE_BOUND_DEFAULT_EXCLUSIVE,
	LOW_BOUND_DEFAULT_EXCLUSIVE>: New constants.
	Update comments.
	* expprint.c (print_subexp_standard): Handle new bounds values.
	(dump_subexp_body_standard): Likewise.

2018-04-27  Tom Tromey  <tom@tromey.com>

	PR rust/22545:
	* gdb.rust/simple.exp: Add inclusive range tests.
2018-04-27 13:20:13 -06:00
Tom Tromey 632e107b32 Enable -Wsuggest-override
I noticed the existence of -Wsuggest-override and so this patch
enables it for gdb.  It found a few spots that could use "override".
Also I went ahead and removed all uses of the "OVERRIDE" macro.

Using override is beneficial because it makes it harder to change a
base class and then forget to change a derived class.

Tested by the buildbot.

ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Add -Wsuggest-override.
	* dwarf2loc.c (class dwarf_evaluate_loc_desc): Use "override", not
	"OVERRIDE".
	(class symbol_needs_eval_context): Likewise.
	* dwarf2read.c (mock_mapped_index::symbol_name_count)
	(mock_mapped_index::symbol_name_at): Use "override".  Remove
	"virtual".
	* dwarf2-frame.c (dwarf_expr_executor::get_addr_index): Use
	"override".
	(class dwarf_expr_executor): Use "override", not "OVERRIDE".
	* aarch64-tdep.c (instruction_reader::read): Use "override".
	(instruction_reader_test::read): Likewise.
	* arm-tdep.c (instruction_reader::read): Use "override".
	(instruction_reader_thumb::read): Likewise.

gdbserver/ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2018-04-27 12:53:14 -06:00
Andrzej Kaczmarek b75abf5bb6 Fix remote 'g' command error handling (PR remote/9665)
'g' command returns hex-string as response so simply checking for 'E'
to determine if it failed is not enough and can trigger spurious error
messages.  For example, invalid behaviour can be easily triggered on
Cortex-M as follows:

  (gdb) set $r0 = 0xe0
  Sending packet: $P0=e0000000#72...Packet received: OK
  Packet P (set-register) is supported
  Sending packet: $g#67...Packet received: E0000000849A0020...
  Remote failure reply: E0000000849A0020...

This patch fixes the problem by calling putpkt()/getpkt() directly and
checking result with packet_check_result().  This works fine since Enn
response has odd number of bytes while proper response has even number
of bytes.

Also, remote_send() is now not used anywhere so it can be removed.

gdb/Changelog:
2018-04-26  Andrzej Kaczmarek  <andrzej.kaczmarek@codecoup.pl>

	PR remote/9665
	* remote.c (send_g_packet): Use putpkt/getpkt/packet_check_result
	instead of remote_send.
	(remote_send): Remove.
2018-04-26 23:47:25 +01:00
Pedro Alves 79188d8d27 Fix resolving GNU ifunc bp locations when inferior runs resolver
I noticed that if you set a breakpoint on an ifunc before the ifunc is
resolved, and then let the program call the ifunc, thus resolving it,
GDB end up with a location for that original breakpoint that is
pointing to the ifunc target, but it is left pointing to the first
address of the function, instead of after its prologue.  After
prologue is what you get if you create a new breakpoint at that point.

1) With no debug info for the target function:

  1.a) Set before resolving, and then program continued passed resolving:

    Num     Type           Disp Enb Address            What
    1       breakpoint     keep y   0x0000000000400753 <final>

  1.b) Breakpoint set after inferior resolved ifunc:

    Num     Type           Disp Enb Address            What
    2       breakpoint     keep y   0x0000000000400757 <final+4>


2) With debug info for the target function:

   1.a) Set before resolving, and then program continued passed resolving:

     Num     Type           Disp Enb Address            What
     1       breakpoint     keep y   0x0000000000400753 in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:20

   1.b) Breakpoint set after inferior resolved ifunc:

     Num     Type           Disp Enb Address            What
     2       breakpoint     keep y   0x000000000040075a in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:21

The problem is that elf_gnu_ifunc_resolver_return_stop (called by the
internal breakpoint that traps the resolver returning) does not agree
with linespec.c:minsym_found.  It does not skip to the function's
start line (i.e., past the prologue).  We can now use the
find_function_start_sal overload added by the previous commmit to fix
this.

New tests included, which fail before the patch, and pass afterwards.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* elfread.c (elf_gnu_ifunc_resolver_return_stop): Use
	find_function_start_sal instead of find_pc_line.

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

	* gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves
	ifunc breakpoint locations correctly of ifunc breakpoints set
	while the program resolves the ifunc.
2018-04-26 13:12:09 +01:00
Pedro Alves c7075ad503 Extend GNU ifunc testcases
This patch extends/rewrites the gdb.base/gnu-ifunc.exp testcase to
cover the many different fixes in earlier patches.  (This was actually
what encovered most of the problems.)

The current testcase uses an ifunc symbol with the same name as the
ifunc resolver symbol and makes sure to compile the ifunc resolver
without debug info.  That does not model how ifuncs are implemented in
gcc/ifunc nowadays.  Instead, what we have is that the glibc ifunc
resolvers nowadays are written in C and end up with debug info.

Also, in some cases the ifunc target is written in assembly, but in
other cases it's written in C.  In the case of target function written
in C, if the target function has debug info, when we set a break on
the ifunc, we want to set it past the prologue of the target function.
Currently GDB gets that wrong.

To make sure we cover all the different scenarios, the testcase is
tweaked to cover all the different combinations of

 - An ifunc resolver with the same name as the user-visible symbol vs
   an ifunc resolver with a different name as the user-visible symbol.

 - ifunc resolver compiled with and without debug info.

 - ifunc target function compiled with and without debug info.

The testcase currently sets breakpoints on ifuncs, calls ifunc
functions, steps into ifunc functions, etc.  After this series, this
all works and the testcase passes cleanly.

While working on this, I noticed that "b gnu_ifunc" before and after
the inferior resolved the ifunc would end up with a breakpoint with
different locations.  That's now covered by new tests inside the new
"set-break" procedure.

It also tests other things like making sure we can't call an ifunc
without a return-type case if we don't know the type of the target.
And making sure that we pass enough arguments when we do know the
type.

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

	* gdb.base/gnu-ifunc-final.c: New file.
	* gdb.base/gnu-ifunc.c (final): Delete, moved to gnu-ifunc-final.c.
	* gdb.base/gnu-ifunc.exp (executable): Delete.
	(staticexecutable): Adjust.
	(lib_opts, exec_opts): Delete.
	(make_binsuffix, build, set-break): New procedures.
	(misc_tests): New, with tests factored out from the top level.
	(top level): Test different combinations of ifunc resolver name,
	resolver with and with debug info, and ifunc target with and
	without debug info.  Wrap static tests with with_target_prefix.
2018-04-26 13:11:09 +01:00
Pedro Alves f50776aad5 For PPC64/ELFv1: Introduce mst_data_gnu_ifunc
Running the new tests added later in the series on PPC64 (ELFv1)
revealed that the current ifunc support needs a bit of a design rework
to work properly on PPC64/ELFv1, as most of the new tests fail.  The
ifunc support only kind of works today if the ifunc symbol and the
resolver have the same name, as is currently tested by the
gdb.base/gnu-ifunc.exp testcase, which is unlike how ifuncs are
written nowadays.

The crux of the problem is that ifunc symbols are really function
descriptors, not text symbols:

   44: 0000000000020060    104 FUNC    GLOBAL DEFAULT       18 gnu_ifunc_resolver
   54: 0000000000020060    104 GNU_IFUNC GLOBAL DEFAULT     18 gnu_ifunc

But, currently GDB only knows about ifunc symbols that are text
symbols.  GDB's support happens to work in practice for PPC64 when the
ifunc and resolver are one and only, like in the current
gdb.base/gnu-ifunc.exp testcase:

   15: 0000000000020060    104 GNU_IFUNC GLOBAL DEFAULT       18 gnu_ifunc

because in that case, the synthetic ".gnu_ifunc" entry point text
symbol that bfd creates from the actual GNU ifunc "gnu_ifunc" function
(descriptor) symbol ends up with the the "is a gnu ifunc" flag set /
copied over:

  (gdb) maint print msymbols
  ...
  [ 8] i 0x9c4 .gnu_ifunc section .text                <<< mst_text_gnu_ifunc
  ...
  [29] D 0x20060 gnu_ifunc section .opd  crtstuff.c    <<< mst_data

But, if the resolver gets a distinct symbol/name from the ifunc
symbol, then we end up with this:

  (gdb) maint print msymbols
  [ 8] T 0x9e4 .gnu_ifunc_resolver section .text               <<< mst_text
  ...
  [29] D 0x20060 gnu_ifunc section .opd  crtstuff.c            <<< mst_data
  [30] D 0x20060 gnu_ifunc_resolver section .opd  crtstuff.c   <<< mst_data

I have a follow up bfd patch that turns that into:

   (gdb) maint print msymbols
+  [ 8] i 0x9e4 .gnu_ifunc section .text               <<< mst_text_gnu_ifunc
   [ 8] T 0x9e4 .gnu_ifunc_resolver section .text      <<< mst_text
   ...
   [29] D 0x20060 gnu_ifunc section .opd  crtstuff.c
   [30] D 0x20060 gnu_ifunc_resolver section .opd  crtstuff.c

but that won't help everything.  We still need this patch.

Specifically, when we do a symbol lookup by name, like e.g., to call a
function (see c-exp.y hunk), e.g., "p gnu_ifunc()", then we need to
know that the found "gnu_ifunc" minimal symbol is an ifunc in order to
do some special processing.  But, on PPC, that lookup by name finds
the function descriptor symbol, which presently is just a mst_data
symbol, while at present, we look for mst_text_gnu_ifunc symbols to
decide whether to do special GNU ifunc processing.  In most of those
places, we could try to resolve the function descriptor with
gdbarch_convert_from_func_ptr_addr, and then lookup the minimal symbol
at the resolved PC, see if that finds a minimal symbol of type
mst_text_gnu_ifunc.  If so, then we could assume that the original
mst_dadta / function descriptor "gnu_ifunc" symbol was an ifunc.  I
tried it, and it mostly works, even if it's not the most efficient.

However, there's one case that can't work with such a design -- it's
that of the user calling the ifunc resolver directly to debug it, like
"p gnu_ifunc_resolver(0)", expecting that to return the function
pointer of the final function (which is exercised by the new tests
added later).  In this case, with the not-fully-working solution, we'd
resolve the function descriptor, find that there's an
mst_text_gnu_ifunc symbol for the resolved address, and proceed
calling the function as if we tried to call "gnu_ifunc", the
user-visible GNU ifunc symbol, instead of the resolver.  I.e., it'd be
impossible to call the resolver directly as a normal function.

Introducing mst_data_gnu_ifunc eliminates the need for several
gdbarch_convert_from_func_ptr_addr calls, and, fixes the "call
resolver directly" use case mentioned above too.  It's the cleanest
approach I could think of.

In sum, we make GNU ifunc function descriptor symbols get a new
"mst_data_gnu_ifunc" minimal symbol type instead of the bare mst_data
type.  So when symbol lookup by name finds such a minimal symbol, we
know we found an ifunc symbol, without resolving the entry/text
symbol.  If the user calls the the resolver symbol instead, like "p
gnu_ifunc_resolver(0)", then we'll find the regular mst_data symbol
for "gnu_ifunc_resolver", and we'll call the resolver function as just
another regular function.

With this, most of the GNU ifunc tests added by a later patch pass on
PPC64 too.  The following bfd patch fixes the remaining issues.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (set_breakpoint_location_function): Handle
	mst_data_gnu_ifunc.
	* c-exp.y (variable production): Handle mst_data_gnu_ifunc.
	* elfread.c (elf_symtab_read): Give data symbols with
	BSF_GNU_INDIRECT_FUNCTION set mst_data_gnu_ifunc type.
	(elf_rel_plt_read): Update comment.
	* linespec.c (convert_linespec_to_sals): Handle
	mst_data_gnu_ifunc.
	(minsym_found): Handle mst_data_gnu_ifunc.
	* minsyms.c (msymbol_is_function, minimal_symbol_reader::record)
	(find_solib_trampoline_target): Handle mst_data_gnu_ifunc.
	* parse.c (find_minsym_type_and_address): Handle
	mst_data_gnu_ifunc.
	* symmisc.c (dump_msymbols): Handle mst_data_gnu_ifunc.
	* symtab.c (find_gnu_ifunc): Handle mst_data_gnu_ifunc.
	* symtab.h (minimal_symbol_type) <mst_text_gnu_ifunc>: Update
	comment.
	<mst_data_gnu_ifunc>: New enumerator.
2018-04-26 13:09:16 +01:00
Pedro Alves 20944a6e20 Fix stepping past GNU ifunc resolvers (introduce lookup_msym_prefer)
When we're stepping (with "step"), we want to skip trampoline-like
functions automatically, including GNU ifunc resolvers.  That is done
by infrun.c calling into:

  in_solib_dynsym_resolve_code
    -> svr4_in_dynsym_resolve_code
      -> in_gnu_ifunc_stub

A problem here is that if there's a regular text symbol at the same
address as the ifunc symbol, the minimal symbol lookup in
in_gnu_ifunc_stub may miss the GNU ifunc symbol:

(...)
    41: 000000000000071a    53 FUNC    GLOBAL DEFAULT   11 gnu_ifunc_resolver
(...)
    50: 000000000000071a    53 IFUNC   GLOBAL DEFAULT   11 gnu_ifunc
(...)

This causes this FAIL in the tests added later in the series:

 (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: resolver received HWCAP
 set step-mode on
 (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: set step-mode on
 step
 0x00007ffff7bd371a in gnu_ifunc_resolver () from build/gdb/testsuite/outputs/gdb.base/gnu-ifunc/gnu-ifunc-lib-1-0-0.so
 (gdb) FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: step

Above, GDB simply thought that it stepped into a regular function, so
it stopped stepping, while it should have continued stepping past the
resolver.

The fix is to teach minimal symbol lookup to prefer GNU ifunc symbols
if desired.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* minsyms.c (lookup_minimal_symbol_by_pc_section_1): Rename to ...
	(lookup_minimal_symbol_by_pc_section): ... this.  Replace
	'want_trampoline' parameter by a lookup_msym_prefer parameter.
	Handle it.
	(lookup_minimal_symbol_by_pc_section): Delete old implementation.
	(lookup_minimal_symbol_by_pc): Adjust.
	(in_gnu_ifunc_stub): Prefer GNU ifunc symbols.
	(lookup_solib_trampoline_symbol_by_pc): Adjust.
	* minsyms.h (lookup_msym_prefer): New enum.
	(lookup_minimal_symbol_by_pc_section): Replace 'want_trampoline'
	parameter by a lookup_msym_prefer parameter.
2018-04-26 13:08:47 +01:00
Pedro Alves 1adeb82266 For PPC64: elf_gnu_ifunc_record_cache: handle plt symbols in .text section
elf_gnu_ifunc_record_cache doesn't ever record anything on PPC64
(tested on gcc110 on the compile farm, CentOS 7.4, ELFv1), because
that expects to find PLT symbols in the .plt section, while there we
get:

  (gdb) info symbol 'gnu_ifunc@plt'
  gnu_ifunc@plt in section .text
                           ^^^^^

I guess that may be related to the comment in ppc-linux-tdep.c that
says "For secure PLT, stub is in .text".

In any case, this commit fixes the issue by making the function look
at the symbol name instead of at the section.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* elfread.c (elf_gnu_ifunc_record_cache): Check if the symbol name
	ends in "@plt" instead of looking at the symbol's section.
2018-04-26 13:08:01 +01:00
Pedro Alves 42ddae103c Factor out minsym_found/find_function_start_sal overload
I need to make the ifunc resolving code in elfread.c skip the target
function's prologue like minsym_found does.  I thought of factoring
that out to a separate function, but turns out there's already a
comment in find_function_start_sal that says that should agree with
minsym_found...

Instead of making sure the code agrees with a comment, factor out the
common code to a separate function and use it from both places.

Note that the current find_function_start_sal does a bit more than
minsym_found's equivalent (the "We always should ..." bit), though
that's probably a latent bug.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* linespec.c (minsym_found): Use find_function_start_sal CORE_ADDR
	overload.
	* symtab.c (find_function_start_sal(CORE_ADDR, obj_section *,bool)):
	New, factored out from ...
	(find_function_start_sal(symbol *, int)): ... this.  Reimplement
	and use bool.
	* symtab.h (find_function_start_sal(CORE_ADDR, obj_section *,bool)):
	New.
	(find_function_start_sal(symbol *, int)): Change boolean parameter
	type to bool.
2018-04-26 13:07:47 +01:00
Pedro Alves a0aca7b0e1 Eliminate find_pc_partial_function_gnu_ifunc
Not used anywhere any longer.

If this is ever reinstated, note that this case:

	  cache_pc_function_is_gnu_ifunc = TYPE_GNU_IFUNC (SYMBOL_TYPE (f));

was incorrect in that regular symbols never have type marked as GNU
ifunc type, only minimal symbols.  At some point I had some fix that
checking the matching minsym here.  But in the end I ended up just
eliminating need for this function, so that fix was not necessary.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* blockframe.c (cache_pc_function_is_gnu_ifunc): Delete.  Remove
	all references.
	(find_pc_partial_function_gnu_ifunc): Rename to ...
	(find_pc_partial_function): ... this, and remove references to
	'is_gnu_ifunc_p'.
	(find_pc_partial_function): Delete old implementation.
	* symtab.h (find_pc_partial_function_gnu_ifunc): Delete.
2018-04-26 13:07:25 +01:00
Pedro Alves 76af0f2635 Breakpoints, don't skip prologue of ifunc resolvers with debug info
Without this patch, some of the tests added to gdb.base/gnu-ifunc.exp
by a following patch fail like so:

  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: before resolving: break gnu_ifunc
  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: before resolving: info breakpoints
  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: after resolving: break gnu_ifunc
  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: after resolving: info breakpoints
  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: before resolving: break gnu_ifunc
  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: before resolving: info breakpoints
  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: after resolving: break gnu_ifunc
  FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: after resolving: info breakpoints

All of them trigger iff:

 - you have debug info for the ifunc resolver.
 - the resolver and the user-visible symbol have the same name.

If you have an ifunc that has a resolver with the same name as the
user visible symbol, debug info for the resolver masks out the ifunc
minsym.  When you set a breakpoint by name on the user visible symbol,
GDB finds the DWARF symbol for the resolver, and thinking that it's a
regular function, sets a breakpoint location past its prologue.

Like so, location 1.2, before the ifunc is resolved by the inferior:

  (gdb) break gnu_ifunc
  Breakpoint 2 at 0x7ffff7bd36ea (2 locations)
  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  1       breakpoint     keep y   <MULTIPLE>
  1.1                         y     0x00007ffff7bd36ea <gnu_ifunc>
  1.2                         y     0x00007ffff7bd36f2 in gnu_ifunc at src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c:34
  (gdb)

And like so, location 2.2, if you set the breakpoint after the ifunc
is resolved by the inferior (to "final"):

  (gdb) break gnu_ifunc
  Breakpoint 5 at 0x400757 (2 locations)
  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  2       breakpoint     keep y   <MULTIPLE>
  2.1                         y     0x000000000040075a in final at src/gdb/testsuite/gdb.base/gnu-ifunc-resd.c:21
  2.2                         y     0x00007ffff7bd36f2 in gnu_ifunc at src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c:34
  (gdb)

I don't think this is right because when users set a breakpoint at an
ifunc, they don't care about debugging the resolver.  Instead what you
should is a single location for the ifunc in the first case, and a
single location of the ifunc target in the second case.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* linespec.c (struct bound_minimal_symbol_search_key): New.
	(convert_linespec_to_sals): Sort minimal symbols earlier.  Don't
	skip first line if we found a GNU ifunc minimal symbol by name.
	(compare_msymbols): Change parameters to work with a destructured
	lhs minsym.
	(compare_msymbols_for_qsort, compare_msymbols_for_bsearch): New
	functions.
2018-04-26 13:06:53 +01:00
Pedro Alves 3467ec66bc Fix setting breakpoints on ifunc functions after they're already resolved
This fixes setting breakpoints on ifunc functions by name after the
ifunc has already been resolved.

In that case, if you have debug info for the ifunc resolver, without
the fix, then gdb puts a breakpoint past the prologue of the resolver,
instead of setting a breakpoint at the ifunc target:

  break gnu_ifunc
  Breakpoint 4 at 0x7ffff7bd36f2: file src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c, line 34.
  (gdb) continue
  Continuing.
  [Inferior 1 (process 13300) exited normally]
  (gdb)

above we should have stopped at "final", but didn't because we never
resolved the ifunc to the final location.

If you don't have debug info for the resolver, GDB manages to resolve
the ifunc target, but, it should be setting a breakpoint after the
prologue of the final function, and instead what you get is that GDB
sets a breakpoint on the first address of the target function.  With
the gnu-ifunc.exp tests added by a later patch, we get, without the
fix:

  (gdb) break gnu_ifunc
  Breakpoint 4 at 0x400753
  (gdb) continue
  Continuing.

  Breakpoint 4, final (arg=1) at src/gdb/testsuite/gdb.base/gnu-ifunc-final.c:20
  20	{

vs, fixed:

  (gdb) break gnu_ifunc
  Breakpoint 4 at 0x40075a: file src/gdb/testsuite/gdb.base/gnu-ifunc-final.c, line 21.
  (gdb) continue
  Continuing.

  Breakpoint 4, final (arg=2) at src/gdb/testsuite/gdb.base/gnu-ifunc-final.c:21
  21	  return arg + 1;
  (gdb)

Fix the problems above by moving the ifunc target resolving to
linespec.c, before we skip a function's prologue.  We need to save
something in the sal, so that set_breakpoint_location_function knows
that it needs to create a bp_gnu_ifunc_resolver bp_location.  Might as
well just save a pointer to the minsym.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (set_breakpoint_location_function): Don't resolve
	ifunc targets here.  Instead, if we have an ifunc minsym, use its
	address/name.
	(add_location_to_breakpoint): Store the minsym and the objfile in
	the breakpoint location.
	* breakpoint.h (bp_location) <msymbol, objfile>: New fields.
	* linespec.c (minsym_found): Resolve GNU ifunc targets here.
	Record the minsym in the sal.
	* symtab.h (symtab_and_line) <msymbol>: New field.
2018-04-26 13:06:21 +01:00
Pedro Alves 28f4fa4d05 Fix elf_gnu_ifunc_resolve_by_got buglet
The next patch will add a call to elf_gnu_ifunc_resolve_by_got that
trips on a latent buglet -- the function is writing to its output
parameter even if the address wasn't found, confusing the caller.  The
function's intro comment says:

  /* Try to find the target resolved function entry address of a STT_GNU_IFUNC
     function NAME.  If the address is found it is stored to *ADDR_P (if ADDR_P
     is not NULL) and the function returns 1.  It returns 0 otherwise.

So fix the function accordingly.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* elfread.c (elf_gnu_ifunc_resolve_by_got): Don't write to *ADDR_P
	unless we actually resolved the ifunc.
2018-04-26 13:05:58 +01:00
Pedro Alves ca31ab1d67 Calling ifunc functions when resolver has debug info, user symbol same name
If the GNU ifunc resolver has the same name as the user visible
symbol, and the resolver has debug info, then the DWARF info for the
resolver masks the ifunc minsym.  In that scenario, if you try calling
the ifunc from GDB, you call the resolver instead.  With the
gnu-ifunc.exp testcase added in a following patch, you'd see:

  (gdb) p gnu_ifunc (3)
  $1 = (int (*)(int)) 0x400753 <final>
  (gdb) FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: p gnu_ifunc (3)
                                                       ^^^^^^^^^^^^^^^^

That is, we called the ifunc resolver manually, which returned a
pointer to the ifunc target function ("final").  The "final" symbol is
the function that GDB should have called automatically,

  ~~~~~~~~~~~~
  int
  final (int arg)
  {
    return arg + 1;
  }
  ~~~~~~~~~

which is what happens if you don't have debug info for the resolver:

  (gdb) p gnu_ifunc (3)
  $1 = 4
  (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=0: resolved_debug=1: p gnu_ifunc (3)
                                                       ^^^^^^^^^^^^^^^^

or if the resolver's symbol has a different name from the ifunc (as is
the case with modern uses of ifunc via __attribute__ ifunc, such as
glibc uses):

  (gdb) p gnu_ifunc (3)
  $1 = 4
  (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=1: resolved_debug=0: p gnu_ifunc (3)
                                      ^^^^^^^^^^^^^^^

in which case after this patch, you can still call the resolver
directly if you want:

  (gdb) p gnu_ifunc_resolver (3)
  $1 = (int (*)(int)) 0x400753 <final>

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* c-exp.y (variable production): Prefer ifunc minsyms over
	regular function symbols.
	* symtab.c (find_gnu_ifunc): New function.
	* minsyms.h (lookup_msym_prefer): New enum.
	(lookup_minimal_symbol_by_pc_section): Replace 'want_trampoline'
	parameter by a lookup_msym_prefer parameter.
	* symtab.h (find_gnu_ifunc): New declaration.
2018-04-26 13:05:29 +01:00
Pedro Alves 8388016d7f Calling ifunc functions when target has no debug info but resolver has
After the previous patch, on Fedora 27 (glibc 2.26), if you try
calling strlen in the inferior, you now get:

  (top-gdb) p strlen ("hello")
  '__strlen_avx2' has unknown return type; cast the call to its declared return type

This is correct, because __strlen_avx2 is written in assembly.

We can improve on this though -- if the final ifunc resolved/target
function has no debug info, but the ifunc _resolver_ does have debug
info, we can try extracting the final function's type from the type
that the resolver returns.  E.g.,:

  typedef size_t (*strlen_t) (const char*);

  size_t my_strlen (const char *) { /* some implementation */ }
  strlen_t strlen_resolver (unsigned long hwcap) { return my_strlen; }

  extern size_t strlen (const char *s);
  __typeof (strlen) strlen __attribute__ ((ifunc ("strlen_resolver")));

In the strlen example above, the resolver returns strlen_t, which is a
typedef for pointer to a function that returns size_t.  "strlen_t" is
the type of both the user-visible "strlen", and of the the target
function that implements it.

This patch teaches GDB to extract that type.

This is done for actual inferior function calls (in infcall.c), and
for ptype (in eval_call).  By the time we get to either of these
places, we've already lost the original symbol/minsym, and only have
values and types to work with.  Hence the changes to c-exp.y and
evaluate_var_msym_value, to ensure that we propagate the ifunc
minsymbol's info.

The change to make ifunc symbols have no/unknown return type exposes a
latent problem -- gdb.compile/compile-ifunc.exp calls a no-debug-info
function, but we did not warn about it.  The test is fixed by this
commit too.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* blockframe.c (find_gnu_ifunc_target_type): New function.
	(find_function_type): New.
	* eval.c (evaluate_var_msym_value): For GNU ifunc types, always
	return a value with a memory address.
	(eval_call): For calls to GNU ifunc functions, try to find the
	type of the target function from the type that the resolver
	returns.
	* gdbtypes.c (objfile_type): Don't install a return type for ifunc
	symbols.
	* infcall.c (find_function_return_type): Delete.
	(find_function_addr): Add 'function_type' parameter.  For calls to
	GNU ifunc functions, try to find the type of the target function
	from the type that the resolver returns, and return it via
	FUNCTION_TYPE.
	(call_function_by_hand_dummy): Adjust to use the function type
	returned by find_function_addr.
	(find_function_addr): Add 'function_type' parameter and move
	description here.
	* symtab.h (find_function_type, find_gnu_ifunc_target_type): New
	declarations.

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

	* gdb.compile/compile-ifunc.exp: Also expect "function has unknown
	return type" warnings.
2018-04-26 13:04:48 +01:00
Pedro Alves a376e11d84 Fix calling ifunc functions when resolver has debug info and different name
Currently, on Fedora 27 (glibc 2.26), if you try to call strlen in the
inferior you get:

 (gdb) p strlen ("hello")
 $1 = (size_t (*)(const char *)) 0x7ffff554aac0 <__strlen_avx2>

strlen is an ifunc function, and what we see above is the result of
calling the ifunc resolver in the inferior.  That returns a pointer to
the actual target function that implements strlen on my machine.  GDB
should have turned around and called the resolver automatically
without the user noticing.

This is was caused by commit:

  commit bf223d3e80
  Date: Mon Aug 21 11:34:32 2017 +0100

      Handle function aliases better (PR gdb/19487, errno printing)

which added the find_function_alias_target call to c-exp.y, to try to
find an alias with debug info for a minsym.  For ifunc symbols, that
finds the ifunc's resolver if it has debug info (in the example it's
called "strlen_ifunc"), with the result that GDB calls that as a
regular function.

After this commit, we get now get:

  (top-gdb) p strlen ("hello")
  '__strlen_avx2' has unknown return type; cast the call to its declared return type

Which is correct, because __strlen_avx2 is written in assembly.
That'll be improved in a following patch, though.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* c-exp.y (variable production): Skip finding an alias for ifunc
	symbols.
2018-04-26 13:04:09 +01:00
Pedro Alves 02e169e2da Fix breakpoints in ifunc after inferior resolved it (@got.plt symbol creation)
Setting a breakpoint on an ifunc symbol after the ifunc has already
been resolved by the inferior should result in creating a breakpoint
location at the ifunc target.  However, that's not what happens on
current Fedora:

  (gdb) n
  53        i = gnu_ifunc (1);    /* break-at-call */
  (gdb)
  54        assert (i == 2);
  (gdb) b gnu_ifunc
  Breakpoint 2 at gnu-indirect-function resolver at 0x7ffff7bd36ee
  (gdb) info breakpoints
  Num     Type                   Disp Enb Address            What
  2       STT_GNU_IFUNC resolver keep y   0x00007ffff7bd36ee <gnu_ifunc+4>

The problem is that elf_gnu_ifunc_resolve_by_got never manages to
resolve an ifunc target.  The reason is that GDB never actually
creates the internal got.plt symbols:

 (gdb) p 'gnu_ifunc@got.plt'
 No symbol "gnu_ifunc@got.plt" in current context.

and this is because GDB expects that rela.plt has relocations for
.plt, while it actually has relocations for .got.plt:

 Relocation section [10] '.rela.plt' for section [22] '.got.plt' at offset 0x570 contains 2 entries:
   Offset              Type            Value               Addend Name
   0x0000000000601018  X86_64_JUMP_SLOT 000000000000000000      +0 __assert_fail
   0x0000000000601020  X86_64_JUMP_SLOT 000000000000000000      +0 gnu_ifunc


Using an older system on the GCC compile farm (machine gcc15, an
x86-64 running Debian 6.0.8, with GNU ld 2.20.1), we see that it used
to be that we'd get a .rela.plt section for .plt:

 Relocation section [ 9] '.rela.plt' for section [11] '.plt' at offset 0x578 contains 3 entries:
   Offset              Type            Value               Addend Name
   0x0000000000600cc0  X86_64_JUMP_SLOT 000000000000000000      +0 __assert_fail
   0x0000000000600cc8  X86_64_JUMP_SLOT 000000000000000000      +0 __libc_start_main
   0x0000000000600cd0  X86_64_JUMP_SLOT 000000000000000000      +0 gnu_ifunc

Those offsets did point into .got.plt, as seen with objdump -h:

  20 .got.plt      00000030  0000000000600ca8  0000000000600ca8  00000ca8  2**3
     		   CONTENTS, ALLOC, LOAD, DATA

I also tested on gcc110 on the compile farm (PPC64 running CentOS
7.4.1708, with GNU ld 2.25.1), and there we see instead:

 Relocation section [ 9] '.rela.plt' for section [23] '.plt' at offset 0x5d0 contains 4 entries:
   Offset              Type            Value               Addend Name
   0x0000000010020148  PPC64_JMP_SLOT  000000000000000000      +0 __libc_start_main
   0x0000000010020160  PPC64_JMP_SLOT  000000000000000000      +0 __gmon_start__
   0x0000000010020178  PPC64_JMP_SLOT  000000000000000000      +0 __assert_fail
   0x0000000010020190  PPC64_JMP_SLOT  000000000000000000      +0 gnu_ifunc

But note that those offsets point into .plt, not .got.plt, as seen
with objdump -h:

 22 .plt          00000078  0000000010020130  0000000010020130  00010130  2**3
                  ALLOC

This commit makes us support all the different combinations above.

With that addressed, we now get:

 (gdb) p 'gnu_ifunc@got.plt'
 $1 = (<text from jump slot in .got.plt, no debug info>) 0x400753 <final>

And setting a breakpoint on the ifunc finds the ifunc target:

 (gdb) b gnu_ifunc
 Breakpoint 2 at 0x400753
 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 2       breakpoint     keep y   0x0000000000400753 <final>

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

	* elfread.c (elf_rel_plt_read): Look for relocations for .got.plt too.
2018-04-26 13:02:26 +01:00
Pedro Alves 249b573352 Fix new inferior events output
Since f67c0c9171 ("Enable 'set print inferior-events' and improve
detach/fork/kill/exit messages"), when detaching a remote process, we
get, for detach against a remote target:

 (gdb) detach
 Detaching from program: ...., process 5388
 Ending remote debugging.
 [Inferior 1 (Thread 5388.5388) detached]
              ^^^^^^^^^^^^^^^^

That is incorrect, for it is printing a thread id as string while we
should be printing the process id instead.  I.e., either one of:

 [Inferior 1 (process 5388) detached]
 [Inferior 1 (Remote target) detached]

depending on remote stub support for the multi-process extensions.


Similarly, after killing a process, we're printing thread ids while we
should be printing process ids.  E.g., on native GNU/Linux:

 (gdb) k
 Kill the program being debugged? (y or n) y
 [Inferior 1 (Thread 0x7ffff7faa8c0 (LWP 30721)) has been killed]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

while it should have been:

 Kill the program being debugged? (y or n) y
 [Inferior 1 (process 30721) has been killed]
              ^^^^^^^^^^^^^

There's a wording inconsistency between detach and kill:

 [Inferior 1 (process 30721) has been killed]
 [Inferior 1 (process 30721) detached]

Given we were already saying "detached" instead of "has been
detached", and we used to say just "exited", and given that the "has
been" doesn't really add any information, this commit changes the
message to just "killed":

 [Inferior 1 (process 30721) killed]

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

	* infcmd.c (kill_command): Print the pid as string, not the whole
	thread's ptid.  Add comment.  s/has been killed/killed/ in output
	message.
	* remote.c (remote_detach_1): Print the pid as string, not the
	whole thread's ptid.

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

	* gdb.base/hook-stop.exp: Expect "killed" instead of "has been
	killed".
	* gdb.base/kill-after-signal.exp: Likewise.
	* gdb.threads/kill.exp: Likewise.
2018-04-25 17:28:25 +01:00
Sergio Durigan Junior f67c0c9171 Enable 'set print inferior-events' and improve detach/fork/kill/exit messages
This patch aims to turn 'set print inferior-events' always on, and do
some cleanup on the messages printed by GDB when various inferior
events happen (attach, detach, fork, kill, exit).

To make sure that the patch is correct, I've tested it with a handful
of combinations of 'set follow-fork-mode', 'set detach-on-fork' and
'set print inferior-events'.  In the end, I decided to make my
hand-made test into an official testcase.  More on that below.

Using the following program as an example:

  #include <unistd.h>
  int main ()
  {
    fork ();
    return 0;
  }

We see the following outputs from the patched GDB:

- With 'set print inferior-events on':

    (gdb) r
    Starting program: a.out
    [Detaching after fork from child process 27749]
    [Inferior 1 (process 27745) exited normally]
    (gdb)

- With 'set print inferior-events off':

    (gdb) r
    Starting program: a.out
    [Inferior 1 (process 27823) exited normally]
    (gdb)

  Comparing this against an unpatched GDB:

- With 'set print inferior-events off' and 'set follow-fork-mode
  child':

    (gdb) r
    Starting program: a.out
    [Inferior 2 (process 5993) exited normally]
    (gdb)

  Compare this against an unpatched GDB:

    (unpatched-gdb) r
    Starting program: a.out
    [New process 5702]
    [Inferior 2 (process 5702) exited normally]
    (unpatched-gdb)

  It is possible to notice that, in this scenario, the patched GDB
  will lose the '[New process %d]' message.

- With 'set print inferior-events on', 'set follow-fork-mode child'
  and 'set detach-on-fork on':

    (gdb) r
    Starting program: a.out
    [Attaching after process 27905 fork to child process 27909]
    [New inferior 2 (process 27909)]
    [Detaching after fork from parent process 27905]
    [Inferior 1 (process 27905) detached]
    [Inferior 2 (process 27909) exited normally]
    (gdb)

  Compare this output with an unpatched GDB, using the same settings:

    (unpatched-gdb) r
    Starting program: a.out
    [New inferior 28033]
    [Inferior 28029 detached]
    [New process 28033]
    [Inferior 2 (process 28033) exited normally]
    [Inferior 28033 exited]
    (unpatched-gdb)

As can be seen above, I've also made a few modifications to messages
that are printed when 'set print inferior-events' is on.  For example,
a few of the messages did not contain the '[' and ']' as
prefix/suffix, which led to a few inconsistencies like:

  Attaching after process 22995 fork to child process 22999.
  [New inferior 22999]
  Detaching after fork from child process 22999.
  [Inferior 22995 detached]
  [Inferior 2 (process 22999) exited normally]

So I took the opportunity and included the square brackets where
applicable.  I have also made the existing messages more uniform, by
always printing "Inferior %d (process %d)..." where applicable.  This
makes it easier to identify the inferior number and the PID number
from the messages.

As suggested by Pedro, the "[Inferior %d exited]" message from
'exit_inferior' has been removed, because it got duplicated when
'inferior-events' is on.  I'm also using the
'add_{thread,inferior}_silent' versions (instead of their verbose
counterparts) on some locations, also to avoid duplicated messages.
For example, a patched GDB with 'set print inferior-events on', 'set
detach-on-fork on' and 'set follow-fork-mode child', but using
'add_thread', would print:

  (gdb) run
  Starting program: a.out
  [Attaching after process 25088 fork to child process 25092.]
  [New inferior 25092]   <--- duplicated
  [Detaching after fork from child process 25092.]
  [Inferior 25088 detached]
  [New process 25092]    <--- duplicated
  [Inferior 2 (process 25092) exited normally]

But if we use 'add_thread_silent' (with the same configuration as
before):

  (gdb) run
  Starting program: a.out
  [Attaching after process 31606 fork to child process 31610]
  [New inferior 2 (process 31610)]
  [Detaching after fork from parent process 31606]
  [Inferior 1 (process 31606) detached]
  [Inferior 2 (process 31610) exited normally]

As for the tests, the configuration options being exercised are:

- follow-fork-mode: child/parent
- detach-on-fork: on/off
- print inferior-events: on/off

It was also necessary to perform adjustments on several testcases,
because the expected messages changed considerably.

Built and regtested on BuildBot, without regressions.

gdb/ChangeLog:
2018-04-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* infcmd.c (kill_command): Print message when inferior has
	been killed.
	* inferior.c (print_inferior_events): Remove 'static'.  Set as
	'1'.
	(add_inferior): Improve message printed when
	'print_inferior_events' is on.
	(exit_inferior): Remove message printed when
	'print_inferior_events' is on.
	(detach_inferior): Improve message printed when
	'print_inferior_events' is on.
	(initialize_inferiors): Use 'add_inferior_silent' to set
	'current_inferior_'.
	* inferior.h (print_inferior_events): Declare here as
	'extern'.
	* infrun.c (follow_fork_inferior): Print '[Attaching...]' or
	'[Detaching...]' messages when 'print_inferior_events' is on.
	Use 'add_thread_silent' instead of 'add_thread'.  Add '[' and ']'
	as prefix/suffix for messages.  Remove periods.  Fix erroneous
	'Detaching after fork from child...', replace it by '... from
	parent...'.
	(handle_vfork_child_exec_or_exit): Add '[' and ']' as
	prefix/suffix when printing 'Detaching...' messages.  Print
	them when 'print_inferior_events' is on.
	* remote.c (remote_detach_1): Print message when detaching
	from inferior and '!is_fork_parent'.

gdb/testsuite/ChangeLog:
2018-04-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/attach-non-pgrp-leader.exp: Adjust 'Detaching...'
	regexps to expect for '[Inferior ... detached]' as well.
	* gdb.base/attach.exp: Likewise.
	* gdb.base/catch-syscall.exp (check_for_program_end): Adjust
	"gdb_continue_to_end".
	(test_catch_syscall_with_wrong_args): Likewise.
	* gdb.base/foll-fork.exp: Adjust regexps to match '[' and
	']'.  Don't set 'verbose' on.
	* gdb.base/foll-vfork.exp: Likewise.
	* gdb.base/fork-print-inferior-events.c: New file.
	* gdb.base/fork-print-inferior-events.exp: New file.
	* gdb.base/hook-stop.exp: Adjust regexps to expect for new
	'[Inferior ... has been killed]' message.
	* gdb.base/kill-after-signal.exp: Likewise.
	* gdb.base/solib-overlap.exp: Adjust regexps to expect for new
	detach message.
	* gdb.threads/kill.exp: Adjust regexps to expect for new kill
	message.
	* gdb.threads/clone-attach-detach.exp: Adjust 'Detaching...'
	regexps to expect for '[Inferior ... detached]' as well.
	* gdb.threads/process-dies-while-detaching.exp: Likewise.
2018-04-24 15:46:15 -04:00
Simon Marchi 0a8ddac418 info-shared.exp: Replace libs=-ldl with shlib_load
As reported in PR 23104, -ldl doesn't work on FreeBSD.  Replace it with
shlib_load, which adds the right flags for dynamic library loading based
on the current target platform.

The test still passes on Linux, and should now pass on FreeBSD, though I
did not test personally.

gdb/testsuite/ChangeLog:

	PR gdb/23104
	* gdb.base/info-shared.exp: Replace libs=-ldl with shlib_load.
2018-04-24 10:14:27 -04:00
Tom Tromey e427af1889 Reindent cli-out.h
I noticed that cli-out.h had incorrect indentation in some spots.
This fixes it.

ChangeLog
2018-04-24  Tom Tromey  <tom@tromey.com>

	* cli-out.h: Reindent.
2018-04-24 07:34:03 -06:00
Tom Tromey 05b1d8d6fc Remove cli_ui_out::out_field_fmt
I noticed that cli_ui_out::out_field_fmt is only used by a single
caller, and it can easily be replaced by fputs_filtered.  So, this
patch removes it.

ChangeLog
2018-04-24  Tom Tromey  <tom@tromey.com>

	* cli-out.c (cli_ui_out::out_field_fmt): Remove.
	(cli_ui_out::do_field_string): Use fputs_filtered.
	* cli-out.h (class cli_ui_out) <out_field_fmt>: Remove.
2018-04-24 07:34:03 -06:00
Tom Tromey a95c7daba4 Remove a cleanup from scm-frame.c
This removes a cleanup from scm-frame.c, replacing it with
unique_xmalloc_ptr and a new scope.  I believe this also fixes a
latent bug involving calling do_cleanups twice for a single cleanup.

Regression tested using the gdb.guile test suite on x86-64 Fedora 26.

ChangeLog
2018-04-23  Tom Tromey  <tom@tromey.com>

	* guile/scm-frame.c (gdbscm_frame_read_var): Use
	gdb::unique_xmalloc_ptr.
2018-04-23 17:50:19 -06:00
Tom Tromey 458412c368 Regenerate gdb/configure and gdbserver/configure
Pedro pointed out that gdb/configure and gdbserver/configure weren't
updated after some recent *.m4 changes.

This patch rebuilds those files.  Tested by rebuilding.  Pedro
approved this in the thread where he raised this issue, so I'm pushing
it in.

ChangeLog
2018-04-23  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.

gdbserver/ChangeLog
2018-04-23  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2018-04-23 09:29:41 -06:00
Rajendra SY db86b02b3a Fixed test case to compile & run on FreeBSD
Problems:
1. linking -dl lib on FreeBSD platform
2. backtrace from ld-elf shows r_debug_state() instead of _dl_debug_state()

Cause:
1. There is no dl library on FreeBSD platform test has to ignore linking "-ldl"
2. The stop due to a shared library event shows backtrace frame #0
   function as r_debug_state()

gdb/ChangeLog:

	PR gdb/23095
	* gdb/testsuite/gdb.base/break-probes.exp: Pass shlib_load to
	prepare_for_testing.  Set normal_bp to r_debug_state if target
	is bsd.
2018-04-22 18:20:05 -04:00
Pedro Alves 00aecdcf62 FreeBSD: Fix 'Couldn't get registers: Device busy' error (PR gdb/23077)
As Rajendra SY reported at
<https://sourceware.org/ml/gdb-patches/2018-04/msg00399.html>, several
attach-related tests are failing on FreeBSD.  The "attach" command
errors with "Couldn't get registers: Device busy".

When the "attach" command is executed, it calls target_attach ->
inf_ptrace_attach, which just does the ptrace(PT_ATTACH), it does not
wait for the child to stop with SIGSTOP.  Afterwards, the command is
complete and we go back to the event loop.  The event loop wakes up
and we end up in target_wait -> fbsd_wait, and handle the SIGSTOP
stop.

At the end of execute_command, though, before going back to the event
loop, we check if the frame language changed via
check_frame_language_change().  That reads the current PC, which is
what leads to the registers read that fails.

The problem is that we fail to mark the attached-to thread as
executing between the initial attach, and the subsequent target_wait.
Until we see the thread stop with SIGSTOP, we shouldn't try to read
registers off of it.  I guess there may a timing issue here - if
you're "lucky", the thread may stop before gdb reads its registers,
masking the problem.

With that fixed, check_frame_language_change() becomes a nop until the
thread is marked not-executing again, after target_wait is called and
we go through handle_inferior_event -> normal_stop.

We haven't seen the problem on Linux because there, the target_attach
implementation waits for the thread to stop before returning.  Still,
that's supposedly hidden from the core, since the Linux target, like
most targets, is a '!to_attach_no_wait' target.

This fixes:
 FAIL: gdb.base/attach.exp: attach1, after setting file
 FAIL: gdb.base/attach.exp: attach2, with no file
 FAIL: gdb.base/attach.exp: load file manually, after attach2 (re-read) (got interactive prompt)
 FAIL: gdb.base/attach.exp: attach when process' a.out not in cwd

 FAIL: gdb.base/dprintf-detach.exp: bai=on ds=gdb dd=on: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=on ds=gdb dd=off: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=on ds=call dd=on: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=on ds=call dd=off: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=on ds=agent dd=on: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=on ds=agent dd=off: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=off ds=gdb dd=on: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=off ds=gdb dd=off: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=off ds=call dd=on: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=off ds=call dd=off: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=off ds=agent dd=on: re-attach to inferior
 FAIL: gdb.base/dprintf-detach.exp: bai=off ds=agent dd=off: re-attach to inferior

gdb/ChangeLog:
2018-04-21  Pedro Alves  <palves@redhat.com>
	    Rajendra SY  <rajendra.sy@gmail.com>

	* inf-ptrace.c (inf_ptrace_attach): Mark the thread as executing.
	* remote.c (extended_remote_attach): In all-stop mode, mark the
	thread as executing.
2018-04-21 18:19:30 +01:00
Philippe Waroquiers 5c8f23cdab Improve on-line help for thread_apply_command and thread_apply_all_command.
Add a Usage: line for thread_apply_command, in particular to mention
the thread ID list.

In thread_apply_command and thread_apply_all_command help, use
uppercase for arg names, as this style seems to be more standard.

2018-04-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* thread.c (_initialize_thread): improve on-line help for
	thread_apply_command and thread_apply_all_command.
2018-04-20 23:15:18 +02:00
Richard Bunt d27d16bfdc Add test case for a known hang in infrun
The hang occurs when GDB tries to call inferior functions on two
different threads with scheduler-locking turned on. The first call works
fine, with the call to infrun_async(1) causing the signal_handler to be
marked and the event to be handled, but then the event loop resets the
"ready" member to zero, while leaving infrun_is_async set to 1. As a
result, GDB hangs if the user switches to another thread and calls a
second function because calling infrun_async(1) a second time has no
effect, meaning the inferior call events are never handled.

The added test case provokes the above issue.

gdb/testsuite/ChangeLog:

	* gdb.threads/multiple-successive-infcall.c: New test.
	* gdb.threads/multiple-successive-infcall.exp: New file.
2018-04-19 23:02:35 -04:00
Philippe Waroquiers 224608c3ca [OB PATCH] Fix some comments in thread.c
Fix some typos.
Remove obsolete comment about dispatch to thread_apply_command,
rather tell that thread_command either switches to a thread,
or prints the current thread.

2018-04-19  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* thread.c (thread_apply_all_command): Fix comment.
	(thread_command): Fix comment.
2018-04-19 22:59:17 +02:00
Simon Marchi f31c089e78 Fix dependency tracking in gdbserver subdirectories
The dependency tracking (the thing that knows which source file included
which other source file during last build to know what to rebuild when
an included file changes) is broken for gdbserver subdirectories (arch
and common).

The dependency tracking files are created in the form

  arch/.deps/i386.Po

but we try to include

  .deps/arch/i386.Po

An easy smoke test is too "touch" the gdb/features/i386/32bit-core.c
file in the source directory and try to rebuild gdbserver.  This file is
included by gdb/arch/i386.c, so it should cause
gdb/gdbserver/arch/i386.o in the build directory to be rebuilt.  It
currently isn't rebuilt, but is with this patch applied.

This patch copies the technique used in GDB to transform the dep file
paths to the proper form.

Also, while testing using the depcomp method of dependency tracking (by
just hacking the condition), I noticed that depcomp was not found.  The
path to depcomp seems to be missing a "..".

gdb/gdbserver/ChangeLog:

	* Makefile.in (depcomp): Add "..".
	(all_deps_files): New and use it.
2018-04-19 13:23:32 -04:00
Alan Hayward b319b0984b Remove xml files from gdbserver
For ports which use new target descriptions, remove
the xml files from being built into gdbserver.

gdbserver/
	* configure.srv (aarch64*-*-linux*): Don't include xml.
	(i[34567]86-*-cygwin*): Likewise.
	(i[34567]86-*-linux*): Likewise.
	(i[34567]86-*-lynxos*): Likewise.
	(i[34567]86-*-mingw32ce*): Likewise.
	(i[34567]86-*-mingw*): Likewise.
	(i[34567]86-*-nto*): Likewise.
	(tic6x-*-uclinux): Likewise.
	(x86_64-*-linux*): Likewise.
	(x86_64-*-mingw*): Likewise.
	(x86_64-*-cygwin*): Likewise.
2018-04-18 21:03:05 +01:00
Alan Hayward 3b74854b8d Remove xml file references from target descriptions
gdb/
	* common/tdesc.h (tdesc_create_feature): Remove xml filename
	parameter.
	* features/aarch64-core.c (create_feature_aarch64_core):
	Regenerate.
	* features/aarch64-fpu.c (create_feature_aarch64_fpu):
	Likewise.
	* features/i386/32bit-avx.c (create_feature_i386_32bit_avx):
	Likewise.
	* features/i386/32bit-avx512.c
	(create_feature_i386_32bit_avx512): Likewise.
	* features/i386/32bit-core.c (create_feature_i386_32bit_core):
	Likewise.
	* features/i386/32bit-linux.c (create_feature_i386_32bit_linux):
	Likewise.
	* features/i386/32bit-mpx.c (create_feature_i386_32bit_mpx):
	Likewise.
	* features/i386/32bit-pkeys.c (create_feature_i386_32bit_pkeys):
	Likewise.
	* features/i386/32bit-sse.c (create_feature_i386_32bit_sse):
	Likewise.
	* features/i386/64bit-avx.c (create_feature_i386_64bit_avx):
	Likewise.
	* features/i386/64bit-avx512.c
	(create_feature_i386_64bit_avx512): Likewise.
	* features/i386/64bit-core.c (create_feature_i386_64bit_core):
	Likewise.
	* features/i386/64bit-linux.c (create_feature_i386_64bit_linux):
	Likewise.
	* features/i386/64bit-mpx.c (create_feature_i386_64bit_mpx):
	Likewise.
	* features/i386/64bit-pkeys.c (create_feature_i386_64bit_pkeys):
	Likewise.
	* features/i386/64bit-segments.c
	(create_feature_i386_64bit_segments): Likewise.
	* features/i386/64bit-sse.c (create_feature_i386_64bit_sse):
	Likewise.
	* features/i386/x32-core.c
	(create_feature_i386_x32_core): Likewise.
	* features/tic6x-c6xp.c (create_feature_tic6x_c6xp): Likewise.
	* features/tic6x-core.c (create_feature_tic6x_core): Likewise.
	* features/tic6x-gp.c (create_feature_tic6x_gp): Likewise.
	* target-descriptions.c: In generated code, don't pass xml
	filename.

gdbserver/
	* tdesc.c: Remove xml parameter.
2018-04-18 20:49:37 +01:00
Alan Hayward e98577a9dc Create xml from target descriptions
Add a print_xml_feature visitor class which turns a
target description into xml. Both gdb and gdbserver can do this.

gdb/
	* common/tdesc.c (print_xml_feature::visit_pre): Add xml parsing.
	(print_xml_feature::visit_post): Likewise.
	(print_xml_feature::visit): Likewise.
	* common/tdesc.h (tdesc_get_features_xml): Use const tdesc.
	(print_xml_feature): Add new class.
	* regformats/regdat.sh: Null xmltarget on feature targets.
	* target-descriptions.c (struct target_desc): Add xmltarget.
	(maintenance_check_tdesc_xml_convert): Add unittest function.
	(tdesc_get_features_xml): Add function to get xml.
	(maintenance_check_xml_descriptions): Test xml generation.
	* xml-tdesc.c (string_read_description_xml): Add function.
	* xml-tdesc.h (string_read_description_xml): Add declaration.

gdbserver/
	* gdb/gdbserver/server.c (get_features_xml): Remove cast.
	* tdesc.c (void target_desc::accept): Fill in function.
	(tdesc_get_features_xml): Remove old xml creation.
	(print_xml_feature::visit_pre): Add xml vistor.
	* tdesc.h (struct target_desc): Make xmltarget mutable.
	(tdesc_get_features_xml): Remove declaration.
2018-04-18 20:44:39 +01:00
Alan Hayward ad7fc756d1 Add feature reference in .dat files
For all targets which use the newer style target descriptions, add a
"feature" marker in the dat files.
Update regdat.sh to parse feature, but do not use it (yet).

gdb/
	* features/Makefile: Add feature marker to targets with new style
	target descriptions.
	* regformats/aarch64.dat: Regenerate.
	* regformats/i386/amd64-avx-avx512-linux.dat: Likewise.
	* regformats/i386/amd64-avx-linux.dat: Likewise.
	* regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat: Likewise.
	* regformats/i386/amd64-avx-mpx-linux.dat: Likewise.
	* regformats/i386/amd64-linux.dat: Likewise.
	* regformats/i386/amd64-mpx-linux.dat: Likewise.
	* regformats/i386/amd64.dat: Likewise.
	* regformats/i386/i386-avx-avx512-linux.dat: Likewise.
	* regformats/i386/i386-avx-linux.dat: Likewise.
	* regformats/i386/i386-avx-mpx-avx512-pku-linux.dat: Likewise.
	* regformats/i386/i386-avx-mpx-linux.dat: Likewise.
	* regformats/i386/i386-linux.dat: Likewise.
	* regformats/i386/i386-mmx-linux.dat: Likewise.
	* regformats/i386/i386-mpx-linux.dat: Likewise.
	* regformats/i386/i386.dat: Likewise.
	* regformats/i386/x32-avx-avx512-linux.dat: Likewise.
	* regformats/i386/x32-avx-linux.dat: Likewise.
	* regformats/i386/x32-linux.dat: Likewise.
	* regformats/tic6x-c62x-linux.dat: Likewise.
	* regformats/tic6x-c64x-linux.dat: Likewise.
	* regformats/tic6x-c64xp-linux.dat: Likewise.
	* regformats/regdat.sh: Parse feature marker.
2018-04-18 20:08:42 +01:00
Alan Hayward d278f585af Add tdesc osabi and architecture functions
gdb/
	* common/tdesc.h (tdesc_architecture_name): Add new declaration.
	(tdesc_osabi_name): Likewise.
	* target-descriptions.c (tdesc_architecture_name): Add new function.
	(tdesc_osabi_name): Likewise.

gdbserver/
	* tdesc.c (tdesc_architecture_name): Add new function.
	(tdesc_osabi_name): Likewise.
	(tdesc_get_features_xml): Use new functions.
2018-04-18 14:00:43 +01:00
Alan Hayward eee8a18dd2 Commonise tdesc types and makes use of them in gdbserver tdesc
gdb/
	* common/tdesc.c (tdesc_predefined_type): Move to here.
	(tdesc_named_type): Likewise.
	(tdesc_create_vector): Likewise.
	(tdesc_create_struct): Likewise.
	(tdesc_set_struct_size): Likewise.
	(tdesc_create_union): Likewise.
	(tdesc_create_flags): Likewise.
	(tdesc_create_enum): Likewise.
	(tdesc_add_field): Likewise.
	(tdesc_add_typed_bitfield): Likewise.
	(tdesc_add_bitfield): Likewise.
	(tdesc_add_flag): Likewise.
	(tdesc_add_enum_value): Likewise.
	* common/tdesc.h (struct tdesc_type_builtin): Likewise.
	(struct tdesc_type_vector): Likewise.
	(struct tdesc_type_field): Likewise.
	(struct tdesc_type_with_fields): Likewise.
	(tdesc_create_enum): Add declaration.
	(tdesc_add_typed_bitfield): Likewise.
	(tdesc_add_enum_value): Likewise.
	* target-descriptions.c (tdesc_type_field): Move from here.
	(tdesc_type_builtin): Likewise.
	(tdesc_type_vector): Likewise.
	(tdesc_type_with_fields): Likewise.
	(tdesc_predefined_types): Likewise.
	(tdesc_named_type): Likewise.
	(tdesc_create_vector): Likewise.
	(tdesc_create_struct): Likewise.
	(tdesc_set_struct_size): Likewise.
	(tdesc_create_union): Likewise.
	(tdesc_create_flags): Likewise.
	(tdesc_create_enum): Likewise.
	(tdesc_add_field): Likewise.
	(tdesc_add_typed_bitfield): Likewise.
	(tdesc_add_bitfield): Likewise.
	(tdesc_add_flag): Likewise.
	(tdesc_add_enum_value): Likewise.
	* gdb/target-descriptions.h (tdesc_create_enum): Likewise.
	(tdesc_add_typed_bitfield): Likewise.
	(tdesc_add_enum_value): Likewise.

gdbserver/
	* tdesc.c (tdesc_create_flags): Remove.
	(tdesc_add_flag): Likewise.
	(tdesc_named_type): Likewise.
	(tdesc_create_union): Likewise.
	(tdesc_create_struct): Likewise.
	(tdesc_create_vector): Likewise.
	(tdesc_add_bitfield): Likewise.
	(tdesc_add_field): Likewise.
	(tdesc_set_struct_size): Likewise.
2018-04-18 14:00:39 +01:00
Alan Hayward 82ec9bc705 Commonise tdesc_feature and makes use of it in gdbserver tdesc
gdb/
	* common/tdesc.c (tdesc_feature::accept): Move to here.
	(tdesc_feature::operator==): Likewise.
	(tdesc_create_reg): Likewise.
	* common/tdesc.h (tdesc_type_kind): Likewise.
	(struct tdesc_type): Likewise.
	(struct tdesc_feature): Likewise.
	* regformats/regdat.sh: Create a feature.
	* target-descriptions.c (tdesc_type_kind): Move from here.
	(tdesc_type): Likewise.
	(tdesc_type_up): Likewise.
	(tdesc_feature): Likewise.
	(tdesc_create_reg): Likewise.

gdbserver/
	* tdesc.c (~target_desc): Remove implictly deleted items.
	(init_target_desc): Iterate all features.
	(tdesc_get_features_xml): Use vector.
	(tdesc_create_feature): Create feature.
	* tdesc.h (tdesc_feature) Remove
	(target_desc): Add features.
2018-04-18 14:00:34 +01:00
Alan Hayward ea3e7d7179 Commonise tdesc_reg and makes use of it in gdbserver tdesc
gdb/
	* Makefile.in: Add arch/tdesc.c
	* common/tdesc.c: New file.
	* common/tdesc.h (tdesc_element_visitor): Move to here.
	(tdesc_element): Likewise.
	(tdesc_reg): Likewise.
	(tdesc_reg_up): Likewise.
	* regformats/regdef.h (reg): Add offset to constructors.
	* target-descriptions.c (tdesc_element_visitor): Move from here.
	(tdesc_element): Likewise.
	(tdesc_reg): Likewise.
	(tdesc_reg_up): Likewise.

gdbserver/
	* Makefile.in: Add common/tdesc.c
	* tdesc.c (init_target_desc): init all reg_defs from register vector.
	(tdesc_create_reg): Create tdesc_reg.
	* tdesc.h (tdesc_feature): Add register vector.
2018-04-18 14:00:30 +01:00
Tom Tromey bedda9aced Conditionally drop the discriminant field in quirk_rust_enum
While debugging the crash that Jan reported, I noticed that in some
situations we could end up with a situation where one branch of a Rust
enum type ended up with a field count of -1.

The fix is simple: only conditionally drop the discriminant field when
rewriting the enum variants.

I couldn't find a way to test this; I only noticed it while debugging
the DWARF reader.

2018-04-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (quirk_rust_enum): Conditionally drop the
	discriminant field.
2018-04-17 13:37:44 -06:00
Tom Tromey a037790ec5 Fix crash in quirk_rust_enum
I noticed that quirk_rust_enum can crash when presented with a union
whose fields are all scalar types.

This patch adds a new test case and fixes the bug.

Regression tested on Fedora 26 x86-64.

2018-04-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (quirk_rust_enum): Handle unions correctly.

2018-04-17  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.rs (Union): New type.
	(main): New local "u".
	* gdb.rust/simple.exp (test_one_slice): Add new test case.
2018-04-17 13:37:44 -06:00
Andreas Arnez c7dcbf88c6 Don't print symbol declaration's line number in rbreak output
This commit:

  b744723f57 -- Show line numbers in output for "info var/func/type"

adds the symbol declaration's line number to the output of certain GDB
commands.  It also (inadvertently) changes the `rbreak' command's output,
like this:

  (gdb) rbreak foo
  Breakpoint 1 at 0x40049b: file rbreak.c, line 6.
  4:      static int foo1(void);
  Breakpoint 2 at 0x4004b1: file rbreak.c, line 12.
  10:     static int foo2(void);
  (gdb)

where the function declaration is now prefixed by its source line number,
followed by a colon.  But without showing the declaration's file name, the
line number is useless and can possibly cause severe confusion.

No declaration line number was shown before.  Instead, the function
declaration started at the first column:

  (gdb) rbreak foo
  Breakpoint 1 at 0x40049b: file rbreak.c, line 6.
  static int foo1(void);
  Breakpoint 2 at 0x4004b1: file rbreak.c, line 12.
  static int foo2(void);
  (gdb)

This old behavior is restored, fixing some FAILs in fullpath-expand.exp,
realname-expand.exp, and pr10179.exp.

In order to distinguish when to print location information, the meaning of
print_symbol_info()'s parameter `last' is changed.  Now NULL means to skip
any filename or line number information.  Previously NULL meant to always
print the filename.

gdb/ChangeLog:

	* symtab.c (print_symbol_info): Skip printing filename and line
	number when `last' is NULL.
	(symtab_symbol_info): Use empty string instead of NULL for first
	invocation of print_symbol_info.
	(rbreak_command): Pass NULL to `last' parameter of
	print_symbol_info.
2018-04-17 19:31:58 +02:00
Simon Marchi 07d28c7777 linux_spu_make_corefile_notes: return note_data instead of nullptr
Since commit

  9018be2 ("Make target_read_alloc & al return vectors")

the test gdb.threads/gcore-stale-thread.exp test results in UNSUPPORTED:

  UNSUPPORTED: gdb.threads/gcore-stale-thread.exp: save a corefile

The problem is that the linux_spu_make_corefile_notes started returning
nullptr when reading TARGET_OBJECT_SPU fails.  The previous (and proper)
behaviour is to return the note_data received as a parameter, so that
other functions may continue to append to this buffer.

With this patch, the test goes back to PASS.

gdb/ChangeLog:

	* linux-tdep.c (linux_spu_make_corefile_notes): Return note_data
	instead of nullptr.
2018-04-16 16:47:06 -04:00
Andreas Arnez e3a91079b5 Adjust more test cases to changed output of info var/func/type
After this commit:

  b744723f57 -- Show line numbers in output for "info var/func/type"

the test cases dbx.exp and info-fun.exp yield new FAILs because two
regular expressions have not been adjusted to the changed output yet.
This is fixed.

gdb/testsuite/ChangeLog:

	* gdb.base/dbx.exp (test_whereis): Adjust regexp to added line
	number information in output of "whereis" command.
	* gdb.base/info-fun.exp: Likewise, for "info fun" command.
2018-04-16 20:58:14 +02:00
Pedro Alves 8a3de5e1a3 gdb: Remove support for SH-5/SH64
Since bfd dropped support for SH-5, there's no point in keeping it in
GDB either.

This restores --enable-targets=all builds.

gdb/ChangeLog:
2018-04-16  Pedro Alves  <palves@redhat.com>

	* MAINTAINERS (sh): Remove.
	* Makefile.in (ALL_TARGET_OBS): Remove sh64-tdep.o.
	(HFILES_NO_SRCDIR): Remove sh64-tdep.h.
	(ALLDEPFILES): Remove sh64-tdep.c.
	* NEWS: Mentions that support for SH-5/SH64 is removed.
	* configure.tgt (sh*-*-linux*): Remove reference to sh64-tdep.o.
	(sh*-*-openbsd*): Ditto.
	(sh64-*-elf*): Remove.
	(sh*): Remove.
	* regcache.c (cooked_write_test): Remove bfd_mach_sh5 case.
	* sh-linux-tdep.c: Remove reference to bfd_mach_sh5.
	* sh-tdep.c: No longer include "sh64-tdep.h".
	(sh_gdbarch_init): Remove reference to bfd_mach_sh5.
	* sh64-tdep.c, sh64-tdep.h: Remove files.
2018-04-16 13:20:15 +01:00
Pedro Alves a2a79012fe gdb: Remove OpenBSD/m88k support
Support for m88k was fully removed from bfd, which broke gdb
--enable-targets=all builds:

  > gdb/m88k-tdep.c: In function void _initialize_m88k_tdep():
  > gdb/m88k-tdep.c:867:21: error: bfd_arch_m88k was not declared in this scope
  >    gdbarch_register (bfd_arch_m88k, m88k_gdbarch_init, NULL);

There's no point in keeping GDB support for OpenBSD/m88k with no bfd
support, so this commit simply removes the port.

gdb/ChangeLog:
2018-04-16  Pedro Alves  <palves@redhat.com>

	* MAINTAINERS: Remove m88k.
	* Makefile.in (ALL_TARGET_OBS): Remove m88k-tdep.o.
	(HFILES_NO_SRCDIR): Remove m88k-tdep.h.
	(ALLDEPFILES): Remove m88k-bsd-nat.c and m88k-tdep.c.
	* NEWS: Mention that support for OpenBSD/m88k was removed.
	* configure.host (m88*-*-*): Remove support.
	* configure.nat (m88k-*-*): Remove support.
	* configure.tgt (m88*-*-openbsd*): Remove.
	* m88k-bsd-nat.c, m88k-tdep.c, m88k-tdep.h: Delete.
2018-04-16 13:16:22 +01:00
Simon Marchi eda4efb127 Add x86-tdep.o to i386/amd64 target build
We get this error when doing a build with a single amd64 target (the
default when doing just ./configure on x86-64 GNU/Linux):

/home/simark/src/binutils-gdb/gdb/i386-tdep.c:4431: error: undefined reference to 'x86_in_indirect_branch_thunk(unsigned long, char const**, int, int)'
/home/simark/src/binutils-gdb/gdb/amd64-tdep.c:3045: error: undefined reference to 'x86_in_indirect_branch_thunk(unsigned long, char const**, int, int)'

The problem is that commit

  1d509aa625 ("infrun: step through indirect branch thunks")

missed adding x86-tdep.o to the list of object file included in an amd64
or i386 build.  The problem is not seen with --enable-targets=all
because that file is included in ALL_TARGET_OBS.

Built-tested using:

  * --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
  * --host=armv7-rpi2-linux-gnueabihf --target=x86_64-pc-linux-gnu

gdb/ChangeLog:

	* configure.tgt (x86_tobjs): New variable.
	(amd64_tobjs, i386_tobjs): Use it.
2018-04-15 15:43:47 -04:00
Andreas Arnez b744723f57 Show line numbers in output for "info var/func/type"
The GDB commands "info variables", "info functions", and "info types" show
the appropriate list of definitions matching the given pattern.  They also
group them by source files.  But no line numbers within these source files
are shown.

The line number information is particularly useful to the user when a
simple "grep" doesn't readily point to a definition.  This is often the
case when the definition involves a macro, occurs within a namespace, or
when the identifier appears very frequently in the source file.

This patch enriches the printout of these commands by the line numbers and
adjusts affected test cases to the changed output where necessary.  The
new output looks like this:

  (gdb) i variables
  All defined variables:

  File foo.c:
  3:	const char * const foo;
  1:	int x;

The line number is followed by a colon and a tab character, which is then
followed by the symbol definition.  If no line number is available, the
tab is printed out anyhow, so definitions line up.

gdb/ChangeLog:

	* symtab.c (print_symbol_info): Precede the symbol definition by
	the line number when available.
	* NEWS: Advertise this enhancement.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Mention the fact that "info
	variables/functions/types" show source files and line numbers.

gdb/testsuite/ChangeLog:

	* gdb.ada/info_types.exp: Adjust expected output to the line
	numbers now printed by "info var/func/type".
	* gdb.base/completion.exp: Likewise.
	* gdb.base/included.exp: Likewise.
	* gdb.cp/cp-relocate.exp: Likewise.
	* gdb.cp/cplusfuncs.exp: Likewise.
	* gdb.cp/namespace.exp: Likewise.
	* gdb.dwarf2/dw2-case-insensitive.exp: Likewise.
2018-04-13 19:26:05 +02:00
Markus Metzger 4a4495d62d btrace: set/show record btrace cpu
Add new set/show commands to set the processor that is used for enabling
errata workarounds when decoding branch trace.

The general format is "<vendor>:<identifier>" but we also allow two
special values "auto" and "none".

The default is "auto", which is the current behaviour of having GDB
determine the processor on which the trace was recorded.

If that cpu is not known to the trace decoder, e.g. when using an old
decoder on a new system, decode may fail with "unknown cpu".  In most
cases it should suffice to 'downgrade' decode to assume an older cpu.
Unfortunately, we can't do this automatically.

The other special value, "none", disables errata workarounds.

gdb/
	* NEWS (New options): announce set/show record btrace cpu.
	* btrace.c: Include record-btrace.h.
	(btrace_compute_ftrace_pt): Skip enabling errata workarounds if
	the vendor is unknown.
	(btrace_compute_ftrace_1): Add cpu parameter.  Update callers.
	Maybe overwrite the btrace configuration's cpu.
	(btrace_compute_ftrace): Add cpu parameter.  Update callers.
	(btrace_fetch): Add cpu parameter.  Update callers.
	(btrace_maint_update_pt_packets): Call record_btrace_get_cpu.
	Maybe overwrite the btrace configuration's cpu.  Skip enabling
	errata workarounds if the vendor is unknown.
	* python/py-record-btrace.c: Include record-btrace.h.
	(recpy_bt_begin, recpy_bt_end, recpy_bt_instruction_history)
	(recpy_bt_function_call_history): Call record_btrace_get_cpu.
	* record-btrace.c (record_btrace_cpu_state_kind): New.
	(record_btrace_cpu): New.
	(set_record_btrace_cpu_cmdlist): New.
	(record_btrace_get_cpu): New.
	(require_btrace_thread, record_btrace_info)
	(record_btrace_resume_thread): Call record_btrace_get_cpu.
	(cmd_set_record_btrace_cpu_none): New.
	(cmd_set_record_btrace_cpu_auto): New.
	(cmd_set_record_btrace_cpu): New.
	(cmd_show_record_btrace_cpu): New.
	(_initialize_record_btrace): Initialize set/show record btrace cpu
	commands.
	* record-btrace.h (record_btrace_get_cpu): New.

testsuite/
	* gdb.btrace/cpu.exp: New.

doc/
	* gdb.texinfo: Document set/show record btrace cpu.
2018-04-13 11:35:55 +02:00
Markus Metzger 69f90c75b3 record: fix typo in "set record" output
Alan Hayward pointed out a typo in the output of "set record btrace" that
I took from "set record".  Fix the original.

gdb/
	* record.c (set_record_command): Fix typo in message.
2018-04-13 11:31:35 +02:00
Markus Metzger b85310e1ec btrace: fix output of "set record btrace"
Instead of giving a message that "set record btrace" needs a sub-command,
GDB crashed.  Fix it.  A regression test comes with the next patch.

gdb/
	* record-btrace.c (cmd_set_record_btrace): Print sub-commands.
2018-04-13 11:30:15 +02:00
Markus Metzger 1d509aa625 infrun: step through indirect branch thunks
With version 7.3 GCC supports new options

   -mindirect-branch=<choice>
   -mfunction-return=<choice>

The choices are:

    keep                behaves as before
    thunk               jumps through a thunk
    thunk-external      jumps through an external thunk
    thunk-inline        jumps through an inlined thunk

For thunk and thunk-external, GDB would, on a call to the thunk, step into
the thunk and then resume to its caller assuming that this is an
undebuggable function.  On a return thunk, GDB would stop inside the
thunk.

Make GDB step through such thunks instead.

Before:
    Temporary breakpoint 1, main ()
        at gdb.base/step-indirect-call-thunk.c:37
    37        x = apply (inc, 41);
    (gdb) s
    apply (op=0x80483e6 <inc>, x=41)
        at gdb.base/step-indirect-call-thunk.c:29
    29        return op (x);
    (gdb)
    30      }

After:
    Temporary breakpoint 1, main ()
        at gdb.base/step-indirect-call-thunk.c:37
    37        x = apply (inc, 41);
    (gdb) s
    apply (op=0x80483e6 <inc>, x=41)
        at gdb.base/step-indirect-call-thunk.c:29
    29        return op (x);
    (gdb)
    inc (x=41) at gdb.base/step-indirect-call-thunk.c:23
    23        return x + 1;

This is independent of the step-mode.  In order to step into the thunk,
you would need to use stepi.

When stepping over an indirect call thunk, GDB would first step through
the thunk, then recognize that it stepped into a sub-routine and resume to
the caller (of the thunk).  Not sure whether this is worth optimizing.

Thunk detection is implemented via gdbarch.  I implemented the methods for
IA.  Other architectures may run into unexpected fails.

The tests assume a fixed number of instruction steps to reach a thunk.
This depends on the compiler as well as the architecture.  They may need
adjustments when we add support for more architectures.  Or we can simply
drop those tests that cover being able to step into thunks using
instruction stepping.

When using an older GCC, the tests will fail to build and will be reported
as untested:

    Running .../gdb.base/step-indirect-call-thunk.exp ...
    gdb compile failed, \
    gcc: error: unrecognized command line option '-mindirect-branch=thunk'
    gcc: error: unrecognized command line option '-mfunction-return=thunk'

                    === gdb Summary ===

    # of untested testcases         1

gdb/
	* infrun.c (process_event_stop_test): Call
	gdbarch_in_indirect_branch_thunk.
	* gdbarch.sh (in_indirect_branch_thunk): New.
	* gdbarch.c: Regenerated.
	* gdbarch.h: Regenerated.
	* x86-tdep.h: New.
	* x86-tdep.c: New.
	* Makefile.in (ALL_TARGET_OBS): Add x86-tdep.o.
	(HFILES_NO_SRCDIR): Add x86-tdep.h.
	(ALLDEPFILES): Add x86-tdep.c.
	* arch-utils.h (default_in_indirect_branch_thunk): New.
	* arch-utils.c (default_in_indirect_branch_thunk): New.
	* i386-tdep: Include x86-tdep.h.
	(i386_in_indirect_branch_thunk): New.
	(i386_elf_init_abi): Set in_indirect_branch_thunk gdbarch
	function.
	* amd64-tdep: Include x86-tdep.h.
	(amd64_in_indirect_branch_thunk): New.
	(amd64_init_abi): Set in_indirect_branch_thunk gdbarch function.

testsuite/
	* gdb.base/step-indirect-call-thunk.exp: New.
	* gdb.base/step-indirect-call-thunk.c: New.
	* gdb.reverse/step-indirect-call-thunk.exp: New.
	* gdb.reverse/step-indirect-call-thunk.c: New.
2018-04-13 10:44:47 +02:00
Jan Kratochvil b4be9bfdab Fix -D_GLIBCXX_DEBUG gdb-add-index regression
Fedora Rawhide started to use -D_GLIBCXX_DEBUG which made gdb-add-index
failing:
	gdb: Out-of-bounds vector access while running gdb-add-index
	https://bugzilla.redhat.com/show_bug.cgi?id=1540559

/usr/include/c++/7/debug/safe_iterator.h:270:
Error: attempt to dereference a past-the-end iterator.
Objects involved in the operation:
    iterator "this" @ 0x0x7fffffffcb90 {
      type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<unsigned char*, std::__cxx1998::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > >, std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > (mutable iterator);
      state = past-the-end;
      references sequence with type 'std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > >' @ 0x0x7fffffffcc50
    }

/usr/include/c++/7/debug/vector:417:
Error: attempt to subscript container with out-of-bounds index 556, but
container only holds 556 elements.
Objects involved in the operation:
    sequence "this" @ 0x0x2e87af8 {
      type = std::__debug::vector<partial_symbol*, std::allocator<partial_symbol*> >;
    }

The two -D_GLIBCXX_DEBUG regressions were made by:

commit bc8f2430e0
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Jun 12 16:29:53 2017 +0100
    Code cleanup: C++ify .gdb_index producer

commit af5bf4ada4
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Sat Oct 14 08:06:29 2017 -0400
    Replace psymbol_allocation_list with std::vector

gdb/ChangeLog
2018-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/23053
	* dwarf-index-write.c (data_buf::grow) (write_one_signatured_type)
	(recursively_write_psymbols) (debug_names::recursively_write_psymbols)
	(debug_names::write_one_signatured_type): Fix -D_GLIBCXX_DEBUG
	regression.
2018-04-12 22:31:39 +02:00
Tom Tromey 53d7df28bc Remove old univariant code from rust-lang.c
Since moving Rust enum handling into dwarf2read.c, some old code for
handling univariant enums in rust-lang.c has been obsolete.  This
patch removes this code.

Tested on x86-64 Fedora 26, using rustc 1.23 (1.24 emits incorrect
DWARF for enums and so can't be used for this test).

2018-04-12  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_print_struct_def): Remove univariant code.
	(rust_evaluate_subexp): Likewise.
2018-04-12 11:03:59 -06:00
Pedro Alves 70b33f195b Fix Solaris build
This commit fixes a bit of rot in procfs.c caused by recent changes.

Specifically, the target_ops::to_detach change to pass down 'inferior
*' missed updating a forward declation, and the change to use
scoped_fd in more places missed removing one do_cleanups call.

  src/gdb/procfs.c: In function ‘target_ops* procfs_target()’:
  src/gdb/procfs.c:167:16: error: invalid conversion from ‘void (*)(target_ops*, const char*, int)’ to ‘void (*)(target_ops*, inferior*, int)’ [-fpermissive]
     t->to_detach = procfs_detach;
		  ^
  src/gdb/procfs.c: In function ‘ssd* proc_get_LDT_entry(procinfo*, int)’:
  src/gdb/procfs.c:1624:17: error: ‘old_chain’ was not declared in this scope
      do_cleanups (old_chain);
		   ^
  src/gdb/procfs.c: At global scope:
  src/gdb/procfs.c:90:13: error: ‘void procfs_detach(target_ops*, const char*, int)’ declared ‘static’ but never defined [-Werror=unused-function]
   static void procfs_detach (struct target_ops *, const char *, int);
	       ^
  src/gdb/procfs.c:1923:1: error: ‘void procfs_detach(target_ops*, inferior*, int)’ defined but not used [-Werror=unused-function]
   procfs_detach (struct target_ops *ops, inferior *inf, int from_tty)
   ^

gdb/ChangeLog:
2018-04-12  Pedro Alves  <palves@redhat.com>

	* procfs.c (procfs_detach): Make forward declaration's prototype
	match definition's protototype.
	(proc_get_LDT_entry): Remove stale do_cleanups call.
2018-04-12 17:47:59 +01:00
Pedro Alves 436411b1c6 Eliminate target_has_exited
Nothing uses this.

gdb/ChangeLog:
2018-04-12  Pedro Alves  <palves@redhat.com>

	* target.h (target_ops::to_has_exited): Delete.
	(target_has_exited): Delete.
	* target-delegates.c: Regenerate.
2018-04-12 17:36:01 +01:00
Simon Marchi 6295b6da16 Add test for following fork on position-independent executables
Commit

  b2e586e ("Defer breakpoint reset when cloning progspace for fork
  child")

fixed following fork childs when the executable is position-independent.
This patch adds a little test for it.

gdb/testsuite/ChangeLog:

	* gdb.base/pie-fork.c: New file.
	* gdb.base/pie-fork.exp: New file.
2018-04-11 14:55:40 -04:00
Tom Tromey 50146e7022 Add Rust test case for ".." struct initializer
Building with --coverage pointed out that there was no Rust test for
initializing a structure using the ".." initializer.  This patch adds
such a test.

Regression tested on x86-64 Fedora 26.

2018-04-11  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.exp: Add test for ".." struct initializer.
2018-04-11 08:25:34 -06:00
Pedro Alves 20db9c52a2 File I/O file handles after target closes
A future patch will propose making the remote target's target_ops be
heap-allocated (to make it possible to have multiple instances of
remote targets, for multiple simultaneous connections), and will
delete/destroy the remote target at target_close time.

That change trips on a latent problem, though.  File I/O handles
remain open even after the target is gone, with a dangling pointer to
a target that no longer exists.  This results in GDB crashing when it
calls the target_ops backend associated with the file handle:

 (gdb) Disconnect
 Ending remote debugging.
 * GDB crashes deferencing a dangling pointer

Backtrace:

   #0  0x00007f79338570a0 in main_arena () at /lib64/libc.so.6
   #1  0x0000000000858bfe in target_fileio_close(int, int*) (fd=1, target_errno=0x7ffe0499a4c8)
       at src/gdb/target.c:2980
   #2  0x00000000007088bd in gdb_bfd_iovec_fileio_close(bfd*, void*) (abfd=0x1a631b0, stream=0x223c9d0)
       at src/gdb/gdb_bfd.c:353
   #3  0x0000000000930906 in opncls_bclose (abfd=0x1a631b0) at src/bfd/opncls.c:528
   #4  0x0000000000930cf9 in bfd_close_all_done (abfd=0x1a631b0) at src/bfd/opncls.c:768
   #5  0x0000000000930cb3 in bfd_close (abfd=0x1a631b0) at src/bfd/opncls.c:735
   #6  0x0000000000708dc5 in gdb_bfd_close_or_warn(bfd*) (abfd=0x1a631b0) at src/gdb/gdb_bfd.c:511
   #7  0x00000000007091a2 in gdb_bfd_unref(bfd*) (abfd=0x1a631b0) at src/gdb/gdb_bfd.c:615
   #8  0x000000000079ed8e in objfile::~objfile() (this=0x2154730, __in_chrg=<optimized out>)
       at src/gdb/objfiles.c:682
   #9  0x000000000079fd1a in objfile_purge_solibs() () at src/gdb/objfiles.c:1065
   #10 0x00000000008162ca in no_shared_libraries(char const*, int) (ignored=0x0, from_tty=1)
       at src/gdb/solib.c:1251
   #11 0x000000000073b89b in disconnect_command(char const*, int) (args=0x0, from_tty=1)
       at src/gdb/infcmd.c:3035

This goes unnoticed in current master, because the current remote
target's target_ops is never destroyed nowadays, so we end up calling:

  remote_hostio_close -> remote_hostio_send_command

which gracefully fails with FILEIO_ENOSYS if remote_desc is NULL
(because the target is closed).

Fix this by invalidating a target's file I/O handles when the target
is closed.

With this change, remote_hostio_send_command no longer needs to handle the
case of being called with a closed remote target, originally added here:
<https://sourceware.org/ml/gdb-patches/2008-08/msg00359.html>.

gdb/ChangeLog:
2018-04-11  Pedro Alves  <palves@redhat.com>

	* target.c (fileio_fh_t::t): Add comment.
	(target_fileio_pwrite, target_fileio_pread, target_fileio_fstat)
	(target_fileio_close): Handle a NULL target.
	(invalidate_fileio_fh): New.
	(target_close): Call it.
	* remote.c (remote_hostio_send_command): No longer check whether
	remote_desc is open.
2018-04-11 11:40:05 +01:00
Pedro Alves 5ff79300ae C++ify fileio_fh_t, replace VEC with std::vector
Preparation for the next patch.

- Replace VEC with std::vector.
- Rewrite a couple macros as methods/functions.
- While at it, rename fileio_fh_t::fd as fileio_fh_t::target_fd to
  avoid confusion between target and host file descriptors.

gdb/ChangeLog:
2018-04-11  Pedro Alves  <palves@redhat.com>

	* target.c (fileio_fh_t): Make it a named struct instead of a
	typedef.
	(fileio_fh_t::is_closed): New method.
	(DEF_VEC_O (fileio_fh_t)): Remove.
	(fileio_fhandles): Now a std::vector.
	(is_closed_fileio_fh): Delete.
	(acquire_fileio_fd): Adjust.  Rename parameters.
	(release_fileio_fd): Adjust.
	(fileio_fd_to_fh): Reimplement as a function instead of a macro.
	(target_fileio_pwrite, target_fileio_pread, target_fileio_fstat)
	(target_fileio_close): Adjust.
2018-04-11 11:29:39 +01:00
Simon Marchi 6e22e10d63 Iterate by index in auto_load_safe_path_vec_update
As reported by Jan, we get this error when building with -D_GLIBCXX_DEBUG:

/usr/include/c++/7/debug/safe_iterator.h:297:
Error: attempt to increment a singular iterator.
Objects involved in the operation:
    iterator "this" @ 0x0x7fffffffd140 {
      type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<char, gdb::xfree_deleter<char> >*, std::__cxx1998::vector<std::unique_ptr<char, gdb::xfree_deleter<char> >, std::allocator<std::unique_ptr<char, gdb::xfree_deleter<char> > > > >, std::__debug::vector<std::unique_ptr<char, gdb::xfree_deleter<char> >, std::allocator<std::unique_ptr<char, gdb::xfree_deleter<char> > > > > (mutable iterator);
      state = singular;
      references sequence with type 'std::__debug::vector<std::unique_ptr<char, gdb::xfree_deleter<char> >, std::allocator<std::unique_ptr<char, gdb::xfree_deleter<char> > > >' @ 0x0x265db40
    }

The bug was introduced by commit

commit e80aaf6183
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Fri Mar 2 23:22:06 2018 -0500
Make delim_string_to_char_ptr_vec return an std::vector

The problem is that we iterate using a range-based for on a vector to
which we push in the loop.  Pushing to the vector invalidates the
iterator used in the loop.  Instead, change the code to iterate by index
as was done in the previous code.

gdb/ChangeLog:

	* auto-load.c (auto_load_safe_path_vec_update): Iterate by
	index.
2018-04-10 16:50:59 -04:00
Pedro Alves f50d8a2eae Fix gdb.base/fork-running-state.exp race
On my multi-target branch I was occasionaly seeing a FAIL like this:

  (gdb) PASS: gdb.base/fork-running-state.exp: detach-on-fork=off: follow-fork=parent: non-stop: kill parent
  [Inferior 2 (process 32672) exited normally]
  kill inferior 2
  warning: Inferior ID 2 is not running.
  (gdb) FAIL: gdb.base/fork-running-state.exp: detach-on-fork=off: follow-fork=parent: non-stop: kill child (the program exited)
  ... other similar fails ...

Turns out to be a testcase bug/race.  A tweak like this increases the
changes of hitting the race substancially:

  --- a/gdb/testsuite/gdb.base/fork-running-state.c
  +++ b/gdb/testsuite/gdb.base/fork-running-state.c
  @@ -29,7 +29,7 @@ fork_child (void)
   {
     while (1)
       {
  -      sleep (1);
  +      usleep (100);


The testcase has two processes, parent and child fork.  The problem is
that the child exits itself if it notices the parent is gone, but the
testcase .exp does not expect that.

I first wrote a patch that handled the different combinations of
non-stop/detach-on-fork/follow-fork/schedule-multiple, making the .exp
file know when to expect the child to exit itself vs when to kill it
explicitly, but the result was that the code to kill the parent and
child was getting about as large as the test code that is the actual
point of the testcase, above the kills.

So I scratched that approach and came up with a simpler patch --
simply make the child not exit itself when the parent exits.

The .exp file is going to kill both parent and child explicitly, and,
main() already calls alarm() as a safeguard.  I don't think we lose
anything.

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

	* gdb.base/fork-running-state.c (fork_child): Don't exit if parent
	exits.  Instead loop running forever.
	(fork_parent): Run forever too.
2018-04-10 15:00:39 +01:00
Pedro Alves 731f534f91 Replace finish_thread_state_cleanup with a RAII class
gdb/ChangeLog:
2018-04-10  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (finish_thread_state_cleanup): Delete declaration.
	(scoped_finish_thread_state): New class.
	* infcmd.c (run_command_1): Use it instead of finish_thread_state
	cleanup.
	* infrun.c (proceed, prepare_for_detach, wait_for_inferior)
	(fetch_inferior_event, normal_stop): Likewise.
	* thread.c (finish_thread_state_cleanup): Delete.
2018-04-10 14:49:30 +01:00
Simon Marchi d5f4488f09 Add selftests for range_contains and insert_into_bit_range_vector
Add some selftests for these two functions.  To to make it easier to
compare sequences of ranges, add operator== and operator!= to compare
two gdb::array_view, and add operator== in struct range.

gdb/ChangeLog:

	* value.c: Include "selftest.h" and "common/array-view.h".
	(struct range) <operator ==>: New.
	(test_ranges_contain): New.
	(check_ranges_vector): New.
	(test_insert_into_bit_range_vector): New.
	(_initialize_values): Register selftests.
	* common/array-view.h (operator==, operator!=): New.
2018-04-09 15:47:12 -04:00
Simon Marchi b24531ed17 Use an std::vector for inline_states
This patch replaces VEC(inline_state) with std::vector<inline_state> and
adjusts the code that uses it.

gdb/ChangeLog:

	* common/gdb_vecs.h (unordered_remove): Add overload that takes
	an iterator.
	* inline-frame.c: Include <algorithm>.
	(struct inline_state): Add constructor.
	(inline_state_s): Remove.
	(DEF_VEC_O(inline_state_s)): Remove.
	(inline_states): Change type to std::vector.
	(find_inline_frame_state): Adjust to std::vector.
	(allocate_inline_frame_state): Remove.
	(clear_inline_frame_state): Adjust to std::vector.
	(skip_inline_frames): Adjust to std::vector.
2018-04-09 15:40:45 -04:00
Simon Marchi c252925ccc Remove VEC(tsv_s), use std::vector instead
This patch removes VEC(tsv_s), using an std::vector instead.  I C++ified
trace_state_variable a bit in the process, using std::string for the
name.  I also thought it would be nicer to pass a const reference to
target_download_trace_state_variable, since we know it will never be
NULL.  This highlighted that the make-target-delegates script didn't
handle references well, so I adjusted this as well.  It will surely be
useful in the future.

gdb/ChangeLog:

	* tracepoint.h (struct trace_state_variable): Add constructor.
	<name>: Change type to std::string.
	* tracepoint.c (tsv_s): Remove.
	(DEF_VEC_O(tsv_s)): Remove.
	(tvariables): Change to std::vector.
	(create_trace_state_variable): Adjust to std::vector.
	(find_trace_state_variable): Likewise.
	(find_trace_state_variable_by_number): Likewise.
	(delete_trace_state_variable): Likewise.
	(trace_variable_command): Adjust to std::string.
	(delete_trace_variable_command): Likewise.
	(tvariables_info_1): Adjust to std::vector.
	(save_trace_state_variables): Likewise.
	(start_tracing): Likewise.
	(merge_uploaded_trace_state_variables): Adjust to std::vector
	and std::string.
	* target.h (struct target_ops)
	<to_download_trace_state_variable>: Pass reference to
	trace_state_variable.
	* target-debug.h (target_debug_print_const_trace_state_variable_r): New.
	* target-delegates.c: Re-generate.
	* mi/mi-interp.c (mi_tsv_created): Adjust to std::string.
	(mi_tsv_deleted): Likewise.
	* mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise.
	* remote.c (remote_download_trace_state_variable): Change
	pointer to reference and adjust.
	* make-target-delegates (parse_argtypes): Handle references.
	(write_function_header): Likewise.
	(munge_type): Likewise.
2018-04-09 15:16:19 -04:00
Simon Marchi c9638d2669 Adapt and integrate string_view tests
The previous patch copied the string_view tests from libstdc++.  This
patch adjusts them in a similar way that the libstdc++ optional tests
are integrated in our unit test suite.

Not all tests are used, some of them require language features not
present in c++11.  For example, we can't use a string_view constructor
where the length is not explicit in a constexpr, because
std::char_traits::length is not a constexpr itself (it is in c++17
though).  Nevertheless, a good number of tests are integrated, which
covers pretty well the string_view features.

gdb/ChangeLog:

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	string_view-selftests.c.
	* unittests/basic_string_view/capacity/1.cc: Adapt to GDB
	testsuite.
	* unittests/basic_string_view/cons/char/1.cc: Likewise.
	* unittests/basic_string_view/cons/char/2.cc: Likewise.
	* unittests/basic_string_view/cons/char/3.cc: Likewise.
	* unittests/basic_string_view/element_access/char/1.cc:
	Likewise.
	* unittests/basic_string_view/element_access/char/empty.cc:
	Likewise.
	* unittests/basic_string_view/element_access/char/front_back.cc:
	Likewise.
	* unittests/basic_string_view/inserters/char/2.cc: Likewise.
	* unittests/basic_string_view/modifiers/remove_prefix/char/1.cc:
	Likewise.
	* unittests/basic_string_view/modifiers/remove_suffix/char/1.cc:
	Likewise.
	* unittests/basic_string_view/modifiers/swap/char/1.cc:
	Likewise.
	* unittests/basic_string_view/operations/compare/char/1.cc:
	Likewise.
	* unittests/basic_string_view/operations/compare/char/13650.cc:
	Likewise.
	* unittests/basic_string_view/operations/copy/char/1.cc:
	Likewise.
	* unittests/basic_string_view/operations/data/char/1.cc:
	Likewise.
	* unittests/basic_string_view/operations/find/char/1.cc:
	Likewise.
	* unittests/basic_string_view/operations/find/char/2.cc:
	Likewise.
	* unittests/basic_string_view/operations/find/char/3.cc:
	Likewise.
	* unittests/basic_string_view/operations/find/char/4.cc:
	Likewise.
	* unittests/basic_string_view/operations/rfind/char/1.cc:
	Likewise.
	* unittests/basic_string_view/operations/rfind/char/2.cc:
	Likewise.
	* unittests/basic_string_view/operations/rfind/char/3.cc:
	Likewise.
	* unittests/basic_string_view/operations/substr/char/1.cc:
	Likewise.
	* unittests/basic_string_view/operators/char/2.cc: Likewise.
	* unittests/string_view-selftests.c: New file.
2018-04-09 14:20:47 -04:00
Simon Marchi fdc116781b Copy string_view tests from libstdc++
This patch copies the string_view tests from the gcc repository (commit
02a4441f002c).

  ${gcc}/libstdc++-v3/testsuite/21_strings/basic_string_view ->
    ${binutils-gdb}/gdb/unittests/basic_string_view

The local modifications are done in the following patch, so that it's
easier to review them.

gdb/ChangeLog:

	* unittests/basic_string_view/capacity/1.cc: New file.
	* unittests/basic_string_view/capacity/empty_neg.cc: New file.
	* unittests/basic_string_view/cons/char/1.cc: New file.
	* unittests/basic_string_view/cons/char/2.cc: New file.
	* unittests/basic_string_view/cons/char/3.cc: New file.
	* unittests/basic_string_view/cons/wchar_t/1.cc: New file.
	* unittests/basic_string_view/cons/wchar_t/2.cc: New file.
	* unittests/basic_string_view/cons/wchar_t/3.cc: New file.
	* unittests/basic_string_view/element_access/char/1.cc: New file.
	* unittests/basic_string_view/element_access/char/2.cc: New file.
	* unittests/basic_string_view/element_access/char/empty.cc: New file.
	* unittests/basic_string_view/element_access/char/front_back.cc: New file.
	* unittests/basic_string_view/element_access/wchar_t/1.cc: New file.
	* unittests/basic_string_view/element_access/wchar_t/2.cc: New file.
	* unittests/basic_string_view/element_access/wchar_t/empty.cc: New file.
	* unittests/basic_string_view/element_access/wchar_t/front_back.cc: New file.
	* unittests/basic_string_view/include.cc: New file.
	* unittests/basic_string_view/inserters/char/1.cc: New file.
	* unittests/basic_string_view/inserters/char/2.cc: New file.
	* unittests/basic_string_view/inserters/char/3.cc: New file.
	* unittests/basic_string_view/inserters/pod/10081-out.cc: New file.
	* unittests/basic_string_view/inserters/wchar_t/1.cc: New file.
	* unittests/basic_string_view/inserters/wchar_t/2.cc: New file.
	* unittests/basic_string_view/inserters/wchar_t/3.cc: New file.
	* unittests/basic_string_view/literals/types.cc: New file.
	* unittests/basic_string_view/literals/values.cc: New file.
	* unittests/basic_string_view/modifiers/remove_prefix/char/1.cc: New file.
	* unittests/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc: New file.
	* unittests/basic_string_view/modifiers/remove_suffix/char/1.cc: New file.
	* unittests/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc: New file.
	* unittests/basic_string_view/modifiers/swap/char/1.cc: New file.
	* unittests/basic_string_view/modifiers/swap/wchar_t/1.cc: New file.
	* unittests/basic_string_view/operations/compare/char/1.cc: New file.
	* unittests/basic_string_view/operations/compare/char/13650.cc: New file.
	* unittests/basic_string_view/operations/compare/char/2.cc: New file.
	* unittests/basic_string_view/operations/compare/char/70483.cc: New file.
	* unittests/basic_string_view/operations/compare/wchar_t/1.cc: New file.
	* unittests/basic_string_view/operations/compare/wchar_t/13650.cc: New file.
	* unittests/basic_string_view/operations/compare/wchar_t/2.cc: New file.
	* unittests/basic_string_view/operations/copy/char/1.cc: New file.
	* unittests/basic_string_view/operations/copy/wchar_t/1.cc: New file.
	* unittests/basic_string_view/operations/data/char/1.cc: New file.
	* unittests/basic_string_view/operations/data/wchar_t/1.cc: New file.
	* unittests/basic_string_view/operations/find/char/1.cc: New file.
	* unittests/basic_string_view/operations/find/char/2.cc: New file.
	* unittests/basic_string_view/operations/find/char/3.cc: New file.
	* unittests/basic_string_view/operations/find/char/4.cc: New file.
	* unittests/basic_string_view/operations/find/wchar_t/1.cc: New file.
	* unittests/basic_string_view/operations/find/wchar_t/2.cc: New file.
	* unittests/basic_string_view/operations/find/wchar_t/3.cc: New file.
	* unittests/basic_string_view/operations/find/wchar_t/4.cc: New file.
	* unittests/basic_string_view/operations/rfind/char/1.cc: New file.
	* unittests/basic_string_view/operations/rfind/char/2.cc: New file.
	* unittests/basic_string_view/operations/rfind/char/3.cc: New file.
	* unittests/basic_string_view/operations/rfind/wchar_t/1.cc: New file.
	* unittests/basic_string_view/operations/rfind/wchar_t/2.cc: New file.
	* unittests/basic_string_view/operations/rfind/wchar_t/3.cc: New file.
	* unittests/basic_string_view/operations/string_conversion/1.cc: New file.
	* unittests/basic_string_view/operations/substr/char/1.cc: New file.
	* unittests/basic_string_view/operations/substr/wchar_t/1.cc: New file.
	* unittests/basic_string_view/operators/char/2.cc: New file.
	* unittests/basic_string_view/operators/wchar_t/2.cc: New file.
	* unittests/basic_string_view/range_access/char/1.cc: New file.
	* unittests/basic_string_view/range_access/wchar_t/1.cc: New file.
	* unittests/basic_string_view/requirements/explicit_instantiation/1.cc: New file.
	* unittests/basic_string_view/requirements/explicit_instantiation/char/1.cc: New file.
	* unittests/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc: New file.
	* unittests/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc: New file.
	* unittests/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc: New file.
	* unittests/basic_string_view/requirements/typedefs.cc: New file.
	* unittests/basic_string_view/typedefs.cc: New file.
	* unittests/basic_string_view/types/1.cc: New file.
2018-04-09 14:20:47 -04:00
Simon Marchi 8345c4a267 Add gdb::string_view
We had a few times the need for a data structure that does essentially
what C++17's std::string_view does, which is to give an std::string-like
interface (only the read-only operations) to an arbitrary character
buffer.

This patch adapts the files copied from libstdc++ by the previous patch
to integrate them with GDB.  Here's a summary of the changes:

  * Remove things related to wstring_view, u16string_view and
  u32string_view (I don't think we need them, but we can always add them
  later).

  * Remove usages of _GLIBCXX_BEGIN_NAMESPACE_VERSION and
  _GLIBCXX_END_NAMESPACE_VERSION.

  * Put the code in the gdb namespace.  I had to add a few "std::" in
  front of std type usages.

  * Change __throw_out_of_range_fmt() for error().

  * Make gdb::string_view an alias of std::string_view when building
  with >= c++17.

  * Remove a bunch of constexpr, because they are not valid in c++11
  (e.g. they are not a single return line).

  * Use std::common_type<_Tp>::type instead of std::common_type_t<_Tp>,
  because c++11 doesn't have the later.

  * Remove the #pragma GCC system_header, since that silences some
  warnings that we might want to have if we're doing something not
  correctly.

  * Remove operator ""sv.  It would need a lot of work to make all
  supported compilers happy, and we can easily live without it.

  * Remove operator<<.  It is implemented using __ostream_insert (a
  libstdc++ internal).  Bringing it in might be possible, but I don't
  think that would be worth the effort, since we don't really use
  streams at the moment.

  * Replace internal libstdc++ asserts ( __glibcxx_assert and
  __glibcxx_requires_string_len) with gdb_assert.

  * Remove hash helpers, because they use libstdc++ internal functions.
  If we need them we always import them later.

The string_view class in cli/cli-script.c is removed and its usage
replaced with the new gdb::string_view.

gdb/ChangeLog:

	* common/gdb_string_view.h: Remove libstdc++ implementation
	details, adjust to gdb reality.
	* common/gdb_string_view.tcc: Likewise.
	* cli/cli-script.c (struct string_view): Remove.
	(user_args) <m_args>: Change element type to gdb::string_view.
	(user_args::insert_args): Adjust.
2018-04-09 14:20:46 -04:00
Simon Marchi 7adcdf08e7 Copy string_view files from libstdc++
This patch copies the following files from libstdc++ (commit
02a4441f002c):

  ${gcc}/libstdc++-v3/include/experimental/string_view
    -> ${binutils-gdb}/gdb/common/gdb_string_view.h

  ${gcc}/libstdc++-v3/include/experimental/bits/string_view.tcc
    -> ${binutils-gdb}/gdb/common/gdb_string_view.tcc

The local modifications are done in the following patch in order to make
it easier to review them.

gdb/ChangeLog:

	* common/gdb_string_view.h: New file.
	* common/gdb_string_view.tcc: New file.
2018-04-09 14:10:10 -04:00
Simon Marchi 41260ac25d Update ax_cv_cxx_compile_cxx.m4
This file provides the AX_CXX_COMPILE_STDCXX macro.  In the context of
the following patch, I wanted to build and test GDB in c++17 mode.  The
version of the macro we have in the repo does not support detecting
c++17 compilers, but the upstream version has been updated to do so.

Since we have local modifications to the file, I had to reconcile our
modifications and the updated upstream version (which was relatively
straightforward).

gdb/ChangeLog:

	* ax_cxx_compile_stdcxx.m4: Sync with upstream.
	* configure: Re-generate.
2018-04-09 14:09:24 -04:00
Pedro Alves 0bee6dd4aa Apply "Convert observers to C++" edit to gdbarch.sh
Regenerating gdbarch.c results in:

  --- gdbarch.c   2018-03-26 23:18:52.905548891 +0100
  +++ new-gdbarch.c       2018-04-09 15:32:30.006712207 +0100
  @@ -44,7 +44,7 @@
   #include "reggroups.h"
   #include "osabi.h"
   #include "gdb_obstack.h"
  -#include "observable.h"
  +#include "observer.h"
   #include "regcache.h"
   #include "objfiles.h"
   #include "auxv.h"
  @@ -5457,7 +5457,7 @@
     gdb_assert (new_gdbarch != NULL);
     gdb_assert (new_gdbarch->initialized_p);
     current_inferior ()->gdbarch = new_gdbarch;
  -  gdb::observers::architecture_changed.notify (new_gdbarch);
  +  observer_notify_architecture_changed (new_gdbarch);
     registers_changed ();
   }


Clearly commit 76727919ce ("Convert observers to C++") edited
gdbarch.c directly instead of gdbarch.sh.  This fixes it.

gdb/ChangeLog:
2018-04-09  Pedro Alves  <palves@redhat.com>

	* gdbarch.sh: Include "observable.h" instead of "observer.h".
	(set_target_gdbarch): Call
	gdb::observers::architecture_changed.notify instead of
	observer_notify_architecture_changed.
2018-04-09 15:34:48 +01:00
Simon Marchi a0be7a3671 Fix gdb.mi/mi-stack.exp when gcc generates a stack protector
I see some failures in the gdb.mi/mi-stack.exp test.  The test runs to
the callee4 function:

  int callee4 (void)
  {
    int A=1;
    int B=2;
    int C;
    int D[3] = {0, 1, 2};

    C = A + B;
    return 0;
  }

and expects to be stopped at the A=1 line.  However, when gcc generates
some stack protection code, it will stop at the { instead, as shown by
this disassembly (after I did "break callee4" and "run"):

  (gdb) disassemble /s
  Dump of assembler code for function callee4:
  /home/simark/src/binutils-gdb/gdb/testsuite/gdb.mi/mi-stack.c:
  26	{
     0x00005555555546ca <+0>:	push   %rbp
     0x00005555555546cb <+1>:	mov    %rsp,%rbp
     0x00005555555546ce <+4>:	sub    $0x20,%rsp
  => 0x00005555555546d2 <+8>:	mov    %fs:0x28,%rax
     0x00005555555546db <+17>:	mov    %rax,-0x8(%rbp)
     0x00005555555546df <+21>:	xor    %eax,%eax

  27	  int A=1; /* callee4 begin */
     0x00005555555546e1 <+23>:	movl   $0x1,-0x20(%rbp)

  28	  int B=2;
     0x00005555555546e8 <+30>:	movl   $0x2,-0x1c(%rbp)

The rest of the test relies on execution stopping on the A=1, so many things
fail after that.  This patch uses mi_continue_to_line instead, to stop at the
A=1 line precisely.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-stack.exp (test_stack_frame_listing): Use
	mi_continue_to_line.
	* gdb.mi/mi-stack.c (callee4): Add comment.
2018-04-07 14:09:14 -04:00