Clang 如何从LLVM指令中获取文件名和目录?

Clang 如何从LLVM指令中获取文件名和目录?,clang,llvm,llvm-clang,llvm-c++-api,Clang,Llvm,Llvm Clang,Llvm C++ Api,我需要在llvm过程中提取目录和文件名。 llvm的当前版本将getFilename和getDirectory从DebugLoc移动到DebugInfoMetadata。我无法直接在DebugLoc标题中找到类成员getFilename。因此,如何从指令转到源代码文件名和目录 此外,还有一个打印函数可能会有所帮助,但它只需要llvm::raw_ostream,不能重定向到std::string void print (raw_ostream &OS) const // prints s

我需要在llvm过程中提取目录和文件名。 llvm的当前版本将
getFilename
getDirectory
DebugLoc
移动到
DebugInfoMetadata
。我无法直接在
DebugLoc
标题中找到类成员
getFilename
。因此,如何从指令转到源代码文件名和目录

此外,还有一个打印函数可能会有所帮助,但它只需要
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
---我几分钟前想出的解决办法----

(一)

(二)

auto*Scope=cast(位置->getScope());
std::string fileName=Scope->getFilename();

其中F是要获取源文件名的函数。

第二种解决方案有效。第一个解决方案为调用“打印”位置->打印(流)提供了一个错误
没有匹配的成员函数
const DebugLoc &location = i_iter->getDebugLoc();
const DILocation *test =location.get();
test->getFilename();`
std::string dbgInfo;
llvm::raw_string_ostream rso(dbgInfo);
location->print(rso);
std::sting dbgStr = rso.str()
auto *Scope = cast<DIScope>(location->getScope());
std::string fileName = Scope->getFilename();
F.getParent()->getSourceFileName();