Skip to content

Commit 84088d3

Browse files
authored
[DLCov 1/5] Add CMake option for enhanced debug line coverage tracking (#107278)
This is part of a series of patches that tries to improve DILocation bug detection in Debugify. This first patch adds the necessary CMake flag to LLVM and a variable defined by that flag to LLVM's config header, allowing the next patch to track information without affecting normal builds. This series of patches adds a "DebugLoc coverage tracking" feature, that inserts conditionally-compiled tracking information into DebugLocs (and by extension, to Instructions), which is used by Debugify to provide more accurate and detailed coverage reports. When enabled, this features tracks whether and why we have intentionally dropped a DebugLoc, allowing Debugify to ignore false positives. An optional additional feature allows also storing a stack trace of the point where a DebugLoc was unintentionally dropped/not generated, which is used to make fixing detected errors significantly easier. The goal of these features is to provide useful tools for developers to fix existing DebugLoc errors and allow reliable detection of regressions by either manual inspection or an automated script.
1 parent f576c1f commit 84088d3

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

llvm/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ endif()
536536

537537
option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF)
538538

539+
set(LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING "DISABLED" CACHE STRING
540+
"Enhance Debugify's line number coverage tracking; enabling this is ABI-breaking. Can be DISABLED, or COVERAGE.")
541+
set_property(CACHE LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING PROPERTY STRINGS DISABLED COVERAGE)
542+
539543
set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)
540544
if (MINGW)
541545
# Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ else()
196196
message(FATAL_ERROR "Unknown value for LLVM_ABI_BREAKING_CHECKS: \"${LLVM_ABI_BREAKING_CHECKS}\"!")
197197
endif()
198198

199+
string(TOUPPER "${LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING}" uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING)
200+
201+
if( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING STREQUAL "COVERAGE" )
202+
set( ENABLE_DEBUGLOC_COVERAGE_TRACKING 1 )
203+
elseif( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING STREQUAL "DISABLED" OR NOT DEFINED LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING )
204+
# The DISABLED setting is default and requires no additional defines.
205+
else()
206+
message(FATAL_ERROR "Unknown value for LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING: \"${LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING}\"!")
207+
endif()
208+
199209
if( LLVM_REVERSE_ITERATION )
200210
set( LLVM_ENABLE_REVERSE_ITERATION 1 )
201211
endif()

llvm/docs/CMake.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ enabled sub-projects. Nearly all of these variable names begin with
482482
**LLVM_ENABLE_BINDINGS**:BOOL
483483
If disabled, do not try to build the OCaml bindings.
484484

485+
**LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING**:STRING
486+
Enhances Debugify's ability to detect line number errors by storing extra
487+
information inside Instructions, removing false positives from Debugify's
488+
results at the cost of performance. Allowed values are `DISABLED` (default)
489+
and `COVERAGE`. `COVERAGE` tracks whether and why a line number was
490+
intentionally dropped or not generated for an instruction, allowing Debugify
491+
to avoid reporting these as errors; this comes with a small performance cost
492+
of ~0.1%. `COVERAGE` is an ABI-breaking option.
493+
485494
**LLVM_ENABLE_DIA_SDK**:BOOL
486495
Enable building with MSVC DIA SDK for PDB debugging support. Available
487496
only with MSVC. Defaults to ON.

llvm/include/llvm/Config/config.h.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */
2020
#cmakedefine01 LLVM_ENABLE_CRASH_DUMPS
2121

22+
/* Define to 1 to enable expensive checks for debug location coverage checking,
23+
and to 0 otherwise. */
24+
#cmakedefine01 ENABLE_DEBUGLOC_COVERAGE_TRACKING
25+
2226
/* Define to 1 to prefer forward slashes on Windows, and to 0 prefer
2327
backslashes. */
2428
#cmakedefine01 LLVM_WINDOWS_PREFER_FORWARD_SLASH

0 commit comments

Comments
 (0)