| 1 | /* Printing of backtraces and error messages |
| 2 | * Copyright (C) 1996,1997 Free Software Foundation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2, or (at your option) |
| 7 | * any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; see the file COPYING. If not, write to |
| 16 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 17 | * Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | * As a special exception, the Free Software Foundation gives permission |
| 20 | * for additional uses of the text contained in its release of GUILE. |
| 21 | * |
| 22 | * The exception is that, if you link the GUILE library with other files |
| 23 | * to produce an executable, this does not by itself cause the |
| 24 | * resulting executable to be covered by the GNU General Public License. |
| 25 | * Your use of that executable is in no way restricted on account of |
| 26 | * linking the GUILE library code into it. |
| 27 | * |
| 28 | * This exception does not however invalidate any other reasons why |
| 29 | * the executable file might be covered by the GNU General Public License. |
| 30 | * |
| 31 | * This exception applies only to the code released by the |
| 32 | * Free Software Foundation under the name GUILE. If you copy |
| 33 | * code from other Free Software Foundation releases into a copy of |
| 34 | * GUILE, as the General Public License permits, the exception does |
| 35 | * not apply to the code that you add in this way. To avoid misleading |
| 36 | * anyone as to the status of such modified files, you must delete |
| 37 | * this exception notice from them. |
| 38 | * |
| 39 | * If you write modifications of your own for GUILE, it is your choice |
| 40 | * whether to permit this exception to apply to your modifications. |
| 41 | * If you do not wish that, delete this exception notice. |
| 42 | * |
| 43 | * The author can be reached at djurfeldt@nada.kth.se |
| 44 | * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */ |
| 45 | |
| 46 | #include <stdio.h> |
| 47 | #include "_scm.h" |
| 48 | #include "stacks.h" |
| 49 | #include "srcprop.h" |
| 50 | #include "genio.h" |
| 51 | #include "struct.h" |
| 52 | #include "strports.h" |
| 53 | #include "throw.h" |
| 54 | |
| 55 | #include "backtrace.h" |
| 56 | |
| 57 | /* {Error reporting and backtraces} |
| 58 | * (A first approximation.) |
| 59 | * |
| 60 | * Note that these functions shouldn't generate errors themselves. |
| 61 | */ |
| 62 | |
| 63 | #ifndef SCM_RECKLESS |
| 64 | #undef SCM_ASSERT |
| 65 | #define SCM_ASSERT(_cond, _arg, _pos, _subr) \ |
| 66 | if (!(_cond)) \ |
| 67 | return SCM_BOOL_F; |
| 68 | #endif |
| 69 | |
| 70 | static void display_header SCM_P ((SCM source, SCM port)); |
| 71 | static void |
| 72 | display_header (source, port) |
| 73 | SCM source; |
| 74 | SCM port; |
| 75 | { |
| 76 | SCM fname = (SCM_NIMP (source) && SCM_MEMOIZEDP (source) |
| 77 | ? scm_source_property (source, scm_i_filename) |
| 78 | : SCM_BOOL_F); |
| 79 | if (SCM_NIMP (fname) && SCM_STRINGP (fname)) |
| 80 | { |
| 81 | scm_prin1 (fname, port, 0); |
| 82 | scm_putc (':', port); |
| 83 | scm_prin1 (scm_source_property (source, scm_i_line), port, 0); |
| 84 | scm_putc (':', port); |
| 85 | scm_prin1 (scm_source_property (source, scm_i_column), port, 0); |
| 86 | } |
| 87 | else |
| 88 | scm_puts ("ERROR", port); |
| 89 | scm_puts (": ", port); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | void |
| 94 | scm_display_error_message (message, args, port) |
| 95 | SCM message; |
| 96 | SCM args; |
| 97 | SCM port; |
| 98 | { |
| 99 | int writingp; |
| 100 | char *start; |
| 101 | char *p; |
| 102 | |
| 103 | if (SCM_IMP (message) || !SCM_ROSTRINGP (message) || SCM_IMP (args) |
| 104 | || !scm_list_p (args)) |
| 105 | { |
| 106 | scm_prin1 (message, port, 0); |
| 107 | scm_putc ('\n', port); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | SCM_COERCE_SUBSTR (message); |
| 112 | start = SCM_ROCHARS (message); |
| 113 | for (p = start; *p != '\0'; ++p) |
| 114 | if (*p == '%') |
| 115 | { |
| 116 | if (SCM_IMP (args) || SCM_NCONSP (args)) |
| 117 | continue; |
| 118 | |
| 119 | ++p; |
| 120 | if (*p == 's') |
| 121 | writingp = 0; |
| 122 | else if (*p == 'S') |
| 123 | writingp = 1; |
| 124 | else |
| 125 | continue; |
| 126 | |
| 127 | scm_lfwrite (start, p - start - 1, port); |
| 128 | scm_prin1 (SCM_CAR (args), port, writingp); |
| 129 | args = SCM_CDR (args); |
| 130 | start = p + 1; |
| 131 | } |
| 132 | scm_lfwrite (start, p - start, port); |
| 133 | scm_putc ('\n', port); |
| 134 | } |
| 135 | |
| 136 | static void display_expression SCM_P ((SCM frame, SCM pname, SCM source, SCM port)); |
| 137 | static void |
| 138 | display_expression (frame, pname, source, port) |
| 139 | SCM frame; |
| 140 | SCM pname; |
| 141 | SCM source; |
| 142 | SCM port; |
| 143 | { |
| 144 | SCM print_state = scm_make_print_state (); |
| 145 | scm_print_state *pstate = SCM_PRINT_STATE (print_state); |
| 146 | pstate->writingp = 0; |
| 147 | pstate->fancyp = 1; |
| 148 | pstate->level = 2; |
| 149 | pstate->length = 3; |
| 150 | if (SCM_NIMP (pname) && SCM_ROSTRINGP (pname)) |
| 151 | { |
| 152 | if (SCM_NIMP (frame) |
| 153 | && SCM_FRAMEP (frame) |
| 154 | && SCM_FRAME_EVAL_ARGS_P (frame)) |
| 155 | scm_puts ("While evaluating arguments to ", port); |
| 156 | else |
| 157 | scm_puts ("In procedure ", port); |
| 158 | scm_iprin1 (pname, port, pstate); |
| 159 | if (SCM_NIMP (source) && SCM_MEMOIZEDP (source)) |
| 160 | { |
| 161 | scm_puts (" in expression ", port); |
| 162 | pstate->writingp = 1; |
| 163 | scm_iprin1 (scm_unmemoize (source), port, pstate); |
| 164 | } |
| 165 | } |
| 166 | else if (SCM_NIMP (source)) |
| 167 | { |
| 168 | scm_puts ("In expression ", port); |
| 169 | pstate->writingp = 1; |
| 170 | scm_iprin1 (scm_unmemoize (source), port, pstate); |
| 171 | } |
| 172 | scm_puts (":\n", port); |
| 173 | scm_free_print_state (print_state); |
| 174 | } |
| 175 | |
| 176 | struct display_error_args { |
| 177 | SCM stack; |
| 178 | SCM port; |
| 179 | SCM subr; |
| 180 | SCM message; |
| 181 | SCM args; |
| 182 | SCM rest; |
| 183 | }; |
| 184 | |
| 185 | static SCM |
| 186 | display_error_body (struct display_error_args *a, SCM jmpbuf) |
| 187 | { |
| 188 | SCM current_frame = SCM_BOOL_F; |
| 189 | SCM source = SCM_BOOL_F; |
| 190 | SCM pname = SCM_BOOL_F; |
| 191 | if (SCM_DEBUGGINGP |
| 192 | && SCM_NIMP (a->stack) |
| 193 | && SCM_STACKP (a->stack) |
| 194 | && SCM_STACK_LENGTH (a->stack) > 0) |
| 195 | { |
| 196 | current_frame = scm_stack_ref (a->stack, SCM_INUM0); |
| 197 | source = SCM_FRAME_SOURCE (current_frame); |
| 198 | if (!(SCM_NIMP (source) && SCM_MEMOIZEDP (source))) |
| 199 | source = SCM_FRAME_SOURCE (SCM_FRAME_PREV (current_frame)); |
| 200 | if (SCM_FRAME_PROC_P (current_frame) |
| 201 | && scm_procedure_p (SCM_FRAME_PROC (current_frame)) == SCM_BOOL_T) |
| 202 | pname = scm_procedure_name (SCM_FRAME_PROC (current_frame)); |
| 203 | } |
| 204 | if (!(SCM_NIMP (pname) && SCM_ROSTRINGP (pname))) |
| 205 | pname = a->subr; |
| 206 | if ((SCM_NIMP (source) && SCM_MEMOIZEDP (source)) |
| 207 | || (SCM_NIMP (pname) && SCM_ROSTRINGP (pname))) |
| 208 | { |
| 209 | display_header (source, a->port); |
| 210 | display_expression (current_frame, pname, source, a->port); |
| 211 | } |
| 212 | display_header (source, a->port); |
| 213 | scm_display_error_message (a->message, a->args, a->port); |
| 214 | return SCM_UNSPECIFIED; |
| 215 | } |
| 216 | |
| 217 | struct display_error_handler_data { |
| 218 | char *mode; |
| 219 | SCM port; |
| 220 | }; |
| 221 | |
| 222 | /* This is the exception handler for error reporting routines. |
| 223 | Note that it is very important that this handler *doesn't* try to |
| 224 | print more than the error tag, since the error very probably is |
| 225 | caused by an erroneous print call-back routine. If we would |
| 226 | tru to print all objects, we would enter an infinite loop. */ |
| 227 | static SCM |
| 228 | display_error_handler (struct display_error_handler_data *data, |
| 229 | SCM tag, SCM args) |
| 230 | { |
| 231 | SCM print_state = scm_make_print_state (); |
| 232 | scm_puts ("\nException during displaying of ", data->port); |
| 233 | scm_puts (data->mode, data->port); |
| 234 | scm_puts (": ", data->port); |
| 235 | scm_iprin1 (tag, data->port, SCM_PRINT_STATE (print_state)); |
| 236 | scm_putc ('\n', data->port); |
| 237 | return SCM_UNSPECIFIED; |
| 238 | } |
| 239 | |
| 240 | SCM_PROC(s_display_error, "display-error", 6, 0, 0, scm_display_error); |
| 241 | SCM |
| 242 | scm_display_error (stack, port, subr, message, args, rest) |
| 243 | SCM stack; |
| 244 | SCM port; |
| 245 | SCM subr; |
| 246 | SCM message; |
| 247 | SCM args; |
| 248 | SCM rest; |
| 249 | { |
| 250 | struct display_error_args a = { stack, port, subr, message, args, rest }; |
| 251 | struct display_error_handler_data data = { "error", port }; |
| 252 | scm_internal_catch (SCM_BOOL_T, |
| 253 | (scm_catch_body_t) display_error_body, &a, |
| 254 | (scm_catch_handler_t) display_error_handler, &data); |
| 255 | return SCM_UNSPECIFIED; |
| 256 | } |
| 257 | |
| 258 | static void indent SCM_P ((int n, SCM port)); |
| 259 | static void |
| 260 | indent (n, port) |
| 261 | int n; |
| 262 | SCM port; |
| 263 | { |
| 264 | int i; |
| 265 | for (i = 0; i < n; ++i) |
| 266 | scm_putc (' ', port); |
| 267 | } |
| 268 | |
| 269 | static void display_frame_expr SCM_P ((char *hdr, SCM exp, char *tlr, int indentation, SCM sport, SCM port, scm_print_state *pstate)); |
| 270 | static void |
| 271 | display_frame_expr (hdr, exp, tlr, indentation, sport, port, pstate) |
| 272 | char *hdr; |
| 273 | SCM exp; |
| 274 | char *tlr; |
| 275 | int indentation; |
| 276 | SCM sport; |
| 277 | SCM port; |
| 278 | scm_print_state *pstate; |
| 279 | { |
| 280 | if (SCM_NIMP (exp) && SCM_CONSP (exp)) |
| 281 | { |
| 282 | scm_iprlist (hdr, exp, tlr[0], port, pstate); |
| 283 | scm_puts (&tlr[1], port); |
| 284 | } |
| 285 | else |
| 286 | scm_iprin1 (exp, port, pstate); |
| 287 | scm_putc ('\n', port); |
| 288 | } |
| 289 | |
| 290 | static void display_application SCM_P ((SCM frame, int indentation, SCM sport, SCM port, scm_print_state *pstate)); |
| 291 | static void |
| 292 | display_application (frame, indentation, sport, port, pstate) |
| 293 | SCM frame; |
| 294 | int indentation; |
| 295 | SCM sport; |
| 296 | SCM port; |
| 297 | scm_print_state *pstate; |
| 298 | { |
| 299 | SCM proc = SCM_FRAME_PROC (frame); |
| 300 | SCM name = (SCM_NFALSEP (scm_procedure_p (proc)) |
| 301 | ? scm_procedure_name (proc) |
| 302 | : SCM_BOOL_F); |
| 303 | display_frame_expr ("[", |
| 304 | scm_cons (SCM_NFALSEP (name) ? name : proc, |
| 305 | SCM_FRAME_ARGS (frame)), |
| 306 | SCM_FRAME_EVAL_ARGS_P (frame) ? " ..." : "]", |
| 307 | indentation, |
| 308 | sport, |
| 309 | port, |
| 310 | pstate); |
| 311 | } |
| 312 | |
| 313 | SCM_PROC(s_display_application, "display-application", 1, 1, 0, scm_display_application); |
| 314 | |
| 315 | SCM |
| 316 | scm_display_application (SCM frame, SCM port) |
| 317 | { |
| 318 | if (SCM_UNBNDP (port)) |
| 319 | port = scm_cur_outp; |
| 320 | if (SCM_FRAME_PROC_P (frame)) |
| 321 | /* Display an application. */ |
| 322 | { |
| 323 | SCM print_state; |
| 324 | scm_print_state *pstate; |
| 325 | |
| 326 | /* Create a print state for printing of frames. */ |
| 327 | print_state = scm_make_print_state (); |
| 328 | pstate = SCM_PRINT_STATE (print_state); |
| 329 | pstate->writingp = 1; |
| 330 | pstate->fancyp = 1; |
| 331 | pstate->level = 2; |
| 332 | pstate->length = 9; |
| 333 | |
| 334 | display_application (frame, 0, SCM_BOOL_F, port, pstate); /*fixme*/ |
| 335 | return SCM_BOOL_T; |
| 336 | } |
| 337 | else |
| 338 | return SCM_BOOL_F; |
| 339 | } |
| 340 | |
| 341 | static void display_frame SCM_P ((SCM frame, int nfield, int indentation, SCM sport, SCM port, scm_print_state *pstate)); |
| 342 | static void |
| 343 | display_frame (frame, nfield, indentation, sport, port, pstate) |
| 344 | SCM frame; |
| 345 | int nfield; |
| 346 | int indentation; |
| 347 | SCM sport; |
| 348 | SCM port; |
| 349 | scm_print_state *pstate; |
| 350 | { |
| 351 | int n, i, j; |
| 352 | |
| 353 | /* Announce missing frames? */ |
| 354 | if (!SCM_BACKWARDS_P && SCM_FRAME_OVERFLOW_P (frame)) |
| 355 | { |
| 356 | indent (nfield + 1 + indentation, port); |
| 357 | scm_puts ("...\n", port); |
| 358 | } |
| 359 | |
| 360 | /* Check size of frame number. */ |
| 361 | n = SCM_FRAME_NUMBER (frame); |
| 362 | for (i = 0, j = n; j > 0; ++i) j /= 10; |
| 363 | |
| 364 | /* Number indentation. */ |
| 365 | indent (nfield - (i ? i : 1), port); |
| 366 | |
| 367 | /* Frame number. */ |
| 368 | scm_iprin1 (SCM_MAKINUM (n), port, pstate); |
| 369 | |
| 370 | /* Real frame marker */ |
| 371 | scm_putc (SCM_FRAME_REAL_P (frame) ? '*' : ' ', port); |
| 372 | |
| 373 | /* Indentation. */ |
| 374 | indent (indentation, port); |
| 375 | |
| 376 | if (SCM_FRAME_PROC_P (frame)) |
| 377 | /* Display an application. */ |
| 378 | display_application (frame, nfield + 1 + indentation, sport, port, pstate); |
| 379 | else |
| 380 | /* Display a special form. */ |
| 381 | { |
| 382 | SCM source = SCM_FRAME_SOURCE (frame); |
| 383 | SCM copy = scm_source_property (source, scm_i_copy); |
| 384 | display_frame_expr ("(", |
| 385 | SCM_NIMP (copy) && SCM_CONSP (copy) |
| 386 | ? copy |
| 387 | : scm_unmemoize (source), |
| 388 | ")", |
| 389 | nfield + 1 + indentation, |
| 390 | sport, |
| 391 | port, |
| 392 | pstate); |
| 393 | } |
| 394 | |
| 395 | /* Announce missing frames? */ |
| 396 | if (SCM_BACKWARDS_P && SCM_FRAME_OVERFLOW_P (frame)) |
| 397 | { |
| 398 | indent (nfield + 1 + indentation, port); |
| 399 | scm_puts ("...\n", port); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | struct display_backtrace_args { |
| 404 | SCM stack; |
| 405 | SCM port; |
| 406 | SCM first; |
| 407 | SCM depth; |
| 408 | }; |
| 409 | |
| 410 | SCM_PROC(s_display_backtrace, "display-backtrace", 2, 2, 0, scm_display_backtrace); |
| 411 | |
| 412 | static SCM |
| 413 | display_backtrace_body (struct display_backtrace_args *a, SCM jmpbuf) |
| 414 | { |
| 415 | int n_frames, beg, end, n, i, j; |
| 416 | int nfield, indent_p, indentation; |
| 417 | SCM frame, sport, print_state; |
| 418 | scm_print_state *pstate; |
| 419 | |
| 420 | a->port = SCM_COERCE_OUTPORT (a->port); |
| 421 | |
| 422 | /* Argument checking and extraction. */ |
| 423 | SCM_ASSERT (SCM_NIMP (a->stack) && SCM_STACKP (a->stack), |
| 424 | a->stack, |
| 425 | SCM_ARG1, |
| 426 | s_display_backtrace); |
| 427 | SCM_ASSERT (SCM_NIMP (a->port) && SCM_OPOUTPORTP (a->port), |
| 428 | a->port, |
| 429 | SCM_ARG2, |
| 430 | s_display_backtrace); |
| 431 | n_frames = SCM_INUM (scm_stack_length (a->stack)); |
| 432 | n = SCM_INUMP (a->depth) ? SCM_INUM (a->depth) : SCM_BACKTRACE_DEPTH; |
| 433 | if (SCM_BACKWARDS_P) |
| 434 | { |
| 435 | beg = SCM_INUMP (a->first) ? SCM_INUM (a->first) : 0; |
| 436 | end = beg + n - 1; |
| 437 | if (end >= n_frames) |
| 438 | end = n_frames - 1; |
| 439 | n = end - beg + 1; |
| 440 | } |
| 441 | else |
| 442 | { |
| 443 | if (SCM_INUMP (a->first)) |
| 444 | { |
| 445 | beg = SCM_INUM (a->first); |
| 446 | end = beg - n + 1; |
| 447 | if (end < 0) |
| 448 | end = 0; |
| 449 | } |
| 450 | else |
| 451 | { |
| 452 | beg = n - 1; |
| 453 | end = 0; |
| 454 | if (beg >= n_frames) |
| 455 | beg = n_frames - 1; |
| 456 | } |
| 457 | n = beg - end + 1; |
| 458 | } |
| 459 | SCM_ASSERT (beg >= 0 && beg < n_frames, a->first, SCM_ARG3, s_display_backtrace); |
| 460 | SCM_ASSERT (n > 0, a->depth, SCM_ARG4, s_display_backtrace); |
| 461 | |
| 462 | /* Create a string port used for adaptation of printing parameters. */ |
| 463 | sport = scm_mkstrport (SCM_INUM0, |
| 464 | scm_make_string (SCM_MAKINUM (240), SCM_UNDEFINED), |
| 465 | SCM_OPN | SCM_WRTNG, |
| 466 | s_display_backtrace); |
| 467 | |
| 468 | /* Create a print state for printing of frames. */ |
| 469 | print_state = scm_make_print_state (); |
| 470 | pstate = SCM_PRINT_STATE (print_state); |
| 471 | pstate->writingp = 1; |
| 472 | pstate->fancyp = 1; |
| 473 | pstate->level = 2; |
| 474 | pstate->length = 3; |
| 475 | |
| 476 | /* First find out if it's reasonable to do indentation. */ |
| 477 | if (SCM_BACKWARDS_P) |
| 478 | indent_p = 0; |
| 479 | else |
| 480 | { |
| 481 | indent_p = 1; |
| 482 | frame = scm_stack_ref (a->stack, SCM_MAKINUM (beg)); |
| 483 | for (i = 0, j = 0; i < n; ++i) |
| 484 | { |
| 485 | if (SCM_FRAME_REAL_P (frame)) |
| 486 | ++j; |
| 487 | if (j > SCM_BACKTRACE_INDENT) |
| 488 | { |
| 489 | indent_p = 0; |
| 490 | break; |
| 491 | } |
| 492 | frame = (SCM_BACKWARDS_P |
| 493 | ? SCM_FRAME_PREV (frame) |
| 494 | : SCM_FRAME_NEXT (frame)); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /* Determine size of frame number field. */ |
| 499 | j = SCM_FRAME_NUMBER (scm_stack_ref (a->stack, SCM_MAKINUM (end))); |
| 500 | for (i = 0; j > 0; ++i) j /= 10; |
| 501 | nfield = i ? i : 1; |
| 502 | |
| 503 | scm_puts ("Backtrace:\n", a->port); |
| 504 | |
| 505 | /* Print frames. */ |
| 506 | frame = scm_stack_ref (a->stack, SCM_MAKINUM (beg)); |
| 507 | indentation = 1; |
| 508 | display_frame (frame, nfield, indentation, sport, a->port, pstate); |
| 509 | for (i = 1; i < n; ++i) |
| 510 | { |
| 511 | if (indent_p && SCM_FRAME_EVAL_ARGS_P (frame)) |
| 512 | ++indentation; |
| 513 | frame = SCM_BACKWARDS_P ? SCM_FRAME_PREV (frame) : SCM_FRAME_NEXT (frame); |
| 514 | display_frame (frame, nfield, indentation, sport, a->port, pstate); |
| 515 | } |
| 516 | |
| 517 | return SCM_UNSPECIFIED; |
| 518 | } |
| 519 | |
| 520 | SCM |
| 521 | scm_display_backtrace (stack, port, first, depth) |
| 522 | SCM stack; |
| 523 | SCM port; |
| 524 | SCM first; |
| 525 | SCM depth; |
| 526 | { |
| 527 | struct display_backtrace_args a = { stack, port, first, depth }; |
| 528 | struct display_error_handler_data data = { "backtrace", port }; |
| 529 | scm_internal_catch (SCM_BOOL_T, |
| 530 | (scm_catch_body_t) display_backtrace_body, &a, |
| 531 | (scm_catch_handler_t) display_error_handler, &data); |
| 532 | return SCM_UNSPECIFIED; |
| 533 | } |
| 534 | |
| 535 | SCM_VCELL (scm_has_shown_backtrace_hint_p_var, "has-shown-backtrace-hint?"); |
| 536 | |
| 537 | SCM_PROC(s_backtrace, "backtrace", 0, 0, 0, scm_backtrace); |
| 538 | SCM |
| 539 | scm_backtrace () |
| 540 | { |
| 541 | if (SCM_NFALSEP (SCM_CDR (scm_the_last_stack_var))) |
| 542 | { |
| 543 | scm_newline (scm_cur_outp); |
| 544 | scm_display_backtrace (SCM_CDR (scm_the_last_stack_var), |
| 545 | scm_cur_outp, |
| 546 | SCM_UNDEFINED, |
| 547 | SCM_UNDEFINED); |
| 548 | scm_newline (scm_cur_outp); |
| 549 | if (SCM_FALSEP (SCM_CDR (scm_has_shown_backtrace_hint_p_var)) |
| 550 | && !SCM_BACKTRACE_P) |
| 551 | { |
| 552 | scm_puts ("Type \"(debug-enable 'backtrace)\" if you would like " |
| 553 | "a backtrace\n" |
| 554 | "automatically if an error occurs in the future.\n", |
| 555 | scm_cur_outp); |
| 556 | SCM_SETCDR (scm_has_shown_backtrace_hint_p_var, SCM_BOOL_T); |
| 557 | } |
| 558 | } |
| 559 | else |
| 560 | { |
| 561 | scm_puts ("No backtrace available.\n", scm_cur_outp); |
| 562 | } |
| 563 | return SCM_UNSPECIFIED; |
| 564 | } |
| 565 | |
| 566 | \f |
| 567 | |
| 568 | void |
| 569 | scm_init_backtrace () |
| 570 | { |
| 571 | scm_the_last_stack_var = scm_sysintern ("the-last-stack", SCM_BOOL_F); |
| 572 | |
| 573 | #include "backtrace.x" |
| 574 | } |