GDB (xrefs)
compile.c
Go to the documentation of this file.
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 
45 
46 
47 /* Initial filename for temporary files. */
48 
49 #define TMP_PREFIX "/tmp/gdbobj-"
50 
51 /* Hold "compile" commands. */
52 
54 
55 /* Debug flag for "compile" commands. */
56 
58 
59 /* Implement "show debug compile". */
60 
61 static void
62 show_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 
69 
70 /* Check *ARG for a "-raw" or "-r" argument. Return 0 if not seen.
71  Return 1 if seen and update *ARG. */
72 
73 static int
74 check_raw_argument (const char **arg)
75 {
76  *arg = skip_spaces (*arg);
77 
78  if (arg != NULL
79  && (check_for_argument (arg, "-raw", sizeof ("-raw") - 1)
80  || check_for_argument (arg, "-r", sizeof ("-r") - 1)))
81  return 1;
82  return 0;
83 }
84 
85 /* Handle the input from the 'compile file' command. The "compile
86  file" command is used to evaluate an expression contained in a file
87  that may contain calls to the GCC compiler. */
88 
89 static void
90 compile_file_command (const char *arg, int from_tty)
91 {
93 
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);
117  std::string buffer = string_printf ("#include \"%s\"\n", abspath.get ());
118  eval_compile_command (NULL, buffer.c_str (), scope, NULL);
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 
126 static void
127 compile_code_command (const char *arg, int from_tty)
128 {
130 
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)
148  eval_compile_command (NULL, arg, scope, NULL);
149  else
150  {
152 
153  l->control_u.compile.scope = scope;
155  }
156 }
157 
158 /* Callback for compile_print_command. */
159 
160 void
161 compile_print_value (struct value *val, void *data_voidp)
162 {
163  const struct format_data *fmtp = (const struct format_data *) data_voidp;
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 
173 static void
174 compile_print_command (const char *arg, int from_tty)
175 {
177  struct format_data fmt;
178 
180 
181  /* Passing &FMT as SCOPE_DATA is safe as do_module_cleanup will not
182  touch the stale pointer if compile_object_run has already quit. */
183  print_command_parse_format (&arg, "compile print", &fmt);
184 
185  if (arg && *arg)
186  eval_compile_command (NULL, arg, scope, &fmt);
187  else
188  {
190 
191  l->control_u.compile.scope = scope;
192  l->control_u.compile.scope_data = &fmt;
194  }
195 }
196 
197 /* A cleanup function to remove a directory and all its contents. */
198 
199 static void
200 do_rmdir (void *arg)
201 {
202  const char *dir = (const char *) arg;
203  char *zap;
204  int wstat;
205 
207  zap = concat ("rm -rf ", dir, (char *) NULL);
208  wstat = system (zap);
209  if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
210  warning (_("Could not remove temporary directory %s"), dir);
211  XDELETEVEC (zap);
212 }
213 
214 /* Return the name of the temporary directory to use for .o files, and
215  arrange for the directory to be removed at shutdown. */
216 
217 static const char *
219 {
220  static char *tempdir_name;
221 
222 #define TEMPLATE TMP_PREFIX "XXXXXX"
223  char tname[sizeof (TEMPLATE)];
224 
225  if (tempdir_name != NULL)
226  return tempdir_name;
227 
228  strcpy (tname, TEMPLATE);
229 #undef TEMPLATE
230 #ifdef HAVE_MKDTEMP
231  tempdir_name = mkdtemp (tname);
232 #else
233  error (_("Command not supported on this host."));
234 #endif
235  if (tempdir_name == NULL)
236  perror_with_name (_("Could not make temporary directory"));
237 
238  tempdir_name = xstrdup (tempdir_name);
239  make_final_cleanup (do_rmdir, tempdir_name);
240  return tempdir_name;
241 }
242 
243 /* Compute the names of source and object files to use. */
244 
245 static compile_file_names
247 {
248  static int seq;
249  const char *dir = get_compile_file_tempdir ();
250 
251  ++seq;
252 
253  return compile_file_names (string_printf ("%s%sout%d.c",
254  dir, SLASH_STRING, seq),
255  string_printf ("%s%sout%d.o",
256  dir, SLASH_STRING, seq));
257 }
258 
259 /* Get the block and PC at which to evaluate an expression. */
260 
261 static const struct block *
263 {
264  const struct block *block = get_selected_block (pc);
265 
266  if (block == NULL)
267  {
269 
270  if (cursal.symtab)
272  STATIC_BLOCK);
273  if (block != NULL)
274  *pc = BLOCK_START (block);
275  }
276  else
277  *pc = BLOCK_START (block);
278 
279  return block;
280 }
281 
282 /* Call buildargv (via gdb_argv), set its result for S into *ARGVP but
283  calculate also the number of parsed arguments into *ARGCP. If
284  buildargv has returned NULL then *ARGCP is set to zero. */
285 
286 static void
287 build_argc_argv (const char *s, int *argcp, char ***argvp)
288 {
289  gdb_argv args (s);
290 
291  *argcp = args.count ();
292  *argvp = args.release ();
293 }
294 
295 /* String for 'set compile-args' and 'show compile-args'. */
296 static char *compile_args;
297 
298 /* Parsed form of COMPILE_ARGS. COMPILE_ARGS_ARGV is NULL terminated. */
299 static int compile_args_argc;
300 static char **compile_args_argv;
301 
302 /* Implement 'set compile-args'. */
303 
304 static void
305 set_compile_args (const char *args, int from_tty, struct cmd_list_element *c)
306 {
307  freeargv (compile_args_argv);
309 }
310 
311 /* Implement 'show compile-args'. */
312 
313 static void
314 show_compile_args (struct ui_file *file, int from_tty,
315  struct cmd_list_element *c, const char *value)
316 {
317  fprintf_filtered (file, _("Compile command command-line arguments "
318  "are \"%s\".\n"),
319  value);
320 }
321 
322 /* Append ARGC and ARGV (as parsed by build_argc_argv) to *ARGCP and *ARGVP.
323  ARGCP+ARGVP can be zero+NULL and also ARGC+ARGV can be zero+NULL. */
324 
325 static void
326 append_args (int *argcp, char ***argvp, int argc, char **argv)
327 {
328  int argi;
329 
330  *argvp = XRESIZEVEC (char *, *argvp, (*argcp + argc + 1));
331 
332  for (argi = 0; argi < argc; argi++)
333  (*argvp)[(*argcp)++] = xstrdup (argv[argi]);
334  (*argvp)[(*argcp)] = NULL;
335 }
336 
337 /* String for 'set compile-gcc' and 'show compile-gcc'. */
338 static char *compile_gcc;
339 
340 /* Implement 'show compile-gcc'. */
341 
342 static void
343 show_compile_gcc (struct ui_file *file, int from_tty,
344  struct cmd_list_element *c, const char *value)
345 {
346  fprintf_filtered (file, _("Compile command GCC driver filename is \"%s\".\n"),
347  value);
348 }
349 
350 /* Return DW_AT_producer parsed for get_selected_frame () (if any).
351  Return NULL otherwise.
352 
353  GCC already filters its command-line arguments only for the suitable ones to
354  put into DW_AT_producer - see GCC function gen_producer_string. */
355 
356 static const char *
358 {
361  const char *cs;
362 
363  if (symtab == NULL || symtab->producer == NULL
364  || !startswith (symtab->producer, "GNU "))
365  return NULL;
366 
367  cs = symtab->producer;
368  while (*cs != 0 && *cs != '-')
369  cs = skip_spaces (skip_to_space (cs));
370  if (*cs != '-')
371  return NULL;
372  return cs;
373 }
374 
375 /* Filter out unwanted options from *ARGCP and ARGV. */
376 
377 static void
378 filter_args (int *argcp, char **argv)
379 {
380  char **destv;
381 
382  for (destv = argv; *argv != NULL; argv++)
383  {
384  /* -fpreprocessed may get in commonly from ccache. */
385  if (strcmp (*argv, "-fpreprocessed") == 0)
386  {
387  xfree (*argv);
388  (*argcp)--;
389  continue;
390  }
391  *destv++ = *argv;
392  }
393  *destv = NULL;
394 }
395 
396 /* Produce final vector of GCC compilation options. First element is target
397  size ("-m64", "-m32" etc.), optionally followed by DW_AT_producer options
398  and then compile-args string GDB variable. */
399 
400 static void
401 get_args (const struct compile_instance *compiler, struct gdbarch *gdbarch,
402  int *argcp, char ***argvp)
403 {
404  const char *cs_producer_options;
405  int argc_compiler;
406  char **argv_compiler;
407 
409  argcp, argvp);
410 
411  cs_producer_options = get_selected_pc_producer_options ();
412  if (cs_producer_options != NULL)
413  {
414  int argc_producer;
415  char **argv_producer;
416 
417  build_argc_argv (cs_producer_options, &argc_producer, &argv_producer);
418  filter_args (&argc_producer, argv_producer);
419  append_args (argcp, argvp, argc_producer, argv_producer);
420  freeargv (argv_producer);
421  }
422 
424  &argc_compiler, &argv_compiler);
425  append_args (argcp, argvp, argc_compiler, argv_compiler);
426  freeargv (argv_compiler);
427 
429 }
430 
431 /* A cleanup function to destroy a gdb_gcc_instance. */
432 
433 static void
435 {
436  struct compile_instance *inst = (struct compile_instance *) arg;
437 
438  inst->destroy (inst);
439 }
440 
441 /* A helper function suitable for use as the "print_callback" in the
442  compiler object. */
443 
444 static void
445 print_callback (void *ignore, const char *message)
446 {
447  fputs_filtered (message, gdb_stderr);
448 }
449 
450 /* Process the compilation request. On success it returns the object
451  and source file names. On an error condition, error () is
452  called. */
453 
454 static compile_file_names
455 compile_to_object (struct command_line *cmd, const char *cmd_string,
457 {
458  struct compile_instance *compiler;
459  struct cleanup *cleanup;
460  const struct block *expr_block;
461  CORE_ADDR trash_pc, expr_pc;
462  int argc;
463  char **argv;
464  int ok;
465  struct gdbarch *gdbarch = get_current_arch ();
466  std::string triplet_rx;
467  char *error_message;
468 
470  error (_("The program must be running for the compile command to "\
471  "work."));
472 
473  expr_block = get_expr_block_and_pc (&trash_pc);
475 
476  /* Set up instance and context for the compiler. */
478  error (_("No compiler support for language %s."),
482 
483  compiler->fe->ops->set_print_callback (compiler->fe, print_callback, NULL);
484 
485  compiler->scope = scope;
486  compiler->block = expr_block;
487 
488  /* From the provided expression, build a scope to pass to the
489  compiler. */
490 
491  string_file input_buf;
492  const char *input;
493 
494  if (cmd != NULL)
495  {
496  struct command_line *iter;
497 
498  for (iter = cmd->body_list[0]; iter; iter = iter->next)
499  {
500  input_buf.puts (iter->line);
501  input_buf.puts ("\n");
502  }
503 
504  input = input_buf.c_str ();
505  }
506  else if (cmd_string != NULL)
507  input = cmd_string;
508  else
509  error (_("Neither a simple expression, or a multi-line specified."));
510 
512  = current_language->la_compute_program (compiler, input, gdbarch,
513  expr_block, expr_pc);
514  if (compile_debug)
515  fprintf_unfiltered (gdb_stdlog, "debug output:\n\n%s", code.c_str ());
516 
517  if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
518  compiler->fe->ops->set_verbose (compiler->fe, compile_debug);
519 
520  if (compile_gcc[0] != 0)
521  {
522  if (compiler->fe->ops->version < GCC_FE_VERSION_1)
523  error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
524  "(libcc1 interface version 1 or higher)"));
525 
526  compiler->fe->ops->set_driver_filename (compiler->fe, compile_gcc);
527  }
528  else
529  {
530  const char *os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch));
531  const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
532 
533  /* Allow triplets with or without vendor set. */
534  triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx;
535 
536  if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
537  compiler->fe->ops->set_triplet_regexp (compiler->fe,
538  triplet_rx.c_str ());
539  }
540 
541  /* Set compiler command-line arguments. */
542  get_args (compiler, gdbarch, &argc, &argv);
543  gdb_argv argv_holder (argv);
544 
545  if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
546  error_message = compiler->fe->ops->set_arguments (compiler->fe, argc, argv);
547  else
548  error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe,
549  triplet_rx.c_str (),
550  argc, argv);
551  if (error_message != NULL)
552  {
553  make_cleanup (xfree, error_message);
554  error ("%s", error_message);
555  }
556 
557  if (compile_debug)
558  {
559  int argi;
560 
561  fprintf_unfiltered (gdb_stdlog, "Passing %d compiler options:\n", argc);
562  for (argi = 0; argi < argc; argi++)
563  fprintf_unfiltered (gdb_stdlog, "Compiler option %d: <%s>\n",
564  argi, argv[argi]);
565  }
566 
568 
569  gdb::optional<gdb::unlinker> source_remover;
570 
571  {
572  gdb_file_up src = gdb_fopen_cloexec (fnames.source_file (), "w");
573  if (src == NULL)
574  perror_with_name (_("Could not open source file for writing"));
575 
576  source_remover.emplace (fnames.source_file ());
577 
578  if (fputs (code.c_str (), src.get ()) == EOF)
579  perror_with_name (_("Could not write to source file"));
580  }
581 
582  if (compile_debug)
583  fprintf_unfiltered (gdb_stdlog, "source file produced: %s\n\n",
584  fnames.source_file ());
585 
586  /* Call the compiler and start the compilation process. */
587  compiler->fe->ops->set_source_file (compiler->fe, fnames.source_file ());
588 
589  if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
590  ok = compiler->fe->ops->compile (compiler->fe, fnames.object_file ());
591  else
592  ok = compiler->fe->ops->compile_v0 (compiler->fe, fnames.object_file (),
593  compile_debug);
594  if (!ok)
595  error (_("Compilation failed."));
596 
597  if (compile_debug)
598  fprintf_unfiltered (gdb_stdlog, "object file produced: %s\n\n",
599  fnames.object_file ());
600 
601  /* Keep the source file. */
602  source_remover->keep ();
603 
605 
606  return fnames;
607 }
608 
609 /* The "compile" prefix command. */
610 
611 static void
612 compile_command (const char *args, int from_tty)
613 {
614  /* If a sub-command is not specified to the compile prefix command,
615  assume it is a direct code compilation. */
616  compile_code_command (args, from_tty);
617 }
618 
619 /* See compile.h. */
620 
621 void
622 eval_compile_command (struct command_line *cmd, const char *cmd_string,
624 {
626 
627  compile_file_names fnames = compile_to_object (cmd, cmd_string, scope);
628 
629  gdb::unlinker object_remover (fnames.object_file ());
630  gdb::unlinker source_remover (fnames.source_file ());
631 
633  if (compile_module == NULL)
634  {
636  eval_compile_command (cmd, cmd_string,
638  return;
639  }
640 
641  /* Keep the files. */
642  source_remover.keep ();
643  object_remover.keep ();
644 
646 }
647 
648 /* See compile/compile-internal.h. */
649 
652 {
653  const char *regname = gdbarch_register_name (gdbarch, regnum);
654 
655  return string_printf ("__%s", regname);
656 }
657 
658 /* See compile/compile-internal.h. */
659 
660 int
662  const char *regname)
663 {
664  int regnum;
665 
666  if (regname[0] != '_' || regname[1] != '_')
667  error (_("Invalid register name \"%s\"."), regname);
668  regname += 2;
669 
670  for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
671  if (strcmp (regname, gdbarch_register_name (gdbarch, regnum)) == 0)
672  return regnum;
673 
674  error (_("Cannot find gdbarch register \"%s\"."), regname);
675 }
676 
677 void
679 {
680  struct cmd_list_element *c = NULL;
681 
683  _("\
684 Command to compile source code and inject it into the inferior."),
685  &compile_command_list, "compile ", 1, &cmdlist);
686  add_com_alias ("expression", "compile", class_obscure, 0);
687 
689  _("\
690 Compile, inject, and execute code.\n\
691 \n\
692 Usage: compile code [-r|-raw] [--] [CODE]\n\
693 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping.\n\
694 --: Do not parse any options beyond this delimiter. All text to the\n\
695  right will be treated as source code.\n\
696 \n\
697 The source code may be specified as a simple one line expression, e.g.:\n\
698 \n\
699  compile code printf(\"Hello world\\n\");\n\
700 \n\
701 Alternatively, you can type a multiline expression by invoking\n\
702 this command with no argument. GDB will then prompt for the\n\
703 expression interactively; type a line containing \"end\" to\n\
704 indicate the end of the expression."),
706 
708  _("\
709 Evaluate a file containing source code.\n\
710 \n\
711 Usage: compile file [-r|-raw] [filename]\n\
712 -r|-raw: Suppress automatic 'void _gdb_expr () { CODE }' wrapping."),
715 
717  _("\
718 Evaluate EXPR by using the compiler and print result.\n\
719 \n\
720 Usage: compile print[/FMT] [EXPR]\n\
721 \n\
722 The expression may be specified on the same line as the command, e.g.:\n\
723 \n\
724  compile print i\n\
725 \n\
726 Alternatively, you can type a multiline expression by invoking\n\
727 this command with no argument. GDB will then prompt for the\n\
728 expression interactively; type a line containing \"end\" to\n\
729 indicate the end of the expression.\n\
730 \n\
731 EXPR may be preceded with /FMT, where FMT is a format letter\n\
732 but no count or size letter (see \"x\" command)."),
734 
736 Set compile command debugging."), _("\
737 Show compile command debugging."), _("\
738 When on, compile command debugging is enabled."),
739  NULL, show_compile_debug,
741 
742  add_setshow_string_cmd ("compile-args", class_support,
743  &compile_args,
744  _("Set compile command GCC command-line arguments"),
745  _("Show compile command GCC command-line arguments"),
746  _("\
747 Use options like -I (include file directory) or ABI settings.\n\
748 String quoting is parsed like in shell, for example:\n\
749  -mno-align-double \"-I/dir with a space/include\""),
751 
752  /* Override flags possibly coming from DW_AT_producer. */
753  compile_args = xstrdup ("-O0 -gdwarf-4"
754  /* We use -fPIE Otherwise GDB would need to reserve space large enough for
755  any object file in the inferior in advance to get the final address when
756  to link the object file to and additionally the default system linker
757  script would need to be modified so that one can specify there the
758  absolute target address.
759  -fPIC is not used at is would require from GDB to generate .got. */
760  " -fPIE"
761  /* We want warnings, except for some commonly happening for GDB commands. */
762  " -Wall "
763  " -Wno-implicit-function-declaration"
764  " -Wno-unused-but-set-variable"
765  " -Wno-unused-variable"
766  /* Override CU's possible -fstack-protector-strong. */
767  " -fno-stack-protector"
768  );
769  set_compile_args (compile_args, 0, NULL);
770 
772  &compile_gcc,
773  _("Set compile command "
774  "GCC driver filename"),
775  _("Show compile command "
776  "GCC driver filename"),
777  _("\
778 It should be absolute filename of the gcc executable.\n\
779 If empty the default target triplet will be searched in $PATH."),
780  NULL, show_compile_gcc, &setlist,
781  &showlist);
782  compile_gcc = xstrdup ("");
783 }
const char * string
Definition: signals.c:50
int count() const
Definition: utils.h:194
CORE_ADDR get_frame_address_in_block(struct frame_info *this_frame)
Definition: frame.c:2407
void eval_compile_command(struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope, void *scope_data)
Definition: compile.c:622
struct ui * current_ui
Definition: event-top.c:453
struct frame_info * get_selected_frame(const char *message)
Definition: frame.c:1638
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
enum command_control_type execute_control_command_untraced(struct command_line *cmd)
Definition: cli-script.c:665
bfd_vma CORE_ADDR
Definition: common-types.h:41
char ** release()
Definition: utils.h:185
static void compile_file_command(const char *arg, int from_tty)
Definition: compile.c:90
const char * gcc_target_options
const char * gdbarch_gnu_triplet_regexp(struct gdbarch *gdbarch)
Definition: gdbarch.c:5013
void xfree(void *)
static void do_rmdir(void *arg)
Definition: compile.c:200
const char * source_file() const
static char * compile_gcc
Definition: compile.c:338
static void set_compile_args(const char *args, int from_tty, struct cmd_list_element *c)
Definition: compile.c:305
void warning(const char *fmt,...)
Definition: errors.c:26
int async
Definition: top.h:102
command_line_up get_command_line(enum command_control_type type, const char *arg)
Definition: cli-script.c:170
struct symtab_and_line get_current_source_symtab_and_line(void)
Definition: source.c:171
const char * osabi_triplet_regexp(enum gdb_osabi osabi)
Definition: osabi.c:98
int compile_register_name_demangle(struct gdbarch *gdbarch, const char *regname)
Definition: compile.c:661
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:262
compile_i_scope_types
Definition: defs.h:61
static const char * get_selected_pc_producer_options(void)
Definition: compile.c:357
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition: completer.c:152
#define BLOCKVECTOR_BLOCK(blocklist, n)
Definition: block.h:125
struct cmd_list_element * cmdlist
Definition: cli-cmds.c:79
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:2039
static char ** compile_args_argv
Definition: compile.c:300
char * skip_spaces(char *chp)
Definition: common-utils.c:337
#define _(String)
Definition: gdb_locale.h:35
static char * compile_args
Definition: compile.c:296
#define BLOCK_START(bl)
Definition: block.h:105
static void cleanup_compile_instance(void *arg)
Definition: compile.c:434
static void append_args(int *argcp, char ***argvp, int argc, char **argv)
Definition: compile.c:326
enum gdb_osabi gdbarch_osabi(struct gdbarch *gdbarch)
Definition: gdbarch.c:1527
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:367
struct compunit_symtab * find_pc_compunit_symtab(CORE_ADDR pc)
Definition: symtab.c:2988
scoped_restore_tmpl< T > make_scoped_restore(T *var)
char * line
Definition: cli-script.h:54
struct cmd_list_element * setlist
Definition: cli-cmds.c:111
#define SYMTAB_BLOCKVECTOR(symtab)
Definition: symtab.h:1334
#define SLASH_STRING
Definition: host-defs.h:58
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
Definition: filestuff.h:59
void print_value(struct value *val, const struct format_data *fmtp)
Definition: printcmd.c:1171
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
static void compile_command(const char *args, int from_tty)
Definition: compile.c:612
static compile_file_names compile_to_object(struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope)
Definition: compile.c:455
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2008
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
Definition: cli-decode.c:160
static void build_argc_argv(const char *s, int *argcp, char ***argvp)
Definition: compile.c:287
#define WIFEXITED(w)
Definition: gdb_wait.h:44
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2018
struct compile_instance *(* la_get_compile_instance)(void)
Definition: language.h:409
struct cmd_list_element * showlist
Definition: cli-cmds.c:119
struct cmd_list_element * add_com_alias(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag)
Definition: cli-decode.c:912
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1811
enum compile_i_scope_types scope
Definition: cli-script.h:60
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:116
void add_setshow_string_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:613
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:798
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
Definition: filestuff.c:296
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
Definition: gdbarch.c:2282
static void show_compile_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: compile.c:62
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:107
static int compile_args_argc
Definition: compile.c:299
const char * skip_to_space(const char *chp)
Definition: common-utils.c:361
#define target_has_execution
Definition: target.h:1756
static void filter_args(int *argcp, char **argv)
Definition: compile.c:378
int regnum
Definition: aarch64-tdep.c:77
void * scope_data
Definition: cli-script.h:61
#define WEXITSTATUS(w)
Definition: gdb_wait.h:67
struct cmd_list_element * setdebuglist
Definition: cli-cmds.c:153
virtual void puts(const char *str)
Definition: ui-file.h:63
#define XRESIZEVEC(T, P, N)
Definition: poison.h:169
struct symtab * symtab
Definition: symtab.h:1751
static int check_raw_argument(const char **arg)
Definition: compile.c:74
#define TMP_PREFIX
Definition: compile.c:49
void _initialize_compile(void)
Definition: compile.c:678
#define gdb_assert(expr)
Definition: gdb_assert.h:32
Definition: block.h:60
Definition: value.c:169
static void print_callback(void *ignore, const char *message)
Definition: compile.c:445
void(* destroy)(struct compile_instance *)
struct command_line * next
Definition: cli-script.h:53
struct compile_module * compile_object_load(const compile_file_names &file_names, enum compile_i_scope_types scope, void *scope_data)
static compile_file_names get_new_file_names()
Definition: compile.c:246
enum compile_i_scope_types scope
#define TEMPLATE
T & emplace(Args &&... args)
Definition: gdb_optional.h:152
const struct language_defn * current_language
Definition: language.c:81
gdb::unique_xmalloc_ptr< char > gdb_abspath(const char *path)
Definition: utils.c:2978
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
std::string compile_register_name_mangled(struct gdbarch *gdbarch, int regnum)
Definition: compile.c:651
#define gdb_stderr
Definition: utils.h:344
static void compile_code_command(const char *arg, int from_tty)
Definition: compile.c:127
enum compile_i_scope_types scope
void print_command_parse_format(const char **expp, const char *cmdname, struct format_data *fmtp)
Definition: printcmd.c:1144
const char * c_str() const
Definition: ui-file.h:137
struct gcc_base_context * fe
static const char * get_compile_file_tempdir(void)
Definition: compile.c:218
void compile_print_value(struct value *val, void *data_voidp)
Definition: compile.c:161
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:569
static void show_compile_args(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: compile.c:314
int code
Definition: ser-unix.c:239
Definition: buffer.h:23
CORE_ADDR pc
Definition: symtab.h:1759
std::string string_printf(const char *fmt,...)
Definition: common-utils.c:150
struct cleanup * make_final_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:135
const struct block * get_selected_block(CORE_ADDR *addr_in_block)
Definition: stack.c:2216
static void compile_print_command(const char *arg, int from_tty)
Definition: compile.c:174
static struct cmd_list_element * compile_command_list
Definition: compile.c:53
void compile_object_run(struct compile_module *module)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: corelow.c:879
const struct block * block
#define gdb_stdlog
Definition: utils.h:349
void add_setshow_optional_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:654
static const struct block * get_expr_block_and_pc(CORE_ADDR *pc)
Definition: compile.c:262
struct cmd_list_element * showdebuglist
Definition: cli-cmds.c:155
static void show_compile_gcc(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: compile.c:343
std::unique_ptr< command_line, command_lines_deleter > command_line_up
Definition: cli-script.h:88
#define XDELETEVEC(P)
Definition: poison.h:181
argv
Definition: __init__.py:63
const char * la_name
Definition: language.h:136
struct command_line ** body_list
Definition: cli-script.h:71
const char * object_file() const
void error(const char *fmt,...)
Definition: errors.c:38
char * gdbarch_gcc_target_options(struct gdbarch *gdbarch)
Definition: gdbarch.c:4996
std::string(* la_compute_program)(struct compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc)
Definition: language.h:425
int check_for_argument(const char **str, const char *arg, int arg_len)
Definition: cli-utils.c:297
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:174
int compile_debug
Definition: compile.c:57
static void get_args(const struct compile_instance *compiler, struct gdbarch *gdbarch, int *argcp, char ***argvp)
Definition: compile.c:401