* ser-unix.c (wait_for): Do not reset timeout_remaining for cygwin32 so
[deliverable/binutils-gdb.git] / gdb / debugify.c
CommitLineData
4659e3b3 1
27e81a4e
DP
2/* Debug macros for developemnt.
3 Copyright 1997
4 Free Software Foundation, Inc.
5
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
7ae78a73
DP
22#define DEBUGIFY
23#include "debugify.h"
24#include "config.h"
25
4659e3b3 26#include <stdio.h>
27e81a4e 27#ifdef HAVE_STDLIB_H
4659e3b3 28#include <stdlib.h>
27e81a4e
DP
29#endif
30#ifdef HAVE_STRING_H
4659e3b3 31#include <string.h>
27e81a4e
DP
32#else
33#include <strings.h>
34#endif
4659e3b3 35
4659e3b3
DP
36#define REDIRECT
37
27e81a4e 38static FILE *fout = NULL;
4659e3b3 39static char fname[128];
27e81a4e 40static int file_cnt = 0; /* count number of open files */
4659e3b3 41
27e81a4e 42void
8662603f
DP
43puts_dbg (data)
44 const char *data;
4659e3b3 45{
27e81a4e 46 FILE *fdbg;
4659e3b3 47
27e81a4e
DP
48 fdbg = fopen ("dbg.log", "a+");
49 if (fdbg == NULL)
50 return;
51 fprintf (fdbg, data);
52 fclose (fdbg);
4659e3b3
DP
53}
54
55/* Can't easily get the message back to gdb... write to a log instead. */
27e81a4e 56void
8662603f
DP
57fputs_dbg (data, fakestream)
58 const char *data;
59 FILE *fakestream;
4659e3b3
DP
60{
61#ifdef REDIRECT
27e81a4e 62 puts_dbg (data);
4659e3b3 63#else /* REDIRECT */
27e81a4e
DP
64
65 if (fakestream == stdout || fakestream == stderr || fakestream == NULL)
66 {
67 if (fout == NULL)
68 {
69 for (file_cnt = 0; file_cnt < 20; file_cnt++)
70 {
71 sprintf (fname, "dbg%d.log", file_cnt);
72 if ((fout = fopen (fname), "r") != NULL)
73 fclose (fout);
74 else
75 break;
76 }
77 fout = fopen (fname, "w");
78 if (fout == NULL)
79 return;
80 }
81 fakestream = fout;
82 }
83 fprintf (fakestream, data);
84 fflush (fakestream);
4659e3b3
DP
85#endif /* REDIRECT */
86}
87
27e81a4e 88void
8662603f 89#ifdef ANSI_PROTOTYPES
27e81a4e 90printf_dbg (const char *format,...)
8662603f
DP
91#else
92printf_dbg (va_alist)
93 va_dcl
94#endif
4659e3b3
DP
95{
96 va_list args;
97 char buf[256];
8662603f 98#ifdef ANSI_PROTOTYPES
4659e3b3 99 va_start (args, format);
8662603f
DP
100#else
101 char *format;
102
103 va_start (args);
104 format = va_arg (args, char *);
105#endif
4659e3b3 106 vsprintf (buf, format, args);
27e81a4e 107 puts_dbg (buf);
4659e3b3
DP
108 va_end (args);
109}
This page took 0.08831 seconds and 4 git commands to generate.