debugging in windows env

53
Debugging Debugging in Windows Env in Windows Env Feb, 2004 Feb, 2004 Kim, Hyungsik Kim, Hyungsik Consultant Consultant [email protected] [email protected] Microsoft Korea Microsoft Korea

Upload: remedios-graves

Post on 01-Jan-2016

88 views

Category:

Documents


0 download

DESCRIPTION

Debugging in Windows Env. Feb, 2004 Kim, Hyungsik Consultant [email protected] Microsoft Korea. 목차. Introduction 문제의 종류 , 디버깅 방법 분류 , 용어설명 , 무엇이 필요한가 ? Debuggers, Debugging Tool list up 디버깅 툴 설치 디렉토리 살펴보기 Exception Flow 이해 Demo : 디버거 설치 덤프 수집하기 덤프 분석하기 주요 상황별 Player 이해 - PowerPoint PPT Presentation

TRANSCRIPT

DebuggingDebuggingin Windows Envin Windows Env

Feb, 2004Feb, 2004Kim, HyungsikKim, Hyungsik

ConsultantConsultant

[email protected]@microsoft.com

Microsoft KoreaMicrosoft Korea

목차목차► IntroductionIntroduction

문제의 종류문제의 종류 , , 디버깅 방법 분류디버깅 방법 분류 , , 용어설명용어설명 , , 무엇이 필요한가무엇이 필요한가 ?? Debuggers, Debugging Tool list upDebuggers, Debugging Tool list up 디버깅 툴 설치 디렉토리 살펴보기디버깅 툴 설치 디렉토리 살펴보기 Exception Flow Exception Flow 이해이해

► Demo : Demo : 디버거 설치디버거 설치► 덤프 수집하기덤프 수집하기► 덤프 분석하기덤프 분석하기► 주요 상황별 주요 상황별 Player Player 이해이해

Inetinfo.exe, dllhost.exe, aspnet_wp.exe Inetinfo.exe, dllhost.exe, aspnet_wp.exe 등등 ....► Live Debugging Live Debugging 데모데모► 심벌 생성하기심벌 생성하기► Debugging Debugging 상황별 대처 시나리오상황별 대처 시나리오► Art of DebuggingArt of Debugging► ReferencesReferences► SummarySummary

문제문제 (Bug)(Bug) 의 종류의 종류

►Crash – Crash – 비정상종료비정상종료 Access Violation – Access Violation – 자주 일어나는 케이스자주 일어나는 케이스 Crash Crash 란 말보다 란 말보다 AVAV 란 말을 더 많이 사용하는 듯란 말을 더 많이 사용하는 듯 ....

►Hang – Hang – 모호한 말모호한 말 , , 여러 케이스여러 케이스 CPU 100%CPU 100% LockLock IO PendingIO Pending

►Memory LeakMemory Leak►논리적인 오류논리적인 오류► 그외그외……

Debugging Debugging 이란이란 ??

► Debugger Debugger 및 및 Debugging ToolDebugging Tool 를 이용해서 문제를 를 이용해서 문제를 해결하는 과정해결하는 과정

► Debugging Debugging 대상에 의한 분류대상에 의한 분류 Kernel Mode DebuggingKernel Mode Debugging

► Drivers, File Systems, Operating System componentsDrivers, File Systems, Operating System components► Kernel Kernel 의 문제 생기면 블루스크린 의 문제 생기면 블루스크린

User Mode DebuggingUser Mode Debugging► User ApplicationUser Application 도 문제가 발생할 수 있다도 문제가 발생할 수 있다 . .

이 경우 이 경우 User AppUser App 만 종료됨만 종료됨 ..

► Debugging Debugging 방법에 의한 분류방법에 의한 분류 Dump Debugging – DumpDump Debugging – Dump 화일로 분석화일로 분석 Interactive(Live)Interactive(Live) Debugging – Debugging – 실행시 실행시 Debuggee Debuggee 에 에 AttachAttach

용어 설명용어 설명► DumpDump

특정 시점에 특정 프로세스의 메모리 이미지를 디스크에 적은 것특정 시점에 특정 프로세스의 메모리 이미지를 디스크에 적은 것► Checked Build and Free BuildChecked Build and Free Build

디버깅정보를 포함한 버젼 디버깅정보를 포함한 버젼 (Checked or Debug Build)(Checked or Debug Build) 디버깅정보가 없는 버젼디버깅정보가 없는 버젼 ,, 속도향상 속도향상 (Free or Release Build)(Free or Release Build)

