DAOS-18797 build: disable Go compiler optimizations in debug builds#18185
DAOS-18797 build: disable Go compiler optimizations in debug builds#18185
Conversation
|
Ticket title is 'Go binaries not debuggable with dlv due to compiler optimizations' |
When building DAOS in debug mode, the Go binaries were compiled with optimizations enabled, making it effectively impossible to use Go debuggers effectively: - Debuggers warn about optimized functions - Source lines are not correctly mapped to the execution pointer - Variables may be inlined or eliminated, making inspection unreliable Add '-gcflags "all=-N -l"' to the non-release build flags to disable compiler optimizations (-N) and inlining (-l), as recommended by the Go debugger documentation. This change only affects debug builds; release builds are unaffected. The resulting binaries will be larger and slower, which is expected and acceptable in a debug context.
…ebugging Add --dlv and --run flags to src/control/run_go_tests.sh to allow launching an interactive Delve (dlv) debug session directly from the test runner script without any additional environment setup. src/control/run_go_tests.sh --dlv --run <TestName> <package> The script already handles CGo environment setup (CGO_CFLAGS, CGO_LDFLAGS, LD_LIBRARY_PATH) via .build_vars.sh, so no manual configuration is needed. The same build tags used for the full test suite (firmware, fault_injection, test_stubs, spdk) are applied to the dlv build as well. A --help / -h flag is also added documenting all supported options.
d563ec0 to
9d2ee28
Compare
|
Test stage NLT completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos/job/PR-18185/2/display/redirect |
|
Test stage Unit Test completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos/job/PR-18185/2/display/redirect |
|
Test stage Unit Test bdev with memcheck completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos/job/PR-18185/2/display/redirect |
|
Test stage Unit Test with memcheck completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos/job/PR-18185/2/display/redirect |
|
Test stage Unit Test bdev completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos/job/PR-18185/2/display/redirect |
a301ef9 to
014d90b
Compare
kjacque
left a comment
There was a problem hiding this comment.
LGTM. Nice improvement, thanks!
Description
When building DAOS in debug mode, the Go binaries produced by the build system
are compiled with optimizations enabled. This makes it effectively impossible to
use Go debuggers (e.g.
dlv,gdbwith Go support) because:This PR fixes this by adding
-gcflags "all=-N -l"to the non-release buildflags in
src/control/SConscript. These flags instruct the Go compiler todisable optimizations (
-N) and inlining (-l), which are the standard flagsrecommended by the Go debugger documentation. The fix also applies to sanitizer
builds (
-asan), which were previously also missing the debugger-friendly flags.This change only affects debug builds; release builds are completely unaffected.
The resulting binaries will be larger and slower, which is expected and
acceptable in a debug context.
src/control/run_go_tests.shis also extended with--dlvand--runflagsto launch an interactive
dlvsession directly from the test runner, with theCGo environment already set up — no manual configuration needed.
Reviewer Validation —
dlvExamplesThe following examples demonstrate the impact of this PR and can be reproduced
by any reviewer to validate it. All examples assume a debug DAOS build is
available and
dlvis installed.Example 1 — Observe the difference: before vs after
This is the most direct validation. With the old build, setting a breakpoint in
dmgtriggers the optimization warning; with this PR it does not.Before this PR, dlv outputs:
Source lines jump erratically and local variables are often shown as
optimized away.After this PR, no warning is shown, breakpoints map correctly to source
lines, and all local variables are inspectable.
Example 2 — Inspect variables in
dmg pool listExpected after this PR:
req,ctx, andrpcClientare all fullyinspectable with their concrete values.
Example 3 — Attach to a running
daos_serverand trace pool creationStart
daos_servernormally, then in another terminal:Before this PR: the breakpoint may be hit but
stepjumps to unrelatedlines and
localsshowsoptimized away.Example 4 — Debug
daos_agentstartupAfter this PR: the
cmdstruct prints with all populated fields, making iteasy to verify that configuration was loaded correctly.
Example 5 — Use
run_go_tests.sh --dlvto debug a unit testsrc/control/run_go_tests.shnow supports a--dlvflag that sets up the fullCGo environment and launches an interactive
dlvsession for any package:# From the repo root src/control/run_go_tests.sh --dlv \ --run TestFaultComparison \ github.com/daos-stack/daos/src/control/faultThis requires no additional setup — the script sources
.build_vars.shautomatically. For packages with CGo dependencies (e.g.
server), it alsoexports the correct
CGO_CFLAGS/CGO_LDFLAGS/LD_LIBRARY_PATH.Steps for the author:
After all prior steps are complete: