Search code examples
pythoncdebugginglibusb

Debug crashing C Library used in Python project


complete Python noob here (and rusty in C).

I am using a Mac with Lion OS. Trying to use NFCpy, which uses USBpy, which uses libUSB. libUSB is crashing due to a null pointer but I have no idea how to debug that since there are so many parts involved.

Right now I am using xcode to view the code highlighted but I run everything from bash. I can switch to Windows or Linux if this is going to be somehow easier with a different environment.

Any suggestions on how to debug this would be much appreciated ;-)

PS: It would be just fine if I could see the prints I put in C in the bash where I run the Python script


Solution

  • You should see your printf() you put in C in your terminal, something is already wrong here. Are you sure that you're using the latest compiled library? To be sure, instead of print, you can use use assert(0) (you need to include assert.h).

    Anyway, you can debug your software using gdb:

    gdb --args python yourfile.py
    
    # type "run" to start the program
    # if you put assert() in your code, gdb will stop at the assert, or you can put 
    # manual breakpoint by using "b filename:lineno" before "run"