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
56 /* {Support for debugging with gdb}
62 * 3. Prevent print from causing segmentation fault when given broken pairs
70 #include "gdb_interface.h"
74 /* Be carefull when this macro is true.
75 scm_gc_heap_lock is set during gc.
77 #define SCM_GC_P (scm_gc_heap_lock)
79 /* Macros that encapsulate blocks of code which can be called by the
82 #define SCM_BEGIN_FOREIGN_BLOCK \
84 old_ints = scm_ints_disabled; scm_ints_disabled = 1; \
85 old_gc = scm_block_gc; scm_block_gc = 1; \
86 scm_print_carefully_p = 1; \
90 #define SCM_END_FOREIGN_BLOCK \
92 scm_print_carefully_p = 0; \
93 scm_block_gc = old_gc; \
94 scm_ints_disabled = old_ints; \
98 #define RESET_STRING { gdb_output_length = 0; }
100 #define SEND_STRING(str) \
103 gdb_output_length = strlen (str); \
110 unsigned short gdb_options
= GDB_HAVE_BINDINGS
;
112 char *gdb_language
= "lisp/c";
118 int gdb_output_length
;
120 int scm_print_carefully_p
;
122 static SCM gdb_input_port
;
123 static int port_mark_p
, stream_mark_p
, string_mark_p
;
126 static int tok_buf_mark_p
;
128 static SCM gdb_output_port
;
129 static int old_ints
, old_gc
;
132 static void unmark_port
SCM_P ((SCM port
));
139 port_mark_p
= SCM_GC8MARKP (port
);
140 SCM_CLRGC8MARK (port
);
141 stream
= SCM_STREAM (port
);
142 stream_mark_p
= SCM_GCMARKP (stream
);
143 SCM_CLRGCMARK (stream
);
144 string
= SCM_CDR (stream
);
145 string_mark_p
= SCM_GC8MARKP (string
);
146 SCM_CLRGC8MARK (string
);
150 static void remark_port
SCM_P ((SCM port
));
156 SCM stream
= SCM_STREAM (port
);
157 SCM string
= SCM_CDR (stream
);
158 if (string_mark_p
) SCM_SETGC8MARK (string
);
159 if (stream_mark_p
) SCM_SETGCMARK (stream
);
160 if (port_mark_p
) SCM_SETGC8MARK (port
);
165 gdb_maybe_valid_type_p (value
)
168 if (SCM_IMP (value
) || scm_cellp (value
))
169 return scm_tag (value
) != SCM_MAKINUM (-1);
181 /* Need to be restrictive about what to read? */
185 for (p
= str
; *p
!= '\0'; ++p
)
191 SEND_STRING ("Can't read this kind of expressions during gc");
201 SEND_STRING ("Premature end of lisp expression");
208 SCM_BEGIN_FOREIGN_BLOCK
;
209 unmark_port (gdb_input_port
);
210 /* Replace string in input port and reset stream */
211 ans
= SCM_CDR (SCM_STREAM (gdb_input_port
));
212 SCM_SETCHARS (ans
, str
);
213 SCM_SETLENGTH (ans
, strlen (str
), scm_tc7_string
);
214 SCM_SETCAR (SCM_STREAM (gdb_input_port
), SCM_INUM0
);
215 /* Read one object */
216 tok_buf_mark_p
= SCM_GC8MARKP (tok_buf
);
217 SCM_CLRGC8MARK (tok_buf
);
218 ans
= scm_lreadr (&tok_buf
, gdb_input_port
, 0, SCM_BOOL_F
, &ans
);
223 SEND_STRING ("Non-immediate created during gc. Memory may be trashed.");
229 /* Protect answer from future GC */
231 scm_permanent_object (ans
);
234 SCM_SETGC8MARK (tok_buf
);
235 remark_port (gdb_input_port
);
236 SCM_END_FOREIGN_BLOCK
;
253 SEND_STRING ("Can't evaluate lisp expressions during gc");
256 SCM_BEGIN_FOREIGN_BLOCK
;
258 SCM env
= scm_top_level_env (SCM_CDR (scm_top_level_lookup_closure_var
));
259 gdb_result
= scm_permanent_object (scm_ceval (exp
, env
));
261 SCM_END_FOREIGN_BLOCK
;
271 SCM_BEGIN_FOREIGN_BLOCK
;
273 SCM_SETCAR (SCM_STREAM (gdb_output_port
), SCM_INUM0
);
274 scm_write (obj
, gdb_output_port
);
275 scm_display (SCM_MAKICHR (0), gdb_output_port
);
276 SEND_STRING (SCM_CHARS (SCM_CDR (SCM_STREAM (gdb_output_port
))));
277 SCM_END_FOREIGN_BLOCK
;
283 gdb_binding (name
, value
)
290 SEND_STRING ("Can't create new bindings during gc");
293 SCM_BEGIN_FOREIGN_BLOCK
;
295 SCM vcell
= scm_sym2vcell (name
,
296 SCM_CDR (scm_top_level_lookup_closure_var
),
298 SCM_SETCDR (vcell
, value
);
300 SCM_END_FOREIGN_BLOCK
;
307 static char *s
= "scm_init_gdb_interface";
310 scm_print_carefully_p
= 0;
312 port
= scm_mkstrport (SCM_INUM0
,
313 scm_make_string (SCM_MAKINUM (80), SCM_UNDEFINED
),
316 gdb_output_port
= scm_permanent_object (port
);
318 port
= scm_mkstrport (SCM_INUM0
,
319 scm_make_string (SCM_MAKINUM (0), SCM_UNDEFINED
),
322 gdb_input_port
= scm_permanent_object (port
);
324 tok_buf
= scm_permanent_object (scm_makstr (30L, 0));