Skip to content

Instantly share code, notes, and snippets.

@o11c
Created August 27, 2015 20:57
Show Gist options
  • Select an option

  • Save o11c/ac1ab2b43639367ded60 to your computer and use it in GitHub Desktop.

Select an option

Save o11c/ac1ab2b43639367ded60 to your computer and use it in GitHub Desktop.
// 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