This is an archive of the discontinued LLVM Phabricator instance.

[llvm-debuginfo-analyzer] 06 - Warning and internal options
ClosedPublic

Authored by CarlosAlbertoEnciso on May 17 2022, 6:46 AM.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 6:46 AM
CarlosAlbertoEnciso requested review of this revision.May 17 2022, 6:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 6:46 AM
CarlosAlbertoEnciso edited the summary of this revision. (Show Details)May 17 2022, 7:10 AM
CarlosAlbertoEnciso removed a project: Restricted Project.
CarlosAlbertoEnciso removed subscribers: mgorny, hiraditya.
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 7:10 AM
CarlosAlbertoEnciso edited the summary of this revision. (Show Details)May 18 2022, 1:34 AM

Some my comments repeat comments to previous patches, sorry if it looks noisy. Could you check the {A, B} replacement of the std::make_pair(A, B)? If it works, there is a couple of places where std::make_pair is used and they can be replaced with {A, B} too.

llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h
60

What about to add #include <list> to make the header more self-contained?

llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
146

This is a bit inconsistent declaration: MapType is declared with typename while all the other types are declared with class. Something one should be used: either typename or class.

153

I'm sorry but I cannot find where the List is deleted. So, I get the Map takes ownership of the List but there is no destructor of function where the Map's entries (of the DebugTags map, for example) is deleted.

154

I believe this should work too.

llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
41

I believe this should work.

44

To create an LVDuplicateEntry in place.

72

If format is the llvm::format function, the lambda captures nothing.

llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp
1127

The code is mostly identical to LVScopeCompileUnit::addInvalidLocation(LVLocation *Location), it may make sense to extract the body in a static free function and pass into it an additional parameter: LVOffsetLocationsMap which is either &InvalidLocations or &InvalidRanges.

1199

I believe this should work too.

1210

I believe this should work too.

1223

I believe this should work too.

1236
llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
93

A std::bad_alloc will be thrown if the test is out of memory. It makes sense to wrap the line in the try-catch block or use the non-throwing overload of the new operator.

177

There is an overload of the operator== for two StringRefs, so there is no needs in EXPECT_STREQ, moreover the data() method of StringRef doesn't guarantee that the returned string will be null terminated.

psamolysov added inline comments.May 31 2022, 11:12 PM
llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
154

Or, it could be better Map->emplace(Key, List);.

llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
41

Or, it could be better Integrity.emplace(Element, Scope);.

psamolysov added inline comments.Jun 2 2022, 9:43 AM
llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
53–55

Here could be a bug: if AddressToLineData.upper_bound(Address) returns AddressToLineData.end(), AddressToLineData.end() is definitely not equal to AddressToLineData.begin(), Iter changes it's value to an element previous to the end and the check Iter != AddressToLineData.end() is forever be true.

llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h
60

Included <list>

llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
146

Changed to use typename.

llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp
1199

Nice change.

1210

Nice change.

1223

Nice change.

1236

Nice change.

llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
93

Changed to use the non-throwing overload.

177

Changed to EXPECT_EQ(Element->getName(), Name);

llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
153

Very good catch. The destructor part is missing.

// Delete the map contained list.
template <typename MapType> void deleteList(MapType &Map) {
  for (typename MapType::const_reference Entry : Map)
    delete Entry.second;
}
154

Replaced with Map->emplace(Key, List);.

llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
41

Replaced with Integrity.emplace(Element, Scope);.

44

Replaced with Duplicate.emplace_back(Element, Scope, Iter->second);

72

