Tài liệu Bài giảng Chapter 15 Debugging: Chapter 15DebuggingDebugging with High Level LanguagesSame goals as low-level debuggingExamine and set values in memoryExecute portions of programStop execution when (and where) desiredWant debugging tools to operate onhigh-level language constructsExamine and set variables, not memory locationsTrace and set breakpoints onstatements and function calls, not instructions...but also want access to low-level tools when needed2Types of ErrorsSyntactic ErrorsInput code is not legalCaught by compiler (or other translation mechanism)Semantic ErrorsLegal code, but not what programmer intendedNot caught by compiler, because syntax is correctAlgorithmic ErrorsProblem with the logic of the programProgram does what programmer intended, but it doesn't solve the right problem3Syntactic ErrorsCommon errors:missing semicolon or bracemis-spelled type in declarationOne mistake can cause an avalanche of errorsbecause compiler can't recover and gets confused main () { int i int j; for (i = 0; i <...
10 trang |
Chia sẻ: honghanh66 | Lượt xem: 1318 | Lượt tải: 0
Bạn đang xem nội dung tài liệu Bài giảng Chapter 15 Debugging, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Chapter 15DebuggingDebugging with High Level LanguagesSame goals as low-level debuggingExamine and set values in memoryExecute portions of programStop execution when (and where) desiredWant debugging tools to operate onhigh-level language constructsExamine and set variables, not memory locationsTrace and set breakpoints onstatements and function calls, not instructions...but also want access to low-level tools when needed2Types of ErrorsSyntactic ErrorsInput code is not legalCaught by compiler (or other translation mechanism)Semantic ErrorsLegal code, but not what programmer intendedNot caught by compiler, because syntax is correctAlgorithmic ErrorsProblem with the logic of the programProgram does what programmer intended, but it doesn't solve the right problem3Syntactic ErrorsCommon errors:missing semicolon or bracemis-spelled type in declarationOne mistake can cause an avalanche of errorsbecause compiler can't recover and gets confused main () { int i int j; for (i = 0; i <= 10; i++) { j = i * 7; printf("%d x 7 = %d\n", i, j); }}missing semicolon4Semantic ErrorsCommon ErrorsMissing braces to group statements togetherConfusing assignment with equalityWrong assumptions about operator precedence, associativityWrong limits on for-loop counterUninitialized variableshmain () { int i int j; for (i = 0; i <= 10; i++) j = i * 7; printf("%d x 7 = %d\n", i, j);}missing braces,so printf not part of if5Algorithmic ErrorsDesign is wrong,so program does not solve the correct problemDifficult to findProgram does what we intendedProblem might not show up until many runs of programMaybe difficult to fixHave to redesign, may have large impact on program codeClassic example: Y2K bugonly allow 2 digits for year, assuming 19__6Debugging TechniquesAd-HocInsert printf statements to track control flow and valuesCode explicitly checks for values out of expected range, etc.Advantage:No special debugging tools neededDisadvantages:Requires intimate knowledge of code and expected valuesFrequent re-compile and execute cyclesInserted code can be buggySource-Level DebuggerExamine and set variable valuesTracing, breakpoints, single-stepping on source-code statements7Source-Level Debuggermain windowof Cygwinversion of gdb8Source-Level Debugging TechniquesBreakpointsStop when a particular statement is reachedStop at entry or exit of a functionConditional breakpoints:Stop if a variable is equal to a specific value, etc.Watchpoints:Stop when a variable is set to a specific valueSingle-SteppingExecute one statement at a timeStep "into" or step "over" function callsStep into: next statement is first inside function callStep over: execute function without stoppingStep out: finish executing current functionand stop on exit9Source-Level Debugging TechniquesDisplaying ValuesShow value consistent with declared type of variableDereference pointers (variables that hold addresses)See Chapter 17Inspect parts of a data structureSee Chapters 19 and 1710
Các file đính kèm theo tài liệu này:
- pattpatelch15_6499.ppt