This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Problems with hook-stop
- From: "Carl Shapiro" <carl dot shapiro at gmail dot com>
- To: gdb at sourceware dot org
- Date: Wed, 26 Sep 2007 01:33:11 -0700
- Subject: Problems with hook-stop
Hi,
I am trying to write a user-defined command hook that automatically
passes a SIGTRAP to my program. Here is the definition I am working
with:
define hook-stop
if (((* (char *) ($pc - 1)) & 0xff) == 0xcc)
signal SIGTRAP
end
end
My target architecture is x86. This command fires the first time I
hit an "int3" instruction. The next time I hit an int3, hook-stop is
not executed and I must manually pass a SIGTRAP by evaluating "signal
SIGTRAP". It seems that every other time gdb is stopped with a
SIGTRAP the stop hook is not executed. Here's a program that can be
used to demonstrate this:
#include <signal.h>
#include <stdio.h>
void handler(int signum) {
fprintf(stderr, "handler(signum=%d)\n", signum);
}
int main(int argc, char *argv[]) {
struct sigaction sa;
int i;
sa.sa_handler = handler;
for (i = 0;; ++i) {
fprintf(stderr, "i=%d\n", i);
asm("int3");
}
return 0;
}
If I remove the "signal SIGTRAP" statement from hook-stop, it fires
every time around the loop. Does anyone know where am I going wrong
wrong?
Thanks,
Carl