Debugging COM Clients and Servers Using RPC Debugging

You can use RPC (remote procedure call) debugging to debug COM client/server applications. You must enable RPC debugging if you want to use it.

To enable RPC debugging

  1. From the Tools menu, choose Options.

  2. In the Options dialog box, choose the Debug tab.

  3. Select the Just-in-time debugging check box.

  4. Select the OLE RPC debugging check box.

    Note   With Windows NT, you must have administrator privileges to select the OLE RPC debugging check box.

  5. Choose OK.

RPC debugging works with two types of remote procedure calls:

When the client you are debugging steps into an in-process remote procedure call, the debugger steps into the server code. If the in-process server runs on a different thread, the debugger switches focus to the server thread.

When the client you are debugging steps into an out-of-process remote procedure call, RPC debugging launches (or activates) a second instance of the debugger to handle the COM server you are stepping into. Similarly, when you are debugging a server that returns to the client, RPC debugging launches or activates an instance of the debugger for the client.

In either case (in-process or out-of-process), the debugger opens the source code for the server, if the source code is available. If the source code is not available, the debugger presents the disassembled object code in the Disassembly window.

If you are debugging a server and choose the Step Out command, the debugger returns to the client side. 

Consider the following example. Suppose you have a COM server with an interface like this:

interface ISimpleServer {

   HRESULT Method1(
      IN int   n
      );
};

The client looks like this:

   ISimpleServer*   server = NULL;

   //
   // server = CoCreateInstance (... SIMPLE_SERVER );
   
   hr = server->Method1 (100);
   
   if (FAILED (hr))
   .
   .
   .

And the server looks like this:

HRESULT
CSimpleServer::Method1(
   int   n
   )
{
    char buffer [256];
    
    sprintf (buffer, ""n is %d\n", n);
    OutputDebugString (buffer);
}         

With RPC debugging enabled, you might set a breakpoint on this line from the client application:

   hr = server->Method1 (100);

When the debugger reaches the breakpoint, you can choose Step Into. This command causes the debugger to step into the first line of CSimpleServer::Method1:

    char buffer [256];

If you then choose Step Out, control returns to the client on the next line of code:

   if (FAILED (hr))