From: Rich Payne <rdp@talisman.alphalinux.org>
To: axp-list@redhat.com
Subject: Re: Unaligned wrapper
Date: Fri, 20 Aug 1999 09:13:18 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.10.9908200849110.11103-100000@talisman.mv.com> (raw)
In-Reply-To: <Pine.OSF.3.96.990820081330.4990G-100000@perf.zko.dec.com>
We can add this into alphalinux.org, no problem. Just give me a day or
two.
--rdp
On Fri, 20 Aug 1999, Phillip Ezolt wrote:
> Sean,
> This is a REALLY useful program. Could you make sure that it gets
> put either into a FAQ or on the AlphaLinux page?
>
> --Phil
>
> Compaq: Business Critical Servers Division/Benchmark Performance Engineering
> ---------------- Alpha, The Fastest Processor on Earth --------------------
> Phillip.Ezolt@compaq.com |C|O|M|P|A|Q| ezolt@perf.zko.dec.com
>
>
>
> On Thu, 19 Aug 1999, Sean Hunter wrote:
>
> > Here is the wrapper program I wrote to assist with the debugging of
> > unaligned traps. Its the bastard child of something similar Richard
> > Henderson posted here, and the execcap program that Andrew Morgan
> > wrote for the libcap package, with a few bits of mine thrown in.
> > Thanks to Michal Jaegermann for the pointers.
> >
> > Basically, it runs the program given on the commandline in gdb with
> > the given arguments, but sets the flags so that the program will
> > recieve a SIGBUS on encountering an unaligned trap. What you do is
> > compile the code below thussly...
> >
> > gcc unaligned.c -o unaligned
> >
> > ...then you run your naughty program. Say I want to debug the horrid
> > "ping" program that came with redhat 6 (yes I know there's an update,
> > this is just an example). What you do is get the source, build it
> > (without stripping the debugging symbols), change to the directory so
> > that gdb can find the relevant source files (in this case the
> > directory is called "ping"), and go
> >
> > unaligned ping harold
> >
> > ... the "harold" is because I'm testing it by pinging one of the hosts
> > on my network here. You'd substitute a suitable alternative.
> >
> > You'll see the following....
> >
> > Extra arguments passed to gdb in file /tmp/file6krPqZ.
> > Be sure to delete it when you're done.
> >
> > GNU gdb 4.17.0.11 with Linux support
> > Copyright 1998 Free Software Foundation, Inc.
> > GDB is free software, covered by the GNU General Public License, and you are
> > welcome to change it and/or distribute copies of it under certain conditions.
> > Type "show copying" to see the conditions.
> > There is absolutely no warranty for GDB. Type "show warranty" for details.
> > This GDB was configured as "alpha-redhat-linux".
> > PING harold.uncarved.co.uk (10.0.1.1): 56 data bytes
> >
> > Program received signal SIGBUS, Bus error.
> > 0x12000359c in tvsub (out=0x11ffffa30, in=0x1201187fc) at ping.c:885
> > 885 if ((out->tv_usec -= in->tv_usec) < 0) {
> > (gdb)
> >
> > In other words, gdb has run the program and helpfully stopped at the
> > offending line. Now, you just have to figure out how to fix the
> > error...
> >
> > Sean
> >
> > BTW, I'm providing this in the hope that someone will find this
> > useful, and that more people will fix the unaligned traps on alpha.
> > If it doesn't work for you, please mail me and I'll do my best to
> > help.
> >
> >
> >
> > #include <errno.h>
> > #include <stdio.h>
> >
> > #ifndef __linux__
> > #include <sys/sysinfo.h>
> > #else
> > #include <asm/sysinfo.h>
> > #include <asm/unistd.h>
> >
> > static int setsysinfo(unsigned long op, void *buffer, unsigned long size,
> > int *start, void *arg, unsigned long flag)
> > {
> > syscall(__NR_osf_setsysinfo, op, buffer, size, start, arg, flag);
> > }
> > #endif
> >
> >
> > static void usage(void)
> > {
> > fprintf(stderr,
> > "usage: unaligned <command-path> [command-args...]\n\n"
> > " This program is designed to assist debugging of\n"
> > " unaligned traps by running the program in gdb\n"
> > " and causing it to get SIGBUS when it encounters\n"
> > " an unaligned trap.\n\n"
> > " It is free software written by Sean Hunter <sean@uncarved.co.uk>\n"
> > " based on code by Richard Henderson and Andrew Morgan. It is provided\n"
> > " under the gnu public license without warrantees of any kind.\n\n");
> >
> > exit(1);
> > }
> >
> >
> > void trap_unaligned(void)
> > {
> > unsigned int buf[2];
> > buf[0] = SSIN_UACPROC;
> > buf[1] = UAC_SIGBUS | UAC_NOPRINT;
> > setsysinfo(SSI_NVPAIRS, buf, 1, 0, 0, 0);
> >
> > }
> >
> >
> > int main(int argc, char **argv)
> > {
> > char* tmp_filename;
> > char* my_debugger = "/usr/bin/gdb";
> > FILE* tmp_file;
> > int curr_arg;
> >
> > /* check that we have at least 1 argument */
> > if (argc < 2) {
> > usage();
> > }
> >
> > trap_unaligned();
> >
> > if (argc > 2) {
> > /* add the extra args to a file to pass to gdb */
> > tmp_filename = tmpnam(NULL);
> > tmp_file = fopen(tmp_filename, "w+");
> > if (!tmp_file) {
> > fprintf(stderr, "Unable to create temp file %s reason: %s\n",
> > tmp_filename,
> > strerror(errno));
> > }
> >
> > fprintf(tmp_file, "file %s\n", argv[1]);
> > fprintf(tmp_file, "set args");
> > for(curr_arg = 2; curr_arg < argc; curr_arg++) {
> > fprintf(tmp_file, " %s", argv[curr_arg]);
> > }
> > fprintf(tmp_file, "\n");
> > #ifndef NOAUTORUN
> > fprintf(tmp_file, "run\n");
> > #endif
> > fclose(tmp_file);
> >
> > printf("Extra arguments passed to gdb in file %s.\n"
> > "Be sure to delete it when you're done.\n\n",
> > tmp_filename);
> >
> > execlp(my_debugger, argv[1], "-x", tmp_filename, NULL);
> >
> > }
> > else {
> > execlp(my_debugger, argv[1], NULL);
> > }
> >
> > /* if we fall through to here, our exec failed -- announce the fact */
> > fprintf(stderr, "Unable to execute command: %s\n", strerror(errno));
> >
> > usage();
> >
> > }
> >
> > /* use gcc unaligned.c -o unaliged to compile. Add -DNOAUTORUN if you
> > don't want gdb to automatically run the program */
> >
> > --
> > To unsubscribe: send e-mail to axp-list-request@redhat.com with
> > 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
> >
> >
> >
>
> --
> To unsubscribe: send e-mail to axp-list-request@redhat.com with
> 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
>
Rich Payne
rpayne@alphalinux.org www.alphalinux.org
next prev parent reply other threads:[~1999-08-20 13:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-19 22:54 Unaligned wrapper Sean Hunter
1999-08-20 12:14 ` Phillip Ezolt
1999-08-20 13:13 ` Rich Payne [this message]
1999-08-20 17:02 ` Sean Hunter
1999-08-20 19:07 ` Eric Ding
1999-08-20 21:13 ` Michal Jaegermann
1999-08-25 21:45 ` Eric Ding
1999-08-20 21:35 ` Eric Cifreo
-- strict thread matches above, loose matches on Subject: below --
1999-08-20 20:38 Designer Seven
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox