[llvm-dev] DebugInfo, Metadata usage
DES via llvm-dev
llvm-dev at lists.llvm.org
Mon May 22 06:14:57 PDT 2017
Hello LLVM Community,
I'm working on some analyzer\checker and want to implement checker for
variables.
In that case, I want to retrieve some information about types of
variables or identify that the variable is either string or not.
As an example, for strings which can be char or string type I came up
with a solution to find it out via isString or isCString methods. But
for strings whose type is wchar my approach is not working. Cause,
internally in IR wchar string is an array of integers.
I looked up some information about how to get types of variables that
were got from the source level in IR level. (I've been reading some info
in LLVM Blog about metadata, in llvm docs about SourceLevel Debugging
with LLVM + StripSymbols.cpp, Metadata.cpp, DebugInfo.cpp)
I found that I can get it from DebugInfo or Metadata.
But my little research was not successful.
my code excerpt:
DebugInfoFinder DIFinder;
DIFinder.processModule(*M);
llvm::outs() << "Count of global Variables in Module : " <<
DIFinder.global_variable_count() << "\n";
for(DIGlobalVariableExpression *DIGVExpr : DIFinder.global_variables())
{
if(DIGlobalVariable *DIGV = DIGVExpr->getVariable())
{
llvm::outs() << "DIGV DisplayName : " <<
DIGV->getDisplayName() << "\n";
}
}
for(DIType *DIT : DIFinder.types())
{
if(DIBasicType* DIBT = dyn_cast<DIBasicType>(DIT))
{
llvm::outs() << "DIBasicType in Module : " << DIT->getName()
<< "\n";
StringRef Encoding =
dwarf::AttributeEncodingString(DIBT->getEncoding());
if(!Encoding.empty())
{
llvm::outs() << "Encoding : " << Encoding.str() << "\n";
}
}
}
llvm::outs() << "\n\nPrint All Strings Declarations: \n";
for(GlobalVariable& GV : M->globals())
{
if(!GV.hasInitializer()) continue;
if(ConstantDataSequential *CDS =
dyn_cast<ConstantDataSequential>(GV.getInitializer()))
{
llvm::outs() << "GVName: " << GV.getName() << "\n";
llvm::outs() << "\tRawDataValues : " <<
CDS->getRawDataValues().str() << "\n"; // here I see my wchar string
if(CDS->isString() || CDS->isCString()) // but these checks
are not appropriate for checking strings of wchar's type
{
llvm::outs() << "\tCString&&Std::String : " <<
CDS->getAsString().str() << "\n";
}
}
}
What way can I get DIBasicType for ConstantDataSequential?
Literally, I want to know is there any way to get the relationship
between constant, globals and related debuginfo, metadata information?
I would appreciate it for any help.
In advance, thank you very much.
--
----------------------
the best regards!
0x0859549A
More information about the llvm-dev
mailing list