自动跟踪变化的变量 [英] Trace changes to variables automatically

查看:91
本文介绍了自动跟踪变化的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调试一个C程序(GCC和GDB Linux和Visual Studio的Windows环境),让两个不同的体系结构不同的结果。我想通过跟踪更改存储在变量的值,以找到差异每个架构比较执行。

I am debugging a C program (GCC and GDB in Linux and Visual Studio in Windows) that gives different results on two different architectures. I'd like to compare execution on each architecture by tracing the changes to the values stored in variables in order to locate differences.


file main.c, line 234. Variable A changes from 34 to 23
file main.c, line 236. Variable B changes from 0 to 2
.....
etc.

能否编译器指示仪这样的效果,而无需手动乱扔垃圾与源的printf 语句?

推荐答案

我会写一个脚本来自动驾驶仪的调试器。我不知道是否想到的是适用于Windows(这大概是),但它的编写自动驾驶仪的互动工具脚本一个伟大的工具。该脚本会去是这样的:

I would write a script to autopilot the debugger. I don't know if expect is available on windows (it probably is), but it's a great tool for writing scripts that autopilot interactive tools. The script would go something like:


#!/usr/bin/expect
set progname [lindex $argv 0]
spawn gdb $progname
expect "(gdb)"
send "break main\n"
expect "(gdb)"
send "run\n"
while 1 {
    expect {
    "(gdb)" {
        send "info locals\n"
        expect "(gdb)"
        send "next\n"
    }
"Program exited normally" {
    exit;
}
}

}

我要改变主到你想程序出错的功能。您还可以插入任何其他调试器命令你想要的,如打印出该行正在打印的变量之前;这里我用信息机打印出所有的本地值。显然,你需要这个输出保存为分析文件。 Expect是pretty易于学习和语法都是基于TCL。

I would change "main" to the function where you think the program goes wrong. You can also insert any other debugger commands you want, such as printing out the line you are on before printing the variables; here i use "info locals" that prints out all local values. Clearly you would need to save this output to a file for analysis. Expect is pretty easy to learn and the syntax is all based on tcl.

这篇关于自动跟踪变化的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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