http://blogs.msdn.com/debuggingtoolbox/archive/2007/03/18/windbg-script-digging-the-call-stack.aspx
글 : Roberto Alexis Farah 번역 : 이태화
안녕하세요 오랜만에 글을 번역해 보는군요 정말 많은 글들이 있는데 시간이 부족하여 많은 정보를 전달해 드리지 못해서 죄송 ^^;
--------------------------------------------------------------------------------
Windbg 는 많은 command 와 command 변형을 가지고 있어서 command 을 잊어 버리기도 합니다. 예를 들어 call stack 에서 보다 많은 정보를 얻고자 하는데 command 가 기억나지 않을때 call stack 정보를 자세히 보는 command 는 기억하고 있는데 전체 stack 을 보고자 할때 stack 정보, local 변수 정보등을 command 를 type 하지 않고 빠르게 보고자 할때..
이런 시나리오에 적합한 script 를 제공하고자 합니다.
이 script 는 call stack 에서 아래의 정보를 빠르게 볼 수 있게 해줍니다. - ANSI strings. - Unicode strings. - Symbols. - Pointer 참조. - 해당 frame 의 Local 변수variables by frames. (symbol 이 있어야 합니다.)
Interface 는 매우 간단하나 멋집니다.. 저는 GUI 팀에 있지 않습니다.
아래에는 두개의 screenshot 이 있습니다.
코드 설명 : d 명령과 k 명령을 사용하여 현재의 stack 부터 stackbase 까지 메모리와 stack 보여주는 예제입니다.
참고
d - memory 를 보여주는 명령 dp - computer 의 pointer-size 에 맞게 메모리를 보여주는 명령 32Bit 에서는 4byte 64Bit 에서는 8Byte du - Unicode 로 보여주기 da - ASCII 로 보여주기 s - Symbol 보여주기
k - stack frame 을 보여주는 명령 kp - stack 의 모든 parameter 를 보여줍니다. M - 이것에 대한 설명은 Windbg Help 에 없네요
$csp 현재 call stack pointer. x86-based processors: The same as esp. Itanium-based processors: The same as bsp. x64-based processors: The same as rsp. $teb The address of the thread environment block (TEB) of the current thread.
ad : 별명 삭제 이 예제에서는 ScriptName 을 삭제
@$teb+0x4 는 StackBase 값이다. 1: kd> dt _TEB ntdll!_TEB +0x000 NtTib : _NT_TIB 1: kd> dt _nt_tib BTScan!_NT_TIB +0x000 ExceptionList : Ptr32 _EXCEPTION_REGISTRATION_RECORD +0x004 StackBase : Ptr32 Void Source code - DIG_STACK.TXT: $$ $$ ============================================================================= $$ Dig information from the current call stack: $$ - Unicode Strings $$ - ANSI Strings $$ - Symbols $$ - Pointer references $$ - Local variables by frames $$ $$ Compatibility: Win32, should work on Win64. $$ $$ Usage: $$>< to run the script. $$ $$ If necessary change the filename below to include your path and filename. $$ By default it uses the WinDbg path and the default file name is DIG_STACK.TXT $$ $$ Roberto Alexis Farah $$ Blog: http://blogs.msdn.com/debuggingtoolbox/ $$ $$ All my scripts are provided "AS IS" with no warranties, and confer no rights. $$ ============================================================================= $$ ad /q * .block { as ScriptName MYSCRIPTS\\DIG_STACK.txt } .block { .printf /D "<link cmd=\"dpu @$csp poi(@$teb+0x4);ad /q *; $$><${ScriptName}\"><b>Unicode Strings</b></link>\n\n" .printf /D "<link cmd=\"dpa @$csp poi(@$teb+0x4);ad /q *; $$><${ScriptName}\"><b>ANSI Strings</b></link>\n\n" .printf /D "<link cmd=\"dps @$csp poi(@$teb+0x4);ad /q *; $$><${ScriptName}\"><b>Symbols</b></link>\n\n" .printf /D "<link cmd=\"dpp @$csp poi(@$teb+0x4);ad /q *; $$><${ScriptName}\"><b>Pointer References</b></link>\n\n" .printf /D "<link cmd=\"kpM 2000;ad /q *; $$><${ScriptName}\"><b>Local Variables by Frames</b></link>\n" } $$ ===========================================================================