Debugging a program that uses SIGINT with gdb

前端 未结 3 1732
挽巷
挽巷 2021-02-07 09:41

I frequently work with PostgreSQL for debugging, and it uses SIGINT internally for some of its inter-backend signalling.

As a result when running certain ba

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-07 10:18

    On UNIX-like systems, you can distinguish a tty-initiated SIGINT from one sent by kill by looking at the si_pid element in the siginfo struct. If the pid is 0, it came from a tty.

    So you could do something like this:

    catch signal SIGINT
    commands
      if $_siginfo._sifields._kill.si_pid == 0
        print "Received SIGINT from tty"
      else
        printf "Received SIGINT from %d; continuing\n", $_siginfo._sifields._kill.si_pid
        signal SIGINT
      end
    end
    

提交回复
热议问题