如何在没有VS的情况下调试用c#编写的程序

时间:2012-10-13 11:18:52

标签: c# debugging

  

可能重复:
  How to Debug .net applications without Visual Studio

嗨,我做了一个小程序,它适合我和少数人

但它正在一位朋友身上坠毁

我如何调试和了解哪些行确实导致错误?

without installing visual studio

4 个答案:

答案 0 :(得分:3)

你可以做的最好的(并且是一个很好的编码实践)在一个新的buid添加try catch异常块的方法中使用日志记录工具(在catch块中)让我们说一个文本文件

  1. 方法名称(使用新的StackTrace()查找.. GetFrame(1).GetMethod()。名称或System.Reflection.MethodBase.GetCurrentMethod().Name),
  2. 其参数和
  3. 异常消息。

答案 1 :(得分:2)

如果您的意思是“未安装调试器”,则可以尝试使用Mono

答案 2 :(得分:1)

您可以使用可以运行的WinDbg(来自现有安装的xcopy),并且使用SoS附加组件可以在调试C#应用程序时提供很多帮助 - 即使在事后也是如此。一开始可能很难掌握,但值得学习 - 在几种情况下它会非常有用。

此处参考SoS:http://msdn.microsoft.com/en-us/library/bb190764.aspx

我有这个快速的作弊表,我发现最有用的东西(在互联网上找到,然后随着时间的推移而丰富):

Starting, Attaching, Executing and Exiting


Start -> All Programs -> Debugging Tools for Windows -> WinDbg
F6
attach to process
Ctrl-Break
interrupt debugee
.detach
detach from a process
g
continue debugee execution
q
exit WinDbg

Getting Help
?
help on commands that affect the debugee
.help
help on commands that affect the debugger
.hh command
view the on line help file
!help
help on the extension dll at the top of the chain (e. g., SOS)

Issuing Commands
up arrow, down arrow, enter
scroll through command history
Right mouse button
paste into command window

Examining the Unmanaged Environment
lmf
list loaded modules with full path
lmt
list loaded modules with last modified timestamp
~
list unmanaged threads
~thread s
select a thread for thread specific commands
!token -n
view thread permissions
k
view the unmanaged call stack
!runaway
view thread CPU consumption
bp
set a breakpoint
.dump path
dump small memory image
.dump /ma path
dump complete memory image

Working with Extension DLLs (e. g., SOS)
.chain
list extensions dlls
.load clr10\sos
load SOS for debugging framework 1.0 / 1.1 (use .unload to unload)
.loadby sos mscorwks
load SOS for debugging framework 2.0
.loadby sos clr
load SOS for debugging framework 4.0

SOS Commands
!threads
view managed threads
!clrstack
view the managed call stack
!dumpstack
view combined unmanaged & managed call stack
!clrstack -p
view function call arguments
!clrstack –l
view stack (local) variables
!name2ee module class
view addresses associated with a class or method
!dumpmt –md address
view the method table & methods for a class
!dumpmd address
view detailed information about a method
!do address
view information about an object
!dumpheap –stat
view memory consumption by type
!dumpheap –min size
view memory consumption by object when at least size
!dumpheap –type type
view memory consumption for all objects of type type
!gcroot address
view which object are holding a reference to address
!syncblk
view information about managed locks

SOS 2.0 Commands
!bpmd module method
set breakpoint
!DumpArray address
view contents of an array
!PrintException
view information about most recent exception

答案 3 :(得分:0)

如果您不想安装任何其他调试器,

然后你应该只是简单地实现跟踪并仔细记录代码的每个部分,然后你可以查看文本文件中的跟踪或错误..

实现跟踪和日志的方法:

use可以在TraceListener命名空间上使用system.diaognosis类 或使用

Microsoft.Practices.EnterpriseLibrary.Logging namespace's class `Logger` to implement tracing:

语法:

Logger.Write(message, "Trace", 0, 0, System.Diagnostics.TraceEventType.Information);