David的测试技术空间,收藏好文档和分享我的技术理解。5年的数通产品测试和安全产品测试经验,3年Web产品测试和多年测试管理和测试工具开发经验。目前关注性能分析调优、Jmeter和TestNG+WebDriver+Hamcrest的培训推广。Welcome沟通交流,请留言或者发邮件到daviwang_2004 at soguo.com。

Runtime Debugger (Cordbg.exe)

上一篇 / 下一篇  2007-12-18 10:29:41

http://msdn2.microsoft.com/en-us/library/a6zb7c8d(VS.80).aspx
.NET Framework Tools 
Runtime Debugger (Cordbg.exe) 

The Runtime 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 Debug API to provide debugging services. The source code for Cordbg.exe is being shipped as a sample application. Developers can examine the code to learn how to use the debugging services. Currently, you can only use Cordbg.exe to debug managed code; there is no support for debugging unmanaged code.

Use the first line of syntax belowto start a Cordbg.exe session. Use the second line at the(cordbg)promptinside a Cordbg.exe session.

cordbg [ProgramName[Program arguments]][optional arguments ]
command [command arguments]

Parameters

CommandDescrīption

ap[pdomainenum] [option]

Enumerates all application domains, assemblies, and modules in the current process. If you do not specify theoptionargument, the command lists all application domains, assemblies, and modules in the current process. After detaching or attaching, you must specify thegocommand to resume execution.

Theoptionargument can be one of the following:

attach

Lists the application domains in the process and prompts the user to select the domain to attach to.

detach

Lists the application domains in the process and prompts the user to select the domain to detach from.

0

Lists the application domains in the process.

1

Lists the application domains and assemblies in the process.

as[sociatesource] {s|bbreakpoint id}filename

Associates the given file name with the current stack frame pointer (options) or the specified breakpoint (optionb).

a[ttach]pid

Attaches the debugger to a running process. Cordbg.exe kills the program that it is currently debugging (if there is one), and attempts to attach to the process specified by thepidargument. The process identification numberpidcan be in decimal or hexadecimal format.

b[reak] [[file:]line number] |

[[class::]function[:offset]]

Sets or displays breakpoints. If you do not specify any arguments, the tool displays a list of current breakpoints; otherwise, it sets a breakpoint at the specified location. You can set a breakpoint at a line number in the current source file, a line number in a fully qualified source file, or in a method qualified by a class and optional offset.

Breakpoints persist across runs in a session. You can use thestopcommand the same way you usebreak.

Cordbg.exe displays breakpoints as "unbound" if the specified breakpoint location cannot be bound to code. When a breakpoint is unbound, it means that the underlying code for the breakpoint location has not been loaded yet. This can happen for a number of valid reasons, such as a misspelled file or class name (they are case-sensitive). Also, breakpoints will be unbound if you set them before running an application. Breakpoints become bound when the real code is loaded. The debugger tries to automatically rebind every unbound breakpoint when it loads a module.

ca[tch] [event]

Displays a list of event types, or causes the specified event type to stop the debugger. If you do not specify an argument, the tool displays a list of event types, where event types that stop the debugger are marked "on," and event types that are ignored are marked "off." If you specify an argument, the debugger stops when events of the specified type occur. By default, the debugger only stops on unhandled exception events (that is, second chance exceptions). Event types that stop the debugger persist across runs in a session. To cause the debugger to ignore a particular type of event, use theignorecommand.

The event argument can be one of the following:

e[xceptions] [exception type]

The tool adds the exception type to a list of first chance exceptions to catch. If you do not specify an exception type, the tool catches all first chance exceptions. The exception type is case sensitive, for example,System.ArgumentException.

u[nhandled]

Unhandled exceptions

c[lass]

Class load events

m[odule]

Module load events

t[hread]

Thread start events

conn[ect]machine_nameport

For smart device projects.

Connects to a remote device running a .NET Compact Framework application.

ParameterDefinition

machine_name

Required. The name or IP address of the remote computer.

Port

Required. The port to use to connect to the remote computer.

cont[count]

Continues the program. If you do not specify an argument, the program continues once. If you do specify an argument, the program continues the specified number of times. This command is useful for continuing a program when a class load event, exception, or breakpoint stops the debugger. You can use thegocommand the same way you usecont.

del[ete] [breakpoint id, ...]

Deletes breakpoints. If you do not specify any arguments, the tool deletes all current breakpoints. If you specify one or morebreakpoint idarguments, the tool deletes the specified breakpoints. You can obtain breakpoint identifiers by using thebreakorstopcommands. You can use theremovecommand the same way you usedelete.

de[tach]

Detaches the debugger from the current process. The process automatically continues and runs as if a debugger is not attached to it.

dis[assemble] [0xaddress][{+|-}delta] [line count]

