Commit Graph

2056 Commits

Author SHA1 Message Date
John Baldwin 74792ff782 Add native target for FreeBSD/riscv.
gdb/ChangeLog:

	* Makefile.in (ALLDEPFILES): Add riscv-fbsd-nat.c.
	* NEWS: Mention new FreeBSD/riscv native configuration.
	* configure.host: Add riscv*-*-freebsd*.
	* configure.nat: Likewise.
	* riscv-fbsd-nat.c: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Contributors): Add SRI International and University
	of Cambridge for FreeBSD/riscv.
2018-10-08 14:47:34 -07:00
John Baldwin ed65e20bc7 Add FreeBSD/riscv architecture.
Support for collecting and supplying general purpose and floating
point register sets is provided along with signal frame unwinding.

FreeBSD only supports RV64 currently, so while some provision is made
for RV32 in the general-purpose register set, the changes have only
been tested on RV64.

gdb/ChangeLog:

	* Makefile.in (ALL_TARGET_OBS): Add riscv-fbsd-tdep.o.
	(HFILES_NO_SRCDIR): Add riscv-fbsd-tdep.h.
	(ALLDEPFILES): Add riscv-fbsd-tdep.c.
	* NEWS: Mention new FreeBSD/riscv target.
	* configure.tgt: Add riscv*-*-freebsd*.
	* riscv-fbsd-tdep.c: New file.
	* riscv-fbsd-tdep.h: New file.
2018-10-08 14:47:34 -07:00
Tom Tromey a8a5dbcab8 Do not accidentally include in-tree readline headers
PR build/17077 points out that when --with-system-readline is given,
gdb will still pick up the in-tree readline headers.  Normally this is
not a big problem, because readline is very stable and so the ABI does
not change much; but it is clearly a bug to do this, and could bite at
some point.

The basic problem is that OPCODES_CFLAGS uses -I$(OPCODES_SRC)/..  so
that #include "opcodes/..." works.  However, this also makes it so the

This patch fixes the problem in a mildly hacky way: remove the
offending -I option, and change gdb to use #include "../opcodes/..."
instead.  This continues to make it clear where the header comes from,
without allowing incorrect behavior.

Tested by rebuilding and then looking at the *.Po files.

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

	PR build/17077:
	* Makefile.in (OPCODES_CFLAGS): Remove "-I$(OPCODES_SRC)/..".
	* arc-tdep.c, frv-tdep.c, lm32-tdep.c, mep-tdep.c,
	microblaze-tdep.c, or1k-tdep.h: Use ../opcodes, not opcodes, in
	#include.
2018-10-06 22:46:56 -06:00
John Darrington c1168a2f66 Allow remote debugging over a Unix local domain socket.
Extend the "target remote" and "target extended-remote" commands
such that if the filename provided is a Unix local domain (AF_UNIX)
socket, then it'll be treated as such, instead of trying to open
it as if it were a character device.

gdb/ChangeLog:
	* NEWS: Mention changed commands.
	* ser-uds.c: New file.
	* configure.ac (SER_HARDWIRE): Add ser-uds.o.
	* configure: Regenerate.
	* Makefile.in: Add new file.
	* serial.c (serial_open): Check if filename is a socket
	  and lookup the appropriate interface accordingly.

gdb/doc/ChangeLog:
	* gdb.texinfo (Remote Connection Commands): Describe
	  the changes to target remote and target extended-remote
	  relating to Unix domain sockets.
2018-10-02 16:10:57 +02:00
Gary Benson 7c619dbdae Move duplicated code to common/gdb_proc_service.h
This commit moves now-identical code from gdb/gdb_proc_service.h
and gdb/gdbserver/gdb_proc_service.h into the new shared file
gdb/common/gdb_proc_service.h.

gdb/ChangeLog:

	* common/gdb_proc_service.h: New file, factored out from...
	* gdb_proc_service.h: Moved common code to the above file.
	* Makefile.in (HFILES_NO_SRCDIR): Add the above new file.

gdb/gdbserver/ChangeLog:

	* gdb_proc_service.h: Moved common code to
	common/gdb_proc_service.h.
2018-10-01 10:37:39 +01:00
Rainer Orth 8674be7924 Fold i386-v4-nat.c into i386-sol2-nat.c
I've been carrying around the following patch for some time.  I noticed
that both i386-sol2-nat.c and i386-v4-nat.c are Solaris-only now and it
seems confusing to carry both around.

So this patch merges i386-v4-nat.c into i386-sol2-nat.c, simplifying it
in a couple of places, like removing checks for macros that are always
defined.

Tested on 64-bit Solaris 11.5/x86 (amd64-pc-solaris2.11) and 32-bit
Solaris 11.3/x86 (i386-pc-solaris2.11) half a year ago.

	* i386-v4-nat.c (regmap, supply_gregset, fill_gregset)
	(supply_fpregset, fill_fpregset): Move ...
	* i386-sol2-nat.c [PR_MODEL_NATIVE != PR_MODEL_LP64]: ... here.
	Remove HAVE_GREGSET_T, HAVE_FPREGET_T guards.
	Remove references to ioctl-based procfs.
	Include <sys/reg.h>.
	Remove PR_MODEL_NATIVE guards.
	* configure.nat <sol2, i386> (NATDEPFILES): Remove i386-v4-nat.o.
	* Makefile.in (ALLDEPFILES): Remove i386-v4-nat.c.
2018-09-20 10:10:07 +02:00
Simon Marchi 8ff03f0bfb Sort objects in gdb and gdbserver Makefiles
Tom mentioned this a while ago, as a way to give you a cheap sense of
progression in your build, as all object files will be built
alphabetically (including the directory part).  I tried it and I think
it's nice.

gdb/ChangeLog:

	* Makefile.in (LIBGDB_OBS): Sort COMMON_OBS.

