팁 조정

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
1. 디버거 진입 중단
1.1 c++
_asm { int 3 }
매크로(macro) #ifdef DEBUG
#define BREAKPOINT __asm int3
#else
#define BREAKPOINT
#endif
1.2 사용 가능
_CrtDbgBreak()
, crtdbg.h에서 정의
1.3 모든 플랫폼(x86, x64 사용 가능)debugbreak (), intrin.h
1.4 csharp System.Diagnostics.Debugger.Break(); 1.5 기타 사용 가능한 NULL 포인터, 제로(0) 작업 등.2. 자체 assert 매크로void 정의declspec(noreturn) __assertNoReturn(char *, int, char *);
#if defined(_PREFAST_)
//For PREfast runs
//
   #define myAssert(x) __assume(x)
#elif defined(DBG)
//
//For checked builds with a simple assert mechanism
//(where DBG is the checked build symbol)
//
//The following function call will not cause false-positive
//results because __assertNoReturn will not return. More complex
//macros might return. In that case, use __assume.
//
   #define myAssert(x) ((!(x))?__assertNoReturn(__FILE__, __LINE__, #x):1)
#else
//Free build
   #define myAssert(x)  //Nothing
#endif
3. 일반 단축키 디버깅(VS)
F5 프로그램 시작 및 디버깅
F10 step over, 한 줄씩 디버깅
F11 step into
shift + F11 step out
ctrl + shift + F10 ,set next statement
CTRL +* : SHOW NEWXT STATEMENT
조건 단점: 하나의 예name.Equals("Name3")
조건 브레이크를 설정하면 브레이크 기호 중간에 더하기 기호가 나타납니다.
VS2010에서는 브레이크를 가져오고 내보낼 수 있습니다.
Breakpoint Hit Count 사용
4. 현재 파일 이름과 현재 줄 가져오기
(.net charp) c#의File__ __line__
string
 currentFile=
new
 System.Diagnostics.StackTrace(
true
).GetFrame(0).GetFileName();
int
 currentLine = 
new
 System.Diagnostics.StackTrace(
true
).GetFrame(0).GetFileLineNumber(); 
String MethodName = new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name;

MethodBase.GetCurrentMethod().Name


MethodInfo.GetCurrentMethod().Name


[Conditional("DEBUG")]
void DebugFunc()
{
} 

디버깅에 유용한 단축키(VS2010)
Shortcut Keys
Descriptions
Ctrl-Alt-V, A
Displays the Auto window
Ctrl-Alt-B
Displays the Breakpoints dialog
Ctrl-Alt-C
Displays the Call Stack
Ctrl-Shift-F9
Clears all of the breakpoints in the project
Ctrl-F9
Enables or disables the breakpoint on the current line of code
Ctrl-Alt-E
Displays the Exceptions dialog
Ctrl-Alt-I
Displays the Immediate window
Ctrl-Alt-V, L
Displays the Locals window
Ctrl-Alt-Q
Displays the Quick Watch dialog
Ctrl-Shift-F5
Terminates the current debugging session, rebuilds if necessary, and starts a new debugging session.
Ctrl-F10
Starts or resumes execution of your code and then halts execution when it reaches the selected statement.
Ctrl-Shift-F10
Sets the execution point to the line of code you choose
Alt-NUM *
Highlights the next statement
F5
If not currently debugging, this runs the startup project or projects and attaches the debugger.
Ctrl-F5
Runs the code without invoking the debugger
F11
Step Into
Shift-F11
Executes the remaining lines out from procedure
F10
Executes the next line of code but does not step into any function calls
Shift-F5
Available in break and run modes, this terminates the debugging session
Ctrl-Alt-H
Displays the Threads window to view all of the threads for the current process
F9
Sets or removes a breakpoint at the current line
Ctrl-Alt-W, 1
Displays the Watch 1 window to view the values of variables or watch expressions
Ctrl-Alt-P
Displays the Processes dialog, which allows you to attach or detach the debugger to one or more running processes
Ctrl-D,V
IntelliTrace Event
6. OutputDebugString 사용
vc에서 OutputDebugString 사용
c#사용 가능:
debug에서 볼 수 있음
System.Diagnostics.Debug.WriteLine("I am using dot net debugging");
release와 debug에서 모두 볼 수 있습니다
System.Diagnostics.Trace.WriteLine("I am using dot net tracing");
대화 상자 시스템.Windows.Forms.MessageBox.Show("Exception at File:Line:"+ ExceptionToStr(e)); 출력을 파일로 리디렉션하려면 다음과 같이 하십시오.
System.Diagnostics.Trace.Listeners.Clear();
System.Diagnostics.Trace.AutoFlush=true;
System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener("app.log"));
//z 2013-04-28 10:23:21 [email protected][T7,L117,R5,V108]
7. vbscript 디버깅
Dim objIEDebugWindow

Debug "This is a great way to display intermediate results in a separate window."


Sub Debug( myText )
  ' Uncomment the next line to turn off debugging
  ' Exit Sub

  If Not IsObject( objIEDebugWindow ) Then
    Set objIEDebugWindow = CreateObject( "InternetExplorer.Application" )
    objIEDebugWindow.Navigate "about:blank"
    objIEDebugWindow.Visible = True
    objIEDebugWindow.ToolBar = False
    objIEDebugWindow.Width   = 200
    objIEDebugWindow.Height  = 300
    objIEDebugWindow.Left    = 10
    objIEDebugWindow.Top     = 10
    Do While objIEDebugWindow.Busy
      WScript.Sleep 100
    Loop
    objIEDebugWindow.Document.Title = "IE Debug Window"
    objIEDebugWindow.Document.Body.InnerHTML = _
                 "<b>" & Now & "</b></br>"
  End If

  objIEDebugWindow.Document.Body.InnerHTML = _
                   objIEDebugWindow.Document.Body.InnerHTML _
                   & myText & "<br>" & vbCrLf
End Sub

Notes:
(1) objIEDebugWindow must be declared in the main script body, not in the subroutine (must be global)!
 
(2)
Do not discard the objIEDebugWindow object at the end of the script, or your debug window will vanish!

좋은 웹페이지 즐겨찾기