Remove ptid_get_pid
[binutils-gdb.git] / gdb / compile / compile.c
1 /* General Compile and inject code
2
3 Copyright (C) 2014-2018 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 "top.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 #include "common/gdb_optional.h"
43 #include "common/gdb_unlinker.h"
44 #include "common/pathstuff.h"
45
46 \f
47
48 /* Initial filename for temporary files. */
49
50 #define TMP_PREFIX "/tmp/gdbobj-"
51
52 /* Hold "compile" commands. */
53
54 static struct cmd_list_element *compile_command_list;
55
56 /* Debug flag for "compile" commands. */
57
58 int compile_debug;
59
60 /* Implement "show debug compile". */
61
62 static void
63 show_compile_debug (struct ui_file *file, int from_tty,
64 struct cmd_list_element *c, const char *value)
65 {
66 fprintf_filtered (file, _("Compile debugging is %s.\n"), value);
67 }
68
69 \f
70
71 /* Check *ARG for a "-raw" or "-r" argument. Return 0 if not seen.
72 Return 1 if seen and update *ARG. */
73
74 static int
75 check_raw_argument (const char **arg)
76 {
77 *arg = skip_spaces (*arg);
78
79 if (arg != NULL
80 && (check_for_argument (arg, "-raw", sizeof ("-raw") - 1)
81 || check_for_argument (arg, "-r", sizeof ("-r") - 1)))
82 return 1;
83 return 0;
84 }
85
86 /* Handle the input from the 'compile file' command. The "compile
87 file" command is used to evaluate an expression contained in a file
88 that may contain calls to the GCC compiler. */
89
90 static void
91 compile_file_command (const char *arg, int from_tty)
92 {
93 enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
94
95 scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
96
97 /* Check the user did not just <enter> after command. */
98 if (arg == NULL)
99 error (_("You must provide a filename for this command."));
100
101 /* Check if a raw (-r|-raw) argument is provided. */
102 if (arg != NULL && check_raw_argument (&arg))
103 {
104 scope = COMPILE_I_RAW_SCOPE;
105 arg = skip_spaces (arg);
106 }
107
108 /* After processing arguments, check there is a filename at the end
109 of the command. */
110 if (arg[0] == '\0')
111 error (_("You must provide a filename with the raw option set."));
112
113 if (arg[0] == '-')
114 error (_("Unknown argument specified."));
115
116 arg = skip_spaces (arg);
117 gdb::unique_xmalloc_ptr<char> abspath = gdb_abspath (arg);
118 std::string buffer = string_printf ("#include \"%s\"\n", abspath.get ());
119 eval_compile_command (NULL, buffer.c_str (), scope, NULL);
120 }
121
122 /* Handle the input from the 'compile code' command. The
123 "compile code" command is used to evaluate an expression that may
124 contain calls to the GCC compiler. The language expected in this
125 compile command is the language currently set in GDB. */
126
127 static void
128 compile_code_command (const char *arg, int from_tty)
129 {
130 enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
131
132 scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
133
134 if (arg != NULL && check_raw_argument (&arg))
135 {
136 scope = COMPILE_I_RAW_SCOPE;
137 arg = skip_spaces (arg);
138 }
139
140 arg = skip_spaces (arg);
141
142 if (arg != NULL && !check_for_argument (&arg, "--", sizeof ("--") - 1))
143 {
144 if (arg[0] == '-')
145 error (_("Unknown argument specified."));
146 }
147
148 if (arg && *arg)
149 eval_compile_command (NULL, arg, scope, NULL);
150 else
151 {
152 counted_command_line l = get_command_line (compile_control, "");
153
154 l->control_u.compile.scope = scope;
155 execute_control_command_untraced (l.get ());
156 }
157 }
158
159 /* Callback for compile_print_command. */
160
161 void
162 compile_print_value (struct value *val, void *data_voidp)
163 {
164 const struct format_data *fmtp = (const struct format_data *) data_voidp;
165
166 print_value (val, fmtp);
167 }
168
169 /* Handle the input from the 'compile print' command. The "compile
170 print" command is used to evaluate and print an expression that may
171 contain calls to the GCC compiler. The language expected in this
172 compile command is the language currently set in GDB. */
173
174 static void
175 compile_print_command (const char *arg, int from_tty)
176 {
177 enum compile_i_scope_types scope = COMPILE_I_PRINT_ADDRESS_SCOPE;
178 struct format_data fmt;
179
180 scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
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 {
190 counted_command_line l = get_command_line (compile_control, "");
191
192 l->control_u.compile.scope = scope;
193 l->control_u.compile.scope_data = &fmt;
194 execute_control_command_untraced (l.get ());
195 }
196 }
197
198 /* A cleanup function to remove a directory and all its contents. */
199
200 static void
201 do_rmdir (void *arg)
202 {
203 const char *dir = (const char *) arg;
204 char *zap;
205 int wstat;
206
207 gdb_assert (startswith (dir, TMP_PREFIX));
208 zap = concat ("rm -rf ", dir, (char *) NULL);
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);
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
218 static const char *
219 get_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
231 #ifdef HAVE_MKDTEMP
232 tempdir_name = mkdtemp (tname);
233 #else
234 error (_("Command not supported on this host."));
235 #endif
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
244 /* Compute the names of source and object files to use. */
245
246 static compile_file_names
247 get_new_file_names ()
248 {
249 static int seq;
250 const char *dir = get_compile_file_tempdir ();
251
252 ++seq;
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));
258 }
259
260 /* Get the block and PC at which to evaluate an expression. */
261
262 static const struct block *
263 get_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
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. */
286
287 static void
288 build_argc_argv (const char *s, int *argcp, char ***argvp)
289 {
290 gdb_argv args (s);
291
292 *argcp = args.count ();
293 *argvp = args.release ();
294 }
295
296 /* String for 'set compile-args' and 'show compile-args'. */
297 static char *compile_args;
298
299 /* Parsed form of COMPILE_ARGS. COMPILE_ARGS_ARGV is NULL terminated. */
300 static int compile_args_argc;
301 static char **compile_args_argv;
302
303 /* Implement 'set compile-args'. */
304
305 static void
306 set_compile_args (const 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
314 static void
315 show_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
326 static void
327 append_args (int *argcp, char ***argvp, int argc, char **argv)
328 {
329 int argi;
330
331 *argvp = XRESIZEVEC (char *, *argvp, (*argcp + argc + 1));
332
333 for (argi = 0; argi < argc; argi++)
334 (*argvp)[(*argcp)++] = xstrdup (argv[argi]);
335 (*argvp)[(*argcp)] = NULL;
336 }
337
338 /* String for 'set compile-gcc' and 'show compile-gcc'. */
339 static char *compile_gcc;
340
341 /* Implement 'show compile-gcc'. */
342
343 static void
344 show_compile_gcc (struct ui_file *file, int from_tty,
345 struct cmd_list_element *c, const char *value)
346 {
347 fprintf_filtered (file, _("Compile command GCC driver filename is \"%s\".\n"),
348 value);
349 }
350
351 /* Return DW_AT_producer parsed for get_selected_frame () (if any).
352 Return NULL otherwise.
353
354 GCC already filters its command-line arguments only for the suitable ones to
355 put into DW_AT_producer - see GCC function gen_producer_string. */
356
357 static const char *
358 get_selected_pc_producer_options (void)
359 {
360 CORE_ADDR pc = get_frame_pc (get_selected_frame (NULL));
361 struct compunit_symtab *symtab = find_pc_compunit_symtab (pc);
362 const char *cs;
363
364 if (symtab == NULL || symtab->producer == NULL
365 || !startswith (symtab->producer, "GNU "))
366 return NULL;
367
368 cs = symtab->producer;
369 while (*cs != 0 && *cs != '-')
370 cs = skip_spaces (skip_to_space (cs));
371 if (*cs != '-')
372 return NULL;
373 return cs;
374 }
375
376 /* Filter out unwanted options from *ARGCP and ARGV. */
377
378 static void
379 filter_args (int *argcp, char **argv)
380 {
381 char **destv;
382
383 for (destv = argv; *argv != NULL; argv++)
384 {
385 /* -fpreprocessed may get in commonly from ccache. */
386 if (strcmp (*argv, "-fpreprocessed") == 0)
387 {
388 xfree (*argv);
389 (*argcp)--;
390 continue;
391 }
392 *destv++ = *argv;
393 }
394 *destv = NULL;
395 }
396
397 /* Produce final vector of GCC compilation options.
398
399 The first element of the combined argument vector are arguments
400 relating to the target size ("-m64", "-m32" etc.). These are
401 sourced from the inferior's architecture.
402
403 The second element of the combined argument vector are arguments
404 stored in the inferior DW_AT_producer section. If these are stored
405 in the inferior (there is no guarantee that they are), they are
406 added to the vector.
407
408 The third element of the combined argument vector are argument
409 supplied by the language implementation provided by
410 compile-{lang}-support. These contain language specific arguments.
411
412 The final element of the combined argument vector are arguments
413 supplied by the "set compile-args" command. These are always
414 appended last so as to override any of the arguments automatically
415 generated above. */
416
417 static void
418 get_args (const struct compile_instance *compiler, struct gdbarch *gdbarch,
419 int *argcp, char ***argvp)
420 {
421 const char *cs_producer_options;
422 int argc_compiler;
423 char **argv_compiler;
424
425 build_argc_argv (gdbarch_gcc_target_options (gdbarch),
426 argcp, argvp);
427
428 cs_producer_options = get_selected_pc_producer_options ();
429 if (cs_producer_options != NULL)
430 {
431 int argc_producer;
432 char **argv_producer;
433
434 build_argc_argv (cs_producer_options, &argc_producer, &argv_producer);
435 filter_args (&argc_producer, argv_producer);
436 append_args (argcp, argvp, argc_producer, argv_producer);
437 freeargv (argv_producer);
438 }
439
440 build_argc_argv (compiler->gcc_target_options,
441 &argc_compiler, &argv_compiler);
442 append_args (argcp, argvp, argc_compiler, argv_compiler);
443 freeargv (argv_compiler);
444
445 append_args (argcp, argvp, compile_args_argc, compile_args_argv);
446 }
447
448 /* A cleanup function to destroy a gdb_gcc_instance. */
449
450 static void
451 cleanup_compile_instance (void *arg)
452 {
453 struct compile_instance *inst = (struct compile_instance *) arg;
454
455 inst->destroy (inst);
456 }
457
458 /* A helper function suitable for use as the "print_callback" in the
459 compiler object. */
460
461 static void
462 print_callback (void *ignore, const char *message)
463 {
464 fputs_filtered (message, gdb_stderr);
465 }
466
467 /* Process the compilation request. On success it returns the object
468 and source file names. On an error condition, error () is
469 called. */
470
471 static compile_file_names
472 compile_to_object (struct command_line *cmd, const char *cmd_string,
473 enum compile_i_scope_types scope)
474 {
475 struct compile_instance *compiler;
476 struct cleanup *cleanup;
477 const struct block *expr_block;
478 CORE_ADDR trash_pc, expr_pc;
479 int argc;
480 char **argv;
481 int ok;
482 struct gdbarch *gdbarch = get_current_arch ();
483 std::string triplet_rx;
484 char *error_message;
485
486 if (!target_has_execution)
487 error (_("The program must be running for the compile command to "\
488 "work."));
489
490 expr_block = get_expr_block_and_pc (&trash_pc);
491 expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
492
493 /* Set up instance and context for the compiler. */
494 if (current_language->la_get_compile_instance == NULL)
495 error (_("No compiler support for language %s."),
496 current_language->la_name);
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
508 string_file input_buf;
509 const char *input;
510
511 if (cmd != NULL)
512 {
513 struct command_line *iter;
514
515 for (iter = cmd->body_list_0.get (); iter; iter = iter->next)
516 {
517 input_buf.puts (iter->line);
518 input_buf.puts ("\n");
519 }
520
521 input = input_buf.c_str ();
522 }
523 else if (cmd_string != NULL)
524 input = cmd_string;
525 else
526 error (_("Neither a simple expression, or a multi-line specified."));
527
528 std::string code
529 = current_language->la_compute_program (compiler, input, gdbarch,
530 expr_block, expr_pc);
531 if (compile_debug)
532 fprintf_unfiltered (gdb_stdlog, "debug output:\n\n%s", code.c_str ());
533
534 if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
535 compiler->fe->ops->set_verbose (compiler->fe, compile_debug);
536
537 if (compile_gcc[0] != 0)
538 {
539 if (compiler->fe->ops->version < GCC_FE_VERSION_1)
540 error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
541 "(libcc1 interface version 1 or higher)"));
542
543 compiler->fe->ops->set_driver_filename (compiler->fe, compile_gcc);
544 }
545 else
546 {
547 const char *os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch));
548 const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
549
550 /* Allow triplets with or without vendor set. */
551 triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx;
552
553 if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
554 compiler->fe->ops->set_triplet_regexp (compiler->fe,
555 triplet_rx.c_str ());
556 }
557
558 /* Set compiler command-line arguments. */
559 get_args (compiler, gdbarch, &argc, &argv);
560 gdb_argv argv_holder (argv);
561
562 if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
563 error_message = compiler->fe->ops->set_arguments (compiler->fe, argc, argv);
564 else
565 error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe,
566 triplet_rx.c_str (),
567 argc, argv);
568 if (error_message != NULL)
569 {
570 make_cleanup (xfree, error_message);
571 error ("%s", error_message);
572 }
573
574 if (compile_debug)
575 {
576 int argi;
577
578 fprintf_unfiltered (gdb_stdlog, "Passing %d compiler options:\n", argc);
579 for (argi = 0; argi < argc; argi++)
580 fprintf_unfiltered (gdb_stdlog, "Compiler option %d: <%s>\n",
581 argi, argv[argi]);
582 }
583
584 compile_file_names fnames = get_new_file_names ();
585
586 gdb::optional<gdb::unlinker> source_remover;
587
588 {
589 gdb_file_up src = gdb_fopen_cloexec (fnames.source_file (), "w");
590 if (src == NULL)
591 perror_with_name (_("Could not open source file for writing"));
592
593 source_remover.emplace (fnames.source_file ());
594
595 if (fputs (code.c_str (), src.get ()) == EOF)
596 perror_with_name (_("Could not write to source file"));
597 }
598
599 if (compile_debug)
600 fprintf_unfiltered (gdb_stdlog, "source file produced: %s\n\n",
601 fnames.source_file ());
602
603 /* Call the compiler and start the compilation process. */
604 compiler->fe->ops->set_source_file (compiler->fe, fnames.source_file ());
605
606 if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
607 ok = compiler->fe->ops->compile (compiler->fe, fnames.object_file ());
608 else
609 ok = compiler->fe->ops->compile_v0 (compiler->fe, fnames.object_file (),
610 compile_debug);
611 if (!ok)
612 error (_("Compilation failed."));
613
614 if (compile_debug)
615 fprintf_unfiltered (gdb_stdlog, "object file produced: %s\n\n",
616 fnames.object_file ());
617
618 /* Keep the source file. */
619 source_remover->keep ();
620
621 do_cleanups (cleanup);
622
623 return fnames;
624 }
625
626 /* The "compile" prefix command. */
627
628 static void
629 compile_command (const char *args, int from_tty)
630 {
631 /* If a sub-command is not specified to the compile prefix command,
632 assume it is a direct code compilation. */
633 compile_code_command (args, from_tty);
634 }
635
636 /* See compile.h. */
637
638 void
639 eval_compile_command (struct command_line *cmd, const char *cmd_string,
640 enum compile_i_scope_types scope, void *scope_data)
641 {
642 struct compile_module *compile_module;
643
644 compile_file_names fnames = compile_to_object (cmd, cmd_string, scope);
645
646 gdb::unlinker object_remover (fnames.object_file ());
647 gdb::unlinker source_remover (fnames.source_file ());
648
649 compile_module = compile_object_load (fnames, scope, scope_data);
650 if (compile_module == NULL)
651 {
652 gdb_assert (scope == COMPILE_I_PRINT_ADDRESS_SCOPE);
653 eval_compile_command (cmd, cmd_string,
654 COMPILE_I_PRINT_VALUE_SCOPE, scope_data);
655 return;
656 }
657
658 /* Keep the files. */
659 source_remover.keep ();
660 object_remover.keep ();
661
662 compile_object_run (compile_module);
663 }
664
665 /* See compile/compile-internal.h. */
666
667 std::string
668 compile_register_name_mangled (struct gdbarch *gdbarch, int regnum)
669 {
670 const char *regname = gdbarch_register_name (gdbarch, regnum);
671
672 return string_printf ("__%s", regname);
673 }
674
675 /* See compile/compile-internal.h. */
676
677 int
678 compile_register_name_demangle (struct gdbarch *gdbarch,
679 const char *regname)
680 {
681 int regnum;
682
683 if (regname[0] != '_' || regname[1] != '_')
684 error (_("Invalid register name \"%s\"."), regname);
685 regname += 2;
686
687 for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
688 if (strcmp (regname, gdbarch_register_name (gdbarch, regnum)) == 0)
689 return regnum;
690
691 error (_("Cannot find gdbarch register \"%s\"."), regname);
692 }
693
694 void
695 _initialize_compile (void)
696 {
697 struct cmd_list_element *c = NULL;
698
699 add_prefix_cmd ("compile", class_obscure, compile_command,
700 _("\
701 Command to compile source code and inject it into the inferior."),
702 &compile_command_list, "compile ", 1, &cmdlist);
703 add_com_alias ("expression", "compile", class_obscure, 0);
704
705 add_cmd ("code", class_obscure, compile_code_command,
706 _("\
707 Compile, inject, and execute code.\n\
708 \n\
709 Usage: compile code [-r|-raw] [--] [CODE]\n\
710 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping.\n\
711 --: Do not parse any options beyond this delimiter. All text to the\n\
712 right will be treated as source code.\n\
713 \n\
714 The source code may be specified as a simple one line expression, e.g.:\n\
715 \n\
716 compile code printf(\"Hello world\\n\");\n\
717 \n\
718 Alternatively, you can type a multiline expression by invoking\n\
719 this command with no argument. GDB will then prompt for the\n\
720 expression interactively; type a line containing \"end\" to\n\
721 indicate the end of the expression."),
722 &compile_command_list);
723
724 c = add_cmd ("file", class_obscure, compile_file_command,
725 _("\
726 Evaluate a file containing source code.\n\
727 \n\
728 Usage: compile file [-r|-raw] [filename]\n\
729 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping."),
730 &compile_command_list);
731 set_cmd_completer (c, filename_completer);
732
733 add_cmd ("print", class_obscure, compile_print_command,
734 _("\
735 Evaluate EXPR by using the compiler and print result.\n\
736 \n\
737 Usage: compile print[/FMT] [EXPR]\n\
738 \n\
739 The expression may be specified on the same line as the command, e.g.:\n\
740 \n\
741 compile print i\n\
742 \n\
743 Alternatively, you can type a multiline expression by invoking\n\
744 this command with no argument. GDB will then prompt for the\n\
745 expression interactively; type a line containing \"end\" to\n\
746 indicate the end of the expression.\n\
747 \n\
748 EXPR may be preceded with /FMT, where FMT is a format letter\n\
749 but no count or size letter (see \"x\" command)."),
750 &compile_command_list);
751
752 add_setshow_boolean_cmd ("compile", class_maintenance, &compile_debug, _("\
753 Set compile command debugging."), _("\
754 Show compile command debugging."), _("\
755 When on, compile command debugging is enabled."),
756 NULL, show_compile_debug,
757 &setdebuglist, &showdebuglist);
758
759 add_setshow_string_cmd ("compile-args", class_support,
760 &compile_args,
761 _("Set compile command GCC command-line arguments"),
762 _("Show compile command GCC command-line arguments"),
763 _("\
764 Use options like -I (include file directory) or ABI settings.\n\
765 String quoting is parsed like in shell, for example:\n\
766 -mno-align-double \"-I/dir with a space/include\""),
767 set_compile_args, show_compile_args, &setlist, &showlist);
768
769 /* Override flags possibly coming from DW_AT_producer. */
770 compile_args = xstrdup ("-O0 -gdwarf-4"
771 /* We use -fPIE Otherwise GDB would need to reserve space large enough for
772 any object file in the inferior in advance to get the final address when
773 to link the object file to and additionally the default system linker
774 script would need to be modified so that one can specify there the
775 absolute target address.
776 -fPIC is not used at is would require from GDB to generate .got. */
777 " -fPIE"
778 /* We want warnings, except for some commonly happening for GDB commands. */
779 " -Wall "
780 " -Wno-implicit-function-declaration"
781 " -Wno-unused-but-set-variable"
782 " -Wno-unused-variable"
783 /* Override CU's possible -fstack-protector-strong. */
784 " -fno-stack-protector"
785 );
786 set_compile_args (compile_args, 0, NULL);
787
788 add_setshow_optional_filename_cmd ("compile-gcc", class_support,
789 &compile_gcc,
790 _("Set compile command "
791 "GCC driver filename"),
792 _("Show compile command "
793 "GCC driver filename"),
794 _("\
795 It should be absolute filename of the gcc executable.\n\
796 If empty the default target triplet will be searched in $PATH."),
797 NULL, show_compile_gcc, &setlist,
798 &showlist);
799 compile_gcc = xstrdup ("");
800 }