Displays native disassembled instructions for the current instruction pointer oraddress, if specified. The default number of instructions displayed is five. If you specify aline countargument, the tool displays the specified number of extra instructions before and after the current instruction pointer or address. The lastline countused becomes the default for the current session. If you specify a delta, the number specified will be added to the current instruction pointer or specified address to begin disassembling.

d[own] [count]

Moves the stack frame pointer down the stack toward frames called by the current frame for inspection purposes. If you do not specify an argument, the stack frame pointer moves down one frame. If you specify an argument, the stack frame pointer moves down by the specified number of frames. If source level information is available, the tool displays the source line for the frame. This command is frequently used in conjunction with theupcommand.

du[mp]address[count]

Dumps a block of memory, with the output in hexadecimal or decimal format depending on the debugger's mode (seemode). Theaddressargument is the address of the block of memory. Thecountargument is the number of bytes to dump.

ex[it]

Stops the current process and exits the debugger. You can use thequitcommand in the same way you useexit.

f[unceval] [class::]function[arg0 arg1...argn]

Evaluates the specified function on the current thread. The tool stores the new object in the variable$resultand can use it for subsequent evaluations. Valid arguments are limited to other variables, 4-byte integers, and the constantsNull,True, andFalse.

NoteNote

For a member function, the first argument should be an object of the class or derived class to which the member function belongs.

g[o] [count]

Seecont.

h[elp] [command...]

Displays descrīptions for the specified commands. If you do not specify any arguments, Cordbg.exe displays a list of debugger commands. You can use the?command the same way you usehelp.

ig[nore] [event]

Displays a list of event types or causes the specified event type to be ignored by the debugger. If you do not specify aneventargument, the tool displays a list of event types, where event types that are ignored are marked "off" and event types that stop the debugger are marked "on." If you specify an argument, the tool ignores events of the specified type. To set an event type to stop the debugger, use thecatchcommand.

Theeventargument can be one of the following event types:

e[xceptions] [exception type]

The tool adds the exception type to a list of first chance exceptions to ignore. If you do not specify an exception type, the tool ignores all first chance exceptions. The exception type is case sensitive, for example,System.ArgumentException.

u[nhandled]

Unhandled exceptions

c[lass]

Class load events

m[odule]

Module load events

t[hread]

Thread start events

i[n] [count]

Seestep.

k[ill]

Stops the current process. The debugger remains active to process further commands.

l[ist]option

Displays a list of loaded modules, classes, or global functions.

Theoptionargument can be one of the following:

mod

Lists the loaded modules in the process.

cl

Lists the loaded classes in the process.

fu

Lists global functions for each module in the process.