You are correct.
Changed to auto PrintIndex = [](unsigned Index) {.

llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp
1127

Refactored as:

void LVScopeCompileUnit::addInvalidLocationOrRange(LVLocation *Location,
                                                   LVElement *Element,
                                                   LVOffsetLocationsMap *Map) {
  LVOffset Offset = Element->getOffset();
  addInvalidOffset(Offset, Element);
  addItem<LVOffsetLocationsMap, LVLocations, LVOffset, LVLocation *>(
      Map, Offset, Location);
}

// Record symbols with invalid locations.
void LVScopeCompileUnit::addInvalidLocation(LVLocation *Location) {
  addInvalidLocationOrRange(Location, Location->getParentSymbol(),
                            &InvalidLocations);
}

// Record scopes with invalid ranges.
void LVScopeCompileUnit::addInvalidRange(LVLocation *Location) {
  addInvalidLocationOrRange(Location, Location->getParentScope(),
                            &InvalidRanges);
}
llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
53–55

Sorry, I'm afraid I don't follow you.

The logic behind that code, is to get a LVLine that corresponds to the given Address.

Let's assume we have the following values:

{ Address 100, Line-1 } => Line-1 represents the address range [100-199] and [...-100]
{ Address 200, Line-2 } => Line-2 represents the address range [200-299]
{ Address 300, Line-3 } => Line-3 represents the address range [300-...]

Then

lineUpperBound(50)  -> Line-1
lineUpperBound(100) -> Line-1
lineUpperBound(150) -> Line-1
lineUpperBound(200) -> Line-2
lineUpperBound(250) -> Line-2
lineUpperBound(300) -> Line-3
lineUpperBound(350) -> Line-3
psamolysov added inline comments.Jul 6 2022, 6:20 AM
llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
53–55

Thank you for the explanation. I'm still not sure how you can get AddressToLineData.end() after std::prev(Iter). Only one case is possible: AddressToLineData is empty, in this case begin() is equals to end(), so the check (Iter != AddressToLineData.end()) is required in this case. Maybe it makes sense to add the check if (AddressToLineData.empty()) before the call to AddressToLineData.upper_bound(Address) and remove the ternary operator at the end? I believe it can improve the method's readability.

llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
53–55

Thanks for your great suggestion. It improve the function's readability.

Changed version to:

LVLine *MyAddressToLine::lineUpperBound(LVAddress Address) {
  if (AddressToLineData.empty())
    return nullptr;
  LVAddressToLine::const_iterator Iter = AddressToLineData.upper_bound(Address);
  if (Iter != AddressToLineData.begin())
    Iter = std::prev(Iter);
  return Iter->second;
}
psamolysov added inline comments.Jul 7 2022, 11:38 PM
llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
53–55

This method looks good for me. Thanks.

  • Addressed the reviewer’s feedback.
  • Tool renamed as: llvm-debuginfo-analyzer.
CarlosAlbertoEnciso retitled this revision from [llvm-dva] 06 - Warning and internal options to [llvm-debuginfo-analyzer] 06 - Warning and internal options.Jul 25 2022, 2:19 AM
CarlosAlbertoEnciso edited the summary of this revision. (Show Details)
probinson added inline comments.Sep 19 2022, 2:54 PM
llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
43
54
103

exit in a library function?

llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
95

Use ASSERT_NE so the test will abort if the allocation fails.

Update patch due to changes in previous patches.

llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
54

Added braces.

103

This is a good point.

During the development of the CodeView Reader, due to incorrect parsing of the debug information, in some cases the same logical element was added to more than one logical scope.

If this method detects an error, it means the tool will crash as the memory is corrupted: the same logical element being destroyed more than once. That is the reason to force the exit.

llvm/unittests/DebugInfo/LogicalView/WarningInternalTest.cpp
95

ASSERT_NE can be used only inside functions that don't return a value.

See https://google.github.io/googletest/advanced.html#assertion-placement

The one constraint is that assertions that generate a fatal failure (FAIL* and ASSERT_*) can only be used in void-returning functions.

Address points raised by @probinson.

probinson added inline comments.Sep 30 2022, 7:38 AM
llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
43

ping.

103

Better to have this function return a bool status, and the caller can do the exit or whatever else is appropriate to its context.

llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
43

Changed to // We found a duplicate..

103
bool checkIntegrityScopesTree(LVScope *Root) {
  ...
  // Start traversing the scopes root and print any duplicates.
  TraverseScope(Root);
  bool PassIntegrity = true;
  if (Duplicate.size()) {
    ...
    PassIntegrity = false;
  }
  return PassIntegrity;
}

If the scopes tree integrity fails, propagate an Error condition to the caller LVReader::doLoad().

Error LVReader::doLoad() {
  ...
  if (options().getInternalIntegrity() && !checkIntegrityScopesTree(Root))
    return make_error<StringError>("Duplicated elements in Scopes Tree");
  ...
  return Error::success();
}
llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
103

It should read:

Error LVReader::doLoad() {
  ...
  if (options().getInternalIntegrity() && !checkIntegrityScopesTree(Root))
    return llvm::make_error<StringError>("Duplicated elements in Scopes Tree",
                                         inconvertibleErrorCode());
  ...
  return Error::success();
}

Please upload the latest revision.

Updated patch to address reviews from @probinson.

This revision is now accepted and ready to land.Oct 5 2022, 7:22 AM
This revision was landed with ongoing or failed builds.Oct 23 2022, 9:14 PM
This revision was automatically updated to reflect the committed changes.

@psamolysov , @probinson Thanks very much for all your valuable reviews.

@hliao Thanks for fixing the multi-stage link issue.

CarlosAlbertoEnciso edited the summary of this revision. (Show Details)Nov 14 2022, 4:02 AM