Skip to content

Commit b7f53df

Browse files
committed
[analyzer] Self-debug: Dump dynamic type info and taint with the program state.
Useful for debugging problems with dynamic type info and taint. Differential Revision: https://reviews.llvm.org/D43657 llvm-svn: 326239
1 parent 4068481 commit b7f53df

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ inline ProgramStateRef setDynamicTypeInfo(ProgramStateRef State,
5151
DynamicTypeInfo(NewTy, CanBeSubClassed));
5252
}
5353

54+
void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out,
55+
const char *NL, const char *Sep);
56+
5457
} // ento
5558
} // clang
5659

clang/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,28 @@ ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *Reg,
4747
return NewState;
4848
}
4949

50+
void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out,
51+
const char *NL, const char *Sep) {
52+
bool First = true;
53+
for (const auto &I : State->get<DynamicTypeMap>()) {
54+
if (First) {
55+
Out << NL << "Dynamic types of regions:" << NL;
56+
First = false;
57+
}
58+
const MemRegion *MR = I.first;
59+
const DynamicTypeInfo &DTI = I.second;
60+
Out << MR << " : ";
61+
if (DTI.isValid()) {
62+
Out << DTI.getType()->getPointeeType().getAsString();
63+
if (DTI.canBeASubClass()) {
64+
Out << " (or its subclass)";
65+
}
66+
} else {
67+
Out << "Invalid type info";
68+
}
69+
Out << NL;
70+
}
71+
}
72+
5073
} // namespace ento
5174
} // namespace clang

clang/lib/StaticAnalyzer/Core/ProgramState.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
1818
#include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
1919
#include "clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h"
20+
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
2021
#include "llvm/Support/raw_ostream.h"
2122

2223
using namespace clang;
@@ -449,6 +450,12 @@ void ProgramState::print(raw_ostream &Out, const char *NL, const char *Sep,
449450
// Print out the constraints.
450451
Mgr.getConstraintManager().print(this, Out, NL, Sep);
451452

453+
// Print out the tracked dynamic types.
454+
printDynamicTypeInfo(this, Out, NL, Sep);
455+
456+
// Print out tainted symbols.
457+
printTaint(Out, NL, Sep);
458+
452459
// Print checker-specific data.
453460
Mgr.getOwningEngine()->printState(Out, this, NL, Sep, LC);
454461
}
@@ -466,7 +473,7 @@ void ProgramState::printTaint(raw_ostream &Out,
466473
TaintMapImpl TM = get<TaintMap>();
467474

468475
if (!TM.isEmpty())
469-
Out <<"Tainted Symbols:" << NL;
476+
Out <<"Tainted symbols:" << NL;
470477

471478
for (TaintMapImpl::iterator I = TM.begin(), E = TM.end(); I != E; ++I) {
472479
Out << I->first << " : " << I->second << NL;

0 commit comments

Comments
 (0)