跨版线匹配 [英] Cross version line matching

查看:168
本文介绍了跨版线匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑如何进行自动的错误跟踪,作为其中的一部分,我想知道什么可以匹配源代码行号(或更准确的数字映射从指令指针通过类似 addr2line )在一个版本的程序中同一行在另一个。 (假设一切都在某种源代码控制中,可用于我的代码)



最简单的方法是在文件上使用diff工具/ lib,然后做一些数学跨线数学,但这有一些限制:




  • 它不处理交叉文件动作。

  • 它可能不会很好,线条变化

  • 它不看中间版本的信息。

  • 当diff工具出错时,它无法手动修补行。

  • 有点笨重



在我开始潜水开发更好的东西之前:




  • 这样做已经存在?

  • 系统有没有想到的?


解决方案

我的建议是:而不是尝试跟踪行号,您观察到的行数可能随着软件的变化而迅速失去同步,您应该使用唯一标识符

来装饰每个断言(或其他感兴趣的行)。



假设您使用C,在断言的情况下,可以像更改类似 assert(x == 42); to assert((check_x,x == 42)); - 由于C中逗号运算符的语义,这在功能上是相同的并且事实上字符串字面值将始终为true。



当然这意味着您需要识别一个pri ori 您希望跟踪的项目。但是鉴于没有一般可靠的方式来匹配版本之间的源代码行(我的意思是,对于任何可以提出的机制,我相信我可以提出一种情况,其中机制是错误的)我会认为这个是最好的你可以做。



另一个想法:如果你使用C ++,你可以使用 RAII 非常优雅地跟踪动态范围。基本上,您有一个 Track 类,其构造函数使用描述范围的字符串,并将其添加到当前活动作用域的全局堆栈。 Track 析构函数将顶层元素从堆栈中弹出。最终的成分是静态函数 Track :: getState(),它只返回所有当前活动的作用域的列表 - 这可以从异常处理程序或其他错误中调用处理机制。


I'm considering how to do automatic bug tracking and as part of that I'm wondering what is available to match source code line numbers (or more accurate numbers mapped from instruction pointers via something like addr2line) in one version of a program to the same line in another. (Assume everything is in some kind of source control and is available to my code)

The simplest approach would be to use a diff tool/lib on the files and do some math on the line number spans, however this has some limitations:

  • It doesn't handle cross file motion.
  • It might not play well with lines that get changed
  • It doesn't look at the information available in the intermediate versions.
  • It provides no way to manually patch up lines when the diff tool gets things wrong.
  • It's kinda clunky

Before I start diving into developing something better:

  • What already exists to do this?
  • What features do similar system have that I've not thought of?

解决方案

My suggestion is: instead of trying to track line numbers, which as you observed can quickly get out of sync as software changes, you should decorate each assertion (or other line of interest) with a unique identifier.

Assuming you're using C, in the case of assertions, this could be as simple as changing something like assert(x == 42); to assert(("check_x", x == 42)); -- this is functionally identical, due to the semantics of the comma operator in C and the fact that a string literal will always evaluate to true.

Of course this means that you need to identify a priori those items that you wish to track. But given that there's no generally reliable way to match up source line numbers across versions (by which I mean that for any mechanism you could propose, I believe I could propose a situation in which that mechanism does the wrong thing) I would argue that this is the best you can do.

Another idea: If you're using C++, you can make use of RAII to track dynamic scopes very elegantly. Basically, you have a Track class whose constructor takes a string describing the scope and adds this to a global stack of currently active scopes. The Track destructor pops the top element off the stack. The final ingredient is a static function Track::getState(), which simply returns a list of all currently active scopes -- this can be called from an exception handler or other error-handling mechanism.

这篇关于跨版线匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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