Step from pdb in gdb when debugging c extension
Asked Answered
P

0

6

I'm developing a C(++) extension for python. I have a library in C that I wrap using Swig. Unfortunately I have some error that I would like to debug that is within the C extension. My program makes heavy use of MsgBuffer class which I send over a serial connection. All the messages may contain multiple parts. If I add a MsgPart to a MsgBuffer, then the msg should make a copy of the message, but currently it looks like I'm adding a reference, because once I modify the part, add the modified part, the initial part looks like it is modified as well.

So What I would like to do is set a breakpoint in my python program and step through the debugger.

pin = 12  # Pin 12 on Teensy3.2
pullup = False  # No need for enabling pull up resistor.
msg = MsgBuffer(TEENSY_REQ_INPUT_PIN)
part= MsgPart()
part.write_uint32(pin)
msg.add_part(part)
part.write_uint32(1 if pullup else 0)
msg.add_part(part) # I would like to set a breakpoint here in order to see whether it is added as reference or it is copied in the c extension
self._serial.write_msg(msg)

I would like to step from python's debugger into a C debugger. How I now currently do this is to put a input('press enter') and attach a C debugger to the process, but I find this inconvenient. I would like to step into the extension from python, is this possible?

Panathenaea answered 22/8, 2019 at 15:17 Comment(3)
That would be convenient. I usually set breakpoints in the C code and attach the C debugger - there is no need to modify any code with inputs.Curtcurtail
It can be configured and done using eclipse, pdb and gdb. On Windows, it is a little simpler, learn.microsoft.com/en-us/visualstudio/python/…. What platform are you usingCurtcurtail
@JensMunk Currently i'm using Ubuntu-18.04 linux, I'm targeting windows as well, but this is coming at a later state (although I'm feeling a bit sorry now if that is much easier). I'm using IntelliJ clion (for c(++) extensions) and can use pycharm to remain in the 'IntelliJ envrironment. Generally, my scripts terminate before i've got time to attach the debugger, hence the input.Panathenaea

© 2022 - 2024 — McMap. All rights reserved.