How can I get the execution context in a signal handler?

I get an error illegal operandwhen starting the program. The program in which the crash occurs is written to the assembly and linked as an object file, so I'm not sure how to use it gdb. I noticed an error capturing a signal SIGILL. I want to get the address of the violating instruction. One of the methods that comes to my mind is to get the last execution context in the signal handler and write the value from it rip. I know that this context is passed to signal handlers, but I don’t know how to do it.

+3
source share
2 answers

If you want to follow the route of the signal handler, it is easy to get the address of the instruction that causes the signal handler to start. When you create your signal handler, set the bit SA_SIGINFOin the flag settings. Then, when you write the handler, it will have access to the structure siginfo_t, which includes the field si_addr, which is the address of the memory cell that caused the exception.

+4
source

written in the assembly and linked as an object file, so I'm not sure how to use gdb with it

GDB is great for debugging build code. You will need info registers, x/i $pc.

One of the methods that comes to my mind is to get the last execution context in the signal handler and write the value of the rip register from it.

(. , ).

, , GDB . , GDB , , , .

0

All Articles