MCPcopy Create free account
hub / github.com/ddopson/node-segfault-handler / segfault_stack_frame_1

Function segfault_stack_frame_1

src/segfault-handler.cpp:261–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259// create some stack frames to inspect from CauseSegfault
260#ifndef _WIN32
261__attribute__ ((noinline))
262#else
263__declspec(noinline)
264#endif
265void segfault_stack_frame_1()
266{
267 // DDOPSON-2013-04-16 using the address "1" instead of "0" prevents a nasty compiler over-optimization
268 // When using "0", the compiler will over-optimize (unless using -O0) and generate a UD2 instruction
269 // UD2 is x86 for "Invalid Instruction" ... (yeah, they have a valid code that means invalid)
270 // Long story short, we don't get our SIGSEGV. Which means no pretty demo of stacktraces.
271 // Instead, you see "Illegal Instruction: 4" on the console and the program stops.
272
273 int *foo = (int*)1;
274 fprintf(stderr, "NodeSegfaultHandlerNative: about to dereference NULL (will cause a SIGSEGV)\n");
275 *foo = 78; // trigger a SIGSEGV
276
277}
278
279#ifndef _WIN32
280__attribute__ ((noinline))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected