Skip to content

Conversation

@kolkov
Copy link
Owner

@kolkov kolkov commented Dec 18, 2025

Summary

Hotfix release addressing bugs reported by @glycerine.

Fixes

Issue #15: Test command flags

  • Add -c flag support (compile only, don't run)
  • Add -o flag support (output file path)
  • Version injection via GoReleaser ldflags (was hardcoded v0.4.10)

Issue #16: CGO file handling

  • Detect CGO files by checking for import "C" statement
  • Copy CGO files unchanged (skip instrumentation)
  • Prevents C symbol errors during build

Issue #17: Stack traces

Test plan

  • Pre-release checks passed (88.3% coverage, 0 lint issues)
  • racedetector test -c -o works correctly
  • CGO projects build without errors
  • Stack traces show user code location

Related

Replace hardcoded Version constant with dynamic injection:
- Change const to var with 'dev' default for local development
- Add GetVersion() with fallback to runtime/debug.ReadBuildInfo()
- Update .goreleaser.yml to inject version into runtime package
- Add -trimpath and mod_timestamp for reproducible builds

This fixes issue #15 (missing go.sum) and #17 (wrong version in stack traces)
where v0.4.10 was hardcoded instead of current release version.

Version priority:
1. ldflags (GoReleaser builds)
2. Build info (go install @Version)
3. 'dev' fallback (local development)

Fixes: #15, #17
Add CGO detection and handling:
- Add isCGOFile() to detect 'import "C"' in AST
- Add CGOSkipped flag to InstrumentStats
- Copy CGO files unchanged instead of instrumenting
- Print 'Skipped (CGO): filename' for visibility

CGO files cannot be processed by go/parser for C symbols.
This fixes compilation errors like:
  could not determine what C.xxx refers to

Fixes: #16
- Use stored PC directly instead of capturing current stack
- Remove misleading 'future enhancement' message
- Clarify that PC points to OnWrite/OnRead (internal frame)

Note: Full stack traces for previous access require storing
multiple PCs in VarState, planned for v0.8.0.

Partial fix for: #17
Test command fixes (Issue #15):
- Add -c flag support (compile only, don't run)
- Add -o flag support (output file path)
- Copy compiled binary to specified output path
- Add copyFile() helper for cross-platform support

Stack trace improvements (Issue #17):
- captureCallerPC() now captures user-code PC correctly (skip=2)
- formatStackTrace() filters internal frames (OnWrite, OnRead, runtime.*)
- Fallback shows internal frame if it's all we have (better than nothing)
- Extract isInternalStackFrame() and writeFrameToBuffer() helpers
- Reduce cyclomatic complexity from 17 to acceptable levels

Performance note:
- PC capture ~145ns (runtime.Callers baseline on Windows Go 1.25.3)
- Within <20x overhead target, optimization tracked in Issue #18

Fixes: #15, #17
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 50.98039% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.68%. Comparing base (b0307ec) to head (3c1430e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/racedetector/test.go 23.91% 34 Missing and 1 partial ⚠️
cmd/racedetector/build.go 10.00% 8 Missing and 1 partial ⚠️
cmd/racedetector/runtime/link.go 37.50% 3 Missing and 2 partials ⚠️
internal/race/detector/report.go 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #19      +/-   ##
==========================================
- Coverage   73.55%   72.68%   -0.88%     
==========================================
  Files          26       26              
  Lines        2583     2658      +75     
==========================================
+ Hits         1900     1932      +32     
- Misses        579      619      +40     
- Partials      104      107       +3     
Flag Coverage Δ
unittests 72.68% <50.98%> (-0.88%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/racedetector/instrument/instrument.go 81.39% <100.00%> (+5.63%) ⬆️
cmd/racedetector/instrument/visitor.go 74.65% <ø> (ø)
internal/race/detector/detector.go 72.72% <100.00%> (ø)
internal/race/detector/report.go 90.90% <96.29%> (+0.90%) ⬆️
cmd/racedetector/runtime/link.go 59.12% <37.50%> (-0.88%) ⬇️
cmd/racedetector/build.go 55.43% <10.00%> (-1.87%) ⬇️
cmd/racedetector/test.go 37.22% <23.91%> (-3.10%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b0307ec...3c1430e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@kolkov kolkov merged commit 9a29001 into main Dec 18, 2025
26 checks passed
@kolkov kolkov deleted the hotfix/version-injection branch December 18, 2025 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants