Skip to content

Commit

Permalink
chore: better debugging with gdb (#145)
Browse files Browse the repository at this point in the history
* Add nix wrapper for GDB. This is added to docs.

* Use `log_min_messages=INFO` by default for better debugging.

* Add tags to gitignore.
  • Loading branch information
steve-chavez authored Sep 3, 2024
1 parent fb98045 commit de214de
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ nix/nginx/logs/nginx.pid
*.control
*.so
nginx.pid
tags
18 changes: 18 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ select net.http_get('http://localhost:3000/projects');
-- * Connection #0 to host localhost left intact
```

### GDB

To debug the background worker, grab its PID from the logs:

```
$ nix-shell
$ net-with-pg-16 psql
2024-09-02 20:16:26.905 -05 [1145879] INFO: pg_net_worker started with a config of: pg_net.ttl=6 hours, pg_net.batch_size=200, pg_net.database_name=postgres
```

And use it like:

```
$ nix-shell
$ sudo with-gdb -p 1145879
```

## Documentation

All public API must be documented. Building documentation requires python 3.6+
Expand Down
12 changes: 12 additions & 0 deletions nix/gdbScript.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ gdb, writeText, writeShellScriptBin } :

let
file = writeText "gdbconf" ''
# Do this so we can do `backtrace` once a segfault occurs. Otherwise once SIGSEGV is received the bgworker will quit and we can't backtrace.
handle SIGSEGV stop nopass
'';
script = ''
${gdb}/bin/gdb -x ${file} "$@"
'';
in
writeShellScriptBin "with-gdb" script
2 changes: 1 addition & 1 deletion nix/pgScript.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

let
LOGMIN = builtins.getEnv "LOGMIN";
logMin = if builtins.stringLength LOGMIN == 0 then "WARNING" else LOGMIN; # warning is the default in pg
logMin = if builtins.stringLength LOGMIN == 0 then "INFO" else LOGMIN;
ver = builtins.head (builtins.splitVersion postgresql.version);
script = ''
set -euo pipefail
Expand Down
3 changes: 3 additions & 0 deletions nix/pg_net.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ stdenv.mkDerivation {

src = ../.;

# this is enough for enabling debug info
dontStrip = true;

installPhase = ''
mkdir -p $out/bin
install -D pg_net.so -t $out/lib
Expand Down
2 changes: 2 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mkShell {
extAll = map (x: callPackage ./nix/pgScript.nix { postgresql = pgWithExt { pg = x;}; }) supportedPgVersions;
nginxScript = callPackage ./nix/nginxScript.nix {};
pathodScript = callPackage ./nix/pathodScript.nix { mitmproxy = oldNixpkgs.mitmproxy; };
gdbScript = callPackage ./nix/gdbScript.nix {};
pythonDeps = with python3Packages; [
pytest
psycopg2
Expand All @@ -37,6 +38,7 @@ mkShell {
format.do format.doCheck
nginxScript
pathodScript
gdbScript
];
shellHook = ''
export HISTFILE=.history
Expand Down

0 comments on commit de214de

Please sign in to comment.