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