49 #define TMP_PREFIX "/tmp/gdbobj-" 98 error (
_(
"You must provide a filename for this command."));
110 error (
_(
"You must provide a filename with the raw option set."));
113 error (
_(
"Unknown argument specified."));
144 error (
_(
"Unknown argument specified."));
153 l->control_u.compile.scope = scope;
191 l->control_u.compile.scope = scope;
192 l->control_u.compile.scope_data = &fmt;
202 const char *dir = (
const char *) arg;
207 zap = concat (
"rm -rf ", dir, (
char *) NULL);
208 wstat = system (zap);
210 warning (
_(
"Could not remove temporary directory %s"), dir);
220 static char *tempdir_name;
222 #define TEMPLATE TMP_PREFIX "XXXXXX" 225 if (tempdir_name != NULL)
231 tempdir_name = mkdtemp (tname);
233 error (
_(
"Command not supported on this host."));
235 if (tempdir_name == NULL)
238 tempdir_name = xstrdup (tempdir_name);
261 static const struct block *
291 *argcp = args.
count ();
330 *argvp =
XRESIZEVEC (
char *, *argvp, (*argcp + argc + 1));
332 for (argi = 0; argi < argc; argi++)
333 (*argvp)[(*argcp)++] = xstrdup (
argv[argi]);
334 (*argvp)[(*argcp)] = NULL;
368 while (*cs != 0 && *cs !=
'-')
385 if (strcmp (*
argv,
"-fpreprocessed") == 0)
402 int *argcp,
char ***argvp)
404 const char *cs_producer_options;
406 char **argv_compiler;
412 if (cs_producer_options != NULL)
415 char **argv_producer;
419 append_args (argcp, argvp, argc_producer, argv_producer);
420 freeargv (argv_producer);
424 &argc_compiler, &argv_compiler);
425 append_args (argcp, argvp, argc_compiler, argv_compiler);
426 freeargv (argv_compiler);
460 const struct block *expr_block;
470 error (
_(
"The program must be running for the compile command to "\
478 error (
_(
"No compiler support for language %s."),
485 compiler->
scope = scope;
486 compiler->
block = expr_block;
501 input_buf.
puts (
"\n");
504 input = input_buf.
c_str ();
506 else if (cmd_string != NULL)
509 error (
_(
"Neither a simple expression, or a multi-line specified."));
513 expr_block, expr_pc);
517 if (compiler->
fe->ops->version >= GCC_FE_VERSION_1)
522 if (compiler->
fe->ops->version < GCC_FE_VERSION_1)
523 error (
_(
"Command 'set compile-gcc' requires GCC version 6 or higher " 524 "(libcc1 interface version 1 or higher)"));
534 triplet_rx =
std::string (arch_rx) +
"(-[^-]*)?-" + os_rx;
536 if (compiler->
fe->ops->version >= GCC_FE_VERSION_1)
537 compiler->
fe->ops->set_triplet_regexp (compiler->
fe,
538 triplet_rx.c_str ());
545 if (compiler->
fe->ops->version >= GCC_FE_VERSION_1)
546 error_message = compiler->
fe->ops->set_arguments (compiler->
fe, argc,
argv);
548 error_message = compiler->
fe->ops->set_arguments_v0 (compiler->
fe,
551 if (error_message != NULL)
554 error (
"%s", error_message);
562 for (argi = 0; argi < argc; argi++)
578 if (fputs (
code.c_str (), src.get ()) == EOF)
587 compiler->
fe->ops->set_source_file (compiler->
fe, fnames.
source_file ());
589 if (compiler->
fe->ops->version >= GCC_FE_VERSION_1)
592 ok = compiler->
fe->ops->compile_v0 (compiler->
fe, fnames.
object_file (),
595 error (
_(
"Compilation failed."));
602 source_remover->
keep ();
642 source_remover.keep ();
643 object_remover.keep ();
666 if (regname[0] !=
'_' || regname[1] !=
'_')
667 error (
_(
"Invalid register name \"%s\"."), regname);
674 error (
_(
"Cannot find gdbarch register \"%s\"."), regname);
684 Command to compile source code and inject it into the inferior."),
690 Compile, inject, and execute code.\n\ 692 Usage: compile code [-r|-raw] [--] [CODE]\n\ 693 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping.\n\ 694 --: Do not parse any options beyond this delimiter. All text to the\n\ 695 right will be treated as source code.\n\ 697 The source code may be specified as a simple one line expression, e.g.:\n\ 699 compile code printf(\"Hello world\\n\");\n\ 701 Alternatively, you can type a multiline expression by invoking\n\ 702 this command with no argument. GDB will then prompt for the\n\ 703 expression interactively; type a line containing \"end\" to\n\ 704 indicate the end of the expression."),
709 Evaluate a file containing source code.\n\ 711 Usage: compile file [-r|-raw] [filename]\n\ 712 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping."),
718 Evaluate EXPR by using the compiler and print result.\n\ 720 Usage: compile print[/FMT] [EXPR]\n\ 722 The expression may be specified on the same line as the command, e.g.:\n\ 726 Alternatively, you can type a multiline expression by invoking\n\ 727 this command with no argument. GDB will then prompt for the\n\ 728 expression interactively; type a line containing \"end\" to\n\ 729 indicate the end of the expression.\n\ 731 EXPR may be preceded with /FMT, where FMT is a format letter\n\ 732 but no count or size letter (see \"x\" command)."),
736 Set compile command debugging."),
_(
"\ 737 Show compile command debugging."),
_(
"\ 738 When on, compile command debugging is enabled."),
744 _(
"Set compile command GCC command-line arguments"),
745 _(
"Show compile command GCC command-line arguments"),
747 Use options like -I (include file directory) or ABI settings.\n\ 748 String quoting is parsed like in shell, for example:\n\ 749 -mno-align-double \"-I/dir with a space/include\""),
763 " -Wno-implicit-function-declaration" 764 " -Wno-unused-but-set-variable" 765 " -Wno-unused-variable" 767 " -fno-stack-protector" 773 _(
"Set compile command " 774 "GCC driver filename"),
775 _(
"Show compile command " 776 "GCC driver filename"),
778 It should be absolute filename of the gcc executable.\n\ 779 If empty the default target triplet will be searched in $PATH."),
CORE_ADDR get_frame_address_in_block(struct frame_info *this_frame)
void eval_compile_command(struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope, void *scope_data)
struct frame_info * get_selected_frame(const char *message)
CORE_ADDR get_frame_pc(struct frame_info *frame)
enum command_control_type execute_control_command_untraced(struct command_line *cmd)
static void compile_file_command(const char *arg, int from_tty)
const char * gcc_target_options
const char * gdbarch_gnu_triplet_regexp(struct gdbarch *gdbarch)
static void do_rmdir(void *arg)
const char * source_file() const
static char * compile_gcc
static void set_compile_args(const char *args, int from_tty, struct cmd_list_element *c)
void warning(const char *fmt,...)
command_line_up get_command_line(enum command_control_type type, const char *arg)
struct symtab_and_line get_current_source_symtab_and_line(void)
const char * osabi_triplet_regexp(enum gdb_osabi osabi)
int compile_register_name_demangle(struct gdbarch *gdbarch, const char *regname)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
static const char * get_selected_pc_producer_options(void)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
#define BLOCKVECTOR_BLOCK(blocklist, n)
struct cmd_list_element * cmdlist
int gdbarch_num_regs(struct gdbarch *gdbarch)
static char ** compile_args_argv
char * skip_spaces(char *chp)
static char * compile_args
static void cleanup_compile_instance(void *arg)
static void append_args(int *argcp, char ***argvp, int argc, char **argv)
enum gdb_osabi gdbarch_osabi(struct gdbarch *gdbarch)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
struct compunit_symtab * find_pc_compunit_symtab(CORE_ADDR pc)
scoped_restore_tmpl< T > make_scoped_restore(T *var)
struct cmd_list_element * setlist
#define SYMTAB_BLOCKVECTOR(symtab)
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
void print_value(struct value *val, const struct format_data *fmtp)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
static void compile_command(const char *args, int from_tty)
static compile_file_names compile_to_object(struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
static void build_argc_argv(const char *s, int *argcp, char ***argvp)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
struct compile_instance *(* la_get_compile_instance)(void)
struct cmd_list_element * showlist
struct cmd_list_element * add_com_alias(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag)
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
enum compile_i_scope_types scope
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
void add_setshow_string_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct gdbarch * get_current_arch(void)
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
static void show_compile_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static int startswith(const char *string, const char *pattern)
static int compile_args_argc
const char * skip_to_space(const char *chp)
#define target_has_execution
static void filter_args(int *argcp, char **argv)
struct cmd_list_element * setdebuglist
virtual void puts(const char *str)
#define XRESIZEVEC(T, P, N)
static int check_raw_argument(const char **arg)
void _initialize_compile(void)
static void print_callback(void *ignore, const char *message)
void(* destroy)(struct compile_instance *)
struct command_line * next
struct compile_module * compile_object_load(const compile_file_names &file_names, enum compile_i_scope_types scope, void *scope_data)
static compile_file_names get_new_file_names()
enum compile_i_scope_types scope
T & emplace(Args &&... args)
const struct language_defn * current_language
gdb::unique_xmalloc_ptr< char > gdb_abspath(const char *path)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
std::string compile_register_name_mangled(struct gdbarch *gdbarch, int regnum)
static void compile_code_command(const char *arg, int from_tty)
enum compile_i_scope_types scope
void print_command_parse_format(const char **expp, const char *cmdname, struct format_data *fmtp)
const char * c_str() const
struct gcc_base_context * fe
static const char * get_compile_file_tempdir(void)
void compile_print_value(struct value *val, void *data_voidp)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void show_compile_args(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
std::string string_printf(const char *fmt,...)
struct cleanup * make_final_cleanup(make_cleanup_ftype *function, void *arg)
const struct block * get_selected_block(CORE_ADDR *addr_in_block)
static void compile_print_command(const char *arg, int from_tty)
static struct cmd_list_element * compile_command_list
void compile_object_run(struct compile_module *module)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
const struct block * block
void add_setshow_optional_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static const struct block * get_expr_block_and_pc(CORE_ADDR *pc)
struct cmd_list_element * showdebuglist
static void show_compile_gcc(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
std::unique_ptr< command_line, command_lines_deleter > command_line_up
struct command_line ** body_list
const char * object_file() const
void error(const char *fmt,...)
char * gdbarch_gcc_target_options(struct gdbarch *gdbarch)
std::string(* la_compute_program)(struct compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc)
int check_for_argument(const char **str, const char *arg, int arg_len)
void do_cleanups(struct cleanup *old_chain)
static void get_args(const struct compile_instance *compiler, struct gdbarch *gdbarch, int *argcp, char ***argvp)