debugging - How to view c# variables using windbg -


i have c# windows service installed on 32 bit windows server 2003 machine wish debug.

the problem have log file error message tells me following:

system.nullreferenceexception: object reference not set instance of object. @ videoprocessor.resetcameraproperties(dataserviceobject dso) @ videoprocessor.addserver(dataserviceobject dso) @ videoprocessor.loadservers() @ videoprocessor.start() atvideoservercomponent.connect() 

the actual code function resetcameraproperties is:

protected void resetcameraproperties(dataserviceobject dso)     {         // find cameratype.         //type videocameratype = typemanager.instance["xfire.common.videoobjects.videoserver"];         if (_videocameratype == null) return;          //load cameras data service layer         string whereclause = "serverid = ?";         object[] args = new object[] { dso["objectid"] };         idataservicecollection videocameradsocollection = clientserverconnection.instance.findcollection(_videocameratype, whereclause, args, null, collectionoptions.filterbypartitionresponsibility) 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 server disconnected, know should 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 camera.             serverresult result = clientserverconnection.instance.persistobject(camera, null);             if (result.fault != null)             {                 if (videotrace.traceerror) trace.writeline(result.fault.message);             }      }           
  1. i have opened windbg , did file-->attach process
  2. i have set breakpoints in function above using steps outlined here: http://blogs.msdn.com/b/alejacma/archive/2009/07/13/managed-debugging-with-windbg-preparing-the-environment.aspx
  3. when breakpoint hit step forward using f10 see following:

    setting breakpoint: bp 05a0a260 [videoprocessor.resetcameraproperties* (xfire.common.dataservicelayer.dataserviceobject)] adding pending breakpoints... **0:024> g driverwindowsservice.onstop service stopping... breakpoint 0 hit 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 push 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 push edi

this means nothign me @ present (i'm windbg newbie)

  1. i have pdb file windows service (i got visual studio debug output folder) , have copied itto target machine in folder c:\symbols.
  2. in windbg did file-->symbol file path , set location of pdb file copied over. symbol path follows: c:\symcache;c:\symbols;srv*c:\symcache*http://msdl.microsoft.com/download/symbols
  3. in windbg did view-->watch , typed in name of variable inside function above (videocameratype). got following error:


    * ** * either specified unqualified symbol, or debugger * doesn't have full symbol information. unqualified symbol * resolution turned off default. please either specify * qualified symbol module!symbolname, or enable resolution * of unqualified symbols typing ".symopt- 100". note * enabling unqualified symbol resolution network symbol * server shares in symbol path may cause debugger * appear hang long periods of time when incorrect * symbol name typed or network symbol server down. * * commands work properly, symbol path * must point .pdb files have full type information. * * .pdb files (such public os symbols) not * contain required information. contact group * provided these symbols if need command * work. * * * type referenced: _videocameratype * **


how can view variables , see going on in code???? have source code windows service if thats help.

thanks

first thing symbol files not matching binaries there no source file paths , line numbers in exception stack trace. mentioned copied them visual studio debug output, assume have binaries compiled in release (with no symbols) , pdb files debug. won't work. need change project settings service, recompile , deploy (you should have pdb, dll , exe files in release output folder). should generate more meaningful stack trace exception.

now, second part. need distinguish managed environment native one. in windbg debugging clr seen operating system, debugging not c# application clr interpreter compiles ilasm (compiled c# code) native cpu instructions , executes them. layer below see in vs (with managed debugger attached). keeping in mind need either dig clr internals , try figure out addresses in registers mean or use sort of translator heavy work you. , sos comes play. you've used when set breakpoint. interested in knowing value of variable need first find out @ address clr lied out you. see _videocameratype private class member, isn't it? if may dump managed objects stack using !dso command. should see similar output below:

> !dso os thread id: 0xad8 (0) rsp/reg          object           name 000000000068e8f0 00000000025f2bc8 program+test 000000000068e8f8 00000000025f2be0 system.string    test 000000000068e910 00000000025f2bc8 program+test 000000000068e918 00000000025f2bc8 program+test 

where program+test replaced class name. may dump object content using !do command , address object column:

> !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 

find class member name , use !do command once again using address value column (this works reference types). in our example be:

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  << 

things trickier if need figure out value of local variable is. may try !clrstack -a not show in release builds. left analysis of generated assembly (!u @rip) in order find out address of variables landed (registry, stack). after figuring out, issue again !do command address you've found. happy debugging :)


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -