2. 2
WHAT IS A DEBUGGER?
“A software tool that is used to detect the
source of program or script errors, by
performing step-by-step execution of
application code and viewing the content of
code variables.”
-MSDN
3. 3
DEBUGGER? (CON'T)
A debugger is not an IDE
Though the two can be integrated, they are separate
entities.
A debugger loads in a program (compiled
executable, or interpreted source code) and
allows the user to trace through the execution.
Debuggers typically can do disassembly, stack
traces, expression watches, and more.
4. DEBUGGING
Debugging is a methodical process of finding
and reducing the number of bugs, or defects, in a
computer program
An interactive debugging system provides
programmers with facilities that aid in testing and
debugging of programs
Here we discuss
◦ Introducing important functions and capabilities
of IDS
◦ Relationship of IDS to other parts of the system
◦ The nature of the user interface for IDS
5. 5
OTHER FORMS OF DEBUGGING
Periodic printf/cout/print/write/etc.
Statements with relevant information
Assert statements
Desk Checking
6. 6
TYPES OF DEBUGGERS
Two types of debuggers (really, two types
of languages)
Interpreted language debuggers
Compiled language debuggers
Which do you think is easier to write?
7. 7
DEBUGGERS FOR COMPILED LANGUAGES
Harder to implement
Generally, would like information about source
code (not normally included in compiled
executables)
Work on a lower level
Need special “debug” executables.
More complex, and we'll focus on these.
8. DEBUGGING PROCESS
Print debugging is the act of watching (live or
recorded) trace statements, or print statements, that
indicate the flow of execution of a process.
In computers, debugging is the process of locating
and fixing or bypassing bugs (errors) in computer
program code or the engineering of a hardware
device.
Remote debugging is the process of debugging a
program running on a system different than the
debugger.
Post-mortem debugging is the act of debugging the
core dump of process.
9. DEBUGGING FUNCTIONS AND CAPABILITIES
Debugging system should also provide functions
such as tracing and trace back
Trace back can show the path by which the
current statement in the program was reached.
It can also show which statements have modified
a given variable or parameter.
The statements are displayed rather than as
hexadecimal displacements
10. PROGRAM-DISPLAY CAPABILITIES
A debugger should have good program-display
capabilities.
Program being debugged should be displayed
completely with statement numbers.
The program may be displayed as originally written
or with macro expansion.
Keeping track of any changes made to the programs
during the debugging session.
Support for symbolically displaying or modifying
the contents of any of the variables and constants in
the program.
Resume execution – after these changes
11. The context being used has many different effects on the
debugging interaction.
The statements are different depending on the language
Cobol - MOVE 6.5 TO X
Fortran - X = 6.5
C - X = 6.5
Examples of assignment statements
Similarly, the condition that X be unequal to Z may be
expressed as
Cobol - IF X NOT EQUAL TO Z
Fortran - IF ( X.NE.Z)
C - IF ( X <> Z)
12. It is also important that a debugging system be
able to deal with optimized code. Many
optimizations like
◦ Invariant expressions can be removed from
loops
◦ Separate loops can be combined into a
single loop
◦ Redundant expression may be eliminated
◦ Elimination of unnecessary branch
instructions
13. RELATIONSHIP WITH OTHER PARTS OF
THE SYSTEM
The important requirement for an interactive
debugger is that it always be available.
Must appear as part of the run-time
environment and an integral part of the
system.
When an error is discovered, immediate
debugging must be possible.
The debugger must communicate and
cooperate with other operating system
components such as interactive subsystems.
14. Debugging is more important at production
time than it is at application-development
time.
When an application fails during a production
run, work dependent on that application stops.
The debugger must also exist in a way that is
consistent with the security and integrity
components of the system.
The debugger must coordinate its activities
with those of existing and future language
compilers and interpreters.
15. USER-INTERFACE CRITERIA
Debugging systems should be simple in its
organization and familiar in its language,
closely reflect common user tasks.
The user interaction should make use of
full-screen displays and windowing-
systems as much as possible.
With menus and full-screen editors, the user
has far less information to enter and
remember.
16. USER-INTERFACE CRITERIA
There should be complete functional
equivalence between commands and menus
– user where unable to use full-screen IDSs
may use commands.
The command language should have a clear,
logical and simple syntax; command
formats should be as flexible as possible.
Any good IDSs should have an on-line
HELP facility. HELP should be accessible
from any state of the debugging session.
17. 17
FUNCTIONS OF A DEBUGGER
Disassembly
Execution Tracing/Stack tracing
Symbol watches
18. 18
DISASSEMBLY
Most basic form of debugging
Translating machine code into assembly
instructions that are more easily
understood by the user.
Typically implementable as a simple lookup
table
No higher-level information (variable
names, etc.)
Relatively easy to implement.
19. 19
EXECUTION TRACING
Follows the program through the execution.
Users can step through line-by-line, or use
breakpoints.
Typically allows for “watches” on – registers,
memory locations, symbols
Allows for tracing up the stack of runtime
errors (back traces)
Allows user to trace the causes of
unexpected behavior and fix them
20. 20
SYMBOL INFORMATION
Problem – a compiler/assembler translates
variable names and other symbols into
internally consistent memory addresses
How does a debugger know which location is
denoted by a particular symbol?
We need a “debug” executable.
21. BASIC DEBUGGER DIVISION
Host debugger
Provides user
interface
Provides lookup of
debug information
Communicates with
target
Target Debug
Monitor
In control of the
target
When program
being debugged
stops, control is
given to the debug
monitor
22. JTAG DEBUGGING
Host debugger
Provides user
interface
Provides lookup of
debug information
Communicates with
target
Target
Program in
control – no
debug
monitor
present
JTAG
Probe
23. JTAG PROBE
Provides direct access to the registers and
memory of the target through the hardware.
May be “smart enough” to know about cache.
Using JTAG means program being debugged
runs more normally – no debug monitor.
24. EMBEDDED DEBUGGING
Properties of a debugging environment:
1. Run Control of the target
- Start and stop the program execution
2. Ability to change code and data on target
- Fix errors, test alternatives
3. Real-Time Monitoring of target execution
- Non-intrusive in terms of performance
4. Timing and Functional Accuracy
- Debugged system should act like the real system
25. HOST DEBUGGER COMPONENTS
Debugger FunctionsUICC
Expression
Evaluation
Debug Info Context
Breakpoints
Execution
Control
Symbol
Table
Target T.I.P.
Host-Target
Protocol
Run
Time
Msg.
Utilities
Debugger
Types
Seq.
Interface
26. HOST-BASED DEBUGGING
- Compile C to your laptop, not the microcontroller
Compile and debug your program on the host system not target
Advantages:
1.Can use a debugging environment
2.Easy to try it, not much setup (register names, etc)
Disadvantages:
1.Timing is way off
2.Peripherals will not work, need to simulate them
3.Interrupts probably implemented differently
4.Different data sizes and “endian”ness
27. 27
DEBUG VS. RELEASE BUILDS
Debug builds usually are not optimized
Debug executables contain:
program's symbol tables
location of the source file
line number tags for assembly instuctions.
28. 28
PROS OF A DEBUGGER:-
No need for precognition of what the error
might be.
Flexible
Allows for “live” error checking – no need to
re-write and re-compile when you realize a
certain type of error may be occuring
Dynamic
Can view the entire relevant scope
29. 29
CONS OF A DEBUGGER :-
With simple errors, may not want to bother
with starting up the debugger environment.
Obvious error
Simple to check using prints/asserts
Hard-to-use debugger environment
Error occurs in optimized code
Changes execution of program (error
doesn’t occur while running debugger)