]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/unalignedtest/unaligned.c
3 This program is a wrapper to assist in debugging analigned traps on the Alpha
9 COPYRIGHT AND PERMISSION NOTICE
13 Copyright (c) 2002 Sean Hunter
17 Permission is hereby granted, free of charge, to any person obtaining a
19 copy of this software and associated documentation files (the
21 "Software"), to deal in the Software without restriction, including
23 without limitation the rights to use, copy, modify, merge, publish,
25 distribute, and/or sell copies of the Software, and to permit persons
27 to whom the Software is furnished to do so, provided that the above
29 copyright notice(s) and this permission notice appear in all copies of
31 the Software and that both the above copyright notice(s) and this
33 permission notice appear in supporting documentation.
37 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
43 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
45 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
47 INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
49 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
51 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
53 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
57 Except as contained in this notice, the name of a copyright holder
59 shall not be used in advertising or otherwise to promote the sale, use
61 or other dealings in this Software without prior written authorization
63 of the copyright holder.
67 --------------------------------------------------------------------------------
69 All trademarks and registered trademarks mentioned herein are the property
71 of their respective owners.
83 #include <asm/sysinfo.h>
85 #include <asm/unistd.h>
89 #define TMP_PATH_MAX 1024
97 setsysinfo(unsigned long op
, void *buffer
, unsigned long size
,
99 int *start
, void *arg
, unsigned long flag
)
103 syscall(__NR_osf_setsysinfo
, op
, buffer
, size
, start
, arg
, flag
);
119 buf
[0] = SSIN_UACPROC
;
121 buf
[1] = UAC_SIGBUS
| UAC_NOPRINT
;
123 setsysinfo(SSI_NVPAIRS
, buf
, 1, 0, 0, 0);
139 "usage: unaligned [-b] <command-path> [command-args...]\n\n"
141 " This program is designed to assist debugging of\n"
143 " unaligned traps by running the program in gdb\n"
145 " and causing it to get SIGBUS when it encounters\n"
147 " an unaligned trap.\n\n"
149 " It is free software written by Sean Hunter <sean@uncarved.co.uk>\n"
151 " based on code by Richard Henderson and Andrew Morgan.\n\n"
167 main(int argc
, char **argv
)
171 const char my_debugger
[] = "/usr/bin/gdb";
187 /* check that we have at least 1 argument */
195 if( strcmp("-b" , argv
[1]) == 0 ){
215 /* We're going to use bash process redirection to create a "file" for gdb to read
217 * containing the arguments we need */
221 for(; curr_arg
< argc
; curr_arg
++) {
223 size
+= strlen(argv
[curr_arg
]);
227 temp_str
= (char *) malloc(sizeof(char) * size
);
231 fprintf(stderr
, "Unable to malloc memory for string use: %s\n", strerror(errno
));
239 sprintf(temp_str
, "%s -batch %s -x <( echo file %s; echo set args", my_debugger
, argv
[2], argv
[2]);
243 sprintf(temp_str
, "%s %s -x <( echo file %s; echo set args", my_debugger
, argv
[1], argv
[1]);
247 curr
= temp_str
+ strlen(temp_str
);
249 for(curr_arg
= 2; curr_arg
< argc
; curr_arg
++) {
251 sprintf(curr
, " %s", argv
[curr_arg
]);
253 curr
= temp_str
+ strlen(temp_str
);
259 curr
= temp_str
+ strlen(temp_str
);
261 sprintf(curr
, "; echo run");
265 curr
= temp_str
+ strlen(temp_str
);
271 execlp("/bin/bash", "/bin/bash", "-c", temp_str
, NULL
);
279 execlp(my_debugger
, my_debugger
, argv
[1], NULL
);
285 /* if we fall through to here, our exec failed -- announce the fact */
287 fprintf(stderr
, "Unable to execute command: %s\n", strerror(errno
));
299 /* use gcc unaligned.c -o unaliged to compile. Add -DNOAUTORUN if you
301 don't want gdb to automatically run the program */