GCC Middle and Back End API Reference
diagnostic-format-sarif.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "diagnostic.h"
#include "diagnostic-metadata.h"
#include "diagnostic-path.h"
#include "json.h"
#include "cpplib.h"
#include "logical-location.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-diagram.h"
#include "text-art/canvas.h"
#include "diagnostic-format-sarif.h"
#include "ordered-hash-map.h"
#include "sbitmap.h"
Include dependency graph for diagnostic-format-sarif.cc:

Data Structures

class  sarif_invocation
 
class  sarif_artifact
 
class  sarif_result
 
class  sarif_ice_notification
 
class  sarif_thread_flow
 
class  sarif_builder
 
class  sarif_output_format
 
class  sarif_stream_output_format
 
class  sarif_file_output_format
 

Macros

#define INCLUDE_VECTOR
 
#define PWD_PROPERTY_NAME   ("PWD")
 
#define FILE_PREFIX   ("file://")
 
#define SARIF_SCHEMA   "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"
 
#define SARIF_VERSION   "2.1.0"
 

Enumerations

enum class  diagnostic_artifact_role {
  analysis_target , debug_output_file , result_file , traced_file ,
  NUM_ROLES
}
 

Functions

static const char * get_artifact_role_string (enum diagnostic_artifact_role role)
 
static const char * maybe_get_sarif_level (diagnostic_t diag_kind)
 
static char * make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind)
 
static char * make_pwd_uri_str ()
 
static const char * maybe_get_sarif_kind (enum logical_location_kind kind)
 
json::objectmake_sarif_logical_location_object (const logical_location &logical_loc)
 
static void sarif_ice_handler (diagnostic_context *context)
 
static void diagnostic_output_format_init_sarif (diagnostic_context *context)
 
void diagnostic_output_format_init_sarif_stderr (diagnostic_context *context, const char *main_input_filename_, bool formatted)
 
void diagnostic_output_format_init_sarif_file (diagnostic_context *context, const char *main_input_filename_, bool formatted, const char *base_file_name)
 
void diagnostic_output_format_init_sarif_stream (diagnostic_context *context, const char *main_input_filename_, bool formatted, FILE *stream)
 

Macro Definition Documentation

◆ FILE_PREFIX

#define FILE_PREFIX   ("file://")

Referenced by make_pwd_uri_str().

◆ INCLUDE_VECTOR

#define INCLUDE_VECTOR
SARIF output for diagnostics
   Copyright (C) 2018-2024 Free Software Foundation, Inc.
   Contributed by David Malcolm <dmalcolm@redhat.com>.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   

◆ PWD_PROPERTY_NAME

#define PWD_PROPERTY_NAME   ("PWD")
The ID value for use in "uriBaseId" properties (SARIF v2.1.0 section 3.4.4)
for when we need to express paths relative to PWD.   

Referenced by sarif_builder::make_artifact_location_object(), and sarif_builder::make_run_object().

◆ SARIF_SCHEMA

#define SARIF_SCHEMA   "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"

◆ SARIF_VERSION

#define SARIF_VERSION   "2.1.0"

Enumeration Type Documentation

◆ diagnostic_artifact_role

enum class diagnostic_artifact_role
strong
Corresponds to values for the SARIF artifact objects "roles" property.
(SARIF v2.1.0 section 3.24.6).   
Enumerator
analysis_target 
debug_output_file 
result_file 
traced_file 
NUM_ROLES 

Function Documentation

◆ diagnostic_output_format_init_sarif()

◆ diagnostic_output_format_init_sarif_file()

void diagnostic_output_format_init_sarif_file ( diagnostic_context * context,
const char * main_input_filename_,
bool formatted,
const char * base_file_name )
Populate CONTEXT in preparation for SARIF output to a file named
BASE_FILE_NAME.sarif.   

References base_file_name(), diagnostic_output_format_init_sarif(), and diagnostic_context::set_output_format().

Referenced by diagnostic_output_format_init().

◆ diagnostic_output_format_init_sarif_stderr()

void diagnostic_output_format_init_sarif_stderr ( diagnostic_context * context,
const char * main_input_filename_,
bool formatted )
Populate CONTEXT in preparation for SARIF output to stderr.   

References diagnostic_output_format_init_sarif(), and diagnostic_context::set_output_format().

Referenced by diagnostic_output_format_init().

◆ diagnostic_output_format_init_sarif_stream()

void diagnostic_output_format_init_sarif_stream ( diagnostic_context * context,
const char * main_input_filename_,
bool formatted,
FILE * stream )
Populate CONTEXT in preparation for SARIF output to STREAM.   

References diagnostic_output_format_init_sarif(), and diagnostic_context::set_output_format().

◆ get_artifact_role_string()

static const char * get_artifact_role_string ( enum diagnostic_artifact_role role)
static
Get a string for ROLE corresponding to the
SARIF v2.1.0 section 3.24.6 "roles" property.   

References analysis_target, debug_output_file, gcc_unreachable, result_file, and traced_file.

Referenced by sarif_artifact::populate_roles().

◆ make_pwd_uri_str()

static char * make_pwd_uri_str ( )
static
Get the PWD, or NULL, as an absolute file-based URI,
adding a trailing forward slash (as required by SARIF v2.1.0
section 3.14.14).   

References FILE_PREFIX, gcc_assert, and NULL.

Referenced by sarif_builder::make_artifact_location_object_for_pwd().

◆ make_rule_id_for_diagnostic_kind()

static char * make_rule_id_for_diagnostic_kind ( diagnostic_t diag_kind)
static
Make a string for DIAG_KIND suitable for use a ruleId
(SARIF v2.1.0 section 3.27.5) as a fallback for when we don't
have anything better to use.   

References gcc_assert, and get_diagnostic_kind_text().

Referenced by sarif_builder::make_result_object().

◆ make_sarif_logical_location_object()

json::object * make_sarif_logical_location_object ( const logical_location & logical_loc)

◆ maybe_get_sarif_kind()

static const char * maybe_get_sarif_kind ( enum logical_location_kind kind)
static

◆ maybe_get_sarif_level()

static const char * maybe_get_sarif_level ( diagnostic_t diag_kind)
static
Attempt to convert DIAG_KIND to a suitable value for the "level"
property (SARIF v2.1.0 section 3.27.10).

Return NULL if there isn't one.   

References NULL.

Referenced by sarif_builder::make_result_object().

◆ sarif_ice_handler()

static void sarif_ice_handler ( diagnostic_context * context)
static
Callback for diagnostic_context::ice_handler_cb for when an ICE
occurs.   

References diagnostic_finish(), and fnotice().

Referenced by diagnostic_output_format_init_sarif().