我需要在llvm传递期间提取目录和文件名。当前版本的llvm将getFilename
和getDirectory
从DebugLoc
移动到DebugInfoMetadata
。我在getFilename
标题中找不到类成员DebugLoc
。那么,如何从指令转到源代码文件名和目录?
http://llvm.org/docs/doxygen/html/classllvm_1_1DebugLoc.html
此外,有一个打印功能可能会有所帮助,但它只需要一个llvm::raw_ostream
,不能重定向到std::string
。
void print (raw_ostream &OS) const
// prints source location /path/to/file.exe:line:col @[inlined at]
下面的代码是给出错误的原因
const DebugLoc &location = an_instruction_iter->getDebugLoc()
StringRef File = location->getFilename() // Gives an error
---我几分钟前发现的解决方案----
const DebugLoc &location = i_iter->getDebugLoc();
const DILocation *test =location.get();
test->getFilename();`
1)
std::string dbgInfo;
llvm::raw_string_ostream rso(dbgInfo);
location->print(rso);
std::sting dbgStr = rso.str()
2)
auto *Scope = cast<DIScope>(location->getScope());
std::string fileName = Scope->getFilename();