unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: saving and restoring the error stack trace
@ 2006-08-29  3:08 dsmich
  2006-09-01  7:34 ` Neil Jerram
  0 siblings, 1 reply; 15+ messages in thread
From: dsmich @ 2006-08-29  3:08 UTC (permalink / raw)
  Cc: guile-user

---- Neil Jerram <neil@ossau.uklinux.net> wrote: 
> Neil Jerram <neil@ossau.uklinux.net> writes:
> 
> > Thanks; I expect to have some draft text for you by end tomorrow.
> 
> Draft text is below; please let me know your thoughts on it - most
> importantly, of course, whether it answers your question!

> 5.21.2 Debugging when an error occurs

   ...

Thank you, thank you!  This bit of documentation has been sorely needed for a long time.  Many people come to Guile from the "C side" with poor or nonexistant Scheme experience.  Usually to add Guile to some C application, which of course throws out the REPL and it's backtracing and error reporting capabilities.  So then when errors happen you have no idea where or how.  Making a C program extended by Guile spit out a proper backtrace is a twisty maze of handlers and catchers, and some of them need to be lazy.  (Lazy? Why would I want a *lazy* handler, I want  a hard-working, full-featured kind of handler, not some wimpy light weight *lazy* handler!)

My point is that getting good backtraces from C is non-obvious and a huge hindrance to people just learning how to use Guile and Scheme.  But that's over now.  Thanks again Neil.

-Dale



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


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: saving and restoring the error stack trace
@ 2006-09-01 20:10 Marco Maggi
  0 siblings, 0 replies; 15+ messages in thread
From: Marco Maggi @ 2006-09-01 20:10 UTC (permalink / raw)


"Neil Jerram" wrote:
> Out of interest, though, what changes would you like to the
> presentation?

If you are referring to  the documentation draft: I think it
is fine. If you are referring to the stack trace I posted: I
would like it  to be the same as for  a 'common' error: with
the section

> <unnamed port>: In procedure gsl-ode-evolve in expression
> (gsl-p-ode-evolve ode initial-indep-value ...):
> <unnamed port>: my error message 1 and 2

displayed at  the bottom, below  all the stack frames.  I do
not think that it is easy to do: I obtain the stack trace by
recording the stack  at the moment of error,  and then using
the  lower section  of  it  as part  of  the error  message.
Splitting a stack and appending a section to another seems a
dirty  thing (I  do not  know  how a  stack is  implemented,
though).

"Neil Jerram" wrote:

>do you think  that the way my Emacs  interface displays the
>stack is better or worse than this?
>http://www.ossau.uklinux.net/guile/debugging-demo/shot2.html

I  dunno. It has  a completely  different purpose.  Nice one
that there is a stepping debugger, though.

"Neil Jerram" wrote:
>"Marco Maggi" wrote:
>> and that the args content is not explicitly documented
>> even if its content is well defined in 'scm_error_scm()':
>>
>>   scm_ithrow (key,
>>         scm_list_4 (subr, message, args, data), 1);
>
>Yes, here I completely agree with you.

I  do not  have  enough experience  to  be authoritative  on
exception handling. :)

I want  to make clear that  the 'args' I am  referring to is
the  'args'  handed  to  the  'scm_t_catch_handler  handler'
function, parameter of  'scm_c_catch()'. This 'args' ends up
being the:

  scm_list_4 (subr, message, args, data)

list;  this  value is  exception  independent.  I want  this
'args'  created   by  'scm_error_scm()'  to   be  officially
documented  so  that  there   is  a  constraint  on  keeping
compatibility. :) I do not  think that this list needs to be
changed;  maybe a  helper function  that formats  the string
could be useful, so that one can avoid putting:

  scm_simple_format(s_port, s_message,
    (scm_is_eq(SCM_BOOL_F, s_args)? SCM_EOL : s_args));

in the code, as I have done, to build the message.


"Ludovic Courts" wrote:
>Indeed,  this exception  model is  not very  convenient.  In
>some cases,  it's even hardly usable, as  examplified by the
>`test-suite/lib.scm'   hacks  (use   of  regexps   to  parse
>exception messages and determine their meaning...).

