mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2025-01-22 16:20:29 +01:00
(sighandler): New function.
(main): Install SIGTERM handler and send SIGTERM to self to test backtracing through signal handler. (Logical change 1.18)
This commit is contained in:
parent
4d37950b2c
commit
72e98c4610
1 changed files with 15 additions and 0 deletions
15
tests/bt.c
15
tests/bt.c
|
@ -15,6 +15,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
GNU General Public License for more details. */
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <libunwind.h>
|
||||
|
@ -66,9 +67,23 @@ foo (void)
|
|||
printf ("[%d] ip=%p\n", i, buffer[i]);
|
||||
}
|
||||
|
||||
int
|
||||
sighandler (int signal, void *siginfo, struct sigcontext *sc)
|
||||
{
|
||||
void *buffer[20];
|
||||
int n;
|
||||
|
||||
printf ("sighandler: got signal %d @ %lx\n", signal, sc->sc_ip);
|
||||
|
||||
do_backtrace();
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
foo ();
|
||||
|
||||
signal (SIGTERM, sighandler);
|
||||
kill (getpid (), SIGTERM);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue