[C++-sig] Re: debuging

Greg Burley burley at tabq.com.au
Wed Nov 20 02:15:40 CET 2002


Hi Mike,

What's wrong with using gdb and stepping through your code.  See notes
that follow ...


Debugging BPL Extensions
========================

Once you have created a boost python extension for your c++ library or
class, you may need to debug the code.  Afterall this is one of the
reasons for wrapping the library in python. An expected side-effect or
benefit of using BPL is that debugging should be isolated to the c++
library that is under test, given that python code is minimal and
boost::python either works or it doesn't. (ie. While errors can occur
when the wrapping method is invalid, most errors are caught by the
compiler ;-).

The basic steps required to initiate a gdb session to debug a c++
library via python are shown here. Note, however that you should start
the gdb session in the directory that contains your BPL my_ext.so
module. 

      (gdb) target exec python
      (gdb) run
       >>> from my_ext import *
       >>> [C-c]
      (gdb) break MyClass::MyBuggyFunction
      (gdb) cont
       >>> pyobj = MyClass()
       >>> pyobj.MyBuggyFunction()
      Breakpoint 1, MyClass::MyBuggyFunction ...
      Current language:  auto; currently c++
      (gdb) do debugging stuff

hope this helps,
greg


"Mike Rovner" <mike at bindkey.com> writes:

> "Bjorn Pettersen" <BPettersen at NAREX.com> wrote in message
> 
> > I just got 'TypeError: bad argument type for built-in
> > operation' and have absolutely no idea what to do next.
> 
> Sounds like you need to get the traceback... Here's how I do it (you'll
> probably want to modify it to throw a more standard exception ;-)
> 
> -- bjorn
> 
> Thank you for the code.
> Apparently I'm still sleepy 'cause I don't know how to use it.
> 
> Let me start from the beginning:
> 
> I wrapped cpp class and instantiated it from python.
> When I tried it's method I got:
> >>> import My
> >>> a=My.Obj('a')
> >>> a
> <My.Obj object at 0x999999>    # faked
> >>> a.name
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: bad argument type for built-in operation
> 
> I certainly would like to have cpp traceback through BPL library code (I'm
> using debug version) but I don't know how.
> I feel like having a key to the chamber with gold but see no lock around,
> only walls. ;)
> Please guide me a couple steps further.
> 
> Mike
> 
> 
> 
> 
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list