► ExceptionException 소프트웨어 혹은 하드웨어에서 발생하는 이벤트소프트웨어 혹은 하드웨어에서 발생하는 이벤트 대부분 대부분 Bad EventBad Event 를 의미하며 대부분 소프트웨어에서 발생함를 의미하며 대부분 소프트웨어에서 발생함 .. First Chance First Chance 와 와 Second ChanceSecond Chance 로 구별됨로 구별됨 . .

► SymbolsSymbols Q121366Q121366 Binary Binary 화일이 메모리에 로드된 주소를 기준으로화일이 메모리에 로드된 주소를 기준으로 실제함수명실제함수명 ++

변수명등의 매칭 기능 제공변수명등의 매칭 기능 제공► AttachAttach

디버거가 디버깅 할 대상 프로세스에 디버거가 디버깅 할 대상 프로세스에 ConnectConnect 하는 것하는 것

Dump Dump 수집기수집기 DebuggerDebugger 심벌심벌 소스 코드소스 코드

위로부터 순차적으로 중요위로부터 순차적으로 중요 . . 심벌이 없어도 일단 어는 모듈이 문제인지는 심벌이 없어도 일단 어는 모듈이 문제인지는 알수 있고알수 있고 , , 소스가 없어도 함수명은 알아낼수 있음소스가 없어도 함수명은 알아낼수 있음 ..

DebuggingDebugging 을 위해 필요한 것을 위해 필요한 것

CDB/NTSDCDB/NTSD►CDB and NTSD CDB and NTSD 는 콘솔 어플리케이션임는 콘솔 어플리케이션임 . .

Windows NT Windows NT 이상에 사용 가능이상에 사용 가능 WindbgWindbg

►GUI GUI 지원하는 디버거 지원하는 디버거 Windows NT, Win2000, WinMeWindows NT, Win2000, WinMe

MSDEVMSDEV►DevStudio is a GUI based tool DevStudio is a GUI based tool

( including a debugger) that allows ( including a debugger) that allows editing, compiling and debugging editing, compiling and debugging programsprograms

►All Platform including All Platform including Win95/98Win95/98

DebuggersDebuggers

Dump catchers Dump catchers (( 덤프 수집기덤프 수집기 ))

UserDump (First Chance Exception)UserDump (First Chance Exception) 수동 덤프 수집시 사용수동 덤프 수집시 사용 자동으로 덤프 수집시에도 사용됨자동으로 덤프 수집시에도 사용됨 .(Service.(Service 로 동작로 동작 ))

► Doctor Watson (Second Chance)Doctor Watson (Second Chance) Drwtsn32, Drwtsn32 -iDrwtsn32, Drwtsn32 -i 22ndnd chance exception chance exception 발생하여 프로세스 비 정상 종료시 덤프 및 발생하여 프로세스 비 정상 종료시 덤프 및

분석로그 생성 분석로그 생성

► Adplus.vbs (First Chance , Second Chance)Adplus.vbs (First Chance , Second Chance) 내부적으로 내부적으로 CDB CDB 사용하여 덤프및 로그 생성사용하여 덤프및 로그 생성 Adplus –crash –pn inetinfo.exeAdplus –crash –pn inetinfo.exe Adplus –crash –iis Adplus –crash –iis Adplus –hang –iisAdplus –hang –iis

► Windbg, CDB Windbg, CDB 도 커맨드 이용하여 덤프 수집 가능함도 커맨드 이용하여 덤프 수집 가능함 ..

Memleak Memleak 관련 툴관련 툴

►UmdhUmdh 메모리 리크를 알아낼 때 사용됨메모리 리크를 알아낼 때 사용됨 .. Q268343Q268343

►GFlagsGFlags Heap Curruption Heap Curruption 점검시 사용점검시 사용 메모리 리크 점검시도 메모리 리크 점검시도 umdhumdh 와 같이 사용와 같이 사용

Demo :

Debugger 설치설치된 Folder 살펴 보기

Demo – Demo – 심벌 및 디버거 설치심벌 및 디버거 설치

► http://www.microsoft.com/whdc/ddk/debugghttp://www.microsoft.com/whdc/ddk/debugging/default.mspxing/default.mspx 최신 버젼 최신 버젼 Debugger Debugger 다운로드 가능다운로드 가능

► 각종 툴별 각종 툴별 Symbol Path Symbol Path 지정하는 법지정하는 법 CDB, DoctorWatsonCDB, DoctorWatson

► _NT_SYMBOL_PATH _NT_SYMBOL_PATH 환경변수환경변수 WindbgWindbg

WindbgWindbg► 메뉴에서 심벌 패스 지정하면 됨메뉴에서 심벌 패스 지정하면 됨 ..

Dump Dump 수집하기수집하기 , , Text LogText Log 분석분석

- Doctor Watson- Doctor Watson- Userdump- Userdump

