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.
2014-05-14 22:35:45 +02:00
|
|
|
|
/* Convert types from GDB to GCC
|
|
|
|
|
|
2015-01-01 10:32:14 +01:00
|
|
|
|
Copyright (C) 2014-2015 Free Software Foundation, Inc.
|
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.
2014-05-14 22:35:45 +02:00
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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. */
|
2015-07-08 14:42:19 +02:00
|
|
|
|
if (add != NULL && add->gcc_type != gcc_type)
|
|
|
|
|
error (_("Unexpected type id from GCC, check you use recent enough GCC."));
|
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.
2014-05-14 22:35:45 +02:00
|
|
|
|
|
|
|
|
|
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. */
|
2015-07-06 22:05:06 +02:00
|
|
|
|
type = check_typedef (type);
|
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.
2014-05-14 22:35:45 +02:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
}
|