Home | History | Annotate | Line # | Download | only in compile
compile.c revision 1.7.2.1
      1      1.1  christos /* General Compile and inject code
      2      1.1  christos 
      3  1.7.2.1  perseant    Copyright (C) 2014-2023 Free Software Foundation, Inc.
      4      1.1  christos 
      5      1.1  christos    This file is part of GDB.
      6      1.1  christos 
      7      1.1  christos    This program is free software; you can redistribute it and/or modify
      8      1.1  christos    it under the terms of the GNU General Public License as published by
      9      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10      1.1  christos    (at your option) any later version.
     11      1.1  christos 
     12      1.1  christos    This program is distributed in the hope that it will be useful,
     13      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1  christos    GNU General Public License for more details.
     16      1.1  christos 
     17      1.1  christos    You should have received a copy of the GNU General Public License
     18      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19      1.1  christos 
     20      1.1  christos #include "defs.h"
     21      1.4  christos #include "top.h"
     22      1.1  christos #include "ui-out.h"
     23      1.1  christos #include "command.h"
     24      1.1  christos #include "cli/cli-script.h"
     25      1.1  christos #include "cli/cli-utils.h"
     26      1.7  christos #include "cli/cli-option.h"
     27      1.1  christos #include "completer.h"
     28      1.1  christos #include "gdbcmd.h"
     29      1.1  christos #include "compile.h"
     30      1.1  christos #include "compile-internal.h"
     31      1.1  christos #include "compile-object-load.h"
     32      1.1  christos #include "compile-object-run.h"
     33      1.1  christos #include "language.h"
     34      1.1  christos #include "frame.h"
     35      1.1  christos #include "source.h"
     36      1.1  christos #include "block.h"
     37      1.1  christos #include "arch-utils.h"
     38      1.7  christos #include "gdbsupport/filestuff.h"
     39      1.1  christos #include "target.h"
     40      1.1  christos #include "osabi.h"
     41      1.7  christos #include "gdbsupport/gdb_wait.h"
     42      1.3  christos #include "valprint.h"
     43      1.7  christos #include "gdbsupport/gdb_optional.h"
     44      1.7  christos #include "gdbsupport/gdb_unlinker.h"
     45      1.7  christos #include "gdbsupport/pathstuff.h"
     46  1.7.2.1  perseant #include "gdbsupport/scoped_ignore_signal.h"
     47  1.7.2.1  perseant #include "gdbsupport/buildargv.h"
     48      1.1  christos 
     49      1.1  christos 
     50      1.1  christos 
     52      1.1  christos /* Initial filename for temporary files.  */
     53      1.1  christos 
     54      1.1  christos #define TMP_PREFIX "/tmp/gdbobj-"
     55      1.1  christos 
     56      1.1  christos /* Hold "compile" commands.  */
     57      1.1  christos 
     58      1.1  christos static struct cmd_list_element *compile_command_list;
     59      1.1  christos 
     60      1.1  christos /* Debug flag for "compile" commands.  */
     61      1.7  christos 
     62      1.1  christos bool compile_debug;
     63      1.6  christos 
     64      1.6  christos /* Object of this type are stored in the compiler's symbol_err_map.  */
     65      1.6  christos 
     66      1.6  christos struct symbol_error
     67      1.6  christos {
     68      1.6  christos   /* The symbol.  */
     69      1.6  christos 
     70      1.6  christos   const struct symbol *sym;
     71      1.6  christos 
     72      1.6  christos   /* The error message to emit.  This is malloc'd and owned by the
     73      1.6  christos      hash table.  */
     74      1.6  christos 
     75      1.6  christos   char *message;
     76      1.6  christos };
     77      1.6  christos 
     78      1.6  christos /* Hash a type_map_instance.  */
     79      1.6  christos 
     80      1.6  christos static hashval_t
     81      1.6  christos hash_type_map_instance (const void *p)
     82      1.6  christos {
     83      1.6  christos   const struct type_map_instance *inst = (const struct type_map_instance *) p;
     84      1.6  christos 
     85      1.6  christos   return htab_hash_pointer (inst->type);
     86      1.6  christos }
     87      1.6  christos 
     88      1.6  christos /* Check two type_map_instance objects for equality.  */
     89      1.6  christos 
     90      1.6  christos static int
     91      1.6  christos eq_type_map_instance (const void *a, const void *b)
     92      1.6  christos {
     93      1.6  christos   const struct type_map_instance *insta = (const struct type_map_instance *) a;
     94      1.6  christos   const struct type_map_instance *instb = (const struct type_map_instance *) b;
     95      1.6  christos 
     96      1.6  christos   return insta->type == instb->type;
     97      1.6  christos }
     98      1.6  christos 
     99      1.6  christos /* Hash function for struct symbol_error.  */
    100      1.6  christos 
    101      1.6  christos static hashval_t
    102      1.6  christos hash_symbol_error (const void *a)
    103      1.6  christos {
    104      1.6  christos   const struct symbol_error *se = (const struct symbol_error *) a;
    105      1.6  christos 
    106      1.6  christos   return htab_hash_pointer (se->sym);
    107      1.6  christos }
    108      1.6  christos 
    109      1.6  christos /* Equality function for struct symbol_error.  */
    110      1.6  christos 
    111      1.6  christos static int
    112      1.6  christos eq_symbol_error (const void *a, const void *b)
    113      1.6  christos {
    114      1.6  christos   const struct symbol_error *sea = (const struct symbol_error *) a;
    115      1.6  christos   const struct symbol_error *seb = (const struct symbol_error *) b;
    116      1.6  christos 
    117      1.6  christos   return sea->sym == seb->sym;
    118      1.6  christos }
    119      1.6  christos 
    120      1.6  christos /* Deletion function for struct symbol_error.  */
    121      1.6  christos 
    122      1.6  christos static void
    123      1.6  christos del_symbol_error (void *a)
    124      1.6  christos {
    125      1.6  christos   struct symbol_error *se = (struct symbol_error *) a;
    126      1.6  christos 
    127      1.6  christos   xfree (se->message);
    128      1.6  christos   xfree (se);
    129      1.6  christos }
    130      1.6  christos 
    131      1.6  christos /* Constructor for compile_instance.  */
    132      1.6  christos 
    133      1.6  christos compile_instance::compile_instance (struct gcc_base_context *gcc_fe,
    134      1.6  christos 				    const char *options)
    135      1.6  christos   : m_gcc_fe (gcc_fe), m_gcc_target_options (options),
    136      1.6  christos     m_type_map (htab_create_alloc (10, hash_type_map_instance,
    137      1.6  christos 				   eq_type_map_instance,
    138      1.6  christos 				   xfree, xcalloc, xfree)),
    139      1.6  christos     m_symbol_err_map (htab_create_alloc (10, hash_symbol_error,
    140      1.6  christos 					 eq_symbol_error, del_symbol_error,
    141      1.6  christos 					 xcalloc, xfree))
    142      1.6  christos {
    143      1.6  christos }
    144      1.6  christos 
    145      1.6  christos /* See compile-internal.h.  */
    146      1.6  christos 
    147      1.6  christos bool
    148      1.6  christos compile_instance::get_cached_type (struct type *type, gcc_type *ret) const
    149      1.6  christos {
    150      1.6  christos   struct type_map_instance inst, *found;
    151      1.6  christos 
    152      1.6  christos   inst.type = type;
    153      1.6  christos   found = (struct type_map_instance *) htab_find (m_type_map.get (), &inst);
    154      1.6  christos   if (found != NULL)
    155      1.6  christos     {
    156      1.6  christos       *ret = found->gcc_type_handle;
    157      1.6  christos       return true;
    158      1.6  christos     }
    159      1.6  christos 
    160      1.6  christos   return false;
    161      1.6  christos }
    162      1.6  christos 
    163      1.6  christos /* See compile-internal.h.  */
    164      1.6  christos 
    165      1.6  christos void
    166      1.6  christos compile_instance::insert_type (struct type *type, gcc_type gcc_type)
    167      1.6  christos {
    168      1.6  christos   struct type_map_instance inst, *add;
    169      1.6  christos   void **slot;
    170      1.6  christos 
    171      1.6  christos   inst.type = type;
    172      1.6  christos   inst.gcc_type_handle = gcc_type;
    173      1.6  christos   slot = htab_find_slot (m_type_map.get (), &inst, INSERT);
    174      1.6  christos 
    175      1.6  christos   add = (struct type_map_instance *) *slot;
    176      1.6  christos   /* The type might have already been inserted in order to handle
    177      1.6  christos      recursive types.  */
    178      1.6  christos   if (add != NULL && add->gcc_type_handle != gcc_type)
    179      1.6  christos     error (_("Unexpected type id from GCC, check you use recent enough GCC."));
    180      1.6  christos 
    181      1.6  christos   if (add == NULL)
    182      1.6  christos     {
    183      1.6  christos       add = XNEW (struct type_map_instance);
    184      1.6  christos       *add = inst;
    185      1.6  christos       *slot = add;
    186      1.6  christos     }
    187      1.6  christos }
    188      1.6  christos 
    189      1.6  christos /* See compile-internal.h.  */
    190      1.6  christos 
    191      1.6  christos void
    192      1.6  christos compile_instance::insert_symbol_error (const struct symbol *sym,
    193      1.6  christos 				       const char *text)
    194      1.6  christos {
    195      1.6  christos   struct symbol_error e;
    196      1.6  christos   void **slot;
    197      1.6  christos 
    198      1.6  christos   e.sym = sym;
    199      1.6  christos   slot = htab_find_slot (m_symbol_err_map.get (), &e, INSERT);
    200      1.6  christos   if (*slot == NULL)
    201      1.6  christos     {
    202      1.6  christos       struct symbol_error *ep = XNEW (struct symbol_error);
    203      1.6  christos 
    204      1.6  christos       ep->sym = sym;
    205      1.6  christos       ep->message = xstrdup (text);
    206      1.6  christos       *slot = ep;
    207      1.6  christos     }
    208      1.6  christos }
    209      1.6  christos 
    210      1.6  christos /* See compile-internal.h.  */
    211      1.6  christos 
    212      1.6  christos void
    213      1.6  christos compile_instance::error_symbol_once (const struct symbol *sym)
    214      1.6  christos {
    215      1.6  christos   struct symbol_error search;
    216      1.6  christos   struct symbol_error *err;
    217      1.6  christos 
    218      1.6  christos   if (m_symbol_err_map == NULL)
    219      1.6  christos     return;
    220      1.6  christos 
    221      1.6  christos   search.sym = sym;
    222      1.6  christos   err = (struct symbol_error *) htab_find (m_symbol_err_map.get (), &search);
    223      1.6  christos   if (err == NULL || err->message == NULL)
    224      1.6  christos     return;
    225      1.6  christos 
    226      1.6  christos   gdb::unique_xmalloc_ptr<char> message (err->message);
    227      1.6  christos   err->message = NULL;
    228      1.6  christos   error (_("%s"), message.get ());
    229      1.6  christos }
    230      1.1  christos 
    231      1.1  christos /* Implement "show debug compile".  */
    232      1.1  christos 
    233      1.1  christos static void
    234      1.1  christos show_compile_debug (struct ui_file *file, int from_tty,
    235      1.1  christos 		    struct cmd_list_element *c, const char *value)
    236  1.7.2.1  perseant {
    237      1.1  christos   gdb_printf (file, _("Compile debugging is %s.\n"), value);
    238      1.1  christos }
    239      1.1  christos 
    240      1.1  christos 
    241      1.7  christos 
    243      1.7  christos /* Options for the compile command.  */
    244      1.1  christos 
    245      1.7  christos struct compile_options
    246      1.7  christos {
    247      1.7  christos   /* For -raw.  */
    248      1.7  christos   bool raw = false;
    249      1.7  christos };
    250      1.7  christos 
    251      1.7  christos using compile_flag_option_def
    252      1.7  christos   = gdb::option::flag_option_def<compile_options>;
    253      1.7  christos 
    254      1.7  christos static const gdb::option::option_def compile_command_option_defs[] = {
    255      1.7  christos 
    256      1.7  christos   compile_flag_option_def {
    257      1.7  christos     "raw",
    258      1.7  christos     [] (compile_options *opts) { return &opts->raw; },
    259      1.7  christos     N_("Suppress automatic 'void _gdb_expr () { CODE }' wrapping."),
    260      1.7  christos   },
    261      1.7  christos 
    262      1.7  christos };
    263      1.7  christos 
    264      1.1  christos /* Create an option_def_group for the "compile" command's options,
    265      1.7  christos    with OPTS as context.  */
    266      1.7  christos 
    267      1.7  christos static gdb::option::option_def_group
    268      1.7  christos make_compile_options_def_group (compile_options *opts)
    269      1.1  christos {
    270      1.1  christos   return {{compile_command_option_defs}, opts};
    271      1.1  christos }
    272      1.1  christos 
    273      1.1  christos /* Handle the input from the 'compile file' command.  The "compile
    274      1.1  christos    file" command is used to evaluate an expression contained in a file
    275      1.1  christos    that may contain calls to the GCC compiler.  */
    276      1.7  christos 
    277      1.1  christos static void
    278      1.7  christos compile_file_command (const char *args, int from_tty)
    279      1.7  christos {
    280      1.7  christos   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
    281      1.1  christos 
    282      1.7  christos   /* Check if a -raw option is provided.  */
    283      1.1  christos 
    284      1.7  christos   compile_options options;
    285      1.7  christos 
    286      1.7  christos   const gdb::option::option_def_group group
    287      1.7  christos     = make_compile_options_def_group (&options);
    288      1.7  christos   gdb::option::process_options
    289      1.1  christos     (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR,
    290      1.7  christos      group);
    291      1.7  christos 
    292      1.1  christos   enum compile_i_scope_types scope
    293      1.7  christos     = options.raw ? COMPILE_I_RAW_SCOPE : COMPILE_I_SIMPLE_SCOPE;
    294      1.1  christos 
    295      1.7  christos   args = skip_spaces (args);
    296      1.7  christos 
    297      1.7  christos   /* After processing options, check whether we have a filename.  */
    298      1.1  christos   if (args == nullptr || args[0] == '\0')
    299      1.7  christos     error (_("You must provide a filename for this command."));
    300  1.7.2.1  perseant 
    301  1.7.2.1  perseant   args = skip_spaces (args);
    302      1.6  christos   std::string abspath = gdb_abspath (args);
    303      1.1  christos   std::string buffer = string_printf ("#include \"%s\"\n", abspath.c_str ());
    304      1.1  christos   eval_compile_command (NULL, buffer.c_str (), scope, NULL);
    305      1.7  christos }
    306      1.7  christos 
    307      1.7  christos /* Completer for the "compile file" command.  */
    308      1.7  christos 
    309      1.7  christos static void
    310      1.7  christos compile_file_command_completer (struct cmd_list_element *ignore,
    311      1.7  christos 				completion_tracker &tracker,
    312      1.7  christos 				const char *text, const char *word)
    313      1.7  christos {
    314      1.7  christos   const gdb::option::option_def_group group
    315      1.7  christos     = make_compile_options_def_group (nullptr);
    316      1.7  christos   if (gdb::option::complete_options
    317      1.7  christos       (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group))
    318      1.7  christos     return;
    319      1.7  christos 
    320      1.7  christos   word = advance_to_filename_complete_word_point (tracker, text);
    321      1.7  christos   filename_completer (ignore, tracker, text, word);
    322      1.1  christos }
    323      1.1  christos 
    324      1.1  christos /* Handle the input from the 'compile code' command.  The
    325      1.1  christos    "compile code" command is used to evaluate an expression that may
    326      1.1  christos    contain calls to the GCC compiler.  The language expected in this
    327      1.1  christos    compile command is the language currently set in GDB.  */
    328      1.7  christos 
    329      1.1  christos static void
    330      1.5  christos compile_code_command (const char *args, int from_tty)
    331      1.1  christos {
    332      1.7  christos   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
    333      1.1  christos 
    334      1.7  christos   compile_options options;
    335      1.7  christos 
    336      1.7  christos   const gdb::option::option_def_group group
    337      1.7  christos     = make_compile_options_def_group (&options);
    338      1.1  christos   gdb::option::process_options
    339      1.7  christos     (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group);
    340      1.7  christos 
    341      1.1  christos   enum compile_i_scope_types scope
    342      1.7  christos     = options.raw ? COMPILE_I_RAW_SCOPE : COMPILE_I_SIMPLE_SCOPE;
    343      1.7  christos 
    344      1.1  christos   if (args && *args)
    345      1.1  christos     eval_compile_command (NULL, args, scope, NULL);
    346      1.6  christos   else
    347      1.1  christos     {
    348      1.1  christos       counted_command_line l = get_command_line (compile_control, "");
    349      1.5  christos 
    350      1.1  christos       l->control_u.compile.scope = scope;
    351      1.1  christos       execute_control_command_untraced (l.get ());
    352      1.1  christos     }
    353      1.7  christos }
    354      1.7  christos 
    355      1.7  christos /* Completer for the "compile code" command.  */
    356      1.7  christos 
    357      1.7  christos static void
    358      1.7  christos compile_code_command_completer (struct cmd_list_element *ignore,
    359      1.7  christos 				completion_tracker &tracker,
    360      1.7  christos 				const char *text, const char *word)
    361      1.7  christos {
    362      1.7  christos   const gdb::option::option_def_group group
    363      1.7  christos     = make_compile_options_def_group (nullptr);
    364      1.7  christos   if (gdb::option::complete_options
    365      1.7  christos       (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group))
    366      1.7  christos     return;
    367      1.7  christos 
    368      1.7  christos   word = advance_to_expression_complete_word_point (tracker, text);
    369      1.7  christos   symbol_completer (ignore, tracker, text, word);
    370      1.3  christos }
    371      1.3  christos 
    372      1.3  christos /* Callback for compile_print_command.  */
    373      1.3  christos 
    374      1.3  christos void
    375      1.7  christos compile_print_value (struct value *val, void *data_voidp)
    376      1.3  christos {
    377      1.7  christos   const value_print_options *print_opts = (value_print_options *) data_voidp;
    378      1.3  christos 
    379      1.3  christos   print_value (val, *print_opts);
    380      1.3  christos }
    381      1.3  christos 
    382      1.3  christos /* Handle the input from the 'compile print' command.  The "compile
    383      1.3  christos    print" command is used to evaluate and print an expression that may
    384      1.3  christos    contain calls to the GCC compiler.  The language expected in this
    385      1.3  christos    compile command is the language currently set in GDB.  */
    386      1.6  christos 
    387      1.3  christos static void
    388      1.3  christos compile_print_command (const char *arg, int from_tty)
    389      1.7  christos {
    390      1.3  christos   enum compile_i_scope_types scope = COMPILE_I_PRINT_ADDRESS_SCOPE;
    391      1.5  christos   value_print_options print_opts;
    392      1.3  christos 
    393      1.7  christos   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
    394      1.7  christos 
    395      1.7  christos   get_user_print_options (&print_opts);
    396      1.7  christos   /* Override global settings with explicit options, if any.  */
    397      1.7  christos   auto group = make_value_print_options_def_group (&print_opts);
    398      1.7  christos   gdb::option::process_options
    399      1.7  christos     (&arg, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group);
    400      1.7  christos 
    401      1.7  christos   print_command_parse_format (&arg, "compile print", &print_opts);
    402      1.7  christos 
    403      1.7  christos   /* Passing &PRINT_OPTS as SCOPE_DATA is safe as do_module_cleanup
    404      1.3  christos      will not touch the stale pointer if compile_object_run has
    405      1.3  christos      already quit.  */
    406      1.7  christos 
    407      1.3  christos   if (arg && *arg)
    408      1.3  christos     eval_compile_command (NULL, arg, scope, &print_opts);
    409      1.6  christos   else
    410      1.3  christos     {
    411      1.3  christos       counted_command_line l = get_command_line (compile_control, "");
    412      1.7  christos 
    413      1.5  christos       l->control_u.compile.scope = scope;
    414      1.3  christos       l->control_u.compile.scope_data = &print_opts;
    415      1.3  christos       execute_control_command_untraced (l.get ());
    416      1.3  christos     }
    417      1.1  christos }
    418      1.1  christos 
    419      1.1  christos /* A cleanup function to remove a directory and all its contents.  */
    420      1.1  christos 
    421      1.1  christos static void
    422      1.4  christos do_rmdir (void *arg)
    423      1.1  christos {
    424      1.1  christos   const char *dir = (const char *) arg;
    425      1.1  christos   char *zap;
    426      1.3  christos   int wstat;
    427      1.1  christos 
    428      1.1  christos   gdb_assert (startswith (dir, TMP_PREFIX));
    429      1.1  christos   zap = concat ("rm -rf ", dir, (char *) NULL);
    430      1.1  christos   wstat = system (zap);
    431      1.1  christos   if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
    432      1.1  christos     warning (_("Could not remove temporary directory %s"), dir);
    433      1.1  christos   XDELETEVEC (zap);
    434      1.1  christos }
    435      1.1  christos 
    436      1.1  christos /* Return the name of the temporary directory to use for .o files, and
    437      1.1  christos    arrange for the directory to be removed at shutdown.  */
    438      1.1  christos 
    439      1.1  christos static const char *
    440      1.1  christos get_compile_file_tempdir (void)
    441      1.1  christos {
    442      1.1  christos   static char *tempdir_name;
    443      1.1  christos 
    444      1.1  christos #define TEMPLATE TMP_PREFIX "XXXXXX"
    445      1.1  christos   char tname[sizeof (TEMPLATE)];
    446      1.1  christos 
    447      1.1  christos   if (tempdir_name != NULL)
    448      1.1  christos     return tempdir_name;
    449      1.1  christos 
    450      1.1  christos   strcpy (tname, TEMPLATE);
    451      1.1  christos #undef TEMPLATE
    452      1.1  christos   tempdir_name = mkdtemp (tname);
    453      1.1  christos   if (tempdir_name == NULL)
    454      1.1  christos     perror_with_name (_("Could not make temporary directory"));
    455      1.1  christos 
    456      1.1  christos   tempdir_name = xstrdup (tempdir_name);
    457      1.1  christos   make_final_cleanup (do_rmdir, tempdir_name);
    458      1.1  christos   return tempdir_name;
    459      1.5  christos }
    460      1.1  christos 
    461      1.5  christos /* Compute the names of source and object files to use.  */
    462      1.5  christos 
    463      1.1  christos static compile_file_names
    464      1.1  christos get_new_file_names ()
    465      1.1  christos {
    466      1.1  christos   static int seq;
    467      1.1  christos   const char *dir = get_compile_file_tempdir ();
    468      1.5  christos 
    469      1.5  christos   ++seq;
    470      1.5  christos 
    471      1.5  christos   return compile_file_names (string_printf ("%s%sout%d.c",
    472      1.5  christos 					    dir, SLASH_STRING, seq),
    473      1.1  christos 			     string_printf ("%s%sout%d.o",
    474      1.1  christos 					    dir, SLASH_STRING, seq));
    475      1.1  christos }
    476      1.1  christos 
    477      1.1  christos /* Get the block and PC at which to evaluate an expression.  */
    478      1.1  christos 
    479      1.1  christos static const struct block *
    480      1.1  christos get_expr_block_and_pc (CORE_ADDR *pc)
    481      1.1  christos {
    482      1.1  christos   const struct block *block = get_selected_block (pc);
    483      1.1  christos 
    484      1.1  christos   if (block == NULL)
    485      1.1  christos     {
    486      1.1  christos       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
    487  1.7.2.1  perseant 
    488  1.7.2.1  perseant       if (cursal.symtab)
    489      1.1  christos 	block = cursal.symtab->compunit ()->blockvector ()->static_block ();
    490  1.7.2.1  perseant 
    491      1.1  christos       if (block != NULL)
    492      1.1  christos 	*pc = block->entry_pc ();
    493  1.7.2.1  perseant     }
    494      1.1  christos   else
    495      1.1  christos     *pc = block->entry_pc ();
    496      1.1  christos 
    497      1.1  christos   return block;
    498      1.1  christos }
    499  1.7.2.1  perseant 
    500  1.7.2.1  perseant /* String for 'set compile-args' and 'show compile-args'.  */
    501  1.7.2.1  perseant static std::string compile_args =
    502  1.7.2.1  perseant   /* Override flags possibly coming from DW_AT_producer.  */
    503  1.7.2.1  perseant   "-O0 -gdwarf-4"
    504  1.7.2.1  perseant   /* We use -fPIE Otherwise GDB would need to reserve space large enough for
    505  1.7.2.1  perseant      any object file in the inferior in advance to get the final address when
    506  1.7.2.1  perseant      to link the object file to and additionally the default system linker
    507  1.7.2.1  perseant      script would need to be modified so that one can specify there the
    508  1.7.2.1  perseant      absolute target address.
    509  1.7.2.1  perseant      -fPIC is not used at is would require from GDB to generate .got.  */
    510  1.7.2.1  perseant   " -fPIE"
    511  1.7.2.1  perseant   /* We want warnings, except for some commonly happening for GDB commands.  */
    512  1.7.2.1  perseant   " -Wall "
    513  1.7.2.1  perseant   " -Wno-unused-but-set-variable"
    514  1.7.2.1  perseant   " -Wno-unused-variable"
    515      1.1  christos   /* Override CU's possible -fstack-protector-strong.  */
    516  1.7.2.1  perseant   " -fno-stack-protector";
    517  1.7.2.1  perseant 
    518      1.1  christos /* Parsed form of COMPILE_ARGS.  */
    519      1.1  christos static gdb_argv compile_args_argv;
    520      1.1  christos 
    521      1.1  christos /* Implement 'set compile-args'.  */
    522      1.6  christos 
    523      1.1  christos static void
    524  1.7.2.1  perseant set_compile_args (const char *args, int from_tty, struct cmd_list_element *c)
    525      1.1  christos {
    526      1.1  christos   compile_args_argv = gdb_argv (compile_args.c_str ());
    527      1.1  christos }
    528      1.1  christos 
    529      1.1  christos /* Implement 'show compile-args'.  */
    530      1.1  christos 
    531      1.1  christos static void
    532      1.1  christos show_compile_args (struct ui_file *file, int from_tty,
    533  1.7.2.1  perseant 		   struct cmd_list_element *c, const char *value)
    534  1.7.2.1  perseant {
    535  1.7.2.1  perseant   gdb_printf (file, _("Compile command command-line arguments "
    536      1.1  christos 		      "are \"%s\".\n"),
    537      1.1  christos 	      value);
    538      1.6  christos }
    539  1.7.2.1  perseant 
    540      1.6  christos /* String for 'set compile-gcc' and 'show compile-gcc'.  */
    541      1.6  christos static std::string compile_gcc;
    542      1.6  christos 
    543      1.6  christos /* Implement 'show compile-gcc'.  */
    544      1.6  christos 
    545      1.6  christos static void
    546      1.6  christos show_compile_gcc (struct ui_file *file, int from_tty,
    547  1.7.2.1  perseant 		  struct cmd_list_element *c, const char *value)
    548  1.7.2.1  perseant {
    549      1.6  christos   gdb_printf (file, _("Compile command GCC driver filename is \"%s\".\n"),
    550      1.6  christos 	      value);
    551      1.1  christos }
    552      1.1  christos 
    553      1.1  christos /* Return DW_AT_producer parsed for get_selected_frame () (if any).
    554      1.1  christos    Return NULL otherwise.
    555      1.1  christos 
    556      1.1  christos    GCC already filters its command-line arguments only for the suitable ones to
    557      1.1  christos    put into DW_AT_producer - see GCC function gen_producer_string.  */
    558      1.1  christos 
    559      1.1  christos static const char *
    560      1.1  christos get_selected_pc_producer_options (void)
    561      1.1  christos {
    562      1.1  christos   CORE_ADDR pc = get_frame_pc (get_selected_frame (NULL));
    563      1.1  christos   struct compunit_symtab *symtab = find_pc_compunit_symtab (pc);
    564  1.7.2.1  perseant   const char *cs;
    565  1.7.2.1  perseant 
    566      1.1  christos   if (symtab == NULL || symtab->producer () == NULL
    567      1.1  christos       || !startswith (symtab->producer (), "GNU "))
    568  1.7.2.1  perseant     return NULL;
    569      1.1  christos 
    570      1.6  christos   cs = symtab->producer ();
    571      1.1  christos   while (*cs != 0 && *cs != '-')
    572      1.1  christos     cs = skip_spaces (skip_to_space (cs));
    573      1.1  christos   if (*cs != '-')
    574      1.1  christos     return NULL;
    575      1.1  christos   return cs;
    576  1.7.2.1  perseant }
    577      1.1  christos 
    578      1.1  christos /* Filter out unwanted options from ARGV.  */
    579  1.7.2.1  perseant 
    580      1.1  christos static void
    581      1.1  christos filter_args (char **argv)
    582      1.1  christos {
    583      1.1  christos   char **destv;
    584      1.1  christos 
    585      1.1  christos   for (destv = argv; *argv != NULL; argv++)
    586      1.1  christos     {
    587      1.1  christos       /* -fpreprocessed may get in commonly from ccache.  */
    588      1.1  christos       if (strcmp (*argv, "-fpreprocessed") == 0)
    589      1.1  christos 	{
    590      1.1  christos 	  xfree (*argv);
    591      1.1  christos 	  continue;
    592      1.1  christos 	}
    593      1.1  christos       *destv++ = *argv;
    594      1.1  christos     }
    595      1.1  christos   *destv = NULL;
    596      1.6  christos }
    597      1.6  christos 
    598      1.6  christos /* Produce final vector of GCC compilation options.
    599      1.6  christos 
    600      1.6  christos    The first element of the combined argument vector are arguments
    601      1.6  christos    relating to the target size ("-m64", "-m32" etc.).  These are
    602      1.6  christos    sourced from the inferior's architecture.
    603      1.6  christos 
    604      1.6  christos    The second element of the combined argument vector are arguments
    605      1.6  christos    stored in the inferior DW_AT_producer section.  If these are stored
    606      1.6  christos    in the inferior (there is no guarantee that they are), they are
    607      1.6  christos    added to the vector.
    608      1.6  christos 
    609      1.6  christos    The third element of the combined argument vector are argument
    610      1.6  christos    supplied by the language implementation provided by
    611      1.6  christos    compile-{lang}-support.  These contain language specific arguments.
    612      1.6  christos 
    613      1.6  christos    The final element of the combined argument vector are arguments
    614      1.6  christos    supplied by the "set compile-args" command.  These are always
    615      1.1  christos    appended last so as to override any of the arguments automatically
    616  1.7.2.1  perseant    generated above.  */
    617  1.7.2.1  perseant 
    618      1.1  christos static gdb_argv
    619      1.1  christos get_args (const compile_instance *compiler, struct gdbarch *gdbarch)
    620  1.7.2.1  perseant {
    621      1.1  christos   const char *cs_producer_options;
    622  1.7.2.1  perseant   gdb_argv result;
    623  1.7.2.1  perseant 
    624  1.7.2.1  perseant   std::string gcc_options = gdbarch_gcc_target_options (gdbarch);
    625  1.7.2.1  perseant 
    626  1.7.2.1  perseant   /* Make sure we have a non-empty set of options, otherwise GCC will
    627  1.7.2.1  perseant      error out trying to look for a filename that is an empty string.  */
    628      1.1  christos   if (!gcc_options.empty ())
    629      1.1  christos     result = gdb_argv (gcc_options.c_str ());
    630      1.1  christos 
    631      1.1  christos   cs_producer_options = get_selected_pc_producer_options ();
    632  1.7.2.1  perseant   if (cs_producer_options != NULL)
    633  1.7.2.1  perseant     {
    634      1.1  christos       gdb_argv argv_producer (cs_producer_options);
    635  1.7.2.1  perseant       filter_args (argv_producer.get ());
    636      1.1  christos 
    637      1.1  christos       result.append (std::move (argv_producer));
    638  1.7.2.1  perseant     }
    639  1.7.2.1  perseant 
    640      1.1  christos   result.append (gdb_argv (compiler->gcc_target_options ().c_str ()));
    641  1.7.2.1  perseant   result.append (compile_args_argv);
    642      1.1  christos 
    643      1.1  christos   return result;
    644      1.1  christos }
    645      1.1  christos 
    646      1.1  christos /* A helper function suitable for use as the "print_callback" in the
    647      1.1  christos    compiler object.  */
    648      1.1  christos 
    649      1.1  christos static void
    650  1.7.2.1  perseant print_callback (void *ignore, const char *message)
    651      1.1  christos {
    652      1.1  christos   gdb_puts (message, gdb_stderr);
    653      1.1  christos }
    654      1.5  christos 
    655      1.5  christos /* Process the compilation request.  On success it returns the object
    656      1.1  christos    and source file names.  On an error condition, error () is
    657      1.5  christos    called.  */
    658      1.3  christos 
    659      1.5  christos static compile_file_names
    660      1.1  christos compile_to_object (struct command_line *cmd, const char *cmd_string,
    661      1.1  christos 		   enum compile_i_scope_types scope)
    662      1.1  christos {
    663      1.1  christos   const struct block *expr_block;
    664      1.1  christos   CORE_ADDR trash_pc, expr_pc;
    665      1.6  christos   int ok;
    666      1.1  christos   struct gdbarch *gdbarch = get_current_arch ();
    667  1.7.2.1  perseant   std::string triplet_rx;
    668      1.1  christos 
    669      1.1  christos   if (!target_has_execution ())
    670      1.1  christos     error (_("The program must be running for the compile command to "\
    671      1.1  christos 	     "work."));
    672      1.1  christos 
    673      1.1  christos   expr_block = get_expr_block_and_pc (&trash_pc);
    674      1.1  christos   expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
    675  1.7.2.1  perseant 
    676  1.7.2.1  perseant   /* Set up instance and context for the compiler.  */
    677      1.7  christos   std::unique_ptr<compile_instance> compiler
    678      1.4  christos     = current_language->get_compile_instance ();
    679  1.7.2.1  perseant   if (compiler == nullptr)
    680      1.6  christos     error (_("No compiler support for language %s."),
    681      1.6  christos 	   current_language->name ());
    682      1.6  christos   compiler->set_print_callback (print_callback, NULL);
    683      1.1  christos   compiler->set_scope (scope);
    684      1.1  christos   compiler->set_block (expr_block);
    685      1.1  christos 
    686      1.5  christos   /* From the provided expression, build a scope to pass to the
    687      1.5  christos      compiler.  */
    688      1.5  christos 
    689      1.5  christos   string_file input_buf;
    690      1.1  christos   const char *input;
    691      1.1  christos 
    692      1.1  christos   if (cmd != NULL)
    693      1.1  christos     {
    694      1.6  christos       struct command_line *iter;
    695      1.1  christos 
    696      1.5  christos       for (iter = cmd->body_list_0.get (); iter; iter = iter->next)
    697      1.5  christos 	{
    698      1.1  christos 	  input_buf.puts (iter->line);
    699      1.1  christos 	  input_buf.puts ("\n");
    700      1.5  christos 	}
    701      1.1  christos 
    702      1.1  christos       input = input_buf.c_str ();
    703      1.3  christos     }
    704      1.1  christos   else if (cmd_string != NULL)
    705      1.1  christos     input = cmd_string;
    706      1.1  christos   else
    707      1.5  christos     error (_("Neither a simple expression, or a multi-line specified."));
    708      1.7  christos 
    709      1.7  christos   std::string code
    710      1.1  christos     = current_language->compute_program (compiler.get (), input, gdbarch,
    711  1.7.2.1  perseant 					 expr_block, expr_pc);
    712      1.1  christos   if (compile_debug)
    713      1.6  christos     gdb_printf (gdb_stdlog, "debug output:\n\n%s", code.c_str ());
    714      1.6  christos 
    715  1.7.2.1  perseant   compiler->set_verbose (compile_debug);
    716      1.6  christos 
    717      1.6  christos   if (!compile_gcc.empty ())
    718      1.6  christos     {
    719      1.6  christos       if (compiler->version () < GCC_FE_VERSION_1)
    720      1.6  christos 	error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
    721  1.7.2.1  perseant 		 "(libcc1 interface version 1 or higher)"));
    722      1.6  christos 
    723      1.6  christos       compiler->set_driver_filename (compile_gcc.c_str ());
    724      1.6  christos     }
    725      1.6  christos   else
    726      1.6  christos     {
    727      1.1  christos       const char *os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch));
    728      1.6  christos       const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
    729  1.7.2.1  perseant 
    730  1.7.2.1  perseant       /* Allow triplets with or without vendor set.  */
    731  1.7.2.1  perseant       triplet_rx = std::string (arch_rx) + "(-[^-]*)?-";
    732      1.6  christos       if (os_rx != nullptr)
    733      1.6  christos 	triplet_rx += os_rx;
    734      1.1  christos       compiler->set_triplet_regexp (triplet_rx.c_str ());
    735      1.1  christos     }
    736  1.7.2.1  perseant 
    737  1.7.2.1  perseant   /* Set compiler command-line arguments.  */
    738  1.7.2.1  perseant   gdb_argv argv_holder = get_args (compiler.get (), gdbarch);
    739      1.6  christos   int argc = argv_holder.count ();
    740  1.7.2.1  perseant   char **argv = argv_holder.get ();
    741  1.7.2.1  perseant 
    742      1.1  christos   gdb::unique_xmalloc_ptr<char> error_message
    743      1.1  christos     = compiler->set_arguments (argc, argv, triplet_rx.c_str ());
    744      1.6  christos 
    745      1.1  christos   if (error_message != NULL)
    746      1.1  christos     error ("%s", error_message.get ());
    747      1.1  christos 
    748      1.1  christos   if (compile_debug)
    749      1.1  christos     {
    750  1.7.2.1  perseant       int argi;
    751      1.1  christos 
    752  1.7.2.1  perseant       gdb_printf (gdb_stdlog, "Passing %d compiler options:\n", argc);
    753  1.7.2.1  perseant       for (argi = 0; argi < argc; argi++)
    754      1.1  christos 	gdb_printf (gdb_stdlog, "Compiler option %d: <%s>\n",
    755      1.1  christos 		    argi, argv[argi]);
    756      1.5  christos     }
    757      1.1  christos 
    758      1.6  christos   compile_file_names fnames = get_new_file_names ();
    759      1.6  christos 
    760      1.6  christos   gdb::optional<gdb::unlinker> source_remover;
    761      1.6  christos 
    762      1.6  christos   {
    763      1.6  christos     gdb_file_up src = gdb_fopen_cloexec (fnames.source_file (), "w");
    764      1.6  christos     if (src == NULL)
    765      1.6  christos       perror_with_name (_("Could not open source file for writing"));
    766      1.6  christos 
    767      1.6  christos     source_remover.emplace (fnames.source_file ());
    768      1.6  christos 
    769      1.6  christos     if (fputs (code.c_str (), src.get ()) == EOF)
    770      1.1  christos       perror_with_name (_("Could not write to source file"));
    771      1.1  christos   }
    772  1.7.2.1  perseant 
    773  1.7.2.1  perseant   if (compile_debug)
    774  1.7.2.1  perseant     gdb_printf (gdb_stdlog, "source file produced: %s\n\n",
    775  1.7.2.1  perseant 		fnames.source_file ());
    776  1.7.2.1  perseant 
    777  1.7.2.1  perseant   /* If we don't do this, then GDB simply exits
    778      1.1  christos      when the compiler dies.  */
    779      1.1  christos   scoped_ignore_sigpipe ignore_sigpipe;
    780      1.6  christos 
    781      1.6  christos   /* Call the compiler and start the compilation process.  */
    782      1.6  christos   compiler->set_source_file (fnames.source_file ());
    783      1.1  christos   ok = compiler->compile (fnames.object_file (), compile_debug);
    784      1.1  christos   if (!ok)
    785      1.1  christos     error (_("Compilation failed."));
    786  1.7.2.1  perseant 
    787  1.7.2.1  perseant   if (compile_debug)
    788      1.1  christos     gdb_printf (gdb_stdlog, "object file produced: %s\n\n",
    789      1.6  christos 		fnames.object_file ());
    790      1.6  christos 
    791      1.5  christos   /* Keep the source file.  */
    792      1.1  christos   source_remover->keep ();
    793      1.1  christos   return fnames;
    794      1.1  christos }
    795      1.1  christos 
    796      1.1  christos /* The "compile" prefix command.  */
    797      1.6  christos 
    798      1.1  christos static void
    799      1.1  christos compile_command (const char *args, int from_tty)
    800      1.1  christos {
    801      1.1  christos   /* If a sub-command is not specified to the compile prefix command,
    802      1.1  christos      assume it is a direct code compilation.  */
    803      1.1  christos   compile_code_command (args, from_tty);
    804      1.1  christos }
    805      1.1  christos 
    806      1.1  christos /* See compile.h.  */
    807      1.3  christos 
    808      1.3  christos void
    809      1.1  christos eval_compile_command (struct command_line *cmd, const char *cmd_string,
    810      1.5  christos 		      enum compile_i_scope_types scope, void *scope_data)
    811      1.1  christos {
    812      1.6  christos   compile_file_names fnames = compile_to_object (cmd, cmd_string, scope);
    813      1.6  christos 
    814      1.6  christos   gdb::unlinker object_remover (fnames.object_file ());
    815  1.7.2.1  perseant   gdb::unlinker source_remover (fnames.source_file ());
    816  1.7.2.1  perseant 
    817      1.5  christos   compile_module_up compile_module = compile_object_load (fnames, scope,
    818      1.5  christos 							  scope_data);
    819      1.5  christos   if (compile_module == NULL)
    820      1.5  christos     {
    821      1.5  christos       gdb_assert (scope == COMPILE_I_PRINT_ADDRESS_SCOPE);
    822      1.5  christos       eval_compile_command (cmd, cmd_string,
    823      1.1  christos 			    COMPILE_I_PRINT_VALUE_SCOPE, scope_data);
    824      1.6  christos       return;
    825      1.6  christos     }
    826      1.6  christos 
    827      1.6  christos   /* Keep the files.  */
    828      1.6  christos   source_remover.keep ();
    829  1.7.2.1  perseant   object_remover.keep ();
    830      1.1  christos 
    831      1.1  christos   compile_object_run (std::move (compile_module));
    832      1.1  christos }
    833      1.1  christos 
    834      1.6  christos /* See compile/compile-internal.h.  */
    835      1.1  christos 
    836      1.1  christos std::string
    837      1.1  christos compile_register_name_mangled (struct gdbarch *gdbarch, int regnum)
    838      1.1  christos {
    839      1.6  christos   const char *regname = gdbarch_register_name (gdbarch, regnum);
    840      1.1  christos 
    841      1.1  christos   return string_printf ("__%s", regname);
    842      1.1  christos }
    843      1.1  christos 
    844      1.1  christos /* See compile/compile-internal.h.  */
    845      1.1  christos 
    846      1.1  christos int
    847      1.1  christos compile_register_name_demangle (struct gdbarch *gdbarch,
    848      1.1  christos 				 const char *regname)
    849      1.1  christos {
    850      1.1  christos   int regnum;
    851      1.1  christos 
    852      1.1  christos   if (regname[0] != '_' || regname[1] != '_')
    853      1.1  christos     error (_("Invalid register name \"%s\"."), regname);
    854      1.1  christos   regname += 2;
    855      1.1  christos 
    856      1.1  christos   for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
    857      1.1  christos     if (strcmp (regname, gdbarch_register_name (gdbarch, regnum)) == 0)
    858      1.1  christos       return regnum;
    859      1.1  christos 
    860      1.1  christos   error (_("Cannot find gdbarch register \"%s\"."), regname);
    861      1.6  christos }
    862      1.6  christos 
    863      1.6  christos /* Forwards to the plug-in.  */
    864      1.6  christos 
    865      1.6  christos #define FORWARD(OP,...) (m_gcc_fe->ops->OP (m_gcc_fe, ##__VA_ARGS__))
    866      1.6  christos 
    867      1.6  christos /* See compile-internal.h.  */
    868      1.6  christos 
    869      1.6  christos void
    870      1.6  christos compile_instance::set_print_callback
    871      1.6  christos   (void (*print_function) (void *, const char *), void *datum)
    872      1.6  christos {
    873      1.6  christos   FORWARD (set_print_callback, print_function, datum);
    874      1.6  christos }
    875      1.6  christos 
    876      1.6  christos /* See compile-internal.h.  */
    877      1.6  christos 
    878      1.6  christos unsigned int
    879      1.6  christos compile_instance::version () const
    880      1.6  christos {
    881      1.6  christos   return m_gcc_fe->ops->version;
    882      1.6  christos }
    883      1.6  christos 
    884      1.6  christos /* See compile-internal.h.  */
    885      1.6  christos 
    886      1.6  christos void
    887      1.6  christos compile_instance::set_verbose (int level)
    888      1.6  christos {
    889      1.6  christos   if (version () >= GCC_FE_VERSION_1)
    890      1.6  christos     FORWARD (set_verbose, level);
    891      1.6  christos }
    892      1.6  christos 
    893      1.6  christos /* See compile-internal.h.  */
    894      1.6  christos 
    895      1.6  christos void
    896      1.6  christos compile_instance::set_driver_filename (const char *filename)
    897      1.6  christos {
    898      1.6  christos   if (version () >= GCC_FE_VERSION_1)
    899      1.6  christos     FORWARD (set_driver_filename, filename);
    900      1.6  christos }
    901      1.6  christos 
    902      1.6  christos /* See compile-internal.h.  */
    903      1.6  christos 
    904      1.6  christos void
    905      1.6  christos compile_instance::set_triplet_regexp (const char *regexp)
    906      1.6  christos {
    907      1.6  christos   if (version () >= GCC_FE_VERSION_1)
    908      1.6  christos     FORWARD (set_triplet_regexp, regexp);
    909      1.6  christos }
    910      1.6  christos 
    911  1.7.2.1  perseant /* See compile-internal.h.  */
    912      1.6  christos 
    913      1.6  christos gdb::unique_xmalloc_ptr<char>
    914      1.6  christos compile_instance::set_arguments (int argc, char **argv, const char *regexp)
    915  1.7.2.1  perseant {
    916      1.6  christos   if (version () >= GCC_FE_VERSION_1)
    917  1.7.2.1  perseant     return gdb::unique_xmalloc_ptr<char> (FORWARD (set_arguments, argc, argv));
    918  1.7.2.1  perseant   else
    919      1.6  christos     return gdb::unique_xmalloc_ptr<char> (FORWARD (set_arguments_v0, regexp,
    920      1.6  christos 						   argc, argv));
    921      1.6  christos }
    922      1.6  christos 
    923      1.6  christos /* See compile-internal.h.  */
    924      1.6  christos 
    925      1.6  christos void
    926      1.6  christos compile_instance::set_source_file (const char *filename)
    927      1.6  christos {
    928      1.6  christos   FORWARD (set_source_file, filename);
    929      1.6  christos }
    930      1.6  christos 
    931      1.6  christos /* See compile-internal.h.  */
    932      1.6  christos 
    933      1.6  christos bool
    934      1.6  christos compile_instance::compile (const char *filename, int verbose_level)
    935      1.6  christos {
    936      1.6  christos   if (version () >= GCC_FE_VERSION_1)
    937      1.6  christos     return FORWARD (compile, filename);
    938      1.6  christos   else
    939      1.6  christos     return FORWARD (compile_v0, filename, verbose_level);
    940      1.6  christos }
    941      1.6  christos 
    942      1.6  christos #undef FORWARD
    943      1.6  christos 
    944      1.1  christos /* See compile.h.  */
    945      1.7  christos cmd_list_element *compile_cmd_element = nullptr;
    946      1.1  christos 
    947      1.7  christos void _initialize_compile ();
    948      1.1  christos void
    949      1.1  christos _initialize_compile ()
    950      1.1  christos {
    951      1.6  christos   struct cmd_list_element *c = NULL;
    952      1.6  christos 
    953      1.1  christos   compile_cmd_element = add_prefix_cmd ("compile", class_obscure,
    954  1.7.2.1  perseant 					compile_command, _("\
    955  1.7.2.1  perseant Command to compile source code and inject it into the inferior."),
    956      1.1  christos 		  &compile_command_list, 1, &cmdlist);
    957      1.7  christos   add_com_alias ("expression", compile_cmd_element, class_obscure, 0);
    958      1.7  christos 
    959      1.7  christos   const auto compile_opts = make_compile_options_def_group (nullptr);
    960      1.7  christos 
    961      1.1  christos   static const std::string compile_code_help
    962      1.1  christos     = gdb::option::build_help (_("\
    963      1.7  christos Compile, inject, and execute code.\n\
    964      1.7  christos \n\
    965      1.7  christos Usage: compile code [OPTION]... [CODE]\n\
    966      1.7  christos \n\
    967      1.1  christos Options:\n\
    968      1.1  christos %OPTIONS%\n\
    969      1.1  christos \n\
    970      1.1  christos The source code may be specified as a simple one line expression, e.g.:\n\
    971      1.1  christos \n\
    972      1.3  christos     compile code printf(\"Hello world\\n\");\n\
    973      1.3  christos \n\
    974      1.3  christos Alternatively, you can type a multiline expression by invoking\n\
    975      1.3  christos this command with no argument.  GDB will then prompt for the\n\
    976      1.7  christos expression interactively; type a line containing \"end\" to\n\
    977      1.7  christos indicate the end of the expression."),
    978      1.7  christos 			       compile_opts);
    979      1.7  christos 
    980      1.7  christos   c = add_cmd ("code", class_obscure, compile_code_command,
    981      1.7  christos 	       compile_code_help.c_str (),
    982      1.1  christos 	       &compile_command_list);
    983      1.7  christos   set_cmd_completer_handle_brkchars (c, compile_code_command_completer);
    984      1.7  christos 
    985      1.1  christos static const std::string compile_file_help
    986      1.1  christos     = gdb::option::build_help (_("\
    987      1.7  christos Evaluate a file containing source code.\n\
    988      1.7  christos \n\
    989      1.7  christos Usage: compile file [OPTION].. [FILENAME]\n\
    990      1.7  christos \n\
    991      1.7  christos Options:\n\
    992      1.7  christos %OPTIONS%"),
    993      1.7  christos 			       compile_opts);
    994      1.7  christos 
    995      1.1  christos   c = add_cmd ("file", class_obscure, compile_file_command,
    996      1.7  christos 	       compile_file_help.c_str (),
    997      1.7  christos 	       &compile_command_list);
    998      1.7  christos   set_cmd_completer_handle_brkchars (c, compile_file_command_completer);
    999      1.1  christos 
   1000      1.7  christos   const auto compile_print_opts = make_value_print_options_def_group (nullptr);
   1001      1.7  christos 
   1002      1.3  christos   static const std::string compile_print_help
   1003      1.3  christos     = gdb::option::build_help (_("\
   1004      1.7  christos Evaluate EXPR by using the compiler and print result.\n\
   1005      1.7  christos \n\
   1006      1.7  christos Usage: compile print [[OPTION]... --] [/FMT] [EXPR]\n\
   1007      1.7  christos \n\
   1008      1.7  christos Options:\n\
   1009      1.7  christos %OPTIONS%\n\
   1010      1.7  christos \n\
   1011      1.7  christos Note: because this command accepts arbitrary expressions, if you\n\
   1012      1.3  christos specify any command option, you must use a double dash (\"--\")\n\
   1013      1.3  christos to mark the end of option processing.  E.g.: \"compile print -o -- myobj\".\n\
   1014      1.3  christos \n\
   1015      1.3  christos The expression may be specified on the same line as the command, e.g.:\n\
   1016      1.3  christos \n\
   1017      1.3  christos     compile print i\n\
   1018      1.3  christos \n\
   1019      1.3  christos Alternatively, you can type a multiline expression by invoking\n\
   1020      1.3  christos this command with no argument.  GDB will then prompt for the\n\
   1021      1.3  christos expression interactively; type a line containing \"end\" to\n\
   1022      1.3  christos indicate the end of the expression.\n\
   1023      1.3  christos \n\
   1024      1.7  christos EXPR may be preceded with /FMT, where FMT is a format letter\n\
   1025      1.7  christos but no count or size letter (see \"x\" command)."),
   1026      1.7  christos 			       compile_print_opts);
   1027      1.7  christos 
   1028      1.7  christos   c = add_cmd ("print", class_obscure, compile_print_command,
   1029      1.7  christos 	       compile_print_help.c_str (),
   1030      1.3  christos 	       &compile_command_list);
   1031      1.1  christos   set_cmd_completer_handle_brkchars (c, print_command_completer);
   1032      1.1  christos 
   1033      1.1  christos   add_setshow_boolean_cmd ("compile", class_maintenance, &compile_debug, _("\
   1034      1.1  christos Set compile command debugging."), _("\
   1035      1.1  christos Show compile command debugging."), _("\
   1036      1.1  christos When on, compile command debugging is enabled."),
   1037      1.1  christos 			   NULL, show_compile_debug,
   1038      1.1  christos 			   &setdebuglist, &showdebuglist);
   1039      1.1  christos 
   1040      1.7  christos   add_setshow_string_cmd ("compile-args", class_support,
   1041      1.7  christos 			  &compile_args,
   1042      1.1  christos 			  _("Set compile command GCC command-line arguments."),
   1043      1.1  christos 			  _("Show compile command GCC command-line arguments."),
   1044      1.1  christos 			  _("\
   1045      1.1  christos Use options like -I (include file directory) or ABI settings.\n\
   1046      1.1  christos String quoting is parsed like in shell, for example:\n\
   1047      1.1  christos   -mno-align-double \"-I/dir with a space/include\""),
   1048  1.7.2.1  perseant 			  set_compile_args, show_compile_args, &setlist, &showlist);
   1049  1.7.2.1  perseant 
   1050  1.7.2.1  perseant 
   1051      1.6  christos   /* Initialize compile_args_argv.  */
   1052      1.6  christos   set_compile_args (compile_args.c_str (), 0, NULL);
   1053      1.6  christos 
   1054      1.6  christos   add_setshow_optional_filename_cmd ("compile-gcc", class_support,
   1055      1.7  christos 				     &compile_gcc,
   1056      1.6  christos 				     _("Set compile command "
   1057      1.7  christos 				       "GCC driver filename."),
   1058      1.6  christos 				     _("Show compile command "
   1059      1.6  christos 				       "GCC driver filename."),
   1060      1.6  christos 				     _("\
   1061      1.6  christos It should be absolute filename of the gcc executable.\n\
   1062      1.6  christos If empty the default target triplet will be searched in $PATH."),
   1063      1.1  christos 				     NULL, show_compile_gcc, &setlist,
   1064                    				     &showlist);
   1065                    }
   1066