|
From: | Robert E. Griffith |
Subject: | Re: using valgrind on a loadable builtin |
Date: | Thu, 26 May 2022 13:41:13 -0400 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 |
I rebuilt bash to use glibc's malloc. Passing --without-bash-malloc to configure did not seem to work for me -- maybe I misunderstood where to use it. I edited the configure script manually to change...
$ grep "^opt_bash_malloc=" configure opt_bash_malloc=no # changed yes to no $ ./configure; make clean; make CFLAGS="-g -O0"Confirmed that worked by observing 'objdump -t bash | grep malloc' before contained sh_malloc and after did not (amung others)
For some reason I dont understand, running "valgrind bash -c "myscript.sh"' valgrind would only print its starting comments and nothing else. Maybe because myscript.sh was crashing?
What worked was this... $ valgrind --log-file=valgrind.log --leak-check=full ../../bashParse/bash # your options and path to bash may vary (new bash prompt)$ echo $$ <thePID> (new bash prompt)$ source myscript.sh (new bash prompt)$ exit # only if myscript.sh did not end the bash process $ grep <thePID> valgrind.log valgrind.log.myscriptvalgrind.log contained a lot of information about each subshell bash created along the way so that is why I filtered for the top level bash pid.
Once I got this working, valgrind made it clear where the bug was (I had accidentally misplaced the +1 for the terminator in the expression -- malloc(strlen(s1)+strlen(s2+1))
--BobG On 5/25/22 21:52, Robert E. Griffith wrote:
Oh! That makes sense now. Thanks. I was inspecting the memory and was confused that it did not seem to use the same chunk structure of the glibc malloc.--BobG On 5/25/22 18:19, Eduardo Bustamante wrote:On Wed, May 25, 2022 at 10:44 AM Robert E. Griffith <bobg@junga.com> wrote:I am trying to to use valgrind memcheck on my loadable builtin which is getting a "corrupted size vs. prev_size" error but its output is suspiciously clean and when I use the -v (verbose) switch I do not see any msg about my builtin's .so being loaded even though I do seeconfirmation that the builtin gets loaded and ran in the output. So Isuspect that it is not monitoring my .so. I am running it like... valgrind -v ../../bashParse/bash -c 'bg-dev tests run bg_objects.sh:' The script enables my builtin. bash and my builtin are being built with -g and no -O<n>Anyone have any tips on getting meaningful output from valgrind for aloadable builtin?Bash provides its own (lib/malloc/) malloc implementation. When building bash, you can provide --without-bash-malloc to the configure script to instead link against the libc malloc. You can search for see opt_bash_malloc in "configure", or the USING_BASH_MALLOC macro.You can review these files to see how it's all hooked up: builtins.h, general.h, xmalloc.hValgrind is not capable of tracing the malloc that Bash provides.
[Prev in Thread] | Current Thread | [Next in Thread] |