- Adplus.vbs - Adplus.vbs

Doctor WatsonDoctor Watson

► Auto Debugger Auto Debugger 이해하기이해하기 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\

Windows NT\CurrentVersion\AeDebugWindows NT\CurrentVersion\AeDebug

► Drwtsn32Drwtsn32 drwtsn32 –i (default debuggerdrwtsn32 –i (default debugger 로 세팅로 세팅 )) drwtsn32 (drwtsn32 ( 설정값 설정화면 로드설정값 설정화면 로드 ))

► Drwtsn32Drwtsn32 는 이미 설치되어 있음는 이미 설치되어 있음 . . 별도의 설치 별도의 설치 작업은 필요 없음작업은 필요 없음 ..

Doctor Watson Log Doctor Watson Log 활용법활용법 독립적인 독립적인 exe exe 형태의 서비스 형태의 서비스 demon demon 같은 프로세스가 이상 종료시 같은 프로세스가 이상 종료시

유용하다유용하다 자체 핸들러가 있어서 자체 핸들러가 있어서 22ndnd chance chance 가 발생하지 않는 경우 가 발생하지 않는 경우 (COM+ (COM+

Compoent, Asp pages, asp.net pages) Compoent, Asp pages, asp.net pages) 에는 잘 사용되지 않는다에는 잘 사용되지 않는다 ..

꼭 덤프를 분석해야만 문제를 해결할수 있는 것은 아니다꼭 덤프를 분석해야만 문제를 해결할수 있는 것은 아니다 .. Doctor Watson LogDoctor Watson Log 도 충분히 활용하면 문제를 쉽게 해결할 수 있도 충분히 활용하면 문제를 쉽게 해결할 수 있

다다 .. LogLog 는 누적되므로 이전에 문제 생겼던 정보도 알수 있다는 누적되므로 이전에 문제 생겼던 정보도 알수 있다 .. LogLog 에서 정확한 모듈명에서 정확한 모듈명 ++ 함수명을 보여줄려면 미리 심벌패스가 함수명을 보여줄려면 미리 심벌패스가

_NT_SYMBOL_PATH_NT_SYMBOL_PATH 에 설치되어 있어야 한다에 설치되어 있어야 한다 .. 자체 핸들러가 없어서 이상 종료 하는 프로세스의 덤프 수집할려면 자체 핸들러가 없어서 이상 종료 하는 프로세스의 덤프 수집할려면

이게 좋은 방법이게 좋은 방법 22ndnd Chance Exception Chance Exception 수집수집

Userdump Userdump 사용해보기사용해보기

► Userdump Userdump 툴은 서비스로 동작하여 원하는 프로세스를 감시할 수 있다툴은 서비스로 동작하여 원하는 프로세스를 감시할 수 있다 ..► 특정 특정 ExceptionException 을 지정할 수 있다을 지정할 수 있다 . . 보통 보통 AVAV 만 지정하여 감시한다만 지정하여 감시한다 ..► 수동으로 덤프수집도 가능하다수동으로 덤프수집도 가능하다 .- .- 행 덤프시 사용행 덤프시 사용► Q241215 Q241215 에서 다운로드 할수 있음에서 다운로드 할수 있음 . (. ( 디버깅 툴과는 별도 설치 필요함디버깅 툴과는 별도 설치 필요함 .).)

UserdumpUserdump

► 수동 덤프 수집수동 덤프 수집 UserdumpUserdump 가 설치된 디렉토리에서 아래와 같이 키인가 설치된 디렉토리에서 아래와 같이 키인 Userdump –pUserdump –p

► 전체 프로세스 리스트 함전체 프로세스 리스트 함 ..

Userdump 1132 1132.dmpUserdump 1132 1132.dmp► Pid 1132 Pid 1132 덤프 수집하여 덤프 수집하여 1132.dmp 1132.dmp 화일로 저장화일로 저장

Userdump notepad.exe notepad.dmpUserdump notepad.exe notepad.dmp► Notepad.exe Notepad.exe 프로그램 덤프 수집하여 프로그램 덤프 수집하여 notepad.dmpnotepad.dmp 로 저장로 저장

► 수동 덤프 수집후 대상 수동 덤프 수집후 대상 application application 계속 런닝됨계속 런닝됨 ..► 11stst chance Exception chance Exception 수집수집

Adplus.vbs Adplus.vbs 사용하기사용하기

► Debugging Debugging 툴에 포함된 유틸리티툴에 포함된 유틸리티► 내부적으로는 내부적으로는 cdbcdb 를 사용하여 특정 를 사용하여 특정 AppApp 의 의 11stst

Exception Exception 및 및 22ndnd Exception Exception 에 반응하도록 코딩 에 반응하도록 코딩 되어 있음되어 있음 ..

► Vbs Vbs 화일의 내용을 고쳐서 동작을 커스터마이즈 화일의 내용을 고쳐서 동작을 커스터마이즈 할수 있음할수 있음 .. 11stst Exception Exception 시에도 시에도 Full Dump Full Dump 받으라고 할수 있받으라고 할수 있

음음 ..

► -crash mode-crash mode 는 는 Local ConsoleLocal Console 에서만 가능에서만 가능 (( 터미날 에서는 작동할 수 없음터미날 에서는 작동할 수 없음 ))

WinDBG WinDBG 와 친숙해지기와 친숙해지기

►Attaching to a ProcessAttaching to a Process►Starting a ProcessStarting a Process►Reading a Dump FileReading a Dump File►Common CommandsCommon Commands

k k for stacK for stacK lm lm for list modules for list modules ~ ~ lists all threads lists all threads ~ <thread number> ~ <thread number> changes to a specific thread changes to a specific thread

numbernumber ~*kb ~*kb lists the stacks for all threads in a process lists the stacks for all threads in a process gg Go (Start the process again) Go (Start the process again)

Basic Debugging CommandsBasic Debugging Commands► K,Kb,kpK,Kb,kp

To list the current threadTo list the current thread

► ~*k~*k To list all the threadTo list all the thread

► RR To dump the registersTo dump the registers

► Dd <address>Dd <address> Dump in DWORD from the specified addressDump in DWORD from the specified address

► Dv Dv Dump local variablesDump local variables

Basic Debugging CommandsBasic Debugging Commands (2) (2)

► !locks!locks To determine if there are any critical section To determine if there are any critical section

deadlocksdeadlocks

► !peb!peb To dump process environment blockTo dump process environment block

► !reload!reload To reload the symbolsTo reload the symbols

► UU Display in DisassemblyDisplay in Disassembly

Using WinDBG to view a .DMP file generated by UserDump or Dr. Watson

Demo – Open CrashDumpDemo – Open CrashDump

Attaching Process 기본 명령어 사용해 보기 kb, ~*kb, Call Stack, go

Breakpoint 사용해 보기

bp, bl, bc Symbol Path 재 지정후 다시로드 .reload

Exception Flow 보여주기

Demo – Attach Process Demo – Attach Process

Exception Exception 이해이해

1st Chance Exception 알림

Kernel

Debugger 가 처리하지 않으면Exception Handler 찾음

Handler Y/N?

2nd Chance Exception 알림

Program 종료

디버거

Exception 발생

Program 계속

Debugger 가 처리하지 않으면프로세스 종료

1

AdPlus 1st ,Userdump

AdPlus 2nd,DoctorWatson

2

Understanding Key PlayersUnderstanding Key Players

► Asp, Asp.net Asp, Asp.net 환경에서 환경에서 Process Process 연관도 연관도 이해하기이해하기 ..

► Virtual Dir Virtual Dir 설정에 따른 프로세스 연관도 이해설정에 따른 프로세스 연관도 이해► COM+ COM+ 사용시 사용시 Exception Flow Exception Flow 이해이해

IIS WebService IIS WebService 이해이해

► Debugging Debugging 대상을 이해하기 위해서 대상을 이해하기 위해서 IIS IIS Webservice Webservice 환경 이해 필요환경 이해 필요

► 실행환경별 구분실행환경별 구분 InProcess (inetinfo)InProcess (inetinfo) Isolated (Isolated ( 독자적 독자적 Dllhost)Dllhost) Pooled out of Process (Pooled Dllhost, Pooled out of Process (Pooled Dllhost,

Default)Default)

Web Application ArchitectureWeb Application Architecture

APP

DLLHOST.EXEA

SP

COM+ Application

DLLHOST.EXE

Initial: Number of CPUs + 7

APP

APP

APP

HTTP

Web A

ppli cat i on Manager

Port 80 INETINFO.EXE

GE

T

HTM

GIF

SMTP

FTPSVC

W3SVC ASP

AS

P

Po olT

hread Lim

it (2 x # MB

)M

axPoolT

hreads (4 x CP

Us)

ISAPI

IIS and ASP.NET RelationshipIIS and ASP.NET Relationship

호출상황별 호출상황별 Exception FlowException Flow

► AV InProc AV InProc 컴포넌트 컴포넌트 called by User Win32 Processcalled by User Win32 Process 11stst chance Exception chance Exception 발생발생 핸들러 있으면 계속 수행핸들러 있으면 계속 수행 , , 없으면 없으면 22ndnd Chance Chance 발생발생 . . 프로그램 종료프로그램 종료

► AV InProc AV InProc 컴포넌트 컴포넌트 called by ASP called by ASP 페이지페이지 Asp Asp 혹은 혹은 Asp.netAsp.net 은 기본적으로 자체 핸들러 있음은 기본적으로 자체 핸들러 있음 . . 11stst chance chance 만 발생후 계속 수행만 발생후 계속 수행

► AV Com+ AV Com+ 컴포넌트컴포넌트 (dllhost.exe) called by User Application(dllhost.exe) called by User Application COM+ Failfast COM+ Failfast 동작 동작 Com+Com+ 의 의 Dllhost.exe Dllhost.exe 에서 에서 11stst Chance Chance 만 발생후 만 발생후 dllhost.exedllhost.exe 종료종료 User ApplicationUser Application 은 핸들러 없으면 종료은 핸들러 없으면 종료 , , 있으면 계속 수행있으면 계속 수행

► AV Com+ AV Com+ 컴포넌트 컴포넌트 (dllhost.exe) called by Asp(dllhost.exe) called by Asp 페이지페이지 COM+ Failfast COM+ Failfast 동작 동작 Com+Com+ 의 의 Dllhost.exe Dllhost.exe 에서 에서 11stst Chance Chance 만 발생후 만 발생후 dllhost.exedllhost.exe 종료종료 AspAsp 페이지는 시스템 기본 에러 핸들러 따라감페이지는 시스템 기본 에러 핸들러 따라감 . .

COM+ FailfastCOM+ Failfast

► HKEY_LOCAL_MACHINE\Software\HKEY_LOCAL_MACHINE\Software\Microsoft\COM3Microsoft\COM3

► Add KeyAdd Key to create a new key named to create a new key named DebugDebug. . ► Under the newly created key, click Under the newly created key, click Add ValueAdd Value

on the on the EditEdit menu to add a string value named menu to add a string value named DebugBreakOnFailFastDebugBreakOnFailFast, and then click , and then click OKOK. .

► Set the value of the new string to Set the value of the new string to YY..► When the COM+ application failfasts, it displays When the COM+ application failfasts, it displays

the the Assertion FailedAssertion Failed dialog box. At this point, dialog box. At this point, you can obtain a dump with Userdump. you can obtain a dump with Userdump.

Developer 툴별

컴파일 옵션 및 심벌 생성하기

Developer Tools – VB 6.0Developer Tools – VB 6.0

► Visual Basic 6.0Visual Basic 6.0 Component CreationComponent Creation

► ActiveX DLL or ActiveX EXEActiveX DLL or ActiveX EXE Threading Models SupportedThreading Models Supported

► Apartment Model (STA)Apartment Model (STA)► SingleSingle

SymbolsSymbols► Can be generated by checking the “Symbolic Debug Can be generated by checking the “Symbolic Debug

Information” checkboxInformation” checkbox RecommendationsRecommendations

► ““Unattended Execution” and “Retain In Memory” must Unattended Execution” and “Retain In Memory” must be checked when using components within IIS/MTS be checked when using components within IIS/MTS environment environment (Q241896)(Q241896)

VB 6.0 VB 6.0 심볼 만들기심볼 만들기

VB Compile OptionVB Compile Option

““Unattended Execution” and “Retain In Memory” must be Unattended Execution” and “Retain In Memory” must be checked when using components within IIS/MTS checked when using components within IIS/MTS environment (Q241896)environment (Q241896)http://support.microsoft.com/default.aspx?scid=kb;en-http://support.microsoft.com/default.aspx?scid=kb;en-us;286036us;286036

VB Component VB Component 컴파일 옵션 점검 컴파일 옵션 점검 툴툴

► SAMPLE: Using VBCHKW2K to Isolate DLLs SAMPLE: Using VBCHKW2K to Isolate DLLs Compiled Without Retain In Memory and Compiled Without Retain In Memory and Unattended ExecutionUnattended Execution http://support.microsoft.com/default.aspx?scid=kb;en-http://support.microsoft.com/default.aspx?scid=kb;en-

us;286036us;286036

Developer ToolsDeveloper Tools►Visual C++ 6.0Visual C++ 6.0

Component CreationComponent Creation►Use the ATL WizardUse the ATL Wizard

Threading Models SupportedThreading Models Supported►Apartment, Free, Both, Both w/ FTMApartment, Free, Both, Both w/ FTM

SymbolsSymbols►Debug builds by defaultDebug builds by default►Release builds LinkRelease builds Link Debug under Project Settings.. Debug under Project Settings..

