|
diagnostic_manager * | diagnostic_manager_new (void) |
|
void | diagnostic_manager_release (diagnostic_manager *) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_manager_set_tool_name (diagnostic_manager *diag_mgr, const char *value) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
void | diagnostic_manager_set_full_name (diagnostic_manager *diag_mgr, const char *value) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
void | diagnostic_manager_set_version_string (diagnostic_manager *diag_mgr, const char *value) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
void | diagnostic_manager_set_version_url (diagnostic_manager *diag_mgr, const char *value) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
diagnostic_text_sink * | diagnostic_manager_add_text_sink (diagnostic_manager *diag_mgr, FILE *dst_stream, enum diagnostic_colorize colorize) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
void | diagnostic_text_sink_set_source_printing_enabled (diagnostic_text_sink *text_sink, int value) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_text_sink_set_colorize (diagnostic_text_sink *text_sink, enum diagnostic_colorize colorize) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_text_sink_set_labelled_source_colorization_enabled (diagnostic_text_sink *text_sink, int value) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_manager_add_sarif_sink (diagnostic_manager *diag_mgr, FILE *dst_stream, const diagnostic_file *main_input_file, enum diagnostic_sarif_version version) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
void | diagnostic_manager_write_patch (diagnostic_manager *diag_mgr, FILE *dst_stream) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
diagnostic_file * | diagnostic_manager_new_file (diagnostic_manager *diag_mgr, const char *name, const char *sarif_source_language) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(3) |
|
void | diagnostic_file_set_buffered_content (diagnostic_file *file, const char *buf, size_t sz) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
void | diagnostic_manager_debug_dump_file (diagnostic_manager *diag_mgr, const diagnostic_file *file, FILE *out) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
const diagnostic_physical_location * | diagnostic_manager_new_location_from_file_and_line (diagnostic_manager *diag_mgr, const diagnostic_file *file, diagnostic_line_num_t line_num) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
const diagnostic_physical_location * | diagnostic_manager_new_location_from_file_line_column (diagnostic_manager *diag_mgr, const diagnostic_file *file, diagnostic_line_num_t line_num, diagnostic_column_num_t column_num) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
const diagnostic_physical_location * | diagnostic_manager_new_location_from_range (diagnostic_manager *diag_mgr, const diagnostic_physical_location *loc_caret, const diagnostic_physical_location *loc_start, const diagnostic_physical_location *loc_end) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(4) |
|
void | diagnostic_manager_debug_dump_location (const diagnostic_manager *diag_mgr, const diagnostic_physical_location *loc, FILE *out) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
const diagnostic_logical_location * | diagnostic_manager_new_logical_location (diagnostic_manager *diag_mgr, enum diagnostic_logical_location_kind_t kind, const diagnostic_logical_location *parent, const char *short_name, const char *fully_qualified_name, const char *decorated_name) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(6) |
|
void | diagnostic_manager_debug_dump_logical_location (const diagnostic_manager *diag_mgr, const diagnostic_logical_location *loc, FILE *out) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
void | diagnostic_manager_begin_group (diagnostic_manager *diag_mgr) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_manager_end_group (diagnostic_manager *diag_mgr) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
diagnostic * | diagnostic_begin (diagnostic_manager *diag_mgr, enum diagnostic_level level) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_set_cwe (diagnostic *diag, unsigned cwe_id) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_add_rule (diagnostic *diag, const char *title, const char *url) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(3) |
|
void | diagnostic_set_location (diagnostic *diag, const diagnostic_physical_location *loc) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(2) |
|
void | diagnostic_set_location_with_label (diagnostic *diag, const diagnostic_physical_location *loc, const char *fmt,...) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
void | diagnostic_add_location (diagnostic *diag, const diagnostic_physical_location *loc) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_add_location_with_label (diagnostic *diag, const diagnostic_physical_location *loc, const char *text) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
void | diagnostic_set_logical_location (diagnostic *diag, const diagnostic_logical_location *logical_loc) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(2) |
|
void | diagnostic_add_fix_it_hint_insert_before (diagnostic *diag, const diagnostic_physical_location *loc, const char *addition) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
void | diagnostic_add_fix_it_hint_insert_after (diagnostic *diag, const diagnostic_physical_location *loc, const char *addition) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
void | diagnostic_add_fix_it_hint_replace (diagnostic *diag, const diagnostic_physical_location *loc, const char *replacement) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(3) |
|
void | diagnostic_add_fix_it_hint_delete (diagnostic *diag, const diagnostic_physical_location *loc) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(2) |
|
diagnostic_execution_path * | diagnostic_add_execution_path (diagnostic *diag) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
diagnostic_execution_path * | diagnostic_manager_new_execution_path (diagnostic_manager *manager) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(1) |
|
void | diagnostic_take_execution_path (diagnostic *diag, diagnostic_execution_path *path) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL(2) |
|
void | diagnostic_execution_path_release (diagnostic_execution_path *path) LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL(1) |
|
diagnostic_event_id | diagnostic_execution_path_add_event (diagnostic_execution_path *path, const diagnostic_physical_location *physical_loc, const diagnostic_logical_location *logical_loc, unsigned stack_depth, const char *fmt,...) LIBGDIAGNOSTICS_PARAM_GCC_FORMAT_STRING(5 |
|
diagnostic_event_id diagnostic_event_id | diagnostic_execution_path_add_event_va (diagnostic_execution_path *path, const diagnostic_physical_location *physical_loc, const diagnostic_logical_location *logical_loc, unsigned stack_depth, const char *fmt, va_list *args) LIBGDIAGNOSTICS_PARAM_GCC_FORMAT_STRING(5 |
|
diagnostic_event_id diagnostic_event_id void | diagnostic_finish (diagnostic *diag, const char *fmt,...) LIBGDIAGNOSTICS_PARAM_GCC_FORMAT_STRING(2 |
|
diagnostic_event_id diagnostic_event_id void void | diagnostic_finish_va (diagnostic *diag, const char *fmt, va_list *args) LIBGDIAGNOSTICS_PARAM_GCC_FORMAT_STRING(2 |
|
#define LIBGDIAGNOSTICS_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) |
A pure C API for emitting diagnostics.
Copyright (C) 2023-2025 Free Software Foundation, Inc.
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 macro simplifies testing whether we are using gcc, and if it
is of a particular minimum version. (Both major & minor numbers are
significant.) This macro will evaluate to 0 if we are not using
gcc at all.
typedef struct diagnostic diagnostic |
A "diagnostic" is an opaque bundle of state for a particular
diagnostic that is being constructed in memory.
A diagnostic has a primary location and zero or more secondary
locations. For example:
| a = (foo && bar)
| ~~~~~^~~~~~~
This diagnostic has a single diagnostic_location, with the caret
at the first "&", and the start/finish at the parentheses.
Contrast with:
| a = (foo && bar)
| ~~~ ^~ ~~~
This diagnostic has three locations
- The primary location (at "&&") has its caret and start location at
the first "&" and end at the second "&.
- The secondary location for "foo" has its start and finish at the "f"
and "o" of "foo"; the caret is not flagged for display, but is perhaps at
the "f" of "foo".
- Similarly, the other secondary location (for "bar") has its start and
finish at the "b" and "r" of "bar"; the caret is not flagged for
display, but is perhaps at the"b" of "bar".
Types for storing line and column information in text files.
Both libgdiagnostics and emacs number source *lines* starting at 1, but
they have differing conventions for *columns*.
libgdiagnostics uses a 1-based convention for source columns,
whereas Emacs's M-x column-number-mode uses a 0-based convention.
For example, an error in the initial, left-hand
column of source line 3 is reported by libgdiagnostics as:
some-file.c:3:1: error: ...etc...
On navigating to the location of that error in Emacs
(e.g. via "next-error"),
the locus is reported in the Mode Line
(assuming M-x column-number-mode) as:
some-file.c 10% (3, 0)
i.e. "3:1:" in libgdiagnostics corresponds to "(3, 0)" in Emacs.
typedef struct diagnostic_physical_location diagnostic_physical_location |
Opaque type representing a key into a database of source locations within
a diagnostic_manager. Locations are created by various API calls into
the diagnostic_manager expressing source code points and ranges. They
persist until the diagnostic_manager is released, which cleans them
up.
NULL means "UNKNOWN", and can be returned by the manager as a
fallback when a problem occurs (e.g. too many locations).
A diagnostic_location can be a single point within the source code,
such as here (at the the '"' at the start of the string literal):
| int i = "foo";
| ^
or be a range with a start and finish, and a "caret" location.
| a = (foo && bar)
| ~~~~~^~~~~~~
where the caret here is at the first "&", and the start and finish
are at the parentheses.
Add a new output sink to DIAG_MGR, which writes SARIF of the given
version to DST_STREAM.
The output is not written until DIAG_MGR is released.
DST_STREAM is borrowed, and must outlive DIAG_MGR.
For the result to be a valid SARIF file according to the schema,
DIAG_MGR must have had diagnostic_manager_set_tool_name called on it.
Public entrypoint.
References abort, diagnostic_manager::add_sink(), DIAGNOSTIC_SARIF_VERSION_2_1_0, DIAGNOSTIC_SARIF_VERSION_2_2_PRERELEASE, FAIL_IF_NULL, make_unique(), v2_1_0, and v2_2_prerelease_2024_08_08.
Referenced by libgdiagnostics::manager::add_sarif_sink().
Destinations for diagnostics.
Add a new output sink to DIAG_MGR, which writes GCC-style diagnostics
to DST_STREAM.
Return a borrowed pointer to the sink, which is cleaned up when DIAG_MGR
is released.
DST_STREAM is borrowed, and must outlive DIAG_MGR.
The output for each diagnostic is written and flushed as each
diagnostic is finished.
Public entrypoint.
References diagnostic_manager::add_sink(), and FAIL_IF_NULL.
Referenced by libgdiagnostics::manager::add_text_sink().
Attempt to create a diagnostic_physical_location representing a
range within a source file, with a highlighted "caret" location.
All must be within the same file, but they can be on different lines.
For example, consider the location of the binary expression below:
...|__________1111111112222222
...|12345678901234567890123456
...|
521|int sum (int foo, int bar)
522|{
523| return foo + bar;
...| ~~~~^~~~~
524|}
The location's caret is at the "+", line 523 column 15, but starts
earlier, at the "f" of "foo" at column 11. The finish is at the "r"
of "bar" at column 19.
Public entrypoint.
References FAIL_IF_NULL, and diagnostic_manager::new_location_from_range().
Referenced by libgdiagnostics::manager::new_location_from_range().