]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostics: capture backtraces in SARIF notifications [PR116602]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 16 Oct 2024 17:10:11 +0000 (13:10 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 16 Oct 2024 17:10:11 +0000 (13:10 -0400)
commit69b2d523b1069651053cd39dc9b4810a2c7f964a
treefe2182cabe79785d0f9ebaecae5c46bd1ef3a1c2
parentd826b6389d9605944ce2261c07d2c9515992bccf
diagnostics: capture backtraces in SARIF notifications [PR116602]

This patch makes the SARIF output's crash handler attempt to capture
a backtrace in JSON form within the notification's property bag.  The
precise format of the property is subject to change, but, for example,
in one of the test cases I got output like this:

"properties": {"gcc/backtrace": {"frames": [{"pc": "0x7f39c610a32d",
                                             "function": "pass_crash_test::execute(function*)",
                                             "filename": "/home/david/gcc-newgit/src/gcc/testsuite/gcc.dg/plugin/crash_test_plugin.c",
                                             "lineno": 98}]}}}],

The backtrace code is based on that in diagnostic.cc.

gcc/ChangeLog:
PR other/116602
* diagnostic-format-sarif.cc: Include "demangle.h" and
"backtrace.h".
(sarif_invocation::add_notification_for_ice): Add "backtrace"
param and pass it to ctor.
(sarif_ice_notification::sarif_ice_notification): Add "backtrace"
param and add it to property bag.
(bt_stop): New, taken from diagnostic.cc.
(struct bt_closure): New.
(bt_callback): New, adapted from diagnostic.cc.
(sarif_builder::make_stack_from_backtrace): New.
(sarif_builder::on_report_diagnostic): Attempt to get backtrace
and pass it to add_notification_for_ice.

gcc/testsuite/ChangeLog:
PR other/116602
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_1.py: Add check
for backtrace.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_2.py: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostic-format-sarif.cc
gcc/testsuite/gcc.dg/plugin/crash-test-ice-in-header-sarif-2_1.py
gcc/testsuite/gcc.dg/plugin/crash-test-ice-in-header-sarif-2_2.py