Skip to content

Commit

Permalink
[analyzer] Self-debug: Dump dynamic type info and taint with the prog…
Browse files Browse the repository at this point in the history
…ram state.

Useful for debugging problems with dynamic type info and taint.

Differential Revision: https://reviews.llvm.org/D43657

llvm-svn: 326239
  • Loading branch information
haoNoQ committed Feb 27, 2018
1 parent 4068481 commit b7f53df
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Expand Up @@ -51,6 +51,9 @@ inline ProgramStateRef setDynamicTypeInfo(ProgramStateRef State,
DynamicTypeInfo(NewTy, CanBeSubClassed));
}

void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out,
const char *NL, const char *Sep);

} // ento
} // clang

Expand Down
23 changes: 23 additions & 0 deletions clang/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
Expand Up @@ -47,5 +47,28 @@ ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *Reg,
return NewState;
}

void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out,
const char *NL, const char *Sep) {
bool First = true;
for (const auto &I : State->get<DynamicTypeMap>()) {
if (First) {
Out << NL << "Dynamic types of regions:" << NL;
First = false;
}
const MemRegion *MR = I.first;
const DynamicTypeInfo &DTI = I.second;
Out << MR << " : ";
if (DTI.isValid()) {
Out << DTI.getType()->getPointeeType().getAsString();
if (DTI.canBeASubClass()) {
Out << " (or its subclass)";
}
} else {
Out << "Invalid type info";
}
Out << NL;
}
}

} // namespace ento
} // namespace clang
9 changes: 8 additions & 1 deletion clang/lib/StaticAnalyzer/Core/ProgramState.cpp
Expand Up @@ -17,6 +17,7 @@
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
#include "llvm/Support/raw_ostream.h"

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

// Print out the tracked dynamic types.
printDynamicTypeInfo(this, Out, NL, Sep);

// Print out tainted symbols.
printTaint(Out, NL, Sep);

// Print checker-specific data.
Mgr.getOwningEngine()->printState(Out, this, NL, Sep, LC);
}
Expand All @@ -466,7 +473,7 @@ void ProgramState::printTaint(raw_ostream &Out,
TaintMapImpl TM = get<TaintMap>();

if (!TM.isEmpty())
Out <<"Tainted Symbols:" << NL;
Out <<"Tainted symbols:" << NL;

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

0 comments on commit b7f53df

Please sign in to comment.