1

I made small assembly code about registering signal handler.

.section .data
.set SIGSEGV, 11
.set SA_SIGINFO, 4

.section .bss   
.lcomm my_sigaction, 140 # size of sigaction struction is 140

.section .text
.global main

myhandler:
    nop
    push %eax
    pop %eax

main:
    # Registring signal handler for SIGSEGV
    movl $myhandler, my_sigaction           # fill sa_handler field 
    movl $132, %edi                         # fill sa_flags field
    movl $SA_SIGINFO, my_sigaction(,%edi,1) # SA_SIGINFO  designate that whenever signal appears, run the signal handling function.

    # Call sigaction(int, const struct sigaction *, struct sigaction *)
    pushl $0                                # 1st param : oact
    pushl $my_sigaction                     # 2nd param : act
    pushl $SIGSEGV                          # 3rd param : sig
    call sigaction
    addl $12, %esp

    jmp 0x11223344                         # Segmantation fault    

When I execute compiled binary, myhandler worked well.

However ... when I tried to debug this, gdb just stoped after SIGSEGV signal occurred.
So I could not reach to myhandler with gdb..

Question.
How can I debug myhandler function, which runs after SIGSEGV signal?

PS 1. I checked here, but setting follow-process-mode wasn't helpful in my case. ;(
PS 2. I checked here, but after asserting handle SIGSEGV nostop, gdb infinitely emits the "Program received signal SIGSEGV, Segmentation fault" message when SIGSEGV occured...

Jiwon
  • 1,074
  • 1
  • 11
  • 27

1 Answers1

3

I solved the problem myself.

pwndbg> b myhandler
pwndbg> handle SIGSEGV pass
Signal        Stop  Print   Pass to program Description
SIGSEGV       Yes   Yes Yes     Segmentation fault
pwndbg> handle SIGSEGV nostop
Signal        Stop  Print   Pass to program Description
SIGSEGV       No    Yes Yes     Segmentation fault
pwndbg> r
Breakpoint myhandler

Setting pass and nostop on SIGSEGV signal worked!
After SIGSEGV occured, I can still debug binary on gdb.

Jiwon
  • 1,074
  • 1
  • 11
  • 27