Rewording for "make an intervention".
[bpt/guile.git] / libguile / backtrace.c
CommitLineData
ab4f3efb 1/* Printing of backtraces and error messages
c7c2d875 2 * Copyright (C) 1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2009, 2010, 2011 Free Software Foundation
ab4f3efb 3 *
73be1d9e 4 * This library is free software; you can redistribute it and/or
53befeb7
NJ
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 3 of
7 * the License, or (at your option) any later version.
ab4f3efb 8 *
53befeb7
NJ
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
ab4f3efb 13 *
73be1d9e
MV
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
53befeb7
NJ
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
73be1d9e 18 */
ab4f3efb 19
dbb605f5 20#ifdef HAVE_CONFIG_H
615873d2
RB
21# include <config.h>
22#endif
1bbd0b84 23
7beabedb 24#include <stdio.h>
2b407f9b
MD
25#include <ctype.h>
26
a0599745 27#include "libguile/_scm.h"
2fb36297 28
b1508ade
MD
29#ifdef HAVE_UNISTD_H
30#include <unistd.h>
31#endif
82893676
MG
32#ifdef HAVE_IO_H
33#include <io.h>
34#endif
b1508ade 35
218d580a 36#include "libguile/deprecation.h"
a0599745
MD
37#include "libguile/stacks.h"
38#include "libguile/srcprop.h"
39#include "libguile/struct.h"
40#include "libguile/strports.h"
41#include "libguile/throw.h"
42#include "libguile/fluids.h"
43#include "libguile/ports.h"
44#include "libguile/strings.h"
dfd03fb9 45#include "libguile/dynwind.h"
aa3f6951 46#include "libguile/frames.h"
ab4f3efb 47
a0599745
MD
48#include "libguile/validate.h"
49#include "libguile/backtrace.h"
fec097f0 50#include "libguile/filesys.h"
22fc179a 51#include "libguile/private-options.h"
ab4f3efb
MD
52
53/* {Error reporting and backtraces}
ab4f3efb
MD
54 *
55 * Note that these functions shouldn't generate errors themselves.
56 */
57
e8df456a
AW
58static SCM
59boot_print_exception (SCM port, SCM frame, SCM key, SCM args)
60#define FUNC_NAME "boot-print-exception"
61{
62 scm_puts ("Throw to key ", port);
63 scm_write (key, port);
64 scm_puts (" with args ", port);
65 scm_write (args, port);
66 return SCM_UNSPECIFIED;
67}
68#undef FUNC_NAME
69
70SCM
71scm_print_exception (SCM port, SCM frame, SCM key, SCM args)
72#define FUNC_NAME "print-exception"
73{
74 static SCM print_exception = SCM_BOOL_F;
75
76 SCM_VALIDATE_OPOUTPORT (1, port);
77 if (scm_is_true (frame))
78 SCM_VALIDATE_FRAME (2, frame);
79 SCM_VALIDATE_SYMBOL (3, key);
80 SCM_VALIDATE_LIST (4, args);
81
82 if (scm_is_false (print_exception))
9179e8a5
AW
83 print_exception =
84 scm_module_variable (scm_the_root_module (),
85 scm_from_latin1_symbol ("print-exception"));
e8df456a
AW
86
87 return scm_call_4 (scm_variable_ref (print_exception),
88 port, frame, key, args);
89}
90#undef FUNC_NAME
91
92
93\f
94
dfd03fb9
MD
95/* Print parameters for error messages. */
96
97#define DISPLAY_ERROR_MESSAGE_MAX_LEVEL 7
98#define DISPLAY_ERROR_MESSAGE_MAX_LENGTH 10
99
100/* Print parameters for failing expressions in error messages.
101 * (See also `print_params' below for backtrace print parameters.)
102 */
103
104#define DISPLAY_EXPRESSION_MAX_LEVEL 2
105#define DISPLAY_EXPRESSION_MAX_LENGTH 3
106
ab4f3efb
MD
107#undef SCM_ASSERT
108#define SCM_ASSERT(_cond, _arg, _pos, _subr) \
109 if (!(_cond)) \
110 return SCM_BOOL_F;
ab4f3efb 111
e8df456a 112
f3acc5c1 113void
6e8d25a6 114scm_display_error_message (SCM message, SCM args, SCM port)
ab4f3efb 115{
9ddf197e
AW
116 scm_print_exception (port, SCM_BOOL_F, scm_misc_error_key,
117 scm_list_3 (SCM_BOOL_F, message, args));
bdf8afff
MD
118}
119
e40a4095
DH
120
121/* The function scm_i_display_error prints out a detailed error message. This
122 * function will be called directly within libguile to signal error messages.
123 * No parameter checks will be performed by scm_i_display_error. Thus, User
124 * code should rather use the function scm_display_error.
125 */
126void
218d580a 127scm_i_display_error (SCM frame, SCM port, SCM subr, SCM message, SCM args, SCM rest)
bdf8afff 128{
9ddf197e
AW
129 scm_print_exception (port, frame, scm_misc_error_key,
130 scm_list_3 (subr, message, args));
e40a4095
DH
131}
132
133
134SCM_DEFINE (scm_display_error, "display-error", 6, 0, 0,
218d580a 135 (SCM frame, SCM port, SCM subr, SCM message, SCM args, SCM rest),
c73bdd3a 136 "Display an error message to the output port @var{port}.\n"
218d580a 137 "@var{frame} is the frame in which the error occurred, @var{subr} is\n"
bb2c02f2 138 "the name of the procedure in which the error occurred and\n"
c73bdd3a
MG
139 "@var{message} is the actual error message, which may contain\n"
140 "formatting instructions. These will format the arguments in\n"
141 "the list @var{args} accordingly. @var{rest} is currently\n"
142 "ignored.")
e40a4095
DH
143#define FUNC_NAME s_scm_display_error
144{
145 SCM_VALIDATE_OUTPUT_PORT (2, port);
146
218d580a 147 scm_i_display_error (frame, port, subr, message, args, rest);
e40a4095 148
ab4f3efb
MD
149 return SCM_UNSPECIFIED;
150}
1bbd0b84 151#undef FUNC_NAME
ab4f3efb 152
e40a4095 153
2b407f9b
MD
154typedef struct {
155 int level;
156 int length;
157} print_params_t;
158
159static int n_print_params = 9;
160static print_params_t default_print_params[] = {
161 { 4, 9 }, { 4, 3 },
162 { 3, 4 }, { 3, 3 },
163 { 2, 4 }, { 2, 3 },
164 { 1, 4 }, { 1, 3 }, { 1, 2 }
165};
166static print_params_t *print_params = default_print_params;
167
168#ifdef GUILE_DEBUG
3b3b36dd 169SCM_DEFINE (scm_set_print_params_x, "set-print-params!", 1, 0, 0,
5623a9b4 170 (SCM params),
c73bdd3a
MG
171 "Set the print parameters to the values from @var{params}.\n"
172 "@var{params} must be a list of two-element lists which must\n"
173 "hold two integer values.")
e8e9b690 174#define FUNC_NAME s_scm_set_print_params_x
2b407f9b 175{
3fceef59
MD
176 int i;
177 int n;
2b407f9b
MD
178 SCM ls;
179 print_params_t *new_params;
3fceef59
MD
180
181 SCM_VALIDATE_NONEMPTYLIST_COPYLEN (2, params, n);
c96d76b8 182 for (ls = params; !SCM_NULL_OR_NIL_P (ls); ls = SCM_CDR (ls))
2b407f9b 183 SCM_ASSERT (scm_ilength (SCM_CAR (params)) == 2
e11e83f3
MV
184 && scm_is_unsigned_integer (SCM_CAAR (ls), 0, INT_MAX)
185 && scm_is_unsigned_integer (SCM_CADAR (ls), 0, INT_MAX),
2b407f9b
MD
186 params,
187 SCM_ARG2,
e8e9b690 188 s_scm_set_print_params_x);
4c9419ac 189 new_params = scm_malloc (n * sizeof (print_params_t));
2b407f9b 190 if (print_params != default_print_params)
4c9419ac 191 free (print_params);
2b407f9b
MD
192 print_params = new_params;
193 for (i = 0; i < n; ++i)
194 {
e11e83f3
MV
195 print_params[i].level = scm_to_int (SCM_CAAR (params));
196 print_params[i].length = scm_to_int (SCM_CADAR (params));
2b407f9b
MD
197 params = SCM_CDR (params);
198 }
199 n_print_params = n;
200 return SCM_UNSPECIFIED;
201}
1bbd0b84 202#undef FUNC_NAME
2b407f9b
MD
203#endif
204
ab4f3efb 205static void
1bbd0b84 206indent (int n, SCM port)
ab4f3efb
MD
207{
208 int i;
209 for (i = 0; i < n; ++i)
b7f3516f 210 scm_putc (' ', port);
ab4f3efb
MD
211}
212
ab4f3efb 213static void
34d19ef6 214display_frame_expr (char *hdr, SCM exp, char *tlr, int indentation, SCM sport, SCM port, scm_print_state *pstate)
ab4f3efb 215{
2b407f9b 216 int i = 0, n;
92c2555f 217 scm_t_ptob_descriptor *ptob = scm_ptobs + SCM_PTOBNUM (sport);
2b407f9b 218 do
ab4f3efb 219 {
2b407f9b
MD
220 pstate->length = print_params[i].length;
221 ptob->seek (sport, 0, SEEK_SET);
d2e53ed6 222 if (scm_is_pair (exp))
2b407f9b
MD
223 {
224 pstate->level = print_params[i].level - 1;
225 scm_iprlist (hdr, exp, tlr[0], sport, pstate);
226 scm_puts (&tlr[1], sport);
227 }
228 else
229 {
230 pstate->level = print_params[i].level;
231 scm_iprin1 (exp, sport, pstate);
232 }
233 ptob->flush (sport);
234 n = ptob->seek (sport, 0, SEEK_CUR);
235 ++i;
ab4f3efb 236 }
2b407f9b
MD
237 while (indentation + n > SCM_BACKTRACE_WIDTH && i < n_print_params);
238 ptob->truncate (sport, n);
2b407f9b 239
22e47f69 240 scm_display (scm_strport_to_string (sport), port);
ab4f3efb
MD
241}
242
e3c37929 243static void
34d19ef6 244display_application (SCM frame, int indentation, SCM sport, SCM port, scm_print_state *pstate)
e3c37929 245{
aa3f6951 246 SCM proc = scm_frame_procedure (frame);
7888309b 247 SCM name = (scm_is_true (scm_procedure_p (proc))
e3c37929
MD
248 ? scm_procedure_name (proc)
249 : SCM_BOOL_F);
250 display_frame_expr ("[",
7888309b 251 scm_cons (scm_is_true (name) ? name : proc,
aa3f6951
AW
252 scm_frame_arguments (frame)),
253 "]",
e3c37929
MD
254 indentation,
255 sport,
256 port,
257 pstate);
258}
259
3b3b36dd 260SCM_DEFINE (scm_display_application, "display-application", 1, 2, 0,
1bbd0b84 261 (SCM frame, SCM port, SCM indent),
c73bdd3a
MG
262 "Display a procedure application @var{frame} to the output port\n"
263 "@var{port}. @var{indent} specifies the indentation of the\n"
264 "output.")
1bbd0b84 265#define FUNC_NAME s_scm_display_application
e3c37929 266{
34d19ef6 267 SCM_VALIDATE_FRAME (1, frame);
e3c37929 268 if (SCM_UNBNDP (port))
9de87eea 269 port = scm_current_output_port ();
2b407f9b 270 else
34d19ef6 271 SCM_VALIDATE_OPOUTPORT (2, port);
2b407f9b
MD
272 if (SCM_UNBNDP (indent))
273 indent = SCM_INUM0;
2b407f9b 274
aa3f6951
AW
275 /* Display an application. */
276 {
277 SCM sport, print_state;
278 scm_print_state *pstate;
e3c37929 279
aa3f6951
AW
280 /* Create a string port used for adaptation of printing parameters. */
281 sport = scm_mkstrport (SCM_INUM0,
282 scm_make_string (scm_from_int (240),
283 SCM_UNDEFINED),
284 SCM_OPN | SCM_WRTNG,
285 FUNC_NAME);
286
287 /* Create a print state for printing of frames. */
288 print_state = scm_make_print_state ();
289 pstate = SCM_PRINT_STATE (print_state);
290 pstate->writingp = 1;
291 pstate->fancyp = 1;
e3c37929 292
aa3f6951
AW
293 display_application (frame, scm_to_int (indent), sport, port, pstate);
294 return SCM_BOOL_T;
295 }
e3c37929 296}
1bbd0b84 297#undef FUNC_NAME
e3c37929 298
fec097f0
MV
299SCM_SYMBOL (sym_base, "base");
300
301static void
302display_backtrace_get_file_line (SCM frame, SCM *file, SCM *line)
303{
aa3f6951 304 SCM source = scm_frame_source (frame);
e052d296 305 *file = *line = SCM_BOOL_F;
b3f04491
AW
306 if (scm_is_pair (source)
307 && scm_is_pair (scm_cdr (source))
308 && scm_is_pair (scm_cddr (source))
309 && !scm_is_pair (scm_cdddr (source)))
e052d296 310 {
028e3d06
AW
311 /* (addr . (filename . (line . column))), from vm compilation */
312 *file = scm_cadr (source);
313 *line = scm_caddr (source);
e052d296 314 }
fec097f0
MV
315}
316
317static void
318display_backtrace_file (frame, last_file, port, pstate)
319 SCM frame;
320 SCM *last_file;
321 SCM port;
322 scm_print_state *pstate;
323{
324 SCM file, line;
325
326 display_backtrace_get_file_line (frame, &file, &line);
327
aa3f6951 328 if (scm_is_true (scm_equal_p (file, *last_file)))
fec097f0
MV
329 return;
330
331 *last_file = file;
332
333 scm_puts ("In ", port);
7888309b
MV
334 if (scm_is_false (file))
335 if (scm_is_false (line))
fec097f0
MV
336 scm_puts ("unknown file", port);
337 else
338 scm_puts ("current input", port);
339 else
340 {
341 pstate->writingp = 0;
342 scm_iprin1 (file, port, pstate);
343 pstate->writingp = 1;
344 }
345 scm_puts (":\n", port);
346}
347
348static void
349display_backtrace_file_and_line (SCM frame, SCM port, scm_print_state *pstate)
350{
351 SCM file, line;
352
353 display_backtrace_get_file_line (frame, &file, &line);
354
bc36d050 355 if (scm_is_eq (SCM_PACK (SCM_SHOW_FILE_NAME), sym_base))
fec097f0 356 {
7888309b 357 if (scm_is_false (file))
fec097f0 358 {
7888309b 359 if (scm_is_false (line))
fec097f0
MV
360 scm_putc ('?', port);
361 else
362 scm_puts ("<stdin>", port);
363 }
364 else
365 {
366 pstate -> writingp = 0;
4110fa69 367#ifdef HAVE_POSIX
3b9ee0a4
MV
368 scm_iprin1 ((scm_is_string (file)?
369 scm_basename (file, SCM_UNDEFINED) : file),
fec097f0 370 port, pstate);
4110fa69
MV
371#else
372 scm_iprin1 (file, port, pstate);
373#endif
fec097f0
MV
374 pstate -> writingp = 1;
375 }
376
377 scm_putc (':', port);
378 }
7888309b 379 else if (scm_is_true (line))
fec097f0
MV
380 {
381 int i, j=0;
e11e83f3 382 for (i = scm_to_int (line)+1; i > 0; i = i/10, j++)
fec097f0
MV
383 ;
384 indent (4-j, port);
385 }
386
7888309b 387 if (scm_is_false (line))
fec097f0
MV
388 scm_puts (" ?", port);
389 else
e11e83f3 390 scm_intprint (scm_to_int (line) + 1, 10, port);
fec097f0
MV
391 scm_puts (": ", port);
392}
393
ab4f3efb 394static void
aa3f6951
AW
395display_frame (SCM frame, int n, int nfield, int indentation,
396 SCM sport, SCM port, scm_print_state *pstate)
ab4f3efb 397{
aa3f6951 398 int i, j;
ab4f3efb 399
fec097f0 400 /* display file name and line number */
7888309b 401 if (scm_is_true (SCM_PACK (SCM_SHOW_FILE_NAME)))
fec097f0
MV
402 display_backtrace_file_and_line (frame, port, pstate);
403
ab4f3efb 404 /* Check size of frame number. */
ab4f3efb
MD
405 for (i = 0, j = n; j > 0; ++i) j /= 10;
406
407 /* Number indentation. */
408 indent (nfield - (i ? i : 1), port);
409
410 /* Frame number. */
93ccaef0 411 scm_iprin1 (scm_from_int (n), port, pstate);
ab4f3efb 412
ab4f3efb
MD
413 /* Indentation. */
414 indent (indentation, port);
415
aa3f6951
AW
416 /* Display an application. */
417 display_application (frame, nfield + 1 + indentation, sport, port, pstate);
1ae6af28 418 scm_putc ('\n', port);
ab4f3efb
MD
419}
420
bdf8afff
MD
421struct display_backtrace_args {
422 SCM stack;
423 SCM port;
424 SCM first;
425 SCM depth;
2b55be75 426 SCM highlight_objects;
bdf8afff
MD
427};
428
bdf8afff 429static SCM
5843e5c9 430display_backtrace_body (struct display_backtrace_args *a)
1bbd0b84 431#define FUNC_NAME "display_backtrace_body"
ab4f3efb
MD
432{
433 int n_frames, beg, end, n, i, j;
434 int nfield, indent_p, indentation;
435 SCM frame, sport, print_state;
fec097f0 436 SCM last_file;
ab4f3efb
MD
437 scm_print_state *pstate;
438
78446828
MV
439 a->port = SCM_COERCE_OUTPORT (a->port);
440
ab4f3efb 441 /* Argument checking and extraction. */
5843e5c9
DH
442 SCM_VALIDATE_STACK (1, a->stack);
443 SCM_VALIDATE_OPOUTPORT (2, a->port);
e11e83f3
MV
444 n_frames = scm_to_int (scm_stack_length (a->stack));
445 n = scm_is_integer (a->depth) ? scm_to_int (a->depth) : SCM_BACKTRACE_DEPTH;
ab4f3efb
MD
446 if (SCM_BACKWARDS_P)
447 {
e11e83f3 448 beg = scm_is_integer (a->first) ? scm_to_int (a->first) : 0;
ab4f3efb
MD
449 end = beg + n - 1;
450 if (end >= n_frames)
451 end = n_frames - 1;
452 n = end - beg + 1;
453 }
454 else
455 {
e11e83f3 456 if (scm_is_integer (a->first))
ab4f3efb 457 {
e11e83f3 458 beg = scm_to_int (a->first);
ab4f3efb
MD
459 end = beg - n + 1;
460 if (end < 0)
461 end = 0;
462 }
463 else
464 {
465 beg = n - 1;
466 end = 0;
467 if (beg >= n_frames)
468 beg = n_frames - 1;
469 }
470 n = beg - end + 1;
471 }
bdf8afff
MD
472 SCM_ASSERT (beg >= 0 && beg < n_frames, a->first, SCM_ARG3, s_display_backtrace);
473 SCM_ASSERT (n > 0, a->depth, SCM_ARG4, s_display_backtrace);
ab4f3efb
MD
474
475 /* Create a string port used for adaptation of printing parameters. */
476 sport = scm_mkstrport (SCM_INUM0,
93ccaef0 477 scm_make_string (scm_from_int (240), SCM_UNDEFINED),
ab4f3efb 478 SCM_OPN | SCM_WRTNG,
1bbd0b84 479 FUNC_NAME);
ab4f3efb
MD
480
481 /* Create a print state for printing of frames. */
482 print_state = scm_make_print_state ();
483 pstate = SCM_PRINT_STATE (print_state);
484 pstate->writingp = 1;
485 pstate->fancyp = 1;
2b55be75 486 pstate->highlight_objects = a->highlight_objects;
ab4f3efb
MD
487
488 /* First find out if it's reasonable to do indentation. */
aa3f6951 489 indent_p = 0;
ab4f3efb
MD
490
491 /* Determine size of frame number field. */
aa3f6951 492 j = end;
ab4f3efb
MD
493 for (i = 0; j > 0; ++i) j /= 10;
494 nfield = i ? i : 1;
495
ab4f3efb 496 /* Print frames. */
ab4f3efb 497 indentation = 1;
fec097f0 498 last_file = SCM_UNDEFINED;
aa3f6951
AW
499 if (SCM_BACKWARDS_P)
500 end++;
501 else
502 end--;
503 for (i = beg; i != end; SCM_BACKWARDS_P ? ++i : --i)
ab4f3efb 504 {
aa3f6951 505 frame = scm_stack_ref (a->stack, scm_from_int (i));
bc36d050 506 if (!scm_is_eq (SCM_PACK (SCM_SHOW_FILE_NAME), sym_base))
fec097f0 507 display_backtrace_file (frame, &last_file, a->port, pstate);
aa3f6951 508 display_frame (frame, i, nfield, indentation, sport, a->port, pstate);
ab4f3efb 509 }
bdf8afff 510
463b2219
ML
511 scm_remember_upto_here_1 (print_state);
512
bdf8afff
MD
513 return SCM_UNSPECIFIED;
514}
1bbd0b84 515#undef FUNC_NAME
bdf8afff 516
9ddf197e
AW
517static SCM
518error_during_backtrace (void *data, SCM tag, SCM throw_args)
519{
520 SCM port = PTR2SCM (data);
521
522 scm_puts ("Exception thrown while printing backtrace:\n", port);
523 scm_print_exception (port, SCM_BOOL_F, tag, throw_args);
524
525 return SCM_UNSPECIFIED;
526}
527
528
09c6d80a 529SCM_DEFINE (scm_display_backtrace_with_highlights, "display-backtrace", 2, 3, 0,
2b55be75 530 (SCM stack, SCM port, SCM first, SCM depth, SCM highlights),
b5944f66 531 "Display a backtrace to the output port @var{port}. @var{stack}\n"
c73bdd3a 532 "is the stack to take the backtrace from, @var{first} specifies\n"
b5944f66
NJ
533 "where in the stack to start and @var{depth} how many frames\n"
534 "to display. @var{first} and @var{depth} can be @code{#f},\n"
c648c681 535 "which means that default values will be used.\n"
b5944f66
NJ
536 "If @var{highlights} is given it should be a list; the elements\n"
537 "of this list will be highlighted wherever they appear in the\n"
538 "backtrace.")
2b55be75 539#define FUNC_NAME s_scm_display_backtrace_with_highlights
bdf8afff 540{
0b2cb4ee 541 struct display_backtrace_args a;
0b2cb4ee
MD
542 a.stack = stack;
543 a.port = port;
544 a.first = first;
545 a.depth = depth;
2b55be75
MV
546 if (SCM_UNBNDP (highlights))
547 a.highlight_objects = SCM_EOL;
548 else
549 a.highlight_objects = highlights;
9ddf197e 550
bdf8afff 551 scm_internal_catch (SCM_BOOL_T,
92c2555f 552 (scm_t_catch_body) display_backtrace_body, &a,
9ddf197e
AW
553 (scm_t_catch_handler) error_during_backtrace, SCM2PTR (port));
554
ab4f3efb
MD
555 return SCM_UNSPECIFIED;
556}
1bbd0b84 557#undef FUNC_NAME
ab4f3efb 558
2b55be75
MV
559SCM
560scm_display_backtrace (SCM stack, SCM port, SCM first, SCM depth)
561{
562 return scm_display_backtrace_with_highlights (stack, port, first, depth,
563 SCM_EOL);
564}
565
86d31dfe 566SCM_VARIABLE (scm_has_shown_backtrace_hint_p_var, "has-shown-backtrace-hint?");
5aab5d96 567
2b55be75
MV
568SCM_DEFINE (scm_backtrace_with_highlights, "backtrace", 0, 1, 0,
569 (SCM highlights),
ec16eb78
AW
570 "Display a backtrace of the current stack to the current\n"
571 "output port. If @var{highlights} is given, it should be\n"
572 "a list; the elements of this list will be highlighted\n"
573 "wherever they appear in the backtrace.")
2b55be75 574#define FUNC_NAME s_scm_backtrace_with_highlights
5aab5d96 575{
9de87eea 576 SCM port = scm_current_output_port ();
ec16eb78
AW
577 SCM stack = scm_make_stack (SCM_BOOL_T, SCM_EOL);
578
2b55be75
MV
579 if (SCM_UNBNDP (highlights))
580 highlights = SCM_EOL;
581
ec16eb78
AW
582 scm_newline (port);
583 scm_puts ("Backtrace:\n", port);
584 scm_display_backtrace_with_highlights (stack, port, SCM_BOOL_F, SCM_BOOL_F,
585 highlights);
586 scm_newline (port);
587
5aab5d96
MD
588 return SCM_UNSPECIFIED;
589}
1bbd0b84 590#undef FUNC_NAME
5aab5d96 591
2b55be75
MV
592SCM
593scm_backtrace (void)
594{
595 return scm_backtrace_with_highlights (SCM_EOL);
596}
597
ab4f3efb
MD
598\f
599
600void
601scm_init_backtrace ()
602{
e8df456a 603 scm_c_define_gsubr ("print-exception", 4, 0, 0, boot_print_exception);
a0599745 604#include "libguile/backtrace.x"
ab4f3efb 605}
89e00824
ML
606
607/*
608 Local Variables:
609 c-file-style: "gnu"
610 End:
611*/