New python function gdb.lookup_objfile.

gdb/ChangeLog:

	* NEWS: Mention gdb.lookup_objfile.
	* python/python.c (GdbMethods): Add lookup_objfile.
	* python/python-internal.h (gdbpy_lookup_objfile): Declare.
	* python/py-objfile.c: #include "symtab.h".
	(objfpy_build_id_ok, objfpy_build_id_matches): New functions.
	(objfpy_lookup_objfile_by_name): New function.
	(objfpy_lookup_objfile_by_build_id): New function.
	(gdbpy_lookup_objfile): New function.

gdb/doc/ChangeLog:

	* python.texi (Objfiles In Python): Document gdb.lookup_objfile.

gdb/testsuite/ChangeLog:

	* lib/gdb-python.exp (get_python_valueof): New function.
	* gdb.python/py-objfile.exp: Add tests for gdb.lookup_objfile.
introduce ui_file_write_for_put

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.

gdb/ChangeLog
2014-12-12  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.
add gcc/gdb interface files

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.

include/ChangeLog
2014-12-12  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.
add some missing ops to DWARF assembler

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

gdb/testsuite/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>

	* lib/dwarf.exp (_location): Ignore blank lines.  Allow comments.
	Handle DW_OP_pick, DW_OP_skip, DW_OP_bra.
add make_unqualified_type

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.

gdb/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>

	* gdbtypes.h (make_unqualified_type): Declare.
	* gdbtypes.c (make_unqualified_type): New function.
add dummy frame destructor

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.

gdb/ChangeLog
2014-12-12  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.
add infcall_mmap and gcc_target_options gdbarch methods

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.

gdb/ChangeLog
2014-12-12  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.
add gnu_triplet_regexp gdbarch method

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.

gdb/ChangeLog
2014-12-12  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.
introduce call_function_by_hand_dummy

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.

gdb/ChangeLog
2014-12-12  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.
split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax

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.

gdb/ChangeLog
2014-12-12  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.
make dwarf_expr_frame_base_1 public

This exports dwarf_expr_frame_base_1 so that other code can use it.

gdb/ChangeLog
2014-12-12  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.
export dwarf2_reg_to_regnum_or_error

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

gdb/ChangeLog
2014-12-12  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.
add linux_infcall_mmap

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

gdb/ChangeLog
2014-12-12  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.
add s390_gcc_target_options

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".

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

	* s390-linux-tdep.c (s390_gcc_target_options): New function.
	(s390_gdbarch_init): Add it to gdbarch.
the "compile" command

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-12-12  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-12-12  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-12-12  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.
Automatic date update in version.in
Give quick_symbol_functions "methods" a consistent naming scheme.
Add missing function comments.

gdb/ChangeLog:

	* psymtab.c (psym_map_symtabs_matching_filename): Renamed from
	partial_map_symtabs_matching_filename.  All uses updated.
	(psym_find_pc_sect_compunit_symtab): Renamed from
	find_pc_sect_compunit_symtab_from_partial.  All uses updated.
	Add function comment.
	(psym_lookup_symbol): Renamed from lookup_symbol_aux_psymtabs.
	All uses updated.  Add function comment.
	(psym_relocate): Renamed from relocate_psymtabs.  All uses updated.
	Add function comment.
	(psym_find_last_source_symtab): Renamed from
	find_last_source_symtab_from_partial.  All uses updated.
	Add function comment.
	(psym_forget_cached_source_info): Renamed from
	forget_cached_source_info_partial.  All uses updated.
	Add function comment.
	(psym_print_stats): Renamed from print_psymtab_stats_for_objfile.
	All uses updated.  Add function comment.
	(psym_dump): Renamed from dump_psymtabs_for_objfile.  All uses
	updated.  Add function comment.
	(psym_expand_symtabs_for_function): Renamed from
	read_symtabs_for_function.  All uses updated.  Update function comment.
	(psym_expand_all_symtabs): Renamed from expand_partial_symbol_tables.
	All uses updated.  Add function comment.
	(psym_expand_symtabs_with_fullname): Renamed from
	read_psymtabs_with_fullname.  All uses updated.  Add function comment.
	(psym_map_symbol_filenames): Renamed from map_symbol_filenames_psymtab.
	All uses updated.  Add function comment.
	(psym_map_matching_symbols): Renamed from map_matching_symbols_psymtab.
	All uses updated.
	(psym_expand_symtabs_matching): Renamed from
	expand_symtabs_matching_via_partial.  All uses updated.
	Add function comment.
	(psym_has_symbols): Renamed from objfile_has_psyms.  All uses updated.
	Add function comment.
