public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4 00/14] let gdb reuse gcc's C compiler
@ 2014-11-23 19:27 Jan Kratochvil
  2014-11-23 19:27 ` [PATCH v4 02/14] add gcc/gdb interface files Jan Kratochvil
                   ` (15 more replies)
  0 siblings, 16 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:27 UTC (permalink / raw)
  To: gdb-patches

Hi,

https://github.com/tromey/gdb.git
submit/compile

This is version 4 of the patch to let gdb reuse gcc's C compiler.

Version 3 is here:

    https://sourceware.org/ml/gdb-patches/2014-11/msg00005.html

There is now also a description of this project at:
    https://sourceware.org/gdb/wiki/GCCCompileAndExecute

Current GCC trunk (future 5.0) has now the libcc1.so support.
This makes it relatively easy to test this patchset.

New in version 4:
 * Testcases have been moved all into new directory gdb.compile/ .
 * doc updates.
 * Fix of GDB_MMAP_* symbols for host-independent linux-tdep.c.
 * Minor fixes.

Built and regtested on x86-64, x86_64-m32 and i686 Fedora 21pre in linux-nat
and gdbserver modes.

Going to check it in in a week as v3 seems to be reviewed now.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 03/14] add some missing ops to DWARF assembler
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
  2014-11-23 19:27 ` [PATCH v4 02/14] add gcc/gdb interface files Jan Kratochvil
@ 2014-11-23 19:27 ` Jan Kratochvil
  2014-11-23 19:27 ` [PATCH v4 01/14] introduce ui_file_write_for_put Jan Kratochvil
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:27 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

This changes the DWARF assembler to allow comments in a location
expression, and also adds support for a few new opcodes I needed.

2014-10-07  Tom Tromey  <tromey@redhat.com>

	* lib/dwarf.exp (_location): Ignore blank lines.  Allow comments.
	Handle DW_OP_pick, DW_OP_skip, DW_OP_bra.
---
 gdb/testsuite/ChangeLog     |    5 +++++
 gdb/testsuite/lib/dwarf.exp |    9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 6bbd72b..7567785 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-10-07  Tom Tromey  <tromey@redhat.com>
+
+	* lib/dwarf.exp (_location): Ignore blank lines.  Allow comments.
+	Handle DW_OP_pick, DW_OP_skip, DW_OP_bra.
+
 2014-11-22  Yao Qi  <yao@codesourcery.com>
 
 	* gdb.trace/entry-values.c: Remove asms.
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 778ad1c..72153ec 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -803,7 +803,8 @@ namespace eval Dwarf {
 	variable _cu_offset_size
 
 	foreach line [split $body \n] {
-	    if {[lindex $line 0] == ""} {
+	    # Ignore blank lines, and allow embedded comments.
+	    if {[lindex $line 0] == "" || [regexp -- {^[ \t]*#} $line]} {
 		continue
 	    }
 	    set opcode [_map_name [lindex $line 0] _OP]
@@ -814,6 +815,7 @@ namespace eval Dwarf {
 		    _op .${_cu_addr_size}byte [lindex $line 1]
 		}
 
+		DW_OP_pick -
 		DW_OP_const1u -
 		DW_OP_const1s {
 		    _op .byte [lindex $line 1]
@@ -854,6 +856,11 @@ namespace eval Dwarf {
 		    _op .uleb128 [lindex $line 2]
 		}
 
+		DW_OP_skip -
+		DW_OP_bra {
+		    _op .2byte [lindex $line 1]
+		}
+
 		DW_OP_GNU_implicit_pointer {
 		    if {[llength $line] != 3} {
 			error "usage: DW_OP_GNU_implicit_pointer LABEL OFFSET"

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 04/14] add make_unqualified_type
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (2 preceding siblings ...)
  2014-11-23 19:27 ` [PATCH v4 01/14] introduce ui_file_write_for_put Jan Kratochvil
@ 2014-11-23 19:27 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 13/14] add s390_gcc_target_options Jan Kratochvil
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:27 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

There's seemingly no function to get the unqualified variant of a
type, so this patch adds one.  This new function will be used in the
final patch.

2014-10-07  Tom Tromey  <tromey@redhat.com>

	* gdbtypes.h (make_unqualified_type): Declare.
	* gdbtypes.c (make_unqualified_type): New function.
---
 gdb/ChangeLog  |    5 +++++
 gdb/gdbtypes.c |   13 +++++++++++++
 gdb/gdbtypes.h |    2 ++
 3 files changed, 20 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d6d2b49..15753eb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2014-10-07  Tom Tromey  <tromey@redhat.com>
 
+	* gdbtypes.h (make_unqualified_type): Declare.
+	* gdbtypes.c (make_unqualified_type): New function.
+
+2014-10-07  Tom Tromey  <tromey@redhat.com>
+
 	* ui-file.h (ui_file_write_for_put): Declare.
 	* ui-file.c (ui_file_write_for_put): New function.
 	* mi/mi-out.c (do_write): Remove.
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b921c64..d0f2a9b 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -703,6 +703,19 @@ make_restrict_type (struct type *type)
 			      NULL);
 }
 
+/* Make a type without const, volatile, or restrict.  */
+
+struct type *
+make_unqualified_type (struct type *type)
+{
+  return make_qualified_type (type,
+			      (TYPE_INSTANCE_FLAGS (type)
+			       & ~(TYPE_INSTANCE_FLAG_CONST
+				   | TYPE_INSTANCE_FLAG_VOLATILE
+				   | TYPE_INSTANCE_FLAG_RESTRICT)),
+			      NULL);
+}
+
 /* Replace the contents of ntype with the type *type.  This changes the
    contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
    the changes are propogated to all types in the TYPE_CHAIN.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 14a1f08..a29fb5f 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1632,6 +1632,8 @@ extern struct type *make_cv_type (int, int, struct type *, struct type **);
 
 extern struct type *make_restrict_type (struct type *);
 
+extern struct type *make_unqualified_type (struct type *);
+
 extern void replace_type (struct type *, struct type *);
 
 extern int address_space_name_to_int (struct gdbarch *, char *);

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 02/14] add gcc/gdb interface files
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
@ 2014-11-23 19:27 ` Jan Kratochvil
  2014-11-23 19:27 ` [PATCH v4 03/14] add some missing ops to DWARF assembler Jan Kratochvil
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:27 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

The gcc plugin is split into two parts.  One part is an ordinary gcc
plugin.  The other part is a shared library that is loaded by gdb.

This patch adds some files that define the interface exported by this
shared library to gdb.  These files also define the internal API by
which the gdb- and gcc-sides communicate.

These files will be kept in sync between gcc and gdb like much of
include/.

The exported API has been intentionally kept very simple.  In
particular only a single function is exported from the gdb-side
library; symbol visibility is used to hide everything else.  This
exported symbol is a function which is called to return a structure
holding function pointers that gdb then uses.  This structure is
versioned so that changes can be made without necessarily requiring a
simultaneous gdb upgrade.

Note that the C compiler API is broken out separately.  This lets us
extend it to other GCC front ends as desired.  We plan to investigate
C++ in the future.

2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Tom Tromey  <tromey@redhat.com>

	* gcc-c-fe.def: New file.
	* gcc-c-interface.h: New file.
	* gcc-interface.h: New file.
---
 include/ChangeLog         |    8 ++
 include/gcc-c-fe.def      |  197 ++++++++++++++++++++++++++++++++++++++++
 include/gcc-c-interface.h |  220 +++++++++++++++++++++++++++++++++++++++++++++
 include/gcc-interface.h   |  127 ++++++++++++++++++++++++++
 4 files changed, 552 insertions(+)
 create mode 100644 include/gcc-c-fe.def
 create mode 100644 include/gcc-c-interface.h
 create mode 100644 include/gcc-interface.h

diff --git a/include/ChangeLog b/include/ChangeLog
index 4c3d652..f7d0f4a 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,11 @@
+2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
+	    Jan Kratochvil  <jan.kratochvil@redhat.com>
+	    Tom Tromey  <tromey@redhat.com>
+
+	* gcc-c-fe.def: New file.
+	* gcc-c-interface.h: New file.
+	* gcc-interface.h: New file.
+
 2014-11-21  Shinichiro Hamaji  <shinichiro.hamaji@gmail.com>
 
 	* dwarf2.def (DW_AT_APPLE_optimized, DW_AT_APPLE_flags)
diff --git a/include/gcc-c-fe.def b/include/gcc-c-fe.def
new file mode 100644
index 0000000..19cb867
--- /dev/null
+++ b/include/gcc-c-fe.def
@@ -0,0 +1,197 @@
+/* Interface between GCC C FE and GDB  -*- c -*-
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+
+/* Create a new "decl" in GCC.  A decl is a declaration, basically a
+   kind of symbol.
+
+   NAME is the name of the new symbol.  SYM_KIND is the kind of
+   symbol being requested.  SYM_TYPE is the new symbol's C type;
+   except for labels, where this is not meaningful and should be
+   zero.  If SUBSTITUTION_NAME is not NULL, then a reference to this
+   decl in the source will later be substituted with a dereference
+   of a variable of the given name.  Otherwise, for symbols having
+   an address (e.g., functions), ADDRESS is the address.  FILENAME
+   and LINE_NUMBER refer to the symbol's source location.  If this
+   is not known, FILENAME can be NULL and LINE_NUMBER can be 0.
+   This function returns the new decl.  */
+
+GCC_METHOD7 (gcc_decl, build_decl,
+	     const char *,	      /* Argument NAME.  */
+	     enum gcc_c_symbol_kind,  /* Argument SYM_KIND.  */
+	     gcc_type,		      /* Argument SYM_TYPE.  */
+	     const char *,	      /* Argument SUBSTITUTION_NAME.  */
+	     gcc_address,	      /* Argument ADDRESS.  */
+	     const char *,	      /* Argument FILENAME.  */
+	     unsigned int)	      /* Argument LINE_NUMBER.  */
+
+/* Insert a GCC decl into the symbol table.  DECL is the decl to
+   insert.  IS_GLOBAL is true if this is an outermost binding, and
+   false if it is a possibly-shadowing binding.  */
+
+GCC_METHOD2 (int /* bool */, bind,
+	     gcc_decl,		   /* Argument DECL.  */
+	     int /* bool */)       /* Argument IS_GLOBAL.  */
+
+/* Insert a tagged type into the symbol table.  NAME is the tag name
+   of the type and TAGGED_TYPE is the type itself.  TAGGED_TYPE must
+   be either a struct, union, or enum type, as these are the only
+   types that have tags.  FILENAME and LINE_NUMBER refer to the type's
+   source location.  If this is not known, FILENAME can be NULL and
+   LINE_NUMBER can be 0.  */
+
+GCC_METHOD4 (int /* bool */, tagbind,
+	     const char *,	      /* Argument NAME.  */
+	     gcc_type,		      /* Argument TAGGED_TYPE.  */
+	     const char *,	      /* Argument FILENAME.  */
+	     unsigned int)	      /* Argument LINE_NUMBER.  */
+
+/* Return the type of a pointer to a given base type.  */
+
+GCC_METHOD1 (gcc_type, build_pointer_type,
+	     gcc_type)			/* Argument BASE_TYPE.  */
+
+/* Create a new 'struct' type.  Initially it has no fields.  */
+
+GCC_METHOD0 (gcc_type, build_record_type)
+
+/* Create a new 'union' type.  Initially it has no fields.  */
+
+GCC_METHOD0 (gcc_type, build_union_type)
+
+/* Add a field to a struct or union type.  FIELD_NAME is the field's
+   name.  FIELD_TYPE is the type of the field.  BITSIZE and BITPOS
+   indicate where in the struct the field occurs.  */
+
+GCC_METHOD5 (int /* bool */, build_add_field,
+	     gcc_type,			   /* Argument RECORD_OR_UNION_TYPE. */
+	     const char *,		   /* Argument FIELD_NAME.  */
+	     gcc_type,			   /* Argument FIELD_TYPE.  */
+	     unsigned long,		   /* Argument BITSIZE.  */
+	     unsigned long)		   /* Argument BITPOS.  */
+
+/* After all the fields have been added to a struct or union, the
+   struct or union type must be "finished".  This does some final
+   cleanups in GCC.  */
+
+GCC_METHOD2 (int /* bool */, finish_record_or_union,
+	     gcc_type,			   /* Argument RECORD_OR_UNION_TYPE. */
+	     unsigned long)		   /* Argument SIZE_IN_BYTES.  */
+
+/* Create a new 'enum' type.  The new type initially has no
+   associated constants.  */
+
+GCC_METHOD1 (gcc_type, build_enum_type,
+	     gcc_type)			    /* Argument UNDERLYING_INT_TYPE. */
+
+/* Add a new constant to an enum type.  NAME is the constant's
+   name and VALUE is its value.  */
+
+GCC_METHOD3 (int /* bool */, build_add_enum_constant,
+	     gcc_type,		       /* Argument ENUM_TYPE.  */
+	     const char *,	       /* Argument NAME.  */
+	     unsigned long)	       /* Argument VALUE.  */
+
+/* After all the constants have been added to an enum, the type must
+   be "finished".  This does some final cleanups in GCC.  */
+
+GCC_METHOD1 (int /* bool */, finish_enum_type,
+	     gcc_type)		       /* Argument ENUM_TYPE.  */
+
+/* Create a new function type.  RETURN_TYPE is the type returned by
+   the function, and ARGUMENT_TYPES is a vector, of length NARGS, of
+   the argument types.  IS_VARARGS is true if the function is
+   varargs.  */
+
+GCC_METHOD3 (gcc_type, build_function_type,
+	     gcc_type,			   /* Argument RETURN_TYPE.  */
+	     const struct gcc_type_array *, /* Argument ARGUMENT_TYPES.  */
+	     int /* bool */)               /* Argument IS_VARARGS.  */
+
+/* Return an integer type with the given properties.  */
+
+GCC_METHOD2 (gcc_type, int_type,
+	     int /* bool */,               /* Argument IS_UNSIGNED.  */
+	     unsigned long)                /* Argument SIZE_IN_BYTES.  */
+
+/* Return a floating point type with the given properties.  */
+
+GCC_METHOD1 (gcc_type, float_type,
+	     unsigned long)			/* Argument SIZE_IN_BYTES.  */
+
+/* Return the 'void' type.  */
+
+GCC_METHOD0 (gcc_type, void_type)
+
+/* Return the 'bool' type.  */
+
+GCC_METHOD0 (gcc_type, bool_type)
+
+/* Create a new array type.  If NUM_ELEMENTS is -1, then the array
+   is assumed to have an unknown length.  */
+
+GCC_METHOD2 (gcc_type, build_array_type,
+	     gcc_type,			  /* Argument ELEMENT_TYPE.  */
+	     int)			  /* Argument NUM_ELEMENTS.  */
+
+/* Create a new variably-sized array type.  UPPER_BOUND_NAME is the
+   name of a local variable that holds the upper bound of the array;
+   it is one less than the array size.  */
+
+GCC_METHOD2 (gcc_type, build_vla_array_type,
+	     gcc_type,			  /* Argument ELEMENT_TYPE.  */
+	     const char *)		  /* Argument UPPER_BOUND_NAME.  */
+
+/* Return a qualified variant of a given base type.  QUALIFIERS says
+   which qualifiers to use; it is composed of or'd together
+   constants from 'enum gcc_qualifiers'.  */
+
+GCC_METHOD2 (gcc_type, build_qualified_type,
+	     gcc_type,			      /* Argument UNQUALIFIED_TYPE.  */
+	     enum gcc_qualifiers)	      /* Argument QUALIFIERS.  */
+
+/* Build a complex type given its element type.  */
+
+GCC_METHOD1 (gcc_type, build_complex_type,
+	     gcc_type)			  /* Argument ELEMENT_TYPE.  */
+
+/* Build a vector type given its element type and number of
+   elements.  */
+
+GCC_METHOD2 (gcc_type, build_vector_type,
+	     gcc_type,			  /* Argument ELEMENT_TYPE.  */
+	     int)			  /* Argument NUM_ELEMENTS.  */
+
+/* Build a constant.  NAME is the constant's name and VALUE is its
+   value.  FILENAME and LINE_NUMBER refer to the type's source
+   location.  If this is not known, FILENAME can be NULL and
+   LINE_NUMBER can be 0.  */
+
+GCC_METHOD5 (int /* bool */, build_constant,
+	     gcc_type,		  /* Argument TYPE.  */
+	     const char *,	  /* Argument NAME.  */
+	     unsigned long,	  /* Argument VALUE.  */
+	     const char *,	  /* Argument FILENAME.  */
+	     unsigned int)	  /* Argument LINE_NUMBER.  */
+
+/* Emit an error and return an error type object.  */
+
+GCC_METHOD1 (gcc_type, error,
+	     const char *)		 /* Argument MESSAGE.  */
diff --git a/include/gcc-c-interface.h b/include/gcc-c-interface.h
new file mode 100644
index 0000000..25ef62f
--- /dev/null
+++ b/include/gcc-c-interface.h
@@ -0,0 +1,220 @@
+/* Interface between GCC C FE and GDB
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_C_INTERFACE_H
+#define GCC_C_INTERFACE_H
+
+#include "gcc-interface.h"
+
+/* This header defines the interface to the GCC API.  It must be both
+   valid C and valid C++, because it is included by both programs.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Forward declaration.  */
+
+struct gcc_c_context;
+
+/*
+ * Definitions and declarations for the C front end.
+ */
+
+/* Defined versions of the C front-end API.  */
+
+enum gcc_c_api_version
+{
+  GCC_C_FE_VERSION_0 = 0
+};
+
+/* Qualifiers.  */
+
+enum gcc_qualifiers
+{
+  GCC_QUALIFIER_CONST = 1,
+  GCC_QUALIFIER_VOLATILE = 2,
+  GCC_QUALIFIER_RESTRICT = 4
+};
+
+/* This enumerates the kinds of decls that GDB can create.  */
+
+enum gcc_c_symbol_kind
+{
+  /* A function.  */
+
+  GCC_C_SYMBOL_FUNCTION,
+
+  /* A variable.  */
+
+  GCC_C_SYMBOL_VARIABLE,
+
+  /* A typedef.  */
+
+  GCC_C_SYMBOL_TYPEDEF,
+
+  /* A label.  */
+
+  GCC_C_SYMBOL_LABEL
+};
+
+/* This enumerates the types of symbols that GCC might request from
+   GDB.  */
+
+enum gcc_c_oracle_request
+{
+  /* An ordinary symbol -- a variable, function, typedef, or enum
+     constant.  */
+
+  GCC_C_ORACLE_SYMBOL,
+
+  /* A struct, union, or enum tag.  */
+
+  GCC_C_ORACLE_TAG,
+
+  /* A label.  */
+
+  GCC_C_ORACLE_LABEL
+};
+
+/* The type of the function called by GCC to ask GDB for a symbol's
+   definition.  DATUM is an arbitrary value supplied when the oracle
+   function is registered.  CONTEXT is the GCC context in which the
+   request is being made.  REQUEST specifies what sort of symbol is
+   being requested, and IDENTIFIER is the name of the symbol.  */
+
+typedef void gcc_c_oracle_function (void *datum,
+				    struct gcc_c_context *context,
+				    enum gcc_c_oracle_request request,
+				    const char *identifier);
+
+/* The type of the function called by GCC to ask GDB for a symbol's
+   address.  This should return 0 if the address is not known.  */
+
+typedef gcc_address gcc_c_symbol_address_function (void *datum,
+						   struct gcc_c_context *ctxt,
+						   const char *identifier);
+
+/* An array of types used for creating a function type.  */
+
+struct gcc_type_array
+{
+  /* Number of elements.  */
+
+  int n_elements;
+
+  /* The elements.  */
+
+  gcc_type *elements;
+};
+
+/* The vtable used by the C front end.  */
+
+struct gcc_c_fe_vtable
+{
+  /* The version of the C interface.  The value is one of the
+     gcc_c_api_version constants.  */
+
+  unsigned int c_version;
+
+  /* Set the callbacks for this context.
+
+     The binding oracle is called whenever the C parser needs to look
+     up a symbol.  This gives the caller a chance to lazily
+     instantiate symbols using other parts of the gcc_c_fe_interface
+     API.
+
+     The address oracle is called whenever the C parser needs to look
+     up a symbol.  This is only called for symbols not provided by the
+     symbol oracle -- that is, just built-in functions where GCC
+     provides the declaration.
+
+     DATUM is an arbitrary piece of data that is passed back verbatim
+     to the callbakcs in requests.  */
+
+  void (*set_callbacks) (struct gcc_c_context *self,
+			 gcc_c_oracle_function *binding_oracle,
+			 gcc_c_symbol_address_function *address_oracle,
+			 void *datum);
+
+#define GCC_METHOD0(R, N) \
+  R (*N) (struct gcc_c_context *);
+#define GCC_METHOD1(R, N, A) \
+  R (*N) (struct gcc_c_context *, A);
+#define GCC_METHOD2(R, N, A, B) \
+  R (*N) (struct gcc_c_context *, A, B);
+#define GCC_METHOD3(R, N, A, B, C) \
+  R (*N) (struct gcc_c_context *, A, B, C);
+#define GCC_METHOD4(R, N, A, B, C, D) \
+  R (*N) (struct gcc_c_context *, A, B, C, D);
+#define GCC_METHOD5(R, N, A, B, C, D, E) \
+  R (*N) (struct gcc_c_context *, A, B, C, D, E);
+#define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
+  R (*N) (struct gcc_c_context *, A, B, C, D, E, F, G);
+
+#include "gcc-c-fe.def"
+
+#undef GCC_METHOD0
+#undef GCC_METHOD1
+#undef GCC_METHOD2
+#undef GCC_METHOD3
+#undef GCC_METHOD4
+#undef GCC_METHOD5
+#undef GCC_METHOD7
+
+};
+
+/* The C front end object.  */
+
+struct gcc_c_context
+{
+  /* Base class.  */
+
+  struct gcc_base_context base;
+
+  /* Our vtable.  This is a separate field because this is simpler
+     than implementing a vtable inheritance scheme in C.  */
+
+  const struct gcc_c_fe_vtable *c_ops;
+};
+
+/* The name of the .so that the compiler builds.  We dlopen this
+   later.  */
+
+#define GCC_C_FE_LIBCC libcc1.so
+
+/* The compiler exports a single initialization function.  This macro
+   holds its name as a symbol.  */
+
+#define GCC_C_FE_CONTEXT gcc_c_fe_context
+
+/* The type of the initialization function.  The caller passes in the
+   desired base version and desired C-specific version.  If the
+   request can be satisfied, a compatible gcc_context object will be
+   returned.  Otherwise, the function returns NULL.  */
+
+typedef struct gcc_c_context *gcc_c_fe_context_function
+    (enum gcc_base_api_version,
+     enum gcc_c_api_version);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GCC_C_INTERFACE_H */
diff --git a/include/gcc-interface.h b/include/gcc-interface.h
new file mode 100644
index 0000000..34010f2
--- /dev/null
+++ b/include/gcc-interface.h
@@ -0,0 +1,127 @@
+/* Generic interface between GCC and GDB
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_INTERFACE_H
+#define GCC_INTERFACE_H
+
+/* This header defines the interface to the GCC API.  It must be both
+   valid C and valid C++, because it is included by both programs.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Opaque typedefs for objects passed through the interface.  */
+
+typedef unsigned long long gcc_type;
+typedef unsigned long long gcc_decl;
+
+/* An address in the inferior.  */
+
+typedef unsigned long long gcc_address;
+
+/* Forward declaration.  */
+
+struct gcc_base_context;
+
+/* Defined versions of the generic API.  */
+
+enum gcc_base_api_version
+{
+  GCC_FE_VERSION_0 = 0
+};
+
+/* The operations defined by the GCC base API.  This is the vtable for
+   the real context structure which is passed around.
+
+   The "base" API is concerned with basics shared by all compiler
+   front ends: setting command-line arguments, the file names, etc.
+
+   Front-end-specific interfaces inherit from this one.  */
+
+struct gcc_base_vtable
+{
+  /* The actual version implemented in this interface.  This field can
+     be relied on not to move, so users can always check it if they
+     desire.  The value is one of the gcc_base_api_version constants.
+  */
+
+  unsigned int version;
+
+  /* Set the compiler's command-line options for the next compilation.
+     TRIPLET_REGEXP is a regular expression that is used to match the
+     configury triplet prefix to the compiler.
+     The arguments are copied by GCC.  ARGV need not be
+     NULL-terminated.  The arguments must be set separately for each
+     compilation; that is, after a compile is requested, the
+     previously-set arguments cannot be reused.
+
+     This returns NULL on success.  On failure, returns a malloc()d
+     error message.  The caller is responsible for freeing it.  */
+
+  char *(*set_arguments) (struct gcc_base_context *self,
+			  const char *triplet_regexp,
+			  int argc, char **argv);
+
+  /* Set the file name of the program to compile.  The string is
+     copied by the method implementation, but the caller must
+     guarantee that the file exists through the compilation.  */
+
+  void (*set_source_file) (struct gcc_base_context *self, const char *file);
+
+  /* Set a callback to use for printing error messages.  DATUM is
+     passed through to the callback unchanged.  */
+
+  void (*set_print_callback) (struct gcc_base_context *self,
+			      void (*print_function) (void *datum,
+						      const char *message),
+			      void *datum);
+
+  /* Perform the compilation.  FILENAME is the name of the resulting
+     object file.  VERBOSE can be set to cause GCC to print some
+     information as it works.  Returns true on success, false on
+     error.  */
+
+  int /* bool */ (*compile) (struct gcc_base_context *self,
+			     const char *filename,
+			     int /* bool */ verbose);
+
+  /* Destroy this object.  */
+
+  void (*destroy) (struct gcc_base_context *self);
+};
+
+/* The GCC object.  */
+
+struct gcc_base_context
+{
+  /* The virtual table.  */
+
+  const struct gcc_base_vtable *ops;
+};
+
+/* The name of the dummy wrapper function generated by gdb.  */
+
+#define GCC_FE_WRAPPER_FUNCTION "_gdb_expr"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GCC_INTERFACE_H */

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 01/14] introduce ui_file_write_for_put
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
  2014-11-23 19:27 ` [PATCH v4 02/14] add gcc/gdb interface files Jan Kratochvil
  2014-11-23 19:27 ` [PATCH v4 03/14] add some missing ops to DWARF assembler Jan Kratochvil
@ 2014-11-23 19:27 ` Jan Kratochvil
  2014-11-23 19:27 ` [PATCH v4 04/14] add make_unqualified_type Jan Kratochvil
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:27 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

This introduces a small helper function, ui_file_write_for_put.  It is
a wrapper for ui_write that is suitable for passing directly to
ui_file_put.

This patch also updates one existing spot to use this new function.

2014-10-07  Tom Tromey  <tromey@redhat.com>

	* ui-file.h (ui_file_write_for_put): Declare.
	* ui-file.c (ui_file_write_for_put): New function.
	* mi/mi-out.c (do_write): Remove.
	(mi_out_put): Use ui_file_write_for_put.
---
 gdb/ChangeLog   |    7 +++++++
 gdb/mi/mi-out.c |    8 +-------
 gdb/ui-file.c   |    6 ++++++
 gdb/ui-file.h   |    6 ++++++
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 07dacc0..d6d2b49 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2014-10-07  Tom Tromey  <tromey@redhat.com>
+
+	* ui-file.h (ui_file_write_for_put): Declare.
+	* ui-file.c (ui_file_write_for_put): New function.
+	* mi/mi-out.c (do_write): Remove.
+	(mi_out_put): Use ui_file_write_for_put.
+
 2014-11-23  Patrick Palka  <patrick@parcs.ath.cx>
 
 	* MAINTAINERS (Write After Approval): Add myself.
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 6ec41e6..9f5d1c0 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -376,18 +376,12 @@ mi_out_rewind (struct ui_out *uiout)
 
 /* Dump the buffer onto the specified stream.  */
 
-static void
-do_write (void *data, const char *buffer, long length_buffer)
-{
-  ui_file_write (data, buffer, length_buffer);
-}
-
 void
 mi_out_put (struct ui_out *uiout, struct ui_file *stream)
 {
   mi_out_data *data = ui_out_data (uiout);
 
-  ui_file_put (data->buffer, do_write, stream);
+  ui_file_put (data->buffer, ui_file_write_for_put, stream);
   ui_file_rewind (data->buffer);
 }
 
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index 49607dc..e3c7ba2 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -223,6 +223,12 @@ ui_file_write (struct ui_file *file,
 }
 
 void
+ui_file_write_for_put (void *data, const char *buffer, long length_buffer)
+{
+  ui_file_write (data, buffer, length_buffer);
+}
+
+void
 ui_file_write_async_safe (struct ui_file *file,
 			  const char *buf,
 			  long length_buf)
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 50c1333..29ce5e0 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -98,6 +98,12 @@ extern int ui_file_isatty (struct ui_file *);
 extern void ui_file_write (struct ui_file *file, const char *buf,
 			   long length_buf);
 
+/* A wrapper for ui_file_write that is suitable for use by
+   ui_file_put.  */
+
+extern void ui_file_write_for_put (void *data, const char *buffer,
+				   long length_buffer);
+
 extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
 				      long length_buf);
 

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 12/14] add linux_infcall_mmap
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (5 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 11/14] export dwarf2_reg_to_regnum_or_error Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-12-15 12:41   ` Ulrich Weigand
  2014-11-23 19:28 ` [PATCH v4 05/14] add dummy frame destructor Jan Kratochvil
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

This implements the new gdbarch "infcall_mmap" method for Linux.

2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-tdep.c: Include objfiles.h and infcall.h.
	(GDB_MMAP_MAP_PRIVATE, GDB_MMAP_MAP_ANONYMOUS, linux_infcall_mmap): New
	function.
	(linux_init_abi): Add linux_infcall_mmap to gdbarch.
---
 gdb/ChangeLog    |    7 +++++++
 gdb/linux-tdep.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 02c28b2..114fa0f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* linux-tdep.c: Include objfiles.h and infcall.h.
+	(GDB_MMAP_MAP_PRIVATE, GDB_MMAP_MAP_ANONYMOUS, linux_infcall_mmap): New
+	function.
+	(linux_init_abi): Add linux_infcall_mmap to gdbarch.
+
+2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	* dwarf2loc.h (dwarf2_reg_to_regnum_or_error): Declare.
 	* dwarf2loc.c (dwarf2_reg_to_regnum_or_error): Rename from
 	translate_register.  Now public.
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index ffc3e87..485f5ca 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -33,6 +33,8 @@
 #include "arch-utils.h"
 #include "gdb_obstack.h"
 #include "observer.h"
+#include "objfiles.h"
+#include "infcall.h"
 
 #include <ctype.h>
 
@@ -1921,6 +1923,52 @@ linux_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
   return 1;
 }
 
+/* Symbols for linux_infcall_mmap's ARG_FLAGS; their Linux MAP_* system
+   definitions would be dependent on compilation host.  */
+#define GDB_MMAP_MAP_PRIVATE	0x02		/* Changes are private.  */
+#define GDB_MMAP_MAP_ANONYMOUS	0x20		/* Don't use a file.  */
+
+/* See gdbarch.sh 'infcall_mmap'.  */
+
+static CORE_ADDR
+linux_infcall_mmap (CORE_ADDR size, unsigned prot)
+{
+  struct objfile *objf;
+  /* Do there still exist any Linux systems without "mmap64"?
+     "mmap" uses 64-bit off_t on x86_64 and 32-bit off_t on i386 and x32.  */
+  struct value *mmap_val = find_function_in_inferior ("mmap64", &objf);
+  struct value *addr_val;
+  struct gdbarch *gdbarch = get_objfile_arch (objf);
+  CORE_ADDR retval;
+  enum
+    {
+      ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, ARG_MAX
+    };
+  struct value *arg[ARG_MAX];
+
+  arg[ARG_ADDR] = value_from_pointer (builtin_type (gdbarch)->builtin_data_ptr,
+				      0);
+  /* Assuming sizeof (unsigned long) == sizeof (size_t).  */
+  arg[ARG_LENGTH] = value_from_ulongest
+		    (builtin_type (gdbarch)->builtin_unsigned_long, size);
+  gdb_assert ((prot & ~(GDB_MMAP_PROT_READ | GDB_MMAP_PROT_WRITE
+			| GDB_MMAP_PROT_EXEC))
+	      == 0);
+  arg[ARG_PROT] = value_from_longest (builtin_type (gdbarch)->builtin_int, prot);
+  arg[ARG_FLAGS] = value_from_longest (builtin_type (gdbarch)->builtin_int,
+				       GDB_MMAP_MAP_PRIVATE
+				       | GDB_MMAP_MAP_ANONYMOUS);
+  arg[ARG_FD] = value_from_longest (builtin_type (gdbarch)->builtin_int, -1);
+  arg[ARG_OFFSET] = value_from_longest (builtin_type (gdbarch)->builtin_int64,
+					0);
+  addr_val = call_function_by_hand (mmap_val, ARG_MAX, arg);
+  retval = value_as_address (addr_val);
+  if (retval == (CORE_ADDR) -1)
+    error (_("Failed inferior mmap call for %s bytes, errno is changed."),
+	   pulongest (size));
+  return retval;
+}
+
 /* To be called from the various GDB_OSABI_LINUX handlers for the
    various GNU/Linux architectures and machine types.  */
 
@@ -1939,6 +1987,7 @@ linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_gdb_signal_to_target (gdbarch,
 				    linux_gdb_signal_to_target);
   set_gdbarch_vsyscall_range (gdbarch, linux_vsyscall_range);
+  set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);
 }
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 06/14] add infcall_mmap and gcc_target_options gdbarch methods
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (8 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 09/14] split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 07/14] add gnu_triplet_regexp gdbarch method Jan Kratochvil
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

The compiler needed two new gdbarch methods.

The infcall_mmap method allocates memory in the inferior.
This is used when inserting the object code.

The gcc_target_options method computes some arch-specific gcc options
to pass to the compiler.  This is used to ensure that gcc generates
object code for the correct architecture.

2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* arch-utils.c (default_infcall_mmap)
	(default_gcc_target_options): New functions.
	* arch-utils.h (GDB_MMAP_PROT_READ, GDB_MMAP_PROT_WRITE)
	(GDB_MMAP_PROT_EXEC): Define.
	(default_infcall_mmap, default_gcc_target_options): Declare.
	* gdbarch.h: Rebuild.
	* gdbarch.c: Rebuild.
	* gdbarch.sh (infcall_mmap, gcc_target_options): New methods.
---
 gdb/ChangeLog    |   11 +++++++++++
 gdb/arch-utils.c |   16 ++++++++++++++++
 gdb/arch-utils.h |    9 +++++++++
 gdb/gdbarch.c    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 gdb/gdbarch.h    |   17 +++++++++++++++++
 gdb/gdbarch.sh   |   11 +++++++++++
 6 files changed, 110 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 951b7b5..d62748a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,16 @@
 2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* arch-utils.c (default_infcall_mmap)
+	(default_gcc_target_options): New functions.
+	* arch-utils.h (GDB_MMAP_PROT_READ, GDB_MMAP_PROT_WRITE)
+	(GDB_MMAP_PROT_EXEC): Define.
+	(default_infcall_mmap, default_gcc_target_options): Declare.
+	* gdbarch.h: Rebuild.
+	* gdbarch.c: Rebuild.
+	* gdbarch.sh (infcall_mmap, gcc_target_options): New methods.
+
+2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	* dummy-frame.c (struct dummy_frame) <dtor, dtor_data>: New
 	fields.
 	(pop_dummy_frame): Call the destructor if it exists.
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index a2e76de..950912d 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -839,6 +839,22 @@ default_skip_permanent_breakpoint (struct regcache *regcache)
   regcache_write_pc (regcache, current_pc);
 }
 
+CORE_ADDR
+default_infcall_mmap (CORE_ADDR size, unsigned prot)
+{
+  error (_("This target does not support inferior memory allocation by mmap."));
+}
+
+/* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
+   created in inferior memory by GDB (normally it is set by ld.so).  */
+
+char *
+default_gcc_target_options (struct gdbarch *gdbarch)
+{
+  return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
+		     gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_gdbarch_utils;
 
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 1f5dd55..1ccb56a 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -186,4 +186,13 @@ extern int default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *ra
    module determines whether a breakpoint is permanent.  */
 extern void default_skip_permanent_breakpoint (struct regcache *regcache);
 
+/* Symbols for gdbarch_infcall_mmap; their Linux PROT_* system
+   definitions would be dependent on compilation host.  */
+#define GDB_MMAP_PROT_READ	0x1	/* Page can be read.  */
+#define GDB_MMAP_PROT_WRITE	0x2	/* Page can be written.  */
+#define GDB_MMAP_PROT_EXEC	0x4	/* Page can be executed.  */
+
+extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot);
+extern char *default_gcc_target_options (struct gdbarch *gdbarch);
+
 #endif
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index f89a6d2..7eb1e6b 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -318,6 +318,8 @@ struct gdbarch
   gdbarch_insn_is_jump_ftype *insn_is_jump;
   gdbarch_auxv_parse_ftype *auxv_parse;
   gdbarch_vsyscall_range_ftype *vsyscall_range;
+  gdbarch_infcall_mmap_ftype *infcall_mmap;
+  gdbarch_gcc_target_options_ftype *gcc_target_options;
 };
 
 /* Create a new ``struct gdbarch'' based on information provided by
@@ -412,6 +414,8 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->insn_is_ret = default_insn_is_ret;
   gdbarch->insn_is_jump = default_insn_is_jump;
   gdbarch->vsyscall_range = default_vsyscall_range;
+  gdbarch->infcall_mmap = default_infcall_mmap;
+  gdbarch->gcc_target_options = default_gcc_target_options;
   /* gdbarch_alloc() */
 
   return gdbarch;
@@ -634,6 +638,8 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of insn_is_jump, invalid_p == 0 */
   /* Skip verify of auxv_parse, has predicate.  */
   /* Skip verify of vsyscall_range, invalid_p == 0 */
+  /* Skip verify of infcall_mmap, invalid_p == 0 */
+  /* Skip verify of gcc_target_options, invalid_p == 0 */
   buf = ui_file_xstrdup (log, &length);
   make_cleanup (xfree, buf);
   if (length > 0)
@@ -895,6 +901,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: frame_red_zone_size = %s\n",
                       plongest (gdbarch->frame_red_zone_size));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: gcc_target_options = <%s>\n",
+                      host_address_to_string (gdbarch->gcc_target_options));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_gcore_bfd_target_p() = %d\n",
                       gdbarch_gcore_bfd_target_p (gdbarch));
   fprintf_unfiltered (file,
@@ -961,6 +970,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: in_solib_return_trampoline = <%s>\n",
                       host_address_to_string (gdbarch->in_solib_return_trampoline));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: infcall_mmap = <%s>\n",
+                      host_address_to_string (gdbarch->infcall_mmap));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_info_proc_p() = %d\n",
                       gdbarch_info_proc_p (gdbarch));
   fprintf_unfiltered (file,
@@ -4441,6 +4453,40 @@ set_gdbarch_vsyscall_range (struct gdbarch *gdbarch,
   gdbarch->vsyscall_range = vsyscall_range;
 }
 
+CORE_ADDR
+gdbarch_infcall_mmap (struct gdbarch *gdbarch, CORE_ADDR size, unsigned prot)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->infcall_mmap != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_infcall_mmap called\n");
+  return gdbarch->infcall_mmap (size, prot);
+}
+
+void
+set_gdbarch_infcall_mmap (struct gdbarch *gdbarch,
+                          gdbarch_infcall_mmap_ftype infcall_mmap)
+{
+  gdbarch->infcall_mmap = infcall_mmap;
+}
+
+char *
+gdbarch_gcc_target_options (struct gdbarch *gdbarch)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->gcc_target_options != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_gcc_target_options called\n");
+  return gdbarch->gcc_target_options (gdbarch);
+}
+
+void
+set_gdbarch_gcc_target_options (struct gdbarch *gdbarch,
+                                gdbarch_gcc_target_options_ftype gcc_target_options)
+{
+  gdbarch->gcc_target_options = gcc_target_options;
+}
+
 
 /* Keep a registry of per-architecture data-pointers required by GDB
    modules.  */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 0bd1d56..304d136 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1339,6 +1339,23 @@ typedef int (gdbarch_vsyscall_range_ftype) (struct gdbarch *gdbarch, struct mem_
 extern int gdbarch_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range);
 extern void set_gdbarch_vsyscall_range (struct gdbarch *gdbarch, gdbarch_vsyscall_range_ftype *vsyscall_range);
 
+/* Allocate SIZE bytes of PROT protected page aligned memory in inferior.
+   PROT has GDB_MMAP_PROT_* bitmask format.
+   Throw an error if it is not possible.  Returned address is always valid. */
+
+typedef CORE_ADDR (gdbarch_infcall_mmap_ftype) (CORE_ADDR size, unsigned prot);
+extern CORE_ADDR gdbarch_infcall_mmap (struct gdbarch *gdbarch, CORE_ADDR size, unsigned prot);
+extern void set_gdbarch_infcall_mmap (struct gdbarch *gdbarch, gdbarch_infcall_mmap_ftype *infcall_mmap);
+
+/* Return string (caller has to use xfree for it) with options for GCC
+   to produce code for this target, typically "-m64", "-m32" or "-m31".
+   These options are put before CU's DW_AT_producer compilation options so that
+   they can override it.  Method may also return NULL. */
+
+typedef char * (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch);
+extern char * gdbarch_gcc_target_options (struct gdbarch *gdbarch);
+extern void set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, gdbarch_gcc_target_options_ftype *gcc_target_options);
+
 /* Definition for an unknown syscall, used basically in error-cases.  */
 #define UNKNOWN_SYSCALL (-1)
 
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 8aeb394..d3d4e57 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1042,6 +1042,17 @@ M:int:auxv_parse:gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_AD
 # range with zero length is returned.  Returns true if the vsyscall is
 # found, false otherwise.
 m:int:vsyscall_range:struct mem_range *range:range::default_vsyscall_range::0
+
+# Allocate SIZE bytes of PROT protected page aligned memory in inferior.
+# PROT has GDB_MMAP_PROT_* bitmask format.
+# Throw an error if it is not possible.  Returned address is always valid.
+f:CORE_ADDR:infcall_mmap:CORE_ADDR size, unsigned prot:size, prot::default_infcall_mmap::0
+
+# Return string (caller has to use xfree for it) with options for GCC
+# to produce code for this target, typically "-m64", "-m32" or "-m31".
+# These options are put before CU's DW_AT_producer compilation options so that
+# they can override it.  Method may also return NULL.
+m:char *:gcc_target_options:void:::default_gcc_target_options::0
 EOF
 }
 

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 07/14] add gnu_triplet_regexp gdbarch method
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (9 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 06/14] add infcall_mmap and gcc_target_options gdbarch methods Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 08/14] introduce call_function_by_hand_dummy Jan Kratochvil
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

gdb has to inform libcc1.so of the target being used, so that the
correct compiler can be invoked.  The compiler is invoked using the
GNU configury triplet prefix, e.g., "x86_64-unknown-linux-gnu-gcc".

In order for this to work we need to map the gdbarch to the GNU
configury triplet arch.  In most cases these are identical; however,
the x86 family poses some problems, as the BFD arch names are quite
different from the GNU triplet names.  So, we introduce a new gdbarch
method for this.  A regular expression is used because there are
various valid values for the arch prefix in the triplet.

This patch also updates the osabi code to associate a regular
expression with the OS ABI.  I have only added a concrete value for
Linux.  Note that the "-gnu" part is optional, at least on Fedora it
is omitted from the installed GCC executable's name.

2014-10-07  Tom Tromey  <tromey@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* osabi.h (osabi_triplet_regexp): Declare.
	* osabi.c (struct osabi_names): New.
	(gdb_osabi_names): Change type to struct osabi_names.  Update
	values.
	(gdbarch_osabi_name): Update.
	(osabi_triplet_regexp): New function.
	(osabi_from_tdesc_string, _initialize_gdb_osabi): Update.
	* i386-tdep.c (i386_gnu_triplet_regexp): New method.
	(i386_elf_init_abi, i386_go32_init_abi, i386_gdbarch_init): Call
	set_gdbarch_gnu_triplet_regexp.
	* gdbarch.sh (gnu_triplet_regexp): New method.
	* gdbarch.c, gdbarch.h: Rebuild.
	* arch-utils.h (default_gnu_triplet_regexp): Declare.
	* arch-utils.c (default_gnu_triplet_regexp): New function.
---
 gdb/ChangeLog    |   18 +++++++++++
 gdb/arch-utils.c |    8 +++++
 gdb/arch-utils.h |    1 +
 gdb/gdbarch.c    |   23 ++++++++++++++
 gdb/gdbarch.h    |   10 ++++++
 gdb/gdbarch.sh   |    7 ++++
 gdb/i386-tdep.c  |   17 ++++++++++
 gdb/osabi.c      |   88 ++++++++++++++++++++++++++++++++++--------------------
 gdb/osabi.h      |    4 ++
 9 files changed, 144 insertions(+), 32 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d62748a..9222c54 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,21 @@
+2014-10-07  Tom Tromey  <tromey@redhat.com>
+	    Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* osabi.h (osabi_triplet_regexp): Declare.
+	* osabi.c (struct osabi_names): New.
+	(gdb_osabi_names): Change type to struct osabi_names.  Update
+	values.
+	(gdbarch_osabi_name): Update.
+	(osabi_triplet_regexp): New function.
+	(osabi_from_tdesc_string, _initialize_gdb_osabi): Update.
+	* i386-tdep.c (i386_gnu_triplet_regexp): New method.
+	(i386_elf_init_abi, i386_go32_init_abi, i386_gdbarch_init): Call
+	set_gdbarch_gnu_triplet_regexp.
+	* gdbarch.sh (gnu_triplet_regexp): New method.
+	* gdbarch.c, gdbarch.h: Rebuild.
+	* arch-utils.h (default_gnu_triplet_regexp): Declare.
+	* arch-utils.c (default_gnu_triplet_regexp): New function.
+
 2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	* arch-utils.c (default_infcall_mmap)
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 950912d..ad4d90d 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -855,6 +855,14 @@ default_gcc_target_options (struct gdbarch *gdbarch)
 		     gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
 }
 
+/* gdbarch gnu_triplet_regexp method.  */
+
+const char *
+default_gnu_triplet_regexp (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->arch_name;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_gdbarch_utils;
 
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 1ccb56a..cb78907 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -194,5 +194,6 @@ extern void default_skip_permanent_breakpoint (struct regcache *regcache);
 
 extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot);
 extern char *default_gcc_target_options (struct gdbarch *gdbarch);
+extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch);
 
 #endif
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 7eb1e6b..4cb9fcb 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -320,6 +320,7 @@ struct gdbarch
   gdbarch_vsyscall_range_ftype *vsyscall_range;
   gdbarch_infcall_mmap_ftype *infcall_mmap;
   gdbarch_gcc_target_options_ftype *gcc_target_options;
+  gdbarch_gnu_triplet_regexp_ftype *gnu_triplet_regexp;
 };
 
 /* Create a new ``struct gdbarch'' based on information provided by
@@ -416,6 +417,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->vsyscall_range = default_vsyscall_range;
   gdbarch->infcall_mmap = default_infcall_mmap;
   gdbarch->gcc_target_options = default_gcc_target_options;
+  gdbarch->gnu_triplet_regexp = default_gnu_triplet_regexp;
   /* gdbarch_alloc() */
 
   return gdbarch;
@@ -640,6 +642,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of vsyscall_range, invalid_p == 0 */
   /* Skip verify of infcall_mmap, invalid_p == 0 */
   /* Skip verify of gcc_target_options, invalid_p == 0 */
+  /* Skip verify of gnu_triplet_regexp, invalid_p == 0 */
   buf = ui_file_xstrdup (log, &length);
   make_cleanup (xfree, buf);
   if (length > 0)
@@ -943,6 +946,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: get_syscall_number = <%s>\n",
                       host_address_to_string (gdbarch->get_syscall_number));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: gnu_triplet_regexp = <%s>\n",
+                      host_address_to_string (gdbarch->gnu_triplet_regexp));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: half_bit = %s\n",
                       plongest (gdbarch->half_bit));
   fprintf_unfiltered (file,
@@ -4487,6 +4493,23 @@ set_gdbarch_gcc_target_options (struct gdbarch *gdbarch,
   gdbarch->gcc_target_options = gcc_target_options;
 }
 
+const char *
+gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->gnu_triplet_regexp != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_gnu_triplet_regexp called\n");
+  return gdbarch->gnu_triplet_regexp (gdbarch);
+}
+
+void
+set_gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch,
+                                gdbarch_gnu_triplet_regexp_ftype gnu_triplet_regexp)
+{
+  gdbarch->gnu_triplet_regexp = gnu_triplet_regexp;
+}
+
 
 /* Keep a registry of per-architecture data-pointers required by GDB
    modules.  */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 304d136..962ef9a 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1356,6 +1356,16 @@ typedef char * (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch);
 extern char * gdbarch_gcc_target_options (struct gdbarch *gdbarch);
 extern void set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, gdbarch_gcc_target_options_ftype *gcc_target_options);
 
+/* Return a regular expression that matches names used by this
+   architecture in GNU configury triplets.  The result is statically
+   allocated and must not be freed.  The default implementation simply
+   returns the BFD architecture name, which is correct in nearly every
+   case. */
+
+typedef const char * (gdbarch_gnu_triplet_regexp_ftype) (struct gdbarch *gdbarch);
+extern const char * gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch);
+extern void set_gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch, gdbarch_gnu_triplet_regexp_ftype *gnu_triplet_regexp);
+
 /* Definition for an unknown syscall, used basically in error-cases.  */
 #define UNKNOWN_SYSCALL (-1)
 
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index d3d4e57..f049efc 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1053,6 +1053,13 @@ f:CORE_ADDR:infcall_mmap:CORE_ADDR size, unsigned prot:size, prot::default_infca
 # These options are put before CU's DW_AT_producer compilation options so that
 # they can override it.  Method may also return NULL.
 m:char *:gcc_target_options:void:::default_gcc_target_options::0
+
+# Return a regular expression that matches names used by this
+# architecture in GNU configury triplets.  The result is statically
+# allocated and must not be freed.  The default implementation simply
+# returns the BFD architecture name, which is correct in nearly every
+# case.
+m:const char *:gnu_triplet_regexp:void:::default_gnu_triplet_regexp::0
 EOF
 }
 
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 6c4ef17..0750506 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -4306,6 +4306,17 @@ i386_stap_parse_special_token (struct gdbarch *gdbarch,
 
 \f
 
+/* gdbarch gnu_triplet_regexp method.  Both arches are acceptable as GDB always
+   also supplies -m64 or -m32 by gdbarch_gcc_target_options.  */
+
+static const char *
+i386_gnu_triplet_regexp (struct gdbarch *gdbarch)
+{
+  return "(x86_64|i.86)";
+}
+
+\f
+
 /* Generic ELF.  */
 
 void
@@ -4332,6 +4343,8 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 				      i386_stap_is_single_operand);
   set_gdbarch_stap_parse_special_token (gdbarch,
 					i386_stap_parse_special_token);
+
+  set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp);
 }
 
 /* System V Release 4 (SVR4).  */
@@ -4379,6 +4392,8 @@ i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
 
   set_gdbarch_has_dos_based_file_system (gdbarch, 1);
+
+  set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp);
 }
 \f
 
@@ -8402,6 +8417,8 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
      gap for the upper AVX, MPX and AVX512 registers.  */
   set_gdbarch_num_regs (gdbarch, I386_AVX512_NUM_REGS);
 
+  set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp);
+
   /* Get the x86 target description from INFO.  */
   tdesc = info.target_desc;
   if (! tdesc_has_registers (tdesc))
diff --git a/gdb/osabi.c b/gdb/osabi.c
index d33ef9c..50d391a 100644
--- a/gdb/osabi.c
+++ b/gdb/osabi.c
@@ -41,46 +41,70 @@ static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] = {
 };
 static const char *set_osabi_string;
 
+/* Names associated with each osabi.  */
+
+struct osabi_names
+{
+  /* The "pretty" name.  */
+
+  const char *pretty;
+
+  /* The triplet regexp, or NULL if not known.  */
+
+  const char *regexp;
+};
+
 /* This table matches the indices assigned to enum gdb_osabi.  Keep
    them in sync.  */
-static const char * const gdb_osabi_names[] =
+static const struct osabi_names gdb_osabi_names[] =
 {
-  "none",
-
-  "SVR4",
-  "GNU/Hurd",
-  "Solaris",
-  "GNU/Linux",
-  "FreeBSD a.out",
-  "FreeBSD ELF",
-  "NetBSD a.out",
-  "NetBSD ELF",
-  "OpenBSD ELF",
-  "Windows CE",
-  "DJGPP",
-  "Irix",
-  "HP/UX ELF",
-  "HP/UX SOM",
-  "QNX Neutrino",
-  "Cygwin",
-  "AIX",
-  "DICOS",
-  "Darwin",
-  "Symbian",
-  "OpenVMS",
-  "LynxOS178",
-  "Newlib",
-
-  "<invalid>"
+  { "none", NULL },
+
+  { "SVR4", NULL },
+  { "GNU/Hurd", NULL },
+  { "Solaris", NULL },
+  { "GNU/Linux", "linux(-gnu)?" },
+  { "FreeBSD a.out", NULL },
+  { "FreeBSD ELF", NULL },
+  { "NetBSD a.out", NULL },
+  { "NetBSD ELF", NULL },
+  { "OpenBSD ELF", NULL },
+  { "Windows CE", NULL },
+  { "DJGPP", NULL },
+  { "Irix", NULL },
+  { "HP/UX ELF", NULL },
+  { "HP/UX SOM", NULL },
+  { "QNX Neutrino", NULL },
+  { "Cygwin", NULL },
+  { "AIX", NULL },
+  { "DICOS", NULL },
+  { "Darwin", NULL },
+  { "Symbian", NULL },
+  { "OpenVMS", NULL },
+  { "LynxOS178", NULL },
+  { "Newlib", NULL },
+
+  { "<invalid>", NULL }
 };
 
 const char *
 gdbarch_osabi_name (enum gdb_osabi osabi)
 {
   if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
-    return gdb_osabi_names[osabi];
+    return gdb_osabi_names[osabi].pretty;
+
+  return gdb_osabi_names[GDB_OSABI_INVALID].pretty;
+}
+
+/* See osabi.h.  */
+
+const char *
+osabi_triplet_regexp (enum gdb_osabi osabi)
+{
+  if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
+    return gdb_osabi_names[osabi].regexp;
 
-  return gdb_osabi_names[GDB_OSABI_INVALID];
+  return gdb_osabi_names[GDB_OSABI_INVALID].regexp;
 }
 
 /* Lookup the OS ABI corresponding to the specified target description
@@ -92,7 +116,7 @@ osabi_from_tdesc_string (const char *name)
   int i;
 
   for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++)
-    if (strcmp (name, gdb_osabi_names[i]) == 0)
+    if (strcmp (name, gdb_osabi_names[i].pretty) == 0)
       {
 	/* See note above: the name table matches the indices assigned
 	   to enum gdb_osabi.  */
@@ -645,7 +669,7 @@ extern initialize_file_ftype _initialize_gdb_osabi; /* -Wmissing-prototype */
 void
 _initialize_gdb_osabi (void)
 {
-  if (strcmp (gdb_osabi_names[GDB_OSABI_INVALID], "<invalid>") != 0)
+  if (strcmp (gdb_osabi_names[GDB_OSABI_INVALID].pretty, "<invalid>") != 0)
     internal_error
       (__FILE__, __LINE__,
        _("_initialize_gdb_osabi: gdb_osabi_names[] is inconsistent"));
diff --git a/gdb/osabi.h b/gdb/osabi.h
index 4c03790..8408f0a 100644
--- a/gdb/osabi.h
+++ b/gdb/osabi.h
@@ -49,6 +49,10 @@ void gdbarch_init_osabi (struct gdbarch_info, struct gdbarch *);
 /* Return the name of the specified OS ABI.  */
 const char *gdbarch_osabi_name (enum gdb_osabi);
 
+/* Return a regular expression that matches the OS part of a GNU
+   configury triplet for the given OSABI.  */
+const char *osabi_triplet_regexp (enum gdb_osabi osabi);
+
 /* Helper routine for ELF file sniffers.  This looks at ABI tag note
    sections to determine the OS ABI from the note.  It should be called
    via bfd_map_over_sections.  */

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 11/14] export dwarf2_reg_to_regnum_or_error
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (4 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 13/14] add s390_gcc_target_options Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 12/14] add linux_infcall_mmap Jan Kratochvil
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

This exports a utility function, dwarf2_reg_to_regnum_or_error, that
was previously private to dwarf2loc.c.

2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2loc.h (dwarf2_reg_to_regnum_or_error): Declare.
	* dwarf2loc.c (dwarf2_reg_to_regnum_or_error): Rename from
	translate_register.  Now public.
	(dwarf2_compile_expr_to_ax): Update.
---
 gdb/ChangeLog   |    7 +++++++
 gdb/dwarf2loc.c |   18 +++++++-----------
 gdb/dwarf2loc.h |    8 ++++++++
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bf9daed..02c28b2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* dwarf2loc.h (dwarf2_reg_to_regnum_or_error): Declare.
+	* dwarf2loc.c (dwarf2_reg_to_regnum_or_error): Rename from
+	translate_register.  Now public.
+	(dwarf2_compile_expr_to_ax): Update.
+
 2014-10-07  Tom Tromey  <tromey@redhat.com>
 	    Jan Kratochvil  <jan.kratochvil@redhat.com>
 
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 50c2f24..d30b72f 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2707,14 +2707,10 @@ unimplemented (unsigned int op)
 	   op);
 }
 
-/* A helper function to convert a DWARF register to an arch register.
-   ARCH is the architecture.
-   DWARF_REG is the register.
-   This will throw an exception if the DWARF register cannot be
-   translated to an architecture register.  */
+/* See dwarf2loc.h.  */
 
-static int
-translate_register (struct gdbarch *arch, int dwarf_reg)
+int
+dwarf2_reg_to_regnum_or_error (struct gdbarch *arch, int dwarf_reg)
 {
   int reg = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_reg);
   if (reg == -1)
@@ -2965,14 +2961,14 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	case DW_OP_reg30:
 	case DW_OP_reg31:
 	  dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
-	  loc->u.reg = translate_register (arch, op - DW_OP_reg0);
+	  loc->u.reg = dwarf2_reg_to_regnum_or_error (arch, op - DW_OP_reg0);
 	  loc->kind = axs_lvalue_register;
 	  break;
 
 	case DW_OP_regx:
 	  op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
 	  dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
-	  loc->u.reg = translate_register (arch, reg);
+	  loc->u.reg = dwarf2_reg_to_regnum_or_error (arch, reg);
 	  loc->kind = axs_lvalue_register;
 	  break;
 
@@ -3035,7 +3031,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	case DW_OP_breg30:
 	case DW_OP_breg31:
 	  op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
-	  i = translate_register (arch, op - DW_OP_breg0);
+	  i = dwarf2_reg_to_regnum_or_error (arch, op - DW_OP_breg0);
 	  ax_reg (expr, i);
 	  if (offset != 0)
 	    {
@@ -3047,7 +3043,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	  {
 	    op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
 	    op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
-	    i = translate_register (arch, reg);
+	    i = dwarf2_reg_to_regnum_or_error (arch, reg);
 	    ax_reg (expr, i);
 	    if (offset != 0)
 	      {
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
index 082ccfa..76fb45b4 100644
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2loc.h
@@ -222,4 +222,12 @@ extern struct call_site_chain *call_site_find_chain (struct gdbarch *gdbarch,
 						     CORE_ADDR caller_pc,
 						     CORE_ADDR callee_pc);
 
+/* A helper function to convert a DWARF register to an arch register.
+   ARCH is the architecture.
+   DWARF_REG is the register.
+   This will throw an exception if the DWARF register cannot be
+   translated to an architecture register.  */
+
+extern int dwarf2_reg_to_regnum_or_error (struct gdbarch *arch, int dwarf_reg);
+
 #endif /* dwarf2loc.h */

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 13/14] add s390_gcc_target_options
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (3 preceding siblings ...)
  2014-11-23 19:27 ` [PATCH v4 04/14] add make_unqualified_type Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 11/14] export dwarf2_reg_to_regnum_or_error Jan Kratochvil
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

This adds s390_gcc_target_options, an implementation of the new
"gcc_target_options" gdbarch method.  This was needed because the
default implementation of the method doesn't work properly for S390,
as this architecture needs "-m31" rather than "-m32".

2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* s390-linux-tdep.c (s390_gcc_target_options): New function.
	(s390_gdbarch_init): Add it to gdbarch.
---
 gdb/ChangeLog         |    5 +++++
 gdb/s390-linux-tdep.c |    9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 114fa0f..830593f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* s390-linux-tdep.c (s390_gcc_target_options): New function.
+	(s390_gdbarch_init): Add it to gdbarch.
+
+2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	* linux-tdep.c: Include objfiles.h and infcall.h.
 	(GDB_MMAP_MAP_PRIVATE, GDB_MMAP_MAP_ANONYMOUS, linux_infcall_mmap): New
 	function.
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index b5d94ce..5dcf40c 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -2808,6 +2808,14 @@ s390_address_class_name_to_type_flags (struct gdbarch *gdbarch,
     return 0;
 }
 
+/* Implement gdbarch_gcc_target_options.  GCC does not know "-m32".  */
+
+static char *
+s390_gcc_target_options (struct gdbarch *gdbarch)
+{
+  return xstrdup ("-m31");
+}
+
 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
    gdbarch.h.  */
 
@@ -3104,6 +3112,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     {
     case ABI_LINUX_S390:
       set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
+      set_gdbarch_gcc_target_options (gdbarch, s390_gcc_target_options);
       set_solib_svr4_fetch_link_map_offsets
 	(gdbarch, svr4_ilp32_fetch_link_map_offsets);
 

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 05/14] add dummy frame destructor
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (6 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 12/14] add linux_infcall_mmap Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 09/14] split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax Jan Kratochvil
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

The compiler code needed a hook into dummy frame destruction, so that
some state could be kept while the inferior call is made and then
destroyed when the inferior call finishes.

This patch adds an optional destructor to dummy frames and a new API
to access it.

2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dummy-frame.c (struct dummy_frame) <dtor, dtor_data>: New
	fields.
	(pop_dummy_frame): Call the destructor if it exists.
	(register_dummy_frame_dtor, find_dummy_frame_dtor): New
	functions.
	* dummy-frame.h (dummy_frame_dtor_ftype): New typedef.
	(register_dummy_frame_dtor, find_dummy_frame_dtor): Declare.
---
 gdb/ChangeLog     |   10 ++++++++++
 gdb/dummy-frame.c |   41 +++++++++++++++++++++++++++++++++++++++++
 gdb/dummy-frame.h |   13 +++++++++++++
 3 files changed, 64 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 15753eb..951b7b5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* dummy-frame.c (struct dummy_frame) <dtor, dtor_data>: New
+	fields.
+	(pop_dummy_frame): Call the destructor if it exists.
+	(register_dummy_frame_dtor, find_dummy_frame_dtor): New
+	functions.
+	* dummy-frame.h (dummy_frame_dtor_ftype): New typedef.
+	(register_dummy_frame_dtor, find_dummy_frame_dtor): Declare.
+
 2014-10-07  Tom Tromey  <tromey@redhat.com>
 
 	* gdbtypes.h (make_unqualified_type): Declare.
diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c
index a13601b..6ca8b19 100644
--- a/gdb/dummy-frame.c
+++ b/gdb/dummy-frame.c
@@ -61,6 +61,13 @@ struct dummy_frame
 
   /* The caller's state prior to the call.  */
   struct infcall_suspend_state *caller_state;
+
+  /* If non-NULL, a destructor that is run when this dummy frame is
+     popped.  */
+  void (*dtor) (void *data);
+
+  /* Arbitrary data that is passed to DTOR.  */
+  void *dtor_data;
 };
 
 static struct dummy_frame *dummy_frame_stack = NULL;
@@ -127,6 +134,10 @@ pop_dummy_frame (struct dummy_frame **dummy_ptr)
   struct dummy_frame *dummy = *dummy_ptr;
 
   gdb_assert (ptid_equal (dummy->id.ptid, inferior_ptid));
+
+  if (dummy->dtor != NULL)
+    dummy->dtor (dummy->dtor_data);
+
   restore_infcall_suspend_state (dummy->caller_state);
 
   iterate_over_breakpoints (pop_dummy_frame_bpt, dummy);
@@ -190,6 +201,36 @@ dummy_frame_discard (struct frame_id dummy_id, ptid_t ptid)
     remove_dummy_frame (dp);
 }
 
+/* See dummy-frame.h.  */
+
+void
+register_dummy_frame_dtor (struct frame_id dummy_id, ptid_t ptid,
+			   dummy_frame_dtor_ftype *dtor, void *dtor_data)
+{
+  struct dummy_frame_id id = { dummy_id, ptid };
+  struct dummy_frame **dp, *d;
+
+  dp = lookup_dummy_frame (&id);
+  gdb_assert (dp != NULL);
+  d = *dp;
+  gdb_assert (d->dtor == NULL);
+  d->dtor = dtor;
+  d->dtor_data = dtor_data;
+}
+
+/* See dummy-frame.h.  */
+
+int
+find_dummy_frame_dtor (dummy_frame_dtor_ftype *dtor, void *dtor_data)
+{
+  struct dummy_frame *d;
+
+  for (d = dummy_frame_stack; d != NULL; d = d->next)
+    if (d->dtor == dtor && d->dtor_data == dtor_data)
+      return 1;
+  return 0;
+}
+
 /* There may be stale dummy frames, perhaps left over from when an uncaught
    longjmp took us out of a function that was called by the debugger.  Clean
    them up at least once whenever we start a new inferior.  */
diff --git a/gdb/dummy-frame.h b/gdb/dummy-frame.h
index bac1aac..8c1a1d0 100644
--- a/gdb/dummy-frame.h
+++ b/gdb/dummy-frame.h
@@ -54,4 +54,17 @@ extern void dummy_frame_discard (struct frame_id dummy_id, ptid_t ptid);
 
 extern const struct frame_unwind dummy_frame_unwind;
 
+/* Call DTOR with DTOR_DATA when DUMMY_ID frame of thread PTID gets discarded.
+   Dummy frame with DUMMY_ID must exist.  There must be no other call of
+   register_dummy_frame_dtor for that dummy frame.  */
+typedef void (dummy_frame_dtor_ftype) (void *data);
+extern void register_dummy_frame_dtor (struct frame_id dummy_id, ptid_t ptid,
+				       dummy_frame_dtor_ftype *dtor,
+				       void *dtor_data);
+
+/* Return 1 if there exists dummy frame with registered DTOR and DTOR_DATA.
+   Return 0 otherwise.  */
+extern int find_dummy_frame_dtor (dummy_frame_dtor_ftype *dtor,
+				  void *dtor_data);
+
 #endif /* !defined (DUMMY_FRAME_H)  */

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 08/14] introduce call_function_by_hand_dummy
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (10 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 07/14] add gnu_triplet_regexp gdbarch method Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 10/14] make dwarf_expr_frame_base_1 public Jan Kratochvil
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

This provides a variant of call_function_by_hand that allows the dummy
frame destructor to be set.  This is used by the compiler code to
manage some resources when calling the gdb-generated inferior
function.

2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* infcall.h (call_function_by_hand_dummy): Declare.
	* infcall.c (call_function_by_hand): Use
	call_function_by_hand_dummy.
	(call_function_by_hand_dummy): Rename from call_function_by_hand.
	Add arguments.  Register a destructor.
---
 gdb/ChangeLog |    8 ++++++++
 gdb/infcall.c |   16 +++++++++++++++-
 gdb/infcall.h |   11 +++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9222c54..fc60169 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* infcall.h (call_function_by_hand_dummy): Declare.
+	* infcall.c (call_function_by_hand): Use
+	call_function_by_hand_dummy.
+	(call_function_by_hand_dummy): Rename from call_function_by_hand.
+	Add arguments.  Register a destructor.
+
 2014-10-07  Tom Tromey  <tromey@redhat.com>
 	    Jan Kratochvil  <jan.kratochvil@redhat.com>
 
diff --git a/gdb/infcall.c b/gdb/infcall.c
index bbac693..74e90d4 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -455,6 +455,14 @@ cleanup_delete_std_terminate_breakpoint (void *ignore)
   delete_std_terminate_breakpoint ();
 }
 
+/* See infcall.h.  */
+
+struct value *
+call_function_by_hand (struct value *function, int nargs, struct value **args)
+{
+  return call_function_by_hand_dummy (function, nargs, args, NULL, NULL);
+}
+
 /* All this stuff with a dummy frame may seem unnecessarily complicated
    (why not just save registers in GDB?).  The purpose of pushing a dummy
    frame which looks just like a real frame is so that if you call a
@@ -474,7 +482,10 @@ cleanup_delete_std_terminate_breakpoint (void *ignore)
    ARGS is modified to contain coerced values.  */
 
 struct value *
-call_function_by_hand (struct value *function, int nargs, struct value **args)
+call_function_by_hand_dummy (struct value *function,
+			     int nargs, struct value **args,
+			     call_function_by_hand_dummy_dtor_ftype *dummy_dtor,
+			     void *dummy_dtor_data)
 {
   CORE_ADDR sp;
   struct type *values_type, *target_values_type;
@@ -831,6 +842,9 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
      caller (and identify the dummy-frame) onto the dummy-frame
      stack.  */
   dummy_frame_push (caller_state, &dummy_id, inferior_ptid);
+  if (dummy_dtor != NULL)
+    register_dummy_frame_dtor (dummy_id, inferior_ptid,
+			       dummy_dtor, dummy_dtor_data);
 
   /* Discard both inf_status and caller_state cleanups.
      From this point on we explicitly restore the associated state
diff --git a/gdb/infcall.h b/gdb/infcall.h
index c6dcdc3..f895e33 100644
--- a/gdb/infcall.h
+++ b/gdb/infcall.h
@@ -38,4 +38,15 @@ extern CORE_ADDR find_function_addr (struct value *function,
 extern struct value *call_function_by_hand (struct value *function, int nargs,
 					    struct value **args);
 
+/* Similar to call_function_by_hand and additional call
+   register_dummy_frame_dtor with DUMMY_DTOR and DUMMY_DTOR_DATA for the
+   created inferior call dummy frame.  */
+
+typedef void (call_function_by_hand_dummy_dtor_ftype) (void *data);
+extern struct value *
+  call_function_by_hand_dummy (struct value *function, int nargs,
+			       struct value **args,
+			     call_function_by_hand_dummy_dtor_ftype *dummy_dtor,
+			       void *dummy_dtor_data);
+
 #endif

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 09/14] split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (7 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 05/14] add dummy frame destructor Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:28 ` [PATCH v4 06/14] add infcall_mmap and gcc_target_options gdbarch methods Jan Kratochvil
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

This removes dwarf2_compile_expr_to_ax, replacing it with a utility
function that fetches the CFA data and adding the code to actually
compile to an agent expression directly into
dwarf2_compile_expr_to_ax.  This refactoring lets a later patch reuse
the new dwarf2_fetch_cfa_info.

2014-10-07  Tom Tromey  <tromey@redhat.com>

	* dwarf2loc.c (dwarf2_compile_expr_to_ax) <DW_OP_call_frame_cfa>:
	Update.
	* dwarf2-frame.c (dwarf2_fetch_cfa_info): New function, based on
	dwarf2_compile_cfa_to_ax.
	(dwarf2_compile_cfa_to_ax): Remove.
	* dwarf2-frame.h (dwarf2_fetch_cfa_info): Declare.
	(dwarf2_compile_cfa_to_ax): Remove.
---
 gdb/ChangeLog      |   10 ++++++++++
 gdb/dwarf2-frame.c |   40 +++++++++++++++++++---------------------
 gdb/dwarf2-frame.h |   31 +++++++++++++++++++++----------
 gdb/dwarf2loc.c    |   30 ++++++++++++++++++++++++++++--
 4 files changed, 78 insertions(+), 33 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index fc60169..922d8c9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2014-10-07  Tom Tromey  <tromey@redhat.com>
+
+	* dwarf2loc.c (dwarf2_compile_expr_to_ax) <DW_OP_call_frame_cfa>:
+	Update.
+	* dwarf2-frame.c (dwarf2_fetch_cfa_info): New function, based on
+	dwarf2_compile_cfa_to_ax.
+	(dwarf2_compile_cfa_to_ax): Remove.
+	* dwarf2-frame.h (dwarf2_fetch_cfa_info): Declare.
+	(dwarf2_compile_cfa_to_ax): Remove.
+
 2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	* infcall.h (call_function_by_hand_dummy): Declare.
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 586f134..db21cd4 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -882,11 +882,15 @@ dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs,
 }
 \f
 
-void
-dwarf2_compile_cfa_to_ax (struct agent_expr *expr, struct axs_value *loc,
-			  struct gdbarch *gdbarch,
-			  CORE_ADDR pc,
-			  struct dwarf2_per_cu_data *data)
+/* See dwarf2-frame.h.  */
+
+int
+dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
+		       struct dwarf2_per_cu_data *data,
+		       int *regnum_out, LONGEST *offset_out,
+		       CORE_ADDR *text_offset_out,
+		       const gdb_byte **cfa_start_out,
+		       const gdb_byte **cfa_end_out)
 {
   struct dwarf2_fde *fde;
   CORE_ADDR text_offset;
@@ -932,26 +936,20 @@ dwarf2_compile_cfa_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	if (regnum == -1)
 	  error (_("Unable to access DWARF register number %d"),
 		 (int) fs.regs.cfa_reg); /* FIXME */
-	ax_reg (expr, regnum);
 
-	if (fs.regs.cfa_offset != 0)
-	  {
-	    if (fs.armcc_cfa_offsets_reversed)
-	      ax_const_l (expr, -fs.regs.cfa_offset);
-	    else
-	      ax_const_l (expr, fs.regs.cfa_offset);
-	    ax_simple (expr, aop_add);
-	  }
+	*regnum_out = regnum;
+	if (fs.armcc_cfa_offsets_reversed)
+	  *offset_out = -fs.regs.cfa_offset;
+	else
+	  *offset_out = fs.regs.cfa_offset;
+	return 1;
       }
-      break;
 
     case CFA_EXP:
-      ax_const_l (expr, text_offset);
-      dwarf2_compile_expr_to_ax (expr, loc, gdbarch, addr_size,
-				 fs.regs.cfa_exp,
-				 fs.regs.cfa_exp + fs.regs.cfa_exp_len,
-				 data);
-      break;
+      *text_offset_out = text_offset;
+      *cfa_start_out = fs.regs.cfa_exp;
+      *cfa_end_out = fs.regs.cfa_exp + fs.regs.cfa_exp_len;
+      return 0;
 
     default:
       internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h
index 0470cac..5ccf0c8 100644
--- a/gdb/dwarf2-frame.h
+++ b/gdb/dwarf2-frame.h
@@ -120,15 +120,26 @@ extern const struct frame_base *
 
 CORE_ADDR dwarf2_frame_cfa (struct frame_info *this_frame);
 
-/* Update the agent expression EXPR with code to compute the CFA for a
-   frame at PC.  GDBARCH is the architecture of the function at PC.
-   This function may call dwarf2_compile_expr_to_ax; DATA is passed
-   through to that function if needed.  */
-
-extern void dwarf2_compile_cfa_to_ax (struct agent_expr *expr,
-				      struct axs_value *loc,
-				      struct gdbarch *gdbarch,
-				      CORE_ADDR pc,
-				      struct dwarf2_per_cu_data *data);
+/* Find the CFA information for PC.
+
+   Return 1 if a register is used for the CFA, or 0 if another
+   expression is used.  Throw an exception on error.
+
+   GDBARCH is the architecture to use.
+   DATA is the per-CU data.
+
+   REGNUM_OUT is an out parameter that is set to the register number.
+   OFFSET_OUT is the offset to use from this register.
+   These are only filled in when 1 is returned.
+
+   TEXT_OFFSET_OUT, CFA_START_OUT, and CFA_END_OUT describe the CFA
+   in other cases.  These are only used when 0 is returned.  */
+
+extern int dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
+				  struct dwarf2_per_cu_data *data,
+				  int *regnum_out, LONGEST *offset_out,
+				  CORE_ADDR *text_offset_out,
+				  const gdb_byte **cfa_start_out,
+				  const gdb_byte **cfa_end_out);
 
 #endif /* dwarf2-frame.h */
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 6e461bc..ffae7a5 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -3282,8 +3282,34 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	  break;
 
 	case DW_OP_call_frame_cfa:
-	  dwarf2_compile_cfa_to_ax (expr, loc, arch, expr->scope, per_cu);
-	  loc->kind = axs_lvalue_memory;
+	  {
+	    int regnum;
+	    CORE_ADDR text_offset;
+	    LONGEST off;
+	    const gdb_byte *cfa_start, *cfa_end;
+
+	    if (dwarf2_fetch_cfa_info (arch, expr->scope, per_cu,
+				       &regnum, &off,
+				       &text_offset, &cfa_start, &cfa_end))
+	      {
+		/* Register.  */
+		ax_reg (expr, regnum);
+		if (off != 0)
+		  {
+		    ax_const_l (expr, off);
+		    ax_simple (expr, aop_add);
+		  }
+	      }
+	    else
+	      {
+		/* Another expression.  */
+		ax_const_l (expr, text_offset);
+		dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size,
+					   cfa_start, cfa_end, per_cu);
+	      }
+
+	    loc->kind = axs_lvalue_memory;
+	  }
 	  break;
 
 	case DW_OP_GNU_push_tls_address:

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 10/14] make dwarf_expr_frame_base_1 public
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (11 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 08/14] introduce call_function_by_hand_dummy Jan Kratochvil
@ 2014-11-23 19:28 ` Jan Kratochvil
  2014-11-23 19:29 ` [PATCH v4 14/14] the "compile" command Jan Kratochvil
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:28 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

This exports dwarf_expr_frame_base_1 so that other code can use it.

2014-10-07  Tom Tromey  <tromey@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2loc.c (dwarf_expr_frame_base_1): Remove declaration.
	(dwarf_expr_frame_base): Update caller.
	(dwarf_expr_frame_base_1): Rename to ...
	(func_get_frame_base_dwarf_block): ... this and make it public.
	(dwarf2_compile_expr_to_ax, locexpr_describe_location_piece): Update
	callers.
	* dwarf2loc.h (func_get_frame_base_dwarf_block): New declaration.
---
 gdb/ChangeLog   |   11 +++++++++++
 gdb/dwarf2loc.c |   23 +++++++++++------------
 gdb/dwarf2loc.h |   12 ++++++++++++
 3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 922d8c9..bf9daed 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,4 +1,15 @@
 2014-10-07  Tom Tromey  <tromey@redhat.com>
+	    Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* dwarf2loc.c (dwarf_expr_frame_base_1): Remove declaration.
+	(dwarf_expr_frame_base): Update caller.
+	(dwarf_expr_frame_base_1): Rename to ...
+	(func_get_frame_base_dwarf_block): ... this and make it public.
+	(dwarf2_compile_expr_to_ax, locexpr_describe_location_piece): Update
+	callers.
+	* dwarf2loc.h (func_get_frame_base_dwarf_block): New declaration.
+
+2014-10-07  Tom Tromey  <tromey@redhat.com>
 
 	* dwarf2loc.c (dwarf2_compile_expr_to_ax) <DW_OP_call_frame_cfa>:
 	Update.
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index ffae7a5..50c2f24 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -40,9 +40,6 @@
 
 extern int dwarf2_always_disassemble;
 
-static void dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
-				     const gdb_byte **start, size_t *length);
-
 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs;
 
 static struct value *dwarf2_evaluate_loc_desc_full (struct type *type,
@@ -365,9 +362,9 @@ dwarf_expr_frame_base (void *baton, const gdb_byte **start, size_t * length)
      something has gone wrong.  */
   gdb_assert (framefunc != NULL);
 
-  dwarf_expr_frame_base_1 (framefunc,
-			   get_frame_address_in_block (debaton->frame),
-			   start, length);
+  func_get_frame_base_dwarf_block (framefunc,
+				   get_frame_address_in_block (debaton->frame),
+				   start, length);
 }
 
 /* Implement find_frame_base_location method for LOC_BLOCK functions using
@@ -411,9 +408,11 @@ const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs =
   loclist_find_frame_base_location
 };
 
-static void
-dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
-			 const gdb_byte **start, size_t *length)
+/* See dwarf2loc.h.  */
+
+void
+func_get_frame_base_dwarf_block (struct symbol *framefunc, CORE_ADDR pc,
+				 const gdb_byte **start, size_t *length)
 {
   if (SYMBOL_BLOCK_OPS (framefunc) != NULL)
     {
@@ -3074,8 +3073,8 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	    if (!framefunc)
 	      error (_("No function found for block"));
 
-	    dwarf_expr_frame_base_1 (framefunc, expr->scope,
-				     &datastart, &datalen);
+	    func_get_frame_base_dwarf_block (framefunc, expr->scope,
+					     &datastart, &datalen);
 
 	    op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
 	    dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size, datastart,
@@ -3571,7 +3570,7 @@ locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
 	error (_("No function found for block for symbol \"%s\"."),
 	       SYMBOL_PRINT_NAME (symbol));
 
-      dwarf_expr_frame_base_1 (framefunc, addr, &base_data, &base_size);
+      func_get_frame_base_dwarf_block (framefunc, addr, &base_data, &base_size);
 
       if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
 	{
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
index 96925e4..082ccfa 100644
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2loc.h
@@ -80,6 +80,18 @@ extern const gdb_byte *dwarf2_fetch_constant_bytes (sect_offset,
 struct type *dwarf2_get_die_type (cu_offset die_offset,
 				  struct dwarf2_per_cu_data *per_cu);
 
+/* Find the frame base information for FRAMEFUNC at PC.  START is an
+   out parameter which is set to point to the DWARF expression to
+   compute.  LENGTH is an out parameter which is set to the length of
+   the DWARF expression.  This throws an exception on error or if an
+   expression is not found; the returned length will never be
+   zero.  */
+
+extern void func_get_frame_base_dwarf_block (struct symbol *framefunc,
+					     CORE_ADDR pc,
+					     const gdb_byte **start,
+					     size_t *length);
+
 /* Evaluate a location description, starting at DATA and with length
    SIZE, to find the current location of variable of TYPE in the context
    of FRAME.  */

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [PATCH v4 14/14] the "compile" command
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (12 preceding siblings ...)
  2014-11-23 19:28 ` [PATCH v4 10/14] make dwarf_expr_frame_base_1 public Jan Kratochvil
@ 2014-11-23 19:29 ` Jan Kratochvil
  2014-12-14  6:05   ` Yao Qi
  2014-12-05 18:29 ` [patch 15/14] GDB/GCC compile function pointers [Re: [PATCH v4 00/14] let gdb reuse gcc's C compiler] Jan Kratochvil
  2014-12-12 14:40 ` [PATCH v4 00/14] let gdb reuse gcc's C compiler Pedro Alves
  15 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-11-23 19:29 UTC (permalink / raw)
  To: gdb-patches

From: Tom Tromey <tromey@redhat.com>

This final patch adds the new "compile" command and subcommands, and
all the machinery needed to make it work.

A shared library supplied by gcc is used for all communications with
gcc.  Types and most aspects of symbols are provided directly by gdb
to the compiler using this library.

gdb provides some information about the user's code using plain text.
Macros are emitted this way, and DWARF location expressions (and
bounds for VLA) are compiled to C code.

This hybrid approach was taken because, on the one hand, it is better
to provide global declarations and such on demand; but on the other
hand, for local variables, translating DWARF location expressions to C
was much simpler than exporting a full compiler API to gdb -- the same
result, only easier to implement, understand, and debug.

In the ordinary mode, the user's expression is wrapped in a dummy
function.  After compilation, gdb inserts the resulting object code
into the inferior, then calls this function.

Access to local variables is provided by noting which registers are
used by location expressions, and passing a structure of register
values into the function.  Writes to registers are supported by
copying out these values after the function returns.

This approach was taken so that we could eventually implement other
more interesting features based on this same infrastructure; for
example, we're planning to investigate inferior-side breakpoint
conditions.

gdb/ChangeLog
2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Tom Tromey  <tromey@redhat.com>

	* NEWS: Update.
	* symtab.h (struct symbol_computed_ops) <generate_c_location>: New
	field.
	* p-lang.c (pascal_language_defn): Update.
	* opencl-lang.c (opencl_language_defn): Update.
	* objc-lang.c (objc_language_defn): Update.
	* m2-lang.c (m2_language_defn): Update.
	* language.h (struct language_defn) <la_get_compile_instance,
	la_compute_program>: New fields.
	* language.c (unknown_language_defn, auto_language_defn)
	(local_language_defn): Update.
	* jv-lang.c (java_language_defn): Update.
	* go-lang.c (go_language_defn): Update.
	* f-lang.c (f_language_defn): Update.
	* dwarf2loc.h (dwarf2_compile_property_to_c): Declare.
	* dwarf2loc.c (dwarf2_compile_property_to_c)
	(locexpr_generate_c_location, loclist_generate_c_location): New
	functions.
	(dwarf2_locexpr_funcs, dwarf2_loclist_funcs): Update.
	* defs.h (enum compile_i_scope_types): New.
	(enum command_control_type) <compile_control>: New constant.
	(struct command_line) <control_u>: New field.
	* d-lang.c (d_language_defn): Update.
	* compile/compile.c: New file.
	* compile/compile-c-support.c: New file.
	* compile/compile-c-symbols.c: New file.
	* compile/compile-c-types.c: New file.
	* compile/compile.h: New file.
	* compile/compile-internal.h: New file.
	* compile/compile-loc2c.c: New file.
	* compile/compile-object-load.c: New file.
	* compile/compile-object-load.h: New file.
	* compile/compile-object-run.c: New file.
	* compile/compile-object-run.h: New file.
	* cli/cli-script.c (multi_line_command_p, print_command_lines)
	(execute_control_command, process_next_line)
	(recurse_read_control_structure): Handle compile_control.
	* c-lang.h (c_get_compile_context, c_compute_program): Declare.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Update.
	* ada-lang.c (ada_language_defn): Update.
	* Makefile.in (SUBDIR_GCC_COMPILE_OBS, SUBDIR_GCC_COMPILE_SRCS):
	New variables.
	(SFILES): Add SUBDIR_GCC_COMPILE_SRCS.
	(HFILES_NO_SRCDIR): Add compile.h.
	(COMMON_OBS): Add SUBDIR_GCC_COMPILE_OBS.
	(INIT_FILES): Add SUBDIR_GCC_COMPILE_SRCS.
	(compile.o, compile-c-types.o, compile-c-symbols.o)
	(compile-object-load.o, compile-object-run.o, compile-loc2c.o)
	(compile-c-support.o): New targets.

gdb/doc/ChangeLog
2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Altering): Update.
	(Compiling and Injecting Code): New node.

gdb/testsuite/ChangeLog
2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Tom Tromey  <tromey@redhat.com>

	* configure.ac: Add gdb.compile/.
	* configure: Regenerate.
	* gdb.compile/Makefile.in: New file.
	* gdb.compile/compile-ops.exp: New file.
	* gdb.compile/compile-ops.c: New file.
	* gdb.compile/compile-tls.c: New file.
	* gdb.compile/compile-tls.exp: New file.
	* gdb.compile/compile-constvar.S: New file.
	* gdb.compile/compile-constvar.c: New file.
	* gdb.compile/compile-mod.c: New file.
	* gdb.compile/compile-nodebug.c: New file.
	* gdb.compile/compile-setjmp-mod.c: New file.
	* gdb.compile/compile-setjmp.c: New file.
	* gdb.compile/compile-setjmp.exp: New file.
	* gdb.compile/compile-shlib.c: New file.
	* gdb.compile/compile.c: New file.
	* gdb.compile/compile.exp: New file.
	* lib/gdb.exp (skip_compile_feature_tests): New proc.
---
 gdb/ChangeLog                                  |   55 +
 gdb/Makefile.in                                |   61 +
 gdb/NEWS                                       |   19 
 gdb/ada-lang.c                                 |    2 
 gdb/c-lang.c                                   |    8 
 gdb/c-lang.h                                   |   19 
 gdb/cli/cli-script.c                           |   31 +
 gdb/compile/compile-c-support.c                |  399 ++++++++
 gdb/compile/compile-c-symbols.c                |  759 ++++++++++++++++
 gdb/compile/compile-c-types.c                  |  438 +++++++++
 gdb/compile/compile-internal.h                 |  147 +++
 gdb/compile/compile-loc2c.c                    | 1148 ++++++++++++++++++++++++
 gdb/compile/compile-object-load.c              |  588 ++++++++++++
 gdb/compile/compile-object-load.h              |   39 +
 gdb/compile/compile-object-run.c               |  138 +++
 gdb/compile/compile-object-run.h               |   24 +
 gdb/compile/compile.c                          |  651 ++++++++++++++
 gdb/compile/compile.h                          |  102 ++
 gdb/d-lang.c                                   |    2 
 gdb/defs.h                                     |   28 +
 gdb/doc/ChangeLog                              |    6 
 gdb/doc/gdb.texinfo                            |  232 +++++
 gdb/dwarf2loc.c                                |   86 ++
 gdb/dwarf2loc.h                                |   21 
 gdb/f-lang.c                                   |    2 
 gdb/go-lang.c                                  |    2 
 gdb/jv-lang.c                                  |    2 
 gdb/language.c                                 |    6 
 gdb/language.h                                 |   31 +
 gdb/m2-lang.c                                  |    2 
 gdb/objc-lang.c                                |    2 
 gdb/opencl-lang.c                              |    2 
 gdb/p-lang.c                                   |    2 
 gdb/symtab.h                                   |   15 
 gdb/testsuite/ChangeLog                        |   23 
 gdb/testsuite/configure                        |    3 
 gdb/testsuite/configure.ac                     |    6 
 gdb/testsuite/gdb.compile/Makefile.in          |   21 
 gdb/testsuite/gdb.compile/compile-constvar.S   |   95 ++
 gdb/testsuite/gdb.compile/compile-constvar.c   |   18 
 gdb/testsuite/gdb.compile/compile-mod.c        |   26 +
 gdb/testsuite/gdb.compile/compile-nodebug.c    |   24 +
 gdb/testsuite/gdb.compile/compile-ops.c        |   37 +
 gdb/testsuite/gdb.compile/compile-ops.exp      |  424 +++++++++
 gdb/testsuite/gdb.compile/compile-setjmp-mod.c |   46 +
 gdb/testsuite/gdb.compile/compile-setjmp.c     |   24 +
 gdb/testsuite/gdb.compile/compile-setjmp.exp   |   34 +
 gdb/testsuite/gdb.compile/compile-shlib.c      |   26 +
 gdb/testsuite/gdb.compile/compile-tls.c        |   40 +
 gdb/testsuite/gdb.compile/compile-tls.exp      |   42 +
 gdb/testsuite/gdb.compile/compile.c            |  130 +++
 gdb/testsuite/gdb.compile/compile.exp          |  357 +++++++
 gdb/testsuite/lib/gdb.exp                      |   17 
 53 files changed, 6451 insertions(+), 11 deletions(-)
 create mode 100644 gdb/compile/compile-c-support.c
 create mode 100644 gdb/compile/compile-c-symbols.c
 create mode 100644 gdb/compile/compile-c-types.c
 create mode 100644 gdb/compile/compile-internal.h
 create mode 100644 gdb/compile/compile-loc2c.c
 create mode 100644 gdb/compile/compile-object-load.c
 create mode 100644 gdb/compile/compile-object-load.h
 create mode 100644 gdb/compile/compile-object-run.c
 create mode 100644 gdb/compile/compile-object-run.h
 create mode 100644 gdb/compile/compile.c
 create mode 100644 gdb/compile/compile.h
 create mode 100644 gdb/testsuite/gdb.compile/Makefile.in
 create mode 100644 gdb/testsuite/gdb.compile/compile-constvar.S
 create mode 100644 gdb/testsuite/gdb.compile/compile-constvar.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-mod.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-nodebug.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-ops.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-ops.exp
 create mode 100644 gdb/testsuite/gdb.compile/compile-setjmp-mod.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-setjmp.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-setjmp.exp
 create mode 100644 gdb/testsuite/gdb.compile/compile-shlib.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-tls.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-tls.exp
 create mode 100644 gdb/testsuite/gdb.compile/compile.c
 create mode 100644 gdb/testsuite/gdb.compile/compile.exp

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 830593f..e175b0c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,58 @@
+2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
+	    Jan Kratochvil  <jan.kratochvil@redhat.com>
+	    Tom Tromey  <tromey@redhat.com>
+
+	* NEWS: Update.
+	* symtab.h (struct symbol_computed_ops) <generate_c_location>: New
+	field.
+	* p-lang.c (pascal_language_defn): Update.
+	* opencl-lang.c (opencl_language_defn): Update.
+	* objc-lang.c (objc_language_defn): Update.
+	* m2-lang.c (m2_language_defn): Update.
+	* language.h (struct language_defn) <la_get_compile_instance,
+	la_compute_program>: New fields.
+	* language.c (unknown_language_defn, auto_language_defn)
+	(local_language_defn): Update.
+	* jv-lang.c (java_language_defn): Update.
+	* go-lang.c (go_language_defn): Update.
+	* f-lang.c (f_language_defn): Update.
+	* dwarf2loc.h (dwarf2_compile_property_to_c): Declare.
+	* dwarf2loc.c (dwarf2_compile_property_to_c)
+	(locexpr_generate_c_location, loclist_generate_c_location): New
+	functions.
+	(dwarf2_locexpr_funcs, dwarf2_loclist_funcs): Update.
+	* defs.h (enum compile_i_scope_types): New.
+	(enum command_control_type) <compile_control>: New constant.
+	(struct command_line) <control_u>: New field.
+	* d-lang.c (d_language_defn): Update.
+	* compile/compile.c: New file.
+	* compile/compile-c-support.c: New file.
+	* compile/compile-c-symbols.c: New file.
+	* compile/compile-c-types.c: New file.
+	* compile/compile.h: New file.
+	* compile/compile-internal.h: New file.
+	* compile/compile-loc2c.c: New file.
+	* compile/compile-object-load.c: New file.
+	* compile/compile-object-load.h: New file.
+	* compile/compile-object-run.c: New file.
+	* compile/compile-object-run.h: New file.
+	* cli/cli-script.c (multi_line_command_p, print_command_lines)
+	(execute_control_command, process_next_line)
+	(recurse_read_control_structure): Handle compile_control.
+	* c-lang.h (c_get_compile_context, c_compute_program): Declare.
+	* c-lang.c (c_language_defn, cplus_language_defn)
+	(asm_language_defn, minimal_language_defn): Update.
+	* ada-lang.c (ada_language_defn): Update.
+	* Makefile.in (SUBDIR_GCC_COMPILE_OBS, SUBDIR_GCC_COMPILE_SRCS):
+	New variables.
+	(SFILES): Add SUBDIR_GCC_COMPILE_SRCS.
+	(HFILES_NO_SRCDIR): Add compile.h.
+	(COMMON_OBS): Add SUBDIR_GCC_COMPILE_OBS.
+	(INIT_FILES): Add SUBDIR_GCC_COMPILE_SRCS.
+	(compile.o, compile-c-types.o, compile-c-symbols.o)
+	(compile-object-load.o, compile-object-run.o, compile-loc2c.o)
+	(compile-c-support.o): New targets.
+
 2014-10-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	* s390-linux-tdep.c (s390_gcc_target_options): New function.
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 1da8af6..7d1b809 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -280,6 +280,24 @@ SUBDIR_TUI_LDFLAGS=
 SUBDIR_TUI_CFLAGS= \
 	-DTUI=1
 
+#
+# GCC Compile support sub-directory definitions
+#
+SUBDIR_GCC_COMPILE_OBS = \
+	compile.o compile-c-symbols.o compile-c-types.o \
+	compile-object-load.o compile-object-run.o \
+	compile-loc2c.o compile-c-support.o
+SUBDIR_GCC_COMPILE_SRCS = \
+	compile/compile.c \
+	compile/compile-c-symbols.c \
+	compile/compile-c-types.c \
+	compile/compile-object-load.c \
+	compile/compile-object-load.h \
+	compile/compile-object-run.c \
+	compile/compile-object-run.h \
+	compile/compile-loc2c.c \
+	compile/compile-c-support.c
+
 # Guile sub directory definitons for guile support.
 
 SUBDIR_GUILE_OBS = \
@@ -852,7 +870,8 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	common/ptid.c common/buffer.c gdb-dlfcn.c common/agent.c \
 	common/format.c common/filestuff.c btrace.c record-btrace.c ctf.c \
 	target/waitstatus.c common/print-utils.c common/rsp-low.c \
-	common/errors.c common/common-debug.c common/common-exceptions.c
+	common/errors.c common/common-debug.c common/common-exceptions.c \
+	$(SUBDIR_GCC_COMPILE_SRCS)
 
 LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
 
@@ -874,7 +893,7 @@ nto-tdep.h serial.h \
 c-lang.h d-lang.h go-lang.h frame.h event-loop.h block.h cli/cli-setshow.h \
 cli/cli-decode.h cli/cli-cmds.h cli/cli-utils.h \
 cli/cli-script.h macrotab.h symtab.h common/version.h \
-gnulib/import/string.in.h gnulib/import/str-two-way.h \
+compile/compile.h gnulib/import/string.in.h gnulib/import/str-two-way.h \
 gnulib/import/stdint.in.h remote.h remote-notif.h gdb.h sparc-nat.h \
 gdbthread.h dwarf2-frame.h dwarf2-frame-tailcall.h nbsd-nat.h dcache.h \
 amd64-nat.h s390-linux-tdep.h arm-linux-tdep.h exceptions.h macroscope.h \
@@ -1039,7 +1058,8 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
 	format.o registry.o btrace.o record-btrace.o waitstatus.o \
 	print-utils.o rsp-low.o errors.o common-debug.o debug.o \
-	common-exceptions.o
+	common-exceptions.o \
+	$(SUBDIR_GCC_COMPILE_OBS)
 
 TSOBS = inflow.o
 
@@ -1282,7 +1302,7 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
 # duplicates.  Files in the gdb/ directory can end up appearing in
 # COMMON_OBS (as a .o file) and CONFIG_SRCS (as a .c file).
 
-INIT_FILES = $(COMMON_OBS) $(TSOBS) $(CONFIG_SRCS)
+INIT_FILES = $(COMMON_OBS) $(TSOBS) $(CONFIG_SRCS) $(SUBDIR_GCC_COMPILE_SRCS)
 init.c: $(INIT_FILES)
 	@echo Making init.c
 	@rm -f init.c-tmp init.l-tmp
@@ -1914,6 +1934,39 @@ cli-utils.o: $(srcdir)/cli/cli-utils.c
 	$(COMPILE) $(srcdir)/cli/cli-utils.c
 	$(POSTCOMPILE)
 
+# GCC Compile support dependencies
+#
+# Need to explicitly specify the compile rule as make will do nothing
+# or try to compile the object file into the sub-directory.
+
+compile.o: $(srcdir)/compile/compile.c
+	$(COMPILE) $(srcdir)/compile/compile.c
+	$(POSTCOMPILE)
+
+compile-c-types.o: $(srcdir)/compile/compile-c-types.c
+	$(COMPILE) $(srcdir)/compile/compile-c-types.c
+	$(POSTCOMPILE)
+
+compile-c-symbols.o: $(srcdir)/compile/compile-c-symbols.c
+	$(COMPILE) $(srcdir)/compile/compile-c-symbols.c
+	$(POSTCOMPILE)
+
+compile-object-load.o: $(srcdir)/compile/compile-object-load.c
+	$(COMPILE) $(srcdir)/compile/compile-object-load.c
+	$(POSTCOMPILE)
+
+compile-object-run.o: $(srcdir)/compile/compile-object-run.c
+	$(COMPILE) $(srcdir)/compile/compile-object-run.c
+	$(POSTCOMPILE)
+
+compile-loc2c.o: $(srcdir)/compile/compile-loc2c.c
+	$(COMPILE) $(srcdir)/compile/compile-loc2c.c
+	$(POSTCOMPILE)
+
+compile-c-support.o: $(srcdir)/compile/compile-c-support.c
+	$(COMPILE) $(srcdir)/compile/compile-c-support.c
+	$(POSTCOMPILE)
+
 
 #
 # GDBTK sub-directory
diff --git a/gdb/NEWS b/gdb/NEWS
index d6a8b61..21410a5 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -22,11 +22,30 @@
   ** $_any_caller_is(name [, number_of_frames])
   ** $_any_caller_matches(regexp [, number_of_frames])
 
+* GDB now supports the compilation and injection of source code into
+  the inferior.  GDB will use GCC 5.0 or higher built with libcc1.so
+  to compile the source code to object code, and if successful, inject
+  and execute that code within the current context of the inferior.
+  Currently the C language is supported.  The commands used to
+  interface with this new feature are:
+
+     compile code [-raw|-r] [--] [source code]
+     compile file [-raw|-r] filename
+
 * New commands
 
 queue-signal signal-name-or-number
   Queue a signal to be delivered to the thread when it is resumed.
 
+compile code [-r|-raw] [--] [source code]
+  Compile, inject, and execute in the inferior the executable object
+  code produced by compiling the provided source code.
+
+compile file [-r|-raw] filename
+  Compile and inject into the inferior the executable object code
+  produced by compiling the source code stored in the filename
+  provided.
+
 * On resume, GDB now always passes the signal the program had stopped
   for to the thread the signal was sent to, even if the user changed
   threads before resuming.  Previously GDB would often (but not
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3a024d9..69b43f6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13630,6 +13630,8 @@ const struct language_defn ada_language_defn = {
   ada_get_symbol_name_cmp,	/* la_get_symbol_name_cmp */
   ada_iterate_over_symbols,
   &ada_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 1353eea..e8283e3 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -865,6 +865,8 @@ const struct language_defn c_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &c_varobj_ops,
+  c_get_compile_context,
+  c_compute_program,
   LANG_MAGIC
 };
 
@@ -990,6 +992,8 @@ const struct language_defn cplus_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &cplus_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
@@ -1033,6 +1037,8 @@ const struct language_defn asm_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
@@ -1081,6 +1087,8 @@ const struct language_defn minimal_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/c-lang.h b/gdb/c-lang.h
index 76bd426..5a2f878 100644
--- a/gdb/c-lang.h
+++ b/gdb/c-lang.h
@@ -141,5 +141,24 @@ extern int cp_is_vtbl_member (struct type *);
 
 extern int c_textual_element_type (struct type *, char);
 
+/* Create a new instance of the C compiler and return it.  The new
+   compiler is owned by the caller and must be freed using the destroy
+   method.  This function never returns NULL, but rather throws an
+   exception on failure.  This is suitable for use as the
+   la_get_compile_instance language method.  */
+
+extern struct compile_instance *c_get_compile_context (void);
+
+/* This takes the user-supplied text and returns a newly malloc'd bit
+   of code to compile.
+
+   This is used as the la_compute_program language method; see that
+   for a description of the arguments.  */
+
+extern char *c_compute_program (struct compile_instance *inst,
+				const char *input,
+				struct gdbarch *gdbarch,
+				const struct block *expr_block,
+				CORE_ADDR expr_pc);
 
 #endif /* !defined (C_LANG_H) */
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index f8ff58d..779c8dc 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -31,6 +31,7 @@
 
 #include "extension.h"
 #include "interps.h"
+#include "compile/compile.h"
 
 /* Prototypes for local functions.  */
 
@@ -87,6 +88,7 @@ multi_line_command_p (enum command_control_type type)
     case while_control:
     case while_stepping_control:
     case commands_control:
+    case compile_control:
     case python_control:
     case guile_control:
       return 1;
@@ -272,6 +274,19 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
 	  continue;
 	}
 
+      if (list->control_type == compile_control)
+	{
+	  ui_out_field_string (uiout, NULL, "compile expression");
+	  ui_out_text (uiout, "\n");
+	  print_command_lines (uiout, *list->body_list, 0);
+	  if (depth)
+	    ui_out_spaces (uiout, 2 * depth);
+	  ui_out_field_string (uiout, NULL, "end");
+	  ui_out_text (uiout, "\n");
+	  list = list->next;
+	  continue;
+	}
+
       if (list->control_type == guile_control)
 	{
 	  ui_out_field_string (uiout, NULL, "guile");
@@ -599,6 +614,11 @@ execute_control_command (struct command_line *cmd)
 	break;
       }
 
+    case compile_control:
+      eval_compile_command (cmd, NULL, cmd->control_u.compile.scope);
+      ret = simple_control;
+      break;
+
     case python_control:
     case guile_control:
       {
@@ -1040,6 +1060,14 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
 	     here.  */
 	  *command = build_command_line (python_control, "");
 	}
+      else if (p_end - p == 6 && !strncmp (p, "compile", 7))
+	{
+	  /* Note that we ignore the inline "compile command" form
+	     here.  */
+	  *command = build_command_line (compile_control, "");
+	  (*command)->control_u.compile.scope = COMPILE_I_INVALID_SCOPE;
+	}
+
       else if (p_end - p == 5 && !strncmp (p, "guile", 5))
 	{
 	  /* Note that we ignore the inline "guile command" form here.  */
@@ -1133,7 +1161,8 @@ recurse_read_control_structure (char * (*read_next_line_func) (void),
       next = NULL;
       val = process_next_line (read_next_line_func (), &next, 
 			       current_cmd->control_type != python_control
-			       && current_cmd->control_type != guile_control,
+			       && current_cmd->control_type != guile_control
+			       && current_cmd->control_type != compile_control,
 			       validator, closure);
 
       /* Just skip blanks and comments.  */
diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c
new file mode 100644
index 0000000..48a81cb
--- /dev/null
+++ b/gdb/compile/compile-c-support.c
@@ -0,0 +1,399 @@
+/* C language support for compilation.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "compile-internal.h"
+#include "compile.h"
+#include "gdb-dlfcn.h"
+#include "c-lang.h"
+#include "macrotab.h"
+#include "macroscope.h"
+#include "regcache.h"
+
+/* See compile-internal.h.  */
+
+const char *
+c_get_mode_for_size (int size)
+{
+  const char *mode = NULL;
+
+  switch (size)
+    {
+    case 1:
+      mode = "QI";
+      break;
+    case 2:
+      mode = "HI";
+      break;
+    case 4:
+      mode = "SI";
+      break;
+    case 8:
+      mode = "DI";
+      break;
+    default:
+      internal_error (__FILE__, __LINE__, _("Invalid GCC mode size %d."), size);
+    }
+
+  return mode;
+}
+
+/* See compile-internal.h.  */
+
+char *
+c_get_range_decl_name (const struct dynamic_prop *prop)
+{
+  return xstrprintf ("__gdb_prop_%s", host_address_to_string (prop));
+}
+
+\f
+
+#define STR(x) #x
+#define STRINGIFY(x) STR(x)
+
+/* Helper function for c_get_compile_context.  Open the GCC front-end
+   shared library and return the symbol specified by the current
+   GCC_C_FE_CONTEXT.  */
+
+static gcc_c_fe_context_function *
+load_libcc (void)
+{
+  void *handle;
+  gcc_c_fe_context_function *func;
+
+   /* gdb_dlopen will call error () on an error, so no need to check
+      value.  */
+  handle = gdb_dlopen (STRINGIFY (GCC_C_FE_LIBCC));
+  func = (gcc_c_fe_context_function *) gdb_dlsym (handle,
+						  STRINGIFY (GCC_C_FE_CONTEXT));
+
+  if (func == NULL)
+    error (_("could not find symbol %s in library %s"),
+	   STRINGIFY (GCC_C_FE_CONTEXT),
+	   STRINGIFY (GCC_C_FE_LIBCC));
+  return func;
+}
+
+/* Return the compile instance associated with the current context.
+   This function calls the symbol returned from the load_libcc
+   function.  This will provide the gcc_c_context.  */
+
+struct compile_instance *
+c_get_compile_context (void)
+{
+  static gcc_c_fe_context_function *func;
+
+  struct gcc_c_context *context;
+
+  if (func == NULL)
+    {
+      func = load_libcc ();
+      gdb_assert (func != NULL);
+    }
+
+  context = (*func) (GCC_FE_VERSION_0, GCC_C_FE_VERSION_0);
+  if (context == NULL)
+    error (_("The loaded version of GCC does not support the required version "
+	     "of the API."));
+
+  return new_compile_instance (context);
+}
+
+\f
+
+/* Write one macro definition.  */
+
+static void
+print_one_macro (const char *name, const struct macro_definition *macro,
+		 struct macro_source_file *source, int line,
+		 void *user_data)
+{
+  struct ui_file *file = user_data;
+
+  /* Don't print command-line defines.  They will be supplied another
+     way.  */
+  if (line == 0)
+    return;
+
+  fprintf_filtered (file, "#define %s", name);
+
+  if (macro->kind == macro_function_like)
+    {
+      int i;
+
+      fputs_filtered ("(", file);
+      for (i = 0; i < macro->argc; i++)
+	{
+	  fputs_filtered (macro->argv[i], file);
+	  if (i + 1 < macro->argc)
+	    fputs_filtered (", ", file);
+	}
+      fputs_filtered (")", file);
+    }
+
+  fprintf_filtered (file, " %s\n", macro->replacement);
+}
+
+/* Write macro definitions at PC to FILE.  */
+
+static void
+write_macro_definitions (const struct block *block, CORE_ADDR pc,
+			 struct ui_file *file)
+{
+  struct macro_scope *scope;
+
+  if (block != NULL)
+    scope = sal_macro_scope (find_pc_line (pc, 0));
+  else
+    scope = default_macro_scope ();
+  if (scope == NULL)
+    scope = user_macro_scope ();
+
+  if (scope != NULL && scope->file != NULL && scope->file->table != NULL)
+    macro_for_each_in_scope (scope->file, scope->line, print_one_macro, file);
+}
+
+/* Helper function to construct a header scope for a block of code.
+   Takes a scope argument which selects the correct header to
+   insert into BUF.  */
+
+static void
+add_code_header (enum compile_i_scope_types type, struct ui_file *buf)
+{
+  switch (type)
+    {
+    case COMPILE_I_SIMPLE_SCOPE:
+      fputs_unfiltered ("void "
+			GCC_FE_WRAPPER_FUNCTION
+			" (struct "
+			COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG
+			" *"
+			COMPILE_I_SIMPLE_REGISTER_ARG_NAME
+			") {\n",
+			buf);
+      break;
+    case COMPILE_I_RAW_SCOPE:
+      break;
+    default:
+      gdb_assert_not_reached (_("Unknown compiler scope reached."));
+    }
+}
+
+/* Helper function to construct a footer scope for a block of code.
+   Takes a scope argument which selects the correct footer to
+   insert into BUF.  */
+
+static void
+add_code_footer (enum compile_i_scope_types type, struct ui_file *buf)
+{
+  switch (type)
+    {
+    case COMPILE_I_SIMPLE_SCOPE:
+      fputs_unfiltered ("}\n", buf);
+      break;
+    case COMPILE_I_RAW_SCOPE:
+      break;
+    default:
+      gdb_assert_not_reached (_("Unknown compiler scope reached."));
+    }
+}
+
+/* Generate a structure holding all the registers used by the function
+   we're generating.  */
+
+static void
+generate_register_struct (struct ui_file *stream, struct gdbarch *gdbarch,
+			  const unsigned char *registers_used)
+{
+  int i;
+  int seen = 0;
+
+  fputs_unfiltered ("struct " COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG " {\n",
+		    stream);
+
+  if (registers_used != NULL)
+    for (i = 0; i < gdbarch_num_regs (gdbarch); ++i)
+      {
+	if (registers_used[i])
+	  {
+	    struct type *regtype = check_typedef (register_type (gdbarch, i));
+	    char *regname = compile_register_name_mangled (gdbarch, i);
+	    struct cleanup *cleanups = make_cleanup (xfree, regname);
+
+	    seen = 1;
+
+	    /* You might think we could use type_print here.  However,
+	       target descriptions often use types with names like
+	       "int64_t", which may not be defined in the inferior
+	       (and in any case would not be looked up due to the
+	       #pragma business).  So, we take a much simpler
+	       approach: for pointer- or integer-typed registers, emit
+	       the field in the most direct way; and for other
+	       register types (typically flags or vectors), emit a
+	       maximally-aligned array of the correct size.  */
+
+	    fputs_unfiltered ("  ", stream);
+	    switch (TYPE_CODE (regtype))
+	      {
+	      case TYPE_CODE_PTR:
+		fprintf_filtered (stream, "void *%s", regname);
+		break;
+
+	      case TYPE_CODE_INT:
+		{
+		  const char *mode
+		    = c_get_mode_for_size (TYPE_LENGTH (regtype));
+
+		  if (mode != NULL)
+		    {
+		      if (TYPE_UNSIGNED (regtype))
+			fputs_unfiltered ("unsigned ", stream);
+		      fprintf_unfiltered (stream,
+					  "int %s"
+					  " __attribute__ ((__mode__(__%s__)))",
+					  regname,
+					  mode);
+		      break;
+		    }
+		}
+
+		/* Fall through.  */
+
+	      default:
+		fprintf_unfiltered (stream,
+				    "  unsigned char %s[%d]"
+				    " __attribute__((__aligned__("
+				    "__BIGGEST_ALIGNMENT__)))",
+				    regname,
+				    TYPE_LENGTH (regtype));
+	      }
+	    fputs_unfiltered (";\n", stream);
+
+	    do_cleanups (cleanups);
+	  }
+      }
+
+  if (!seen)
+    fputs_unfiltered ("  char " COMPILE_I_SIMPLE_REGISTER_DUMMY ";\n",
+		      stream);
+
+  fputs_unfiltered ("};\n\n", stream);
+}
+
+/* Take the source code provided by the user with the 'compile'
+   command, and compute the additional wrapping, macro, variable and
+   register operations needed.  INPUT is the source code derived from
+   the 'compile' command, GDBARCH is the architecture to use when
+   computing above, EXPR_BLOCK denotes the block relevant contextually
+   to the inferior when the expression was created, and EXPR_PC
+   indicates the value of $PC.  */
+
+char *
+c_compute_program (struct compile_instance *inst,
+		   const char *input,
+		   struct gdbarch *gdbarch,
+		   const struct block *expr_block,
+		   CORE_ADDR expr_pc)
+{
+  struct ui_file *buf, *var_stream = NULL;
+  char *code;
+  struct cleanup *cleanup;
+  struct compile_c_instance *context = (struct compile_c_instance *) inst;
+
+  buf = mem_fileopen ();
+  cleanup = make_cleanup_ui_file_delete (buf);
+
+  write_macro_definitions (expr_block, expr_pc, buf);
+
+  /* Do not generate local variable information for "raw"
+     compilations.  In this case we aren't emitting our own function
+     and the user's code may only refer to globals.  */
+  if (inst->scope != COMPILE_I_RAW_SCOPE)
+    {
+      unsigned char *registers_used;
+      int i;
+
+      /* Generate the code to compute variable locations, but do it
+	 before generating the function header, so we can define the
+	 register struct before the function body.  This requires a
+	 temporary stream.  */
+      var_stream = mem_fileopen ();
+      make_cleanup_ui_file_delete (var_stream);
+      registers_used = generate_c_for_variable_locations (context,
+							  var_stream, gdbarch,
+							  expr_block, expr_pc);
+      make_cleanup (xfree, registers_used);
+
+      generate_register_struct (buf, gdbarch, registers_used);
+
+      fputs_unfiltered ("typedef unsigned int"
+			" __attribute__ ((__mode__(__pointer__)))"
+			" __gdb_uintptr;\n",
+			buf);
+      fputs_unfiltered ("typedef int"
+			" __attribute__ ((__mode__(__pointer__)))"
+			" __gdb_intptr;\n",
+			buf);
+
+      // Iterate all log2 sizes in bytes supported by c_get_mode_for_size.
+      for (i = 0; i < 4; ++i)
+	{
+	  const char *mode = c_get_mode_for_size (1 << i);
+
+	  gdb_assert (mode != NULL);
+	  fprintf_unfiltered (buf,
+			      "typedef int"
+			      " __attribute__ ((__mode__(__%s__)))"
+			      " __gdb_int_%s;\n",
+			      mode, mode);
+	}
+    }
+
+  add_code_header (inst->scope, buf);
+
+  if (inst->scope == COMPILE_I_SIMPLE_SCOPE)
+    {
+      ui_file_put (var_stream, ui_file_write_for_put, buf);
+      fputs_unfiltered ("#pragma GCC user_expression\n", buf);
+    }
+
+  /* The user expression has to be in its own scope, so that "extern"
+     works properly.  Otherwise gcc thinks that the "extern"
+     declaration is in the same scope as the declaration provided by
+     gdb.  */
+  if (inst->scope != COMPILE_I_RAW_SCOPE)
+    fputs_unfiltered ("{\n", buf);
+
+  fputs_unfiltered ("#line 1 \"gdb command line\"\n", buf);
+  fputs_unfiltered (input, buf);
+  fputs_unfiltered ("\n", buf);
+
+  /* For larger user expressions the automatic semicolons may be
+     confusing.  */
+  if (strchr (input, '\n') == NULL)
+    fputs_unfiltered (";\n", buf);
+
+  if (inst->scope != COMPILE_I_RAW_SCOPE)
+    fputs_unfiltered ("}\n", buf);
+
+  add_code_footer (inst->scope, buf);
+  code = ui_file_xstrdup (buf, NULL);
+  do_cleanups (cleanup);
+  return code;
+}
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
new file mode 100644
index 0000000..b489c74
--- /dev/null
+++ b/gdb/compile/compile-c-symbols.c
@@ -0,0 +1,759 @@
+/* Convert symbols from GDB to GCC
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+#include "defs.h"
+#include "compile-internal.h"
+#include "gdb_assert.h"
+#include "symtab.h"
+#include "parser-defs.h"
+#include "block.h"
+#include "objfiles.h"
+#include "compile.h"
+#include "value.h"
+#include "exceptions.h"
+#include "gdbtypes.h"
+#include "dwarf2loc.h"
+
+\f
+
+/* Object of this type are stored in the compiler's symbol_err_map.  */
+
+struct symbol_error
+{
+  /* The symbol.  */
+
+  const struct symbol *sym;
+
+  /* The error message to emit.  This is malloc'd and owned by the
+     hash table.  */
+
+  char *message;
+};
+
+/* Hash function for struct symbol_error.  */
+
+static hashval_t
+hash_symbol_error (const void *a)
+{
+  const struct symbol_error *se = a;
+
+  return htab_hash_pointer (se->sym);
+}
+
+/* Equality function for struct symbol_error.  */
+
+static int
+eq_symbol_error (const void *a, const void *b)
+{
+  const struct symbol_error *sea = a;
+  const struct symbol_error *seb = b;
+
+  return sea->sym == seb->sym;
+}
+
+/* Deletion function for struct symbol_error.  */
+
+static void
+del_symbol_error (void *a)
+{
+  struct symbol_error *se = a;
+
+  xfree (se->message);
+  xfree (se);
+}
+
+/* Associate SYMBOL with some error text.  */
+
+static void
+insert_symbol_error (htab_t hash, const struct symbol *sym, const char *text)
+{
+  struct symbol_error e;
+  void **slot;
+
+  e.sym = sym;
+  slot = htab_find_slot (hash, &e, INSERT);
+  if (*slot == NULL)
+    {
+      struct symbol_error *e = XNEW (struct symbol_error);
+
+      e->sym = sym;
+      e->message = xstrdup (text);
+      *slot = e;
+    }
+}
+
+/* Emit the error message corresponding to SYM, if one exists, and
+   arrange for it not to be emitted again.  */
+
+static void
+error_symbol_once (struct compile_c_instance *context,
+		   const struct symbol *sym)
+{
+  struct symbol_error search;
+  struct symbol_error *err;
+  char *message;
+
+  if (context->symbol_err_map == NULL)
+    return;
+
+  search.sym = sym;
+  err = htab_find (context->symbol_err_map, &search);
+  if (err == NULL || err->message == NULL)
+    return;
+
+  message = err->message;
+  err->message = NULL;
+  make_cleanup (xfree, message);
+  error (_("%s"), message);
+}
+
+\f
+
+/* Compute the name of the pointer representing a local symbol's
+   address.  */
+
+static char *
+symbol_substitution_name (struct symbol *sym)
+{
+  return concat ("__", SYMBOL_NATURAL_NAME (sym), "_ptr", (char *) NULL);
+}
+
+/* Convert a given symbol, SYM, to the compiler's representation.
+   CONTEXT is the compiler instance.  IS_GLOBAL is true if the
+   symbol came from the global scope.  IS_LOCAL is true if the symbol
+   came from a local scope.  (Note that the two are not strictly
+   inverses because the symbol might have come from the static
+   scope.)  */
+
+static void
+convert_one_symbol (struct compile_c_instance *context,
+		    struct symbol *sym,
+		    int is_global,
+		    int is_local)
+{
+  gcc_type sym_type;
+  const char *filename = SYMBOL_SYMTAB (sym)->filename;
+  unsigned short line = SYMBOL_LINE (sym);
+
+  error_symbol_once (context, sym);
+
+  if (SYMBOL_CLASS (sym) == LOC_LABEL)
+    sym_type = 0;
+  else
+    sym_type = convert_type (context, SYMBOL_TYPE (sym));
+
+  if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN)
+    {
+      /* Binding a tag, so we don't need to build a decl.  */
+      C_CTX (context)->c_ops->tagbind (C_CTX (context),
+				       SYMBOL_NATURAL_NAME (sym),
+				       sym_type, filename, line);
+    }
+  else
+    {
+      gcc_decl decl;
+      enum gcc_c_symbol_kind kind;
+      CORE_ADDR addr = 0;
+      char *symbol_name = NULL;
+
+      switch (SYMBOL_CLASS (sym))
+	{
+	case LOC_TYPEDEF:
+	  kind = GCC_C_SYMBOL_TYPEDEF;
+	  break;
+
+	case LOC_LABEL:
+	  kind = GCC_C_SYMBOL_LABEL;
+	  addr = SYMBOL_VALUE_ADDRESS (sym);
+	  break;
+
+	case LOC_BLOCK:
+	  kind = GCC_C_SYMBOL_FUNCTION;
+	  addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
+	  break;
+
+	case LOC_CONST:
+	  if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM)
+	    {
+	      /* Already handled by convert_enum.  */
+	      return;
+	    }
+	  C_CTX (context)->c_ops->build_constant (C_CTX (context), sym_type,
+						  SYMBOL_NATURAL_NAME (sym),
+						  SYMBOL_VALUE (sym),
+						  filename, line);
+	  return;
+
+	case LOC_CONST_BYTES:
+	  error (_("Unsupported LOC_CONST_BYTES for symbol \"%s\"."),
+		 SYMBOL_PRINT_NAME (sym));
+
+	case LOC_UNDEF:
+	  internal_error (__FILE__, __LINE__, _("LOC_UNDEF found for \"%s\"."),
+			  SYMBOL_PRINT_NAME (sym));
+
+	case LOC_COMMON_BLOCK:
+	  error (_("Fortran common block is unsupported for compilation "
+		   "evaluaton of symbol \"%s\"."),
+		 SYMBOL_PRINT_NAME (sym));
+
+	case LOC_OPTIMIZED_OUT:
+	  error (_("Symbol \"%s\" cannot be used for compilation evaluation "
+		   "as it is optimized out."),
+		 SYMBOL_PRINT_NAME (sym));
+
+	case LOC_COMPUTED:
+	  if (is_local)
+	    goto substitution;
+	  /* Probably TLS here.  */
+	  warning (_("Symbol \"%s\" is thread-local and currently can only "
+		     "be referenced from the current thread in "
+		     "compiled code."),
+		   SYMBOL_PRINT_NAME (sym));
+	  /* FALLTHROUGH */
+	case LOC_UNRESOLVED:
+	  /* 'symbol_name' cannot be used here as that one is used only for
+	     local variables from compile_dwarf_expr_to_c.
+	     Global variables can be accessed by GCC only by their address, not
+	     by their name.  */
+	  {
+	    struct value *val;
+	    struct frame_info *frame = NULL;
+
+	    if (symbol_read_needs_frame (sym))
+	      {
+		frame = get_selected_frame (NULL);
+		if (frame == NULL)
+		  error (_("Symbol \"%s\" cannot be used because "
+			   "there is no selected frame"),
+			 SYMBOL_PRINT_NAME (sym));
+	      }
+
+	    val = read_var_value (sym, frame);
+	    if (VALUE_LVAL (val) != lval_memory)
+	      error (_("Symbol \"%s\" cannot be used for compilation "
+		       "evaluation as its address has not been found."),
+		     SYMBOL_PRINT_NAME (sym));
+
+	    kind = GCC_C_SYMBOL_VARIABLE;
+	    addr = value_address (val);
+	  }
+	  break;
+
+
+	case LOC_REGISTER:
+	case LOC_ARG:
+	case LOC_REF_ARG:
+	case LOC_REGPARM_ADDR:
+	case LOC_LOCAL:
+	substitution:
+	  kind = GCC_C_SYMBOL_VARIABLE;
+	  symbol_name = symbol_substitution_name (sym);
+	  break;
+
+	case LOC_STATIC:
+	  kind = GCC_C_SYMBOL_VARIABLE;
+	  addr = SYMBOL_VALUE_ADDRESS (sym);
+	  break;
+
+	case LOC_FINAL_VALUE:
+	default:
+	  gdb_assert_not_reached ("Unreachable case in convert_one_symbol.");
+
+	}
+
+      /* Don't emit local variable decls for a raw expression.  */
+      if (context->base.scope != COMPILE_I_RAW_SCOPE
+	  || symbol_name == NULL)
+	{
+	  decl = C_CTX (context)->c_ops->build_decl (C_CTX (context),
+						     SYMBOL_NATURAL_NAME (sym),
+						     kind,
+						     sym_type,
+						     symbol_name, addr,
+						     filename, line);
+
+	  C_CTX (context)->c_ops->bind (C_CTX (context), decl, is_global);
+	}
+
+      xfree (symbol_name);
+    }
+}
+
+/* Convert a full symbol to its gcc form.  CONTEXT is the compiler to
+   use, IDENTIFIER is the name of the symbol, SYM is the symbol
+   itself, and DOMAIN is the domain which was searched.  */
+
+static void
+convert_symbol_sym (struct compile_c_instance *context, const char *identifier,
+		    struct symbol *sym, domain_enum domain)
+{
+  const struct block *static_block, *found_block;
+  int is_local_symbol;
+
+  found_block = block_found;
+
+  /* If we found a symbol and it is not in the  static or global
+     scope, then we should first convert any static or global scope
+     symbol of the same name.  This lets this unusual case work:
+
+     int x; // Global.
+     int func(void)
+     {
+     int x;
+     // At this spot, evaluate "extern int x; x"
+     }
+  */
+
+  static_block = block_static_block (found_block);
+  /* STATIC_BLOCK is NULL if FOUND_BLOCK is the global block.  */
+  is_local_symbol = (found_block != static_block && static_block != NULL);
+  if (is_local_symbol)
+    {
+      struct symbol *global_sym;
+
+      global_sym = lookup_symbol (identifier, NULL, domain, NULL);
+      /* If the outer symbol is in the static block, we ignore it, as
+	 it cannot be referenced.  */
+      if (global_sym != NULL
+	  && block_found != block_static_block (block_found))
+	{
+	  if (compile_debug)
+	    fprintf_unfiltered (gdb_stdout,
+				"gcc_convert_symbol \"%s\": global symbol\n",
+				identifier);
+	  convert_one_symbol (context, global_sym, 1, 0);
+	}
+    }
+
+  if (compile_debug)
+    fprintf_unfiltered (gdb_stdout,
+			"gcc_convert_symbol \"%s\": local symbol\n",
+			identifier);
+  convert_one_symbol (context, sym, 0, is_local_symbol);
+}
+
+/* Convert a minimal symbol to its gcc form.  CONTEXT is the compiler
+   to use and BMSYM is the minimal symbol to convert.  */
+
+static void
+convert_symbol_bmsym (struct compile_c_instance *context,
+		      struct bound_minimal_symbol bmsym)
+{
+  struct minimal_symbol *msym = bmsym.minsym;
+  struct objfile *objfile = bmsym.objfile;
+  struct type *type;
+  enum gcc_c_symbol_kind kind;
+  gcc_type sym_type;
+  gcc_decl decl;
+  CORE_ADDR addr;
+
+  /* Conversion copied from write_exp_msymbol.  */
+  switch (MSYMBOL_TYPE (msym))
+    {
+    case mst_text:
+    case mst_file_text:
+    case mst_solib_trampoline:
+      type = objfile_type (objfile)->nodebug_text_symbol;
+      kind = GCC_C_SYMBOL_FUNCTION;
+      break;
+
+    case mst_text_gnu_ifunc:
+      type = objfile_type (objfile)->nodebug_text_gnu_ifunc_symbol;
+      kind = GCC_C_SYMBOL_FUNCTION;
+      break;
+
+    case mst_data:
+    case mst_file_data:
+    case mst_bss:
+    case mst_file_bss:
+      type = objfile_type (objfile)->nodebug_data_symbol;
+      kind = GCC_C_SYMBOL_VARIABLE;
+      break;
+
+    case mst_slot_got_plt:
+      type = objfile_type (objfile)->nodebug_got_plt_symbol;
+      kind = GCC_C_SYMBOL_FUNCTION;
+      break;
+
+    default:
+      type = objfile_type (objfile)->nodebug_unknown_symbol;
+      kind = GCC_C_SYMBOL_VARIABLE;
+      break;
+    }
+
+  sym_type = convert_type (context, type);
+  addr = MSYMBOL_VALUE_ADDRESS (objfile, msym);
+  decl = C_CTX (context)->c_ops->build_decl (C_CTX (context),
+					     MSYMBOL_NATURAL_NAME (msym),
+					     kind, sym_type, NULL, addr,
+					     NULL, 0);
+  C_CTX (context)->c_ops->bind (C_CTX (context), decl, 1 /* is_global */);
+}
+
+/* See compile-internal.h.  */
+
+void
+gcc_convert_symbol (void *datum,
+		    struct gcc_c_context *gcc_context,
+		    enum gcc_c_oracle_request request,
+		    const char *identifier)
+{
+  struct compile_c_instance *context = datum;
+  domain_enum domain;
+  volatile struct gdb_exception e;
+  int found = 0;
+
+  switch (request)
+    {
+    case GCC_C_ORACLE_SYMBOL:
+      domain = VAR_DOMAIN;
+      break;
+    case GCC_C_ORACLE_TAG:
+      domain = STRUCT_DOMAIN;
+      break;
+    case GCC_C_ORACLE_LABEL:
+      domain = LABEL_DOMAIN;
+      break;
+    default:
+      gdb_assert_not_reached ("Unrecognized oracle request.");
+    }
+
+  /* We can't allow exceptions to escape out of this callback.  Safest
+     is to simply emit a gcc error.  */
+  TRY_CATCH (e, RETURN_MASK_ALL)
+    {
+      struct symbol *sym;
+
+      sym = lookup_symbol (identifier, context->base.block, domain, NULL);
+      if (sym != NULL)
+	{
+	  convert_symbol_sym (context, identifier, sym, domain);
+	  found = 1;
+	}
+      else if (domain == VAR_DOMAIN)
+	{
+	  struct bound_minimal_symbol bmsym;
+
+	  bmsym = lookup_minimal_symbol (identifier, NULL, NULL);
+	  if (bmsym.minsym != NULL)
+	    {
+	      convert_symbol_bmsym (context, bmsym);
+	      found = 1;
+	    }
+	}
+    }
+
+  if (e.reason < 0)
+    C_CTX (context)->c_ops->error (C_CTX (context), e.message);
+
+  if (compile_debug && !found)
+    fprintf_unfiltered (gdb_stdout,
+			"gcc_convert_symbol \"%s\": lookup_symbol failed\n",
+			identifier);
+  return;
+}
+
+/* See compile-internal.h.  */
+
+gcc_address
+gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
+		    const char *identifier)
+{
+  struct compile_c_instance *context = datum;
+  volatile struct gdb_exception e;
+  gcc_address result = 0;
+  int found = 0;
+
+  /* We can't allow exceptions to escape out of this callback.  Safest
+     is to simply emit a gcc error.  */
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      struct symbol *sym;
+
+      /* We only need global functions here.  */
+      sym = lookup_symbol (identifier, NULL, VAR_DOMAIN, NULL);
+      if (sym != NULL && SYMBOL_CLASS (sym) == LOC_BLOCK)
+	{
+	  if (compile_debug)
+	    fprintf_unfiltered (gdb_stdout,
+				"gcc_symbol_address \"%s\": full symbol\n",
+				identifier);
+	  result = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
+	  found = 1;
+	}
+      else
+	{
+	  struct bound_minimal_symbol msym;
+
+	  msym = lookup_bound_minimal_symbol (identifier);
+	  if (msym.minsym != NULL)
+	    {
+	      if (compile_debug)
+		fprintf_unfiltered (gdb_stdout,
+				    "gcc_symbol_address \"%s\": minimal "
+				    "symbol\n",
+				    identifier);
+	      result = BMSYMBOL_VALUE_ADDRESS (msym);
+	      found = 1;
+	    }
+	}
+    }
+
+  if (e.reason < 0)
+    C_CTX (context)->c_ops->error (C_CTX (context), e.message);
+
+  if (compile_debug && !found)
+    fprintf_unfiltered (gdb_stdout,
+			"gcc_symbol_address \"%s\": failed\n",
+			identifier);
+  return result;
+}
+
+\f
+
+/* A hash function for symbol names.  */
+
+static hashval_t
+hash_symname (const void *a)
+{
+  const struct symbol *sym = a;
+
+  return htab_hash_string (SYMBOL_NATURAL_NAME (sym));
+}
+
+/* A comparison function for hash tables that just looks at symbol
+   names.  */
+
+static int
+eq_symname (const void *a, const void *b)
+{
+  const struct symbol *syma = a;
+  const struct symbol *symb = b;
+
+  return strcmp (SYMBOL_NATURAL_NAME (syma), SYMBOL_NATURAL_NAME (symb)) == 0;
+}
+
+/* If a symbol with the same name as SYM is already in HASHTAB, return
+   1.  Otherwise, add SYM to HASHTAB and return 0.  */
+
+static int
+symbol_seen (htab_t hashtab, struct symbol *sym)
+{
+  void **slot;
+
+  slot = htab_find_slot (hashtab, sym, INSERT);
+  if (*slot != NULL)
+    return 1;
+
+  *slot = sym;
+  return 0;
+}
+
+/* Generate C code to compute the length of a VLA.  */
+
+static void
+generate_vla_size (struct compile_c_instance *compiler,
+		   struct ui_file *stream,
+		   struct gdbarch *gdbarch,
+		   unsigned char *registers_used,
+		   CORE_ADDR pc,
+		   struct type *type,
+		   struct symbol *sym)
+{
+  type = check_typedef (type);
+
+  if (TYPE_CODE (type) == TYPE_CODE_REF)
+    type = check_typedef (TYPE_TARGET_TYPE (type));
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_RANGE:
+      {
+	if (TYPE_HIGH_BOUND_KIND (type) == PROP_LOCEXPR
+	    || TYPE_HIGH_BOUND_KIND (type) == PROP_LOCLIST)
+	  {
+	    const struct dynamic_prop *prop = &TYPE_RANGE_DATA (type)->high;
+	    char *name = c_get_range_decl_name (prop);
+	    struct cleanup *cleanup = make_cleanup (xfree, name);
+
+	    dwarf2_compile_property_to_c (stream, name,
+					  gdbarch, registers_used,
+					  prop, pc, sym);
+	    do_cleanups (cleanup);
+	  }
+      }
+      break;
+
+    case TYPE_CODE_ARRAY:
+      generate_vla_size (compiler, stream, gdbarch, registers_used, pc,
+			 TYPE_INDEX_TYPE (type), sym);
+      generate_vla_size (compiler, stream, gdbarch, registers_used, pc,
+			 TYPE_TARGET_TYPE (type), sym);
+      break;
+
+    case TYPE_CODE_UNION:
+    case TYPE_CODE_STRUCT:
+      {
+	int i;
+
+	for (i = 0; i < TYPE_NFIELDS (type); ++i)
+	  if (!field_is_static (&TYPE_FIELD (type, i)))
+	    generate_vla_size (compiler, stream, gdbarch, registers_used, pc,
+			       TYPE_FIELD_TYPE (type, i), sym);
+      }
+      break;
+    }
+}
+
+/* Generate C code to compute the address of SYM.  */
+
+static void
+generate_c_for_for_one_variable (struct compile_c_instance *compiler,
+				 struct ui_file *stream,
+				 struct gdbarch *gdbarch,
+				 unsigned char *registers_used,
+				 CORE_ADDR pc,
+				 struct symbol *sym)
+{
+  volatile struct gdb_exception e;
+
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      if (is_dynamic_type (SYMBOL_TYPE (sym)))
+	{
+	  struct ui_file *size_file = mem_fileopen ();
+	  struct cleanup *cleanup = make_cleanup_ui_file_delete (size_file);
+
+	  generate_vla_size (compiler, size_file, gdbarch, registers_used, pc,
+			     SYMBOL_TYPE (sym), sym);
+	  ui_file_put (size_file, ui_file_write_for_put, stream);
+
+	  do_cleanups (cleanup);
+	}
+
+      if (SYMBOL_COMPUTED_OPS (sym) != NULL)
+	{
+	  char *generated_name = symbol_substitution_name (sym);
+	  struct cleanup *cleanup = make_cleanup (xfree, generated_name);
+	  /* We need to emit to a temporary buffer in case an error
+	     occurs in the middle.  */
+	  struct ui_file *local_file = mem_fileopen ();
+
+	  make_cleanup_ui_file_delete (local_file);
+	  SYMBOL_COMPUTED_OPS (sym)->generate_c_location (sym, local_file,
+							  gdbarch,
+							  registers_used,
+							  pc, generated_name);
+	  ui_file_put (local_file, ui_file_write_for_put, stream);
+
+	  do_cleanups (cleanup);
+	}
+      else
+	{
+	  switch (SYMBOL_CLASS (sym))
+	    {
+	    case LOC_REGISTER:
+	    case LOC_ARG:
+	    case LOC_REF_ARG:
+	    case LOC_REGPARM_ADDR:
+	    case LOC_LOCAL:
+	      error (_("Local symbol unhandled when generating C code."));
+
+	    case LOC_COMPUTED:
+	      gdb_assert_not_reached (_("LOC_COMPUTED variable "
+					"missing a method."));
+
+	    default:
+	      /* Nothing to do for all other cases, as they don't represent
+		 local variables.  */
+	      break;
+	    }
+	}
+    }
+
+  if (e.reason >= 0)
+    return;
+
+  if (compiler->symbol_err_map == NULL)
+    compiler->symbol_err_map = htab_create_alloc (10,
+						  hash_symbol_error,
+						  eq_symbol_error,
+						  del_symbol_error,
+						  xcalloc,
+						  xfree);
+  insert_symbol_error (compiler->symbol_err_map, sym, e.message);
+}
+
+/* See compile-internal.h.  */
+
+unsigned char *
+generate_c_for_variable_locations (struct compile_c_instance *compiler,
+				   struct ui_file *stream,
+				   struct gdbarch *gdbarch,
+				   const struct block *block,
+				   CORE_ADDR pc)
+{
+  struct cleanup *cleanup, *outer;
+  htab_t symhash;
+  const struct block *static_block = block_static_block (block);
+  unsigned char *registers_used;
+
+  /* If we're already in the static or global block, there is nothing
+     to write.  */
+  if (static_block == NULL || block == static_block)
+    return NULL;
+
+  registers_used = XCNEWVEC (unsigned char, gdbarch_num_regs (gdbarch));
+  outer = make_cleanup (xfree, registers_used);
+
+  /* Ensure that a given name is only entered once.  This reflects the
+     reality of shadowing.  */
+  symhash = htab_create_alloc (1, hash_symname, eq_symname, NULL,
+			       xcalloc, xfree);
+  cleanup = make_cleanup_htab_delete (symhash);
+
+  while (1)
+    {
+      struct symbol *sym;
+      struct block_iterator iter;
+
+      /* Iterate over symbols in this block, generating code to
+	 compute the location of each local variable.  */
+      for (sym = block_iterator_first (block, &iter);
+	   sym != NULL;
+	   sym = block_iterator_next (&iter))
+	{
+	  if (!symbol_seen (symhash, sym))
+	    generate_c_for_for_one_variable (compiler, stream, gdbarch,
+					     registers_used, pc, sym);
+	}
+
+      /* If we just finished the outermost block of a function, we're
+	 done.  */
+      if (BLOCK_FUNCTION (block) != NULL)
+	break;
+      block = BLOCK_SUPERBLOCK (block);
+    }
+
+  do_cleanups (cleanup);
+  discard_cleanups (outer);
+  return registers_used;
+}
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
new file mode 100644
index 0000000..78ae9a8
--- /dev/null
+++ b/gdb/compile/compile-c-types.c
@@ -0,0 +1,438 @@
+/* Convert types from GDB to GCC
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+#include "defs.h"
+#include "gdbtypes.h"
+#include "compile-internal.h"
+#include "gdb_assert.h"
+
+/* An object that maps a gdb type to a gcc type.  */
+
+struct type_map_instance
+{
+  /* The gdb type.  */
+
+  struct type *type;
+
+  /* The corresponding gcc type handle.  */
+
+  gcc_type gcc_type;
+};
+
+/* Hash a type_map_instance.  */
+
+static hashval_t
+hash_type_map_instance (const void *p)
+{
+  const struct type_map_instance *inst = p;
+
+  return htab_hash_pointer (inst->type);
+}
+
+/* Check two type_map_instance objects for equality.  */
+
+static int
+eq_type_map_instance (const void *a, const void *b)
+{
+  const struct type_map_instance *insta = a;
+  const struct type_map_instance *instb = b;
+
+  return insta->type == instb->type;
+}
+
+\f
+
+/* Insert an entry into the type map associated with CONTEXT that maps
+   from the gdb type TYPE to the gcc type GCC_TYPE.  It is ok for a
+   given type to be inserted more than once, provided that the exact
+   same association is made each time.  This simplifies how type
+   caching works elsewhere in this file -- see how struct type caching
+   is handled.  */
+
+static void
+insert_type (struct compile_c_instance *context, struct type *type,
+	     gcc_type gcc_type)
+{
+  struct type_map_instance inst, *add;
+  void **slot;
+
+  inst.type = type;
+  inst.gcc_type = gcc_type;
+  slot = htab_find_slot (context->type_map, &inst, INSERT);
+
+  add = *slot;
+  /* The type might have already been inserted in order to handle
+     recursive types.  */
+  gdb_assert (add == NULL || add->gcc_type == gcc_type);
+
+  if (add == NULL)
+    {
+      add = XNEW (struct type_map_instance);
+      *add = inst;
+      *slot = add;
+    }
+}
+
+/* Convert a pointer type to its gcc representation.  */
+
+static gcc_type
+convert_pointer (struct compile_c_instance *context, struct type *type)
+{
+  gcc_type target = convert_type (context, TYPE_TARGET_TYPE (type));
+
+  return C_CTX (context)->c_ops->build_pointer_type (C_CTX (context),
+						     target);
+}
+
+/* Convert an array type to its gcc representation.  */
+
+static gcc_type
+convert_array (struct compile_c_instance *context, struct type *type)
+{
+  gcc_type element_type;
+  struct type *range = TYPE_INDEX_TYPE (type);
+
+  element_type = convert_type (context, TYPE_TARGET_TYPE (type));
+
+  if (TYPE_LOW_BOUND_KIND (range) != PROP_CONST)
+    return C_CTX (context)->c_ops->error (C_CTX (context),
+					  _("array type with non-constant"
+					    " lower bound is not supported"));
+  if (TYPE_LOW_BOUND (range) != 0)
+    return C_CTX (context)->c_ops->error (C_CTX (context),
+					  _("cannot convert array type with "
+					    "non-zero lower bound to C"));
+
+  if (TYPE_HIGH_BOUND_KIND (range) == PROP_LOCEXPR
+      || TYPE_HIGH_BOUND_KIND (range) == PROP_LOCLIST)
+    {
+      gcc_type result;
+      char *upper_bound;
+
+      if (TYPE_VECTOR (type))
+	return C_CTX (context)->c_ops->error (C_CTX (context),
+					      _("variably-sized vector type"
+						" is not supported"));
+
+      upper_bound = c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high);
+      result = C_CTX (context)->c_ops->build_vla_array_type (C_CTX (context),
+							     element_type,
+							     upper_bound);
+      xfree (upper_bound);
+      return result;
+    }
+  else
+    {
+      LONGEST low_bound, high_bound, count;
+
+      if (get_array_bounds (type, &low_bound, &high_bound) == 0)
+	count = -1;
+      else
+	{
+	  gdb_assert (low_bound == 0); /* Ensured above.  */
+	  count = high_bound + 1;
+	}
+
+      if (TYPE_VECTOR (type))
+	return C_CTX (context)->c_ops->build_vector_type (C_CTX (context),
+							  element_type,
+							  count);
+      return C_CTX (context)->c_ops->build_array_type (C_CTX (context),
+						       element_type, count);
+    }
+}
+
+/* Convert a struct or union type to its gcc representation.  */
+
+static gcc_type
+convert_struct_or_union (struct compile_c_instance *context, struct type *type)
+{
+  int i;
+  gcc_type result;
+
+  /* First we create the resulting type and enter it into our hash
+     table.  This lets recursive types work.  */
+  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+    result = C_CTX (context)->c_ops->build_record_type (C_CTX (context));
+  else
+    {
+      gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
+      result = C_CTX (context)->c_ops->build_union_type (C_CTX (context));
+    }
+  insert_type (context, type, result);
+
+  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+    {
+      gcc_type field_type;
+      unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i);
+
+      field_type = convert_type (context, TYPE_FIELD_TYPE (type, i));
+      if (bitsize == 0)
+	bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
+      C_CTX (context)->c_ops->build_add_field (C_CTX (context), result,
+					       TYPE_FIELD_NAME (type, i),
+					       field_type,
+					       bitsize,
+					       TYPE_FIELD_BITPOS (type, i));
+    }
+
+  C_CTX (context)->c_ops->finish_record_or_union (C_CTX (context), result,
+						  TYPE_LENGTH (type));
+  return result;
+}
+
+/* Convert an enum type to its gcc representation.  */
+
+static gcc_type
+convert_enum (struct compile_c_instance *context, struct type *type)
+{
+  gcc_type int_type, result;
+  int i;
+  struct gcc_c_context *ctx = C_CTX (context);
+
+  int_type = ctx->c_ops->int_type (ctx,
+				   TYPE_UNSIGNED (type),
+				   TYPE_LENGTH (type));
+
+  result = ctx->c_ops->build_enum_type (ctx, int_type);
+  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+    {
+      ctx->c_ops->build_add_enum_constant (ctx,
+					   result,
+					   TYPE_FIELD_NAME (type, i),
+					   TYPE_FIELD_ENUMVAL (type, i));
+    }
+
+  ctx->c_ops->finish_enum_type (ctx, result);
+
+  return result;
+}
+
+/* Convert a function type to its gcc representation.  */
+
+static gcc_type
+convert_func (struct compile_c_instance *context, struct type *type)
+{
+  int i;
+  gcc_type result, return_type;
+  struct gcc_type_array array;
+  int is_varargs = TYPE_VARARGS (type) || !TYPE_PROTOTYPED (type);
+
+  /* This approach means we can't make self-referential function
+     types.  Those are impossible in C, though.  */
+  return_type = convert_type (context, TYPE_TARGET_TYPE (type));
+
+  array.n_elements = TYPE_NFIELDS (type);
+  array.elements = XNEWVEC (gcc_type, TYPE_NFIELDS (type));
+  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+    array.elements[i] = convert_type (context, TYPE_FIELD_TYPE (type, i));
+
+  result = C_CTX (context)->c_ops->build_function_type (C_CTX (context),
+							return_type,
+							&array, is_varargs);
+  xfree (array.elements);
+
+  return result;
+}
+
+/* Convert an integer type to its gcc representation.  */
+
+static gcc_type
+convert_int (struct compile_c_instance *context, struct type *type)
+{
+  return C_CTX (context)->c_ops->int_type (C_CTX (context),
+					   TYPE_UNSIGNED (type),
+					   TYPE_LENGTH (type));
+}
+
+/* Convert a floating-point type to its gcc representation.  */
+
+static gcc_type
+convert_float (struct compile_c_instance *context, struct type *type)
+{
+  return C_CTX (context)->c_ops->float_type (C_CTX (context),
+					     TYPE_LENGTH (type));
+}
+
+/* Convert the 'void' type to its gcc representation.  */
+
+static gcc_type
+convert_void (struct compile_c_instance *context, struct type *type)
+{
+  return C_CTX (context)->c_ops->void_type (C_CTX (context));
+}
+
+/* Convert a boolean type to its gcc representation.  */
+
+static gcc_type
+convert_bool (struct compile_c_instance *context, struct type *type)
+{
+  return C_CTX (context)->c_ops->bool_type (C_CTX (context));
+}
+
+/* Convert a qualified type to its gcc representation.  */
+
+static gcc_type
+convert_qualified (struct compile_c_instance *context, struct type *type)
+{
+  struct type *unqual = make_unqualified_type (type);
+  gcc_type unqual_converted;
+  int quals = 0;
+
+  unqual_converted = convert_type (context, unqual);
+
+  if (TYPE_CONST (type))
+    quals |= GCC_QUALIFIER_CONST;
+  if (TYPE_VOLATILE (type))
+    quals |= GCC_QUALIFIER_VOLATILE;
+  if (TYPE_RESTRICT (type))
+    quals |= GCC_QUALIFIER_RESTRICT;
+
+  return C_CTX (context)->c_ops->build_qualified_type (C_CTX (context),
+						       unqual_converted,
+						       quals);
+}
+
+/* Convert a complex type to its gcc representation.  */
+
+static gcc_type
+convert_complex (struct compile_c_instance *context, struct type *type)
+{
+  gcc_type base = convert_type (context, TYPE_TARGET_TYPE (type));
+
+  return C_CTX (context)->c_ops->build_complex_type (C_CTX (context), base);
+}
+
+/* A helper function which knows how to convert most types from their
+   gdb representation to the corresponding gcc form.  This examines
+   the TYPE and dispatches to the appropriate conversion function.  It
+   returns the gcc type.  */
+
+static gcc_type
+convert_type_basic (struct compile_c_instance *context, struct type *type)
+{
+  /* If we are converting a qualified type, first convert the
+     unqualified type and then apply the qualifiers.  */
+  if ((TYPE_INSTANCE_FLAGS (type) & (TYPE_INSTANCE_FLAG_CONST
+				     | TYPE_INSTANCE_FLAG_VOLATILE
+				     | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
+    return convert_qualified (context, type);
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_PTR:
+      return convert_pointer (context, type);
+
+    case TYPE_CODE_ARRAY:
+      return convert_array (context, type);
+
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      return convert_struct_or_union (context, type);
+
+    case TYPE_CODE_ENUM:
+      return convert_enum (context, type);
+
+    case TYPE_CODE_FUNC:
+      return convert_func (context, type);
+
+    case TYPE_CODE_INT:
+      return convert_int (context, type);
+
+    case TYPE_CODE_FLT:
+      return convert_float (context, type);
+
+    case TYPE_CODE_VOID:
+      return convert_void (context, type);
+
+    case TYPE_CODE_BOOL:
+      return convert_bool (context, type);
+
+    case TYPE_CODE_COMPLEX:
+      return convert_complex (context, type);
+    }
+
+  return C_CTX (context)->c_ops->error (C_CTX (context),
+					_("cannot convert gdb type "
+					  "to gcc type"));
+}
+
+/* See compile-internal.h.  */
+
+gcc_type
+convert_type (struct compile_c_instance *context, struct type *type)
+{
+  struct type_map_instance inst, *found;
+  gcc_type result;
+
+  /* We don't ever have to deal with typedefs in this code, because
+     those are only needed as symbols by the C compiler.  */
+  CHECK_TYPEDEF (type);
+
+  inst.type = type;
+  found = htab_find (context->type_map, &inst);
+  if (found != NULL)
+    return found->gcc_type;
+
+  result = convert_type_basic (context, type);
+  insert_type (context, type, result);
+  return result;
+}
+
+\f
+
+/* Delete the compiler instance C.  */
+
+static void
+delete_instance (struct compile_instance *c)
+{
+  struct compile_c_instance *context = (struct compile_c_instance *) c;
+
+  context->base.fe->ops->destroy (context->base.fe);
+  htab_delete (context->type_map);
+  if (context->symbol_err_map != NULL)
+    htab_delete (context->symbol_err_map);
+  xfree (context);
+}
+
+/* See compile-internal.h.  */
+
+struct compile_instance *
+new_compile_instance (struct gcc_c_context *fe)
+{
+  struct compile_c_instance *result = XCNEW (struct compile_c_instance);
+
+  result->base.fe = &fe->base;
+  result->base.destroy = delete_instance;
+  result->base.gcc_target_options = ("-std=gnu11"
+				     /* Otherwise the .o file may need
+					"_Unwind_Resume" and
+					"__gcc_personality_v0".  */
+				     " -fno-exceptions");
+
+  result->type_map = htab_create_alloc (10, hash_type_map_instance,
+					eq_type_map_instance,
+					xfree, xcalloc, xfree);
+
+  fe->c_ops->set_callbacks (fe, gcc_convert_symbol,
+			    gcc_symbol_address, result);
+
+  return &result->base;
+}
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
new file mode 100644
index 0000000..cb8d3d1
--- /dev/null
+++ b/gdb/compile/compile-internal.h
@@ -0,0 +1,147 @@
+/* Header file for GDB compile command and supporting functions.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_COMPILE_INTERNAL_H
+#define GDB_COMPILE_INTERNAL_H
+
+#include "hashtab.h"
+#include "gcc-c-interface.h"
+
+/* Debugging flag for the "compile" family of commands.  */
+
+extern int compile_debug;
+
+struct block;
+
+/* An object of this type holds state associated with a given
+   compilation job.  */
+
+struct compile_instance
+{
+  /* The GCC front end.  */
+
+  struct gcc_base_context *fe;
+
+  /* The "scope" of this compilation.  */
+
+  enum compile_i_scope_types scope;
+
+  /* The block in which an expression is being parsed.  */
+
+  const struct block *block;
+
+  /* Specify "-std=gnu11", "-std=gnu++11" or similar.  These options are put
+     after CU's DW_AT_producer compilation options to override them.  */
+
+  const char *gcc_target_options;
+
+  /* How to destroy this object.  */
+
+  void (*destroy) (struct compile_instance *);
+};
+
+/* A subclass of compile_instance that is specific to the C front
+   end.  */
+struct compile_c_instance
+{
+  /* Base class.  Note that the base class vtable actually points to a
+     gcc_c_fe_vtable.  */
+
+  struct compile_instance base;
+
+  /* Map from gdb types to gcc types.  */
+
+  htab_t type_map;
+
+  /* Map from gdb symbols to gcc error messages to emit.  */
+
+  htab_t symbol_err_map;
+};
+
+/* A helper macro that takes a compile_c_instance and returns its
+   corresponding gcc_c_context.  */
+
+#define C_CTX(I) ((struct gcc_c_context *) ((I)->base.fe))
+
+/* Define header and footers for different scopes.  */
+
+/* A simple scope just declares a function named "_gdb_expr", takes no
+   arguments and returns no value.  */
+
+#define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs"
+#define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs"
+#define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy"
+
+/* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result
+   to a form suitable for the compiler source.  The register names
+   should not clash with inferior defined macros.  Returned pointer is
+   never NULL.  Returned pointer needs to be deallocated by xfree.  */
+
+extern char *compile_register_name_mangled (struct gdbarch *gdbarch,
+					    int regnum);
+
+/* Convert compiler source register name to register number of
+   GDBARCH.  Returned value is always >= 0, function throws an error
+   for non-matching REG_NAME.  */
+
+extern int compile_register_name_demangle (struct gdbarch *gdbarch,
+					   const char *reg_name);
+
+/* Convert a gdb type, TYPE, to a GCC type.  CONTEXT is used to do the
+   actual conversion.  The new GCC type is returned.  */
+
+struct type;
+extern gcc_type convert_type (struct compile_c_instance *context,
+			      struct type *type);
+
+/* A callback suitable for use as the GCC C symbol oracle.  */
+
+extern gcc_c_oracle_function gcc_convert_symbol;
+
+/* A callback suitable for use as the GCC C address oracle.  */
+
+extern gcc_c_symbol_address_function gcc_symbol_address;
+
+/* Instantiate a GDB object holding state for the GCC context FE.  The
+   new object is returned.  */
+
+extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe);
+
+/* Emit code to compute the address for all the local variables in
+   scope at PC in BLOCK.  Returns a malloc'd vector, indexed by gdb
+   register number, where each element indicates if the corresponding
+   register is needed to compute a local variable.  */
+
+extern unsigned char *generate_c_for_variable_locations
+     (struct compile_c_instance *compiler,
+      struct ui_file *stream,
+      struct gdbarch *gdbarch,
+      const struct block *block,
+      CORE_ADDR pc);
+
+/* Get the GCC mode attribute value for a given type size.  */
+
+extern const char *c_get_mode_for_size (int size);
+
+/* Given a dynamic property, return an xmallocd name that is used to
+   represent its size.  The result must be freed by the caller.  The
+   contents of the resulting string will be the same each time for
+   each call with the same argument.  */
+
+struct dynamic_prop;
+extern char *c_get_range_decl_name (const struct dynamic_prop *prop);
+
+#endif /* GDB_COMPILE_INTERNAL_H */
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
new file mode 100644
index 0000000..e31d44d
--- /dev/null
+++ b/gdb/compile/compile-loc2c.c
@@ -0,0 +1,1148 @@
+/* Convert a DWARF location expression to C
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "dwarf2.h"
+#include "dwarf2expr.h"
+#include "dwarf2loc.h"
+#include "ui-file.h"
+#include "utils.h"
+#include "compile-internal.h"
+#include "compile.h"
+#include "block.h"
+#include "dwarf2-frame.h"
+#include "gdb_vecs.h"
+#include "value.h"
+
+\f
+
+/* Information about a given instruction.  */
+
+struct insn_info
+{
+  /* Stack depth at entry.  */
+
+  unsigned int depth;
+
+  /* Whether this instruction has been visited.  */
+
+  unsigned int visited : 1;
+
+  /* Whether this instruction needs a label.  */
+
+  unsigned int label : 1;
+
+  /* Whether this instruction is DW_OP_GNU_push_tls_address.  This is
+     a hack until we can add a feature to glibc to let us properly
+     generate code for TLS.  */
+
+  unsigned int is_tls : 1;
+};
+
+/* A helper function for compute_stack_depth that does the work.  This
+   examines the DWARF expression starting from START and computes
+   stack effects.
+
+   NEED_TEMPVAR is an out parameter which is set if this expression
+   needs a special temporary variable to be emitted (see the code
+   generator).
+   INFO is an array of insn_info objects, indexed by offset from the
+   start of the DWARF expression.
+   TO_DO is a list of bytecodes which must be examined; it may be
+   added to by this function.
+   BYTE_ORDER and ADDR_SIZE describe this bytecode in the obvious way.
+   OP_PTR and OP_END are the bounds of the DWARF expression.  */
+
+static void
+compute_stack_depth_worker (int start, int *need_tempvar,
+			    struct insn_info *info,
+			    VEC (int) **to_do,
+			    enum bfd_endian byte_order, unsigned int addr_size,
+			    const gdb_byte *op_ptr, const gdb_byte *op_end)
+{
+  const gdb_byte * const base = op_ptr;
+  int stack_depth;
+
+  op_ptr += start;
+  gdb_assert (info[start].visited);
+  stack_depth = info[start].depth;
+
+  while (op_ptr < op_end)
+    {
+      enum dwarf_location_atom op = *op_ptr;
+      uint64_t reg;
+      int64_t offset;
+      int ndx = op_ptr - base;
+
+#define SET_CHECK_DEPTH(WHERE)				\
+      if (info[WHERE].visited)				\
+	{						\
+	  if (info[WHERE].depth != stack_depth)		\
+	    error (_("inconsistent stack depths"));	\
+	}						\
+      else						\
+	{						\
+	  /* Stack depth not set, so set it.  */	\
+	  info[WHERE].visited = 1;			\
+	  info[WHERE].depth = stack_depth;		\
+	}
+
+      SET_CHECK_DEPTH (ndx);
+
+      ++op_ptr;
+
+      switch (op)
+	{
+	case DW_OP_lit0:
+	case DW_OP_lit1:
+	case DW_OP_lit2:
+	case DW_OP_lit3:
+	case DW_OP_lit4:
+	case DW_OP_lit5:
+	case DW_OP_lit6:
+	case DW_OP_lit7:
+	case DW_OP_lit8:
+	case DW_OP_lit9:
+	case DW_OP_lit10:
+	case DW_OP_lit11:
+	case DW_OP_lit12:
+	case DW_OP_lit13:
+	case DW_OP_lit14:
+	case DW_OP_lit15:
+	case DW_OP_lit16:
+	case DW_OP_lit17:
+	case DW_OP_lit18:
+	case DW_OP_lit19:
+	case DW_OP_lit20:
+	case DW_OP_lit21:
+	case DW_OP_lit22:
+	case DW_OP_lit23:
+	case DW_OP_lit24:
+	case DW_OP_lit25:
+	case DW_OP_lit26:
+	case DW_OP_lit27:
+	case DW_OP_lit28:
+	case DW_OP_lit29:
+	case DW_OP_lit30:
+	case DW_OP_lit31:
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_addr:
+	  op_ptr += addr_size;
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_const1u:
+	case DW_OP_const1s:
+	  op_ptr += 1;
+	  ++stack_depth;
+	  break;
+	case DW_OP_const2u:
+	case DW_OP_const2s:
+	  op_ptr += 2;
+	  ++stack_depth;
+	  break;
+	case DW_OP_const4u:
+	case DW_OP_const4s:
+	  op_ptr += 4;
+	  ++stack_depth;
+	  break;
+	case DW_OP_const8u:
+	case DW_OP_const8s:
+	  op_ptr += 8;
+	  ++stack_depth;
+	  break;
+	case DW_OP_constu:
+	case DW_OP_consts:
+	  op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_reg0:
+	case DW_OP_reg1:
+	case DW_OP_reg2:
+	case DW_OP_reg3:
+	case DW_OP_reg4:
+	case DW_OP_reg5:
+	case DW_OP_reg6:
+	case DW_OP_reg7:
+	case DW_OP_reg8:
+	case DW_OP_reg9:
+	case DW_OP_reg10:
+	case DW_OP_reg11:
+	case DW_OP_reg12:
+	case DW_OP_reg13:
+	case DW_OP_reg14:
+	case DW_OP_reg15:
+	case DW_OP_reg16:
+	case DW_OP_reg17:
+	case DW_OP_reg18:
+	case DW_OP_reg19:
+	case DW_OP_reg20:
+	case DW_OP_reg21:
+	case DW_OP_reg22:
+	case DW_OP_reg23:
+	case DW_OP_reg24:
+	case DW_OP_reg25:
+	case DW_OP_reg26:
+	case DW_OP_reg27:
+	case DW_OP_reg28:
+	case DW_OP_reg29:
+	case DW_OP_reg30:
+	case DW_OP_reg31:
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_regx:
+	  op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_breg0:
+	case DW_OP_breg1:
+	case DW_OP_breg2:
+	case DW_OP_breg3:
+	case DW_OP_breg4:
+	case DW_OP_breg5:
+	case DW_OP_breg6:
+	case DW_OP_breg7:
+	case DW_OP_breg8:
+	case DW_OP_breg9:
+	case DW_OP_breg10:
+	case DW_OP_breg11:
+	case DW_OP_breg12:
+	case DW_OP_breg13:
+	case DW_OP_breg14:
+	case DW_OP_breg15:
+	case DW_OP_breg16:
+	case DW_OP_breg17:
+	case DW_OP_breg18:
+	case DW_OP_breg19:
+	case DW_OP_breg20:
+	case DW_OP_breg21:
+	case DW_OP_breg22:
+	case DW_OP_breg23:
+	case DW_OP_breg24:
+	case DW_OP_breg25:
+	case DW_OP_breg26:
+	case DW_OP_breg27:
+	case DW_OP_breg28:
+	case DW_OP_breg29:
+	case DW_OP_breg30:
+	case DW_OP_breg31:
+	  op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+	  ++stack_depth;
+	  break;
+	case DW_OP_bregx:
+	  {
+	    op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
+	    op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+	    ++stack_depth;
+	  }
+	  break;
+	case DW_OP_fbreg:
+	  op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_dup:
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_drop:
+	  --stack_depth;
+	  break;
+
+	case DW_OP_pick:
+	  ++op_ptr;
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_rot:
+	case DW_OP_swap:
+	  *need_tempvar = 1;
+	  break;
+
+	case DW_OP_over:
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_abs:
+	case DW_OP_neg:
+	case DW_OP_not:
+	case DW_OP_deref:
+	  break;
+
+	case DW_OP_deref_size:
+	  ++op_ptr;
+	  break;
+
+	case DW_OP_plus_uconst:
+	  op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
+	  break;
+
+	case DW_OP_div:
+	case DW_OP_shra:
+	case DW_OP_and:
+	case DW_OP_minus:
+	case DW_OP_mod:
+	case DW_OP_mul:
+	case DW_OP_or:
+	case DW_OP_plus:
+	case DW_OP_shl:
+	case DW_OP_shr:
+	case DW_OP_xor:
+	case DW_OP_le:
+	case DW_OP_ge:
+	case DW_OP_eq:
+	case DW_OP_lt:
+	case DW_OP_gt:
+	case DW_OP_ne:
+	  --stack_depth;
+	  break;
+
+	case DW_OP_call_frame_cfa:
+	  ++stack_depth;
+	  break;
+
+	case DW_OP_GNU_push_tls_address:
+	  info[ndx].is_tls = 1;
+	  break;
+
+	case DW_OP_skip:
+	  offset = extract_signed_integer (op_ptr, 2, byte_order);
+	  op_ptr += 2;
+	  offset = op_ptr + offset - base;
+	  /* If the destination has not been seen yet, add it to the
+	     to-do list.  */
+	  if (!info[offset].visited)
+	    VEC_safe_push (int, *to_do, offset);
+	  SET_CHECK_DEPTH (offset);
+	  info[offset].label = 1;
+	  /* We're done with this line of code.  */
+	  return;
+
+	case DW_OP_bra:
+	  offset = extract_signed_integer (op_ptr, 2, byte_order);
+	  op_ptr += 2;
+	  offset = op_ptr + offset - base;
+	  --stack_depth;
+	  /* If the destination has not been seen yet, add it to the
+	     to-do list.  */
+	  if (!info[offset].visited)
+	    VEC_safe_push (int, *to_do, offset);
+	  SET_CHECK_DEPTH (offset);
+	  info[offset].label = 1;
+	  break;
+
+	case DW_OP_nop:
+	  break;
+
+	default:
+	  error (_("unhandled DWARF op: %s"), get_DW_OP_name (op));
+	}
+    }
+
+  gdb_assert (op_ptr == op_end);
+
+#undef SET_CHECK_DEPTH
+}
+
+/* Compute the maximum needed stack depth of a DWARF expression, and
+   some other information as well.
+
+   BYTE_ORDER and ADDR_SIZE describe this bytecode in the obvious way.
+   NEED_TEMPVAR is an out parameter which is set if this expression
+   needs a special temporary variable to be emitted (see the code
+   generator).
+   IS_TLS is an out parameter which is set if this expression refers
+   to a TLS variable.
+   OP_PTR and OP_END are the bounds of the DWARF expression.
+   INITIAL_DEPTH is the initial depth of the DWARF expression stack.
+   INFO is an array of insn_info objects, indexed by offset from the
+   start of the DWARF expression.
+
+   This returns the maximum stack depth.  */
+
+static int
+compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
+		     int *need_tempvar, int *is_tls,
+		     const gdb_byte *op_ptr, const gdb_byte *op_end,
+		     int initial_depth,
+		     struct insn_info **info)
+{
+  unsigned char *set;
+  struct cleanup *outer_cleanup, *cleanup;
+  VEC (int) *to_do = NULL;
+  int stack_depth, i;
+
+  *info = XCNEWVEC (struct insn_info, op_end - op_ptr);
+  outer_cleanup = make_cleanup (xfree, *info);
+
+  cleanup = make_cleanup (VEC_cleanup (int), &to_do);
+
+  VEC_safe_push (int, to_do, 0);
+  (*info)[0].depth = initial_depth;
+  (*info)[0].visited = 1;
+
+  while (!VEC_empty (int, to_do))
+    {
+      int ndx = VEC_pop (int, to_do);
+
+      compute_stack_depth_worker (ndx, need_tempvar, *info, &to_do,
+				  byte_order, addr_size,
+				  op_ptr, op_end);
+    }
+
+  stack_depth = 0;
+  *is_tls = 0;
+  for (i = 0; i < op_end - op_ptr; ++i)
+    {
+      if ((*info)[i].depth > stack_depth)
+	stack_depth = (*info)[i].depth;
+      if ((*info)[i].is_tls)
+	*is_tls = 1;
+    }
+
+  do_cleanups (cleanup);
+  discard_cleanups (outer_cleanup);
+  return stack_depth + 1;
+}
+
+\f
+
+#define GCC_UINTPTR "__gdb_uintptr"
+#define GCC_INTPTR "__gdb_intptr"
+
+/* Emit code to push a constant.  */
+
+static void
+push (int indent, struct ui_file *stream, ULONGEST l)
+{
+  fprintfi_filtered (indent, stream, "__gdb_stack[++__gdb_tos] = %s;\n",
+		     hex_string (l));
+}
+
+/* Emit code to push an arbitrary expression.  This works like
+   printf.  */
+
+static void
+pushf (int indent, struct ui_file *stream, const char *format, ...)
+{
+  va_list args;
+
+  fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos + 1] = ");
+  va_start (args, format);
+  vfprintf_filtered (stream, format, args);
+  va_end (args);
+  fprintf_filtered (stream, ";\n");
+
+  fprintfi_filtered (indent, stream, "++__gdb_tos;\n");
+}
+
+/* Emit code for a unary expression -- one which operates in-place on
+   the top-of-stack.  This works like printf.  */
+
+static void
+unary (int indent, struct ui_file *stream, const char *format, ...)
+{
+  va_list args;
+
+  fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos] = ");
+  va_start (args, format);
+  vfprintf_filtered (stream, format, args);
+  va_end (args);
+  fprintf_filtered (stream, ";\n");
+}
+
+/* Emit code for a unary expression -- one which uses the top two
+   stack items, popping the topmost one.  This works like printf.  */
+
+static void
+binary (int indent, struct ui_file *stream, const char *format, ...)
+{
+  va_list args;
+
+  fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos - 1] = ");
+  va_start (args, format);
+  vfprintf_filtered (stream, format, args);
+  va_end (args);
+  fprintf_filtered (stream, ";\n");
+  fprintfi_filtered (indent, stream, "--__gdb_tos;\n");
+}
+
+/* Print the name of a label given its "SCOPE", an arbitrary integer
+   used for uniqueness, and its TARGET, the bytecode offset
+   corresponding to the label's point of definition.  */
+
+static void
+print_label (struct ui_file *stream, unsigned int scope, int target)
+{
+  fprintf_filtered (stream, "__label_%u_%s",
+		    scope, pulongest (target));
+}
+
+/* Emit code that pushes a register's address on the stack.
+   REGISTERS_USED is an out parameter which is updated to note which
+   register was needed by this expression.  */
+
+static void
+pushf_register_address (int indent, struct ui_file *stream,
+			unsigned char *registers_used,
+			struct gdbarch *gdbarch, int regnum)
+{
+  char *regname = compile_register_name_mangled (gdbarch, regnum);
+  struct cleanup *cleanups = make_cleanup (xfree, regname);
+
+  registers_used[regnum] = 1;
+  pushf (indent, stream, "&" COMPILE_I_SIMPLE_REGISTER_ARG_NAME	 "->%s",
+	 regname);
+
+  do_cleanups (cleanups);
+}
+
+/* Emit code that pushes a register's value on the stack.
+   REGISTERS_USED is an out parameter which is updated to note which
+   register was needed by this expression.  OFFSET is added to the
+   register's value before it is pushed.  */
+
+static void
+pushf_register (int indent, struct ui_file *stream,
+		unsigned char *registers_used,
+		struct gdbarch *gdbarch, int regnum, uint64_t offset)
+{
+  char *regname = compile_register_name_mangled (gdbarch, regnum);
+  struct cleanup *cleanups = make_cleanup (xfree, regname);
+
+  registers_used[regnum] = 1;
+  if (offset == 0)
+    pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
+	   regname);
+  else
+    pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s + %s",
+	   regname, hex_string (offset));
+
+  do_cleanups (cleanups);
+}
+
+/* Compile a DWARF expression to C code.
+
+   INDENT is the indentation level to use.
+   STREAM is the stream where the code should be written.
+
+   TYPE_NAME names the type of the result of the DWARF expression.
+   For locations this is "void *" but for array bounds it will be an
+   integer type.
+
+   RESULT_NAME is the name of a variable in the resulting C code.  The
+   result of the expression will be assigned to this variable.
+
+   SYM is the symbol corresponding to this expression.
+   PC is the location at which the expression is being evaluated.
+   ARCH is the architecture to use.
+
+   REGISTERS_USED is an out parameter which is updated to note which
+   registers were needed by this expression.
+
+   ADDR_SIZE is the DWARF address size to use.
+
+   OPT_PTR and OP_END are the bounds of the DWARF expression.
+
+   If non-NULL, INITIAL points to an initial value to write to the
+   stack.  If NULL, no initial value is written.
+
+   PER_CU is the per-CU object used for looking up various other
+   things.  */
+
+static void
+do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
+			    const char *type_name,
+			    const char *result_name,
+			    struct symbol *sym, CORE_ADDR pc,
+			    struct gdbarch *arch,
+			    unsigned char *registers_used,
+			    unsigned int addr_size,
+			    const gdb_byte *op_ptr, const gdb_byte *op_end,
+			    CORE_ADDR *initial,
+			    struct dwarf2_per_cu_data *per_cu)
+{
+  /* We keep a counter so that labels and other objects we create have
+     unique names.  */
+  static unsigned int scope;
+
+  enum bfd_endian byte_order = gdbarch_byte_order (arch);
+  const gdb_byte * const base = op_ptr;
+  int need_tempvar = 0;
+  int is_tls = 0;
+  struct cleanup *cleanup;
+  struct insn_info *info;
+  int stack_depth;
+
+  ++scope;
+
+  fprintfi_filtered (indent, stream, "%s%s;\n", type_name, result_name);
+  fprintfi_filtered (indent, stream, "{\n");
+  indent += 2;
+
+  stack_depth = compute_stack_depth (byte_order, addr_size,
+				     &need_tempvar, &is_tls,
+				     op_ptr, op_end, initial != NULL,
+				     &info);
+  cleanup = make_cleanup (xfree, info);
+
+  /* This is a hack until we can add a feature to glibc to let us
+     properly generate code for TLS.  You might think we could emit
+     the address in the ordinary course of translating
+     DW_OP_GNU_push_tls_address, but since the operand appears on the
+     stack, it is relatively hard to find, and the idea of calling
+     target_translate_tls_address with OFFSET==0 and then adding the
+     offset by hand seemed too hackish.  */
+  if (is_tls)
+    {
+      struct frame_info *frame = get_selected_frame (NULL);
+      struct value *val;
+
+      if (frame == NULL)
+	error (_("Symbol \"%s\" cannot be used because "
+		 "there is no selected frame"),
+	       SYMBOL_PRINT_NAME (sym));
+
+      val = read_var_value (sym, frame);
+      if (VALUE_LVAL (val) != lval_memory)
+	error (_("Symbol \"%s\" cannot be used for compilation evaluation "
+		 "as its address has not been found."),
+	       SYMBOL_PRINT_NAME (sym));
+
+      warning (_("Symbol \"%s\" is thread-local and currently can only "
+		 "be referenced from the current thread in "
+		 "compiled code."),
+	       SYMBOL_PRINT_NAME (sym));
+
+      fprintfi_filtered (indent, stream, "%s = %s;\n",
+			 result_name,
+			 core_addr_to_string (value_address (val)));
+      fprintfi_filtered (indent - 2, stream, "}\n");
+      do_cleanups (cleanup);
+      return;
+    }
+
+  fprintfi_filtered (indent, stream, GCC_UINTPTR " __gdb_stack[%d];\n",
+		     stack_depth);
+
+  if (need_tempvar)
+    fprintfi_filtered (indent, stream, GCC_UINTPTR " __gdb_tmp;\n");
+  fprintfi_filtered (indent, stream, "int __gdb_tos = -1;\n");
+
+  if (initial != NULL)
+    pushf (indent, stream, core_addr_to_string (*initial));
+
+  while (op_ptr < op_end)
+    {
+      enum dwarf_location_atom op = *op_ptr;
+      uint64_t uoffset, reg;
+      int64_t offset;
+
+      print_spaces (indent - 2, stream);
+      if (info[op_ptr - base].label)
+	{
+	  print_label (stream, scope, op_ptr - base);
+	  fprintf_filtered (stream, ":;");
+	}
+      fprintf_filtered (stream, "/* %s */\n", get_DW_OP_name (op));
+
+      /* This is handy for debugging the generated code:
+      fprintf_filtered (stream, "if (__gdb_tos != %d) abort ();\n",
+			(int) info[op_ptr - base].depth - 1);
+      */
+
+      ++op_ptr;
+
+      switch (op)
+	{
+	case DW_OP_lit0:
+	case DW_OP_lit1:
+	case DW_OP_lit2:
+	case DW_OP_lit3:
+	case DW_OP_lit4:
+	case DW_OP_lit5:
+	case DW_OP_lit6:
+	case DW_OP_lit7:
+	case DW_OP_lit8:
+	case DW_OP_lit9:
+	case DW_OP_lit10:
+	case DW_OP_lit11:
+	case DW_OP_lit12:
+	case DW_OP_lit13:
+	case DW_OP_lit14:
+	case DW_OP_lit15:
+	case DW_OP_lit16:
+	case DW_OP_lit17:
+	case DW_OP_lit18:
+	case DW_OP_lit19:
+	case DW_OP_lit20:
+	case DW_OP_lit21:
+	case DW_OP_lit22:
+	case DW_OP_lit23:
+	case DW_OP_lit24:
+	case DW_OP_lit25:
+	case DW_OP_lit26:
+	case DW_OP_lit27:
+	case DW_OP_lit28:
+	case DW_OP_lit29:
+	case DW_OP_lit30:
+	case DW_OP_lit31:
+	  push (indent, stream, op - DW_OP_lit0);
+	  break;
+
+	case DW_OP_addr:
+	  op_ptr += addr_size;
+	  /* Some versions of GCC emit DW_OP_addr before
+	     DW_OP_GNU_push_tls_address.  In this case the value is an
+	     index, not an address.  We don't support things like
+	     branching between the address and the TLS op.  */
+	  if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
+	    uoffset += dwarf2_per_cu_text_offset (per_cu);
+	  push (indent, stream, uoffset);
+	  break;
+
+	case DW_OP_const1u:
+	  push (indent, stream,
+		extract_unsigned_integer (op_ptr, 1, byte_order));
+	  op_ptr += 1;
+	  break;
+	case DW_OP_const1s:
+	  push (indent, stream,
+		extract_signed_integer (op_ptr, 1, byte_order));
+	  op_ptr += 1;
+	  break;
+	case DW_OP_const2u:
+	  push (indent, stream,
+		extract_unsigned_integer (op_ptr, 2, byte_order));
+	  op_ptr += 2;
+	  break;
+	case DW_OP_const2s:
+	  push (indent, stream,
+		extract_signed_integer (op_ptr, 2, byte_order));
+	  op_ptr += 2;
+	  break;
+	case DW_OP_const4u:
+	  push (indent, stream,
+		extract_unsigned_integer (op_ptr, 4, byte_order));
+	  op_ptr += 4;
+	  break;
+	case DW_OP_const4s:
+	  push (indent, stream,
+		extract_signed_integer (op_ptr, 4, byte_order));
+	  op_ptr += 4;
+	  break;
+	case DW_OP_const8u:
+	  push (indent, stream,
+		extract_unsigned_integer (op_ptr, 8, byte_order));
+	  op_ptr += 8;
+	  break;
+	case DW_OP_const8s:
+	  push (indent, stream,
+		extract_signed_integer (op_ptr, 8, byte_order));
+	  op_ptr += 8;
+	  break;
+	case DW_OP_constu:
+	  op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
+	  push (indent, stream, uoffset);
+	  break;
+	case DW_OP_consts:
+	  op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+	  push (indent, stream, offset);
+	  break;
+
+	case DW_OP_reg0:
+	case DW_OP_reg1:
+	case DW_OP_reg2:
+	case DW_OP_reg3:
+	case DW_OP_reg4:
+	case DW_OP_reg5:
+	case DW_OP_reg6:
+	case DW_OP_reg7:
+	case DW_OP_reg8:
+	case DW_OP_reg9:
+	case DW_OP_reg10:
+	case DW_OP_reg11:
+	case DW_OP_reg12:
+	case DW_OP_reg13:
+	case DW_OP_reg14:
+	case DW_OP_reg15:
+	case DW_OP_reg16:
+	case DW_OP_reg17:
+	case DW_OP_reg18:
+	case DW_OP_reg19:
+	case DW_OP_reg20:
+	case DW_OP_reg21:
+	case DW_OP_reg22:
+	case DW_OP_reg23:
+	case DW_OP_reg24:
+	case DW_OP_reg25:
+	case DW_OP_reg26:
+	case DW_OP_reg27:
+	case DW_OP_reg28:
+	case DW_OP_reg29:
+	case DW_OP_reg30:
+	case DW_OP_reg31:
+	  dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
+	  pushf_register_address (indent, stream, registers_used, arch,
+				  dwarf2_reg_to_regnum_or_error (arch,
+							      op - DW_OP_reg0));
+	  break;
+
+	case DW_OP_regx:
+	  op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
+	  dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
+	  pushf_register_address (indent, stream, registers_used, arch,
+				  dwarf2_reg_to_regnum_or_error (arch, reg));
+	  break;
+
+	case DW_OP_breg0:
+	case DW_OP_breg1:
+	case DW_OP_breg2:
+	case DW_OP_breg3:
+	case DW_OP_breg4:
+	case DW_OP_breg5:
+	case DW_OP_breg6:
+	case DW_OP_breg7:
+	case DW_OP_breg8:
+	case DW_OP_breg9:
+	case DW_OP_breg10:
+	case DW_OP_breg11:
+	case DW_OP_breg12:
+	case DW_OP_breg13:
+	case DW_OP_breg14:
+	case DW_OP_breg15:
+	case DW_OP_breg16:
+	case DW_OP_breg17:
+	case DW_OP_breg18:
+	case DW_OP_breg19:
+	case DW_OP_breg20:
+	case DW_OP_breg21:
+	case DW_OP_breg22:
+	case DW_OP_breg23:
+	case DW_OP_breg24:
+	case DW_OP_breg25:
+	case DW_OP_breg26:
+	case DW_OP_breg27:
+	case DW_OP_breg28:
+	case DW_OP_breg29:
+	case DW_OP_breg30:
+	case DW_OP_breg31:
+	  op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+	  pushf_register (indent, stream, registers_used, arch,
+			  dwarf2_reg_to_regnum_or_error (arch,
+							 op - DW_OP_breg0),
+			  offset);
+	  break;
+	case DW_OP_bregx:
+	  {
+	    op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
+	    op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+	    pushf_register (indent, stream, registers_used, arch,
+			    dwarf2_reg_to_regnum_or_error (arch, reg), offset);
+	  }
+	  break;
+	case DW_OP_fbreg:
+	  {
+	    const gdb_byte *datastart;
+	    size_t datalen;
+	    const struct block *b;
+	    struct symbol *framefunc;
+	    char fb_name[50];
+
+	    b = block_for_pc (pc);
+
+	    if (!b)
+	      error (_("No block found for address"));
+
+	    framefunc = block_linkage_function (b);
+
+	    if (!framefunc)
+	      error (_("No function found for block"));
+
+	    func_get_frame_base_dwarf_block (framefunc, pc,
+					     &datastart, &datalen);
+
+	    op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
+
+	    /* Generate a unique-enough name, in case the frame base
+	       is computed multiple times in this expression.  */
+	    xsnprintf (fb_name, sizeof (fb_name), "__frame_base_%ld",
+		       (long) (op_ptr - base));
+
+	    do_compile_dwarf_expr_to_c (indent, stream,
+					"void *", fb_name,
+					sym, pc,
+					arch, registers_used, addr_size,
+					datastart, datastart + datalen,
+					NULL, per_cu);
+
+	    pushf (indent, stream, "%s + %s", fb_name, hex_string (offset));
+	  }
+	  break;
+
+	case DW_OP_dup:
+	  pushf (indent, stream, "__gdb_stack[__gdb_tos]");
+	  break;
+
+	case DW_OP_drop:
+	  fprintfi_filtered (indent, stream, "--__gdb_tos;\n");
+	  break;
+
+	case DW_OP_pick:
+	  offset = *op_ptr++;
+	  pushf (indent, stream, "__gdb_stack[__gdb_tos - %d]", offset);
+	  break;
+
+	case DW_OP_swap:
+	  fprintfi_filtered (indent, stream,
+			     "__gdb_tmp = __gdb_stack[__gdb_tos - 1];\n");
+	  fprintfi_filtered (indent, stream,
+			     "__gdb_stack[__gdb_tos - 1] = "
+			     "__gdb_stack[__gdb_tos];\n");
+	  fprintfi_filtered (indent, stream, ("__gdb_stack[__gdb_tos] = "
+					      "__gdb_tmp;\n"));
+	  break;
+
+	case DW_OP_over:
+	  pushf (indent, stream, "__gdb_stack[__gdb_tos - 1]");
+	  break;
+
+	case DW_OP_rot:
+	  fprintfi_filtered (indent, stream, ("__gdb_tmp = "
+					      "__gdb_stack[__gdb_tos];\n"));
+	  fprintfi_filtered (indent, stream,
+			     "__gdb_stack[__gdb_tos] = "
+			     "__gdb_stack[__gdb_tos - 1];\n");
+	  fprintfi_filtered (indent, stream,
+			     "__gdb_stack[__gdb_tos - 1] = "
+			     "__gdb_stack[__gdb_tos -2];\n");
+	  fprintfi_filtered (indent, stream, "__gdb_stack[__gdb_tos - 2] = "
+			     "__gdb_tmp;\n");
+	  break;
+
+	case DW_OP_deref:
+	case DW_OP_deref_size:
+	  {
+	    int size;
+	    const char *mode;
+
+	    if (op == DW_OP_deref_size)
+	      size = *op_ptr++;
+	    else
+	      size = addr_size;
+
+	    mode = c_get_mode_for_size (size);
+	    if (mode == NULL)
+	      error (_("Unsupported size %d in %s"),
+		     size, get_DW_OP_name (op));
+
+	    /* Cast to a pointer of the desired type, then
+	       dereference.  */
+	    fprintfi_filtered (indent, stream,
+			       "__gdb_stack[__gdb_tos] = "
+			       "*((__gdb_int_%s *) "
+			       "__gdb_stack[__gdb_tos]);\n",
+			       mode);
+	  }
+	  break;
+
+	case DW_OP_abs:
+	  unary (indent, stream,
+		 "((" GCC_INTPTR ") __gdb_stack[__gdb_tos]) < 0 ? "
+		 "-__gdb_stack[__gdb_tos] : __gdb_stack[__gdb_tos]");
+	  break;
+
+	case DW_OP_neg:
+	  unary (indent, stream, "-__gdb_stack[__gdb_tos]");
+	  break;
+
+	case DW_OP_not:
+	  unary (indent, stream, "~__gdb_stack[__gdb_tos]");
+	  break;
+
+	case DW_OP_plus_uconst:
+	  op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
+	  unary (indent, stream, "__gdb_stack[__gdb_tos] + %s",
+		 hex_string (reg));
+	  break;
+
+	case DW_OP_div:
+	  binary (indent, stream, ("((" GCC_INTPTR
+				   ") __gdb_stack[__gdb_tos-1]) / (("
+				   GCC_INTPTR ") __gdb_stack[__gdb_tos])"));
+	  break;
+
+	case DW_OP_shra:
+	  binary (indent, stream,
+		  "((" GCC_INTPTR ") __gdb_stack[__gdb_tos-1]) >> "
+		  "__gdb_stack[__gdb_tos]");
+	  break;
+
+#define BINARY(OP)							\
+	  binary (indent, stream, ("__gdb_stack[__gdb_tos-1] " #OP	\
+				   " __gdb_stack[__gdb_tos]"));	\
+	  break
+
+	case DW_OP_and:
+	  BINARY (&);
+	case DW_OP_minus:
+	  BINARY (-);
+	case DW_OP_mod:
+	  BINARY (%);
+	case DW_OP_mul:
+	  BINARY (*);
+	case DW_OP_or:
+	  BINARY (|);
+	case DW_OP_plus:
+	  BINARY (+);
+	case DW_OP_shl:
+	  BINARY (<<);
+	case DW_OP_shr:
+	  BINARY (>>);
+	case DW_OP_xor:
+	  BINARY (^);
+#undef BINARY
+
+#define COMPARE(OP)							\
+	  binary (indent, stream,					\
+		  "(((" GCC_INTPTR ") __gdb_stack[__gdb_tos-1]) " #OP	\
+		  " ((" GCC_INTPTR					\
+		  ") __gdb_stack[__gdb_tos]))");			\
+	  break
+
+	case DW_OP_le:
+	  COMPARE (<=);
+	case DW_OP_ge:
+	  COMPARE (>=);
+	case DW_OP_eq:
+	  COMPARE (==);
+	case DW_OP_lt:
+	  COMPARE (<);
+	case DW_OP_gt:
+	  COMPARE (>);
+	case DW_OP_ne:
+	  COMPARE (!=);
+#undef COMPARE
+
+	case DW_OP_call_frame_cfa:
+	  {
+	    int regnum;
+	    CORE_ADDR text_offset;
+	    LONGEST off;
+	    const gdb_byte *cfa_start, *cfa_end;
+
+	    if (dwarf2_fetch_cfa_info (arch, pc, per_cu,
+				       &regnum, &off,
+				       &text_offset, &cfa_start, &cfa_end))
+	      {
+		/* Register.  */
+		pushf_register (indent, stream, registers_used, arch, regnum,
+				off);
+	      }
+	    else
+	      {
+		/* Another expression.  */
+		char cfa_name[50];
+
+		/* Generate a unique-enough name, in case the CFA is
+		   computed multiple times in this expression.  */
+		xsnprintf (cfa_name, sizeof (cfa_name),
+			   "__cfa_%ld", (long) (op_ptr - base));
+
+		do_compile_dwarf_expr_to_c (indent, stream,
+					    "void *", cfa_name,
+					    sym, pc, arch, registers_used,
+					    addr_size,
+					    cfa_start, cfa_end,
+					    &text_offset, per_cu);
+		pushf (indent, stream, cfa_name);
+	      }
+	  }
+
+	  break;
+
+	case DW_OP_skip:
+	  offset = extract_signed_integer (op_ptr, 2, byte_order);
+	  op_ptr += 2;
+	  fprintfi_filtered (indent, stream, "goto ");
+	  print_label (stream, scope, op_ptr + offset - base);
+	  fprintf_filtered (stream, ";\n");
+	  break;
+
+	case DW_OP_bra:
+	  offset = extract_signed_integer (op_ptr, 2, byte_order);
+	  op_ptr += 2;
+	  fprintfi_filtered (indent, stream,
+			     "if ((( " GCC_INTPTR
+			     ") __gdb_stack[__gdb_tos--]) != 0) goto ");
+	  print_label (stream, scope, op_ptr + offset - base);
+	  fprintf_filtered (stream, ";\n");
+	  break;
+
+	case DW_OP_nop:
+	  break;
+
+	default:
+	  error (_("unhandled DWARF op: %s"), get_DW_OP_name (op));
+	}
+    }
+
+  fprintfi_filtered (indent, stream, "%s = (%s) __gdb_stack[__gdb_tos];\n",
+		     result_name, type_name);
+  fprintfi_filtered (indent - 2, stream, "}\n");
+
+  do_cleanups (cleanup);
+}
+
+/* See compile.h.  */
+
+void
+compile_dwarf_expr_to_c (struct ui_file *stream, const char *result_name,
+			 struct symbol *sym, CORE_ADDR pc,
+			 struct gdbarch *arch, unsigned char *registers_used,
+			 unsigned int addr_size,
+			 const gdb_byte *op_ptr, const gdb_byte *op_end,
+			 struct dwarf2_per_cu_data *per_cu)
+{
+  do_compile_dwarf_expr_to_c (2, stream, "void *", result_name, sym, pc,
+			      arch, registers_used, addr_size, op_ptr, op_end,
+			      NULL, per_cu);
+}
+
+/* See compile.h.  */
+
+void
+compile_dwarf_bounds_to_c (struct ui_file *stream,
+			   const char *result_name,
+			   const struct dynamic_prop *prop,
+			   struct symbol *sym, CORE_ADDR pc,
+			   struct gdbarch *arch, unsigned char *registers_used,
+			   unsigned int addr_size,
+			   const gdb_byte *op_ptr, const gdb_byte *op_end,
+			   struct dwarf2_per_cu_data *per_cu)
+{
+  do_compile_dwarf_expr_to_c (2, stream, "unsigned long ", result_name,
+			      sym, pc, arch, registers_used,
+			      addr_size, op_ptr, op_end, NULL, per_cu);
+}
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
new file mode 100644
index 0000000..eedc9fa
--- /dev/null
+++ b/gdb/compile/compile-object-load.c
@@ -0,0 +1,588 @@
+/* Load module for 'compile' command.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "compile-object-load.h"
+#include "compile-internal.h"
+#include "command.h"
+#include "objfiles.h"
+#include "gdbcore.h"
+#include "readline/tilde.h"
+#include "bfdlink.h"
+#include "gdbcmd.h"
+#include "regcache.h"
+#include "inferior.h"
+#include "compile.h"
+#include "arch-utils.h"
+
+/* Helper data for setup_sections.  */
+
+struct setup_sections_data
+{
+  /* Size of all recent sections with matching LAST_PROT.  */
+  CORE_ADDR last_size;
+
+  /* First section matching LAST_PROT.  */
+  asection *last_section_first;
+
+  /* Memory protection like the prot parameter of gdbarch_infcall_mmap. */
+  unsigned last_prot;
+
+  /* Maximum of alignments of all sections matching LAST_PROT.
+     This value is always at least 1.  This value is always a power of 2.  */
+  CORE_ADDR last_max_alignment;
+};
+
+/* Place all ABFD sections next to each other obeying all constraints.  */
+
+static void
+setup_sections (bfd *abfd, asection *sect, void *data_voidp)
+{
+  struct setup_sections_data *data = data_voidp;
+  CORE_ADDR alignment;
+  unsigned prot;
+
+  if (sect != NULL)
+    {
+      /* It is required by later bfd_get_relocated_section_contents.  */
+      if (sect->output_section == NULL)
+	sect->output_section = sect;
+
+      if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0)
+	return;
+
+      // Make the memory always readable.
+      prot = GDB_MMAP_PROT_READ;
+      if ((bfd_get_section_flags (abfd, sect) & SEC_READONLY) == 0)
+	prot |= GDB_MMAP_PROT_WRITE;
+      if ((bfd_get_section_flags (abfd, sect) & SEC_CODE) != 0)
+	prot |= GDB_MMAP_PROT_EXEC;
+
+      if (compile_debug)
+	fprintf_unfiltered (gdb_stdout,
+			    "module \"%s\" section \"%s\" size %s prot %u\n",
+			    bfd_get_filename (abfd),
+			    bfd_get_section_name (abfd, sect),
+			    paddress (target_gdbarch (),
+				      bfd_get_section_size (sect)),
+			    prot);
+    }
+  else
+    prot = -1;
+
+  if (sect == NULL
+      || (data->last_prot != prot && bfd_get_section_size (sect) != 0))
+    {
+      CORE_ADDR addr;
+      asection *sect_iter;
+
+      if (data->last_size != 0)
+	{
+	  addr = gdbarch_infcall_mmap (target_gdbarch (), data->last_size,
+				       data->last_prot);
+	  if (compile_debug)
+	    fprintf_unfiltered (gdb_stdout,
+				"allocated %s bytes at %s prot %u\n",
+				paddress (target_gdbarch (), data->last_size),
+				paddress (target_gdbarch (), addr),
+				data->last_prot);
+	}
+      else
+	addr = 0;
+
+      if ((addr & (data->last_max_alignment - 1)) != 0)
+	error (_("Inferior compiled module address %s "
+		 "is not aligned to BFD required %s."),
+	       paddress (target_gdbarch (), addr),
+	       paddress (target_gdbarch (), data->last_max_alignment));
+
+      for (sect_iter = data->last_section_first; sect_iter != sect;
+	   sect_iter = sect_iter->next)
+	if ((bfd_get_section_flags (abfd, sect_iter) & SEC_ALLOC) != 0)
+	  bfd_set_section_vma (abfd, sect_iter,
+			       addr + bfd_get_section_vma (abfd, sect_iter));
+
+      data->last_size = 0;
+      data->last_section_first = sect;
+      data->last_prot = prot;
+      data->last_max_alignment = 1;
+    }
+
+  if (sect == NULL)
+    return;
+
+  alignment = ((CORE_ADDR) 1) << bfd_get_section_alignment (abfd, sect);
+  data->last_max_alignment = max (data->last_max_alignment, alignment);
+
+  data->last_size = (data->last_size + alignment - 1) & -alignment;
+
+  bfd_set_section_vma (abfd, sect, data->last_size);
+
+  data->last_size += bfd_get_section_size (sect);
+  data->last_size = (data->last_size + alignment - 1) & -alignment;
+}
+
+/* Helper for link_callbacks callbacks vector.  */
+
+static bfd_boolean
+link_callbacks_multiple_definition (struct bfd_link_info *link_info,
+				    struct bfd_link_hash_entry *h, bfd *nbfd,
+				    asection *nsec, bfd_vma nval)
+{
+  bfd *abfd = link_info->input_bfds;
+
+  if (link_info->allow_multiple_definition)
+    return TRUE;
+  warning (_("Compiled module \"%s\": multiple symbol definitions: %s\n"),
+	   bfd_get_filename (abfd), h->root.string);
+  return FALSE;
+}
+
+/* Helper for link_callbacks callbacks vector.  */
+
+static bfd_boolean
+link_callbacks_warning (struct bfd_link_info *link_info, const char *xwarning,
+                        const char *symbol, bfd *abfd, asection *section,
+			bfd_vma address)
+{
+  warning (_("Compiled module \"%s\" section \"%s\": warning: %s\n"),
+	   bfd_get_filename (abfd), bfd_get_section_name (abfd, section),
+	   xwarning);
+  /* Maybe permit running as a module?  */
+  return FALSE;
+}
+
+/* Helper for link_callbacks callbacks vector.  */
+
+static bfd_boolean
+link_callbacks_undefined_symbol (struct bfd_link_info *link_info,
+				 const char *name, bfd *abfd, asection *section,
+				 bfd_vma address, bfd_boolean is_fatal)
+{
+  warning (_("Cannot resolve relocation to \"%s\" "
+	     "from compiled module \"%s\" section \"%s\"."),
+	   name, bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
+  return FALSE;
+}
+
+/* Helper for link_callbacks callbacks vector.  */
+
+static bfd_boolean
+link_callbacks_reloc_overflow (struct bfd_link_info *link_info,
+			       struct bfd_link_hash_entry *entry,
+			       const char *name, const char *reloc_name,
+			       bfd_vma addend, bfd *abfd, asection *section,
+			       bfd_vma address)
+{
+  /* TRUE is required for intra-module relocations.  */
+  return TRUE;
+}
+
+/* Helper for link_callbacks callbacks vector.  */
+
+static bfd_boolean
+link_callbacks_reloc_dangerous (struct bfd_link_info *link_info,
+				const char *message, bfd *abfd,
+				asection *section, bfd_vma address)
+{
+  warning (_("Compiled module \"%s\" section \"%s\": dangerous "
+	     "relocation: %s\n"),
+	   bfd_get_filename (abfd), bfd_get_section_name (abfd, section),
+	   message);
+  return FALSE;
+}
+
+/* Helper for link_callbacks callbacks vector.  */
+
+static bfd_boolean
+link_callbacks_unattached_reloc (struct bfd_link_info *link_info,
+				 const char *name, bfd *abfd, asection *section,
+				 bfd_vma address)
+{
+  warning (_("Compiled module \"%s\" section \"%s\": unattached "
+	     "relocation: %s\n"),
+	   bfd_get_filename (abfd), bfd_get_section_name (abfd, section),
+	   name);
+  return FALSE;
+}
+
+/* Helper for link_callbacks callbacks vector.  */
+
+static void
+link_callbacks_einfo (const char *fmt, ...)
+{
+  struct cleanup *cleanups;
+  va_list ap;
+  char *str;
+
+  va_start (ap, fmt);
+  str = xstrvprintf (fmt, ap);
+  va_end (ap);
+  cleanups = make_cleanup (xfree, str);
+
+  warning (_("Compile module: warning: %s\n"), str);
+
+  do_cleanups (cleanups);
+}
+
+/* Helper for bfd_get_relocated_section_contents.
+   Only these symbols are set by bfd_simple_get_relocated_section_contents
+   but bfd/ seems to use even the NULL ones without checking them first.  */
+
+static const struct bfd_link_callbacks link_callbacks =
+{
+  NULL, /* add_archive_element */
+  link_callbacks_multiple_definition, /* multiple_definition */
+  NULL, /* multiple_common */
+  NULL, /* add_to_set */
+  NULL, /* constructor */
+  link_callbacks_warning, /* warning */
+  link_callbacks_undefined_symbol, /* undefined_symbol */
+  link_callbacks_reloc_overflow, /* reloc_overflow */
+  link_callbacks_reloc_dangerous, /* reloc_dangerous */
+  link_callbacks_unattached_reloc, /* unattached_reloc */
+  NULL, /* notice */
+  link_callbacks_einfo, /* einfo */
+  NULL, /* info */
+  NULL, /* minfo */
+  NULL, /* override_segment_assignment */
+};
+
+struct link_hash_table_cleanup_data
+{
+  bfd *abfd;
+  bfd *link_next;
+};
+
+/* Cleanup callback for struct bfd_link_info.  */
+
+static void
+link_hash_table_free (void *d)
+{
+  struct link_hash_table_cleanup_data *data = d;
+
+  if (data->abfd->is_linker_output)
+    (*data->abfd->link.hash->hash_table_free) (data->abfd);
+  data->abfd->link.next = data->link_next;
+}
+
+/* Relocate and store into inferior memory each section SECT of ABFD.  */
+
+static void
+copy_sections (bfd *abfd, asection *sect, void *data)
+{
+  asymbol **symbol_table = data;
+  bfd_byte *sect_data, *sect_data_got;
+  struct cleanup *cleanups;
+  struct bfd_link_info link_info;
+  struct bfd_link_order link_order;
+  CORE_ADDR inferior_addr;
+  struct link_hash_table_cleanup_data cleanup_data;
+
+  if ((bfd_get_section_flags (abfd, sect) & (SEC_ALLOC | SEC_LOAD))
+      != (SEC_ALLOC | SEC_LOAD))
+    return;
+
+  if (bfd_get_section_size (sect) == 0)
+    return;
+
+  /* Mostly a copy of bfd_simple_get_relocated_section_contents which GDB
+     cannot use as it does not report relocations to undefined symbols.  */
+  memset (&link_info, 0, sizeof (link_info));
+  link_info.output_bfd = abfd;
+  link_info.input_bfds = abfd;
+  link_info.input_bfds_tail = &abfd->link.next;
+
+  cleanup_data.abfd = abfd;
+  cleanup_data.link_next = abfd->link.next;
+
+  abfd->link.next = NULL;
+  link_info.hash = bfd_link_hash_table_create (abfd);
+
+  cleanups = make_cleanup (link_hash_table_free, &cleanup_data);
+  link_info.callbacks = &link_callbacks;
+
+  memset (&link_order, 0, sizeof (link_order));
+  link_order.next = NULL;
+  link_order.type = bfd_indirect_link_order;
+  link_order.offset = 0;
+  link_order.size = bfd_get_section_size (sect);
+  link_order.u.indirect.section = sect;
+
+  sect_data = xmalloc (bfd_get_section_size (sect));
+  make_cleanup (xfree, sect_data);
+
+  sect_data_got = bfd_get_relocated_section_contents (abfd, &link_info,
+						      &link_order, sect_data,
+						      FALSE, symbol_table);
+
+  if (sect_data_got == NULL)
+    error (_("Cannot map compiled module \"%s\" section \"%s\": %s"),
+	   bfd_get_filename (abfd), bfd_get_section_name (abfd, sect),
+	   bfd_errmsg (bfd_get_error ()));
+  gdb_assert (sect_data_got == sect_data);
+
+  inferior_addr = bfd_get_section_vma (abfd, sect);
+  if (0 != target_write_memory (inferior_addr, sect_data,
+				bfd_get_section_size (sect)))
+    error (_("Cannot write compiled module \"%s\" section \"%s\" "
+	     "to inferior memory range %s-%s."),
+	   bfd_get_filename (abfd), bfd_get_section_name (abfd, sect),
+	   paddress (target_gdbarch (), inferior_addr),
+	   paddress (target_gdbarch (),
+		     inferior_addr + bfd_get_section_size (sect)));
+
+  do_cleanups (cleanups);
+}
+
+/* Fetch the type of first parameter of GCC_FE_WRAPPER_FUNCTION.
+   Return NULL if GCC_FE_WRAPPER_FUNCTION has no parameters.
+   Throw an error otherwise.  */
+
+static struct type *
+get_regs_type (struct objfile *objfile)
+{
+  struct symbol *func_sym;
+  struct type *func_type, *regsp_type, *regs_type;
+
+  func_sym = lookup_global_symbol_from_objfile (objfile,
+						GCC_FE_WRAPPER_FUNCTION,
+						VAR_DOMAIN);
+  if (func_sym == NULL)
+    error (_("Cannot find function \"%s\" in compiled module \"%s\"."),
+	   GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
+
+  func_type = SYMBOL_TYPE (func_sym);
+  if (TYPE_CODE (func_type) != TYPE_CODE_FUNC)
+    error (_("Invalid type code %d of function \"%s\" in compiled "
+	     "module \"%s\"."),
+	   TYPE_CODE (func_type), GCC_FE_WRAPPER_FUNCTION,
+	   objfile_name (objfile));
+
+  /* No register parameter present.  */
+  if (TYPE_NFIELDS (func_type) == 0)
+    return NULL;
+
+  if (TYPE_NFIELDS (func_type) != 1)
+    error (_("Invalid %d parameters of function \"%s\" in compiled "
+	     "module \"%s\"."),
+	   TYPE_NFIELDS (func_type), GCC_FE_WRAPPER_FUNCTION,
+	   objfile_name (objfile));
+
+  regsp_type = check_typedef (TYPE_FIELD_TYPE (func_type, 0));
+  if (TYPE_CODE (regsp_type) != TYPE_CODE_PTR)
+    error (_("Invalid type code %d of first parameter of function \"%s\" "
+	     "in compiled module \"%s\"."),
+	   TYPE_CODE (regsp_type), GCC_FE_WRAPPER_FUNCTION,
+	   objfile_name (objfile));
+
+  regs_type = check_typedef (TYPE_TARGET_TYPE (regsp_type));
+  if (TYPE_CODE (regs_type) != TYPE_CODE_STRUCT)
+    error (_("Invalid type code %d of dereferenced first parameter "
+	     "of function \"%s\" in compiled module \"%s\"."),
+	   TYPE_CODE (regs_type), GCC_FE_WRAPPER_FUNCTION,
+	   objfile_name (objfile));
+
+  return regs_type;
+}
+
+/* Store all inferior registers required by REGS_TYPE to inferior memory
+   starting at inferior address REGS_BASE.  */
+
+static void
+store_regs (struct type *regs_type, CORE_ADDR regs_base)
+{
+  struct gdbarch *gdbarch = target_gdbarch ();
+  struct regcache *regcache = get_thread_regcache (inferior_ptid);
+  int fieldno;
+
+  for (fieldno = 0; fieldno < TYPE_NFIELDS (regs_type); fieldno++)
+    {
+      const char *reg_name = TYPE_FIELD_NAME (regs_type, fieldno);
+      ULONGEST reg_bitpos = TYPE_FIELD_BITPOS (regs_type, fieldno);
+      ULONGEST reg_bitsize = TYPE_FIELD_BITSIZE (regs_type, fieldno);
+      ULONGEST reg_offset;
+      struct type *reg_type = check_typedef (TYPE_FIELD_TYPE (regs_type,
+							      fieldno));
+      ULONGEST reg_size = TYPE_LENGTH (reg_type);
+      int regnum;
+      struct value *regval;
+      CORE_ADDR inferior_addr;
+
+      if (strcmp (reg_name, COMPILE_I_SIMPLE_REGISTER_DUMMY) == 0)
+	continue;
+
+      if ((reg_bitpos % 8) != 0 || reg_bitsize != 0)
+	error (_("Invalid register \"%s\" position %s bits or size %s bits"),
+	       reg_name, pulongest (reg_bitpos), pulongest (reg_bitsize));
+      reg_offset = reg_bitpos / 8;
+
+      if (TYPE_CODE (reg_type) != TYPE_CODE_INT
+	  && TYPE_CODE (reg_type) != TYPE_CODE_PTR)
+	error (_("Invalid register \"%s\" type code %d"), reg_name,
+	       TYPE_CODE (reg_type));
+
+      regnum = compile_register_name_demangle (gdbarch, reg_name);
+
+      regval = value_from_register (reg_type, regnum, get_current_frame ());
+      if (value_optimized_out (regval))
+	error (_("Register \"%s\" is optimized out."), reg_name);
+      if (!value_entirely_available (regval))
+	error (_("Register \"%s\" is not available."), reg_name);
+
+      inferior_addr = regs_base + reg_offset;
+      if (0 != target_write_memory (inferior_addr, value_contents (regval),
+				    reg_size))
+	error (_("Cannot write register \"%s\" to inferior memory at %s."),
+	       reg_name, paddress (gdbarch, inferior_addr));
+    }
+}
+
+/* Load OBJECT_FILE into inferior memory.  Throw an error otherwise.
+   Caller must fully dispose the return value by calling compile_object_run.
+   SOURCE_FILE's copy is stored into the returned object.
+   Caller should free both OBJECT_FILE and SOURCE_FILE immediatelly after this
+   function returns.  */
+
+struct compile_module *
+compile_object_load (const char *object_file, const char *source_file)
+{
+  struct cleanup *cleanups, *cleanups_free_objfile;
+  bfd *abfd;
+  struct setup_sections_data setup_sections_data;
+  CORE_ADDR addr, func_addr, regs_addr;
+  struct bound_minimal_symbol bmsym;
+  long storage_needed;
+  asymbol **symbol_table, **symp;
+  long number_of_symbols, missing_symbols;
+  struct type *dptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
+  unsigned dptr_type_len = TYPE_LENGTH (dptr_type);
+  struct compile_module *retval;
+  struct type *regs_type;
+  char *filename, **matching;
+  struct objfile *objfile;
+
+  filename = tilde_expand (object_file);
+  cleanups = make_cleanup (xfree, filename);
+
+  abfd = gdb_bfd_open (filename, gnutarget, -1);
+  if (abfd == NULL)
+    error (_("\"%s\": could not open as compiled module: %s"),
+          filename, bfd_errmsg (bfd_get_error ()));
+  make_cleanup_bfd_unref (abfd);
+
+  if (!bfd_check_format_matches (abfd, bfd_object, &matching))
+    error (_("\"%s\": not in loadable format: %s"),
+          filename, gdb_bfd_errmsg (bfd_get_error (), matching));
+
+  if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) != 0)
+    error (_("\"%s\": not in object format."), filename);
+
+  setup_sections_data.last_size = 0;
+  setup_sections_data.last_section_first = abfd->sections;
+  setup_sections_data.last_prot = -1;
+  setup_sections_data.last_max_alignment = 1;
+  bfd_map_over_sections (abfd, setup_sections, &setup_sections_data);
+  setup_sections (abfd, NULL, &setup_sections_data);
+
+  storage_needed = bfd_get_symtab_upper_bound (abfd);
+  if (storage_needed < 0)
+    error (_("Cannot read symbols of compiled module \"%s\": %s"),
+          filename, bfd_errmsg (bfd_get_error ()));
+
+  /* SYMFILE_VERBOSE is not passed even if FROM_TTY, user is not interested in
+     "Reading symbols from ..." message for automatically generated file.  */
+  objfile = symbol_file_add_from_bfd (abfd, filename, 0, NULL, 0, NULL);
+  cleanups_free_objfile = make_cleanup_free_objfile (objfile);
+
+  bmsym = lookup_minimal_symbol_text (GCC_FE_WRAPPER_FUNCTION, objfile);
+  if (bmsym.minsym == NULL || MSYMBOL_TYPE (bmsym.minsym) == mst_file_text)
+    error (_("Could not find symbol \"%s\" of compiled module \"%s\"."),
+	   GCC_FE_WRAPPER_FUNCTION, filename);
+  func_addr = BMSYMBOL_VALUE_ADDRESS (bmsym);
+
+  /* The memory may be later needed
+     by bfd_generic_get_relocated_section_contents
+     called from default_symfile_relocate.  */
+  symbol_table = obstack_alloc (&objfile->objfile_obstack, storage_needed);
+  number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
+  if (number_of_symbols < 0)
+    error (_("Cannot parse symbols of compiled module \"%s\": %s"),
+          filename, bfd_errmsg (bfd_get_error ()));
+
+  missing_symbols = 0;
+  for (symp = symbol_table; symp < symbol_table + number_of_symbols; symp++)
+    {
+      asymbol *sym = *symp;
+
+      if (sym->flags != 0)
+	continue;
+      if (compile_debug)
+	fprintf_unfiltered (gdb_stdout,
+			    "lookup undefined ELF symbol \"%s\"\n",
+			    sym->name);
+      sym->flags = BSF_GLOBAL;
+      sym->section = bfd_abs_section_ptr;
+      if (strcmp (sym->name, "_GLOBAL_OFFSET_TABLE_") == 0)
+	{
+	  sym->value = 0;
+	  continue;
+	}
+      bmsym = lookup_minimal_symbol (sym->name, NULL, NULL);
+      switch (bmsym.minsym == NULL
+	      ? mst_unknown : MSYMBOL_TYPE (bmsym.minsym))
+	{
+	case mst_text:
+	  sym->value = BMSYMBOL_VALUE_ADDRESS (bmsym);
+	  break;
+	default:
+	  warning (_("Could not find symbol \"%s\" "
+		     "for compiled module \"%s\"."),
+		   sym->name, filename);
+	  missing_symbols++;
+	}
+    }
+  if (missing_symbols)
+    error (_("%ld symbols were missing, cannot continue."), missing_symbols);
+
+  bfd_map_over_sections (abfd, copy_sections, symbol_table);
+
+  regs_type = get_regs_type (objfile);
+  if (regs_type == NULL)
+    regs_addr = 0;
+  else
+    {
+      /* Use read-only non-executable memory protection.  */
+      regs_addr = gdbarch_infcall_mmap (target_gdbarch (),
+					TYPE_LENGTH (regs_type),
+					GDB_MMAP_PROT_READ);
+      gdb_assert (regs_addr != 0);
+      store_regs (regs_type, regs_addr);
+    }
+
+  discard_cleanups (cleanups_free_objfile);
+  do_cleanups (cleanups);
+
+  retval = xmalloc (sizeof (*retval));
+  retval->objfile = objfile;
+  retval->source_file = xstrdup (source_file);
+  retval->func_addr = func_addr;
+  retval->regs_addr = regs_addr;
+  return retval;
+}
diff --git a/gdb/compile/compile-object-load.h b/gdb/compile/compile-object-load.h
new file mode 100644
index 0000000..850111e
--- /dev/null
+++ b/gdb/compile/compile-object-load.h
@@ -0,0 +1,39 @@
+/* Header file to load module for 'compile' command.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_COMPILE_OBJECT_LOAD_H
+#define GDB_COMPILE_OBJECT_LOAD_H
+
+struct compile_module
+{
+  /* objfile for the compiled module.  */
+  struct objfile *objfile;
+
+  /* .c file OBJFILE was built from.  It needs to be xfree-d.  */
+  char *source_file;
+
+  /* Inferior function address.  */
+  CORE_ADDR func_addr;
+
+  /* Inferior registers address or NULL if the inferior function does not
+     require any.  */
+  CORE_ADDR regs_addr;
+};
+
+extern struct compile_module *compile_object_load (const char *object_file,
+						   const char *source_file);
+
+#endif /* GDB_COMPILE_OBJECT_LOAD_H */
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
new file mode 100644
index 0000000..b7c4c4d
--- /dev/null
+++ b/gdb/compile/compile-object-run.c
@@ -0,0 +1,138 @@
+/* Call module for 'compile' command.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "compile-object-run.h"
+#include "value.h"
+#include "infcall.h"
+#include "objfiles.h"
+#include "compile-internal.h"
+#include "dummy-frame.h"
+
+/* Helper for do_module_cleanup.  */
+
+struct do_module_cleanup
+{
+  /* Boolean to set true upon a call of do_module_cleanup.
+     The pointer may be NULL.  */
+  int *executedp;
+
+  /* .c file OBJFILE was built from.  It needs to be xfree-d.  */
+  char *source_file;
+
+  /* objfile_name of our objfile.  */
+  char objfile_name_string[1];
+};
+
+/* Cleanup everything after the inferior function dummy frame gets
+   discarded.  */
+
+static dummy_frame_dtor_ftype do_module_cleanup;
+static void
+do_module_cleanup (void *arg)
+{
+  struct do_module_cleanup *data = arg;
+  struct objfile *objfile;
+
+  if (data->executedp != NULL)
+    *data->executedp = 1;
+
+  ALL_OBJFILES (objfile)
+    if ((objfile->flags & OBJF_USERLOADED) == 0
+        && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0))
+      {
+	free_objfile (objfile);
+
+	/* It may be a bit too pervasive in this dummy_frame dtor callback.  */
+	clear_symtab_users (0);
+
+	break;
+      }
+
+  /* Delete the .c file.  */
+  unlink (data->source_file);
+  xfree (data->source_file);
+
+  /* Delete the .o file.  */
+  unlink (data->objfile_name_string);
+  xfree (data);
+}
+
+/* Perform inferior call of MODULE.  This function may throw an error.
+   This function may leave files referenced by MODULE on disk until
+   the inferior call dummy frame is discarded.  This function may throw errors.
+   Thrown errors and left MODULE files are unrelated events.  Caller must no
+   longer touch MODULE's memory after this function has been called.  */
+
+void
+compile_object_run (struct compile_module *module)
+{
+  struct value *func_val;
+  struct frame_id dummy_id;
+  struct cleanup *cleanups;
+  struct do_module_cleanup *data;
+  volatile struct gdb_exception ex;
+  const char *objfile_name_s = objfile_name (module->objfile);
+  int dtor_found, executed = 0;
+  CORE_ADDR func_addr = module->func_addr;
+  CORE_ADDR regs_addr = module->regs_addr;
+
+  data = xmalloc (sizeof (*data) + strlen (objfile_name_s));
+  data->executedp = &executed;
+  data->source_file = xstrdup (module->source_file);
+  strcpy (data->objfile_name_string, objfile_name_s);
+
+  xfree (module->source_file);
+  xfree (module);
+
+  TRY_CATCH (ex, RETURN_MASK_ERROR)
+    {
+      func_val = value_from_pointer
+		 (builtin_type (target_gdbarch ())->builtin_func_ptr,
+		  func_addr);
+
+      if (regs_addr == 0)
+	call_function_by_hand_dummy (func_val, 0, NULL,
+				     do_module_cleanup, data);
+      else
+	{
+	  struct value *arg_val;
+
+	  arg_val = value_from_pointer
+		    (builtin_type (target_gdbarch ())->builtin_func_ptr,
+		     regs_addr);
+	  call_function_by_hand_dummy (func_val, 1, &arg_val,
+				       do_module_cleanup, data);
+	}
+    }
+  dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
+  if (!executed)
+    data->executedp = NULL;
+  if (ex.reason >= 0)
+    gdb_assert (!dtor_found && executed);
+  else
+    {
+      /* In the case od DTOR_FOUND or in the case of EXECUTED nothing
+	 needs to be done.  */
+      gdb_assert (!(dtor_found && executed));
+      if (!dtor_found && !executed)
+	do_module_cleanup (data);
+      throw_exception (ex);
+    }
+}
diff --git a/gdb/compile/compile-object-run.h b/gdb/compile/compile-object-run.h
new file mode 100644
index 0000000..71ba077
--- /dev/null
+++ b/gdb/compile/compile-object-run.h
@@ -0,0 +1,24 @@
+/* Header file to call module for 'compile' command.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_COMPILE_OBJECT_RUN_H
+#define GDB_COMPILE_OBJECT_RUN_H
+
+#include "compile-object-load.h"
+
+extern void compile_object_run (struct compile_module *module);
+
+#endif /* GDB_COMPILE_OBJECT_RUN_H */
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
new file mode 100644
index 0000000..6d3d16e
--- /dev/null
+++ b/gdb/compile/compile.c
@@ -0,0 +1,651 @@
+/* General Compile and inject code
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "interps.h"
+#include "ui-out.h"
+#include "command.h"
+#include "cli/cli-script.h"
+#include "cli/cli-utils.h"
+#include "completer.h"
+#include "gdbcmd.h"
+#include "compile.h"
+#include "compile-internal.h"
+#include "compile-object-load.h"
+#include "compile-object-run.h"
+#include "language.h"
+#include "frame.h"
+#include "source.h"
+#include "block.h"
+#include "arch-utils.h"
+#include "filestuff.h"
+#include "target.h"
+#include "osabi.h"
+
+\f
+
+/* Initial filename for temporary files.  */
+
+#define TMP_PREFIX "/tmp/gdbobj-"
+
+/* Hold "compile" commands.  */
+
+static struct cmd_list_element *compile_command_list;
+
+/* Debug flag for "compile" commands.  */
+
+int compile_debug;
+
+/* Implement "show debug compile".  */
+
+static void
+show_compile_debug (struct ui_file *file, int from_tty,
+		    struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Compile debugging is %s.\n"), value);
+}
+
+\f
+
+/* Check *ARG for a "-raw" or "-r" argument.  Return 0 if not seen.
+   Return 1 if seen and update *ARG.  */
+
+static int
+check_raw_argument (char **arg)
+{
+  *arg = skip_spaces (*arg);
+
+  if (arg != NULL
+      && (check_for_argument (arg, "-raw", sizeof ("-raw") - 1)
+	  || check_for_argument (arg, "-r", sizeof ("-r") - 1)))
+      return 1;
+  return 0;
+}
+
+/* Handle the input from the 'compile file' command.  The "compile
+   file" command is used to evaluate an expression contained in a file
+   that may contain calls to the GCC compiler.  */
+
+static void
+compile_file_command (char *arg, int from_tty)
+{
+  enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
+  char *buffer;
+  struct cleanup *cleanup;
+
+  cleanup = make_cleanup_restore_integer (&interpreter_async);
+  interpreter_async = 0;
+
+  /* Check the user did not just <enter> after command.  */
+  if (arg == NULL)
+    error (_("You must provide a filename for this command."));
+
+  /* Check if a raw (-r|-raw) argument is provided.  */
+  if (arg != NULL && check_raw_argument (&arg))
+    {
+      scope = COMPILE_I_RAW_SCOPE;
+      arg = skip_spaces (arg);
+    }
+
+  /* After processing arguments, check there is a filename at the end
+     of the command.  */
+  if (arg[0] == '\0')
+    error (_("You must provide a filename with the raw option set."));
+
+  if (arg[0] == '-')
+    error (_("Unknown argument specified."));
+
+  arg = skip_spaces (arg);
+  arg = gdb_abspath (arg);
+  make_cleanup (xfree, arg);
+  buffer = xstrprintf ("#include \"%s\"\n", arg);
+  make_cleanup (xfree, buffer);
+  eval_compile_command (NULL, buffer, scope);
+  do_cleanups (cleanup);
+}
+
+/* Handle the input from the 'compile code' command.  The
+   "compile code" command is used to evaluate an expression that may
+   contain calls to the GCC compiler.  The language expected in this
+   compile command is the language currently set in GDB.  */
+
+static void
+compile_code_command (char *arg, int from_tty)
+{
+  struct cleanup *cleanup;
+  enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
+
+  cleanup = make_cleanup_restore_integer (&interpreter_async);
+  interpreter_async = 0;
+
+  if (arg != NULL && check_raw_argument (&arg))
+    {
+      scope = COMPILE_I_RAW_SCOPE;
+      arg = skip_spaces (arg);
+    }
+
+  arg = skip_spaces (arg);
+
+  if (arg != NULL && !check_for_argument (&arg, "--", sizeof ("--") - 1))
+    {
+      if (arg[0] == '-')
+	error (_("Unknown argument specified."));
+    }
+
+  if (arg && *arg)
+      eval_compile_command (NULL, arg, scope);
+  else
+    {
+      struct command_line *l = get_command_line (compile_control, "");
+
+      make_cleanup_free_command_lines (&l);
+      l->control_u.compile.scope = scope;
+      execute_control_command_untraced (l);
+    }
+
+  do_cleanups (cleanup);
+}
+
+/* A cleanup function to remove a directory and all its contents.  */
+
+static void
+do_rmdir (void *arg)
+{
+  const char *dir = arg;
+  char *zap;
+  
+  gdb_assert (strncmp (dir, TMP_PREFIX, strlen (TMP_PREFIX)) == 0);
+  zap = concat ("rm -rf ", dir, (char *) NULL);
+  system (zap);
+}
+
+/* Return the name of the temporary directory to use for .o files, and
+   arrange for the directory to be removed at shutdown.  */
+
+static const char *
+get_compile_file_tempdir (void)
+{
+  static char *tempdir_name;
+
+#define TEMPLATE TMP_PREFIX "XXXXXX"
+  char tname[sizeof (TEMPLATE)];
+
+  if (tempdir_name != NULL)
+    return tempdir_name;
+
+  strcpy (tname, TEMPLATE);
+#undef TEMPLATE
+  tempdir_name = mkdtemp (tname);
+  if (tempdir_name == NULL)
+    perror_with_name (_("Could not make temporary directory"));
+
+  tempdir_name = xstrdup (tempdir_name);
+  make_final_cleanup (do_rmdir, tempdir_name);
+  return tempdir_name;
+}
+
+/* Compute the names of source and object files to use.  The names are
+   allocated by malloc and should be freed by the caller.  */
+
+static void
+get_new_file_names (char **source_file, char **object_file)
+{
+  static int seq;
+  const char *dir = get_compile_file_tempdir ();
+
+  ++seq;
+  *source_file = xstrprintf ("%s%sout%d.c", dir, SLASH_STRING, seq);
+  *object_file = xstrprintf ("%s%sout%d.o", dir, SLASH_STRING, seq);
+}
+
+/* Get the block and PC at which to evaluate an expression.  */
+
+static const struct block *
+get_expr_block_and_pc (CORE_ADDR *pc)
+{
+  const struct block *block = get_selected_block (pc);
+
+  if (block == NULL)
+    {
+      struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+
+      if (cursal.symtab)
+	block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (cursal.symtab),
+				   STATIC_BLOCK);
+      if (block != NULL)
+	*pc = BLOCK_START (block);
+    }
+  else
+    *pc = BLOCK_START (block);
+
+  return block;
+}
+
+/* Call gdb_buildargv, set its result for S into *ARGVP but calculate also the
+   number of parsed arguments into *ARGCP.  If gdb_buildargv has returned NULL
+   then *ARGCP is set to zero.  */
+
+static void
+build_argc_argv (const char *s, int *argcp, char ***argvp)
+{
+  *argvp = gdb_buildargv (s);
+  *argcp = countargv (*argvp);
+}
+
+/* String for 'set compile-args' and 'show compile-args'.  */
+static char *compile_args;
+
+/* Parsed form of COMPILE_ARGS.  COMPILE_ARGS_ARGV is NULL terminated.  */
+static int compile_args_argc;
+static char **compile_args_argv;
+
+/* Implement 'set compile-args'.  */
+
+static void
+set_compile_args (char *args, int from_tty, struct cmd_list_element *c)
+{
+  freeargv (compile_args_argv);
+  build_argc_argv (compile_args, &compile_args_argc, &compile_args_argv);
+}
+
+/* Implement 'show compile-args'.  */
+
+static void
+show_compile_args (struct ui_file *file, int from_tty,
+		   struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Compile command command-line arguments "
+			    "are \"%s\".\n"),
+		    value);
+}
+
+/* Append ARGC and ARGV (as parsed by build_argc_argv) to *ARGCP and *ARGVP.
+   ARGCP+ARGVP can be zero+NULL and also ARGC+ARGV can be zero+NULL.  */
+
+static void
+append_args (int *argcp, char ***argvp, int argc, char **argv)
+{
+  int argi;
+
+  *argvp = xrealloc (*argvp, (*argcp + argc + 1) * sizeof (**argvp));
+
+  for (argi = 0; argi < argc; argi++)
+    (*argvp)[(*argcp)++] = xstrdup (argv[argi]);
+  (*argvp)[(*argcp)] = NULL;
+}
+
+/* Return DW_AT_producer parsed for get_selected_frame () (if any).
+   Return NULL otherwise.
+
+   GCC already filters its command-line arguments only for the suitable ones to
+   put into DW_AT_producer - see GCC function gen_producer_string.  */
+
+static const char *
+get_selected_pc_producer_options (void)
+{
+  CORE_ADDR pc = get_frame_pc (get_selected_frame (NULL));
+  struct compunit_symtab *symtab = find_pc_compunit_symtab (pc);
+  const char *cs;
+
+  if (symtab == NULL || symtab->producer == NULL
+      || strncmp (symtab->producer, "GNU ", strlen ("GNU ")) != 0)
+    return NULL;
+
+  cs = symtab->producer;
+  while (*cs != 0 && *cs != '-')
+    cs = skip_spaces_const (skip_to_space_const (cs));
+  if (*cs != '-')
+    return NULL;
+  return cs;
+}
+
+/* Produce final vector of GCC compilation options.  First element is target
+   size ("-m64", "-m32" etc.), optionally followed by DW_AT_producer options
+   and then compile-args string GDB variable.  */
+
+static void
+get_args (const struct compile_instance *compiler, struct gdbarch *gdbarch,
+	  int *argcp, char ***argvp)
+{
+  const char *cs_producer_options;
+  int argc_compiler;
+  char **argv_compiler;
+
+  build_argc_argv (gdbarch_gcc_target_options (gdbarch),
+		   argcp, argvp);
+
+  cs_producer_options = get_selected_pc_producer_options ();
+  if (cs_producer_options != NULL)
+    {
+      int argc_producer;
+      char **argv_producer;
+
+      build_argc_argv (cs_producer_options, &argc_producer, &argv_producer);
+      append_args (argcp, argvp, argc_producer, argv_producer);
+      freeargv (argv_producer);
+    }
+
+  build_argc_argv (compiler->gcc_target_options,
+		   &argc_compiler, &argv_compiler);
+  append_args (argcp, argvp, argc_compiler, argv_compiler);
+  freeargv (argv_compiler);
+
+  append_args (argcp, argvp, compile_args_argc, compile_args_argv);
+}
+
+/* A cleanup function to destroy a gdb_gcc_instance.  */
+
+static void
+cleanup_compile_instance (void *arg)
+{
+  struct compile_instance *inst = arg;
+
+  inst->destroy (inst);
+}
+
+/* A cleanup function to unlink a file.  */
+
+static void
+cleanup_unlink_file (void *arg)
+{
+  const char *filename = arg;
+
+  unlink (filename);
+}
+
+/* A helper function suitable for use as the "print_callback" in the
+   compiler object.  */
+
+static void
+print_callback (void *ignore, const char *message)
+{
+  fputs_filtered (message, gdb_stderr);
+}
+
+/* Process the compilation request.  On success it returns the object
+   file name and *SOURCE_FILEP is set to source file name.  On an
+   error condition, error () is called.  The caller is responsible for
+   freeing both strings.  */
+
+static char *
+compile_to_object (struct command_line *cmd, char *cmd_string,
+		   enum compile_i_scope_types scope,
+		   char **source_filep)
+{
+  char *code;
+  char *source_file, *object_file;
+  struct compile_instance *compiler;
+  struct cleanup *cleanup, *inner_cleanup;
+  const struct block *expr_block;
+  CORE_ADDR trash_pc, expr_pc;
+  int argc;
+  char **argv;
+  int ok;
+  FILE *src;
+  struct gdbarch *gdbarch = get_current_arch ();
+  const char *os_rx;
+  const char *arch_rx;
+  char *triplet_rx;
+  char *error_message;
+
+  if (!target_has_execution)
+    error (_("The program must be running for the compile command to "\
+	     "work."));
+
+  expr_block = get_expr_block_and_pc (&trash_pc);
+  expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
+
+  /* Set up instance and context for the compiler.  */
+  if (current_language->la_get_compile_instance == NULL)
+    error (_("No compiler support for this language."));
+  compiler = current_language->la_get_compile_instance ();
+  cleanup = make_cleanup (cleanup_compile_instance, compiler);
+
+  compiler->fe->ops->set_print_callback (compiler->fe, print_callback, NULL);
+
+  compiler->scope = scope;
+  compiler->block = expr_block;
+
+  /* From the provided expression, build a scope to pass to the
+     compiler.  */
+  if (cmd != NULL)
+    {
+      struct ui_file *stream = mem_fileopen ();
+      struct command_line *iter;
+
+      make_cleanup_ui_file_delete (stream);
+      for (iter = cmd->body_list[0]; iter; iter = iter->next)
+	{
+	  fputs_unfiltered (iter->line, stream);
+	  fputs_unfiltered ("\n", stream);
+	}
+
+      code = ui_file_xstrdup (stream, NULL);
+      make_cleanup (xfree, code);
+    }
+  else if (cmd_string != NULL)
+    code = cmd_string;
+  else
+    error (_("Neither a simple expression, or a multi-line specified."));
+
+  code = current_language->la_compute_program (compiler, code, gdbarch,
+					       expr_block, expr_pc);
+  make_cleanup (xfree, code);
+  if (compile_debug)
+    fprintf_unfiltered (gdb_stdout, "debug output:\n\n%s", code);
+
+  os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch));
+  arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
+  triplet_rx = concat (arch_rx, "-[^-]*-", os_rx, (char *) NULL);
+  make_cleanup (xfree, triplet_rx);
+
+  /* Set compiler command-line arguments.  */
+  get_args (compiler, gdbarch, &argc, &argv);
+  make_cleanup_freeargv (argv);
+
+  error_message = compiler->fe->ops->set_arguments (compiler->fe, triplet_rx,
+						    argc, argv);
+  if (error_message != NULL)
+    {
+      make_cleanup (xfree, error_message);
+      error ("%s", error_message);
+    }
+
+  if (compile_debug)
+    {
+      int argi;
+
+      fprintf_unfiltered (gdb_stdout, "Passing %d compiler options:\n", argc);
+      for (argi = 0; argi < argc; argi++)
+	fprintf_unfiltered (gdb_stdout, "Compiler option %d: <%s>\n",
+			    argi, argv[argi]);
+    }
+
+  get_new_file_names (&source_file, &object_file);
+  inner_cleanup = make_cleanup (xfree, source_file);
+  make_cleanup (xfree, object_file);
+
+  src = gdb_fopen_cloexec (source_file, "w");
+  if (src == NULL)
+    perror_with_name (_("Could not open source file for writing"));
+  make_cleanup (cleanup_unlink_file, source_file);
+  if (fputs (code, src) == EOF)
+    perror_with_name (_("Could not write to source file"));
+  fclose (src);
+
+  if (compile_debug)
+    fprintf_unfiltered (gdb_stdout, "source file produced: %s\n\n",
+			source_file);
+
+  /* Call the compiler and start the compilation process.  */
+  compiler->fe->ops->set_source_file (compiler->fe, source_file);
+
+  if (!compiler->fe->ops->compile (compiler->fe, object_file,
+				   compile_debug))
+    error (_("Compilation failed."));
+
+  if (compile_debug)
+    fprintf_unfiltered (gdb_stdout, "object file produced: %s\n\n",
+			object_file);
+
+  discard_cleanups (inner_cleanup);
+  do_cleanups (cleanup);
+  *source_filep = source_file;
+  return object_file;
+}
+
+/* The "compile" prefix command.  */
+
+static void
+compile_command (char *args, int from_tty)
+{
+  /* If a sub-command is not specified to the compile prefix command,
+     assume it is a direct code compilation.  */
+  compile_code_command (args, from_tty);
+}
+
+/* See compile.h.  */
+
+void
+eval_compile_command (struct command_line *cmd, char *cmd_string,
+		      enum compile_i_scope_types scope)
+{
+  char *object_file, *source_file;
+
+  object_file = compile_to_object (cmd, cmd_string, scope, &source_file);
+  if (object_file != NULL)
+    {
+      struct cleanup *cleanup_xfree, *cleanup_unlink;
+      struct compile_module *compile_module;
+
+      cleanup_xfree = make_cleanup (xfree, object_file);
+      make_cleanup (xfree, source_file);
+      cleanup_unlink = make_cleanup (cleanup_unlink_file, object_file);
+      make_cleanup (cleanup_unlink_file, source_file);
+      compile_module = compile_object_load (object_file, source_file);
+      discard_cleanups (cleanup_unlink);
+      do_cleanups (cleanup_xfree);
+      compile_object_run (compile_module);
+    }
+}
+
+/* See compile/compile-internal.h.  */
+
+char *
+compile_register_name_mangled (struct gdbarch *gdbarch, int regnum)
+{
+  const char *regname = gdbarch_register_name (gdbarch, regnum);
+
+  return xstrprintf ("__%s", regname);
+}
+
+/* See compile/compile-internal.h.  */
+
+int
+compile_register_name_demangle (struct gdbarch *gdbarch,
+				 const char *regname)
+{
+  int regnum;
+
+  if (regname[0] != '_' || regname[1] != '_')
+    error (_("Invalid register name \"%s\"."), regname);
+  regname += 2;
+
+  for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
+    if (strcmp (regname, gdbarch_register_name (gdbarch, regnum)) == 0)
+      return regnum;
+
+  error (_("Cannot find gdbarch register \"%s\"."), regname);
+}
+
+extern initialize_file_ftype _initialize_compile;
+
+void
+_initialize_compile (void)
+{
+  struct cmd_list_element *c = NULL;
+
+  add_prefix_cmd ("compile", class_obscure, compile_command,
+		  _("\
+Command to compile source code and inject it into the inferior."),
+		  &compile_command_list, "compile ", 1, &cmdlist);
+  add_com_alias ("expression", "compile", class_obscure, 0);
+
+  add_cmd ("code", class_obscure, compile_code_command,
+	   _("\
+Compile, inject, and execute code.\n\
+\n\
+Usage: compile code [-r|-raw] [--] [CODE]\n\
+-r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping.\n\
+--: Do not parse any options beyond this delimiter.  All text to the\n\
+    right will be treated as source code.\n\
+\n\
+The source code may be specified as a simple one line expression, e.g.:\n\
+\n\
+    compile code printf(\"Hello world\\n\");\n\
+\n\
+Alternatively, you can type the source code interactively.\n\
+You can invoke this mode when no argument is given to the command\n\
+(i.e.,\"compile code\" is typed with nothing after it).  An\n\
+interactive prompt will be shown allowing you to enter multiple\n\
+lines of source code.  Type a line containing \"end\" to indicate\n\
+the end of the source code."),
+	   &compile_command_list);
+
+  c = add_cmd ("file", class_obscure, compile_file_command,
+	       _("\
+Evaluate a file containing source code.\n\
+\n\
+Usage: compile file [-r|-raw] [filename]\n\
+-r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping."),
+	       &compile_command_list);
+  set_cmd_completer (c, filename_completer);
+
+  add_setshow_boolean_cmd ("compile", class_maintenance, &compile_debug, _("\
+Set compile command debugging."), _("\
+Show compile command debugging."), _("\
+When on, compile command debugging is enabled."),
+			   NULL, show_compile_debug,
+			   &setdebuglist, &showdebuglist);
+
+  add_setshow_string_cmd ("compile-args", class_support,
+			  &compile_args,
+			  _("Set compile command GCC command-line arguments"),
+			  _("Show compile command GCC command-line arguments"),
+			  _("\
+Use options like -I (include file directory) or ABI settings.\n\
+String quoting is parsed like in shell, for example:\n\
+  -mno-align-double \"-I/dir with a space/include\""),
+			  set_compile_args, show_compile_args, &setlist, &showlist);
+
+  /* Override flags possibly coming from DW_AT_producer.  */
+  compile_args = xstrdup ("-O0 -gdwarf-4"
+  /* We use -fPIC Otherwise GDB would need to reserve space large enough for
+     any object file in the inferior in advance to get the final address when
+     to link the object file to and additionally the default system linker
+     script would need to be modified so that one can specify there the
+     absolute target address.  */
+			 " -fPIC"
+  /* We don't want warnings.  */
+			 " -w"
+  /* Override CU's possible -fstack-protector-strong.  */
+			 " -fno-stack-protector"
+  );
+  set_compile_args (compile_args, 0, NULL);
+}
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
new file mode 100644
index 0000000..486361f
--- /dev/null
+++ b/gdb/compile/compile.h
@@ -0,0 +1,102 @@
+/* Header file for Compile and inject module.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_COMPILE_H
+#define GDB_COMPILE_H
+
+struct ui_file;
+struct gdbarch;
+struct dwarf2_per_cu_data;
+struct symbol;
+struct dynamic_prop;
+
+/* Public function that is called from compile_control case in the
+   expression command.  GDB returns either a CMD, or a CMD_STRING, but
+   never both.  */
+
+extern void eval_compile_command (struct command_line *cmd, char *cmd_string,
+				  enum compile_i_scope_types scope);
+
+/* Compile a DWARF location expression to C, suitable for use by the
+   compiler.
+
+   STREAM is the stream where the code should be written.
+
+   RESULT_NAME is the name of a variable in the resulting C code.  The
+   result of the expression will be assigned to this variable.
+
+   SYM is the symbol corresponding to this expression.
+   PC is the location at which the expression is being evaluated.
+   ARCH is the architecture to use.
+
+   REGISTERS_USED is an out parameter which is updated to note which
+   registers were needed by this expression.
+
+   ADDR_SIZE is the DWARF address size to use.
+
+   OPT_PTR and OP_END are the bounds of the DWARF expression.
+
+   PER_CU is the per-CU object used for looking up various other
+   things.  */
+
+extern void compile_dwarf_expr_to_c (struct ui_file *stream,
+				     const char *result_name,
+				     struct symbol *sym,
+				     CORE_ADDR pc,
+				     struct gdbarch *arch,
+				     unsigned char *registers_used,
+				     unsigned int addr_size,
+				     const gdb_byte *op_ptr,
+				     const gdb_byte *op_end,
+				     struct dwarf2_per_cu_data *per_cu);
+
+/* Compile a DWARF bounds expression to C, suitable for use by the
+   compiler.
+
+   STREAM is the stream where the code should be written.
+
+   RESULT_NAME is the name of a variable in the resulting C code.  The
+   result of the expression will be assigned to this variable.
+
+   PROP is the dynamic property for which we're compiling.
+
+   SYM is the symbol corresponding to this expression.
+   PC is the location at which the expression is being evaluated.
+   ARCH is the architecture to use.
+
+   REGISTERS_USED is an out parameter which is updated to note which
+   registers were needed by this expression.
+
+   ADDR_SIZE is the DWARF address size to use.
+
+   OPT_PTR and OP_END are the bounds of the DWARF expression.
+
+   PER_CU is the per-CU object used for looking up various other
+   things.  */
+
+extern void compile_dwarf_bounds_to_c (struct ui_file *stream,
+				       const char *result_name,
+				       const struct dynamic_prop *prop,
+				       struct symbol *sym, CORE_ADDR pc,
+				       struct gdbarch *arch,
+				       unsigned char *registers_used,
+				       unsigned int addr_size,
+				       const gdb_byte *op_ptr,
+				       const gdb_byte *op_end,
+				       struct dwarf2_per_cu_data *per_cu);
+
+#endif /* GDB_COMPILE_H */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index e98138f..926ee77 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -231,6 +231,8 @@ static const struct language_defn d_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/defs.h b/gdb/defs.h
index 6b63b6a..7920938 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -55,6 +55,24 @@
 
 #include "host-defs.h"
 
+/* Scope types enumerator.  List the types of scopes the compiler will
+   accept.  */
+
+enum compile_i_scope_types
+  {
+    COMPILE_I_INVALID_SCOPE,
+
+    /* A simple scope.  Wrap an expression into a simple scope that
+       takes no arguments, returns no value, and uses the generic
+       function name "_gdb_expr". */
+
+    COMPILE_I_SIMPLE_SCOPE,
+
+    /* Do not wrap the expression,
+       it has to provide function "_gdb_expr" on its own.  */
+    COMPILE_I_RAW_SCOPE,
+  };
+
 /* Just in case they're not defined in stdio.h.  */
 
 #ifndef SEEK_SET
@@ -364,6 +382,7 @@ enum command_control_type
     if_control,
     commands_control,
     python_control,
+    compile_control,
     guile_control,
     while_stepping_control,
     invalid_control
@@ -377,6 +396,15 @@ struct command_line
     struct command_line *next;
     char *line;
     enum command_control_type control_type;
+    union
+      {
+	struct
+	  {
+	    enum compile_i_scope_types scope;
+	  }
+	compile;
+      }
+    control_u;
     /* * The number of elements in body_list.  */
     int body_count;
     /* * For composite commands, the nested lists of commands.  For
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 2e619da..f314c89 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
+	    Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* gdb.texinfo (Altering): Update.
+	(Compiling and Injecting Code): New node.
+
 2014-10-30  Doug Evans  <dje@google.com>
 
 	* python.texi (Progspaces In Python): Document ability to add
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 15c2908..c94429f 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -16493,6 +16493,7 @@ address, or even return prematurely from a function.
 * Returning::                   Returning from a function
 * Calling::                     Calling your program's functions
 * Patching::                    Patching your program
+* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
 @end menu
 
 @node Assignment
@@ -16915,6 +16916,237 @@ Display whether executable files and core files are opened for writing
 as well as reading.
 @end table
 
+@node Compiling and Injecting Code
+@section Compiling and injecting code in @value{GDBN}
+@cindex injecting code
+@cindex writing into executables
+@cindex compiling code
+
+@value{GDBN} supports on-demand compilation and code injection into
+programs running under @value{GDBN}.  GCC 5.0 or higher built with
+@file{libcc1.so} must be installed for this functionality to be enabled.
+This functionality is implemented with the following commands.
+
+@table @code
+@kindex compile code
+@item compile code @var{source-code}
+@itemx compile code -raw @var{--} @var{source-code}
+Compile @var{source-code} with the compiler language found as the current
+language in @value{GDBN} (@pxref{Languages}).  If compilation and
+injection is not supported with the current language specified in
+@value{GDBN}, or the compiler does not support this feature, an error
+message will be printed.  If @var{source-code} compiles and links
+successfully, @value{GDBN} will load the object-code emitted,
+and execute it within the context of the currently selected inferior.
+It is important to note that the compiled code is executed immediately.
+After execution, the compiled code is removed from @value{GDBN} and any
+new types or variables you have defined will be deleted.
+
+The command allows you to specify @var{source-code} in two ways.
+The simplest method is to provide a single line of code to the command.
+E.g.:
+
+@smallexample
+compile code printf ("hello world\n");
+@end smallexample
+
+If you specify options on the command line as well as source code, they
+may conflict.  The @samp{--} delimiter can be used to separate options
+from actual source code.  E.g.:
+
+@smallexample
+compile code -r -- printf ("hello world\n");
+@end smallexample
+
+Alternatively you can enter source code as multiple lines of text.  To
+enter this mode, invoke the @samp{compile code} command without any text
+following the command.  This will start the multiple-line editor and
+allow you to type as many lines of source code as required.  When you
+have completed typing, enter @samp{end} on its own line to exit the
+editor.
+
+@smallexample
+compile code
+>printf ("hello\n");
+>printf ("world\n");
+>end
+@end smallexample
+
+Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
+provided @var{source-code} in a callable scope.  In this case, you must
+specify the entry point of the code by defining a function named
+@code{_gdb_expr_}.  The @samp{-raw} code cannot access variables of the
+inferior.  Using @samp{-raw} option may be needed for example when
+@var{source-code} requires @samp{#include} lines which may conflict with
+inferior symbols otherwise.
+
+@kindex compile file
+@item compile file @var{filename}
+@itemx compile file -raw @var{filename}
+Like @code{compile code}, but take the source code from @var{filename}.
+
+@smallexample
+compile file /home/user/example.c
+@end smallexample
+@end table
+
+@subsection Caveats when using the @code{compile} command
+
+There are a few caveats to keep in mind when using the @code{compile}
+command.  As the caveats are different per language, the table below
+highlights specific issues on a per language basis.
+
+@table @asis
+@item C code examples and caveats
+When the language in @value{GDBN} is set to @samp{C}, the compiler will
+attempt to compile the source code with a @samp{C} compiler.  The source
+code provided to the @code{compile} command will have much the same
+access to variables and types as it normally would if it were part of
+the program currently being debugged in @value{GDBN}.
+
+Below is a sample program that forms the basis of the examples that
+follow.  This program has been compiled and loaded into @value{GDBN},
+much like any other normal debugging session.
+
+@smallexample
+void function1 (void)
+@{
+   int i = 42;
+   printf ("function 1\n");
+@}
+
+void function2 (void)
+@{
+   int j = 12;
+   function1 ();
+@}
+
+int main(void)
+@{
+   int k = 6;
+   int *p;
+   function2 ();
+   return 0;
+@}
+@end smallexample
+
+For the purposes of the examples in this section, the program above has
+been compiled, loaded into @value{GDBN}, stopped at the function
+@code{main}, and @value{GDBN} is awaiting input from the user.
+
+To access variables and types for any program in @value{GDBN}, the
+program must be compiled and packaged with debug information.  The
+@code{compile} command is not an exception to this rule.  Without debug
+information, you can still use the @code{compile} command, but you will
+be very limited in what variables and types you can access.
+
+So with that in mind, the example above has been compiled with debug
+information enabled.  The @code{compile} command will have access to
+all variables and types (except those that may have been optimized
+out).  Currently, as @value{GDBN} has stopped the program in the
+@code{main} function, the @code{compile} command would have access to
+the variable @code{k}.  You could invoke the @code{compile} command
+and type some source code to set the value of @code{k}.  You can also
+read it, or do anything with that variable you would normally do in
+@code{C}.  Be aware that changes to inferior variables in the
+@code{compile} command are persistent.  In the following example:
+
+@smallexample
+compile code k = 3;
+@end smallexample
+
+@noindent
+the variable @code{k} is now 3.  It will retain that value until
+something else in the example program changes it, or another
+@code{compile} command changes it.
+
+Normal scope and access rules apply to source code compiled and
+injected by the @code{compile} command.  In the example, the variables
+@code{j} and @code{k} are not accessible yet, because the program is
+currently stopped in the @code{main} function, where these variables
+are not in scope.  Therefore, the following command
+
+@smallexample
+compile code j = 3;
+@end smallexample
+
+@noindent
+will result in a compilation error message.
+
+Once the program is continued, execution will bring these variables in
+scope, and they will become accessible; then the code you specify via
+the @code{compile} command will be able to access them.
+
+You can create variables and types with the @code{compile} command as
+part of your source code.  Variables and types that are created as part
+of the @code{compile} command are not visible to the rest of the program for
+the duration of its run.  This example is valid:
+
+@smallexample
+compile code int ff = 5; printf ("ff is %d\n", ff);
+@end smallexample
+
+However, if you were to type the following into @value{GDBN} after that
+command has completed:
+
+@smallexample
+compile code printf ("ff is %d\n'', ff);
+@end smallexample
+
+@noindent
+a compiler error would be raised as the variable @code{ff} no longer
+exists.  Object code generated and injected by the @code{compile}
+command is removed when its execution ends.  Caution is advised
+when assigning to program variables values of variables created by the
+code submitted to the @code{compile} command.  This example is valid:
+
+@smallexample
+compile code int ff = 5; k = ff;
+@end smallexample
+
+The value of the variable @code{ff} is assigned to @code{k}.  The variable
+@code{k} does not require the existence of @code{ff} to maintain the value
+it has been assigned.  However, pointers require particular care in
+assignment.  If the source code compiled with the @code{compile} command
+changed the address of a pointer in the example program, perhaps to a
+variable created in the @code{compile} command, that pointer would point
+to an invalid location when the command exits.  The following example
+would likely cause issues with your debugged program:
+
+@smallexample
+compile code int ff = 5; p = &ff;
+@end smallexample
+
+In this example, @code{p} would point to @code{ff} when the
+@code{compile} command is executing the source code provided to it.
+However, as variables in the (example) program persist with their
+assigned values, the variable @code{p} would point to an invalid
+location when the command exists.  A general rule should be followed
+in that you should either assign @code{NULL} to any assigned pointers,
+or restore a valid location to the pointer before the command exits.
+
+Similar caution must be exercised with any structs, unions, and typedefs
+defined in @code{compile} command.  Types defined in the @code{compile}
+command will no longer be available in the next @code{compile} command.
+Therefore, if you cast a variable to a type defined in the
+@code{compile} command, care must be taken to ensure that any future
+need to resolve the type can be achieved.
+
+@smallexample
+(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
+(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
+gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
+Compilation failed.
+(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
+42
+@end smallexample
+
+Variables that have been optimized away by the compiler are not
+accessible to the code submitted to the @code{compile} command.
+Access to those variables will generate a compiler error which @value{GDBN}
+will print to the console.
+@end table
+
 @node GDB Files
 @chapter @value{GDBN} Files
 
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index d30b72f..460c4cc 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -37,6 +37,7 @@
 #include "dwarf2expr.h"
 #include "dwarf2loc.h"
 #include "dwarf2-frame.h"
+#include "compile/compile.h"
 
 extern int dwarf2_always_disassemble;
 
@@ -2509,6 +2510,42 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
   return 0;
 }
 
+/* See dwarf2loc.h.  */
+
+void
+dwarf2_compile_property_to_c (struct ui_file *stream,
+			      const char *result_name,
+			      struct gdbarch *gdbarch,
+			      unsigned char *registers_used,
+			      const struct dynamic_prop *prop,
+			      CORE_ADDR pc,
+			      struct symbol *sym)
+{
+  struct dwarf2_property_baton *baton = prop->data.baton;
+  const gdb_byte *data;
+  size_t size;
+  struct dwarf2_per_cu_data *per_cu;
+
+  if (prop->kind == PROP_LOCEXPR)
+    {
+      data = baton->locexpr.data;
+      size = baton->locexpr.size;
+      per_cu = baton->locexpr.per_cu;
+    }
+  else
+    {
+      gdb_assert (prop->kind == PROP_LOCLIST);
+
+      data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
+      per_cu = baton->loclist.per_cu;
+    }
+
+  compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc,
+			     gdbarch, registers_used,
+			     dwarf2_per_cu_addr_size (per_cu),
+			     data, data + size, per_cu);
+}
+
 \f
 /* Helper functions and baton for dwarf2_loc_desc_needs_frame.  */
 
@@ -4176,6 +4213,26 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
 			       dlbaton->per_cu);
 }
 
+/* symbol_computed_ops 'generate_c_location' method.  */
+
+static void
+locexpr_generate_c_location (struct symbol *sym, struct ui_file *stream,
+			     struct gdbarch *gdbarch,
+			     unsigned char *registers_used,
+			     CORE_ADDR pc, const char *result_name)
+{
+  struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (sym);
+  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+
+  if (dlbaton->size == 0)
+    error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym));
+
+  compile_dwarf_expr_to_c (stream, result_name,
+			   sym, pc, gdbarch, registers_used, addr_size,
+			   dlbaton->data, dlbaton->data + dlbaton->size,
+			   dlbaton->per_cu);
+}
+
 /* The set of location functions used with the DWARF-2 expression
    evaluator.  */
 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
@@ -4184,7 +4241,8 @@ const struct symbol_computed_ops dwarf2_locexpr_funcs = {
   locexpr_read_needs_frame,
   locexpr_describe_location,
   0,	/* location_has_loclist */
-  locexpr_tracepoint_var_ref
+  locexpr_tracepoint_var_ref,
+  locexpr_generate_c_location
 };
 
 
@@ -4355,6 +4413,29 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
 			       dlbaton->per_cu);
 }
 
+/* symbol_computed_ops 'generate_c_location' method.  */
+
+static void
+loclist_generate_c_location (struct symbol *sym, struct ui_file *stream,
+			     struct gdbarch *gdbarch,
+			     unsigned char *registers_used,
+			     CORE_ADDR pc, const char *result_name)
+{
+  struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (sym);
+  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  const gdb_byte *data;
+  size_t size;
+
+  data = dwarf2_find_location_expression (dlbaton, &size, pc);
+  if (size == 0)
+    error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym));
+
+  compile_dwarf_expr_to_c (stream, result_name,
+			   sym, pc, gdbarch, registers_used, addr_size,
+			   data, data + size,
+			   dlbaton->per_cu);
+}
+
 /* The set of location functions used with the DWARF-2 expression
    evaluator and location lists.  */
 const struct symbol_computed_ops dwarf2_loclist_funcs = {
@@ -4363,7 +4444,8 @@ const struct symbol_computed_ops dwarf2_loclist_funcs = {
   loclist_read_needs_frame,
   loclist_describe_location,
   1,	/* location_has_loclist */
-  loclist_tracepoint_var_ref
+  loclist_tracepoint_var_ref,
+  loclist_generate_c_location
 };
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
index 76fb45b4..e63b35b 100644
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2loc.h
@@ -111,6 +111,27 @@ int dwarf2_evaluate_property (const struct dynamic_prop *prop,
 			      CORE_ADDR address,
 			      CORE_ADDR *value);
 
+/* A helper for the compiler interface that compiles a single dynamic
+   property to C code.
+
+   STREAM is where the C code is to be written.
+   RESULT_NAME is the name of the generated variable.
+   GDBARCH is the architecture to use.
+   REGISTERS_USED is a bit-vector that is filled to note which
+   registers are required by the generated expression.
+   PROP is the property for which code is generated.
+   ADDRESS is the address at which the property is considered to be
+   evaluated.
+   SYM the originating symbol, used for error reporting.  */
+
+void dwarf2_compile_property_to_c (struct ui_file *stream,
+				   const char *result_name,
+				   struct gdbarch *gdbarch,
+				   unsigned char *registers_used,
+				   const struct dynamic_prop *prop,
+				   CORE_ADDR address,
+				   struct symbol *sym);
+
 CORE_ADDR dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
 				  unsigned int addr_index);
 
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 52da04e..dd70798 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -275,6 +275,8 @@ const struct language_defn f_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 8cbc234..7b23fc6 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -597,6 +597,8 @@ static const struct language_defn go_language_defn =
   NULL,
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index acc191a..c73def8 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -1198,6 +1198,8 @@ const struct language_defn java_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &java_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/language.c b/gdb/language.c
index 034086d..83dd4d5 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -827,6 +827,8 @@ const struct language_defn unknown_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
@@ -872,6 +874,8 @@ const struct language_defn auto_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
@@ -915,6 +919,8 @@ const struct language_defn local_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 \f
diff --git a/gdb/language.h b/gdb/language.h
index 73619ca..9ed7e22 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -35,6 +35,7 @@ struct value_print_options;
 struct type_print_options;
 struct lang_varobj_ops;
 struct parser_state;
+struct compile_instance;
 
 #define MAX_FORTRAN_DIMS  7	/* Maximum number of F77 array dims.  */
 
@@ -355,6 +356,36 @@ struct language_defn
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
+    /* If this language allows compilation from the gdb command line,
+       this method should be non-NULL.  When called it should return
+       an instance of struct gcc_context appropriate to the language.
+       When defined this method must never return NULL; instead it
+       should throw an exception on failure.  The returned compiler
+       instance is owned by its caller and must be deallocated by
+       calling its 'destroy' method.  */
+
+    struct compile_instance *(*la_get_compile_instance) (void);
+
+    /* This method must be defined if 'la_get_gcc_context' is defined.
+       If 'la_get_gcc_context' is not defined, then this method is
+       ignored.
+
+       This takes the user-supplied text and returns a newly malloc'd
+       bit of code to compile.  The caller owns the result.
+
+       INST is the compiler instance being used.
+       INPUT is the user's input text.
+       GDBARCH is the architecture to use.
+       EXPR_BLOCK is the block in which the expression is being
+       parsed.
+       EXPR_PC is the PC at which the expression is being parsed.  */
+
+    char *(*la_compute_program) (struct compile_instance *inst,
+				 const char *input,
+				 struct gdbarch *gdbarch,
+				 const struct block *expr_block,
+				 CORE_ADDR expr_pc);
+
     /* Add fields above this point, so the magic number is always last.  */
     /* Magic number for compat checking.  */
 
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 940cbcf..6a68520 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -394,6 +394,8 @@ const struct language_defn m2_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 8a3d21e..6c4e3ef 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -389,6 +389,8 @@ const struct language_defn objc_language_defn = {
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 2006cd8..7af3632 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1083,6 +1083,8 @@ const struct language_defn opencl_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 98fcc3b..53669ad 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -451,6 +451,8 @@ const struct language_defn pascal_language_defn =
   NULL,				/* la_get_symbol_name_cmp */
   iterate_over_symbols,
   &default_varobj_ops,
+  NULL,
+  NULL,
   LANG_MAGIC
 };
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 473c85c..806e3a1 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -641,6 +641,21 @@ struct symbol_computed_ops
 
   void (*tracepoint_var_ref) (struct symbol *symbol, struct gdbarch *gdbarch,
 			      struct agent_expr *ax, struct axs_value *value);
+
+  /* Generate C code to compute the location of SYMBOL.  The C code is
+     emitted to STREAM.  GDBARCH is the current architecture and PC is
+     the PC at which SYMBOL's location should be evaluated.
+     REGISTERS_USED is a vector indexed by register number; the
+     generator function should set an element in this vector if the
+     corresponding register is needed by the location computation.
+     The generated C code must assign the location to a local
+     variable; this variable's name is RESULT_NAME.  */
+
+  void (*generate_c_location) (struct symbol *symbol, struct ui_file *stream,
+			       struct gdbarch *gdbarch,
+			       unsigned char *registers_used,
+			       CORE_ADDR pc, const char *result_name);
+
 };
 
 /* The methods needed to implement LOC_BLOCK for inferior functions.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 7567785..bd6f2ab 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,26 @@
+2014-10-07  Phil Muldoon  <pmuldoon@redhat.com>
+	    Jan Kratochvil  <jan.kratochvil@redhat.com>
+	    Tom Tromey  <tromey@redhat.com>
+
+	* configure.ac: Add gdb.compile/.
+	* configure: Regenerate.
+	* gdb.compile/Makefile.in: New file.
+	* gdb.compile/compile-ops.exp: New file.
+	* gdb.compile/compile-ops.c: New file.
+	* gdb.compile/compile-tls.c: New file.
+	* gdb.compile/compile-tls.exp: New file.
+	* gdb.compile/compile-constvar.S: New file.
+	* gdb.compile/compile-constvar.c: New file.
+	* gdb.compile/compile-mod.c: New file.
+	* gdb.compile/compile-nodebug.c: New file.
+	* gdb.compile/compile-setjmp-mod.c: New file.
+	* gdb.compile/compile-setjmp.c: New file.
+	* gdb.compile/compile-setjmp.exp: New file.
+	* gdb.compile/compile-shlib.c: New file.
+	* gdb.compile/compile.c: New file.
+	* gdb.compile/compile.exp: New file.
+	* lib/gdb.exp (skip_compile_feature_tests): New proc.
+
 2014-10-07  Tom Tromey  <tromey@redhat.com>
 
 	* lib/dwarf.exp (_location): Ignore blank lines.  Allow comments.
diff --git a/gdb/testsuite/configure b/gdb/testsuite/configure
index 15944ed..ca033c3 100755
--- a/gdb/testsuite/configure
+++ b/gdb/testsuite/configure
@@ -3458,7 +3458,7 @@ if test "${build}" = "${host}" -a "${host}" = "${target}"; then
 fi
 
 
-ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.btrace/Makefile gdb.cell/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.dlang/Makefile gdb.fortran/Makefile gdb.gdb/Makefile gdb.go/Makefile gdb.server/Makefile gdb.java/Makefile gdb.hp/Makefile gdb.hp/gdb.objdbg/Makefile gdb.hp/gdb.base-hp/Makefile gdb.hp/gdb.aCC/Makefile gdb.hp/gdb.compat/Makefile gdb.hp/gdb.defects/Makefile gdb.guile/Makefile gdb.linespec/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.multi/Makefile gdb.objc/Makefile gdb.opencl/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.perf/Makefile gdb.python/Makefile gdb.reverse/Makefile gdb.stabs/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
+ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.btrace/Makefile gdb.cell/Makefile gdb.compile/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.dlang/Makefile gdb.fortran/Makefile gdb.gdb/Makefile gdb.go/Makefile gdb.server/Makefile gdb.java/Makefile gdb.hp/Makefile gdb.hp/gdb.objdbg/Makefile gdb.hp/gdb.base-hp/Makefile gdb.hp/gdb.aCC/Makefile gdb.hp/gdb.compat/Makefile gdb.hp/gdb.defects/Makefile gdb.guile/Makefile gdb.linespec/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.multi/Makefile gdb.objc/Makefile gdb.opencl/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.perf/Makefile gdb.python/Makefile gdb.reverse/Makefile gdb.stabs/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -4165,6 +4165,7 @@ do
     "gdb.base/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.base/Makefile" ;;
     "gdb.btrace/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.btrace/Makefile" ;;
     "gdb.cell/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.cell/Makefile" ;;
+    "gdb.compile/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.compile/Makefile" ;;
     "gdb.cp/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.cp/Makefile" ;;
     "gdb.disasm/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.disasm/Makefile" ;;
     "gdb.dwarf2/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.dwarf2/Makefile" ;;
diff --git a/gdb/testsuite/configure.ac b/gdb/testsuite/configure.ac
index 9dccc9f..26f93af 100644
--- a/gdb/testsuite/configure.ac
+++ b/gdb/testsuite/configure.ac
@@ -99,9 +99,9 @@ AC_SUBST(EXTRA_RULES)
 AC_OUTPUT([Makefile \
   gdb.ada/Makefile \
   gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.btrace/Makefile \
-  gdb.cell/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile \
-  gdb.dlang/Makefile gdb.fortran/Makefile gdb.gdb/Makefile gdb.go/Makefile \
-  gdb.server/Makefile gdb.java/Makefile \
+  gdb.cell/Makefile gdb.compile/Makefile gdb.cp/Makefile gdb.disasm/Makefile \
+  gdb.dwarf2/Makefile gdb.dlang/Makefile gdb.fortran/Makefile gdb.gdb/Makefile \
+  gdb.go/Makefile gdb.server/Makefile gdb.java/Makefile \
   gdb.hp/Makefile gdb.hp/gdb.objdbg/Makefile gdb.hp/gdb.base-hp/Makefile \
   gdb.hp/gdb.aCC/Makefile gdb.hp/gdb.compat/Makefile \
   gdb.hp/gdb.defects/Makefile gdb.guile/Makefile gdb.linespec/Makefile \
diff --git a/gdb/testsuite/gdb.compile/Makefile.in b/gdb/testsuite/gdb.compile/Makefile.in
new file mode 100644
index 0000000..6a1a895
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/Makefile.in
@@ -0,0 +1,21 @@
+VPATH = @srcdir@
+srcdir = @srcdir@
+
+EXECUTABLES = \
+	chan handcall hello integers methods package \
+	strings types unsafe
+
+all info install-info dvi install uninstall installcheck check:
+	@echo "Nothing to be done for $@..."
+
+clean mostlyclean:
+	-find . -name '*.o' -print | xargs rm -f
+	-find . -name '*.ali' -print | xargs rm -f
+	-rm -f *~ a.out
+	-rm -f *.dwo *.dwp
+	-rm -f core core.coremaker coremaker.core corefile $(EXECUTABLES)
+
+distclean maintainer-clean realclean: clean
+	-rm -f Makefile config.status config.log
+	-rm -f *-init.exp gdb.log gdb.sum
+	-rm -fr *.log summary detail *.plog *.sum *.psum site.*
diff --git a/gdb/testsuite/gdb.compile/compile-constvar.S b/gdb/testsuite/gdb.compile/compile-constvar.S
new file mode 100644
index 0000000..55d81bc
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-constvar.S
@@ -0,0 +1,95 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+// gcc -o gdb.base/compile-constvar.S -dA -S -g gdb.base/compile-constvar.c
+
+	.file	"compile-constvar.c"
+	.file 1 "gdb.base/compile-constvar.c"
+	.section	.debug_info,"",@progbits
+.Ldebug_info0:
+	.long	.Lend-.Lstart	# Length of Compilation Unit Info
+.Lstart:
+	.value	0x4	# DWARF version number
+	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
+	.byte	0x8	# Pointer Size (in bytes)
+	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
+	.long	.LASF0	# DW_AT_producer: "GNU C 4.8.2 20131212 (Red Hat 4.8.2-7) -mtune=generic -march=x86-64 -g"
+	.byte	0x1	# DW_AT_language
+	.long	.LASF1	# DW_AT_name: "gdb.base/compile-constvar.c"
+	.long	.LASF2	# DW_AT_comp_dir: "/home/jkratoch/redhat/gdb-gdbjit/gdb/testsuite"
+	.uleb128 0x2	# (DIE (0x1d) DW_TAG_variable)
+	.long	.LASF3	# DW_AT_name: "constvar"
+	.long	.Linttype-.Ldebug_info0	# DW_AT_type
+			# DW_AT_external
+	.byte	0x3	# DW_AT_const_value
+.Linttype:
+	.uleb128 0x3	# (DIE (0x32) DW_TAG_base_type)
+	.byte	0x4	# DW_AT_byte_size
+	.byte	0x5	# DW_AT_encoding
+	.ascii "int\0"	# DW_AT_name
+	.byte	0	# end of children of DIE 0xb
+.Lend:
+	.section	.debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1	# (abbrev code)
+	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x25	# (DW_AT_producer)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x13	# (DW_AT_language)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x1b	# (DW_AT_comp_dir)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.byte	0
+	.byte	0
+	.uleb128 0x2	# (abbrev code)
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
+	.byte	0	# DW_children_no
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x1c	# (DW_AT_const_value)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.byte	0
+	.byte	0
+	.uleb128 0x3	# (abbrev code)
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
+	.byte	0	# DW_children_no
+	.uleb128 0xb	# (DW_AT_byte_size)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3e	# (DW_AT_encoding)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_str,"MS",@progbits,1
+.LASF1:
+	.string	"gdb.base/compile-constvar.c"
+.LASF3:
+	.string	"constvar"
+.LASF2:
+	.string	""
+.LASF0:
+	.string	"GNU C 4.8.2 20131212 (Red Hat 4.8.2-7) -mtune=generic -march=x86-64 -g"
+	.ident	"GCC: (GNU) 4.8.2 20131212 (Red Hat 4.8.2-7)"
diff --git a/gdb/testsuite/gdb.compile/compile-constvar.c b/gdb/testsuite/gdb.compile/compile-constvar.c
new file mode 100644
index 0000000..3820b43
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-constvar.c
@@ -0,0 +1,18 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int constvar = 5;
diff --git a/gdb/testsuite/gdb.compile/compile-mod.c b/gdb/testsuite/gdb.compile/compile-mod.c
new file mode 100644
index 0000000..a6dbc32
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-mod.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+// Make 'globalvar' lookup working.
+#pragma GCC user_expression
+
+void
+_gdb_expr (void)
+{
+  globalvar = 3;
+  globalvar += 4;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-nodebug.c b/gdb/testsuite/gdb.compile/compile-nodebug.c
new file mode 100644
index 0000000..4cc8bb3
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-nodebug.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+func_nodebug (int neg)
+{
+  return -neg;
+}
+
+int unresolved = 20;
diff --git a/gdb/testsuite/gdb.compile/compile-ops.c b/gdb/testsuite/gdb.compile/compile-ops.c
new file mode 100644
index 0000000..4474814
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-ops.c
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2011-2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int value = 0xdeadf00d;
+int *ptr = &value;
+
+asm (".section	\".text\"");
+asm (".balign 8");
+asm ("func_start: .globl func_start");
+
+static void
+func (void)
+{
+}
+
+asm ("func_end: .globl func_end");
+
+int
+main (void)
+{
+  func ();
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-ops.exp b/gdb/testsuite/gdb.compile/compile-ops.exp
new file mode 100644
index 0000000..c295836
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-ops.exp
@@ -0,0 +1,424 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Some coverage testing of DWARF operators for the compiler
+# integration.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+    return 0
+}
+
+standard_testfile .c gdbjit-ops.S
+
+#
+# A port of the pr10770.c test code to the DWARF assembler format.
+#
+
+set assert_tos_non0 {
+    bra 3
+    skip -3
+}
+
+set assert_tos_0 [subst {
+    lit0
+    eq
+    $assert_tos_non0
+}]
+
+set program [subst {
+    lit0
+    nop
+    $assert_tos_0
+    lit1
+    const1u 1
+    eq
+    $assert_tos_non0
+    lit16
+    const2u 16
+    eq
+    $assert_tos_non0
+    lit31
+    const4u 31
+    ne
+    $assert_tos_0
+    lit1
+    neg
+    const1s -1
+    eq
+    $assert_tos_non0
+    lit16
+    neg
+    const2s -16
+    ne
+    $assert_tos_0
+    lit31
+    const4s -31
+    neg
+    ne
+    $assert_tos_0
+    lit7
+    dup
+    plus_uconst 2
+    lit9
+    eq
+    $assert_tos_non0
+    lit7
+    eq
+    $assert_tos_non0
+    lit20
+    lit1
+    drop
+    lit20
+    eq
+    $assert_tos_non0
+    lit17
+    lit19
+    over
+    lit17
+    eq
+    $assert_tos_non0
+    lit19
+    eq
+    $assert_tos_non0
+    lit17
+    eq
+    $assert_tos_non0
+    lit1
+    lit2
+    lit3
+    lit4
+    pick 2
+    lit2
+    eq
+    $assert_tos_non0
+    lit4
+    eq
+    $assert_tos_non0
+    lit3
+    eq
+    $assert_tos_non0
+    pick 0
+    lit2
+    eq
+    $assert_tos_non0
+    lit2
+    eq
+    $assert_tos_non0
+    lit1
+    eq
+    $assert_tos_non0
+    lit6
+    lit12
+    swap
+    lit6
+    eq
+    $assert_tos_non0
+    lit12
+    eq
+    $assert_tos_non0
+    lit7
+    lit8
+    lit9
+    rot
+    lit8
+    eq
+    $assert_tos_non0
+    lit7
+    eq
+    $assert_tos_non0
+    lit9
+    eq
+    $assert_tos_non0
+    lit7
+    abs
+    lit7
+    eq
+    $assert_tos_non0
+    const1s -123
+    abs
+    const1u 123
+    eq
+    $assert_tos_non0
+    lit3
+    lit6
+    and
+    lit2
+    eq
+    $assert_tos_non0
+    lit3
+    lit6
+    or
+    lit7
+    eq
+    $assert_tos_non0
+    lit17
+    lit2
+    minus
+    lit15
+    eq
+    $assert_tos_non0
+    # Divide is signed truncating toward zero.
+    const1s -6
+    const1s -2
+    div
+    lit3
+    eq
+    $assert_tos_non0
+    const1s -7
+    const1s 3
+    div
+    const1s -2
+    eq
+    $assert_tos_non0
+    # Modulo is unsigned.
+    const1s -6
+    const1s -4
+    mod
+    const1s -6
+    eq
+    $assert_tos_non0
+    const1s -6
+    lit4
+    mod
+    lit2
+    eq
+    $assert_tos_non0
+    lit6
+    const1s -4
+    mod
+    lit6
+    eq
+    $assert_tos_non0
+    # Signed modulo can be implemented using 'over over div mul minus'.
+    const1s -6
+    const1s -4
+    over
+    over
+    div
+    mul
+    minus
+    const1s -2
+    eq
+    $assert_tos_non0
+    const1s -7
+    lit3
+    over
+    over
+    div
+    mul
+    minus
+    const1s -1
+    eq
+    $assert_tos_non0
+    lit7
+    const1s -3
+    over
+    over
+    div
+    mul
+    minus
+    lit1
+    eq
+    $assert_tos_non0
+    lit16
+    lit31
+    plus_uconst 1
+    mul
+    const2u 512
+    eq
+    $assert_tos_non0
+    lit5
+    not
+    lit31
+    and
+    lit26
+    eq
+    $assert_tos_non0
+    lit12
+    lit31
+    plus
+    const1u 43
+    eq
+    $assert_tos_non0
+    const1s -6
+    lit2
+    plus
+    const1s -4
+    eq
+    $assert_tos_non0
+    const1s -6
+    plus_uconst 3
+    const1s -3
+    eq
+    $assert_tos_non0
+    lit16
+    lit4
+    shl
+    const2u 256
+    eq
+    $assert_tos_non0
+    lit16
+    lit3
+    shr
+    lit2
+    eq
+    $assert_tos_non0
+    const1s -16
+    lit3
+    shra
+    const1s -2
+    eq
+    $assert_tos_non0
+    lit3
+    lit6
+    xor
+    lit5
+    eq
+    $assert_tos_non0
+    lit3
+    lit6
+    le
+    $assert_tos_non0
+    lit3
+    lit3
+    le
+    $assert_tos_non0
+    lit6
+    lit3
+    le
+    $assert_tos_0
+    lit3
+    lit6
+    lt
+    $assert_tos_non0
+    lit3
+    lit3
+    lt
+    $assert_tos_0
+    lit6
+    lit3
+    lt
+    $assert_tos_0
+    lit3
+    lit6
+    ge
+    $assert_tos_0
+    lit3
+    lit3
+    ge
+    $assert_tos_non0
+    lit6
+    lit3
+    ge
+    $assert_tos_non0
+    lit3
+    lit6
+    gt
+    $assert_tos_0
+    lit3
+    lit3
+    gt
+    $assert_tos_0
+    lit6
+    lit3
+    gt
+    $assert_tos_non0
+    const1s -6
+    lit1
+    shr
+    lit0
+    gt
+    $assert_tos_non0
+    const1s -6
+    lit1
+    shra
+    lit0
+    lt
+    $assert_tos_non0
+    # Finally some result.
+    addr ptr
+}]
+
+# Make some DWARF for the test.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    # Creating a CU with 4-byte addresses lets this test link on both
+    # 32- and 64-bit machines.
+    cu { addr_size 4 } {
+
+	declare_labels int_label
+	extern func_start func_end ptr
+
+	compile_unit {
+	    {name file1.txt}
+	    {language @DW_LANG_C}
+	    {low_pc func_start addr}
+	    {high_pc func_end addr}
+	} {
+	    global program
+
+	    int_label: base_type {
+		{name int}
+		{byte_size 4 sdata}
+		{encoding @DW_ATE_signed}
+	    }
+
+	    subprogram {
+		{external 1 flag}
+		{name func}
+		{low_pc func_start addr}
+		{high_pc func_end addr}
+	    } {
+		formal_parameter {
+		    {name param}
+		    {variable_parameter 1 flag}
+		    {type :$int_label}
+		    {location $program SPECIAL_expr}
+		}
+
+		formal_parameter {
+		    {name optimized_out}
+		    {variable_parameter 1 flag}
+		    {type :$int_label}
+		}
+	    }
+	}
+    }
+}
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} \
+	  [list $srcfile $asm_file] {nodebug}] } {
+    return -1
+}
+
+if ![runto func] {
+    return -1
+}
+
+if {[skip_compile_feature_tests]} {
+    untested "could not find libcc1 shared library"
+    return -1
+}
+
+# If we have a bug, this will hang.
+gdb_test_no_output "compile code param"
+
+# We can't access optimized-out variables, but their presence should
+# not affect compilations that don't refer to them.
+gdb_test "compile code optimized_out" \
+    ".*optimized out.*Compilation failed."
diff --git a/gdb/testsuite/gdb.compile/compile-setjmp-mod.c b/gdb/testsuite/gdb.compile/compile-setjmp-mod.c
new file mode 100644
index 0000000..8a1c413
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-setjmp-mod.c
@@ -0,0 +1,46 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+// Make 'done' lookup working.
+#pragma GCC user_expression
+
+static void
+foo ()
+{
+  jmp_buf env;
+
+  switch (setjmp (env))
+    {
+    case 2:
+      done = 1;
+      return;
+    case 0:
+      longjmp (env, 2);
+      break;
+    }
+  abort ();
+}
+
+void
+_gdb_expr (void)
+{
+  foo ();
+}
diff --git a/gdb/testsuite/gdb.compile/compile-setjmp.c b/gdb/testsuite/gdb.compile/compile-setjmp.c
new file mode 100644
index 0000000..c462f48
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-setjmp.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+static int done;
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-setjmp.exp b/gdb/testsuite/gdb.compile/compile-setjmp.exp
new file mode 100644
index 0000000..557c1f0
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-setjmp.exp
@@ -0,0 +1,34 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile .c compile-setjmp-mod.c
+
+if { [prepare_for_testing ${testfile}.exp $testfile] } {
+    return -1
+}
+
+if ![runto_main] {
+    return -1
+}
+
+if {[skip_compile_feature_tests]} {
+    untested "could not find libcc1 shared library"
+    return -1
+}
+
+gdb_test_no_output "compile file -r ${srcdir}/${subdir}/$srcfile2" \
+    "compile file -r"
+
+gdb_test "p done" " = 1"
diff --git a/gdb/testsuite/gdb.compile/compile-shlib.c b/gdb/testsuite/gdb.compile/compile-shlib.c
new file mode 100644
index 0000000..6181af2
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-shlib.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+extern int globalvar;
+
+int shlibvar = 10;
+
+void
+shlib_func (void)
+{
+  globalvar = 1;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-tls.c b/gdb/testsuite/gdb.compile/compile-tls.c
new file mode 100644
index 0000000..6e08a30
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-tls.c
@@ -0,0 +1,40 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <pthread.h>
+
+__thread int global_scope;
+
+static __thread int static_scope;
+
+int foo ()
+{
+  /* Ensure we link against pthreads even with --as-needed.  */
+  pthread_testcancel();
+  return 27;
+}
+
+int
+main (void)
+{
+  static __thread int local_scope;
+
+  /* break-here */
+  foo ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-tls.exp b/gdb/testsuite/gdb.compile/compile-tls.exp
new file mode 100644
index 0000000..e9613f5
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-tls.exp
@@ -0,0 +1,42 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+standard_testfile .c
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+	 executable {debug}] != "" } {
+    return -1
+}
+
+clean_restart ${binfile}
+if ![runto_main] then {
+   fail "Can't run to main"
+   return 0
+}
+
+if {[skip_compile_feature_tests]} {
+    untested "could not find libcc1 shared library"
+    return -1
+}
+
+gdb_test "compile code local_scope = 1" \
+    "warning: .* compiled code."
+gdb_test "print local_scope" " = 1"
+gdb_test "compile code static_scope = 2" \
+    "warning: .* compiled code."
+gdb_test "print static_scope" " = 2"
+gdb_test "compile code global_scope = 3" \
+    "warning: .* compiled code."
+gdb_test "print global_scope" " = 3"
diff --git a/gdb/testsuite/gdb.compile/compile.c b/gdb/testsuite/gdb.compile/compile.c
new file mode 100644
index 0000000..b48acab
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile.c
@@ -0,0 +1,130 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#define SOME_MACRO 23
+#define ARG_MACRO(X, Y) ((X) + (Y) - 1)
+
+
+enum enum_type {
+  ONE = 1,
+  TWO = 2
+};
+
+typedef int v4 __attribute__ ((vector_size (16)));
+
+union union_type;
+
+struct struct_type {
+  char charfield;
+  unsigned char ucharfield;
+  short shortfield;
+  unsigned short ushortfield;
+  int intfield;
+  unsigned int uintfield;
+  unsigned int bitfield : 3;
+  long longfield;
+  unsigned long ulongfield;
+  enum enum_type enumfield;
+  float floatfield;
+  double doublefield;
+  const union union_type *ptrfield;
+  struct struct_type *selffield;
+  int arrayfield[5];
+  _Complex double complexfield;
+  _Bool boolfield;
+  v4 vectorfield;
+};
+
+typedef int inttypedef;
+
+union union_type {
+  int intfield;
+  inttypedef typedeffield;
+};
+
+/* volatile provides some coverage of the conversion code.  */
+volatile struct struct_type struct_object;
+
+union union_type union_object;
+
+
+enum ulonger_enum_type {
+  REALLY_MINUS_1 = -1UL,
+};
+
+enum ulonger_enum_type ulonger;
+
+enum longer_enum_type {
+  MINUS_1 = -1,
+  FORCE_TO_LONG = 1L << ((8 * sizeof (long)) - 2)
+};
+
+enum longer_enum_type longer;
+
+int globalvar = 10;
+
+static void
+func_static (int addend)
+{
+  globalvar += addend;
+}
+
+void
+func_global (int subtrahend)
+{
+  globalvar -= subtrahend;
+}
+
+void
+no_args_or_locals (void)
+{
+  /* no_args_or_locals breakpoint */
+}
+
+int *intptr;
+int globalshadow = 10;
+static int staticshadow = 20;
+int externed = 7;
+
+int
+main (void)
+{
+  int localvar = 50;
+  int shadowed = 51;
+  int bound = 3;
+  int unresolved = 10;
+  int globalshadow = 100;
+  int staticshadow = 200;
+  int externed = 9;
+  int f = 0;
+
+  static int static_local = 77000;
+
+  {
+    int another_local = 7;
+    int shadowed = 52;
+    extern int unresolved;
+    extern int externed;
+
+    int vla[bound];
+
+    func_static (0); /* break-here */
+    no_args_or_locals ();
+  }
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp
new file mode 100644
index 0000000..d0dd791
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile.exp
@@ -0,0 +1,357 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c
+
+get_compiler_info
+set options {}
+if [test_compiler_info gcc*] {
+    lappend options additional_flags=-g3
+}
+
+if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
+    verbose "Skipping x86_64 LOC_CONST test."
+    set srcfile3 ""
+}
+
+set srcfilesoptions [list ${srcfile} ${options}]
+if { $srcfile3 != "" } {
+    lappend srcfilesoptions $srcfile3 ${options}
+}
+lappend srcfilesoptions $srcfile4 "nodebug"
+if { [eval build_executable_from_specs ${testfile}.exp $testfile {$options} ${srcfilesoptions}] } {
+    return -1
+}
+
+clean_restart ${testfile}
+
+#
+# Test command without an running inferior.
+#
+gdb_test "compile code int i=2;" \
+    "The program must be running for the compile command to work.*" \
+    "Test compile code command without running inferior"
+
+gdb_test "compile int i=2;" \
+    "The program must be running for the compile command to work.*" \
+    "Test compile command without running inferior"
+
+gdb_test "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \
+    "The program must be running for the compile command to work.*" \
+    "Test compile file command without running inferior"
+
+if ![runto_main] {
+    return -1
+}
+
+if {[skip_compile_feature_tests]} {
+    untested "could not find libcc1 shared library"
+    return -1
+}
+
+#
+# Test delimiter for code, and arguments.
+#
+
+gdb_test_no_output "compile -- f = 10" \
+    "Test abbreviations and code delimiter"
+
+gdb_test "compile f = 10;" ".*= 10;: No such file.*" \
+    "Test abbreviations and code collision"
+
+gdb_test_no_output "compile -r -- _gdb_expr(){int i = 5;}" \
+    "Test delimiter with -r"
+
+gdb_test_no_output "compile -raw -- _gdb_expr(){int i = 5;}" \
+    "Test delimiter with -raw"
+
+gdb_test "compile -- -r  _gdb_expr(){int i = 5;}" \
+    ".* error: 'r' undeclared \\(first use in this function\\).*" \
+    "Test delimiter with -r after it"
+
+gdb_test "p globalvar" " = 10" "expect 10"
+
+gdb_test_no_output "compile code globalvar = 11" \
+    "set variable without trailing semicolon"
+gdb_test "p globalvar" " = 11" "check variable without trailing semicolon"
+
+gdb_test_no_output "compile code globalvar = SOME_MACRO;" \
+    "set variable from macro"
+gdb_test "p globalvar" " = 23" "expect 23"
+
+gdb_test_no_output "compile code globalvar = ARG_MACRO(0, 0);" \
+    "set variable from function-like macro"
+gdb_test "p globalvar" " = -1" "expect -1"
+
+gdb_test_no_output "compile code globalvar = 42;" "set variable"
+gdb_test "p globalvar" " = 42" "expect 42"
+
+gdb_test_no_output "compile code globalvar *= 2;" "modify variable"
+gdb_test "p globalvar" " = 84" "expect 84"
+
+gdb_test_multiple "compile code" "compile code multiline 1" { -re "\r\n>$" {} }
+gdb_test_multiple "globalvar = 10;" "compile code multiline 2" { -re "\r\n>$" {} }
+gdb_test_multiple "globalvar *= 2;" "compile code multiline 3" { -re "\r\n>$" {} }
+gdb_test_no_output "end" "compile code multiline 4"
+gdb_test "p globalvar" " = 20" "expect 20"
+
+gdb_test_no_output "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \
+    "use external source file"
+gdb_test "p globalvar" " = 7" "expect 7"
+
+gdb_test_no_output "compile code func_static (2);" "call static function"
+gdb_test "p globalvar" " = 9" "expect 9"
+gdb_test_no_output "compile code func_global (1);" "call global function"
+gdb_test "p globalvar" " = 8" "expect 8"
+
+gdb_test_no_output \
+    "compile code globalvar = (sizeof (ulonger) == sizeof (long))" \
+    "compute size of ulonger"
+gdb_test "p globalvar" " = 1" "check size of ulonger"
+gdb_test_no_output \
+    "compile code globalvar = (sizeof (longer) == sizeof (long))" \
+    "compute size of longer"
+gdb_test "p globalvar" " = 1" "check size of longer"
+gdb_test_no_output "compile code globalvar = MINUS_1"
+gdb_test "p globalvar" " = -1" "check MINUS_1"
+
+gdb_test_no_output "compile code globalvar = static_local"
+gdb_test "p globalvar" " = 77000" "check static_local"
+
+gdb_test_no_output "compile code static int staticvar = 5; intptr = &staticvar" \
+    "keep jit in memory"
+gdb_test "p *intptr" " = 5" "expect 5"
+
+gdb_test "compile code func_doesnotexist ();" "warning: Could not find symbol \"func_doesnotexist\" for .*"
+
+gdb_test "compile code *(volatile int *) 0 = 0;" \
+    "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB remains in the frame where the signal was received\\.\r\n.*" \
+    "compile code segfault first"
+gdb_test "bt" \
+    "\r\n#0  \[^\r\n\]* in _gdb_expr \[^\r\n\]*\r\n#1  <function called from gdb>\r\n.*"
+
+set test "p/x \$pc"
+set infcall_pc 0
+gdb_test_multiple $test $test {
+    -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
+	set infcall_pc $expect_out(1,string)
+	pass $test
+    }
+}
+
+gdb_test "info sym $infcall_pc" "\r\n_gdb_expr .*" "info sym found"
+gdb_test "return" "\r\n#0  main .*" "return" \
+	 "Make _gdb_expr return now\\? \\(y or n\\) " "y"
+gdb_test "info sym $infcall_pc" "\r\nNo symbol matches .*" "info sym not found"
+
+gdb_test_no_output "set unwindonsignal on"
+gdb_test "compile code *(volatile int *) 0 = 0;" \
+    "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*" \
+    "compile code segfault second"
+
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here" ".* break-here .*"
+
+gdb_test "p localvar" " = 50" "expect localvar 50"
+
+gdb_test_no_output "compile code localvar = 12;" "set localvar"
+gdb_test "p localvar" " = 12" "expect 12"
+
+gdb_test_no_output "compile code localvar *= 2;" "modify localvar"
+gdb_test "p localvar" " = 24" "expect 24"
+
+gdb_test_no_output "compile code localvar = shadowed" \
+    "test shadowing"
+gdb_test "p localvar" " = 52" "expect 52"
+
+gdb_test_no_output "compile code localvar = externed"
+gdb_test "p localvar" " = 7" "test extern in inner scope"
+
+gdb_test_no_output "compile code vla\[2\] = 7"
+gdb_test "p vla\[2\]" " = 7"
+gdb_test_no_output \
+    "compile code localvar = (sizeof (vla) == bound * sizeof (vla\[0\]))"
+gdb_test "p localvar" " = 1"
+
+#
+# Test setting fields and also many different types.
+#
+
+gdb_test_no_output "compile code struct_object.selffield = &struct_object"
+gdb_test "print struct_object.selffield == &struct_object" " = 1"
+
+gdb_test_no_output "compile code struct_object.charfield = 1"
+gdb_test "print struct_object.charfield" " = 1 '\\\\001'"
+gdb_test_no_output "compile code struct_object.ucharfield = 1"
+gdb_test "print struct_object.ucharfield" " = 1 '\\\\001'"
+
+foreach {field value} {
+    shortfield -5
+    ushortfield 5
+    intfield -7
+    uintfield 7
+    bitfield 2
+    longfield -9
+    ulongfield 9
+    enumfield ONE
+    floatfield 1
+    doublefield 2
+} {
+    gdb_test_no_output "compile code struct_object.$field = $value"
+    gdb_test "print struct_object.$field" " = $value"
+}
+
+gdb_test_no_output "compile code struct_object.arrayfield\[2\] = 7"
+gdb_test "print struct_object.arrayfield" \
+    " = \\{0, 0, 7, 0, 0\\}"
+
+gdb_test_no_output "compile code struct_object.complexfield = 7 + 5i"
+gdb_test "print struct_object.complexfield" " = 7 \\+ 5 \\* I"
+
+gdb_test_no_output "compile code struct_object.boolfield = 1"
+gdb_test "print struct_object.boolfield" " = true"
+
+gdb_test_no_output "compile code struct_object.vectorfield\[2\] = 7"
+gdb_test "print struct_object.vectorfield" \
+    " = \\{0, 0, 7, 0\\}"
+
+gdb_test_no_output "compile code union_object.typedeffield = 7"
+gdb_test "print union_object.typedeffield" " = 7"
+gdb_test "print union_object.intfield" " = 7"
+
+
+# LOC_UNRESOLVED tests.
+
+gdb_test "print unresolved" " = 20"
+gdb_test "compile code globalvar = unresolved;"
+gdb_test "print globalvar" " = 20" "print unresolved value"
+
+# Test shadowing with global and static variables.
+
+gdb_test_no_output "compile code globalshadow += 1;"
+gdb_test "print globalshadow" " = 101"
+gdb_test_no_output "compile code extern int globalshadow; globalshadow += 5;"
+gdb_test "print 'compile.c'::globalshadow" " = 15"
+gdb_test "print globalshadow" " = 101" "print globalshadow second time"
+gdb_test_no_output "compile code staticshadow += 2;"
+gdb_test "print staticshadow" " = 202"
+# "extern int staticshadow;" cannot access static variable.
+
+# Raw code cannot refer to locals.
+# As it references global variable we need the #pragma.
+# For #pragma we need multiline input.
+gdb_test_multiple "compile code -r" "compile code -r multiline 1" { -re "\r\n>$" {} }
+gdb_test_multiple "#pragma GCC user_expression" "compile code -r multiline 2" { -re "\r\n>$" {} }
+gdb_test_multiple "void _gdb_expr(void) { globalshadow = 77000; }" "compile code -r multiline 3" { -re "\r\n>$" {} }
+gdb_test_no_output "end" "compile code -r multiline 4"
+gdb_test "print 'compile.c'::globalshadow" " = 77000" \
+    "check globalshadow with -r"
+
+#
+# Test the case where the registers structure would not normally have
+# any fields.
+#
+
+gdb_breakpoint [gdb_get_line_number "no_args_or_locals breakpoint"]
+gdb_continue_to_breakpoint "no_args_or_locals"
+
+gdb_test_no_output "compile code globalvar = 77;" "set variable to 77"
+gdb_test "p globalvar" " = 77" "expect 77"
+
+
+# Test reference to minimal_symbol, not (full) symbol.
+
+gdb_test_no_output "compile code globalvar = func_nodebug (75);" \
+    "call func_nodebug"
+gdb_test "p globalvar" " = -75" "expect -75"
+gdb_test_no_output \
+  "compile code int (*funcp) (int) = func_nodebug; globalvar = funcp (76);" \
+  "call func_nodebug indirectly"
+gdb_test "p globalvar" " = -76" "expect -76"
+
+
+# Test compiled module memory protection.
+
+gdb_test_no_output "set debug compile on"
+gdb_test "compile code static const int readonly = 1; *(int *) &readonly = 2;" \
+    "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*"
+gdb_test_no_output "set debug compile off"
+
+
+#
+# Some simple coverage tests.
+#
+
+gdb_test "show debug compile" "Compile debugging is .*"
+gdb_test "show compile-args" \
+    "Compile command command-line arguments are .*"
+gdb_test "compile code -z" "Unknown argument.*"
+
+gdb_test "set lang java" \
+    "Warning: the current language does not match this frame."
+gdb_test "compile code globalvar" "No compiler support for this language\."
+gdb_test_no_output "set lang auto"
+
+gdb_test_no_output "compile code union union_type newdecl_u"
+gdb_test_no_output "compile code struct struct_type newdecl_s"
+gdb_test_no_output "compile code inttypedef newdecl_i"
+
+gdb_test "compile file" \
+    "You must provide a filename for this command.*" \
+    "Test compile file without a filename"
+gdb_test "compile file -r" \
+    "You must provide a filename with the raw option set.*" \
+    "Test compile file and raw option without a filename"
+gdb_test "compile file -z" \
+    "Unknown argument.*" \
+    "Test compile file with unknown argument"
+
+
+# LOC_CONST tests.
+
+if { $srcfile3 != "" } {
+    gdb_test "p constvar" " = 3"
+    gdb_test "info addr constvar" {Symbol "constvar" is constant\.}
+
+    gdb_test "compile code globalvar = constvar;"
+    gdb_test "print globalvar" " = 3" "print constvar value"
+} else {
+    untested "print constvar value"
+}
+
+# Shared library tests.
+
+if {[skip_shlib_tests]} {
+    untested "skipping shlib tests"
+    return;
+}
+
+set libbin [standard_output_file ${testfile}-shlib.so]
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} $libbin {debug}] != ""
+     || [build_executable $testfile ${testfile}-shlib $srcfile \
+	     [list debug ldflags=$libbin]] == -1 } {
+    return -1
+}
+
+clean_restart ${testfile}-shlib
+if ![runto_main] {
+    return -1
+}
+
+gdb_test_no_output "compile code shlib_func ();" "call shared library function"
+gdb_test "p globalvar" " = 1" "expect 1"
+
+gdb_test_no_output "compile code shlibvar += 5;" "modify shared library variable"
+gdb_test "p shlibvar" " = 15" "expect 15"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 2c79bc1..560573d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2518,6 +2518,23 @@ proc skip_libstdcxx_probe_tests {} {
     return $ok
 }
 
+# Return 1 if we should skip tests of the "compile" feature.
+# This must be invoked after the inferior has been started.
+
+proc skip_compile_feature_tests {} {
+    global gdb_prompt
+
+    set result 0
+    gdb_test_multiple "compile code -- ;" "check for working compile command" {
+	"Could not load libcc1.*\r\n$gdb_prompt $" {
+	    set result 1
+	}
+	-re "\r\n$gdb_prompt $" {
+	}
+    }
+    return $result
+}
+
 # Check whether we're testing with the remote or extended-remote
 # targets.
 

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [patch 15/14] GDB/GCC compile function pointers  [Re: [PATCH v4 00/14] let gdb reuse gcc's C compiler]
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (13 preceding siblings ...)
  2014-11-23 19:29 ` [PATCH v4 14/14] the "compile" command Jan Kratochvil
@ 2014-12-05 18:29 ` Jan Kratochvil
  2014-12-12 21:51   ` obsolete: " Jan Kratochvil
  2014-12-12 14:40 ` [PATCH v4 00/14] let gdb reuse gcc's C compiler Pedro Alves
  15 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-05 18:29 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 143 bytes --]

Hi,

not sure if it is already approved or under review but here is one fix-up of
the submitted code.  To be integrated during check-in.


Jan

[-- Attachment #2: jitgot.patch --]
[-- Type: text/plain, Size: 1661 bytes --]

diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 6d3d16e..bb6705f 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -636,12 +636,13 @@ String quoting is parsed like in shell, for example:\n\
 
   /* Override flags possibly coming from DW_AT_producer.  */
   compile_args = xstrdup ("-O0 -gdwarf-4"
-  /* We use -fPIC Otherwise GDB would need to reserve space large enough for
+  /* We use -fPIE Otherwise GDB would need to reserve space large enough for
      any object file in the inferior in advance to get the final address when
      to link the object file to and additionally the default system linker
      script would need to be modified so that one can specify there the
-     absolute target address.  */
-			 " -fPIC"
+     absolute target address.
+     -fPIC is not used at is would require from GDB to generate .got.  */
+			 " -fPIE"
   /* We don't want warnings.  */
 			 " -w"
   /* Override CU's possible -fstack-protector-strong.  */
diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp
index d0dd791..fb8b390 100644
--- a/gdb/testsuite/gdb.compile/compile.exp
+++ b/gdb/testsuite/gdb.compile/compile.exp
@@ -259,6 +259,11 @@ gdb_test_no_output "end" "compile code -r multiline 4"
 gdb_test "print 'compile.c'::globalshadow" " = 77000" \
     "check globalshadow with -r"
 
+# Test GOT vs. resolving jit function pointers.
+
+gdb_test_no_output "compile -raw -- int func(){return 21;} _gdb_expr(){int (*funcp)()=func; if (funcp()!=21) abort();}" \
+    "pointer to jit function"
+
 #
 # Test the case where the registers structure would not normally have
 # any fields.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 00/14] let gdb reuse gcc's C compiler
  2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
                   ` (14 preceding siblings ...)
  2014-12-05 18:29 ` [patch 15/14] GDB/GCC compile function pointers [Re: [PATCH v4 00/14] let gdb reuse gcc's C compiler] Jan Kratochvil
@ 2014-12-12 14:40 ` Pedro Alves
  2014-12-12 21:46   ` [commit all 14 parts] " Jan Kratochvil
  15 siblings, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-12 14:40 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches

On 11/23/2014 07:27 PM, Jan Kratochvil wrote:

> https://github.com/tromey/gdb.git
> submit/compile
> 
> This is version 4 of the patch to let gdb reuse gcc's C compiler.
> 
> Version 3 is here:
> 
>     https://sourceware.org/ml/gdb-patches/2014-11/msg00005.html
> 
> There is now also a description of this project at:
>     https://sourceware.org/gdb/wiki/GCCCompileAndExecute
> 
> Current GCC trunk (future 5.0) has now the libcc1.so support.
> This makes it relatively easy to test this patchset.
> 
> New in version 4:
>  * Testcases have been moved all into new directory gdb.compile/ .
>  * doc updates.
>  * Fix of GDB_MMAP_* symbols for host-independent linux-tdep.c.
>  * Minor fixes.
> 
> Built and regtested on x86-64, x86_64-m32 and i686 Fedora 21pre in linux-nat
> and gdbserver modes.
> 
> Going to check it in in a week as v3 seems to be reviewed now.

I don't have further comments.  I think this is good to go.

Kudos everyone; very nice work.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [commit all 14 parts] [PATCH v4 00/14] let gdb reuse gcc's C compiler
  2014-12-12 14:40 ` [PATCH v4 00/14] let gdb reuse gcc's C compiler Pedro Alves
@ 2014-12-12 21:46   ` Jan Kratochvil
  0 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-12 21:46 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Fri, 12 Dec 2014 15:40:08 +0100, Pedro Alves wrote:
> I don't have further comments.  I think this is good to go.

Checked in:
	commit bb2ec1b34e7cc8d8602512235016e74b800dac3b
	commit a2658febe2016f875ffb70287904b01013bcca75
	commit 3bc3cebe8a597c4281cad70e806efe69b2031825
	commit d064d1bef5c64c3525c01461ecd5be76c5fb0ca7
	commit af945b753559079fe37d61917041f2217d181b86
	commit a8fd55897077beda3717e0672807c1b2940e330a
	commit ed12ef62ccad3b86e25ec3b042d8bf7f15c75909
	commit ac04f72bb4396a311ffc445710d4068c13fb0448
	commit f208eee0f3a4f42a0bf20ab900eb36fbba8e4b9e
	commit 233a8fb382c88d7faa6da1cd93a7e21b77e36df4
	commit f1660027106d583c639c9f37096519944d5c20e9
	commit 4ff709eb44e13fee683f01184a490e4fcc5c2862
	commit a92a2e3435f9f579365424fb95d5e07cbd4c4ffd
	commit de571fc5fbd89d21436119ca2cd9dce1375bdcb3

Thanks for the recent thorough review.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* obsolete: [patch 15/14] GDB/GCC compile function pointers  [Re: [PATCH v4 00/14] let gdb reuse gcc's C compiler]
  2014-12-05 18:29 ` [patch 15/14] GDB/GCC compile function pointers [Re: [PATCH v4 00/14] let gdb reuse gcc's C compiler] Jan Kratochvil
@ 2014-12-12 21:51   ` Jan Kratochvil
  0 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-12 21:51 UTC (permalink / raw)
  To: gdb-patches

Reposted as:
	[patch] compile: Fix function pointers
	https://sourceware.org/ml/gdb-patches/2014-12/msg00298.html

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 14/14] the "compile" command
  2014-11-23 19:29 ` [PATCH v4 14/14] the "compile" command Jan Kratochvil
@ 2014-12-14  6:05   ` Yao Qi
  2014-12-14  7:53     ` Jan Kratochvil
  0 siblings, 1 reply; 93+ messages in thread
From: Yao Qi @ 2014-12-14  6:05 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> +static const char *
> +get_compile_file_tempdir (void)
> +{
> +  static char *tempdir_name;
> +
> +#define TEMPLATE TMP_PREFIX "XXXXXX"
> +  char tname[sizeof (TEMPLATE)];
> +
> +  if (tempdir_name != NULL)
> +    return tempdir_name;
> +
> +  strcpy (tname, TEMPLATE);
> +#undef TEMPLATE
> +  tempdir_name = mkdtemp (tname);

Hi Jan,
The build on mingw host is broken because mingw has no mkdtemp.

../../../git/gdb/compile/compile.c: In function 'get_compile_file_tempdir':
../../../git/gdb/compile/compile.c:194:3: error: implicit declaration of function 'mkdtemp' [-Werror=implicit-function-declaration]
   tempdir_name = mkdtemp (tname);
   ^
../../../git/gdb/compile/compile.c:194:16: error: assignment makes pointer from integer without a cast [-Werror]
   tempdir_name = mkdtemp (tname);
                ^
cc1: all warnings being treated as errors

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 14/14] the "compile" command
  2014-12-14  6:05   ` Yao Qi
@ 2014-12-14  7:53     ` Jan Kratochvil
  2014-12-14  8:54       ` Yao Qi
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-14  7:53 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Hi Yao,

On Sun, 14 Dec 2014 07:00:28 +0100, Yao Qi wrote:
> The build on mingw host is broken because mingw has no mkdtemp.
> 
> ../../../git/gdb/compile/compile.c: In function 'get_compile_file_tempdir':
> ../../../git/gdb/compile/compile.c:194:3: error: implicit declaration of function 'mkdtemp' [-Werror=implicit-function-declaration]

confirming in a local MinGW build.

Is it OK to import mkdtemp from gnulib?  Asking before I create such patch.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 14/14] the "compile" command
  2014-12-14  7:53     ` Jan Kratochvil
@ 2014-12-14  8:54       ` Yao Qi
  2014-12-14 18:24         ` [mingw rfc] Add mkdtemp to gdb/gnulib/ [Re: [PATCH v4 14/14] the "compile" command] Jan Kratochvil
  0 siblings, 1 reply; 93+ messages in thread
From: Yao Qi @ 2014-12-14  8:54 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> Is it OK to import mkdtemp from gnulib?  Asking before I create such patch.

Yes, that is fine by me.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-14  8:54       ` Yao Qi
@ 2014-12-14 18:24         ` Jan Kratochvil
  2014-12-15  3:16           ` Yao Qi
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-14 18:24 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches, Kai Tietz

[-- Attachment #1: Type: text/plain, Size: 779 bytes --]

Hi Yao,

On Sun, 14 Dec 2014 09:54:29 +0100, Yao Qi wrote:
> Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> > Is it OK to import mkdtemp from gnulib?  Asking before I create such patch.
> Yes, that is fine by me.

attached, although it is not ready for check-in.

On Fedora 21 x86_64 it builds now 32-bit target with mingw-w64, you are right
that with the 'compile' patches I checked in it did not.

But mingw-w64 64-bit target would build OK (after commenting out the mkdtemp()
call) before adding the gnulib mkdtemp module.  But after the gnulib mkdtemp
addition there are many errors (attached as the second attachment).  It is all
about
	struct timeval *
vs.
	struct rpl_timeval *
but an advice from mingw64 aware hacker would be nice to know what to do.


Thanks,
Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 137205 bytes --]

gdb/ChangeLog
2014-12-14  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Import mkdtemp into gnulib.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add mkdtemp.
	* gnulib/Makefile.in (aclocal_m4_deps): Add the new *.m4 files.
	* gnulib/aclocal.m4: Updated by update-gnulib.sh.
	* gnulib/config.in: Updated by update-gnulib.sh.
	* gnulib/configure: Updated by update-gnulib.sh.
	* gnulib/import/Makefile.am: Updated by update-gnulib.sh.
	* gnulib/import/Makefile.in: Updated by update-gnulib.sh.
	* gnulib/import/fcntl.in.h: New file by update-gnulib.sh.
	* gnulib/import/gettimeofday.c: New file by update-gnulib.sh.
	* gnulib/import/m4/fcntl_h.m4: New file by update-gnulib.sh.
	* gnulib/import/m4/gettimeofday.m4: New file by update-gnulib.sh.
	* gnulib/import/m4/gnulib-cache.m4: Updated by update-gnulib.sh.
	* gnulib/import/m4/gnulib-comp.m4: Updated by update-gnulib.sh.
	* gnulib/import/m4/mkdtemp.m4: New file by update-gnulib.sh.
	* gnulib/import/m4/sys_socket_h.m4: New file by update-gnulib.sh.
	* gnulib/import/m4/sys_time_h.m4: New file by update-gnulib.sh.
	* gnulib/import/m4/tempname.m4: New file by update-gnulib.sh.
	* gnulib/import/mkdtemp.c: New file by update-gnulib.sh.
	* gnulib/import/sys_time.in.h: New file by update-gnulib.sh.
	* gnulib/import/tempname.c: New file by update-gnulib.sh.
	* gnulib/import/tempname.h: New file by update-gnulib.sh.

diff --git a/gdb/gnulib/Makefile.in b/gdb/gnulib/Makefile.in
index 2252fec..c5d384f 100644
--- a/gdb/gnulib/Makefile.in
+++ b/gdb/gnulib/Makefile.in
@@ -213,7 +213,9 @@ aclocal_m4_deps = \
 	import/m4/configmake.m4 \
 	import/m4/extensions.m4 \
 	import/m4/fcntl-o.m4 \
+	import/m4/fcntl_h.m4 \
 	import/m4/fnmatch.m4 \
+	import/m4/gettimeofday.m4 \
 	import/m4/glibc21.m4 \
 	import/m4/gnulib-cache.m4 \
 	import/m4/gnulib-common.m4 \
@@ -233,6 +235,7 @@ aclocal_m4_deps = \
 	import/m4/mbstate_t.m4 \
 	import/m4/memchr.m4 \
 	import/m4/memmem.m4 \
+	import/m4/mkdtemp.m4 \
 	import/m4/mmap-anon.m4 \
 	import/m4/multiarch.m4 \
 	import/m4/off_t.m4 \
@@ -242,7 +245,10 @@ aclocal_m4_deps = \
 	import/m4/stddef_h.m4 \
 	import/m4/stdint.m4 \
 	import/m4/string_h.m4 \
+	import/m4/sys_socket_h.m4 \
+	import/m4/sys_time_h.m4 \
 	import/m4/sys_types_h.m4 \
+	import/m4/tempname.m4 \
 	import/m4/unistd_h.m4 \
 	import/m4/warn-on-use.m4 \
 	import/m4/wchar_h.m4 \
diff --git a/gdb/gnulib/aclocal.m4 b/gdb/gnulib/aclocal.m4
index 76fb3f0..0c58adf 100644
--- a/gdb/gnulib/aclocal.m4
+++ b/gdb/gnulib/aclocal.m4
@@ -1028,11 +1028,13 @@ m4_include([import/m4/exponentl.m4])
 m4_include([import/m4/extensions.m4])
 m4_include([import/m4/extern-inline.m4])
 m4_include([import/m4/fcntl-o.m4])
+m4_include([import/m4/fcntl_h.m4])
 m4_include([import/m4/float_h.m4])
 m4_include([import/m4/fnmatch.m4])
 m4_include([import/m4/fpieee.m4])
 m4_include([import/m4/frexp.m4])
 m4_include([import/m4/frexpl.m4])
+m4_include([import/m4/gettimeofday.m4])
 m4_include([import/m4/glibc21.m4])
 m4_include([import/m4/gnulib-common.m4])
 m4_include([import/m4/gnulib-comp.m4])
@@ -1057,6 +1059,7 @@ m4_include([import/m4/mbsrtowcs.m4])
 m4_include([import/m4/mbstate_t.m4])
 m4_include([import/m4/memchr.m4])
 m4_include([import/m4/memmem.m4])
+m4_include([import/m4/mkdtemp.m4])
 m4_include([import/m4/mmap-anon.m4])
 m4_include([import/m4/multiarch.m4])
 m4_include([import/m4/nocrash.m4])
@@ -1074,8 +1077,11 @@ m4_include([import/m4/stdio_h.m4])
 m4_include([import/m4/stdlib_h.m4])
 m4_include([import/m4/string_h.m4])
 m4_include([import/m4/strstr.m4])
+m4_include([import/m4/sys_socket_h.m4])
 m4_include([import/m4/sys_stat_h.m4])
+m4_include([import/m4/sys_time_h.m4])
 m4_include([import/m4/sys_types_h.m4])
+m4_include([import/m4/tempname.m4])
 m4_include([import/m4/time_h.m4])
 m4_include([import/m4/unistd_h.m4])
 m4_include([import/m4/warn-on-use.m4])
diff --git a/gdb/gnulib/config.in b/gdb/gnulib/config.in
index 5d8018d..830c787 100644
--- a/gdb/gnulib/config.in
+++ b/gdb/gnulib/config.in
@@ -50,6 +50,13 @@
    and handles trailing slash correctly. */
 #undef FUNC_REALPATH_WORKS
 
+/* Define if gettimeofday clobbers the localtime buffer. */
+#undef GETTIMEOFDAY_CLOBBERS_LOCALTIME
+
+/* Define this to 'void' or 'struct timezone' to match the system's
+   declaration of the second argument to gettimeofday. */
+#undef GETTIMEOFDAY_TIMEZONE
+
 /* Define to a C preprocessor expression that evaluates to 1 or 0, depending
    whether the gnulib module canonicalize-lgpl shall be considered present. */
 #undef GNULIB_CANONICALIZE_LGPL
@@ -78,6 +85,9 @@
 /* Define to 1 when the gnulib module frexpl should be tested. */
 #undef GNULIB_TEST_FREXPL
 
+/* Define to 1 when the gnulib module gettimeofday should be tested. */
+#undef GNULIB_TEST_GETTIMEOFDAY
+
 /* Define to 1 when the gnulib module lstat should be tested. */
 #undef GNULIB_TEST_LSTAT
 
@@ -99,6 +109,9 @@
 /* Define to 1 when the gnulib module memmem should be tested. */
 #undef GNULIB_TEST_MEMMEM
 
+/* Define to 1 when the gnulib module mkdtemp should be tested. */
+#undef GNULIB_TEST_MKDTEMP
+
 /* Define to 1 when the gnulib module readlink should be tested. */
 #undef GNULIB_TEST_READLINK
 
@@ -187,6 +200,9 @@
 /* Define to 1 if you have the `getcwd' function. */
 #undef HAVE_GETCWD
 
+/* Define to 1 if you have the `gettimeofday' function. */
+#undef HAVE_GETTIMEOFDAY
+
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
@@ -248,6 +264,9 @@
 /* Define to 1 if you have the `mempcpy' function. */
 #undef HAVE_MEMPCPY
 
+/* Define to 1 if you have the `mkdtemp' function. */
+#undef HAVE_MKDTEMP
+
 /* Define to 1 if you have the `mprotect' function. */
 #undef HAVE_MPROTECT
 
@@ -390,6 +409,9 @@
 /* Define to 1 if fchownat is declared even after undefining macros. */
 #undef HAVE_RAW_DECL_FCHOWNAT
 
+/* Define to 1 if fcntl is declared even after undefining macros. */
+#undef HAVE_RAW_DECL_FCNTL
+
 /* Define to 1 if fdatasync is declared even after undefining macros. */
 #undef HAVE_RAW_DECL_FDATASYNC
 
@@ -495,6 +517,9 @@
 /* Define to 1 if getsubopt is declared even after undefining macros. */
 #undef HAVE_RAW_DECL_GETSUBOPT
 
+/* Define to 1 if gettimeofday is declared even after undefining macros. */
+#undef HAVE_RAW_DECL_GETTIMEOFDAY
+
 /* Define to 1 if getusershell is declared even after undefining macros. */
 #undef HAVE_RAW_DECL_GETUSERSHELL
 
@@ -669,6 +694,9 @@
 /* Define to 1 if modfl is declared even after undefining macros. */
 #undef HAVE_RAW_DECL_MODFL
 
+/* Define to 1 if openat is declared even after undefining macros. */
+#undef HAVE_RAW_DECL_OPENAT
+
 /* Define to 1 if opendir is declared even after undefining macros. */
 #undef HAVE_RAW_DECL_OPENDIR
 
@@ -1077,9 +1105,15 @@
 /* Define to 1 if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#undef HAVE_SYS_SOCKET_H
+
 /* Define to 1 if you have the <sys/stat.h> header file. */
 #undef HAVE_SYS_STAT_H
 
+/* Define to 1 if you have the <sys/timeb.h> header file. */
+#undef HAVE_SYS_TIMEB_H
+
 /* Define to 1 if you have the <sys/time.h> header file. */
 #undef HAVE_SYS_TIME_H
 
@@ -1104,6 +1138,9 @@
 /* Define to 1 if you have the <wctype.h> header file. */
 #undef HAVE_WCTYPE_H
 
+/* Define to 1 if you have the <winsock2.h> header file. */
+#undef HAVE_WINSOCK2_H
+
 /* Define if you have the 'wint_t' type. */
 #undef HAVE_WINT_T
 
@@ -1125,6 +1162,9 @@
 /* Define to 1 if the system has the type `_Bool'. */
 #undef HAVE__BOOL
 
+/* Define to 1 if you have the `_ftime' function. */
+#undef HAVE__FTIME
+
 /* Define as the bit index in the word where to find bit 0 of the exponent of
    'long double'. */
 #undef LDBL_EXPBIT0_BIT
@@ -1371,6 +1411,9 @@
 /* Define to a replacement function name for fnmatch(). */
 #undef fnmatch
 
+/* Define to rpl_gmtime if the replacement function should be used. */
+#undef gmtime
+
 /* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
    the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
    earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
@@ -1381,6 +1424,9 @@
 # define __GNUC_STDC_INLINE__ 1
 #endif
 
+/* Define to rpl_localtime if the replacement function should be used. */
+#undef localtime
+
 /* Define to a type if <wchar.h> does not define. */
 #undef mbstate_t
 
diff --git a/gdb/gnulib/configure b/gdb/gnulib/configure
index 29e49b9..f087cfd 100644
--- a/gdb/gnulib/configure
+++ b/gdb/gnulib/configure
@@ -1048,6 +1048,15 @@ HAVE_INTTYPES_H
 HAVE_WCHAR_H
 HAVE_UNSIGNED_LONG_LONG_INT
 HAVE_LONG_LONG_INT
+HAVE_WINSOCK2_H
+NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H
+NEXT_SYS_TIME_H
+REPLACE_STRUCT_TIMEVAL
+REPLACE_GETTIMEOFDAY
+HAVE_SYS_TIME_H
+HAVE_STRUCT_TIMEVAL
+HAVE_GETTIMEOFDAY
+GNULIB_GETTIMEOFDAY
 FREXPL_LIBM
 HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
 FREXP_LIBM
@@ -1314,6 +1323,17 @@ GL_GENERATE_FLOAT_H_TRUE
 FLOAT_H
 NEXT_AS_FIRST_DIRECTIVE_FLOAT_H
 NEXT_FLOAT_H
+NEXT_AS_FIRST_DIRECTIVE_FCNTL_H
+NEXT_FCNTL_H
+REPLACE_OPENAT
+REPLACE_OPEN
+REPLACE_FCNTL
+HAVE_OPENAT
+HAVE_FCNTL
+GNULIB_OPENAT
+GNULIB_OPEN
+GNULIB_NONBLOCKING
+GNULIB_FCNTL
 EOVERFLOW_VALUE
 EOVERFLOW_HIDDEN
 ENOLINK_VALUE
@@ -3258,6 +3278,8 @@ as_fn_append ac_func_list " readlink"
 as_fn_append ac_func_list " realpath"
 as_fn_append ac_header_list " sys/param.h"
 as_fn_append ac_header_list " dirent.h"
+as_fn_append ac_header_list " unistd.h"
+as_fn_append ac_func_list " symlink"
 as_fn_append ac_func_list " btowc"
 as_fn_append ac_func_list " isblank"
 as_fn_append ac_func_list " iswctype"
@@ -3269,11 +3291,12 @@ as_fn_append ac_func_list " wmempcpy"
 as_fn_append ac_header_list " wctype.h"
 gl_fnmatch_required=GNU
 as_fn_append ac_func_list " alarm"
+as_fn_append ac_header_list " sys/time.h"
+as_fn_append ac_header_list " sys/socket.h"
+as_fn_append ac_func_list " gettimeofday"
 as_fn_append ac_header_list " wchar.h"
 as_fn_append ac_header_list " stdint.h"
 as_fn_append ac_header_list " inttypes.h"
-as_fn_append ac_header_list " unistd.h"
-as_fn_append ac_func_list " symlink"
 as_fn_append ac_func_list " lstat"
 as_fn_append ac_header_list " math.h"
 as_fn_append ac_func_list " mbsinit"
@@ -3282,7 +3305,6 @@ as_fn_append ac_header_list " sys/mman.h"
 as_fn_append ac_func_list " mprotect"
 as_fn_append ac_func_list " link"
 as_fn_append ac_header_list " sys/stat.h"
-as_fn_append ac_header_list " sys/time.h"
 as_fn_append ac_header_list " features.h"
 as_fn_append ac_func_list " iswcntrl"
 # Check that the precious variables saved in the cache have kept the same
@@ -5201,6 +5223,7 @@ fi
   # Code from module extensions:
 
   # Code from module extern-inline:
+  # Code from module fcntl-h:
   # Code from module float:
   # Code from module fnmatch:
   # Code from module fnmatch-gnu:
@@ -5209,6 +5232,7 @@ fi
   # Code from module fpucw:
   # Code from module frexp:
   # Code from module frexpl:
+  # Code from module gettimeofday:
   # Code from module include_next:
   # Code from module inttypes:
   # Code from module inttypes-incomplete:
@@ -5227,6 +5251,7 @@ fi
   # Code from module memchr:
   # Code from module memmem:
   # Code from module memmem-simple:
+  # Code from module mkdtemp:
   # Code from module multiarch:
   # Code from module nocrash:
   # Code from module pathmax:
@@ -5251,7 +5276,9 @@ fi
   # Code from module strstr:
   # Code from module strstr-simple:
   # Code from module sys_stat:
+  # Code from module sys_time:
   # Code from module sys_types:
+  # Code from module tempname:
   # Code from module time:
   # Code from module unistd:
   # Code from module update-copyright:
@@ -7064,6 +7091,189 @@ $as_echo "$gl_cv_header_errno_h_EOVERFLOW" >&6; }
 
 
 
+  GNULIB_FCNTL=0;
+  GNULIB_NONBLOCKING=0;
+  GNULIB_OPEN=0;
+  GNULIB_OPENAT=0;
+    HAVE_FCNTL=1;
+  HAVE_OPENAT=1;
+  REPLACE_FCNTL=0;
+  REPLACE_OPEN=0;
+  REPLACE_OPENAT=0;
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working fcntl.h" >&5
+$as_echo_n "checking for working fcntl.h... " >&6; }
+if test "${gl_cv_header_working_fcntl_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  gl_cv_header_working_fcntl_h=cross-compiling
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+           #include <sys/stat.h>
+           #if HAVE_UNISTD_H
+           # include <unistd.h>
+           #else /* on Windows with MSVC */
+           # include <io.h>
+           # include <stdlib.h>
+           # defined sleep(n) _sleep ((n) * 1000)
+           #endif
+           #include <fcntl.h>
+           #ifndef O_NOATIME
+            #define O_NOATIME 0
+           #endif
+           #ifndef O_NOFOLLOW
+            #define O_NOFOLLOW 0
+           #endif
+           static int const constants[] =
+            {
+              O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
+              O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
+            };
+
+int
+main ()
+{
+
+            int result = !constants;
+            #if HAVE_SYMLINK
+            {
+              static char const sym[] = "conftest.sym";
+              if (symlink ("/dev/null", sym) != 0)
+                result |= 2;
+              else
+                {
+                  int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0);
+                  if (fd >= 0)
+                    {
+                      close (fd);
+                      result |= 4;
+                    }
+                }
+              if (unlink (sym) != 0 || symlink (".", sym) != 0)
+                result |= 2;
+              else
+                {
+                  int fd = open (sym, O_RDONLY | O_NOFOLLOW);
+                  if (fd >= 0)
+                    {
+                      close (fd);
+                      result |= 4;
+                    }
+                }
+              unlink (sym);
+            }
+            #endif
+            {
+              static char const file[] = "confdefs.h";
+              int fd = open (file, O_RDONLY | O_NOATIME);
+              if (fd < 0)
+                result |= 8;
+              else
+                {
+                  struct stat st0;
+                  if (fstat (fd, &st0) != 0)
+                    result |= 16;
+                  else
+                    {
+                      char c;
+                      sleep (1);
+                      if (read (fd, &c, 1) != 1)
+                        result |= 24;
+                      else
+                        {
+                          if (close (fd) != 0)
+                            result |= 32;
+                          else
+                            {
+                              struct stat st1;
+                              if (stat (file, &st1) != 0)
+                                result |= 40;
+                              else
+                                if (st0.st_atime != st1.st_atime)
+                                  result |= 64;
+                            }
+                        }
+                    }
+                }
+            }
+            return result;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_header_working_fcntl_h=yes
+else
+  case $? in #(
+        4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
+        64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
+        68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
+         *) gl_cv_header_working_fcntl_h='no';;
+        esac
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_working_fcntl_h" >&5
+$as_echo "$gl_cv_header_working_fcntl_h" >&6; }
+
+  case $gl_cv_header_working_fcntl_h in #(
+  *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
+  *) ac_val=1;;
+  esac
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_WORKING_O_NOATIME $ac_val
+_ACEOF
+
+
+  case $gl_cv_header_working_fcntl_h in #(
+  *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
+  *) ac_val=1;;
+  esac
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_WORKING_O_NOFOLLOW $ac_val
+_ACEOF
+
+
+ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default"
+if test "x$ac_cv_type_pid_t" = x""yes; then :
+
+else
+
+cat >>confdefs.h <<_ACEOF
+#define pid_t int
+_ACEOF
+
+fi
+
+ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default"
+if test "x$ac_cv_type_mode_t" = x""yes; then :
+
+else
+
+cat >>confdefs.h <<_ACEOF
+#define mode_t int
+_ACEOF
+
+fi
+
+
 
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for mbstate_t" >&5
 $as_echo_n "checking for mbstate_t... " >&6; }
@@ -7457,67 +7667,364 @@ $as_echo "#define HAVE_SAME_LONG_DOUBLE_AS_DOUBLE 1" >>confdefs.h
   fi
 
 
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for unsigned long long int" >&5
-$as_echo_n "checking for unsigned long long int... " >&6; }
-if test "${ac_cv_type_unsigned_long_long_int+set}" = set; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
+$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
+if test "${ac_cv_c_restrict+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_cv_type_unsigned_long_long_int=yes
-     if test "x${ac_cv_prog_cc_c99-no}" = xno; then
-       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  ac_cv_c_restrict=no
+   # The order here caters to the fact that C++ does not require restrict.
+   for ac_kw in __restrict __restrict__ _Restrict restrict; do
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
-  /* For now, do not test the preprocessor; as of 2007 there are too many
-         implementations with broken preprocessors.  Perhaps this can
-         be revisited in 2012.  In the meantime, code should not expect
-         #if to work with literals wider than 32 bits.  */
-      /* Test literals.  */
-      long long int ll = 9223372036854775807ll;
-      long long int nll = -9223372036854775807LL;
-      unsigned long long int ull = 18446744073709551615ULL;
-      /* Test constant expressions.   */
-      typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
-                     ? 1 : -1)];
-      typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
-                     ? 1 : -1)];
-      int i = 63;
+typedef int * int_ptr;
+	int foo (int_ptr $ac_kw ip) {
+	return ip[0];
+       }
 int
 main ()
 {
-/* Test availability of runtime routines for shift and division.  */
-      long long int llmax = 9223372036854775807ll;
-      unsigned long long int ullmax = 18446744073709551615ull;
-      return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
-              | (llmax / ll) | (llmax % ll)
-              | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
-              | (ullmax / ull) | (ullmax % ull));
+int s[1];
+	int * $ac_kw t = s;
+	t[0] = 0;
+	return foo(t)
   ;
   return 0;
 }
-
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-
-else
-  ac_cv_type_unsigned_long_long_int=no
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_restrict=$ac_kw
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-     fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+     test "$ac_cv_c_restrict" != no && break
+   done
+
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_unsigned_long_long_int" >&5
-$as_echo "$ac_cv_type_unsigned_long_long_int" >&6; }
-  if test $ac_cv_type_unsigned_long_long_int = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_restrict" >&5
+$as_echo "$ac_cv_c_restrict" >&6; }
 
-$as_echo "#define HAVE_UNSIGNED_LONG_LONG_INT 1" >>confdefs.h
+ case $ac_cv_c_restrict in
+   restrict) ;;
+   no) $as_echo "#define restrict /**/" >>confdefs.h
+ ;;
+   *)  cat >>confdefs.h <<_ACEOF
+#define restrict $ac_cv_c_restrict
+_ACEOF
+ ;;
+ esac
 
-  fi
 
+  GNULIB_GETTIMEOFDAY=0;
+    HAVE_GETTIMEOFDAY=1;
+  HAVE_STRUCT_TIMEVAL=1;
+  HAVE_SYS_TIME_H=1;
+  REPLACE_GETTIMEOFDAY=0;
+  REPLACE_STRUCT_TIMEVAL=0;
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long long int" >&5
-$as_echo_n "checking for long long int... " >&6; }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+     if test $gl_cv_have_include_next = yes; then
+       gl_cv_next_sys_time_h='<'sys/time.h'>'
+     else
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking absolute name of <sys/time.h>" >&5
+$as_echo_n "checking absolute name of <sys/time.h>... " >&6; }
+if test "${gl_cv_next_sys_time_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+             if test $ac_cv_header_sys_time_h = yes; then
+
+
+               cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/time.h>
+
+_ACEOF
+                                                                                                                        case "$host_os" in
+                 aix*) gl_absname_cpp="$ac_cpp -C" ;;
+                 *)    gl_absname_cpp="$ac_cpp" ;;
+               esac
+
+               case "$host_os" in
+                 mingw*)
+                                                                                                                                     gl_dirsep_regex='[/\\]'
+                   ;;
+                 *)
+                   gl_dirsep_regex='\/'
+                   ;;
+               esac
+                                             gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
+
+               gl_header_literal_regex=`echo 'sys/time.h' \
+                                        | sed -e "$gl_make_literal_regex_sed"`
+               gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
+                   s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
+                   s|^/[^/]|//&|
+                   p
+                   q
+                 }'
+                                                            gl_cv_next_sys_time_h='"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&5 |
+                      sed -n "$gl_absolute_header_sed"`'"'
+          else
+               gl_cv_next_sys_time_h='<'sys/time.h'>'
+             fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_next_sys_time_h" >&5
+$as_echo "$gl_cv_next_sys_time_h" >&6; }
+     fi
+     NEXT_SYS_TIME_H=$gl_cv_next_sys_time_h
+
+     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
+       gl_next_as_first_directive='<'sys/time.h'>'
+     else
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
+       gl_next_as_first_directive=$gl_cv_next_sys_time_h
+     fi
+     NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H=$gl_next_as_first_directive
+
+
+
+
+
+  if test $ac_cv_header_sys_time_h != yes; then
+    HAVE_SYS_TIME_H=0
+  fi
+
+
+
+
+
+  if test $ac_cv_header_sys_socket_h != yes; then
+                    for ac_header in winsock2.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "winsock2.h" "ac_cv_header_winsock2_h" "$ac_includes_default"
+if test "x$ac_cv_header_winsock2_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_WINSOCK2_H 1
+_ACEOF
+
+fi
+
+done
+
+  fi
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    HAVE_WINSOCK2_H=1
+    UNISTD_H_HAVE_WINSOCK2_H=1
+    SYS_IOCTL_H_HAVE_WINSOCK2_H=1
+  else
+    HAVE_WINSOCK2_H=0
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct timeval" >&5
+$as_echo_n "checking for struct timeval... " >&6; }
+if test "${gl_cv_sys_struct_timeval+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#if HAVE_SYS_TIME_H
+             #include <sys/time.h>
+            #endif
+            #include <time.h>
+            #if HAVE_WINSOCK2_H
+            # include <winsock2.h>
+            #endif
+
+int
+main ()
+{
+static struct timeval x; x.tv_sec = x.tv_usec;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_sys_struct_timeval=yes
+else
+  gl_cv_sys_struct_timeval=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_sys_struct_timeval" >&5
+$as_echo "$gl_cv_sys_struct_timeval" >&6; }
+  if test $gl_cv_sys_struct_timeval != yes; then
+    HAVE_STRUCT_TIMEVAL=0
+  else
+                            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wide-enough struct timeval.tv_sec member" >&5
+$as_echo_n "checking for wide-enough struct timeval.tv_sec member... " >&6; }
+if test "${gl_cv_sys_struct_timeval_tv_sec+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#if HAVE_SYS_TIME_H
+               #include <sys/time.h>
+              #endif
+              #include <time.h>
+              #if HAVE_WINSOCK2_H
+              # include <winsock2.h>
+              #endif
+
+int
+main ()
+{
+static struct timeval x;
+              typedef int verify_tv_sec_type[
+                sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1
+              ];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_sys_struct_timeval_tv_sec=yes
+else
+  gl_cv_sys_struct_timeval_tv_sec=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_sys_struct_timeval_tv_sec" >&5
+$as_echo "$gl_cv_sys_struct_timeval_tv_sec" >&6; }
+    if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
+      REPLACE_STRUCT_TIMEVAL=1
+    fi
+  fi
+
+
+    for gl_func in gettimeofday; do
+    as_gl_Symbol=`$as_echo "gl_cv_have_raw_decl_$gl_func" | $as_tr_sh`
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $gl_func is declared without a macro" >&5
+$as_echo_n "checking whether $gl_func is declared without a macro... " >&6; }
+if { as_var=$as_gl_Symbol; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#if HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <time.h>
+
+int
+main ()
+{
+#undef $gl_func
+  (void) $gl_func;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$as_gl_Symbol=yes"
+else
+  eval "$as_gl_Symbol=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$as_gl_Symbol
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+    eval as_val=\$$as_gl_Symbol
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_RAW_DECL_$gl_func" | $as_tr_cpp` 1
+_ACEOF
+
+                     eval ac_cv_have_decl_$gl_func=yes
+fi
+      done
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for unsigned long long int" >&5
+$as_echo_n "checking for unsigned long long int... " >&6; }
+if test "${ac_cv_type_unsigned_long_long_int+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_type_unsigned_long_long_int=yes
+     if test "x${ac_cv_prog_cc_c99-no}" = xno; then
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+  /* For now, do not test the preprocessor; as of 2007 there are too many
+         implementations with broken preprocessors.  Perhaps this can
+         be revisited in 2012.  In the meantime, code should not expect
+         #if to work with literals wider than 32 bits.  */
+      /* Test literals.  */
+      long long int ll = 9223372036854775807ll;
+      long long int nll = -9223372036854775807LL;
+      unsigned long long int ull = 18446744073709551615ULL;
+      /* Test constant expressions.   */
+      typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
+                     ? 1 : -1)];
+      typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
+                     ? 1 : -1)];
+      int i = 63;
+int
+main ()
+{
+/* Test availability of runtime routines for shift and division.  */
+      long long int llmax = 9223372036854775807ll;
+      unsigned long long int ullmax = 18446744073709551615ull;
+      return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
+              | (llmax / ll) | (llmax % ll)
+              | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
+              | (ullmax / ull) | (ullmax % ull));
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+  ac_cv_type_unsigned_long_long_int=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_unsigned_long_long_int" >&5
+$as_echo "$ac_cv_type_unsigned_long_long_int" >&6; }
+  if test $ac_cv_type_unsigned_long_long_int = yes; then
+
+$as_echo "#define HAVE_UNSIGNED_LONG_LONG_INT 1" >>confdefs.h
+
+  fi
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long long int" >&5
+$as_echo_n "checking for long long int... " >&6; }
 if test "${ac_cv_type_long_long_int+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
@@ -9119,235 +9626,85 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
  presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
  esac
 
-
-
-
-  case "$host_os" in
-    mingw*)
-                        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit off_t" >&5
-$as_echo_n "checking for 64-bit off_t... " >&6; }
-if test "${gl_cv_type_off_t_64+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/types.h>
-                int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  gl_cv_type_off_t_64=yes
-else
-  gl_cv_type_off_t_64=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_type_off_t_64" >&5
-$as_echo "$gl_cv_type_off_t_64" >&6; }
-      if test $gl_cv_type_off_t_64 = no; then
-        WINDOWS_64_BIT_OFF_T=1
-      else
-        WINDOWS_64_BIT_OFF_T=0
-      fi
-                  WINDOWS_64_BIT_ST_SIZE=1
-      ;;
-    *)
-                                                      WINDOWS_64_BIT_OFF_T=0
-      WINDOWS_64_BIT_ST_SIZE=0
-      ;;
-  esac
-
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nl_langinfo and CODESET" >&5
-$as_echo_n "checking for nl_langinfo and CODESET... " >&6; }
-if test "${am_cv_langinfo_codeset+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <langinfo.h>
-int
-main ()
-{
-char* cs = nl_langinfo(CODESET); return !cs;
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  am_cv_langinfo_codeset=yes
-else
-  am_cv_langinfo_codeset=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_langinfo_codeset" >&5
-$as_echo "$am_cv_langinfo_codeset" >&6; }
-  if test $am_cv_langinfo_codeset = yes; then
-
-$as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
-
-  fi
-
-
-
-
-
-
-
-
-
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working fcntl.h" >&5
-$as_echo_n "checking for working fcntl.h... " >&6; }
-if test "${gl_cv_header_working_fcntl_h+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test "$cross_compiling" = yes; then :
-  gl_cv_header_working_fcntl_h=cross-compiling
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/types.h>
-           #include <sys/stat.h>
-           #if HAVE_UNISTD_H
-           # include <unistd.h>
-           #else /* on Windows with MSVC */
-           # include <io.h>
-           # include <stdlib.h>
-           # defined sleep(n) _sleep ((n) * 1000)
-           #endif
-           #include <fcntl.h>
-           #ifndef O_NOATIME
-            #define O_NOATIME 0
-           #endif
-           #ifndef O_NOFOLLOW
-            #define O_NOFOLLOW 0
-           #endif
-           static int const constants[] =
-            {
-              O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
-              O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
-            };
-
-int
-main ()
-{
-
-            int result = !constants;
-            #if HAVE_SYMLINK
-            {
-              static char const sym[] = "conftest.sym";
-              if (symlink ("/dev/null", sym) != 0)
-                result |= 2;
-              else
-                {
-                  int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0);
-                  if (fd >= 0)
-                    {
-                      close (fd);
-                      result |= 4;
-                    }
-                }
-              if (unlink (sym) != 0 || symlink (".", sym) != 0)
-                result |= 2;
-              else
-                {
-                  int fd = open (sym, O_RDONLY | O_NOFOLLOW);
-                  if (fd >= 0)
-                    {
-                      close (fd);
-                      result |= 4;
-                    }
-                }
-              unlink (sym);
-            }
-            #endif
-            {
-              static char const file[] = "confdefs.h";
-              int fd = open (file, O_RDONLY | O_NOATIME);
-              if (fd < 0)
-                result |= 8;
-              else
-                {
-                  struct stat st0;
-                  if (fstat (fd, &st0) != 0)
-                    result |= 16;
-                  else
-                    {
-                      char c;
-                      sleep (1);
-                      if (read (fd, &c, 1) != 1)
-                        result |= 24;
-                      else
-                        {
-                          if (close (fd) != 0)
-                            result |= 32;
-                          else
-                            {
-                              struct stat st1;
-                              if (stat (file, &st1) != 0)
-                                result |= 40;
-                              else
-                                if (st0.st_atime != st1.st_atime)
-                                  result |= 64;
-                            }
-                        }
-                    }
-                }
-            }
-            return result;
+
+
+
+  case "$host_os" in
+    mingw*)
+                        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit off_t" >&5
+$as_echo_n "checking for 64-bit off_t... " >&6; }
+if test "${gl_cv_type_off_t_64+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+                int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
+
+int
+main ()
+{
+
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  gl_cv_header_working_fcntl_h=yes
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_type_off_t_64=yes
 else
-  case $? in #(
-        4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
-        64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
-        68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
-         *) gl_cv_header_working_fcntl_h='no';;
-        esac
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
+  gl_cv_type_off_t_64=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_working_fcntl_h" >&5
-$as_echo "$gl_cv_header_working_fcntl_h" >&6; }
-
-  case $gl_cv_header_working_fcntl_h in #(
-  *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
-  *) ac_val=1;;
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_type_off_t_64" >&5
+$as_echo "$gl_cv_type_off_t_64" >&6; }
+      if test $gl_cv_type_off_t_64 = no; then
+        WINDOWS_64_BIT_OFF_T=1
+      else
+        WINDOWS_64_BIT_OFF_T=0
+      fi
+                  WINDOWS_64_BIT_ST_SIZE=1
+      ;;
+    *)
+                                                      WINDOWS_64_BIT_OFF_T=0
+      WINDOWS_64_BIT_ST_SIZE=0
+      ;;
   esac
 
-cat >>confdefs.h <<_ACEOF
-#define HAVE_WORKING_O_NOATIME $ac_val
-_ACEOF
 
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nl_langinfo and CODESET" >&5
+$as_echo_n "checking for nl_langinfo and CODESET... " >&6; }
+if test "${am_cv_langinfo_codeset+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <langinfo.h>
+int
+main ()
+{
+char* cs = nl_langinfo(CODESET); return !cs;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  am_cv_langinfo_codeset=yes
+else
+  am_cv_langinfo_codeset=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 
-  case $gl_cv_header_working_fcntl_h in #(
-  *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
-  *) ac_val=1;;
-  esac
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_langinfo_codeset" >&5
+$as_echo "$am_cv_langinfo_codeset" >&6; }
+  if test $am_cv_langinfo_codeset = yes; then
 
-cat >>confdefs.h <<_ACEOF
-#define HAVE_WORKING_O_NOFOLLOW $ac_val
-_ACEOF
+$as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
 
+  fi
 
 ac_fn_c_check_decl "$LINENO" "getc_unlocked" "ac_cv_have_decl_getc_unlocked" "$ac_includes_default"
 if test "x$ac_cv_have_decl_getc_unlocked" = x""yes; then :
@@ -10821,52 +11178,6 @@ $as_echo "#define HAVE_WCHAR_T 1" >>confdefs.h
 
   fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
-$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
-if test "${ac_cv_c_restrict+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_cv_c_restrict=no
-   # The order here caters to the fact that C++ does not require restrict.
-   for ac_kw in __restrict __restrict__ _Restrict restrict; do
-     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-typedef int * int_ptr;
-	int foo (int_ptr $ac_kw ip) {
-	return ip[0];
-       }
-int
-main ()
-{
-int s[1];
-	int * $ac_kw t = s;
-	t[0] = 0;
-	return foo(t)
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ac_cv_c_restrict=$ac_kw
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-     test "$ac_cv_c_restrict" != no && break
-   done
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_restrict" >&5
-$as_echo "$ac_cv_c_restrict" >&6; }
-
- case $ac_cv_c_restrict in
-   restrict) ;;
-   no) $as_echo "#define restrict /**/" >>confdefs.h
- ;;
-   *)  cat >>confdefs.h <<_ACEOF
-#define restrict $ac_cv_c_restrict
-_ACEOF
- ;;
- esac
-
 
 
 
@@ -11103,17 +11414,6 @@ fi
 
 
 
-ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default"
-if test "x$ac_cv_type_mode_t" = x""yes; then :
-
-else
-
-cat >>confdefs.h <<_ACEOF
-#define mode_t int
-_ACEOF
-
-fi
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5
 $as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
 if test -z "$MKDIR_P"; then
@@ -11158,17 +11458,6 @@ $as_echo "$MKDIR_P" >&6; }
 
 
 
-ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default"
-if test "x$ac_cv_type_pid_t" = x""yes; then :
-
-else
-
-cat >>confdefs.h <<_ACEOF
-#define pid_t int
-_ACEOF
-
-fi
-
 
 
 
@@ -11192,8 +11481,6 @@ fi
 
 
 
-
-
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct timespec in <time.h>" >&5
 $as_echo_n "checking for struct timespec in <time.h>... " >&6; }
 if test "${gl_cv_sys_struct_timespec_in_time_h+set}" = set; then :
@@ -11970,7 +12257,122 @@ _ACEOF
 
 
 
-$as_echo "#define GNULIB_TEST_DIRFD 1" >>confdefs.h
+$as_echo "#define GNULIB_TEST_DIRFD 1" >>confdefs.h
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether // is distinct from /" >&5
+$as_echo_n "checking whether // is distinct from /... " >&6; }
+if test "${gl_cv_double_slash_root+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+   if test x"$cross_compiling" = xyes ; then
+        # When cross-compiling, there is no way to tell whether // is special
+        # short of a list of hosts.  However, the only known hosts to date
+        # that have a distinct // are Apollo DomainOS (too old to port to),
+        # Cygwin, and z/OS.  If anyone knows of another system for which // has
+        # special semantics and is distinct from /, please report it to
+        # <bug-gnulib@gnu.org>.
+        case $host in
+          *-cygwin | i370-ibm-openedition)
+            gl_cv_double_slash_root=yes ;;
+          *)
+            # Be optimistic and assume that / and // are the same when we
+            # don't know.
+            gl_cv_double_slash_root='unknown, assuming no' ;;
+        esac
+      else
+        set x `ls -di / // 2>/dev/null`
+        if test "$2" = "$4" && wc //dev/null >/dev/null 2>&1; then
+          gl_cv_double_slash_root=no
+        else
+          gl_cv_double_slash_root=yes
+        fi
+      fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_double_slash_root" >&5
+$as_echo "$gl_cv_double_slash_root" >&6; }
+  if test "$gl_cv_double_slash_root" = yes; then
+
+$as_echo "#define DOUBLE_SLASH_IS_DISTINCT_ROOT 1" >>confdefs.h
+
+  fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+     if test $gl_cv_have_include_next = yes; then
+       gl_cv_next_fcntl_h='<'fcntl.h'>'
+     else
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking absolute name of <fcntl.h>" >&5
+$as_echo_n "checking absolute name of <fcntl.h>... " >&6; }
+if test "${gl_cv_next_fcntl_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+               cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <fcntl.h>
+
+_ACEOF
+                                                                                                                        case "$host_os" in
+                 aix*) gl_absname_cpp="$ac_cpp -C" ;;
+                 *)    gl_absname_cpp="$ac_cpp" ;;
+               esac
+
+               case "$host_os" in
+                 mingw*)
+                                                                                                                                     gl_dirsep_regex='[/\\]'
+                   ;;
+                 *)
+                   gl_dirsep_regex='\/'
+                   ;;
+               esac
+                                             gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
+
+               gl_header_literal_regex=`echo 'fcntl.h' \
+                                        | sed -e "$gl_make_literal_regex_sed"`
+               gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
+                   s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
+                   s|^/[^/]|//&|
+                   p
+                   q
+                 }'
+                                                            gl_cv_next_fcntl_h='"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&5 |
+                      sed -n "$gl_absolute_header_sed"`'"'
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_next_fcntl_h" >&5
+$as_echo "$gl_cv_next_fcntl_h" >&6; }
+     fi
+     NEXT_FCNTL_H=$gl_cv_next_fcntl_h
+
+     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
+       gl_next_as_first_directive='<'fcntl.h'>'
+     else
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
+       gl_next_as_first_directive=$gl_cv_next_fcntl_h
+     fi
+     NEXT_AS_FIRST_DIRECTIVE_FCNTL_H=$gl_next_as_first_directive
+
 
 
 
@@ -11980,43 +12382,45 @@ $as_echo "#define GNULIB_TEST_DIRFD 1" >>confdefs.h
 
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether // is distinct from /" >&5
-$as_echo_n "checking whether // is distinct from /... " >&6; }
-if test "${gl_cv_double_slash_root+set}" = set; then :
+    for gl_func in fcntl openat; do
+    as_gl_Symbol=`$as_echo "gl_cv_have_raw_decl_$gl_func" | $as_tr_sh`
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $gl_func is declared without a macro" >&5
+$as_echo_n "checking whether $gl_func is declared without a macro... " >&6; }
+if { as_var=$as_gl_Symbol; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
-   if test x"$cross_compiling" = xyes ; then
-        # When cross-compiling, there is no way to tell whether // is special
-        # short of a list of hosts.  However, the only known hosts to date
-        # that have a distinct // are Apollo DomainOS (too old to port to),
-        # Cygwin, and z/OS.  If anyone knows of another system for which // has
-        # special semantics and is distinct from /, please report it to
-        # <bug-gnulib@gnu.org>.
-        case $host in
-          *-cygwin | i370-ibm-openedition)
-            gl_cv_double_slash_root=yes ;;
-          *)
-            # Be optimistic and assume that / and // are the same when we
-            # don't know.
-            gl_cv_double_slash_root='unknown, assuming no' ;;
-        esac
-      else
-        set x `ls -di / // 2>/dev/null`
-        if test "$2" = "$4" && wc //dev/null >/dev/null 2>&1; then
-          gl_cv_double_slash_root=no
-        else
-          gl_cv_double_slash_root=yes
-        fi
-      fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_double_slash_root" >&5
-$as_echo "$gl_cv_double_slash_root" >&6; }
-  if test "$gl_cv_double_slash_root" = yes; then
-
-$as_echo "#define DOUBLE_SLASH_IS_DISTINCT_ROOT 1" >>confdefs.h
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <fcntl.h>
 
-  fi
+int
+main ()
+{
+#undef $gl_func
+  (void) $gl_func;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$as_gl_Symbol=yes"
+else
+  eval "$as_gl_Symbol=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$as_gl_Symbol
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+    eval as_val=\$$as_gl_Symbol
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_RAW_DECL_$gl_func" | $as_tr_cpp` 1
+_ACEOF
 
+                     eval ac_cv_have_decl_$gl_func=yes
+fi
+      done
 
 
 
@@ -12903,6 +13307,211 @@ $as_echo "#define GNULIB_TEST_FREXPL 1" >>confdefs.h
 
 
 
+
+  gl_gettimeofday_timezone=void
+  if test $ac_cv_func_gettimeofday != yes; then
+    HAVE_GETTIMEOFDAY=0
+  else
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether gettimeofday clobbers localtime buffer" >&5
+$as_echo_n "checking whether gettimeofday clobbers localtime buffer... " >&6; }
+if test "${gl_cv_func_gettimeofday_clobber+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  # When cross-compiling:
+      case "$host_os" in
+                # Guess all is fine on glibc systems.
+        *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
+                # If we don't know, assume the worst.
+        *)      gl_cv_func_gettimeofday_clobber="guessing yes" ;;
+      esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+          #include <sys/time.h>
+          #include <time.h>
+          #include <stdlib.h>
+
+int
+main ()
+{
+
+          time_t t = 0;
+          struct tm *lt;
+          struct tm saved_lt;
+          struct timeval tv;
+          lt = localtime (&t);
+          saved_lt = *lt;
+          gettimeofday (&tv, NULL);
+          return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_gettimeofday_clobber=no
+else
+  gl_cv_func_gettimeofday_clobber=yes
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_gettimeofday_clobber" >&5
+$as_echo "$gl_cv_func_gettimeofday_clobber" >&6; }
+
+ case "$gl_cv_func_gettimeofday_clobber" in
+   *yes)
+     REPLACE_GETTIMEOFDAY=1
+
+
+$as_echo "#define gmtime rpl_gmtime" >>confdefs.h
+
+
+$as_echo "#define localtime rpl_localtime" >>confdefs.h
+
+
+
+$as_echo "#define GETTIMEOFDAY_CLOBBERS_LOCALTIME 1" >>confdefs.h
+
+     ;;
+ esac
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gettimeofday with POSIX signature" >&5
+$as_echo_n "checking for gettimeofday with POSIX signature... " >&6; }
+if test "${gl_cv_func_gettimeofday_posix_signature+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/time.h>
+              struct timeval c;
+              int gettimeofday (struct timeval *restrict, void *restrict);
+
+int
+main ()
+{
+/* glibc uses struct timezone * rather than the POSIX void *
+                 if _GNU_SOURCE is defined.  However, since the only portable
+                 use of gettimeofday uses NULL as the second parameter, and
+                 since the glibc definition is actually more typesafe, it is
+                 not worth wrapping this to get a compliant signature.  */
+              int (*f) (struct timeval *restrict, void *restrict)
+                = gettimeofday;
+              int x = f (&c, 0);
+              return !(x | c.tv_sec | c.tv_usec);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_func_gettimeofday_posix_signature=yes
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/time.h>
+int gettimeofday (struct timeval *restrict, struct timezone *restrict);
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_func_gettimeofday_posix_signature=almost
+else
+  gl_cv_func_gettimeofday_posix_signature=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_gettimeofday_posix_signature" >&5
+$as_echo "$gl_cv_func_gettimeofday_posix_signature" >&6; }
+    if test $gl_cv_func_gettimeofday_posix_signature = almost; then
+      gl_gettimeofday_timezone='struct timezone'
+    elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
+      REPLACE_GETTIMEOFDAY=1
+    fi
+        if test $REPLACE_STRUCT_TIMEVAL = 1; then
+      REPLACE_GETTIMEOFDAY=1
+    fi
+
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define GETTIMEOFDAY_TIMEZONE $gl_gettimeofday_timezone
+_ACEOF
+
+
+  if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS gettimeofday.$ac_objext"
+
+
+  for ac_header in sys/timeb.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "sys/timeb.h" "ac_cv_header_sys_timeb_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_timeb_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SYS_TIMEB_H 1
+_ACEOF
+
+fi
+
+done
+
+  for ac_func in _ftime
+do :
+  ac_fn_c_check_func "$LINENO" "_ftime" "ac_cv_func__ftime"
+if test "x$ac_cv_func__ftime" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE__FTIME 1
+_ACEOF
+
+fi
+done
+
+
+  fi
+
+
+
+
+
+          GNULIB_GETTIMEOFDAY=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_GETTIMEOFDAY 1" >>confdefs.h
+
+
+
+
+
+
+
+
   PRIPTR_PREFIX=
   if test -n "$STDINT_H"; then
         PRIPTR_PREFIX='"l"'
@@ -15277,6 +15886,52 @@ $as_echo "#define GNULIB_TEST_MEMMEM 1" >>confdefs.h
 
 
 
+  for ac_func in mkdtemp
+do :
+  ac_fn_c_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp"
+if test "x$ac_cv_func_mkdtemp" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_MKDTEMP 1
+_ACEOF
+
+fi
+done
+
+  if test $ac_cv_func_mkdtemp = no; then
+    HAVE_MKDTEMP=0
+  fi
+
+  if test $HAVE_MKDTEMP = 0; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS mkdtemp.$ac_objext"
+
+    :
+
+  fi
+
+
+
+
+
+          GNULIB_MKDTEMP=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_MKDTEMP 1" >>confdefs.h
+
+
+
+
+
 
 
 
@@ -16751,6 +17406,10 @@ fi
 
 
 
+
+
+
+
      if test $gl_cv_have_include_next = yes; then
        gl_cv_next_sys_types_h='<'sys/types.h'>'
      else
@@ -16820,6 +17479,11 @@ $as_echo "$gl_cv_next_sys_types_h" >&6; }
 
 
 
+  :
+
+
+
+
 
 
 
diff --git a/gdb/gnulib/import/Makefile.am b/gdb/gnulib/import/Makefile.am
index f1f14ef..06d6ff4 100644
--- a/gdb/gnulib/import/Makefile.am
+++ b/gdb/gnulib/import/Makefile.am
@@ -21,7 +21,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes lstat memchr memmem pathmax readlink rename strstr sys_stat unistd update-copyright wchar wctype-h
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes lstat memchr memmem mkdtemp pathmax readlink rename strstr sys_stat unistd update-copyright wchar wctype-h
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -242,6 +242,41 @@ EXTRA_DIST += errno.in.h
 
 ## end   gnulib module errno
 
+## begin gnulib module fcntl-h
+
+BUILT_SOURCES += fcntl.h
+
+# We need the following in order to create <fcntl.h> when the system
+# doesn't have one that works with the given compiler.
+fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
+	      -e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \
+	      -e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \
+	      -e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \
+	      -e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \
+	      -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
+	      -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
+	      -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
+	      -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
+	      -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/fcntl.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += fcntl.h fcntl.h-t
+
+EXTRA_DIST += fcntl.in.h
+
+## end   gnulib module fcntl-h
+
 ## begin gnulib module float
 
 BUILT_SOURCES += $(FLOAT_H)
@@ -324,6 +359,15 @@ EXTRA_libgnu_a_SOURCES += frexp.c frexpl.c
 
 ## end   gnulib module frexpl
 
+## begin gnulib module gettimeofday
+
+
+EXTRA_DIST += gettimeofday.c
+
+EXTRA_libgnu_a_SOURCES += gettimeofday.c
+
+## end   gnulib module gettimeofday
+
 ## begin gnulib module inttypes-incomplete
 
 BUILT_SOURCES += inttypes.h
@@ -815,6 +859,15 @@ EXTRA_libgnu_a_SOURCES += memmem.c
 
 ## end   gnulib module memmem-simple
 
+## begin gnulib module mkdtemp
+
+
+EXTRA_DIST += mkdtemp.c
+
+EXTRA_libgnu_a_SOURCES += mkdtemp.c
+
+## end   gnulib module mkdtemp
+
 ## begin gnulib module pathmax
 
 
@@ -1463,6 +1516,40 @@ EXTRA_DIST += sys_stat.in.h
 
 ## end   gnulib module sys_stat
 
+## begin gnulib module sys_time
+
+BUILT_SOURCES += sys/time.h
+
+# We need the following in order to create <sys/time.h> when the system
+# doesn't have one that works with the given compiler.
+sys/time.h: sys_time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \
+	      -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
+	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
+	      -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \
+	      -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \
+	      -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \
+	      -e 's/@''REPLACE_STRUCT_TIMEVAL''@/$(REPLACE_STRUCT_TIMEVAL)/g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_time.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += sys/time.h sys/time.h-t
+
+EXTRA_DIST += sys_time.in.h
+
+## end   gnulib module sys_time
+
 ## begin gnulib module sys_types
 
 BUILT_SOURCES += sys/types.h
@@ -1488,6 +1575,14 @@ EXTRA_DIST += sys_types.in.h
 
 ## end   gnulib module sys_types
 
+## begin gnulib module tempname
+
+libgnu_a_SOURCES += tempname.c
+
+EXTRA_DIST += tempname.h
+
+## end   gnulib module tempname
+
 ## begin gnulib module time
 
 BUILT_SOURCES += time.h
diff --git a/gdb/gnulib/import/Makefile.in b/gdb/gnulib/import/Makefile.in
index 3dfd74e..effb1c2 100644
--- a/gdb/gnulib/import/Makefile.in
+++ b/gdb/gnulib/import/Makefile.in
@@ -36,7 +36,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes lstat memchr memmem pathmax readlink rename strstr sys_stat unistd update-copyright wchar wctype-h
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes lstat memchr memmem mkdtemp pathmax readlink rename strstr sys_stat unistd update-copyright wchar wctype-h
 
 
 
@@ -79,11 +79,13 @@ am__aclocal_m4_deps = $(top_srcdir)/import/m4/00gnulib.m4 \
 	$(top_srcdir)/import/m4/extensions.m4 \
 	$(top_srcdir)/import/m4/extern-inline.m4 \
 	$(top_srcdir)/import/m4/fcntl-o.m4 \
+	$(top_srcdir)/import/m4/fcntl_h.m4 \
 	$(top_srcdir)/import/m4/float_h.m4 \
 	$(top_srcdir)/import/m4/fnmatch.m4 \
 	$(top_srcdir)/import/m4/fpieee.m4 \
 	$(top_srcdir)/import/m4/frexp.m4 \
 	$(top_srcdir)/import/m4/frexpl.m4 \
+	$(top_srcdir)/import/m4/gettimeofday.m4 \
 	$(top_srcdir)/import/m4/glibc21.m4 \
 	$(top_srcdir)/import/m4/gnulib-common.m4 \
 	$(top_srcdir)/import/m4/gnulib-comp.m4 \
@@ -108,6 +110,7 @@ am__aclocal_m4_deps = $(top_srcdir)/import/m4/00gnulib.m4 \
 	$(top_srcdir)/import/m4/mbstate_t.m4 \
 	$(top_srcdir)/import/m4/memchr.m4 \
 	$(top_srcdir)/import/m4/memmem.m4 \
+	$(top_srcdir)/import/m4/mkdtemp.m4 \
 	$(top_srcdir)/import/m4/mmap-anon.m4 \
 	$(top_srcdir)/import/m4/multiarch.m4 \
 	$(top_srcdir)/import/m4/nocrash.m4 \
@@ -125,8 +128,11 @@ am__aclocal_m4_deps = $(top_srcdir)/import/m4/00gnulib.m4 \
 	$(top_srcdir)/import/m4/stdlib_h.m4 \
 	$(top_srcdir)/import/m4/string_h.m4 \
 	$(top_srcdir)/import/m4/strstr.m4 \
+	$(top_srcdir)/import/m4/sys_socket_h.m4 \
 	$(top_srcdir)/import/m4/sys_stat_h.m4 \
+	$(top_srcdir)/import/m4/sys_time_h.m4 \
 	$(top_srcdir)/import/m4/sys_types_h.m4 \
+	$(top_srcdir)/import/m4/tempname.m4 \
 	$(top_srcdir)/import/m4/time_h.m4 \
 	$(top_srcdir)/import/m4/unistd_h.m4 \
 	$(top_srcdir)/import/m4/warn-on-use.m4 \
@@ -146,7 +152,7 @@ am__DEPENDENCIES_1 =
 am_libgnu_a_OBJECTS = dirname-lgpl.$(OBJEXT) basename-lgpl.$(OBJEXT) \
 	stripslash.$(OBJEXT) localcharset.$(OBJEXT) malloca.$(OBJEXT) \
 	math.$(OBJEXT) stdio.$(OBJEXT) strnlen1.$(OBJEXT) \
-	unistd.$(OBJEXT) wctype-h.$(OBJEXT)
+	tempname.$(OBJEXT) unistd.$(OBJEXT) wctype-h.$(OBJEXT)
 libgnu_a_OBJECTS = $(am_libgnu_a_OBJECTS)
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -293,6 +299,7 @@ GNULIB_FCHDIR = @GNULIB_FCHDIR@
 GNULIB_FCHMODAT = @GNULIB_FCHMODAT@
 GNULIB_FCHOWNAT = @GNULIB_FCHOWNAT@
 GNULIB_FCLOSE = @GNULIB_FCLOSE@
+GNULIB_FCNTL = @GNULIB_FCNTL@
 GNULIB_FDATASYNC = @GNULIB_FDATASYNC@
 GNULIB_FDOPEN = @GNULIB_FDOPEN@
 GNULIB_FDOPENDIR = @GNULIB_FDOPENDIR@
@@ -346,6 +353,7 @@ GNULIB_GETLOGIN = @GNULIB_GETLOGIN@
 GNULIB_GETLOGIN_R = @GNULIB_GETLOGIN_R@
 GNULIB_GETPAGESIZE = @GNULIB_GETPAGESIZE@
 GNULIB_GETSUBOPT = @GNULIB_GETSUBOPT@
+GNULIB_GETTIMEOFDAY = @GNULIB_GETTIMEOFDAY@
 GNULIB_GETUSERSHELL = @GNULIB_GETUSERSHELL@
 GNULIB_GRANTPT = @GNULIB_GRANTPT@
 GNULIB_GROUP_MEMBER = @GNULIB_GROUP_MEMBER@
@@ -429,8 +437,11 @@ GNULIB_MODF = @GNULIB_MODF@
 GNULIB_MODFF = @GNULIB_MODFF@
 GNULIB_MODFL = @GNULIB_MODFL@
 GNULIB_NANOSLEEP = @GNULIB_NANOSLEEP@
+GNULIB_NONBLOCKING = @GNULIB_NONBLOCKING@
 GNULIB_OBSTACK_PRINTF = @GNULIB_OBSTACK_PRINTF@
 GNULIB_OBSTACK_PRINTF_POSIX = @GNULIB_OBSTACK_PRINTF_POSIX@
+GNULIB_OPEN = @GNULIB_OPEN@
+GNULIB_OPENAT = @GNULIB_OPENAT@
 GNULIB_OPENDIR = @GNULIB_OPENDIR@
 GNULIB_PCLOSE = @GNULIB_PCLOSE@
 GNULIB_PERROR = @GNULIB_PERROR@
@@ -691,6 +702,7 @@ HAVE_FACCESSAT = @HAVE_FACCESSAT@
 HAVE_FCHDIR = @HAVE_FCHDIR@
 HAVE_FCHMODAT = @HAVE_FCHMODAT@
 HAVE_FCHOWNAT = @HAVE_FCHOWNAT@
+HAVE_FCNTL = @HAVE_FCNTL@
 HAVE_FDATASYNC = @HAVE_FDATASYNC@
 HAVE_FDOPENDIR = @HAVE_FDOPENDIR@
 HAVE_FEATURES_H = @HAVE_FEATURES_H@
@@ -714,6 +726,7 @@ HAVE_GETHOSTNAME = @HAVE_GETHOSTNAME@
 HAVE_GETLOGIN = @HAVE_GETLOGIN@
 HAVE_GETPAGESIZE = @HAVE_GETPAGESIZE@
 HAVE_GETSUBOPT = @HAVE_GETSUBOPT@
+HAVE_GETTIMEOFDAY = @HAVE_GETTIMEOFDAY@
 HAVE_GRANTPT = @HAVE_GRANTPT@
 HAVE_GROUP_MEMBER = @HAVE_GROUP_MEMBER@
 HAVE_HYPOTF = @HAVE_HYPOTF@
@@ -764,6 +777,7 @@ HAVE_MKSTEMPS = @HAVE_MKSTEMPS@
 HAVE_MODFF = @HAVE_MODFF@
 HAVE_MODFL = @HAVE_MODFL@
 HAVE_NANOSLEEP = @HAVE_NANOSLEEP@
+HAVE_OPENAT = @HAVE_OPENAT@
 HAVE_OPENDIR = @HAVE_OPENDIR@
 HAVE_OS_H = @HAVE_OS_H@
 HAVE_PCLOSE = @HAVE_PCLOSE@
@@ -816,6 +830,7 @@ HAVE_STRTOD = @HAVE_STRTOD@
 HAVE_STRTOLL = @HAVE_STRTOLL@
 HAVE_STRTOULL = @HAVE_STRTOULL@
 HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@
+HAVE_STRUCT_TIMEVAL = @HAVE_STRUCT_TIMEVAL@
 HAVE_STRVERSCMP = @HAVE_STRVERSCMP@
 HAVE_SYMLINK = @HAVE_SYMLINK@
 HAVE_SYMLINKAT = @HAVE_SYMLINKAT@
@@ -823,6 +838,7 @@ HAVE_SYS_BITYPES_H = @HAVE_SYS_BITYPES_H@
 HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@
 HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
 HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
+HAVE_SYS_TIME_H = @HAVE_SYS_TIME_H@
 HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@
 HAVE_TANF = @HAVE_TANF@
 HAVE_TANHF = @HAVE_TANHF@
@@ -867,6 +883,7 @@ HAVE_WCSXFRM = @HAVE_WCSXFRM@
 HAVE_WCTRANS_T = @HAVE_WCTRANS_T@
 HAVE_WCTYPE_H = @HAVE_WCTYPE_H@
 HAVE_WCTYPE_T = @HAVE_WCTYPE_T@
+HAVE_WINSOCK2_H = @HAVE_WINSOCK2_H@
 HAVE_WINT_T = @HAVE_WINT_T@
 HAVE_WMEMCHR = @HAVE_WMEMCHR@
 HAVE_WMEMCMP = @HAVE_WMEMCMP@
@@ -901,6 +918,7 @@ MAKEINFO = @MAKEINFO@
 MKDIR_P = @MKDIR_P@
 NEXT_AS_FIRST_DIRECTIVE_DIRENT_H = @NEXT_AS_FIRST_DIRECTIVE_DIRENT_H@
 NEXT_AS_FIRST_DIRECTIVE_ERRNO_H = @NEXT_AS_FIRST_DIRECTIVE_ERRNO_H@
+NEXT_AS_FIRST_DIRECTIVE_FCNTL_H = @NEXT_AS_FIRST_DIRECTIVE_FCNTL_H@
 NEXT_AS_FIRST_DIRECTIVE_FLOAT_H = @NEXT_AS_FIRST_DIRECTIVE_FLOAT_H@
 NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H = @NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H@
 NEXT_AS_FIRST_DIRECTIVE_MATH_H = @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
@@ -910,6 +928,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@
 NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
 NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H@
+NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_TYPES_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_TYPES_H@
 NEXT_AS_FIRST_DIRECTIVE_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_TIME_H@
 NEXT_AS_FIRST_DIRECTIVE_UNISTD_H = @NEXT_AS_FIRST_DIRECTIVE_UNISTD_H@
@@ -917,6 +936,7 @@ NEXT_AS_FIRST_DIRECTIVE_WCHAR_H = @NEXT_AS_FIRST_DIRECTIVE_WCHAR_H@
 NEXT_AS_FIRST_DIRECTIVE_WCTYPE_H = @NEXT_AS_FIRST_DIRECTIVE_WCTYPE_H@
 NEXT_DIRENT_H = @NEXT_DIRENT_H@
 NEXT_ERRNO_H = @NEXT_ERRNO_H@
+NEXT_FCNTL_H = @NEXT_FCNTL_H@
 NEXT_FLOAT_H = @NEXT_FLOAT_H@
 NEXT_INTTYPES_H = @NEXT_INTTYPES_H@
 NEXT_MATH_H = @NEXT_MATH_H@
@@ -926,6 +946,7 @@ NEXT_STDIO_H = @NEXT_STDIO_H@
 NEXT_STDLIB_H = @NEXT_STDLIB_H@
 NEXT_STRING_H = @NEXT_STRING_H@
 NEXT_SYS_STAT_H = @NEXT_SYS_STAT_H@
+NEXT_SYS_TIME_H = @NEXT_SYS_TIME_H@
 NEXT_SYS_TYPES_H = @NEXT_SYS_TYPES_H@
 NEXT_TIME_H = @NEXT_TIME_H@
 NEXT_UNISTD_H = @NEXT_UNISTD_H@
@@ -969,6 +990,7 @@ REPLACE_EXPM1F = @REPLACE_EXPM1F@
 REPLACE_FABSL = @REPLACE_FABSL@
 REPLACE_FCHOWNAT = @REPLACE_FCHOWNAT@
 REPLACE_FCLOSE = @REPLACE_FCLOSE@
+REPLACE_FCNTL = @REPLACE_FCNTL@
 REPLACE_FDOPEN = @REPLACE_FDOPEN@
 REPLACE_FDOPENDIR = @REPLACE_FDOPENDIR@
 REPLACE_FFLUSH = @REPLACE_FFLUSH@
@@ -1003,6 +1025,7 @@ REPLACE_GETGROUPS = @REPLACE_GETGROUPS@
 REPLACE_GETLINE = @REPLACE_GETLINE@
 REPLACE_GETLOGIN_R = @REPLACE_GETLOGIN_R@
 REPLACE_GETPAGESIZE = @REPLACE_GETPAGESIZE@
+REPLACE_GETTIMEOFDAY = @REPLACE_GETTIMEOFDAY@
 REPLACE_HUGE_VAL = @REPLACE_HUGE_VAL@
 REPLACE_HYPOT = @REPLACE_HYPOT@
 REPLACE_HYPOTF = @REPLACE_HYPOTF@
@@ -1060,6 +1083,8 @@ REPLACE_NAN = @REPLACE_NAN@
 REPLACE_NANOSLEEP = @REPLACE_NANOSLEEP@
 REPLACE_NULL = @REPLACE_NULL@
 REPLACE_OBSTACK_PRINTF = @REPLACE_OBSTACK_PRINTF@
+REPLACE_OPEN = @REPLACE_OPEN@
+REPLACE_OPENAT = @REPLACE_OPENAT@
 REPLACE_OPENDIR = @REPLACE_OPENDIR@
 REPLACE_PERROR = @REPLACE_PERROR@
 REPLACE_POPEN = @REPLACE_POPEN@
@@ -1108,6 +1133,7 @@ REPLACE_STRSTR = @REPLACE_STRSTR@
 REPLACE_STRTOD = @REPLACE_STRTOD@
 REPLACE_STRTOIMAX = @REPLACE_STRTOIMAX@
 REPLACE_STRTOK_R = @REPLACE_STRTOK_R@
+REPLACE_STRUCT_TIMEVAL = @REPLACE_STRUCT_TIMEVAL@
 REPLACE_SYMLINK = @REPLACE_SYMLINK@
 REPLACE_TIMEGM = @REPLACE_TIMEGM@
 REPLACE_TMPFILE = @REPLACE_TMPFILE@
@@ -1222,21 +1248,22 @@ noinst_LIBRARIES = libgnu.a
 noinst_LTLIBRARIES = 
 EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h \
 	canonicalize-lgpl.c dirent.in.h dirfd.c dirname.h dosname.h \
-	errno.in.h float.c float.in.h itold.c fnmatch.c fnmatch.in.h \
-	fnmatch_loop.c fpucw.h frexp.c frexp.c frexpl.c inttypes.in.h \
-	float+.h isnan.c isnand-nolibm.h isnand.c float+.h isnan.c \
-	isnanl-nolibm.h isnanl.c config.charset ref-add.sin \
-	ref-del.sin lstat.c malloc.c malloca.h malloca.valgrind \
-	math.in.h mbrtowc.c mbsinit.c mbsrtowcs-impl.h \
-	mbsrtowcs-state.c mbsrtowcs.c memchr.c memchr.valgrind \
-	memmem.c str-two-way.h pathmax.h readlink.c rename.c rmdir.c \
-	same-inode.h $(top_srcdir)/import/extra/snippet/_Noreturn.h \
+	errno.in.h fcntl.in.h float.c float.in.h itold.c fnmatch.c \
+	fnmatch.in.h fnmatch_loop.c fpucw.h frexp.c frexp.c frexpl.c \
+	gettimeofday.c inttypes.in.h float+.h isnan.c isnand-nolibm.h \
+	isnand.c float+.h isnan.c isnanl-nolibm.h isnanl.c \
+	config.charset ref-add.sin ref-del.sin lstat.c malloc.c \
+	malloca.h malloca.valgrind math.in.h mbrtowc.c mbsinit.c \
+	mbsrtowcs-impl.h mbsrtowcs-state.c mbsrtowcs.c memchr.c \
+	memchr.valgrind memmem.c str-two-way.h mkdtemp.c pathmax.h \
+	readlink.c rename.c rmdir.c same-inode.h \
+	$(top_srcdir)/import/extra/snippet/_Noreturn.h \
 	$(top_srcdir)/import/extra/snippet/arg-nonnull.h \
 	$(top_srcdir)/import/extra/snippet/c++defs.h \
 	$(top_srcdir)/import/extra/snippet/warn-on-use.h stat.c \
 	stdbool.in.h stddef.in.h stdint.in.h stdio.in.h stdlib.in.h \
 	streq.h string.in.h str-two-way.h strstr.c sys_stat.in.h \
-	sys_types.in.h time.in.h unistd.in.h \
+	sys_time.in.h sys_types.in.h tempname.h time.in.h unistd.in.h \
 	$(top_srcdir)/import/extra/update-copyright verify.h \
 	wchar.in.h wctype.in.h
 
@@ -1249,21 +1276,22 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h \
 # statements but through direct file reference. Therefore this snippet must be
 # present in all Makefile.am that need it. This is ensured by the applicability
 # 'all' defined above.
-BUILT_SOURCES = $(ALLOCA_H) configmake.h dirent.h $(ERRNO_H) \
+BUILT_SOURCES = $(ALLOCA_H) configmake.h dirent.h $(ERRNO_H) fcntl.h \
 	$(FLOAT_H) $(FNMATCH_H) inttypes.h math.h arg-nonnull.h \
 	c++defs.h warn-on-use.h $(STDBOOL_H) $(STDDEF_H) $(STDINT_H) \
-	stdio.h stdlib.h string.h sys/stat.h sys/types.h time.h \
-	unistd.h wchar.h wctype.h
+	stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h \
+	time.h unistd.h wchar.h wctype.h
 SUFFIXES = .sed .sin
 MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t dirent.h \
-	dirent.h-t errno.h errno.h-t float.h float.h-t fnmatch.h \
-	fnmatch.h-t inttypes.h inttypes.h-t math.h math.h-t \
-	arg-nonnull.h arg-nonnull.h-t c++defs.h c++defs.h-t \
+	dirent.h-t errno.h errno.h-t fcntl.h fcntl.h-t float.h \
+	float.h-t fnmatch.h fnmatch.h-t inttypes.h inttypes.h-t math.h \
+	math.h-t arg-nonnull.h arg-nonnull.h-t c++defs.h c++defs.h-t \
 	warn-on-use.h warn-on-use.h-t stdbool.h stdbool.h-t stddef.h \
 	stddef.h-t stdint.h stdint.h-t stdio.h stdio.h-t stdlib.h \
 	stdlib.h-t string.h string.h-t sys/stat.h sys/stat.h-t \
-	sys/types.h sys/types.h-t time.h time.h-t unistd.h unistd.h-t \
-	wchar.h wchar.h-t wctype.h wctype.h-t
+	sys/time.h sys/time.h-t sys/types.h sys/types.h-t time.h \
+	time.h-t unistd.h unistd.h-t wchar.h wchar.h-t wctype.h \
+	wctype.h-t
 MOSTLYCLEANDIRS = sys
 CLEANFILES = configmake.h configmake.h-t charset.alias ref-add.sed \
 	ref-del.sed
@@ -1273,14 +1301,15 @@ AM_CPPFLAGS =
 AM_CFLAGS = 
 libgnu_a_SOURCES = dirname-lgpl.c basename-lgpl.c stripslash.c \
 	localcharset.h localcharset.c malloca.c math.c stdio.c \
-	strnlen1.h strnlen1.c unistd.c wctype-h.c
+	strnlen1.h strnlen1.c tempname.c unistd.c wctype-h.c
 libgnu_a_LIBADD = $(gl_LIBOBJS) @ALLOCA@
 libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) @ALLOCA@
 EXTRA_libgnu_a_SOURCES = alloca.c canonicalize-lgpl.c dirfd.c float.c \
 	itold.c fnmatch.c fnmatch_loop.c frexp.c frexp.c frexpl.c \
-	isnan.c isnand.c isnan.c isnanl.c lstat.c malloc.c mbrtowc.c \
-	mbsinit.c mbsrtowcs-state.c mbsrtowcs.c memchr.c memmem.c \
-	readlink.c rename.c rmdir.c stat.c strstr.c
+	gettimeofday.c isnan.c isnand.c isnan.c isnanl.c lstat.c \
+	malloc.c mbrtowc.c mbsinit.c mbsrtowcs-state.c mbsrtowcs.c \
+	memchr.c memmem.c mkdtemp.c readlink.c rename.c rmdir.c stat.c \
+	strstr.c
 charset_alias = $(DESTDIR)$(libdir)/charset.alias
 charset_tmp = $(DESTDIR)$(libdir)/charset.tmp
 
@@ -1360,6 +1389,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fnmatch_loop.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frexp.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frexpl.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gettimeofday.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnan.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnand.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnanl.Po@am__quote@
@@ -1375,6 +1405,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbsrtowcs.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memchr.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memmem.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkdtemp.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readlink.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rename.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rmdir.Po@am__quote@
@@ -1383,6 +1414,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stripslash.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strnlen1.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strstr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tempname.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unistd.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wctype-h.Po@am__quote@
 
@@ -1830,6 +1862,32 @@ dirent.h: dirent.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
 @GL_GENERATE_ERRNO_H_FALSE@errno.h: $(top_builddir)/config.status
 @GL_GENERATE_ERRNO_H_FALSE@	rm -f $@
 
+# We need the following in order to create <fcntl.h> when the system
+# doesn't have one that works with the given compiler.
+fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
+	      -e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \
+	      -e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \
+	      -e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \
+	      -e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \
+	      -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
+	      -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
+	      -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
+	      -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
+	      -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/fcntl.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+
 # We need the following in order to create <float.h> when the system
 # doesn't have one that works with the given compiler.
 @GL_GENERATE_FLOAT_H_TRUE@float.h: float.in.h $(top_builddir)/config.status
@@ -2674,6 +2732,31 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNU
 	} > $@-t && \
 	mv $@-t $@
 
+# We need the following in order to create <sys/time.h> when the system
+# doesn't have one that works with the given compiler.
+sys/time.h: sys_time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \
+	      -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
+	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
+	      -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \
+	      -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \
+	      -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \
+	      -e 's/@''REPLACE_STRUCT_TIMEVAL''@/$(REPLACE_STRUCT_TIMEVAL)/g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_time.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+
 # We need the following in order to create <sys/types.h> when the system
 # doesn't have one that works with the given compiler.
 sys/types.h: sys_types.in.h $(top_builddir)/config.status
diff --git a/gdb/gnulib/import/fcntl.in.h b/gdb/gnulib/import/fcntl.in.h
new file mode 100644
index 0000000..604c31b
--- /dev/null
+++ b/gdb/gnulib/import/fcntl.in.h
@@ -0,0 +1,347 @@
+/* Like <fcntl.h>, but with non-working flags defined to 0.
+
+   Copyright (C) 2006-2012 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* written by Paul Eggert */
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+#if defined __need_system_fcntl_h
+/* Special invocation convention.  */
+
+/* Needed before <sys/stat.h>.
+   May also define off_t to a 64-bit type on native Windows.  */
+#include <sys/types.h>
+/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
+   <fcntl.h>.  On glibc systems, we would like to avoid namespace pollution.
+   But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
+   extern "C" { ... } block, which leads to errors in C++ mode with the
+   overridden <sys/stat.h> from gnulib.  These errors are known to be gone
+   with g++ version >= 4.3.  */
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+# include <sys/stat.h>
+#endif
+#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef _@GUARD_PREFIX@_FCNTL_H
+
+/* Needed before <sys/stat.h>.
+   May also define off_t to a 64-bit type on native Windows.  */
+#include <sys/types.h>
+/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
+   <fcntl.h>.  On glibc systems, we would like to avoid namespace pollution.
+   But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
+   extern "C" { ... } block, which leads to errors in C++ mode with the
+   overridden <sys/stat.h> from gnulib.  These errors are known to be gone
+   with g++ version >= 4.3.  */
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+# include <sys/stat.h>
+#endif
+/* The include_next requires a split double-inclusion guard.  */
+#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
+
+#ifndef _@GUARD_PREFIX@_FCNTL_H
+#define _@GUARD_PREFIX@_FCNTL_H
+
+#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems.  */
+# include <unistd.h>
+#endif
+
+/* Native Windows platforms declare open(), creat() in <io.h>.  */
+#if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
+    && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+# include <io.h>
+#endif
+
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Declare overridden functions.  */
+
+#if @GNULIB_FCNTL@
+# if @REPLACE_FCNTL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fcntl
+#   define fcntl rpl_fcntl
+#  endif
+_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
+_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
+# else
+#  if !@HAVE_FCNTL@
+_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
+#  endif
+_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
+# endif
+_GL_CXXALIASWARN (fcntl);
+#elif defined GNULIB_POSIXCHECK
+# undef fcntl
+# if HAVE_RAW_DECL_FCNTL
+_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
+                 "use gnulib module fcntl for portability");
+# endif
+#endif
+
+#if @GNULIB_OPEN@
+# if @REPLACE_OPEN@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef open
+#   define open rpl_open
+#  endif
+_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+                             _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+# else
+_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+# endif
+/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
+   default argument.  _GL_CXXALIASWARN does not work in this case.  */
+# if !defined __hpux
+_GL_CXXALIASWARN (open);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef open
+/* Assume open is always declared.  */
+_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
+                 "use gnulib module open for portability");
+#endif
+
+#if @GNULIB_OPENAT@
+# if @REPLACE_OPENAT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef openat
+#   define openat rpl_openat
+#  endif
+_GL_FUNCDECL_RPL (openat, int,
+                  (int fd, char const *file, int flags, /* mode_t mode */ ...)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (openat, int,
+                  (int fd, char const *file, int flags, /* mode_t mode */ ...));
+# else
+#  if !@HAVE_OPENAT@
+_GL_FUNCDECL_SYS (openat, int,
+                  (int fd, char const *file, int flags, /* mode_t mode */ ...)
+                  _GL_ARG_NONNULL ((2)));
+#  endif
+_GL_CXXALIAS_SYS (openat, int,
+                  (int fd, char const *file, int flags, /* mode_t mode */ ...));
+# endif
+_GL_CXXALIASWARN (openat);
+#elif defined GNULIB_POSIXCHECK
+# undef openat
+# if HAVE_RAW_DECL_OPENAT
+_GL_WARN_ON_USE (openat, "openat is not portable - "
+                 "use gnulib module openat for portability");
+# endif
+#endif
+
+
+/* Fix up the FD_* macros, only known to be missing on mingw.  */
+
+#ifndef FD_CLOEXEC
+# define FD_CLOEXEC 1
+#endif
+
+/* Fix up the supported F_* macros.  Intentionally leave other F_*
+   macros undefined.  Only known to be missing on mingw.  */
+
+#ifndef F_DUPFD_CLOEXEC
+# define F_DUPFD_CLOEXEC 0x40000000
+/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise.  */
+# define GNULIB_defined_F_DUPFD_CLOEXEC 1
+#else
+# define GNULIB_defined_F_DUPFD_CLOEXEC 0
+#endif
+
+#ifndef F_DUPFD
+# define F_DUPFD 1
+#endif
+
+#ifndef F_GETFD
+# define F_GETFD 2
+#endif
+
+/* Fix up the O_* macros.  */
+
+#if !defined O_DIRECT && defined O_DIRECTIO
+/* Tru64 spells it 'O_DIRECTIO'.  */
+# define O_DIRECT O_DIRECTIO
+#endif
+
+#if !defined O_CLOEXEC && defined O_NOINHERIT
+/* Mingw spells it 'O_NOINHERIT'.  */
+# define O_CLOEXEC O_NOINHERIT
+#endif
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
+#ifndef O_DIRECT
+# define O_DIRECT 0
+#endif
+
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
+#ifndef O_DSYNC
+# define O_DSYNC 0
+#endif
+
+#ifndef O_EXEC
+# define O_EXEC O_RDONLY /* This is often close enough in older systems.  */
+#endif
+
+#ifndef O_IGNORE_CTTY
+# define O_IGNORE_CTTY 0
+#endif
+
+#ifndef O_NDELAY
+# define O_NDELAY 0
+#endif
+
+#ifndef O_NOATIME
+# define O_NOATIME 0
+#endif
+
+#ifndef O_NONBLOCK
+# define O_NONBLOCK O_NDELAY
+#endif
+
+/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
+   value of O_NONBLOCK.  Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
+   or to 0 as fallback.  */
+#if @GNULIB_NONBLOCKING@
+# if O_NONBLOCK
+#  define GNULIB_defined_O_NONBLOCK 0
+# else
+#  define GNULIB_defined_O_NONBLOCK 1
+#  undef O_NONBLOCK
+#  define O_NONBLOCK 0x40000000
+# endif
+#endif
+
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
+#ifndef O_NOLINK
+# define O_NOLINK 0
+#endif
+
+#ifndef O_NOLINKS
+# define O_NOLINKS 0
+#endif
+
+#ifndef O_NOTRANS
+# define O_NOTRANS 0
+#endif
+
+#ifndef O_RSYNC
+# define O_RSYNC 0
+#endif
+
+#ifndef O_SEARCH
+# define O_SEARCH O_RDONLY /* This is often close enough in older systems.  */
+#endif
+
+#ifndef O_SYNC
+# define O_SYNC 0
+#endif
+
+#ifndef O_TTY_INIT
+# define O_TTY_INIT 0
+#endif
+
+#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+# undef O_ACCMODE
+# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+#endif
+
+/* For systems that distinguish between text and binary I/O.
+   O_BINARY is usually declared in fcntl.h  */
+#if !defined O_BINARY && defined _O_BINARY
+  /* For MSC-compatible compilers.  */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+
+#if defined __BEOS__ || defined __HAIKU__
+  /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect.  */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+# define O_TEXT 0
+#endif
+
+/* Fix up the AT_* macros.  */
+
+/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive.  Its
+   value exceeds INT_MAX, so its use as an int doesn't conform to the
+   C standard, and GCC and Sun C complain in some cases.  If the bug
+   is present, undef AT_FDCWD here, so it can be redefined below.  */
+#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
+# undef AT_FDCWD
+#endif
+
+/* Use the same bit pattern as Solaris 9, but with the proper
+   signedness.  The bit pattern is important, in case this actually is
+   Solaris with the above workaround.  */
+#ifndef AT_FDCWD
+# define AT_FDCWD (-3041965)
+#endif
+
+/* Use the same values as Solaris 9.  This shouldn't matter, but
+   there's no real reason to differ.  */
+#ifndef AT_SYMLINK_NOFOLLOW
+# define AT_SYMLINK_NOFOLLOW 4096
+#endif
+
+#ifndef AT_REMOVEDIR
+# define AT_REMOVEDIR 1
+#endif
+
+/* Solaris 9 lacks these two, so just pick unique values.  */
+#ifndef AT_SYMLINK_FOLLOW
+# define AT_SYMLINK_FOLLOW 2
+#endif
+
+#ifndef AT_EACCESS
+# define AT_EACCESS 4
+#endif
+
+
+#endif /* _@GUARD_PREFIX@_FCNTL_H */
+#endif /* _@GUARD_PREFIX@_FCNTL_H */
+#endif
diff --git a/gdb/gnulib/import/gettimeofday.c b/gdb/gnulib/import/gettimeofday.c
new file mode 100644
index 0000000..5d35060
--- /dev/null
+++ b/gdb/gnulib/import/gettimeofday.c
@@ -0,0 +1,154 @@
+/* Provide gettimeofday for systems that don't have it or for which it's broken.
+
+   Copyright (C) 2001-2003, 2005-2007, 2009-2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+/* written by Jim Meyering */
+
+#include <config.h>
+
+/* Specification.  */
+#include <sys/time.h>
+
+#include <time.h>
+
+#if HAVE_SYS_TIMEB_H
+# include <sys/timeb.h>
+#endif
+
+#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
+
+/* Work around the bug in some systems whereby gettimeofday clobbers
+   the static buffer that localtime uses for its return value.  The
+   gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
+   this problem.  The tzset replacement is necessary for at least
+   Solaris 2.5, 2.5.1, and 2.6.  */
+
+static struct tm tm_zero_buffer;
+static struct tm *localtime_buffer_addr = &tm_zero_buffer;
+
+# undef localtime
+extern struct tm *localtime (time_t const *);
+
+# undef gmtime
+extern struct tm *gmtime (time_t const *);
+
+/* This is a wrapper for localtime.  It is used only on systems for which
+   gettimeofday clobbers the static buffer used for localtime's result.
+
+   On the first call, record the address of the static buffer that
+   localtime uses for its result.  */
+
+struct tm *
+rpl_localtime (time_t const *timep)
+{
+  struct tm *tm = localtime (timep);
+
+  if (localtime_buffer_addr == &tm_zero_buffer)
+    localtime_buffer_addr = tm;
+
+  return tm;
+}
+
+/* Same as above, since gmtime and localtime use the same buffer.  */
+struct tm *
+rpl_gmtime (time_t const *timep)
+{
+  struct tm *tm = gmtime (timep);
+
+  if (localtime_buffer_addr == &tm_zero_buffer)
+    localtime_buffer_addr = tm;
+
+  return tm;
+}
+
+#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
+
+#if TZSET_CLOBBERS_LOCALTIME
+
+# undef tzset
+extern void tzset (void);
+
+/* This is a wrapper for tzset, for systems on which tzset may clobber
+   the static buffer used for localtime's result.  */
+void
+rpl_tzset (void)
+{
+  /* Save and restore the contents of the buffer used for localtime's
+     result around the call to tzset.  */
+  struct tm save = *localtime_buffer_addr;
+  tzset ();
+  *localtime_buffer_addr = save;
+}
+#endif
+
+/* This is a wrapper for gettimeofday.  It is used only on systems
+   that lack this function, or whose implementation of this function
+   causes problems.  */
+
+int
+gettimeofday (struct timeval *restrict tv, void *restrict tz)
+{
+#undef gettimeofday
+#if HAVE_GETTIMEOFDAY
+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
+  /* Save and restore the contents of the buffer used for localtime's
+     result around the call to gettimeofday.  */
+  struct tm save = *localtime_buffer_addr;
+# endif
+
+# if defined timeval /* 'struct timeval' overridden by gnulib?  */
+#  undef timeval
+  struct timeval otv;
+  int result = gettimeofday (&otv, (struct timezone *) tz);
+  if (result == 0)
+    {
+      tv->tv_sec = otv.tv_sec;
+      tv->tv_usec = otv.tv_usec;
+    }
+# else
+  int result = gettimeofday (tv, (struct timezone *) tz);
+# endif
+
+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
+  *localtime_buffer_addr = save;
+# endif
+
+  return result;
+
+#else
+
+# if HAVE__FTIME
+
+  struct _timeb timebuf;
+  _ftime (&timebuf);
+  tv->tv_sec = timebuf.time;
+  tv->tv_usec = timebuf.millitm * 1000;
+
+# else
+
+#  if !defined OK_TO_USE_1S_CLOCK
+#   error "Only 1-second nominal clock resolution found.  Is that intended?" \
+          "If so, compile with the -DOK_TO_USE_1S_CLOCK option."
+#  endif
+  tv->tv_sec = time (NULL);
+  tv->tv_usec = 0;
+
+# endif
+
+  return 0;
+
+#endif
+}
diff --git a/gdb/gnulib/import/m4/fcntl_h.m4 b/gdb/gnulib/import/m4/fcntl_h.m4
new file mode 100644
index 0000000..cac28ae
--- /dev/null
+++ b/gdb/gnulib/import/m4/fcntl_h.m4
@@ -0,0 +1,50 @@
+# serial 15
+# Configure fcntl.h.
+dnl Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl_FCNTL_H],
+[
+  AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
+  AC_REQUIRE([gl_FCNTL_O_FLAGS])
+  gl_NEXT_HEADERS([fcntl.h])
+
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
+  dnl Ensure the type mode_t gets defined.
+  AC_REQUIRE([AC_TYPE_MODE_T])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use, if it is not common
+  dnl enough to be declared everywhere.
+  gl_WARN_ON_USE_PREPARE([[#include <fcntl.h>
+    ]], [fcntl openat])
+])
+
+AC_DEFUN([gl_FCNTL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_FCNTL_H_DEFAULTS],
+[
+  GNULIB_FCNTL=0;        AC_SUBST([GNULIB_FCNTL])
+  GNULIB_NONBLOCKING=0;  AC_SUBST([GNULIB_NONBLOCKING])
+  GNULIB_OPEN=0;         AC_SUBST([GNULIB_OPEN])
+  GNULIB_OPENAT=0;       AC_SUBST([GNULIB_OPENAT])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_FCNTL=1;          AC_SUBST([HAVE_FCNTL])
+  HAVE_OPENAT=1;         AC_SUBST([HAVE_OPENAT])
+  REPLACE_FCNTL=0;       AC_SUBST([REPLACE_FCNTL])
+  REPLACE_OPEN=0;        AC_SUBST([REPLACE_OPEN])
+  REPLACE_OPENAT=0;      AC_SUBST([REPLACE_OPENAT])
+])
diff --git a/gdb/gnulib/import/m4/gettimeofday.m4 b/gdb/gnulib/import/m4/gettimeofday.m4
new file mode 100644
index 0000000..eda9702
--- /dev/null
+++ b/gdb/gnulib/import/m4/gettimeofday.m4
@@ -0,0 +1,140 @@
+# serial 20
+
+# Copyright (C) 2001-2003, 2005, 2007, 2009-2012 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+dnl From Jim Meyering.
+
+AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
+[
+  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H])
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([gettimeofday])
+
+  gl_gettimeofday_timezone=void
+  if test $ac_cv_func_gettimeofday != yes; then
+    HAVE_GETTIMEOFDAY=0
+  else
+    gl_FUNC_GETTIMEOFDAY_CLOBBER
+    AC_CACHE_CHECK([for gettimeofday with POSIX signature],
+      [gl_cv_func_gettimeofday_posix_signature],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <sys/time.h>
+              struct timeval c;
+              int gettimeofday (struct timeval *restrict, void *restrict);
+            ]],
+            [[/* glibc uses struct timezone * rather than the POSIX void *
+                 if _GNU_SOURCE is defined.  However, since the only portable
+                 use of gettimeofday uses NULL as the second parameter, and
+                 since the glibc definition is actually more typesafe, it is
+                 not worth wrapping this to get a compliant signature.  */
+              int (*f) (struct timeval *restrict, void *restrict)
+                = gettimeofday;
+              int x = f (&c, 0);
+              return !(x | c.tv_sec | c.tv_usec);
+            ]])],
+          [gl_cv_func_gettimeofday_posix_signature=yes],
+          [AC_COMPILE_IFELSE(
+            [AC_LANG_PROGRAM(
+              [[#include <sys/time.h>
+int gettimeofday (struct timeval *restrict, struct timezone *restrict);
+              ]])],
+            [gl_cv_func_gettimeofday_posix_signature=almost],
+            [gl_cv_func_gettimeofday_posix_signature=no])])])
+    if test $gl_cv_func_gettimeofday_posix_signature = almost; then
+      gl_gettimeofday_timezone='struct timezone'
+    elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
+      REPLACE_GETTIMEOFDAY=1
+    fi
+    dnl If we override 'struct timeval', we also have to override gettimeofday.
+    if test $REPLACE_STRUCT_TIMEVAL = 1; then
+      REPLACE_GETTIMEOFDAY=1
+    fi
+    m4_ifdef([gl_FUNC_TZSET_CLOBBER], [
+      gl_FUNC_TZSET_CLOBBER
+      case "$gl_cv_func_tzset_clobber" in
+        *yes)
+          REPLACE_GETTIMEOFDAY=1
+          gl_GETTIMEOFDAY_REPLACE_LOCALTIME
+          AC_DEFINE([tzset], [rpl_tzset],
+            [Define to rpl_tzset if the wrapper function should be used.])
+          AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1],
+            [Define if tzset clobbers localtime's static buffer.])
+          ;;
+      esac
+    ])
+  fi
+  AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
+    [Define this to 'void' or 'struct timezone' to match the system's
+     declaration of the second argument to gettimeofday.])
+])
+
+
+dnl See if gettimeofday clobbers the static buffer that localtime uses
+dnl for its return value.  The gettimeofday function from Mac OS X 10.0.4
+dnl (i.e., Darwin 1.3.7) has this problem.
+dnl
+dnl If it does, then arrange to use gettimeofday and localtime only via
+dnl the wrapper functions that work around the problem.
+
+AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
+[
+ AC_REQUIRE([gl_HEADER_SYS_TIME_H])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+ AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
+  [gl_cv_func_gettimeofday_clobber],
+  [AC_RUN_IFELSE(
+     [AC_LANG_PROGRAM(
+        [[#include <string.h>
+          #include <sys/time.h>
+          #include <time.h>
+          #include <stdlib.h>
+        ]],
+        [[
+          time_t t = 0;
+          struct tm *lt;
+          struct tm saved_lt;
+          struct timeval tv;
+          lt = localtime (&t);
+          saved_lt = *lt;
+          gettimeofday (&tv, NULL);
+          return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
+        ]])],
+     [gl_cv_func_gettimeofday_clobber=no],
+     [gl_cv_func_gettimeofday_clobber=yes],
+     [# When cross-compiling:
+      case "$host_os" in
+                # Guess all is fine on glibc systems.
+        *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
+                # If we don't know, assume the worst.
+        *)      gl_cv_func_gettimeofday_clobber="guessing yes" ;;
+      esac
+     ])])
+
+ case "$gl_cv_func_gettimeofday_clobber" in
+   *yes)
+     REPLACE_GETTIMEOFDAY=1
+     gl_GETTIMEOFDAY_REPLACE_LOCALTIME
+     AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
+       [Define if gettimeofday clobbers the localtime buffer.])
+     ;;
+ esac
+])
+
+AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
+  AC_DEFINE([gmtime], [rpl_gmtime],
+    [Define to rpl_gmtime if the replacement function should be used.])
+  AC_DEFINE([localtime], [rpl_localtime],
+    [Define to rpl_localtime if the replacement function should be used.])
+])
+
+# Prerequisites of lib/gettimeofday.c.
+AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
+  AC_CHECK_HEADERS([sys/timeb.h])
+  AC_CHECK_FUNCS([_ftime])
+])
diff --git a/gdb/gnulib/import/m4/gnulib-cache.m4 b/gdb/gnulib/import/m4/gnulib-cache.m4
index 7cc681a..9cf8cc7 100644
--- a/gdb/gnulib/import/m4/gnulib-cache.m4
+++ b/gdb/gnulib/import/m4/gnulib-cache.m4
@@ -27,7 +27,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes lstat memchr memmem pathmax readlink rename strstr sys_stat unistd update-copyright wchar wctype-h
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes lstat memchr memmem mkdtemp pathmax readlink rename strstr sys_stat unistd update-copyright wchar wctype-h
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
@@ -43,6 +43,7 @@ gl_MODULES([
   lstat
   memchr
   memmem
+  mkdtemp
   pathmax
   readlink
   rename
diff --git a/gdb/gnulib/import/m4/gnulib-comp.m4 b/gdb/gnulib/import/m4/gnulib-comp.m4
index f280cf2..866835c 100644
--- a/gdb/gnulib/import/m4/gnulib-comp.m4
+++ b/gdb/gnulib/import/m4/gnulib-comp.m4
@@ -52,6 +52,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module extensions:
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   # Code from module extern-inline:
+  # Code from module fcntl-h:
   # Code from module float:
   # Code from module fnmatch:
   # Code from module fnmatch-gnu:
@@ -60,6 +61,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module fpucw:
   # Code from module frexp:
   # Code from module frexpl:
+  # Code from module gettimeofday:
   # Code from module include_next:
   # Code from module inttypes:
   # Code from module inttypes-incomplete:
@@ -78,6 +80,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module memchr:
   # Code from module memmem:
   # Code from module memmem-simple:
+  # Code from module mkdtemp:
   # Code from module multiarch:
   # Code from module nocrash:
   # Code from module pathmax:
@@ -102,7 +105,9 @@ AC_DEFUN([gl_EARLY],
   # Code from module strstr:
   # Code from module strstr-simple:
   # Code from module sys_stat:
+  # Code from module sys_time:
   # Code from module sys_types:
+  # Code from module tempname:
   # Code from module time:
   # Code from module unistd:
   # Code from module update-copyright:
@@ -148,6 +153,7 @@ AC_DEFUN([gl_INIT],
   gl_DOUBLE_SLASH_ROOT
   gl_HEADER_ERRNO_H
   AC_REQUIRE([gl_EXTERN_INLINE])
+  gl_FCNTL_H
   gl_FLOAT_H
   if test $REPLACE_FLOAT_LDBL = 1; then
     AC_LIBOBJ([float])
@@ -175,6 +181,12 @@ AC_DEFUN([gl_INIT],
     AC_LIBOBJ([frexpl])
   fi
   gl_MATH_MODULE_INDICATOR([frexpl])
+  gl_FUNC_GETTIMEOFDAY
+  if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then
+    AC_LIBOBJ([gettimeofday])
+    gl_PREREQ_GETTIMEOFDAY
+  fi
+  gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
   gl_INTTYPES_H
   gl_INTTYPES_INCOMPLETE
   gl_FUNC_ISNAND_NO_LIBM
@@ -238,6 +250,12 @@ AC_DEFUN([gl_INIT],
     AC_LIBOBJ([memmem])
   fi
   gl_STRING_MODULE_INDICATOR([memmem])
+  gl_FUNC_MKDTEMP
+  if test $HAVE_MKDTEMP = 0; then
+    AC_LIBOBJ([mkdtemp])
+    gl_PREREQ_MKDTEMP
+  fi
+  gl_STDLIB_MODULE_INDICATOR([mkdtemp])
   gl_MULTIARCH
   gl_PATHMAX
   gl_FUNC_READLINK
@@ -280,8 +298,11 @@ AC_DEFUN([gl_INIT],
   gl_STRING_MODULE_INDICATOR([strstr])
   gl_HEADER_SYS_STAT_H
   AC_PROG_MKDIR_P
+  gl_HEADER_SYS_TIME_H
+  AC_PROG_MKDIR_P
   gl_SYS_TYPES_H
   AC_PROG_MKDIR_P
+  gl_FUNC_GEN_TEMPNAME
   gl_HEADER_TIME_H
   gl_UNISTD_H
   gl_WCHAR_H
@@ -442,6 +463,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/dirname.h
   lib/dosname.h
   lib/errno.in.h
+  lib/fcntl.in.h
   lib/float+.h
   lib/float.c
   lib/float.in.h
@@ -451,6 +473,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/fpucw.h
   lib/frexp.c
   lib/frexpl.c
+  lib/gettimeofday.c
   lib/inttypes.in.h
   lib/isnan.c
   lib/isnand-nolibm.h
@@ -475,6 +498,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/memchr.c
   lib/memchr.valgrind
   lib/memmem.c
+  lib/mkdtemp.c
   lib/pathmax.h
   lib/readlink.c
   lib/ref-add.sin
@@ -497,7 +521,10 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/strnlen1.h
   lib/strstr.c
   lib/sys_stat.in.h
+  lib/sys_time.in.h
   lib/sys_types.in.h
+  lib/tempname.c
+  lib/tempname.h
   lib/time.in.h
   lib/unistd.c
   lib/unistd.in.h
@@ -521,11 +548,13 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/extensions.m4
   m4/extern-inline.m4
   m4/fcntl-o.m4
+  m4/fcntl_h.m4
   m4/float_h.m4
   m4/fnmatch.m4
   m4/fpieee.m4
   m4/frexp.m4
   m4/frexpl.m4
+  m4/gettimeofday.m4
   m4/glibc21.m4
   m4/gnulib-common.m4
   m4/include_next.m4
@@ -549,6 +578,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/mbstate_t.m4
   m4/memchr.m4
   m4/memmem.m4
+  m4/mkdtemp.m4
   m4/mmap-anon.m4
   m4/multiarch.m4
   m4/nocrash.m4
@@ -566,8 +596,11 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/stdlib_h.m4
   m4/string_h.m4
   m4/strstr.m4
+  m4/sys_socket_h.m4
   m4/sys_stat_h.m4
+  m4/sys_time_h.m4
   m4/sys_types_h.m4
+  m4/tempname.m4
   m4/time_h.m4
   m4/unistd_h.m4
   m4/warn-on-use.m4
diff --git a/gdb/gnulib/import/m4/mkdtemp.m4 b/gdb/gnulib/import/m4/mkdtemp.m4
new file mode 100644
index 0000000..885832d
--- /dev/null
+++ b/gdb/gnulib/import/m4/mkdtemp.m4
@@ -0,0 +1,20 @@
+# mkdtemp.m4 serial 8
+dnl Copyright (C) 2001-2003, 2006-2007, 2009-2012 Free Software Foundation,
+dnl Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MKDTEMP],
+[
+  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+  AC_CHECK_FUNCS([mkdtemp])
+  if test $ac_cv_func_mkdtemp = no; then
+    HAVE_MKDTEMP=0
+  fi
+])
+
+# Prerequisites of lib/mkdtemp.c
+AC_DEFUN([gl_PREREQ_MKDTEMP],
+[:
+])
diff --git a/gdb/gnulib/import/m4/sys_socket_h.m4 b/gdb/gnulib/import/m4/sys_socket_h.m4
new file mode 100644
index 0000000..acfae41
--- /dev/null
+++ b/gdb/gnulib/import/m4/sys_socket_h.m4
@@ -0,0 +1,176 @@
+# sys_socket_h.m4 serial 23
+dnl Copyright (C) 2005-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Simon Josefsson.
+
+AC_DEFUN([gl_HEADER_SYS_SOCKET],
+[
+  AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
+  dnl On OSF/1, the functions recv(), send(), recvfrom(), sendto() have
+  dnl old-style declarations (with return type 'int' instead of 'ssize_t')
+  dnl unless _POSIX_PII_SOCKET is defined.
+  case "$host_os" in
+    osf*)
+      AC_DEFINE([_POSIX_PII_SOCKET], [1],
+        [Define to 1 in order to get the POSIX compatible declarations
+         of socket functions.])
+      ;;
+  esac
+
+  AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
+    [gl_cv_header_sys_socket_h_selfcontained],
+    [
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
+        [gl_cv_header_sys_socket_h_selfcontained=yes],
+        [gl_cv_header_sys_socket_h_selfcontained=no])
+    ])
+  if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
+    dnl If the shutdown function exists, <sys/socket.h> should define
+    dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
+    AC_CHECK_FUNCS([shutdown])
+    if test $ac_cv_func_shutdown = yes; then
+      AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
+        [gl_cv_header_sys_socket_h_shut],
+        [
+          AC_COMPILE_IFELSE(
+            [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
+               [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
+            [gl_cv_header_sys_socket_h_shut=yes],
+            [gl_cv_header_sys_socket_h_shut=no])
+        ])
+      if test $gl_cv_header_sys_socket_h_shut = no; then
+        SYS_SOCKET_H='sys/socket.h'
+      fi
+    fi
+  fi
+  # We need to check for ws2tcpip.h now.
+  gl_PREREQ_SYS_H_SOCKET
+  AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
+  /* sys/types.h is not needed according to POSIX, but the
+     sys/socket.h in i386-unknown-freebsd4.10 and
+     powerpc-apple-darwin5.5 required it. */
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+])
+  if test $ac_cv_type_struct_sockaddr_storage = no; then
+    HAVE_STRUCT_SOCKADDR_STORAGE=0
+  fi
+  if test $ac_cv_type_sa_family_t = no; then
+    HAVE_SA_FAMILY_T=0
+  fi
+  if test $ac_cv_type_struct_sockaddr_storage != no; then
+    AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
+      [],
+      [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
+      [#include <sys/types.h>
+       #ifdef HAVE_SYS_SOCKET_H
+       #include <sys/socket.h>
+       #endif
+       #ifdef HAVE_WS2TCPIP_H
+       #include <ws2tcpip.h>
+       #endif
+      ])
+  fi
+  if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
+     || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
+    SYS_SOCKET_H='sys/socket.h'
+  fi
+  gl_PREREQ_SYS_H_WINSOCK2
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[
+/* Some systems require prerequisite headers.  */
+#include <sys/types.h>
+#include <sys/socket.h>
+    ]], [socket connect accept bind getpeername getsockname getsockopt
+    listen recv send recvfrom sendto setsockopt shutdown accept4])
+])
+
+AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
+[
+  dnl Check prerequisites of the <sys/socket.h> replacement.
+  AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
+  gl_CHECK_NEXT_HEADERS([sys/socket.h])
+  if test $ac_cv_header_sys_socket_h = yes; then
+    HAVE_SYS_SOCKET_H=1
+    HAVE_WS2TCPIP_H=0
+  else
+    HAVE_SYS_SOCKET_H=0
+    if test $ac_cv_header_ws2tcpip_h = yes; then
+      HAVE_WS2TCPIP_H=1
+    else
+      HAVE_WS2TCPIP_H=0
+    fi
+  fi
+  AC_SUBST([HAVE_SYS_SOCKET_H])
+  AC_SUBST([HAVE_WS2TCPIP_H])
+])
+
+# Common prerequisites of the <sys/socket.h> replacement and of the
+# <sys/select.h> replacement.
+# Sets and substitutes HAVE_WINSOCK2_H.
+AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
+[
+  m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
+  m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
+  AC_CHECK_HEADERS_ONCE([sys/socket.h])
+  if test $ac_cv_header_sys_socket_h != yes; then
+    dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
+    dnl the check for those headers unconditional; yet cygwin reports
+    dnl that the headers are present but cannot be compiled (since on
+    dnl cygwin, all socket information should come from sys/socket.h).
+    AC_CHECK_HEADERS([winsock2.h])
+  fi
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    HAVE_WINSOCK2_H=1
+    UNISTD_H_HAVE_WINSOCK2_H=1
+    SYS_IOCTL_H_HAVE_WINSOCK2_H=1
+  else
+    HAVE_WINSOCK2_H=0
+  fi
+  AC_SUBST([HAVE_WINSOCK2_H])
+])
+
+AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
+[
+  GNULIB_SOCKET=0;      AC_SUBST([GNULIB_SOCKET])
+  GNULIB_CONNECT=0;     AC_SUBST([GNULIB_CONNECT])
+  GNULIB_ACCEPT=0;      AC_SUBST([GNULIB_ACCEPT])
+  GNULIB_BIND=0;        AC_SUBST([GNULIB_BIND])
+  GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
+  GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
+  GNULIB_GETSOCKOPT=0;  AC_SUBST([GNULIB_GETSOCKOPT])
+  GNULIB_LISTEN=0;      AC_SUBST([GNULIB_LISTEN])
+  GNULIB_RECV=0;        AC_SUBST([GNULIB_RECV])
+  GNULIB_SEND=0;        AC_SUBST([GNULIB_SEND])
+  GNULIB_RECVFROM=0;    AC_SUBST([GNULIB_RECVFROM])
+  GNULIB_SENDTO=0;      AC_SUBST([GNULIB_SENDTO])
+  GNULIB_SETSOCKOPT=0;  AC_SUBST([GNULIB_SETSOCKOPT])
+  GNULIB_SHUTDOWN=0;    AC_SUBST([GNULIB_SHUTDOWN])
+  GNULIB_ACCEPT4=0;     AC_SUBST([GNULIB_ACCEPT4])
+  HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
+  HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
+                        AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
+  HAVE_SA_FAMILY_T=1;   AC_SUBST([HAVE_SA_FAMILY_T])
+  HAVE_ACCEPT4=1;       AC_SUBST([HAVE_ACCEPT4])
+])
diff --git a/gdb/gnulib/import/m4/sys_time_h.m4 b/gdb/gnulib/import/m4/sys_time_h.m4
new file mode 100644
index 0000000..c4a30cd
--- /dev/null
+++ b/gdb/gnulib/import/m4/sys_time_h.m4
@@ -0,0 +1,110 @@
+# Configure a replacement for <sys/time.h>.
+# serial 8
+
+# Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# Written by Paul Eggert and Martin Lambers.
+
+AC_DEFUN([gl_HEADER_SYS_TIME_H],
+[
+  dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
+  dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
+  dnl statements that occur in other macros.
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
+])
+
+AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
+[
+  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
+  AC_CHECK_HEADERS_ONCE([sys/time.h])
+  gl_CHECK_NEXT_HEADERS([sys/time.h])
+
+  if test $ac_cv_header_sys_time_h != yes; then
+    HAVE_SYS_TIME_H=0
+  fi
+
+  dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
+  dnl only. So include that header in the list.
+  gl_PREREQ_SYS_H_WINSOCK2
+  AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#if HAVE_SYS_TIME_H
+             #include <sys/time.h>
+            #endif
+            #include <time.h>
+            #if HAVE_WINSOCK2_H
+            # include <winsock2.h>
+            #endif
+          ]],
+          [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
+       [gl_cv_sys_struct_timeval=yes],
+       [gl_cv_sys_struct_timeval=no])
+    ])
+  if test $gl_cv_sys_struct_timeval != yes; then
+    HAVE_STRUCT_TIMEVAL=0
+  else
+    dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
+    dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
+    dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
+    dnl smaller than the 'time_t' type mandated by POSIX.
+    dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but
+    dnl that is good enough.
+    AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member],
+      [gl_cv_sys_struct_timeval_tv_sec],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#if HAVE_SYS_TIME_H
+               #include <sys/time.h>
+              #endif
+              #include <time.h>
+              #if HAVE_WINSOCK2_H
+              # include <winsock2.h>
+              #endif
+            ]],
+            [[static struct timeval x;
+              typedef int verify_tv_sec_type[
+                sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1
+              ];
+            ]])],
+         [gl_cv_sys_struct_timeval_tv_sec=yes],
+         [gl_cv_sys_struct_timeval_tv_sec=no])
+      ])
+    if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
+      REPLACE_STRUCT_TIMEVAL=1
+    fi
+  fi
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[
+#if HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <time.h>
+    ]], [gettimeofday])
+])
+
+AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
+[
+  GNULIB_GETTIMEOFDAY=0;     AC_SUBST([GNULIB_GETTIMEOFDAY])
+  dnl Assume POSIX behavior unless another module says otherwise.
+  HAVE_GETTIMEOFDAY=1;       AC_SUBST([HAVE_GETTIMEOFDAY])
+  HAVE_STRUCT_TIMEVAL=1;     AC_SUBST([HAVE_STRUCT_TIMEVAL])
+  HAVE_SYS_TIME_H=1;         AC_SUBST([HAVE_SYS_TIME_H])
+  REPLACE_GETTIMEOFDAY=0;    AC_SUBST([REPLACE_GETTIMEOFDAY])
+  REPLACE_STRUCT_TIMEVAL=0;  AC_SUBST([REPLACE_STRUCT_TIMEVAL])
+])
diff --git a/gdb/gnulib/import/m4/tempname.m4 b/gdb/gnulib/import/m4/tempname.m4
new file mode 100644
index 0000000..20ad78b
--- /dev/null
+++ b/gdb/gnulib/import/m4/tempname.m4
@@ -0,0 +1,19 @@
+#serial 5
+
+# Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# glibc provides __gen_tempname as a wrapper for mk[ds]temp.  Expose
+# it as a public API, and provide it on systems that are lacking.
+AC_DEFUN([gl_FUNC_GEN_TEMPNAME],
+[
+  gl_PREREQ_TEMPNAME
+])
+
+# Prerequisites of lib/tempname.c.
+AC_DEFUN([gl_PREREQ_TEMPNAME],
+[
+  :
+])
diff --git a/gdb/gnulib/import/mkdtemp.c b/gdb/gnulib/import/mkdtemp.c
new file mode 100644
index 0000000..3f465b3
--- /dev/null
+++ b/gdb/gnulib/import/mkdtemp.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1999, 2001-2003, 2006-2007, 2009-2012 Free Software
+   Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Extracted from misc/mkdtemp.c.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdlib.h>
+
+#include "tempname.h"
+
+/* Generate a unique temporary directory from XTEMPLATE.
+   The last six characters of XTEMPLATE must be "XXXXXX";
+   they are replaced with a string that makes the filename unique.
+   The directory is created, mode 700, and its name is returned.
+   (This function comes from OpenBSD.) */
+char *
+mkdtemp (char *xtemplate)
+{
+  if (gen_tempname (xtemplate, 0, 0, GT_DIR))
+    return NULL;
+  else
+    return xtemplate;
+}
diff --git a/gdb/gnulib/import/sys_time.in.h b/gdb/gnulib/import/sys_time.in.h
new file mode 100644
index 0000000..d915cee
--- /dev/null
+++ b/gdb/gnulib/import/sys_time.in.h
@@ -0,0 +1,205 @@
+/* Provide a more complete sys/time.h.
+
+   Copyright (C) 2007-2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert.  */
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+#if defined _@GUARD_PREFIX@_SYS_TIME_H
+
+/* Simply delegate to the system's header, without adding anything.  */
+# if @HAVE_SYS_TIME_H@
+#  @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
+# endif
+
+#else
+
+# define _@GUARD_PREFIX@_SYS_TIME_H
+
+# if @HAVE_SYS_TIME_H@
+#  @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
+# else
+#  include <time.h>
+# endif
+
+/* On native Windows with MSVC, get the 'struct timeval' type.
+   Also, on native Windows with a 64-bit time_t, where we are overriding the
+   'struct timeval' type, get all declarations of system functions whose
+   signature contains 'struct timeval'.  */
+# if (defined _MSC_VER || @REPLACE_STRUCT_TIMEVAL@) && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
+#  define _GL_INCLUDING_WINSOCK2_H
+#  include <winsock2.h>
+#  undef _GL_INCLUDING_WINSOCK2_H
+# endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if !@HAVE_STRUCT_TIMEVAL@ || @REPLACE_STRUCT_TIMEVAL@
+
+#  if @REPLACE_STRUCT_TIMEVAL@
+#   define timeval rpl_timeval
+#  endif
+
+#  if !GNULIB_defined_struct_timeval
+struct timeval
+{
+  time_t tv_sec;
+  long int tv_usec;
+};
+#   define GNULIB_defined_struct_timeval 1
+#  endif
+
+# endif
+
+# ifdef __cplusplus
+}
+# endif
+
+# if @GNULIB_GETTIMEOFDAY@
+#  if @REPLACE_GETTIMEOFDAY@
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef gettimeofday
+#    define gettimeofday rpl_gettimeofday
+#   endif
+_GL_FUNCDECL_RPL (gettimeofday, int,
+                  (struct timeval *restrict, void *restrict)
+                  _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (gettimeofday, int,
+                  (struct timeval *restrict, void *restrict));
+#  else
+#   if !@HAVE_GETTIMEOFDAY@
+_GL_FUNCDECL_SYS (gettimeofday, int,
+                  (struct timeval *restrict, void *restrict)
+                  _GL_ARG_NONNULL ((1)));
+#   endif
+/* Need to cast, because on glibc systems, by default, the second argument is
+                                                  struct timezone *.  */
+_GL_CXXALIAS_SYS_CAST (gettimeofday, int,
+                       (struct timeval *restrict, void *restrict));
+#  endif
+_GL_CXXALIASWARN (gettimeofday);
+# elif defined GNULIB_POSIXCHECK
+#  undef gettimeofday
+#  if HAVE_RAW_DECL_GETTIMEOFDAY
+_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
+                 "use gnulib module gettimeofday for portability");
+#  endif
+# endif
+
+/* Hide some function declarations from <winsock2.h>.  */
+
+# if defined _MSC_VER && @HAVE_WINSOCK2_H@
+#  if !defined _@GUARD_PREFIX@_UNISTD_H
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef close
+#    define close close_used_without_including_unistd_h
+#   else
+     _GL_WARN_ON_USE (close,
+                      "close() used without including <unistd.h>");
+#   endif
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef gethostname
+#    define gethostname gethostname_used_without_including_unistd_h
+#   else
+     _GL_WARN_ON_USE (gethostname,
+                      "gethostname() used without including <unistd.h>");
+#   endif
+#  endif
+#  if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef socket
+#    define socket              socket_used_without_including_sys_socket_h
+#    undef connect
+#    define connect             connect_used_without_including_sys_socket_h
+#    undef accept
+#    define accept              accept_used_without_including_sys_socket_h
+#    undef bind
+#    define bind                bind_used_without_including_sys_socket_h
+#    undef getpeername
+#    define getpeername         getpeername_used_without_including_sys_socket_h
+#    undef getsockname
+#    define getsockname         getsockname_used_without_including_sys_socket_h
+#    undef getsockopt
+#    define getsockopt          getsockopt_used_without_including_sys_socket_h
+#    undef listen
+#    define listen              listen_used_without_including_sys_socket_h
+#    undef recv
+#    define recv                recv_used_without_including_sys_socket_h
+#    undef send
+#    define send                send_used_without_including_sys_socket_h
+#    undef recvfrom
+#    define recvfrom            recvfrom_used_without_including_sys_socket_h
+#    undef sendto
+#    define sendto              sendto_used_without_including_sys_socket_h
+#    undef setsockopt
+#    define setsockopt          setsockopt_used_without_including_sys_socket_h
+#    undef shutdown
+#    define shutdown            shutdown_used_without_including_sys_socket_h
+#   else
+     _GL_WARN_ON_USE (socket,
+                      "socket() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (connect,
+                      "connect() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (accept,
+                      "accept() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (bind,
+                      "bind() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (getpeername,
+                      "getpeername() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (getsockname,
+                      "getsockname() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (getsockopt,
+                      "getsockopt() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (listen,
+                      "listen() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (recv,
+                      "recv() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (send,
+                      "send() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (recvfrom,
+                      "recvfrom() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (sendto,
+                      "sendto() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (setsockopt,
+                      "setsockopt() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (shutdown,
+                      "shutdown() used without including <sys/socket.h>");
+#   endif
+#  endif
+#  if !defined _@GUARD_PREFIX@_SYS_SELECT_H
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef select
+#    define select select_used_without_including_sys_select_h
+#   else
+     _GL_WARN_ON_USE (select,
+                      "select() used without including <sys/select.h>");
+#   endif
+#  endif
+# endif
+
+#endif /* _@GUARD_PREFIX@_SYS_TIME_H */
diff --git a/gdb/gnulib/import/tempname.c b/gdb/gnulib/import/tempname.c
new file mode 100644
index 0000000..26a38ce
--- /dev/null
+++ b/gdb/gnulib/import/tempname.c
@@ -0,0 +1,309 @@
+/* tempname.c - generate the name of a temporary file.
+
+   Copyright (C) 1991-2003, 2005-2007, 2009-2012 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Extracted from glibc sysdeps/posix/tempname.c.  See also tmpdir.c.  */
+
+#if !_LIBC
+# include <config.h>
+# include "tempname.h"
+#endif
+
+#include <sys/types.h>
+#include <assert.h>
+
+#include <errno.h>
+#ifndef __set_errno
+# define __set_errno(Val) errno = (Val)
+#endif
+
+#include <stdio.h>
+#ifndef P_tmpdir
+# define P_tmpdir "/tmp"
+#endif
+#ifndef TMP_MAX
+# define TMP_MAX 238328
+#endif
+#ifndef __GT_FILE
+# define __GT_FILE      0
+# define __GT_DIR       1
+# define __GT_NOCREATE  2
+#endif
+#if !_LIBC && (GT_FILE != __GT_FILE || GT_DIR != __GT_DIR       \
+               || GT_NOCREATE != __GT_NOCREATE)
+# error report this to bug-gnulib@gnu.org
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fcntl.h>
+#include <sys/time.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+
+#if _LIBC
+# define struct_stat64 struct stat64
+#else
+# define struct_stat64 struct stat
+# define __gen_tempname gen_tempname
+# define __getpid getpid
+# define __gettimeofday gettimeofday
+# define __mkdir mkdir
+# define __open open
+# define __lxstat64(version, file, buf) lstat (file, buf)
+#endif
+
+#if ! (HAVE___SECURE_GETENV || _LIBC)
+# define __secure_getenv getenv
+#endif
+
+#ifdef _LIBC
+# include <hp-timing.h>
+# if HP_TIMING_AVAIL
+#  define RANDOM_BITS(Var) \
+  if (__builtin_expect (value == UINT64_C (0), 0))                            \
+    {                                                                         \
+      /* If this is the first time this function is used initialize           \
+         the variable we accumulate the value in to some somewhat             \
+         random value.  If we'd not do this programs at startup time          \
+         might have a reduced set of possible names, at least on slow         \
+         machines.  */                                                        \
+      struct timeval tv;                                                      \
+      __gettimeofday (&tv, NULL);                                             \
+      value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;                      \
+    }                                                                         \
+  HP_TIMING_NOW (Var)
+# endif
+#endif
+
+/* Use the widest available unsigned type if uint64_t is not
+   available.  The algorithm below extracts a number less than 62**6
+   (approximately 2**35.725) from uint64_t, so ancient hosts where
+   uintmax_t is only 32 bits lose about 3.725 bits of randomness,
+   which is better than not having mkstemp at all.  */
+#if !defined UINT64_MAX && !defined uint64_t
+# define uint64_t uintmax_t
+#endif
+
+#if _LIBC
+/* Return nonzero if DIR is an existent directory.  */
+static int
+direxists (const char *dir)
+{
+  struct_stat64 buf;
+  return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
+}
+
+/* Path search algorithm, for tmpnam, tmpfile, etc.  If DIR is
+   non-null and exists, uses it; otherwise uses the first of $TMPDIR,
+   P_tmpdir, /tmp that exists.  Copies into TMPL a template suitable
+   for use with mk[s]temp.  Will fail (-1) if DIR is non-null and
+   doesn't exist, none of the searched dirs exists, or there's not
+   enough space in TMPL. */
+int
+__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
+               int try_tmpdir)
+{
+  const char *d;
+  size_t dlen, plen;
+
+  if (!pfx || !pfx[0])
+    {
+      pfx = "file";
+      plen = 4;
+    }
+  else
+    {
+      plen = strlen (pfx);
+      if (plen > 5)
+        plen = 5;
+    }
+
+  if (try_tmpdir)
+    {
+      d = __secure_getenv ("TMPDIR");
+      if (d != NULL && direxists (d))
+        dir = d;
+      else if (dir != NULL && direxists (dir))
+        /* nothing */ ;
+      else
+        dir = NULL;
+    }
+  if (dir == NULL)
+    {
+      if (direxists (P_tmpdir))
+        dir = P_tmpdir;
+      else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
+        dir = "/tmp";
+      else
+        {
+          __set_errno (ENOENT);
+          return -1;
+        }
+    }
+
+  dlen = strlen (dir);
+  while (dlen > 1 && dir[dlen - 1] == '/')
+    dlen--;                     /* remove trailing slashes */
+
+  /* check we have room for "${dir}/${pfx}XXXXXX\0" */
+  if (tmpl_len < dlen + 1 + plen + 6 + 1)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx);
+  return 0;
+}
+#endif /* _LIBC */
+
+/* These are the characters used in temporary file names.  */
+static const char letters[] =
+"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+
+/* Generate a temporary file name based on TMPL.  TMPL must match the
+   rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
+   The name constructed does not exist at the time of the call to
+   __gen_tempname.  TMPL is overwritten with the result.
+
+   KIND may be one of:
+   __GT_NOCREATE:       simply verify that the name does not exist
+                        at the time of the call.
+   __GT_FILE:           create the file using open(O_CREAT|O_EXCL)
+                        and return a read-write fd.  The file is mode 0600.
+   __GT_DIR:            create a directory, which will be mode 0700.
+
+   We use a clever algorithm to get hard-to-predict names. */
+int
+__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
+{
+  int len;
+  char *XXXXXX;
+  static uint64_t value;
+  uint64_t random_time_bits;
+  unsigned int count;
+  int fd = -1;
+  int save_errno = errno;
+  struct_stat64 st;
+
+  /* A lower bound on the number of temporary files to attempt to
+     generate.  The maximum total number of temporary file names that
+     can exist for a given template is 62**6.  It should never be
+     necessary to try all of these combinations.  Instead if a reasonable
+     number of names is tried (we define reasonable as 62**3) fail to
+     give the system administrator the chance to remove the problems.  */
+#define ATTEMPTS_MIN (62 * 62 * 62)
+
+  /* The number of times to attempt to generate a temporary file.  To
+     conform to POSIX, this must be no smaller than TMP_MAX.  */
+#if ATTEMPTS_MIN < TMP_MAX
+  unsigned int attempts = TMP_MAX;
+#else
+  unsigned int attempts = ATTEMPTS_MIN;
+#endif
+
+  len = strlen (tmpl);
+  if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6))
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  /* This is where the Xs start.  */
+  XXXXXX = &tmpl[len - 6 - suffixlen];
+
+  /* Get some more or less random data.  */
+#ifdef RANDOM_BITS
+  RANDOM_BITS (random_time_bits);
+#else
+  {
+    struct timeval tv;
+    __gettimeofday (&tv, NULL);
+    random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
+  }
+#endif
+  value += random_time_bits ^ __getpid ();
+
+  for (count = 0; count < attempts; value += 7777, ++count)
+    {
+      uint64_t v = value;
+
+      /* Fill in the random bits.  */
+      XXXXXX[0] = letters[v % 62];
+      v /= 62;
+      XXXXXX[1] = letters[v % 62];
+      v /= 62;
+      XXXXXX[2] = letters[v % 62];
+      v /= 62;
+      XXXXXX[3] = letters[v % 62];
+      v /= 62;
+      XXXXXX[4] = letters[v % 62];
+      v /= 62;
+      XXXXXX[5] = letters[v % 62];
+
+      switch (kind)
+        {
+        case __GT_FILE:
+          fd = __open (tmpl,
+                       (flags & ~O_ACCMODE)
+                       | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+          break;
+
+        case __GT_DIR:
+          fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
+          break;
+
+        case __GT_NOCREATE:
+          /* This case is backward from the other three.  __gen_tempname
+             succeeds if __xstat fails because the name does not exist.
+             Note the continue to bypass the common logic at the bottom
+             of the loop.  */
+          if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
+            {
+              if (errno == ENOENT)
+                {
+                  __set_errno (save_errno);
+                  return 0;
+                }
+              else
+                /* Give up now. */
+                return -1;
+            }
+          continue;
+
+        default:
+          assert (! "invalid KIND in __gen_tempname");
+          abort ();
+        }
+
+      if (fd >= 0)
+        {
+          __set_errno (save_errno);
+          return fd;
+        }
+      else if (errno != EEXIST)
+        return -1;
+    }
+
+  /* We got out of the loop because we ran out of combinations to try.  */
+  __set_errno (EEXIST);
+  return -1;
+}
diff --git a/gdb/gnulib/import/tempname.h b/gdb/gnulib/import/tempname.h
new file mode 100644
index 0000000..7972562
--- /dev/null
+++ b/gdb/gnulib/import/tempname.h
@@ -0,0 +1,50 @@
+/* Create a temporary file or directory.
+
+   Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* header written by Eric Blake */
+
+#ifndef GL_TEMPNAME_H
+# define GL_TEMPNAME_H
+
+# include <stdio.h>
+
+# ifdef __GT_FILE
+#  define GT_FILE     __GT_FILE
+#  define GT_DIR      __GT_DIR
+#  define GT_NOCREATE __GT_NOCREATE
+# else
+#  define GT_FILE     0
+#  define GT_DIR      1
+#  define GT_NOCREATE 2
+# endif
+
+/* Generate a temporary file name based on TMPL.  TMPL must match the
+   rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
+   The name constructed does not exist at the time of the call to
+   gen_tempname.  TMPL is overwritten with the result.
+
+   KIND may be one of:
+   GT_NOCREATE:         simply verify that the name does not exist
+                        at the time of the call.
+   GT_FILE:             create a large file using open(O_CREAT|O_EXCL)
+                        and return a read-write fd.  The file is mode 0600.
+   GT_DIR:              create a directory, which will be mode 0700.
+
+   We use a clever algorithm to get hard-to-predict names. */
+extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
+
+#endif /* GL_TEMPNAME_H */
diff --git a/gdb/gnulib/update-gnulib.sh b/gdb/gnulib/update-gnulib.sh
index 04d4283..761786e 100644
--- a/gdb/gnulib/update-gnulib.sh
+++ b/gdb/gnulib/update-gnulib.sh
@@ -41,6 +41,7 @@ IMPORTED_GNULIB_MODULES="\
     lstat \
     memchr \
     memmem \
+    mkdtemp \
     pathmax \
     readlink \
     rename \

[-- Attachment #3: mingw64.errors --]
[-- Type: text/plain, Size: 9018 bytes --]

../../gdb/ser-tcp.c: In function 'wait_for_connect':
../../gdb/ser-tcp.c:137:53: error: passing argument 5 of 'select' from incompatible pointer type [-Werror]
       n = select (scb->fd + 1, &rset, &wset, &eset, &t);
                                                     ^
In file included from ../../gdb/serial.h:23:0,
                 from ../../gdb/ser-tcp.c:21:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h:995:34: note: expected 'PTIMEVAL' but argument is of type 'struct rpl_timeval *'
   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
                                  ^
cc1: all warnings being treated as errors
make[2]: *** [ser-tcp.o] Error 1
../../gdb/symfile.c: In function 'generic_load':
../../gdb/symfile.c:2190:10: error: passing argument 4 of 'print_transfer_performance' from incompatible pointer type [-Werror]
          &start_time, &end_time);
          ^
In file included from ../../gdb/symfile.c:22:0:
../../gdb/defs.h:270:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void print_transfer_performance (struct ui_file *stream,
             ^
../../gdb/symfile.c:2190:23: error: passing argument 5 of 'print_transfer_performance' from incompatible pointer type [-Werror]
          &start_time, &end_time);
                       ^
In file included from ../../gdb/symfile.c:22:0:
../../gdb/defs.h:270:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void print_transfer_performance (struct ui_file *stream,
             ^
../../gdb/symfile.c: At top level:
../../gdb/symfile.c:2198:1: error: conflicting types for 'print_transfer_performance'
 print_transfer_performance (struct ui_file *stream,
 ^
In file included from ../../gdb/symfile.c:22:0:
../../gdb/defs.h:270:13: note: previous declaration of 'print_transfer_performance' was here
 extern void print_transfer_performance (struct ui_file *stream,
             ^
../../gdb/symfile.c:3567:10: error: 'SIZE' redeclared as different kind of symbol
     VMA, SIZE, LMA, MAPPED
          ^
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/windows.h:69:0,
                 from /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h:23,
                 from build-gnulib/import/sys/time.h:49,
                 from ../../gdb/symfile.c:65:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/windef.h:102:3: note: previous declaration of 'SIZE' was here
 } SIZE,*PSIZE,*LPSIZE;
   ^
cc1: all warnings being treated as errors
make[2]: *** [symfile.o] Error 1
../../gdb/maint.c: In function 'report_command_stats':
../../gdb/maint.c:874:17: error: incompatible types when assigning to type 'struct rpl_timeval' from type 'struct timeval'
       wait_time = get_prompt_for_continue_wait_time ();
                 ^
make[2]: *** [maint.o] Error 1
../../gdb/utils.c: In function 'defaulted_query':
../../gdb/utils.c:1349:16: error: passing argument 1 of 'timeval_sub' from incompatible pointer type [-Werror]
   timeval_sub (&prompt_delta, &prompt_ended, &prompt_started);
                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:33:13: note: expected 'struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_sub (struct timeval *result,
             ^
../../gdb/utils.c:1349:31: error: passing argument 2 of 'timeval_sub' from incompatible pointer type [-Werror]
   timeval_sub (&prompt_delta, &prompt_ended, &prompt_started);
                               ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:33:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_sub (struct timeval *result,
             ^
../../gdb/utils.c:1349:46: error: passing argument 3 of 'timeval_sub' from incompatible pointer type [-Werror]
   timeval_sub (&prompt_delta, &prompt_ended, &prompt_started);
                                              ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:33:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_sub (struct timeval *result,
             ^
../../gdb/utils.c:1350:16: error: passing argument 1 of 'timeval_add' from incompatible pointer type [-Werror]
   timeval_add (&prompt_for_continue_wait_time,
                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:30:13: note: expected 'struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_add (struct timeval *result,
             ^
../../gdb/utils.c:1351:16: error: passing argument 2 of 'timeval_add' from incompatible pointer type [-Werror]
                &prompt_for_continue_wait_time, &prompt_delta);
                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:30:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_add (struct timeval *result,
             ^
../../gdb/utils.c:1351:48: error: passing argument 3 of 'timeval_add' from incompatible pointer type [-Werror]
                &prompt_for_continue_wait_time, &prompt_delta);
                                                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:30:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_add (struct timeval *result,
             ^
../../gdb/utils.c: In function 'prompt_for_continue':
../../gdb/utils.c:1878:16: error: passing argument 1 of 'timeval_sub' from incompatible pointer type [-Werror]
   timeval_sub (&prompt_delta, &prompt_ended, &prompt_started);
                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:33:13: note: expected 'struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_sub (struct timeval *result,
             ^
../../gdb/utils.c:1878:31: error: passing argument 2 of 'timeval_sub' from incompatible pointer type [-Werror]
   timeval_sub (&prompt_delta, &prompt_ended, &prompt_started);
                               ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:33:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_sub (struct timeval *result,
             ^
../../gdb/utils.c:1878:46: error: passing argument 3 of 'timeval_sub' from incompatible pointer type [-Werror]
   timeval_sub (&prompt_delta, &prompt_ended, &prompt_started);
                                              ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:33:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_sub (struct timeval *result,
             ^
../../gdb/utils.c:1879:16: error: passing argument 1 of 'timeval_add' from incompatible pointer type [-Werror]
   timeval_add (&prompt_for_continue_wait_time,
                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:30:13: note: expected 'struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_add (struct timeval *result,
             ^
../../gdb/utils.c:1880:16: error: passing argument 2 of 'timeval_add' from incompatible pointer type [-Werror]
                &prompt_for_continue_wait_time, &prompt_delta);
                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:30:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_add (struct timeval *result,
             ^
../../gdb/utils.c:1880:48: error: passing argument 3 of 'timeval_add' from incompatible pointer type [-Werror]
                &prompt_for_continue_wait_time, &prompt_delta);
                                                ^
In file included from ../../gdb/utils.c:41:0:
../../gdb/../include/timeval-utils.h:30:13: note: expected 'const struct timeval *' but argument is of type 'struct rpl_timeval *'
 extern void timeval_add (struct timeval *result,
             ^
../../gdb/utils.c: At top level:
../../gdb/utils.c:1917:1: error: conflicting types for 'get_prompt_for_continue_wait_time'
 get_prompt_for_continue_wait_time (void)
 ^
In file included from ../../gdb/defs.h:706:0,
                 from ../../gdb/utils.c:20:
../../gdb/utils.h:58:16: note: previous declaration of 'get_prompt_for_continue_wait_time' was here
 struct timeval get_prompt_for_continue_wait_time (void);
                ^
cc1: all warnings being treated as errors
make[2]: *** [utils.o] Error 1
make[2]: Target 'all' not remade because of errors.
make[1]: *** [all-gdb] Error 2
make[1]: Target 'all-host' not remade because of errors.
make: *** [all] Error 2

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-14 18:24         ` [mingw rfc] Add mkdtemp to gdb/gnulib/ [Re: [PATCH v4 14/14] the "compile" command] Jan Kratochvil
@ 2014-12-15  3:16           ` Yao Qi
  2014-12-15 12:44             ` Joel Brobecker
  0 siblings, 1 reply; 93+ messages in thread
From: Yao Qi @ 2014-12-15  3:16 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Kai Tietz

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> But mingw-w64 64-bit target would build OK (after commenting out the mkdtemp()
> call) before adding the gnulib mkdtemp module.  But after the gnulib mkdtemp
> addition there are many errors (attached as the second attachment).  It is all
> about
> 	struct timeval *
> vs.
> 	struct rpl_timeval *
> but an advice from mingw64 aware hacker would be nice to know what to do.

Hi Jan,
I can reproduce your build failure with x86_64-w64-mingw32-gcc too.
Looks gnulib sys_time module needs update, or maybe we have to use win32
api, such as GetTempPath and GetRandomFileName.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 12/14] add linux_infcall_mmap
  2014-11-23 19:28 ` [PATCH v4 12/14] add linux_infcall_mmap Jan Kratochvil
@ 2014-12-15 12:41   ` Ulrich Weigand
  2014-12-15 13:49     ` Yao Qi
  0 siblings, 1 reply; 93+ messages in thread
From: Ulrich Weigand @ 2014-12-15 12:41 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Jan Kratochvil wrote:

> +  enum
> +    {
> +      ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, ARG_MAX
> +    };
> +  struct value *arg[ARG_MAX];

This causes:
/home/uweigand/dailybuild/spu-tc-2014-12-13/binutils-gdb-head/binutils-gdb/gdb/linux-tdep.c: In function 'linux_infcall_mmap':
/home/uweigand/dailybuild/spu-tc-2014-12-13/binutils-gdb-head/binutils-gdb/gdb/linux-tdep.c:1945: error: expected identifier before numeric constant

on my RHEL 5 build system, presumably because ARG_MAX is defined 
(to a numeric constant) by a system header.

Can we give those more distinctive names?

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15  3:16           ` Yao Qi
@ 2014-12-15 12:44             ` Joel Brobecker
  2014-12-15 13:11               ` Kai Tietz
                                 ` (2 more replies)
  0 siblings, 3 replies; 93+ messages in thread
From: Joel Brobecker @ 2014-12-15 12:44 UTC (permalink / raw)
  To: Yao Qi; +Cc: Jan Kratochvil, gdb-patches, Kai Tietz

Hi Yao,

> I can reproduce your build failure with x86_64-w64-mingw32-gcc too.
> Looks gnulib sys_time module needs update, or maybe we have to use win32
> api, such as GetTempPath and GetRandomFileName.

Do you mean that the problem is solved with a more recent version
of gnulib?

I would personally take a two-step approach: First, immediately
fix the build issue using the second recommendation you made, which
is to use win32 routines on Windows hosts for now.  Then, we can
work towards first upgrading gnulib, and then importing mkdtemp.
I find that updating gnulib to always be fairly disruptive, which
is why I propose we stabilize the problem first to get builds
working back ASAP, and then look at gnulib.

-- 
Joel

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 12:44             ` Joel Brobecker
@ 2014-12-15 13:11               ` Kai Tietz
  2014-12-15 13:24               ` Yao Qi
  2014-12-15 17:12               ` Jan Kratochvil
  2 siblings, 0 replies; 93+ messages in thread
From: Kai Tietz @ 2014-12-15 13:11 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Yao Qi, Jan Kratochvil, gdb-patches

Hi,

----- Ursprüngliche Mail -----
> Hi Yao,
> 
> > I can reproduce your build failure with x86_64-w64-mingw32-gcc too.
> > Looks gnulib sys_time module needs update, or maybe we have to use win32
> > api, such as GetTempPath and GetRandomFileName.
> 
> Do you mean that the problem is solved with a more recent version
> of gnulib?
> 
> I would personally take a two-step approach: First, immediately
> fix the build issue using the second recommendation you made, which
> is to use win32 routines on Windows hosts for now.  Then, we can
> work towards first upgrading gnulib, and then importing mkdtemp.
> I find that updating gnulib to always be fairly disruptive, which
> is why I propose we stabilize the problem first to get builds
> working back ASAP, and then look at gnulib.
> 
> --
> Joel
> 

I fully agree with Joel.

Kai

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 12:44             ` Joel Brobecker
  2014-12-15 13:11               ` Kai Tietz
@ 2014-12-15 13:24               ` Yao Qi
  2014-12-15 17:12               ` Jan Kratochvil
  2 siblings, 0 replies; 93+ messages in thread
From: Yao Qi @ 2014-12-15 13:24 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Jan Kratochvil, gdb-patches, Kai Tietz

Joel Brobecker <brobecker@adacore.com> writes:

> Do you mean that the problem is solved with a more recent version
> of gnulib?

No, that isn't what I meant.  What I mean by "update" is to fix the
problem in gnulib sys_time and update gnulib import.  Sorry for the confusion.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 12/14] add linux_infcall_mmap
  2014-12-15 12:41   ` Ulrich Weigand
@ 2014-12-15 13:49     ` Yao Qi
  2014-12-15 16:48       ` Jan Kratochvil
  0 siblings, 1 reply; 93+ messages in thread
From: Yao Qi @ 2014-12-15 13:49 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Jan Kratochvil, gdb-patches

Ulrich Weigand <uweigand@de.ibm.com> writes:

> /home/uweigand/dailybuild/spu-tc-2014-12-13/binutils-gdb-head/binutils-gdb/gdb/linux-tdep.c:
> In function 'linux_infcall_mmap':
> /home/uweigand/dailybuild/spu-tc-2014-12-13/binutils-gdb-head/binutils-gdb/gdb/linux-tdep.c:1945:
> error: expected identifier before numeric constant
>
> on my RHEL 5 build system, presumably because ARG_MAX is defined 
> (to a numeric constant) by a system header.
>
> Can we give those more distinctive names?

I got the same problem.  Patch below unblocks the build.

-- 
Yao (齐尧)

From: Yao Qi <yao@codesourcery.com>
Date: Mon, 15 Dec 2014 21:40:29 +0800
Subject: [PATCH] Replace ARG_MAX with ARG_LAST

We define an enum ARG_MAX in linux_infcall_mmap, but it is conflict
with macro ARG_MAX which is defined in /usr/include/linux/limits.h.
This causes a build failure below,

 gdb/linux-tdep.c: In function 'linux_infcall_mmap':
 gdb/linux-tdep.c:1945:70: error: expected identifier before numeric constant

the enum in the pre-processed source becomes:

  enum
    {
      ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, 131072
    };

This patch is to replace ARG_MAX with ARG_LAST.

gdb:

2014-12-15  Yao Qi  <yao@codesourcery.com>

	* linux-tdep.c (linux_infcall_mmap): Replace ARG_MAX with
	ARG_LAST.
---
 gdb/linux-tdep.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 485f5ca..6b5e475 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1942,9 +1942,9 @@ linux_infcall_mmap (CORE_ADDR size, unsigned prot)
   CORE_ADDR retval;
   enum
     {
-      ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, ARG_MAX
+      ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, ARG_LAST
     };
-  struct value *arg[ARG_MAX];
+  struct value *arg[ARG_LAST];
 
   arg[ARG_ADDR] = value_from_pointer (builtin_type (gdbarch)->builtin_data_ptr,
 				      0);
@@ -1961,7 +1961,7 @@ linux_infcall_mmap (CORE_ADDR size, unsigned prot)
   arg[ARG_FD] = value_from_longest (builtin_type (gdbarch)->builtin_int, -1);
   arg[ARG_OFFSET] = value_from_longest (builtin_type (gdbarch)->builtin_int64,
 					0);
-  addr_val = call_function_by_hand (mmap_val, ARG_MAX, arg);
+  addr_val = call_function_by_hand (mmap_val, ARG_LAST, arg);
   retval = value_as_address (addr_val);
   if (retval == (CORE_ADDR) -1)
     error (_("Failed inferior mmap call for %s bytes, errno is changed."),
-- 
1.9.3

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 12/14] add linux_infcall_mmap
  2014-12-15 13:49     ` Yao Qi
@ 2014-12-15 16:48       ` Jan Kratochvil
  2014-12-16  5:27         ` Yao Qi
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-15 16:48 UTC (permalink / raw)
  To: Yao Qi; +Cc: Ulrich Weigand, gdb-patches

On Mon, 15 Dec 2014 14:49:15 +0100, Yao Qi wrote:
> I got the same problem.  Patch below unblocks the build.

I am sure fine with this patch.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 12:44             ` Joel Brobecker
  2014-12-15 13:11               ` Kai Tietz
  2014-12-15 13:24               ` Yao Qi
@ 2014-12-15 17:12               ` Jan Kratochvil
  2014-12-15 17:48                 ` Eli Zaretskii
  2014-12-15 18:14                 ` Joel Brobecker
  2 siblings, 2 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-15 17:12 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Yao Qi, gdb-patches, Kai Tietz

On Mon, 15 Dec 2014 13:43:58 +0100, Joel Brobecker wrote:
> I would personally take a two-step approach: First, immediately
> fix the build issue using the second recommendation you made, which
> is to use win32 routines on Windows hosts for now.  Then, we can
> work towards first upgrading gnulib, and then importing mkdtemp.
> I find that updating gnulib to always be fairly disruptive, which
> is why I propose we stabilize the problem first to get builds
> working back ASAP, and then look at gnulib.

Does it mean that after upgrading gnulib we can drop the MS-Windows host
routines (which need to be written yet) again?

IMO a more clean solution would be s/gdb_select/select/g, drop gdb_select from
mingw-hdep.c and import gnulib select instead which handles what gdb_select is
there fore, hopefully more transparently.  But I haven't tried any of that.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 17:12               ` Jan Kratochvil
@ 2014-12-15 17:48                 ` Eli Zaretskii
  2014-12-15 18:14                 ` Joel Brobecker
  1 sibling, 0 replies; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-15 17:48 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: brobecker, yao, gdb-patches, ktietz

> Date: Mon, 15 Dec 2014 18:12:25 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Yao Qi <yao@codesourcery.com>, gdb-patches@sourceware.org,        Kai Tietz <ktietz@redhat.com>
> 
> Does it mean that after upgrading gnulib we can drop the MS-Windows host
> routines (which need to be written yet) again?
> 
> IMO a more clean solution would be s/gdb_select/select/g, drop gdb_select from
> mingw-hdep.c and import gnulib select instead which handles what gdb_select is
> there fore, hopefully more transparently.  But I haven't tried any of that.

Beware: each such replacement must be carefully studied before
concluding that it is what we want.  In particular, Gnulib's 'select'
is a "package deal": when you import it, you get more than what you
asked for.  Some potential issues are with blocking/non-blocking
sockets and anonymous pipes.

IOW, it's not an easy decision, at least not with 'select'.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 17:12               ` Jan Kratochvil
  2014-12-15 17:48                 ` Eli Zaretskii
@ 2014-12-15 18:14                 ` Joel Brobecker
  2014-12-15 18:21                   ` Jan Kratochvil
  1 sibling, 1 reply; 93+ messages in thread
From: Joel Brobecker @ 2014-12-15 18:14 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Yao Qi, gdb-patches, Kai Tietz

> Does it mean that after upgrading gnulib we can drop the MS-Windows host
> routines (which need to be written yet) again?

Provided that the corresponding gnulib modules can in fact be
imported without problem, then my answer would be yes. As you
found out, it often does not work that way. So far, if you look
at your update, and yao's update not so long ago, it's 3 breakages
(I found 2, you found 1).  gnulib provides a really nice abstraction
layer, but it does not always work the way we hoped!

> IMO a more clean solution would be s/gdb_select/select/g, drop
> gdb_select from mingw-hdep.c and import gnulib select instead which
> handles what gdb_select is there fore, hopefully more transparently.
> But I haven't tried any of that.

As Eli pointed out, it's not necessarily an easy change. I don't
see the relation between select and mkdtemp, but maybe I missed
something.

-- 
Joel

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 18:14                 ` Joel Brobecker
@ 2014-12-15 18:21                   ` Jan Kratochvil
  2014-12-15 18:35                     ` Joel Brobecker
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-15 18:21 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Yao Qi, gdb-patches, Kai Tietz

On Mon, 15 Dec 2014 19:14:49 +0100, Joel Brobecker wrote:
> > Does it mean that after upgrading gnulib we can drop the MS-Windows host
> > routines (which need to be written yet) again?
> 
> Provided that the corresponding gnulib modules can in fact be
> imported without problem, then my answer would be yes.

Could someone write the MS-Windows calling code.  I can try that myself but I
cannot test it much, from what I tried in the past gdb.exe does not work much
under Wine.


> As Eli pointed out, it's not necessarily an easy change.

OK.


> I don't > see the relation between select and mkdtemp, but maybe I missed
> something.

Importing mkdtemp from gnulib broke select() calls:

On Sun, 14 Dec 2014 19:23:41 +0100, Jan Kratochvil wrote:
# But after the gnulib mkdtemp
# addition there are many errors (attached as the second attachment).  It is all
# about
#       struct timeval *
# vs.
#       struct rpl_timeval *


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 18:21                   ` Jan Kratochvil
@ 2014-12-15 18:35                     ` Joel Brobecker
  2014-12-15 18:40                       ` Jan Kratochvil
  0 siblings, 1 reply; 93+ messages in thread
From: Joel Brobecker @ 2014-12-15 18:35 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Yao Qi, gdb-patches, Kai Tietz

> > Provided that the corresponding gnulib modules can in fact be
> > imported without problem, then my answer would be yes.
> 
> Could someone write the MS-Windows calling code.  I can try that myself but I
> cannot test it much, from what I tried in the past gdb.exe does not work much
> under Wine.

The replacement for mkdtemp?

-- 
Joel

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 18:35                     ` Joel Brobecker
@ 2014-12-15 18:40                       ` Jan Kratochvil
  2014-12-15 18:57                         ` Eli Zaretskii
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-15 18:40 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Yao Qi, gdb-patches, Kai Tietz

On Mon, 15 Dec 2014 19:35:54 +0100, Joel Brobecker wrote:
> > Could someone write the MS-Windows calling code.  I can try that myself but I
                                                   ?
> > cannot test it much, from what I tried in the past gdb.exe does not work much
> > under Wine.
> 
> The replacement for mkdtemp?

Yes:

On Mon, 15 Dec 2014 04:15:43 +0100, Yao Qi wrote:
# or maybe we have to use win32 api, such as GetTempPath and GetRandomFileName.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [mingw rfc] Add mkdtemp to gdb/gnulib/  [Re: [PATCH v4 14/14] the "compile" command]
  2014-12-15 18:40                       ` Jan Kratochvil
@ 2014-12-15 18:57                         ` Eli Zaretskii
  2014-12-15 22:28                           ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Jan Kratochvil
  0 siblings, 1 reply; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-15 18:57 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: brobecker, yao, gdb-patches, ktietz

> Date: Mon, 15 Dec 2014 19:40:14 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Yao Qi <yao@codesourcery.com>, gdb-patches@sourceware.org,        Kai Tietz <ktietz@redhat.com>
> 
> On Mon, 15 Dec 2014 19:35:54 +0100, Joel Brobecker wrote:
> > > Could someone write the MS-Windows calling code.  I can try that myself but I
>                                                    ?
> > > cannot test it much, from what I tried in the past gdb.exe does not work much
> > > under Wine.
> > 
> > The replacement for mkdtemp?
> 
> Yes:
> 
> On Mon, 15 Dec 2014 04:15:43 +0100, Yao Qi wrote:
> # or maybe we have to use win32 api, such as GetTempPath and GetRandomFileName.

If you write it, I can test it.

Or I can write it myself, but then it will take a few days.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-15 18:57                         ` Eli Zaretskii
@ 2014-12-15 22:28                           ` Jan Kratochvil
  2014-12-15 22:56                             ` Jan Kratochvil
                                               ` (4 more replies)
  0 siblings, 5 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-15 22:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: brobecker, yao, gdb-patches, ktietz

[-- Attachment #1: Type: text/plain, Size: 1147 bytes --]

On Mon, 15 Dec 2014 19:57:28 +0100, Eli Zaretskii wrote:
> > On Mon, 15 Dec 2014 04:15:43 +0100, Yao Qi wrote:
> > # or maybe we have to use win32 api, such as GetTempPath and GetRandomFileName.
> 
> If you write it, I can test it.

In the end I have managed to test it by Wine myself:

$ wine build_win32/gdb/gdb.exe -q build_win32/gdb/gdb.exe -ex start -ex 'compile code 1' -ex 'set confirm no' -ex quit
[...]
Temporary breakpoint 1, main (argc=1, argv=0x241418) at ../../gdb/gdb.c:29
29	  args.argc = argc;
Could not load libcc1.so: Module not found.

Even if it managed to load libcc1.so (it needs host-dependent name libcc1.dll)
then it would soon end up at least on:

default_infcall_mmap:
  error (_("This target does not support inferior memory allocation by mmap."));

As currently there is only:

linux-tdep.c:
  set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);

While one could debug Linux targets from MS-Windows host I find it somehow
overcomplicated now when we are trying to get it running at least on native
Linux x86*.

The 'compile' project needs a larger port effort to run on MS-Windows.

OK for check-in?


Thanks,
Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 627 bytes --]

gdb/ChangeLog
2014-12-15  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix MinGW compilation.
	* compile/compile.c (get_compile_file_tempdir): Call error on _WIN32.

--- ./gdb/compile/compile.c	2014-12-14 02:48:38.000000000 +0100
+++ ./gdb/compile/compile.c	2014-12-15 23:21:28.788716340 +0100
@@ -191,7 +191,11 @@ get_compile_file_tempdir (void)
 
   strcpy (tname, TEMPLATE);
 #undef TEMPLATE
+#ifdef _WIN32
+  error (_("mkdtemp needs to be implemented for MS-Windows hosts"));
+#else
   tempdir_name = mkdtemp (tname);
+#endif
   if (tempdir_name == NULL)
     perror_with_name (_("Could not make temporary directory"));
 

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-15 22:28                           ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Jan Kratochvil
@ 2014-12-15 22:56                             ` Jan Kratochvil
  2014-12-16  3:40                               ` Eli Zaretskii
  2014-12-16  3:37                             ` Eli Zaretskii
                                               ` (3 subsequent siblings)
  4 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-15 22:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: brobecker, yao, gdb-patches, ktietz

On Mon, 15 Dec 2014 23:28:01 +0100, Jan Kratochvil wrote:
> The 'compile' project needs a larger port effort to run on MS-Windows.

For example there is also

compile/compile.c:
  zap = concat ("rm -rf ", dir, (char *) NULL);
  system (zap);

which is AFAIK a no-go on MinGW.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-15 22:28                           ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Jan Kratochvil
  2014-12-15 22:56                             ` Jan Kratochvil
@ 2014-12-16  3:37                             ` Eli Zaretskii
  2014-12-16  9:06                               ` Kai Tietz
  2014-12-17 19:18                               ` Jan Kratochvil
  2014-12-16 12:40                             ` Pierre Muller
                                               ` (2 subsequent siblings)
  4 siblings, 2 replies; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-16  3:37 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: brobecker, yao, gdb-patches, ktietz

> Date: Mon, 15 Dec 2014 23:28:01 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org,
>         ktietz@redhat.com
> 
> Even if it managed to load libcc1.so (it needs host-dependent name libcc1.dll)
> then it would soon end up at least on:
> 
> default_infcall_mmap:
>   error (_("This target does not support inferior memory allocation by mmap."));
> 
> As currently there is only:
> 
> linux-tdep.c:
>   set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);

Why is mmap needed here?

> OK for check-in?
> 
> 
> Thanks,
> Jan
> gdb/ChangeLog
> 2014-12-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	Fix MinGW compilation.
> 	* compile/compile.c (get_compile_file_tempdir): Call error on _WIN32.
> 
> --- ./gdb/compile/compile.c	2014-12-14 02:48:38.000000000 +0100
> +++ ./gdb/compile/compile.c	2014-12-15 23:21:28.788716340 +0100
> @@ -191,7 +191,11 @@ get_compile_file_tempdir (void)
>  
>    strcpy (tname, TEMPLATE);
>  #undef TEMPLATE
> +#ifdef _WIN32
> +  error (_("mkdtemp needs to be implemented for MS-Windows hosts"));
> +#else
>    tempdir_name = mkdtemp (tname);
> +#endif
>    if (tempdir_name == NULL)
>      perror_with_name (_("Could not make temporary directory"));

I think _WIN32 will catch Cygwin as well, which is not what you want.

Why not just check HAVE_MKDTEMP?

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-15 22:56                             ` Jan Kratochvil
@ 2014-12-16  3:40                               ` Eli Zaretskii
  2014-12-16  9:04                                 ` Kai Tietz
  2014-12-17 17:30                                 ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Steve Ellcey
  0 siblings, 2 replies; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-16  3:40 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: brobecker, yao, gdb-patches, ktietz

> Date: Mon, 15 Dec 2014 23:55:51 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org,
>         ktietz@redhat.com
> 
> On Mon, 15 Dec 2014 23:28:01 +0100, Jan Kratochvil wrote:
> > The 'compile' project needs a larger port effort to run on MS-Windows.
> 
> For example there is also
> 
> compile/compile.c:
>   zap = concat ("rm -rf ", dir, (char *) NULL);
>   system (zap);

Yuck!  Do we really allow such atrocities in GDB?  What if 'rm' is
some unrelated or even malicious script?

I think this should be replaced by suitable C function calls.  IMO,
this kind of programming is OK for prototyping, but not for the final
code.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [PATCH v4 12/14] add linux_infcall_mmap
  2014-12-15 16:48       ` Jan Kratochvil
@ 2014-12-16  5:27         ` Yao Qi
  0 siblings, 0 replies; 93+ messages in thread
From: Yao Qi @ 2014-12-16  5:27 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ulrich Weigand, gdb-patches

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> I am sure fine with this patch.

Patch is pushed in.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-16  3:40                               ` Eli Zaretskii
@ 2014-12-16  9:04                                 ` Kai Tietz
  2014-12-17 21:02                                   ` [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Jan Kratochvil
  2014-12-17 17:30                                 ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Steve Ellcey
  1 sibling, 1 reply; 93+ messages in thread
From: Kai Tietz @ 2014-12-16  9:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Jan Kratochvil, brobecker, yao, gdb-patches



----- Ursprüngliche Mail -----
> > Date: Mon, 15 Dec 2014 23:55:51 +0100
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> > Cc: brobecker@adacore.com, yao@codesourcery.com,
> > gdb-patches@sourceware.org,
> >         ktietz@redhat.com
> > 
> > On Mon, 15 Dec 2014 23:28:01 +0100, Jan Kratochvil wrote:
> > > The 'compile' project needs a larger port effort to run on MS-Windows.
> > 
> > For example there is also
> > 
> > compile/compile.c:
> >   zap = concat ("rm -rf ", dir, (char *) NULL);
> >   system (zap);
> 
> Yuck!  Do we really allow such atrocities in GDB?  What if 'rm' is
> some unrelated or even malicious script?
> 
> I think this should be replaced by suitable C function calls.  IMO,
> this kind of programming is OK for prototyping, but not for the final
> code.
> 

Ouch, to use console is for sure a bad thing.  To use POSIX-shell commands is even worse.  Why not using here instead an implementation using FTW-API?  At least mingw-w64 added this API recently to runtime for gcc's sake, so implementation of an 'rm -rf' should be pretty easy.

Kai

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-16  3:37                             ` Eli Zaretskii
@ 2014-12-16  9:06                               ` Kai Tietz
  2014-12-17 19:18                               ` Jan Kratochvil
  1 sibling, 0 replies; 93+ messages in thread
From: Kai Tietz @ 2014-12-16  9:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Jan Kratochvil, brobecker, yao, gdb-patches

----- Ursprüngliche Mail -----
> > Date: Mon, 15 Dec 2014 23:28:01 +0100
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> > Cc: brobecker@adacore.com, yao@codesourcery.com,
> > gdb-patches@sourceware.org,
> >         ktietz@redhat.com
> > 
> > Even if it managed to load libcc1.so (it needs host-dependent name
> > libcc1.dll)
> > then it would soon end up at least on:
> > 
> > default_infcall_mmap:
> >   error (_("This target does not support inferior memory allocation by
> >   mmap."));
> > 
> > As currently there is only:
> > 
> > linux-tdep.c:
> >   set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);
> 
> Why is mmap needed here?
> 
> > OK for check-in?
> > 
> > 
> > Thanks,
> > Jan
> > gdb/ChangeLog
> > 2014-12-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
> > 
> > 	Fix MinGW compilation.
> > 	* compile/compile.c (get_compile_file_tempdir): Call error on _WIN32.
> > 
> > --- ./gdb/compile/compile.c	2014-12-14 02:48:38.000000000 +0100
> > +++ ./gdb/compile/compile.c	2014-12-15 23:21:28.788716340 +0100
> > @@ -191,7 +191,11 @@ get_compile_file_tempdir (void)
> >  
> >    strcpy (tname, TEMPLATE);
> >  #undef TEMPLATE
> > +#ifdef _WIN32
> > +  error (_("mkdtemp needs to be implemented for MS-Windows hosts"));
> > +#else
> >    tempdir_name = mkdtemp (tname);
> > +#endif
> >    if (tempdir_name == NULL)
> >      perror_with_name (_("Could not make temporary directory"));
> 
> I think _WIN32 will catch Cygwin as well, which is not what you want.
> 
> Why not just check HAVE_MKDTEMP?
> 

Well, _WIN32 isn't set necessarily for Cygwin.  For Cygwin this define is just set if the windows.h header got included AFAIK.  Anyway, there are better ways to check, and indeed HAVE_MKDTEMP seems to be the most correct check, isn't it?

Kai

^ permalink raw reply	[flat|nested] 93+ messages in thread

* RE: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-15 22:28                           ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Jan Kratochvil
  2014-12-15 22:56                             ` Jan Kratochvil
  2014-12-16  3:37                             ` Eli Zaretskii
@ 2014-12-16 12:40                             ` Pierre Muller
  2014-12-17 18:21                               ` Jan Kratochvil
  2014-12-17  1:22                             ` Yao Qi
  2014-12-17 11:16                             ` Pedro Alves
  4 siblings, 1 reply; 93+ messages in thread
From: Pierre Muller @ 2014-12-16 12:40 UTC (permalink / raw)
  To: 'Jan Kratochvil', 'Eli Zaretskii'
  Cc: brobecker, yao, gdb-patches, ktietz

  Hi Jan,

  I tested your patch,
which appeared as an attached file named 1.sql,
which made it difficult to guess it was indeed the patch...

  Nevertheless, your patch fixes compilation error for mingw32
and as such it should be committed as an obvious fix.

  To go a little bit further, I tried to use 
the compile command on the newly generated mingw32 GDB executable.
 
using ./gdb ./gdb
(with a minimal hello.c source code)

<<<<  (top-gdb) compile code hello.c
returns
>>>> The program must be running for the compile command to work.
I am not sure why this restriction should apply.

 (top-gdb) start
Temporary breakpoint 3 at 0x40158a: file ../../../binutils-gdb/gdb/gdb.c, line 28.
Starting program: E:\cygwin-32\home\Pierre\git\build\mult-mingw32\gdb\gdb.exe
[New Thread 6572.0x4e0]

Temporary breakpoint 3, main (argc=1, argv=0x3d4b30)
    at ../../../binutils-gdb/gdb/gdb.c:28
 (top-gdb) compile file hello.c
Could not load libcc1.so: "libcc1.so": Le module spécifié est introuvable.
 (French meaning: "the specified module can't be found").

  So the mkdtmp is not the only problem 
for mingw compile support.


Pierre Muller

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-15 22:28                           ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Jan Kratochvil
                                               ` (2 preceding siblings ...)
  2014-12-16 12:40                             ` Pierre Muller
@ 2014-12-17  1:22                             ` Yao Qi
  2014-12-17 10:57                               ` Pedro Alves
  2014-12-17 11:16                             ` Pedro Alves
  4 siblings, 1 reply; 93+ messages in thread
From: Yao Qi @ 2014-12-17  1:22 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Eli Zaretskii, brobecker, gdb-patches, ktietz

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> In the end I have managed to test it by Wine myself:
>
> $ wine build_win32/gdb/gdb.exe -q build_win32/gdb/gdb.exe -ex start
> -ex 'compile code 1' -ex 'set confirm no' -ex quit
> [...]
> Temporary breakpoint 1, main (argc=1, argv=0x241418) at ../../gdb/gdb.c:29
> 29	  args.argc = argc;
> Could not load libcc1.so: Module not found.
>
> Even if it managed to load libcc1.so (it needs host-dependent name libcc1.dll)
> then it would soon end up at least on:
>
> default_infcall_mmap:
>   error (_("This target does not support inferior memory allocation by mmap."));
>
> As currently there is only:
>
> linux-tdep.c:
>   set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);

The module not found problem and unsupported mmap problem are separated
ones.  They are not related to the mkdtemp problem we are discussing
here, IMO.

>
> While one could debug Linux targets from MS-Windows host I find it somehow
> overcomplicated now when we are trying to get it running at least on native
> Linux x86*.
>
> The 'compile' project needs a larger port effort to run on MS-Windows.

If 'compile' feature on mingw/Windows doesn't work, why don't we disable
it on Windows?

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17  1:22                             ` Yao Qi
@ 2014-12-17 10:57                               ` Pedro Alves
  2014-12-17 11:40                                 ` Yao Qi
  0 siblings, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-17 10:57 UTC (permalink / raw)
  To: Yao Qi, Jan Kratochvil; +Cc: Eli Zaretskii, brobecker, gdb-patches, ktietz

On 12/17/2014 01:21 AM, Yao Qi wrote:
>> >
>> > While one could debug Linux targets from MS-Windows host I find it somehow
>> > overcomplicated now when we are trying to get it running at least on native
>> > Linux x86*.
>> >
>> > The 'compile' project needs a larger port effort to run on MS-Windows.
> If 'compile' feature on mingw/Windows doesn't work, why don't we disable
> it on Windows?

You mean, not compile the whole set of compile/ files on Windows?  I think we're
not that far off from making the command usable on all hosts.  I'd rather keep
it building everywhere, and guard the specific bits that need porting
or better abstractions guarded with #if HAVE_FOO.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-15 22:28                           ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Jan Kratochvil
                                               ` (3 preceding siblings ...)
  2014-12-17  1:22                             ` Yao Qi
@ 2014-12-17 11:16                             ` Pedro Alves
  2014-12-17 18:17                               ` [patchv2] " Jan Kratochvil
  4 siblings, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-17 11:16 UTC (permalink / raw)
  To: Jan Kratochvil, Eli Zaretskii; +Cc: brobecker, yao, gdb-patches, ktietz

On 12/15/2014 10:28 PM, Jan Kratochvil wrote:
> On Mon, 15 Dec 2014 19:57:28 +0100, Eli Zaretskii wrote:
>>> On Mon, 15 Dec 2014 04:15:43 +0100, Yao Qi wrote:
>>> # or maybe we have to use win32 api, such as GetTempPath and GetRandomFileName.
>>
>> If you write it, I can test it.
> 
> In the end I have managed to test it by Wine myself:
> 
> $ wine build_win32/gdb/gdb.exe -q build_win32/gdb/gdb.exe -ex start -ex 'compile code 1' -ex 'set confirm no' -ex quit
> [...]
> Temporary breakpoint 1, main (argc=1, argv=0x241418) at ../../gdb/gdb.c:29
> 29	  args.argc = argc;
> Could not load libcc1.so: Module not found.
> 
> Even if it managed to load libcc1.so (it needs host-dependent name libcc1.dll)
> then it would soon end up at least on:
> 
> default_infcall_mmap:
>   error (_("This target does not support inferior memory allocation by mmap."));
> 
> As currently there is only:
> 
> linux-tdep.c:
>   set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);
> 
> While one could debug Linux targets from MS-Windows host I find it somehow
> overcomplicated now when we are trying to get it running at least on native
> Linux x86*.
> 
> The 'compile' project needs a larger port effort to run on MS-Windows.
> 
> OK for check-in?

Can you send a version that does an autoconf check for mkdtemp instead?

> +  error (_("mkdtemp needs to be implemented for MS-Windows hosts"));

I think the error text should be a bit more generic and not mention a
particular implementation detail, like "Command not supported on this host." or
some such -- I think the testsuite will need to be extended to handle this error,
presumably in skip_compile_feature_tests.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 10:57                               ` Pedro Alves
@ 2014-12-17 11:40                                 ` Yao Qi
  2014-12-17 11:43                                   ` Pedro Alves
  0 siblings, 1 reply; 93+ messages in thread
From: Yao Qi @ 2014-12-17 11:40 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Jan Kratochvil, Eli Zaretskii, brobecker, gdb-patches, ktietz

Pedro Alves <palves@redhat.com> writes:

> You mean, not compile the whole set of compile/ files on Windows?  I think we're

Yes.

> not that far off from making the command usable on all hosts.  I'd rather keep
> it building everywhere, and guard the specific bits that need porting
> or better abstractions guarded with #if HAVE_FOO.

At least, user should get an explicit message that 'compile' command
isn't supported if the user run the 'compile' command on Windows for example.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 11:40                                 ` Yao Qi
@ 2014-12-17 11:43                                   ` Pedro Alves
  2014-12-17 11:56                                     ` Yao Qi
  2014-12-17 19:15                                     ` Jan Kratochvil
  0 siblings, 2 replies; 93+ messages in thread
From: Pedro Alves @ 2014-12-17 11:43 UTC (permalink / raw)
  To: Yao Qi; +Cc: Jan Kratochvil, Eli Zaretskii, brobecker, gdb-patches, ktietz

On 12/17/2014 11:40 AM, Yao Qi wrote:

> At least, user should get an explicit message that 'compile' command
> isn't supported if the user run the 'compile' command on Windows for example.

Agreed.  That's what I suggested in the other mail too:

 https://sourceware.org/ml/gdb-patches/2014-12/msg00475.html

Would that be OK with you?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 11:43                                   ` Pedro Alves
@ 2014-12-17 11:56                                     ` Yao Qi
  2014-12-17 19:15                                     ` Jan Kratochvil
  1 sibling, 0 replies; 93+ messages in thread
From: Yao Qi @ 2014-12-17 11:56 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Jan Kratochvil, Eli Zaretskii, brobecker, gdb-patches, ktietz

On 12/17/2014 07:43 PM, Pedro Alves wrote:
> Agreed.  That's what I suggested in the other mail too:
> 
>  https://sourceware.org/ml/gdb-patches/2014-12/msg00475.html
> 
> Would that be OK with you?

Yes, that is OK to me.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-16  3:40                               ` Eli Zaretskii
  2014-12-16  9:04                                 ` Kai Tietz
@ 2014-12-17 17:30                                 ` Steve Ellcey
  1 sibling, 0 replies; 93+ messages in thread
From: Steve Ellcey @ 2014-12-17 17:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Jan Kratochvil, brobecker, yao, gdb-patches, ktietz

On Tue, 2014-12-16 at 05:39 +0200, Eli Zaretskii wrote:
> > Date: Mon, 15 Dec 2014 23:55:51 +0100
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> > Cc: brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org,
> >         ktietz@redhat.com
> > 
> > On Mon, 15 Dec 2014 23:28:01 +0100, Jan Kratochvil wrote:
> > > The 'compile' project needs a larger port effort to run on MS-Windows.
> > 
> > For example there is also
> > 
> > compile/compile.c:
> >   zap = concat ("rm -rf ", dir, (char *) NULL);
> >   system (zap);
> 
> Yuck!  Do we really allow such atrocities in GDB?  What if 'rm' is
> some unrelated or even malicious script?
> 
> I think this should be replaced by suitable C function calls.  IMO,
> this kind of programming is OK for prototyping, but not for the final
> code.

I am running into a different problem with the system call.  I am
building on Linux using the latest GCC and glibc (unreleased top of tree
sources) and my build fails with:

/scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result]
cc1: all warnings being treated as errors
make[1]: *** [compile.o] Error 1

If we don't get rid of the system call can we at least check the return
value of system?

Steve Ellcey
sellcey@imgtec.com

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [patchv2] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 11:16                             ` Pedro Alves
@ 2014-12-17 18:17                               ` Jan Kratochvil
  2014-12-17 18:33                                 ` Pedro Alves
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-17 18:17 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Eli Zaretskii, brobecker, yao, gdb-patches, ktietz

[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

On Wed, 17 Dec 2014 12:15:42 +0100, Pedro Alves wrote:
> Can you send a version that does an autoconf check for mkdtemp instead?

Done.

> > +  error (_("mkdtemp needs to be implemented for MS-Windows hosts"));
> 
> I think the error text should be a bit more generic and not mention a
> particular implementation detail, like "Command not supported on this host." or
> some such

Done.


> I think the testsuite will need to be extended to handle this error,
> presumably in skip_compile_feature_tests.

Done.

Tested it does build on Fedora 21 x86_64 mingw64 for 32-bit and 64-bit
.exe targets.

OK for check-in?


Thanks,
Jan

[-- Attachment #2: 1.patch --]
[-- Type: text/plain, Size: 4783 bytes --]

gdb/ChangeLog
2014-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

        Fix MinGW compilation.
	* compile/compile.c (get_compile_file_tempdir): Call error if
	!HAVE_MKDTEMP.
	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (AC_CHECK_FUNCS): Add mkdtemp.

gdb/testsuite/ChangeLog
2014-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

        Fix MinGW compilation.
	* gdb.compile/compile-ops.exp: Update untested message if
	!skip_compile_feature_tests.
	* gdb.compile/compile-setjmp.exp: Likewise.
	* gdb.compile/compile-tls.exp: Likewise.
	* gdb.compile/compile.exp: Likewise.
	* lib/gdb.exp (skip_compile_feature_tests): Check also "Command not
	supported on this host".

diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 6d3d16e..414fc35 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -191,7 +191,11 @@ get_compile_file_tempdir (void)
 
   strcpy (tname, TEMPLATE);
 #undef TEMPLATE
+#ifdef HAVE_MKDTEMP
   tempdir_name = mkdtemp (tname);
+#else
+  error (_("Command not supported on this host."));
+#endif
   if (tempdir_name == NULL)
     perror_with_name (_("Could not make temporary directory"));
 
diff --git a/gdb/config.in b/gdb/config.in
index fb3c315..9d3f32d 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -231,6 +231,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `mkdtemp' function. */
+#undef HAVE_MKDTEMP
+
 /* Define to 1 if you have a working `mmap' system call. */
 #undef HAVE_MMAP
 
diff --git a/gdb/configure b/gdb/configure
index 8985230..7ff74ba 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -10496,7 +10496,7 @@ for ac_func in getrusage getuid getgid \
 		sigaction sigprocmask sigsetmask socketpair \
 		ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
 		setrlimit getrlimit posix_madvise waitpid \
-		ptrace64 sigaltstack
+		ptrace64 sigaltstack mkdtemp
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gdb/configure.ac b/gdb/configure.ac
index c933e3f..e972ac2 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1317,7 +1317,7 @@ AC_CHECK_FUNCS([getrusage getuid getgid \
 		sigaction sigprocmask sigsetmask socketpair \
 		ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
 		setrlimit getrlimit posix_madvise waitpid \
-		ptrace64 sigaltstack])
+		ptrace64 sigaltstack mkdtemp])
 AM_LANGINFO_CODESET
 GDB_AC_COMMON
 
diff --git a/gdb/testsuite/gdb.compile/compile-ops.exp b/gdb/testsuite/gdb.compile/compile-ops.exp
index c295836..4fc950f 100644
--- a/gdb/testsuite/gdb.compile/compile-ops.exp
+++ b/gdb/testsuite/gdb.compile/compile-ops.exp
@@ -411,7 +411,7 @@ if ![runto func] {
 }
 
 if {[skip_compile_feature_tests]} {
-    untested "could not find libcc1 shared library"
+    untested "compile command not supported (could not find libcc1 shared library?)"
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.compile/compile-setjmp.exp b/gdb/testsuite/gdb.compile/compile-setjmp.exp
index 557c1f0..8f876e2 100644
--- a/gdb/testsuite/gdb.compile/compile-setjmp.exp
+++ b/gdb/testsuite/gdb.compile/compile-setjmp.exp
@@ -24,7 +24,7 @@ if ![runto_main] {
 }
 
 if {[skip_compile_feature_tests]} {
-    untested "could not find libcc1 shared library"
+    untested "compile command not supported (could not find libcc1 shared library?)"
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.compile/compile-tls.exp b/gdb/testsuite/gdb.compile/compile-tls.exp
index e9613f5..d95a351 100644
--- a/gdb/testsuite/gdb.compile/compile-tls.exp
+++ b/gdb/testsuite/gdb.compile/compile-tls.exp
@@ -27,7 +27,7 @@ if ![runto_main] then {
 }
 
 if {[skip_compile_feature_tests]} {
-    untested "could not find libcc1 shared library"
+    untested "compile command not supported (could not find libcc1 shared library?)"
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp
index d0dd791..040b727 100644
--- a/gdb/testsuite/gdb.compile/compile.exp
+++ b/gdb/testsuite/gdb.compile/compile.exp
@@ -57,7 +57,7 @@ if ![runto_main] {
 }
 
 if {[skip_compile_feature_tests]} {
-    untested "could not find libcc1 shared library"
+    untested "compile command not supported (could not find libcc1 shared library?)"
     return -1
 }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3a3a396..08087f2 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2538,6 +2538,9 @@ proc skip_compile_feature_tests {} {
 	"Could not load libcc1.*\r\n$gdb_prompt $" {
 	    set result 1
 	}
+	-re "Command not supported on this host\\..*\r\n$gdb_prompt $" {
+	    set result 1
+	}
 	-re "\r\n$gdb_prompt $" {
 	}
     }

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-16 12:40                             ` Pierre Muller
@ 2014-12-17 18:21                               ` Jan Kratochvil
  0 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-17 18:21 UTC (permalink / raw)
  To: Pierre Muller
  Cc: 'Eli Zaretskii', brobecker, yao, gdb-patches, ktietz

Hi Pierre,

On Tue, 16 Dec 2014 13:40:28 +0100, Pierre Muller wrote:
> which appeared as an attached file named 1.sql,
> which made it difficult to guess it was indeed the patch...

The mail has:
	Content-Type: text/plain; charset=us-ascii
	Content-Disposition: inline; filename=1

So there was no ".sql" extension; there was just no extension at all.


>   To go a little bit further, I tried to use 
> the compile command on the newly generated mingw32 GDB executable.
>  
> using ./gdb ./gdb
> (with a minimal hello.c source code)
> 
> <<<<  (top-gdb) compile code hello.c
> returns
> >>>> The program must be running for the compile command to work.
> I am not sure why this restriction should apply.

I do not understand what it should do without running inferior.  Or rather
I can understand it but that would be a functionality completely unrelated to
the current 'compile' functionality - which hooks into the running inferior.
I would find it rather confusing myself.


>  (top-gdb) start
> Temporary breakpoint 3 at 0x40158a: file ../../../binutils-gdb/gdb/gdb.c, line 28.
> Starting program: E:\cygwin-32\home\Pierre\git\build\mult-mingw32\gdb\gdb.exe
> [New Thread 6572.0x4e0]
> 
> Temporary breakpoint 3, main (argc=1, argv=0x3d4b30)
>     at ../../../binutils-gdb/gdb/gdb.c:28
>  (top-gdb) compile file hello.c
> Could not load libcc1.so: "libcc1.so": Le module spécifié est introuvable.
>  (French meaning: "the specified module can't be found").
> 
>   So the mkdtmp is not the only problem 
> for mingw compile support.

That is correct, you need to build gcc-5.0 which contains libcc1.so.
But that currently also will not work as it will get named libcc1.dll, you can
read more in:
	https://sourceware.org/ml/gdb-patches/2014-12/msg00429.html


Thanks,
Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patchv2] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 18:17                               ` [patchv2] " Jan Kratochvil
@ 2014-12-17 18:33                                 ` Pedro Alves
  2014-12-17 19:12                                   ` [commit] " Jan Kratochvil
  0 siblings, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-17 18:33 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Eli Zaretskii, brobecker, yao, gdb-patches, ktietz

On 12/17/2014 06:17 PM, Jan Kratochvil wrote:

> OK for check-in?

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [commit] [patchv2] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 18:33                                 ` Pedro Alves
@ 2014-12-17 19:12                                   ` Jan Kratochvil
  0 siblings, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-17 19:12 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Eli Zaretskii, brobecker, yao, gdb-patches, ktietz

On Wed, 17 Dec 2014 19:33:38 +0100, Pedro Alves wrote:
> On 12/17/2014 06:17 PM, Jan Kratochvil wrote:
> 
> > OK for check-in?
> 
> OK.

Checked in:
	1bc1068a0c1a1a0fad09500c97edf88467de9be0


Thanks,
Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 11:43                                   ` Pedro Alves
  2014-12-17 11:56                                     ` Yao Qi
@ 2014-12-17 19:15                                     ` Jan Kratochvil
  1 sibling, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-17 19:15 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, Eli Zaretskii, brobecker, gdb-patches, ktietz

On Wed, 17 Dec 2014 12:43:35 +0100, Pedro Alves wrote:
> On 12/17/2014 11:40 AM, Yao Qi wrote:
> 
> > At least, user should get an explicit message that 'compile' command
> > isn't supported if the user run the 'compile' command on Windows for example.
> 
> Agreed.  That's what I suggested in the other mail too:
> 
>  https://sourceware.org/ml/gdb-patches/2014-12/msg00475.html
> 
> Would that be OK with you?

This is not completely correct.  With the patch above being checked in now the
'compile' command will still fail on:

$ wine build_win32/gdb/gdb.exe -q build_win32/gdb/gdb.exe -ex start -ex 'compile code 1' -ex 'set confirm no' -ex quit
[...]
Temporary breakpoint 1, main (argc=1, argv=0x241418) at ../../gdb/gdb.c:29
29        args.argc = argc;
Could not load libcc1.so: Module not found.

It would need some special exception.

So far it is obvious that one needs gcc-5.0 which "nobody" has.  But after
gcc-5.0 gets released MinGW gdb.exe will still print "Could not load libcc1.so"
while (I expect) MinGW gcc-5.0 will have "libcc1.dll".


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-16  3:37                             ` Eli Zaretskii
  2014-12-16  9:06                               ` Kai Tietz
@ 2014-12-17 19:18                               ` Jan Kratochvil
  2014-12-17 19:31                                 ` Eli Zaretskii
  1 sibling, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-17 19:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: brobecker, yao, gdb-patches, ktietz

On Tue, 16 Dec 2014 04:37:15 +0100, Eli Zaretskii wrote:
> > default_infcall_mmap:
> >   error (_("This target does not support inferior memory allocation by mmap."));
> > 
> > As currently there is only:
> > 
> > linux-tdep.c:
> >   set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);
> 
> Why is mmap needed here?

The project obviously needs something like:
	(gdb) call dlopen("just compile piece of code.so");

But as dlopen() is intrusive to the inferior Tom decided it is better to do
much less intrusive
	(gdb) print mmap(...)

instead and reimplement what inferior dlopen() does
in gdb/compile/compile-object-load.c - which is being done.

Without mmap() there is nowhere to load the compiled code at.



Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 19:18                               ` Jan Kratochvil
@ 2014-12-17 19:31                                 ` Eli Zaretskii
  2014-12-17 19:37                                   ` Jan Kratochvil
  2014-12-17 20:34                                   ` Pedro Alves
  0 siblings, 2 replies; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-17 19:31 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: brobecker, yao, gdb-patches, ktietz

> Date: Wed, 17 Dec 2014 20:17:55 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org,
>         ktietz@redhat.com
> 
> > > linux-tdep.c:
> > >   set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);
> > 
> > Why is mmap needed here?
> 
> The project obviously needs something like:
> 	(gdb) call dlopen("just compile piece of code.so");
> 
> But as dlopen() is intrusive to the inferior Tom decided it is better to do
> much less intrusive
> 	(gdb) print mmap(...)
> 
> instead and reimplement what inferior dlopen() does
> in gdb/compile/compile-object-load.c - which is being done.

Why is dlopen "intrusive"?  ISTM that using the Windows equivalent of
dlopen is exactly the right thing here.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 19:31                                 ` Eli Zaretskii
@ 2014-12-17 19:37                                   ` Jan Kratochvil
  2014-12-17 20:34                                   ` Pedro Alves
  1 sibling, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-17 19:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: brobecker, yao, gdb-patches, ktietz

On Wed, 17 Dec 2014 20:31:18 +0100, Eli Zaretskii wrote:
> Why is dlopen "intrusive"?  ISTM that using the Windows equivalent of
> dlopen is exactly the right thing here.

First I do not want to advocate the mmap() + ld.so reimplementation too much
as I would implement it the dlopen() way (at least in the initial
implementation) myself.

But AFAIK (but I do not know much) MS-Windows implements its dlopen-like
feature in MS-Windows kernel which may be safe.  Contrary to it GNU/Linux
implements dlopen() fully in glibc - userland - calling from kernel only that
mmap() to map the .so file from disk, map some new pages of memory etc. By
having to modify the _r_debug.r_map link list which is in many times corrupted
when debugging crashed program GDB would crash the inferior even more on
'compile code' command.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 19:31                                 ` Eli Zaretskii
  2014-12-17 19:37                                   ` Jan Kratochvil
@ 2014-12-17 20:34                                   ` Pedro Alves
  2014-12-18 17:22                                     ` Eli Zaretskii
  1 sibling, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-17 20:34 UTC (permalink / raw)
  To: Eli Zaretskii, Jan Kratochvil; +Cc: brobecker, yao, gdb-patches, ktietz

On 12/17/2014 07:31 PM, Eli Zaretskii wrote:
>> Date: Wed, 17 Dec 2014 20:17:55 +0100
>> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>> Cc: brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org,
>>         ktietz@redhat.com
>>
>>>> linux-tdep.c:
>>>>   set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);
>>>
>>> Why is mmap needed here?
>>
>> The project obviously needs something like:
>> 	(gdb) call dlopen("just compile piece of code.so");
>>
>> But as dlopen() is intrusive to the inferior Tom decided it is better to do
>> much less intrusive
>> 	(gdb) print mmap(...)
>>
>> instead and reimplement what inferior dlopen() does
>> in gdb/compile/compile-object-load.c - which is being done.
> 
> Why is dlopen "intrusive"?

Pasting here what I said recently on a glibc thread, re. reasons
for not using dlopen for this.

Off the top of my head, I'm sure there are more:

 - The user might want to evaluate an expression while the program itself
   has just called dlopen and is now stopped inside it.  This pesky dlopen
   recursion thing.    It's best if GDB only calls async-signal
   safe functions behind the scenes, if possible.  Of course if the
   injected expression involves calls to async-signal unsafe code that breaks
   the inferior, the user gets what she asked for.

 - The program might have not been linked with -ldl.

 - I suspect there may be issues with messing with symbol resolution
   and self library walks in the inferior too.  Not sure if RTLD_LOCAL is
   enough.  dlmopen might be a better fit, but hmm, that isn't very
   well supported in GDB/glibc.

 - A lower level mechanism has much better chances of working on
   more targets and runtimes-of-languages-other-than-C with minimal
   changes.

> ISTM that using the Windows equivalent of dlopen is exactly the right thing here.

That may well be, though I think that it's better if "info shared"
doesn't show the modules injected into the inferior, which using LoadLibrary
(Windows's dlopen) would give you.


Note that set_gdbarch_infcall_mmap doesn't need to implement the
whole feature set of mmap.  We only need to be able to carve out a
piece of memory.  Should map trivially to VirtualAlloc.


I expect that we'll end up using this same gdbarch hook to allocate
memory in the inferior when we need to coerce variables to the inferior.
We currently call "malloc" for that, which isn't ideal in the sense
that the inferior can well be already inside malloc when we do that,
leading do deadlock or corruption.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-16  9:04                                 ` Kai Tietz
@ 2014-12-17 21:02                                   ` Jan Kratochvil
  2014-12-17 22:07                                     ` Steve Ellcey
                                                       ` (4 more replies)
  0 siblings, 5 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-17 21:02 UTC (permalink / raw)
  To: Kai Tietz, Steve Ellcey; +Cc: Eli Zaretskii, brobecker, yao, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 927 bytes --]

On Tue, 16 Dec 2014 10:04:02 +0100, Kai Tietz wrote:
> Why not using here instead an implementation using FTW-API?

Done.


> At least mingw-w64 added this API recently to runtime for gcc's sake, so
> implementation of an 'rm -rf' should be pretty easy.

It has built on Fedora 21 x86_64 mingw64 for both 32-bit and 64-bit targets.
I am not sure about various other Unices but if the patch gets approved...


On Wed, 17 Dec 2014 18:29:51 +0100, Steve Ellcey wrote:
> /scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result]
> cc1: all warnings being treated as errors
> make[1]: *** [compile.o] Error 1

It should get fixed by this patch.


I have briefly tested (on Linux; on MinGW I have only tested the build) it
really does delete the directory and its files.

OK for check-in?


Thanks,
Jan

[-- Attachment #2: 3.patch --]
[-- Type: text/plain, Size: 1637 bytes --]

gdb/ChangeLog
2014-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* compile/compile.c: Include ftw.h.
	(do_rmdir_fn): New function.
	(do_rmdir): Call nftw with it.

diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 414fc35..7dbc819 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -37,6 +37,7 @@
 #include "filestuff.h"
 #include "target.h"
 #include "osabi.h"
+#include <ftw.h>
 
 \f
 
@@ -162,17 +163,42 @@ compile_code_command (char *arg, int from_tty)
   do_cleanups (cleanup);
 }
 
+/* Helper for do_rmdir.  */
+
+static int
+do_rmdir_fn (const char *fpath, const struct stat *sb, int typeflag,
+	     struct FTW *ftwbuf)
+{
+  switch (typeflag)
+    {
+    case FTW_DP:
+      if (rmdir (fpath) != 0)
+	warning (_("Cannot remove 'compile' command directory \"%s\": %s"),
+		 fpath, safe_strerror (errno));
+      break;
+    case FTW_F:
+      if (unlink (fpath) != 0)
+	warning (_("Cannot remove 'compile' command file \"%s\": %s"),
+		 fpath, safe_strerror (errno));
+      break;
+    default:
+      warning (_("Unknown 'typeflag' %d for 'compile' command file \"%s\"."),
+	       typeflag, fpath);
+    }
+
+  /* Continue the walk.  */
+  return 0;
+}
+
 /* A cleanup function to remove a directory and all its contents.  */
 
 static void
 do_rmdir (void *arg)
 {
   const char *dir = arg;
-  char *zap;
-  
+
   gdb_assert (strncmp (dir, TMP_PREFIX, strlen (TMP_PREFIX)) == 0);
-  zap = concat ("rm -rf ", dir, (char *) NULL);
-  system (zap);
+  nftw (dir, do_rmdir_fn, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
 }
 
 /* Return the name of the temporary directory to use for .o files, and

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-17 21:02                                   ` [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Jan Kratochvil
@ 2014-12-17 22:07                                     ` Steve Ellcey
  2014-12-17 22:42                                     ` Pedro Alves
                                                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 93+ messages in thread
From: Steve Ellcey @ 2014-12-17 22:07 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Kai Tietz, Eli Zaretskii, brobecker, yao, gdb-patches

On Wed, 2014-12-17 at 22:01 +0100, Jan Kratochvil wrote:

> On Wed, 17 Dec 2014 18:29:51 +0100, Steve Ellcey wrote:
> > /scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result]
> > cc1: all warnings being treated as errors
> > make[1]: *** [compile.o] Error 1
> 
> It should get fixed by this patch.

Yes, that patch fixes my build problem.

Steve Ellcey
sellcey@imgtec.com

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-17 21:02                                   ` [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Jan Kratochvil
  2014-12-17 22:07                                     ` Steve Ellcey
@ 2014-12-17 22:42                                     ` Pedro Alves
  2014-12-18 18:14                                       ` Jan Kratochvil
  2014-12-18  5:38                                     ` Yao Qi
                                                       ` (2 subsequent siblings)
  4 siblings, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-17 22:42 UTC (permalink / raw)
  To: Jan Kratochvil, Kai Tietz, Steve Ellcey
  Cc: Eli Zaretskii, brobecker, yao, gdb-patches

On 12/17/2014 09:01 PM, Jan Kratochvil wrote:
> On Tue, 16 Dec 2014 10:04:02 +0100, Kai Tietz wrote:
>> Why not using here instead an implementation using FTW-API?
> 
> Done.
> 
> 
>> At least mingw-w64 added this API recently to runtime for gcc's sake, so
>> implementation of an 'rm -rf' should be pretty easy.
> 
> It has built on Fedora 21 x86_64 mingw64 for both 32-bit and 64-bit targets.
> I am not sure about various other Unices but if the patch gets approved...

Well, if the patch gets approved, what's the plan then?  :-)

See https://www.gnu.org/software/gnulib/manual/html_node/ftw.html:

 "This function is missing on some platforms: Mac OS X 10.3, FreeBSD 5.2.1, NetBSD 3.0, Minix 3.1.8, mingw, MSVC 9, BeOS. "

Note that's problems _not_ fixed by Gnulib.  In reality, there's no real ftw
module in gnulib.  But there _is_ an fts module.

So it seems to me that we should use the fts API instead of ftw.  And then
we'll either need to import the gnulib module, or start out with an
autoconf check.

> 
> 
> On Wed, 17 Dec 2014 18:29:51 +0100, Steve Ellcey wrote:
>> /scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result]
>> cc1: all warnings being treated as errors
>> make[1]: *** [compile.o] Error 1
> 
> It should get fixed by this patch.
> 
> 
> I have briefly tested (on Linux; on MinGW I have only tested the build) it
> really does delete the directory and its files.
> 
> OK for check-in?


Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-17 21:02                                   ` [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Jan Kratochvil
  2014-12-17 22:07                                     ` Steve Ellcey
  2014-12-17 22:42                                     ` Pedro Alves
@ 2014-12-18  5:38                                     ` Yao Qi
  2014-12-18 17:23                                     ` Eli Zaretskii
  2014-12-18 20:56                                     ` Sergio Durigan Junior
  4 siblings, 0 replies; 93+ messages in thread
From: Yao Qi @ 2014-12-18  5:38 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Kai Tietz, Steve Ellcey, Eli Zaretskii, brobecker, gdb-patches

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> On Wed, 17 Dec 2014 18:29:51 +0100, Steve Ellcey wrote:
>> /scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10:
>> error: ignoring return value of 'system', declared with attribute
>> warn_unused_result [-Werror=unused-result]
>> cc1: all warnings being treated as errors
>> make[1]: *** [compile.o] Error 1
>
> It should get fixed by this patch.

This build failure was reported in 
https://sourceware.org/bugzilla/show_bug.cgi?id=17718

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-17 20:34                                   ` Pedro Alves
@ 2014-12-18 17:22                                     ` Eli Zaretskii
  2014-12-18 18:00                                       ` Pedro Alves
  0 siblings, 1 reply; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-18 17:22 UTC (permalink / raw)
  To: Pedro Alves; +Cc: jan.kratochvil, brobecker, yao, gdb-patches, ktietz

> Date: Wed, 17 Dec 2014 20:34:12 +0000
> From: Pedro Alves <palves@redhat.com>
> CC: brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org,
>         ktietz@redhat.com
> 
> Note that set_gdbarch_infcall_mmap doesn't need to implement the
> whole feature set of mmap.  We only need to be able to carve out a
> piece of memory.  Should map trivially to VirtualAlloc.

That's true, but if this feature will work by doing the equivalent of
dlopen, then it will most probably only ever work on GNU/Linux.  Even
there, we cannot really hope to do all this stuff by hand, do it
safely, and then track all the changes in the OS to keep this working
for the years to come.  And good luck being able to do it at all on
proprietary systems such as Windows, where you cannot simply examine
the sources of the DLL loader.

I conclude that sadly this feature is extremely limited, and will
probably die very soon, unless we change its implementation to
something more portable and safe.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-17 21:02                                   ` [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Jan Kratochvil
                                                       ` (2 preceding siblings ...)
  2014-12-18  5:38                                     ` Yao Qi
@ 2014-12-18 17:23                                     ` Eli Zaretskii
  2014-12-18 17:31                                       ` Jan Kratochvil
  2014-12-18 20:56                                     ` Sergio Durigan Junior
  4 siblings, 1 reply; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-18 17:23 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: ktietz, sellcey, brobecker, yao, gdb-patches

> Date: Wed, 17 Dec 2014 22:01:44 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, brobecker@adacore.com, yao@codesourcery.com,
>         gdb-patches@sourceware.org
> 
> > Why not using here instead an implementation using FTW-API?
> 
> Done.
> 
> 
> > At least mingw-w64 added this API recently to runtime for gcc's sake, so
> > implementation of an 'rm -rf' should be pretty easy.
> 
> It has built on Fedora 21 x86_64 mingw64 for both 32-bit and 64-bit targets.
> I am not sure about various other Unices but if the patch gets approved...

There's no ftw in MinGW32.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 17:23                                     ` Eli Zaretskii
@ 2014-12-18 17:31                                       ` Jan Kratochvil
  2014-12-18 17:40                                         ` Eli Zaretskii
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-18 17:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ktietz, sellcey, brobecker, yao, gdb-patches

On Thu, 18 Dec 2014 18:23:11 +0100, Eli Zaretskii wrote:
> > It has built on Fedora 21 x86_64 mingw64 for both 32-bit and 64-bit targets.
> > I am not sure about various other Unices but if the patch gets approved...
> 
> There's no ftw in MinGW32.

32-bit .exe can be build either by MinGW3 (considered by Fedora as obsolete
now)
	http://www.mingw.org/
or by MinGW64 in 32-bit mode
	http://mingw-w64.sourceforge.net/
at least according to:
	https://fedoraproject.org/wiki/Features/Mingw-w64_cross_compiler

From the Fedora point of view MinGW64 32-bit mode seems to be a superset of
MinGW32 so why to care about MinGW32 anymore?  Or what do I miss?


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 17:31                                       ` Jan Kratochvil
@ 2014-12-18 17:40                                         ` Eli Zaretskii
  2014-12-18 20:15                                           ` Kai Tietz
  0 siblings, 1 reply; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-18 17:40 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: ktietz, sellcey, brobecker, yao, gdb-patches

> Date: Thu, 18 Dec 2014 18:31:03 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: ktietz@redhat.com, sellcey@imgtec.com, brobecker@adacore.com,
>         yao@codesourcery.com, gdb-patches@sourceware.org
> 
> >From the Fedora point of view MinGW64 32-bit mode seems to be a superset of
> MinGW32 so why to care about MinGW32 anymore?  Or what do I miss?

That _I_ use MinGW32?

Seriously, though: from my POV, MinGW64 is not reliable yet to switch
to it completely, their development still breaks the libraries too
often, and there are significant backward-incompatible changes now and
then.  The fact that there's no official releases of MinGW64 doesn't
help.  And no, MinGW64 is not a superset of MinGW32, it's a different
project with an incompatible ABI and subtly incompatible header files.
(Please don't start an argument about that, I'm not really
interested.)

Even if there were no problems with MinGW64, I don't think we should
stop supporting MinGW32 just like that, it is still a live project,
and I, for one, is quite happy with it.  I hope GDB will not drop its
support any time soon.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: Fix MinGW build  [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/]
  2014-12-18 17:22                                     ` Eli Zaretskii
@ 2014-12-18 18:00                                       ` Pedro Alves
  0 siblings, 0 replies; 93+ messages in thread
From: Pedro Alves @ 2014-12-18 18:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: jan.kratochvil, brobecker, yao, gdb-patches, ktietz

On 12/18/2014 05:22 PM, Eli Zaretskii wrote:
>> Date: Wed, 17 Dec 2014 20:34:12 +0000
>> From: Pedro Alves <palves@redhat.com>
>> CC: brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org,
>>         ktietz@redhat.com
>>
>> Note that set_gdbarch_infcall_mmap doesn't need to implement the
>> whole feature set of mmap.  We only need to be able to carve out a
>> piece of memory.  Should map trivially to VirtualAlloc.
> 
> That's true, but if this feature will work by doing the equivalent of
> dlopen, then it will most probably only ever work on GNU/Linux.  Even
> there, we cannot really hope to do all this stuff by hand, do it
> safely, and then track all the changes in the OS to keep this working
> for the years to come.  And good luck being able to do it at all on
> proprietary systems such as Windows, where you cannot simply examine
> the sources of the DLL loader.

I don't think we'll need to.  In fact, I have a feeling that on Windows
things will tend to be simpler, given PE is simpler/more contained
than ELF.  But if it turns out that whoever tries to make this work on
Windows finds out that the LoadLibrary route is better for Windows, then
I don't see that as a problem.  I'm sure we can fit that in by overriding
some hooks.

> I conclude that sadly this feature is extremely limited, and will
> probably die very soon, unless we change its implementation to
> something more portable and safe.

We shall see.  :-)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-17 22:42                                     ` Pedro Alves
@ 2014-12-18 18:14                                       ` Jan Kratochvil
  2014-12-18 18:24                                         ` Pedro Alves
  2014-12-18 20:26                                         ` Eli Zaretskii
  0 siblings, 2 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-18 18:14 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Kai Tietz, Steve Ellcey, Eli Zaretskii, brobecker, yao, gdb-patches

On Wed, 17 Dec 2014 23:41:53 +0100, Pedro Alves wrote:
> See https://www.gnu.org/software/gnulib/manual/html_node/ftw.html:
> 
>  "This function is missing on some platforms: Mac OS X 10.3, FreeBSD 5.2.1,
>  NetBSD 3.0, Minix 3.1.8, mingw, MSVC 9, BeOS. "

This list does not say much and it is even obsolete, at least "mingw" supports
ftw(); although Eli disagrees in:
	https://sourceware.org/ml/gdb-patches/2014-12/msg00540.html

On MacOS X GDB does not work anyway, FreeBSD latest stable release is 10.1 so
5.2.1 seems irrelevant, NetBSD 6.1.5 vs. 3.0 likewise, for other OS I have no
idea if they are supported by GDB and nobody knows - configure.{host,tgt}
triplets naming are too cryptic to quickly check it by someone not familiar
with that platform and there is no official list of supported platforms
I asked for recently at least in:

Message-ID: <20140817211647.GA17152@host2.jankratochvil.net>
On Sun, 17 Aug 2014 23:16:47 +0200, Jan Kratochvil wrote:
# This is one of the general problems of GDB that one cannot do any change
# affecting platforms which one cannot (or at least not easily enough) test on.
#
# Platform not automatically being tested by Jenkins for any patch submitted to
# Gerrit should be officially unsupported.


> So it seems to me that we should use the fts API instead of ftw.  And then
> we'll either need to import the gnulib module, or start out with an
> autoconf check.

As global maintainer Eli asked for ftw()->fts() (despite I do not see there
valid technical argument in that mail myself) going to implement it; otherwise
I would not see from the platform list at
	https://www.gnu.org/software/gnulib/manual/html_node/ftw.html
if ftw() is really supported on all GDB hosts or not.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 18:14                                       ` Jan Kratochvil
@ 2014-12-18 18:24                                         ` Pedro Alves
  2014-12-18 18:41                                           ` Jan Kratochvil
  2014-12-18 20:26                                         ` Eli Zaretskii
  1 sibling, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-18 18:24 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Kai Tietz, Steve Ellcey, Eli Zaretskii, brobecker, yao, gdb-patches

On 12/18/2014 06:14 PM, Jan Kratochvil wrote:
> On Wed, 17 Dec 2014 23:41:53 +0100, Pedro Alves wrote:
>> See https://www.gnu.org/software/gnulib/manual/html_node/ftw.html:
>>
>>  "This function is missing on some platforms: Mac OS X 10.3, FreeBSD 5.2.1,
>>  NetBSD 3.0, Minix 3.1.8, mingw, MSVC 9, BeOS. "
> 
> This list does not say much and it is even obsolete, at least "mingw" supports
> ftw(); although Eli disagrees in:
> 	https://sourceware.org/ml/gdb-patches/2014-12/msg00540.html

What you miss is that mingw and mingw-w64 are different projects,
lead by different people.

> 
> On MacOS X GDB does not work anyway, 

Huh?

> Message-ID: <20140817211647.GA17152@host2.jankratochvil.net>
> On Sun, 17 Aug 2014 23:16:47 +0200, Jan Kratochvil wrote:
> # This is one of the general problems of GDB that one cannot do any change
> # affecting platforms which one cannot (or at least not easily enough) test on.

Sergio has been working hard on a setting up a buildbot.  But you know that ...

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 18:24                                         ` Pedro Alves
@ 2014-12-18 18:41                                           ` Jan Kratochvil
  2014-12-18 19:07                                             ` Pedro Alves
  2014-12-19 12:59                                             ` Joel Brobecker
  0 siblings, 2 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-18 18:41 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Kai Tietz, Steve Ellcey, Eli Zaretskii, brobecker, yao, gdb-patches

On Thu, 18 Dec 2014 19:23:55 +0100, Pedro Alves wrote:
> What you miss is that mingw and mingw-w64 are different projects,
> lead by different people.

https://www.gnu.org/software/gnulib/manual/html_node/Target-Platforms.html#Target-Platforms
does not list "mingw-w64" and it does not list which implementation of "mingw"
they mean.


> > On MacOS X GDB does not work anyway, 
> 
> Huh?

This is from my memories of reading #gdb@freenode that FSF GDB was reporting
fatal errors on trivial programs for anyone asking about OSX there.  I do not
have OSX to test it myself (and I do not remember if I tested GDB there myself
when I had OSX available) so maybe GDB works on OSX now if you say so, OK.


> > Message-ID: <20140817211647.GA17152@host2.jankratochvil.net>
> > On Sun, 17 Aug 2014 23:16:47 +0200, Jan Kratochvil wrote:
> > # This is one of the general problems of GDB that one cannot do any change
> > # affecting platforms which one cannot (or at least not easily enough) test on.
> 
> Sergio has been working hard on a setting up a buildbot.  But you know that ...

(1) That does not work yet (for example it is not public yet).
(2) It is currently unclear whether all the supported OSes (while nobody knows
    the currently valid list of them) will get buildslaves connected to the
    buildbot project.  Some of those OSes are proprietary.

But sure that all may happen one day.  But for now it is irrelevant.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 18:41                                           ` Jan Kratochvil
@ 2014-12-18 19:07                                             ` Pedro Alves
  2014-12-18 21:05                                               ` Jan Kratochvil
  2014-12-19 12:59                                             ` Joel Brobecker
  1 sibling, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-18 19:07 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Kai Tietz, Steve Ellcey, Eli Zaretskii, brobecker, yao, gdb-patches

Ranting does not help, that's all I'll say.

From the trying to be useful department: you'll find code using
the fts api in GNU coreutils / rm.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 17:40                                         ` Eli Zaretskii
@ 2014-12-18 20:15                                           ` Kai Tietz
  2014-12-18 20:47                                             ` Eli Zaretskii
  2014-12-18 23:47                                             ` Pedro Alves
  0 siblings, 2 replies; 93+ messages in thread
From: Kai Tietz @ 2014-12-18 20:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Jan Kratochvil, sellcey, brobecker, yao, gdb-patches

----- Ursprüngliche Mail -----
> > Date: Thu, 18 Dec 2014 18:31:03 +0100
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> > Cc: ktietz@redhat.com, sellcey@imgtec.com, brobecker@adacore.com,
> >         yao@codesourcery.com, gdb-patches@sourceware.org
> > 
> > >From the Fedora point of view MinGW64 32-bit mode seems to be a superset
> > >of
> > MinGW32 so why to care about MinGW32 anymore?  Or what do I miss?
> 
> That _I_ use MinGW32?

That is actually your problem, isn't it?  The mingw-w64 target support ftw, so why not simply allow it for targets providing it, and other targets can be covered by gnulib?
Anyway gnulib is nothing I am concerned in general.
 
> Seriously, though: from my POV, MinGW64 is not reliable yet to switch
> to it completely, their development still breaks the libraries too
> often, and there are significant backward-incompatible changes now and
> then.  The fact that there's no official releases of MinGW64 doesn't
> help.

Seriously answering this ...

Mingw-w64 has official release.  All bigger distributors have done already a lot of different releases for it.  Just for the interest people, mingw-w64 already has 3 different release-branches.  Current release-version we provide is 3.4.  So, this is for sure no valid point.  We have official releases, and we had actually already more then one ...

What libraries "mingw-w64" breaks often?!?   Could you please go in detail?  I am curious to hear that, as all distributors I know (Fedora, Debian, OpenSuse, ArchLinux, ...) haven't reported this.  Or is that just one thing you have a "gut" feeling about?

>  And no, MinGW64 is not a superset of MinGW32, it's a different
> project with an incompatible ABI and subtly incompatible header files.
> (Please don't start an argument about that, I'm not really
> interested.)

True, MinGW.org and mingw-w64 are two different ventures with differences in feature-sets.  Actually, mingw-w64 supports most (if not all) what MinGW.org supports plus a bit more (Unicode-entry support, 64-bit and 32-bit, partial ARM 32 support, supporting also other compilers then just gcc (but of course gcc is our main-target, full C99-math, working complex-math support, etc).

Just one point here I got curious about. What you mean by ABI?  The ABI of mingw-targets is the same for all targets using gcc.  So what ABI-differences you are talking about?!?

> Even if there were no problems with MinGW64, I don't think we should
> stop supporting MinGW32 just like that, it is still a live project,
> and I, for one, is quite happy with it.  I hope GDB will not drop its
> support any time soon.

No problem about this, but why blocking things not related to MinGW.org?

Kai

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 18:14                                       ` Jan Kratochvil
  2014-12-18 18:24                                         ` Pedro Alves
@ 2014-12-18 20:26                                         ` Eli Zaretskii
  1 sibling, 0 replies; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-18 20:26 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: palves, ktietz, sellcey, brobecker, yao, gdb-patches

> Date: Thu, 18 Dec 2014 19:14:32 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Kai Tietz <ktietz@redhat.com>, Steve Ellcey <sellcey@imgtec.com>,
>         Eli Zaretskii <eliz@gnu.org>, brobecker@adacore.com,
>         yao@codesourcery.com, gdb-patches@sourceware.org
> 
> As global maintainer Eli asked for ftw()->fts()

Actually, I didn't.  (But I don't object to that, either.)  I just
said that MinGW32 doesn't have ftw.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 20:15                                           ` Kai Tietz
@ 2014-12-18 20:47                                             ` Eli Zaretskii
  2014-12-18 20:55                                               ` Kai Tietz
  2014-12-18 23:47                                             ` Pedro Alves
  1 sibling, 1 reply; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-18 20:47 UTC (permalink / raw)
  To: Kai Tietz; +Cc: jan.kratochvil, sellcey, brobecker, yao, gdb-patches

> Date: Thu, 18 Dec 2014 15:14:48 -0500 (EST)
> From: Kai Tietz <ktietz@redhat.com>
> Cc: Jan Kratochvil <jan.kratochvil@redhat.com>, sellcey@imgtec.com,
>         brobecker@adacore.com, yao@codesourcery.com,
>         gdb-patches@sourceware.org
> 
> > > >From the Fedora point of view MinGW64 32-bit mode seems to be a superset
> > > >of
> > > MinGW32 so why to care about MinGW32 anymore?  Or what do I miss?
> > 
> > That _I_ use MinGW32?
> 
> That is actually your problem, isn't it?

I don't see it as a problem, necessarily.

> The mingw-w64 target support ftw, so why not simply allow it for targets providing it, and other targets can be covered by gnulib?

Sure, why not?  I wasn't objecting to that, I just provided
information, since Jan seemed to think ftw is available everywhere.

> What libraries "mingw-w64" breaks often?!?  Could you please go in detail?  I am curious to hear that, as all distributors I know (Fedora, Debian, OpenSuse, ArchLinux, ...) haven't reported this.  Or is that just one thing you have a "gut" feeling about?

The latest that I saw is this:

  http://lists.gnu.org/archive/html/bug-gnulib/2014-12/msg00186.html

And I remember a few more lately.

But look, I don't want to argue, I specifically said that.  Jan asked
why not forget about MinGW32, and I gave _my_ reasons.  You don't have
to agree, and we don't have to convince each other.  My only request
is that GDB doesn't drop MinGW32 support.

> Just one point here I got curious about. What you mean by ABI?  The ABI of mingw-targets is the same for all targets using gcc.  So what ABI-differences you are talking about?!?

Exception handling across DLLs is one difference I know of.

> > Even if there were no problems with MinGW64, I don't think we should
> > stop supporting MinGW32 just like that, it is still a live project,
> > and I, for one, is quite happy with it.  I hope GDB will not drop its
> > support any time soon.
> 
> No problem about this, but why blocking things not related to MinGW.org?

I didn't, it's a misunderstanding.  Sorry if I caused it.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build]
  2014-12-18 20:47                                             ` Eli Zaretskii
@ 2014-12-18 20:55                                               ` Kai Tietz
  0 siblings, 0 replies; 93+ messages in thread
From: Kai Tietz @ 2014-12-18 20:55 UTC (permalink / raw)
  To: Eli Zaretskii
  Cc: Kai Tietz, Jan Kratochvil, sellcey, Joel Brobecker, Yao Qi, gdb-patches

2014-12-18 21:47 GMT+01:00 Eli Zaretskii <eliz@gnu.org>:
>> Date: Thu, 18 Dec 2014 15:14:48 -0500 (EST)
>> From: Kai Tietz <ktietz@redhat.com>
>> Cc: Jan Kratochvil <jan.kratochvil@redhat.com>, sellcey@imgtec.com,
>>         brobecker@adacore.com, yao@codesourcery.com,
>>         gdb-patches@sourceware.org
>>
>> > > >From the Fedora point of view MinGW64 32-bit mode seems to be a superset
>> > > >of
>> > > MinGW32 so why to care about MinGW32 anymore?  Or what do I miss?
>> >
>> > That _I_ use MinGW32?
>>
>> That is actually your problem, isn't it?
>
> I don't see it as a problem, necessarily.
>
>> The mingw-w64 target support ftw, so why not simply allow it for targets providing it, and other targets can be covered by gnulib?
>
> Sure, why not?  I wasn't objecting to that, I just provided
> information, since Jan seemed to think ftw is available everywhere.
>
>> What libraries "mingw-w64" breaks often?!?  Could you please go in detail?  I am curious to hear that, as all distributors I know (Fedora, Debian, OpenSuse, ArchLinux, ...) haven't reported this.  Or is that just one thing you have a "gut" feeling about?
>
> The latest that I saw is this:
>
>   http://lists.gnu.org/archive/html/bug-gnulib/2014-12/msg00186.html
>
> And I remember a few more lately.

Hmm, this isn't something we got reported at all.  As you are using
pthread-library based toolchain (this is a build-option, and not a
mandatory mingw-w64 thing at all) I don't see that this is a mingw-w64
venture issue at all.  Btw we (on mingw-w64) strongly recomment to use
winpthread instead, as it solves some quirks existing with other
pthread-implementations available for Win32 ... anyway later is
off-topic.

> But look, I don't want to argue, I specifically said that.  Jan asked
> why not forget about MinGW32, and I gave _my_ reasons.  You don't have
> to agree, and we don't have to convince each other.  My only request
> is that GDB doesn't drop MinGW32 support.

Sure, no problem about that.  Nevertheless I have a problem if you try
to tell people things not true.

>> Just one point here I got curious about. What you mean by ABI?  The ABI of mingw-targets is the same for all targets using gcc.  So what ABI-differences you are talking about?!?
>
> Exception handling across DLLs is one difference I know of.

This is again a build-option of gcc, and has nothing directly to do
with mingw-w64.  For example, you can find for 32-bit dw2 based
exception-handling toolchain provided by mingw-builds projects (and
some others providing for 32-bit dw2 too).  For 64-bit there is SEH,
which replaces dw2 completely.

>> > Even if there were no problems with MinGW64, I don't think we should
>> > stop supporting MinGW32 just like that, it is still a live project,
>> > and I, for one, is quite happy with it.  I hope GDB will not drop its
>> > support any time soon.
>>
>> No problem about this, but why blocking things not related to MinGW.org?
>
> I didn't, it's a misunderstanding.  Sorry if I caused it.

Ok, np.

Kai

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-17 21:02                                   ` [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Jan Kratochvil
                                                       ` (3 preceding siblings ...)
  2014-12-18 17:23                                     ` Eli Zaretskii
@ 2014-12-18 20:56                                     ` Sergio Durigan Junior
  4 siblings, 0 replies; 93+ messages in thread
From: Sergio Durigan Junior @ 2014-12-18 20:56 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Kai Tietz, Steve Ellcey, Eli Zaretskii, brobecker, yao, gdb-patches

On Wednesday, December 17 2014, Jan Kratochvil wrote:

> On Wed, 17 Dec 2014 18:29:51 +0100, Steve Ellcey wrote:
>> /scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result]
>> cc1: all warnings being treated as errors
>> make[1]: *** [compile.o] Error 1
>
> It should get fixed by this patch.

https://sourceware.org/bugzilla/show_bug.cgi?id=17718 has been fixed
about this as well, FYI.

> I have briefly tested (on Linux; on MinGW I have only tested the build) it
> really does delete the directory and its files.
>
> OK for check-in?
>
>
> Thanks,
> Jan
> gdb/ChangeLog
> 2014-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
> 	* compile/compile.c: Include ftw.h.
> 	(do_rmdir_fn): New function.
> 	(do_rmdir): Call nftw with it.
>
> diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
> index 414fc35..7dbc819 100644
> --- a/gdb/compile/compile.c
> +++ b/gdb/compile/compile.c
> @@ -37,6 +37,7 @@
>  #include "filestuff.h"
>  #include "target.h"
>  #include "osabi.h"
> +#include <ftw.h>
>  
>  \f
>  
> @@ -162,17 +163,42 @@ compile_code_command (char *arg, int from_tty)
>    do_cleanups (cleanup);
>  }
>  
> +/* Helper for do_rmdir.  */
> +
> +static int
> +do_rmdir_fn (const char *fpath, const struct stat *sb, int typeflag,
> +	     struct FTW *ftwbuf)
> +{
> +  switch (typeflag)
> +    {
> +    case FTW_DP:
> +      if (rmdir (fpath) != 0)
> +	warning (_("Cannot remove 'compile' command directory \"%s\": %s"),
> +		 fpath, safe_strerror (errno));
> +      break;
> +    case FTW_F:
> +      if (unlink (fpath) != 0)
> +	warning (_("Cannot remove 'compile' command file \"%s\": %s"),
> +		 fpath, safe_strerror (errno));
> +      break;
> +    default:
> +      warning (_("Unknown 'typeflag' %d for 'compile' command file \"%s\"."),
> +	       typeflag, fpath);
> +    }
> +
> +  /* Continue the walk.  */
> +  return 0;
> +}
> +
>  /* A cleanup function to remove a directory and all its contents.  */
>  
>  static void
>  do_rmdir (void *arg)
>  {
>    const char *dir = arg;
> -  char *zap;
> -  
> +
>    gdb_assert (strncmp (dir, TMP_PREFIX, strlen (TMP_PREFIX)) == 0);
> -  zap = concat ("rm -rf ", dir, (char *) NULL);
> -  system (zap);
> +  nftw (dir, do_rmdir_fn, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
>  }
>  
>  /* Return the name of the temporary directory to use for .o files, and

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 19:07                                             ` Pedro Alves
@ 2014-12-18 21:05                                               ` Jan Kratochvil
  2014-12-18 21:11                                                 ` Eli Zaretskii
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-18 21:05 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Kai Tietz, Steve Ellcey, Eli Zaretskii, brobecker, yao, gdb-patches

On Thu, 18 Dec 2014 20:07:39 +0100, Pedro Alves wrote:
> Ranting does not help, that's all I'll say.

I am just trying to show (for many years) despite contributor's best effort
(*) the current GDB project's maintenance requires multiple reimplementations
of patches until everyone approves the patch as all the requirements are
nowhere written and the maintainers only show their requirements one after
another after each of the patch variant is submitted.  This leads to the slow
development of GDB despite a lot of time invested into it.

(*) I feel at least as good as a median newcomer to GDB.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 21:05                                               ` Jan Kratochvil
@ 2014-12-18 21:11                                                 ` Eli Zaretskii
  2014-12-18 21:24                                                   ` Jan Kratochvil
  0 siblings, 1 reply; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-18 21:11 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: palves, ktietz, sellcey, brobecker, yao, gdb-patches

> Date: Thu, 18 Dec 2014 22:04:45 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Kai Tietz <ktietz@redhat.com>, Steve Ellcey <sellcey@imgtec.com>,
>         Eli Zaretskii <eliz@gnu.org>, brobecker@adacore.com,
>         yao@codesourcery.com, gdb-patches@sourceware.org
> 
> I am just trying to show (for many years) despite contributor's best effort
> (*) the current GDB project's maintenance requires multiple reimplementations
> of patches until everyone approves the patch as all the requirements are
> nowhere written and the maintainers only show their requirements one after
> another after each of the patch variant is submitted.  This leads to the slow
> development of GDB despite a lot of time invested into it.

If this is a problem, how about writing down the requirements?

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 21:11                                                 ` Eli Zaretskii
@ 2014-12-18 21:24                                                   ` Jan Kratochvil
  2014-12-18 22:18                                                     ` Sergio Durigan Junior
                                                                       ` (2 more replies)
  0 siblings, 3 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-18 21:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: palves, ktietz, sellcey, brobecker, yao, gdb-patches

On Thu, 18 Dec 2014 22:11:16 +0100, Eli Zaretskii wrote:
> If this is a problem, how about writing down the requirements?

I was more general above.  In this specific case it would mean describing APIs
of all the supported OSes.  I do not think it is possible.

This can be implemented by a buildbot for all supported OSes.

A prerequisite for that is to settle down a list of really supported OSes.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 21:24                                                   ` Jan Kratochvil
@ 2014-12-18 22:18                                                     ` Sergio Durigan Junior
  2014-12-18 23:06                                                     ` Pedro Alves
  2014-12-19  8:24                                                     ` Eli Zaretskii
  2 siblings, 0 replies; 93+ messages in thread
From: Sergio Durigan Junior @ 2014-12-18 22:18 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Eli Zaretskii, palves, ktietz, sellcey, brobecker, yao, gdb-patches

On Thursday, December 18 2014, Jan Kratochvil wrote:

> This can be implemented by a buildbot for all supported OSes.

As Pedro already mentioned, I am working towards setting up a buildbot
for GDB.  I will write more details soon at the gdb@ list; I don't want
to hijack this thread.

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 21:24                                                   ` Jan Kratochvil
  2014-12-18 22:18                                                     ` Sergio Durigan Junior
@ 2014-12-18 23:06                                                     ` Pedro Alves
  2014-12-19  0:12                                                       ` Jan Kratochvil
  2014-12-19  8:24                                                     ` Eli Zaretskii
  2 siblings, 1 reply; 93+ messages in thread
From: Pedro Alves @ 2014-12-18 23:06 UTC (permalink / raw)
  To: Jan Kratochvil, Eli Zaretskii
  Cc: ktietz, sellcey, brobecker, yao, gdb-patches

On 12/18/2014 09:23 PM, Jan Kratochvil wrote:
> On Thu, 18 Dec 2014 22:11:16 +0100, Eli Zaretskii wrote:
>> If this is a problem, how about writing down the requirements?
> 
> I was more general above.  In this specific case it would mean describing APIs
> of all the supported OSes.  I do not think it is possible.

- gnulib seems to be good at describe portability issues.
- We use gnulib as low level host portability layer

Always check gnulib.

> This can be implemented by a buildbot for all supported OSes.

Yes, we're getting there.  We need a working master buildbot setup first.
Ideally, that'd be setup in sourceware.org itself, and then we'd
use machines in the gcc compile farm for the build slaves.  But,
as you know, we're actively working on this.

> A prerequisite for that is to settle down a list of really supported OSes.

Not necessarily.  I see it the other way around.   Once buildbot is up
and running for a while, we can require that either people setup
buildbot slaves for their favorite host OSs, or the OSs will be considered
unsupported.

Meanwhile, we should start with a list of OSes gdb supposedly
builds for, per gdb/configure.host.  I had built this table
a while ago:

 https://sourceware.org/ml/gdb/2014-10/msg00026.html

It's obviously quite bare, missing OS version info, for
example.  I had extended it since with GDBserver info,
but left it to neglect on my hard drive since.  But it's a start.
I've now put it up on the wiki, here:

  https://sourceware.org/gdb/wiki/Systems

(linked from the home page).

Maybe once this has more info, it should be migrated to
MAINTAINERS or README in the sources, but while in "collect info"
phase at least, wiki is easier.  Everyone, please do feel free
to extend|massage|whatever this page.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 20:15                                           ` Kai Tietz
  2014-12-18 20:47                                             ` Eli Zaretskii
@ 2014-12-18 23:47                                             ` Pedro Alves
  2014-12-19  9:28                                               ` Kai Tietz
  2014-12-19 19:25                                               ` Jan Kratochvil
  1 sibling, 2 replies; 93+ messages in thread
From: Pedro Alves @ 2014-12-18 23:47 UTC (permalink / raw)
  To: Kai Tietz, Eli Zaretskii
  Cc: Jan Kratochvil, sellcey, brobecker, yao, gdb-patches

On 12/18/2014 08:14 PM, Kai Tietz wrote:
> ----- Ursprüngliche Mail -----
>>> Date: Thu, 18 Dec 2014 18:31:03 +0100
>>> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>>> Cc: ktietz@redhat.com, sellcey@imgtec.com, brobecker@adacore.com,
>>>         yao@codesourcery.com, gdb-patches@sourceware.org
>>>
>>> >From the Fedora point of view MinGW64 32-bit mode seems to be a superset
>>>> of
>>> MinGW32 so why to care about MinGW32 anymore?  Or what do I miss?
>>
>> That _I_ use MinGW32?
> 
> That is actually your problem, isn't it?  The mingw-w64 target support ftw, so why
> not simply allow it for targets providing it, and other targets can be covered by gnulib?
> Anyway gnulib is nothing I am concerned in general.

Let me try to make this clear.

gnulib does not provide an ftw replacement.  And AFAIK, that's on
purpose.  Note that ftw has been marked obsolete in POSIX.1-2008.
Per POSIX, applications "should" be using nftw/nftw64 instead.

For our purposes, both APIs are just as good (*).  It's just
that ftw has System V roots, while fts has BSD roots.

In practice, programs that use fts instead are just, if not
more portable.

But, as I mentioned, gnulib provides an fts replacement
for systems that don't have it.  So if we use fts instead, we're
good to go everywhere.

(*) - see ftw vs fts limitations here:
   http://lists.gnu.org/archive/html/bug-gnu-utils/2003-02/msg00224.html

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 23:06                                                     ` Pedro Alves
@ 2014-12-19  0:12                                                       ` Jan Kratochvil
  2014-12-19 10:48                                                         ` Pedro Alves
  0 siblings, 1 reply; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-19  0:12 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Eli Zaretskii, ktietz, sellcey, brobecker, yao, gdb-patches

On Fri, 19 Dec 2014 00:06:10 +0100, Pedro Alves wrote:
> Always check gnulib.

As I have described I do not find the obsolete list of OSes too useful, it is
rather waiting for the buildbot.


> > A prerequisite for that is to settle down a list of really supported OSes.
> 
> Not necessarily.  I see it the other way around.   Once buildbot is up
> and running for a while, we can require that either people setup
> buildbot slaves for their favorite host OSs, or the OSs will be considered
> unsupported.

I do not expect this can ever pass GDB global maintainers.


> I've now put it up on the wiki, here:
> 
>   https://sourceware.org/gdb/wiki/Systems

Yes, that is really useful, waiting for it for so many years, thanks.


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 21:24                                                   ` Jan Kratochvil
  2014-12-18 22:18                                                     ` Sergio Durigan Junior
  2014-12-18 23:06                                                     ` Pedro Alves
@ 2014-12-19  8:24                                                     ` Eli Zaretskii
  2 siblings, 0 replies; 93+ messages in thread
From: Eli Zaretskii @ 2014-12-19  8:24 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: palves, ktietz, sellcey, brobecker, yao, gdb-patches

> Date: Thu, 18 Dec 2014 22:23:53 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: palves@redhat.com, ktietz@redhat.com, sellcey@imgtec.com,
>         brobecker@adacore.com, yao@codesourcery.com,
>         gdb-patches@sourceware.org
> 
> On Thu, 18 Dec 2014 22:11:16 +0100, Eli Zaretskii wrote:
> > If this is a problem, how about writing down the requirements?
> 
> I was more general above.

So was I.  If you think our requirements are not detailed enough, with
the result of complicating the patch submission process and the job of
contributors, I think we should try to put more details into the
existing documentation.

Of course, some requirements that come up during the review cannot
possibly be codified, because they are general principles or minor
preferences that are too many to write down.  I don't think we can
avoid that, but we could try.  E.g., after each such issue comes up,
we could ask ourselves whether it is worth adding to the
documentation.

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 23:47                                             ` Pedro Alves
@ 2014-12-19  9:28                                               ` Kai Tietz
  2014-12-19 19:25                                               ` Jan Kratochvil
  1 sibling, 0 replies; 93+ messages in thread
From: Kai Tietz @ 2014-12-19  9:28 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Eli Zaretskii, Jan Kratochvil, sellcey, brobecker, yao, gdb-patches

----- Ursprüngliche Mail -----
Just for the records.  We provide on mingw-w64 both APIs.  The nftw, and the old ftw.

Kai

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-19  0:12                                                       ` Jan Kratochvil
@ 2014-12-19 10:48                                                         ` Pedro Alves
  0 siblings, 0 replies; 93+ messages in thread
From: Pedro Alves @ 2014-12-19 10:48 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Eli Zaretskii, ktietz, sellcey, brobecker, yao, gdb-patches

On 12/19/2014 12:11 AM, Jan Kratochvil wrote:
> On Fri, 19 Dec 2014 00:06:10 +0100, Pedro Alves wrote:
>> Always check gnulib.
> 
> As I have described I do not find the obsolete list of OSes too useful, it is
> rather waiting for the buildbot.

Not just the list, but the code.

>> I've now put it up on the wiki, here:
>>
>>   https://sourceware.org/gdb/wiki/Systems
> 
> Yes, that is really useful, waiting for it for so many years, thanks.

Note that all I did was sed configure.host, and massage the result
a bit.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 18:41                                           ` Jan Kratochvil
  2014-12-18 19:07                                             ` Pedro Alves
@ 2014-12-19 12:59                                             ` Joel Brobecker
  1 sibling, 0 replies; 93+ messages in thread
From: Joel Brobecker @ 2014-12-19 12:59 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Pedro Alves, Kai Tietz, Steve Ellcey, Eli Zaretskii, yao, gdb-patches

> > Huh?
> 
> This is from my memories of reading #gdb@freenode that FSF GDB was reporting
> fatal errors on trivial programs for anyone asking about OSX there.  I do not
> have OSX to test it myself (and I do not remember if I tested GDB there myself
> when I had OSX available) so maybe GDB works on OSX now if you say so, OK.

OSX is not an easy OS for debuggers, and I am not surprised that people
might have some issues with it. But, FWIW, I confirm GDB works pretty
well for us. And we also tested it on the latest OSX release, and for
the first time ever, nothing appears to have regressed.

Not sure what people's issues are on OS, and I won't hijack this thread
to discuss this.

-- 
Joel

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-18 23:47                                             ` Pedro Alves
  2014-12-19  9:28                                               ` Kai Tietz
@ 2014-12-19 19:25                                               ` Jan Kratochvil
  2014-12-19 20:55                                                 ` Jan Kratochvil
  2014-12-20 12:26                                                 ` Joel Brobecker
  1 sibling, 2 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-19 19:25 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Kai Tietz, Eli Zaretskii, sellcey, brobecker, yao, gdb-patches

On Fri, 19 Dec 2014 00:47:27 +0100, Pedro Alves wrote:
> For our purposes, both APIs are just as good (*).  It's just
> that ftw has System V roots, while fts has BSD roots.
> 
> In practice, programs that use fts instead are just, if not
> more portable.
> 
> But, as I mentioned, gnulib provides an fts replacement
> for systems that don't have it.  So if we use fts instead, we're
> good to go everywhere.

Linux fts man page
	http://man7.org/linux/man-pages/man3/fts.3.html
says
	BUGS
	All of the APIs described in this man page are not safe when
	compiling a program using the LFS APIs (e.g., when compiling with
	-D_FILE_OFFSET_BITS=64).
and _FILE_OFFSET_BITS=64 happens on 32-bit hosts and --enable-64-bit-bfd.

Contrary to it gnulib fts documentation
	https://www.gnu.org/software/gnulib/manual/html_node/fts_005fread.html
says
	On platforms where off_t is a 32-bit type, this function may not
	correctly report the size of files or block devices larger than 2 GB
	and may not work correctly on huge directories larger than 2 GB. Also,
	on platforms where ino_t is a 32-bit type, this function may report
	inode numbers incorrectly. The fix is to use the AC_SYS_LARGEFILE
	macro (only on Mac OS X systems).

This would suggest as if GDB should be compatible with 32-bit hosts and
--enable-64-bit-bfd GDB should use gnulib fts even on Linux; but I guess the
gnulib fts replacement would not be active on Linux.

The temporary files being deleted are never larger than 2GB nor their size is
read.  So I hope nobody is going address these issues (I would add 32-bit
hosts are not relevant anymore anyway).


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-19 19:25                                               ` Jan Kratochvil
@ 2014-12-19 20:55                                                 ` Jan Kratochvil
  2014-12-20 12:26                                                 ` Joel Brobecker
  1 sibling, 0 replies; 93+ messages in thread
From: Jan Kratochvil @ 2014-12-19 20:55 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Kai Tietz, Eli Zaretskii, sellcey, brobecker, yao, gdb-patches

On Fri, 19 Dec 2014 20:24:57 +0100, Jan Kratochvil wrote:
> This would suggest as if GDB should be compatible with 32-bit hosts and
> --enable-64-bit-bfd GDB should use gnulib fts even on Linux; but I guess the
> gnulib fts replacement would not be active on Linux.

It would be active - so that this mail should be resolved by it:

gnulib/modules/fts:
dnl Use this version of fts unconditionally, since the GNU libc and
dnl NetBSD versions have bugs and/or unnecessary limitations.
AC_LIBOBJ([fts])


Jan

^ permalink raw reply	[flat|nested] 93+ messages in thread

* Re: [patch] compile: rm -rf -> ftw()+rmdir()+unlink()  [Re: [patch] compile: Fix MinGW build]
  2014-12-19 19:25                                               ` Jan Kratochvil
  2014-12-19 20:55                                                 ` Jan Kratochvil
@ 2014-12-20 12:26                                                 ` Joel Brobecker
  1 sibling, 0 replies; 93+ messages in thread
From: Joel Brobecker @ 2014-12-20 12:26 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Pedro Alves, Kai Tietz, Eli Zaretskii, sellcey, yao, gdb-patches

> The temporary files being deleted are never larger than 2GB nor their
> size is read.  So I hope nobody is going address these issues (I would
> add 32-bit hosts are not relevant anymore anyway).

Yes, they are still very relevant. A lot of programs do not want
to switch over to 64bit; and I think the x32 ABI might also have
stemmed from that.

-- 
Joel

^ permalink raw reply	[flat|nested] 93+ messages in thread

end of thread, other threads:[~2014-12-20 12:26 UTC | newest]

Thread overview: 93+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-23 19:27 [PATCH v4 00/14] let gdb reuse gcc's C compiler Jan Kratochvil
2014-11-23 19:27 ` [PATCH v4 02/14] add gcc/gdb interface files Jan Kratochvil
2014-11-23 19:27 ` [PATCH v4 03/14] add some missing ops to DWARF assembler Jan Kratochvil
2014-11-23 19:27 ` [PATCH v4 01/14] introduce ui_file_write_for_put Jan Kratochvil
2014-11-23 19:27 ` [PATCH v4 04/14] add make_unqualified_type Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 13/14] add s390_gcc_target_options Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 11/14] export dwarf2_reg_to_regnum_or_error Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 12/14] add linux_infcall_mmap Jan Kratochvil
2014-12-15 12:41   ` Ulrich Weigand
2014-12-15 13:49     ` Yao Qi
2014-12-15 16:48       ` Jan Kratochvil
2014-12-16  5:27         ` Yao Qi
2014-11-23 19:28 ` [PATCH v4 05/14] add dummy frame destructor Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 09/14] split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 06/14] add infcall_mmap and gcc_target_options gdbarch methods Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 07/14] add gnu_triplet_regexp gdbarch method Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 08/14] introduce call_function_by_hand_dummy Jan Kratochvil
2014-11-23 19:28 ` [PATCH v4 10/14] make dwarf_expr_frame_base_1 public Jan Kratochvil
2014-11-23 19:29 ` [PATCH v4 14/14] the "compile" command Jan Kratochvil
2014-12-14  6:05   ` Yao Qi
2014-12-14  7:53     ` Jan Kratochvil
2014-12-14  8:54       ` Yao Qi
2014-12-14 18:24         ` [mingw rfc] Add mkdtemp to gdb/gnulib/ [Re: [PATCH v4 14/14] the "compile" command] Jan Kratochvil
2014-12-15  3:16           ` Yao Qi
2014-12-15 12:44             ` Joel Brobecker
2014-12-15 13:11               ` Kai Tietz
2014-12-15 13:24               ` Yao Qi
2014-12-15 17:12               ` Jan Kratochvil
2014-12-15 17:48                 ` Eli Zaretskii
2014-12-15 18:14                 ` Joel Brobecker
2014-12-15 18:21                   ` Jan Kratochvil
2014-12-15 18:35                     ` Joel Brobecker
2014-12-15 18:40                       ` Jan Kratochvil
2014-12-15 18:57                         ` Eli Zaretskii
2014-12-15 22:28                           ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Jan Kratochvil
2014-12-15 22:56                             ` Jan Kratochvil
2014-12-16  3:40                               ` Eli Zaretskii
2014-12-16  9:04                                 ` Kai Tietz
2014-12-17 21:02                                   ` [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Jan Kratochvil
2014-12-17 22:07                                     ` Steve Ellcey
2014-12-17 22:42                                     ` Pedro Alves
2014-12-18 18:14                                       ` Jan Kratochvil
2014-12-18 18:24                                         ` Pedro Alves
2014-12-18 18:41                                           ` Jan Kratochvil
2014-12-18 19:07                                             ` Pedro Alves
2014-12-18 21:05                                               ` Jan Kratochvil
2014-12-18 21:11                                                 ` Eli Zaretskii
2014-12-18 21:24                                                   ` Jan Kratochvil
2014-12-18 22:18                                                     ` Sergio Durigan Junior
2014-12-18 23:06                                                     ` Pedro Alves
2014-12-19  0:12                                                       ` Jan Kratochvil
2014-12-19 10:48                                                         ` Pedro Alves
2014-12-19  8:24                                                     ` Eli Zaretskii
2014-12-19 12:59                                             ` Joel Brobecker
2014-12-18 20:26                                         ` Eli Zaretskii
2014-12-18  5:38                                     ` Yao Qi
2014-12-18 17:23                                     ` Eli Zaretskii
2014-12-18 17:31                                       ` Jan Kratochvil
2014-12-18 17:40                                         ` Eli Zaretskii
2014-12-18 20:15                                           ` Kai Tietz
2014-12-18 20:47                                             ` Eli Zaretskii
2014-12-18 20:55                                               ` Kai Tietz
2014-12-18 23:47                                             ` Pedro Alves
2014-12-19  9:28                                               ` Kai Tietz
2014-12-19 19:25                                               ` Jan Kratochvil
2014-12-19 20:55                                                 ` Jan Kratochvil
2014-12-20 12:26                                                 ` Joel Brobecker
2014-12-18 20:56                                     ` Sergio Durigan Junior
2014-12-17 17:30                                 ` [patch] compile: Fix MinGW build [Re: [mingw rfc] Add mkdtemp to gdb/gnulib/] Steve Ellcey
2014-12-16  3:37                             ` Eli Zaretskii
2014-12-16  9:06                               ` Kai Tietz
2014-12-17 19:18                               ` Jan Kratochvil
2014-12-17 19:31                                 ` Eli Zaretskii
2014-12-17 19:37                                   ` Jan Kratochvil
2014-12-17 20:34                                   ` Pedro Alves
2014-12-18 17:22                                     ` Eli Zaretskii
2014-12-18 18:00                                       ` Pedro Alves
2014-12-16 12:40                             ` Pierre Muller
2014-12-17 18:21                               ` Jan Kratochvil
2014-12-17  1:22                             ` Yao Qi
2014-12-17 10:57                               ` Pedro Alves
2014-12-17 11:40                                 ` Yao Qi
2014-12-17 11:43                                   ` Pedro Alves
2014-12-17 11:56                                     ` Yao Qi
2014-12-17 19:15                                     ` Jan Kratochvil
2014-12-17 11:16                             ` Pedro Alves
2014-12-17 18:17                               ` [patchv2] " Jan Kratochvil
2014-12-17 18:33                                 ` Pedro Alves
2014-12-17 19:12                                   ` [commit] " Jan Kratochvil
2014-12-05 18:29 ` [patch 15/14] GDB/GCC compile function pointers [Re: [PATCH v4 00/14] let gdb reuse gcc's C compiler] Jan Kratochvil
2014-12-12 21:51   ` obsolete: " Jan Kratochvil
2014-12-12 14:40 ` [PATCH v4 00/14] let gdb reuse gcc's C compiler Pedro Alves
2014-12-12 21:46   ` [commit all 14 parts] " Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).