Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 625
Jeroen Wiert Pluimers Avatar asked Oct 05 '12 07:10

Jeroen Wiert Pluimers


2 Answers

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;
like image 161
Sertac Akyuz Avatar answered Nov 18 '22 12:11

Sertac Akyuz


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.

like image 2
Lex Li Avatar answered Nov 18 '22 12:11

Lex Li