Screen Swap Setting Crucial to Debugging PM Apps with Children

ID Number: Q50514

2.20 2.35 3.00 3.10 3.11 3.12 3.50

OS/2

Summary:

Using protected-mode CodeView (CVP) to debug Presentation Manager (PM)

programs that spawn one or more child processes can be difficult. CVP

works correctly for debugging just the parent PM process, but once you

begin CodeView with the /O option to specify that you also want to

debug child processes, you may find that you regularly hang the

computer during your debugging session.

CodeView does not have a problem with PM programs even if they invoke

child processes. However, when you use the /O switch to debug the

children at the same time, you will run into difficulty. This is

because of problems with CodeView conflicting with the OS/2 kernel as

you bring a process to the foreground for debugging, while a

system-dependent process like the PM parent is relegated to the

background where it can become blocked.

For example, if the parent gets to a point where it is waiting on a

message, but it is not in the foreground, there is no way to get the

focus back to this waiting process and you are essentially hung. The

parent cannot process the message because it must be in the foreground

to do so, and CodeView cannot continue until the message is processed,

so it just waits.

The key to debugging the parent and child processes of a PM program at

the same time is the setting of Screen Swap on the Options menu (or

Flip/Swap in CodeView 2.x). Under CodeView, Screen Swap ON forces

messaging, Screen Swap OFF does not. Therefore, you must turn Screen

Swap on and off as you go, depending on which particular part of the

program you are currently debugging. The Screen Swap setting is

crucial in determining whether you hang the system or not.

More Information:

The ability to debug child processes from the parent's CodeView

session became an available option beginning with CVP version 2.3. By

specifying the /O switch on the command line, CVP allows you to trace

into child processes. (See the CVP 2.3/2.35 note below if you are

using that particular version of CodeView.)

Regarding debugging child processes in PM programs, you must proceed

in an exacting manner. Unfortunately, the specifics are different for

every program, so an all-encompassing set of debugging procedures

cannot be devised. Nevertheless, the following general guidelines can

be used for debugging most PM applications with their accompanying

child processes:

1. This becomes critical only with the /O option.

2. You need to debug in a full screen and not a PM window.

3. Remember, Screen Swap ON forces messaging, Screen Swap OFF does

not. Therefore, while you begin debugging in the parent program,

you should have Screen Swap ON, since you need messaging whenever

you are doing any of the window initialization routines.

4. Set a breakpoint in the parent somewhere after the window

initialization code, but before the call to start the child

process. It usually works to put the breakpoint at the "while get

message - dispatch message" loop or in the ClientWndProc procedure

at the main switch statement.

5. You must make sure that the breakpoint is placed in a position

where you will stop at it before the prompt appears to ask you if

you want to debug the child, but after ALL the window

initialization has been completed. You will also probably need to

set another breakpoint at the point where the parent program is

going to begin executing again after you have finished working

with the child.

6. Do a GO, and when the breakpoint is reached, turn Screen Swap OFF.

Make sure that the prompt to debug the child is not already

visible or you will lock up.

7. Do a GO (or some traces) and you should get the prompt to debug

the child. Answer "Y" and you should be able to debug the child

process at this point.

8. Use the Process command (the "|") or the Process option on the Run

menu to gain access to the child. Never use CTRL+ESC or ALT+ESC to

switch to the other processes because these will probably cause

you to hang.

9. Go ahead and set breakpoints, watches, and so on, in the child and

do your debugging.

10. After the child process is completed, use the Quit command to exit

the child process's CodeView screen or use the Process command to

reselect the parent process.

11. Once you have returned to the parent process, and before you do a

Restart (or load), or before you do ANY other window

initialization, you MUST turn Screen Swap ON again.

12. Remember to always be aware of where you are in the program and

what the current state of Screen Swap is, since turning Screen

Swap on or off at the wrong time will almost always cause you to

hang.

Again, this is only the general outline of steps to follow and each

application requires different specific steps. Don't be too surprised

if you still run into occasional lock-ups.

CVP 2.3/2.35 Note: When using the /O switch with these versions of

CVP, there is a bug that may also cause you to hang. The problem

involves using /O on the command line and then saying "No" when asked

if you want to debug the child. So, with this version of CodeView, you

should always answer "Yes" when asked if you want to debug the child.

For more information on this problem, use the following query:

CodeView 2.30 hangs debugging child processes