gdb.guile/scm-error.exp: Handle guile 2.2 backtrace output.
[deliverable/binutils-gdb.git] / gdb / guile / guile.c
1 /* General GDB/Guile code.
2
3 Copyright (C) 2014 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 /* See README file in this directory for implementation notes, coding
21 conventions, et.al. */
22
23 #include "defs.h"
24 #include "breakpoint.h"
25 #include "cli/cli-cmds.h"
26 #include "cli/cli-script.h"
27 #include "cli/cli-utils.h"
28 #include "command.h"
29 #include "gdbcmd.h"
30 #include "interps.h"
31 #include "extension-priv.h"
32 #include "utils.h"
33 #include "version.h"
34 #ifdef HAVE_GUILE
35 #include "guile.h"
36 #include "guile-internal.h"
37 #ifdef HAVE_GC_GC_H
38 #include <gc/gc.h> /* PR 17185 */
39 #endif
40 #endif
41
42 /* The Guile version we're using.
43 We *could* use the macros in libguile/version.h but that would preclude
44 handling the user switching in a different version with, e.g.,
45 LD_LIBRARY_PATH (using a different version than what gdb was compiled with
46 is not something to be done lightly, but can be useful). */
47 int gdbscm_guile_major_version;
48 int gdbscm_guile_minor_version;
49 int gdbscm_guile_micro_version;
50
51 /* The guile subdirectory within gdb's data-directory. */
52 static const char *guile_datadir;
53
54 /* Declared constants and enum for guile exception printing. */
55 const char gdbscm_print_excp_none[] = "none";
56 const char gdbscm_print_excp_full[] = "full";
57 const char gdbscm_print_excp_message[] = "message";
58
59 /* "set guile print-stack" choices. */
60 static const char *const guile_print_excp_enums[] =
61 {
62 gdbscm_print_excp_none,
63 gdbscm_print_excp_full,
64 gdbscm_print_excp_message,
65 NULL
66 };
67
68 /* The exception printing variable. 'full' if we want to print the
69 error message and stack, 'none' if we want to print nothing, and
70 'message' if we only want to print the error message. 'message' is
71 the default. */
72 const char *gdbscm_print_excp = gdbscm_print_excp_message;
73
74 #ifdef HAVE_GUILE
75 /* Forward decls, these are defined later. */
76 static const struct extension_language_script_ops guile_extension_script_ops;
77 static const struct extension_language_ops guile_extension_ops;
78 #endif
79
80 /* The main struct describing GDB's interface to the Guile
81 extension language. */
82 const struct extension_language_defn extension_language_guile =
83 {
84 EXT_LANG_GUILE,
85 "guile",
86 "Guile",
87
88 ".scm",
89 "-gdb.scm",
90
91 guile_control,
92
93 #ifdef HAVE_GUILE
94 &guile_extension_script_ops,
95 &guile_extension_ops
96 #else
97 NULL,
98 NULL
99 #endif
100 };
101 \f
102 #ifdef HAVE_GUILE
103
104 static void gdbscm_finish_initialization
105 (const struct extension_language_defn *);
106 static int gdbscm_initialized (const struct extension_language_defn *);
107 static void gdbscm_eval_from_control_command
108 (const struct extension_language_defn *, struct command_line *);
109 static script_sourcer_func gdbscm_source_script;
110
111 int gdb_scheme_initialized;
112
113 /* Symbol for setting documentation strings. */
114 SCM gdbscm_documentation_symbol;
115
116 /* Keywords used by various functions. */
117 static SCM from_tty_keyword;
118 static SCM to_string_keyword;
119
120 /* The name of the various modules (without the surrounding parens). */
121 const char gdbscm_module_name[] = "gdb";
122 const char gdbscm_init_module_name[] = "gdb";
123
124 /* The name of the bootstrap file. */
125 static const char boot_scm_filename[] = "boot.scm";
126
127 /* The interface between gdb proper and loading of python scripts. */
128
129 static const struct extension_language_script_ops guile_extension_script_ops =
130 {
131 gdbscm_source_script,
132 gdbscm_source_objfile_script,
133 gdbscm_auto_load_enabled
134 };
135
136 /* The interface between gdb proper and guile scripting. */
137
138 static const struct extension_language_ops guile_extension_ops =
139 {
140 gdbscm_finish_initialization,
141 gdbscm_initialized,
142
143 gdbscm_eval_from_control_command,
144
145 NULL, /* gdbscm_start_type_printers, */
146 NULL, /* gdbscm_apply_type_printers, */
147 NULL, /* gdbscm_free_type_printers, */
148
149 gdbscm_apply_val_pretty_printer,
150
151 NULL, /* gdbscm_apply_frame_filter, */
152
153 gdbscm_preserve_values,
154
155 gdbscm_breakpoint_has_cond,
156 gdbscm_breakpoint_cond_says_stop,
157
158 NULL, /* gdbscm_check_quit_flag, */
159 NULL, /* gdbscm_clear_quit_flag, */
160 NULL, /* gdbscm_set_quit_flag, */
161 };
162
163 /* Implementation of the gdb "guile-repl" command. */
164
165 static void
166 guile_repl_command (char *arg, int from_tty)
167 {
168 struct cleanup *cleanup;
169
170 cleanup = make_cleanup_restore_integer (&interpreter_async);
171 interpreter_async = 0;
172
173 arg = skip_spaces (arg);
174
175 /* This explicitly rejects any arguments for now.
176 "It is easier to relax a restriction than impose one after the fact."
177 We would *like* to be able to pass arguments to the interactive shell
178 but that's not what python-interactive does. Until there is time to
179 sort it out, we forbid arguments. */
180
181 if (arg && *arg)
182 error (_("guile-repl currently does not take any arguments."));
183 else
184 {
185 dont_repeat ();
186 gdbscm_enter_repl ();
187 }
188
189 do_cleanups (cleanup);
190 }
191
192 /* Implementation of the gdb "guile" command.
193 Note: Contrary to the Python version this displays the result.
194 Have to see which is better.
195
196 TODO: Add the result to Guile's history? */
197
198 static void
199 guile_command (char *arg, int from_tty)
200 {
201 struct cleanup *cleanup;
202
203 cleanup = make_cleanup_restore_integer (&interpreter_async);
204 interpreter_async = 0;
205
206 arg = skip_spaces (arg);
207
208 if (arg && *arg)
209 {
210 char *msg = gdbscm_safe_eval_string (arg, 1);
211
212 if (msg != NULL)
213 {
214 make_cleanup (xfree, msg);
215 error ("%s", msg);
216 }
217 }
218 else
219 {
220 struct command_line *l = get_command_line (guile_control, "");
221
222 make_cleanup_free_command_lines (&l);
223 execute_control_command_untraced (l);
224 }
225
226 do_cleanups (cleanup);
227 }
228
229 /* Given a command_line, return a command string suitable for passing
230 to Guile. Lines in the string are separated by newlines. The return
231 value is allocated using xmalloc and the caller is responsible for
232 freeing it. */
233
234 static char *
235 compute_scheme_string (struct command_line *l)
236 {
237 struct command_line *iter;
238 char *script = NULL;
239 int size = 0;
240 int here;
241
242 for (iter = l; iter; iter = iter->next)
243 size += strlen (iter->line) + 1;
244
245 script = xmalloc (size + 1);
246 here = 0;
247 for (iter = l; iter; iter = iter->next)
248 {
249 int len = strlen (iter->line);
250
251 strcpy (&script[here], iter->line);
252 here += len;
253 script[here++] = '\n';
254 }
255 script[here] = '\0';
256 return script;
257 }
258
259 /* Take a command line structure representing a "guile" command, and
260 evaluate its body using the Guile interpreter.
261 This is the extension_language_ops.eval_from_control_command "method". */
262
263 static void
264 gdbscm_eval_from_control_command
265 (const struct extension_language_defn *extlang, struct command_line *cmd)
266 {
267 char *script, *msg;
268 struct cleanup *cleanup;
269
270 if (cmd->body_count != 1)
271 error (_("Invalid \"guile\" block structure."));
272
273 cleanup = make_cleanup (null_cleanup, NULL);
274
275 script = compute_scheme_string (cmd->body_list[0]);
276 msg = gdbscm_safe_eval_string (script, 0);
277 xfree (script);
278 if (msg != NULL)
279 {
280 make_cleanup (xfree, msg);
281 error ("%s", msg);
282 }
283
284 do_cleanups (cleanup);
285 }
286
287 /* Read a file as Scheme code.
288 This is the extension_language_script_ops.script_sourcer "method".
289 FILE is the file to run. FILENAME is name of the file FILE.
290 This does not throw any errors. If an exception occurs an error message
291 is printed. */
292
293 static void
294 gdbscm_source_script (const struct extension_language_defn *extlang,
295 FILE *file, const char *filename)
296 {
297 char *msg = gdbscm_safe_source_script (filename);
298
299 if (msg != NULL)
300 {
301 fprintf_filtered (gdb_stderr, "%s\n", msg);
302 xfree (msg);
303 }
304 }
305 \f
306 /* (execute string [#:from-tty boolean] [#:to-string boolean])
307 A Scheme function which evaluates a string using the gdb CLI. */
308
309 static SCM
310 gdbscm_execute_gdb_command (SCM command_scm, SCM rest)
311 {
312 int from_tty_arg_pos = -1, to_string_arg_pos = -1;
313 int from_tty = 0, to_string = 0;
314 volatile struct gdb_exception except;
315 const SCM keywords[] = { from_tty_keyword, to_string_keyword, SCM_BOOL_F };
316 char *command;
317 char *result = NULL;
318 struct cleanup *cleanups;
319
320 gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#tt",
321 command_scm, &command, rest,
322 &from_tty_arg_pos, &from_tty,
323 &to_string_arg_pos, &to_string);
324
325 /* Note: The contents of "command" may get modified while it is
326 executed. */
327 cleanups = make_cleanup (xfree, command);
328
329 TRY_CATCH (except, RETURN_MASK_ALL)
330 {
331 struct cleanup *inner_cleanups;
332
333 inner_cleanups = make_cleanup_restore_integer (&interpreter_async);
334 interpreter_async = 0;
335
336 prevent_dont_repeat ();
337 if (to_string)
338 result = execute_command_to_string (command, from_tty);
339 else
340 {
341 execute_command (command, from_tty);
342 result = NULL;
343 }
344
345 /* Do any commands attached to breakpoint we stopped at. */
346 bpstat_do_actions ();
347
348 do_cleanups (inner_cleanups);
349 }
350 do_cleanups (cleanups);
351 GDBSCM_HANDLE_GDB_EXCEPTION (except);
352
353 if (result)
354 {
355 SCM r = gdbscm_scm_from_c_string (result);
356 xfree (result);
357 return r;
358 }
359 return SCM_UNSPECIFIED;
360 }
361
362 /* (data-directory) -> string */
363
364 static SCM
365 gdbscm_data_directory (void)
366 {
367 return gdbscm_scm_from_c_string (gdb_datadir);
368 }
369
370 /* (guile-data-directory) -> string */
371
372 static SCM
373 gdbscm_guile_data_directory (void)
374 {
375 return gdbscm_scm_from_c_string (guile_datadir);
376 }
377
378 /* (gdb-version) -> string */
379
380 static SCM
381 gdbscm_gdb_version (void)
382 {
383 return gdbscm_scm_from_c_string (version);
384 }
385
386 /* (host-config) -> string */
387
388 static SCM
389 gdbscm_host_config (void)
390 {
391 return gdbscm_scm_from_c_string (host_name);
392 }
393
394 /* (target-config) -> string */
395
396 static SCM
397 gdbscm_target_config (void)
398 {
399 return gdbscm_scm_from_c_string (target_name);
400 }
401
402 #else /* ! HAVE_GUILE */
403
404 /* Dummy implementation of the gdb "guile-repl" and "guile"
405 commands. */
406
407 static void
408 guile_repl_command (char *arg, int from_tty)
409 {
410 arg = skip_spaces (arg);
411 if (arg && *arg)
412 error (_("guile-repl currently does not take any arguments."));
413 error (_("Guile scripting is not supported in this copy of GDB."));
414 }
415
416 static void
417 guile_command (char *arg, int from_tty)
418 {
419 arg = skip_spaces (arg);
420 if (arg && *arg)
421 error (_("Guile scripting is not supported in this copy of GDB."));
422 else
423 {
424 /* Even if Guile isn't enabled, we still have to slurp the
425 command list to the corresponding "end". */
426 struct command_line *l = get_command_line (guile_control, "");
427 struct cleanup *cleanups = make_cleanup_free_command_lines (&l);
428
429 execute_control_command_untraced (l);
430 do_cleanups (cleanups);
431 }
432 }
433
434 #endif /* ! HAVE_GUILE */
435 \f
436 /* Lists for 'set,show,info guile' commands. */
437
438 static struct cmd_list_element *set_guile_list;
439 static struct cmd_list_element *show_guile_list;
440 static struct cmd_list_element *info_guile_list;
441
442 /* Function for use by 'set guile' prefix command. */
443
444 static void
445 set_guile_command (char *args, int from_tty)
446 {
447 help_list (set_guile_list, "set guile ", all_commands, gdb_stdout);
448 }
449
450 /* Function for use by 'show guile' prefix command. */
451
452 static void
453 show_guile_command (char *args, int from_tty)
454 {
455 cmd_show_list (show_guile_list, from_tty, "");
456 }
457
458 /* The "info scheme" command is defined as a prefix, with
459 allow_unknown 0. Therefore, its own definition is called only for
460 "info scheme" with no args. */
461
462 static void
463 info_guile_command (char *args, int from_tty)
464 {
465 printf_unfiltered (_("\"info guile\" must be followed"
466 " by the name of an info command.\n"));
467 help_list (info_guile_list, "info guile ", all_commands, gdb_stdout);
468 }
469 \f
470 /* Initialization. */
471
472 #ifdef HAVE_GUILE
473
474 static const scheme_function misc_guile_functions[] =
475 {
476 { "execute", 1, 0, 1, gdbscm_execute_gdb_command,
477 "\
478 Execute the given GDB command.\n\
479 \n\
480 Arguments: string [#:to-string boolean] [#:from-tty boolean]\n\
481 If #:from-tty is true then the command executes as if entered\n\
482 from the keyboard. The default is false (#f).\n\
483 If #:to-string is true then the result is returned as a string.\n\
484 Otherwise output is sent to the current output port,\n\
485 which is the default.\n\
486 Returns: The result of the command if #:to-string is true.\n\
487 Otherwise returns unspecified." },
488
489 { "data-directory", 0, 0, 0, gdbscm_data_directory,
490 "\
491 Return the name of GDB's data directory." },
492
493 { "guile-data-directory", 0, 0, 0, gdbscm_guile_data_directory,
494 "\
495 Return the name of the Guile directory within GDB's data directory." },
496
497 { "gdb-version", 0, 0, 0, gdbscm_gdb_version,
498 "\
499 Return GDB's version string." },
500
501 { "host-config", 0, 0, 0, gdbscm_host_config,
502 "\
503 Return the name of the host configuration." },
504
505 { "target-config", 0, 0, 0, gdbscm_target_config,
506 "\
507 Return the name of the target configuration." },
508
509 END_FUNCTIONS
510 };
511
512 /* Load BOOT_SCM_FILE, the first Scheme file that gets loaded. */
513
514 static SCM
515 boot_guile_support (void *boot_scm_file)
516 {
517 /* Load boot.scm without compiling it (there's no need to compile it).
518 The other files should have been compiled already, and boot.scm is
519 expected to adjust '%load-compiled-path' accordingly. If they haven't
520 been compiled, Guile will auto-compile them. The important thing to keep
521 in mind is that there's a >= 100x speed difference between compiled and
522 non-compiled files. */
523 return scm_c_primitive_load ((const char *) boot_scm_file);
524 }
525
526 /* Return non-zero if ARGS has the "standard" format for throw args.
527 The standard format is:
528 (function format-string (format-string-args-list) ...).
529 FUNCTION is #f if no function was recorded. */
530
531 static int
532 standard_throw_args_p (SCM args)
533 {
534 if (gdbscm_is_true (scm_list_p (args))
535 && scm_ilength (args) >= 3)
536 {
537 /* The function in which the error occurred. */
538 SCM arg0 = scm_list_ref (args, scm_from_int (0));
539 /* The format string. */
540 SCM arg1 = scm_list_ref (args, scm_from_int (1));
541 /* The arguments of the format string. */
542 SCM arg2 = scm_list_ref (args, scm_from_int (2));
543
544 if ((scm_is_string (arg0) || gdbscm_is_false (arg0))
545 && scm_is_string (arg1)
546 && gdbscm_is_true (scm_list_p (arg2)))
547 return 1;
548 }
549
550 return 0;
551 }
552
553 /* Print the error recorded in a "standard" throw args. */
554
555 static void
556 print_standard_throw_error (SCM args)
557 {
558 /* The function in which the error occurred. */
559 SCM arg0 = scm_list_ref (args, scm_from_int (0));
560 /* The format string. */
561 SCM arg1 = scm_list_ref (args, scm_from_int (1));
562 /* The arguments of the format string. */
563 SCM arg2 = scm_list_ref (args, scm_from_int (2));
564
565 /* ARG0 is #f if no function was recorded. */
566 if (gdbscm_is_true (arg0))
567 {
568 scm_simple_format (scm_current_error_port (),
569 scm_from_latin1_string (_("Error in function ~s:~%")),
570 scm_list_1 (arg0));
571 }
572 scm_simple_format (scm_current_error_port (), arg1, arg2);
573 }
574
575 /* Print the error message recorded in KEY, ARGS, the arguments to throw.
576 Normally we let Scheme print the error message.
577 This function is used when Scheme initialization fails.
578 We can still use the Scheme C API though. */
579
580 static void
581 print_throw_error (SCM key, SCM args)
582 {
583 /* IWBN to call gdbscm_print_exception_with_stack here, but Guile didn't
584 boot successfully so play it safe and avoid it. The "format string" and
585 its args are embedded in ARGS, but the content of ARGS depends on KEY.
586 Make sure ARGS has the expected canonical content before trying to use
587 it. */
588 if (standard_throw_args_p (args))
589 print_standard_throw_error (args);
590 else
591 {
592 scm_simple_format (scm_current_error_port (),
593 scm_from_latin1_string (_("Throw to key `~a' with args `~s'.~%")),
594 scm_list_2 (key, args));
595 }
596 }
597
598 /* Handle an exception thrown while loading BOOT_SCM_FILE. */
599
600 static SCM
601 handle_boot_error (void *boot_scm_file, SCM key, SCM args)
602 {
603 fprintf_unfiltered (gdb_stderr, ("Exception caught while booting Guile.\n"));
604
605 print_throw_error (key, args);
606
607 fprintf_unfiltered (gdb_stderr, "\n");
608 warning (_("Could not complete Guile gdb module initialization from:\n"
609 "%s.\n"
610 "Limited Guile support is available.\n"
611 "Suggest passing --data-directory=/path/to/gdb/data-directory.\n"),
612 (const char *) boot_scm_file);
613
614 return SCM_UNSPECIFIED;
615 }
616
617 /* Load gdb/boot.scm, the Scheme side of GDB/Guile support.
618 Note: This function assumes it's called within the gdb module. */
619
620 static void
621 initialize_scheme_side (void)
622 {
623 char *boot_scm_path;
624 char *msg;
625
626 guile_datadir = concat (gdb_datadir, SLASH_STRING, "guile", NULL);
627 boot_scm_path = concat (guile_datadir, SLASH_STRING, "gdb",
628 SLASH_STRING, boot_scm_filename, NULL);
629
630 scm_c_catch (SCM_BOOL_T, boot_guile_support, boot_scm_path,
631 handle_boot_error, boot_scm_path, NULL, NULL);
632
633 xfree (boot_scm_path);
634 }
635
636 /* Install the gdb scheme module.
637 The result is a boolean indicating success.
638 If initializing the gdb module fails an error message is printed.
639 Note: This function runs in the context of the gdb module. */
640
641 static void
642 initialize_gdb_module (void *data)
643 {
644 /* Computing these is a pain, so only do it once.
645 Also, do it here and save the result so that obtaining the values
646 is thread-safe. */
647 gdbscm_guile_major_version = gdbscm_scm_string_to_int (scm_major_version ());
648 gdbscm_guile_minor_version = gdbscm_scm_string_to_int (scm_minor_version ());
649 gdbscm_guile_micro_version = gdbscm_scm_string_to_int (scm_micro_version ());
650
651 /* The documentation symbol needs to be defined before any calls to
652 gdbscm_define_{variables,functions}. */
653 gdbscm_documentation_symbol = scm_from_latin1_symbol ("documentation");
654
655 /* The smob and exception support must be initialized early. */
656 gdbscm_initialize_smobs ();
657 gdbscm_initialize_exceptions ();
658
659 /* The rest are initialized in alphabetical order. */
660 gdbscm_initialize_arches ();
661 gdbscm_initialize_auto_load ();
662 gdbscm_initialize_blocks ();
663 gdbscm_initialize_breakpoints ();
664 gdbscm_initialize_commands ();
665 gdbscm_initialize_disasm ();
666 gdbscm_initialize_frames ();
667 gdbscm_initialize_iterators ();
668 gdbscm_initialize_lazy_strings ();
669 gdbscm_initialize_math ();
670 gdbscm_initialize_objfiles ();
671 gdbscm_initialize_parameters ();
672 gdbscm_initialize_ports ();
673 gdbscm_initialize_pretty_printers ();
674 gdbscm_initialize_pspaces ();
675 gdbscm_initialize_strings ();
676 gdbscm_initialize_symbols ();
677 gdbscm_initialize_symtabs ();
678 gdbscm_initialize_types ();
679 gdbscm_initialize_values ();
680
681 gdbscm_define_functions (misc_guile_functions, 1);
682
683 from_tty_keyword = scm_from_latin1_keyword ("from-tty");
684 to_string_keyword = scm_from_latin1_keyword ("to-string");
685
686 initialize_scheme_side ();
687
688 gdb_scheme_initialized = 1;
689 }
690
691 /* Utility to call scm_c_define_module+initialize_gdb_module from
692 within scm_with_guile. */
693
694 static void *
695 call_initialize_gdb_module (void *data)
696 {
697 /* Most of the initialization is done by initialize_gdb_module.
698 It is called via scm_c_define_module so that the initialization is
699 performed within the desired module. */
700 scm_c_define_module (gdbscm_module_name, initialize_gdb_module, NULL);
701
702 return NULL;
703 }
704
705 /* A callback to finish Guile initialization after gdb has finished all its
706 initialization.
707 This is the extension_language_ops.finish_initialization "method". */
708
709 static void
710 gdbscm_finish_initialization (const struct extension_language_defn *extlang)
711 {
712 /* Restore the environment to the user interaction one. */
713 scm_set_current_module (scm_interaction_environment ());
714 }
715
716 /* The extension_language_ops.initialized "method". */
717
718 static int
719 gdbscm_initialized (const struct extension_language_defn *extlang)
720 {
721 return gdb_scheme_initialized;
722 }
723
724 /* Enable or disable Guile backtraces. */
725
726 static void
727 gdbscm_set_backtrace (int enable)
728 {
729 static const char disable_bt[] = "(debug-disable 'backtrace)";
730 static const char enable_bt[] = "(debug-enable 'backtrace)";
731
732 if (enable)
733 gdbscm_safe_eval_string (enable_bt, 0);
734 else
735 gdbscm_safe_eval_string (disable_bt, 0);
736 }
737
738 #endif /* HAVE_GUILE */
739
740 /* Install the various gdb commands used by Guile. */
741
742 static void
743 install_gdb_commands (void)
744 {
745 add_com ("guile-repl", class_obscure,
746 guile_repl_command,
747 #ifdef HAVE_GUILE
748 _("\
749 Start an interactive Guile prompt.\n\
750 \n\
751 To return to GDB, type the EOF character (e.g., Ctrl-D on an empty\n\
752 prompt) or ,quit.")
753 #else /* HAVE_GUILE */
754 _("\
755 Start a Guile interactive prompt.\n\
756 \n\
757 Guile scripting is not supported in this copy of GDB.\n\
758 This command is only a placeholder.")
759 #endif /* HAVE_GUILE */
760 );
761 add_com_alias ("gr", "guile-repl", class_obscure, 1);
762
763 /* Since "help guile" is easy to type, and intuitive, we add general help
764 in using GDB+Guile to this command. */
765 add_com ("guile", class_obscure, guile_command,
766 #ifdef HAVE_GUILE
767 _("\
768 Evaluate one or more Guile expressions.\n\
769 \n\
770 The expression(s) can be given as an argument, for instance:\n\
771 \n\
772 guile (display 23)\n\
773 \n\
774 The result of evaluating the last expression is printed.\n\
775 \n\
776 If no argument is given, the following lines are read and passed\n\
777 to Guile for evaluation. Type a line containing \"end\" to indicate\n\
778 the end of the set of expressions.\n\
779 \n\
780 The Guile GDB module must first be imported before it can be used.\n\
781 Do this with:\n\
782 (gdb) guile (use-modules (gdb))\n\
783 or if you want to import the (gdb) module with a prefix, use:\n\
784 (gdb) guile (use-modules ((gdb) #:renamer (symbol-prefix-proc 'gdb:)))\n\
785 \n\
786 The Guile interactive session, started with the \"guile-repl\"\n\
787 command, provides extensive help and apropos capabilities.\n\
788 Type \",help\" once in a Guile interactive session.")
789 #else /* HAVE_GUILE */
790 _("\
791 Evaluate a Guile expression.\n\
792 \n\
793 Guile scripting is not supported in this copy of GDB.\n\
794 This command is only a placeholder.")
795 #endif /* HAVE_GUILE */
796 );
797 add_com_alias ("gu", "guile", class_obscure, 1);
798
799 add_prefix_cmd ("guile", class_obscure, set_guile_command,
800 _("Prefix command for Guile preference settings."),
801 &set_guile_list, "set guile ", 0,
802 &setlist);
803 add_alias_cmd ("gu", "guile", class_obscure, 1, &setlist);
804
805 add_prefix_cmd ("guile", class_obscure, show_guile_command,
806 _("Prefix command for Guile preference settings."),
807 &show_guile_list, "show guile ", 0,
808 &showlist);
809 add_alias_cmd ("gu", "guile", class_obscure, 1, &showlist);
810
811 add_prefix_cmd ("guile", class_obscure, info_guile_command,
812 _("Prefix command for Guile info displays."),
813 &info_guile_list, "info guile ", 0,
814 &infolist);
815 add_info_alias ("gu", "guile", 1);
816
817 /* The name "print-stack" is carried over from Python.
818 A better name is "print-exception". */
819 add_setshow_enum_cmd ("print-stack", no_class, guile_print_excp_enums,
820 &gdbscm_print_excp, _("\
821 Set mode for Guile exception printing on error."), _("\
822 Show the mode of Guile exception printing on error."), _("\
823 none == no stack or message will be printed.\n\
824 full == a message and a stack will be printed.\n\
825 message == an error message without a stack will be printed."),
826 NULL, NULL,
827 &set_guile_list, &show_guile_list);
828 }
829
830 /* Provide a prototype to silence -Wmissing-prototypes. */
831 extern initialize_file_ftype _initialize_guile;
832
833 void
834 _initialize_guile (void)
835 {
836 char *msg;
837
838 install_gdb_commands ();
839
840 #if HAVE_GUILE
841 /* The Python support puts the C side in module "_gdb", leaving the Python
842 side to define module "gdb" which imports "_gdb". There is evidently no
843 similar convention in Guile so we skip this. */
844
845 /* PR 17185 There are problems with using libgc 7.4.0.
846 Copy over the workaround Guile uses (Guile is working around a different
847 problem, but the workaround is the same). */
848 #if (GC_VERSION_MAJOR == 7 && GC_VERSION_MINOR == 4 && GC_VERSION_MICRO == 0)
849 /* The bug is only known to appear with pthreads. We assume any system
850 using pthreads also uses setenv (and not putenv). That is why we don't
851 have a similar call to putenv here. */
852 #if defined (HAVE_SETENV)
853 setenv ("GC_MARKERS", "1", 1);
854 #endif
855 #endif
856
857 /* scm_with_guile is the most portable way to initialize Guile.
858 Plus we need to initialize the Guile support while in Guile mode
859 (e.g., called from within a call to scm_with_guile). */
860 scm_with_guile (call_initialize_gdb_module, NULL);
861
862 /* Set Guile's backtrace to match the "set guile print-stack" default.
863 [N.B. The two settings are still separate.]
864 But only do this after we've initialized Guile, it's nice to see a
865 backtrace if there's an error during initialization.
866 OTOH, if the error is that gdb/init.scm wasn't found because gdb is being
867 run from the build tree, the backtrace is more noise than signal.
868 Sigh. */
869 gdbscm_set_backtrace (0);
870 #endif
871 }
This page took 0.052888 seconds and 5 git commands to generate.