1

I am writing a python program that includes an extension module written in C. The extension module defines a function that is used in my program continually.

I have a memory leak somewhere in my program, but I don't know how to find it. I have tried 1) Installing Valgrind. I can't get this to work however since I have OSX Mavericks (10.9) and Valgrind only supports OXS 10.7 (and 10.8 somewhat unstably). 2) Using gdb. I can't seem to get gdb to run python scripts, as I'd need to set a breakpoint in the c function that gets called from my python code. I believe i need to install python-debuginfo in order to do that, but I have not been able to. 3) Using pdb. I had, however, no idea what to do to debug c code using pdb.

Is there a good tool to use to debug memory leaks in my program?

Faiyam Rahman
  • 305
  • 2
  • 4
  • 8

1 Answers1

0

The debugger that currently ships with the Mac development tools is now lldb, it replaces gdb. The interface is somewhat similar to gdb. You can install gdb using Homebrew.

The way to debug C extensions is just like any other shared library. Debug the executable (python) that loads the shared library (your extension), and set breakpoints that would become valid after the executable loads the shared library.

Run lldb:

lldb /path/to/python -- your_python_script.py

set some breakpoints (replace with your relevant breakpoints)

(lldb) b some_source_file.c:4343

then run, and the debugger will stop at the breakpoint

(lldb) r

now you can debug the C extension normally.

sterin
  • 1,898
  • 15
  • 13