1 /* GDB interface for Guile
2 * Copyright (C) 1996, 1997, 1999 Free Software Foundation
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, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307 USA
19 * As a special exception, the Free Software Foundation gives permission
20 * for additional uses of the text contained in its release of GUILE.
22 * The exception is that, if you link the GUILE library with other files
23 * to produce an executable, this does not by itself cause the
24 * resulting executable to be covered by the GNU General Public License.
25 * Your use of that executable is in no way restricted on account of
26 * linking the GUILE library code into it.
28 * This exception does not however invalidate any other reasons why
29 * the executable file might be covered by the GNU General Public License.
31 * This exception applies only to the code released by the
32 * Free Software Foundation under the name GUILE. If you copy
33 * code from other Free Software Foundation releases into a copy of
34 * GUILE, as the General Public License permits, the exception does
35 * not apply to the code that you add in this way. To avoid misleading
36 * anyone as to the status of such modified files, you must delete
37 * this exception notice from them.
39 * If you write modifications of your own for GUILE, it is your choice
40 * whether to permit this exception to apply to your modifications.
41 * If you do not wish that, delete this exception notice.
43 * The author can be reached at djurfeldt@nada.kth.se
44 * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */
46 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
47 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
66 /* {Support for debugging with gdb}
72 * 3. Prevent print from causing segmentation fault when given broken pairs
77 #include "gdb_interface.h"
81 /* Be carefull when this macro is true.
82 scm_gc_heap_lock is set during gc.
84 #define SCM_GC_P (scm_gc_heap_lock)
86 /* Macros that encapsulate blocks of code which can be called by the
89 #define SCM_BEGIN_FOREIGN_BLOCK \
91 old_ints = scm_ints_disabled; scm_ints_disabled = 1; \
92 old_gc = scm_block_gc; scm_block_gc = 1; \
93 scm_print_carefully_p = 1; \
97 #define SCM_END_FOREIGN_BLOCK \
99 scm_print_carefully_p = 0; \
100 scm_block_gc = old_gc; \
101 scm_ints_disabled = old_ints; \
105 #define RESET_STRING { gdb_output_length = 0; }
107 #define SEND_STRING(str) \
110 gdb_output_length = strlen (str); \
117 unsigned short gdb_options
= GDB_HAVE_BINDINGS
;
119 char *gdb_language
= "lisp/c";
125 int gdb_output_length
;
127 int scm_print_carefully_p
;
129 static SCM gdb_input_port
;
130 static int port_mark_p
, stream_mark_p
, string_mark_p
;
133 static int tok_buf_mark_p
;
135 static SCM gdb_output_port
;
136 static int old_ints
, old_gc
;
140 unmark_port (SCM port
)
143 port_mark_p
= SCM_GC8MARKP (port
);
144 SCM_CLRGC8MARK (port
);
145 stream
= SCM_STREAM (port
);
146 stream_mark_p
= SCM_GCMARKP (stream
);
147 SCM_CLRGCMARK (stream
);
148 string
= SCM_CDR (stream
);
149 string_mark_p
= SCM_GC8MARKP (string
);
150 SCM_CLRGC8MARK (string
);
155 remark_port (SCM port
)
157 SCM stream
= SCM_STREAM (port
);
158 SCM string
= SCM_CDR (stream
);
159 if (string_mark_p
) SCM_SETGC8MARK (string
);
160 if (stream_mark_p
) SCM_SETGCMARK (stream
);
161 if (port_mark_p
) SCM_SETGC8MARK (port
);
166 gdb_maybe_valid_type_p (SCM value
)
168 if (SCM_IMP (value
) || scm_cellp (value
))
169 return scm_tag (value
) != SCM_MAKINUM (-1);
180 /* Need to be restrictive about what to read? */
184 for (p
= str
; *p
!= '\0'; ++p
)
190 SEND_STRING ("Can't read this kind of expressions during gc");
200 SEND_STRING ("Premature end of lisp expression");
207 SCM_BEGIN_FOREIGN_BLOCK
;
208 unmark_port (gdb_input_port
);
209 scm_seek (gdb_input_port
, SCM_INUM0
, SCM_MAKINUM (SEEK_SET
));
210 scm_puts (str
, gdb_input_port
);
211 scm_truncate_file (gdb_input_port
, SCM_UNDEFINED
);
212 scm_seek (gdb_input_port
, SCM_INUM0
, SCM_MAKINUM (SEEK_SET
));
213 /* Read one object */
214 tok_buf_mark_p
= SCM_GC8MARKP (tok_buf
);
215 SCM_CLRGC8MARK (tok_buf
);
216 ans
= scm_lreadr (&tok_buf
, gdb_input_port
, &ans
);
221 SEND_STRING ("Non-immediate created during gc. Memory may be trashed.");
227 /* Protect answer from future GC */
229 scm_permanent_object (ans
);
232 SCM_SETGC8MARK (tok_buf
);
233 remark_port (gdb_input_port
);
234 SCM_END_FOREIGN_BLOCK
;
250 SEND_STRING ("Can't evaluate lisp expressions during gc");
253 SCM_BEGIN_FOREIGN_BLOCK
;
255 SCM env
= scm_top_level_env (SCM_CDR (scm_top_level_lookup_closure_var
));
256 gdb_result
= scm_permanent_object (scm_ceval (exp
, env
));
258 SCM_END_FOREIGN_BLOCK
;
267 SCM_BEGIN_FOREIGN_BLOCK
;
269 scm_seek (gdb_output_port
, SCM_INUM0
, SCM_MAKINUM (SEEK_SET
));
270 scm_write (obj
, gdb_output_port
);
271 scm_truncate_file (gdb_output_port
, SCM_UNDEFINED
);
273 scm_port
*pt
= SCM_PTAB_ENTRY (gdb_output_port
);
275 scm_flush (gdb_output_port
);
276 *(pt
->write_buf
+ pt
->read_buf_size
) = 0;
277 SEND_STRING (pt
->read_buf
);
279 SCM_END_FOREIGN_BLOCK
;
285 gdb_binding (SCM name
, SCM 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 (0), 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
),
320 SCM_OPN
| SCM_RDNG
| SCM_WRTNG
,
322 gdb_input_port
= scm_permanent_object (port
);
324 tok_buf
= scm_permanent_object (scm_makstr (30L, 0));