* trouble with scm_display_backtrace in guile 1.8.3
@ 2008-02-04 10:30 René Köcher
2008-02-05 14:26 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: René Köcher @ 2008-02-04 10:30 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 2707 bytes --]
Hi,
as the subject states I encountered some problems while
trying to get a backtrace for a exception. I'm trying to embedd
guile into a C programm which should catch exceptions at
global scope and print usable error messages and backtraces.
After some searching I got to the code below which works fine
except for backtrace display.. (crashes with wrong-type-arg)
Any help on this is much appreciated, all samples and
documentation I found was targeted at guile 1.6...
======================================================================
#include <stdio.h>
#include <libguile.h>
void continue_init (void *data, int argc, char **argv);
SCM guile_catch_exception (SCM key, SCM args);
int
main (int argc, char **argv)
{
if (argc < 2)
{
fprintf(stderr, "%s 'scheme expression'\n", argv[0]);
return 1;
}
scm_boot_guile(argc, argv, 0);
return 0;
}
void
continue_init (void *data, int argc, char **argv)
{
/* NOTE: this is from a guile 1.6 solution but seems not to work */
/* enable backtraces */
SCM_DEVAL_P = 1;
SCM_BACKTRACE_P = 1;
SCM_RECORD_POSITONS_P = 1;
SCM_RESET_DEBUG_MODE;
/* eval and exit */
scm_internal_stack_catch(SCM_BOOL_T,
(scm_t_catch_body)scm_c_eval_string,
(void*)argv[1],
(scm_t_catch_handler)guile_catch_exception,
NULL);
}
SCM
guile_catch_exception (SCM key, SCM args)
{
if (scm_ilength(args) >= 3)
{
SCM stack = scm_fluid_ref(
SCM_VARIABLE_REF(scm_the_last_stack_fluid_var));
SCM subr = SCM_CAR(args);
SCM mesg = SCM_CADR(args);
SCM cargs = SCM_CADDR(args);
#if 1
/* FIXME: still wrong-type-arg error.. */
scm_display_backtrace(stack, scm_current_error_port(),
SCM_UNDEFINED, SCM_UNDEFINED);
#endif
scm_newline(scm_current_error_port());
scm_display_error(stack, scm_current_error_port(),
subr, mesg, cargs, SCM_EOL);
return SCM_BOOL_F;
}
else
{
scm_puts("E991: uncaught throw.",scm_current_error_port());
}
return SCM_BOOL_T;
}
======================================================================
----------------------------------------------------------------------
BitSpinn.org - Don't get twisted up!
----------------------------------------------------------------------
[-- Attachment #2: Type: text/html, Size: 5861 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: trouble with scm_display_backtrace in guile 1.8.3
2008-02-04 10:30 trouble with scm_display_backtrace in guile 1.8.3 René Köcher
@ 2008-02-05 14:26 ` Ludovic Courtès
2008-02-06 22:47 ` RenéKöcher
0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2008-02-05 14:26 UTC (permalink / raw)
To: guile-user
Hi,
(I must confess I'd be more comfortable with the same piece of code in
Scheme... Generally, I find it more convenient to have the boot code as
a Guile script which then loads all the relevant pieces of C code.
Scheme code is also less likely to break with future Guile versions.)
"René Köcher" <shirk87@googlemail.com> writes:
> SCM stack = scm_fluid_ref(
> SCM_VARIABLE_REF(scm_the_last_stack_fluid_var));
> SCM subr = SCM_CAR(args);
> SCM mesg = SCM_CADR(args);
> SCM cargs = SCM_CADDR(args);
> #if 1
> /* FIXME: still wrong-type-arg error.. */
> scm_display_backtrace(stack, scm_current_error_port(),
> SCM_UNDEFINED, SCM_UNDEFINED);
Presumably STACK is `#f' here, can you confirm it (e.g., by
`scm_write'ing it)? If so, then this means that `SCM_DEBUG_P' is
somehow not taken into account.
In theory, what you propose should work:
guile> (define (foo x)
(catch #t
(lambda () (error "sdf"))
(lambda args (fluid-ref the-last-stack))))
guile> (foo 2)
#<stack 8050fc0:b7a8dbf0>
As you can see, the error handler gets to see a valid stack when looking
at THE-LAST-STACK.
Thanks,
Ludovic.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: trouble with scm_display_backtrace in guile 1.8.3
2008-02-05 14:26 ` Ludovic Courtès
@ 2008-02-06 22:47 ` RenéKöcher
0 siblings, 0 replies; 3+ messages in thread
From: RenéKöcher @ 2008-02-06 22:47 UTC (permalink / raw)
To: guile-user
Ludovic Courtès <ludo <at> gnu.org> writes:
>
> Hi,
>
> (I must confess I'd be more comfortable with the same piece of code in
> Scheme... Generally, I find it more convenient to have the boot code as
> a Guile script which then loads all the relevant pieces of C code.
> Scheme code is also less likely to break with future Guile versions.)
I agree with you on this but I'm trying to integrate guile within the vim editor
and a extern scheme bootup file just won't fit in
(neither does embedded scheme source..).
>
> Presumably STACK is `#f' here, can you confirm it (e.g., by
> `scm_write'ing it)? If so, then this means that `SCM_DEBUG_P' is
> somehow not taken into account.
Seems that this _was_ the case but I got backtraces working now.
Sadly I'm not really sure about the 'how' and 'why'..
my ports partition crashed yesterday and so I had to reinstall
guile and allother macports packages and now my backtraces work
as expected... *weird*
Ϟ
But thanks anyway,
Shirk
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-02-06 22:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-04 10:30 trouble with scm_display_backtrace in guile 1.8.3 René Köcher
2008-02-05 14:26 ` Ludovic Courtès
2008-02-06 22:47 ` RenéKöcher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).