mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
SCM_DEBUGGINGP: * debug.h (scm_debug_mode_p, scm_debug_mode, SCM_DEBUGGINGP), eval.c (scm_debug_mode_p): Deprecated scm_debug_mode and SCM_DEBUGGINGP. Provided scm_debug_mode_p instead, to have one single interface that also matches the naming conventions. Probably scm_debug_mode_p should be part of the private interface anyway. * debug.h (scm_debug_mode_p), backtrace.c (display_error_body), eval.c (SCM_APPLY, scm_trampoline_0, scm_trampoline_1, scm_trampoline_2): Change uses of scm_debug_mode or SCM_DEBUGGINGP to scm_debug_mode_p. Deprecate direct access to scm_ceval, scm_deval and scm_ceval_ptr: * eval.h (scm_ceval, scm_deval, scm_ceval_ptr), debug.h (scm_ceval_ptr): Deprecated. Moved declaration of scm_ceval_ptr from debug.h to eval.h. * debug.h (SCM_RESET_DEBUG_MODE): Don't access scm_ceval_ptr any more, just leave it with setting scm_debug_mode_p, which is equivalent for practical purposes. * deprecated.h (SCM_XEVAL, SCM_XEVALCAR): Call scm_i_eval_x instead of *scm_ceval_ptr. Leave all evaluating to scm_i_eval_x. * gdbint.c (gdb_eval): Call scm_i_eval_x instead of scm_ceval. * eval.c (ceval, deval, scm_ceval, scm_deval): Made scm_ceval static and renamed it to ceval throughout. Provide a new exported but deprecated function scm_ceval as a wrapper for backwards compatibility. The same is done for the deval/scm_deval pair of functions. * eval.c (CEVAL, SCM_CEVAL): Renamed SCM_CEVAL to CEVAL throughout. Defined CEVAL to ceval or deval, based on compilation phase. * eval.c (SCM_XEVAL, SCM_XEVALCAR): Dispatch on scm_debug_mode_p to ceval and deval instead of calling *scm_ceval_ptr. * eval.c (dispatching_eval): New deprecated static function. * eval.c (scm_ceval_ptr): Initialized to dispatching_eval in order to emulate its old behaviour as closely as possible. Change the evaluator such that only expressions for which pair? is true are passed to CEVAL, and such that all other expressions are evaluated outside of CEVAL: * eval.c (EVAL): New, provided in analogy to EVALCAR. Evaluate an expression that is assumed to be memoized already. All but expressions of the form '(<form> <form> ...)' are evaluated inline without calling an evaluator. * eval.c (SCM_XEVAL, SCM_XEVALCAR, EVALCAR): Evaluate all but expressions of the form '(<form> <form> ...)' inline without calling an evaluator. * eval.c (scm_i_eval_x, scm_i_eval, scm_ceval, scm_deval): Handle the special case of unmemoized symbols passed on the top level. * eval.c (CEVAL): Change calls to CEVAL to EVAL, except where it is known that the expression passed to CEVAL is of the form '(<form> <form> ...)'. Remove handling of the tc7-objects, since now it is known that the input expression of CEVAL is a pair.
306 lines
6.4 KiB
C
306 lines
6.4 KiB
C
/* GDB interface for Guile
|
||
* Copyright (C) 1996,1997,1999,2000,2001,2002,2004
|
||
* Free Software Foundation, Inc.
|
||
*
|
||
* This library is free software; you can redistribute it and/or
|
||
* modify it under the terms of the GNU Lesser General Public
|
||
* License as published by the Free Software Foundation; either
|
||
* version 2.1 of the License, or (at your option) any later version.
|
||
*
|
||
* This library is distributed in the hope that it will be useful,
|
||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
* Lesser General Public License for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public
|
||
* License along with this library; if not, write to the Free Software
|
||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
*/
|
||
|
||
#if HAVE_CONFIG_H
|
||
# include <config.h>
|
||
#endif
|
||
|
||
#include "libguile/_scm.h"
|
||
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#ifdef HAVE_UNISTD_H
|
||
#include <unistd.h>
|
||
#endif
|
||
|
||
#include "libguile/strports.h"
|
||
#include "libguile/read.h"
|
||
#include "libguile/eval.h"
|
||
#include "libguile/chars.h"
|
||
#include "libguile/modules.h"
|
||
#include "libguile/ports.h"
|
||
#include "libguile/fluids.h"
|
||
#include "libguile/strings.h"
|
||
#include "libguile/init.h"
|
||
|
||
#include "libguile/gdbint.h"
|
||
|
||
/* {Support for debugging with gdb}
|
||
*
|
||
* TODO:
|
||
*
|
||
* 1. Redirect outputs
|
||
* 2. Catch errors
|
||
* 3. Prevent print from causing segmentation fault when given broken pairs
|
||
*/
|
||
|
||
#define GDB_TYPE SCM
|
||
|
||
#include "libguile/gdb_interface.h"
|
||
|
||
|
||
|
||
/* Be carefull when this macro is true.
|
||
scm_gc_running_p is set during gc.
|
||
*/
|
||
#define SCM_GC_P (scm_gc_running_p)
|
||
|
||
/* Macros that encapsulate blocks of code which can be called by the
|
||
* debugger.
|
||
*/
|
||
#define SCM_BEGIN_FOREIGN_BLOCK \
|
||
do { \
|
||
old_gc = scm_block_gc; scm_block_gc = 1; \
|
||
scm_print_carefully_p = 1; \
|
||
} while (0)
|
||
|
||
|
||
#define SCM_END_FOREIGN_BLOCK \
|
||
do { \
|
||
scm_print_carefully_p = 0; \
|
||
scm_block_gc = old_gc; \
|
||
} while (0)
|
||
|
||
|
||
#define RESET_STRING { gdb_output_length = 0; }
|
||
|
||
#define SEND_STRING(str) \
|
||
do { \
|
||
gdb_output = (char *) (str); \
|
||
gdb_output_length = strlen ((const char *) (str)); \
|
||
} while (0)
|
||
|
||
|
||
/* {Gdb interface}
|
||
*/
|
||
|
||
unsigned short gdb_options = GDB_HAVE_BINDINGS;
|
||
|
||
char *gdb_language = "lisp/c";
|
||
|
||
SCM gdb_result;
|
||
|
||
char *gdb_output;
|
||
|
||
int gdb_output_length;
|
||
|
||
int scm_print_carefully_p;
|
||
|
||
static SCM gdb_input_port;
|
||
static int port_mark_p, stream_mark_p, string_mark_p;
|
||
|
||
static SCM tok_buf;
|
||
static int tok_buf_mark_p;
|
||
|
||
static SCM gdb_output_port;
|
||
static int old_gc;
|
||
|
||
|
||
static void
|
||
unmark_port (SCM port)
|
||
{
|
||
SCM stream, string;
|
||
port_mark_p = SCM_GC_MARK_P (port);
|
||
SCM_CLEAR_GC_MARK (port);
|
||
stream = SCM_PACK (SCM_STREAM (port));
|
||
stream_mark_p = SCM_GC_MARK_P (stream);
|
||
SCM_CLEAR_GC_MARK (stream);
|
||
string = SCM_CDR (stream);
|
||
string_mark_p = SCM_GC_MARK_P (string);
|
||
SCM_CLEAR_GC_MARK (string);
|
||
}
|
||
|
||
|
||
static void
|
||
remark_port (SCM port)
|
||
{
|
||
SCM stream = SCM_PACK (SCM_STREAM (port));
|
||
SCM string = SCM_CDR (stream);
|
||
if (string_mark_p)
|
||
SCM_SET_GC_MARK (string);
|
||
if (stream_mark_p)
|
||
SCM_SET_GC_MARK (stream);
|
||
if (port_mark_p)
|
||
SCM_SET_GC_MARK (port);
|
||
}
|
||
|
||
|
||
int
|
||
gdb_maybe_valid_type_p (SCM value)
|
||
{
|
||
return SCM_IMP (value) || scm_in_heap_p (value);
|
||
}
|
||
|
||
|
||
int
|
||
gdb_read (char *str)
|
||
{
|
||
SCM ans;
|
||
int status = 0;
|
||
RESET_STRING;
|
||
/* Need to be restrictive about what to read? */
|
||
if (SCM_GC_P)
|
||
{
|
||
char *p;
|
||
for (p = str; *p != '\0'; ++p)
|
||
switch (*p)
|
||
{
|
||
case '(':
|
||
case '\'':
|
||
case '"':
|
||
SEND_STRING ("Can't read this kind of expressions during gc");
|
||
return -1;
|
||
case '#':
|
||
if (*++p == '\0')
|
||
goto premature;
|
||
if (*p == '\\')
|
||
{
|
||
if (*++p != '\0')
|
||
continue;
|
||
premature:
|
||
SEND_STRING ("Premature end of lisp expression");
|
||
return -1;
|
||
}
|
||
default:
|
||
continue;
|
||
}
|
||
}
|
||
SCM_BEGIN_FOREIGN_BLOCK;
|
||
unmark_port (gdb_input_port);
|
||
scm_seek (gdb_input_port, SCM_INUM0, SCM_MAKINUM (SEEK_SET));
|
||
scm_puts (str, gdb_input_port);
|
||
scm_truncate_file (gdb_input_port, SCM_UNDEFINED);
|
||
scm_seek (gdb_input_port, SCM_INUM0, SCM_MAKINUM (SEEK_SET));
|
||
/* Read one object */
|
||
tok_buf_mark_p = SCM_GC_MARK_P (tok_buf);
|
||
SCM_CLEAR_GC_MARK (tok_buf);
|
||
ans = scm_lreadr (&tok_buf, gdb_input_port, &ans);
|
||
if (SCM_GC_P)
|
||
{
|
||
if (SCM_NIMP (ans))
|
||
{
|
||
SEND_STRING ("Non-immediate created during gc. Memory may be trashed.");
|
||
status = -1;
|
||
goto exit;
|
||
}
|
||
}
|
||
gdb_result = ans;
|
||
/* Protect answer from future GC */
|
||
if (SCM_NIMP (ans))
|
||
scm_permanent_object (ans);
|
||
exit:
|
||
if (tok_buf_mark_p)
|
||
SCM_SET_GC_MARK (tok_buf);
|
||
remark_port (gdb_input_port);
|
||
SCM_END_FOREIGN_BLOCK;
|
||
return status;
|
||
}
|
||
|
||
|
||
int
|
||
gdb_eval (SCM exp)
|
||
{
|
||
RESET_STRING;
|
||
if (SCM_GC_P)
|
||
{
|
||
SEND_STRING ("Can't evaluate lisp expressions during gc");
|
||
return -1;
|
||
}
|
||
SCM_BEGIN_FOREIGN_BLOCK;
|
||
{
|
||
SCM env = scm_top_level_env (SCM_TOP_LEVEL_LOOKUP_CLOSURE);
|
||
gdb_result = scm_permanent_object (scm_i_eval_x (exp, env));
|
||
}
|
||
SCM_END_FOREIGN_BLOCK;
|
||
return 0;
|
||
}
|
||
|
||
|
||
int
|
||
gdb_print (SCM obj)
|
||
{
|
||
if (!scm_initialized_p)
|
||
SEND_STRING ("*** Guile not initialized ***");
|
||
else
|
||
{
|
||
RESET_STRING;
|
||
SCM_BEGIN_FOREIGN_BLOCK;
|
||
/* Reset stream */
|
||
scm_seek (gdb_output_port, SCM_INUM0, SCM_MAKINUM (SEEK_SET));
|
||
scm_write (obj, gdb_output_port);
|
||
scm_truncate_file (gdb_output_port, SCM_UNDEFINED);
|
||
{
|
||
scm_t_port *pt = SCM_PTAB_ENTRY (gdb_output_port);
|
||
|
||
scm_flush (gdb_output_port);
|
||
*(pt->write_buf + pt->read_buf_size) = 0;
|
||
SEND_STRING (pt->read_buf);
|
||
}
|
||
SCM_END_FOREIGN_BLOCK;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
int
|
||
gdb_binding (SCM name, SCM value)
|
||
{
|
||
RESET_STRING;
|
||
if (SCM_GC_P)
|
||
{
|
||
SEND_STRING ("Can't create new bindings during gc");
|
||
return -1;
|
||
}
|
||
SCM_BEGIN_FOREIGN_BLOCK;
|
||
{
|
||
SCM var = scm_sym2var (name, SCM_TOP_LEVEL_LOOKUP_CLOSURE, SCM_BOOL_T);
|
||
SCM_VARIABLE_SET (var, value);
|
||
}
|
||
SCM_END_FOREIGN_BLOCK;
|
||
return 0;
|
||
}
|
||
|
||
void
|
||
scm_init_gdbint ()
|
||
{
|
||
static char *s = "scm_init_gdb_interface";
|
||
SCM port;
|
||
|
||
scm_print_carefully_p = 0;
|
||
|
||
port = scm_mkstrport (SCM_INUM0,
|
||
scm_make_string (SCM_MAKINUM (0), SCM_UNDEFINED),
|
||
SCM_OPN | SCM_WRTNG,
|
||
s);
|
||
gdb_output_port = scm_permanent_object (port);
|
||
|
||
port = scm_mkstrport (SCM_INUM0,
|
||
scm_make_string (SCM_MAKINUM (0), SCM_UNDEFINED),
|
||
SCM_OPN | SCM_RDNG | SCM_WRTNG,
|
||
s);
|
||
gdb_input_port = scm_permanent_object (port);
|
||
|
||
tok_buf = scm_permanent_object (scm_allocate_string (30));
|
||
}
|
||
|
||
/*
|
||
Local Variables:
|
||
c-file-style: "gnu"
|
||
End:
|
||
*/
|