Debugging and Profiling - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Debugging and Profiling

Description:

command line options when you compile the program. Parallel Research Group, Kasetsart University ... Compiling. Compile with ' g ' flag. Starting GDB. gdb ... – PowerPoint PPT presentation

Number of Views:118
Avg rating:3.0/5.0
Slides: 30
Provided by: tharaa8
Category:

less

Transcript and Presenter's Notes

Title: Debugging and Profiling


1
Debugging and Profiling
  • Thara Angskun

2
Agenda
  • Debugging
  • printf()
  • preprocessor directives
  • gdb,xxgdb, gvd
  • strace, ltrace
  • debauch, electric fence
  • gjdb
  • Profiling
  • gprof

3
DEBUGGING
4
Printf()
  • __FILE__
  • __LINE__
  • __FUNCTION__
  • getpid() for thread

5
Example
/ File b.c / include ltstdio.hgt main()
printf(File s Function s Line d\n,
__FILE__,__FUNCTION__,__LINE__)
b38tra_at_psi b38tra ./a.out File b.c Function
main Line 5
6
Preprocessor Directive
  • define, undef
  • ifdef, ifndef, if, elif, else, endif

7
define, undef
define A define B 100 define C hello undef A
8
Logical Directive
ifdef MACRO lines to evaluate if MACRO is
defined else lines to evaluate if MACRO is not
defined endif ifndef MACRO lines to evaluate
if MACRO is not defined else lines to evaluate
if MACRO is defined endif
Macros can be defined or undefined with the -D'
and -U' command line options when you compile
the program
9
ONCE ONLY HEADER
/ File foo.h / ifndef FILE_FOO_SEEN define
FILE_FOO_SEEN the entire file endif
10
Logical Directive (cont)
if expression elif expression else endi
f
Example if defined (__vax__) defined
(__ns16000__) if BUFSIZE gt 1024
11
GDB (GNU debugger)
  • Compiling
  • Compile with g flag
  • Starting GDB
  • gdb
  • gdb myprog
  • gdb myprog core
  • gdb myprog ltpidgt

12
Frequently used command
  • Break point
  • break filefunction
  • break fileline
  • clear filefunction
  • clear fileline
  • info break
  • delete number
  • Run
  • run command-line-argument

13
Frequently used command
  • step, next
  • finish, continue, until
  • print
  • list
  • file
  • help
  • quit

14
XXGDB
15
GVD(GNU visual debugger)
16
GVD (Cont.)
17
Strace
  • System call tracer
  • can spawn new process to trace
  • can be invoked on an existing process
  • Support various OS

IRIXÃ’
18
Strace
  • strace (Linux,Windows NT, Windows2000)
  • trace (HP-UX 10.20 and below)
  • ktrace (BSD)
  • tusc (HP-UX 11.0 and later)
  • truss (Solaris2.6 and later, AIX, SCO-Unixware)
  • par (Irix)

19
Strace
  • No need to be recompiled
  • No need source code
  • Output are printed on stderr or the file that
    specific with o option

20
Output
  • SYSNAME(PARAMETER) RETURN_VALUE
  • open("/dev/null", O_RDONLY) 3
  • open("/foo/bar", O_RDONLY) -1 ENOENT (No such
    file or directory)
  • Display flag
  • open("xyzzy", O_WRONLYO_APPENDO_CREAT, 0666)
    3

21
Output
  • Display structure
  • lstat("/dev/null",st_modeS_IFCHR0666,
    st_rdevmakedev(1, 3), ...) 0
  • lstat("/foo/bar", 0xb004) -1 ENOENT (No such
    file or directory)
  • Display 32 first string
  • read(3, "root00System Administrator/"...,
    1024) 422

22
Output
  • Display array
  • getgroups(32, 100, 0) 2
  • Display bit-sets
  • sigprocmask(SIG_BLOCK, CHLD TTOU, ) 0
  • sigprocmask(SIG_UNBLOCK, , NULL) 0

23
Ltrace
  • Library call tracer
  • can spawn new process to trace
  • can be invoked on an existing process
  • Can not trace script language
  • Its use is very similar to Strace

24
Memory leak checker
  • debauch -a program argument
  • Electric Fence
  • compile with lefence
  • ef program argument
  • export LD_PRELOADlibefence.so.0.0
  • program argument

25
GJDB
  • Support various languages
  • C, C, Java, Pascal, Assembly, Lex-Yacc
  • Perl, Python, xml, xsl, html, MPI, etc.
  • Support various platform
  • UNIX, Windows

26
PROFILING
27
GPROF
  • Compiling
  • with option -pg
  • Running
  • program argument
  • Analyze
  • gprof program gmon.out

28
GPROF Result
Each sample counts as 0.01 seconds.
cumulative self self total
time seconds seconds calls us/call
us/call name 89.47 1.36 1.36 2
680000.00 680000.00 b 9.87 1.51 0.15
1 150000.00 150000.00 c 0.66 1.52
0.01 1 10000.00 690000.00 a
29
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com