Debugging Tactics Flashcards

1
Q

Basic debugging tactics

A
  • commenting out the code
  • validating the code flow
  • printing values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Validating code flow

A

Used when the program is calling to a function too many or few times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Using validating code flow

A

By placing statements at the top of the function to print the functions name
Use std::cerr and do not indent the debug statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Printing values

A

Used when the program is calculating or passing wrong value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Using printing values

A

By outputting the value of variables and expressions by using std::cerr

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why not to use debug statements

A
  • clutter the code
  • clutter the output of the program
  • must be removed, it is not reusable
  • requires modification which can introduce new bugs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Conditionalizing the debugging code

A

To make the debugging statements conditional using preprocessor directives

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Using conditionalizing the debugging code

A

With #define ENABLE_DEBUG by commenting/uncommenting it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Conditionalizing the debugging code in multi-file program

A

Use #define ENABLE_DEBUG in a header file in all code files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Log file

A

File stored in disk, that records events that occur in the software

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Logging

A

Process of writing information to a log file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Advantages of log file

A
  • aviding clutter, because it is stored on a separate file

* can be sent to others for diagnosis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Program state

A

Tracked value of variables , called function and current point of execution within the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Debugger

A

Computer program that allows the programer to control how a program executes and examin the program state while the program is running

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Advantige of debugger

A

Ability to precisily control execution of the program and ability to view/modify program’s state

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Stepping

A

Set of related debugger features that let us execute (step through) our code statement by statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Step into

A

That executes the next statement in the normal execution path of the program, and pauses so you can inspect the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Stepping into without running

A
  • the program will recompile
  • will begin to run
  • will open diagnostic windows
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Step over

A

Executes an entire function without stepping, use it when you know a function works

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Step out

A

Executes remaining code in the function currently being executed, use it when you accidentally stepped into a function that you don’t want to debug

21
Q

Step back

A

Rewind the last step, so you can return the program to a prior state

22
Q

Run to cursor

A

Executes the prigram until the execution reaches the statement selected by your cursor, then it returns the control to you

23
Q

Continue

A

Continues runnung the program as per normal, either until the program terminates or until something triggers control to return back

24
Q

Start

A

Running the program fromthe begining, it can be invoked when not already in a debug session

25
Breakpoint
Tells the debugger to stop executing the program at the breakpoint when running in debug mode
26
Advantages of breakpoints
* return control everytime they are encountered | * you can set a breakpoint and it will persist until you remove it
27
Set next statement
Changes the point of execution to some other statement (jumping), you can jump forwards and backwards
28
Watching variables
Process of inspecting the value of a variable while the program is executing in debug mode.
29
Ways to watch variables
* hovering the mouse over variables | * quickWatch in the right-click menu
30
Watch window
Window where you can add variables you like to continually inspect, will be updated as you step trough
31
Ways to add variables to watch window
* trough watch window by typing the name of the variable in the left column * trough code window by right-click on variable and add watch
32
Watching out of scope variables
Will stay on the window, but will be marked as not available or show the last kmown value but it will be grayed out
33
Other watch window use
Evaluating simple expressions
34
Local watches
Quick way to watch value of local variables in scope
35
Call stack
List of all the active functions that have been called to get to the current point of execution
36
Included in the call stack
Entry for each function called and which line of code will be returned to when the function returns
37
Adding functions to the call stack
The function is added to the top of the stack, when it's returned the function is removed from the top of the stack and the control is returned to the function below it
38
Call stack window
Debugger window that shows the current call stack
39
Use for call stacks
In conjunction with breakpoints, when your breakpoint is hit and you want to know what functions were called to get to that point of code
40
Things that can help avoid making errors
* follow the best practices * don't program when tired * understand where the common pitfalls are in a language * keep your programs simple * don't let your functions to get too long * preder using the standard library to writing your own code * comment liberary
41
Refacturing
Process of making strucrltural changes to your code without changing it's behaviour
42
Making behavioural and structural changes
At the same time tends to lead to more errors
43
Defensive programming
Practice where the programmer tries to anticipate all the ways the software could be mis-used by end-users or developers using the code
44
Programming a little bit a time
Fast way to find errors especialy if you test the code and make sure it works
45
Testing functions
Primitive form of unit testing, by which a small unit of source code are tested to determine whether they are correct
46
Use of testing functions
Ex. testadd(), tests the function by calling it with different values
47
Constrains
Involve the addition of some extra code to check that some set of assumptions or expectations are not violated
48
Static analysis tools (linters)
Programs that analyze your code to identify specific semantic issues