2011. 10. 14. 11:24

WinDbg 를 이용한 분석 (1) - 예제

00400000 00413000 image00400000 C (no symbols)
71710000 71794000 comctl32 (deferred)
77980000 77a1b000 oleaut32 (deferred)
77de0000 77e49000 user32 (deferred)
77e50000 77f32000 kernel32 (deferred)
77f40000 77f7c000 GDI32 (deferred)
77f80000 77ffc000 ntdll (pdb symbols) c:\websymbols\ntdll.pdb\41AFDCD61\ntdll.pdb
786f0000 7875f000 RPCRT4 (deferred)
796d0000 79735000 ADVAPI32 (deferred)
7cf00000 7cfef000 ole32 (deferred)

- .help : 메타명령어 (.명령) 도움말

- .hh : DEBUGGER.CHM 명령 띄우기.

- ~ Thread 관련 명령

Threads can only be specified in user mode. In kernel mode, the tilde (~) refers to a processor.

Also note that many commands can be preceded by a thread symbol. For an explanation of a tilde (~) followed by a command, see the entry for the command itself.

Here are examples of the use of this command. The following command will display all threads:

0:001> ~

The following command will also display all threads:

0:001> ~*

The following command will display the currently active thread:

0:001> ~.

The following command will display the thread that originally caused the exception (or that was active when the debugger attached to the process):

0:001> ~#

The following command will display thread number 2:

0:001> ~2

Here is an example of the output of this command:

0:001> ~
0 id: 4dc.470 Suspend: 0 Teb 7ffde000 Unfrozen
. 1 id: 4dc.534 Suspend: 0 Teb 7ffdd000 Unfrozen
# 2 id: 4dc.5a8 Suspend: 0 Teb 7ffdc000 Unfrozen

On the first line of this example, 0 is the decimal thread number; 4DC is the hexadecimal process ID, 470 is the hexadecimal thread ID, 0x7FFDE000 is the address of the TEB, and Unfrozen is the thread status. The period (.) before thread 1 means this is the current thread. The number sign (#) before thread 2 means this thread was the one that originally caused the exception or it was ctive when the debugger attached to the rocess.

- LD : (load Symbols)

0:000> ld ole32
Symbols loaded for ole32
0:000> lm
start end module name
00400000 00413000 image00400000 C (no symbols)
71710000 71794000 comctl32 (deferred)
77980000 77a1b000 oleaut32 (deferred)
77de0000 77e49000 user32 (deferred)
77e50000 77f32000 kernel32 (deferred)
77f40000 77f7c000 GDI32 (deferred)
77f80000 77ffc000 ntdll (pdb symbols) c:\websymbols\ntdll.pdb\41AFDCD61\ntdll.pdb
786f0000 7875f000 RPCRT4 (deferred)
796d0000 79735000 ADVAPI32 (deferred)
7cf00000 7cfef000 ole32 (pdb symbols) c:\websymbols\ole32.pdb\42CABEE01\ole32.pdb
0:000> ld kernel32
Symbols loaded for kernel32
0:000> lm
start end module name
00400000 00413000 image00400000 C (no symbols)
71710000 71794000 comctl32 (deferred)
77980000 77a1b000 oleaut32 (deferred)
77de0000 77e49000 user32 (deferred)
77e50000 77f32000 kernel32 (pdb symbols) c:\websymbols\kernel32.pdb\4498D8981\kernel32.pdb
77f40000 77f7c000 GDI32 (deferred)
77f80000 77ffc000 ntdll (pdb symbols) c:\websymbols\ntdll.pdb\41AFDCD61\ntdll.pdb
786f0000 7875f000 RPCRT4 (deferred)
796d0000 79735000 ADVAPI32 (deferred)
7cf00000 7cfef000 ole32 (pdb symbols) c:\websymbols\ole32.pdb\42CABEE01\ole32.pdb
0:000> ld *
Symbols already loaded for image00400000
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINNT\system32\comctl32.dll -
Symbols loaded for comctl32
Symbols loaded for oleaut32
Symbols loaded for user32
Symbols already loaded for kernel32
Symbols loaded for GDI32
Symbols already loaded for ntdll
Symbols loaded for RPCRT4
Symbols loaded for ADVAPI32
Symbols already loaded for ole32
0:000> lm
start end module name
00400000 00413000 image00400000 C (no symbols)
71710000 71794000 comctl32 (export symbols) C:\WINNT\system32\comctl32.dll
77980000 77a1b000 oleaut32 (pdb symbols) c:\websymbols\oleaut32.pdb\3DF8FF78\oleaut32.pdb
77de0000 77e49000 user32 (pdb symbols) c:\websymbols\user32.pdb\4211D1FD1\user32.pdb
77e50000 77f32000 kernel32 (pdb symbols) c:\websymbols\kernel32.pdb\4498D8981\kernel32.pdb
77f40000 77f7c000 GDI32 (pdb symbols) c:\websymbols\gdi32.pdb\43B3D6741\gdi32.pdb
77f80000 77ffc000 ntdll (pdb symbols) c:\websymbols\ntdll.pdb\41AFDCD61\ntdll.pdb
786f0000 7875f000 RPCRT4 (pdb symbols) c:\websymbols\rpcrt4.pdb\41E6468F7\rpcrt4.pdb
796d0000 79735000 ADVAPI32 (pdb symbols) c:\websymbols\advapi32.pdb\4253BAFE1\advapi32.pdb
7cf00000 7cfef000 ole32 (pdb symbols) c:\websymbols\ole32.pdb\42CABEE01\ole32.pdb


심볼에 대한 자세한 정보를 얻고자 하는 경우
0:000> lm v m gdi32
start end module name
77f40000 77f7c000 GDI32 (pdb symbols) c:\websymbols\gdi32.pdb\43B3D6741\gdi32.pdb
Loaded symbol image file: c:\websymbols\gdi32.dbg\43B3E1B73c000\gdi32.dbg
Image path: C:\WINNT\system32\GDI32.dll
Image name: GDI32.dll
Timestamp: Thu Dec 29 22:16:39 2005 (43B3E1B7)
CheckSum: 0003E315
ImageSize: 0003C000
File version: 5.0.2195.7073
Product version: 5.0.2195.7073
File flags: 0 (Mask 3F)
File OS: 40004 NT Win32
File type: 2.0 Dll
File date: 00000000.00000000
Translations: 0409.04b0
CompanyName: Microsoft Corporation
ProductName: Microsoft(R) Windows (R) 2000 Operating System
InternalName: gdi32
OriginalFilename: gdi32
ProductVersion: 5.00.2195.7073
FileVersion: 5.00.2195.7073
FileDescription: GDI Client DLL
LegalCopyright: Copyright (C) Microsoft Corp. 1981-1999


심볼서버

To use the Microsoft Symbol Server

1. Make sure you have installed the latest version of Debugging Tools for Windows.

2. Start a debugging session.

3. Decide where to store the downloaded symbols (the "downstream store"). This can be a local drive or a UNC path.

4. Set the debugger symbol path as follows, substituting your downstream store path for DownstreamStore.

SRV*DownstreamStore*http://msdl.microsoft.com/download/symbols

) SRV*c:\websymbols*http://msdl.microsoft.com/download/symbols

