MSL2008. Debugging
-
Upload
juan-a-suarez-romero -
Category
Education
-
view
111 -
download
0
description
Transcript of MSL2008. Debugging
Master on Free Software
What is a bug?
● Basically, an error in a program● When a program performs as it shouldn't
perform ● All software have bugs
– Programming is complex– Human task -> errors
Master on Free Software
Type of bugs● Resource-accessing bugs● Semantic bugs
– Wrong results– Unfullfil specifications
● Performance bugs● Memory bugs
– Overflows => crashes– Leaks
● Concurrent bugs
Master on Free Software
Bugfixing
● Find a bug– By developers– By users
● Report a bug– Bugzilla
● Locate the problem– Debugging tools
● Fix it
Master on Free Software
Finding bugs
● By developers
– Compile-time errors are not bugs!
– Running time
● By chance● Running tests● Using tools (see debugging)
● By users
– They don't look for, but bugs turn up!
– Reported to developers
● By testers
– Mix between developers and users
– Use more sophisticated techniques
Master on Free Software
Reporting bugs
● Crash-report applications● Bugtrackers: issue tracker system
– Open a ticket (bug)– Add comments and/or other stuff– Tickets have states (life cycle)– Close ticket (bug)– Examples
● Bugzilla (from Mozilla Project)● Mantis Bug Tracker
Master on Free Software
Finding the problem
● To find something, we need to know about it– Develop small tests to reproduce the problem– Use debugging tools
● Debuggers● Profilers● Memory checkers● ...
Master on Free Software
Fixing bugs
● Using input from the last point● Verify tests perform fine
– Bug is fixed– Not introduce new bugs
● Document and commit
Master on Free Software
Bugzilla
● Developed by Mozilla Foundation (1998)● Web-based (LAMP)● Widely used● Highly configurable
Master on Free Software
Bugzilla
Master on Free Software
Bugzilla
Master on Free Software
Bugzilla
Where is the bug?
Master on Free Software
Bugzilla
Severity of bug Blocker Critical Major Normal Minor
Master on Free Software
Bugzilla
Bug description Overview Preconditions Steps to reproduce Actual results Expected results Frequency Other relevant information
Master on Free Software
Bugzilla
● Priority: How urgent is to fix the bug?● Differences between severity and priority
– Severity is a technical matter– Priority is a business matter– Severity is absolute– Priority is relative– Priority can be calculated from severity
Master on Free Software
Bugzilla
Master on Free Software
Bugzilla
Master on Free Software
Triagging
● Medical term: choose which patient would receive medical cares
● Useful when there are a lot of bugs, but few developers– Share bugs among developers– Use bug features and developers habilities to
assign the bugs
Master on Free Software
Bugzilla
Master on Free Software
Bugzilla
From Bugzilla Documentation
Master on Free Software
Some tools
● Printf ;-)● GDB (GNU Debugger)● Valgrind● Electric Fence● OProfile● G_DEBUG (fatal_warnings, fatal_criticals)
Master on Free Software
● Profile all running code
OProfile
Master on Free Software
Electric Fence
● Find overflows / underflows● Easy to use: preload/link against efence
library● Mark with “red zones” buffers
– Crash inmediately when touching them– Thus, errors don't turn up in a future time
Master on Free Software
G_DEBUG
● Useful to debug problems in Glib● Environment variable
– fatal_criticals: g_critical generates a core dump
– fatal_warnings: g_warning generates a core dump
Master on Free Software
Valgrind
● Tool suite for debugging and profiling● Simulates a x86 processor
– Memcheck: memory problems● Memory accesses not allowed● Memory leaks● Bad frees
– Cachegrind: cache profiler– Massif: heap profiler– Helgrind: thread debugger
Master on Free Software
GDB
● GNU Debugger● Text mode
– Other frontends: IDEs, emacs, DDD, XXGDB
● Trace the code– See what is doing– Inspect the data
Master on Free Software
GDB
● Requirements to debug an application– Add debugging symbols -> not stripped– Remove optimizations (-O0)
Master on Free Software
GDB
● How to use– Run process with gdb– Inspect core dumps– Attach to running process
Master on Free Software
Core dumps
● Dump of information of a process when it crashes– See while it crashed– Inspect data
● ulimit -c <size of core>● ./gdb <program> <core>
Master on Free Software
GDB● Run: runs the program from start
● Continue: continues running a stopped program
● Backtrace: show the stack
● Break: add a breakpoint
● Delete: delete a breakpoint
● Next: runs the current line to next
● Step: same as Next, but if current is a function, enter inside
● Print: print the content of a variable
● Display: same as Print, but more permanent
Master on Free Software
References
● http://www.google.es● http://www.wikipedia.org● http://www.bugzilla.org● http://www.mantisbt.org● http://library.gnome.org/devel/glib/unstable/glib-running.html
● http://sourceware.org/gdb/● http://oprofile.sourceforge.net● http://valgrind.org