如何从给定LLVM IR的源代码中获取变量的所有行号? [英] How to get all the line number of a variable from source code given LLVM IR?

查看:488
本文介绍了如何从给定LLVM IR的源代码中获取变量的所有行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全是LLVM的新手.我想知道如何从给定LLVM IR的源代码中获取特定变量的所有行号?

I am totally a newbie in LLVM. I wanted to know how we can get all the line numbers for a particular variable from source code given LLVM IR?

例如(显示LLVM IR的代码段)

For example (showing snippet of LLVM IR)

store i32 0, i32* %i, align 4, !dbg !12
!12 = !DILocation(line: 2, column: 6, scope: !7)
%4 = load i32*, i32** %ip, align 8, !dbg !30
!30 = !DILocation(line: 7, column: 4, scope: !25)

我相信,通过检查LLVM IR,获取任何变量的行号详细信息与在指令末尾访问!dbg有关.但是我不知道如何访问这些信息.

I believe, from inspecting LLVM IR, getting the line number details for any variable has something to do with accessing !dbg at the end of instruction. But I don't know how to access those information.

另一个疑问是,如果使用指针存储变量的地址,我们如何知道它为哪个变量存储地址?

Another doubt is if a pointer is used to store address of a variable, how do we know for which variable it is storing address of?

推荐答案

LLVM中的所有内容都是一个值,某些值会跟踪其用户. 42(常数int)不是,但是您感兴趣的值确实可以跟踪其用户.我有一些代码可以处理使用特殊值的phi节点;这是找到这些phi节点的三行:

Everything in LLVM is a Value, and some of the Values keep track of their users. 42 (a constant int) does not, but the Values you are interested in do keep track of their users. I have some code that processes the phi nodes that use a partciular Value; here are three lines that find those phi nodes:

for(auto u : someValue->users()) {
  PHINode * phi = dyn_cast<PHINode>(u);
  if(phi)
    …

请注意,这仅适用于模块内.如果您具有全局值(例如许多函数),则不会跟踪模块外部的使用(例如大多数函数调用).

Note that this only works in-module. If you have a global value (such as many functions) then uses from outside the module aren't tracked (such as most function calls).

这篇关于如何从给定LLVM IR的源代码中获取变量的所有行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