4

Say I am in IPython (e.g. on the new QT console), and that I call a C++ library that I wrote from it (e.g. using SWIG or Boost.Python). I would like to set a breakpoint in my C++ code and have the ability to interact with my C++ workspace (i.e. my variables when I hit the breakpoint) with IPython (e.g. plot my C++ variables, etc.).

In other words I would like to debug my C++ code from IPython. Is this at all possible? What are some tools I can use for this?

1
  • 1
    Have you tried the new python extensions in gdb 7? I know they're not IPython, but you can do quite a lot with them. This article is just one of many examples of how to use it. misspent.wordpress.com/2012/03/24/… Commented Jul 22, 2012 at 6:26

2 Answers 2

3

(assuming you are on Linux) You just need gdb. First set up configuration telling gdb where your source files are by adding this to $HOME/.gdbinit: directory absolute-path-to-source

Now start gdb python and on the gdb prompt do: set args /usr/bin/ipython run

You can't directly do gdb ipython because ipython is a script. Please refer to the gdb documentation from here on.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't get an IPython prompt this way, I only see IPython 5.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. but no prompt, no console echo :-( (this is with lldb, but still...)
It works with Python 2.7.13 / IPython 3.2.2 on OpenSuSE Leap 42. I didn't test it with other versions sorry.
0

In general, you won't be able to debug C++ code directly with IPython. What you can do, though, is use a C++ debugger to debug your C++ code.

Essentially, you tell your C++ debugger to execute whatever process you need to use to run your code (this could be IPython itself), and set a breakpoint in your C++ code (your debugger will know to wait for the appropriate DLL to be loaded if it's in a DLL). From there, you are debugging your part of the code that is running in the IPython process.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.