# Debugging in gnuradio

**URL:** <https://www.ruby-forum.com/t/debugging-in-gnuradio/218571>\
**Category:** GNU Radio\
**Created:** [April 4, 2012, 4:08pm UTC](https://www.ruby-forum.com/t/debugging-in-gnuradio/218571 "2012-04-04T16:08:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 4, 2012, 4:08pm UTC](https://www.ruby-forum.com/t/debugging-in-gnuradio/218571/1 "2012-04-04T16:08:49Z")

</div>

Hi,

I am having a hard time with a “segmentation fault” error. I am no  
expert in  
python (I just started to use it last week) but I find it difficult to  
believe that a segmentation fault error would appear in python code.  
However, I am not using any block made by me.

So this is the part of my code where there is an segmentation fault:

def measure\_callback(self,kv):  
print “Measuring!!”  
if self.state==SNR\_MEASURE:  
print “Measuring SNR”  
self.lock()  
self.disconnect((self.gr\_file\_source\_0, 0),  
(self.gr\_throttle\_0,0), self.fft\_sink)  
self.connect((self.gr\_file\_source\_0, 0),  
(self.gr\_complex\_to\_mag\_squared\_0, 0), (self.gr\_moving\_average\_ff\_1, 0),  
(self.gr\_multiply\_const\_ff\_0, 0), self.pwr\_measure)  
self.unlock()  
time.sleep(5)  
snr\_val=10\*math.log(self.pwr\_measure.level())  
print "SNR measured = ", snr\_val  
self.lock()  
self.disconnect((self.gr\_file\_source\_0,  
0),(self.gr\_complex\_to\_mag\_squared\_0, 0), (self.gr\_moving\_average\_ff\_1,  
0),  
(self.gr\_multiply\_const\_ff\_0, 0), self.pwr\_measure)  
self.connect((self.gr\_file\_source\_0, 0),  
self.gr\_throttle\_0,  
self.fft\_sink)  
self.unlock()

So basically I am reading a signal from a file\_source and showing its  
FFT on  
a graphical interface. Then when there is a callback from a button I  
made,  
this measure\_callback(self,kv) is called and I change my circuit to  
measure  
SNR.

I used some prints and discovered that the “segmentation fault” happens  
at  
“time.sleep(5)”. Lol. Furthermore, the error doesn’t happen all the  
times I  
run this code.

Unfortunately, I don’t know any type of debugging programs for gnuradio  
(I  
don’t know if there is one) but it would be very handy because with just  
a  
“Segmentation Fault” message with no traceback it is difficult to know  
what  
to do.

So, any suggestion about what might be causing this problem?

## Francisco

View this message in context:  
[http://old.nabble.com/Debugging-in-gnuradio-tp33557751p33557751.html](http://old.nabble.com/Debugging-in-gnuradio-tp33557751p33557751.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![frankist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e36b37/32.png) [@frankist](https://www.ruby-forum.com/u/frankist)\
**Post date:** [April 5, 2012, 11:12am UTC](https://www.ruby-forum.com/t/debugging-in-gnuradio/218571/2 "2012-04-05T11:12:22Z")

</div>

It seems I found the solution, in spite of not knowing the reason.

I just have to re-assign a new block to each block variable every time I  
re-connect them. It seems that connecting and disconnecting the same  
blocks  
several times was the cause for the segmentation fault.

frankist wrote:

> def measure\_callback(self,kv):  
> time.sleep(5)  
> So basically I am reading a signal from a file\_source and showing its FFT  
> “Segmentation Fault” message with no traceback it is difficult to know  
> what to do.
> 
> So, any suggestion about what might be causing this problem?
> 
> Francisco

–  
View this message in context:  
[http://old.nabble.com/Debugging-in-gnuradio-tp33557751p33568799.html](http://old.nabble.com/Debugging-in-gnuradio-tp33557751p33568799.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![frankist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e36b37/32.png) [@frankist](https://www.ruby-forum.com/u/frankist)\
**Post date:** [April 6, 2012, 12:17am UTC](https://www.ruby-forum.com/t/debugging-in-gnuradio/218571/3 "2012-04-06T00:17:43Z")

</div>

On Thu, Apr 5, 2012 at 5:11 AM, frankist [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> It seems I found the solution, in spite of not knowing the reason.
> 
> I just have to re-assign a new block to each block variable every time I  
> re-connect them. It seems that connecting and disconnecting the same blocks  
> several times was the cause for the segmentation fault.

You shouldn’t have to do that. What version of GNU Radio are you  
using, and are you on a 32-bit platform? This might be related to a  
bug in the disconnect/reconnect calls that was patched recently.

You can use the following link as a guide to debugging segfaults when  
they occur:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/FAQ#How-do-I-debug-GNU-Radio-in-Python](http://gnuradio.org/redmine/projects/gnuradio/wiki/FAQ#How-do-I-debug-GNU-Radio-in-Python)

Tom

---

<div class="post-metadata">

**Author:** ![frankist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e36b37/32.png) [@frankist](https://www.ruby-forum.com/u/frankist)\
**Post date:** [April 10, 2012, 11:39am UTC](https://www.ruby-forum.com/t/debugging-in-gnuradio/218571/4 "2012-04-10T11:39:21Z")

</div>

Hmm… Thanks a lot. I think the problem may be related to the  
connects/disconnects. Even if I am always reconnecting blocks, some  
freezes  
happen sometimes in the disconnect() commands.

Is the patch you are refering to the new gnu version 3.5.3?

Also, I would like to know if there is a better method than the “sleep”  
commands I used for letting the circuit for a short period of time. I  
mean,  
I used a head block to select just a few samples at the end of the  
circuit,  
but if I don’t use the time.sleep(), the python script won’t wait until  
I  
get the number of samples I need. So what I am asking is a type of  
semaphore  
command that lets the python script know when the gnuradio graph has  
already  
finished.

Tom R.-2 wrote:

> > > However, I am not using any block made by me.  
> > > self.connect((self.gr\_file\_source\_0, 0),  
> > > self.connect((self.gr\_file\_source\_0, 0),
> > > 
> > > “Segmentation Fault” message with no traceback it is difficult to know  
> > > Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).  
> > > [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

–  
View this message in context:  
[http://old.nabble.com/Debugging-in-gnuradio-tp33557751p33660247.html](http://old.nabble.com/Debugging-in-gnuradio-tp33557751p33660247.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).
