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