Skip to content

Commit 243467e

Browse files
committed
More debugging documentation
There are a few things I think people should know, post-Meson.
1 parent cba27ba commit 243467e

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

doc/manual/source/development/building.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,18 @@ It is useful to perform multiple cross and native builds on the same source tree
167167
for example to ensure that better support for one platform doesn't break the build for another.
168168
Meson thankfully makes this very easy by confining all build products to the build directory --- one simple shares the source directory between multiple build directories, each of which contains the build for Nix to a different platform.
169169

170-
Nixpkgs's `configurePhase` always chooses `build` in the current directory as the name and location of the build.
171-
This makes having multiple build directories slightly more inconvenient.
172-
The good news is that Meson/Ninja seem to cope well with relocating the build directory after it is created.
170+
Here's how to do that:
173171

174-
Here's how to do that
175-
176-
1. Configure as usual
172+
1. Instruct Nixpkgs's infra where we want Meson to put its build directory
177173

178174
```bash
179-
configurePhase
175+
mesonBuildDir=build-my-variant-name
180176
```
181177

182-
2. Rename the build directory
178+
1. Configure as usual
183179

184180
```bash
185-
cd .. # since `configurePhase` cd'd inside
186-
mv build build-linux # or whatever name we want
187-
cd build-linux
181+
configurePhase
188182
```
189183

190184
3. Build as usual
@@ -193,10 +187,6 @@ Here's how to do that
193187
buildPhase
194188
```
195189

196-
> **N.B.**
197-
> [`nixpkgs#335818`](https://github.com/NixOS/nixpkgs/issues/335818) tracks giving `mesonConfigurePhase` proper support for custom build directories.
198-
> When it is fixed, we can simplify these instructions and then remove this notice.
199-
200190
## System type
201191

202192
Nix uses a string with the following format to identify the *system type* or *platform* it runs on:

doc/manual/source/development/debugging.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This section shows how to build and debug Nix with debug symbols enabled.
44

5+
Additionally, see [Testing Nix](./testing.md) for further instructions on how to debug Nix in the context of a unit test or functional test.
6+
57
## Building Nix with Debug Symbols
68

79
In the development shell, set the `mesonBuildType` environment variable to `debug` before configuring the build:
@@ -13,6 +15,15 @@ In the development shell, set the `mesonBuildType` environment variable to `debu
1315
Then, proceed to build Nix as described in [Building Nix](./building.md).
1416
This will build Nix with debug symbols, which are essential for effective debugging.
1517

18+
It is also possible to build without debugging for faster build:
19+
20+
```console
21+
[nix-shell]$ NIX_HARDENING_ENABLE=$(printLines $NIX_HARDENING_ENABLE | grep -v fortify)
22+
[nix-shell]$ export mesonBuildType=debug
23+
```
24+
25+
(The first line is needed because `fortify` hardening requires at least some optimization.)
26+
1627
## Debugging the Nix Binary
1728

1829
Obtain your preferred debugger within the development shell:

doc/manual/source/development/testing.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,34 @@ A environment variables that Google Test accepts are also worth knowing:
8787
8888
This is used to avoid logging passing tests.
8989
90-
Putting the two together, one might run
90+
3. [`GTEST_BREAK_ON_FAILURE`](https://google.github.io/googletest/advanced.html#turning-assertion-failures-into-break-points)
91+
92+
This is used to create a debugger breakpoint when an assertion failure occurs.
93+
94+
Putting the first two together, one might run
9195
9296
```bash
9397
GTEST_BRIEF=1 GTEST_FILTER='ErrorTraceTest.*' meson test nix-expr-tests -v
9498
```
9599
96100
for short but comprensive output.
97101

102+
### Debugging tests
103+
104+
For debugging, it is useful to combine the third option above with Meson's [`--gdb`](https://mesonbuild.com/Unit-tests.html#other-test-options) flag:
105+
106+
```bash
107+
GTEST_BRIEF=1 GTEST_FILTER='Group.my-failing-test' meson test nix-expr-tests --gdb
108+
```
109+
110+
This will:
111+
112+
1. Run the unit test with GDB
113+
114+
2. Run just `Group.my-failing-test`
115+
116+
3. Stop the program when the test fails, allowing the user to then issue arbitrary commands to GDB.
117+
98118
### Characterisation testing { #characaterisation-testing-unit }
99119

100120
See [functional characterisation testing](#characterisation-testing-functional) for a broader discussion of characterisation testing.
@@ -213,10 +233,10 @@ edit it like so:
213233
bar
214234
```
215235

216-
Then, running the test with `./mk/debug-test.sh` will drop you into GDB once the script reaches that point:
236+
Then, running the test with [`--interactive`](https://mesonbuild.com/Unit-tests.html#other-test-options) will prevent Meson from hijacking the terminal so you can drop you into GDB once the script reaches that point:
217237

218238
```shell-session
219-
$ ./mk/debug-test.sh tests/functional/${testName}.sh
239+
$ meson test ${testName} --interactive
220240
...
221241
+ gdb blash blub
222242
GNU gdb (GDB) 12.1

0 commit comments

Comments
 (0)