You are on page 1of 38

Agenda

Building
Make

Debugging
Gdb

Documenting
Doxygen
2

Build chain
An automatic build chain is useful to:
Com Com com files" Com com Com ile thousands of sou!ce files" ile #uickly: $ithout !unning manually the ile! and $ithout !ecom iling u %to%date ile easily: thi!d a!ties must be able to ile the code" ile on &a!ious latfo!ms"
3

Build chain: Make


Make:
(!aditional build chain in )nix en&i!onment" *e#ui!es a configu!ation file +Makefile," -u o!t command line a!amete!s" Based on the conce t of dependency" Based on the conce t of timestamp"

Cons:
.ot easily o!table" - ace +indentation, sensiti&e semantics"
'

Makefile
Makefile contains:
Configu!ation &a!iables"
0"g" $hich com ile! and linke! to use1 flags to be assed to com ile! and linke!"

Di!ecti&es +e"g" com iling inst!uctions,


2ta!get3: 2main sou!ce file3 2othe! files"""3 \tab 2com iling4linking commands3
.5(0: heade!s de ending on othe! heade!s can be 6u dated7 by using touch
/

Makefile
9a!iables:
9A*.AM0: 9A;)0;<-(
Assigns a a list of &alues1 at !eading time + o!table,"

9A*.AM0:: 9A;)0;<-(
Assigns to a &a!iable a list of &alues immediately +G.),"

9A*.AM0=: 9A;)0;<-(
Adds the list of &alues to !e&ious assigned &alues"

>+9A*.AM0,
*eads a &a!iable"
8

Makefile
Common &a!iable names:
CC: the C como ile!
C@;AG-: flags fo! the C com ile!"

CAA: the C== com ile!"


CAA@;AG-: flags fo! the C== com ile!"

;D: the linke!"


;D@;AG-: flags fo! the linke! ;D;<B-: lib!a!ies to link"
?

Makefile
C!edefined mac!os:
>D: the ta!get" >2: the fi!st de endency" >E: all the de endencies" >F: modified files" G: the cu!!ent file"

Makefile: - ecial ta!gets


@i!st ta!get:
0xecuted if make is !un $ithout othe! a!amete!s"

(a!get common names:


all: com iles and links all the ta!gets" clean: deletes gene!ated files" install: installs all gene!ated files" hel : !ints a list of ossible ta!gets" doc: gene!ates documentation"

"CI5.J
Collects as de endencies ta!gets $hich do not match any gene!ated file name +e"g" all1 clean,"
H

Makefile: *unning
*un make $ith Makefile1 on default ta!get:
make

*un make in a!allel +o tional: max numbe! of a!allel th!eads,:


make %M'

*un make $ith MyMake as config file:


make %f MyMake

*un make $ith a s ecific ta!get +a


make a "x
KL

"x,:

Makefile 0xam le K
@iles:
<m lementation: main.c com.c set.c Ieade!s: com.h set.h1 located into include"

Auxilia!y lib!a!ies:
-tanda!d C math lib!a!y" Custom libsupport.so located into lib"

KK

Makefile 0xam le K
# Configuring: CC:= gcc LD:= gcc CFLAGS:= -c -Wall -Iinclude LDFLAGS:= -Llib LDLIBS:= -lsupport -lm
K2

Makefile 0xam le K
# Sources: S CS:= main!c com!c set!c # "b#ects: "B$S:= $(SRCS,.c=.o)

K3

Makefile 0xam le K
# De%ault target: all: m&app!' m&app!': ()"B$S* @echo Lin+ing (, @$(LD) $(LDFLAGS) -o $@ $^ $(LDLI S) clean: ,rm -!o m&app!'
K'

Makefile 0xam le K
# Compiling. b& using # pattern matc/ing: !.o: !.c ,ec/o (, ,()CC* ()CFLAGS* -o (, (0 ."#$%&: '(( c(e'n
K/

Makefile 0xam le K
0xam le K !os:
9e!y sho!t" 9e!y !eusable"

0xam le K cons:
.ot fine tuned: does not ca tu!e de endencies !elated to heade! files"

K8

Makefile 0xam le 2
# Fine tuned compiling: )'in.o: )'in.c co).h *e+.h ,ec/o (, ,()CC* ()CFLAGS* -o (, (0 *e+.o: *e+.c *e+.h ,ec/o (, ,()CC* ()CFLAGS* -o (, (0 co).o: co).c co).h *e+.h ,ec/o (, ,()CC* ()CFLAGS* -o (, (0
K?

Makefile 0xam le 2
0xam le 2 !os:
Ca tu!es all the de endencies" 9e!y safe1 e&en in case of a!allel com iling"

0xam le 2 cons:
;onge! to $!ite" Cannot be !eused"

KB

Agenda
Building
Make

Debugging
Gdb

Documenting
Doxygen
KH

Debugging
9e!ification and debugging:
5ne of the ha!dest hases of de&elo ment" (he most time consuming acti&ity +?L%BLG,

<t is fundamental to use tools to:


-im lify debugging" - eed u the bug fixing"

2L

Debugge!
A debugge! allo$s:
(o sus end the execution of a !og!am in s ecific oints" (o execute the !og!am ste by ste " (o ins ect &a!iable &alues at !un%time"

2K

Debugge!
GDB +Gnu Debugge!,:
@!ee and o en sou!ce" -tanda!d tool used $ith gcc" *e#ui!es an en!iched executable:
gcc %g: com ile $ith debugging infos" gcc %ggdb: as %g1 but ta!geting gdb ex licitly"

Command line tool"


DDD is the most famous g!a hical inte!face"
22

GDB: Basic Commands


;oad an executable $ith gdb
gdb myNexec"x

Ouit f!om gdb:


#uit 4 #

-et e&entual executable a!amete!s


set a!gs 2 a!amete!s3

Iel about a to ic +e"g" about a command,


hel 2to ic3
23

GDB B!eak oints


B!eak oint:
A b!eak oint ma!ks a lace in the sou!ce code" (he execution of a !og!am is sus ended $hen a b!eak oint is !eached" )seful to ins ect the !og!am at !untime in a s ecific lace" Gdb syntax:
b!eak 4 b 2file:line3 b!eak 4 b 2method.ame3
2'

GDB Patch
Patch oint
-us ends the execution $hene&e! a $atched ex !ession changes its &alue" )seful to check the e&olution of a &a!iable" Gdb syntax:
$atch 2ex !ession3

2/

GDB 0x !ession e&aluation


C!int
C!ints the !esult of an ex !ession1 by using the cu!!ent &alues fo! the &a!iables" )seful to ins ect &a!iables" GDB syntax:
!int 4 2ex !ession3

28

GDB -tack ins ection


Backt!ace
C!inting the list of last method called" Allo$s to unde!stand the execution o!de!" GDB syntax:
backt!ace 4 bt

@!ame
C!ints infos about the cu!!ent method stack" GDB synthax:
f!ame 4 f +sho!t desc!, info f!ame 4 info f +long,
2?

GDB 0xecution
0xecutes a !og!am f!om the beginning: !un 4 ! Continues the execution1 f!om the !eached oint: continue 4 c 0xecute the next line atomically: next 4 n 0xecute the next inst!uction1 going into e&entual methods called: ste 4 s *e eat the last command: Q!etu!n
2B

Agenda
Building
Make

Debugging
Gdb

Documenting
Doxygen
2H

Documenting
Documentation:
@o! use!:
Manuals1 guides1 tuto!ials1 etc"" AC< documentation +fo! lib!a!ies,"

@o! de&elo e!s:


AC< documentation" <m lementation code documentation" 5the! +use cases1 s ecification1 etc","
3L

Documenting
-ou!ce code documentation:
Comments fo! the AC<"
Automatic gene!ation of AC< documentation"

Comments on im lementation details"


0mbedded in the sou!ce code"

3K

Doxygen
Doxygen:
(ool fo! automatic gene!ation of AC< documentation" *uns on many latfo!ms" @!ee and o en sou!ce" -u o!ts many languages"
C1 C==1 Ra&a"

-u

o!ts many out ut fo!mats"


32

HTML1 ;atex1 *(@"

*unning Doxygen
Gene!ate a configu!ation file +Doxyfile,:
doxygen %g

Configu!e the Doxyfile:


emacs Doxyfile

*un doxygen:
doxygen

*un $ith a s ecific configu!ation file:


doxygen Config@ile
33

Doxygen Configu!ation
Main configu!ation a!amete!s:
C*5R0C(N.AM0 +e"g" My;ib, 5)(C)(ND<*0C(5*J +e"g" doc, <.C)( 4 @<;0NCA((0*.- +e"g" s!c, *0C)*-<90 +e"g" J0-, 0AC;)D0 4 0AC;)D0NCA((0*.- +S"Ma&a, G0.0*A(0NS +e"g" G0.0*A(0NI(M;,
3'

Doxygen (ags
Doxygen a!ses s ecial comments:
4SS Comment a!sed +C, S4
4S Comment not a!sed +C, S4

444 Comment a!sed +C==,


44 Comemnt not a!sed +C==,

Doxygen acce t tags to manage s ecial documentation:


Dtag Qtag
3/

Doxygen (ags
Main tags:
Db!ief 2comment3
A sho!t comment"

D a!am 2 a!am.ame3 2comment3


@o! method a!amete!

D!etu!n 2comment3
@o! method !etu!n &alue"

Dth!o$ 2exce tion.ame3 2comment3


@o! exce tions th!o$n by a method +not fo! C,
38

Doxygen (ags
(ags fo! global documentation:
<nfo!mation about file content:
4SS Dfile S 2comment 3 S4

G!ou ing logically !elated methods:


4SS Dname 2g!ou .ame3S4 4SDT S4 2methodsPith(hei!Documentation3 4SDU S4
3?

Doxygen 0xam le
1-- ,name List accessors! -1 1-,2 -1 1-- ,brie% Gets t/e element at gi3en position! - Linear comple'it&! - ,param l 4/e list! - ,param pos 4/e position! - ,return 4/e stored element! -1 3oid - getList5lement) List - l. int pos *6 1-,7 -1
3B

You might also like