But applications and test suites are different scenarios.

"Ludovic Courts" wrote:
>Ideally, Guile should  use some SRFI-3[56]-like mechanism to
>represent exceptions.

SRFI-35 defines  a complex value,  maybe too complex.  It is
not  clear to me  if a  fine-grained hierarchy  of exception
descriptors can really improve the quality of the code.

There   are   two   classes   of   exceptions:   logic   and
runtime. Logic  are the problems that I  should have removed
at debugging time, I do not think that it is possible to try
to recover from those.  Runtime are state synchronisations.

How can the application recover from a state synchronisation
exception?   One  aborts   the   transaction  and/or   frees
asynchronous resources allocated for the operation. Is there
a significant  number of real-world  cases in which  one can
retry the operation without aborting/freeing?

Should  it  be possible  to  do  something without  breaking
compatibility  by generalising  the 'key'  argument  and use
upon it a generalised version of 'equal?'?




--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



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


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: saving and restoring the error stack trace
@ 2006-08-31  6:04 Marco Maggi
  2006-09-01  7:47 ` Neil Jerram
  0 siblings, 1 reply; 15+ messages in thread
From: Marco Maggi @ 2006-08-31  6:04 UTC (permalink / raw)


"Neil Jerram" wrote:
> [...] please let me know your thoughts on it -
> most importantly, of course, whether it answers your
> question!

Making the stack with this:

  s_error_stack = scm_make_stack(SCM_BOOL_T, SCM_EOL);

and using the function (scm_t = SCM):

void
rethrow_error_with_stack (scm_t s_error_stack,
                          scm_t s_error_key,
                          scm_t s_error_args,
                          const char * procname)
{
  scm_t		s_port, s_string, s_stack;
  size_t	len;

  s_stack = scm_make_stack(SCM_BOOL_T, SCM_EOL);
  len =
    scm_to_uint(scm_stack_length(s_error_stack)) -
    scm_to_uint(scm_stack_length(s_stack)) - 1;

  s_port = scm_open_output_string();
  {
    scm_t	s_message =
scm_list_ref(s_error_args,scm_from_uint(1));
    scm_t	s_args    =
scm_list_ref(s_error_args,scm_from_uint(2));

    scm_simple_format(s_port, s_message,
		      (scm_is_eq(SCM_BOOL_F, s_args)? SCM_EOL : s_args));
    scm_newline(s_port);
    scm_display_backtrace(s_error_stack, s_port,
 			  scm_from_uint(len), SCM_UNDEFINED);
    s_string = scm_get_output_string(s_port);
  }
  scm_close_output_port(s_port);
  scm_error_scm(s_error_key, scm_from_locale_string(procname),
		s_string, SCM_BOOL_F,
		scm_list_ref(s_error_args, scm_from_uint(3)));
}

I have error messages like:

Backtrace:
In unknown file:
   ?: 0* [dotest "gsl-ode-error-2.4" #<procedure #f ()> ...]
   ?: 1  (let* () (let* (# #) (let* # #)))
   ...
   ?: 2  (begin (display name) (if (thunk? setup) (setup)) ...)
   ?: 3* (let (# # # ...) (set-current-input-port saved-in) ...)
   ?: 4* (if catch-error (catch #t thunk (lambda (key .
args) key)) (thunk))
   ?: 5  [#<procedure #f ()>]
   ...
   ?: 6  (let* ((result (quote ()))) (if debugging
(newline)) ...)
   ?: 7* [gsl-ode-evolve #<universal GSL SMOB 404697f8>
#:initial-indep-value ...]
   ?: 8  (let-keywords args #f ...)
   ...
   ?: 9  [gsl-p-ode-evolve #<universal GSL SMOB 404697f8>
0.0 ...]

<unnamed port>: In procedure gsl-ode-evolve in expression
(gsl-p-ode-evolve ode initial-indep-value ...):
<unnamed port>: my error message 1 and 2
In unknown file:
   ?: 10* [#<procedure #f (t y)> 0.0 #,(gsl-vector-real 1 2.0)]
   ?: 11* [gsl-ode-invoke-fun 0.0 #,(gsl-vector-real 1 2.0) ...]
   ?: 12  (let* ((o (func t #))) (if (gsl? o) (slot-ref o
(quote v)) ...))
   ?: 13* [#<procedure #f (t y)> 0.0 #,(gvr 1  2.0)]
   ?: 14  [throwing-error]
    ...
   ?: 15  [scm-error my-own-error "sub-throwing-error" ...]

which is not perfect but seems good enough for me.

I am a little annoyed that I have to use a port to
build the backtrace string, and that the args content
is not explicitly documented (that is, I was not
able to find it) even if its content is well defined
in 'scm_error_scm()':

  scm_ithrow (key,
        scm_list_4 (subr, message, args, data), 1);


--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



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


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: saving and restoring the error stack trace
@ 2006-08-25  9:39 Marco Maggi
  2006-08-27 12:53 ` Neil Jerram
  0 siblings, 1 reply; 15+ messages in thread
