|
From: Nicholas N. <nj...@cs...> - 2005-07-27 20:53:02
|
Hi, I just discovered that Valgrind refuses to execute any shell script missing a "#!" line at the start, saying: valgrind: do_exec(./foo) failed: Exec format error It seems that the normal behaviour when executing an executable file with the shell: - if it's an executable, execute natively - if it's a script with a "#!" line, use the named interpreter - else default to interpreting with /bin/sh Valgrind doesn't do that 3rd step. Perhaps it should? N |
|
From: Julian S. <js...@ac...> - 2005-07-27 21:13:02
|
> - if it's an executable, execute natively > - if it's a script with a "#!" line, use the named interpreter > - else default to interpreting with /bin/sh > > Valgrind doesn't do that 3rd step. Perhaps it should? I guess it should, yes. How intrusive a change would it be? J |
|
From: Nicholas N. <nj...@cs...> - 2005-07-27 21:37:29
|
On Wed, 27 Jul 2005, Julian Seward wrote:
>> - if it's an executable, execute natively
>> - if it's a script with a "#!" line, use the named interpreter
>> - else default to interpreting with /bin/sh
>>
>> Valgrind doesn't do that 3rd step. Perhaps it should?
>
> I guess it should, yes. How intrusive a change would it be?
Not very, it's just a few lines in m_ume.c. Below is a preliminary patch
(done with "diff -b", because I had to indent a section of code). I
haven't tested it thoroughly but the cases I tested worked. I don't know
whether defaulting to /bin/sh is Linux-specific, though.
N
*** ../trunk7/coregrind/m_ume.c Mon Jul 18 19:33:34 2005
--- coregrind/m_ume.c Wed Jul 27 16:32:11 2005
***************
*** 581,587 ****
static int match_script(const char *hdr, Int len)
{
! return (len > 2) && memcmp(hdr, "#!", 2) == 0;
}
--- 581,590 ----
+ // If we don't match as ELF, assume it's a script. (If there's not #!
line,
+ // we default to assuming a /bin/sh script.)
static int match_script(const char *hdr, Int len)
{
! //return (len > 2) && memcmp(hdr, "#!", 2) == 0;
! return True;
}
***************
*** 595,598 ****
--- 598,603 ----
int eol;
+ if (hdr[0] == '#' && hdr[1] == '!') {
+
interp = hdr + 2;
while(interp < end && (*interp == ' ' || *interp == '\t'))
***************
*** 635,638 ****
--- 640,649 ----
printf("#! script: interp_name=\"%s\" interp_args=\"%s\"\n",
info->interp_name, info->interp_args);
+
+ } else {
+ interp = "/bin/sh";
+ info->interp_name = interp;
+ info->interp_args = NULL;
+ }
return do_exec_inner(interp, info);
|