m[ode] [[mode name{0|1} ]

Sets and displays debugger modes for various debugger features. To set a value, specify themode nameand a1for "on" or0for "off." If you do not specify an argument, the tool displays a list of current mode settings. The modes are persisted in the Windows registry between runs of Cordbg.exe. For more information, see the table of debuggermode arguments.

newo[bj]class

Creates a new object using the current thread. The tool stores the new object in the variable$resultand can use it for subsequent evaluations.

newobjnc class

Creates a new object using the current thread without running a constructor on the object. The new object is initialized to zero. The tool stores the new object in the variable$resultand can use it for subsequent evaluations.

news[tr]string

Creates a new string using the current thread. The tool stores the new object in the variable$resultand can use it for subsequent evaluations.

n[ext] [count]

Steps the program to the next source line, stepping over function calls. If you do not specify an argument, the tool steps one source line. If you specify an argument, the tool steps the specified number of lines. You can use thesocommand the same way you usenext.

ns[ingle] [count]

Steps the program one or more instructions, skipping over function calls. If you do not specify an argument, the tool steps one instruction. If you specify acountargument, the tool steps the specified number of instructions.

o[ut] [count]

Steps the program out of the current function. If you do not specify an argument, the tool performs a step out once for the current function. If you specify an argument, the tool performs a step out the specified number of times.

pa[th] [new path]

Displays or sets the path used to search for source files and debugging symbols. If you do not specify an argument, the tool displays the current path. If you specify anew pathargument, it becomes the new path used to search for source files and debugging symbols. This path persists between sessions in the Windows registry.

p[rint] [variable name]

Displays one or more local variables along with their values. If you do not specify an argument, the tool displays all local variables and their values. If you specify an argument, the tool displays the value of only the specified local variable. For details, seeUsing the print commandin the Examples section.

pro[cessenum]

Enumerates all managed processes and the application domains in each process.

q[uit]

Seeexit.

ref[reshsource] [source file]

Reloads the source code for a given source file. The source file to be reloaded must be part of the currently executing program. After setting a source file path with thepathcommand, you can use therefreshsourcecommand to bring in missing source code.

regd[efault] [force]

Sets the default just-in-time (JIT) debugger to Cordbg.exe. The command does nothing if another debugger is already registered. Use theforceargument to overwrite the registered JIT debugger.

reg[isters]

Displays the contents of the registers for the current thread.

rem[ove] [breakpoint id, ...]

Seedelete.

re[sume] [~] [tid]

Resumes the thread specified by thetidargument when the debugger continues. If you use the~syntax, the tool resumes all threads except the specified thread. If you do not specify an argument, the command has no effect.

r[un] [executable[args]]

Kills the current process (if there is one) and starts a new one. If you do not specify anexecutableargument, this command runs the program that was previously executed with theruncommand. If you specify anexecutableargument, the tool runs the specified program using the optionally suppliedargs. If Cordbg.exe is ignoring class load, module load, and thread start events (as it is by default), the program stops on the first executable instruction of the main thread.

set variable value

Sets the value of the specifiedvariableto the specifiedvalue. The value can be a literal or another variable. For details, seeUsing the set command.in the Examples section.

setip line number

Sets the next statement to execute to the specifiedline number.

sh[ow] [count]

Displays source code lines. If you do not specify an argument, the tool displays the five source code lines before and after the current source code line. If you specify an argument, the tool displays the specified number of lines before and after the current line. The lastcountspecified becomes the default for the current session.

si[<count>]

Seestep.

so[<count>]

Seenext.

ss[ingle] [count]

Steps the program one or more instructions, stepping into function calls. If you do not specify an argument, the tool steps into only one instruction. If you specify an argument, the tool performs the specified number of steps.

s[tep] [count]

Steps the program to the next source line, stepping into function calls. If you do not specify an argument, the program steps to the next line. If you specify an argument, the program steps the specified number of lines. You can use thesicommand or theincommand the same way you usestep.

stop[[file:]line number] |

[[class::]function[:offset]] |

[=0xaddress]

Seebreak.

su[spend] [~] [tid]

Suspends the thread specified by thetidargument when the debugger continues. If you use the~syntax, the tool suspends all threads except the specified thread. If you do not specify an argument, the command has no effect.

t[hreads] [tid]

Displays a list of threads, or sets the current thread. If you do not specify an argument, the tool displays the list of all threads that are still alive and that have run managed code. If you specify an argument, the tool sets the current thread to the specified thread.

up[count]

Moves the stack frame pointer up the stack toward frames that called the current frame for inspection purposes. If you do not specify an argument, the stack frame pointer moves up one frame. If you specify an argument, the stack frame pointer moves up by the specified number of stack frames. If source level information is available, the tool displays the source line for the frame.

w[here] [count]

Displays a stack trace for the current thread. If you do not specify an argument, the tool displays a complete stack trace. If you specify an argument, the tool displays the specified number of stack frames.

wr[itememory]address count byte, ...

Writes the specified bytes to the target process. Theaddressargument specifies the location in which to write the bytes. Thecountargument specifies the number of bytes to write. Thebytearguments specify what to write to the process. If the number of bytes in the list is less than thecountargument, the tool wraps the byte list and copies it again. If the number of bytes in the list is more than thecountargument, the tool ignores the extra bytes.

wt

Steps the application by native instructions, starting from the current instruction and printing the call tree as it goes. The tool prints the number of native instructions executed in each function with the call trace. Tracing stops when the tool reaches the return instruction for the function in which the command was originally executed. At the end of the trace, the tool prints the total number of instructions executed. This command mimics the NT Symbolic Debuggerwtcommand, and you can use it for basic performance analysis. Currently, the tool only counts managed code.

x modulename! string_to_look_for

Displays symbols in the specified module that match the pattern specified by thestring_to_look_forargument. You can use the asterisk (*) character in thestring_to_look_forargument to indicate to the tool to match anything. The tool ignores any characters after the * character.

?[command...]

Seehelp.

>filename

Writes all executed commands to the specifiedfilename. If you do not specifyfilename, the command stops writing commands to the file.

<filename

Reads and executes commands from the specifiedfilename.

NoteNote

Cordbg.exe commands are case-sensitive. In addition, several commands have synonyms, meaning that you can use any one of several commands to produce the same result. For example, you can use either thebreakor thestopcommand to set breakpoints.

You can specify mode arguments using the fewest number of characters necessary to make the mode unique. For example, "mode m 1" is equivalent to "mode moduleloads 1".

ArgumentDescrīption

AppDomainLoads

Displays application domain and assembly load events.

ClassLoads

Displays class load events.

DumpMemoryInBytes

Displays memory contents as bytes or DWORDS.

EmbededCLR

Sets the debugger to target .NET Compact Framework applications running on smart devices. To control this setting, specify 1 for on or 0 for off.

EnhanceDiag

Displays enhanced diagnostic information.

HexDisplay

Displays numbers in hexadecimal or decimal format.

ILNatPrint

Displays offsets in Microsoft intermediate language (MSIL) or native-relative language, or both.

ISAll

Steps through all interceptors.

ISClinit

Steps through class initializers.

ISExceptF

Steps through exception filters.

ISInt

Steps through user interceptors.

ISPolicy

Steps through context policies.

ISSec

Steps through security interceptors.

JitOptimizations

Specifies whether JIT compilation generates code that is easier to debug.

LoggingMessages

Displays managed code log messages.

ModuleLoads

Displays module load events.

SeparateConsole

Specifies whether the process being debugged gets its own console.

ShowArgs

Displays method arguments in the stack trace.

ShowModules

Displays module names in the stack trace.

ShowStaticsOnPrint

Displays static fields for objects.

ShowSuperClassOnPrint

Displays contents of base class for objects.

USAll

Steps through all unmapped stop locations.

USEpi

Steps through method epilogs.

USPro

Steps through method prologs.

USUnmanaged

Steps through unmanaged code.

You should compile the application to debug using compiler-specific flags, which cause your compiler to generate debugging symbols. Refer to your compiler's documentation for more information about these flags. You can still 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 the application, typecordbgat the command prompt to start a debugging session, as shown in the following example.

D:\Program Files\FrameworkSDK\Bin>cordbg
Microsoft (R) Common Language Runtime Test Debugger Shell. Version 2000.14.2100.0, Copyright (c) Microsoft Corp. 1998-2000
(cordbg)

The(cordbg)prompt indicates that you are in the debugger.

Once you are in the debugger, use the commands and appropriate arguments to invoke the required functionality.

When you start a debugging session from the command line, you can also provide the name of the application you want to debug, program arguments, and optional arguments. The Cordbg.exe optional arguments are the same commands that you would use while in Cordbg.exe but you must prefix them with the exclamation point (!) character. You can use the ! character as a literal in a string by prefixing it with the backslash (\) character. This is necessary when using thexcommand.

If a numeric argument to a command begins with the prefix0x, Cordbg.exe assumes the argument is in hexadecimal format. Otherwise, it assumes the argument is in decimal format.

Most commands in Cordbg.exe can be prefixed with an asterisk (*), which causes the command to execute once for each managed thread in the process. The command is executed in the context of each thread. The most useful command to prefix with an asterisk is thew[here] command. For example,*wwill cause the stack trace of every managed thread to be printed.

For more information about the runtime's debugging services, see the Enabling Profiling and Debugging specification. In addition, tools developers should see the Debug Overview and Debug Reference specifications located in the Tools Developers Guide folder that ships with the .NET Framework SDK.

Starting a Cordbg.exe session

The following command starts a Cordbg.exe session for the applicationMyApplication.exewith the program argumentsaand2and the following optional commands: set a breakpoint inMyApplication.csat line 42; continue the application; display symbols inMyApplication.exematching the string'SomeString'.

cordbg MyApplication.exe a 2 !b MyApplication.cs:42 !g !x MyApplication.exe\!SomeString

Running an executable inside a Cordbg.exe session

The following command entered from within a Cordbg.exe session (at the(cordbg)prompt) runs the executableMyApplication.exewith the program argumentsaand2.

run MyApplication.exe a 2

Using the print command

The following commands demonstrate that you can use dot notation with theprintcommand to specify variables within objects.

print obj.var1
print obj1.obj2.var1

If a class extends another class, theprintcommand shows both the specified class's fields and the base class's fields. For example, if classm1has fieldsa,b, andcand classm2extendsm1and has fieldsd,e, andf, then an instancemyInstanceofm2prints as follows.

myInstance = <addr> <m2>
a = 1
b = 2
c = 3
m2::d = 4
m2::e = 5
m2::f = 6

You can specify class static variables by prefixing the variable name with the class name, as follows.

print MyClass::StaticVar1
print System::Boolean::True

Array indexes must be simple expressions. The following array indexes are valid for use with theprintcommand.

print arr[1]
print arr[i]
print arr1[arr2[1]]
print md[1][5][myObject.a]

The following array indexes are not valid for use with theprintcommand, because the array index is not a simple expression.

print arr[i + 1]
print arr[i + 2]

Using the set command

When using thesetcommand, the value being assigned to the specified variable can be a literal or another variable. The following are valid uses of thesetcommand.

set int1 0x2a
set float1 3.1415
set char1 'a'
set bool1 true
set obj1 0x12345678
set obj1 obj2
set obj1.m_length[obj1.m_height] obj3.m_length[2]

Reference

.NET Framework Tools
SDK Command Prompt

TAG:

 

评分:0

我来说两句

Open Toolbar