This is an archive of the discontinued LLVM Phabricator instance.

[lldb][InstrumentationRuntime] Make 'data' struct anonymous in order to avoid collisions with types in the debuggee
ClosedPublic

Authored by Michael137 on Mar 8 2023, 3:36 AM.

Details

Summary

The UBSAN/ASAN plugins would previously call the internal helper
structure injected into the source expression struct data { ... };

This occasionally collided with user-defined types of the same (quite
common) name. In the presence of varibale with the same name LLDB would
simply fail to run the injected InstrumentationRuntime expressions
with:

warning: cannot evaluate AddressSanitizer expression:
expression failed to parse:
error: <user expression 2>:2:5: must use 'struct' tag to refer to type 'data' in this scope
data t;

In the presence of another type called 'data', LLDB would most likely
crash with something like:

0x00000001198de614 clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) + 1088
0x00000001198de614 clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) + 1088
0x0000000119907930 clang::ASTImporter::ImportDefinition(clang::Decl*) + 596
0x00000001163db928 lldb_private::ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(clang::Decl*, clang::Decl*) + 100
0x00000001163da070 (anonymous namespace)::CompleteTagDeclsScope::~CompleteTagDeclsScope() + 572
...

...because it got the types confused.

This patch makes these structures anonymous so there's no
chance of clashing with other types in the program. This is
already the approach taken in UBSan/InstrumentationRuntimeABSan.cpp.

Testing

  • API tests still pass
  • Tested manually that the memory history command now works in the presence of a local called data

Diff Detail

Event Timeline

Michael137 created this revision.Mar 8 2023, 3:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2023, 3:36 AM
Michael137 requested review of this revision.Mar 8 2023, 3:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2023, 3:36 AM
Michael137 edited the summary of this revision. (Show Details)Mar 8 2023, 3:45 AM

Not sure there's a test to be added here.

Of course I could add a dummy data type to the API tests called struct data {}; and confirm that it doesn't crash (I did this manually locally), but it doesn't seem like something that would catch regressions in the future. But if people want I can add them in

Michael137 edited the summary of this revision. (Show Details)
Michael137 updated this revision to Diff 503308.Mar 8 2023, 3:53 AM
  • Update commit message
Michael137 edited the summary of this revision. (Show Details)Mar 8 2023, 3:56 AM
Michael137 edited the summary of this revision. (Show Details)Mar 8 2023, 4:08 AM

The TSAN instrumenter has the same struct data definition. I actually got a report of this crashing in TSAN yesterday. You should do that one as well. Otherwise, LGTM and I don't think you need to add a test with "struct data" in it on the off chance that someone reverts this back to exactly struct data...

Michael137 updated this revision to Diff 503572.Mar 8 2023, 4:53 PM
Michael137 edited the summary of this revision. (Show Details)
  • Apply fix to TSAN structure as well

The TSAN instrumenter has the same struct data definition. I actually got a report of this crashing in TSAN yesterday. You should do that one as well. Otherwise, LGTM and I don't think you need to add a test with "struct data" in it on the off chance that someone reverts this back to exactly struct data...

Ah good point, done

jingham accepted this revision.Mar 9 2023, 4:39 PM

LGTM

This revision is now accepted and ready to land.Mar 9 2023, 4:39 PM