code_junkie

Inspect the return value of a function in gdb

Nov 12th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. int fun() {
  2. return 42;
  3. }
  4.  
  5. int main( int argc, char *v[] ) {
  6. fun();
  7. return 0;
  8. }
  9.  
  10. (gdb) r
  11. Starting program: /usr/home/hark/a.out
  12.  
  13. Breakpoint 1, fun () at test.c:2
  14. 2 return 42;
  15. (gdb) finish
  16. Run till exit from #0 fun () at test.c:2
  17. main () at test.c:7
  18. 7 return 0;
  19. Value returned is $1 = 42
  20. (gdb)
  21.  
  22. gdb ls
  23. This GDB was configured as "ppc64-yellowdog-linux-gnu"...
  24. (no debugging symbols found)
  25. Using host libthread_db library "/lib64/libthread_db.so.1".
  26.  
  27. (gdb) break __libc_start_main
  28. Breakpoint 1 at 0x10013cb0
  29. (gdb) r
  30. Starting program: /bin/ls
  31. (no debugging symbols found)
  32. (no debugging symbols found)
  33. (no debugging symbols found)
  34. (no debugging symbols found)
  35. (no debugging symbols found)
  36. (no debugging symbols found)
  37. Breakpoint 1 at 0xfdfed3c
  38. (no debugging symbols found)
  39. [Thread debugging using libthread_db enabled]
  40. [New Thread 4160418656 (LWP 10650)]
  41. (no debugging symbols found)
  42. (no debugging symbols found)
  43. [Switching to Thread 4160418656 (LWP 10650)]
  44.  
  45. Breakpoint 1, 0x0fdfed3c in __libc_start_main () from /lib/libc.so.6
  46. (gdb) info frame
  47. Stack level 0, frame at 0xffd719a0:
  48. pc = 0xfdfed3c in __libc_start_main; saved pc 0x0
  49. called by frame at 0x0
  50. Arglist at 0xffd71970, args:
  51. Locals at 0xffd71970, Previous frame's sp is 0xffd719a0
  52. Saved registers:
  53. r24 at 0xffd71980, r25 at 0xffd71984, r26 at 0xffd71988, r27 at 0xffd7198c,
  54. r28 at 0xffd71990, r29 at 0xffd71994, r30 at 0xffd71998, r31 at 0xffd7199c,
  55. pc at 0xffd719a4, lr at 0xffd719a4
  56. (gdb) frame 0
  57. #0 0x0fdfed3c in __libc_start_main () from /lib/libc.so.6
  58. (gdb) info fr
  59. Stack level 0, frame at 0xffd719a0:
  60. pc = 0xfdfed3c in __libc_start_main; saved pc 0x0
  61. called by frame at 0x0
  62. Arglist at 0xffd71970, args:
  63. Locals at 0xffd71970, Previous frame's sp is 0xffd719a0
  64. Saved registers:
  65. r24 at 0xffd71980, r25 at 0xffd71984, r26 at 0xffd71988, r27 at 0xffd7198c,
  66. r28 at 0xffd71990, r29 at 0xffd71994, r30 at 0xffd71998, r31 at 0xffd7199c,
  67. pc at 0xffd719a4, lr at 0xffd719a4
Add Comment
Please, Sign In to add comment