Rename cp_is_anonymous to cp_is_in_anonymous.

gdb/ChangeLog:

	* cp-support.h (cp_is_in_anonymous): Renamed from cp_is_anonymous.
	All callers updated.  Rename arg "namespace" to "symbol_name".
value_maybe_namespace_elt: Remove unnecessary test of result != NULL.

Both allocate_value and value_of_variable are guaranteed to return non-NULL.

gdb/ChangeLog:

	* valops.c (value_maybe_namespace_elt): Remove unnecessary test of
	result != NULL.
Lift DWARF unwinder restriction in dwarf2-frame.c::dwarf2_frame_cfa

GDB is currently broken on all SPARC targets when using GCC 4.9.
When trying to print any local variable:

    (gdb) p x
    can't compute CFA for this frame

This is related to the fact that the compiler now generates DWARF 4
debugging info by default, and in particular that it now emits
DW_OP_call_frame_cfa, which triggers a limitation in dwarf2_frame_cfa:

   /* This restriction could be lifted if other unwinders are known to
      compute the frame base in a way compatible with the DWARF
      unwinder.  */
   if (!frame_unwinder_is (this_frame, &dwarf2_frame_unwind)
       && !frame_unwinder_is (this_frame, &dwarf2_tailcall_frame_unwind))
     error (_("can't compute CFA for this frame"));

We couldn't append the dwarf2 unwinder to all SPARC targets because
it does not work properly with StackGhost:
    https://www.sourceware.org/ml/gdb-patches/2014-07/msg00012.html

We also later discovered that using the DWARF2 unwinder means
using it for computing the function's return address, which
is buggy when it comes to functions returning a struct (where
the return address is saved-pc+12 instead of saved-pc+8).
This is because GCC is emitting the info about the return address
as %o7/%i7 instead of the actual return address.  For functions
that have debugging info, we compensate by looking at the function's
return type and add the extra +4, but for function without debug
info, we're stuck.

EricB and I twisted the issue in all the directions we could think of,
and unfortunately couldn't find a way to make it work without
introduction one regression or another.

But, stepping back a little, just removing the restriction seems to work
well for us on all both sparc-elf and {sparc,sparc64}-solaris.
After reviewing the previous discussions about this test, I could
not figure out whether some unwinders were already known to have
incompatible CFAs or if the concern was purely theoretical:
    https://www.sourceware.org/ml/gdb-patches/2009-06/msg00191.html
    https://www.sourceware.org/ml/gdb-patches/2009-07/msg00570.html
    https://www.sourceware.org/ml/gdb-patches/2009-09/msg00027.html

At the moment, we took the approach of trying it out, and see what
happens...

gdb/ChangeLog:

        PR backtrace/16215:
        * dwarf2-frame.c (dwarf2_frame_cfa): Remove the restriction
        the frame unwinder must either be the dwarf2_frame_unwind
        or the dwarf2_tailcall_frame_unwind.  Verify that this_frame's
        stack_addr is valid before calling get_frame_base.  Throw
        an error if not valid.

Tested on sparc-solaris and sparc-elf with AdaCore's testsuite
(the FSF testsuite crashes all of AdaCore's solaris machines).