[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trace, backtrace, exceptions and TeXmacs

From: david
Subject: Trace, backtrace, exceptions and TeXmacs
Date: Tue, 4 Feb 2003 14:00:10 +0100
User-agent: Mutt/1.4i


sorry to annoy people with one more stupid question related to
debugging and error handling in applications embedding guile, but I
could not solve my problem by merely searching the mailing list

 My problem 

I have a problem combining backtrace display as previously described here:

and a home-made tracing system (attached) used in TeXmacs.

Attachment: debug-part.scm
Description: Text document

When I do

  (define (foo) (/ 1 0))
  (set-trace-level! foo)  ; these forms are defined in the attached
  (backtrack foo)         ; snipped of texmacs' debug.scm

I get the following output on the console (the first line is the
output of the home-made trace).

 1  [catch #t #<procedure ()> #<procedure TeXmacs-guile-error-handler args>]
 2* [#<procedure ()>]
 3* [object->string ...
 4* [eval-string "(make-return)"]
 5* [#<procedure ()>]
 6  (if (string-null? (get-env "return action")) (pass) ...)
 7  [process-input]
 8* [TeXmacs-guile-eval-any "(backtrack (foo))"]
 9  [catch #t #<procedure ()> #<procedure TeXmacs-guile-error-handler
10* [#<procedure ()>]
11* [object->string ...
12* [eval-string "(backtrack (foo))"]
13* (backtrack (foo))
14  [lazy-catch #t #<procedure ()> #<procedure backtrace-dumper (key .
15* [#<procedure ()>]
16* [#<procedure args>]
17  [catch #t #<procedure ()> #<procedure err>]
18* [#<procedure err> numerical-overflow "/" "Numerical overflow" #f
19* [apply #<primitive-procedure throw> #]
20  [apply #<primitive-procedure throw> #]
ERROR: In procedure apply in expression (apply throw err):
ERROR: Numerical overflow

It seems that the apply in wrap-trace-level is executed twice, and the
second time it has invalid arguments.

I could not find any way of preventing that strang behaviour, and that
is very annoying. I tried wrapping the lazy catch in a (catch
'ignore-this ...) as in the provided example, but it did not help (and
prevented the error going all the way up to the texmacs).

Also I was unable to reproduce the problem in a simple guile
interpreter because the built-in backtrace feature seems to get in the
way of exception handling.

Actually I would rather like to find a way to use the built-in trace
feature, any idea?

I am using guile-1.4.1. I know I should use a more recent release but
we have a policy of supporting all guile versions from 1.3.4 (esp. the
main developer of TeXmacs uses this version) so I rather not use
guile-1.6 for development.

 Why it is all so dirty 

I know I should rather use the built-in tracing capability defined by

 (use-modules (ice-9 debug))

but (trace foo), where foo is some buggy function, does not seem to
enable any tracing from within TeXmacs. I have tried enabling
debugging as described there:

by including the following snippet early in the application

    SCM_DEVAL_P = 1;

But it does not seem to have any effect. Specifically it does not
enable lazy-catch based backtrace display. On the other hand,
including that statement:

  (debug-enable 'backtrace 'debug)

early in the scheme environment initialization did activate backtraces
inside lazy-catch, but did not allow me to use the built-in trace

 More context

For information, TeXmacs evaluates scheme commands using the following
code (I admit it is pretty dumb):

    [this is part of the VERY early environment init]

    "(define (TeXmacs-guile-error-handler . args)\n"
    "  (object->string args))\n"
    "(define (object->string obj)\n"
    "  (call-with-output-string\n"
    "    (lambda (port) (write obj port))))\n"
    "(define (TeXmacs-guile-eval-any s)\n"
    "  (catch\n"
    "    #t\n"
    "    (lambda ()\n"
    "      (object->string (eval-string s)))\n"
    "    TeXmacs-guile-error-handler))\n"

    [this is the corresponding C++ code]

    eval_scheme_any (string s, string& r) {
      // cout << "Eval any] " << start (s) << "\n";
      string prg= "(TeXmacs-guile-eval-any \"" * back_slash (s) * "\")";
      char* _s= as_charp (prg);
      SCM result= gh_eval_str (_s);
      delete[] _s;

      int len_r;
      char* _r= scm2newstr (result, &len_r);
      r= _r;
      free (_r);

      if (r == "#<unspecified>") r= "";
      // cout << "Yields] " << start (r) << "\n";
      return false;

Please, help!

David Allouche         | GNU TeXmacs -- Writing is a pleasure
Free software engineer |     |
   address@hidden  |    address@hidden
TeXmacs is NOT a LaTeX front-end and is unrelated to emacs.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]