장애의종류

Crash: Heap Corrupt, AV(Access Violation)

Hang: Deal lock, Orphaned thread, contention..

Leak: Memory Leak

장애 종류에 따른 대처

Crash:

Access Violation

- adplus.vbs > CDB 사용

- Tlist process id확인 (id)

- Adplus.vbs –crash –p pid : Crash 발생하면 메모리 덤프를 생성

Heap Corrupt

- page heap: heap영역에 할당된 메모리의 영역을 체크함. 범위를 초과하는 경우 프로세스를 종료시킴.

- gflags.exe 성능을 떨어뜨릴 있으면 덤프를 뜨고나면 disable 시켜야 한다.

http://support.microsoft.com/kb/286470/ : 마이크로 소프트의 페이지

시스템 범위 페이지 힙에 GFlags 사용

GFlags 도구는 시스템 범위 페이지 힙을 설정하는 사용됩니다. GFlags 명령을 적용하려면 명령을 실행한 컴퓨터를 다시 시작해야 합니다.

시스템 범위 일반 페이지 힙을 설정하려면 다음과 같이 하십시오. 1. 명령줄에 다음을 입력합니다.

gflags -r +hpa

2. 컴퓨터를 다시 시작합니다.

시스템 범위 일반 페이지 힙을 해제하려면 다음과 같이 하십시오. 1. 명령줄에 다음을 입력합니다.

gflags -r -hpa

2. 컴퓨터를 다시 시작합니다.

단일 프로세스 페이지 힙에 GFlags 사용

특정 프로세스를 모니터링하기 위해 페이지 힙을 사용할 있도록 설정할 있습니다. 이렇게 하려면 다음 단계를 수행하십시오.

1. 명령 프롬프트에서 디버그 도구를 설치한 디렉터리로 변경합니다.

2. 명령 프롬프트에서 다음을 입력한 Enter 키를 누릅니다.

Gflags.exe –p /enable lsass.exe

참고 lsass.exe Pageheap 도구로 모니터링할 프로세스의 이름을 나타냅니다.

3. 페이지 모니터링이 이상 필요하지 않으면 모니터링을 해제합니다. 수신 대기 포트의 목록을 얻으려면 프롬프트에서 다음 명령을 입력하고 Enter 키를 누릅니다.

Gflags.exe -p /disable lsass.exe

참고 lsass.exe Pageheap 도구로 모니터링할 프로세스의 이름을 나타냅니다.

4. 현재 Pageheap 확인을 사용하는 모든 프로그램을 표시하려면 명령 프롬프트에서 다음을 입력한 다음 Enter 키를 누릅니다.

Gflags.exe –p

* Hang 장애

Deadlock, 무한 루프(while(true){ … } )등의 로직 관련 문제.

- Hang dump 받는다. Hang dump 이상 받아서 체크하도록 한다.

Adplus.vbs –hang –p pid(process id)

- Deallock이나 lock 문제가 되는 경우에는 Windbg !lock 통해서 현재 lock 가장 많이 잡고 있는 Thread등을 조사하여 본다.

* 메모리 누수

Windows 2000/XP, 2003 이상의 경우

- DebugDiag라는 메모리 누수 감지 공개소프트웨어를 사용하고, perfmon(성능 모니터)에서 process private bytes, virtual Bytes 살펴보아서 private bytes 지속적인 증가, virtual Bytes 계단식 증가를 살펴보도록 한다.