libgdiagnostics
Published 2 months ago• 3 minute read
libgdiagnostics is GCC's diagnostic-handling code wrapped up as a shared library, with a opaque pure C API that other tools can use, covering things like:
A sarif-replay command-line tool is also provided, which takes SARIF files as input, and uses libgdiagnostics to "replay" any diagnostics within them as if they were GCC diagnostics.
Experimental implementation added in GCC 15
Header: libgdiagnostics.h
API documentation: https://gcc.gnu.org/onlinedocs/libgdiagnostics/
┏━━━━━━━━━━━━━━━━━━ GCC ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┣━━━━━━━ Other projects ━━━━━━━┫ ┃┌───┐ ┌───┐ ┌──────────────────────────┐ ┃ ┏...┓ ┏...┓ ┏━ binutils ━┓ ┃│gcc│ ┌┴──┐│ │ sarif-replay │ ┃ ┃ ┃ ┃ ┃ ┃ ┌──┐ ┌──┐ ┃ ┃└─o─┘┌┴──┐├┘ ├──────────────────────────┤ ┃ ┗━┆━┛ ┗━┆━┛ ┃ │as│ │ld│ ┃ ┃ ┆ │cc1├┘ │A tool for dumping .sarif │ ┃ ┆ ┆ ┃ └─o┘ └─o┘ ┃ ┃ ┆ └─o─┘ ┌─────────────────────┐│files as if they were GCC │ ┃ ┆ ┆ ┃ ┆(in C)┆ ┃ ┃ ┆ ┆etc │ dg-lint ││diagnostics (C++, GPLv3) │ ┃ ┆ ┆ ┗━━━┆━━━━━━┆━━┛ ┃ ┆ ┆ ├─────────────────────┤└────────────o─────────────┘ ┃ ┆ ┆ ┆ ┆ ┃ ┆ ┆ │ (internal tool) │ ┆ ┃ ┆ ┆ ┆ ┆ ┃ ┆ ┆ └────────────o────────┘ ┆ ┗━━━━━┆━━━━━┓ ┆ ┆ ┆ ┃ ┆ ┆ ┆ ┆ ┆ ┃ ┆ ┆ ┆ ┃ ┆ ┆ ┌──────────────o────────────────┐ ┌──o─────────────────────o──┐ ┃ ┆ ┆ ┆ ┃ ┆ ┆ │ libgdiagnostics.py (GPLv3) │ │ libgdiagnostics+.h (GPLv3)│ ┃ ┆ ┆ ┆ ┃ ┆ ┆ ├───────────────────────────────┤ ├───────────────────────────┤ ┃ ┆ ┆ ┆ ┃ ┆ ┆ │Python 3 bindings, using ctypes│ │A header-only C++ wrapper │ ┃ ┆ ┆ ┆ ┃ ┆ ┆ └──────────────o────────────────┘ │API giving syntactic sugar │ ┃ ┆ ┆ ┆ ┃ ┆ ┆ ┆ │on top of the C API │ ┃ ┆ ┆ ┆ ┃ ┆ ┆ ┆ └────────────o──────────────┘ ┃ ┆ ┆ ┆ ┃ ┆ ┆ ┆ ┆ ┗━━┆━━━━━━━━━┆━━━━━━┆━━━┓ ┃ ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┃ ┃ ┆ ┆ ┌──────────────o────────────────────────────────o────────────────────o─────────o──────o─┐ ┃ ┃ ┆ ┆ │ libgdiagnostics.h/.so (GPLv3) │ ┃ ┃┌─o────o──┐├───────────────────────────────────────────────────────────────────────────────────────┤ ┃ ┃│global_dc││ An opaque C API (with stable ABI) for emitting diagnostics, │ ┃ ┃└─o────o──┘│ with source quoting, fix-it hints, SARIF output, execution │ ┃ ┃ ┆ ┆ │ paths, etc (internals implemented using GCC's subset of C++11) │ ┃ ┃ ┆ ┆ └─────────────────────o────────────────────────────────────o────────────────────────────┘ ┃ ┃ ┆ ┆ ┆ ┆ ┃ ┃┌─o────o─────────────────────────o────────────────────────────────────o─────┐ ┃ ┃│ GCC's diagnostics subsystem (implemented in GCC's subset of C++11) │ ┃ ┃└───────────────────────────────────────────────────────────────────────────┘ ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
History
2024-06-18: Refactoring to help libdiagnostics: removed "tree" dependency from diagnostic paths
2023-11-21: v2 of prototype
2023-11-15: C++ example of dumping a SARIF file
2023-11-06: Initial prototype posted to mailing list
Loading...
You may also like...
Loading...