GDB (xrefs)
compile-internal.h
Go to the documentation of this file.
1 /* Header file for GDB compile command and supporting functions.
2  Copyright (C) 2014-2018 Free Software Foundation, Inc.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 
17 #ifndef GDB_COMPILE_INTERNAL_H
18 #define GDB_COMPILE_INTERNAL_H
19 
20 #include "hashtab.h"
21 #include "gcc-c-interface.h"
22 #include "common/enum-flags.h"
23 
24 /* enum-flags wrapper. */
25 DEF_ENUM_FLAGS_TYPE (enum gcc_qualifiers, gcc_qualifiers_flags);
26 
27 /* Debugging flag for the "compile" family of commands. */
28 
29 extern int compile_debug;
30 
31 struct block;
32 
33 /* An object of this type holds state associated with a given
34  compilation job. */
35 
37 {
38  /* The GCC front end. */
39 
40  struct gcc_base_context *fe;
41 
42  /* The "scope" of this compilation. */
43 
45 
46  /* The block in which an expression is being parsed. */
47 
48  const struct block *block;
49 
50  /* Specify "-std=gnu11", "-std=gnu++11" or similar. These options are put
51  after CU's DW_AT_producer compilation options to override them. */
52 
53  const char *gcc_target_options;
54 
55  /* How to destroy this object. */
56 
57  void (*destroy) (struct compile_instance *);
58 };
59 
60 /* A subclass of compile_instance that is specific to the C front
61  end. */
63 {
64  /* Base class. Note that the base class vtable actually points to a
65  gcc_c_fe_vtable. */
66 
68 
69  /* Map from gdb types to gcc types. */
70 
71  htab_t type_map;
72 
73  /* Map from gdb symbols to gcc error messages to emit. */
74 
76 };
77 
78 /* A helper macro that takes a compile_c_instance and returns its
79  corresponding gcc_c_context. */
80 
81 #define C_CTX(I) ((struct gcc_c_context *) ((I)->base.fe))
82 
83 /* Define header and footers for different scopes. */
84 
85 /* A simple scope just declares a function named "_gdb_expr", takes no
86  arguments and returns no value. */
87 
88 #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs"
89 #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs"
90 #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy"
91 #define COMPILE_I_PRINT_OUT_ARG_TYPE "void *"
92 #define COMPILE_I_PRINT_OUT_ARG "__gdb_out_param"
93 #define COMPILE_I_EXPR_VAL "__gdb_expr_val"
94 #define COMPILE_I_EXPR_PTR_TYPE "__gdb_expr_ptr_type"
95 
96 /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result
97  to a form suitable for the compiler source. The register names
98  should not clash with inferior defined macros. */
99 
101  int regnum);
102 
103 /* Convert compiler source register name to register number of
104  GDBARCH. Returned value is always >= 0, function throws an error
105  for non-matching REG_NAME. */
106 
108  const char *reg_name);
109 
110 /* Convert a gdb type, TYPE, to a GCC type. CONTEXT is used to do the
111  actual conversion. The new GCC type is returned. */
112 
113 struct type;
114 extern gcc_type convert_type (struct compile_c_instance *context,
115  struct type *type);
116 
117 /* A callback suitable for use as the GCC C symbol oracle. */
118 
119 extern gcc_c_oracle_function gcc_convert_symbol;
120 
121 /* A callback suitable for use as the GCC C address oracle. */
122 
123 extern gcc_c_symbol_address_function gcc_symbol_address;
124 
125 /* Instantiate a GDB object holding state for the GCC context FE. The
126  new object is returned. */
127 
128 extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe);
129 
130 /* Emit code to compute the address for all the local variables in
131  scope at PC in BLOCK. Returns a malloc'd vector, indexed by gdb
132  register number, where each element indicates if the corresponding
133  register is needed to compute a local variable. */
134 
135 extern unsigned char *generate_c_for_variable_locations
136  (struct compile_c_instance *compiler,
137  string_file &stream,
138  struct gdbarch *gdbarch,
139  const struct block *block,
140  CORE_ADDR pc);
141 
142 /* Get the GCC mode attribute value for a given type size. */
143 
144 extern const char *c_get_mode_for_size (int size);
145 
146 /* Given a dynamic property, return a name that is used to represent
147  its size. The contents of the resulting string will be the same
148  each time for each call with the same argument. */
149 
150 struct dynamic_prop;
151 extern std::string c_get_range_decl_name (const struct dynamic_prop *prop);
152 
153 /* Type used to hold and pass around the source and object file names
154  to use for compilation. */
156 {
157 public:
160  {}
161 
162  /* Provide read-only views only. Return 'const char *' instead of
163  std::string to avoid having to use c_str() everywhere in client
164  code. */
165 
166  const char *source_file () const
167  { return m_source_file.c_str (); }
168 
169  const char *object_file () const
170  { return m_object_file.c_str (); }
171 
172 private:
173  /* Storage for the file names. */
176 };
177 
178 #endif /* GDB_COMPILE_INTERNAL_H */
const char * string
Definition: signals.c:50
bfd_vma CORE_ADDR
Definition: common-types.h:41
const char * gcc_target_options
struct compile_instance base
const char * source_file() const
int compile_debug
Definition: compile.c:57
std::string c_get_range_decl_name(const struct dynamic_prop *prop)
DEF_ENUM_FLAGS_TYPE(enum gcc_qualifiers, gcc_qualifiers_flags)
compile_i_scope_types
Definition: defs.h:61
std::string m_object_file
gcc_c_symbol_address_function gcc_symbol_address
std::string m_source_file
unsigned char * generate_c_for_variable_locations(struct compile_c_instance *compiler, string_file &stream, struct gdbarch *gdbarch, const struct block *block, CORE_ADDR pc)
struct compile_instance * new_compile_instance(struct gcc_c_context *fe)
Definition: gdbtypes.h:749
gcc_c_oracle_function gcc_convert_symbol
int regnum
Definition: aarch64-tdep.c:77
Definition: block.h:60
void(* destroy)(struct compile_instance *)
compile_file_names(std::string source_file, std::string object_file)
gcc_type convert_type(struct compile_c_instance *context, struct type *type)
std::string compile_register_name_mangled(struct gdbarch *gdbarch, int regnum)
Definition: compile.c:651
enum compile_i_scope_types scope
struct gcc_base_context * fe
const char * c_get_mode_for_size(int size)
const struct block * block
const char * object_file() const
size_t size
Definition: go32-nat.c:242
int compile_register_name_demangle(struct gdbarch *gdbarch, const char *reg_name)
Definition: compile.c:661