/* GDB interface for Guile
- * Copyright (C) 1996 Free Software Foundation
+ * Copyright (C) 1996, 1997, 1999 Free Software Foundation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* The author can be reached at djurfeldt@nada.kth.se
* Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */
-#include <stdio.h>
+/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
+ gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
+
+
#include "_scm.h"
+
+#include <stdio.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#include "tag.h"
#include "strports.h"
#include "read.h"
#include "eval.h"
#include "chars.h"
+#include "modules.h"
+#include "ports.h"
+#include "root.h"
+#include "strings.h"
#include "gdbint.h"
\f
* 3. Prevent print from causing segmentation fault when given broken pairs
*/
-#include <stdio.h>
-#include "_scm.h"
-
#define GDB_TYPE SCM
#include "gdb_interface.h"
* debugger.
*/
#define SCM_BEGIN_FOREIGN_BLOCK \
-{ \
+do { \
old_ints = scm_ints_disabled; scm_ints_disabled = 1; \
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; \
scm_ints_disabled = old_ints; \
-} \
+} while (0)
#define RESET_STRING { gdb_output_length = 0; }
#define SEND_STRING(str) \
-{ \
+do { \
gdb_output = str; \
gdb_output_length = strlen (str); \
-} \
+} while (0)
/* {Gdb interface}
static int old_ints, old_gc;
-static void unmark_port SCM_P ((SCM port));
-
static void
-unmark_port (port)
- SCM port;
+unmark_port (SCM port)
{
SCM stream, string;
port_mark_p = SCM_GC8MARKP (port);
}
-static void remark_port SCM_P ((SCM port));
-
static void
-remark_port (port)
- SCM port;
+remark_port (SCM port)
{
SCM stream = SCM_STREAM (port);
SCM string = SCM_CDR (stream);
int
-gdb_maybe_valid_type_p (value)
- SCM value;
+gdb_maybe_valid_type_p (SCM value)
{
if (SCM_IMP (value) || scm_cellp (value))
return scm_tag (value) != SCM_MAKINUM (-1);
int
-gdb_read (str)
- char *str;
+gdb_read (char *str)
{
SCM ans;
int status = 0;
}
SCM_BEGIN_FOREIGN_BLOCK;
unmark_port (gdb_input_port);
- /* Replace string in input port and reset stream */
- ans = SCM_CDR (SCM_STREAM (gdb_input_port));
- SCM_SETCHARS (ans, str);
- SCM_SETLENGTH (ans, strlen (str), scm_tc7_string);
- SCM_SETCAR (SCM_STREAM (gdb_input_port), SCM_INUM0);
+ 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_GC8MARKP (tok_buf);
SCM_CLRGC8MARK (tok_buf);
int
-gdb_eval (exp)
- SCM exp;
+gdb_eval (SCM exp)
{
RESET_STRING;
if (SCM_IMP (exp))
int
-gdb_print (obj)
- SCM obj;
+gdb_print (SCM obj)
{
RESET_STRING;
SCM_BEGIN_FOREIGN_BLOCK;
/* Reset stream */
- SCM_SETCAR (SCM_STREAM (gdb_output_port), SCM_INUM0);
+ scm_seek (gdb_output_port, SCM_INUM0, SCM_MAKINUM (SEEK_SET));
scm_write (obj, gdb_output_port);
- scm_display (SCM_MAKICHR (0), gdb_output_port);
- SEND_STRING (SCM_CHARS (SCM_CDR (SCM_STREAM (gdb_output_port))));
+ scm_truncate_file (gdb_output_port, SCM_UNDEFINED);
+ {
+ scm_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 (name, value)
- SCM name;
- SCM value;
+gdb_binding (SCM name, SCM value)
{
RESET_STRING;
if (SCM_GC_P)
scm_print_carefully_p = 0;
port = scm_mkstrport (SCM_INUM0,
- scm_make_string (SCM_MAKINUM (80), SCM_UNDEFINED),
+ 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_OPN | SCM_RDNG | SCM_WRTNG,
s);
gdb_input_port = scm_permanent_object (port);