0% found this document useful (0 votes)
9 views20 pages

Tools and Techniques For Debugging II

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

Tools and Techniques For Debugging II

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

Module 8.

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.

In this module, you will explore:

● 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.

To enhance your understanding, we have tailored specific learning activities:

● Using IDE tools to inspect variable values during code execution.


● Integrating logging and error handling into the "Add Student" Application,
including success and failure events.
● Creating custom event logs and viewing them in Windows Event Viewer
with specific messages for success and failure.

Subject Learning Outcomes

The material in this module relates to the following subject learning outcomes:

​ SLO 5: Gain hands-on experience with debugging through various tools,


including IDEs, and understand how to set breakpoints, inspect variables,
and trace code execution.

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.

Accordingly, it is suggested that you allow:

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.

Topic 1. Examining Variable Contents

Key takeaways from this topic...

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

Section 1: Understanding and Examining Variable Contents in Programming

In programming, the capacity to critically examine the contents of variables as a


program runs is a highly useful skill for developers, which enables them to gauge the
transformations data undergoes throughout runtime, assisting in spotting and
rectifying bugs and other discrepancies. Mastery of techniques to explore variable
contents can be a vital component in a programmer's arsenal, ensuring seamless
system operations.

Understanding Variables

A primary step in this process is comprehending the characteristics and functions of


variables in a program. Variables, the storage units in a program, harbour data that
may vary during the runtime. Characterised by a unique name and type, they are
central in storing data manipulated within a program.

Techniques to Examine Variable Contents

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

GDB - Viewing Data

Links to an external site.

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/>

Ways to Look at the Values of Variables While Debugging in Visual Studio

Links to an external site.


Consider these seven different ways to inspect the values of your variables while
debugging through your code in the Visual Studio debugger without modifying your
code.

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/>

Section 2: Practical Applications and Real-world Implementation

Analysing variable contents finds utility in several real-world applications.

● Bug Identification and Resolution


Through the keen observation of variable value alterations, programmers
can detect logical errors or bugs, pinpointing moments where values differ
from expected results.
● Optimising Code
Vigilant tracking of stored variable values can identify opportunities to
refine the code, improving the program’s performance and speed.
● Data Validation
Using this technique ensures the alignment of processed data with the
program’s intended functionality, confirming the validity of inputs and
outputs.

Section 3: Case Study - Elevating Software Efficiency


Background

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

The established debugging procedures were gradually becoming burdensome,


inducing delays in rolling out new functionalities and updates. There was a pressing
need for a more systematic strategy to pinpoint and amend issues efficiently, without
hindering the developmental cycle.

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

The heightened focus on scrutinising variable contents transformed the debugging


landscape at FinTech Hub. Developers could now swiftly isolate and rectify glitches,
slashing debugging time and hastening the development pace. The evolved
techniques culminated in the creation of more reliable and sturdy software solutions,
nurturing an ethos of quality and efficiency within the development squad. This case
elucidates the central role that detailed inspection of variable contents can play in
bolstering software development procedures.

Topic 2. Implementing Logging and Error Handling


Frameworks

Key takeaways from this topic...

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

Section 1: The Foundations of Logging and Error Handling

Developing software transcends the mere construction of functionalities. An essential


responsibility for developers is to forge systems that are both robust and
straightforward to maintain. In this context, the implementation of logging and error
handling frameworks becomes imperative.
These frameworks function as vital tools in monitoring the health of the system,
facilitating issue diagnosis, and guaranteeing smooth and dependable operations.

Importance of Logging and Error Handling

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.

Contrastingly, error handling is the methodology employed to address exceptions or


errors that surface during a program’s execution. Proper error handling tactics
facilitate the graceful management of unforeseen scenarios, averting system crashes
and thus fostering stability and reliability in the system.

Section 2: Techniques, Tools, and Practical Applications

Techniques and Tools

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

The incorporation of logging and error handling frameworks manifests in numerous


practical applications, including:

● 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

Error Logging in C++

Links to an external site.

Explore this comprehensive guide on implementing error logging in C++ to facilitate


effective error tracking and handling, and learn how to create a simple class to log
program errors.
Reference: Rollbar staff, 2022, 'What is Error Logging in C++', Rollbar Guide, accessed 31 January
2024, <https://rollbar.com/guides/cpp/cpp-error-logging/>

Section 3: Case Study - Enhancing Operational Efficacy at HealthNet Solutions

Background

HealthNet Solutions, a notable player in healthcare technology, was grappling with


recurring system downtimes, which were detrimentally impacting the quality of their
service and client satisfaction levels. The leadership acknowledged the urgent
necessity to strengthen the system's resilience and enhance issue traceability.

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:

● Development of Logging Framework


Crafting a structured logging framework that systematically categorised
and documented system events.
● Integration of Error Handling Modules
Integrating modules that adeptly captured and addressed exceptions,
mitigating system crashes and simplifying troubleshooting.
● Training and Skill Development
Equipping the development team with the necessary skills to effectively
utilise the newly implemented frameworks, thereby enhancing their
capacity to monitor, identify, and resolve issues proficiently.

Outcome

The inception of these frameworks signaled a monumental shift at HealthNet


Solutions. The system metamorphosed into a more stable and manageable entity,
with downtimes significantly curtailed. The development team could now promptly
pinpoint and resolve issues, markedly elevating service quality and customer
satisfaction levels. This scenario underscores the pivotal role that logging and error
handling frameworks assume in augmenting the reliability and efficacy of software
systems.

