debugging - How to find out what is throwing an exception using windbg -
i have c# windows service throwing exception.
have launched service using windbg , have let run until exception thrown.
when debugger stops do:
- prefer_dml 1
- !threads. prints out threads , click on exception in question.
i click on _message , displays:
0:018> !dumpobj /d 0105e134 name: system.string methodtable: 79b9f9ac eeclass: 798d8bb0 size: 120(0x78) bytes file: c:\windows\microsoft.net\assembly\gac_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll string: object reference not set instance of object.
then do: !clrstack , following:
06f8e090 04d48299 ad.intellex.driverservice.servercomponentmanager.stopcrossfire() 06f8e098 04d48214 ad.intellex.driverservice.windowsservice.onstop() 76b5e8\system.serviceprocess.ni.dll 06f8e108 04d48177 ad.intellex.driverservice.windowsservice.unhandledexceptioneventhandler(system.object, system.unhandledexceptioneventargs) 06f8e4cc 791421db [gcframe: 06f8e4cc] 06f8e568 791421db [gcframe: 06f8e568] 06f8e63c 791421db [gcframe: 06f8e63c] 06f8e740 791421db [gcframe: 06f8e740] 06f8f234 791421db [helpermethodframe_protectobj: 06f8f234] system.runtime.compilerservices.runtimehelpers.executecodewithguaranteedcleanup(trycode, cleanupcode, system.object) 06f8ec78 04d47f23 ad.hardwareinterface.intellexhardwareinterface.objectprocessor.cameraalarmactivate(int32, softwarehouse.crossfire.common.dataservicelayer.dataserviceobject, ad.common.videoobjectdefinitions.cameraalertstatus, boolean, system.datetime, system.collections.generic.dictionary`2 byref) 06f8edb8 04d46db3 ad.hardwareinterface.intellexhardwareinterface.intellexprocessor.processcameraalarm(system.object) 06f8edf4 79b2d871 system.threading.queueuserworkitemcallback.waitcallback_context(system.object) 06f8edfc 79ab4db5 system.threading.executioncontext.runtrycode(system.object) 06f8f234 791421db [helpermethodframe_protectobj: 06f8f234] system.runtime.compilerservices.runtimehelpers.executecodewithguaranteedcleanup(trycode, cleanupcode, system.object) 06f8f298 79ab4cba system.threading.executioncontext.runinternal(system.threading.executioncontext, system.threading.contextcallback, system.object) 06f8f2b0 79ab7fc2 system.threading.executioncontext.run(system.threading.executioncontext, system.threading.contextcallback, system.object, boolean) 06f8f2d4 79af2b66 system.threading.queueuserworkitemcallback.system.threading.ithreadpoolworkitem.executeworkitem() 06f8f2e8 79af23f3 system.threading.threadpoolworkqueue.dispatch() 06f8f334 79af2299 system.threading._threadpoolwaitcallback.performwaitcallback() 06f8f6f4 791421db [debuggeru2mcatchhandlerframe: 06f8f6f4]
if read ways see function throws exception objectprocessor.cameraalarmactivate
the code function follows:
public override void cameraalarmactivate(int cameranumber, dataserviceobject dso, ad.common.videoobjectdefinitions.cameraalertstatus status, bool isbegin, datetime time, out dictionary<string, object> msgformatparameters) { msgformatparameters = null; try { _alarmmutex.waitone(); type type = typemanager.instance["softwarehouse.nextgen.common.securityobjects.videocamera"]; if (type == null) return; dataserviceobject camera = clientserverconnection.instance.findobject(type, "number = ? , serverid = ?", new object[] { cameranumber, (int)dso[camerakey.objectid] }, true) dataserviceobject; if (camera != null) { string alert = status.tostring(); list<string> alarmlist = checkintellexcameracontainer(camera, dso, alert); if(alarmlist != null && alarmlist.count > 0) { bool alarmtojournal = false; // if alarm motion... if (status == ad.common.videoobjectdefinitions.cameraalertstatus.motion && alarmlist.contains("motion")) { alarmtojournal = true; if (isbegin) { // set motion property true. camera["motion"] = true; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "motion" }, new object[] { true }); } else { // set motion property false. camera["motion"] = false; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "motion" }, new object[] { false }); } } // if alarm videoloss... if (status == ad.common.videoobjectdefinitions.cameraalertstatus.videoloss && alarmlist.contains(status.tostring().tolower())) { alarmtojournal = true; if (isbegin) { // set videoloss property true. camera[camerakey.videoloss] = true; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { camerakey.videoloss }, new object[] { true }); } else { // set videoloss property false; camera[camerakey.videoloss] = false; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { camerakey.videoloss }, new object[] { false }); } } // if alarm light... if (status == ad.common.videoobjectdefinitions.cameraalertstatus.lightchange && alarmlist.contains("light")) { alarmtojournal = true; if (isbegin) { // set light property true. camera["light"] = true; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "light" }, new object[] { true }); } else { // set light property false; camera["light"] = false; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "light" }, new object[] { false }); } } // if alarm perimeter... if (status == ad.common.videoobjectdefinitions.cameraalertstatus.perimeterprotection && alarmlist.contains("perimeter")) { alarmtojournal = true; if (isbegin) { // set perimeter property true. camera["perimeter"] = true; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "perimeter" }, new object[] { true }); } else { // set light property false; camera["perimeter"] = false; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "perimeter" }, new object[] { false }); } } // if alarm alarmin(drycontact)... if ((status == ad.common.videoobjectdefinitions.cameraalertstatus.externalalarm || status == ad.common.videoobjectdefinitions.cameraalertstatus.drycontact) && alarmlist.contains("alarmin")) { alarmtojournal = true; if (isbegin) { // set alarmin property true. camera["alarmin"] = true; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "alarmin" }, new object[] { true }); } else { // set alarmin property false; camera["alarmin"] = false; clientserverconnection.instance.updateobject(camera.objectkey, new string[] { "alarmin" }, new object[] { false }); } } if(alarmtojournal) msgformatparameters = createmessageparameters(status, camera, dso, time); } } } catch (exception) { } { _alarmmutex.releasemutex(); } }
i want @ function in debugger select ip value function output of !clrstack. (04d47f23)
i following:
0:018> !u /d 04d47f23 normal jit generated code ad.hardwareinterface.intellexhardwareinterface.objectprocessor.cameraalarmactivate(int32, softwarehouse.crossfire.common.dataservicelayer.dataserviceobject, ad.common.videoobjectdefinitions.cameraalertstatus, boolean, system.datetime, system.collections.generic.dictionary`2<system.string,system.object> byref) begin 04d474d0, size a79 04d474d0 55 push ebp 04d474d1 8bec mov ebp,esp 04d474d3 57 push edi 04d474d4 56 push esi 04d474d5 53 push ebx 04d474d6 81ec10010000 sub esp,110h 04d474dc 8bf1 mov esi,ecx 04d474de 8dbd78ffffff lea edi,[ebp-88h] 04d474e4 b91e000000 mov ecx,1eh 04d474e9 33c0 xor eax,eax 04d474eb f3ab rep stos dword ptr es:[edi] 04d474ed 8bce mov ecx,esi 04d474ef 33c0 xor eax,eax 04d474f1 8945e8 mov dword ptr [ebp-18h],eax 04d474f4 898d74ffffff mov dword ptr [ebp-8ch],ecx 04d474fa 8bfa mov edi,edx 04d474fc 8b5d18 mov ebx,dword ptr [ebp+18h] 04d474ff 8b4508 mov eax,dword ptr [ebp+8] 04d47502 33d2 xor edx,edx 04d47504 8910 mov dword ptr [eax],edx 04d47506 8b8574ffffff mov eax,dword ptr [ebp-8ch] 04d4750c 8b4834 mov ecx,dword ptr [eax+34h] 04d4750f 8b01 mov eax,dword ptr [ecx] 04d47511 8b402c mov eax,dword ptr [eax+2ch] 04d47514 ff500c call dword ptr [eax+0ch] 04d47517 e8d4ad4bfe call 032022f0 (softwarehouse.crossfire.common.core.typemanager.get_instance(), mdtoken: 010acf2c) 04d4751c 8bc8 mov ecx,eax 04d4751e 8b158c28b501 mov edx,dword ptr ds:[1b5288ch] ("softwarehouse.nextgen.common.securityobjects.videocamera") 04d47524 3909 cmp dword ptr [ecx],ecx 04d47526 e8e5d04bfe call 03204610 (softwarehouse.crossfire.common.core.typemanager.get_item(system.string), mdtoken: 010acf2c) 04d4752b 8945dc mov dword ptr [ebp-24h],eax 04d4752e 8bc8 mov ecx,eax 04d47530 33d2 xor edx,edx 04d47532 e853134274 call clr!runtimetypehandle::typeeq (7916888a) 04d47537 85c0 test eax,eax 04d47539 7418 je <unloaded_avcodec-53.dll>+0x8e7553 (04d47553) 04d4753b c745e400000000 mov dword ptr [ebp-1ch],0 04d47542 c745e8fc000000 mov dword ptr [ebp-18h],0fch 04d47549 68377fd404 push offset <unloaded_avcodec-53.dll>+0x8e7f37 (04d47f37) 04d4754e e9c7090000 jmp <unloaded_avcodec-53.dll>+0x8e7f1a (04d47f1a) 04d47553 e878ca4bfe call 03203fd0 (softwarehouse.crossfire.common.clientinterfacelayer.clientserverconnection.get_instance(), mdtoken: 010acf2c) 04d47558 898534ffffff mov dword ptr [ebp-0cch],eax 04d4755e ba02000000 mov edx,2 04d47563 b9e2428879 mov ecx,offset mscorlib_ni+0x42e2 (798842e2) 04d47568 e853acc3fb call 009821c0 (jithelp: corinfo_help_newarr_1_obj) 04d4756d 89856cffffff mov dword ptr [ebp-94h],eax 04d47573 b97829ba79 mov ecx,offset mscorlib_ni+0x322978 (79ba2978) (mt: system.int32) 04d47578 e8a3aac3fb call 00982020 (jithelp: corinfo_help_newsfast) 04d4757d 8bf0 mov esi,eax 04d4757f 8b856cffffff mov eax,dword ptr [ebp-94h] 04d47585 8945b0 mov dword ptr [ebp-50h],eax 04d47588 897e04 mov dword ptr [esi+4],edi 04d4758b 56 push esi 04d4758c 8b8d6cffffff mov ecx,dword ptr [ebp-94h] 04d47592 33d2 xor edx,edx 04d47594 e8fb584574 call clr!jit_stelem_ref (7919ce94) 04d47599 8b15002ab501 mov edx,dword ptr ds:[1b52a00h] ("objectid") 04d4759f 8b4d1c mov ecx,dword ptr [ebp+1ch] 04d475a2 8b01 mov eax,dword ptr [ecx] 04d475a4 8b4034 mov eax,dword ptr [eax+34h] 04d475a7 ff5014 call dword ptr [eax+14h] 04d475aa 8bf8 mov edi,eax 04d475ac 813f7829ba79 cmp dword ptr [edi],offset mscorlib_ni+0x322978 (79ba2978) 04d475b2 740c je <unloaded_avcodec-53.dll>+0x8e75c0 (04d475c0) 04d475b4 8bd7 mov edx,edi 04d475b6 b97829ba79 mov ecx,offset mscorlib_ni+0x322978 (79ba2978) (mt: system.int32) 04d475bb e85e614274 call clr!jit_unbox (7916d71e) 04d475c0 b97829ba79 mov ecx,offset mscorlib_ni+0x322978 (79ba2978) (mt: system.int32) 04d475c5 e856aac3fb call 00982020 (jithelp: corinfo_help_newsfast) 04d475ca 8bf0 mov esi,eax 04d475cc 8b856cffffff mov eax,dword ptr [ebp-94h] 04d475d2 8945ac mov dword ptr [ebp-54h],eax 04d475d5 8b4704 mov eax,dword ptr [edi+4] 04d475d8 894604 mov dword ptr [esi+4],eax 04d475db 56 push esi 04d475dc 8b8d6cffffff mov ecx,dword ptr [ebp-94h] 04d475e2 ba01000000 mov edx,1 04d475e7 e8a8584574 call clr!jit_stelem_ref (7919ce94) 04d475ec 8b8534ffffff mov eax,dword ptr [ebp-0cch] 04d475f2 3900 cmp dword ptr [eax],eax 04d475f4 ff358833b101 push dword ptr ds:[1b13388h] ("number = ? , serverid = ?") 04d475fa ffb56cffffff push dword ptr [ebp-94h] 04d47600 6a01 push 1 04d47602 6a00 push 0 04d47604 8b55dc mov edx,dword ptr [ebp-24h] 04d47607 8bc8 mov ecx,eax 04d47609 ff15c05a9900 call dword ptr ds:[995ac0h] (softwarehouse.crossfire.common.clientinterfacelayer.clientserverconnection.findobject(system.type, system.string, system.object[], boolean, softwarehouse.crossfire.common.core.remoteproxyoption), mdtoken: 010acf2c) 04d4760f 8bd0 mov edx,eax 04d47611 b9a0576e03 mov ecx,36e57a0h (mt: softwarehouse.crossfire.common.dataservicelayer.dataserviceobject) 04d47616 e8b7584574 call clr!jit_isinstanceofclass (7919ced2) 04d4761b 8bf8 mov edi,eax 04d4761d 85ff test edi,edi 04d4761f 0f84e0080000 je <unloaded_avcodec-53.dll>+0x8e7f05 (04d47f05) 04d47625 b918889503 mov ecx,3958818h (mt: ad.common.videoobjectdefinitions.cameraalertstatus) 04d4762a e8f1a9c3fb call 00982020 (jithelp: corinfo_help_newsfast) 04d4762f 8bf0 mov esi,eax
is there way can tell throwing exception???
since have debugger catching exception , have determined exception being thrown method named 'cameraalarmactivate', set breakpoint @ top of method , step through until exception hits. can inspect variables , troubleshoot accordingly.
from exception object can more information.
// stack trace exception source file information var st = new stacktrace(ex, true); // top stack frame var frame = st.getframe(0); // line number stack frame var line = frame.getfilelinenumber();
from here: c# - line number threw exception
in general isn't practice have empty exception handler's because errors can go unnoticed. suggest @ least integrating logging library application has own log file , writing error log entry exceptions. can write other verbose type of logs can trace through applications state via log file after error has occurred. helpful windows service or background based job errors can happen @ place. log4net logging library easy use: http://logging.apache.org/log4net/
other that, wild guess quick @ code client connection dropping @ point , clientserverconnection or clientserverconnection.instance become null @ point. example of can within exception block. catch specific exception , re-connect , re-try.
lastly, might missing symbols debug function more detail, or may have enable of options project related debugging unmanaged code.
Comments
Post a Comment