Debugging 如何使用windbg查看c#变量
我在32位WindowsServer2003机器上安装了一个C#windows服务,我希望对其进行调试 我遇到的问题是日志文件错误消息告诉我以下内容:Debugging 如何使用windbg查看c#变量,debugging,windbg,symbols,Debugging,Windbg,Symbols,我在32位WindowsServer2003机器上安装了一个C#windows服务,我希望对其进行调试 我遇到的问题是日志文件错误消息告诉我以下内容: System.NullReferenceException: Object reference not set to an instance of an object. at VideoProcessor.ResetCameraProperties(DataServiceObject dso) at VideoProcessor.AddServe
System.NullReferenceException: Object reference not set to an instance of an object.
at VideoProcessor.ResetCameraProperties(DataServiceObject dso)
at VideoProcessor.AddServer(DataServiceObject dso)
at VideoProcessor.LoadServers()
at VideoProcessor.Start()
atVideoServerComponent.Connect()
函数ResetCameraProperties的实际代码为:
protected void ResetCameraProperties(DataServiceObject dso)
{
// Find the CameraType.
//Type videoCameraType = TypeManager.Instance["XFire.Common.VideoObjects.VideoServer"];
if (_videoCameraType == null) return;
//Load cameras from the Data Service Layer
string whereClause = "ServerID = ?";
object[] args = new object[] { dso["ObjectID"] };
IDataServiceCollection videoCameraDsoCollection = ClientServerConnection.Instance.FindCollection(_videoCameraType, whereClause, args, null, CollectionOptions.FilterByPartitionResponsibility) as IDataServiceCollection;
if (videoCameraDsoCollection == null || 0 == videoCameraDsoCollection.Count)
return;
videoCameraDsoCollection.LoadContainerOnEnumeration = false;
foreach (DataServiceObject camera in videoCameraDsoCollection)
{
if (!(bool)dso[RecorderKey.Online] && (int)dso[RecorderKey.VideoServerAlarm] == (int)VideoServerComponent.GetVideoServerAlarm("Offline"))
{
// If the server is disconnected, then we know everything should be offline.
camera[CameraKey.VideoCameraAlarm] = VideoServerComponent.GetEnumValueOfType("XFire.Common.VideoObjectDefinitions.VideoCameraAlarm", "Unknown");
camera[CameraKey.Videoloss] = true;
}
else if ((bool)dso[RecorderKey.Online] && (int)dso[RecorderKey.VideoServerAlarm] == (int)VideoServerComponent.GetVideoServerAlarm("Online"))
{
camera[CameraKey.VideoCameraAlarm] = VideoServerComponent.GetEnumValueOfType("XFire.Common.VideoObjectDefinitions.VideoCameraAlarm", "Normal");
camera[CameraKey.Videoloss] = false;
}
// Save the camera.
ServerResult result = ClientServerConnection.Instance.PersistObject(camera, null);
if (result.Fault != null)
{
if (VideoTrace.TraceError) Trace.WriteLine(result.Fault.Message);
}
}
System.NullReferenceException: Object reference not set to an instance of an object.
at VideoProcessor.ResetCameraProperties(DataServiceObject dso)
at VideoProcessor.AddServer(DataServiceObject dso)
at VideoProcessor.LoadServers()
at VideoProcessor.Start()
atVideoServerComponent.Connect()
设置断点:bp 05A0A260[VideoProcessor.ResetCameraProperties*(XFire.Common.DataServiceLayer.DataServiceObject)]
正在添加挂起的断点。。。
**0:024>g
DriverWindowService.OnStop服务正在停止。。。
断点0命中
eax=00000001 ebx=00902870 ecx=00a1e020 edx=01066e78 esi=00affb48 edi=01066e78
eip=05a0a260 esp=0674e68c ebp=0674e6b0 iopl=0 nv向上ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
05a0a260 55推式ebp
0:024>p
eax=00000001 ebx=00902870 ecx=00a1e020 edx=01066e78 esi=00affb48 edi=01066e78
eip=05a0a261 esp=0674e688 ebp=0674e6b0 iopl=0 nv向上ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
05a0a261 8bec mov ebp,esp
0:024>p
eax=00000001 ebx=00902870 ecx=00a1e020 edx=01066e78 esi=00affb48 edi=01066e78
eip=05a0a263 esp=0674e688 ebp=0674e688 iopl=0 nv向上ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
05a0a263 57推式edi* *** 指定了非限定符号,或者调试器 *没有完整的符号信息。不合格符号* 默认情况下,分辨率处于关闭状态。请指定一个 *完全限定符号模块!symbolname,或启用分辨率* 通过键入“.symopt-100”来检查不合格符号。请注意 *使用网络符号启用非限定符号解析* 符号路径中的服务器共享可能导致调试器 *当错误的* 已键入符号名称或网络符号服务器已关闭<强> ** 要使某些命令正常工作,请选择符号路径 *必须指向包含完整类型信息的.pdb文件<强>* *某些.pdb文件(如公共操作系统符号)不* 包含所需信息。联系 *如果您需要此命令执行* 工作<强> ** *引用的类型:\u videoCameraType* **
谢谢首先,您的符号文件可能与二进制文件不匹配,因为在异常堆栈跟踪中没有源文件路径和行号。您提到您从VisualStudio调试输出中复制了它们,所以我假设您在发行版中编译了二进制文件(没有符号)和来自调试的pdb文件。这行不通。您需要做的是,重新编译并部署它(您现在应该在发布输出文件夹中有pdb、dll和exe文件)。这将为异常生成更有意义的堆栈跟踪 现在是第二部分。您需要区分托管环境和本机环境。在windbg中,您调试的是操作系统所看到的CLR,因此您不仅调试C#应用程序,还调试将ILASM(已编译C#代码)编译为本机CPU指令然后执行它们的CLR解释器。因此,您是在VS中通常看到的层之下的一层(连接了托管调试器)。记住这一点,您需要深入研究CLR内部并尝试找出寄存器中的地址意味着什么,或者使用某种翻译器来完成这项繁重的工作。而这正是发挥作用的地方。您在设置断点时已经使用了它。因为您只想知道变量的值,所以您需要首先找出CLR为您设置的地址。从我所看到的
\u videoCameraType
是一个私人类成员,不是吗?如果是这样,您可以使用从堆栈中转储托管对象!dso
命令。你应该看到类似的东西
> !do 00000000025f2bc8
Name: Program+Test
MethodTable: 000007fe58333a08
EEClass: 000007fe584422b8
Size: 24(0x18) bytes
File: D:\temp\Test.exe
Fields:
MT Field Offset Type VT Attr Value Name
000007feb4dcb318 4000001 8 System.String 0 instance 00000000025f2be0 _testVariable
0:000> !do 00000000025f2be0
Name: System.String
MethodTable: 000007feb4dcb318
EEClass: 000007feb4733720
Size: 34(0x22) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
String: test
Fields:
MT Field Offset Type VT Attr Value Name
000007feb4dce0c8 40000aa 8 System.Int32 1 instance 4 m_stringLength
000007feb4dcc600 40000ab c System.Char 1 instance 74 m_firstChar
000007feb4dcb318 40000ac 18 System.String 0 shared static Empty
>> Domain:Value 000000000074f960:NotInit <<