简体   繁体   English

如果我有一个C函数并且我用gdb调试它,我如何找到函数的返回值?

[英]If I have a C function and I'm debugging it with gdb, how do I find the return value of a function?

我有一个作业,要求我找到主要的寄存器检查的返回值(我们正在学习gdb),我将如何去做呢?

In general, look at the calling convention. 一般来说,查看调用约定。

In x86, all calling conventions return small integer results on EAX, and large (64-bit) results on EDX:EAX (EDX holding the higher bits), and floating point results in FP0. 在x86中,所有调用约定在EAX上返回小整数结果,在EDX上返回大(64位)结果:EAX(EDX保持较高位),浮点结果为FP0。

In x64, small integer results are returned on RAX, and floating point results in FP0. 在x64中,RAX返回小整数结果,浮点结果为FP0。

In ARM (including thumb-mode), integer results are returned in R0. 在ARM(包括拇指模式)中,整数结果在R0中返回。

If you're trying to work out where to put your breakpoint, my suggestion is to put a breakpoint at the start of the main function. 如果你想找出断点的位置,我的建议是在函数的开头加一个断点。 If you do that, the return address (ie where main will return to once it is finished executing) will be the value on the top of the stack. 如果这样做,返回地址(即main将在完成执行后返回的位置)将是堆栈顶部的值。 If you put a breakpoint there, you'll break just after the main function has finished executing. 如果你在那里放置一个断点,你将在main函数完成执行后立即中断。

Since main has the return type of int , you can look at EAX (or RAX or R0) to see what value main returned. 由于main的返回类型为int ,因此您可以查看EAX(或RAX或R0)以查看main返回的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM