Skip to content

Commit cb4c8e4

Browse files
authored
Add additional debugging instructions (#12)
1 parent ae9528b commit cb4c8e4

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Remove all query parameters by passing in an empty string.
5050
```
5151
import querymodifier;
5252
set req.url = querymodifier.modifyparams(url=req.url, params="", exclude_params=true);
53-
# Or use the conveniecen function, `excludeallparams`.
53+
# Or use the convenience function, `excludeallparams`.
5454
# set req.url = querymodifier.excludeallparams(url=req.url);
5555
5656
# Original URL: example.com/?search=name&ts=123456789&v=123456789&id=987654321
@@ -80,6 +80,8 @@ I'm happy to review any PRs. Any bug reports are also welcome.
8080

8181
### Debugging
8282

83+
#### ASan
84+
8385
The module can also be built with [`AddressSanitizer`](https://github.com/google/sanitizers/wiki/AddressSanitizer) support.
8486

8587
It is recommended that when developing on the module, you build with `AddressSanitizer` support enabled in order to help identify any memory issues with the VMOD.
@@ -94,9 +96,47 @@ There are also some scripts in the `debug` directory to assist. Navigate to the
9496

9597
_Note_: Do not use the module built with ASan support in production. This is meant for development purposes only.
9698

99+
#### gdb
100+
101+
`gdb` is also included in the debug Dockerfile for your convenience.
102+
103+
- After you've brought up Docker Compose, exec into the Varnish container.
104+
105+
```bash
106+
docker compose exec varnish
107+
```
108+
109+
- Attach `gdb` to the Varnish child process. You can either get the PID with `ps` or Varnish will print the child PID to the console like `varnish-1 | Debug: Child (31) Started`.
110+
111+
```bash
112+
(gdb) attach 31
113+
```
114+
115+
- Set a breakpoint, for example on the `vmod_modifyparams` function. A `.gdbinit` file is included in the Docker container to instruct `gdb` where to find the VMOD shared libraries.
116+
117+
```bash
118+
(gdb) b vmod_modifyparams
119+
Breakpoint 1 at 0xffff7e0b14cc: file vmod_querymodifier.c, line 219.
120+
```
121+
122+
- Send a request to `http://localhost:8080` that exercises the VMOD.
123+
124+
- Continue the debugger and then use `gdb` as you normally would.
125+
126+
```bash
127+
(gdb) c
128+
Continuing.
129+
[Switching to Thread 0xffff855cf140 (LWP 372)]
130+
131+
Thread 101 "cache-worker" hit Breakpoint 1, vmod_modifyparams (ctx=0xffff855cd9b8, uri=0xffff79a3d8ac "/?blah=1&ts=1", params_in=0xffff7e0e7610 "ts,v,cacheFix,date",
132+
exclude_params=1) at vmod_querymodifier.c:219
133+
219 CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
134+
```
135+
97136
## Acknowledgements
98137

99138
- The NY Times [`libvmod-queryfilter` VMOD](https://github.com/nytimes/libvmod-queryfilter/) for insipiration.
139+
- dridi [`vmod-querystring` VMOD](https://git.sr.ht/~dridi/vmod-querystring) for insipiration.
100140
- [`vcdk`](https://github.com/nigoroll/vcdk/) for the project structure.
101141
- Guillaume Quintard for the [VMOD tutorial](https://info.varnish-software.com/blog/creating-a-vmod-vmod-str).
102142

debug/.gdbinit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set solib-search-path /var/lib/varnish/varnishd/vmod_cache

debug/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ RUN apt-get update && \
99
automake \
1010
python3-docutils \
1111
autoconf-archive \
12-
libasan8
12+
libasan8 \
13+
gdb \
14+
procps
1315

1416
WORKDIR /
1517

1618
COPY . /libvmod-querymodifier
1719
RUN cd /libvmod-querymodifier \
18-
&& ./bootstrap --enable-asan \
20+
&& ./bootstrap --enable-asan CFLAGS="-g -O0" \
1921
&& make \
2022
&& make install

debug/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ services:
1111
volumes:
1212
- ./default.vcl:/etc/varnish/default.vcl
1313
- ./entrypoint.sh:/entrypoint.sh
14+
- ./.gdbinit:/root/.gdbinit
15+
cap_add:
16+
- SYS_PTRACE
17+
security_opt:
18+
- seccomp=unconfined
1419
nginx:
1520
image: nginx:1.27-alpine
1621
ports:

0 commit comments

Comments
 (0)