MSL2008. Debugging

31
Master on Free Software Debugging Juan A. Suárez Romero <[email protected]>

description

Presentation about debugging done at Master on Free Software 2008 Edition

Transcript of MSL2008. Debugging

Page 1: MSL2008. Debugging

Master on Free Software

DebuggingJuan A. Suárez Romero

<[email protected]>

Page 2: 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

Page 3: MSL2008. Debugging

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

Page 4: MSL2008. Debugging

Master on Free Software

Bugfixing

● Find a bug– By developers– By users

● Report a bug– Bugzilla

● Locate the problem– Debugging tools

● Fix it

Page 5: MSL2008. Debugging

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

Page 6: MSL2008. Debugging

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

Page 7: MSL2008. Debugging

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

Page 8: MSL2008. Debugging

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

Page 9: MSL2008. Debugging

Master on Free Software

Bugzilla

● Developed by Mozilla Foundation (1998)● Web-based (LAMP)● Widely used● Highly configurable

Page 10: MSL2008. Debugging

Master on Free Software

Bugzilla

Page 11: MSL2008. Debugging

Master on Free Software

Bugzilla

Page 12: MSL2008. Debugging

Master on Free Software

Bugzilla

Where is the bug?

Page 13: MSL2008. Debugging

Master on Free Software

Bugzilla

Severity of bug­ Blocker­ Critical­ Major­ Normal­ Minor

Page 14: MSL2008. Debugging

Master on Free Software

Bugzilla

Bug description­ Overview­ Preconditions­ Steps to reproduce­ Actual results­ Expected results­ Frequency­ Other relevant information

Page 15: MSL2008. Debugging

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

Page 16: MSL2008. Debugging

Master on Free Software

Bugzilla

Page 17: MSL2008. Debugging

Master on Free Software

Bugzilla

Page 18: MSL2008. Debugging

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

Page 19: MSL2008. Debugging

Master on Free Software

Bugzilla

Page 20: MSL2008. Debugging

Master on Free Software

Bugzilla

From Bugzilla Documentation

Page 21: MSL2008. Debugging

Master on Free Software

Some tools

● Printf ;-)● GDB (GNU Debugger)● Valgrind● Electric Fence● OProfile● G_DEBUG (fatal_warnings, fatal_criticals)

Page 22: MSL2008. Debugging

Master on Free Software

● Profile all running code

OProfile

Page 23: MSL2008. Debugging

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

Page 24: MSL2008. Debugging

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

Page 25: MSL2008. Debugging

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

Page 26: MSL2008. Debugging

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

Page 27: MSL2008. Debugging

Master on Free Software

GDB

● Requirements to debug an application– Add debugging symbols -> not stripped– Remove optimizations (-O0)

Page 28: MSL2008. Debugging

Master on Free Software

GDB

● How to use– Run process with gdb– Inspect core dumps– Attach to running process

Page 29: MSL2008. Debugging

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>

Page 30: MSL2008. Debugging

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

Page 31: MSL2008. Debugging

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