0% found this document useful (0 votes)
10 views16 pages

Cstoolslab 6

Uploaded by

hoodboy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views16 pages

Cstoolslab 6

Uploaded by

hoodboy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Lab#05

Debugging
CS205L
Comp Engr. Marwa Bibi
Learning Outcomes
• Understand breakpoint configuration, including conditional, inline,
and function breakpoints.
• Master navigation and control functionalities such as step into, step
out, step over, and stop.
• Develop proficiency in data inspection and analysis using logpoints,
watch windows, and call stacks.
Debugging
• The process of finding the root of a problem in a code base and fixing
it.
• Techniques typically include setting breakpoints, stepping through
code, inspecting variables, analyzing program flow, and making
adjustments to correct the identified issues.
• The primary goal is to ensure that the software functions as intended
and produces the expected output.
C++ debugging Configuration
• Open launch.json file, define the necessary settings for debugging
environment .
• Update the program, cwd(current working directory) and
miDebuggerPath(as per your system path) fields
valuesaccording to one’s project setup in this file.
• Once configured, press ctrl+shift+D
• to start debugging
Data Inspection
• Data Inspection options allow to inspect and analyze the values of variables,
expressions, and memory locations while the program is executing. Data
Inspection can be done in multiple ways during debugging on VS Code.
• Variables View: In the Debug sidebar, there is a "Variables" view that
displays a list of variables and their current values.
• Hover Inspection: Hover over variables or
expressions in the code while debugging to see their
current values. VS Code will display a tooltip with
the value of the variable or expression.
Watch Window, Breakpoints Inspection and Call Stack options are also
available.
Breakpoints
• Markers set within the source code that pause the execution of a
program when reached. They allow developers to inspect the
program's state, variables, and control flow at that particular point in
execution.
• Conditional Breakpoints: These breakpoints halt the program's
execution only if a specified condition evaluates to true. This allows
developers to focus on debugging specific scenarios or conditions
within the code.
Breakpoints Cont…
• Inline Breakpoints (Tracepoints): These breakpoints don't pause
program execution but instead log a message or perform some action
when reached. They are useful for monitoring the program's behavior
without interrupting its flow.

• Function Breakpoints: These breakpoints pause the program's


execution whenever a specific function is called. They are helpful for
tracking the flow of control through functions during debugging
sessions
Breakpoints
Step Into
• "Step Into" command allows debugger to move the execution point to
the next line of code.
• If the next line of code is a function call, the debugger will enter the
called function and pause execution at the first line of that function
allowing to examine the code inside that function.
function addNumbers(a, b) {
let result = a + b;
}

let x = 5;
let y = 10;
// If you "step into" below line, you will enter the 'addNumbers' function.
let z = addNumbers(x, y);
Step Over
• The debugger will execute the current line of code and pause on the
next line, without entering any function calls that might be present on
the current line.
function addNumbers(a, b) {
let result = a + b;
return result;
}

let x = 5;
let y = 10;
// If you "step over" below line, you will not enter the 'addNumbers' function.
let z = addNumbers(x, y);
Step Out
• The debugger continues execution until the current function returns, and then pauses at
the line of code immediately after the function call that initiated the current function.

function multiplyNumbers(a, b) {
let result = a * b;
return result;
}
function addNumbers(a, b) {
let sumResult = a + b;
// If you "step into" here and then "step out," you will return to this line.
let product = multiplyNumbers(a, b);
return sumResult + product;
}
let x = 5;
let y = 10;
// If you "step out" here, you will return to where 'addNumbers' was called.
let z = addNumbers(x, y);
Logpoints
• Logpoints in debugging are special breakpoints that do not halt the
execution of the program like regular breakpoints do. Instead, they
allow developers to log messages or perform actions when a certain
point in the code is reached during debugging.
Watch Window
• Debugging tool that allows to monitor the values of specific variables or
expressions during the debugging process.
• Provides a convenient way to track the state of variables and expressions as
the program executes, helping to understand how they change over time.
• Watch Window on VS Code provide facility of;
Adding Variables/Expressions: Can add variables or expressions to the watch
window.
Monitoring Values: Display their current values as your program executes
Variable Inspection: Provides additional information about the variables or
expressions you're watching, such as their data types, memory addresses, or any
associated metadata.
Call Stack
• Refers to a list of function calls that have been made up to the current
point of execution in the code.
• It provides a hierarchical view of the function calls, showing which
functions have been called, in what order, and from where.
• Call Stack option provides Function Call Hierarchy(most recent
function call at the top), Function Names and Locations and Insight
into Program Flow(which functions have been called and in what
sequence) etc.
Call Stack
Reference Links
1)https://code.visualstudio.com/docs/cpp/launch-json-reference
2) https://code.visualstudio.com/docs/cpp/config-mingw
3)
https://www.youtube.com/playlist?list=PL36enNxU148Q5I5Uh1dPN0C4p
pq1CHiCE
4)
https://learn.microsoft.com/en-us/visualstudio/debugger/getting-started
-with-the-debugger-cpp?view=vs-2022
5) https://www.youtube.com/watch?v=9_HTh6L5vRI
6)
https://code.visualstudio.com/blogs/2018/07/12/introducing-logpoints-a
nd-auto-attach

You might also like