gdb/gdbserver/ChangeLog:

	* Makefile.in (gdbserver$(EXEEXT)): Sort OBS.
	(gdbreplay$(EXEEXT)): Sort GDBREPLAY_OBS.
	($(IPA_LIB)): Sort IPA_OBJS.
2018-09-16 20:34:56 -04:00
Eli Zaretskii 23c4651c06 Fix "make install-strip" failure to install gdb-add-index.sh
gdb/ChangeLog:
2018-09-10  Eli Zaretskii  <eliz@gnu.org>

	* Makefile.in (transformed_name): Use INSTALL_SCRIPT instead of
	INSTALL_PROGRAM to install gdb-add-index.sh.  Don't append
	$(EXEEXT) to the script, as it is not a program.
2018-09-10 10:14:04 +03:00
Tom Tromey 8dc9fd87b0 Simplify ada-exp.o rule
The ada-exp.o rule no longer needs to pass -Wno-old-style-definition
to the compiler, as this option has no meaning in C++.  So, This patch
simplifies the explicit ada-exp.o rule in the Makefile.  The rule is
still needed because, according to the comment, ada-exp.c may appear
in the srcdir.

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

	* Makefile.in (GDB_WARN_CFLAGS_NO_DEFS): Remove.
	(ada-exp.o): Update.
2018-09-04 10:45:55 -06:00
Tom Tromey 3322c5d9a1 Remove unneeded explicit .o targets
Makefile.in had special cases to compile printcmd.o and target-float.o
with a different set of warnings.  However, this is no longer
required, so this patch removes those rules.

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

	* Makefile.in (printcmd.o, target-float.o): Remove.
	(GDB_WARN_CFLAGS_NO_FORMAT): Remove.
2018-09-04 10:45:54 -06:00
Tom Tromey ba2bf2aaba Remove obsolete comments from Makefiles
This removes an obsolete comment from Makefile.in.  This was copied
into gnulib/Makefile.in, so this removes that comment as well.

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

	* gnulib/Makefile.in: Remove obsolete comment.
	* Makefile.in: Remove obsolete comment.
2018-09-04 10:45:54 -06:00
Keith Seitz 078a020797 C++ compile support
This patch adds *basic* support for C++ to the compile feature.  It does
most simple type conversions, including everything that C compile does and
your basic "with-classes" type of C++.

I've written a new compile-support.exp support file which adds a new test
facility for automating and simplifying "compile print" vs "compile code"
testing.  See testsuite/lib/compile-support.exp and CompileExpression
for more on that.  The tests use this facility extensively.

This initial support has several glaring omissions:
- No template support at all
  I have follow-on patches for this, but they add much complexity
  to this "basic" support.  Consequently, they will be submitted separately.
- Cannot print functions
  The code template needs tweaking, and I simply haven't gotten to it yet.
- So-called "special function" support is not included
  Using constructors, destructors, operators, etc will not work. I have
  follow-on patches for that, but they require some work because of the
  recent churn in symbol searching.
- There are several test suite references to "compile/1234" bugs.
  I will file bugs and update the test suite's bug references before pushing
  these patches.

The test suite started as a copy of the original C-language support, but
I have written tests to exercise the basic functionality of the plug-in.

I've added a new option for outputting debug messages for C++ type-conversion
("debug compile-cplus-types").

