GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "version.h"
#include "demangle.h"
#include "intl.h"
#include "backtrace.h"
#include "diagnostic.h"
#include "diagnostic-color.h"
#include "diagnostic-url.h"
#include "diagnostic-metadata.h"
#include "diagnostic-path.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-diagram.h"
#include "diagnostic-format.h"
#include "diagnostic-format-sarif.h"
#include "diagnostic-format-text.h"
#include "edit-context.h"
#include "selftest.h"
#include "selftest-diagnostic.h"
#include "opts.h"
#include "cpplib.h"
#include "text-art/theme.h"
#include "pretty-print-urlifier.h"
#include "logical-location.h"
#include "diagnostic-buffer.h"
#include "make-unique.h"
#include "diagnostic.def"
Macros | |
#define | INCLUDE_VECTOR |
#define | DEFINE_DIAGNOSTIC_KIND(K, T, C) |
#define | DEFINE_DIAGNOSTIC_KIND(K, T, C) |
Functions | |
static void | real_abort (void) ATTRIBUTE_NORETURN |
char * | build_message_string (const char *msg,...) |
int | get_terminal_width (void) |
void | diagnostic_set_caret_max_width (diagnostic_context *context, int value) |
void | diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg, va_list *args, rich_location *richloc, diagnostic_t kind) |
void | diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid, va_list *args, rich_location *richloc, diagnostic_t kind) |
const char * | diagnostic_get_color_for_kind (diagnostic_t kind) |
static int | convert_column_unit (file_cache &fc, enum diagnostics_column_unit column_unit, int tabstop, expanded_location s) |
const char * | get_diagnostic_kind_text (diagnostic_t kind) |
static int | bt_callback (void *data, uintptr_t pc, const char *filename, int lineno, const char *function) |
static void | bt_err_callback (void *data, const char *msg, int errnum) |
void | default_diagnostic_start_span_fn (const diagnostic_location_print_policy &loc_policy, pretty_printer *pp, expanded_location exploc) |
static void | print_escaped_string (pretty_printer *pp, const char *text) |
static void | print_parseable_fixits (file_cache &fc, pretty_printer *pp, rich_location *richloc, enum diagnostics_column_unit column_unit, int tabstop) |
char * | get_cwe_url (int cwe) |
int | num_digits (int value) |
const char * | trim_filename (const char *name) |
void | fancy_abort (const char *file, int line, const char *function) |
void | diagnostic_output_format_init (diagnostic_context &context, const char *main_input_filename_, const char *base_file_name, enum diagnostics_output_format format, bool json_formatting) |
Variables | |
const char * | progname |
static const char *const | diagnostic_kind_color [] |
static const char *const | diagnostic_kind_text [] |
static const char *const | bt_stop [] |
#define DEFINE_DIAGNOSTIC_KIND | ( | K, | |
T, | |||
C ) |
#define DEFINE_DIAGNOSTIC_KIND | ( | K, | |
T, | |||
C ) |
#define INCLUDE_VECTOR |
Language-independent diagnostic subroutines for the GNU Compiler Collection Copyright (C) 1999-2024 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis <gdr@codesourcery.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/>.
This file implements the language independent aspect of diagnostic message module.
|
static |
A callback function passed to the backtrace_full function.
References bt_stop, free(), i, and NULL.
Referenced by fancy_abort().
|
static |
A callback function passed to the backtrace_full function. This is called if backtrace_full has an error.
References msg.
Referenced by diagnostic_context::action_after_output(), and fancy_abort().
char * build_message_string | ( | const char * | msg, |
... ) |
Return a malloc'd string containing MSG formatted a la printf. The caller is responsible for freeing the memory.
Referenced by diagnostic_text_output_format::build_prefix(), diagnostic_text_output_format::file_name_as_prefix(), and diagnostic_column_policy::get_location_text().
|
static |
Given an expanded_location, convert the column (which is in 1-based bytes) to the requested units, without converting the origin. Return -1 if the column is invalid (<= 0).
References DIAGNOSTICS_COLUMN_UNIT_BYTE, DIAGNOSTICS_COLUMN_UNIT_DISPLAY, gcc_unreachable, and location_compute_display_column().
Referenced by diagnostic_column_policy::converted_column(), and print_parseable_fixits().
void default_diagnostic_start_span_fn | ( | const diagnostic_location_print_policy & | loc_policy, |
pretty_printer * | pp, | ||
expanded_location | exploc ) |
const char * diagnostic_get_color_for_kind | ( | diagnostic_t | kind | ) |
Get a color name for diagnostics of type KIND Result could be NULL.
References diagnostic_kind_color.
Referenced by diagnostic_text_output_format::build_prefix(), diagnostic_text_output_format::print_any_cwe(), diagnostic_text_output_format::print_any_rules(), and diagnostic_text_output_format::print_option_information().
void diagnostic_output_format_init | ( | diagnostic_context & | context, |
const char * | main_input_filename_, | ||
const char * | base_file_name, | ||
enum diagnostics_output_format | format, | ||
bool | json_formatting ) |
Set the output format for CONTEXT to FORMAT, using BASE_FILE_NAME for file-based output formats.
References base_file_name(), diagnostic_output_format_init_json_file(), diagnostic_output_format_init_json_stderr(), diagnostic_output_format_init_sarif_file(), diagnostic_output_format_init_sarif_stderr(), DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE, DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR, DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE, DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR, DIAGNOSTICS_OUTPUT_FORMAT_TEXT, gcc_unreachable, line_table, and v2_1_0.
Referenced by common_handle_option(), and driver_handle_option().
void diagnostic_set_caret_max_width | ( | diagnostic_context * | context, |
int | value ) |
Set caret_max_width to value.
References diagnostic_context::get_reference_printer(), get_terminal_width(), INT_MAX, diagnostic_context::m_source_printing, output_buffer::m_stream, diagnostic_source_printing_options::max_width, and pp_buffer().
Referenced by common_handle_option(), and diagnostic_context::initialize().
void diagnostic_set_info | ( | diagnostic_info * | diagnostic, |
const char * | gmsgid, | ||
va_list * | args, | ||
rich_location * | richloc, | ||
diagnostic_t | kind ) |
Initialize DIAGNOSTIC, where the message GMSGID has not yet been translated.
References _, diagnostic_set_info_translated(), and gcc_assert.
Referenced by diagnostic_text_output_format::append_note(), diagnostic_for_asm(), sink::emit(), and format_string_diagnostic_t::emit_warning_n_va().
void diagnostic_set_info_translated | ( | diagnostic_info * | diagnostic, |
const char * | msg, | ||
va_list * | args, | ||
rich_location * | richloc, | ||
diagnostic_t | kind ) |
Initialize DIAGNOSTIC, where the message MSG has already been translated.
References errno, gcc_assert, msg, and NULL.
Referenced by diagnostic_set_info(), and format_string_diagnostic_t::emit_warning_n_va().
void fancy_abort | ( | const char * | file, |
int | line, | ||
const char * | function ) |
Report an internal compiler error in a friendly manner. This is the function that gets called upon use of abort() in the source code generally, thanks to a special macro.
References bt_callback(), bt_err_callback(), count, diagnostic_kind_text, fnotice(), fputc(), diagnostic_context::get_reference_printer(), global_dc, internal_error(), NULL, real_abort(), and trim_filename().
Referenced by _fatal_insn().
char * get_cwe_url | ( | int | cwe | ) |
Generate a URL string describing CWE. The caller is responsible for freeing the string.
Referenced by sarif_builder::make_reporting_descriptor_object_for_cwe_id(), and diagnostic_text_output_format::print_any_cwe().
const char * get_diagnostic_kind_text | ( | diagnostic_t | kind | ) |
Get unlocalized string describing KIND.
References diagnostic_kind_text.
Referenced by diagnostic_text_output_format::build_prefix(), diagnostic_counters::dump(), make_rule_id_for_diagnostic_kind(), and json_output_format::on_report_diagnostic().
int get_terminal_width | ( | void | ) |
Return the value of the getenv("COLUMNS") as an integer. If the value is not set to a positive integer, use ioctl to get the terminal width. If it fails, return INT_MAX.
Referenced by diagnostic_set_caret_max_width(), and print_specific_help().
int num_digits | ( | int | value | ) |
Get the number of digits in the decimal representation of VALUE.
References gcc_assert.
Referenced by dump_location_info().
|
static |
Helper function for print_parseable_fixits. Print TEXT to PP, obeying the escaping rules for -fdiagnostics-parseable-fixits.
References gcc_assert, pp_character(), pp_printf(), and pp_string().
Referenced by print_parseable_fixits().
|
static |
Implementation of -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. Print a machine-parseable version of all fixits in RICHLOC to PP, using COLUMN_UNIT to express columns. Use TABSTOP when handling DIAGNOSTICS_COLUMN_UNIT_DISPLAY.
References convert_column_unit(), expand_location(), gcc_assert, i, NULL, pp_newline(), pp_printf(), pp_set_prefix(), pp_string(), pp_take_prefix(), and print_escaped_string().
Referenced by diagnostic_context::report_diagnostic().
|
static |
Disable warnings about quoting issues in the pp_xxx calls below that (intentionally) don't follow GCC diagnostic conventions.
Really call the system 'abort'. This has to go right at the end of this file, so that there are no functions after it that call abort and get the system abort instead of our macro.
References abort.
Referenced by diagnostic_context::action_after_output(), diagnostic_context::error_recursion(), and fancy_abort().
const char * trim_filename | ( | const char * | name | ) |
Given a partial pathname as input, return another pathname that shares no directory elements with the pathname of __FILE__. This is used by fancy_abort() to print `internal compiler error in expr.cc' instead of `internal compiler error in ../../GCC/gcc/expr.cc'.
Referenced by fancy_abort().
|
static |
Functions at which to stop the backtrace print. It's not particularly helpful to print the callers of these functions.
Referenced by bt_callback().
|
static |
Referenced by diagnostic_get_color_for_kind().
|
static |
Referenced by fancy_abort(), and get_diagnostic_kind_text().
const char* progname |
Name of program invoked, sans directories.