[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] debugging C code called from python

From: Martin Dvh
Subject: Re: [Discuss-gnuradio] debugging C code called from python
Date: Tue, 09 Aug 2005 16:47:32 +0200
User-agent: Debian Thunderbird 1.0.2 (X11/20050331)

Hi Andrew,
Hi, what is the best way to debug C++ code called
from python? Is it possible to use gdb? Or is the
idea to get everything working through test-cases
first & hence avoid the issue?
from the how-to-write-a-block documentation/wiki
Debugging with gdb

If your block isn't working, and you can't sort it out through python test cases or a few printfs in the code, you may want to use gdb to debug it. The trick of course is that all of GNU Radio, including your new block, is dynamically loaded into python for execution.

Try this: In your python test code, after the relevant imports, print out the process id and wait for a keystroke. In another window run gdb and tell it to attach to the python process with the given process id. At this point you can set breakpoints or whatever in your code. Go back to the python window and hit Enter so it'll continue.

  #!/usr/bin/env python
  from gnuradio import gr
  from gnuradio import my_buggy_module

  # insert this in your test code...
  import os
  print 'Blocked waiting for GDB attach (pid = %d)' % (os.getpid(),)
  raw_input ('Press Enter to continue: ')
  # remainder of your test code follows...

Another SNAFU you might run into is that gdb 6.2 isn't able to set breakpoints in the constructors or destructors generated by g++ 3.4. In this case, insert a call to the nop function gri_debugger_hook in the constructor and recompile. Load the code as before and set a break point on gri_debugger_hook.

This even works on windows although you have to use the cygwin version of gdb 
(or insight)
The cygwin gdb also works with the version of gnuradio built with mingw.
(the mingw gdb doesn't seem to work for me)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]