From: Marco Maggi @ 2006-08-25  9:39 UTC (permalink / raw)


"Neil Jerram" wrote:
>"Marco Maggi" <marco.maggi-ipsu@poste.it> writes:
>> If an error occurs in the invocation of
>> my-other-scheme-impl-scheme-function I want a
>> full stack trace of the error be shown to the
>> user that invoked my-scheme-implemented-scheme-function
>> at the REPL.
>
>> Is there a way?

> Yes, and I'm in the process of writing this up
> properly for the manual.
> How quickly do you need an answer?

I am in no hurry at all. Take your time.
Thank You.

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



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


^ permalink raw reply	[flat|nested] 15+ messages in thread
* saving and restoring the error stack trace
@ 2006-08-24 19:34 Marco Maggi
  2006-08-24 21:53 ` Neil Jerram
  0 siblings, 1 reply; 15+ messages in thread
From: Marco Maggi @ 2006-08-24 19:34 UTC (permalink / raw)


Ciao,

  I am interfacing the GSL ordinary differential
equations solver with Guile. I have the following
stack of invocations:

my-scheme-implemented-scheme-function
|
 ->my-C-implemented-scheme-function
   |
    ->gsl_odeiv_evolve_apply
      |
       ->my_C_callback
         |
          ->scm_internal_catch
            |
             ->my_other_C_callback
               |
                ->my-other-scheme-impl-scheme-function

If an error occurs in the invocation of
my-other-scheme-impl-scheme-function I want a
full stack trace of the error be shown to the
user that invoked my-scheme-implemented-scheme-function
at the REPL.

I cannot let the dynwind mechanism pass through
gsl_odeiv_evolve_apply, that is why I am using
scm_internal_catch. But in this way if I rethrow
the exception in my-C-implemented-scheme-function
I loose the stack trace that includes the body
of my-other-scheme-impl-scheme-function.

For the ones that know how Tcl works: what I want
is the same as saving the "errorInfo" global variable
and restoring it later.

Is there a way?

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



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


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

end of thread, other threads:[~2006-09-08  6:09 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-29  3:08 saving and restoring the error stack trace dsmich
2006-09-01  7:34 ` Neil Jerram
  -- strict thread matches above, loose matches on Subject: below --
2006-09-01 20:10 Marco Maggi
2006-08-31  6:04 Marco Maggi
2006-09-01  7:47 ` Neil Jerram
2006-09-01  9:39   ` Ludovic Courtès
2006-09-07 22:11     ` Neil Jerram
2006-08-25  9:39 Marco Maggi
2006-08-27 12:53 ` Neil Jerram
2006-08-28 22:21   ` Neil Jerram
2006-09-07  9:02     ` Volkan YAZICI
2006-09-07 21:36       ` Neil Jerram
2006-09-08  6:09         ` Volkan YAZICI
2006-08-24 19:34 Marco Maggi
2006-08-24 21:53 ` 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).