Attaching the debugger to a already running process
The Clarion debugger has the ability to be installed as the system debugger. When an application GPF's the user normally has the option to close the application or debug it using the system debugger. The OS runs the debugger with specific command-line switches which tells the debugger which process to debug.
One of the side affects of the this is that you have the ability to connect the debugger to an already running application even if it hasn't GPF'ed.
Assume for the moment that you are attempting to reproduce a GPF that needs a a particularly complicated set to steps to re-create. Normally you would have to run the application under the debugger, then set a breakpoint somewhere and tell the debugger to go until it hits the breakpoint.
Now you can run the application and only attach the debugger to the process when you get near the point where the problem occurs. To do this you need to run the debugger with the command line of "CxDBX -P yyyy" where "x" is normally the version of Clarion you are using and "yyyy" is the decimal process ID of the process you want to attach to.
For example, if Notepad is running as process ID 492 and I wanted to use the Clarion 5.5 debugger I would type :
C55DBX -P 492
Once the debugger has opened you can look in the "Trace" window and make sure that everything worked OK. One thing to confuse you is that the debugger shows the process ID it is connecting to in hexadecimal (0x1EC). In the screenshot below you can clearly see the debugger being notified as all the DLL's that Notepad relies on are being loaded. Depending on which debugger you have you may, or may not, see the DLL name - prior to C5.5 the debugger only shows the load address. With 5.5 it shows the name from the 'Exports' section of the PE file.

The only thing you may be left wondering is "How do I get the process ID of the application in the first place?"
The answer to that question is easily answered if you are running Windows NT or Windows 2000 - simply get the (decimal) process ID from the Task Manager.
If you are running Windows 95,. Windows 98 or Windows ME then you need an application which can show you the currently running processes. There are lots of freeware and shareware programs that do this, including PVIEW that ships with the Platform SDK and the source code that came with my "Enumerating Running Processes" article
Alternatively, you could make a call to the Win32 API GetCurrentProcessID() and simply display the process ID using the Clarion MESSAGE() statement.
Back to the home page