diff options
author | Dawn Perchik <dawn@cygnus> | 1997-02-12 22:48:45 +0000 |
---|---|---|
committer | Dawn Perchik <dawn@cygnus> | 1997-02-12 22:48:45 +0000 |
commit | 4659e3b3672dd188d167d8dba5c9a429c3cdaf51 (patch) | |
tree | b057fc2855e7cc9fbbb4dd214fa911f91045bdb3 /gdb/debugify.c | |
parent | 19336eb964e520638e838e895563ced9ddeec2d8 (diff) | |
download | gdb-4659e3b3672dd188d167d8dba5c9a429c3cdaf51.zip gdb-4659e3b3672dd188d167d8dba5c9a429c3cdaf51.tar.gz gdb-4659e3b3672dd188d167d8dba5c9a429c3cdaf51.tar.bz2 |
* debugify.c, debugify.h: New files. Provide common macros
for writing debug info to a log file or stdio.
Diffstat (limited to 'gdb/debugify.c')
-rw-r--r-- | gdb/debugify.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gdb/debugify.c b/gdb/debugify.c new file mode 100644 index 0000000..7f5af2a --- /dev/null +++ b/gdb/debugify.c @@ -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); +} |