如何阅读使用gdb局部变量? [英] How to read local variables with gdb?

查看:144
本文介绍了如何阅读使用gdb局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,你可以通过观察一个积极的用gdb从$ EBP抵消找到任何参数:

I know that you can find any parameters by looking at a positive offset from $ebp using gdb:

(gdb) x/4wx $ebp

然后,我会看在第3和第4使用的地址 X / S ,因为它们将是第一个和第二个参数。怎么样局部变量?我怎么会看在值负从$ EBP偏移?
此外,有没有反正看$ EAX的价值?
每当我尝试使用 X / S $ EAX 打印$ EAX的值,地址是出界或值为0,这一点我敢肯定,这不是因为我只是把一个恒定值在寄存器中。

Then, I would look at the 3rd and 4th addresses using x/s because they would be the first and second parameter. What about for local variables? How would I look at the values at a negative offset from $ebp? Also, is there anyway to look at the value of $eax? Whenever I try to print the value of $eax using x/s $eax, the address is out of bound or the value is 0, which I am sure that it is not because I just put a constant value in the register.

我试过信息当地人,但我得到的消息没有可用的符号表信息。

I tried info locals but I get the message "No symbol table info available".

推荐答案

首先,你需要编译符号调试到您的二进制文件。使用GCC的-g选项与当前的命令来做到这一点。如果您使用的是不同的编译器,你需要咨询其文档。在此之后,信息当地人和打印命令将正常工作。

First you need to compile debugging the symbols into your binary. Use the -g option on gcc with your current command to do this. If you're using a different compiler you will need to consult its documentation. After this, 'info locals' and the print command will work.

要查看任何局部变量,所有你需要做的就是使用打印命令。例如看局部变量'我'是为'打印我一样简单。

To look at any local variable all you need to do is use the 'print' command. For example to look at the local variable 'i' it's as easy as 'print i'.

您应该能够处理$ eax中以同样的方式作为$ EBP。我怀疑你有问题,因为你使用X /秒。 X /旨意尝试并打印出一个字符串,因此它会继续下去,直到它碰到一个空字符。如果不这样做很长一段时间那么字符串的长度会出界。尝试'X / D $ EAX。你甚至可以做打印$ EAX。您还可以使用信息登记让所有的寄存器数据。

You should be able to handle $eax in the same way as $ebp. I suspect you have problems because you're using x/s. x/s will try and print out a string, and so it will continue until it hits a null character. If this doesn't happen for a long time then the length of the string will go out of bounds. Try 'x/d $eax'. You can even do 'print $eax'. You can also use 'info registers' to get all the register data.

这篇关于如何阅读使用gdb局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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