Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function allows a debugger to attach to an active process and then debug it.

Syntax

BOOL DebugActiveProcess( 
  DWORD 
dwProcessId 
);

Parameters

dwProcessId

[in] Identifier for the process to be debugged.

The debugger gets debugging access to the process in the same way it would if it created the process with the DEBUG_ONLY_THIS_PROCESS flag.

For more information, see Remarks.

Return Value

Nonzero indicates success. Zero indicates failure.

To get extended error information, call GetLastError.

Remarks

The DebugActiveProcessfunction and the CreateProcessfunction enable a debugger thread to create a process and attach to the process or attach to an existing process and debug it. These functions should:

  1. Stop all the threads within the process given by dwProcessId.

  2. Create read and write ends of the message queue in both the debugger and the debuggee processes.

  3. Create a thread to write the current state of the application: creating a process, loading modules, creating debug events, and so on.

  4. Return to the debugger.

  5. When these functions return, the debugger thread needs to call the WaitForDebugEventfunction to start processing all the debug events from the target process.

After a successful return from DebugActiveProcess, when the debugger is waiting for debug events using the WaitForDebugEventfunction, the system sends a CREATE_PROCESS_DEBUG_EVENT debugging event that identifies the primary thread handle that is currently part of the process.

The system sends an individual CREATE_THREAD_DEBUG_EVENT debugging event for each secondary thread handle that is currently part of the process.

These handles have permission, or access rights, to receive and set thread contexts using the GetThreadContextand SetThreadContextfunctions.

For both the CREATE_PROCESS_DEBUG_EVENT and CREATE_THREAD_DEBUG_EVENT debugging events, the lpStartAddressmember of the CREATE_PROCESS_DEBUG_INFOstructure is NULL.

Close these thread handles using the CloseHandlefunction.

No initial debug breakpoint is set when DebugActiveProcessattaches.

Windows CE 2.0 and later provide built in support for just-in-time (JIT) debugging. Keep the following in mind about JIT debugging:

  • You can register a JIT debugger by placing the name of your debugger in the string registry value JITDebuggerat HKEY_LOCAL_MACHINE\Debug.

  • To enable JIT debugging, you must perform a warm boot on the Windows Embedded CE target platform after the JITDebuggervalue is added to the registry.

  • When your debugger is invoked by JIT debugging, the identifier of the process being debugged is passed on the command line.

The Windows Embedded CE JIT debugger is a second-chance exception handler. The debugger must have appropriate access to the target process; it must be able to open the process for PROCESS_ALL_ACCESS access.

  • On Windows Embedded CE, the debugger has appropriate access if the process identifier is valid. After the system checks the process identifier and determines that a valid debugging attachment is being made, the function returns TRUE. The debugger is then expected to wait for debugging events by using the WaitForDebugEventfunction. The system suspends all threads in the process and sends the debugger events representing the current state of the process.

  • For each DLL loaded into the address space of the target process, the system sends a LOAD_DLL_DEBUG_EVENT debugging event. The system arranges for the first thread in the process to execute a breakpoint instruction after it resumes. Continuing this thread causes it to return to whatever it was doing before the debugger was attached. After these tasks are completed, the system resumes all threads in the process.

  • When the first thread in the process resumes, it executes a breakpoint instruction that causes an EXCEPTION_DEBUG_EVENT debugging event to be sent to the debugger.

  • All future debugging events are sent to the debugger by using the normal mechanism and rules.

    Note:
    To use JIT debugging, you must set the following registry value.
    Copy Code
    [HKEY_LOCAL_MACHINE\Debug]
    "JITDebugger": REG_SZ
    

Requirements

Header winbase.h
Library coredll.lib, Nk.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also