Production Production 서버에 올라간 버젼은 대부분 서버에 올라간 버젼은 대부분 Release Release ModeMode 일 것임일 것임 . . 그러면 그러면 Release Release 모드에서 모드에서 Debug Debug SymbolSymbol 을 만들어야 함을 만들어야 함 ..

VC 6.0 VC 6.0 심볼 만들기심볼 만들기 (Release Mode) (Release Mode) Q291585Q291585

VC 6.0 VC 6.0 심볼 만들기 심볼 만들기 (Release Mode)(Release Mode)

.NET.NET

디버깅 시나리오디버깅 시나리오

►Crash (AV)Crash (AV)►High CPU UtilizationHigh CPU Utilization►Memory LeakMemory Leak►Art of DebuggingArt of Debugging

Scenario 1: Access ViolationsScenario 1: Access Violations► 일반적인 원인일반적인 원인

Null pointer assignment/accessNull pointer assignment/access Stray pointers pointing to invalid Stray pointers pointing to invalid

memorymemory Array indices going out of rangeArray indices going out of range Non thread safe components in Non thread safe components in

multithreaded environmentmultithreaded environment For Visual Basic COM DLLs – unattended For Visual Basic COM DLLs – unattended

execution and retain in memory is not execution and retain in memory is not setset

Scenario 1: Access Violations (2)Scenario 1: Access Violations (2)

► DumpDump 를 수집 를 수집 (DrWatson , Userdump, adplus.vbs)(DrWatson , Userdump, adplus.vbs)

► Windbg Windbg 로 덤프 연다로 덤프 연다 ..► 문제를 일으킨 쓰레드의 문제를 일으킨 쓰레드의 call stack call stack 본다본다 ..► 문제를 일으킨 소스를 문제를 일으킨 소스를 reviewreview 한다한다 ..

Scenario 2: High CPU UtilizationScenario 2: High CPU Utilization

► CPUCPU 를 많이 사용하는 프로세스를 찾아내라를 많이 사용하는 프로세스를 찾아내라 .. 성능모니터 이용 아래 카운터 사용성능모니터 이용 아래 카운터 사용

► % processor time% processor time► Process IDProcess ID

Scenario 2: High CPU Utilization (2)Scenario 2: High CPU Utilization (2)

► 성능로그에서성능로그에서 , , 문제가되는 프로세스의 문제가되는 프로세스의 쓰레드별로 쓰레드별로 CPU CPU 사용량을 측정하라사용량을 측정하라 . (. ( 스레드 스레드 IDID 도 로깅도 로깅 ) ) Add following counter Add following counter Object = threadObject = thread Counter = ID threadCounter = ID thread Instance = highest CPU consuming processInstance = highest CPU consuming process

Scenario 2: High CPU Utilization (3)Scenario 2: High CPU Utilization (3)

► 문제가 되는 스레드 문제가 되는 스레드 IDID 를 알아낸다를 알아낸다 ..► UserDumpUserDump 를 사용하여 문제프로세스의 를 사용하여 문제프로세스의

덤프를 받는다덤프를 받는다 .. userdump <process ID> <dump userdump <process ID> <dump

file name>file name>► WindbgWindbg 로 덤프를 연후 문제가 된 로 덤프를 연후 문제가 된

쓰레드의 콜스택을 본다쓰레드의 콜스택을 본다 ..► 문제가되는 함수의 소스를 문제가되는 함수의 소스를 ReviewReview 한다한다 ..

Art of DebuggingArt of Debugging

► 고객의 말은 반만 믿어라고객의 말은 반만 믿어라 .. 자신이 정확한 현상 데이타를 보기전에는 고객의 말은 참조만 하자신이 정확한 현상 데이타를 보기전에는 고객의 말은 참조만 하

라라 . . 잘못된 현상 정의로 인해 많은 시간이 소요되고는 한다잘못된 현상 정의로 인해 많은 시간이 소요되고는 한다 ..► 버그의 재현 절차를 알아내라버그의 재현 절차를 알아내라 ..

버그의 재현을 성공한다면 이미 그 버그는 반은 풀린 것이다버그의 재현을 성공한다면 이미 그 버그는 반은 풀린 것이다 ..

► 버그를 잘 설명할수 있어야 한다버그를 잘 설명할수 있어야 한다 .. 그냥 그냥 ““ 이상해요이상해요”” , “, “ 불안해요불안해요” ” 라는 말을 다음의 말로 바꾼다라는 말을 다음의 말로 바꾼다 ..

► 55 명 이상의 사용자가 명 이상의 사용자가 22 시간 사용후 시간 사용후 inetinfo.exe inetinfo.exe 가 가 HangHang 이 이 걸린다걸린다 ..

