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?
(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.
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.
Related
I'm working on a relatively old Centos system where I am restricted in the packages I can install. I needed a newer version of gdb, so I built that successfully from source in my home dir. This gdb steps through my code fine, but I am looking for trouble that is manifesting in the C++ allocator (mt_allocator.cc) and this new version of gdb can't step through that code. I can break successfully on a function there:
break '__gnu_cxx::__pool<true>::_M_initialize()'
but when that breakpoint hits and I try to step through the code, gdb tells me:
Single stepping until exit from function _ZN9__gnu_cxx6__poolILb1EE13_M_initializeEv,
which has no line number information.
I tried using the dir command within gdb to add the path to where mt_allocator.cc is, but that had no effect.
What do I need to tell gdb so it can find those files?
Ah, found it. The Centos package manager put the debug files for the STL code at /usr/lib/debug. So:
set debug-file-directory /usr/lib/debug
within gdb gets it done.
I have a C++ project that is called in Python (via boost-python) and I want to debug the C++ code from python process. How can I do that? In Windows with Visual Studio I can use the functionality attach to process. How to achieve the same in Eclipse?
Thanks
For me it works great just adding a debug configuration in C/C++ for the program /usr/bin/python (or whatever search path you have to the python interpreter) and then put the python program you want to run as the arguments. Put the breakpoints you want in the C-code and you should be all set for running the debug configuration and opening the debug perspective.
If it still does not work you may also check that you are using Legacy (or Standard) Process Launcher. For some reason the GDB process launcher does not seem to work here.
I have a C++ project with a SWIG-generated Python front-end, which I build using CMake. I am now trying to find a convenient way to debug my mixed Python/C++ code. I am able to get a stack-trace of errors using gdb, but I would like to have some more fancy features such as the ability to step through the code and set breakpoints, for example using Eclipse.
Using the Eclipse generator for CMake I am able to generate a project that I am able to import into Eclipse. This works fine and I am also able to step through the pure C++ executables. But then the problem starts.
First of all, I am not able to build the Python front-end from inside Eclipse. From command line I just do "make python", but there is no target "python" in the Eclipse project.
Secondly, once I've compiled the Python front-end, I have no clue how to step through a Python script that contains calls to my wrapped C++ classes. Eclipse has debugging both for Python and for C++, but can they be combined?
some more fancy features such as the ability to step through the code and set breakpoints, for example using Eclipse
how are those features "fancy"? You can already do those in pdb for Python, or gdb for C++.
I'd suggest running the python code with pdb (or using pdb.set_trace() to interrupt execution at an interesting point), and attach gdb to the process in a separate terminal. Use pdb to set breakpoints in, and step through, your Python code. Use gdb to set breakpoints in, and step through, your C++ code. When pdb steps over a native call, gdb will take over. When gdb continue allows Python execution to resume, pdb will take over.
This should let you jump between C++ and Python breakpoints without needing to trace through the interpreter.
Disclaimer: I largely think IDEs are rubbish bloatware, so if Eclipse does have a good way to integrate this, I wouldn't know about it anyway.
I am trying to debug a library for a third party software. I have the source code of the library and I have compiled it using -g. I need to start the software to use the library and debug. AFAIK I have to start the program, then from gdb use attach and the id of the process. I am doing this, but gdb says "Can't attach to process".
Does anyone know why might this be happening?
Try to start it with gdb, just inside, having it attached in the gdb call.
gdb your_program_name
run your_parameter1 your_paremeter2...
Currently the gdb console of Eclipse just connects the stdin/stdout between the java gui and the underlying gdb process, hence many gdb shell features are missing, e.g. tab-autocomplete, command history etc.
I want to know if there is an enhanced console for fast gdb interacting. I really like the frequently used gdb commands like "print" and "call" etc. IMHO, "print" command is superiors sometimes than Eclipse "Expression watcher" because it only execute once and the later will be evaluated any time and be crash-prone.
If you think there is no need to use gdb console, then what's you best-practise in terms of gdb UI to eclipse UI transfer.
There doesn't seem to be any gdb-specific plugin, beside the initial gdb integration initiated with Eclipse3.4.
And the current list of gdb bugs doesn't include your missing features.
If you're writing c/++, why not just find the eclipse-generated elf and use gdb via the shell?