gdb/ChangeLog:

	* Makefile.in (SUBDIR_GCC_COMPILE_SRCS): Add compile-cplus-symbols.c
	and compile-cplus-types.c.
	(HFILES_NO_SRCDIR): Add gcc-cp-plugin.h.
	* c-lang.c (cplus_language_defn): Set C++ compile functions.
	* c-lang.h (cplus_get_compile_context, cplus_compute_program):
	Declare.
	* compile/compile-c-support.c: Include compile-cplus.h.
	(load_libcompile): Templatize.
	(get_compile_context): "New" function.
	(c_get_compile_context): Use get_compile_context.
	(cplus_get_compile_context): New function.
	(cplus_push_user_expression, cplus_pop_user_expression)
	(cplus_add_code_header, cplus_add_input, cplus_compile_program)
	(cplus_compute_program): Define new structs/functions.
	* compile/compile-cplus-symmbols.c: New file.
	* compile/compile-cplus-types.c: New file.
	* compile/compile-cplus.h: New file.
	* compile/compile-internal.h (debug_compile_oracle, GCC_TYPE_NONE):
	Declare.
	* compile/compile-object-load.c (get_out_value_type): Use
	strncmp_iw when comparing symbol names.
	(compile_object_load): Add mst_bss and mst_data.
	* compile/compile.c (_initialize_compile): Remove
	-Wno-implicit-function-declaration from `compile_args'.
	* compile/gcc-cp-plugin.h: New file.
	* NEWS: Mention C++ compile support and new debug options.

gdb/testsuite/ChangeLog:

	* gdb.compile/compile-cplus-anonymous.cc: New file.
	* gdb.compile/compile-cplus-anonymous.exp: New file.
	* gdb.compile/compile-cplus-array-decay.cc: New file.
	* gdb.compile/compile-cplus-array-decay.exp: New file.
	* gdb.compile/compile-cplus-inherit.cc: New file.
	* gdb.compile/compile-cplus-inherit.exp: New file.
	* gdb.compile/compile-cplus-member.cc: New file.
	* gdb.compile/compile-cplus-member.exp: New file.
	* gdb.compile/compile-cplus-method.cc: New file.
	* gdb.compile/compile-cplus-method.exp: New file.
	* gdb.compile/compile-cplus-mod.c: "New" file.
	* gdb.compile/compile-cplus-namespace.cc: New file.
	* gdb.compile/compile-cplus-namespace.exp: New file.
	* gdb.compile/compile-cplus-nested.cc: New file.
	* gdb.compile/compile-cplus-nested.exp: New file.
	* gdb.compile/compile-cplus-print.c: "New" file.
	* gdb.compile/compile-cplus-print.exp: "New" file.
	* gdb.compile/compile-cplus-virtual.cc: New file.
	* gdb.compile/compile-cplus-virtual.exp: New file.
	* gdb.compile/compile-cplus.c: "New" file.
	* gdb.compile/compile-cplus.exp: "New" file.
	* lib/compile-support.exp: New file.

doc/ChangeLog:

	* gdb.texinfo (Compiling and injecting code in GDB): Document
	set/show "compile-oracle" and "compile-cplus-types" commands.
2018-08-29 15:12:24 -07:00
Hafiz Abid Qadeer 9d24df82ec Add support for new target 'csky'.
2018-08-28  Jiangshuai Li  <jiangshuai_li@c-sky.com>
	    Hafiz Abid Qadeer  <abidh@codesourcery.com>
	    Don Breazeal  <donb@codesourcery.com>

	* csky-linux-tdep.c: New file.
	* csky-tdep.c: Likewise.
	* csky-tdep.h: Likewise.
	* Makefile.in (ALL_TARGET_OBS): Add csky-linux-tdep.o and
	csky-tdep.o.
	(HFILES_NO_SRCDIR): Add csky-tdep.h.
	(ALLDEPFILES): Add csky-linux-tdep.c and csky-tdep.c
	* configure.tgt: Add csky support.
2018-08-28 12:08:11 +01:00
Keith Seitz 18cdc6d8f8 Add a C++ wrapper for GCC C plug-in
This patch introduces a new class which wraps the GCC C compile plug-in.
It is a little unfortunate that this all happened in between the time that
GCC moved to C++ and GDB moved to C++, leaving us with an ABI promise to
support a C-like interface.  The hope is to isolate GDB from some of this
should it change in the future.

Broadly, what this does is replace calls like:

  C_CTX (context)->c_ops->operation (C_CTX (context), ...);

with calls that now look like:

  context->c_plugin->operation (...);

This API will be further refined in following patches when struct
compile_instance/compile_c_instance are changed into classes.

gdb/ChangeLog:
        * Makefile.in (HFILES_NO_SRCDIR): Add compile/gcc-c-plugin.h.
        * compile/compile-c-types.c: Define GCC_METHODN macros and include
        gcc-c-fe.def to define C plugin.
        (delete_instance): Delete `c_plugin'.
        (new_compile_instance): Initialize `c_plugin'.
        * compile/compile-c.h: Include gcc_c_plugin.h.
        (struct compile_c_instance) <c_plugin>: New member.
        * gcc-c-plugin.h: New file.
        Update all callers with API change.
2018-08-10 11:14:25 -07:00
Keith Seitz b7dc48b4a8 Move C-related declarations to compile-c.h
This patch simply moves a bunch of C language-related declarations from
the various compile header files into a new C-specific header, compile-c.h.

gdb/ChangeLog:
        * Makefile.in (SUBDIR_GCC_COMPILE_SRCS): Move header files ...
        (HFILES_NO_SRCDIR): ... to here.
        Add compile-internal.h and compile-c.h.
        * compile/compile-c-support.c: Include compile-c.h.
        * compile/compile-c-symbols.c: Include compile-c.h.
        (generate_c_for_variable_locations): Update comment.
        * compile/compile-c-types.c: Include compile-c.h.
        * compile/compile-c.h: New file -- moved C language declarations
        from other files here.
        * compile/compile-internal.h: Do not include hashtab.h or
        common/enum-flags.h.
        (gcc_qualifiers_flags, struct compile_c_instance, C_CTX)
        (gcc_convert_symbol, gcc_symbol_address)
        (generate_c_for_variable_locations, c_get_mode_for_size)
        (c_get_range_decl_name): Definitions moved to compile-c.h.
        * compile/compile-loc2c.c: Include compile-c.h.
2018-08-10 11:14:25 -07:00
Jim Wilson 52a187f8e7 RISC-V: Add configure support for riscv*-linux*.
This adds the target and native configure support, and the NEWS entries for
the new target and native configurations.

	gdb/
	* Makefile.in (ALL_TARGET_OBS): Add riscv-linux-tdep.c.
	(ALLDEPFILES): Add riscv-linux-nat.c, and riscv-linux-tdep.c.
	* NEWS: Mention new GNU/Linux RISC-V target.
	* configure.host: Add riscv*-*-linux*.
	* configure.nat: Add riscv*.
	* configure.tgt: Add riscv*-*-linux*.
2018-08-09 13:37:45 -07:00
Tom Tromey 9c61296405 Allow CPPFLAGS to be set on the make command line
While looking into PR build/8751 (which seems to be fixed), I noticed
that it's not possible to change CPPFLAGS for gdb on the "make"
command line.  It's reasonable to want to do this sometimes, and I
think this patch should suffice.

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

	* Makefile.in (CPPFLAGS): New variable.
	(INTERNAL_CPPFLAGS): Use it.
2018-08-07 16:39:13 -06:00
Simon Marchi 87d6a7aa93 Add DWARF index cache
New in v3:

- Remove things related to the dwarf-5 format.
- Fix compilation on mingw (scoped_mmap.c).

GDB can generate indexes for DWARF debug information, which, when
integrated in the original binary, can speed up loading object files.
This can be done using the gdb-add-index script or directly by the
linker itself.  However, not many people know about this.  And even
among those who do, because it requires additional steps, I don't know a
lot of people who actually go through that trouble.

To help make using the DWARF index more transparent, this patch
introduces a DWARF index cache.  When enabled, loading an index-less
binary in GDB will automatically save an index file in ~/.cache/gdb.
When loading that same object file again, the index file will be looked
up and used to load the DWARF index.  You therefore get the benefit of
the DWARF index without having to do additional manual steps or
modifying your build system.  When an index section is already present
in the file, GDB will prefer that one over looking up the cache.

When doing my edit-compile-debug cycle, I often debug multiple times the
same build, so the cache helps reducing the load time of the debug
sessions after the first one.

- The saved index file is exactly the same as the output of the "save
  gdb-index" command.  It is therefore the exact same content that would
  be found in the .gdb_index or .debug_names section.  We just leave it
  as a standalone file instead of merging it in the binary.

- The cache is just a directory with files named after the object
  file's build-id.  It is not possible to save/load the index for an
  object file without build-id in the cache.

- The cache uses the gdb index format.  The problem with the dwarf-5
  format is that we can generate an addendum to the .debug_str section
  that you're supposed to integrate to the original binary.  This
  complicates a little bit loading the data from the cached index files,
  so I would leave this for later.

- The size taken up by ~/.cache/gdb is not limited.  I was thinking we
  could add configurable limit (like ccache does), but that would come
  after.  Also, maybe a command to flush the cache.

- The cache is disabled by default.  I think once it's been out there
  and tested for a while, it could be turned on by default, so that
  everybody can enjoy it.

- The code was made to follow the XDG specification: if the
  XDG_CACHE_HOME environment variable, it is used, otherwise it falls
  back to ~/.cache/gdb.  It is possible to change it using "set
  index-cache directory".  On other OSes than GNU/Linux, ~/.cache may
  not be the best place to put such data.  On macOS it should probably
  default to ~/Library/Caches/...  On Windows, %LocalAppData%/...  I
  don't intend to do this part, but further patches are welcome.

- I think that we need to be careful that multiple instances of GDB
  don't interfere with each other (not far fetched at all if you run GDB
  in some automated script) and the cache is always coherent (either the
  file is not found, or it is found and entirely valid).  Writing the
  file directly to its final location seems like a recipe for failure.
  One GDB could read a file in the index while it is being written by
  another GDB.  To mitigate this, I made write_psymtabs_to_index write
  to temporary files and rename them once it's done.  Two GDB instances
  writing the index for the same file should not step on each other's
  toes (the last file to be renamed will stay).  A GDB looking up a file
  will only see a complete file or no file.  Also, if GDB crashes while
  generating the index file, it will leave a work-in-progress file, but
  it won't be picked up by other instances looking up in the cache.

gdb/ChangeLog:

	* common/pathstuff.h (get_standard_cache_dir): New.
	* common/pathstuff.c (get_standard_cache_dir): New.
	* build-id.h (build_id_to_string): New.
	* dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX,
	DEBUG_STR_SUFFIX): Move to here.
	* dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX,
	DEBUG_STR_SUFFIX): Move from there.
	(write_psymtabs_to_index): Make non-static, add basename
	parameter.  Write to temporary files, rename when done.
	(save_gdb_index_command): Adjust call to
	write_psymtabs_to_index.
	* dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New
	field.
	* dwarf2read.c (dwz_file) <index_cache_res>: New field.
	(get_gdb_index_contents_from_cache): New.
	(get_gdb_index_contents_from_cache_dwz): New.
	(dwarf2_initialize_objfile): Read index from cache.
	(dwarf2_build_psymtabs): Save to index.
	* dwarf-index-cache.h: New file.
	* dwarf-index-cache.c: New file.
	* dwarf-index-write.h: New file.

gdb/testsuite/ChangeLog:

	* boards/index-cache-gdb.exp: New file.
	* gdb.dwarf2/index-cache.exp: New file.
	* gdb.dwarf2/index-cache.c: New file.
	* gdb.base/maint.exp: Check if we are using the index cache.
2018-08-07 18:14:20 -04:00
Simon Marchi 5c831bb1eb Introduce mmap_file function
New in v2:

- As Tom pointed out, we don't need to keep the fd around after
  mmapping.  This simplifies things quite a bit, since we don't need a
  new class.  It's now just a function that returns a scoped_mmap.

We already have scoped_mmap, which is a thin RAII layer over mmap.  If
one simply wants to mmap an entire file for reading, it takes a bit of
boilerplate.  This patch introduces the mmap_file function to make this
easier.

gdb/ChangeLog:

	* Makefile.in (COMMON_SFILES): Add common/scoped_mmap.c.
	* common/scoped_mmap.c: New file.
	* common/scoped_mmap.h (destroy): New method.
	(~scoped_mmap, reset): Use destroy.
	(scoped_mmap): New move constructor.
	(mmap_file): New declaration.
	* unittests/scoped_mmap-selftests.c (test_normal,
	test_invalid_filename, run_tests): New functions.
	(_initialize_scoped_mmap_selftests): Register selftest.
2018-08-07 18:10:29 -04:00
Tom Tromey 0baae8dbd3 Introduce buildsym-legacy.h
This introduces a new header, buildsym-legacy.h, and changes all the
symbol readers to use it.  The idea is to put the function-based
interface, that relies on the buildsym_compunit global, into a
separate header.  Then when a symbol reader is updated to use the new
interface, it can simply not include buildsym-legacy.h, so it's easy
to be sure that the new API is used everywhere.

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

	* xcoffread.c: Include buildsym-legacy.h.
	* windows-nat.c: Include buildsym-legacy.h.
	* stabsread.c: Include buildsym-legacy.h.
	* mdebugread.c: Include buildsym-legacy.h.
	* buildsym-legacy.h: New file.
	* buildsym-legacy.c: New file, from buildsym.c.
	* go32-nat.c: Include buildsym-legacy.h.
	* dwarf2read.c: Include buildsym-legacy.h.
	* dbxread.c: Include buildsym-legacy.h.
	* cp-namespace.c: Include buildsym-legacy.h.
	* coffread.c: Include buildsym-legacy.h.
	* buildsym.h: Move some contents to buildsym-legacy.h.
	* buildsym.c: Include buildsym-legacy.h.  Move many functions to
	buildsym-legacy.c.
	* Makefile.in (HFILES_NO_SRCDIR): Add buildsym-legacy.h.
2018-07-20 09:42:53 -06:00
Tom Tromey 056dec39ed Remove --disable-gdbcli
I think it doesn't really make sense to allow building gdb without the
CLI.  Perhaps at one time this was a goal, but libgdb is long gone and
the CLI is intrinsic to gdb.

So, this patch removes the implementation of this configure option.
It is still recognized (this is autoconf's default), but does nothing.

This simplifies configure.ac and Makefile.in a bit.

Tested by rebuilding.

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

	* configure.ac: Remove --disable-gdbcli.
	* configure: Rebuild.
	* Makefile.in (SUBDIR_CLI_DEPS, SUBDIR_CLI_LDFLAGS)
	(SUBDIR_CLI_CFLAGS): Remove.
	(SFILES): Use SUBDIR_CLI_SRCS.
	(COMMON_OBS): Use SUBDIR_CLI_OBS.
2018-07-17 09:54:17 -06:00
Philippe Waroquiers bc7b042bcb Add a self-test for cli-utils.c
tests added for:
* number_or_range_parser
  In particular, it tests the cur_tok when parsing is finished.

* parse_flags

* parse_flags_qcs

gdb/ChangeLog
2018-07-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/cli-utils-selftests.c
	* unittests/cli-utils-selftests.c: New file.
2018-07-12 23:10:56 +02:00
Sergio Durigan Junior c7ab0aef11 Implement IPv6 support for GDB/gdbserver
This patch implements IPv6 support for both GDB and gdbserver.  Based
on my research, it is the fourth attempt to do that since 2006.  Since
I used ideas from all of the previous patches, I also added their
authors's names on the ChangeLogs as a way to recognize their
efforts.  For reference sake, you can find the previous attempts at:

  https://sourceware.org/ml/gdb-patches/2006-09/msg00192.html

  https://sourceware.org/ml/gdb-patches/2014-02/msg00248.html

  https://sourceware.org/ml/gdb-patches/2016-02/msg00226.html

The basic idea behind the patch is to start using the new
'getaddrinfo'/'getnameinfo' calls, which are responsible for
translating names and addresses in a protocol-independent way.  This
means that if we ever have a new version of the IP protocol, we won't
need to change the code again (or, at least, won't have to change the
majority of the code).

The function 'getaddrinfo' returns a linked list of possible addresses
to connect to.  Dealing with multiple addresses proved to be a hard
task with the current TCP auto-retry mechanism implemented on
ser-tcp:net_open.  For example, when gdbserver listened only on an
IPv4 socket:

  $ ./gdbserver --once 127.0.0.1:1234 ./a.out

and GDB was instructed to try to connect to both IPv6 and IPv4
sockets:

  $ ./gdb -ex 'target extended-remote localhost:1234' ./a.out

the user would notice a somewhat big delay before GDB was able to
connect to the IPv4 socket.  This happened because GDB was trying to
connect to the IPv6 socket first, and had to wait until the connection
timed out before it tried to connect to the IPv4 socket.

For that reason, I had to rewrite the main loop and implement a new
method for handling multiple connections.  After some discussion,
Pedro and I agreed on the following algorithm:

  1) For each entry returned by 'getaddrinfo', we try to open a socket
  and connect to it.

  2.a) If we have a successful 'connect', we just use that connection.

  2.b) If we don't have a successfull 'connect', but if we've got a
  ECONNREFUSED (meaning the the connection was refused), we keep track
  of this fact by using a flag.

  2.c) If we don't have a successfull 'connect', but if we've got a
  EINPROGRESS (meaning that the connection is in progress), we perform
  a 'select' call on the socket until we have a result (either a
  successful connection, or an error on the socket).

  3) If tcp_auto_retry is true, and we haven't gotten a successful
  connection, and at least one of our attempts failed with
  ECONNREFUSED, then we wait a little bit (i.e., call
  'wait_for_connect'), check to see if there was a
  timeout/interruption (in which case we bail out), and then go back
  to (1).

After multiple tests, I was able to connect without delay on the
scenario described above, and was also able to connect in all other
types of scenarios.

I also implemented some hostname parsing functions (along with their
corresponding unit tests) which are used to help GDB and gdbserver to
parse hostname strings provided by the user.  These new functions are
living inside common/netstuff.[ch].  I've had to do that since IPv6
introduces a new URL scheme, which defines that square brackets can be
used to enclose the host part and differentiate it from the
port (e.g., "[::1]:1234" means "host ::1, port 1234").  I spent some
time thinking about a reasonable way to interpret what the user wants,
and I came up with the following:

  - If the user has provided a prefix that doesn't specify the protocol
    version (i.e., "tcp:" or "udp:"), or if the user has not provided
    any prefix, don't make any assumptions (i.e., assume AF_UNSPEC when
    dealing with 'getaddrinfo') *unless* the host starts with "[" (in
    which case, assume it's an IPv6 host).

  - If the user has provided a prefix that does specify the protocol
    version (i.e., "tcp4:", "tcp6:", "udp4:" or "udp6:"), then respect
    that.

This method doesn't follow strictly what RFC 2732 proposes (that
literal IPv6 addresses should be provided enclosed in "[" and "]")
because IPv6 addresses still can be provided without square brackets
in our case, but since we have prefixes to specify protocol versions I
think this is not an issue.

Another thing worth mentioning is the new 'GDB_TEST_SOCKETHOST'
testcase parameter, which makes it possible to specify the
hostname (without the port) to be used when testing GDB and
gdbserver.  For example, to run IPv6 tests:

  $ make check-gdb RUNTESTFLAGS='GDB_TEST_SOCKETHOST=tcp6:[::1]'

Or, to run IPv4 tests:

  $ make check-gdb RUNTESTFLAGS='GDB_TEST_SOCKETHOST=tcp4:127.0.0.1'

This required a few changes on the gdbserver-base.exp, and also a
minimal adjustment on gdb.server/run-without-local-binary.exp.

Finally, I've implemented a new testcase,
gdb.server/server-connect.exp, which is supposed to run on the native
host and perform various "smoke tests" using different connection
methods.

This patch has been regression-tested on BuildBot and locally, and
also built using a x86_64-w64-mingw32 GCC, and no problems were found.

gdb/ChangeLog:
2018-07-11  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Paul Fertser  <fercerpav@gmail.com>
	    Tsutomu Seki  <sekiriki@gmail.com>
	    Pedro Alves  <palves@redhat.com>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	'unittests/parse-connection-spec-selftests.c'.
	(COMMON_SFILES): Add 'common/netstuff.c'.
	(HFILES_NO_SRCDIR): Add 'common/netstuff.h'.
	* NEWS (Changes since GDB 8.2): Mention IPv6 support.
	* common/netstuff.c: New file.
	* common/netstuff.h: New file.
	* ser-tcp.c: Include 'netstuff.h' and 'wspiapi.h'.
	(wait_for_connect): Update comment.  New parameter
	'gdb::optional<int> sock' instead of 'struct serial *scb'.
	Use 'sock' directly instead of 'scb->fd'.
	(try_connect): New function, with code from 'net_open'.
	(net_open): Rewrite main loop to deal with multiple
	sockets/addresses.  Handle IPv6-style hostnames; implement
	support for IPv6 connections.
	* unittests/parse-connection-spec-selftests.c: New file.

gdb/gdbserver/ChangeLog:
2018-07-11  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Paul Fertser  <fercerpav@gmail.com>
	    Tsutomu Seki  <sekiriki@gmail.com>

	* Makefile.in (SFILES): Add '$(srcdir)/common/netstuff.c'.
	(OBS): Add 'common/netstuff.o'.
	(GDBREPLAY_OBS): Likewise.
	* gdbreplay.c: Include 'wspiapi.h' and 'netstuff.h'.
	(remote_open): Implement support for IPv6
	connections.
	* remote-utils.c: Include 'netstuff.h', 'filestuff.h'
	and 'wspiapi.h'.
	(handle_accept_event): Accept connections from IPv6 sources.
	(remote_prepare): Handle IPv6-style hostnames; implement
	support for IPv6 connections.
	(remote_open): Implement support for printing connections from
	IPv6 sources.

gdb/testsuite/ChangeLog:
2018-07-11  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Paul Fertser  <fercerpav@gmail.com>
	    Tsutomu Seki  <sekiriki@gmail.com>

	* README (Testsuite Parameters): Mention new 'GDB_TEST_SOCKETHOST'
	parameter.
	* boards/native-extended-gdbserver.exp: Do not set 'sockethost'
	by default.
	* boards/native-gdbserver.exp: Likewise.
	* gdb.server/run-without-local-binary.exp: Improve regexp used
	for detecting when a remote debugging connection succeeds.
	* gdb.server/server-connect.exp: New file.
	* lib/gdbserver-support.exp (gdbserver_default_get_comm_port):
	Do not prefix the port number with ":".
	(gdbserver_start): New global GDB_TEST_SOCKETHOST.  Implement
	support for detecting and using it.  Add '$debughost_gdbserver'
	to the list of arguments used to start gdbserver.  Handle case
	when gdbserver cannot resolve a network name.

gdb/doc/ChangeLog:
2018-07-11  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Paul Fertser  <fercerpav@gmail.com>
	    Tsutomu Seki  <sekiriki@gmail.com>

	* gdb.texinfo (Remote Connection Commands): Add explanation
	about new IPv6 support.  Add new connection prefixes.
2018-07-11 19:41:31 -04:00
Tom Tromey 8fd32c1ce6 Don't mention XM_CDEPS or NAT_CLIBS
Neither XM_CDEPS nor NAT_CLIBS are defined anywhere, so remove the
uses.

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

	* Makefile.in (CDEPS): Don't mention XM_CDEPS.
	(CLIBS): Don't mention NAT_CLIBS.
2018-07-09 08:03:49 -06:00
Tom Tromey 31278b5193 Remove ADD_FILES and ADD_DEPS from Makefile.in
Nothing defines XM_ADD_FILES, TM_ADD_FILES, or NAT_ADD_FILES any more,
so consequently ADD_FILES and ADD_DEPS are no longer needed.  So, this
removes them.

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

	* Makefile.in (ADD_FILES, ADD_DEPS): Remove.
	(LIBGDB_OBS, clean mostlyclean): Update.
	(gdb$(EXEEXT), insight$(EXEEXT)): Update.
2018-07-09 08:03:49 -06:00
Tom Tromey e5fd1493fd Minimize yacc and lex output
This minimizes the "make" output from the yacc and lex rules,
following the same technique as the rest of the Makefile.

The lex rule had a special case to deal with the situation where flex
is not available.  I don't think this is needed, so I removed it.  If
flex is truly unavailable, the person building gdb can simply "touch"
the output file.

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

	* Makefile.in (%.c: %.y): Use ECHO_YACC.
	(%.c: %.l): Use ECHO_LEX.  Just fail if flex not available.
	* silent-rules.mk (ECHO_YACC, ECHO_LEX): New variables.
2018-07-09 08:03:49 -06:00
Tom Tromey 981e0c0c1a Fix exec.c handling in Makefile
exec.c ws handled specially in COMMON_OBS, but there doesn't seem to
be a reason for this.  This changes the Makefile to treat exec.c as an
ordinary source file.

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

	* Makefile.in (ALLDEPFILES): Remove exec.c.
	(COMMON_OBS): Remove exec.o.
	(COMMON_SFILES): Add exec.c.
2018-07-09 08:03:49 -06:00
Tom Tromey 14ccceb2e2 Remove lint support
I don't think anyone uses lint any more, so this removes the support
for it from the Makefile.

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

	* Makefile.in (LINT, LINTFLAGS, LINTFILES, lint): Remove.
2018-07-09 08:03:49 -06:00
Tom Tromey 5d3c3a68c3 Use a stamp file for version.c
This introduces a stamp file for version.c, preventing unnecessary
version.o rebuilds.

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

	* Makefile.in (clean mostlyclean): Remove stamp-version.
	(version.c): Depend on stamp-version.
	(stamp-version): New rule, from version.c rule.
2018-07-09 08:03:49 -06:00
Tom Tromey 1998086d54 Use a stamp file for init.c
This introduces a stamp file for init.c.  This prevents constant
rebuilds of init.o, by arranging for init.c to only be modified when
its contents change.  (FWIW this is a standard idiom in use by
Automake and by gdb itself for many years.)

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

	* Makefile.in (init.c): Depend on stamp-init.
	(stamp-init): New rule, from init.c rule.
	(clean mostlyclean): Remove stamp-init.
2018-07-09 08:03:49 -06:00
Tom Tromey 4c7549492b Simplify INIT_FILES
This simplifies the INIT_FILES variable.  COMMON_OBS includes
CONFIG_OBS and SUBDIR_GCC_COMPILE_OBS, so there's no need to reference
CONFIG_OBS or SUBDIR_GCC_COMPILE_SRCS there.  Once this is done, it it
clear that duplicates can't occur, so remove the duplicate-removing
code as well.

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

	* Makefile.in (INIT_FILES): Remove CONFIG_SRCS,
	SUBDIR_GCC_COMPILE_SRCS.
2018-07-09 08:03:49 -06:00
Tom Tromey 6497f1dd03 Remove some unused code from init.c build rule
The init.c build rule has a few sed expressions that aren't necessary
any more.  This removes them.

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

	* Makefile.in (init.c): Remove some unused sed rules.
2018-07-09 08:03:49 -06:00
Tom Tromey 97a34db942 Remove TSOBS from gdb/Makefile.in
The TSOBS variable doesn't seem to serve a useful purpose in
gdb/Makefile.in, so remove it.

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

	* Makefile.in (TSOBS): Remove.
	(INIT_FILES): Update.
	(LIBGDB_OBS): Update.
	(COMMON_SFILES): Add inflow.c.
	(SFILES): Remove inflow.c.
2018-07-09 08:03:48 -06:00
Tom Tromey 44cee4fdf4 Add --enable-codesign to gdb's configure
macOS requires that the gdb executable be signed in order to be able
to successfully use ptrace.  This must be done after each link.

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

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

	* NEWS: Mention --enable-codesign.
	* silent-rules.mk (ECHO_SIGN): New variable.
	* configure.ac: Add --enable-codesign.
	* configure: Rebuild.
	* Makefile.in (CODESIGN, CODESIGN_CERT): New variables.
	(gdb$(EXEEXT)): Optionally invoke codesign.
2018-06-28 15:13:43 -06:00
Simon Marchi 141ec9f67f Copy gdb-gdb.py to build dir
I have thought for a long time how nice it would be to have cool pretty
printers for GDB's internal types.  Well, turns out there are few
already in gdb-gdb.py!  Unfortunately, if you build GDB outside of the
source directory, that file never gets loaded.  top-gdb will look for a
file called

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

but that file is in the source directory at

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

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

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

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

gdb/ChangeLog:

	* gdb-gdb.py: Move to...
	* gdb-gdb.py.in: ... here.
	* configure.ac (AC_CONFIG_FILES): Add gdb-gdb.py.
	* Makefile.in (all): Add gdb-gdb.gdb and gdb-gdb.py as
	dependencies.
	(distclean): Remove gdb-gdb.py when cleaning.
	(gdb-gdb.py, gdb-gdb.gdb): New rules.
	* configure: Re-generate.
2018-06-27 14:32:02 -04:00
Simon Marchi baf00c2d75 Add configure.nat as a dependency of config.status
After pulling Alan's change that added aarch64-sve-linux-ptrace.o to
configure.nat, I got an undefined reference to aarch64_sve_get_vq when
doing a "make clean && make".  It turns out that re-running configure
(./config.status --recheck) was needed to re-generate the Makefile with
aarch64-sve-linux-ptrace.o included in the object list.  Putting
configure.nat in the dependencies of config.status would make sure that
when we modify configure.nat, the configure script is re-ran.  I think
it also makes sense because configure.tgt and configure.host are also
there.

gdb/ChangeLog:

	* Makefile.in (config.status): Add configure.nat as a
	dependency.
2018-06-04 10:40:27 -04:00
Alan Hayward 122394f147 Function for reading the Aarch64 SVE vector length
Returns 0 for systems without SVE support.

Note the defines taken from Linux kernel headers
in aarch64-sve-linux-ptrace.h.

gdb/
	* Makefile.in: Add new header.
	* gdb/arch/aarch64.h (sve_vg_from_vl): New macro.
	(sve_vl_from_vg): Likewise.
	(sve_vq_from_vl): Likewise.
	(sve_vl_from_vq): Likewise.
	(sve_vq_from_vg): Likewise.
	(sve_vg_from_vq): Likewise.
	* configure.nat: Add new c file.
	* nat/aarch64-sve-linux-ptrace.c: New file.
	* nat/aarch64-sve-linux-ptrace.h: New file.

gdbserver/
	* configure.srv: Add new c/h file.
2018-05-31 14:36:48 +01:00
Simon Marchi fdbe37e35f Add or1k target to --enable-targets=all
The or1k-tdep.o object is missing from the ALL_TARGET_OBS, which means
it's not currently included in an --enable-targets=all build.

gdb/ChangeLog:

	* Makefile.in (ALL_TARGET_OBS): Add or1k-tdep.o.
2018-05-30 12:04:35 -04:00
Tom Tromey b8283aea9e Remove last reference to REMOTE_OBS
REMOTE_OBS was removed from Makefile.in in
18ca73470a, but one reference remains.
This patch removes the lingerer.

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

	* Makefile.in (DEPFILES): Don't reference REMOTE_OBS.
2018-05-27 14:54:08 -06: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
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
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
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
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
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
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
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 cd4fb1b2ff Move DWARF index-related things to a separate file
I want to add a DWARF index-related feature (automatically produce index
files when loading objfiles in GDB), but I don't want to add many
hundred lines to the already too big dwarf2read.c.  I thought it would
be a logical split to move everything related to the DWARF index to its
own file.

I first tried to move everything that reads and writes DWARF indices to
a separate file, but found that the "read" part is a little bit
entangled with the rest of dwarf2read.c, so the line is hard to draw
about where to split.  The write part is quite isolated though, so I
moved this part to a new file, dwarf-index-write.c.  Some things are
necessary to both reading and writing indices, so I placed them in
dwarf-index-common.{c,h}.  The idea would be to have a
dwarf-index-read.c eventually that would use it too (for now that code
is still in dwarf2read.c).

This required moving some things to a new dwarf2read.h header, so they
can be read by the code that writes the index.

The patch is big in number of lines, but it's all existing code being
moved around.  The only changes are that some functions are not static
anymore, a declaration is added in a .h file, and therefore the comment
is moved there.

I built-tested it with a little and big endian target.

This patch is also available on the users/simark/split-dwarf2read
branch.

gdb/ChangeLog:

	* Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and
	dwarf-index-write.c
	(HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h.
	* dwarf-index-common.c: New file.
	* dwarf-index-common.h: New file.
	* dwarf-index-write.c: New file.
	* dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h.
	(struct dwarf2_section_info): Move from here.
	(dwarf2_section_info_def): Likewise.
	(DEF_VEC_O (dwarf2_section_info_def)): Likewise.
	(offset_type): Likewise.
	(DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise.
	(DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise.
	(DW2_GDB_INDEX_CU_SET_VALUE): Likewise.
	(byte_swap): Likewise.
	(MAYBE_SWAP): Likewise.
	(dwarf2_per_cu_ptr): Likewise.
	(DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise.
	(struct tu_stats): Likewise.
	(struct dwarf2_per_objfile): Likewise.
	(struct dwarf2_per_cu_data): Likewise.
	(struct signatured_type): Likewise.
	(sig_type_ptr): Likewise.
	(DEF_VEC_P (sig_type_ptr)): Likewise.
	(INDEX4_SUFFIX): Likewise.
	(INDEX5_SUFFIX): Likewise.
	(DEBUG_STR_SUFFIX): Likewise.
	(dwarf2_read_section): Make non-static.
	(mapped_index_string_hash): Move from here.
	(dwarf5_djb_hash): Likewise.
	(file_write): Likewise.
	(class data_buf): Likewise.
	(struct symtab_index_entry): Likewise.
	(struct mapped_symtab): Likewise.
	(find_slot): Likewise.
	(hash_expand): Likewise.
	(add_index_entry): Likewise.
	(uniquify_cu_indices): Likewise.
	(class c_str_view): Likewise.
	(class c_str_view_hasher): Likewise.
	(class vector_hasher): Likewise.
	(write_hash_table): Likewise.
	(psym_index_map): Likewise.
	(struct addrmap_index_data): Likewise.
	(add_address_entry): Likewise.
	(add_address_entry_worker): Likewise.
	(write_address_map): Likewise.
	(symbol_kind): Likewise.
	(write_psymbols): Likewise.
	(struct signatured_type_index_data): Likewise.
	(write_one_signatured_type): Likewise.
	(recursively_count_psymbols): Likewise.
	(recursively_write_psymbols): Likewise.
	(class debug_names): Likewise.
	(check_dwarf64_offsets): Likewise.
	(psyms_seen_size): Likewise.
	(write_gdbindex): Likewise.
	(write_debug_names): Likewise.
	(assert_file_size): Likewise.
	(write_psymtabs_to_index): Likewise.
	(save_gdb_index_command): Likewise.
	(_initialize_dwarf2_read): Don't register the "save gdb-index"
	command.
	* dwarf2read.h: New file.
2018-03-27 10:07:47 -04:00
Simon Marchi 62c222b6d9 Make parse_static_tracepoint_marker_definition work with multiple static tracepoint definitions
Since I modify the parse_static_tracepoint_marker_definition function in
the next patch, I wanted to write a unit test for it.  Doing so showed
that it doesn't handle multiple consecutive static tracepoint
definitions separated by commas.  However, the RSP documentation [1]
states that servers may return multiple definitions, like:

  1234:6d61726b657231:6578747261207374756666,abba:6d61726b657232:

The problem is that the function uses strlen to compute the length of
the last field (the extra field).  If there are additional definitions
in addition to the one we are currently parsing, the returned length
will include those definitions, and we'll try to hex-decode past the
extra field.

This patch changes parse_static_tracepoint_marker_definition to consider
the case where the current definition is followed by a comma and more
definitions.  It also adds the unit test that found the issue in the
first place.

I don't think this causes any backwards compatibility issues, because
the previous code only handled single static tracepoint definitions, and
the new code handles that correctly.

gdb/ChangeLog:

	* tracepoint.c (parse_static_tracepoint_marker_definition):
	Consider case where the definition is followed by more
	definitions.
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	tracepoint-selftests.c.
	* unittests/tracepoint-selftests.c: New.

[1] https://sourceware.org/gdb/onlinedocs/gdb/Tracepoint-Packets.html#qTfSTM
2018-03-22 00:26:39 -04:00