Created
August 27, 2015 20:57
-
-
Save o11c/ac1ab2b43639367ded60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // valid values for each: 0-2, where 0 is "do nothing" | |
| #define SIGNAL_MODE 1 | |
| #define RAISE_MODE 2 | |
| #include <signal.h> | |
| #include <stdio.h> | |
| void handler(int _) | |
| { | |
| // In general it is not safe to call stdio functions from a signal | |
| // handler, but in this case it only called from a particular place | |
| // in main so happens to be safe. | |
| puts("signal"); | |
| } | |
| int main() | |
| { | |
| #if SIGNAL_MODE == 1 | |
| signal(SIGTRAP, SIG_IGN); | |
| #endif | |
| #if SIGNAL_MODE == 2 | |
| signal(SIGTRAP, handler); | |
| #endif | |
| #if RAISE_MODE == 1 | |
| raise(SIGTRAP); | |
| #endif | |
| #if RAISE_MODE == 2 | |
| asm("int3"); | |
| #endif | |
| puts("Hello, World!"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment