]> Git Repo - binutils.git/blob - gdb/debugify.c
7f5af2a681e73b262847c56255cf324a6efb9af3
[binutils.git] / gdb / debugify.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <stdarg.h>
6
7 #define DEBUGIFY
8 #include "debugify.h"
9
10 #define REDIRECT
11
12 static FILE *fout=NULL;
13 static char fname[128];
14 static int file_cnt=0;  /* count number of open files */
15
16 void puts_dbg(const char *data)
17 {
18     FILE *fdbg;
19
20     fdbg=fopen("dbg.log","a+");
21     if (fdbg==NULL) 
22         return;
23     fprintf(fdbg,data);
24     fclose(fdbg);
25 }
26
27 /* Can't easily get the message back to gdb... write to a log instead. */
28 void fputs_dbg (const char *data, FILE * fakestream)
29 {
30 #ifdef REDIRECT
31     puts_dbg(data);
32 #else /* REDIRECT */
33       
34       //CIOLogView_output (s);
35       if (fakestream==stdout || fakestream==stderr || fakestream==NULL)
36       {
37           if (fout==NULL) 
38           {
39               for (file_cnt=0; file_cnt<20; file_cnt++)
40               {
41                   sprintf(fname,"dbg%d.log",file_cnt);
42                   if ((fout=fopen(fname),"r")!=NULL)
43                       fclose(fout);
44                   else
45                       break;
46               }
47               fout=fopen(fname,"w");
48               if (fout==NULL) 
49                   return;
50           }
51           fakestream=fout;
52       }
53       fprintf(fakestream,data);
54       fflush(fakestream);
55 #endif /* REDIRECT */
56 }
57
58 void printf_dbg(const char* format,...)
59 {
60   va_list args;
61   char buf[256];
62   va_start (args, format);
63   vsprintf (buf, format, args);
64   puts_dbg(buf);
65   va_end (args);
66 }
This page took 0.018318 seconds and 2 git commands to generate.