Trellis_encoder_bb segfaults when inside hier_block

Hi,

I’ve been playing around with the gr-trellis stuff, mainly to figure out
how it works. My first step was to build a conv. coder/decoder.
When I figured out how that works, I wanted to pack everything into a
hierarchical block which handles all the configuration of the FSM etc.
However, it seems that trellis_encoder_bb (which I was using) does not
like to live inside a hier_block: Upon destruction of the hier_block, it
always segfaults. I don’t get this behaviour with other blocks.

Here’s the guts of my code:

chancoding_industrystd_encoder_bb::chancoding_industrystd_encoder_bb ()
: gr_hier_block2 (“industrystd_encoder_bb”,
gr_make_io_signature (1, 1, sizeof(char)),
gr_make_io_signature (1, 1, sizeof(char)))
{
trellis_encoder_bb_sptr encoder =
trellis_encoder_bb_sptrllis_make_encoder_bb(fsm(1, 2, make_G()), 0);
connect(self(), 0, encoder, 0);
connect(encoder, 0, self(), 0);
}

There’s nothing else in the hier_block. I’ve also tried making the
encoder an attribute of my class, to no avail.

This simple test case is enough to create a segfault:

void
qa_industrystd_bb::t1()
{
chancoding_industrystd_encoder_bb_sptr
encoder(chancoding_make_industrystd_encoder_bb());
}

The segfault is thrown whenever everything is destroyed (not, however,
during execution of the destructor). For the C++ QA test code above, the
segfaults occurs right at the end, i.e. after test_all finishes.
When I try it through SWIG, it also segfaults, but I haven’t exactly
pinpointed where.

Here’s a backtrace of a segfault as seen from gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00a1f532 in main_arena () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt
#0 0x00a1f532 in main_arena () from /lib/tls/i686/cmov/libc.so.6
#1 0x0038c2e8 in checked_delete<gr_hier_block2> (this=0x8050570) at
/usr/include/boost/checked_delete.hpp:34
#2 boost::detail::sp_counted_impl_p<gr_hier_block2>::dispose
(this=0x8050570) at /usr/include/boost/detail/sp_counted_impl.hpp:78
#3 0x0038c3c5 in boost::detail::sp_counted_base::release
(this=0x3fcc4c, __x=0x8050588) at
/usr/include/boost/detail/sp_counted_base_gcc_x86.hpp:145
#4 ~shared_count (this=0x3fcc4c, __x=0x8050588) at
/usr/include/boost/detail/shared_count.hpp:216
#5 ~shared_ptr (this=0x3fcc4c, __x=0x8050588) at
/usr/include/boost/shared_ptr.hpp:165
#6 ~pair (this=0x3fcc4c, __x=0x8050588) at
/usr/include/c++/4.4/bits/stl_pair.h:68
#7 __gnu_cxx::new_allocator<std::pair<gr_basic_block* const,
boost::shared_ptr<gr_basic_block> > >::destroy (this=0x3fcc4c,
__x=0x8050588)
at /usr/include/c++/4.4/ext/new_allocator.h:115
#8 std::_Rb_tree<gr_basic_block*, std::pair<gr_basic_block* const,
boost::shared_ptr<gr_basic_block> >,
std::_Select1st<std::pair<gr_basic_block* const,
boost::shared_ptr<gr_basic_block> > >, std::less<gr_basic_block*>,
std::allocator<std::pair<gr_basic_block* const,
boost::shared_ptr<gr_basic_block> > > >::_M_destroy_node (this=0x3fcc4c,
__x=0x8050588)
at /usr/include/c++/4.4/bits/stl_tree.h:383
#9 std::_Rb_tree<gr_basic_block*, std::pair<gr_basic_block* const,
boost::shared_ptr<gr_basic_block> >,
std::_Select1st<std::pair<gr_basic_block* const,
boost::shared_ptr<gr_basic_block> > >, std::less<gr_basic_block*>,
std::allocator<std::pair<gr_basic_block* const,
boost::shared_ptr<gr_basic_block> > > >::_M_erase (this=0x3fcc4c,
__x=0x8050588)
at /usr/include/c++/4.4/bits/stl_tree.h:972
#10 0x0038c424 in ~_Rb_tree (this=0x3fcc4c, __in_chrg=) at /usr/include/c++/4.4/bits/stl_tree.h:614
#11 ~map (this=0x3fcc4c, __in_chrg=) at
/usr/include/c++/4.4/bits/stl_map.h:87
#12 0x0090c428 in __cxa_finalize (d=0x3fc260) at cxa_finalize.c:56
#13 0x00293ae4 in __do_global_dtors_aux () from
/usr/local/lib/libgnuradio-core-3.3.1git.so.0
#14 0x00399450 in _fini () from
/usr/local/lib/libgnuradio-core-3.3.1git.so.0
#15 0x0011df46 in _dl_fini () at dl-fini.c:248
#16 0x0090c05f in __run_exit_handlers (status=0, listp=0xa1e304,
run_list_atexit=true) at exit.c:78
#17 0x0090c0cf in *__GI_exit (status=0) at exit.c:100
#18 0x008f3b5e in __libc_start_main (main=0x8049d10 , argc=1,
ubp_av=0xbfffee54, init=0x804ab20 <__libc_csu_init>, fini=0x804ab10
<__libc_csu_fini>,
rtld_fini=0x11dd20 <_dl_fini>, stack_end=0xbfffee4c) at
libc-start.c:252
#19 0x08049c71 in _start () at …/sysdeps/i386/elf/start.S:119

