开发者

Address of instruction causing SIGSEGV in external program

I want to get address of instruction that causes external program to SIGSEGV. I tried using ptrace for this, but I'm getting EIP from kernel space (probably default signal handler?). How GDB is able 开发者_运维百科to get the correct EIP?

Is there a way to make GDB provide this information using some API?

edit: I don't have sources of the program, only binary executable. I need automation, so I can't simply use "run", "info registers" in GDB. I want to implement "info registers" in my own mini-debugger :)


You can attach to a process using ptrace. I found an article at Linux Gazette.

It looks like you will want PTRACE_GETREGS for the registers. You will want to look at some example code like strace to see how it manages signal handling and such. It looks to me from reading the documentation that the traced child will stop at every signal and the tracing parent must wait() for the signal from the child then command it to continue using PTRACE_CONT.


Compile your program with -g, run gdb <your_app>, type run and the error will occur. After that use info registers and look in the rip register.

You can use objectdump -D <your_app> to get some more information about the code at that position.


You can enable core dumps with ulimit -c unlimited before running your external program.

Then you can examine the core dump file after a crash using gdb /path/to/program corefile

Because it is binary and not compiled with debugging options you will have to view details at the register and machine code level.


Try making a core dump, then analyse it with gdb. If you meant you wanted to make gdb run all your commands at one touch of a key by 'automate', gdb ca do that too. Type your commands into a file and look into the help user-defined section of manuals, gdb can handle canned commands.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