Re: Signals (SIGVTALARM) and the current function... (fwd)

From: StormeRider (silk@ici.net)
Date: 07/28/00


Fair warning: this is an OLD post that I finally got to look at.

>This is how to make it work on libc5 (note, I have not tested this
>myself):
>
>
>Subject:      Re: Saved Context Access in exception handler
>From:         seyko@p5.f434.n5020.z2.fidonet.org (Sergey Korshunoff)
>Date:         1998/05/25
>Message-ID:   <6kbj60$2kr@p5.f434.n5020.z2.fidonet.org>
>Newsgroups:   comp.os.linux.development.apps
>  [More Headers]
>[Subscribe to comp.os.linux.development.apps]
>[LINK]
>
>Look at the example. It works for libc v5.x.x and for glibc (libc v6.0.x)
>Regards,
>         Sergey Korshunoff
>
>
>== begin  ===================================================================
>#include <stdio.h>      /* fprintf() */
>#include <unistd.h>     /* _exit() */
>#include <string.h>     /* strsignal() */
>#include <signal.h>     /* signal(), sigcontext */
>
># if defined( _LINUX_C_LIB_VERSION_MAJOR ) && _LINUX_C_LIB_VERSION_MAJOR==5
>#   include <asm/sigcontext.h>    /* sigcontext (for libc 5.x.x) */
>#   define sigcontext sigcontext_struct
># endif
>
>
>void sig_handler ( int signum, struct sigcontext info )
>{
>     if( signum == SIGSEGV )
>     {
>         fprintf( stderr,
>                  "Fatal error: segmentation violation accessing %p\n"
>                  " caused by code at %p\n",
>                         (void *)info.cr2, (void *)info.eip );
>     }
>
>     fprintf( stderr,
>              "Program terminated by signal `%d' (%s)\n",
>                         signum, strsignal(signum));
>
>     _exit( -1 );
>}
>
>int main()
>{
>   signal(SIGSEGV, (void (*)(int))sig_handler ); /* sigaction() is better */
>   int* p= (int *)0x10;
>
>   *p=1;
>
>   return 0;
>}
>
>
>==============================================================================
><erwin@andreasen.com>      Herlev, Denmark              UNIX System Programmer
><URL:http://www.abandoned.org/drylock/>     <*>         (not speaking for) DDE
>==============================================================================

Ok, I tried this... I had to modify main like so to get it to work on my
system:

int main()
{
   int* p= (int *)0x10;

   signal(SIGSEGV, (void (*)(int))sig_handler ); /* sigaction() is better */

   *p=1;

   return 0;
}

Having the signal before declaring the variable p irritated my compiler. :)
What I was wondering is if anyone knows how to do this with a sigaction-based
setup. Ie, for my "halt and copyover" handler, I use the following sections
of code:

void init_signals (void)
{
   struct sigaction halt_action, ignore_action, alarm_action;

   halt_action.sa_handler = halt_mud;
   sigemptyset(&halt_action.sa_mask);
   halt_action.sa_flags = SA_NOMASK;

   sigaction( SIGINT,  &halt_action,   NULL ); /* interrupted at keyboard */
   sigaction( SIGQUIT, &halt_action,   NULL ); /* quit at keyboard */
   sigaction( SIGILL,  &halt_action,   NULL ); /* illegal instruction */
   sigaction( SIGFPE,  &halt_action,   NULL ); /* floating point error */
   sigaction( SIGSEGV, &halt_action,   NULL ); /* invalid memory reference */
   sigaction( SIGTERM, &halt_action,   NULL ); /* terminate */
}

Somewhat snipped copy, of course. :) My halt_mud used to be defined as

         void halt_mud (int sig) {

And now is defined as:

         void halt_mud (int sig, struct sigcontext info) {

However, having the sigcontext doesn't seem to make it a valid sa_handler
type... Any ideas? I'm basically looking to use this to add the EIP information
to my automated core-file emails so I can manually gdb the files and find the
section of source for the more "pesky" bugs.... The ones that seem to have
all relevant information blasted from the core file so that gdb doesn't seem to
have any clue where the program was at each frame.

Thanks for the help.

--SR


--
StormeRider             "Peace favor your code."
thelastsunrise.net 9000 (http://www.thelastsunrise.net)
windsofstorm.net 4008 (http://winds.windsofstorm.net)


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT