|
From: Nicholas N. <nj...@ca...> - 2003-08-11 12:02:45
|
Hi, I've found a problem with Valgrind's handling of quoted command line arguments. It's pretty obscure, I guess that's why nobody's complained before. Compare these two commands, with and without Valgrind: [~/grind/massif] echo "foo -> bar" | sed -e 's/^.* -> /b/' bbar [~/grind/massif] echo "foo -> bar" | valgrind sed -e 's/^.* -> /b/' ==26593== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux. ==26593== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward. ==26593== Using valgrind-20030716, a program supervision framework for x86-linux. ==26593== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward. ==26593== Estimated CPU clock rate is 1404 MHz ==26593== For more details, rerun with: -v ==26593== sed: -e expression #1, char 5: Unterminated `s' command ==26593== ==26593== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ==26593== malloc/free: in use at exit: 4884 bytes in 3 blocks. ==26593== malloc/free: 44 allocs, 41 frees, 9247 bytes allocated. ==26593== For a detailed leak analysis, rerun with: --leak-check=yes ==26593== For counts of detected errors, rerun with: -v The problem is the spaces in the quoted string; the string gets broken up into 3 arguments; this happens in the "valgrind" startup script. I've tried to stop this, fiddling with the quotes, using $* instead of $@, but it's beyond my understanding of shell quoting rules. Does anyone have any suggestions? Thanks. N |
|
From: Tom H. <th...@cy...> - 2003-08-11 12:23:18
|
In message <Pin...@gr...>
Nicholas Nethercote <nj...@ca...> wrote:
> [~/grind/massif] echo "foo -> bar" | valgrind sed -e 's/^.* -> /b/'
[ snipped output ]
> The problem is the spaces in the quoted string; the string gets broken up
> into 3 arguments; this happens in the "valgrind" startup script. I've
> tried to stop this, fiddling with the quotes, using $* instead of $@, but
> it's beyond my understanding of shell quoting rules. Does anyone have any
> suggestions?
It seems to work for me, which is what I would expect as all the
script is doing is shifting the argument list (although not in this
case as there are switches for valgrind) and then using exec "$@"
which is supposed to preserve the existing word boundaries. Here's
the output I get:
audi [~] % echo "foo -> bar" | valgrind sed -e 's/^.* -> /b/'
==25239== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==25239== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==25239== Using valgrind-20030716, a program supervision framework for x86-linux.
==25239== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==25239== Estimated CPU clock rate is 2019 MHz
==25239== For more details, rerun with: -v
==25239==
bbar
==25239== Warning: client attempted to close Valgrind's logfile fd (2).
==25239== Use --logfile-fd=<number> to select an alternative logfile fd.
==25239== discard syms in /usr/lib/locale/locale-archive due to munmap()
==25239==
==25239== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==25239== malloc/free: in use at exit: 13647 bytes in 97 blocks.
==25239== malloc/free: 232 allocs, 135 frees, 85411 bytes allocated.
==25239== For a detailed leak analysis, rerun with: --leak-check=yes
==25239== For counts of detected errors, rerun with: -v
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|
|
From: Nicholas N. <nj...@ca...> - 2003-08-11 13:51:52
|
On 11 Aug 2003, Tom Hughes wrote: > > [~/grind/massif] echo "foo -> bar" | valgrind sed -e 's/^.* -> /b/' > > [ snipped output ] > > > The problem is the spaces in the quoted string; the string gets broken up > > into 3 arguments; this happens in the "valgrind" startup script. I've > > tried to stop this, fiddling with the quotes, using $* instead of $@, but > > it's beyond my understanding of shell quoting rules. Does anyone have any > > suggestions? > > It seems to work for me, which is what I would expect as all the > script is doing is shifting the argument list (although not in this > case as there are switches for valgrind) and then using exec "$@" > which is supposed to preserve the existing word boundaries. You're completely right. My invocation of Valgrind was via a bash function; in that function I was using inappropriate quoting :( Apologies for the distraction, thanks for the correction. N |