[llvm] [llvm-dwarfdump][LineCov 1/3] Add variable coverage metrics (PR #169646)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 10 05:50:30 PST 2025


================
@@ -0,0 +1,257 @@
+//===-- Coverage.cpp - Debug info coverage metrics ------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm-dwarfdump.h"
+#include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/DebugInfo/DIContext.h"
+#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
+#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/IR/CFG.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/DebugProgramInstruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IRReader/IRReader.h"
+#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SourceMgr.h"
+#include <set>
+
+using namespace llvm;
+using namespace llvm::dwarf;
+using namespace llvm::object;
+
+typedef std::pair<std::string, std::string> StringPair;
+/// Pair of file index and line number representing a source location.
+typedef std::pair<uint16_t, std::size_t> SourceLocation;
+
+/// Returns the set of source lines covered by a variable's debug information.
----------------
SLTozer wrote:

Suggest expanding this to give a bit more detail about what the function does, and what the return values may mean. I'd suggest adding a description of the possible return values similar to the comment inside the function, ("Returns an empty set if the the variable has location ranges that don't cover any source lines, and returns an empty optional (std::nullopt) if the variable has no location ranges."); may also be worth mentioning that the ranges will be limited to the containing function's address ranges or will directly use that function's address ranges if the variable has no DW_AT_location, to minimize future surprise.

https://github.com/llvm/llvm-project/pull/169646


More information about the llvm-commits mailing list