forked from qunying/rhide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidebug.cc
163 lines (146 loc) · 3.25 KB
/
idebug.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* Copyright (C) 1996-2000 Robert H”hne, see COPYING.RH for details */
/* This file is part of RHIDE. */
#include "rhide.h"
#include <rhutils.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __DJGPP__
#include <dos.h>
#include <dpmi.h>
#endif
#ifdef __DJGPP__
unsigned short win_version = 0;
int nt_detected = 0;
int w95_detected = 0;
/* Return windows version number, or 0 if not returned */
static unsigned short
_get_win_version()
{
__dpmi_regs regs;
regs.x.ax = 0x160a;
__dpmi_int(0x2f, ®s);
if (regs.x.ax)
return 0;
return regs.x.bx;
}
CONSTRUCTOR_FUNCTION(init_win_check)
{
win_version = _get_win_version();
nt_detected = (win_version == 0) && (_get_dos_version(1) == 0x0532);
w95_detected = win_version >= 0x0400;
}
#endif
static const char *
_getenv(char *v)
{
const char *vv = getenv(v);
return vv ? vv : "";
}
static void
sample_program(char *&buf, int c)
{
char *cmd;
#ifdef __DJGPP__
string_dup(cmd,
"echo \"int main(){return 0;}\" | redir -eo gcc -Xlinker -v -Wa,-v -v -o /dev/null -x ");
#else
string_dup(cmd,
"echo \"int main(){return 0;}\" | gcc -Xlinker -v -Wa,-v -v -o /dev/null -x ");
#endif
string_cat(cmd, c ? "c -" : "c++ -");
#ifndef __DJGPP__
string_cat(cmd, " 2>&1");
#endif
string_cat(buf, _("executing: "), "\n", cmd, "\n", NULL);
FILE *f;
char Buf[1000];
f = popen(cmd, "r");
if (!f)
return;
while (fgets(Buf, 999, f))
{
string_cat(buf, Buf);
}
pclose(f);
}
char *
create_bug_report(int call_gcc)
{
char *buf = NULL;
string_cat(buf, "This is a bug report for ");
string_cat(buf, IDEVersion);
string_cat(buf, " (");
string_cat(buf, build_date);
string_cat(buf, " ");
string_cat(buf, build_time);
string_cat(buf, ")\n");
#ifdef __DJGPP__
{
char temp[100];
_get_dos_version(1);
sprintf(temp, "%s %d.%d", _os_flavor, _osmajor, _osminor);
string_cat(buf, "I am running ");
string_cat(buf, temp);
if (win_version > 0)
{
string_cat(buf, " (Windows ");
if (w95_detected)
string_cat(buf, "95");
else
{
sprintf(temp, "%d.%d", win_version / 0x100, win_version & 0xff);
string_cat(buf, temp);
}
string_cat(buf, ")");
}
else if (nt_detected)
{
string_cat(buf, " (Windows NT :-( )");
}
}
#endif
string_cat(buf, "\n\nImportant environment variables:");
#define VAR(x) string_cat(buf,"\n"#x"="); string_cat(buf,_getenv(#x))
VAR(PATH);
#ifdef __DJGPP__
VAR(DJGPP);
VAR(DJDIR);
VAR(LFN);
#endif
VAR(INFOPATH);
VAR(LOCALEDIR);
VAR(LANGUAGE);
VAR(SHELL);
#ifdef __DJGPP__
VAR(COMSPEC);
VAR(DJSYSFLAGS);
#endif
#ifdef __linux__
VAR(TERM);
#endif
string_cat(buf, "\n");
if (call_gcc)
{
string_cat(buf,
"\nHere is the output from a sample compilation and link for C\n");
sample_program(buf, 1);
string_cat(buf, "\nEnd of the sample\n");
string_cat(buf,
"\nHere is the output from a sample compilation and link for C++\n");
sample_program(buf, 0);
string_cat(buf, "\nEnd of the sample\n");
}
string_cat(buf, "\n\n\n\
My problem is the following:\n\
============================\n\
\n\n");
return buf;
}
#ifdef TEST
int
main()
{
fprintf(stderr, "%s", create_bug_report(1));
return 0;
}
#endif