GDB Debugger Commands with Example Code

Run Sanfoundry’s sample source file gfile.c and do the following under GDB control:

    1. Set breakpoint at main()
    2. Run the program now (it should stop at main)
    3. Single step once
    4. Show the content of gfile.c
    5. Show the content of main() function
    6. Show stack frames
    7. Show stack frames and local variables in each frames
    8. Show local variables for main
    9. Show value of lvar and change it to 4
    10. Show global variables
    11. Show values of global variables
    12. Show arguments to the program
    13. Show process map
    14. Show registers
    15. Show assembly level instructions for main()
    16. show 10 instructions at the current instruction pointer
    17. Show all threads
    18. Print the address of gvar variable
    19. Dump/print 10 bytes at a specified address (take address of gvar)
    20. set breakpoint at sum
    21. run the program now (it should stop at sum)
    22. Single step once
    23. Show local variables of sum()
    24. Show local variables of main()
    25. Single step
    26. Step over the next line (it will not enter function)
    27. Execute the next assembly instruction
    28. Continue to execute the program till the end

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.