arm-linux-gnueabihf-gcov.1 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is turned on, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{
  60. . if \nF \{
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "GCOV 1"
  136. .TH GCOV 1 "2019-11-14" "gcc-7.5.0" "GNU"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. gcov \- coverage testing tool
  143. .SH "SYNOPSIS"
  144. .IX Header "SYNOPSIS"
  145. gcov [\fB\-v\fR|\fB\-\-version\fR] [\fB\-h\fR|\fB\-\-help\fR]
  146. [\fB\-a\fR|\fB\-\-all\-blocks\fR]
  147. [\fB\-b\fR|\fB\-\-branch\-probabilities\fR]
  148. [\fB\-c\fR|\fB\-\-branch\-counts\fR]
  149. [\fB\-d\fR|\fB\-\-display\-progress\fR]
  150. [\fB\-f\fR|\fB\-\-function\-summaries\fR]
  151. [\fB\-i\fR|\fB\-\-intermediate\-format\fR]
  152. [\fB\-l\fR|\fB\-\-long\-file\-names\fR]
  153. [\fB\-m\fR|\fB\-\-demangled\-names\fR]
  154. [\fB\-n\fR|\fB\-\-no\-output\fR]
  155. [\fB\-o\fR|\fB\-\-object\-directory\fR \fIdirectory|file\fR]
  156. [\fB\-p\fR|\fB\-\-preserve\-paths\fR]
  157. [\fB\-r\fR|\fB\-\-relative\-only\fR]
  158. [\fB\-s\fR|\fB\-\-source\-prefix\fR \fIdirectory\fR]
  159. [\fB\-u\fR|\fB\-\-unconditional\-branches\fR]
  160. [\fB\-x\fR|\fB\-\-hash\-filenames\fR]
  161. \fIfiles\fR
  162. .SH "DESCRIPTION"
  163. .IX Header "DESCRIPTION"
  164. \&\fBgcov\fR is a test coverage program. Use it in concert with \s-1GCC\s0
  165. to analyze your programs to help create more efficient, faster running
  166. code and to discover untested parts of your program. You can use
  167. \&\fBgcov\fR as a profiling tool to help discover where your
  168. optimization efforts will best affect your code. You can also use
  169. \&\fBgcov\fR along with the other profiling tool, \fBgprof\fR, to
  170. assess which parts of your code use the greatest amount of computing
  171. time.
  172. .PP
  173. Profiling tools help you analyze your code's performance. Using a
  174. profiler such as \fBgcov\fR or \fBgprof\fR, you can find out some
  175. basic performance statistics, such as:
  176. .IP "*" 4
  177. how often each line of code executes
  178. .IP "*" 4
  179. what lines of code are actually executed
  180. .IP "*" 4
  181. how much computing time each section of code uses
  182. .PP
  183. Once you know these things about how your code works when compiled, you
  184. can look at each module to see which modules should be optimized.
  185. \&\fBgcov\fR helps you determine where to work on optimization.
  186. .PP
  187. Software developers also use coverage testing in concert with
  188. testsuites, to make sure software is actually good enough for a release.
  189. Testsuites can verify that a program works as expected; a coverage
  190. program tests to see how much of the program is exercised by the
  191. testsuite. Developers can then determine what kinds of test cases need
  192. to be added to the testsuites to create both better testing and a better
  193. final product.
  194. .PP
  195. You should compile your code without optimization if you plan to use
  196. \&\fBgcov\fR because the optimization, by combining some lines of code
  197. into one function, may not give you as much information as you need to
  198. look for `hot spots' where the code is using a great deal of computer
  199. time. Likewise, because \fBgcov\fR accumulates statistics by line (at
  200. the lowest resolution), it works best with a programming style that
  201. places only one statement on each line. If you use complicated macros
  202. that expand to loops or to other control structures, the statistics are
  203. less helpful\-\-\-they only report on the line where the macro call
  204. appears. If your complex macros behave like functions, you can replace
  205. them with inline functions to solve this problem.
  206. .PP
  207. \&\fBgcov\fR creates a logfile called \fI\fIsourcefile\fI.gcov\fR which
  208. indicates how many times each line of a source file \fI\fIsourcefile\fI.c\fR
  209. has executed. You can use these logfiles along with \fBgprof\fR to aid
  210. in fine-tuning the performance of your programs. \fBgprof\fR gives
  211. timing information you can use along with the information you get from
  212. \&\fBgcov\fR.
  213. .PP
  214. \&\fBgcov\fR works only on code compiled with \s-1GCC. \s0 It is not
  215. compatible with any other profiling or test coverage mechanism.
  216. .SH "OPTIONS"
  217. .IX Header "OPTIONS"
  218. .IP "\fB\-a\fR" 4
  219. .IX Item "-a"
  220. .PD 0
  221. .IP "\fB\-\-all\-blocks\fR" 4
  222. .IX Item "--all-blocks"
  223. .PD
  224. Write individual execution counts for every basic block. Normally gcov
  225. outputs execution counts only for the main blocks of a line. With this
  226. option you can determine if blocks within a single line are not being
  227. executed.
  228. .IP "\fB\-b\fR" 4
  229. .IX Item "-b"
  230. .PD 0
  231. .IP "\fB\-\-branch\-probabilities\fR" 4
  232. .IX Item "--branch-probabilities"
  233. .PD
  234. Write branch frequencies to the output file, and write branch summary
  235. info to the standard output. This option allows you to see how often
  236. each branch in your program was taken. Unconditional branches will not
  237. be shown, unless the \fB\-u\fR option is given.
  238. .IP "\fB\-c\fR" 4
  239. .IX Item "-c"
  240. .PD 0
  241. .IP "\fB\-\-branch\-counts\fR" 4
  242. .IX Item "--branch-counts"
  243. .PD
  244. Write branch frequencies as the number of branches taken, rather than
  245. the percentage of branches taken.
  246. .IP "\fB\-d\fR" 4
  247. .IX Item "-d"
  248. .PD 0
  249. .IP "\fB\-\-display\-progress\fR" 4
  250. .IX Item "--display-progress"
  251. .PD
  252. Display the progress on the standard output.
  253. .IP "\fB\-f\fR" 4
  254. .IX Item "-f"
  255. .PD 0
  256. .IP "\fB\-\-function\-summaries\fR" 4
  257. .IX Item "--function-summaries"
  258. .PD
  259. Output summaries for each function in addition to the file level summary.
  260. .IP "\fB\-h\fR" 4
  261. .IX Item "-h"
  262. .PD 0
  263. .IP "\fB\-\-help\fR" 4
  264. .IX Item "--help"
  265. .PD
  266. Display help about using \fBgcov\fR (on the standard output), and
  267. exit without doing any further processing.
  268. .IP "\fB\-i\fR" 4
  269. .IX Item "-i"
  270. .PD 0
  271. .IP "\fB\-\-intermediate\-format\fR" 4
  272. .IX Item "--intermediate-format"
  273. .PD
  274. Output gcov file in an easy-to-parse intermediate text format that can
  275. be used by \fBlcov\fR or other tools. The output is a single
  276. \&\fI.gcov\fR file per \fI.gcda\fR file. No source code is required.
  277. .Sp
  278. The format of the intermediate \fI.gcov\fR file is plain text with
  279. one entry per line
  280. .Sp
  281. .Vb 4
  282. \& file:<source_file_name>
  283. \& function:<line_number>,<execution_count>,<function_name>
  284. \& lcount:<line number>,<execution_count>
  285. \& branch:<line_number>,<branch_coverage_type>
  286. \&
  287. \& Where the <branch_coverage_type> is
  288. \& notexec (Branch not executed)
  289. \& taken (Branch executed and taken)
  290. \& nottaken (Branch executed, but not taken)
  291. \&
  292. \& There can be multiple <file> entries in an intermediate gcov
  293. \& file. All entries following a <file> pertain to that source file
  294. \& until the next <file> entry.
  295. .Ve
  296. .Sp
  297. Here is a sample when \fB\-i\fR is used in conjunction with \fB\-b\fR option:
  298. .Sp
  299. .Vb 9
  300. \& file:array.cc
  301. \& function:11,1,_Z3sumRKSt6vectorIPiSaIS0_EE
  302. \& function:22,1,main
  303. \& lcount:11,1
  304. \& lcount:12,1
  305. \& lcount:14,1
  306. \& branch:14,taken
  307. \& lcount:26,1
  308. \& branch:28,nottaken
  309. .Ve
  310. .IP "\fB\-l\fR" 4
  311. .IX Item "-l"
  312. .PD 0
  313. .IP "\fB\-\-long\-file\-names\fR" 4
  314. .IX Item "--long-file-names"
  315. .PD
  316. Create long file names for included source files. For example, if the
  317. header file \fIx.h\fR contains code, and was included in the file
  318. \&\fIa.c\fR, then running \fBgcov\fR on the file \fIa.c\fR will
  319. produce an output file called \fIa.c##x.h.gcov\fR instead of
  320. \&\fIx.h.gcov\fR. This can be useful if \fIx.h\fR is included in
  321. multiple source files and you want to see the individual
  322. contributions. If you use the \fB\-p\fR option, both the including
  323. and included file names will be complete path names.
  324. .IP "\fB\-m\fR" 4
  325. .IX Item "-m"
  326. .PD 0
  327. .IP "\fB\-\-demangled\-names\fR" 4
  328. .IX Item "--demangled-names"
  329. .PD
  330. Display demangled function names in output. The default is to show
  331. mangled function names.
  332. .IP "\fB\-n\fR" 4
  333. .IX Item "-n"
  334. .PD 0
  335. .IP "\fB\-\-no\-output\fR" 4
  336. .IX Item "--no-output"
  337. .PD
  338. Do not create the \fBgcov\fR output file.
  339. .IP "\fB\-o\fR \fIdirectory|file\fR" 4
  340. .IX Item "-o directory|file"
  341. .PD 0
  342. .IP "\fB\-\-object\-directory\fR \fIdirectory\fR" 4
  343. .IX Item "--object-directory directory"
  344. .IP "\fB\-\-object\-file\fR \fIfile\fR" 4
  345. .IX Item "--object-file file"
  346. .PD
  347. Specify either the directory containing the gcov data files, or the
  348. object path name. The \fI.gcno\fR, and
  349. \&\fI.gcda\fR data files are searched for using this option. If a directory
  350. is specified, the data files are in that directory and named after the
  351. input file name, without its extension. If a file is specified here,
  352. the data files are named after that file, without its extension.
  353. .IP "\fB\-p\fR" 4
  354. .IX Item "-p"
  355. .PD 0
  356. .IP "\fB\-\-preserve\-paths\fR" 4
  357. .IX Item "--preserve-paths"
  358. .PD
  359. Preserve complete path information in the names of generated
  360. \&\fI.gcov\fR files. Without this option, just the filename component is
  361. used. With this option, all directories are used, with \fB/\fR characters
  362. translated to \fB#\fR characters, \fI.\fR directory components
  363. removed and unremoveable \fI..\fR
  364. components renamed to \fB^\fR. This is useful if sourcefiles are in several
  365. different directories.
  366. .IP "\fB\-r\fR" 4
  367. .IX Item "-r"
  368. .PD 0
  369. .IP "\fB\-\-relative\-only\fR" 4
  370. .IX Item "--relative-only"
  371. .PD
  372. Only output information about source files with a relative pathname
  373. (after source prefix elision). Absolute paths are usually system
  374. header files and coverage of any inline functions therein is normally
  375. uninteresting.
  376. .IP "\fB\-s\fR \fIdirectory\fR" 4
  377. .IX Item "-s directory"
  378. .PD 0
  379. .IP "\fB\-\-source\-prefix\fR \fIdirectory\fR" 4
  380. .IX Item "--source-prefix directory"
  381. .PD
  382. A prefix for source file names to remove when generating the output
  383. coverage files. This option is useful when building in a separate
  384. directory, and the pathname to the source directory is not wanted when
  385. determining the output file names. Note that this prefix detection is
  386. applied before determining whether the source file is absolute.
  387. .IP "\fB\-u\fR" 4
  388. .IX Item "-u"
  389. .PD 0
  390. .IP "\fB\-\-unconditional\-branches\fR" 4
  391. .IX Item "--unconditional-branches"
  392. .PD
  393. When branch probabilities are given, include those of unconditional branches.
  394. Unconditional branches are normally not interesting.
  395. .IP "\fB\-v\fR" 4
  396. .IX Item "-v"
  397. .PD 0
  398. .IP "\fB\-\-version\fR" 4
  399. .IX Item "--version"
  400. .PD
  401. Display the \fBgcov\fR version number (on the standard output),
  402. and exit without doing any further processing.
  403. .IP "\fB\-w\fR" 4
  404. .IX Item "-w"
  405. .PD 0
  406. .IP "\fB\-\-verbose\fR" 4
  407. .IX Item "--verbose"
  408. .PD
  409. Print verbose informations related to basic blocks and arcs.
  410. .IP "\fB\-x\fR" 4
  411. .IX Item "-x"
  412. .PD 0
  413. .IP "\fB\-\-hash\-filenames\fR" 4
  414. .IX Item "--hash-filenames"
  415. .PD
  416. By default, gcov uses the full pathname of the source files to to create
  417. an output filename. This can lead to long filenames that can overflow
  418. filesystem limits. This option creates names of the form
  419. \&\fI\fIsource-file\fI##\fImd5\fI.gcov\fR,
  420. where the \fIsource-file\fR component is the final filename part and
  421. the \fImd5\fR component is calculated from the full mangled name that
  422. would have been used otherwise.
  423. .PP
  424. \&\fBgcov\fR should be run with the current directory the same as that
  425. when you invoked the compiler. Otherwise it will not be able to locate
  426. the source files. \fBgcov\fR produces files called
  427. \&\fI\fImangledname\fI.gcov\fR in the current directory. These contain
  428. the coverage information of the source file they correspond to.
  429. One \fI.gcov\fR file is produced for each source (or header) file
  430. containing code,
  431. which was compiled to produce the data files. The \fImangledname\fR part
  432. of the output file name is usually simply the source file name, but can
  433. be something more complicated if the \fB\-l\fR or \fB\-p\fR options are
  434. given. Refer to those options for details.
  435. .PP
  436. If you invoke \fBgcov\fR with multiple input files, the
  437. contributions from each input file are summed. Typically you would
  438. invoke it with the same list of files as the final link of your executable.
  439. .PP
  440. The \fI.gcov\fR files contain the \fB:\fR separated fields along with
  441. program source code. The format is
  442. .PP
  443. .Vb 1
  444. \& <execution_count>:<line_number>:<source line text>
  445. .Ve
  446. .PP
  447. Additional block information may succeed each line, when requested by
  448. command line option. The \fIexecution_count\fR is \fB\-\fR for lines
  449. containing no code. Unexecuted lines are marked \fB#####\fR or
  450. \&\fB=====\fR, depending on whether they are reachable by
  451. non-exceptional paths or only exceptional paths such as \*(C+ exception
  452. handlers, respectively. Given \fB\-a\fR option, unexecuted blocks are
  453. marked \fB$$$$$\fR or \fB%%%%%\fR, depending on whether a basic block
  454. is reachable via non-exceptional or exceptional paths.
  455. .PP
  456. Note that \s-1GCC\s0 can completely remove the bodies of functions that are
  457. not needed \*(-- for instance if they are inlined everywhere. Such functions
  458. are marked with \fB\-\fR, which can be confusing.
  459. Use the \fB\-fkeep\-inline\-functions\fR and \fB\-fkeep\-static\-functions\fR
  460. options to retain these functions and
  461. allow gcov to properly show their \fIexecution_count\fR.
  462. .PP
  463. Some lines of information at the start have \fIline_number\fR of zero.
  464. These preamble lines are of the form
  465. .PP
  466. .Vb 1
  467. \& \-:0:<tag>:<value>
  468. .Ve
  469. .PP
  470. The ordering and number of these preamble lines will be augmented as
  471. \&\fBgcov\fR development progresses \-\-\- do not rely on them remaining
  472. unchanged. Use \fItag\fR to locate a particular preamble line.
  473. .PP
  474. The additional block information is of the form
  475. .PP
  476. .Vb 1
  477. \& <tag> <information>
  478. .Ve
  479. .PP
  480. The \fIinformation\fR is human readable, but designed to be simple
  481. enough for machine parsing too.
  482. .PP
  483. When printing percentages, 0% and 100% are only printed when the values
  484. are \fIexactly\fR 0% and 100% respectively. Other values which would
  485. conventionally be rounded to 0% or 100% are instead printed as the
  486. nearest non-boundary value.
  487. .PP
  488. When using \fBgcov\fR, you must first compile your program with two
  489. special \s-1GCC\s0 options: \fB\-fprofile\-arcs \-ftest\-coverage\fR.
  490. This tells the compiler to generate additional information needed by
  491. gcov (basically a flow graph of the program) and also includes
  492. additional code in the object files for generating the extra profiling
  493. information needed by gcov. These additional files are placed in the
  494. directory where the object file is located.
  495. .PP
  496. Running the program will cause profile output to be generated. For each
  497. source file compiled with \fB\-fprofile\-arcs\fR, an accompanying
  498. \&\fI.gcda\fR file will be placed in the object file directory.
  499. .PP
  500. Running \fBgcov\fR with your program's source file names as arguments
  501. will now produce a listing of the code along with frequency of execution
  502. for each line. For example, if your program is called \fItmp.c\fR, this
  503. is what you see when you use the basic \fBgcov\fR facility:
  504. .PP
  505. .Vb 6
  506. \& $ gcc \-fprofile\-arcs \-ftest\-coverage tmp.c
  507. \& $ a.out
  508. \& $ gcov tmp.c
  509. \& File \*(Aqtmp.c\*(Aq
  510. \& Lines executed:90.00% of 10
  511. \& Creating \*(Aqtmp.c.gcov\*(Aq
  512. .Ve
  513. .PP
  514. The file \fItmp.c.gcov\fR contains output from \fBgcov\fR.
  515. Here is a sample:
  516. .PP
  517. .Vb 10
  518. \& \-: 0:Source:tmp.c
  519. \& \-: 0:Graph:tmp.gcno
  520. \& \-: 0:Data:tmp.gcda
  521. \& \-: 0:Runs:1
  522. \& \-: 0:Programs:1
  523. \& \-: 1:#include <stdio.h>
  524. \& \-: 2:
  525. \& \-: 3:int main (void)
  526. \& 1: 4:{
  527. \& 1: 5: int i, total;
  528. \& \-: 6:
  529. \& 1: 7: total = 0;
  530. \& \-: 8:
  531. \& 11: 9: for (i = 0; i < 10; i++)
  532. \& 10: 10: total += i;
  533. \& \-: 11:
  534. \& 1: 12: if (total != 45)
  535. \& #####: 13: printf ("Failure\en");
  536. \& \-: 14: else
  537. \& 1: 15: printf ("Success\en");
  538. \& 1: 16: return 0;
  539. \& \-: 17:}
  540. .Ve
  541. .PP
  542. When you use the \fB\-a\fR option, you will get individual block
  543. counts, and the output looks like this:
  544. .PP
  545. .Vb 10
  546. \& \-: 0:Source:tmp.c
  547. \& \-: 0:Graph:tmp.gcno
  548. \& \-: 0:Data:tmp.gcda
  549. \& \-: 0:Runs:1
  550. \& \-: 0:Programs:1
  551. \& \-: 1:#include <stdio.h>
  552. \& \-: 2:
  553. \& \-: 3:int main (void)
  554. \& 1: 4:{
  555. \& 1: 4\-block 0
  556. \& 1: 5: int i, total;
  557. \& \-: 6:
  558. \& 1: 7: total = 0;
  559. \& \-: 8:
  560. \& 11: 9: for (i = 0; i < 10; i++)
  561. \& 11: 9\-block 0
  562. \& 10: 10: total += i;
  563. \& 10: 10\-block 0
  564. \& \-: 11:
  565. \& 1: 12: if (total != 45)
  566. \& 1: 12\-block 0
  567. \& #####: 13: printf ("Failure\en");
  568. \& $$$$$: 13\-block 0
  569. \& \-: 14: else
  570. \& 1: 15: printf ("Success\en");
  571. \& 1: 15\-block 0
  572. \& 1: 16: return 0;
  573. \& 1: 16\-block 0
  574. \& \-: 17:}
  575. .Ve
  576. .PP
  577. In this mode, each basic block is only shown on one line \*(-- the last
  578. line of the block. A multi-line block will only contribute to the
  579. execution count of that last line, and other lines will not be shown
  580. to contain code, unless previous blocks end on those lines.
  581. The total execution count of a line is shown and subsequent lines show
  582. the execution counts for individual blocks that end on that line. After each
  583. block, the branch and call counts of the block will be shown, if the
  584. \&\fB\-b\fR option is given.
  585. .PP
  586. Because of the way \s-1GCC\s0 instruments calls, a call count can be shown
  587. after a line with no individual blocks.
  588. As you can see, line 13 contains a basic block that was not executed.
  589. .PP
  590. When you use the \fB\-b\fR option, your output looks like this:
  591. .PP
  592. .Vb 7
  593. \& $ gcov \-b tmp.c
  594. \& File \*(Aqtmp.c\*(Aq
  595. \& Lines executed:90.00% of 10
  596. \& Branches executed:80.00% of 5
  597. \& Taken at least once:80.00% of 5
  598. \& Calls executed:50.00% of 2
  599. \& Creating \*(Aqtmp.c.gcov\*(Aq
  600. .Ve
  601. .PP
  602. Here is a sample of a resulting \fItmp.c.gcov\fR file:
  603. .PP
  604. .Vb 10
  605. \& \-: 0:Source:tmp.c
  606. \& \-: 0:Graph:tmp.gcno
  607. \& \-: 0:Data:tmp.gcda
  608. \& \-: 0:Runs:1
  609. \& \-: 0:Programs:1
  610. \& \-: 1:#include <stdio.h>
  611. \& \-: 2:
  612. \& \-: 3:int main (void)
  613. \& function main called 1 returned 1 blocks executed 75%
  614. \& 1: 4:{
  615. \& 1: 5: int i, total;
  616. \& \-: 6:
  617. \& 1: 7: total = 0;
  618. \& \-: 8:
  619. \& 11: 9: for (i = 0; i < 10; i++)
  620. \& branch 0 taken 91% (fallthrough)
  621. \& branch 1 taken 9%
  622. \& 10: 10: total += i;
  623. \& \-: 11:
  624. \& 1: 12: if (total != 45)
  625. \& branch 0 taken 0% (fallthrough)
  626. \& branch 1 taken 100%
  627. \& #####: 13: printf ("Failure\en");
  628. \& call 0 never executed
  629. \& \-: 14: else
  630. \& 1: 15: printf ("Success\en");
  631. \& call 0 called 1 returned 100%
  632. \& 1: 16: return 0;
  633. \& \-: 17:}
  634. .Ve
  635. .PP
  636. For each function, a line is printed showing how many times the function
  637. is called, how many times it returns and what percentage of the
  638. function's blocks were executed.
  639. .PP
  640. For each basic block, a line is printed after the last line of the basic
  641. block describing the branch or call that ends the basic block. There can
  642. be multiple branches and calls listed for a single source line if there
  643. are multiple basic blocks that end on that line. In this case, the
  644. branches and calls are each given a number. There is no simple way to map
  645. these branches and calls back to source constructs. In general, though,
  646. the lowest numbered branch or call will correspond to the leftmost construct
  647. on the source line.
  648. .PP
  649. For a branch, if it was executed at least once, then a percentage
  650. indicating the number of times the branch was taken divided by the
  651. number of times the branch was executed will be printed. Otherwise, the
  652. message \*(L"never executed\*(R" is printed.
  653. .PP
  654. For a call, if it was executed at least once, then a percentage
  655. indicating the number of times the call returned divided by the number
  656. of times the call was executed will be printed. This will usually be
  657. 100%, but may be less for functions that call \f(CW\*(C`exit\*(C'\fR or \f(CW\*(C`longjmp\*(C'\fR,
  658. and thus may not return every time they are called.
  659. .PP
  660. The execution counts are cumulative. If the example program were
  661. executed again without removing the \fI.gcda\fR file, the count for the
  662. number of times each line in the source was executed would be added to
  663. the results of the previous run(s). This is potentially useful in
  664. several ways. For example, it could be used to accumulate data over a
  665. number of program runs as part of a test verification suite, or to
  666. provide more accurate long-term information over a large number of
  667. program runs.
  668. .PP
  669. The data in the \fI.gcda\fR files is saved immediately before the program
  670. exits. For each source file compiled with \fB\-fprofile\-arcs\fR, the
  671. profiling code first attempts to read in an existing \fI.gcda\fR file; if
  672. the file doesn't match the executable (differing number of basic block
  673. counts) it will ignore the contents of the file. It then adds in the
  674. new execution counts and finally writes the data to the file.
  675. .SS "Using \fBgcov\fP with \s-1GCC\s0 Optimization"
  676. .IX Subsection "Using gcov with GCC Optimization"
  677. If you plan to use \fBgcov\fR to help optimize your code, you must
  678. first compile your program with two special \s-1GCC\s0 options:
  679. \&\fB\-fprofile\-arcs \-ftest\-coverage\fR. Aside from that, you can use any
  680. other \s-1GCC\s0 options; but if you want to prove that every single line
  681. in your program was executed, you should not compile with optimization
  682. at the same time. On some machines the optimizer can eliminate some
  683. simple code lines by combining them with other lines. For example, code
  684. like this:
  685. .PP
  686. .Vb 4
  687. \& if (a != b)
  688. \& c = 1;
  689. \& else
  690. \& c = 0;
  691. .Ve
  692. .PP
  693. can be compiled into one instruction on some machines. In this case,
  694. there is no way for \fBgcov\fR to calculate separate execution counts
  695. for each line because there isn't separate code for each line. Hence
  696. the \fBgcov\fR output looks like this if you compiled the program with
  697. optimization:
  698. .PP
  699. .Vb 4
  700. \& 100: 12:if (a != b)
  701. \& 100: 13: c = 1;
  702. \& 100: 14:else
  703. \& 100: 15: c = 0;
  704. .Ve
  705. .PP
  706. The output shows that this block of code, combined by optimization,
  707. executed 100 times. In one sense this result is correct, because there
  708. was only one instruction representing all four of these lines. However,
  709. the output does not indicate how many times the result was 0 and how
  710. many times the result was 1.
  711. .PP
  712. Inlineable functions can create unexpected line counts. Line counts are
  713. shown for the source code of the inlineable function, but what is shown
  714. depends on where the function is inlined, or if it is not inlined at all.
  715. .PP
  716. If the function is not inlined, the compiler must emit an out of line
  717. copy of the function, in any object file that needs it. If
  718. \&\fIfileA.o\fR and \fIfileB.o\fR both contain out of line bodies of a
  719. particular inlineable function, they will also both contain coverage
  720. counts for that function. When \fIfileA.o\fR and \fIfileB.o\fR are
  721. linked together, the linker will, on many systems, select one of those
  722. out of line bodies for all calls to that function, and remove or ignore
  723. the other. Unfortunately, it will not remove the coverage counters for
  724. the unused function body. Hence when instrumented, all but one use of
  725. that function will show zero counts.
  726. .PP
  727. If the function is inlined in several places, the block structure in
  728. each location might not be the same. For instance, a condition might
  729. now be calculable at compile time in some instances. Because the
  730. coverage of all the uses of the inline function will be shown for the
  731. same source lines, the line counts themselves might seem inconsistent.
  732. .PP
  733. Long-running applications can use the \f(CW\*(C`_\|_gcov_reset\*(C'\fR and \f(CW\*(C`_\|_gcov_dump\*(C'\fR
  734. facilities to restrict profile collection to the program region of
  735. interest. Calling \f(CW\*(C`_\|_gcov_reset(void)\*(C'\fR will clear all profile counters
  736. to zero, and calling \f(CW\*(C`_\|_gcov_dump(void)\*(C'\fR will cause the profile information
  737. collected at that point to be dumped to \fI.gcda\fR output files.
  738. Instrumented applications use a static destructor with priority 99
  739. to invoke the \f(CW\*(C`_\|_gcov_dump\*(C'\fR function. Thus \f(CW\*(C`_\|_gcov_dump\*(C'\fR
  740. is executed after all user defined static destructors,
  741. as well as handlers registered with \f(CW\*(C`atexit\*(C'\fR.
  742. If an executable loads a dynamic shared object via dlopen functionality,
  743. \&\fB\-Wl,\-\-dynamic\-list\-data\fR is needed to dump all profile data.
  744. .SH "SEE ALSO"
  745. .IX Header "SEE ALSO"
  746. \&\fIgpl\fR\|(7), \fIgfdl\fR\|(7), \fIfsf\-funding\fR\|(7), \fIgcc\fR\|(1) and the Info entry for \fIgcc\fR.
  747. .SH "COPYRIGHT"
  748. .IX Header "COPYRIGHT"
  749. Copyright (c) 1996\-2017 Free Software Foundation, Inc.
  750. .PP
  751. Permission is granted to copy, distribute and/or modify this document
  752. under the terms of the \s-1GNU\s0 Free Documentation License, Version 1.3 or
  753. any later version published by the Free Software Foundation; with the
  754. Invariant Sections being \*(L"\s-1GNU\s0 General Public License\*(R" and \*(L"Funding
  755. Free Software\*(R", the Front-Cover texts being (a) (see below), and with
  756. the Back-Cover Texts being (b) (see below). A copy of the license is
  757. included in the \fIgfdl\fR\|(7) man page.
  758. .PP
  759. (a) The \s-1FSF\s0's Front-Cover Text is:
  760. .PP
  761. .Vb 1
  762. \& A GNU Manual
  763. .Ve
  764. .PP
  765. (b) The \s-1FSF\s0's Back-Cover Text is:
  766. .PP
  767. .Vb 3
  768. \& You have freedom to copy and modify this GNU Manual, like GNU
  769. \& software. Copies published by the Free Software Foundation raise
  770. \& funds for GNU development.
  771. .Ve