1 /* GDB interface for Guile
2 * Copyright (C) 1996 Mikael Djurfeldt
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this software; see the file COPYING. If not, write to
16 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice.
42 * The author can be reached at djurfeldt@nada.kth.se
43 * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN
50 /* {Support for debugging with gdb}
56 * 3. Prevent print from causing segmentation fault when given broken pairs
64 #include "gdb_interface.h"
68 /* Be carefull when this macro is true.
69 scm_gc_heap_lock is set during gc.
71 #define SCM_GC_P (scm_gc_heap_lock)
73 /* Macros that encapsulate blocks of code which can be called by the
76 #define SCM_BEGIN_FOREIGN_BLOCK \
78 old_ints = scm_ints_disabled; scm_ints_disabled = 1; \
79 old_gc = scm_block_gc; scm_block_gc = 1; \
80 scm_print_carefully_p = 1; \
84 #define SCM_END_FOREIGN_BLOCK \
86 scm_print_carefully_p = 0; \
87 scm_block_gc = old_gc; \
88 scm_ints_disabled = old_ints; \
92 #define RESET_STRING { gdb_output_length = 0; }
94 #define SEND_STRING(str) \
97 gdb_output_length = strlen (str); \
103 unsigned short gdb_options
= GDB_HAVE_BINDINGS
;
105 char *gdb_language
= "lisp/c";
111 int gdb_output_length
;
113 int scm_print_carefully_p
;
115 static SCM gdb_input_port
;
116 static SCM gdb_output_port
;
117 static int old_ints
, old_gc
;
121 gdb_maybe_valid_type_p (SCM value
)
124 gdb_maybe_valid_type_p (value
)
128 if (SCM_IMP (value
) || scm_cellp (value
))
129 return scm_tag (value
) != SCM_MAKINUM (-1);
145 /* Need to be restrictive about what to read? */
149 for (p
= str
; *p
!= '\0'; ++p
)
155 SEND_STRING ("Can't read this kind of expressions during gc");
165 SEND_STRING ("Premature end of lisp expression");
172 SCM_BEGIN_FOREIGN_BLOCK
;
173 /* Replace string in input port and reset stream */
174 ans
= SCM_CDR (SCM_STREAM (gdb_input_port
));
175 SCM_SETCHARS (ans
, str
);
176 SCM_SETLENGTH (ans
, strlen (str
), scm_tc7_string
);
177 SCM_SETCAR (SCM_STREAM (gdb_input_port
), SCM_INUM0
);
178 /* Read one object */
179 ans
= scm_read (gdb_input_port
, SCM_UNDEFINED
, SCM_UNDEFINED
);
184 SEND_STRING ("Non-immediate created during gc. Memory may be trashed.");
189 /* Protect answer from future GC */
190 gdb_result
= scm_permanent_object (ans
);;
192 SCM_END_FOREIGN_BLOCK
;
213 SEND_STRING ("Can't evaluate lisp expressions during gc");
216 SCM_BEGIN_FOREIGN_BLOCK
;
218 SCM env
= scm_top_level_env (SCM_CDR (scm_top_level_lookup_thunk_var
));
219 gdb_result
= scm_permanent_object (scm_ceval (exp
, env
));
221 SCM_END_FOREIGN_BLOCK
;
235 SCM_BEGIN_FOREIGN_BLOCK
;
237 SCM_SETCAR (SCM_STREAM (gdb_output_port
), SCM_INUM0
);
238 scm_write (obj
, gdb_output_port
);
239 scm_display (SCM_MAKICHR (0), gdb_output_port
);
240 SEND_STRING (SCM_CHARS (SCM_CDR (SCM_STREAM (gdb_output_port
))));
241 SCM_END_FOREIGN_BLOCK
;
247 gdb_binding (SCM name
, SCM value
)
250 gdb_binding (name
, value
)
258 SEND_STRING ("Can't create new bindings during gc");
261 SCM_BEGIN_FOREIGN_BLOCK
;
263 SCM vcell
= scm_sym2vcell (name
,
264 SCM_CDR (scm_top_level_lookup_thunk_var
),
266 SCM_SETCDR (vcell
, value
);
268 SCM_END_FOREIGN_BLOCK
;
275 static char *s
= "scm_init_gdb_interface";
278 scm_print_carefully_p
= 0;
280 port
= scm_mkstrport (SCM_INUM0
,
281 scm_make_string (SCM_MAKINUM (80), SCM_UNDEFINED
),
284 gdb_output_port
= scm_permanent_object (port
);
286 port
= scm_mkstrport (SCM_INUM0
,
287 scm_make_string (SCM_MAKINUM (0), SCM_UNDEFINED
),
290 gdb_input_port
= scm_permanent_object (port
);