MDbg.exe (.NET Framework Command-Line Debugger)
The NET Framework Command-Line Debugger helps tools vendors and application developers find and fix bugs in programs that target the .NET Framework common language runtime. This tool uses the runtime debugging API to provide debugging services. You can use MDbg.exe to debug only managed code; there is no support for debugging unmanaged code.
This tool is available through NuGet. For installation information, see MDbg 0.1.0. To run the tool, use the Package Manager Console. For more information about how to use the Package Manager Console, see the Package Manager Console article.
At the Package Manager prompt, type the following:
MDbg [ProgramName[arguments]] [options]
When you are in the debugger (as indicated by the mdbg> prompt), type one of the commands described in the next section:
MDbg.exe commands are case-sensitive.
|ap[rocess] [number]||Switches to another debugged process or prints available processes. The numbers are not real process IDs (PIDs), but a 0-indexed list.|
|a[ttach] [pid]||Attaches to a process or prints available processes.|
|b[reak] [ClassName.Method | FileName:LineNo]||Sets a breakpoint at the specified method. Modules are scanned sequentially.
- break FileName:LineNo sets a breakpoint at a location in the source.
- break ~number sets a breakpoint on a symbol recently displayed with the x command.
- break module!ClassName.Method+IlOffset sets a breakpoint on the fully qualified location.
|block[ingObjects]||Displays monitor locks, which are blocking threads.|
|ca[tch] [exceptionType]||Causes the debugger to break on all exceptions, and not just on the unhandled exceptions.|
|cl[earException]||Marks the current exception as handled so that execution can continue. If the cause of the exception has not been dealt with, the exception may be quickly rethrown.|
|conf[ig] [option value]||Displays all configurable options and shows how the options are invoked without any optional values. If the option is specified, sets
|del[ete]||Deletes a breakpoint.|
|de[tach]||Detaches from a debugged process.|
|d[own] [frames]||Moves the active stack frame down.|
|echo||Echoes a message to the console.|
|enableNotif[ication] typeName 0|1||Enables (1) or disables (0) custom notifications for the specified type.|
|ex[it] [exitcode]||Exits the MDbg.exe shell, and optionally specifies the process exit code.|
|fo[reach] [OtherCommand]||Performs a command on all threads. OtherCommand is a valid command that operates on one thread; foreach OtherCommand performs the same command on all threads.|
||Performs a function evaluation on the current active thread where the function to evaluate is functionName. The function name must be fully qualified, including namespaces.
If the function that is being evaluated is not static, the first parameter passed in should be a
To request a value from an application domain, prefix the variable with the module and application domain name; for example,
|g[o]||Causes the program to continue until it encounters a breakpoint, the program exits, or an event (for example, an unhandled exception) causes the program to stop.|
|Displays a description of all commands or a detailed description of a specified command.|
|ig[nore] [event]||Causes the debugger to stop on unhandled exceptions only.|
|int[ercept] FrameNumber||Rolls the debugger back to a specified frame number.
If the debugger encounters an exception, use this command to roll the debugger back to the specified frame number. You can change the program state by using the set command and continue by using the go command.
|k[ill]||Stops the active process.|
|l[ist] [modules | appdomains | assemblies]||Displays the loaded modules, application domains, or assemblies.|
|lo[ad] assemblyName||Loads an extension in the following manner: The specified assembly is loaded and an attempt is then made to run the static method
|log [eventType]||Set or display the events to be logged.|
|mo[de] [option on/off]||Sets different debugger options. Use
|mon[itorInfo] monitorReference||Displays object monitor lock information.|
|newo[bj] typeName [arguments...]||Creates a new object of type typeName.|
|n[ext]||Runs code and moves to the next line (even if the next line includes many function calls).|
|Opendump pathToDumpFile||Opens the specified dump file for debugging.|
|o[ut]||Moves to the end of the current function.|
|pa[th] [pathName]||Searches the specified path for the source files if the location in the binaries is not available.|
|p[rint] [var] | [
||Prints all variables in scope (print), prints the specified variable (print var), or prints the debugger variables (print
|printe[xception] [-r]||Prints the last exception on the current thread. Use the
|pro[cessenum]||Displays the active processes.|
|q[uit] [exitcode]||Quits the MDbg.exe shell, optionally specifying the process exit code.|
||Resumes the current thread or the thread specified by the threadNumber parameter.
If the threadNumber parameter is specified as
Resuming a non-suspended thread has no effect.
||Stops the current process (if there is one) and starts a new one. If no executable argument is passed, this command runs the program that was previously executed with the
If class load, module load, and thread start events are ignored (as they are by default), the program stops on the first executable instruction of the main thread.
You can force the debugger to just-in-time (JIT) compile the code by using one of the following three flags:
|Set variable=value||Changes the value of any in-scope variable.
You can also create your own debugger variables and assign reference values to them from within your application. These values act as handles to the original value, and even the original value is out of scope. All debugger variables must begin with
||Sets the current instruction pointer (IP) in the file to the specified position. If you specify the
|sh[ow] [lines]||Specifies the number of lines to show.|
|s[tep]||Moves execution into the next function on the current line, or moves to the next line if there is no function to step into.|
|su[spend] [* | [~]threadNumber]||Suspends the current thread or the thread specified by the threadNumber parameter. If threadNumber is specified as
|sy[mbol] commandName [commandValue]||Specifies one of the following commands:
|t[hread] [newThread] [-nick nickname
||The thread command with no parameters displays all managed threads in the current process. Threads are usually identified by their thread numbers; however, if the thread has an assigned nickname, the nickname is displayed instead. You can use the
Nicknames cannot be numbers. If the current thread already has an assigned nickname, the old nickname is replaced with the new one. If the new nickname is an empty string (""), the nickname for the current thread is deleted and no new nickname is assigned to the thread.
|u[p]||Moves the active stack frame up.|
|uwgc[handle] [var] | [address]||Prints the variable tracked by a handle. The handle can be specified by name or address.|
|when||Displays the currently active
when delete all |
specific_condition can be one of the following:
- number - For
specific_condition must be empty for other values of stopReason.
||Displays debug information about stack frames.
- Specifying a number for
- If you specify the threadID parameter, you can control which thread is associated with the stack. The default is the current thread only. Use the all command to get all threads.
||Displays functions that match the
If numSymbols is specified, the output is limited to the specified number. If
Compile the application to be debugged by using compiler-specific flags that cause your compiler to generate debugging symbols. Refer to your compiler's documentation for more information about these flags. You can debug optimized applications, but some debugging information will be missing. For example, many local variables will not be visible and source lines will be inaccurate.
After you compile your application, type mdbg at the command prompt to start a debugging session, as shown in the following example.
C:\Program Files\Microsoft Visual Studio 8\VC>mdbg MDbg (Managed debugger) v2.0.50727.42 (RTM.050727-4200) started. Copyright (C) Microsoft Corporation. All rights reserved. For information about commands type "help"; to exit program type "quit". mdbg>
mdbg> prompt indicates that you are in the debugger.
Once you are in the debugger, use the commands and arguments described in the previous section.
Send feedback about: