I've got a Perl script (running on Xubuntu Lucid Lynx within VirtualBox) that wraps around several C/C++ binaries feeding the inputs of one into the others. One of the lines consists of generally:
my $ret_code=`cat $input | c_binary`;
my $ret_val= $?;
For some input files the code causes a coredump, but both $ret_val
and $ret_code
are 0 and "" respectively. I can see the errors scrolling by when I run it, but I seem to have no way of "capturing" this programmatically. How could I do this? The intent is to on error remove some lines from the input and retry the parsing.
Here are the errors:
*** stack smashing detected ***: code/parser terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x50)[0x798390]
/lib/tls/i686/cmov/libc.so.6(+0xe233a)[0x79833a]
code/parser[0x804edd8]
[0x2e303039]
======= Memory map: ========
0043b000-0043c000 r-xp 00000000 00:00 0 [vdso]
0045a000-00475000 r-xp 00000000 08:01 11041 /lib/ld-2.11.1.so
00475000-00476000 r--p 0001a000 08:01 11041 /lib/ld-2.11.1.so
00476000-00477000 rw-p 0001b000 08:01 11041 /lib/ld-2.11.1.so
006b6000-00809000 r-xp 00000000 08:01 10897 /lib/tls/i686/cmov/libc-2.11.1.so
00809000-0080a000 ---p 00153000 08:01 10897 /lib/tls/i686/cmov/libc-2.11.1.so
0080a000-0080c000 r--p 00153000 08:01 10897 /lib/tls/i686/cmov/libc-2.11.1.so
0080c000-0080d000 rw-p 00155000 08:01 10897 /lib/tls/i686/cmov/libc-2.11.1.so
0080d000-00810000 rw-p 00000000 00:00 0
008ba000-008d7000 r-xp 00000000 08:01 8268 /lib/libgcc_s.so.1
008d7000-008d8000 r--p 0001c000 08:01 8268 /lib/libgcc_s.so.1
008d8000-008d9000 rw-p 0001d000 08:01 8268 /lib/libgcc_s.so.1
00c89000-00cad000 r-xp 00000000 08:01 10901 /lib/tls/i686/cmov/libm-2.11.1.so
00cad000-00cae000 r--p 00023000 08:01 10901 /lib/tls/i686/cmov/libm-2.11.1.so
00cae000-00caf000 rw-p 00024000 08:01 10901 /lib/tls/i686/cmov/libm-2.11.1.so
08048000-08055000 r-xp 00000000 08:01 407893 /home/abugorsk/Documents/code/stepbystep/collins-parser/code/parser
08055000-08056000 r--p 0000c000 08:01 407893 /home/abugorsk/Documents/code/stepbystep/collins-parser/code/parser
08056000-08057000 rw-p 0000d000 08:01 407893 /home/abugorsk/Documents/code/stepbystep/collins-parser/code/parser
08057000-0c50f000 rw-p 00000000 00:00 0
0e168000-0fa57000 rw-p 00000000 00:00 0 [heap]
b44a3000-b77c9000 rw-p 00000000 00:00 0
b77da000-b77dc000 rw-p 00000000 00:00 0
bff2b000-bff40000 rw-p 00000000 00:00 0 [stack]
Aborted
The values returned are:
LOG: Parser return code: 0
LOG: Parser return value:
The actual code snippet in question:
my $command = "cd $STEPBYSTEP_HOME/collins-parser; cat models/model$model_num/events | code/parser $src models/model$model_num/grammar 10000 1 1 1 1 1> $dest 2> $parse_log";
llog "Executing command: $command";
my $ret_code = $?;
llog "Parser return code: $ret_code";
my $ret_val = `$command`;