Python and C++ applications

The challenge – Debugging Python and C/C++ applications

on Jun 15, 17 • by Jasmit Singh • with No Comments

Developers rely on debuggers and dynamic analysis tools to understand how their program runs, but understanding the calls across language barriers creates a challenging debugging situation...

Home » Dynamic analysis » The challenge – Debugging Python and C/C++ applications

Many institutes and companies use Python as part of their development cycle. Whether pursuing speed, efficiency, or leveraging existing legacy code, developers often need to create interactions between Python and C/C++. This leads to the complexity of debugging mixed language applications.

During the development process of either extending or embedding Python, developers rely on debuggers and dynamic analysis tools to understand how their program runs, but understanding the calls across language barriers and the flow of data between them creates a challenging debugging situation.

A Python process may crash, hang, or simply produce incorrect results after calling native libraries or vice versa. These types of bugs are difficult to debug within Python itself and a developer may decide to use a C/C++ debugger. Since Python is an interpreted language, a typical debugger can only debug the interpreter instance and examine the process at the interpreter level. The result is a complicated stack trace which includes low-level details of functions and variables of Python interpreter. Here is a sample of the stack trace:

Sample of the stack trace

To properly diagnose a problem in the Python code, developers need to see details at an application level where their Python function names and variables are available in the call stack.

Existing debuggers

Python programmers have many choices to diagnose bugs in their Python code. Python is shipped with pdb and provides an interactive source code debugging. PyDev IDE for Eclipse and Spyder provide strong environments for debugging Python. However, few debuggers provide a seamless solution for mixed language debugging.

Download this white paper for further details and analysis of debugging Python and C/C++ in Eclipse.

Solution: CodeDynamics and TotalView for HPC

Developers require tools that allow them to view unified call stacks for Python and C++, set breakpoints, and step between Python and C/C++ code, and simultaneously inspect data in Python and C/C++.

The CodeDynamics and TotalView provide a very easy workflow for establishing your Python and C/C++ debugging session. Setting a breakpoint in your C/C++ code is straightforward and when hit an integrated Python and C/C++ stack trace is presented. The “glue” code and Python interpreter level frames are stripped away, leaving the call flow the developer expects. It is easy for developers to drag Python and C/C++ variables into the Data View and examine their values, making sure that the data has crossed the language barriers correctly. This, coupled with its advanced C/C++ debugging capabilities, such as reverse debugging, make it a solid solution for debugging the execution paths and data exchanges between Python and C/C++. As the industry use of Python continues grow and build more complex applications tools like these will also need to advance to provide the debugging capabilities required by the developers.

Download this white paper for further details on Mixed-language debugging with Python and C++.
Examine the Python and C/C++ variables across language barriers to ensure data integrity.

Examine the Python and C/C++ variables across language barriers to ensure data integrity.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top