Skip to content

Commit

Permalink
Adjust readme
Browse files Browse the repository at this point in the history
  • Loading branch information
raub committed Oct 29, 2024
1 parent 9af034e commit 80d204f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ npm i -s segfault-raub
This module installs platform-specific **signal** listeners
(see `sigaction` for **Unix** and `SetUnhandledExceptionFilter` for **Windows**).
Whenever a signal is raised, the module prints a native stack trace (if possible) to both
**STDERR** and to the "**segfault.log**" file (if it exists). If there is no such file, it
**STDERR** and to the "**segfault.log**" file (if it exists inside "working directory").
If there is no such file, it
**won't be created**, so it is up to you if the log-file is needed.

> Note: this **addon uses N-API**, and therefore is ABI-compatible across different
Expand All @@ -31,8 +32,18 @@ require('segfault-raub');
will seize `global['segfault-raub']`. The rest of them will only re-export `global['segfault-raub']`
and **WILL NOT** import their own **binaries**.

---

## Enabling Signals
If you want to use a custom location instead of "**segfault.log**", use

```js
require('segfault-raub').setLogPath("C:/my/log/file.txt");
```

See the [TypeScript declarations](/index.d.ts) with comments.


## Configuring Signals

As listed below, some signals (platform specific) are enabled by default. But they can be
enabled/disabled manually:
Expand Down
33 changes: 25 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
declare module "segfault-raub" {
/**
* Produce a segfault
* Issue an actual segfault, accessing some unavailable memory
*/
* Produce a segfault.
*
* Issue an actual segfault, accessing some unavailable memory.
*/
export const causeSegfault: () => void;

/**
* Divides an integer number by zero.
*/
*/
export const causeDivisionInt: () => void;

/**
* Overflows the program stack.
*/
*/
export const causeOverflow: () => void;

/**
* Executes an illegal instruction.
*/
*/
export const causeIllegal: () => void;

// enable / disable signal handlers

/**
* Enable / disable signal handlers.
*/
export const setSignal: (signalId: number | null, value: boolean) => void;

/**
* Change the path of "segfault.log" location.
*
* E.g. you can set it to `"C:/my.log"` or whatever.
* But you still have to create the file separately,
* the addon won't do that automatically.
*
* If `null` or `""` path passed - resets to "segfault.log".
*/
export const setLogPath: (path: string | null) => void;

// Windows OS constants:
export const EXCEPTION_ALL: number | null;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/segfault-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ DBG_EXPORT JS_METHOD(setLogPath) { NAPI_ENV;
LET_STR_ARG(0, path);

if (!path.length()) {
strcpy_s(logFilePath, "segfault.log");
strcpy(logFilePath, "segfault.log");
RET_UNDEFINED;
}

strcpy_s(logFilePath, path.c_str());
strcpy(logFilePath, path.c_str());
RET_UNDEFINED;
}

Expand Down

0 comments on commit 80d204f

Please sign in to comment.