Topic 3. Creation of Custom Event Logs

Key takeaways from this topic...

1. Custom event logs provide an audit trail for applications, helping in


troubleshooting and system monitoring.
2. The ability to customise event logs allows for a more granular view of events,
separating them into categories like 'success' and 'failure'.
3. Custom event logs can be integrated with system-level logging tools like the
Windows Event Viewer, providing a unified logging interface.

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

Section 1: Introduction to Custom Event Logs and Components

In the realm of software development, the adept management and surveillance of


system activities is of prime importance. Achieving this can be notably facilitated
through the establishment of custom event logs.
These bespoke logs are constructed to monitor and document specific events within
a system, furnishing a nuanced and streamlined avenue for tracking system
behaviours and occurrences. This guide aims to elucidate the critical facets of
creating custom event logs, highlighting their significance and depicting their
utilisation through a practical case study.

Understanding Custom Event Logs

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.

Section 3: Case Study - Enhancing System Operations at GreenTech Innovations

Background

GreenTech Innovations, a pioneer in fostering sustainable technologies, sought to


amplify its capacities in system monitoring and management. As their project
complexities escalated, the demand for a more focused and efficient methodology
for logging system events became pronounced.
Problem Statement

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

To rectify this, GreenTech Innovations launched a project aimed at crafting custom


event logs, implementing the following strategies:

● Identification of Key Event Types


The inaugural step involved pinpointing the central event types warranting
focused monitoring, based on the distinctive traits of their applications.
● Development of Custom Log Structure
A bespoke log structure was formulated, encapsulating relevant metadata
and categorisation attributes to comprehensively capture the identified
events.
● Integration with Monitoring Tools
The newly created custom event logs were amalgamated with existing
monitoring tools, fostering focused monitoring and expedited
troubleshooting procedures.
● Training and Adoption
The IT brigade underwent training to adeptly utilise the new custom event
logs, thereby amplifying their ability to oversee and manage the system
effectively.

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.

Additionally, it fostered concentrated monitoring of custom applications, culminating


in enhanced reliability and performance. This case study underscores the
importance and advantages of establishing custom event logs in refining system
monitoring and management procedures.

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.

Understand Conditional Breakpoints in C++

Links to an external site.

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.

Modern C++ Best Practices for Exceptions and Error Handling

Links to an external site.


Reference: Microsoft staff, 2022, 'Modern C++ Best Practices for Exceptions and Error Handling',
Microsoft Learn, accessed 31 January 2024,
<https://learn.microsoft.com/en-us/cpp/cpp/errors-and-exception-handling-modern-cpp>

Reading: Custom C++ Exceptions for Beginners


This article provides a beginner-friendly guide to using custom exceptions in C++. It
explains the basics of exception handling, emphasizing the use of try-catch blocks
and the throw keyword. It demonstrates the process of handling different types of
exceptions and highlights the importance of adding preconditions and postconditions
when deciding when to throw exceptions.

Custom C++ Exceptions for Beginners

Links to an external site.

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/>

Reading: Exception Handling in C++


This article provides an in-depth overview of exception handling in the C++
programming language. It explains that exceptions are runtime anomalies or
abnormal conditions and describes the mechanism of handling these exceptions
using keywords like try, catch, and throw. The article covers the types of exceptions,
the syntax of try-catch blocks, and the advantages of exception handling over
traditional error handling.

Exception Handling in C++

Links to an external site.

Reference: Geeks for Geeks, n.d., 'Exception Handling in C++', Geeks for Geeks, accessed 31
January 2024, <https://www.geeksforgeeks.org/exception-handling-c/>

Reading: try, throw, and catch Statements


This article discusses the implementation of exception handling in C++ using try,
throw, and catch statements.

try, throw, and catch Statements

Links to an external site.


Reference: Microsoft staff, 2023, 'try, throw, and catch Statements', Microsoft Learn, accessed 31
January 2024, <https://learn.microsoft.com/en-us/cpp/cpp/try-throw-and-catch-statements-cpp>

Video: Exception Handling in C++


This video teaches you how to handle errors in your program and how to work with
exceptions on a real-life example.

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.

Exception Handling in C++

Links to an external site.

(24:46)

Reference: CodeBeauty, 2021, 'Exception Handling in C++', YouTube, accessed 31 January 2024,
<https://youtu.be/kjEhqgmEiWY>

Reading: TraceLogging C/C++ Quick Start


This article provides a step-by-step guide for incorporating TraceLogging into C/C++
user-mode code for Windows applications. It outlines the prerequisites, including
Microsoft Visual Studio 2013 or later and the Windows 10 SDK, and highlights the
importance of using advapi32.lib to avoid linker errors. The article explains the
process of defining and declaring a provider handle in a header file, registering and
unregistering the provider, and logging events using the TraceLoggingWrite macro.

TraceLogging C/C++ Quick Start

Links to an external site.

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>

Reading: Using C++ to Write Logs in Windows Event Viewer


This article discusses the use of C++ for writing logs in the Windows Event Viewer,
specifically focusing on utilizing NTSTATUS values for error identification. It explains
how NTSTATUS values are associated with error messages and how drivers can use
predefined values or define custom ones for logging.

Using C++ to Write Logs in Windows Event Viewer

Links to an external site.


Reference: Christina Holley, 2023, 'Using C++ to Write Logs in Windows Event Viewer', Copy
Programming, accessed 31 January 2024,
<https://copyprogramming.com/howto/log-to-event-viewer-on-windows-with-c>

You might also like