Professional Documents
Culture Documents
What is Debugging?
Debugging is the art of removing bugs
from software.
Debugging is identifying the problem
and providing the solution to the
software program.
Debugging
Noticing
Localising
Understanding
Repairing bugs
Types of bugs
Semantic bugs
Using uninitialized variables
Array boundaries
Using out of range value
Pointer bugs
Common Mistakes
Programming without thinking
Writing code in an unstructured
manner
Works for some cases.
Too many Bugs
Hard to understand
Hard to debug
Hard to fix bugs
Structured Programming
Writing structured programs helps
greatly in debugging the code.
Some of the features of a structured
program:
Structured Programming
When a program is structured, it is
divided into sub-units that may be
tested and debugged separately.
Storing the sub-units of a program into
separate source files can make it
easier to debug them separately.
Sub-units can often be reused in other
programs.
Following Coding
Conventions
Set of rules for naming the file names
Ex: module_init.c, module_init.h
Function and variable naming
Ex: module_open(), module_close()
Ex: bool g_module_init_done;
Documentation
Documentation helps a lot to
understand and debug the code.
Write comments
Memcpy()
/* memcpy-- copy a non overlapping memory block */
void *memcpy(void *pvTo,void *pvFrom, size_t size)
byte *pbTo
byte *pbFrom
= (byte *) pvTo;
= (byte *) pvFrom;
byte *pbTo
byte *pbFrom
= (byte *) pvTo;
= (byte *) pvFrom;
#ifdef DEBUG
if ( pvTo == NULL || pvFrom == NULL )
{
fprintf(stderr, Bad args in memcpy\n);
halt();
}
#endif
while ( size-- > 0 )
{
*pbTo++ = *pbFrom++;
}
return( pvTo );
}
Add asserts
The assert is used (with a booleanexpression parameter) to check
assumptions
If the expression is TRUE nothing
happens, if FALSE, a message is
printed and the program can be
stopped.
*/
{
byte *pbTo
= (byte *) pvTo;
byte *pbFrom
= (byte *) pvFrom;
}
return( pvTo );
}
Debugger functions
Debugging Techniques
Rule of Thumb: Write good, bug-free
code from beggining
Testing/Debugging embedded
software is more difficult than
application software
Post-shipment application problems
are more tolerable than embedded
(real-time or life-critical) software
(continued)
B) a component of the routine which deals with the rest of the system
2) To test, structure the routine such that the hardware-dependent component (A)
calls the hardware-independent part (B).
The test scaffold, vTestMain(), then calls vHandleByte(), to test if the system works
[where vTestMain() pretends to be the hardware sending the chars to vHandleByte()]
(continued)
BYTE *p_by;
.
.
/* Send each of the characters in a_byTestCommand */
p_by = a_byTestCommand;
while (*p_by)
{
/* Send a single character as though received by the interrupt */
vHandleRxByte (*p_by);
/* Go to the next character */
++p_by;
}
.
.
}
Capabilities of Simulators:
Easier to test for portability since simulator takes same Map as the
target
Other parts, e.g., timers and built-in peripherals, can be tested in the
corresponding simulated versions in the simulated microprocessor
architecture
Logic Analyzer
Like storage scopes that (first) capture many
signals and displays them simultaneously
It knows only of VCC and ground voltage levels
(displays are like timing diagrams) Real scopes
display exact voltage (like analog)
Can be used to trigger on-symptom and track
back in stored signal to isolate problem
Many signals can be triggered at their low and/or
high points and for how long in that state
Used in Timing or State Mode
LA cant capture all signals, e.g., on fetch from caches, registers, unaccessed memory
ICE v. LA
LAs have better trace and filtering mechanism, and easier to detail and find
problems
LAs support many but select signals to attach, ICE requires connecting ALL
signals
Software-Only Monitors
Logging
Logging is the process of recording
events, with an automated program.
To provide an audit trail that can be
used to understand the activity of the
system and to diagnose problems.
To understanding the activities of
complex systems particularly in the
case of applications with little user
interaction (such as server
applications).
Examples
Physical systems which have logging
subsystems include process control
systems (Telemetry).
Black box recorders in aircraft.
Many operating systems and
multitudinous computer programs
include some form of logging
subsystem.
Log messages are written to a log file /
memory.
Interpreting Logs
logs are esoteric or too verbose and
therefore hard to understand.
Logs are analyzed with special log
analysis software.
Ex: USB data packets log
Ex: Network data packets log
Transaction Logs
Database systems maintains separate
log called transaction log.
This is used to recover the database
from crash.
Maintain the data in consistent state.
Data Loggers
A data logger is an electronic device
that records data over time.
Generally they are small, battery
powered, portable, and equipped with
a microprocessor, internal memory for
data storage, and sensors.
Connected to PC to analyze the data.
Tracing
Tracing is a specialized use of logging
to record information about a
program's execution.
This information is typically used by
programmers for debugging purposes.
Provides low level information of the
programs execution.
Software tracing
Provides Developers with information
useful for debugging.
It is used both during the development
cycle and after the software is
released.
Tracing messages should be kept in
the code, they can add to the
readability of the code.
Some Considerations
Performance of the system.
Tracing data may include sensitive
information about the product's source
code. Security information like secret
key.
Diagnostics
A diagnostic program is a program
written for the express purpose of
locating problems with the software,
hardware, or any combination thereof
in a system, or a network of systems.
Preferably, diagnostic programs
provide solutions to the user to solve
issues.
Examples
Diagnostics that are run on-demand when a
user needs assistance, typically within the
primary operating system of the computer
(e.g. Linux, Windows)
"Off-line diagnostics" that are run outside the
primary operating system, typically to reduce
the masking influence of software on
hardware issues.
Background diagnostics that monitor the
system for failures and marginal events, and
provide statistical data for failure prediction,
and root cause analysis of actual failure
Types of Diagnostics
Manufacturing testing program with an
emphasis on checking assemblyrelated issues.
End-user targeted diagnostics, easy,
non-technical and an emphasis on
solutions.
Service/warranty testing, focusing on
identifying a failed unit.
Hardware components have specific
features to assist a diagnostic
Questions?