gcov JSON 2

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

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

gcov documents its JSON report in its manual, but publishes no schema. This one is reverse-engineered from GCC’s gcc/gcov.cc (GCC 14 and 15) and the manual of GCC 14: format 2 is written by GCC 14 and later. It adds to format 1 the IDs of the basic blocks of a line and of a branch, a line’s calls and its conditions; gcov writes them always, the lists empty unless asked for. GCC 15 adds the prime paths of a function, written with gcov --prime-paths only, so they are optional. An unknown field is rejected. The schema describes one JSON object: gcov’s standard output holds one per data file, each validated on its own.

Download

Gcov-2.schema.json (6.4 kiB)

Validate a report

gunzip --keep main.gcov.json.gz
check-jsonschema --schemafile Gcov-2.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-2.schema.json",
  4	"title": "gcov JSON report, format 2",
  5	"description": "The JSON report gcov writes with 'gcov --json-format' for one data file, format version 2 (GCC 14 and later). Reverse-engineered from GCC's 'gcov.cc' (GCC 14 and 15) and its documentation: format 2 added the basic blocks of a line and a branch, the calls and the conditions to format 1; GCC 15 added the prime paths of a function, written with 'gcov --prime-paths' only.",
  6	"type": "object",
  7	"required": ["format_version", "gcc_version", "data_file", "files"],
  8	"properties": {
  9		"format_version":            {"description": "Version of the report format.", "const": "2"},
 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		"BlockID": {
 22			"description": "ID of a basic block, unique within its function.",
 23			"type": "integer",
 24			"minimum": 0
 25		},
 26		"File": {
 27			"description": "A source file: its functions and lines.",
 28			"type": "object",
 29			"required": ["file", "functions", "lines"],
 30			"properties": {
 31				"file":      {"description": "Path of the source file, as the compiler named it.", "type": "string"},
 32				"functions": {"type": "array", "items": {"$ref": "#/$defs/Function"}},
 33				"lines":     {"type": "array", "items": {"$ref": "#/$defs/Line"}}
 34			},
 35			"additionalProperties": false
 36		},
 37		"Function": {
 38			"description": "A function: its position, basic blocks and how often it ran.",
 39			"type": "object",
 40			"required": [
 41				"name", "demangled_name", "start_line", "start_column", "end_line", "end_column", "blocks", "blocks_executed",
 42				"execution_count"
 43			],
 44			"properties": {
 45				"name":                {"description": "Name of the function, mangled.", "type": "string"},
 46				"demangled_name":      {"description": "Name of the function, demangled.", "type": "string"},
 47				"start_line":          {"type": "integer", "minimum": 0},
 48				"start_column":        {"type": "integer", "minimum": 0},
 49				"end_line":            {"type": "integer", "minimum": 0},
 50				"end_column":          {"type": "integer", "minimum": 0},
 51				"blocks":              {"description": "Number of basic blocks.", "$ref": "#/$defs/Count"},
 52				"blocks_executed":     {"description": "Number of executed basic blocks.", "$ref": "#/$defs/Count"},
 53				"execution_count":     {"description": "Number of executions.", "$ref": "#/$defs/Count"},
 54				"total_prime_paths":   {"description": "Number of prime paths (GCC 15).", "$ref": "#/$defs/Count"},
 55				"covered_prime_paths": {"description": "Number of covered prime paths (GCC 15).", "$ref": "#/$defs/Count"},
 56				"prime_path_coverage": {"description": "The prime paths not covered (GCC 15).", "type": "array"}
 57			},
 58			"additionalProperties": false
 59		},
 60		"Line": {
 61			"description": "An executable line. A line of several functions - e.g. template instantiations - is listed once per function.",
 62			"type": "object",
 63			"required": ["line_number", "count", "unexecuted_block", "block_ids", "branches", "calls", "conditions"],
 64			"properties": {
 65				"line_number":      {"type": "integer", "minimum": 1},
 66				"function_name":    {"description": "Mangled name of the function; missing for a line of inlined statements.", "type": "string"},
 67				"count":            {"description": "Number of executions.", "$ref": "#/$defs/Count"},
 68				"unexecuted_block": {"description": "Whether a basic block of the line, not only reached by exceptions, never ran.", "type": "boolean"},
 69				"block_ids":        {"description": "The basic blocks ending on this line.", "type": "array", "items": {"$ref": "#/$defs/BlockID"}},
 70				"branches":         {"description": "Listed with 'gcov --branch-probabilities' only.", "type": "array", "items": {"$ref": "#/$defs/Branch"}},
 71				"calls":            {"description": "Listed with 'gcov --branch-probabilities' only.", "type": "array", "items": {"$ref": "#/$defs/Call"}},
 72				"conditions":       {"description": "Listed with 'gcov --conditions' only.", "type": "array", "items": {"$ref": "#/$defs/Condition"}}
 73			},
 74			"additionalProperties": false
 75		},
 76		"Branch": {
 77			"description": "A branch: an edge from a basic block to another.",
 78			"type": "object",
 79			"required": ["count", "throw", "fallthrough", "source_block_id", "destination_block_id"],
 80			"properties": {
 81				"count":                {"description": "Number of times the branch was taken.", "$ref": "#/$defs/Count"},
 82				"throw":                {"description": "Whether the branch is taken by an exception.", "type": "boolean"},
 83				"fallthrough":          {"description": "Whether the branch falls through.", "type": "boolean"},
 84				"source_block_id":      {"$ref": "#/$defs/BlockID"},
 85				"destination_block_id": {"$ref": "#/$defs/BlockID"}
 86			},
 87			"additionalProperties": false
 88		},
 89		"Call": {
 90			"description": "A call: from a basic block to the block continuing after the return.",
 91			"type": "object",
 92			"required": ["source_block_id", "destination_block_id", "returned"],
 93			"properties": {
 94				"source_block_id":      {"$ref": "#/$defs/BlockID"},
 95				"destination_block_id": {"$ref": "#/$defs/BlockID"},
 96				"returned":             {"description": "Number of times the call returned.", "$ref": "#/$defs/Count"}
 97			},
 98			"additionalProperties": false
 99		},
100		"Condition": {
101			"description": "The conditions of a boolean expression (MC/DC, 'gcc -fcondition-coverage').",
102			"type": "object",
103			"required": ["count", "covered", "not_covered_true", "not_covered_false"],
104			"properties": {
105				"count":             {"description": "Number of condition outcomes: twice the number of terms.", "$ref": "#/$defs/Count"},
106				"covered":           {"description": "Number of covered condition outcomes.", "$ref": "#/$defs/Count"},
107				"not_covered_true":  {"description": "The terms, by index, never seen as true.", "type": "array", "items": {"$ref": "#/$defs/Count"}},
108				"not_covered_false": {"description": "The terms, by index, never seen as false.", "type": "array", "items": {"$ref": "#/$defs/Count"}}
109			},
110			"additionalProperties": false
111		}
112	}
113}