GDB Python

Techtutorsti
2 min readDec 29, 2023

--

GDB (GNU Debugger) is a powerful tool for debugging programs, including those written in Python. It allows you to see what is happening inside a program while it executes or what the program was doing when it crashed.

Here’s a brief guide on how to use GDB with Python:

  1. Compile Python with Debugging Symbols: To use GDB effectively with Python, you should have a version of Python compiled with debugging symbols. This often means you need to compile Python from the source with the appropriate flags.
  2. Starting GDB: You start GDB with the command gdb python. This starts GDB and attaches it to the Python interpreter.
  3. Running a Python Script: To run a Python script, use the run command in GDB, followed by the script name and any arguments it requires.
  4. Setting Breakpoints: You can set breakpoints in your Python code to pause execution and inspect the program’s state. For example, b myscript.py:10 sets a breakpoint at line 10 of myscript.py.
  5. Inspecting State: When your program hits a breakpoint, you can inspect the state of your program using various GDB commands. For example, print variable_name will print the value of a variable.
  6. Continuing Execution: To continue the program’s execution after hitting a breakpoint, use the continue command.
  7. Python-Specific Commands: GDB has some Python-specific commands when used with Python. For example, a py-list can list the Python source code, and py-up and py-down can navigate the stack.
  8. Exiting GDB: You can exit GDB by typing quit.

Remember that debugging Python scripts with GDB can be more complex than debugging C/C++ programs, as Python is a high-level, interpreted language. It may require a deeper understanding of Python’s internals, especially when dealing with Python-specific data structures or runtime environments.

Our Python Demo Session:

You can find more information about Python at this https://unogeeks.com/python-training/

UnoGeeks is the №1 Training Institute for Python. Anyone Disagree? Please drop in a comment.

You can check out our Python class details here

Top Python Online Training |UNOGEEKS

You can check out our Python blogs here

Python Archives — UnoGeeks

Follow and connect with us:

— — — — — — — — — — — -

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Please mail us at info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks

--

--