Skip to content

Commit de214de

Browse files
authored
chore: better debugging with gdb (#145)
* Add nix wrapper for GDB. This is added to docs. * Use `log_min_messages=INFO` by default for better debugging. * Add tags to gitignore.
1 parent fb98045 commit de214de

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ nix/nginx/logs/nginx.pid
1313
*.control
1414
*.so
1515
nginx.pid
16+
tags

docs/contributing.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ select net.http_get('http://localhost:3000/projects');
5656
-- * Connection #0 to host localhost left intact
5757
```
5858

59+
### GDB
60+
61+
To debug the background worker, grab its PID from the logs:
62+
63+
```
64+
$ nix-shell
65+
$ net-with-pg-16 psql
66+
67+
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
68+
```
69+
70+
And use it like:
71+
72+
```
73+
$ nix-shell
74+
$ sudo with-gdb -p 1145879
75+
```
76+
5977
## Documentation
6078

6179
All public API must be documented. Building documentation requires python 3.6+

nix/gdbScript.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ gdb, writeText, writeShellScriptBin } :
2+
3+
let
4+
file = writeText "gdbconf" ''
5+
# 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.
6+
handle SIGSEGV stop nopass
7+
'';
8+
script = ''
9+
${gdb}/bin/gdb -x ${file} "$@"
10+
'';
11+
in
12+
writeShellScriptBin "with-gdb" script

nix/pgScript.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
let
44
LOGMIN = builtins.getEnv "LOGMIN";
5-
logMin = if builtins.stringLength LOGMIN == 0 then "WARNING" else LOGMIN; # warning is the default in pg
5+
logMin = if builtins.stringLength LOGMIN == 0 then "INFO" else LOGMIN;
66
ver = builtins.head (builtins.splitVersion postgresql.version);
77
script = ''
88
set -euo pipefail

nix/pg_net.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ stdenv.mkDerivation {
77

88
src = ../.;
99

10+
# this is enough for enabling debug info
11+
dontStrip = true;
12+
1013
installPhase = ''
1114
mkdir -p $out/bin
1215
install -D pg_net.so -t $out/lib

shell.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mkShell {
2424
extAll = map (x: callPackage ./nix/pgScript.nix { postgresql = pgWithExt { pg = x;}; }) supportedPgVersions;
2525
nginxScript = callPackage ./nix/nginxScript.nix {};
2626
pathodScript = callPackage ./nix/pathodScript.nix { mitmproxy = oldNixpkgs.mitmproxy; };
27+
gdbScript = callPackage ./nix/gdbScript.nix {};
2728
pythonDeps = with python3Packages; [
2829
pytest
2930
psycopg2
@@ -37,6 +38,7 @@ mkShell {
3738
format.do format.doCheck
3839
nginxScript
3940
pathodScript
41+
gdbScript
4042
];
4143
shellHook = ''
4244
export HISTFILE=.history

0 commit comments

Comments
 (0)