복잡한 문제라면 여러개의 단일 문제로 나눈다복잡한 문제라면 여러개의 단일 문제로 나눈다 ..► 버그는 하나가 아닐수 있다버그는 하나가 아닐수 있다 . . 하나씩 풀어 나가면 된다하나씩 풀어 나가면 된다 ..

내가 버그를 잘 설명할 수 있을때 동료들이 도와줄수 있는 것이다내가 버그를 잘 설명할 수 있을때 동료들이 도와줄수 있는 것이다 ..

Art of Debugging Art of Debugging (continued)(continued)

► 도구를 잘 이해하고 적절한 도구를 사용해야 한다도구를 잘 이해하고 적절한 도구를 사용해야 한다 .. 덤프 수집이 필요한 버그인가덤프 수집이 필요한 버그인가 ? ? 소스코드 소스코드 ReviewReview 가 필요한 버그인가가 필요한 버그인가 ?? Exception Flow Exception Flow 를 이해하는 것은 중요하다를 이해하는 것은 중요하다 ..

► 조심해야 할 상황조심해야 할 상황 ““ 혼자 사용할때는 문제 없는데혼자 사용할때는 문제 없는데 , , 여럿이 사용하면 에러가 납니다여럿이 사용하면 에러가 납니다 .”.”

► 정말로 동시성 문제일까정말로 동시성 문제일까 ? ? 사용자 사용자 AA 로만 테스트 하였고 사용자 로만 테스트 하였고 사용자 BB 는 잘못된 는 잘못된 데이타를 가지고 있어서 난 에러였다데이타를 가지고 있어서 난 에러였다 . . 데이타 에러였던 것이다데이타 에러였던 것이다 ..

► 고객이 시스템 오픈전에 동시 사용자 테스트를 하였는지 확인할 필요가 있다고객이 시스템 오픈전에 동시 사용자 테스트를 하였는지 확인할 필요가 있다 ..

““ 동시성 테스트도 마쳤습니다동시성 테스트도 마쳤습니다 .” .” ► 과연 서로 다른 정보를 넣어서 테스트 했을까과연 서로 다른 정보를 넣어서 테스트 했을까 ? ? 대부분의 동시 사용자 테스트는 대부분의 동시 사용자 테스트는 11

인의 정보를 그대로 카피해서 하는 경우가 많다인의 정보를 그대로 카피해서 하는 경우가 많다 ..

새로운 기능을 추가한 뒤 부터 문제가 발생합니다새로운 기능을 추가한 뒤 부터 문제가 발생합니다 ..► 이런 경우 새로운 기능과는 전혀 관련이 없는 곳에서의 조작 미스가 원인 일수도 이런 경우 새로운 기능과는 전혀 관련이 없는 곳에서의 조작 미스가 원인 일수도

있습니다있습니다 ..

ReferencesReferences► 중요 디버깅 툴 다운로드중요 디버깅 툴 다운로드

http://www.microsoft.com/ddkhttp://www.microsoft.com/ddk - - 디버깅 툴 디버깅 툴 (windbg, cdb, autodump+)(windbg, cdb, autodump+) http://support.microsoft.com/default.aspx?scid=kb;en-us;241215http://support.microsoft.com/default.aspx?scid=kb;en-us;241215 – userdump – userdump http://www.sysinternals.comhttp://www.sysinternals.com – Process Explorer – Process Explorer 및 각종 툴및 각종 툴

► Win32 Debugging ArticlesWin32 Debugging ArticlesMicrosoft Debugging Tools Knowledge Base ArticlesMicrosoft Debugging Tools Knowledge Base Articleshttp://www.microsoft.com/ddk/debugging/DBG-KB.asphttp://www.microsoft.com/ddk/debugging/DBG-KB.asp

► 메모리 리크 메모리 리크 Tool Tool 및 사용법및 사용법Umdhtools.exe: How to Use Umdh.exe to Find Memory LeaksUmdhtools.exe: How to Use Umdh.exe to Find Memory Leakshttp://support.microsoft.com/default.aspx?scid=kb;en-us;268343http://support.microsoft.com/default.aspx?scid=kb;en-us;268343

► 디버거 없이 비정상 종료 지점 알아내기 디버거 없이 비정상 종료 지점 알아내기 (for Win9x)(for Win9x) HOWTO: Determine the Location of a Crash HOWTO: Determine the Location of a Crash http://support.microsoft.com/default.aspx?scid=kb;en-us;196755http://support.microsoft.com/default.aspx?scid=kb;en-us;196755

