user2994338
user2994338

Reputation:

Program is unable to read local file when being debugged by WinDbg

I'm debugging test.exe which reads a file "data.txt" that is present in the same directory as that of the exe. The program works fine when run directly. But when being debugged under winDBG, the CreateFile WinAPI in the code fails with err#2 (Unable to find file). I saw a related thread about a similar issue when debugging with VS - there the solution was to place the data file along with the source/headers. That solves the VS issue, but does not help this WinDBG issue.

Has anyone faced this issue before? Please let me know if you are aware of a solution.

Upvotes: 0

Views: 317

Answers (1)

Lex Li
Lex Li

Reputation: 63264

If you use relative file paths, then the working directory of your process will affect how they are converted to absolute paths.

When test.exe is launched in Windows Explorer, its working directory is the folder that contains it. In that case the data file in the same folder can be found correctly.

When you use WinDbg to launch test.exe, unless you explicitly set working directory to the one you want, WinDbg will use its own folder. No doubt that leads to the issue you meet.

http://en.wikipedia.org/wiki/Working_directory

Upvotes: 5

Related Questions