unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Enabling Debugging
@ 2006-07-29 11:30 Volkan YAZICI
  2006-07-29 19:08 ` Clinton Ebadi
  0 siblings, 1 reply; 6+ messages in thread
From: Volkan YAZICI @ 2006-07-29 11:30 UTC (permalink / raw)


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.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enabling Debugging
  2006-07-29 11:30 Enabling Debugging Volkan YAZICI
@ 2006-07-29 19:08 ` Clinton Ebadi
  2006-07-31  7:13   ` Volkan YAZICI
  0 siblings, 1 reply; 6+ messages in thread
From: Clinton Ebadi @ 2006-07-29 19:08 UTC (permalink / raw)


Volkan YAZICI <yazicivo@ttnet.net.tr> writes:

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

You should be able to put something like:

	SCM_DEVAL_P = 1;
	SCM_RECORD_POSITIONS_P = 1;
	SCM_BACKTRACE_P = 1;
	SCM_RESET_DEBUG_MODE;

Into your real_main (the one passed to scm_boot_guile). This will give
you debug output similar to the default debugging repl.

-- 
http://unknownlamer.org
Jabber:clinton@hcoop.net AIM:unknownlamer IRC:unknown_lamer@fnode#hcoop
I'm just thinking aloud; isn't thinking allowed?
443E 4F1A E213 7C54 A306  E328 7601 A1F0 F403 574B


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enabling Debugging
  2006-07-29 19:08 ` Clinton Ebadi
@ 2006-07-31  7:13   ` Volkan YAZICI
  2006-07-31  9:53     ` dave
  0 siblings, 1 reply; 6+ messages in thread
From: Volkan YAZICI @ 2006-07-31  7:13 UTC (permalink / raw)
  Cc: guile-user

On Jul 29 03:08, Clinton Ebadi wrote:
> You should be able to put something like:
> 
> 	SCM_DEVAL_P = 1;
> 	SCM_RECORD_POSITIONS_P = 1;
> 	SCM_BACKTRACE_P = 1;
> 	SCM_RESET_DEBUG_MODE;
> 
> Into your real_main (the one passed to scm_boot_guile). This will give
> you debug output similar to the default debugging repl.

I tried placing above 4 lines just before calling gh_eval_str_with_catch(),
that's in the main_prog() invocated by gh_enter(). But scm_backtrace()
still complains about "No backtrace available". Any other ideas?

Also, may anybody suggest an example project that uses guile so I can
take a look at its source code for debugging related stuff.


Regards.

P.S. Using guile 1.6.7 supplied by Debian Sarge.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enabling Debugging
  2006-07-31  7:13   ` Volkan YAZICI
@ 2006-07-31  9:53     ` dave
  2006-08-01 10:46       ` Volkan YAZICI
  0 siblings, 1 reply; 6+ messages in thread
From: dave @ 2006-07-31  9:53 UTC (permalink / raw)
  Cc: Clinton Ebadi, guile-user

On Mon, 2006-07-31 at 10:13 +0300, Volkan YAZICI wrote:
> On Jul 29 03:08, Clinton Ebadi wrote:
> > You should be able to put something like:
> > 
> > 	SCM_DEVAL_P = 1;
> > 	SCM_RECORD_POSITIONS_P = 1;
> > 	SCM_BACKTRACE_P = 1;
> > 	SCM_RESET_DEBUG_MODE;
> > 
> > Into your real_main (the one passed to scm_boot_guile). This will give
> > you debug output similar to the default debugging repl.
> 
> I tried placing above 4 lines just before calling gh_eval_str_with_catch(),
> that's in the main_prog() invocated by gh_enter(). But scm_backtrace()
> still complains about "No backtrace available". Any other ideas?
> 
> Also, may anybody suggest an example project that uses guile so I can
> take a look at its source code for debugging related stuff.

Hi Volkan,

I had to work through this a while back, and the problem I had was that
there are two types of error handler callback - one is called before the
stack is unwound, the other after. If you only set the error callback
for after the unwind there is no stack to do the debugging...

I think you can call gh_eval_str_with_stack_saving_handler() or using
the scm interface you can call scm_c_catch() which allows you to specify
both handlers.

cheers,

dave




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enabling Debugging
  2006-07-31  9:53     ` dave
@ 2006-08-01 10:46       ` Volkan YAZICI
  2006-09-04  7:35         ` Neil Jerram
  0 siblings, 1 reply; 6+ messages in thread
From: Volkan YAZICI @ 2006-08-01 10:46 UTC (permalink / raw)
  Cc: Clinton Ebadi, guile-user

On Jul 31 10:53, dave wrote:
> I had to work through this a while back, and the problem I had was that
> there are two types of error handler callback - one is called before the
> stack is unwound, the other after. If you only set the error callback
> for after the unwind there is no stack to do the debugging...

Can you send an example working code snippet please?

> I think you can call gh_eval_str_with_stack_saving_handler() or using
> the scm interface you can call scm_c_catch() which allows you to specify
> both handlers.

AFAIK, gh_eval_str_with_stack_saving_handler() isn't present in the 1.6
release and it'd be better if my code would be able to run with 1.6
too. Therefore, I'll try to have same effect with scm_c_catch().

I've considered your "before the stack is unwound and the other after"
explanation and concluded with such a scm_c_catch() call:

  scm_c_catch(SCM_BOOL_T,                       /* tag */
             (scm_t_catch_body) eval_code,      /* body */
             (void *) code,                     /* body data */
             (scm_t_catch_handler) catch_err,   /* handler */
             (void *) code,                     /* handler data */
             (scm_t_catch_handler) unwind_catch,
             (void *) code);

