1 /* addr2line.c -- convert addresses to line number and function name
2 Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
4 Contributed by Ulrich Lauther <Ulrich.Lauther@mchp.siemens.de>
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 static int crash_nsymbol
;
29 static void *crash_pointers
[0x100];
30 static char **crash_symbols
;
31 static unsigned crash_signal
;
33 static void crash_handler(int sig
, siginfo_t
*si
, void *ptr
)
35 crash_nsymbol
= backtrace(crash_pointers
, sizeof(crash_pointers
)/sizeof(void*));
37 siglongjmp(crash_buf
, sig
);
40 void set_signals(unsigned activate
)
42 int handle
[] = { SIGABRT
, SIGSEGV
, SIGALRM
};
43 static struct sigaction oldsigs
[sizeof(handle
)/sizeof(*handle
)];
44 struct sigaction newsig
;
46 newsig
.sa_sigaction
= crash_handler
;
47 sigemptyset(&newsig
.sa_mask
);
48 newsig
.sa_flags
= SA_SIGINFO
;
51 for (i
= 0; i
< sizeof(handle
)/sizeof(*handle
); ++i
) {
53 sigaction(handle
[i
], &newsig
, oldsigs
+ i
);
55 sigaction(handle
[i
], oldsigs
+i
, NULL
);
61 void crash_write_backtrace(struct bio
*b
, const char *nick
)
64 b
->writeline(b
, "PRIVMSG %s :Signal %i", nick
, crash_signal
);
65 for (i
= 2; i
< crash_nsymbol
- 1; ++i
)
66 b
->writeline(b
, "PRIVMSG %s :[%i] = %s", nick
, i
-2, crash_symbols
[i
]);
69 void crash_mod(struct bio
*b
, const char *target
)
72 b
->writeline(b
, "PRIVMSG %s :{ Help! A%csistance is required! I believe there is something wrong with me! }", target
, crash_signal
== 6 ? 'S' : 's');
74 b
->writeline(b
, "PRIVMSG %s :Signal %i caught", target
, crash_signal
);
76 crash_symbols
= backtrace_symbols(crash_pointers
, crash_nsymbol
);