top of page

Debugging in Visual Studio

(alle Versionen/all versions)

Sonntag, 28. Februar 2021

Deutsch

Debugger Startmöglichkeiten bei laufenden Prozessen

Standard Just-In-Time (JIT) - Debugger von Windows

Auswertung von Expressions ohne Seiteneffekte im Debugger Direktfenster (Immediate Window)


English

Debugger launch options for running processes

Standard Just-In-Time (JIT) - Debugger of Windows

Evaluation of expressions without side effects in the debugger immediate window (Immediate Window)



Deutsch


Debugger Startmöglichkeiten bei laufenden Prozessen

Dies ist insbesondere bei Anwendungen wie Sage ERP sinnvoll, die über mehrere Prozesse skalieren (u.a. Sage Applikationsserver) und es zur Laufzeit nicht deterministisch ist, welcher Prozess ausgewählt wird, um den eigenen Quellcode auszuführen.


Über "Attach Process" in Visual Studio direkt an mehrere Prozesse hängen

Man kann sich in der Entwicklungsumgebung "Visual Studio" auch direkt an mehrere laufende Prozesse auf einmal hängen:

ree

Tipp: Zusatztools wie https://oz-code.com/ erlauben teilweise zusätzlich "Quick Attachments", um den Debugger noch schneller erneut an Prozesse anzufügen.


Direkt im laufenden Code den Debugger auslösen

#if DEBUG
  System.Diagnostics.Debugger.Launch();
#endif

Zur Laufzeit stellt sich das Ganze teilweise als "Exception" dar; das Debuggen muss explizit bestätigt werden.

ree

Tipp: Man sollte vorher das Visual Studio-Projekt in Visual Studio bereits geöffnet haben, so dass man sich direkt an den laufenden Visual Studio-Prozess anhängen kann.

Ansonsten kann es je nach Anwendung, für die man den Debugger benötigt, aufgrund der zusätzlichen Zeit zum Laden von Visual Studio zu Timeouts in der Anwendung kommen!


Standard Just-In-Time (JIT) - Debugger von Windows

Das JIT-Debuggen von Windows ist ein nützliches Feature, um zur Laufzeit Programmabläufe sinnvoll debuggen zu können.

Grundsätzlich kann jeder .net-compatible Debugger eingesetzt werden.

Windows erkennt über nachfolgenden Registry-Schlüssel, welches Programm als JIT-Debugger verwendet werden soll.

32-Bit:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

Für 64-Bit OS müssen auch nachfolgende Schlüssel beachtet werden:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

Für Visual Studio sieht der Registry-Eintrag üblicherweise wie folgt aus (32Bit/64Bit identisch):

"C:\Windows\system32\vsjitdebugger.exe" -p %ld -e %ld

Weitere Details: MSDN Hinweise zum JIT-Debugger


Auswertung von Expressions ohne Seiteneffekte im Debugger Direktfenster (Immediate Window)


Im Debugger-Direktfenster (Debug → Windows → Immediate Window) kann man Werte auch so auswerten, ohne dass Nebeneffekte auf den laufenden Code entstehen.

Dazu gibt man als Ergänzung bei Abfragen an:

, nse

Hier eine Beispielklasse, um den Effekt zu verdeutlichen:

ree











Wenn "Foo" im "Immediate Window" ausgewertet wird, erhöht sich die Anzahl und der Inhalt der Variable wird verändert:

ree












Wir können hier sehen, dass die Anzahl von 1 auf 2 gestiegen ist.

Durch Hinzufügen von ", nse" (No Side Effects) zum Ausdruck wird der Ausdruck ausgewertet, ohne den Anwendungsstatus zu ändern.

ree












English


Debugger launch options for running processes

This is particularly useful for applications such as Sage ERP, which scale across multiple processes (e.g. Sage application server), and it is not deterministic at runtime, which process is selected to run your own source code.


Attach directly to multiple processes via "Attach Process" in Visual Studio

In the "Visual Studio" development environment, you can also attach directly to several running processes at once:

ree

Tip: Additional tools such as https://oz-code.com/ sometimes also allow "quick attachments" to attach the debugger to processes even faster.


Trigger the debugger directly in the running code

#if DEBUG
  System.Diagnostics.Debugger.Launch();
#endif

At runtime, the whole thing is partly presented as an "Exception"; debugging must be explicitly confirmed.

ree

Tip: You should have previously opened the Visual Studio project in Visual Studio so that you can attach it directly to the running Visual Studio process.

Otherwise, depending on the application you need the debugger for, the application may time out due to the extra time it takes to load Visual Studio!


Standard Just-In-Time (JIT) - Debugger of Windows

Windows JIT debugging is a useful feature for debugging program flows at runtime.

In principle, any .net-compatible debugger can be used.

Windows uses the following registry key to recognize which program is to be used as the JIT debugger.

32-Bit:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

For 64-bit OS, the following keys must also be observed:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

For Visual Studio, the registry entry usually looks like this (32-bit/64-bit identical):

"C:\Windows\system32\vsjitdebugger.exe" -p %ld -e %ld

Further details: MSDN infos about JIT-Debugger


Evaluation of expressions without side effects in the debugger immediate window (Immediate Window)


In the debugger immediate window (Debug → Windows → Immediate Window) you can also evaluate values ​​without side effects on the running code.

To do this, add the following to queries:

, nse

Here is an example class to illustrate the effect:

ree











When "Foo" is evaluated in the "Immediate Window", the count increases and the content of the variable is changed:

ree












We can see here that the number has increased from 1 to 2.

Adding ", nse" (No Side Effects) to the expression evaluates the expression without changing the application state.

ree


bottom of page