Does anyone have an idea why this happens? Is this a user-generated
error, or is it a bug? I was using the latest trunk for this stuff.

Any help is highly appreciated,
Martin


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-3790
Fax: +49 721 608-6071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

Sorry for the double-post, we were having problems with our SMTP today.

On Mon, Aug 02, 2010 at 02:54:48PM +0200, Martin B. wrote:

chancoding_industrystd_encoder_bb::chancoding_industrystd_encoder_bb ()
: gr_hier_block2 (“industrystd_encoder_bb”,
gr_make_io_signature (1, 1, sizeof(char)),
gr_make_io_signature (1, 1, sizeof(char)))
{
trellis_encoder_bb_sptr encoder = trellis_encoder_bb_sptrllis_make_encoder_bb(fsm(1, 2, make_G()), 0);

This was a typo due to pasting into the email window.
make_G() returns a generator matrix, just in case someone wonders.

Besides, I just figured out that the same happens when I use an FIR
filter instead.
Here’s how I create segfaults every time:

  • create a hier_block in C++
  • internally connect an FIR filter (e.g. fir_filter_fff)
  • do anything with that block.

Looks like this has nothing to do with gr-trellis. If this looks like a
bug to any of the devs and not like a mistake on my end, I’ll rig up a
test case for downloading if necessary.

MB


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-3790
Fax: +49 721 608-6071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

On Mon, Aug 02, 2010 at 06:00:10PM +0200, Martin B. wrote:

This was a typo due to pasting into the email window.
Looks like this has nothing to do with gr-trellis. If this looks like a
bug to any of the devs and not like a mistake on my end, I’ll rig up a
test case for downloading if necessary.

Not sure if it’s a bug or not.
Please cook up a small test case that shows the problem.

Thanks!
Eric

On Tue, Aug 03, 2010 at 09:49:30AM +0200, Martin B. wrote:

trellis_encoder_bb_sptr encoder = trellis_encoder_bb_sptrllis_make_encoder_bb(fsm(1, 2, make_G()), 0);

./bootstrap && ./configure && make check
segfaults every time.
I tried it on two machines (32- and 64-Bit Ubuntus), with different GNU
Radio versions (precisely: 3.2.2 and current trunk) and different gcc’s
(4.4.1 and 4.4.3).

Thanks,
MB

Thanks. It crashes for me too :slight_smile:

On Mon, Aug 02, 2010 at 02:07:38PM -0700, Eric B. wrote:

Looks like this has nothing to do with gr-trellis. If this looks like a
bug to any of the devs and not like a mistake on my end, I’ll rig up a
test case for downloading if necessary.

Not sure if it’s a bug or not.
Please cook up a small test case that shows the problem.

Hi Eric,

I’ve created a small out-of-tree module available at
http://mbant.de/testcrash.tar.gz.

./bootstrap && ./configure && make check
segfaults every time.
I tried it on two machines (32- and 64-Bit Ubuntus), with different GNU
Radio versions (precisely: 3.2.2 and current trunk) and different gcc’s
(4.4.1 and 4.4.3).

Thanks,
MB


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-3790
Fax: +49 721 608-6071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

On Tue, Aug 03, 2010 at 02:02:28PM -0700, Eric B. wrote:

All block factories should always use gnuradio::get_initial_sptr instead
of instantiating the shared pointer directly. For blocks that derive
from gr_block, the old way works OK, but when applied to blocks that
derive from gr_hier_block2 problems occur :slight_smile:

The fix I committed changes all the block factories to use
gnuradio::get_initial_sptr.

Thanks for the great test case!

Thank you for the great fix :slight_smile:

Cheers,
MB


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-3790
Fax: +49 721 608-6071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

On Tue, Aug 03, 2010 at 09:49:30AM +0200, Martin B. wrote:

trellis_encoder_bb_sptr encoder = trellis_encoder_bb_sptrllis_make_encoder_bb(fsm(1, 2, make_G()), 0);

./bootstrap && ./configure && make check
segfaults every time.
I tried it on two machines (32- and 64-Bit Ubuntus), with different GNU
Radio versions (precisely: 3.2.2 and current trunk) and different gcc’s
(4.4.1 and 4.4.3).

Thanks,
MB

I’ve found and fixed the problem on the maint branch.
Johnathan will propagate the changes to master and next when he gets a
chance.

Here’s the fix for the test case:

diff -r -u testcrash/lib/testcrash_hierblock.cc
testcrash.new/lib/testcrash_hierblock.cc
— testcrash/lib/testcrash_hierblock.cc 2010-08-03 00:37:14.000000000
-0700
+++ testcrash.new/lib/testcrash_hierblock.cc 2010-08-03
12:31:03.576077097 -0700
@@ -32,7 +32,7 @@
testcrash_hierblock_sptr
testcrash_make_hierblock ()
{

  • return testcrash_hierblock_sptr (new testcrash_hierblock ());
  • return gnuradio::get_initial_sptr (new testcrash_hierblock ());
    }

All block factories should always use gnuradio::get_initial_sptr instead
of instantiating the shared pointer directly. For blocks that derive
from gr_block, the old way works OK, but when applied to blocks that
derive from gr_hier_block2 problems occur :slight_smile:

The fix I committed changes all the block factories to use
gnuradio::get_initial_sptr.

Thanks for the great test case!

Eric