Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to get StackTrace from exception minidump #44

Open
dedmen opened this issue Jun 15, 2021 · 0 comments
Open

Ability to get StackTrace from exception minidump #44

dedmen opened this issue Jun 15, 2021 · 0 comments

Comments

@dedmen
Copy link

dedmen commented Jun 15, 2021

I have a exception on Thread 10320.
But when I just try to read the StackTrace from the thread I get pure garbage.

devenv_JkYlc8CVH5

I can even reproduce this in WinDbg

0:010> .cxr
Resetting default scope
0:010> k
 # Child-SP          RetAddr           Call Site
00 0000008c`6c7fbe18 00007ffe`5978d23b ntdll!NtGetContextThread+0x14
01 0000008c`6c7fbe20 000001bd`63871bfc ntdll!RtlpLocateActivationContextSection+0x13f
02 0000008c`6c7fbec0 00000000`00000002 0x000001bd`63871bfc
03 0000008c`6c7fbec8 00000000`00000002 0x2
04 0000008c`6c7fbed0 0000bddf`f1f90000 0x2
05 0000008c`6c7fbed8 0000bddf`f1f95675 0x0000bddf`f1f90000
06 0000008c`6c7fbee0 00000000`00000000 0x0000bddf`f1f95675

Current thread is just garbage. But if I switch context to the exception and dump the StackTrace again

0:010> .ecxr
rax=00007ff795801fd8 rbx=0000000000000001 rcx=000001bd27a7ff50
rdx=00007ff7958cad88 rsi=000001be54f6a050 rdi=0000000000000000
rip=00007ff7950116ef rsp=0000008c6c7ff1c8 rbp=0000000000000003
 r8=0000000000000000  r9=000000000000000e r10=0000000000000004
r11=0000008c6c7ff1c0 r12=0000000000000001 r13=000001bed219ffc0
r14=0000008c6c7ffa70 r15=0000000000000001
iopl=0         nv up ei pl nz na po nc
cs=0033  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010206
Arma3_x64!XX::GetClamp+0xf:
00007ff7`950116ef 48ffa0b0000000  jmp     qword ptr [rax+0B0h] ds:00007ff7`95802088={Arma3_x64!XX (00007ff7`9434cfd0)}
0:010> k
  *** Stack trace for last set context - .thread/.cxr resets it
 # Child-SP          RetAddr           Call Site
00 0000008c`6c7ff1c8 00007ff7`94fb809d Arma3_x64!XXX::GetClamp+0xf [X]
01 0000008c`6c7ff1d0 00007ff7`94f834b4 Arma3_x64!XXX::SetTextureAndMaterial+0x1fd [X]
02 0000008c`6c7ff2e0 00007ff7`94fa1973 Arma3_x64!XXX::DoPrepareTriangle+0x1444 [X]
03 0000008c`6c7ff390 00007ff7`94a22519 Arma3_x64!XXX+0x1e3 [X]
04 0000008c`6c7ff470 00007ff7`94a75bbd Arma3_x64!XXXL+0x1e9 X]
05 0000008c`6c7ff5d0 00007ff7`94a75887 Arma3_x64!XXX+0x29d [X]
06 0000008c`6c7ff740 00007ff7`94e169d6 Arma3_x64!XXX+0x187 [X]
07 0000008c`6c7ff7f0 00007ff7`94df1048 Arma3_x64!XXX+0x376 [X]
08 0000008c`6c7ff9e0 00007ff7`94f41bde Arma3_x64!XXXk::operator()+0xe8 [X]
09 0000008c`6c7ffa70 00007ff7`94f41fb7 Arma3_x64!XXX+0x12e [X]
0a 0000008c`6c7ffab0 00007ffe`57ab7034 Arma3_x64!InheritFPUSettings+0x57 [X]
0b 0000008c`6c7ffae0 00007ffe`597c2651 kernel32!BaseThreadInitThunk+0x14
0c 0000008c`6c7ffb10 00000000`00000000 ntdll!RtlUserThreadStart+0x21

Everything works perfectly fine.

I just cannot figure out how to do it in SharpDebug, well I know how to do it, but not how to do it with the API limitations.
There doesn't seem to be any API to switch the current context to the SharpDebug.DebugEventInfo.LastEvent

My hacky workaround is

using (ThreadSwitcher switcher = new ThreadSwitcher(StateCache, thread))

Make a copy of this method and remove the thread switcher which would reset the context to the thread.

And then do a very hacky

SharpDebug.Engine.Debuggers.DbgEngDll.ExecuteAndCapture(".ecxr");
var Adbg = SharpDebug.Engine.Context.Debugger as SharpDebug.Engine.Debuggers.DbgEngDll;
var Actx = Adbg.GetStackTraceFromContext(SharpDebug.Thread.Current, IntPtr.Zero, 0);

Basically change the context to the exception inside dbgeng, and then get stack from current active context (without setting context to thread again via the ThreadSwitcher)

This way works perfectly fine. But its quite a stupid solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant