mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
This patch adds support to sarif-replay for "nestingLevel" from "P3358R0 SARIF for Structured Diagnostics" https://wg21.link/P3358R0 Doing so revealed a bug where libgdiagnostics was always creating new location_t values (and thus also diagnostic_physical_location instances), rather than reusing existing location_t values, leading to excess source printing. The patch also fixes this bug, adding a new flag to libgdiagnostics for debugging physical locations, and exposing this in sarif-replay via a new "-fdebug-physical-locations" maintainer option. Finally, the patch adds test coverage for the HTML sink's output of nested diagnostics (both from a GCC plugin, and from sarif-replay). gcc/ChangeLog: PR diagnostics/116253 * diagnostics/context.cc (context::set_nesting_level): New. * diagnostics/context.h (context::set_nesting_level): New decl. * doc/libgdiagnostics/topics/compatibility.rst (LIBGDIAGNOSTICS_ABI_5): New. * doc/libgdiagnostics/topics/physical-locations.rst (diagnostic_manager_set_debug_physical_locations): New. * libgdiagnostics++.h (manager::set_debug_physical_locations): New. * libgdiagnostics-private.h (private_diagnostic_set_nesting_level): New decl. * libgdiagnostics.cc (diagnostic_manager::diagnostic_manager): Initialize m_debug_physical_locations. (diagnostic_manager::new_location_from_file_and_line): Add debug printing. (diagnostic_manager::new_location_from_file_line_column): Likewise. (diagnostic_manager::new_location_from_range): Likewise. (diagnostic_manager::set_debug_physical_locations): New. (diagnostic_manager::ensure_linemap_for_file_and_line): Avoid redundant calls to linemap_add. (diagnostic_manager::new_location): Add debug printing. (diagnostic_manager::m_debug_physical_locations): New field. (diagnostic::diagnostic): Initialize m_nesting_level. (diagnostic::get_nesting_level): New accessor. (diagnostic::set_nesting_level): New. (diagnostic::m_nesting_level): New field. (diagnostic_manager::emit_va): Set and reset the nesting level of the context from that of the diagnostic. (diagnostic_manager_set_debug_physical_locations): New. (private_diagnostic_set_nesting_level): New. * libgdiagnostics.h (diagnostic_manager_set_debug_physical_locations): New decl. * libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_5): New. * libsarifreplay.cc (sarif_replayer::handle_result_obj): Support the "nestingLevel" property. * libsarifreplay.h (replay_options::m_debug_physical_locations): New field. * sarif-replay.cc: Add -fdebug-physical-locations. gcc/testsuite/ChangeLog: PR diagnostics/116253 * gcc.dg/plugin/diagnostic-test-nesting-html.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-html.py: New test script. * gcc.dg/plugin/plugin.exp: Add it. * libgdiagnostics.dg/test-multiple-lines.c: Update expected output to show fix-it hint. * sarif-replay.dg/2.1.0-valid/nested-diagnostics-1.sarif: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
152 lines
5.1 KiB
Plaintext
152 lines
5.1 KiB
Plaintext
# Linker script for libgdiagnostics.so
|
|
# Copyright (C) 2023-2025 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/>. */
|
|
|
|
# The initial release of the library.
|
|
LIBGDIAGNOSTICS_ABI_0
|
|
{
|
|
global:
|
|
# Keep this list in order of decls in header file.
|
|
diagnostic_manager_new;
|
|
diagnostic_manager_release;
|
|
diagnostic_manager_set_tool_name;
|
|
diagnostic_manager_set_full_name;
|
|
diagnostic_manager_set_version_string;
|
|
diagnostic_manager_set_version_url;
|
|
diagnostic_manager_add_text_sink;
|
|
diagnostic_text_sink_set_source_printing_enabled;
|
|
diagnostic_text_sink_set_colorize;
|
|
diagnostic_text_sink_set_labelled_source_colorization_enabled;
|
|
diagnostic_manager_add_sarif_sink;
|
|
diagnostic_manager_write_patch;
|
|
diagnostic_manager_new_file;
|
|
diagnostic_file_set_buffered_content;
|
|
diagnostic_manager_debug_dump_file;
|
|
diagnostic_manager_new_location_from_file_and_line;
|
|
diagnostic_manager_new_location_from_file_line_column;
|
|
diagnostic_manager_new_location_from_range;
|
|
diagnostic_manager_debug_dump_location;
|
|
diagnostic_manager_new_logical_location;
|
|
diagnostic_manager_debug_dump_logical_location;
|
|
diagnostic_manager_begin_group;
|
|
diagnostic_manager_end_group;
|
|
diagnostic_begin;
|
|
diagnostic_set_cwe;
|
|
diagnostic_add_rule;
|
|
diagnostic_set_location;
|
|
diagnostic_set_location_with_label;
|
|
diagnostic_add_location;
|
|
diagnostic_add_location_with_label;
|
|
diagnostic_set_logical_location;
|
|
diagnostic_add_fix_it_hint_insert_before;
|
|
diagnostic_add_fix_it_hint_insert_after;
|
|
diagnostic_add_fix_it_hint_replace;
|
|
diagnostic_add_fix_it_hint_delete;
|
|
|
|
diagnostic_add_execution_path;
|
|
diagnostic_manager_new_execution_path;
|
|
diagnostic_take_execution_path;
|
|
diagnostic_execution_path_release;
|
|
diagnostic_execution_path_add_event;
|
|
diagnostic_execution_path_add_event_va;
|
|
|
|
diagnostic_finish;
|
|
diagnostic_finish_va;
|
|
|
|
|
|
diagnostic_physical_location_get_file;
|
|
|
|
local: *;
|
|
};
|
|
|
|
# Add accessors for diagnostic_logical_location.
|
|
LIBGDIAGNOSTICS_ABI_1 {
|
|
global:
|
|
diagnostic_logical_location_get_kind;
|
|
diagnostic_logical_location_get_parent;
|
|
diagnostic_logical_location_get_short_name;
|
|
diagnostic_logical_location_get_fully_qualified_name;
|
|
diagnostic_logical_location_get_decorated_name;
|
|
} LIBGDIAGNOSTICS_ABI_0;
|
|
|
|
# Add hooks needed for HTML output from sarif-replay
|
|
LIBGDIAGNOSTICS_ABI_2 {
|
|
global:
|
|
diagnostic_manager_add_sink_from_spec;
|
|
diagnostic_manager_set_analysis_target;
|
|
} LIBGDIAGNOSTICS_ABI_1;
|
|
|
|
# Add hooks needed for diagnostic_graph support.
|
|
LIBGDIAGNOSTICS_ABI_3 {
|
|
global:
|
|
diagnostic_manager_new_graph;
|
|
diagnostic_manager_take_global_graph;
|
|
diagnostic_take_graph;
|
|
diagnostic_graph_release;
|
|
diagnostic_graph_set_description;
|
|
diagnostic_graph_add_node;
|
|
diagnostic_graph_add_edge;
|
|
diagnostic_graph_get_node_by_id;
|
|
diagnostic_graph_get_edge_by_id;
|
|
diagnostic_node_set_label;
|
|
diagnostic_node_set_location;
|
|
diagnostic_node_set_logical_location;
|
|
|
|
# Private hooks used by sarif-replay
|
|
private_diagnostic_graph_set_property_bag;
|
|
private_diagnostic_node_set_property_bag;
|
|
private_diagnostic_edge_set_property_bag;
|
|
} LIBGDIAGNOSTICS_ABI_2;
|
|
|
|
# Add diagnostic_message_buffer
|
|
LIBGDIAGNOSTICS_ABI_4 {
|
|
global:
|
|
diagnostic_message_buffer_new;
|
|
diagnostic_message_buffer_release;
|
|
diagnostic_message_buffer_append_str;
|
|
diagnostic_message_buffer_append_text;
|
|
diagnostic_message_buffer_append_byte;
|
|
diagnostic_message_buffer_append_printf;
|
|
diagnostic_message_buffer_append_event_id;
|
|
diagnostic_message_buffer_begin_url;
|
|
diagnostic_message_buffer_end_url;
|
|
diagnostic_message_buffer_begin_quote;
|
|
diagnostic_message_buffer_end_quote;
|
|
diagnostic_message_buffer_begin_color;
|
|
diagnostic_message_buffer_end_color;
|
|
diagnostic_message_buffer_dump;
|
|
diagnostic_finish_via_msg_buf;
|
|
diagnostic_add_location_with_label_via_msg_buf;
|
|
diagnostic_execution_path_add_event_via_msg_buf;
|
|
diagnostic_graph_set_description_via_msg_buf;
|
|
diagnostic_graph_add_edge_via_msg_buf;
|
|
diagnostic_node_set_label_via_msg_buf;
|
|
|
|
# Private hook used by sarif-replay
|
|
private_diagnostic_execution_path_add_event_3;
|
|
} LIBGDIAGNOSTICS_ABI_3;
|
|
|
|
LIBGDIAGNOSTICS_ABI_5 {
|
|
global:
|
|
diagnostic_manager_set_debug_physical_locations;
|
|
|
|
# Private hook used by sarif-replay
|
|
private_diagnostic_set_nesting_level;
|
|
} LIBGDIAGNOSTICS_ABI_4;
|