Jeroen Wiert Pluimers
Jeroen Wiert Pluimers

Reputation: 24483

Switching JIT debuggers?

When you have to maintain different projects with different IDEs, it often makes sense to install them on the same Windows machine.

For instance, mix Visual Studio and Delphi, or various versions of Delphi on the same system (I'm sure others have even different combinations).

One of the things you will find there is that the latest tool installs itself as JIT debugger: the just-in-time debugger that fires when an app crashes.

Depending in which tool and version that app crashed (sometimes you cannot reproduce bugs when running inside the debugger, for instance in case of a Heisenbug), you want to select the debugger in advance.

How can you do that?

Upvotes: 5

Views: 2770

Answers (3)

Sertac Akyuz
Sertac Akyuz

Reputation: 54802

Write a simple application that would launch the debugger you want in case of an application crash.

Register your app in

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug

In case of an 64bit OS, also to the following key

HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug

add/modify the string named Debugger with value:

"C:..\Win32\Debug\Project1.exe" %ld %ld
 

A very simple application:

procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.Items.Add('BDS 16');
  ComboBox1.Items.Add('BDS 15');
  ComboBox1.Items.Add('WinDbg');
  ComboBox1.Items.Add('VS');
  // etc..
  ComboBox1.ItemIndex := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  proc: THandle;
begin
  Assert(ParamCount >= 2);
  proc := OpenProcess(SYNCHRONIZE, False, StrToInt(ParamStr(1)));
  case ComboBox1.ItemIndex of
    0: ShellExecute(0, '', 'C:\..\RAD Studio\9.0\bin\bds.exe',
          PChar(Format('/attach:%s;%s', [ParamStr(1), ParamStr(2)])), '',
          SW_SHOWNORMAL);
    1 : // etc..
    2: ShellExecute(0, '', 'C:\Program Files (x86)\..\windbg.exe',
          PChar(Format('-p %s -e %s -g', [ParamStr(1), ParamStr(2)])), '',
          SW_SHOWNORMAL);
    3: ShellExecute(0, '', 'C:\Windows\system32\VSJitDebugger.exe',
          PChar(Format('-p %s -e %s', [ParamStr(1), ParamStr(2)])), '',
          SW_SHOWNORMAL);
    //..
  end;
  if Bool(proc) then begin
    WaitForSingleObject(proc, INFINITE);
    Application.Terminate;
  end;
end;

Upvotes: 7

Lex Li
Lex Li

Reputation: 63173

If you search Microsoft documentation, you can see that postmortem debugging can be controlled via registry key under \HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug

http://msdn.microsoft.com/en-us/library/windows/hardware/ff542967(v=vs.85).aspx

You need to pay special attention if you want to manually change it.

Upvotes: 2

Arioch 'The
Arioch 'The

Reputation: 16045

I think if you really need to debug several concurrently running applications made with different tools - then the only option for you is to find or create a bridge JIT debugger, the one that would analyze which project crashed and relay the control to a corresponded IDE debugger

Upvotes: 1

Related Questions