Diagnostic Managers

type diagnostic_manager;

A diagnostic_manager is an opaque bundle of state for a client of libgdiagnostics.

It has zero of more “output sinks” to which diagnostics are emitted.

Responsibilities include:

  • location-management

  • caching of source file content

  • patch generation

diagnostic_manager *diagnostic_manager_new(void)

Create a new diagnostic_manager. The caller will need to call diagnostic_release_manager() on it at some point.

Note

No output sinks are created by default; so you will want to create one with something like:

diagnostic_manager_add_text_sink (diag_mgr, stderr,
                                  DIAGNOSTIC_COLORIZE_IF_TTY);
void diagnostic_manager_release(diagnostic_manager *diag_mgr)

Release a diagnostic_manager.

This will flush output to all of the output sinks, and clean up.

The parameter must be non-NULL.

int diagnostic_manager_add_sink_from_spec(diagnostic_manager *affected_mgr, const char *option_name, const char *spec, diagnostic_manager *control_mgr)

This function can be used to support option processing similar to GCC’s -fdiagnostics-add-output=. This allows command-line tools to support the same domain-specific language for specifying output sinks as GCC does.

The function will attempt to parse spec as if it were an argument to GCC’s -fdiagnostics-add-output=. If successful, it will add an output sink to affected_mgr and return zero. Otherwise, it will emit an error diagnostic to control_mgr and return non-zero.

affected_mgr and control_mgr can be the same manager, or be different managers.

This function was added in LIBGDIAGNOSTICS_ABI_2; you can test for its presence using

#ifdef LIBDIAGNOSTICS_HAVE_diagnostic_manager_add_sink_from_spec
void diagnostic_manager_set_analysis_target(diagnostic_manager *mgr, const diagnostic_file *file)

This function sets the “main input file” of mgr to be file. This affects the <title> of generated HTML and the role of the artifact in SARIF output (SARIF v2.1.0 section 3.24.6).

This function was added in LIBGDIAGNOSTICS_ABI_2; you can test for its presence using

#ifdef LIBDIAGNOSTICS_HAVE_diagnostic_manager_set_analysis_target