]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ||
3 | This program is a wrapper to assist in debugging analigned traps on the Alpha | |
4 | ||
5 | architectures. | |
6 | ||
7 | ||
8 | ||
9 | COPYRIGHT AND PERMISSION NOTICE | |
10 | ||
11 | ||
12 | ||
13 | Copyright (c) 2002 Sean Hunter | |
14 | ||
15 | ||
16 | ||
17 | Permission is hereby granted, free of charge, to any person obtaining a | |
18 | ||
19 | copy of this software and associated documentation files (the | |
20 | ||
21 | "Software"), to deal in the Software without restriction, including | |
22 | ||
23 | without limitation the rights to use, copy, modify, merge, publish, | |
24 | ||
25 | distribute, and/or sell copies of the Software, and to permit persons | |
26 | ||
27 | to whom the Software is furnished to do so, provided that the above | |
28 | ||
29 | copyright notice(s) and this permission notice appear in all copies of | |
30 | ||
31 | the Software and that both the above copyright notice(s) and this | |
32 | ||
33 | permission notice appear in supporting documentation. | |
34 | ||
35 | ||
36 | ||
37 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
38 | ||
39 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
40 | ||
41 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | |
42 | ||
43 | OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
44 | ||
45 | HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL | |
46 | ||
47 | INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING | |
48 | ||
49 | FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
50 | ||
51 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | |
52 | ||
53 | WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
54 | ||
55 | ||
56 | ||
57 | Except as contained in this notice, the name of a copyright holder | |
58 | ||
59 | shall not be used in advertising or otherwise to promote the sale, use | |
60 | ||
61 | or other dealings in this Software without prior written authorization | |
62 | ||
63 | of the copyright holder. | |
64 | ||
65 | ||
66 | ||
67 | -------------------------------------------------------------------------------- | |
68 | ||
69 | All trademarks and registered trademarks mentioned herein are the property | |
70 | ||
71 | of their respective owners. | |
72 | ||
73 | ||
74 | ||
75 | */ | |
76 | ||
77 | #include <errno.h> | |
78 | ||
79 | #include <stdio.h> | |
80 | ||
81 | ||
82 | ||
83 | #include <asm/sysinfo.h> | |
84 | ||
85 | #include <asm/unistd.h> | |
86 | ||
87 | ||
88 | ||
89 | #define TMP_PATH_MAX 1024 | |
90 | ||
91 | ||
92 | ||
93 | ||
94 | ||
95 | static int | |
96 | ||
97 | setsysinfo(unsigned long op, void *buffer, unsigned long size, | |
98 | ||
99 | int *start, void *arg, unsigned long flag) | |
100 | ||
101 | { | |
102 | ||
103 | syscall(__NR_osf_setsysinfo, op, buffer, size, start, arg, flag); | |
104 | ||
105 | } | |
106 | ||
107 | ||
108 | ||
109 | ||
110 | ||
111 | void | |
112 | ||
113 | trap_unaligned(void) | |
114 | ||
115 | { | |
116 | ||
117 | unsigned int buf[2]; | |
118 | ||
119 | buf[0] = SSIN_UACPROC; | |
120 | ||
121 | buf[1] = UAC_SIGBUS | UAC_NOPRINT; | |
122 | ||
123 | setsysinfo(SSI_NVPAIRS, buf, 1, 0, 0, 0); | |
124 | ||
125 | } | |
126 | ||
127 | ||
128 | ||
129 | ||
130 | ||
131 | static void | |
132 | ||
133 | usage(void) | |
134 | ||
135 | { | |
136 | ||
137 | fprintf(stderr, | |
138 | ||
139 | "usage: unaligned [-b] <command-path> [command-args...]\n\n" | |
140 | ||
141 | " This program is designed to assist debugging of\n" | |
142 | ||
143 | " unaligned traps by running the program in gdb\n" | |
144 | ||
145 | " and causing it to get SIGBUS when it encounters\n" | |
146 | ||
147 | " an unaligned trap.\n\n" | |
148 | ||
149 | " It is free software written by Sean Hunter <sean@uncarved.co.uk>\n" | |
150 | ||
151 | " based on code by Richard Henderson and Andrew Morgan.\n\n" | |
152 | ||
153 | ); | |
154 | ||
155 | ||
156 | ||
157 | exit(1); | |
158 | ||
159 | } | |
160 | ||
161 | ||
162 | ||
163 | ||
164 | ||
165 | int | |
166 | ||
167 | main(int argc, char **argv) | |
168 | ||
169 | { | |
170 | ||
171 | const char my_debugger[] = "/usr/bin/gdb"; | |
172 | ||
173 | ||
174 | ||
175 | char *temp_str; | |
176 | ||
177 | char *curr; | |
178 | ||
179 | int size = 0; | |
180 | ||
181 | int curr_arg; | |
182 | ||
183 | int isBatchMode = 0; | |
184 | ||
185 | ||
186 | ||
187 | /* check that we have at least 1 argument */ | |
188 | ||
189 | if (argc < 2) { | |
190 | ||
191 | usage(); | |
192 | ||
193 | } | |
194 | ||
195 | if( strcmp("-b" , argv[1]) == 0 ){ | |
196 | ||
197 | isBatchMode = 1; | |
198 | ||
199 | curr_arg = 2; | |
200 | ||
201 | }else{ | |
202 | ||
203 | curr_arg = 1; | |
204 | ||
205 | } | |
206 | ||
207 | ||
208 | ||
209 | trap_unaligned(); | |
210 | ||
211 | ||
212 | ||
213 | if (argc > 2) { | |
214 | ||
215 | /* We're going to use bash process redirection to create a "file" for gdb to read | |
216 | ||
217 | * containing the arguments we need */ | |
218 | ||
219 | size = 2048; | |
220 | ||
221 | for(; curr_arg < argc; curr_arg++) { | |
222 | ||
223 | size += strlen(argv[curr_arg]); | |
224 | ||
225 | } | |
226 | ||
227 | temp_str = (char *) malloc(sizeof(char) * size); | |
228 | ||
229 | if (!temp_str) { | |
230 | ||
231 | fprintf(stderr, "Unable to malloc memory for string use: %s\n", strerror(errno)); | |
232 | ||
233 | exit(255); | |
234 | ||
235 | } | |
236 | ||
237 | if(isBatchMode==1){ | |
238 | ||
239 | sprintf(temp_str, "%s -batch %s -x <( echo file %s; echo set args", my_debugger, argv[2], argv[2]); | |
240 | ||
241 | }else{ | |
242 | ||
243 | sprintf(temp_str, "%s %s -x <( echo file %s; echo set args", my_debugger, argv[1], argv[1]); | |
244 | ||
245 | } | |
246 | ||
247 | curr = temp_str + strlen(temp_str); | |
248 | ||
249 | for(curr_arg = 2; curr_arg < argc; curr_arg++) { | |
250 | ||
251 | sprintf(curr, " %s", argv[curr_arg]); | |
252 | ||
253 | curr = temp_str + strlen(temp_str); | |
254 | ||
255 | } | |
256 | ||
257 | #ifndef NOAUTORUN | |
258 | ||
259 | curr = temp_str + strlen(temp_str); | |
260 | ||
261 | sprintf(curr, "; echo run"); | |
262 | ||
263 | #endif | |
264 | ||
265 | curr = temp_str + strlen(temp_str); | |
266 | ||
267 | sprintf(curr, ")"); | |
268 | ||
269 | ||
270 | ||
271 | execlp("/bin/bash", "/bin/bash", "-c", temp_str, NULL); | |
272 | ||
273 | ||
274 | ||
275 | } | |
276 | ||
277 | else { | |
278 | ||
279 | execlp(my_debugger, my_debugger, argv[1], NULL); | |
280 | ||
281 | } | |
282 | ||
283 | ||
284 | ||
285 | /* if we fall through to here, our exec failed -- announce the fact */ | |
286 | ||
287 | fprintf(stderr, "Unable to execute command: %s\n", strerror(errno)); | |
288 | ||
289 | ||
290 | ||
291 | usage(); | |
292 | ||
293 | ||
294 | ||
295 | } | |
296 | ||
297 | ||
298 | ||
299 | /* use gcc unaligned.c -o unaliged to compile. Add -DNOAUTORUN if you | |
300 | ||
301 | don't want gdb to automatically run the program */ | |
302 | ||
303 | ||
304 |