Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

1044 lines
38KB

  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 "2020-11-03" "gcc-10.2.1" "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\-\-json\-format\fR]
  152. [\fB\-j\fR|\fB\-\-human\-readable\fR]
  153. [\fB\-k\fR|\fB\-\-use\-colors\fR]
  154. [\fB\-l\fR|\fB\-\-long\-file\-names\fR]
  155. [\fB\-m\fR|\fB\-\-demangled\-names\fR]
  156. [\fB\-n\fR|\fB\-\-no\-output\fR]
  157. [\fB\-o\fR|\fB\-\-object\-directory\fR \fIdirectory|file\fR]
  158. [\fB\-p\fR|\fB\-\-preserve\-paths\fR]
  159. [\fB\-q\fR|\fB\-\-use\-hotness\-colors\fR]
  160. [\fB\-r\fR|\fB\-\-relative\-only\fR]
  161. [\fB\-s\fR|\fB\-\-source\-prefix\fR \fIdirectory\fR]
  162. [\fB\-t\fR|\fB\-\-stdout\fR]
  163. [\fB\-u\fR|\fB\-\-unconditional\-branches\fR]
  164. [\fB\-x\fR|\fB\-\-hash\-filenames\fR]
  165. \fIfiles\fR
  166. .SH "DESCRIPTION"
  167. .IX Header "DESCRIPTION"
  168. \&\fBgcov\fR is a test coverage program. Use it in concert with \s-1GCC\s0
  169. to analyze your programs to help create more efficient, faster running
  170. code and to discover untested parts of your program. You can use
  171. \&\fBgcov\fR as a profiling tool to help discover where your
  172. optimization efforts will best affect your code. You can also use
  173. \&\fBgcov\fR along with the other profiling tool, \fBgprof\fR, to
  174. assess which parts of your code use the greatest amount of computing
  175. time.
  176. .PP
  177. Profiling tools help you analyze your code's performance. Using a
  178. profiler such as \fBgcov\fR or \fBgprof\fR, you can find out some
  179. basic performance statistics, such as:
  180. .IP "*" 4
  181. how often each line of code executes
  182. .IP "*" 4
  183. what lines of code are actually executed
  184. .IP "*" 4
  185. how much computing time each section of code uses
  186. .PP
  187. Once you know these things about how your code works when compiled, you
  188. can look at each module to see which modules should be optimized.
  189. \&\fBgcov\fR helps you determine where to work on optimization.
  190. .PP
  191. Software developers also use coverage testing in concert with
  192. testsuites, to make sure software is actually good enough for a release.
  193. Testsuites can verify that a program works as expected; a coverage
  194. program tests to see how much of the program is exercised by the
  195. testsuite. Developers can then determine what kinds of test cases need
  196. to be added to the testsuites to create both better testing and a better
  197. final product.
  198. .PP
  199. You should compile your code without optimization if you plan to use
  200. \&\fBgcov\fR because the optimization, by combining some lines of code
  201. into one function, may not give you as much information as you need to
  202. look for `hot spots' where the code is using a great deal of computer
  203. time. Likewise, because \fBgcov\fR accumulates statistics by line (at
  204. the lowest resolution), it works best with a programming style that
  205. places only one statement on each line. If you use complicated macros
  206. that expand to loops or to other control structures, the statistics are
  207. less helpful\-\-\-they only report on the line where the macro call
  208. appears. If your complex macros behave like functions, you can replace
  209. them with inline functions to solve this problem.
  210. .PP
  211. \&\fBgcov\fR creates a logfile called \fI\fIsourcefile\fI.gcov\fR which
  212. indicates how many times each line of a source file \fI\fIsourcefile\fI.c\fR
  213. has executed. You can use these logfiles along with \fBgprof\fR to aid
  214. in fine-tuning the performance of your programs. \fBgprof\fR gives
  215. timing information you can use along with the information you get from
  216. \&\fBgcov\fR.
  217. .PP
  218. \&\fBgcov\fR works only on code compiled with \s-1GCC. \s0 It is not
  219. compatible with any other profiling or test coverage mechanism.
  220. .SH "OPTIONS"
  221. .IX Header "OPTIONS"
  222. .IP "\fB\-a\fR" 4
  223. .IX Item "-a"
  224. .PD 0
  225. .IP "\fB\-\-all\-blocks\fR" 4
  226. .IX Item "--all-blocks"
  227. .PD
  228. Write individual execution counts for every basic block. Normally gcov
  229. outputs execution counts only for the main blocks of a line. With this
  230. option you can determine if blocks within a single line are not being
  231. executed.
  232. .IP "\fB\-b\fR" 4
  233. .IX Item "-b"
  234. .PD 0
  235. .IP "\fB\-\-branch\-probabilities\fR" 4
  236. .IX Item "--branch-probabilities"
  237. .PD
  238. Write branch frequencies to the output file, and write branch summary
  239. info to the standard output. This option allows you to see how often
  240. each branch in your program was taken. Unconditional branches will not
  241. be shown, unless the \fB\-u\fR option is given.
  242. .IP "\fB\-c\fR" 4
  243. .IX Item "-c"
  244. .PD 0
  245. .IP "\fB\-\-branch\-counts\fR" 4
  246. .IX Item "--branch-counts"
  247. .PD
  248. Write branch frequencies as the number of branches taken, rather than
  249. the percentage of branches taken.
  250. .IP "\fB\-d\fR" 4
  251. .IX Item "-d"
  252. .PD 0
  253. .IP "\fB\-\-display\-progress\fR" 4
  254. .IX Item "--display-progress"
  255. .PD
  256. Display the progress on the standard output.
  257. .IP "\fB\-f\fR" 4
  258. .IX Item "-f"
  259. .PD 0
  260. .IP "\fB\-\-function\-summaries\fR" 4
  261. .IX Item "--function-summaries"
  262. .PD
  263. Output summaries for each function in addition to the file level summary.
  264. .IP "\fB\-h\fR" 4
  265. .IX Item "-h"
  266. .PD 0
  267. .IP "\fB\-\-help\fR" 4
  268. .IX Item "--help"
  269. .PD
  270. Display help about using \fBgcov\fR (on the standard output), and
  271. exit without doing any further processing.
  272. .IP "\fB\-i\fR" 4
  273. .IX Item "-i"
  274. .PD 0
  275. .IP "\fB\-\-json\-format\fR" 4
  276. .IX Item "--json-format"
  277. .PD
  278. Output gcov file in an easy-to-parse \s-1JSON\s0 intermediate format
  279. which does not require source code for generation. The \s-1JSON\s0
  280. file is compressed with gzip compression algorithm
  281. and the files have \fI.gcov.json.gz\fR extension.
  282. .Sp
  283. Structure of the \s-1JSON\s0 is following:
  284. .Sp
  285. .Vb 7
  286. \& {
  287. \& "current_working_directory": <current_working_directory>,
  288. \& "data_file": <data_file>,
  289. \& "format_version": <format_version>,
  290. \& "gcc_version": <gcc_version>
  291. \& "files": [<file>]
  292. \& }
  293. .Ve
  294. .Sp
  295. Fields of the root element have following semantics:
  296. .RS 4
  297. .IP "*" 4
  298. \&\fIcurrent_working_directory\fR: working directory where
  299. a compilation unit was compiled
  300. .IP "*" 4
  301. \&\fIdata_file\fR: name of the data file (\s-1GCDA\s0)
  302. .IP "*" 4
  303. \&\fIformat_version\fR: semantic version of the format
  304. .IP "*" 4
  305. \&\fIgcc_version\fR: version of the \s-1GCC\s0 compiler
  306. .RE
  307. .RS 4
  308. .Sp
  309. Each \fIfile\fR has the following form:
  310. .Sp
  311. .Vb 5
  312. \& {
  313. \& "file": <file_name>,
  314. \& "functions": [<function>],
  315. \& "lines": [<line>]
  316. \& }
  317. .Ve
  318. .Sp
  319. Fields of the \fIfile\fR element have following semantics:
  320. .IP "*" 4
  321. \&\fIfile_name\fR: name of the source file
  322. .RE
  323. .RS 4
  324. .Sp
  325. Each \fIfunction\fR has the following form:
  326. .Sp
  327. .Vb 11
  328. \& {
  329. \& "blocks": <blocks>,
  330. \& "blocks_executed": <blocks_executed>,
  331. \& "demangled_name": "<demangled_name>,
  332. \& "end_column": <end_column>,
  333. \& "end_line": <end_line>,
  334. \& "execution_count": <execution_count>,
  335. \& "name": <name>,
  336. \& "start_column": <start_column>
  337. \& "start_line": <start_line>
  338. \& }
  339. .Ve
  340. .Sp
  341. Fields of the \fIfunction\fR element have following semantics:
  342. .IP "*" 4
  343. \&\fIblocks\fR: number of blocks that are in the function
  344. .IP "*" 4
  345. \&\fIblocks_executed\fR: number of executed blocks of the function
  346. .IP "*" 4
  347. \&\fIdemangled_name\fR: demangled name of the function
  348. .IP "*" 4
  349. \&\fIend_column\fR: column in the source file where the function ends
  350. .IP "*" 4
  351. \&\fIend_line\fR: line in the source file where the function ends
  352. .IP "*" 4
  353. \&\fIexecution_count\fR: number of executions of the function
  354. .IP "*" 4
  355. \&\fIname\fR: name of the function
  356. .IP "*" 4
  357. \&\fIstart_column\fR: column in the source file where the function begins
  358. .IP "*" 4
  359. \&\fIstart_line\fR: line in the source file where the function begins
  360. .RE
  361. .RS 4
  362. .Sp
  363. Note that line numbers and column numbers number from 1. In the current
  364. implementation, \fIstart_line\fR and \fIstart_column\fR do not include
  365. any template parameters and the leading return type but that
  366. this is likely to be fixed in the future.
  367. .Sp
  368. Each \fIline\fR has the following form:
  369. .Sp
  370. .Vb 7
  371. \& {
  372. \& "branches": [<branch>],
  373. \& "count": <count>,
  374. \& "line_number": <line_number>,
  375. \& "unexecuted_block": <unexecuted_block>
  376. \& "function_name": <function_name>,
  377. \& }
  378. .Ve
  379. .Sp
  380. Branches are present only with \fI\-b\fR option.
  381. Fields of the \fIline\fR element have following semantics:
  382. .IP "*" 4
  383. \&\fIcount\fR: number of executions of the line
  384. .IP "*" 4
  385. \&\fIline_number\fR: line number
  386. .IP "*" 4
  387. \&\fIunexecuted_block\fR: flag whether the line contains an unexecuted block
  388. (not all statements on the line are executed)
  389. .IP "*" 4
  390. \&\fIfunction_name\fR: a name of a function this \fIline\fR belongs to
  391. (for a line with an inlined statements can be not set)
  392. .RE
  393. .RS 4
  394. .Sp
  395. Each \fIbranch\fR has the following form:
  396. .Sp
  397. .Vb 5
  398. \& {
  399. \& "count": <count>,
  400. \& "fallthrough": <fallthrough>,
  401. \& "throw": <throw>
  402. \& }
  403. .Ve
  404. .Sp
  405. Fields of the \fIbranch\fR element have following semantics:
  406. .IP "*" 4
  407. \&\fIcount\fR: number of executions of the branch
  408. .IP "*" 4
  409. \&\fIfallthrough\fR: true when the branch is a fall through branch
  410. .IP "*" 4
  411. \&\fIthrow\fR: true when the branch is an exceptional branch
  412. .RE
  413. .RS 4
  414. .RE
  415. .IP "\fB\-j\fR" 4
  416. .IX Item "-j"
  417. .PD 0
  418. .IP "\fB\-\-human\-readable\fR" 4
  419. .IX Item "--human-readable"
  420. .PD
  421. Write counts in human readable format (like 24.6k).
  422. .IP "\fB\-k\fR" 4
  423. .IX Item "-k"
  424. .PD 0
  425. .IP "\fB\-\-use\-colors\fR" 4
  426. .IX Item "--use-colors"
  427. .PD
  428. Use colors for lines of code that have zero coverage. We use red color for
  429. non-exceptional lines and cyan for exceptional. Same colors are used for
  430. basic blocks with \fB\-a\fR option.
  431. .IP "\fB\-l\fR" 4
  432. .IX Item "-l"
  433. .PD 0
  434. .IP "\fB\-\-long\-file\-names\fR" 4
  435. .IX Item "--long-file-names"
  436. .PD
  437. Create long file names for included source files. For example, if the
  438. header file \fIx.h\fR contains code, and was included in the file
  439. \&\fIa.c\fR, then running \fBgcov\fR on the file \fIa.c\fR will
  440. produce an output file called \fIa.c##x.h.gcov\fR instead of
  441. \&\fIx.h.gcov\fR. This can be useful if \fIx.h\fR is included in
  442. multiple source files and you want to see the individual
  443. contributions. If you use the \fB\-p\fR option, both the including
  444. and included file names will be complete path names.
  445. .IP "\fB\-m\fR" 4
  446. .IX Item "-m"
  447. .PD 0
  448. .IP "\fB\-\-demangled\-names\fR" 4
  449. .IX Item "--demangled-names"
  450. .PD
  451. Display demangled function names in output. The default is to show
  452. mangled function names.
  453. .IP "\fB\-n\fR" 4
  454. .IX Item "-n"
  455. .PD 0
  456. .IP "\fB\-\-no\-output\fR" 4
  457. .IX Item "--no-output"
  458. .PD
  459. Do not create the \fBgcov\fR output file.
  460. .IP "\fB\-o\fR \fIdirectory|file\fR" 4
  461. .IX Item "-o directory|file"
  462. .PD 0
  463. .IP "\fB\-\-object\-directory\fR \fIdirectory\fR" 4
  464. .IX Item "--object-directory directory"
  465. .IP "\fB\-\-object\-file\fR \fIfile\fR" 4
  466. .IX Item "--object-file file"
  467. .PD
  468. Specify either the directory containing the gcov data files, or the
  469. object path name. The \fI.gcno\fR, and
  470. \&\fI.gcda\fR data files are searched for using this option. If a directory
  471. is specified, the data files are in that directory and named after the
  472. input file name, without its extension. If a file is specified here,
  473. the data files are named after that file, without its extension.
  474. .IP "\fB\-p\fR" 4
  475. .IX Item "-p"
  476. .PD 0
  477. .IP "\fB\-\-preserve\-paths\fR" 4
  478. .IX Item "--preserve-paths"
  479. .PD
  480. Preserve complete path information in the names of generated
  481. \&\fI.gcov\fR files. Without this option, just the filename component is
  482. used. With this option, all directories are used, with \fB/\fR characters
  483. translated to \fB#\fR characters, \fI.\fR directory components
  484. removed and unremoveable \fI..\fR
  485. components renamed to \fB^\fR. This is useful if sourcefiles are in several
  486. different directories.
  487. .IP "\fB\-q\fR" 4
  488. .IX Item "-q"
  489. .PD 0
  490. .IP "\fB\-\-use\-hotness\-colors\fR" 4
  491. .IX Item "--use-hotness-colors"
  492. .PD
  493. Emit perf-like colored output for hot lines. Legend of the color scale
  494. is printed at the very beginning of the output file.
  495. .IP "\fB\-r\fR" 4
  496. .IX Item "-r"
  497. .PD 0
  498. .IP "\fB\-\-relative\-only\fR" 4
  499. .IX Item "--relative-only"
  500. .PD
  501. Only output information about source files with a relative pathname
  502. (after source prefix elision). Absolute paths are usually system
  503. header files and coverage of any inline functions therein is normally
  504. uninteresting.
  505. .IP "\fB\-s\fR \fIdirectory\fR" 4
  506. .IX Item "-s directory"
  507. .PD 0
  508. .IP "\fB\-\-source\-prefix\fR \fIdirectory\fR" 4
  509. .IX Item "--source-prefix directory"
  510. .PD
  511. A prefix for source file names to remove when generating the output
  512. coverage files. This option is useful when building in a separate
  513. directory, and the pathname to the source directory is not wanted when
  514. determining the output file names. Note that this prefix detection is
  515. applied before determining whether the source file is absolute.
  516. .IP "\fB\-t\fR" 4
  517. .IX Item "-t"
  518. .PD 0
  519. .IP "\fB\-\-stdout\fR" 4
  520. .IX Item "--stdout"
  521. .PD
  522. Output to standard output instead of output files.
  523. .IP "\fB\-u\fR" 4
  524. .IX Item "-u"
  525. .PD 0
  526. .IP "\fB\-\-unconditional\-branches\fR" 4
  527. .IX Item "--unconditional-branches"
  528. .PD
  529. When branch probabilities are given, include those of unconditional branches.
  530. Unconditional branches are normally not interesting.
  531. .IP "\fB\-v\fR" 4
  532. .IX Item "-v"
  533. .PD 0
  534. .IP "\fB\-\-version\fR" 4
  535. .IX Item "--version"
  536. .PD
  537. Display the \fBgcov\fR version number (on the standard output),
  538. and exit without doing any further processing.
  539. .IP "\fB\-w\fR" 4
  540. .IX Item "-w"
  541. .PD 0
  542. .IP "\fB\-\-verbose\fR" 4
  543. .IX Item "--verbose"
  544. .PD
  545. Print verbose informations related to basic blocks and arcs.
  546. .IP "\fB\-x\fR" 4
  547. .IX Item "-x"
  548. .PD 0
  549. .IP "\fB\-\-hash\-filenames\fR" 4
  550. .IX Item "--hash-filenames"
  551. .PD
  552. When using \fI\-\-preserve\-paths\fR,
  553. gcov uses the full pathname of the source files to create
  554. an output filename. This can lead to long filenames that can overflow
  555. filesystem limits. This option creates names of the form
  556. \&\fI\fIsource-file\fI##\fImd5\fI.gcov\fR,
  557. where the \fIsource-file\fR component is the final filename part and
  558. the \fImd5\fR component is calculated from the full mangled name that
  559. would have been used otherwise. The option is an alternative
  560. to the \fI\-\-preserve\-paths\fR on systems which have a filesystem limit.
  561. .PP
  562. \&\fBgcov\fR should be run with the current directory the same as that
  563. when you invoked the compiler. Otherwise it will not be able to locate
  564. the source files. \fBgcov\fR produces files called
  565. \&\fI\fImangledname\fI.gcov\fR in the current directory. These contain
  566. the coverage information of the source file they correspond to.
  567. One \fI.gcov\fR file is produced for each source (or header) file
  568. containing code,
  569. which was compiled to produce the data files. The \fImangledname\fR part
  570. of the output file name is usually simply the source file name, but can
  571. be something more complicated if the \fB\-l\fR or \fB\-p\fR options are
  572. given. Refer to those options for details.
  573. .PP
  574. If you invoke \fBgcov\fR with multiple input files, the
  575. contributions from each input file are summed. Typically you would
  576. invoke it with the same list of files as the final link of your executable.
  577. .PP
  578. The \fI.gcov\fR files contain the \fB:\fR separated fields along with
  579. program source code. The format is
  580. .PP
  581. .Vb 1
  582. \& <execution_count>:<line_number>:<source line text>
  583. .Ve
  584. .PP
  585. Additional block information may succeed each line, when requested by
  586. command line option. The \fIexecution_count\fR is \fB\-\fR for lines
  587. containing no code. Unexecuted lines are marked \fB#####\fR or
  588. \&\fB=====\fR, depending on whether they are reachable by
  589. non-exceptional paths or only exceptional paths such as \*(C+ exception
  590. handlers, respectively. Given the \fB\-a\fR option, unexecuted blocks are
  591. marked \fB$$$$$\fR or \fB%%%%%\fR, depending on whether a basic block
  592. is reachable via non-exceptional or exceptional paths.
  593. Executed basic blocks having a statement with zero \fIexecution_count\fR
  594. end with \fB*\fR character and are colored with magenta color with
  595. the \fB\-k\fR option. This functionality is not supported in Ada.
  596. .PP
  597. Note that \s-1GCC\s0 can completely remove the bodies of functions that are
  598. not needed \*(-- for instance if they are inlined everywhere. Such functions
  599. are marked with \fB\-\fR, which can be confusing.
  600. Use the \fB\-fkeep\-inline\-functions\fR and \fB\-fkeep\-static\-functions\fR
  601. options to retain these functions and
  602. allow gcov to properly show their \fIexecution_count\fR.
  603. .PP
  604. Some lines of information at the start have \fIline_number\fR of zero.
  605. These preamble lines are of the form
  606. .PP
  607. .Vb 1
  608. \& \-:0:<tag>:<value>
  609. .Ve
  610. .PP
  611. The ordering and number of these preamble lines will be augmented as
  612. \&\fBgcov\fR development progresses \-\-\- do not rely on them remaining
  613. unchanged. Use \fItag\fR to locate a particular preamble line.
  614. .PP
  615. The additional block information is of the form
  616. .PP
  617. .Vb 1
  618. \& <tag> <information>
  619. .Ve
  620. .PP
  621. The \fIinformation\fR is human readable, but designed to be simple
  622. enough for machine parsing too.
  623. .PP
  624. When printing percentages, 0% and 100% are only printed when the values
  625. are \fIexactly\fR 0% and 100% respectively. Other values which would
  626. conventionally be rounded to 0% or 100% are instead printed as the
  627. nearest non-boundary value.
  628. .PP
  629. When using \fBgcov\fR, you must first compile your program
  630. with a special \s-1GCC\s0 option \fB\-\-coverage\fR.
  631. This tells the compiler to generate additional information needed by
  632. gcov (basically a flow graph of the program) and also includes
  633. additional code in the object files for generating the extra profiling
  634. information needed by gcov. These additional files are placed in the
  635. directory where the object file is located.
  636. .PP
  637. Running the program will cause profile output to be generated. For each
  638. source file compiled with \fB\-fprofile\-arcs\fR, an accompanying
  639. \&\fI.gcda\fR file will be placed in the object file directory.
  640. .PP
  641. Running \fBgcov\fR with your program's source file names as arguments
  642. will now produce a listing of the code along with frequency of execution
  643. for each line. For example, if your program is called \fItmp.cpp\fR, this
  644. is what you see when you use the basic \fBgcov\fR facility:
  645. .PP
  646. .Vb 6
  647. \& $ g++ \-\-coverage tmp.cpp
  648. \& $ a.out
  649. \& $ gcov tmp.cpp \-m
  650. \& File \*(Aqtmp.cpp\*(Aq
  651. \& Lines executed:92.86% of 14
  652. \& Creating \*(Aqtmp.cpp.gcov\*(Aq
  653. .Ve
  654. .PP
  655. The file \fItmp.cpp.gcov\fR contains output from \fBgcov\fR.
  656. Here is a sample:
  657. .PP
  658. .Vb 10
  659. \& \-: 0:Source:tmp.cpp
  660. \& \-: 0:Working directory:/home/gcc/testcase
  661. \& \-: 0:Graph:tmp.gcno
  662. \& \-: 0:Data:tmp.gcda
  663. \& \-: 0:Runs:1
  664. \& \-: 0:Programs:1
  665. \& \-: 1:#include <stdio.h>
  666. \& \-: 2:
  667. \& \-: 3:template<class T>
  668. \& \-: 4:class Foo
  669. \& \-: 5:{
  670. \& \-: 6: public:
  671. \& 1*: 7: Foo(): b (1000) {}
  672. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  673. \& Foo<char>::Foo():
  674. \& #####: 7: Foo(): b (1000) {}
  675. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  676. \& Foo<int>::Foo():
  677. \& 1: 7: Foo(): b (1000) {}
  678. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  679. \& 2*: 8: void inc () { b++; }
  680. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  681. \& Foo<char>::inc():
  682. \& #####: 8: void inc () { b++; }
  683. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  684. \& Foo<int>::inc():
  685. \& 2: 8: void inc () { b++; }
  686. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  687. \& \-: 9:
  688. \& \-: 10: private:
  689. \& \-: 11: int b;
  690. \& \-: 12:};
  691. \& \-: 13:
  692. \& \-: 14:template class Foo<int>;
  693. \& \-: 15:template class Foo<char>;
  694. \& \-: 16:
  695. \& \-: 17:int
  696. \& 1: 18:main (void)
  697. \& \-: 19:{
  698. \& \-: 20: int i, total;
  699. \& 1: 21: Foo<int> counter;
  700. \& \-: 22:
  701. \& 1: 23: counter.inc();
  702. \& 1: 24: counter.inc();
  703. \& 1: 25: total = 0;
  704. \& \-: 26:
  705. \& 11: 27: for (i = 0; i < 10; i++)
  706. \& 10: 28: total += i;
  707. \& \-: 29:
  708. \& 1*: 30: int v = total > 100 ? 1 : 2;
  709. \& \-: 31:
  710. \& 1: 32: if (total != 45)
  711. \& #####: 33: printf ("Failure\en");
  712. \& \-: 34: else
  713. \& 1: 35: printf ("Success\en");
  714. \& 1: 36: return 0;
  715. \& \-: 37:}
  716. .Ve
  717. .PP
  718. Note that line 7 is shown in the report multiple times. First occurrence
  719. presents total number of execution of the line and the next two belong
  720. to instances of class Foo constructors. As you can also see, line 30 contains
  721. some unexecuted basic blocks and thus execution count has asterisk symbol.
  722. .PP
  723. When you use the \fB\-a\fR option, you will get individual block
  724. counts, and the output looks like this:
  725. .PP
  726. .Vb 10
  727. \& \-: 0:Source:tmp.cpp
  728. \& \-: 0:Working directory:/home/gcc/testcase
  729. \& \-: 0:Graph:tmp.gcno
  730. \& \-: 0:Data:tmp.gcda
  731. \& \-: 0:Runs:1
  732. \& \-: 0:Programs:1
  733. \& \-: 1:#include <stdio.h>
  734. \& \-: 2:
  735. \& \-: 3:template<class T>
  736. \& \-: 4:class Foo
  737. \& \-: 5:{
  738. \& \-: 6: public:
  739. \& 1*: 7: Foo(): b (1000) {}
  740. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  741. \& Foo<char>::Foo():
  742. \& #####: 7: Foo(): b (1000) {}
  743. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  744. \& Foo<int>::Foo():
  745. \& 1: 7: Foo(): b (1000) {}
  746. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  747. \& 2*: 8: void inc () { b++; }
  748. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  749. \& Foo<char>::inc():
  750. \& #####: 8: void inc () { b++; }
  751. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  752. \& Foo<int>::inc():
  753. \& 2: 8: void inc () { b++; }
  754. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  755. \& \-: 9:
  756. \& \-: 10: private:
  757. \& \-: 11: int b;
  758. \& \-: 12:};
  759. \& \-: 13:
  760. \& \-: 14:template class Foo<int>;
  761. \& \-: 15:template class Foo<char>;
  762. \& \-: 16:
  763. \& \-: 17:int
  764. \& 1: 18:main (void)
  765. \& \-: 19:{
  766. \& \-: 20: int i, total;
  767. \& 1: 21: Foo<int> counter;
  768. \& 1: 21\-block 0
  769. \& \-: 22:
  770. \& 1: 23: counter.inc();
  771. \& 1: 23\-block 0
  772. \& 1: 24: counter.inc();
  773. \& 1: 24\-block 0
  774. \& 1: 25: total = 0;
  775. \& \-: 26:
  776. \& 11: 27: for (i = 0; i < 10; i++)
  777. \& 1: 27\-block 0
  778. \& 11: 27\-block 1
  779. \& 10: 28: total += i;
  780. \& 10: 28\-block 0
  781. \& \-: 29:
  782. \& 1*: 30: int v = total > 100 ? 1 : 2;
  783. \& 1: 30\-block 0
  784. \& %%%%%: 30\-block 1
  785. \& 1: 30\-block 2
  786. \& \-: 31:
  787. \& 1: 32: if (total != 45)
  788. \& 1: 32\-block 0
  789. \& #####: 33: printf ("Failure\en");
  790. \& %%%%%: 33\-block 0
  791. \& \-: 34: else
  792. \& 1: 35: printf ("Success\en");
  793. \& 1: 35\-block 0
  794. \& 1: 36: return 0;
  795. \& 1: 36\-block 0
  796. \& \-: 37:}
  797. .Ve
  798. .PP
  799. In this mode, each basic block is only shown on one line \*(-- the last
  800. line of the block. A multi-line block will only contribute to the
  801. execution count of that last line, and other lines will not be shown
  802. to contain code, unless previous blocks end on those lines.
  803. The total execution count of a line is shown and subsequent lines show
  804. the execution counts for individual blocks that end on that line. After each
  805. block, the branch and call counts of the block will be shown, if the
  806. \&\fB\-b\fR option is given.
  807. .PP
  808. Because of the way \s-1GCC\s0 instruments calls, a call count can be shown
  809. after a line with no individual blocks.
  810. As you can see, line 33 contains a basic block that was not executed.
  811. .PP
  812. When you use the \fB\-b\fR option, your output looks like this:
  813. .PP
  814. .Vb 10
  815. \& \-: 0:Source:tmp.cpp
  816. \& \-: 0:Working directory:/home/gcc/testcase
  817. \& \-: 0:Graph:tmp.gcno
  818. \& \-: 0:Data:tmp.gcda
  819. \& \-: 0:Runs:1
  820. \& \-: 0:Programs:1
  821. \& \-: 1:#include <stdio.h>
  822. \& \-: 2:
  823. \& \-: 3:template<class T>
  824. \& \-: 4:class Foo
  825. \& \-: 5:{
  826. \& \-: 6: public:
  827. \& 1*: 7: Foo(): b (1000) {}
  828. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  829. \& Foo<char>::Foo():
  830. \& function Foo<char>::Foo() called 0 returned 0% blocks executed 0%
  831. \& #####: 7: Foo(): b (1000) {}
  832. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  833. \& Foo<int>::Foo():
  834. \& function Foo<int>::Foo() called 1 returned 100% blocks executed 100%
  835. \& 1: 7: Foo(): b (1000) {}
  836. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  837. \& 2*: 8: void inc () { b++; }
  838. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  839. \& Foo<char>::inc():
  840. \& function Foo<char>::inc() called 0 returned 0% blocks executed 0%
  841. \& #####: 8: void inc () { b++; }
  842. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  843. \& Foo<int>::inc():
  844. \& function Foo<int>::inc() called 2 returned 100% blocks executed 100%
  845. \& 2: 8: void inc () { b++; }
  846. \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  847. \& \-: 9:
  848. \& \-: 10: private:
  849. \& \-: 11: int b;
  850. \& \-: 12:};
  851. \& \-: 13:
  852. \& \-: 14:template class Foo<int>;
  853. \& \-: 15:template class Foo<char>;
  854. \& \-: 16:
  855. \& \-: 17:int
  856. \& function main called 1 returned 100% blocks executed 81%
  857. \& 1: 18:main (void)
  858. \& \-: 19:{
  859. \& \-: 20: int i, total;
  860. \& 1: 21: Foo<int> counter;
  861. \& call 0 returned 100%
  862. \& branch 1 taken 100% (fallthrough)
  863. \& branch 2 taken 0% (throw)
  864. \& \-: 22:
  865. \& 1: 23: counter.inc();
  866. \& call 0 returned 100%
  867. \& branch 1 taken 100% (fallthrough)
  868. \& branch 2 taken 0% (throw)
  869. \& 1: 24: counter.inc();
  870. \& call 0 returned 100%
  871. \& branch 1 taken 100% (fallthrough)
  872. \& branch 2 taken 0% (throw)
  873. \& 1: 25: total = 0;
  874. \& \-: 26:
  875. \& 11: 27: for (i = 0; i < 10; i++)
  876. \& branch 0 taken 91% (fallthrough)
  877. \& branch 1 taken 9%
  878. \& 10: 28: total += i;
  879. \& \-: 29:
  880. \& 1*: 30: int v = total > 100 ? 1 : 2;
  881. \& branch 0 taken 0% (fallthrough)
  882. \& branch 1 taken 100%
  883. \& \-: 31:
  884. \& 1: 32: if (total != 45)
  885. \& branch 0 taken 0% (fallthrough)
  886. \& branch 1 taken 100%
  887. \& #####: 33: printf ("Failure\en");
  888. \& call 0 never executed
  889. \& branch 1 never executed
  890. \& branch 2 never executed
  891. \& \-: 34: else
  892. \& 1: 35: printf ("Success\en");
  893. \& call 0 returned 100%
  894. \& branch 1 taken 100% (fallthrough)
  895. \& branch 2 taken 0% (throw)
  896. \& 1: 36: return 0;
  897. \& \-: 37:}
  898. .Ve
  899. .PP
  900. For each function, a line is printed showing how many times the function
  901. is called, how many times it returns and what percentage of the
  902. function's blocks were executed.
  903. .PP
  904. For each basic block, a line is printed after the last line of the basic
  905. block describing the branch or call that ends the basic block. There can
  906. be multiple branches and calls listed for a single source line if there
  907. are multiple basic blocks that end on that line. In this case, the
  908. branches and calls are each given a number. There is no simple way to map
  909. these branches and calls back to source constructs. In general, though,
  910. the lowest numbered branch or call will correspond to the leftmost construct
  911. on the source line.
  912. .PP
  913. For a branch, if it was executed at least once, then a percentage
  914. indicating the number of times the branch was taken divided by the
  915. number of times the branch was executed will be printed. Otherwise, the
  916. message \*(L"never executed\*(R" is printed.
  917. .PP
  918. For a call, if it was executed at least once, then a percentage
  919. indicating the number of times the call returned divided by the number
  920. of times the call was executed will be printed. This will usually be
  921. 100%, but may be less for functions that call \f(CW\*(C`exit\*(C'\fR or \f(CW\*(C`longjmp\*(C'\fR,
  922. and thus may not return every time they are called.
  923. .PP
  924. The execution counts are cumulative. If the example program were
  925. executed again without removing the \fI.gcda\fR file, the count for the
  926. number of times each line in the source was executed would be added to
  927. the results of the previous run(s). This is potentially useful in
  928. several ways. For example, it could be used to accumulate data over a
  929. number of program runs as part of a test verification suite, or to
  930. provide more accurate long-term information over a large number of
  931. program runs.
  932. .PP
  933. The data in the \fI.gcda\fR files is saved immediately before the program
  934. exits. For each source file compiled with \fB\-fprofile\-arcs\fR, the
  935. profiling code first attempts to read in an existing \fI.gcda\fR file; if
  936. the file doesn't match the executable (differing number of basic block
  937. counts) it will ignore the contents of the file. It then adds in the
  938. new execution counts and finally writes the data to the file.
  939. .SS "Using \fBgcov\fP with \s-1GCC\s0 Optimization"
  940. .IX Subsection "Using gcov with GCC Optimization"
  941. If you plan to use \fBgcov\fR to help optimize your code, you must
  942. first compile your program with a special \s-1GCC\s0 option
  943. \&\fB\-\-coverage\fR. Aside from that, you can use any
  944. other \s-1GCC\s0 options; but if you want to prove that every single line
  945. in your program was executed, you should not compile with optimization
  946. at the same time. On some machines the optimizer can eliminate some
  947. simple code lines by combining them with other lines. For example, code
  948. like this:
  949. .PP
  950. .Vb 4
  951. \& if (a != b)
  952. \& c = 1;
  953. \& else
  954. \& c = 0;
  955. .Ve
  956. .PP
  957. can be compiled into one instruction on some machines. In this case,
  958. there is no way for \fBgcov\fR to calculate separate execution counts
  959. for each line because there isn't separate code for each line. Hence
  960. the \fBgcov\fR output looks like this if you compiled the program with
  961. optimization:
  962. .PP
  963. .Vb 4
  964. \& 100: 12:if (a != b)
  965. \& 100: 13: c = 1;
  966. \& 100: 14:else
  967. \& 100: 15: c = 0;
  968. .Ve
  969. .PP
  970. The output shows that this block of code, combined by optimization,
  971. executed 100 times. In one sense this result is correct, because there
  972. was only one instruction representing all four of these lines. However,
  973. the output does not indicate how many times the result was 0 and how
  974. many times the result was 1.
  975. .PP
  976. Inlineable functions can create unexpected line counts. Line counts are
  977. shown for the source code of the inlineable function, but what is shown
  978. depends on where the function is inlined, or if it is not inlined at all.
  979. .PP
  980. If the function is not inlined, the compiler must emit an out of line
  981. copy of the function, in any object file that needs it. If
  982. \&\fIfileA.o\fR and \fIfileB.o\fR both contain out of line bodies of a
  983. particular inlineable function, they will also both contain coverage
  984. counts for that function. When \fIfileA.o\fR and \fIfileB.o\fR are
  985. linked together, the linker will, on many systems, select one of those
  986. out of line bodies for all calls to that function, and remove or ignore
  987. the other. Unfortunately, it will not remove the coverage counters for
  988. the unused function body. Hence when instrumented, all but one use of
  989. that function will show zero counts.
  990. .PP
  991. If the function is inlined in several places, the block structure in
  992. each location might not be the same. For instance, a condition might
  993. now be calculable at compile time in some instances. Because the
  994. coverage of all the uses of the inline function will be shown for the
  995. same source lines, the line counts themselves might seem inconsistent.
  996. .PP
  997. Long-running applications can use the \f(CW\*(C`_\|_gcov_reset\*(C'\fR and \f(CW\*(C`_\|_gcov_dump\*(C'\fR
  998. facilities to restrict profile collection to the program region of
  999. interest. Calling \f(CW\*(C`_\|_gcov_reset(void)\*(C'\fR will clear all profile counters
  1000. to zero, and calling \f(CW\*(C`_\|_gcov_dump(void)\*(C'\fR will cause the profile information
  1001. collected at that point to be dumped to \fI.gcda\fR output files.
  1002. Instrumented applications use a static destructor with priority 99
  1003. to invoke the \f(CW\*(C`_\|_gcov_dump\*(C'\fR function. Thus \f(CW\*(C`_\|_gcov_dump\*(C'\fR
  1004. is executed after all user defined static destructors,
  1005. as well as handlers registered with \f(CW\*(C`atexit\*(C'\fR.
  1006. If an executable loads a dynamic shared object via dlopen functionality,
  1007. \&\fB\-Wl,\-\-dynamic\-list\-data\fR is needed to dump all profile data.
  1008. .PP
  1009. Profiling run-time library reports various errors related to profile
  1010. manipulation and profile saving. Errors are printed into standard error output
  1011. or \fB\s-1GCOV_ERROR_FILE\s0\fR file, if environment variable is used.
  1012. In order to terminate immediately after an errors occurs
  1013. set \fB\s-1GCOV_EXIT_AT_ERROR\s0\fR environment variable.
  1014. That can help users to find profile clashing which leads
  1015. to a misleading profile.
  1016. .SH "SEE ALSO"
  1017. .IX Header "SEE ALSO"
  1018. \&\fIgpl\fR\|(7), \fIgfdl\fR\|(7), \fIfsf\-funding\fR\|(7), \fIgcc\fR\|(1) and the Info entry for \fIgcc\fR.
  1019. .SH "COPYRIGHT"
  1020. .IX Header "COPYRIGHT"
  1021. Copyright (c) 1996\-2020 Free Software Foundation, Inc.
  1022. .PP
  1023. Permission is granted to copy, distribute and/or modify this document
  1024. under the terms of the \s-1GNU\s0 Free Documentation License, Version 1.3 or
  1025. any later version published by the Free Software Foundation; with the
  1026. Invariant Sections being \*(L"\s-1GNU\s0 General Public License\*(R" and \*(L"Funding
  1027. Free Software\*(R", the Front-Cover texts being (a) (see below), and with
  1028. the Back-Cover Texts being (b) (see below). A copy of the license is
  1029. included in the \fIgfdl\fR\|(7) man page.
  1030. .PP
  1031. (a) The \s-1FSF\s0's Front-Cover Text is:
  1032. .PP
  1033. .Vb 1
  1034. \& A GNU Manual
  1035. .Ve
  1036. .PP
  1037. (b) The \s-1FSF\s0's Back-Cover Text is:
  1038. .PP
  1039. .Vb 3
  1040. \& You have freedom to copy and modify this GNU Manual, like GNU
  1041. \& software. Copies published by the Free Software Foundation raise
  1042. \& funds for GNU development.
  1043. .Ve