Working directory

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Working directory

Mark Chimley
Folks,

This is hopefully a question with an easy answer. I've got a program
which seems to cause heap corruption so I thought valgrind would be able
to tell me where this occurs. The trouble is the program uses data files
from the running directory for configuration purposes and running the
program under valgrind seems to prevent it finding these data files. I
therefore cannot reproduce the conditions which cause the problem.

I've looked in the manual, help and FAQs for how to set the working
directory but I cannot find anything related to this. I feel I must be
missing something quite obvious as this would appear to be quite a
fundamental issue.

--
Mark
****
Triathlete, climber, and mediocre pianist
 - aspiring to be just a little bit better than last year
---
Co-founder of Woodland Friends: www.woodlandfriends.co.uk
 - replanting native British woodland for the benefit of communities and
wildlife


------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Reply | Threaded
Open this post in threaded view
|

Re: Working directory

Dallman, John-2
> I've got a program which seems to cause heap corruption so I thought valgrind would be
> able to tell me where this occurs. The trouble is the program uses data files from the
> running directory for configuration purposes and running the program under valgrind
> seems to prevent it finding these data files. I therefore cannot reproduce the
> conditions which cause the problem.

How are you launching your program? The way I do it is to set up a working directory with
the files I need in it, and run the program without Valgrind to verify that it's all set up.

For example, I have kid.out as the executable. with lipsini.lsp as its startup commands.

        ls shows me:
        kid.out lispini.lsp
        kid.out runs it.

Then I just run

        /usr/local/bin/valgrind kid.out

and that runs kid.out under Valgrind with the directory I was in as the current directory.

--
John Dallman


-----------------
Siemens Industry Software Limited is a limited company registered in England and Wales.
Registered number: 3476850.
Registered office: Faraday House, Sir William Siemens Square, Frimley, Surrey, GU16 8QD.

------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Reply | Threaded
Open this post in threaded view
|

Re: Working directory

Philippe Waroquiers
In reply to this post by Mark Chimley
On Thu, 2015-09-10 at 09:40 +0100, Mark Chimley wrote:

> Folks,
>
> This is hopefully a question with an easy answer. I've got a program
> which seems to cause heap corruption so I thought valgrind would be able
> to tell me where this occurs. The trouble is the program uses data files
> from the running directory for configuration purposes and running the
> program under valgrind seems to prevent it finding these data files. I
> therefore cannot reproduce the conditions which cause the problem.
>
> I've looked in the manual, help and FAQs for how to set the working
> directory but I cannot find anything related to this. I feel I must be
> missing something quite obvious as this would appear to be quite a
> fundamental issue.
>
For sure, if valgrind would fiddle with the working directory,
then a lot of things would not work properly.
As an example, doing
   valgrind pwd
properly shows the current working directory where you launch valgrind.

So, something else must happen.

What you could do is to run your application with
   valgrind --trace-syscalls=yes ....
and see e.g. which open syscall is unexpectedly failing.

Alternatively, start your application with valgrind+vgdb,
and put breakpoints at the relevant places to see why the
required files are not being opened.
(see
http://www.valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver
for more info about debugging your application running under valgrind).


Philippe




------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Reply | Threaded
Open this post in threaded view
|

Re: Working directory

Mark Chimley
Valgrind Users,

Many thanks to Philippe and John for helping me out with this. As
rightly pointed out, valgrind shouldn't and doesn't alter the working
directory so it was, indeed, something else preventing access to the
data files. By using valgrind + vgdb I stepped through the code and
found that the config file wasn't being opened because the code uses the
process name to determine what 'conf' file to open. Clearly, under
valgrind (default) the process name is not the program name and is in
fact memcheck-x86-li.

Having sorted the above issue valgrind successfully determined where the
heap corruption was occurring - a silly coding error in the test harness.

Regards,

Mark
****
Triathlete, climber, and mediocre pianist
 - aspiring to be just a little bit better than last year
---
Co-founder of Woodland Friends: www.woodlandfriends.co.uk
 - replanting native British woodland for the benefit of communities and
wildlife


On 10/09/15 21:36, Philippe Waroquiers wrote:

> On Thu, 2015-09-10 at 09:40 +0100, Mark Chimley wrote:
>> Folks,
>>
>> This is hopefully a question with an easy answer. I've got a program
>> which seems to cause heap corruption so I thought valgrind would be able
>> to tell me where this occurs. The trouble is the program uses data files
>> from the running directory for configuration purposes and running the
>> program under valgrind seems to prevent it finding these data files. I
>> therefore cannot reproduce the conditions which cause the problem.
>>
>> I've looked in the manual, help and FAQs for how to set the working
>> directory but I cannot find anything related to this. I feel I must be
>> missing something quite obvious as this would appear to be quite a
>> fundamental issue.
>>
> For sure, if valgrind would fiddle with the working directory,
> then a lot of things would not work properly.
> As an example, doing
>    valgrind pwd
> properly shows the current working directory where you launch valgrind.
>
> So, something else must happen.
>
> What you could do is to run your application with
>    valgrind --trace-syscalls=yes ....
> and see e.g. which open syscall is unexpectedly failing.
>
> Alternatively, start your application with valgrind+vgdb,
> and put breakpoints at the relevant places to see why the
> required files are not being opened.
> (see
> http://www.valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver
> for more info about debugging your application running under valgrind).
>
>
> Philippe
>
>
>
>

------------------------------------------------------------------------------
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users