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