► 프로그램 스스로 예외 발생시 프로그램 스스로 예외 발생시 call stack call stack 정보 기록하기 정보 기록하기 (win9x(win9x 에서도 가능에서도 가능 )) http://msdn.microsoft.com/msdnmag/issues/02/03/hood/default.aspxhttp://msdn.microsoft.com/msdnmag/issues/02/03/hood/default.aspx

ReferencesReferences► VB COM+ VB COM+ 컴포넌트작성시 주의할 점컴포넌트작성시 주의할 점 ..

PRB: Visual Basic DLL Has Memory Leaks and Crashes in COM+ If 'Retain In PRB: Visual Basic DLL Has Memory Leaks and Crashes in COM+ If 'Retain In Memory' Is Not Set Memory' Is Not Set http://http://support.microsoft.com/default.aspx?scidsupport.microsoft.com/default.aspx?scid=kb;en-us;264957=kb;en-us;264957

► VB COM+ VB COM+ 컴포넌트 빌드 옵션 점검 툴 컴포넌트 빌드 옵션 점검 툴 (Windows 2000(Windows 2000 용용 ))SAMPLE: Using VBCHKW2K to Isolate DLLs Compiled Without Retain In SAMPLE: Using VBCHKW2K to Isolate DLLs Compiled Without Retain In Memory and Unattended Execution Memory and Unattended Execution http://support.microsoft.com/default.aspx?scid=kb;en-us;286036http://support.microsoft.com/default.aspx?scid=kb;en-us;286036

► VC++ 6.0 VC++ 6.0 프로젝트용 디버깅 정보 생성하는 법 프로젝트용 디버깅 정보 생성하는 법 (Release Mode(Release Mode 에서에서 ))HOWTO: Create Debug Symbols for a Visual C++ ApplicationHOWTO: Create Debug Symbols for a Visual C++ Application http://support.microsoft.com/default.aspx?scid=kb;en-us;291585http://support.microsoft.com/default.aspx?scid=kb;en-us;291585

► Win32 AppWin32 App 환경에서 환경에서 audodump+ audodump+ 사용하는 법사용하는 법HOWTO: Use Autodump+ to Troubleshoot "Hangs" and "Crashes"HOWTO: Use Autodump+ to Troubleshoot "Hangs" and "Crashes" http://support.microsoft.com/default.aspx?scid=kb;en-us;286350http://support.microsoft.com/default.aspx?scid=kb;en-us;286350

► HOWTO: Obtain a Userdump When COM+ FailfastsHOWTO: Obtain a Userdump When COM+ Failfasts COM+ Failfast COM+ Failfast 이해 및 이해 및 COM+ Component crashCOM+ Component crash 시 덤프 수집 방법시 덤프 수집 방법

http://support.microsoft.com/default.aspx?scid=kb;en-us;287643http://support.microsoft.com/default.aspx?scid=kb;en-us;287643

References References (COM Threading)(COM Threading)

► INFO: Thread Pool Differences Between COM+ and MTSINFO: Thread Pool Differences Between COM+ and MTS http://support.microsoft.com/?id=282490http://support.microsoft.com/?id=282490

► INFO: Registry Key for Tuning COM+ Thread and ActivityINFO: Registry Key for Tuning COM+ Thread and Activity http://support.microsoft.com/?id=303071http://support.microsoft.com/?id=303071

► INFO: Do Not Make Blocking Calls from an STA ComponentINFO: Do Not Make Blocking Calls from an STA Component http://support.microsoft.com/?id=291837http://support.microsoft.com/?id=291837

► COM Threading and Application Architecture in COM+ COM Threading and Application Architecture in COM+ ApplicationsApplications http://msdn.microsoft.com/library/default.asp?url=/library/en-us/http://msdn.microsoft.com/library/default.asp?url=/library/en-us/

dncomser/html/comthread.aspdncomser/html/comthread.asp

► VB VB 로 로 COM+ COM+ 컴포넌트 사용시 장시간 걸리는 메소드는 사용하지 컴포넌트 사용시 장시간 걸리는 메소드는 사용하지 않는 것이 좋습니다않는 것이 좋습니다 . .

References References for .NETfor .NET

► INFO: Roadmap for Debugging in .NET Framework and Visual INFO: Roadmap for Debugging in .NET Framework and Visual Studio .NETStudio .NET http://support.microsoft.com/default.aspx?scid=kb;en-us;308626http://support.microsoft.com/default.aspx?scid=kb;en-us;308626

► Production Debugging for .NET Framework Applications Production Debugging for .NET Framework Applications http://msdn.microsoft.com/library/default.asp?url=/library/en-us/http://msdn.microsoft.com/library/default.asp?url=/library/en-us/

dnbda/html/DBGch01.aspdnbda/html/DBGch01.asp

Q and AQ and A

► 감사합니다감사합니다 ..