But scm_backtrace(), that's placed in both catch_err() and
unwind_catch(), still complains that "No backtrace available".
(Placing that SCM_DEVAL_P = 1; ... SCM_RESET_DEBUG_MODE; stuff
doesn't affect anything too.)

Doesn't anybody have a working example code snippet? How did ppl achieve
to write so much programs using guile?

Furthermore, I've another problem: How do we receive information from
tag and args variables passed to exception handlers? I was using

  buf = SCM_STRING_CHARS(tag);
  len = SCM_STRING_LENGTH(tag);
  while (len-- > 0)
      putchar(*buf++);

method but, in the new 1.8 release it says that I'm using deprecated
functions. So how can get the pointer pointing to the related text
buffer? I cannot use gh_scm2newstr() in this situation, because it
allocates required buffer itself and just dumps an error to stderr
in case of a failure. Actually, I'm working on a shared memory segment
thus I don't want guile to make any memory allocations on its own.
Can I achieve such a functionality? (I want it to use palloc/pfree
instead of recent malloc/free calls.) Can a macro hack like

  #define malloc palloc
  #define free   pfree

solve that problem?

Moreover, as far as SCM_CONSP(args) says so, the third param (args)
passed to exception handlers is a cons. Despite I've tried some
gh_car(), gh_cdr() tricks, I couldn't manage to figure out how to use
that information too.

I'd be very very appreciated if anybody can help me to solve above
problems. (Pointers to existing projects that use guile are welcome
too.)


Regards.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enabling Debugging
  2006-08-01 10:46       ` Volkan YAZICI
@ 2006-09-04  7:35         ` Neil Jerram
  0 siblings, 0 replies; 6+ messages in thread
From: Neil Jerram @ 2006-09-04  7:35 UTC (permalink / raw)
  Cc: Clinton Ebadi, Guile Users

Volkan YAZICI <yazicivo@ttnet.net.tr> writes:

> On Jul 31 10:53, dave wrote:
>> I had to work through this a while back, and the problem I had was that
>> there are two types of error handler callback - one is called before the
>> stack is unwound, the other after. If you only set the error callback
>> for after the unwind there is no stack to do the debugging...
>
> Can you send an example working code snippet please?

You've probably seen the new doc on this subject that I posted to the
guile list a few days ago.  This is also now in the CVS reference
manual (node "Debug on Error"), and I hope that it answers most of
your questions; please let me know if not.

> I've considered your "before the stack is unwound and the other after"
> explanation and concluded with such a scm_c_catch() call:
>
>   scm_c_catch(SCM_BOOL_T,                       /* tag */
>              (scm_t_catch_body) eval_code,      /* body */
>              (void *) code,                     /* body data */
>              (scm_t_catch_handler) catch_err,   /* handler */
>              (void *) code,                     /* handler data */
>              (scm_t_catch_handler) unwind_catch,
>              (void *) code);
>
> But scm_backtrace(), that's placed in both catch_err() and
> unwind_catch(), still complains that "No backtrace available".

Yes; this is because the stack still needs to be captured explicitly
by a scm_make_stack call, within unwind_catch.

> Doesn't anybody have a working example code snippet? How did ppl achieve
> to write so much programs using guile?

I personally like to write as much as possible in Scheme, so I'm
afraid I don't have a tested example.

(In other words, I make a single call out from C to Scheme, using
scm_call or scm_apply, then code whatever exception handling I need
in Scheme, within the function that was called from C.)

> Furthermore, I've another problem: How do we receive information from
> tag and args variables passed to exception handlers? I was using
>
>   buf = SCM_STRING_CHARS(tag);
>   len = SCM_STRING_LENGTH(tag);
>   while (len-- > 0)
>       putchar(*buf++);
>
> method but, in the new 1.8 release it says that I'm using deprecated
> functions. So how can get the pointer pointing to the related text
> buffer? I cannot use gh_scm2newstr() in this situation, because it
> allocates required buffer itself and just dumps an error to stderr
> in case of a failure. Actually, I'm working on a shared memory segment
> thus I don't want guile to make any memory allocations on its own.
> Can I achieve such a functionality? (I want it to use palloc/pfree
> instead of recent malloc/free calls.) Can a macro hack like
>
>   #define malloc palloc
>   #define free   pfree
>
> solve that problem?

The tag is actually a symbol.  What do you want to do with it?  If you
want to test it for equality (with scm_misc_error_key, for example),
use "scm_is_eq (tag, scm_misc_error_key)".  If you want to print it
out to the current output port, use "scm_display (tag,
SCM_UNDEFINED)".

> Moreover, as far as SCM_CONSP(args) says so, the third param (args)
> passed to exception handlers is a cons. Despite I've tried some
> gh_car(), gh_cdr() tricks, I couldn't manage to figure out how to use
> that information too.

This - i.e. knowing how to interpret exception args - is an ongoing
problem.  Please see and contribute to the discussion in another
thread.

Regards,
     Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-09-04  7:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-29 11:30 Enabling Debugging Volkan YAZICI
2006-07-29 19:08 ` Clinton Ebadi
2006-07-31  7:13   ` Volkan YAZICI
2006-07-31  9:53     ` dave
2006-08-01 10:46       ` Volkan YAZICI
2006-09-04  7:35         ` Neil Jerram

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