Home | History | Annotate | Line # | Download | only in compile
compile.c revision 1.1.1.1.2.1
      1 /* General Compile and inject code
      2 
      3    Copyright (C) 2014-2015 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #include "defs.h"
     21 #include "interps.h"
     22 #include "ui-out.h"
     23 #include "command.h"
     24 #include "cli/cli-script.h"
     25 #include "cli/cli-utils.h"
     26 #include "completer.h"
     27 #include "gdbcmd.h"
     28 #include "compile.h"
     29 #include "compile-internal.h"
     30 #include "compile-object-load.h"
     31 #include "compile-object-run.h"
     32 #include "language.h"
     33 #include "frame.h"
     34 #include "source.h"
     35 #include "block.h"
     36 #include "arch-utils.h"
     37 #include "filestuff.h"
     38 #include "target.h"
     39 #include "osabi.h"
     40 #include "gdb_wait.h"
     41 #include "valprint.h"
     42 
     43 
     44 
     46 /* Initial filename for temporary files.  */
     47 
     48 #define TMP_PREFIX "/tmp/gdbobj-"
     49 
     50 /* Hold "compile" commands.  */
     51 
     52 static struct cmd_list_element *compile_command_list;
     53 
     54 /* Debug flag for "compile" commands.  */
     55 
     56 int compile_debug;
     57 
     58 /* Implement "show debug compile".  */
     59 
     60 static void
     61 show_compile_debug (struct ui_file *file, int from_tty,
     62 		    struct cmd_list_element *c, const char *value)
     63 {
     64   fprintf_filtered (file, _("Compile debugging is %s.\n"), value);
     65 }
     66 
     67 
     68 
     70 /* Check *ARG for a "-raw" or "-r" argument.  Return 0 if not seen.
     71    Return 1 if seen and update *ARG.  */
     72 
     73 static int
     74 check_raw_argument (char **arg)
     75 {
     76   *arg = skip_spaces (*arg);
     77 
     78   if (arg != NULL
     79       && (check_for_argument (arg, "-raw", sizeof ("-raw") - 1)
     80 	  || check_for_argument (arg, "-r", sizeof ("-r") - 1)))
     81       return 1;
     82   return 0;
     83 }
     84 
     85 /* Handle the input from the 'compile file' command.  The "compile
     86    file" command is used to evaluate an expression contained in a file
     87    that may contain calls to the GCC compiler.  */
     88 
     89 static void
     90 compile_file_command (char *arg, int from_tty)
     91 {
     92   enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
     93   char *buffer;
     94   struct cleanup *cleanup;
     95 
     96   cleanup = make_cleanup_restore_integer (&interpreter_async);
     97   interpreter_async = 0;
     98 
     99   /* Check the user did not just <enter> after command.  */
    100   if (arg == NULL)
    101     error (_("You must provide a filename for this command."));
    102 
    103   /* Check if a raw (-r|-raw) argument is provided.  */
    104   if (arg != NULL && check_raw_argument (&arg))
    105     {
    106       scope = COMPILE_I_RAW_SCOPE;
    107       arg = skip_spaces (arg);
    108     }
    109 
    110   /* After processing arguments, check there is a filename at the end
    111      of the command.  */
    112   if (arg[0] == '\0')
    113     error (_("You must provide a filename with the raw option set."));
    114 
    115   if (arg[0] == '-')
    116     error (_("Unknown argument specified."));
    117 
    118   arg = skip_spaces (arg);
    119   arg = gdb_abspath (arg);
    120   make_cleanup (xfree, arg);
    121   buffer = xstrprintf ("#include \"%s\"\n", arg);
    122   make_cleanup (xfree, buffer);
    123   eval_compile_command (NULL, buffer, scope, NULL);
    124   do_cleanups (cleanup);
    125 }
    126 
    127 /* Handle the input from the 'compile code' command.  The
    128    "compile code" command is used to evaluate an expression that may
    129    contain calls to the GCC compiler.  The language expected in this
    130    compile command is the language currently set in GDB.  */
    131 
    132 static void
    133 compile_code_command (char *arg, int from_tty)
    134 {
    135   struct cleanup *cleanup;
    136   enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
    137 
    138   cleanup = make_cleanup_restore_integer (&interpreter_async);
    139   interpreter_async = 0;
    140 
    141   if (arg != NULL && check_raw_argument (&arg))
    142     {
    143       scope = COMPILE_I_RAW_SCOPE;
    144       arg = skip_spaces (arg);
    145     }
    146 
    147   arg = skip_spaces (arg);
    148 
    149   if (arg != NULL && !check_for_argument (&arg, "--", sizeof ("--") - 1))
    150     {
    151       if (arg[0] == '-')
    152 	error (_("Unknown argument specified."));
    153     }
    154 
    155   if (arg && *arg)
    156     eval_compile_command (NULL, arg, scope, NULL);
    157   else
    158     {
    159       struct command_line *l = get_command_line (compile_control, "");
    160 
    161       make_cleanup_free_command_lines (&l);
    162       l->control_u.compile.scope = scope;
    163       execute_control_command_untraced (l);
    164     }
    165 
    166   do_cleanups (cleanup);
    167 }
    168 
    169 /* Callback for compile_print_command.  */
    170 
    171 void
    172 compile_print_value (struct value *val, void *data_voidp)
    173 {
    174   const struct format_data *fmtp = data_voidp;
    175 
    176   print_value (val, fmtp);
    177 }
    178 
    179 /* Handle the input from the 'compile print' command.  The "compile
    180    print" command is used to evaluate and print an expression that may
    181    contain calls to the GCC compiler.  The language expected in this
    182    compile command is the language currently set in GDB.  */
    183 
    184 static void
    185 compile_print_command (char *arg_param, int from_tty)
    186 {
    187   const char *arg = arg_param;
    188   struct cleanup *cleanup;
    189   enum compile_i_scope_types scope = COMPILE_I_PRINT_ADDRESS_SCOPE;
    190   struct format_data fmt;
    191 
    192   cleanup = make_cleanup_restore_integer (&interpreter_async);
    193   interpreter_async = 0;
    194 
    195   /* Passing &FMT as SCOPE_DATA is safe as do_module_cleanup will not
    196      touch the stale pointer if compile_object_run has already quit.  */
    197   print_command_parse_format (&arg, "compile print", &fmt);
    198 
    199   if (arg && *arg)
    200     eval_compile_command (NULL, arg, scope, &fmt);
    201   else
    202     {
    203       struct command_line *l = get_command_line (compile_control, "");
    204 
    205       make_cleanup_free_command_lines (&l);
    206       l->control_u.compile.scope = scope;
    207       l->control_u.compile.scope_data = &fmt;
    208       execute_control_command_untraced (l);
    209     }
    210 
    211   do_cleanups (cleanup);
    212 }
    213 
    214 /* A cleanup function to remove a directory and all its contents.  */
    215 
    216 static void
    217 do_rmdir (void *arg)
    218 {
    219   const char *dir = arg;
    220   char *zap;
    221   int wstat;
    222 
    223   gdb_assert (startswith (dir, TMP_PREFIX));
    224   zap = concat ("rm -rf ", dir, (char *) NULL);
    225   wstat = system (zap);
    226   if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
    227     warning (_("Could not remove temporary directory %s"), dir);
    228   XDELETEVEC (zap);
    229 }
    230 
    231 /* Return the name of the temporary directory to use for .o files, and
    232    arrange for the directory to be removed at shutdown.  */
    233 
    234 static const char *
    235 get_compile_file_tempdir (void)
    236 {
    237   static char *tempdir_name;
    238 
    239 #define TEMPLATE TMP_PREFIX "XXXXXX"
    240   char tname[sizeof (TEMPLATE)];
    241 
    242   if (tempdir_name != NULL)
    243     return tempdir_name;
    244 
    245   strcpy (tname, TEMPLATE);
    246 #undef TEMPLATE
    247 #ifdef HAVE_MKDTEMP
    248   tempdir_name = mkdtemp (tname);
    249 #else
    250   error (_("Command not supported on this host."));
    251 #endif
    252   if (tempdir_name == NULL)
    253     perror_with_name (_("Could not make temporary directory"));
    254 
    255   tempdir_name = xstrdup (tempdir_name);
    256   make_final_cleanup (do_rmdir, tempdir_name);
    257   return tempdir_name;
    258 }
    259 
    260 /* Compute the names of source and object files to use.  The names are
    261    allocated by malloc and should be freed by the caller.  */
    262 
    263 static void
    264 get_new_file_names (char **source_file, char **object_file)
    265 {
    266   static int seq;
    267   const char *dir = get_compile_file_tempdir ();
    268 
    269   ++seq;
    270   *source_file = xstrprintf ("%s%sout%d.c", dir, SLASH_STRING, seq);
    271   *object_file = xstrprintf ("%s%sout%d.o", dir, SLASH_STRING, seq);
    272 }
    273 
    274 /* Get the block and PC at which to evaluate an expression.  */
    275 
    276 static const struct block *
    277 get_expr_block_and_pc (CORE_ADDR *pc)
    278 {
    279   const struct block *block = get_selected_block (pc);
    280 
    281   if (block == NULL)
    282     {
    283       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
    284 
    285       if (cursal.symtab)
    286 	block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (cursal.symtab),
    287 				   STATIC_BLOCK);
    288       if (block != NULL)
    289 	*pc = BLOCK_START (block);
    290     }
    291   else
    292     *pc = BLOCK_START (block);
    293 
    294   return block;
    295 }
    296 
    297 /* Call gdb_buildargv, set its result for S into *ARGVP but calculate also the
    298    number of parsed arguments into *ARGCP.  If gdb_buildargv has returned NULL
    299    then *ARGCP is set to zero.  */
    300 
    301 static void
    302 build_argc_argv (const char *s, int *argcp, char ***argvp)
    303 {
    304   *argvp = gdb_buildargv (s);
    305   *argcp = countargv (*argvp);
    306 }
    307 
    308 /* String for 'set compile-args' and 'show compile-args'.  */
    309 static char *compile_args;
    310 
    311 /* Parsed form of COMPILE_ARGS.  COMPILE_ARGS_ARGV is NULL terminated.  */
    312 static int compile_args_argc;
    313 static char **compile_args_argv;
    314 
    315 /* Implement 'set compile-args'.  */
    316 
    317 static void
    318 set_compile_args (char *args, int from_tty, struct cmd_list_element *c)
    319 {
    320   freeargv (compile_args_argv);
    321   build_argc_argv (compile_args, &compile_args_argc, &compile_args_argv);
    322 }
    323 
    324 /* Implement 'show compile-args'.  */
    325 
    326 static void
    327 show_compile_args (struct ui_file *file, int from_tty,
    328 		   struct cmd_list_element *c, const char *value)
    329 {
    330   fprintf_filtered (file, _("Compile command command-line arguments "
    331 			    "are \"%s\".\n"),
    332 		    value);
    333 }
    334 
    335 /* Append ARGC and ARGV (as parsed by build_argc_argv) to *ARGCP and *ARGVP.
    336    ARGCP+ARGVP can be zero+NULL and also ARGC+ARGV can be zero+NULL.  */
    337 
    338 static void
    339 append_args (int *argcp, char ***argvp, int argc, char **argv)
    340 {
    341   int argi;
    342 
    343   *argvp = xrealloc (*argvp, (*argcp + argc + 1) * sizeof (**argvp));
    344 
    345   for (argi = 0; argi < argc; argi++)
    346     (*argvp)[(*argcp)++] = xstrdup (argv[argi]);
    347   (*argvp)[(*argcp)] = NULL;
    348 }
    349 
    350 /* Return DW_AT_producer parsed for get_selected_frame () (if any).
    351    Return NULL otherwise.
    352 
    353    GCC already filters its command-line arguments only for the suitable ones to
    354    put into DW_AT_producer - see GCC function gen_producer_string.  */
    355 
    356 static const char *
    357 get_selected_pc_producer_options (void)
    358 {
    359   CORE_ADDR pc = get_frame_pc (get_selected_frame (NULL));
    360   struct compunit_symtab *symtab = find_pc_compunit_symtab (pc);
    361   const char *cs;
    362 
    363   if (symtab == NULL || symtab->producer == NULL
    364       || !startswith (symtab->producer, "GNU "))
    365     return NULL;
    366 
    367   cs = symtab->producer;
    368   while (*cs != 0 && *cs != '-')
    369     cs = skip_spaces_const (skip_to_space_const (cs));
    370   if (*cs != '-')
    371     return NULL;
    372   return cs;
    373 }
    374 
    375 /* Filter out unwanted options from *ARGCP and ARGV.  */
    376 
    377 static void
    378 filter_args (int *argcp, char **argv)
    379 {
    380   char **destv;
    381 
    382   for (destv = argv; *argv != NULL; argv++)
    383     {
    384       /* -fpreprocessed may get in commonly from ccache.  */
    385       if (strcmp (*argv, "-fpreprocessed") == 0)
    386 	{
    387 	  xfree (*argv);
    388 	  (*argcp)--;
    389 	  continue;
    390 	}
    391       *destv++ = *argv;
    392     }
    393   *destv = NULL;
    394 }
    395 
    396 /* Produce final vector of GCC compilation options.  First element is target
    397    size ("-m64", "-m32" etc.), optionally followed by DW_AT_producer options
    398    and then compile-args string GDB variable.  */
    399 
    400 static void
    401 get_args (const struct compile_instance *compiler, struct gdbarch *gdbarch,
    402 	  int *argcp, char ***argvp)
    403 {
    404   const char *cs_producer_options;
    405   int argc_compiler;
    406   char **argv_compiler;
    407 
    408   build_argc_argv (gdbarch_gcc_target_options (gdbarch),
    409 		   argcp, argvp);
    410 
    411   cs_producer_options = get_selected_pc_producer_options ();
    412   if (cs_producer_options != NULL)
    413     {
    414       int argc_producer;
    415       char **argv_producer;
    416 
    417       build_argc_argv (cs_producer_options, &argc_producer, &argv_producer);
    418       filter_args (&argc_producer, argv_producer);
    419       append_args (argcp, argvp, argc_producer, argv_producer);
    420       freeargv (argv_producer);
    421     }
    422 
    423   build_argc_argv (compiler->gcc_target_options,
    424 		   &argc_compiler, &argv_compiler);
    425   append_args (argcp, argvp, argc_compiler, argv_compiler);
    426   freeargv (argv_compiler);
    427 
    428   append_args (argcp, argvp, compile_args_argc, compile_args_argv);
    429 }
    430 
    431 /* A cleanup function to destroy a gdb_gcc_instance.  */
    432 
    433 static void
    434 cleanup_compile_instance (void *arg)
    435 {
    436   struct compile_instance *inst = arg;
    437 
    438   inst->destroy (inst);
    439 }
    440 
    441 /* A cleanup function to unlink a file.  */
    442 
    443 static void
    444 cleanup_unlink_file (void *arg)
    445 {
    446   const char *filename = arg;
    447 
    448   unlink (filename);
    449 }
    450 
    451 /* A helper function suitable for use as the "print_callback" in the
    452    compiler object.  */
    453 
    454 static void
    455 print_callback (void *ignore, const char *message)
    456 {
    457   fputs_filtered (message, gdb_stderr);
    458 }
    459 
    460 /* Process the compilation request.  On success it returns the object
    461    file name and *SOURCE_FILEP is set to source file name.  On an
    462    error condition, error () is called.  The caller is responsible for
    463    freeing both strings.  */
    464 
    465 static char *
    466 compile_to_object (struct command_line *cmd, const char *cmd_string,
    467 		   enum compile_i_scope_types scope,
    468 		   char **source_filep)
    469 {
    470   char *code;
    471   const char *input;
    472   char *source_file, *object_file;
    473   struct compile_instance *compiler;
    474   struct cleanup *cleanup, *inner_cleanup;
    475   const struct block *expr_block;
    476   CORE_ADDR trash_pc, expr_pc;
    477   int argc;
    478   char **argv;
    479   int ok;
    480   FILE *src;
    481   struct gdbarch *gdbarch = get_current_arch ();
    482   const char *os_rx;
    483   const char *arch_rx;
    484   char *triplet_rx;
    485   char *error_message;
    486 
    487   if (!target_has_execution)
    488     error (_("The program must be running for the compile command to "\
    489 	     "work."));
    490 
    491   expr_block = get_expr_block_and_pc (&trash_pc);
    492   expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
    493 
    494   /* Set up instance and context for the compiler.  */
    495   if (current_language->la_get_compile_instance == NULL)
    496     error (_("No compiler support for this language."));
    497   compiler = current_language->la_get_compile_instance ();
    498   cleanup = make_cleanup (cleanup_compile_instance, compiler);
    499 
    500   compiler->fe->ops->set_print_callback (compiler->fe, print_callback, NULL);
    501 
    502   compiler->scope = scope;
    503   compiler->block = expr_block;
    504 
    505   /* From the provided expression, build a scope to pass to the
    506      compiler.  */
    507   if (cmd != NULL)
    508     {
    509       struct ui_file *stream = mem_fileopen ();
    510       struct command_line *iter;
    511       char *stream_buf;
    512 
    513       make_cleanup_ui_file_delete (stream);
    514       for (iter = cmd->body_list[0]; iter; iter = iter->next)
    515 	{
    516 	  fputs_unfiltered (iter->line, stream);
    517 	  fputs_unfiltered ("\n", stream);
    518 	}
    519 
    520       stream_buf = ui_file_xstrdup (stream, NULL);
    521       make_cleanup (xfree, stream_buf);
    522       input = stream_buf;
    523     }
    524   else if (cmd_string != NULL)
    525     input = cmd_string;
    526   else
    527     error (_("Neither a simple expression, or a multi-line specified."));
    528 
    529   code = current_language->la_compute_program (compiler, input, gdbarch,
    530 					       expr_block, expr_pc);
    531   make_cleanup (xfree, code);
    532   if (compile_debug)
    533     fprintf_unfiltered (gdb_stdlog, "debug output:\n\n%s", code);
    534 
    535   os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch));
    536   arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
    537 
    538   /* Allow triplets with or without vendor set.  */
    539   triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL);
    540   make_cleanup (xfree, triplet_rx);
    541 
    542   /* Set compiler command-line arguments.  */
    543   get_args (compiler, gdbarch, &argc, &argv);
    544   make_cleanup_freeargv (argv);
    545 
    546   error_message = compiler->fe->ops->set_arguments (compiler->fe, triplet_rx,
    547 						    argc, argv);
    548   if (error_message != NULL)
    549     {
    550       make_cleanup (xfree, error_message);
    551       error ("%s", error_message);
    552     }
    553 
    554   if (compile_debug)
    555     {
    556       int argi;
    557 
    558       fprintf_unfiltered (gdb_stdlog, "Passing %d compiler options:\n", argc);
    559       for (argi = 0; argi < argc; argi++)
    560 	fprintf_unfiltered (gdb_stdlog, "Compiler option %d: <%s>\n",
    561 			    argi, argv[argi]);
    562     }
    563 
    564   get_new_file_names (&source_file, &object_file);
    565   inner_cleanup = make_cleanup (xfree, source_file);
    566   make_cleanup (xfree, object_file);
    567 
    568   src = gdb_fopen_cloexec (source_file, "w");
    569   if (src == NULL)
    570     perror_with_name (_("Could not open source file for writing"));
    571   make_cleanup (cleanup_unlink_file, source_file);
    572   if (fputs (code, src) == EOF)
    573     perror_with_name (_("Could not write to source file"));
    574   fclose (src);
    575 
    576   if (compile_debug)
    577     fprintf_unfiltered (gdb_stdlog, "source file produced: %s\n\n",
    578 			source_file);
    579 
    580   /* Call the compiler and start the compilation process.  */
    581   compiler->fe->ops->set_source_file (compiler->fe, source_file);
    582 
    583   if (!compiler->fe->ops->compile (compiler->fe, object_file,
    584 				   compile_debug))
    585     error (_("Compilation failed."));
    586 
    587   if (compile_debug)
    588     fprintf_unfiltered (gdb_stdlog, "object file produced: %s\n\n",
    589 			object_file);
    590 
    591   discard_cleanups (inner_cleanup);
    592   do_cleanups (cleanup);
    593   *source_filep = source_file;
    594   return object_file;
    595 }
    596 
    597 /* The "compile" prefix command.  */
    598 
    599 static void
    600 compile_command (char *args, int from_tty)
    601 {
    602   /* If a sub-command is not specified to the compile prefix command,
    603      assume it is a direct code compilation.  */
    604   compile_code_command (args, from_tty);
    605 }
    606 
    607 /* See compile.h.  */
    608 
    609 void
    610 eval_compile_command (struct command_line *cmd, const char *cmd_string,
    611 		      enum compile_i_scope_types scope, void *scope_data)
    612 {
    613   char *object_file, *source_file;
    614 
    615   object_file = compile_to_object (cmd, cmd_string, scope, &source_file);
    616   if (object_file != NULL)
    617     {
    618       struct cleanup *cleanup_xfree, *cleanup_unlink;
    619       struct compile_module *compile_module;
    620 
    621       cleanup_xfree = make_cleanup (xfree, object_file);
    622       make_cleanup (xfree, source_file);
    623       cleanup_unlink = make_cleanup (cleanup_unlink_file, object_file);
    624       make_cleanup (cleanup_unlink_file, source_file);
    625       compile_module = compile_object_load (object_file, source_file,
    626 					    scope, scope_data);
    627       if (compile_module == NULL)
    628 	{
    629 	  gdb_assert (scope == COMPILE_I_PRINT_ADDRESS_SCOPE);
    630 	  do_cleanups (cleanup_xfree);
    631 	  eval_compile_command (cmd, cmd_string,
    632 				COMPILE_I_PRINT_VALUE_SCOPE, scope_data);
    633 	  return;
    634 	}
    635       discard_cleanups (cleanup_unlink);
    636       do_cleanups (cleanup_xfree);
    637       compile_object_run (compile_module);
    638     }
    639 }
    640 
    641 /* See compile/compile-internal.h.  */
    642 
    643 char *
    644 compile_register_name_mangled (struct gdbarch *gdbarch, int regnum)
    645 {
    646   const char *regname = gdbarch_register_name (gdbarch, regnum);
    647 
    648   return xstrprintf ("__%s", regname);
    649 }
    650 
    651 /* See compile/compile-internal.h.  */
    652 
    653 int
    654 compile_register_name_demangle (struct gdbarch *gdbarch,
    655 				 const char *regname)
    656 {
    657   int regnum;
    658 
    659   if (regname[0] != '_' || regname[1] != '_')
    660     error (_("Invalid register name \"%s\"."), regname);
    661   regname += 2;
    662 
    663   for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
    664     if (strcmp (regname, gdbarch_register_name (gdbarch, regnum)) == 0)
    665       return regnum;
    666 
    667   error (_("Cannot find gdbarch register \"%s\"."), regname);
    668 }
    669 
    670 extern initialize_file_ftype _initialize_compile;
    671 
    672 void
    673 _initialize_compile (void)
    674 {
    675   struct cmd_list_element *c = NULL;
    676 
    677   add_prefix_cmd ("compile", class_obscure, compile_command,
    678 		  _("\
    679 Command to compile source code and inject it into the inferior."),
    680 		  &compile_command_list, "compile ", 1, &cmdlist);
    681   add_com_alias ("expression", "compile", class_obscure, 0);
    682 
    683   add_cmd ("code", class_obscure, compile_code_command,
    684 	   _("\
    685 Compile, inject, and execute code.\n\
    686 \n\
    687 Usage: compile code [-r|-raw] [--] [CODE]\n\
    688 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping.\n\
    689 --: Do not parse any options beyond this delimiter.  All text to the\n\
    690     right will be treated as source code.\n\
    691 \n\
    692 The source code may be specified as a simple one line expression, e.g.:\n\
    693 \n\
    694     compile code printf(\"Hello world\\n\");\n\
    695 \n\
    696 Alternatively, you can type a multiline expression by invoking\n\
    697 this command with no argument.  GDB will then prompt for the\n\
    698 expression interactively; type a line containing \"end\" to\n\
    699 indicate the end of the expression."),
    700 	   &compile_command_list);
    701 
    702   c = add_cmd ("file", class_obscure, compile_file_command,
    703 	       _("\
    704 Evaluate a file containing source code.\n\
    705 \n\
    706 Usage: compile file [-r|-raw] [filename]\n\
    707 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping."),
    708 	       &compile_command_list);
    709   set_cmd_completer (c, filename_completer);
    710 
    711   add_cmd ("print", class_obscure, compile_print_command,
    712 	   _("\
    713 Evaluate EXPR by using the compiler and print result.\n\
    714 \n\
    715 Usage: compile print[/FMT] [EXPR]\n\
    716 \n\
    717 The expression may be specified on the same line as the command, e.g.:\n\
    718 \n\
    719     compile print i\n\
    720 \n\
    721 Alternatively, you can type a multiline expression by invoking\n\
    722 this command with no argument.  GDB will then prompt for the\n\
    723 expression interactively; type a line containing \"end\" to\n\
    724 indicate the end of the expression.\n\
    725 \n\
    726 EXPR may be preceded with /FMT, where FMT is a format letter\n\
    727 but no count or size letter (see \"x\" command)."),
    728 	   &compile_command_list);
    729 
    730   add_setshow_boolean_cmd ("compile", class_maintenance, &compile_debug, _("\
    731 Set compile command debugging."), _("\
    732 Show compile command debugging."), _("\
    733 When on, compile command debugging is enabled."),
    734 			   NULL, show_compile_debug,
    735 			   &setdebuglist, &showdebuglist);
    736 
    737   add_setshow_string_cmd ("compile-args", class_support,
    738 			  &compile_args,
    739 			  _("Set compile command GCC command-line arguments"),
    740 			  _("Show compile command GCC command-line arguments"),
    741 			  _("\
    742 Use options like -I (include file directory) or ABI settings.\n\
    743 String quoting is parsed like in shell, for example:\n\
    744   -mno-align-double \"-I/dir with a space/include\""),
    745 			  set_compile_args, show_compile_args, &setlist, &showlist);
    746 
    747   /* Override flags possibly coming from DW_AT_producer.  */
    748   compile_args = xstrdup ("-O0 -gdwarf-4"
    749   /* We use -fPIE Otherwise GDB would need to reserve space large enough for
    750      any object file in the inferior in advance to get the final address when
    751      to link the object file to and additionally the default system linker
    752      script would need to be modified so that one can specify there the
    753      absolute target address.
    754      -fPIC is not used at is would require from GDB to generate .got.  */
    755 			 " -fPIE"
    756   /* We want warnings, except for some commonly happening for GDB commands.  */
    757 			 " -Wall "
    758 			 " -Wno-implicit-function-declaration"
    759 			 " -Wno-unused-but-set-variable"
    760 			 " -Wno-unused-variable"
    761   /* Override CU's possible -fstack-protector-strong.  */
    762 			 " -fno-stack-protector"
    763   );
    764   set_compile_args (compile_args, 0, NULL);
    765 }
    766