123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #ifdef 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"
- #define GDB_TYPE SCM
- #include "libguile/gdb_interface.h"
- #define SCM_GC_P (scm_gc_running_p)
- #define SCM_BEGIN_FOREIGN_BLOCK \
- do { \
- scm_print_carefully_p = 1; \
- } while (0)
- #define SCM_END_FOREIGN_BLOCK \
- do { \
- scm_print_carefully_p = 0; \
- } 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)
- 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 SCM gdb_output_port;
- int
- gdb_maybe_valid_type_p (SCM value)
- {
- return SCM_IMP (value);
- }
- int
- gdb_read (char *str)
- {
- #if 0
- SCM ans;
- int status = 0;
- RESET_STRING;
-
- if (1)
- {
- 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_from_int (SEEK_SET));
- scm_puts (str, gdb_input_port);
- scm_truncate_file (gdb_input_port, SCM_UNDEFINED);
- scm_seek (gdb_input_port, SCM_INUM0, scm_from_int (SEEK_SET));
-
- ans = scm_read (gdb_input_port);
- 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;
-
- if (SCM_NIMP (ans))
- scm_permanent_object (ans);
- exit:
- remark_port (gdb_input_port);
- SCM_END_FOREIGN_BLOCK;
- return status;
- #else
- abort ();
- #endif
- }
- 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;
- {
- gdb_result = scm_permanent_object (scm_primitive_eval (exp));
- }
- 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;
-
- scm_seek (gdb_output_port, SCM_INUM0, scm_from_int (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_BOOL_F,
- SCM_OPN | SCM_WRTNG,
- s);
- gdb_output_port = scm_permanent_object (port);
- port = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
- SCM_OPN | SCM_RDNG | SCM_WRTNG,
- s);
- gdb_input_port = scm_permanent_object (port);
- }
|