* debugify.c, debugify.h: New files. Provide common macros
authorDawn Perchik <dawn@cygnus>
Wed, 12 Feb 1997 22:48:45 +0000 (22:48 +0000)
committerDawn Perchik <dawn@cygnus>
Wed, 12 Feb 1997 22:48:45 +0000 (22:48 +0000)
        for writing debug info to a log file or stdio.

gdb/.Sanitize
gdb/ChangeLog
gdb/debugify.c [new file with mode: 0644]
gdb/debugify.h [new file with mode: 0644]

index 422d7b707776e5ea13b6c9ecc066550759be5620..faea153c01f5ebe712682c80e89ce6d01d952ed2 100644 (file)
@@ -199,6 +199,8 @@ dbug-rom.c
 dbxread.c
 dcache.c
 dcache.h
+debugify.h
+debugify.c
 defs.h
 delta68-nat.c
 demangle.c
index 11787bc1eaea20c5b502f9f31688c6f76720569f..f59ac7a132d93aafe59e149a82a4d99a804a0ede 100644 (file)
@@ -1,4 +1,9 @@
 
+Wed Feb 12 14:42:47 1997  Dawn Perchik  <dawn@cygnus.com>
+
+        * debugify.c, debugify.h: New files.  Provide common macros
+       for writing debug info to a log file or stdio.
+
 Wed Feb 12 02:44:39 1997  Dawn Perchik  <dawn@cygnus.com>
 
         * c-valprint.c (c_val_print): Fix printing for arrays defined
diff --git a/gdb/debugify.c b/gdb/debugify.c
new file mode 100644 (file)
index 0000000..7f5af2a
--- /dev/null
@@ -0,0 +1,66 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#define DEBUGIFY
+#include "debugify.h"
+
+#define REDIRECT
+
+static FILE *fout=NULL;
+static char fname[128];
+static int file_cnt=0; /* count number of open files */
+
+void puts_dbg(const char *data)
+{
+    FILE *fdbg;
+
+    fdbg=fopen("dbg.log","a+");
+    if (fdbg==NULL) 
+       return;
+    fprintf(fdbg,data);
+    fclose(fdbg);
+}
+
+/* Can't easily get the message back to gdb... write to a log instead. */
+void fputs_dbg (const char *data, FILE * fakestream)
+{
+#ifdef REDIRECT
+    puts_dbg(data);
+#else /* REDIRECT */
+      
+      //CIOLogView_output (s);
+      if (fakestream==stdout || fakestream==stderr || fakestream==NULL)
+      {
+          if (fout==NULL) 
+         {
+             for (file_cnt=0; file_cnt<20; file_cnt++)
+             {
+                 sprintf(fname,"dbg%d.log",file_cnt);
+                 if ((fout=fopen(fname),"r")!=NULL)
+                     fclose(fout);
+                 else
+                     break;
+             }
+             fout=fopen(fname,"w");
+             if (fout==NULL) 
+                 return;
+         }
+         fakestream=fout;
+      }
+      fprintf(fakestream,data);
+      fflush(fakestream);
+#endif /* REDIRECT */
+}
+
+void printf_dbg(const char* format,...)
+{
+  va_list args;
+  char buf[256];
+  va_start (args, format);
+  vsprintf (buf, format, args);
+  puts_dbg(buf);
+  va_end (args);
+}
diff --git a/gdb/debugify.h b/gdb/debugify.h
new file mode 100644 (file)
index 0000000..e250910
--- /dev/null
@@ -0,0 +1,42 @@
+
+#ifndef _DEBUGIFY_H_
+#define _DEBUGIFY_H_
+
+#ifdef DEBUGIFY
+#include <assert.h>
+#ifdef TO_SCREEN
+#define DBG(x) OutputDebugString x
+#elif TO_GDB
+#define DBG(x) printf_unfiltered x
+#elif TO_POPUP
+#define DBG(x) MessageBox x
+#else /* default: TO_FILE "gdb.log" */
+#define DBG(x) printf_dbg x
+#endif 
+
+#define ASSERT(x) assert(x)
+
+#else /* DEBUGIFY */
+#define DBG(x)
+#define ASSERT(x)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef REDIRECT
+#define printf_unfiltered printf_dbg
+#define fputs_unfiltered fputs_dbg
+void fputs_dbg (const char *fmt, FILE *fakestream);
+#endif /* REDIRECT */
+
+void puts_dbg(const char *fmt);
+void printf_dbg(const char *fmt,...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _DEBUGIFY_H_ */
+