假設返回值爲而不是分配給變量,是否可以檢查gdb函數的返回值?如何檢查GDB中函數的返回值?
80
A
回答
92
我想有更好的方法來做到這一點,但finish命令執行到當前堆棧幀被彈出並打印返回值 - 定的程序
int fun() {
return 42;
}
int main(int argc, char *v[]) {
fun();
return 0;
}
可以調試它是這樣 -
(gdb) r
Starting program: /usr/home/hark/a.out
Breakpoint 1, fun() at test.c:2
2 return 42;
(gdb) finish
Run till exit from #0 fun() at test.c:2
main() at test.c:7
7 return 0;
Value returned is $1 = 42
(gdb)
37
是的,只需通過輸入print $eax
來檢查EAX
寄存器。對於大多數函數,返回值都存儲在該寄存器中,即使它沒有被使用。
該例外的是返回類型大於32位,特別是64位整數(long long
),double
s和structs
或classes
功能。
另一個例外是如果您沒有在英特爾架構上運行。在這種情況下,你必須找出使用哪個寄存器(如果有的話)。
7
下面是沒有符號的待辦事項。
gdb ls
This GDB was configured as "ppc64-yellowdog-linux-gnu"...
(no debugging symbols found)
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) break __libc_start_main
Breakpoint 1 at 0x10013cb0
(gdb) r
Starting program: /bin/ls
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
Breakpoint 1 at 0xfdfed3c
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread 4160418656 (LWP 10650)]
(no debugging symbols found)
(no debugging symbols found)
[Switching to Thread 4160418656 (LWP 10650)]
Breakpoint 1, 0x0fdfed3c in __libc_start_main() from /lib/libc.so.6
(gdb) info frame
Stack level 0, frame at 0xffd719a0:
pc = 0xfdfed3c in __libc_start_main; saved pc 0x0
called by frame at 0x0
Arglist at 0xffd71970, args:
Locals at 0xffd71970, Previous frame's sp is 0xffd719a0
Saved registers:
r24 at 0xffd71980, r25 at 0xffd71984, r26 at 0xffd71988, r27 at 0xffd7198c,
r28 at 0xffd71990, r29 at 0xffd71994, r30 at 0xffd71998, r31 at 0xffd7199c,
pc at 0xffd719a4, lr at 0xffd719a4
(gdb) frame 0
#0 0x0fdfed3c in __libc_start_main() from /lib/libc.so.6
(gdb) info fr
Stack level 0, frame at 0xffd719a0:
pc = 0xfdfed3c in __libc_start_main; saved pc 0x0
called by frame at 0x0
Arglist at 0xffd71970, args:
Locals at 0xffd71970, Previous frame's sp is 0xffd719a0
Saved registers:
r24 at 0xffd71980, r25 at 0xffd71984, r26 at 0xffd71988, r27 at 0xffd7198c,
r28 at 0xffd71990, r29 at 0xffd71994, r30 at 0xffd71998, r31 at 0xffd7199c,
pc at 0xffd719a4, lr at 0xffd719a4
格式化有點搞砸了那裏,注意使用「信息框」檢查框,「幀#」的導航您的上下文到另一個上下文(上下堆疊)
還有Bt show是一個縮略的堆棧來幫助你。
相關問題
- 1. 檢查宏中函數的返回值
- 2. 如何檢查函數指針在dlsym中的返回值?
- 3. 如何檢查函數的返回值如果爲真或假
- 4. 檢查沒有返回語句的函數的返回值
- 5. 如何檢查DWScript FileCreate函數的返回值?
- 6. GDB:函數返回後中斷
- 7. 如何通過遞歸函數檢查並返回一對值?
- 8. 如何根據函數返回值檢查單選按鈕?
- 9. 如何返回函數中的Ajax值?
- 10. 如何檢查UIAlertView的返回值?
- 11. 如何快速從Object.keys函數返回的MapIterator中檢索值?
- 12. 如何檢查JavaScript中返回的函數?
- 13. 如何檢查Python中的函數返回?
- 14. 檢查返回值++
- 15. 檢查值是否在MATLAB函數的返回值
- 16. 宏來檢查,如果一個函數的返回值被檢查
- 17. 用gdb檢查的sprintf()函數步步
- 18. 如何在PL/SQL Developer中輕鬆檢查函數的返回值。
- 19. 如何使用OCMock檢查函數在單元測試中的返回值3
- 20. 如何從函數中返回值?
- 21. 如何從jQuery函數中返回值?
- 22. 在Matlab中查找函數返回值
- 23. 如何檢查多個返回值
- 24. 如何檢查UuidCreate()返回值?
- 25. 如何從函數中的select查詢返回int值?
- 26. 如何從SP返回的函數中返回值?
- 27. 如何從回調函數返回值
- 28. 檢查函數是否使用回調或返回值
- 29. 檢查返回false的數組的值?
- 30. 如何在Scala中檢查特定函數是否返回空?
不使用英特爾機器,運行在sparc上。 g0是存儲返回值的地方,但我想要獨立於架構的東西.. – fuad 2008-11-06 05:08:37
感謝您的澄清;我假設你使用的是x86。但除非你將跨多種體系結構編寫GDB腳本,否則我不認爲不使用「print $ g0」這個沒有任何副作用的好理由(與其他答案不同)。 – 2008-11-06 05:11:43