binutils-gdb/gdb/compile/compile.h

103 lines
3.4 KiB
C
Raw Normal View History

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
/* 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 */