unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* 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

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).