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