Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debug question 2

Status
Not open for further replies.

Malachi

Programmer
Aug 13, 2001
38
US
I have a Workspace located in a root directory, with numerous child directories. Within each child directory is a VC++ project that compiles and creates an executable or library within each respective child directory.

Here is an illustration of the directory structure:

[COLOR=yellow black][tt](Parent Directory)[/tt][/color]
[COLOR=yellow black][tt]ChildDirectory1[/tt][/color]
[COLOR=yellow black][tt]Project01[/tt][/color]
[COLOR=yellow black][tt]File01.EXE[/tt][/color]
[COLOR=yellow black][tt]ChildDirectory2[/tt][/color]
[COLOR=yellow black][tt]Project02[/tt][/color]
[COLOR=yellow black][tt]File01.LIB[/tt][/color]
[COLOR=yellow black][tt]ChildDirectory3[/tt][/color]
[COLOR=yellow black][tt]Project03[/tt][/color]
[COLOR=yellow black][tt]File02.EXE[/tt][/color]


I use a third party installation utility to gather up the necessary binaries and supporting files from the project directories and elsewhere to build a setup program that can be used to install the final program.

Generally, each module can be built and debugged separately, so I'm usually hand copying only one file from the project directory to my application directory for testing purposes. However, I now have a bug that seems to be a memory issue. The source of the problem is very difficult to determine by reading the code. I would like to use the Studio debugger this time. Unfortunately, when I try to run the debugger through the VC++ IDE, my program complains about missing DLL's and special support files.

I have a running instance of my completed program on the C:\MYPROG directory. I have changed the "Working Directory" in the onfiguration settings for "Win32 Debug" to point to my program directory "C:\MYPROG". I would like to compile my projects and test the application within the IDE. Is this possible without a drastic change to my project hierarchy?

Thank you in advance
 
Yes, it should be. What I have done in the past is created one workspace and included all the .dsp files in it. What I would suggest for you would be to

1. Make a copy of your current root directory and rename it to MyProg2

2. Load up the main project workspace.

3. On the file view tab, right click the "Workspace" at the top and insert projects into your workspace. (just browse to the dsp projects)

From the sounds of it, you may already have this configuration.

Then, modify the "General" settings for each project. The intermediate files can output to Debug or Release but all the output files should go to one centralized location (I use ..\Debug and ..\Release because it saves time if I do a copy and paste and the path is hard coded)

Now, with all the necessary projects in your workspace, go to the project dependencies and have your main project be dependent on all the ones it needs.

Make sure the output folder is empty
Do a rebuild all

You should see all the files end up in the specified output directory. (Your main project may not need the ..\ in its output path depending on your hierarchy)

You should be able to execute the application upon completion of compilation.

Matt

P.S. Please note that if you have renamed the output file, the renaming on the general tab may not take effect.
 
It looks like I'm getting more than I bargained for now. I have now changed each Debug project's "Output Files" path to C:\MYPROGRAM (no file renaming is necessary). For each output file, there are two additional files with extension .ilk and .pdb. What are these? Is there a way to avoid this?

 
.ilk is a temporary file used in incremental linking, you can safely delete it.

.pdb contains debug info and is quite handy if you want to, well, debug.

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
Ok, via the IDE Workspace Window I have selected the Main program's project (File01.exe)and, after right-clicking the project name, chosen "Set as active Project" from the context menu.

The project name is now marked in bold text. I now press the "Ctrl+F5" combination on the keyboard to execute the program. I get an error that indicates a dependant file (depend.ini) is missing. depend.ini must be a sibling to File01.exe.

I have double-checked to ensure that the depend.ini file is in the same directory as the File01.exe, the file privileges are correct, and that the File01.exe is the debug version compiled by my projects. Why is this executable complaining about the missing initialization file?
 
Ok, now the files are built in the C:\MYPROGRAM Directory, and I no longer get the error message about the missing .ini file. I set a breakpoint in the File02.c source at a function definition. File01.exe, calls File02.exe via a WinExec() call. When I execute my main program by pressing F5 I get an error message:

"One or more breakpoints cannot be set and have been disabled. Execution will stop at the beginning of the program."

I click the OK button and the statement pointer (a yellow arrow) is located at the WinMain function of File01.exe. I'm really trying to debug something in File02.exe. So, press the "step out" button, which lets my main program run. However, I'm unable to put a breakpoint or watch on any of the File02.c source code, whereas I can place a breakpoint or watch in the File01.c source code.

File02.exe cannot execute without being called by File01.exe because some parameters are passed between the two executables. How can I set a breakpoint or watch in the File02.c code in the Debugger window?
 
Set the project which creates the file02.exe program as the active project. In the project settings, Debug tab, put "file01.exe" as the executable for the debug session. That's how I debug my dlls, I hope this will work for your case too.

Good luck,

Vincent
 
Thank you for the response. I changed the "File02" Project Settings "Executable for debug session:" to [COLOR=black white]C:\MYPROGRAM\FILE01.EXE[/color] and the "Working Directory:" is set to [COLOR=black white]C:\MYPROGRAM[/color]. After these changes I set a breakpoint in the File02.c source code and pressed the "F5" key to debug the project.

I still get the error: [COLOR=black gray]One or more breakpoints cannot be set and have been disabled. Execution will stop at the beginning of the program[/color]

Next, I restored the "Executable for debug session:" back to [COLOR=black white]C:\MYPROGRAM\FILE02.EXE[/color] and then added an entry to the "Remote executable path and file name:" of [COLOR=black white]C:\MYPROGRAM\FILE01.EXE[/color]. Pressing "F5" to Debug the program causes "FILE02.EXE" to execute (which will not run unless called by FILE01.EXE).

Thank you for all of your input. Any other suggestions to help?
 
file02.exe runs in a totally separate process. You can't use 1 debugger to debug 2 processes at the same time.

Start a new visual studio.
When file01.exe has started file02.exe use the new visual studio like this:
Menu->Build->Start Debug->Attach to Process...
Select the file02.exe process.
When it has loaded you can set breakpoint and whatever.

I don't think you actually can debug the starting up of file02.exe since its beyond you control (its WinExec that does it). But you can debug it when its started...






/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
Microsoft Knowledge Base Article - 121556 has some interesting information. The section "Can't set breakpoint in source file when corresponding symbolic information isn't loaded into memory by debugger." has helped me avoid the error " One or more breakpoints cannot be set and have been disabled. Execution will stop at the beginning of the program".

I opened the Project Settings for "File01" and selected the Debug tab. Then, I dropped down the Category list and chose "Additional DLLs". Then, I clicked the Local Name list field, changed the file type to "All Files" and browsed to the "File02.EXE" located in "C:\MYPROGRAM". Clicking the Open button, and then the OK button saved the Module to the File01.EXE project. Apparently, all of the projects in the workspace now include this module too.

I set my breakpoint in the "File02.c" source, set the "File01" project as the Active project, and then pressed the "F5" key. Surprisingly, "File01.EXE" executed, and I could then call "File02.EXE". However, at the point where I expected the breakpoint to stop the process, it didn't. I am also unable to set watches in either the File01 or File02 sources during debugging. Does anyone know what I might have done to prevent me from adding watches or the breakpoint from being respected?
 
Thank you Zyrenthian and PerFnurt. I had changed the project settings Debug Working directory to C:\MYPROGRAM", and then changed the General Output Files directory to "C:\MYPROGRAM", and then invoked "File01.EXE". When "File01.EXE" was running I called "File02.EXE" from within "File01.EXE" and attached to the process using PerFnurt's suggested menu path.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top