29#include "gdbsupport/function-view.h"
30#include "gdbsupport/gdb-dlfcn.h"
31#include "gdbsupport/preprocessor.h"
39 const char *mode = NULL;
56 internal_error (_(
"Invalid GCC mode size %d."),
size);
67 return string_printf (
"__gdb_prop_%s", host_address_to_string (prop));
75template <
typename FUNCTYPE>
83 gdb_dlhandle_up handle = gdb_dlopen (fe_libcc);
84 func = (FUNCTYPE *) gdb_dlsym (handle, fe_context);
87 error (_(
"could not find symbol %s in library %s"), fe_context, fe_libcc);
100template <
typename INSTTYPE,
typename FUNCTYPE,
typename CTXTYPE,
101 typename BASE_VERSION_TYPE,
typename API_VERSION_TYPE>
102std::unique_ptr<compile_instance>
104 BASE_VERSION_TYPE base_version,
105 API_VERSION_TYPE api_version)
107 static FUNCTYPE *
func;
108 static CTXTYPE *context;
112 func = load_libcompile<FUNCTYPE> (fe_libcc, fe_context);
113 gdb_assert (
func != NULL);
116 context = (*func) (base_version, api_version);
118 error (_(
"The loaded version of GCC does not support the required version "
121 return gdb::make_unique<INSTTYPE> (context);
126std::unique_ptr<compile_instance>
131 gcc_base_api_version, gcc_c_api_version>
132 (STRINGIFY (GCC_C_FE_LIBCC), STRINGIFY (GCC_C_FE_CONTEXT),
133 GCC_FE_VERSION_0, GCC_C_FE_VERSION_0);
138std::unique_ptr<compile_instance>
143 gcc_base_api_version, gcc_cp_api_version>
144 (STRINGIFY (GCC_CP_FE_LIBCC), STRINGIFY (GCC_CP_FE_CONTEXT),
145 GCC_FE_VERSION_0, GCC_CP_FE_VERSION_0);
171 for (i = 0; i < macro->
argc; i++)
174 if (i + 1 < macro->
argc)
189 gdb::unique_xmalloc_ptr<struct macro_scope> scope;
198 if (scope != NULL && scope->file != NULL && scope->file->table != NULL)
201 [&] (
const char *
name,
206 print_one_macro (name, macro, source, line, file);
216 const std::vector<bool> ®isters_used)
224 if (!registers_used.empty ())
227 if (registers_used[i])
245 switch (regtype->
code ())
263 " __attribute__ ((__mode__(__%s__)))",
274 " unsigned char %s[%s]"
275 " __attribute__((__aligned__("
276 "__BIGGEST_ALIGNMENT__)))",
278 pulongest (regtype->
length ()));
297 gdb_puts (
"#pragma GCC user_expression\n", buf);
324 GCC_FE_WRAPPER_FUNCTION
338 GCC_FE_WRAPPER_FUNCTION
355 gdb_assert_not_reached (
"Unknown compiler scope reached.");
379 gdb_assert_not_reached (
"Unknown compiler scope reached.");
422 gdb_puts (
"#pragma GCC push_user_expression\n", buf);
432 gdb_puts (
"#pragma GCC pop_user_expression\n", buf);
448 GCC_FE_WRAPPER_FUNCTION
460 "#include <cstring>\n"
461 "#include <bits/move.h>\n"
463 GCC_FE_WRAPPER_FUNCTION
480 gdb_assert_not_reached (
"Unknown compiler scope reached.");
503 "std::add_pointer<std::remove_cv<decltype (%s)>::type>::type "
511 ?
"__builtin_addressof" :
""));
535template <
class CompileInstanceType,
class PushUserExpressionPolicy,
536 class PopUserExpressionPolicy,
class AddCodeHeaderPolicy,
537 class AddCodeFooterPolicy,
class AddInputPolicy>
539 :
private PushUserExpressionPolicy,
private PopUserExpressionPolicy,
540 private AddCodeHeaderPolicy,
private AddCodeFooterPolicy,
541 private AddInputPolicy
560 std::string
compute (
const char *input,
const struct block *expr_block,
575 std::vector<bool> registers_used
577 expr_block, expr_pc);
579 buf.
puts (
"typedef unsigned int"
580 " __attribute__ ((__mode__(__pointer__)))"
581 " __gdb_uintptr;\n");
582 buf.
puts (
"typedef int"
583 " __attribute__ ((__mode__(__pointer__)))"
587 for (
int i = 0; i < 4; ++i)
591 gdb_assert (mode != NULL);
593 " __attribute__ ((__mode__(__%s__)))"
601 AddCodeHeaderPolicy::add_code_header (
m_instance->scope (), &buf);
608 PushUserExpressionPolicy::push_user_expression (&buf);
620 buf.
puts (
"#line 1 \"gdb command line\"\n");
622 AddInputPolicy::add_input (
m_instance->scope (), input, &buf);
626 if (strchr (input,
'\n') == NULL)
635 PopUserExpressionPolicy::pop_user_expression (&buf);
637 AddCodeFooterPolicy::add_code_footer (
m_instance->scope (), &buf);
669 const struct block *expr_block,
675 return program.
compute (input, expr_block, expr_pc);
684 const struct block *expr_block,
691 return program.
compute (input, expr_block, expr_pc);
CompileInstanceType * m_instance
std::string compute(const char *input, const struct block *expr_block, CORE_ADDR expr_pc)
compile_program(CompileInstanceType *inst, struct gdbarch *gdbarch)
void write(const char *buf, long length_buf) override
const char * c_str() const
virtual void puts(const char *str)
void printf(const char *,...) ATTRIBUTE_PRINTF(2
std::string c_get_range_decl_name(const struct dynamic_prop *prop)
static void generate_register_struct(struct ui_file *stream, struct gdbarch *gdbarch, const std::vector< bool > ®isters_used)
std::string cplus_compute_program(compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc)
std::unique_ptr< compile_instance > cplus_get_compile_context()
compile_program< compile_cplus_instance, cplus_push_user_expression, cplus_pop_user_expression, cplus_add_code_header, c_add_code_footer, cplus_add_input > cplus_compile_program
FUNCTYPE * load_libcompile(const char *fe_libcc, const char *fe_context)
std::unique_ptr< compile_instance > get_compile_context(const char *fe_libcc, const char *fe_context, BASE_VERSION_TYPE base_version, API_VERSION_TYPE api_version)
std::string c_compute_program(compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc)
static void print_one_macro(const char *name, const struct macro_definition *macro, struct macro_source_file *source, int line, ui_file *file)
std::unique_ptr< compile_instance > c_get_compile_context()
static void write_macro_definitions(const struct block *block, CORE_ADDR pc, struct ui_file *file)
compile_program< compile_c_instance, c_push_user_expression, pop_user_expression_nop, c_add_code_header, c_add_code_footer, c_add_input > c_compile_program
const char * c_get_mode_for_size(int size)
std::vector< bool > generate_c_for_variable_locations(compile_instance *compiler, string_file *stream, struct gdbarch *gdbarch, const struct block *block, CORE_ADDR pc)
#define COMPILE_I_SIMPLE_REGISTER_ARG_NAME
#define COMPILE_I_SIMPLE_REGISTER_DUMMY
#define COMPILE_I_PRINT_OUT_ARG_TYPE
#define COMPILE_I_PRINT_OUT_ARG
#define COMPILE_I_EXPR_VAL
#define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG
#define COMPILE_I_EXPR_PTR_TYPE
std::string compile_register_name_mangled(struct gdbarch *gdbarch, int regnum)
@ COMPILE_I_PRINT_ADDRESS_SCOPE
@ COMPILE_I_PRINT_VALUE_SCOPE
int gdbarch_num_regs(struct gdbarch *gdbarch)
struct type * check_typedef(struct type *type)
gdb::unique_xmalloc_ptr< struct macro_scope > sal_macro_scope(struct symtab_and_line sal)
gdb::unique_xmalloc_ptr< struct macro_scope > default_macro_scope(void)
gdb::unique_xmalloc_ptr< struct macro_scope > user_macro_scope(void)
void macro_for_each_in_scope(struct macro_source_file *file, int line, gdb::function_view< macro_callback_fn > fn)
struct type * register_type(struct gdbarch *gdbarch, int regnum)
void(* func)(remote_target *remote, char *)
void push_user_expression(struct ui_file *buf)
void pop_user_expression(struct ui_file *buf)
void push_user_expression(struct ui_file *buf)
__extension__ enum macro_kind kind
void pop_user_expression(struct ui_file *buf)
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)