Skip to content

Commit 8d1f88b

Browse files
dylanahsmithGenevieve
and
Genevieve
authored
README: Add information on flushing for printf-style debugging (rogchap#198)
* Git ignore v8go.test Since `go test -c` is recommended as a way of running tests with a debugger. * README: Add information on flushing for printf-style debugging * Update README.md Co-authored-by: Genevieve <[email protected]>
1 parent 19ec71c commit 8d1f88b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
deps/darwin-x86_64/libv8_debug.a
99

1010
c.out
11+
12+
/v8go.test

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@ and select your pushed branch eg. `v8_7_upgrade`.
190190
1) Once built, this should open 3 PRs against your branch to add the `libv8.a` for Linux, macOS and Windows; merge
191191
these PRs into your branch. You are now ready to raise the PR against `master` with the latest version of V8.
192192

193+
### Flushing after C/C++ standard library printing for debugging
194+
195+
When using the C/C++ standard library functions for printing (e.g. `printf`), then the output will be buffered by default.
196+
This can cause some confusion, especially because the test binary (created through `go test`) does not flush the buffer
197+
at exit (at the time of writing). When standard output is the terminal, then it will use line buffering and flush when
198+
a new line is printed, otherwise (e.g. if the output is redirected to a pipe or file) it will be fully buffered and not even
199+
flush at the end of a line. When the test binary is executed through `go test .` (e.g. instead of
200+
separately compiled with `go test -c` and run with `./v8go.test`) Go may redirect standard output internally, resulting in
201+
standard output being fully buffered.
202+
203+
A simple way to avoid this problem is to flush the standard output stream after printing with the `fflush(stdout);` statement.
204+
Not relying on the flushing at exit can also help ensure the output is printed before a crash.
205+
193206
### Formatting
194207

195208
Go has `go fmt`, C has `clang-format`. Any changes to the `v8go.h|cc` should be formated with `clang-format` with the

0 commit comments

Comments
 (0)