2020-02-07 18:15:04 +01:00
|
|
|
//===-- Statistics.cpp - Debug Info quality metrics -----------------------===//
|
2020-02-07 12:37:29 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-04-10 03:23:39 +02:00
|
|
|
#include "llvm-dwarfdump.h"
|
2017-10-06 22:24:34 +02:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2018-09-21 23:59:34 +02:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2017-10-06 22:24:34 +02:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
|
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2019-09-20 11:25:11 +02:00
|
|
|
#include "llvm/Support/JSON.h"
|
2017-10-06 22:24:34 +02:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "dwarfdump"
|
|
|
|
using namespace llvm;
|
2020-04-10 03:23:39 +02:00
|
|
|
using namespace llvm::dwarfdump;
|
|
|
|
using namespace llvm::object;
|
2017-10-06 22:24:34 +02:00
|
|
|
|
2021-02-08 09:21:39 +01:00
|
|
|
namespace {
|
2019-09-10 12:37:28 +02:00
|
|
|
/// This represents the number of categories of debug location coverage being
|
|
|
|
/// calculated. The first category is the number of variables with 0% location
|
|
|
|
/// coverage, but the last category is the number of variables with 100%
|
|
|
|
/// location coverage.
|
|
|
|
constexpr int NumOfCoverageCategories = 12;
|
|
|
|
|
2021-02-08 09:21:39 +01:00
|
|
|
/// This is used for zero location coverage bucket.
|
|
|
|
constexpr unsigned ZeroCoverageBucket = 0;
|
|
|
|
|
|
|
|
/// This represents variables DIE offsets.
|
2021-05-10 14:08:33 +02:00
|
|
|
using AbstractOriginVarsTy = llvm::SmallVector<uint64_t>;
|
2021-02-08 09:21:39 +01:00
|
|
|
/// This maps function DIE offset to its variables.
|
2021-05-10 14:08:33 +02:00
|
|
|
using AbstractOriginVarsTyMap = llvm::DenseMap<uint64_t, AbstractOriginVarsTy>;
|
|
|
|
/// This represents function DIE offsets containing an abstract_origin.
|
|
|
|
using FunctionsWithAbstractOriginTy = llvm::SmallVector<uint64_t>;
|
2021-02-08 09:21:39 +01:00
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
/// Holds statistics for one function (or other entity that has a PC range and
|
|
|
|
/// contains variables, such as a compile unit).
|
|
|
|
struct PerFunctionStats {
|
|
|
|
/// Number of inlined instances of this function.
|
|
|
|
unsigned NumFnInlined = 0;
|
2020-01-08 16:33:51 +01:00
|
|
|
/// Number of out-of-line instances of this function.
|
|
|
|
unsigned NumFnOutOfLine = 0;
|
2019-03-02 00:51:54 +01:00
|
|
|
/// Number of inlined instances that have abstract origins.
|
|
|
|
unsigned NumAbstractOrigins = 0;
|
|
|
|
/// Number of variables and parameters with location across all inlined
|
|
|
|
/// instances.
|
2017-10-06 22:24:34 +02:00
|
|
|
unsigned TotalVarWithLoc = 0;
|
|
|
|
/// Number of constants with location across all inlined instances.
|
|
|
|
unsigned ConstantMembers = 0;
|
2020-01-14 19:39:04 +01:00
|
|
|
/// Number of arificial variables, parameters or members across all instances.
|
|
|
|
unsigned NumArtificial = 0;
|
2019-03-02 00:51:54 +01:00
|
|
|
/// List of all Variables and parameters in this function.
|
2018-09-21 23:59:34 +02:00
|
|
|
StringSet<> VarsInFunction;
|
2017-10-06 22:24:34 +02:00
|
|
|
/// Compile units also cover a PC range, but have this flag set to false.
|
|
|
|
bool IsFunction = false;
|
2019-03-02 00:51:54 +01:00
|
|
|
/// Function has source location information.
|
|
|
|
bool HasSourceLocation = false;
|
|
|
|
/// Number of function parameters.
|
|
|
|
unsigned NumParams = 0;
|
|
|
|
/// Number of function parameters with source location.
|
|
|
|
unsigned NumParamSourceLocations = 0;
|
|
|
|
/// Number of function parameters with type.
|
|
|
|
unsigned NumParamTypes = 0;
|
|
|
|
/// Number of function parameters with a DW_AT_location.
|
|
|
|
unsigned NumParamLocations = 0;
|
2020-04-23 12:14:13 +02:00
|
|
|
/// Number of local variables.
|
|
|
|
unsigned NumLocalVars = 0;
|
|
|
|
/// Number of local variables with source location.
|
|
|
|
unsigned NumLocalVarSourceLocations = 0;
|
|
|
|
/// Number of local variables with type.
|
|
|
|
unsigned NumLocalVarTypes = 0;
|
|
|
|
/// Number of local variables with DW_AT_location.
|
|
|
|
unsigned NumLocalVarLocations = 0;
|
2017-10-06 22:24:34 +02:00
|
|
|
};
|
|
|
|
|
2018-11-09 19:10:02 +01:00
|
|
|
/// Holds accumulated global statistics about DIEs.
|
2017-10-06 22:24:34 +02:00
|
|
|
struct GlobalStats {
|
|
|
|
/// Total number of PC range bytes covered by DW_AT_locations.
|
2020-08-25 07:19:00 +02:00
|
|
|
unsigned TotalBytesCovered = 0;
|
|
|
|
/// Total number of parent DIE PC range bytes covered by DW_AT_Locations.
|
2017-10-06 22:24:34 +02:00
|
|
|
unsigned ScopeBytesCovered = 0;
|
2019-11-19 11:28:21 +01:00
|
|
|
/// Total number of PC range bytes in each variable's enclosing scope.
|
|
|
|
unsigned ScopeBytes = 0;
|
2019-09-10 12:37:28 +02:00
|
|
|
/// Total number of PC range bytes covered by DW_AT_locations with
|
|
|
|
/// the debug entry values (DW_OP_entry_value).
|
|
|
|
unsigned ScopeEntryValueBytesCovered = 0;
|
|
|
|
/// Total number of PC range bytes covered by DW_AT_locations of
|
|
|
|
/// formal parameters.
|
|
|
|
unsigned ParamScopeBytesCovered = 0;
|
2020-04-23 12:14:13 +02:00
|
|
|
/// Total number of PC range bytes in each parameter's enclosing scope.
|
2019-11-19 11:28:21 +01:00
|
|
|
unsigned ParamScopeBytes = 0;
|
2019-09-10 12:37:28 +02:00
|
|
|
/// Total number of PC range bytes covered by DW_AT_locations with
|
|
|
|
/// the debug entry values (DW_OP_entry_value) (only for parameters).
|
|
|
|
unsigned ParamScopeEntryValueBytesCovered = 0;
|
|
|
|
/// Total number of PC range bytes covered by DW_AT_locations (only for local
|
|
|
|
/// variables).
|
2020-04-23 12:14:13 +02:00
|
|
|
unsigned LocalVarScopeBytesCovered = 0;
|
|
|
|
/// Total number of PC range bytes in each local variable's enclosing scope.
|
|
|
|
unsigned LocalVarScopeBytes = 0;
|
2019-09-10 12:37:28 +02:00
|
|
|
/// Total number of PC range bytes covered by DW_AT_locations with
|
|
|
|
/// the debug entry values (DW_OP_entry_value) (only for local variables).
|
2020-04-23 12:14:13 +02:00
|
|
|
unsigned LocalVarScopeEntryValueBytesCovered = 0;
|
2019-07-31 18:51:28 +02:00
|
|
|
/// Total number of call site entries (DW_AT_call_file & DW_AT_call_line).
|
2018-10-05 22:37:17 +02:00
|
|
|
unsigned CallSiteEntries = 0;
|
2019-07-31 18:51:28 +02:00
|
|
|
/// Total number of call site DIEs (DW_TAG_call_site).
|
|
|
|
unsigned CallSiteDIEs = 0;
|
|
|
|
/// Total number of call site parameter DIEs (DW_TAG_call_site_parameter).
|
|
|
|
unsigned CallSiteParamDIEs = 0;
|
2018-11-09 19:10:02 +01:00
|
|
|
/// Total byte size of concrete functions. This byte size includes
|
|
|
|
/// inline functions contained in the concrete functions.
|
2019-09-20 11:25:11 +02:00
|
|
|
unsigned FunctionSize = 0;
|
2018-11-09 19:10:02 +01:00
|
|
|
/// Total byte size of inlined functions. This is the total number of bytes
|
|
|
|
/// for the top inline functions within concrete functions. This can help
|
|
|
|
/// tune the inline settings when compiling to match user expectations.
|
2019-09-20 11:25:11 +02:00
|
|
|
unsigned InlineFunctionSize = 0;
|
2017-10-06 22:24:34 +02:00
|
|
|
};
|
|
|
|
|
2019-09-10 12:37:28 +02:00
|
|
|
/// Holds accumulated debug location statistics about local variables and
|
|
|
|
/// formal parameters.
|
|
|
|
struct LocationStats {
|
|
|
|
/// Map the scope coverage decile to the number of variables in the decile.
|
|
|
|
/// The first element of the array (at the index zero) represents the number
|
|
|
|
/// of variables with the no debug location at all, but the last element
|
|
|
|
/// in the vector represents the number of fully covered variables within
|
|
|
|
/// its scope.
|
|
|
|
std::vector<unsigned> VarParamLocStats{
|
|
|
|
std::vector<unsigned>(NumOfCoverageCategories, 0)};
|
|
|
|
/// Map non debug entry values coverage.
|
|
|
|
std::vector<unsigned> VarParamNonEntryValLocStats{
|
|
|
|
std::vector<unsigned>(NumOfCoverageCategories, 0)};
|
|
|
|
/// The debug location statistics for formal parameters.
|
|
|
|
std::vector<unsigned> ParamLocStats{
|
|
|
|
std::vector<unsigned>(NumOfCoverageCategories, 0)};
|
|
|
|
/// Map non debug entry values coverage for formal parameters.
|
|
|
|
std::vector<unsigned> ParamNonEntryValLocStats{
|
|
|
|
std::vector<unsigned>(NumOfCoverageCategories, 0)};
|
|
|
|
/// The debug location statistics for local variables.
|
2020-04-23 12:14:13 +02:00
|
|
|
std::vector<unsigned> LocalVarLocStats{
|
2019-09-10 12:37:28 +02:00
|
|
|
std::vector<unsigned>(NumOfCoverageCategories, 0)};
|
|
|
|
/// Map non debug entry values coverage for local variables.
|
2020-04-23 12:14:13 +02:00
|
|
|
std::vector<unsigned> LocalVarNonEntryValLocStats{
|
2019-09-10 12:37:28 +02:00
|
|
|
std::vector<unsigned>(NumOfCoverageCategories, 0)};
|
|
|
|
/// Total number of local variables and function parameters processed.
|
|
|
|
unsigned NumVarParam = 0;
|
|
|
|
/// Total number of formal parameters processed.
|
|
|
|
unsigned NumParam = 0;
|
|
|
|
/// Total number of local variables processed.
|
|
|
|
unsigned NumVar = 0;
|
|
|
|
};
|
2020-04-10 03:23:39 +02:00
|
|
|
} // namespace
|
2019-09-10 12:37:28 +02:00
|
|
|
|
|
|
|
/// Collect debug location statistics for one DIE.
|
2020-08-25 07:19:00 +02:00
|
|
|
static void collectLocStats(uint64_t ScopeBytesCovered, uint64_t BytesInScope,
|
2019-09-10 12:37:28 +02:00
|
|
|
std::vector<unsigned> &VarParamLocStats,
|
|
|
|
std::vector<unsigned> &ParamLocStats,
|
2020-04-23 12:14:13 +02:00
|
|
|
std::vector<unsigned> &LocalVarLocStats,
|
|
|
|
bool IsParam, bool IsLocalVar) {
|
2020-08-25 07:19:00 +02:00
|
|
|
auto getCoverageBucket = [ScopeBytesCovered, BytesInScope]() -> unsigned {
|
2019-12-05 14:45:57 +01:00
|
|
|
// No debug location at all for the variable.
|
2020-08-25 07:19:00 +02:00
|
|
|
if (ScopeBytesCovered == 0)
|
2019-09-10 12:37:28 +02:00
|
|
|
return 0;
|
2019-12-05 14:45:57 +01:00
|
|
|
// Fully covered variable within its scope.
|
2020-08-25 07:19:00 +02:00
|
|
|
if (ScopeBytesCovered >= BytesInScope)
|
2019-09-10 12:37:28 +02:00
|
|
|
return NumOfCoverageCategories - 1;
|
2019-12-05 14:45:57 +01:00
|
|
|
// Get covered range (e.g. 20%-29%).
|
2020-08-25 07:19:00 +02:00
|
|
|
unsigned LocBucket = 100 * (double)ScopeBytesCovered / BytesInScope;
|
2019-12-05 14:45:57 +01:00
|
|
|
LocBucket /= 10;
|
|
|
|
return LocBucket + 1;
|
2019-09-10 12:37:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
unsigned CoverageBucket = getCoverageBucket();
|
2021-02-08 09:21:39 +01:00
|
|
|
|
2019-09-10 12:37:28 +02:00
|
|
|
VarParamLocStats[CoverageBucket]++;
|
|
|
|
if (IsParam)
|
|
|
|
ParamLocStats[CoverageBucket]++;
|
|
|
|
else if (IsLocalVar)
|
2020-04-23 12:14:13 +02:00
|
|
|
LocalVarLocStats[CoverageBucket]++;
|
2019-09-10 12:37:28 +02:00
|
|
|
}
|
2021-02-08 09:21:39 +01:00
|
|
|
|
2020-01-14 19:36:30 +01:00
|
|
|
/// Construct an identifier for a given DIE from its Prefix, Name, DeclFileName
|
|
|
|
/// and DeclLine. The identifier aims to be unique for any unique entities,
|
|
|
|
/// but keeping the same among different instances of the same entity.
|
|
|
|
static std::string constructDieID(DWARFDie Die,
|
|
|
|
StringRef Prefix = StringRef()) {
|
|
|
|
std::string IDStr;
|
|
|
|
llvm::raw_string_ostream ID(IDStr);
|
|
|
|
ID << Prefix
|
|
|
|
<< Die.getName(DINameKind::LinkageName);
|
|
|
|
|
|
|
|
// Prefix + Name is enough for local variables and parameters.
|
|
|
|
if (!Prefix.empty() && !Prefix.equals("g"))
|
|
|
|
return ID.str();
|
|
|
|
|
|
|
|
auto DeclFile = Die.findRecursively(dwarf::DW_AT_decl_file);
|
|
|
|
std::string File;
|
|
|
|
if (DeclFile) {
|
|
|
|
DWARFUnit *U = Die.getDwarfUnit();
|
|
|
|
if (const auto *LT = U->getContext().getLineTableForUnit(U))
|
|
|
|
if (LT->getFileNameByIndex(
|
|
|
|
dwarf::toUnsigned(DeclFile, 0), U->getCompilationDir(),
|
|
|
|
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File))
|
2020-01-28 20:23:46 +01:00
|
|
|
File = std::string(sys::path::filename(File));
|
2020-01-14 19:36:30 +01:00
|
|
|
}
|
|
|
|
ID << ":" << (File.empty() ? "/" : File);
|
|
|
|
ID << ":"
|
|
|
|
<< dwarf::toUnsigned(Die.findRecursively(dwarf::DW_AT_decl_line), 0);
|
|
|
|
return ID.str();
|
|
|
|
}
|
2019-09-10 12:37:28 +02:00
|
|
|
|
2020-08-25 07:19:00 +02:00
|
|
|
/// Return the number of bytes in the overlap of ranges A and B.
|
|
|
|
static uint64_t calculateOverlap(DWARFAddressRange A, DWARFAddressRange B) {
|
|
|
|
uint64_t Lower = std::max(A.LowPC, B.LowPC);
|
|
|
|
uint64_t Upper = std::min(A.HighPC, B.HighPC);
|
|
|
|
if (Lower >= Upper)
|
|
|
|
return 0;
|
|
|
|
return Upper - Lower;
|
|
|
|
}
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
/// Collect debug info quality metrics for one DIE.
|
dwarfdump --statistics: Use new location list api
Summary:
This patch removes manual location list handling in the statistics code
and replaces it with the new DWARFDie api, which provides access to a
"cooked" location list. This has the following effects:
- the code now properly handles split-dwarf location lists
- it will automatically support dwarf5 location lists once support for
those is added
- it properly handles location lists with base address selection entries
- it fixes a bug where the location list code was using the first
DW_AT_ranges range as a "base address" of the compile unit (it should
have used DW_AT_low_pc instead. The effect of this was that the
computation of the start address of a variable in its scope was broken
for these kinds of compile units. This only manifested itself on
linked files, since in object files the first DW_AT_ranges range
normally starts at 0.
Since pretty much every kind of location list was broken in some way,
it's hard to verify that the new implementation is correct -- the output
will be different in all non-trivial cases, and mostly with good reason.
Most of the existing statistics tests continue to pass though, and a
visual inspection of the statistics for non-trivial inputs shows that
the data is more "reasonable" now. I have updated the "dwo statistics"
test to include the new numbers, as the previous ones were completely
bogus, and I have added a targeted test for the "base address" bug.
Reviewers: dblaikie, cmtice, vsk
Subscribers: aprantl, SouraVX, JDevlieghere, djtodoro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70444
2019-11-19 15:14:59 +01:00
|
|
|
static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
|
2019-11-19 11:28:21 +01:00
|
|
|
std::string VarPrefix, uint64_t BytesInScope,
|
|
|
|
uint32_t InlineDepth,
|
2017-10-06 22:24:34 +02:00
|
|
|
StringMap<PerFunctionStats> &FnStatMap,
|
2019-09-10 12:37:28 +02:00
|
|
|
GlobalStats &GlobalStats,
|
2021-02-08 09:21:39 +01:00
|
|
|
LocationStats &LocStats,
|
2021-05-10 14:08:33 +02:00
|
|
|
AbstractOriginVarsTy *AbstractOriginVariables) {
|
2021-02-22 08:20:37 +01:00
|
|
|
const dwarf::Tag Tag = Die.getTag();
|
|
|
|
// Skip CU node.
|
|
|
|
if (Tag == dwarf::DW_TAG_compile_unit)
|
|
|
|
return;
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
bool HasLoc = false;
|
2019-03-02 00:51:54 +01:00
|
|
|
bool HasSrcLoc = false;
|
|
|
|
bool HasType = false;
|
2020-08-25 07:19:00 +02:00
|
|
|
uint64_t TotalBytesCovered = 0;
|
|
|
|
uint64_t ScopeBytesCovered = 0;
|
2019-09-10 12:37:28 +02:00
|
|
|
uint64_t BytesEntryValuesCovered = 0;
|
|
|
|
auto &FnStats = FnStatMap[FnPrefix];
|
2021-02-22 08:20:37 +01:00
|
|
|
bool IsParam = Tag == dwarf::DW_TAG_formal_parameter;
|
|
|
|
bool IsLocalVar = Tag == dwarf::DW_TAG_variable;
|
|
|
|
bool IsConstantMember = Tag == dwarf::DW_TAG_member &&
|
2020-01-14 19:39:04 +01:00
|
|
|
Die.find(dwarf::DW_AT_const_value);
|
2018-09-21 23:59:34 +02:00
|
|
|
|
2021-02-08 09:21:39 +01:00
|
|
|
// For zero covered inlined variables the locstats will be
|
|
|
|
// calculated later.
|
|
|
|
bool DeferLocStats = false;
|
|
|
|
|
2021-02-22 08:20:37 +01:00
|
|
|
if (Tag == dwarf::DW_TAG_call_site || Tag == dwarf::DW_TAG_GNU_call_site) {
|
2019-07-31 18:51:28 +02:00
|
|
|
GlobalStats.CallSiteDIEs++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-22 08:20:37 +01:00
|
|
|
if (Tag == dwarf::DW_TAG_call_site_parameter ||
|
|
|
|
Tag == dwarf::DW_TAG_GNU_call_site_parameter) {
|
2019-07-31 18:51:28 +02:00
|
|
|
GlobalStats.CallSiteParamDIEs++;
|
2018-10-05 22:37:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-23 12:14:13 +02:00
|
|
|
if (!IsParam && !IsLocalVar && !IsConstantMember) {
|
2018-09-21 23:59:34 +02:00
|
|
|
// Not a variable or constant member.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-19 15:28:35 +01:00
|
|
|
// Ignore declarations of global variables.
|
2020-04-23 12:14:13 +02:00
|
|
|
if (IsLocalVar && Die.find(dwarf::DW_AT_declaration))
|
2020-01-19 15:28:35 +01:00
|
|
|
return;
|
|
|
|
|
2019-03-02 00:51:54 +01:00
|
|
|
if (Die.findRecursively(dwarf::DW_AT_decl_file) &&
|
|
|
|
Die.findRecursively(dwarf::DW_AT_decl_line))
|
|
|
|
HasSrcLoc = true;
|
|
|
|
|
|
|
|
if (Die.findRecursively(dwarf::DW_AT_type))
|
|
|
|
HasType = true;
|
|
|
|
|
2021-02-08 09:21:39 +01:00
|
|
|
if (Die.find(dwarf::DW_AT_abstract_origin)) {
|
2021-05-10 14:08:33 +02:00
|
|
|
if (Die.find(dwarf::DW_AT_location) || Die.find(dwarf::DW_AT_const_value)) {
|
|
|
|
if (AbstractOriginVariables) {
|
|
|
|
auto Offset = Die.find(dwarf::DW_AT_abstract_origin);
|
|
|
|
// Do not track this variable any more, since it has location
|
|
|
|
// coverage.
|
|
|
|
llvm::erase_value(*AbstractOriginVariables, (*Offset).getRawUValue());
|
2021-02-08 09:21:39 +01:00
|
|
|
}
|
2021-05-10 14:08:33 +02:00
|
|
|
} else {
|
|
|
|
// The locstats will be handled at the end of
|
|
|
|
// the collectStatsRecursive().
|
|
|
|
DeferLocStats = true;
|
|
|
|
}
|
2021-02-08 09:21:39 +01:00
|
|
|
}
|
|
|
|
|
2019-09-10 12:37:28 +02:00
|
|
|
auto IsEntryValue = [&](ArrayRef<uint8_t> D) -> bool {
|
|
|
|
DWARFUnit *U = Die.getDwarfUnit();
|
|
|
|
DataExtractor Data(toStringRef(D),
|
|
|
|
Die.getDwarfUnit()->getContext().isLittleEndian(), 0);
|
2020-05-08 18:28:25 +02:00
|
|
|
DWARFExpression Expression(Data, U->getAddressByteSize(),
|
|
|
|
U->getFormParams().Format);
|
2019-09-10 12:37:28 +02:00
|
|
|
// Consider the expression containing the DW_OP_entry_value as
|
|
|
|
// an entry value.
|
|
|
|
return llvm::any_of(Expression, [](DWARFExpression::Operation &Op) {
|
|
|
|
return Op.getCode() == dwarf::DW_OP_entry_value ||
|
|
|
|
Op.getCode() == dwarf::DW_OP_GNU_entry_value;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
if (Die.find(dwarf::DW_AT_const_value)) {
|
|
|
|
// This catches constant members *and* variables.
|
|
|
|
HasLoc = true;
|
2020-08-25 07:19:00 +02:00
|
|
|
ScopeBytesCovered = BytesInScope;
|
|
|
|
TotalBytesCovered = BytesInScope;
|
2018-09-21 23:59:34 +02:00
|
|
|
} else {
|
2017-10-06 22:24:34 +02:00
|
|
|
// Handle variables and function arguments.
|
dwarfdump --statistics: Use new location list api
Summary:
This patch removes manual location list handling in the statistics code
and replaces it with the new DWARFDie api, which provides access to a
"cooked" location list. This has the following effects:
- the code now properly handles split-dwarf location lists
- it will automatically support dwarf5 location lists once support for
those is added
- it properly handles location lists with base address selection entries
- it fixes a bug where the location list code was using the first
DW_AT_ranges range as a "base address" of the compile unit (it should
have used DW_AT_low_pc instead. The effect of this was that the
computation of the start address of a variable in its scope was broken
for these kinds of compile units. This only manifested itself on
linked files, since in object files the first DW_AT_ranges range
normally starts at 0.
Since pretty much every kind of location list was broken in some way,
it's hard to verify that the new implementation is correct -- the output
will be different in all non-trivial cases, and mostly with good reason.
Most of the existing statistics tests continue to pass though, and a
visual inspection of the statistics for non-trivial inputs shows that
the data is more "reasonable" now. I have updated the "dwo statistics"
test to include the new numbers, as the previous ones were completely
bogus, and I have added a targeted test for the "base address" bug.
Reviewers: dblaikie, cmtice, vsk
Subscribers: aprantl, SouraVX, JDevlieghere, djtodoro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70444
2019-11-19 15:14:59 +01:00
|
|
|
Expected<std::vector<DWARFLocationExpression>> Loc =
|
|
|
|
Die.getLocations(dwarf::DW_AT_location);
|
|
|
|
if (!Loc) {
|
|
|
|
consumeError(Loc.takeError());
|
|
|
|
} else {
|
|
|
|
HasLoc = true;
|
2017-10-06 22:24:34 +02:00
|
|
|
// Get PC coverage.
|
dwarfdump --statistics: Use new location list api
Summary:
This patch removes manual location list handling in the statistics code
and replaces it with the new DWARFDie api, which provides access to a
"cooked" location list. This has the following effects:
- the code now properly handles split-dwarf location lists
- it will automatically support dwarf5 location lists once support for
those is added
- it properly handles location lists with base address selection entries
- it fixes a bug where the location list code was using the first
DW_AT_ranges range as a "base address" of the compile unit (it should
have used DW_AT_low_pc instead. The effect of this was that the
computation of the start address of a variable in its scope was broken
for these kinds of compile units. This only manifested itself on
linked files, since in object files the first DW_AT_ranges range
normally starts at 0.
Since pretty much every kind of location list was broken in some way,
it's hard to verify that the new implementation is correct -- the output
will be different in all non-trivial cases, and mostly with good reason.
Most of the existing statistics tests continue to pass though, and a
visual inspection of the statistics for non-trivial inputs shows that
the data is more "reasonable" now. I have updated the "dwo statistics"
test to include the new numbers, as the previous ones were completely
bogus, and I have added a targeted test for the "base address" bug.
Reviewers: dblaikie, cmtice, vsk
Subscribers: aprantl, SouraVX, JDevlieghere, djtodoro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70444
2019-11-19 15:14:59 +01:00
|
|
|
auto Default = find_if(
|
|
|
|
*Loc, [](const DWARFLocationExpression &L) { return !L.Range; });
|
|
|
|
if (Default != Loc->end()) {
|
2017-10-06 22:24:34 +02:00
|
|
|
// Assume the entire range is covered by a single location.
|
2020-08-25 07:19:00 +02:00
|
|
|
ScopeBytesCovered = BytesInScope;
|
|
|
|
TotalBytesCovered = BytesInScope;
|
dwarfdump --statistics: Use new location list api
Summary:
This patch removes manual location list handling in the statistics code
and replaces it with the new DWARFDie api, which provides access to a
"cooked" location list. This has the following effects:
- the code now properly handles split-dwarf location lists
- it will automatically support dwarf5 location lists once support for
those is added
- it properly handles location lists with base address selection entries
- it fixes a bug where the location list code was using the first
DW_AT_ranges range as a "base address" of the compile unit (it should
have used DW_AT_low_pc instead. The effect of this was that the
computation of the start address of a variable in its scope was broken
for these kinds of compile units. This only manifested itself on
linked files, since in object files the first DW_AT_ranges range
normally starts at 0.
Since pretty much every kind of location list was broken in some way,
it's hard to verify that the new implementation is correct -- the output
will be different in all non-trivial cases, and mostly with good reason.
Most of the existing statistics tests continue to pass though, and a
visual inspection of the statistics for non-trivial inputs shows that
the data is more "reasonable" now. I have updated the "dwo statistics"
test to include the new numbers, as the previous ones were completely
bogus, and I have added a targeted test for the "base address" bug.
Reviewers: dblaikie, cmtice, vsk
Subscribers: aprantl, SouraVX, JDevlieghere, djtodoro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70444
2019-11-19 15:14:59 +01:00
|
|
|
} else {
|
2020-08-25 07:19:00 +02:00
|
|
|
// Caller checks this Expected result already, it cannot fail.
|
|
|
|
auto ScopeRanges = cantFail(Die.getParent().getAddressRanges());
|
dwarfdump --statistics: Use new location list api
Summary:
This patch removes manual location list handling in the statistics code
and replaces it with the new DWARFDie api, which provides access to a
"cooked" location list. This has the following effects:
- the code now properly handles split-dwarf location lists
- it will automatically support dwarf5 location lists once support for
those is added
- it properly handles location lists with base address selection entries
- it fixes a bug where the location list code was using the first
DW_AT_ranges range as a "base address" of the compile unit (it should
have used DW_AT_low_pc instead. The effect of this was that the
computation of the start address of a variable in its scope was broken
for these kinds of compile units. This only manifested itself on
linked files, since in object files the first DW_AT_ranges range
normally starts at 0.
Since pretty much every kind of location list was broken in some way,
it's hard to verify that the new implementation is correct -- the output
will be different in all non-trivial cases, and mostly with good reason.
Most of the existing statistics tests continue to pass though, and a
visual inspection of the statistics for non-trivial inputs shows that
the data is more "reasonable" now. I have updated the "dwo statistics"
test to include the new numbers, as the previous ones were completely
bogus, and I have added a targeted test for the "base address" bug.
Reviewers: dblaikie, cmtice, vsk
Subscribers: aprantl, SouraVX, JDevlieghere, djtodoro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70444
2019-11-19 15:14:59 +01:00
|
|
|
for (auto Entry : *Loc) {
|
2020-08-25 07:19:00 +02:00
|
|
|
TotalBytesCovered += Entry.Range->HighPC - Entry.Range->LowPC;
|
|
|
|
uint64_t ScopeBytesCoveredByEntry = 0;
|
|
|
|
// Calculate how many bytes of the parent scope this entry covers.
|
|
|
|
// FIXME: In section 2.6.2 of the DWARFv5 spec it says that "The
|
|
|
|
// address ranges defined by the bounded location descriptions of a
|
|
|
|
// location list may overlap". So in theory a variable can have
|
|
|
|
// multiple simultaneous locations, which would make this calculation
|
|
|
|
// misleading because we will count the overlapped areas
|
|
|
|
// twice. However, clang does not currently emit DWARF like this.
|
|
|
|
for (DWARFAddressRange R : ScopeRanges) {
|
|
|
|
ScopeBytesCoveredByEntry += calculateOverlap(*Entry.Range, R);
|
|
|
|
}
|
|
|
|
ScopeBytesCovered += ScopeBytesCoveredByEntry;
|
dwarfdump --statistics: Use new location list api
Summary:
This patch removes manual location list handling in the statistics code
and replaces it with the new DWARFDie api, which provides access to a
"cooked" location list. This has the following effects:
- the code now properly handles split-dwarf location lists
- it will automatically support dwarf5 location lists once support for
those is added
- it properly handles location lists with base address selection entries
- it fixes a bug where the location list code was using the first
DW_AT_ranges range as a "base address" of the compile unit (it should
have used DW_AT_low_pc instead. The effect of this was that the
computation of the start address of a variable in its scope was broken
for these kinds of compile units. This only manifested itself on
linked files, since in object files the first DW_AT_ranges range
normally starts at 0.
Since pretty much every kind of location list was broken in some way,
it's hard to verify that the new implementation is correct -- the output
will be different in all non-trivial cases, and mostly with good reason.
Most of the existing statistics tests continue to pass though, and a
visual inspection of the statistics for non-trivial inputs shows that
the data is more "reasonable" now. I have updated the "dwo statistics"
test to include the new numbers, as the previous ones were completely
bogus, and I have added a targeted test for the "base address" bug.
Reviewers: dblaikie, cmtice, vsk
Subscribers: aprantl, SouraVX, JDevlieghere, djtodoro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70444
2019-11-19 15:14:59 +01:00
|
|
|
if (IsEntryValue(Entry.Expr))
|
2020-08-25 07:19:00 +02:00
|
|
|
BytesEntryValuesCovered += ScopeBytesCoveredByEntry;
|
dwarfdump --statistics: Use new location list api
Summary:
This patch removes manual location list handling in the statistics code
and replaces it with the new DWARFDie api, which provides access to a
"cooked" location list. This has the following effects:
- the code now properly handles split-dwarf location lists
- it will automatically support dwarf5 location lists once support for
those is added
- it properly handles location lists with base address selection entries
- it fixes a bug where the location list code was using the first
DW_AT_ranges range as a "base address" of the compile unit (it should
have used DW_AT_low_pc instead. The effect of this was that the
computation of the start address of a variable in its scope was broken
for these kinds of compile units. This only manifested itself on
linked files, since in object files the first DW_AT_ranges range
normally starts at 0.
Since pretty much every kind of location list was broken in some way,
it's hard to verify that the new implementation is correct -- the output
will be different in all non-trivial cases, and mostly with good reason.
Most of the existing statistics tests continue to pass though, and a
visual inspection of the statistics for non-trivial inputs shows that
the data is more "reasonable" now. I have updated the "dwo statistics"
test to include the new numbers, as the previous ones were completely
bogus, and I have added a targeted test for the "base address" bug.
Reviewers: dblaikie, cmtice, vsk
Subscribers: aprantl, SouraVX, JDevlieghere, djtodoro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70444
2019-11-19 15:14:59 +01:00
|
|
|
}
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:37:28 +02:00
|
|
|
// Calculate the debug location statistics.
|
2021-02-08 09:21:39 +01:00
|
|
|
if (BytesInScope && !DeferLocStats) {
|
2019-09-10 12:37:28 +02:00
|
|
|
LocStats.NumVarParam++;
|
|
|
|
if (IsParam)
|
|
|
|
LocStats.NumParam++;
|
2020-04-23 12:14:13 +02:00
|
|
|
else if (IsLocalVar)
|
2019-09-10 12:37:28 +02:00
|
|
|
LocStats.NumVar++;
|
|
|
|
|
2020-08-25 07:19:00 +02:00
|
|
|
collectLocStats(ScopeBytesCovered, BytesInScope, LocStats.VarParamLocStats,
|
2020-04-23 12:14:13 +02:00
|
|
|
LocStats.ParamLocStats, LocStats.LocalVarLocStats, IsParam,
|
|
|
|
IsLocalVar);
|
2019-09-10 12:37:28 +02:00
|
|
|
// Non debug entry values coverage statistics.
|
2020-08-25 07:19:00 +02:00
|
|
|
collectLocStats(ScopeBytesCovered - BytesEntryValuesCovered, BytesInScope,
|
2019-09-10 12:37:28 +02:00
|
|
|
LocStats.VarParamNonEntryValLocStats,
|
|
|
|
LocStats.ParamNonEntryValLocStats,
|
2020-04-23 12:14:13 +02:00
|
|
|
LocStats.LocalVarNonEntryValLocStats, IsParam, IsLocalVar);
|
2019-09-10 12:37:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
// Collect PC range coverage data.
|
|
|
|
if (DWARFDie D =
|
|
|
|
Die.getAttributeValueAsReferencedDie(dwarf::DW_AT_abstract_origin))
|
|
|
|
Die = D;
|
2020-01-14 19:36:30 +01:00
|
|
|
|
|
|
|
std::string VarID = constructDieID(Die, VarPrefix);
|
|
|
|
FnStats.VarsInFunction.insert(VarID);
|
|
|
|
|
2020-08-25 07:19:00 +02:00
|
|
|
GlobalStats.TotalBytesCovered += TotalBytesCovered;
|
2017-10-06 22:24:34 +02:00
|
|
|
if (BytesInScope) {
|
2020-08-25 07:19:00 +02:00
|
|
|
GlobalStats.ScopeBytesCovered += ScopeBytesCovered;
|
2019-11-19 11:28:21 +01:00
|
|
|
GlobalStats.ScopeBytes += BytesInScope;
|
2019-09-10 12:37:28 +02:00
|
|
|
GlobalStats.ScopeEntryValueBytesCovered += BytesEntryValuesCovered;
|
|
|
|
if (IsParam) {
|
2020-08-25 07:19:00 +02:00
|
|
|
GlobalStats.ParamScopeBytesCovered += ScopeBytesCovered;
|
2019-11-19 11:28:21 +01:00
|
|
|
GlobalStats.ParamScopeBytes += BytesInScope;
|
2019-09-10 12:37:28 +02:00
|
|
|
GlobalStats.ParamScopeEntryValueBytesCovered += BytesEntryValuesCovered;
|
2020-04-23 12:14:13 +02:00
|
|
|
} else if (IsLocalVar) {
|
2020-08-25 07:19:00 +02:00
|
|
|
GlobalStats.LocalVarScopeBytesCovered += ScopeBytesCovered;
|
2020-04-23 12:14:13 +02:00
|
|
|
GlobalStats.LocalVarScopeBytes += BytesInScope;
|
|
|
|
GlobalStats.LocalVarScopeEntryValueBytesCovered +=
|
|
|
|
BytesEntryValuesCovered;
|
2019-09-10 12:37:28 +02:00
|
|
|
}
|
2019-11-19 11:28:21 +01:00
|
|
|
assert(GlobalStats.ScopeBytesCovered <= GlobalStats.ScopeBytes);
|
2020-01-14 19:39:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsConstantMember) {
|
2017-10-06 22:24:34 +02:00
|
|
|
FnStats.ConstantMembers++;
|
2020-01-14 19:39:04 +01:00
|
|
|
return;
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
2020-01-14 19:39:04 +01:00
|
|
|
|
|
|
|
FnStats.TotalVarWithLoc += (unsigned)HasLoc;
|
|
|
|
|
|
|
|
if (Die.find(dwarf::DW_AT_artificial)) {
|
|
|
|
FnStats.NumArtificial++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsParam) {
|
|
|
|
FnStats.NumParams++;
|
|
|
|
if (HasType)
|
|
|
|
FnStats.NumParamTypes++;
|
|
|
|
if (HasSrcLoc)
|
|
|
|
FnStats.NumParamSourceLocations++;
|
|
|
|
if (HasLoc)
|
|
|
|
FnStats.NumParamLocations++;
|
2020-04-23 12:14:13 +02:00
|
|
|
} else if (IsLocalVar) {
|
|
|
|
FnStats.NumLocalVars++;
|
2020-01-14 19:39:04 +01:00
|
|
|
if (HasType)
|
2020-04-23 12:14:13 +02:00
|
|
|
FnStats.NumLocalVarTypes++;
|
2020-01-14 19:39:04 +01:00
|
|
|
if (HasSrcLoc)
|
2020-04-23 12:14:13 +02:00
|
|
|
FnStats.NumLocalVarSourceLocations++;
|
2020-01-14 19:39:04 +01:00
|
|
|
if (HasLoc)
|
2020-04-23 12:14:13 +02:00
|
|
|
FnStats.NumLocalVarLocations++;
|
2019-03-02 00:51:54 +01:00
|
|
|
}
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 14:08:33 +02:00
|
|
|
/// Recursively collect variables from subprogram with DW_AT_inline attribute.
|
|
|
|
static void collectAbstractOriginFnInfo(
|
|
|
|
DWARFDie Die, uint64_t SPOffset,
|
|
|
|
AbstractOriginVarsTyMap &GlobalAbstractOriginFnInfo) {
|
2021-02-08 09:21:39 +01:00
|
|
|
DWARFDie Child = Die.getFirstChild();
|
|
|
|
while (Child) {
|
|
|
|
const dwarf::Tag ChildTag = Child.getTag();
|
|
|
|
if (ChildTag == dwarf::DW_TAG_formal_parameter ||
|
|
|
|
ChildTag == dwarf::DW_TAG_variable)
|
2021-05-10 14:08:33 +02:00
|
|
|
GlobalAbstractOriginFnInfo[SPOffset].push_back(Child.getOffset());
|
2021-02-08 09:21:39 +01:00
|
|
|
else if (ChildTag == dwarf::DW_TAG_lexical_block)
|
2021-05-10 14:08:33 +02:00
|
|
|
collectAbstractOriginFnInfo(Child, SPOffset, GlobalAbstractOriginFnInfo);
|
2021-02-08 09:21:39 +01:00
|
|
|
Child = Child.getSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
/// Recursively collect debug info quality metrics.
|
2021-05-10 14:08:33 +02:00
|
|
|
static void collectStatsRecursive(
|
|
|
|
DWARFDie Die, std::string FnPrefix, std::string VarPrefix,
|
|
|
|
uint64_t BytesInScope, uint32_t InlineDepth,
|
|
|
|
StringMap<PerFunctionStats> &FnStatMap, GlobalStats &GlobalStats,
|
|
|
|
LocationStats &LocStats,
|
|
|
|
AbstractOriginVarsTyMap &GlobalAbstractOriginFnInfo,
|
|
|
|
FunctionsWithAbstractOriginTy &FnsWithAbstractOriginToBeProcessed,
|
|
|
|
AbstractOriginVarsTy *AbstractOriginVarsPtr = nullptr) {
|
2021-02-22 08:20:37 +01:00
|
|
|
// Skip NULL nodes.
|
|
|
|
if (Die.isNULL())
|
|
|
|
return;
|
|
|
|
|
2018-11-09 19:10:02 +01:00
|
|
|
const dwarf::Tag Tag = Die.getTag();
|
2020-01-09 21:21:17 +01:00
|
|
|
// Skip function types.
|
|
|
|
if (Tag == dwarf::DW_TAG_subroutine_type)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Handle any kind of lexical scope.
|
2021-05-10 15:06:58 +02:00
|
|
|
const bool HasAbstractOrigin = Die.find(dwarf::DW_AT_abstract_origin) != None;
|
2018-11-09 19:10:02 +01:00
|
|
|
const bool IsFunction = Tag == dwarf::DW_TAG_subprogram;
|
|
|
|
const bool IsBlock = Tag == dwarf::DW_TAG_lexical_block;
|
|
|
|
const bool IsInlinedFunction = Tag == dwarf::DW_TAG_inlined_subroutine;
|
2021-05-10 15:06:58 +02:00
|
|
|
// We want to know how many variables (with abstract_origin) don't have
|
|
|
|
// location info.
|
|
|
|
const bool IsCandidateForZeroLocCovTracking =
|
|
|
|
(IsInlinedFunction || (IsFunction && HasAbstractOrigin));
|
|
|
|
|
2021-05-10 14:08:33 +02:00
|
|
|
AbstractOriginVarsTy AbstractOriginVars;
|
|
|
|
|
2021-02-08 09:21:39 +01:00
|
|
|
// Get the vars of the inlined fn, so the locstats
|
|
|
|
// reports the missing vars (with coverage 0%).
|
2021-05-10 15:06:58 +02:00
|
|
|
if (IsCandidateForZeroLocCovTracking) {
|
2021-02-08 09:21:39 +01:00
|
|
|
auto OffsetFn = Die.find(dwarf::DW_AT_abstract_origin);
|
|
|
|
if (OffsetFn) {
|
|
|
|
uint64_t OffsetOfInlineFnCopy = (*OffsetFn).getRawUValue();
|
2021-05-10 14:08:33 +02:00
|
|
|
if (GlobalAbstractOriginFnInfo.count(OffsetOfInlineFnCopy)) {
|
|
|
|
AbstractOriginVars = GlobalAbstractOriginFnInfo[OffsetOfInlineFnCopy];
|
|
|
|
AbstractOriginVarsPtr = &AbstractOriginVars;
|
2021-02-08 09:21:39 +01:00
|
|
|
} else {
|
|
|
|
// This means that the DW_AT_inline fn copy is out of order,
|
2021-05-10 14:08:33 +02:00
|
|
|
// so this abstract origin instance will be processed later.
|
|
|
|
FnsWithAbstractOriginToBeProcessed.push_back(Die.getOffset());
|
|
|
|
AbstractOriginVarsPtr = nullptr;
|
2021-02-08 09:21:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-21 23:59:34 +02:00
|
|
|
|
2021-02-08 09:21:39 +01:00
|
|
|
if (IsFunction || IsInlinedFunction || IsBlock) {
|
2018-09-21 23:59:34 +02:00
|
|
|
// Reset VarPrefix when entering a new function.
|
2021-02-08 09:21:39 +01:00
|
|
|
if (IsFunction || IsInlinedFunction)
|
2018-09-21 23:59:34 +02:00
|
|
|
VarPrefix = "v";
|
2018-11-09 19:10:02 +01:00
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
// Ignore forward declarations.
|
|
|
|
if (Die.find(dwarf::DW_AT_declaration))
|
|
|
|
return;
|
|
|
|
|
2019-03-02 00:51:54 +01:00
|
|
|
// Check for call sites.
|
|
|
|
if (Die.find(dwarf::DW_AT_call_file) && Die.find(dwarf::DW_AT_call_line))
|
|
|
|
GlobalStats.CallSiteEntries++;
|
|
|
|
|
2019-02-08 01:51:33 +01:00
|
|
|
// PC Ranges.
|
|
|
|
auto RangesOrError = Die.getAddressRanges();
|
|
|
|
if (!RangesOrError) {
|
|
|
|
llvm::consumeError(RangesOrError.takeError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Ranges = RangesOrError.get();
|
|
|
|
uint64_t BytesInThisScope = 0;
|
|
|
|
for (auto Range : Ranges)
|
|
|
|
BytesInThisScope += Range.HighPC - Range.LowPC;
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
// Count the function.
|
2018-11-09 19:10:02 +01:00
|
|
|
if (!IsBlock) {
|
2021-02-08 09:21:39 +01:00
|
|
|
// Skip over abstract origins, but collect variables
|
|
|
|
// from it so it can be used for location statistics
|
|
|
|
// for inlined instancies.
|
|
|
|
if (Die.find(dwarf::DW_AT_inline)) {
|
|
|
|
uint64_t SPOffset = Die.getOffset();
|
2021-05-10 14:08:33 +02:00
|
|
|
collectAbstractOriginFnInfo(Die, SPOffset, GlobalAbstractOriginFnInfo);
|
2017-10-06 22:24:34 +02:00
|
|
|
return;
|
2021-02-08 09:21:39 +01:00
|
|
|
}
|
|
|
|
|
2020-01-14 19:36:30 +01:00
|
|
|
std::string FnID = constructDieID(Die);
|
2020-01-08 16:33:51 +01:00
|
|
|
// We've seen an instance of this function.
|
2020-01-14 19:36:30 +01:00
|
|
|
auto &FnStats = FnStatMap[FnID];
|
|
|
|
FnStats.IsFunction = true;
|
2019-03-02 00:51:54 +01:00
|
|
|
if (IsInlinedFunction) {
|
2019-02-08 01:51:33 +01:00
|
|
|
FnStats.NumFnInlined++;
|
2019-03-02 00:51:54 +01:00
|
|
|
if (Die.findRecursively(dwarf::DW_AT_abstract_origin))
|
|
|
|
FnStats.NumAbstractOrigins++;
|
2020-01-08 16:33:51 +01:00
|
|
|
} else {
|
|
|
|
FnStats.NumFnOutOfLine++;
|
2019-03-02 00:51:54 +01:00
|
|
|
}
|
|
|
|
if (Die.findRecursively(dwarf::DW_AT_decl_file) &&
|
|
|
|
Die.findRecursively(dwarf::DW_AT_decl_line))
|
|
|
|
FnStats.HasSourceLocation = true;
|
2020-01-14 19:36:30 +01:00
|
|
|
// Update function prefix.
|
|
|
|
FnPrefix = FnID;
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
|
|
|
|
2018-11-09 19:10:02 +01:00
|
|
|
if (BytesInThisScope) {
|
2017-10-06 22:24:34 +02:00
|
|
|
BytesInScope = BytesInThisScope;
|
2018-11-09 19:10:02 +01:00
|
|
|
if (IsFunction)
|
|
|
|
GlobalStats.FunctionSize += BytesInThisScope;
|
|
|
|
else if (IsInlinedFunction && InlineDepth == 0)
|
|
|
|
GlobalStats.InlineFunctionSize += BytesInThisScope;
|
|
|
|
}
|
2017-10-06 22:24:34 +02:00
|
|
|
} else {
|
|
|
|
// Not a scope, visit the Die itself. It could be a variable.
|
2019-11-19 11:28:21 +01:00
|
|
|
collectStatsForDie(Die, FnPrefix, VarPrefix, BytesInScope, InlineDepth,
|
2021-05-10 14:08:33 +02:00
|
|
|
FnStatMap, GlobalStats, LocStats, AbstractOriginVarsPtr);
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
|
|
|
|
2018-11-09 19:10:02 +01:00
|
|
|
// Set InlineDepth correctly for child recursion
|
|
|
|
if (IsFunction)
|
|
|
|
InlineDepth = 0;
|
|
|
|
else if (IsInlinedFunction)
|
|
|
|
++InlineDepth;
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
// Traverse children.
|
2018-09-21 23:59:34 +02:00
|
|
|
unsigned LexicalBlockIndex = 0;
|
2020-01-14 19:37:47 +01:00
|
|
|
unsigned FormalParameterIndex = 0;
|
2017-10-06 22:24:34 +02:00
|
|
|
DWARFDie Child = Die.getFirstChild();
|
|
|
|
while (Child) {
|
2018-09-21 23:59:34 +02:00
|
|
|
std::string ChildVarPrefix = VarPrefix;
|
|
|
|
if (Child.getTag() == dwarf::DW_TAG_lexical_block)
|
|
|
|
ChildVarPrefix += toHex(LexicalBlockIndex++) + '.';
|
2020-01-14 19:37:47 +01:00
|
|
|
if (Child.getTag() == dwarf::DW_TAG_formal_parameter)
|
|
|
|
ChildVarPrefix += 'p' + toHex(FormalParameterIndex++) + '.';
|
2018-09-21 23:59:34 +02:00
|
|
|
|
2021-05-10 14:08:33 +02:00
|
|
|
collectStatsRecursive(
|
|
|
|
Child, FnPrefix, ChildVarPrefix, BytesInScope, InlineDepth, FnStatMap,
|
|
|
|
GlobalStats, LocStats, GlobalAbstractOriginFnInfo,
|
|
|
|
FnsWithAbstractOriginToBeProcessed, AbstractOriginVarsPtr);
|
2017-10-06 22:24:34 +02:00
|
|
|
Child = Child.getSibling();
|
|
|
|
}
|
2021-02-08 09:21:39 +01:00
|
|
|
|
2021-05-10 15:06:58 +02:00
|
|
|
if (!IsCandidateForZeroLocCovTracking)
|
2021-02-08 09:21:39 +01:00
|
|
|
return;
|
|
|
|
|
2021-05-10 15:06:58 +02:00
|
|
|
// After we have processed all vars of the inlined function (or function with
|
|
|
|
// an abstract_origin), we want to know how many variables have no location.
|
2021-05-10 14:08:33 +02:00
|
|
|
for (auto Offset : AbstractOriginVars) {
|
2021-02-08 09:21:39 +01:00
|
|
|
LocStats.NumVarParam++;
|
|
|
|
LocStats.VarParamLocStats[ZeroCoverageBucket]++;
|
2021-05-10 14:08:33 +02:00
|
|
|
auto FnDie = Die.getDwarfUnit()->getDIEForOffset(Offset);
|
|
|
|
if (!FnDie)
|
2021-02-08 09:21:39 +01:00
|
|
|
continue;
|
2021-05-10 14:08:33 +02:00
|
|
|
auto Tag = FnDie.getTag();
|
2021-02-08 09:21:39 +01:00
|
|
|
if (Tag == dwarf::DW_TAG_formal_parameter) {
|
|
|
|
LocStats.NumParam++;
|
|
|
|
LocStats.ParamLocStats[ZeroCoverageBucket]++;
|
|
|
|
} else if (Tag == dwarf::DW_TAG_variable) {
|
|
|
|
LocStats.NumVar++;
|
|
|
|
LocStats.LocalVarLocStats[ZeroCoverageBucket]++;
|
|
|
|
}
|
|
|
|
}
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
|
|
|
|
2020-08-21 18:32:20 +02:00
|
|
|
/// Print human-readable output.
|
2017-10-06 22:24:34 +02:00
|
|
|
/// \{
|
2020-08-17 03:26:13 +02:00
|
|
|
static void printDatum(json::OStream &J, const char *Key, json::Value Value) {
|
|
|
|
J.attribute(Key, Value);
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(llvm::dbgs() << Key << ": " << Value << '\n');
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
2020-04-02 10:58:27 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
static void printLocationStats(json::OStream &J, const char *Key,
|
2019-09-10 12:37:28 +02:00
|
|
|
std::vector<unsigned> &LocationStats) {
|
2020-08-17 03:26:13 +02:00
|
|
|
J.attribute(
|
|
|
|
(Twine(Key) + " with 0% of parent scope covered by DW_AT_location").str(),
|
|
|
|
LocationStats[0]);
|
2020-04-23 12:14:13 +02:00
|
|
|
LLVM_DEBUG(
|
|
|
|
llvm::dbgs() << Key
|
|
|
|
<< " with 0% of parent scope covered by DW_AT_location: \\"
|
|
|
|
<< LocationStats[0] << '\n');
|
2020-08-17 03:26:13 +02:00
|
|
|
J.attribute(
|
|
|
|
(Twine(Key) + " with (0%,10%) of parent scope covered by DW_AT_location")
|
|
|
|
.str(),
|
|
|
|
LocationStats[1]);
|
2020-04-23 12:14:13 +02:00
|
|
|
LLVM_DEBUG(llvm::dbgs()
|
|
|
|
<< Key
|
|
|
|
<< " with (0%,10%) of parent scope covered by DW_AT_location: "
|
|
|
|
<< LocationStats[1] << '\n');
|
2019-09-10 12:37:28 +02:00
|
|
|
for (unsigned i = 2; i < NumOfCoverageCategories - 1; ++i) {
|
2020-08-17 03:26:13 +02:00
|
|
|
J.attribute((Twine(Key) + " with [" + Twine((i - 1) * 10) + "%," +
|
|
|
|
Twine(i * 10) + "%) of parent scope covered by DW_AT_location")
|
|
|
|
.str(),
|
|
|
|
LocationStats[i]);
|
2019-09-10 12:37:28 +02:00
|
|
|
LLVM_DEBUG(llvm::dbgs()
|
2019-12-11 18:52:49 +01:00
|
|
|
<< Key << " with [" << (i - 1) * 10 << "%," << i * 10
|
2020-04-23 12:14:13 +02:00
|
|
|
<< "%) of parent scope covered by DW_AT_location: "
|
|
|
|
<< LocationStats[i]);
|
2019-09-10 12:37:28 +02:00
|
|
|
}
|
2020-08-17 03:26:13 +02:00
|
|
|
J.attribute(
|
|
|
|
(Twine(Key) + " with 100% of parent scope covered by DW_AT_location")
|
|
|
|
.str(),
|
|
|
|
LocationStats[NumOfCoverageCategories - 1]);
|
2020-04-23 12:14:13 +02:00
|
|
|
LLVM_DEBUG(
|
|
|
|
llvm::dbgs() << Key
|
|
|
|
<< " with 100% of parent scope covered by DW_AT_location: "
|
|
|
|
<< LocationStats[NumOfCoverageCategories - 1]);
|
2019-09-10 12:37:28 +02:00
|
|
|
}
|
2020-04-02 10:58:27 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
static void printSectionSizes(json::OStream &J, const SectionSizes &Sizes) {
|
2021-02-26 05:05:05 +01:00
|
|
|
for (const auto &It : Sizes.DebugSectionSizes)
|
|
|
|
J.attribute((Twine("#bytes in ") + It.first).str(), int64_t(It.second));
|
2020-04-02 10:58:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 14:08:33 +02:00
|
|
|
/// Stop tracking variables that contain abstract_origin with a location.
|
2021-02-08 09:21:39 +01:00
|
|
|
/// This is used for out-of-order DW_AT_inline subprograms only.
|
2021-05-10 14:08:33 +02:00
|
|
|
static void updateVarsWithAbstractOriginLocCovInfo(
|
|
|
|
DWARFDie FnDieWithAbstractOrigin,
|
|
|
|
AbstractOriginVarsTy &AbstractOriginVars) {
|
|
|
|
DWARFDie Child = FnDieWithAbstractOrigin.getFirstChild();
|
2021-02-08 09:21:39 +01:00
|
|
|
while (Child) {
|
|
|
|
const dwarf::Tag ChildTag = Child.getTag();
|
|
|
|
if ((ChildTag == dwarf::DW_TAG_formal_parameter ||
|
|
|
|
ChildTag == dwarf::DW_TAG_variable) &&
|
|
|
|
(Child.find(dwarf::DW_AT_location) ||
|
|
|
|
Child.find(dwarf::DW_AT_const_value))) {
|
|
|
|
auto OffsetVar = Child.find(dwarf::DW_AT_abstract_origin);
|
|
|
|
if (OffsetVar)
|
2021-05-10 14:08:33 +02:00
|
|
|
llvm::erase_value(AbstractOriginVars, (*OffsetVar).getRawUValue());
|
2021-02-08 09:21:39 +01:00
|
|
|
} else if (ChildTag == dwarf::DW_TAG_lexical_block)
|
2021-05-10 14:08:33 +02:00
|
|
|
updateVarsWithAbstractOriginLocCovInfo(Child, AbstractOriginVars);
|
2021-02-08 09:21:39 +01:00
|
|
|
Child = Child.getSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Collect zero location coverage for inlined variables which refer to
|
|
|
|
/// a DW_AT_inline copy of subprogram that is out of order in the DWARF.
|
2021-05-10 15:06:58 +02:00
|
|
|
/// Also cover the variables of a concrete function (represented with
|
|
|
|
/// the DW_TAG_subprogram) with an abstract_origin attribute.
|
2021-05-10 14:08:33 +02:00
|
|
|
static void collectZeroLocCovForVarsWithAbstractOrigin(
|
|
|
|
DWARFUnit *DwUnit, GlobalStats &GlobalStats, LocationStats &LocStats,
|
|
|
|
AbstractOriginVarsTyMap &GlobalAbstractOriginFnInfo,
|
|
|
|
FunctionsWithAbstractOriginTy &FnsWithAbstractOriginToBeProcessed) {
|
|
|
|
for (auto FnOffset : FnsWithAbstractOriginToBeProcessed) {
|
|
|
|
DWARFDie FnDieWithAbstractOrigin = DwUnit->getDIEForOffset(FnOffset);
|
|
|
|
auto FnCopy = FnDieWithAbstractOrigin.find(dwarf::DW_AT_abstract_origin);
|
|
|
|
AbstractOriginVarsTy AbstractOriginVars;
|
|
|
|
if (!FnCopy)
|
2021-02-08 09:21:39 +01:00
|
|
|
continue;
|
|
|
|
|
2021-05-10 14:08:33 +02:00
|
|
|
AbstractOriginVars = GlobalAbstractOriginFnInfo[(*FnCopy).getRawUValue()];
|
|
|
|
updateVarsWithAbstractOriginLocCovInfo(FnDieWithAbstractOrigin,
|
|
|
|
AbstractOriginVars);
|
2021-02-08 09:21:39 +01:00
|
|
|
|
2021-05-10 14:08:33 +02:00
|
|
|
for (auto Offset : AbstractOriginVars) {
|
2021-02-08 09:21:39 +01:00
|
|
|
LocStats.NumVarParam++;
|
|
|
|
LocStats.VarParamLocStats[ZeroCoverageBucket]++;
|
|
|
|
auto Tag = DwUnit->getDIEForOffset(Offset).getTag();
|
|
|
|
if (Tag == dwarf::DW_TAG_formal_parameter) {
|
|
|
|
LocStats.NumParam++;
|
|
|
|
LocStats.ParamLocStats[ZeroCoverageBucket]++;
|
|
|
|
} else if (Tag == dwarf::DW_TAG_variable) {
|
|
|
|
LocStats.NumVar++;
|
|
|
|
LocStats.LocalVarLocStats[ZeroCoverageBucket]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
/// \}
|
|
|
|
|
|
|
|
/// Collect debug info quality metrics for an entire DIContext.
|
|
|
|
///
|
|
|
|
/// Do the impossible and reduce the quality of the debug info down to a few
|
|
|
|
/// numbers. The idea is to condense the data into numbers that can be tracked
|
|
|
|
/// over time to identify trends in newer compiler versions and gauge the effect
|
|
|
|
/// of particular optimizations. The raw numbers themselves are not particularly
|
|
|
|
/// useful, only the delta between compiling the same program with different
|
|
|
|
/// compilers is.
|
2020-04-10 03:23:39 +02:00
|
|
|
bool dwarfdump::collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
|
|
|
|
const Twine &Filename,
|
|
|
|
raw_ostream &OS) {
|
2017-10-06 22:24:34 +02:00
|
|
|
StringRef FormatName = Obj.getFileFormatName();
|
|
|
|
GlobalStats GlobalStats;
|
2019-09-10 12:37:28 +02:00
|
|
|
LocationStats LocStats;
|
2017-10-06 22:24:34 +02:00
|
|
|
StringMap<PerFunctionStats> Statistics;
|
2021-02-08 09:21:39 +01:00
|
|
|
for (const auto &CU : static_cast<DWARFContext *>(&DICtx)->compile_units()) {
|
|
|
|
if (DWARFDie CUDie = CU->getNonSkeletonUnitDIE(false)) {
|
2021-04-26 10:14:12 +02:00
|
|
|
// These variables are being reset for each CU, since there could be
|
|
|
|
// a situation where we have two subprogram DIEs with the same offsets
|
|
|
|
// in two diferent CUs, and we can end up using wrong variables info
|
2021-05-10 14:08:33 +02:00
|
|
|
// when trying to resolve abstract_origin attribute.
|
2021-04-26 10:14:12 +02:00
|
|
|
// TODO: Handle LTO cases where the abstract origin of
|
|
|
|
// the function is in a different CU than the one it's
|
|
|
|
// referenced from or inlined into.
|
2021-05-10 14:08:33 +02:00
|
|
|
AbstractOriginVarsTyMap GlobalAbstractOriginFnInfo;
|
|
|
|
FunctionsWithAbstractOriginTy FnsWithAbstractOriginToBeProcessed;
|
2021-04-26 10:14:12 +02:00
|
|
|
|
2019-11-19 11:28:21 +01:00
|
|
|
collectStatsRecursive(CUDie, "/", "g", 0, 0, Statistics, GlobalStats,
|
2021-05-10 14:08:33 +02:00
|
|
|
LocStats, GlobalAbstractOriginFnInfo,
|
|
|
|
FnsWithAbstractOriginToBeProcessed);
|
2021-02-08 09:21:39 +01:00
|
|
|
|
2021-05-10 14:08:33 +02:00
|
|
|
collectZeroLocCovForVarsWithAbstractOrigin(
|
|
|
|
CUDie.getDwarfUnit(), GlobalStats, LocStats,
|
|
|
|
GlobalAbstractOriginFnInfo, FnsWithAbstractOriginToBeProcessed);
|
2021-02-08 09:21:39 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-06 22:24:34 +02:00
|
|
|
|
2020-04-02 10:58:27 +02:00
|
|
|
/// Collect the sizes of debug sections.
|
|
|
|
SectionSizes Sizes;
|
|
|
|
calculateSectionSizes(Obj, Sizes, Filename);
|
|
|
|
|
2017-10-06 22:24:34 +02:00
|
|
|
/// The version number should be increased every time the algorithm is changed
|
|
|
|
/// (including bug fixes). New metrics may be added without increasing the
|
|
|
|
/// version.
|
2021-05-10 15:06:58 +02:00
|
|
|
unsigned Version = 8;
|
2019-03-02 00:51:54 +01:00
|
|
|
unsigned VarParamTotal = 0;
|
|
|
|
unsigned VarParamUnique = 0;
|
|
|
|
unsigned VarParamWithLoc = 0;
|
2017-10-06 22:24:34 +02:00
|
|
|
unsigned NumFunctions = 0;
|
|
|
|
unsigned NumInlinedFunctions = 0;
|
2019-03-02 00:51:54 +01:00
|
|
|
unsigned NumFuncsWithSrcLoc = 0;
|
|
|
|
unsigned NumAbstractOrigins = 0;
|
|
|
|
unsigned ParamTotal = 0;
|
|
|
|
unsigned ParamWithType = 0;
|
|
|
|
unsigned ParamWithLoc = 0;
|
|
|
|
unsigned ParamWithSrcLoc = 0;
|
2020-04-23 12:14:13 +02:00
|
|
|
unsigned LocalVarTotal = 0;
|
|
|
|
unsigned LocalVarWithType = 0;
|
|
|
|
unsigned LocalVarWithSrcLoc = 0;
|
|
|
|
unsigned LocalVarWithLoc = 0;
|
2017-10-06 22:24:34 +02:00
|
|
|
for (auto &Entry : Statistics) {
|
|
|
|
PerFunctionStats &Stats = Entry.getValue();
|
2020-01-08 16:33:51 +01:00
|
|
|
unsigned TotalVars = Stats.VarsInFunction.size() *
|
|
|
|
(Stats.NumFnInlined + Stats.NumFnOutOfLine);
|
|
|
|
// Count variables in global scope.
|
|
|
|
if (!Stats.IsFunction)
|
2020-04-23 12:14:13 +02:00
|
|
|
TotalVars =
|
|
|
|
Stats.NumLocalVars + Stats.ConstantMembers + Stats.NumArtificial;
|
2017-10-06 22:24:34 +02:00
|
|
|
unsigned Constants = Stats.ConstantMembers;
|
2019-03-02 00:51:54 +01:00
|
|
|
VarParamWithLoc += Stats.TotalVarWithLoc + Constants;
|
|
|
|
VarParamTotal += TotalVars;
|
|
|
|
VarParamUnique += Stats.VarsInFunction.size();
|
|
|
|
LLVM_DEBUG(for (auto &V
|
|
|
|
: Stats.VarsInFunction) llvm::dbgs()
|
2018-09-21 23:59:34 +02:00
|
|
|
<< Entry.getKey() << ": " << V.getKey() << "\n");
|
2017-10-06 22:24:34 +02:00
|
|
|
NumFunctions += Stats.IsFunction;
|
2019-03-02 00:51:54 +01:00
|
|
|
NumFuncsWithSrcLoc += Stats.HasSourceLocation;
|
2017-10-06 22:24:34 +02:00
|
|
|
NumInlinedFunctions += Stats.IsFunction * Stats.NumFnInlined;
|
2019-03-02 00:51:54 +01:00
|
|
|
NumAbstractOrigins += Stats.IsFunction * Stats.NumAbstractOrigins;
|
|
|
|
ParamTotal += Stats.NumParams;
|
|
|
|
ParamWithType += Stats.NumParamTypes;
|
|
|
|
ParamWithLoc += Stats.NumParamLocations;
|
|
|
|
ParamWithSrcLoc += Stats.NumParamSourceLocations;
|
2020-04-23 12:14:13 +02:00
|
|
|
LocalVarTotal += Stats.NumLocalVars;
|
|
|
|
LocalVarWithType += Stats.NumLocalVarTypes;
|
|
|
|
LocalVarWithLoc += Stats.NumLocalVarLocations;
|
|
|
|
LocalVarWithSrcLoc += Stats.NumLocalVarSourceLocations;
|
2017-10-06 22:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print summary.
|
|
|
|
OS.SetBufferSize(1024);
|
2020-08-21 18:32:20 +02:00
|
|
|
json::OStream J(OS, 2);
|
2020-08-17 03:26:13 +02:00
|
|
|
J.objectBegin();
|
|
|
|
J.attribute("version", Version);
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(llvm::dbgs() << "Variable location quality metrics\n";
|
|
|
|
llvm::dbgs() << "---------------------------------\n");
|
2020-04-23 12:14:13 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "file", Filename.str());
|
|
|
|
printDatum(J, "format", FormatName);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#functions", NumFunctions);
|
|
|
|
printDatum(J, "#functions with location", NumFuncsWithSrcLoc);
|
|
|
|
printDatum(J, "#inlined functions", NumInlinedFunctions);
|
|
|
|
printDatum(J, "#inlined functions with abstract origins", NumAbstractOrigins);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
|
|
|
// This includes local variables and formal parameters.
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#unique source variables", VarParamUnique);
|
|
|
|
printDatum(J, "#source variables", VarParamTotal);
|
|
|
|
printDatum(J, "#source variables with location", VarParamWithLoc);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#call site entries", GlobalStats.CallSiteEntries);
|
|
|
|
printDatum(J, "#call site DIEs", GlobalStats.CallSiteDIEs);
|
|
|
|
printDatum(J, "#call site parameter DIEs", GlobalStats.CallSiteParamDIEs);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "sum_all_variables(#bytes in parent scope)",
|
2020-04-23 12:14:13 +02:00
|
|
|
GlobalStats.ScopeBytes);
|
2020-08-25 07:19:00 +02:00
|
|
|
printDatum(J,
|
|
|
|
"sum_all_variables(#bytes in any scope covered by DW_AT_location)",
|
|
|
|
GlobalStats.TotalBytesCovered);
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J,
|
2020-04-23 12:14:13 +02:00
|
|
|
"sum_all_variables(#bytes in parent scope covered by "
|
|
|
|
"DW_AT_location)",
|
|
|
|
GlobalStats.ScopeBytesCovered);
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J,
|
2020-04-23 12:14:13 +02:00
|
|
|
"sum_all_variables(#bytes in parent scope covered by "
|
|
|
|
"DW_OP_entry_value)",
|
2019-09-10 12:37:28 +02:00
|
|
|
GlobalStats.ScopeEntryValueBytesCovered);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "sum_all_params(#bytes in parent scope)",
|
2019-11-19 11:28:21 +01:00
|
|
|
GlobalStats.ParamScopeBytes);
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J,
|
|
|
|
"sum_all_params(#bytes in parent scope covered by DW_AT_location)",
|
|
|
|
GlobalStats.ParamScopeBytesCovered);
|
|
|
|
printDatum(J,
|
2020-04-23 12:14:13 +02:00
|
|
|
"sum_all_params(#bytes in parent scope covered by "
|
|
|
|
"DW_OP_entry_value)",
|
2019-09-10 12:37:28 +02:00
|
|
|
GlobalStats.ParamScopeEntryValueBytesCovered);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "sum_all_local_vars(#bytes in parent scope)",
|
2020-04-23 12:14:13 +02:00
|
|
|
GlobalStats.LocalVarScopeBytes);
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J,
|
2020-04-23 12:14:13 +02:00
|
|
|
"sum_all_local_vars(#bytes in parent scope covered by "
|
|
|
|
"DW_AT_location)",
|
|
|
|
GlobalStats.LocalVarScopeBytesCovered);
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J,
|
2020-04-23 12:14:13 +02:00
|
|
|
"sum_all_local_vars(#bytes in parent scope covered by "
|
|
|
|
"DW_OP_entry_value)",
|
|
|
|
GlobalStats.LocalVarScopeEntryValueBytesCovered);
|
|
|
|
|
2020-08-20 23:11:08 +02:00
|
|
|
printDatum(J, "#bytes within functions", GlobalStats.FunctionSize);
|
|
|
|
printDatum(J, "#bytes within inlined functions",
|
2020-04-23 12:14:13 +02:00
|
|
|
GlobalStats.InlineFunctionSize);
|
|
|
|
|
|
|
|
// Print the summary for formal parameters.
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#params", ParamTotal);
|
|
|
|
printDatum(J, "#params with source location", ParamWithSrcLoc);
|
|
|
|
printDatum(J, "#params with type", ParamWithType);
|
|
|
|
printDatum(J, "#params with binary location", ParamWithLoc);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
|
|
|
// Print the summary for local variables.
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#local vars", LocalVarTotal);
|
|
|
|
printDatum(J, "#local vars with source location", LocalVarWithSrcLoc);
|
|
|
|
printDatum(J, "#local vars with type", LocalVarWithType);
|
|
|
|
printDatum(J, "#local vars with binary location", LocalVarWithLoc);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
|
|
|
// Print the debug section sizes.
|
2020-08-17 03:26:13 +02:00
|
|
|
printSectionSizes(J, Sizes);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
|
|
|
// Print the location statistics for variables (includes local variables
|
|
|
|
// and formal parameters).
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#variables processed by location statistics",
|
2020-04-23 12:14:13 +02:00
|
|
|
LocStats.NumVarParam);
|
2020-08-17 03:26:13 +02:00
|
|
|
printLocationStats(J, "#variables", LocStats.VarParamLocStats);
|
|
|
|
printLocationStats(J, "#variables - entry values",
|
2019-09-10 12:37:28 +02:00
|
|
|
LocStats.VarParamNonEntryValLocStats);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
|
|
|
// Print the location statistics for formal parameters.
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#params processed by location statistics", LocStats.NumParam);
|
|
|
|
printLocationStats(J, "#params", LocStats.ParamLocStats);
|
|
|
|
printLocationStats(J, "#params - entry values",
|
2019-09-10 12:37:28 +02:00
|
|
|
LocStats.ParamNonEntryValLocStats);
|
2020-04-23 12:14:13 +02:00
|
|
|
|
|
|
|
// Print the location statistics for local variables.
|
2020-08-17 03:26:13 +02:00
|
|
|
printDatum(J, "#local vars processed by location statistics",
|
2020-04-23 12:14:13 +02:00
|
|
|
LocStats.NumVar);
|
2020-08-17 03:26:13 +02:00
|
|
|
printLocationStats(J, "#local vars", LocStats.LocalVarLocStats);
|
|
|
|
printLocationStats(J, "#local vars - entry values",
|
2020-04-23 12:14:13 +02:00
|
|
|
LocStats.LocalVarNonEntryValLocStats);
|
2020-08-17 03:26:13 +02:00
|
|
|
J.objectEnd();
|
|
|
|
OS << '\n';
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(
|
2017-10-06 22:24:34 +02:00
|
|
|
llvm::dbgs() << "Total Availability: "
|
2019-03-02 00:51:54 +01:00
|
|
|
<< (int)std::round((VarParamWithLoc * 100.0) / VarParamTotal)
|
|
|
|
<< "%\n";
|
2017-10-06 22:24:34 +02:00
|
|
|
llvm::dbgs() << "PC Ranges covered: "
|
|
|
|
<< (int)std::round((GlobalStats.ScopeBytesCovered * 100.0) /
|
2019-11-19 11:28:21 +01:00
|
|
|
GlobalStats.ScopeBytes)
|
2017-10-06 22:24:34 +02:00
|
|
|
<< "%\n");
|
|
|
|
return true;
|
|
|
|
}
|