[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Enabling Debugging
From: |
Volkan YAZICI |
Subject: |
Enabling Debugging |
Date: |
Sat, 29 Jul 2006 14:30:34 +0300 |
User-agent: |
Mutt/1.4.2.1i |
Hi,
I'm trying to enable debbuging - that's (debug-enable 'backtrace) in
Scheme - from a C program on-the-fly. Therefore, as far as I
understand from the quite poorly documented guile manual, I should
use scm_debug_options() for this purpose. But I couldn't find any clue
about using this function in the neither manual, nor source code.
First, I tried sth like this:
static SCM
exception_handler(void *data, SCM tag, SCM throw_args)
{
const char *buf;
int len;
SCM scm;
printf("\nJust got an error; tag is: [%s] ", (char *) data);
buf = SCM_STRING_CHARS(tag);
len = SCM_STRING_LENGTH(tag);
while (len-- > 0)
putchar(*buf++);
printf("\nBacktrace:\n");
scm = scm_backtrace();
buf = SCM_STRING_CHARS(scm);
len = SCM_STRING_LENGTH(scm);
while (len-- > 0)
putchar(*buf++);
putchar('\n');
return SCM_BOOL_F;
}
static void
main_prog(int argc, char **argv)
{
SCM res;
scm_init_debug();
res = gh_eval_str_with_catch("(string? (number?))",
&exception_handler);
}
... and as you can imagine, it gave a segmentation fault in
"buf = SCM_STRING_CHARS(scm);" line. Then I tried to remove
scm_init_debug() call and mimic its behaviour like this with
no luck again:
/*
* When I rename below _scm_debug_opts into scm_debug_opts (without an
* underscore), it SegFaults in gh_enter().
*/
scm_t_option _scm_debug_opts[] = {
{SCM_OPTION_BOOLEAN, "breakpoints", 1,
"Check for breakpoints."},
{SCM_OPTION_BOOLEAN, "trace", 1,
"Trace mode."},
{SCM_OPTION_BOOLEAN, "procnames", 1,
"Record procedure names at definition."},
{SCM_OPTION_BOOLEAN, "backwards", 1,
"Display backtrace in anti-chronological order."},
{SCM_OPTION_INTEGER, "width", 79,
"Maximal width of backtrace."},
{SCM_OPTION_INTEGER, "indent", 10,
"Maximal indentation in backtrace."},
{SCM_OPTION_INTEGER, "frames", 3,
"Maximum number of tail-recursive frames in backtrace."},
{SCM_OPTION_INTEGER, "maxdepth", 1000,
"Maximal number of stored backtrace frames."},
{SCM_OPTION_INTEGER, "depth", 20,
"Maximal length of printed backtrace."},
{SCM_OPTION_BOOLEAN, "backtrace", 1,
"Show backtrace on error."},
{SCM_OPTION_BOOLEAN, "debug", 1,
"Use the debugging evaluator."},
{SCM_OPTION_INTEGER, "stack", 20000,
"Stack size limit (measured in words; 0 = no check)." },
{SCM_OPTION_SCM, "show-file-name", 1,
"Show file names and line numbers in backtraces when not `#f'."
"A value of `base' displays only base names, while `#t' "
"displays full names."},
{SCM_OPTION_BOOLEAN, "warn-deprecated", 0,
"Warn when deprecated features are used."}
};
#define SCM_N_DEBUG_OPTIONS 14
static void
main_prog(int argc, char **argv)
{
SCM res;
scm_init_opts(scm_debug_options,
_scm_debug_opts,
SCM_N_DEBUG_OPTIONS);
res = gh_eval_str_with_catch("(string? (number?))",
&exception_handler);
}
I'd be very appreciated if somebody can help me to figure out how to
enable/disable debugging on the fly. Also, comments and convention
suggestions about above used methods to catch all exceptions and
display them are welcome too.
Regards.
- Enabling Debugging,
Volkan YAZICI <=