https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121039

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <[email protected]>:

https://gcc.gnu.org/g:9e98b37f32f8bff72885904fc66ea7ec8fefec58

commit r16-3465-g9e98b37f32f8bff72885904fc66ea7ec8fefec58
Author: David Malcolm <[email protected]>
Date:   Fri Aug 29 14:39:37 2025 -0400

    diagnostics: add GCC_DIAGNOSTICS_LOG

    Whilst experimenting with PR diagnostics/121039 (potentially capturing
    suppressed diagnostics in SARIF output), I found it very useful to have
    a text log from the diagnostic subsystem to track what it's doing and
    the decisions it's making (e.g. exactly when and why a diagnostic is
    being rejected).

    This patch adds a simple logging mechanism to the diagnostics subsystem,
    enabled by setting GCC_DIAGNOSTICS_LOG in the environment, which emits
    nested text like this to stderr (or a named file):

    warning (option_id: 668, gmsgid: "%<-Wformat-security%> ignored without
%<-Wformat%>")
      diagnostics::context::diagnostic_impl (option_id: 668, kind: warning,
gmsgid: "%<-Wformat-security%> ignored without %<-Wformat%>")
        diagnostics::context::report_diagnostic
        rejecting: diagnostic not enabled
        false <- diagnostics::context::diagnostic_impl
      false <- warning

    This logging mechanism doesn't use pretty_printer because it can be
    helpful to use it to debug pretty_printer itself.

    gcc/ChangeLog:
            * Makefile.in (OBJS-libcommon): Add diagnostics/logging.o.
            * diagnostic-global-context.cc: Include "diagnostics/logging.h".
            (log_function_params, auto_inc_log_depth): New "using" decls.
            (verbatim): Add logging.
            (emit_diagnostic): Likewise.
            (emit_diagnostic_valist): Likewise.
            (emit_diagnostic_valist_meta): Likewise.
            (inform): Likewise.
            (inform_n): Likewise.
            (warning): Likewise.
            (warning_at): Likewise.
            (warning_meta): Likewise.
            (warning_n): Likewise.
            (pedwarn): Likewise.
            (permerror): Likewise.
            (permerror_opt): Likewise.
            * diagnostics/context.cc: Include "diagnostics/logging.h".
            (context::initialize): Initialize m_logger.  Add logging.
            (context::finish): Add logging.  Clean up m_logger.
            (context::dump): Add indent param.
            (context::set_sink): Add logging.
            (context::add_sink): Add logging.
            (diagnostic_kind_debug_text): New.
            (get_debug_string_for_kind): New.
            (context::report_diagnostic): Add logging.
            (context::diagnostic_impl): Likewise.
            (context::diagnostic_n_impl): Likewise.
            (context::end_group): Likewise.
            * diagnostics/context.h: Include "diagnostics/logging.h".
            (context::dump): Add indent param.
            (context::get_logger): New accessor.
            (context::classify_diagnostics): Add logging.
            (context::push_diagnostics): Likewise.
            (context::pop_diagnostics): Likewise.
            (context::m_logger): New field.
            * diagnostics/html-sink.cc: Include "diagnostics/logging.h".
            (html_builder::flush_to_file): Add logging.
            (html_sink::on_report_diagnostic): Likewise.
            * diagnostics/kinds.h (get_debug_string_for_kind): New decl.
            * diagnostics/logging.cc: New file.
            * diagnostics/logging.h: New file.
            * diagnostics/output-file.h: Include "label-text.h".
            * diagnostics/sarif-sink.cc: Include "diagnostics/logging.h".
            (sarif_builder::flush_to_object): Add logging.
            (sarif_builder::flush_to_file): Likewise.
            (sarif_sink::on_report_diagnostic): Likewise.
            * diagnostics/sink.h (sink::get_logger): New.
            * diagnostics/text-sink.cc: Include "diagnostics/logging.h".
            (text_sink::on_report_diagnostic): Add logging.
            * doc/invoke.texi (Environment Variables): Document
            GCC_DIAGNOSTICS_LOG.
            * opts-diagnostic.cc: Include "diagnostics/logging.h".
            (handle_OPT_fdiagnostics_add_output_): Add loggging.
            (handle_OPT_fdiagnostics_set_output_): Likewise.

    gcc/analyzer/ChangeLog:
            * pending-diagnostic.cc: Include "diagnostics/logging.h".
            (diagnostic_emission_context::warn): Add logging.
            (diagnostic_emission_context::inform): Likewise.

    Signed-off-by: David Malcolm <[email protected]>

Reply via email to