Tools and Techniques For Debugging II
Tools and Techniques For Debugging II
Debugging - Part 2
Debugging is not just about finding errors; it also involves examining variable
contents, implementing logging frameworks, and creating custom event logs.
Building on the fundamentals of debugging, this module delves deeper into
advanced debugging techniques that are crucial for efficient software development.
● Master how to use IDE tools to inspect variable values during code
execution, providing insights into how your code is functioning.
● Learn how to integrate logging and error handling into applications, such
as tracking success and failure events, using modern frameworks and
best practices.
● Explore how to create custom event logs and view them in Windows Event
Viewer, complete with specific messages for success and failure.
The material in this module relates to the following subject learning outcomes:
Student Expectations
During this module, you are expected to spend time working through the prescribed
material prior to attending class. This will enable a more valuable discussion to take
place in online tutorials or conferences, where you will be able to discuss concepts,
present ideas and explore information collaboratively in greater depth.
4 hours for facilitated study. This includes guided facilitated study, watching or
attending course lectures (live or pre-recorded), responding to facilitator feedback.
8 hours for personal study. This includes reading through course material,
undertaking learning activities and exploring additional related resources.
1. The ability to examine variable contents during code execution can reveal
issues and help debug in real-time.
2. Many IDEs offer features like watch windows or immediate windows that
make it easier to inspect variables without stopping code execution.
3. Some debugging tools allow setting conditional breakpoints based on variable
values, enabling targeted debugging.
Learner Guide
The Learner Guide provides the core knowledge for this topic. Work through the
materials and be prepared to discuss these in your forums, tutorials or classes.
Expand All
Panels
Collapse All
Panels
Understanding Variables
Programmers have at their disposal several tools and methods to monitor variable
values and behaviours during runtime, including:
● Print Statements
An uncomplicated technique wherein developers infuse print statements in
the code to visualise the variable values at certain stages of execution.
● Debuggers
A feature in many Integrated Development Environments (IDEs),
debuggers enable developers to halt the execution (via breakpoints) and
scrutinizes the existing variable values, even allowing line-by-line code
progression to witness variable value alterations.
● Watch Expressions
A specialised function within debuggers where developers can earmark
certain variables to “watch,” facilitating constant display of these variable
values as the program executes.
Further Reading
Explore how to inspect variables (program state) in GDB using the print and info
locals commands. Learn how to use GDB commands such as print and info locals as
tools to view the state of a program without the need to insert printf C code
statements and recompile the program.
Liz Willer, 2020, 'GDB - Viewing Data', [online] accessed 31 January 2024,
<https://www.cse.unsw.edu.au/~learn/debugging/modules/gdb_viewing_data/>
Aaron Hallberg, 2016, '7 Ways to Look at the Values of Variables While Debugging in Visual Studio',
Microsoft Dev Blog [online] accessed 31 January 2024,
<https://devblogs.microsoft.com/devops/7-ways-to-look-at-the-values-of-variables-while-debugging-in-
visual-studio/>
At the forefront of finance technology, FinTech Hub was grappling with the task of
sustaining the reliability and performance of its software applications. The intricate
algorithms and expansive datasets in play mandated a precise approach to
debugging to avert system failures and inaccurate data computations.
Problem Statement
Implementation
To revamp the debugging procedure, a pivotal decision was made to amplify the
techniques employed to examine variable contents. The initiative unfolded as
follows:
● Training
A comprehensive training module was introduced to acquaint developers
with advanced debugging tools and techniques, including the proficient
use of watch expressions and breakpoints.
● Integrating Advanced Debuggers
Embedding sophisticated debugging tools into the development landscape
enabled a more nuanced and detailed investigation of variable contents.
● Code Reviews
A routine of regular code reviews was instituted, fostering a culture where
developers scrutinised variable values to pinpoint potential enhancements
and optimisation avenues.
Outcome
1. Logging frameworks offer a systematic way to trace how data moves through
the system, making it easier to locate issues.
2. A robust error handling framework can catch and manage exceptions, thus
preventing crashes and enabling more graceful failure.
3. Proper logging and error handling can also be used to give constructive
feedback to the end-users, helping them understand what went wrong.
Learner Guide
The Learner Guide provides the core knowledge for this topic. Work through the
materials and be prepared to discuss these in your forums, tutorials or classes.
Expand All
Panels
Collapse All
Panels
The process of logging embodies the recording of events within a system, thereby
aiding in the identification, troubleshooting, and resolution of potential issues.
Essentially, it acts as a chronicle of system activities, instrumental in detecting
unusual patterns or behaviours.
Logging
● Log Levels: Employ different log levels such as INFO, WARN, and
ERROR to classify the gravity of log entries.
● Log Aggregation: Centralise log data hailing from diverse sources to
enable streamlined analysis and monitoring.
● Log Rotation: Implement strategies to archive outdated logs and
generate new log files, preventing an overflow of log file data.
Error Handling
● Try-Catch Blocks: Utilise try-catch blocks to encapsulate potentially
exception-throwing code and delineate the handling procedures.
● Custom Error Messages: Develop custom error messages that offer
more detailed insights into the error nature.
● Error Logging: Integrate error logging to document exceptions, facilitating
future analysis and prevention of analogous issues.
Practical Applications
● System Monitoring
Undertake continuous system surveillance to pinpoint and flag potential
issues before escalation.
● Troubleshooting
Facilitate swift identification and rectification of problems through log and
error message analysis.
● Security
Amplify system security through vigilant monitoring and documentation of
unauthorized access attempts.
Further Reading
Background
Problem Statement
The existing infrastructure was devoid of thorough logging and error handling
mechanisms, culminating in extended downtimes and inefficient troubleshooting
procedures. There emerged a critical need to introduce robust frameworks that could
amplify system stability and facilitate efficient maintenance.
Implementation
HealthNet Solutions embarked on an initiative to construct structured logging and
error handling frameworks, employing the following strategies:
Outcome
Learner Guide
The Learner Guide provides the core knowledge for this topic. Work through the
materials and be prepared to discuss these in your forums, tutorials or classes.
Expand All
Panels
Collapse All
Panels
To create custom event logs is to formulate specialised logs that record events
germane to a specific functionality or module within the system. Far from generic,
these logs are crafted to offer detailed insights into particular segments of the
application. Their application extends to recording details about custom applications
or services, enabling focused monitoring and troubleshooting.
Key Components
When embarking on the creation of custom event logs, one should ponder over
several vital components:
● Event Identifiers
Singular identifiers that are allocated to each event type, aiding in their
effortless distinction and promoting efficient filtering and searching.
● Event Categories
The strategy of clustering events into varying categories, dictated by their
characteristics or the modules they pertain to, thereby facilitating
systematic and orderly logging.
● Event Metadata
Incorporation of pertinent metadata such as timestamps, event source,
and event particulars to furnish a well-rounded view of each event.
● Event Severity Levels
The delineation of severity levels to classify events based on their
repercussion, assisting in prioritising response strategies.
Section 2: Applications of Custom Event Logs
The creation of custom event logs finds a place in a myriad of domains, inclusive of:
● Security Monitoring
Establishing custom event logs to exclusively monitor events with security
implications, assisting in the premature detection of potential security
violations.
● Performance Monitoring
Developing logs to oversee the performance metrics of specific modules
or functionalities, fostering proactive performance tuning and
enhancement.
● Compliance and Reporting
Leveraging custom event logs in collating data vital for compliance
reporting, thereby rendering the process more streamlined and efficient.
Background
The conventional event logs utilised by the company were becoming increasingly
challenging for the IT contingent to navigate and pinpoint specific events associated
with their custom-developed applications. The requirement for a more streamlined
approach to log management emerged as a pressing concern.
Implementation
Outcome
The inception of custom event logs markedly uplifted the efficiency of the system
monitoring protocol at GreenTech Innovations. The IT personnel were now equipped
to swiftly identify and react to particular events, diminishing the time and effort
necessitated for troubleshooting.
Further Resources
The resources in this section are for further exploration, providing additional
information for deeper insights.
Expand All
Panels
Collapse All
Panels
Reading: Understand Conditional Breakpoints in C++
Standard function breakpoints probably help in most debugging sessions. But,
sometimes, there's simply too much code to check, too many objects or cases. What
if you want to filter out code that generates a breakpoint? Here's a look at conditional
breakpoints.
Reference: Bartlomiej Filipek, 2016, 'Understand Conditional Breakpoints in C++', Visual Studio
Magazine, accessed 31 January 2024,
<https://visualstudiomagazine.com/articles/2016/09/01/understand-conditional-breakpoints.aspx>
Reading: Modern C++ Best Practices for Exceptions and Error Handling
This article discusses the preferred approaches and best practices for handling
errors in modern C++ programming. It emphasizes the use of exceptions as the
preferred way to report and handle both logic errors and runtime errors in most
scenarios. The article covers basic guidelines for robust error handling, such as
using exceptions for exceptional code, employing assertions for conditions that
should never occur, and providing exception guarantees for functions.
Reference: Peter Forgacs, 2017, 'Custom C++ Exceptions for Beginners', Peter Forgacs @ GitHub,
accessed 31 January 2024,
<https://peterforgacs.github.io/2017/06/25/Custom-C-Exceptions-For-Beginners/>
Reference: Geeks for Geeks, n.d., 'Exception Handling in C++', Geeks for Geeks, accessed 31
January 2024, <https://www.geeksforgeeks.org/exception-handling-c/>
You'll learn about keywords that are used to work with exceptions: try, catch and
throw, and about different types of exception handlers, including the default handler.
(24:46)
Reference: CodeBeauty, 2021, 'Exception Handling in C++', YouTube, accessed 31 January 2024,
<https://youtu.be/kjEhqgmEiWY>
Reference: Microsoft staff, 2022, 'TraceLogging C/C++ Quick Start', Microsoft Learn, accessed 31
January 2024,
<https://learn.microsoft.com/en-us/windows/win32/tracelogging/tracelogging-native-quick-start>