Skip to content

Commit 31c5a8b

Browse files
committed
addressed comments, fixed tsan issues
1 parent 4b29a04 commit 31c5a8b

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OutputCategoryAggregator {
3535
private:
3636
std::mutex WriteMutex;
3737
std::map<std::string, unsigned> Aggregation;
38-
unsigned NumErrors = 0;
38+
uint64_t NumErrors = 0;
3939
bool IncludeDetail;
4040

4141
public:
@@ -46,7 +46,7 @@ class OutputCategoryAggregator {
4646
void Report(StringRef s, std::function<void()> detailCallback);
4747
void EnumerateResults(std::function<void(StringRef, unsigned)> handleCounts);
4848
/// Return the number of errors that have been reported.
49-
unsigned GetNumErrors() const { return NumErrors; }
49+
uint64_t GetNumErrors() const { return NumErrors; }
5050
};
5151

5252
/// A class that verifies DWARF debug information given a DWARF Context.
@@ -307,6 +307,13 @@ class DWARFVerifier {
307307
void verifyDebugNames(const DWARFSection &AccelSection,
308308
const DataExtractor &StrData);
309309

310+
/// Constructs a full name for a DIE. Potentially it does recursive lookup on
311+
/// DIEs. This can lead to extraction of DIEs in a different CU or TU.
312+
SmallVector<std::string, 3> getNames(const DWARFDie &DIE,
313+
bool IncludeStrippedTemplateNames,
314+
bool IncludeObjCNames = true,
315+
bool IncludeLinkageName = true);
316+
310317
public:
311318
DWARFVerifier(raw_ostream &S, DWARFContext &D,
312319
DIDumpOptions DumpOpts = DIDumpOptions::getForSingleDIE());

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ void DWARFVerifier::verifyNameIndexBuckets(const DWARFDebugNames::NameIndex &NI,
12981298
// each Name is reachable from the appropriate bucket.
12991299
std::vector<BucketInfo> BucketStarts;
13001300
BucketStarts.reserve(NI.getBucketCount() + 1);
1301-
const unsigned OrigNumberOfErrors = ErrorCategory.GetNumErrors();
1301+
const uint64_t OrigNumberOfErrors = ErrorCategory.GetNumErrors();
13021302
for (uint32_t Bucket = 0, End = NI.getBucketCount(); Bucket < End; ++Bucket) {
13031303
uint32_t Index = NI.getBucketArrayEntry(Bucket);
13041304
if (Index > NI.getNameCount()) {
@@ -1516,12 +1516,16 @@ void DWARFVerifier::verifyNameIndexAbbrevs(
15161516
}
15171517
}
15181518

1519-
static SmallVector<std::string, 3> getNames(const DWARFDie &DIE,
1520-
bool IncludeStrippedTemplateNames,
1521-
bool IncludeObjCNames = true,
1522-
bool IncludeLinkageName = true) {
1519+
SmallVector<std::string, 3>
1520+
DWARFVerifier::getNames(const DWARFDie &DIE, bool IncludeStrippedTemplateNames,
1521+
bool IncludeObjCNames, bool IncludeLinkageName) {
15231522
SmallVector<std::string, 3> Result;
1524-
if (const char *Str = DIE.getShortName()) {
1523+
const char *Str = nullptr;
1524+
{
1525+
std::lock_guard<std::mutex> Lock(AccessMutex);
1526+
Str = DIE.getShortName();
1527+
}
1528+
if (Str) {
15251529
StringRef Name(Str);
15261530
Result.emplace_back(Name);
15271531
if (IncludeStrippedTemplateNames) {
@@ -1695,15 +1699,12 @@ void DWARFVerifier::verifyNameIndexEntries(
16951699
// NonSkeletonUnitDie to point to the actual type unit in the .dwo/.dwp.
16961700
NonSkeletonUnit =
16971701
NonSkeletonDCtx.getTypeUnitForHash(TypeSig, /*IsDWO=*/true);
1698-
DWARFDie NonSkeletonUnitDie = DWARFDie();
1699-
{
1700-
std::lock_guard<std::mutex> Lock(AccessMutex);
1701-
NonSkeletonUnitDie = NonSkeletonUnit->getUnitDIE(true);
1702-
}
17031702
// If we have foreign type unit in a DWP file, then we need to ignore
17041703
// any entries from type units that don't match the one that made it into
17051704
// the .dwp file.
17061705
if (NonSkeletonDCtx.isDWP()) {
1706+
std::lock_guard<std::mutex> Lock(AccessMutex);
1707+
DWARFDie NonSkeletonUnitDie = NonSkeletonUnit->getUnitDIE(true);
17071708
StringRef DUDwoName = dwarf::toStringRef(
17081709
UnitDie.find({DW_AT_dwo_name, DW_AT_GNU_dwo_name}));
17091710
StringRef TUDwoName = dwarf::toStringRef(
@@ -1958,7 +1959,7 @@ void DWARFVerifier::verifyDebugNames(const DWARFSection &AccelSection,
19581959
[&]() { error() << Msg << '\n'; });
19591960
return;
19601961
}
1961-
const unsigned OriginalNumErrors = ErrorCategory.GetNumErrors();
1962+
const uint64_t OriginalNumErrors = ErrorCategory.GetNumErrors();
19621963
verifyDebugNamesCULists(AccelTable);
19631964
for (const auto &NI : AccelTable)
19641965
verifyNameIndexBuckets(NI, StrData);

llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
780780
if (filterArch(*Obj)) {
781781
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(
782782
*Obj, DWARFContext::ProcessDebugRelocations::Process, nullptr, "",
783-
RecoverableErrorHandler, WithColor::defaultWarningHandler, true);
783+
RecoverableErrorHandler, WithColor::defaultWarningHandler,
784+
/*ThreadSafe=*/true);
784785
DICtx->setParseCUTUIndexManually(ManuallyGenerateUnitIndex);
785786
if (!HandleObj(*Obj, *DICtx, Filename, OS))
786787
Result = false;

0 commit comments

Comments
 (0)