[PATCH] Adding support for reading signal hanlder frame in AIX

Sangamesh Mallayya sangamesh.swamy@in.ibm.com
Mon Jan 15 03:42:00 GMT 2018


Hi All,

Attached patch adds support for reading signal handler frame in AIX.

If gdb is debugging an application which has a signal handler and reaches 
the signal handler frame, 
then we need to read the back chain address from sigconext saved on the 
stack, similarly the LR.

As backchain at an offset 0 will be 0, because we will have sigconext 
saved after the minimum stack size. 
So, correct backchain will be at an offset after minimum stack and the LR 
at an offset 8 will be of the signal millicode address.
If the back chain pointer is NULL and the LR field is in the kernel 
segment(ex. 0x00004a14) then we can probably assume we are in a signal 
handler.

This can be demonstrated using the below sample program.

#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>

void sig_handle(int signo)
{
  printf("Caught signal: %d\n",signo);
  signal(SIGSEGV,sig_handle);
}

void foo()
{
  char *p; 
  signal(SIGSEGV, sig_handle); /* signal handler */
  strcpy(p,"Hello");
  sleep(1); /* Sleep to catch signal */
}

int main()
{
  pthread_t tid;
  pthread_attr_t attr;

  pthread_attr_init(&attr);
  pthread_create(&tid, &attr, (void*)foo, NULL);
  sleep(1);
  pthread_kill(tid,SIGSEGV);

  pthread_join(tid,NULL);
}


Debugging without the patch
------------------------------------
Here gdb stops at frame #1 as it doesn't understand the signal handler 
frame as backchain at offset 0 will be 0.

Reading symbols from /home/sangam/gdb_sighandle/thread-signal1...done.
(gdb) br sig_handle
Breakpoint 1 at 0x10000550: file thread-signal1.c, line 9.
(gdb) r
Starting program: /home/sangam/gdb_sighandle/thread-signal1 
[New Thread 1]
[New Thread 258]

Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1]
0xd057b720 in _vp_start () from /usr/lib/libpthread.a(shr_xpg5.o)
(gdb) c
Continuing.
[Switching to Thread 258]

Thread 3 hit Breakpoint 1, sig_handle (signo=11) at thread-signal1.c:9
9         printf("Caught signal: %d\n",signo);

(gdb) bt
#0  sig_handle (signo=11) at thread-signal1.c:9
#1  0x00004a14 in ?? ()
(gdb) 

Debugging with the patch
--------------------------------
Here gdb reads the signal handler frame  and gets the correct back and LR 
value.

Reading symbols from /home/sangam/gdb_sighandle/thread-signal1...done.
(gdb) br sig_handle
Breakpoint 1 at 0x10000550: file thread-signal1.c, line 9.
(gdb) r
Starting program: /home/sangam/gdb_sighandle/thread-signal1 
[New Thread 1]
[New Thread 258]

Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1]
0xd057b720 in _vp_start () from /usr/lib/libpthread.a(shr_xpg5.o)
(gdb) c
Continuing.
[Switching to Thread 258]

Thread 3 hit Breakpoint 1, sig_handle (signo=11) at thread-signal1.c:9
9         printf("Caught signal: %d\n",signo);
(gdb) bt
#0  sig_handle (signo=11) at thread-signal1.c:9
#1  0x100005e0 in foo () at thread-signal1.c:17
#2  0x100005cc in foo () at thread-signal1.c:16
#3  0xd0564f68 in _pthread_body () from /usr/lib/libpthread.a(shr_xpg5.o)
#4  0x00000000 in ?? ()
(gdb) 


Here is the gdb.base testsuite summary

                === gdb Summary ===

# of expected passes            13509
# of unexpected failures        4229
# of expected failures          14
# of unresolved testcases       3
# of untested testcases         61
# of unsupported tests          32


# of expected passes            13515
# of unexpected failures        4224
# of expected failures          14
# of unresolved testcases       3
# of untested testcases         61
# of unsupported tests          32


Please review and let me know your comments.



Thanks,
Sangamesh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signal_handler_aix.patch
Type: application/octet-stream
Size: 5015 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20180115/652e3a5e/attachment.obj>


More information about the Gdb-patches mailing list