gcov JSON 1

The JSON report GCC’s gcov writes with gcov --json-format, format version 1, as a JSON Schema.

Read by pyEDAA.Reports.CodeCoverage.Gcov.Document - see gcov JSON - for a JSON object stating "format_version": "1".

gcov documents its JSON report in its manual, but publishes no schema. This one is reverse-engineered from GCC’s gcc/gcov.cc (GCC 9 to 13): format 1 is written by GCC 9 to 13. It knows no basic blocks, calls or conditions of a line - format 2 added them -, so a field of format 2 is rejected, like any unknown field. The schema describes one JSON object: gcov’s standard output holds one per data file, each validated on its own.

Download

Gcov-1.schema.json (3.9 kiB)

Validate a report

gunzip --keep main.gcov.json.gz
check-jsonschema --schemafile Gcov-1.schema.json main.gcov.json

Source

 1{
 2	"$schema": "https://json-schema.org/draft/2020-12/schema",
 3	"$id": "https://edaa-org.github.io/pyEDAA.Reports/Schemas/Gcov-1.schema.json",
 4	"title": "gcov JSON report, format 1",
 5	"description": "The JSON report gcov writes with 'gcov --json-format' for one data file, format version 1 (GCC 9 to 13). Reverse-engineered from GCC's 'gcov.cc' (GCC 9 to 13) and its documentation.",
 6	"type": "object",
 7	"required": ["format_version", "gcc_version", "data_file", "files"],
 8	"properties": {
 9		"format_version":            {"description": "Version of the report format.", "const": "1"},
10		"gcc_version":               {"description": "Version of GCC.", "type": "string"},
11		"current_working_directory": {"description": "Directory the compilation unit was compiled in.", "type": "string"},
12		"data_file":                 {"description": "Name of the data file (GCDA), as gcov was called with it.", "type": "string"},
13		"files":                     {"type": "array", "items": {"$ref": "#/$defs/File"}}
14	},
15	"additionalProperties": false,
16	"$defs": {
17		"Count": {
18			"type": "integer",
19			"minimum": 0
20		},
21		"File": {
22			"description": "A source file: its functions and lines.",
23			"type": "object",
24			"required": ["file", "functions", "lines"],
25			"properties": {
26				"file":      {"description": "Path of the source file, as the compiler named it.", "type": "string"},
27				"functions": {"type": "array", "items": {"$ref": "#/$defs/Function"}},
28				"lines":     {"type": "array", "items": {"$ref": "#/$defs/Line"}}
29			},
30			"additionalProperties": false
31		},
32		"Function": {
33			"description": "A function: its position, basic blocks and how often it ran.",
34			"type": "object",
35			"required": [
36				"name", "demangled_name", "start_line", "start_column", "end_line", "end_column", "blocks", "blocks_executed",
37				"execution_count"
38			],
39			"properties": {
40				"name":            {"description": "Name of the function, mangled.", "type": "string"},
41				"demangled_name":  {"description": "Name of the function, demangled.", "type": "string"},
42				"start_line":      {"type": "integer", "minimum": 0},
43				"start_column":    {"type": "integer", "minimum": 0},
44				"end_line":        {"type": "integer", "minimum": 0},
45				"end_column":      {"type": "integer", "minimum": 0},
46				"blocks":          {"description": "Number of basic blocks.", "$ref": "#/$defs/Count"},
47				"blocks_executed": {"description": "Number of executed basic blocks.", "$ref": "#/$defs/Count"},
48				"execution_count": {"description": "Number of executions.", "$ref": "#/$defs/Count"}
49			},
50			"additionalProperties": false
51		},
52		"Line": {
53			"description": "An executable line. A line of several functions - e.g. template instantiations - is listed once per function.",
54			"type": "object",
55			"required": ["line_number", "count", "unexecuted_block", "branches"],
56			"properties": {
57				"line_number":      {"type": "integer", "minimum": 1},
58				"function_name":    {"description": "Mangled name of the function; missing for a line of inlined statements.", "type": "string"},
59				"count":            {"description": "Number of executions.", "$ref": "#/$defs/Count"},
60				"unexecuted_block": {"description": "Whether a basic block of the line, not only reached by exceptions, never ran.", "type": "boolean"},
61				"branches":         {"description": "Listed with 'gcov --branch-probabilities' only.", "type": "array", "items": {"$ref": "#/$defs/Branch"}}
62			},
63			"additionalProperties": false
64		},
65		"Branch": {
66			"description": "A branch: an edge from a basic block to another.",
67			"type": "object",
68			"required": ["count", "throw", "fallthrough"],
69			"properties": {
70				"count":       {"description": "Number of times the branch was taken.", "$ref": "#/$defs/Count"},
71				"throw":       {"description": "Whether the branch is taken by an exception.", "type": "boolean"},
72				"fallthrough": {"description": "Whether the branch falls through.", "type": "boolean"}
73			},
74			"additionalProperties": false
75		}
76	}
77}