]> Git Repo - binutils.git/blob - gdb/compile/compile-internal.h
Automatic date update in version.in
[binutils.git] / gdb / compile / compile-internal.h
1 /* Header file for GDB compile command and supporting functions.
2    Copyright (C) 2014-2022 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 COMPILE_COMPILE_INTERNAL_H
18 #define COMPILE_COMPILE_INTERNAL_H
19
20 #include "gcc-c-interface.h"
21 #include "gdbsupport/gdb-hashtab.h"
22
23 /* Debugging flag for the "compile" family of commands.  */
24
25 extern bool compile_debug;
26
27 struct block;
28
29 /* An object that maps a gdb type to a gcc type.  */
30
31 struct type_map_instance
32 {
33   /* The gdb type.  */
34
35   struct type *type;
36
37   /* The corresponding gcc type handle.  */
38
39   gcc_type gcc_type_handle;
40 };
41
42 /* An object of this type holds state associated with a given
43    compilation job.  */
44
45 class compile_instance
46 {
47 public:
48   compile_instance (struct gcc_base_context *gcc_fe, const char *options);
49
50   virtual ~compile_instance ()
51   {
52     m_gcc_fe->ops->destroy (m_gcc_fe);
53   }
54
55   /* Returns the GCC options to be passed during compilation.  */
56   const std::string &gcc_target_options () const
57   {
58     return m_gcc_target_options;
59   }
60
61   /* Query the type cache for TYPE, returning the compiler's
62      type for it in RET.  */
63   bool get_cached_type (struct type *type, gcc_type *ret) const;
64
65   /* Insert GCC_TYPE into the type cache for TYPE.
66
67      It is ok for a given type to be inserted more than once, provided that
68      the exact same association is made each time.  */
69   void insert_type (struct type *type, gcc_type gcc_type);
70
71   /* Associate SYMBOL with some error text.  */
72   void insert_symbol_error (const struct symbol *sym, const char *text);
73
74   /* Emit the error message corresponding to SYM, if one exists, and
75      arrange for it not to be emitted again.  */
76   void error_symbol_once (const struct symbol *sym);
77
78   /* These currently just forward to the underlying ops
79      vtable.  */
80
81   /* Set the plug-in print callback.  */
82   void set_print_callback (void (*print_function) (void *, const char *),
83                            void *datum);
84
85   /* Return the plug-in's front-end version.  */
86   unsigned int version () const;
87
88   /* Set the plug-in's verbosity level.  Nop for GCC_FE_VERSION_0.  */
89   void set_verbose (int level);
90
91   /* Set the plug-in driver program.  Nop for GCC_FE_VERSION_0.  */
92   void set_driver_filename (const char *filename);
93
94   /* Set the regular expression used to match the configury triplet
95      prefix to the compiler.  Nop for GCC_FE_VERSION_0.  */
96   void set_triplet_regexp (const char *regexp);
97
98   /* Set compilation arguments.  REGEXP is only used for protocol
99      version GCC_FE_VERSION_0.  */
100   gdb::unique_xmalloc_ptr<char> set_arguments (int argc, char **argv,
101                                                const char *regexp = NULL);
102
103   /* Set the filename of the program to compile.  Nop for GCC_FE_VERSION_0.  */
104   void set_source_file (const char *filename);
105
106   /* Compile the previously specified source file to FILENAME.
107      VERBOSE_LEVEL is only used for protocol version GCC_FE_VERSION_0.  */
108   bool compile (const char *filename, int verbose_level = -1);
109
110   /* Set the scope type for this compile.  */
111   void set_scope (enum compile_i_scope_types scope)
112   {
113     m_scope = scope;
114   }
115
116   /* Return the scope type.  */
117   enum compile_i_scope_types scope () const
118   {
119     return m_scope;
120   }
121
122   /* Set the block to be used for symbol searches.  */
123   void set_block (const struct block *block)
124   {
125     m_block = block;
126   }
127
128   /* Return the search block.  */
129   const struct block *block () const
130   {
131     return m_block;
132   }
133
134 protected:
135
136   /* The GCC front end.  */
137   struct gcc_base_context *m_gcc_fe;
138
139   /* The "scope" of this compilation.  */
140   enum compile_i_scope_types m_scope;
141
142   /* The block in which an expression is being parsed.  */
143   const struct block *m_block;
144
145   /* Specify "-std=gnu11", "-std=gnu++11" or similar.  These options are put
146      after CU's DW_AT_producer compilation options to override them.  */
147   std::string m_gcc_target_options;
148
149   /* Map from gdb types to gcc types.  */
150   htab_up m_type_map;
151
152   /* Map from gdb symbols to gcc error messages to emit.  */
153   htab_up m_symbol_err_map;
154 };
155
156 /* Define header and footers for different scopes.  */
157
158 /* A simple scope just declares a function named "_gdb_expr", takes no
159    arguments and returns no value.  */
160
161 #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs"
162 #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs"
163 #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy"
164 #define COMPILE_I_PRINT_OUT_ARG_TYPE "void *"
165 #define COMPILE_I_PRINT_OUT_ARG "__gdb_out_param"
166 #define COMPILE_I_EXPR_VAL "__gdb_expr_val"
167 #define COMPILE_I_EXPR_PTR_TYPE "__gdb_expr_ptr_type"
168
169 /* A "type" to indicate a NULL type.  */
170
171 const gcc_type GCC_TYPE_NONE = (gcc_type) -1;
172
173 /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result
174    to a form suitable for the compiler source.  The register names
175    should not clash with inferior defined macros. */
176
177 extern std::string compile_register_name_mangled (struct gdbarch *gdbarch,
178                                                   int regnum);
179
180 /* Convert compiler source register name to register number of
181    GDBARCH.  Returned value is always >= 0, function throws an error
182    for non-matching REG_NAME.  */
183
184 extern int compile_register_name_demangle (struct gdbarch *gdbarch,
185                                            const char *reg_name);
186
187 /* Type used to hold and pass around the source and object file names
188    to use for compilation.  */
189 class compile_file_names
190 {
191 public:
192   compile_file_names (std::string source_file, std::string object_file)
193     : m_source_file (source_file), m_object_file (object_file)
194   {}
195
196   /* Provide read-only views only.  Return 'const char *' instead of
197      std::string to avoid having to use c_str() everywhere in client
198      code.  */
199
200   const char *source_file () const
201   { return m_source_file.c_str (); }
202
203   const char *object_file () const
204   { return m_object_file.c_str (); }
205
206 private:
207   /* Storage for the file names.  */
208   std::string m_source_file;
209   std::string m_object_file;
210 };
211
212 #endif /* COMPILE_COMPILE_INTERNAL_H */
This page took 0.036703 seconds and 4 git commands to generate.