From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 426E5385841B for ; Mon, 6 Nov 2023 22:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 426E5385841B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 426E5385841B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699309815; cv=none; b=FUzPx4JqtTtJGi8VXk1QqVnJKKp9kuK1MtMBkXz13wwbxTZnKuKPW0UjBVHvF4QVeKtWlKxq1DjcsImnUy6oVrr/xQeumHhUrtruollssHqO8I/cE9yotzC7scC1vOEaqdPvE1T8R3D8hhrhHkobrMl5fyqLd0PlJMmsslTm9d8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699309815; c=relaxed/simple; bh=Z3xzbYYt7H/kypfdzpDYWmTPlZdNi2p9c0C5w/uVWiM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LTOnTwo+dM0PpR3p/JGLFN2zHAydU/sj84P0c9cK3nxZWtI2B0ZJB6X6Bk7vDmthjhtriNFT9PUxIJbZNjQHiZCOaQMwRVQMwkYrmqqXCtellhmPxvou9zkv4UkSHK8iot8RI+jfxRdaYj+6+Kl4d9HBsp6iJdOXmVi5rOiMPCU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699309813; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tmWpelBw2VcJ65n7aYIcQWkJvCJc4r1YEnRm4aZAjdE=; b=MG0HVryA3c9rtAfZkKWWBBaDLbHmX0ZcjFO6fqpOSGd4w1wLI/+6RRRtCbF7hOqULDlTCs sAth8ShCQfTzKNZomjMvqZWcgqOuN00kPEAdTS6h+cRZc34+GGedsh128uqmtQDEFq1qQY mHtYP+mUz2RM22hAL6xU8d2l9C2NFTI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175-grUJgPGvNyGRrUmgTcOCog-1; Mon, 06 Nov 2023 17:30:12 -0500 X-MC-Unique: grUJgPGvNyGRrUmgTcOCog-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9DE3853063; Mon, 6 Nov 2023 22:30:11 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.8.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 631AC40C6EB9; Mon, 6 Nov 2023 22:30:11 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, binutils@sourceware.org Cc: Nick Clifton , Simon Sobisch , David Malcolm Subject: [PATCH/RFC] libdiagnostics: a shared library for emitting diagnostics Date: Mon, 6 Nov 2023 17:29:56 -0500 Message-Id: <20231106222959.2707741-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: It's fairly easy for tools to implement simple diagnostics via fprintf of FILE:LINE:COLUMN: error: message to stderr, but as diagnostics get more featureful, using a shared library makes sense. This patch kit extends GCC to add a new "libdiagnostics" shared library on the host, built around GCC's existing diagnostic-handling code, exposed via a pure C API intended for client code that wants to emit GCC-style diagnostics. It implements: - quoting pertinent source code (with a cache) - underlining points and ranges in the source code, possibly with labels - emitting fix-it hints - generating patches from fix-it hints - SARIF output The first patch (for GCC) shows libdiagnostic.h (the public header file), along with examples of simple self-contained programs that show various uses of the API. The second patch (for GCC) is the work-in-progress implementation. The third patch (for binutils) is an experiment at using the API with gas. Status: this is a rough prototype. I'm posting it now to get feedback, both from GCC developers, and from projects that might make use of this library (binutils? GNU Cobol? others?). The header file has a "TODO" list at the end listing various known unfinished aspects, and "known unknowns". Thoughts? David Malcolm (2): libdiagnostics: header and examples libdiagnostics: work-in-progress implementation gcc/Makefile.in | 134 +- gcc/configure | 2 +- gcc/configure.ac | 2 +- gcc/input.h | 2 +- gcc/libdiagnostics.cc | 1124 +++++++++++++++++ gcc/libdiagnostics.h | 544 ++++++++ gcc/libdiagnostics.map | 57 + .../libdiagnostics.dg/libdiagnostics.exp | 544 ++++++++ .../libdiagnostics.dg/test-error-with-note.c | 57 + gcc/testsuite/libdiagnostics.dg/test-error.c | 49 + .../libdiagnostics.dg/test-fix-it-hint.c | 48 + .../libdiagnostics.dg/test-helpers.h | 29 + .../libdiagnostics.dg/test-labelled-ranges.c | 52 + .../libdiagnostics.dg/test-logical-location.c | 62 + .../libdiagnostics.dg/test-metadata.c | 53 + .../libdiagnostics.dg/test-multiple-lines.c | 58 + .../test-note-with-fix-it-hint.c | 51 + .../libdiagnostics.dg/test-warning.c | 52 + .../test-write-sarif-to-file.c | 46 + .../test-write-text-to-file.c | 47 + 20 files changed, 3008 insertions(+), 5 deletions(-) create mode 100644 gcc/libdiagnostics.cc create mode 100644 gcc/libdiagnostics.h create mode 100644 gcc/libdiagnostics.map create mode 100644 gcc/testsuite/libdiagnostics.dg/libdiagnostics.exp create mode 100644 gcc/testsuite/libdiagnostics.dg/test-error-with-note.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-error.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-fix-it-hint.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-helpers.h create mode 100644 gcc/testsuite/libdiagnostics.dg/test-labelled-ranges.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-logical-location.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-metadata.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-multiple-lines.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-note-with-fix-it-hint.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-warning.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-write-sarif-to-file.c create mode 100644 gcc/testsuite/libdiagnostics.dg/test-write-text-to-file.c -- 2.26.3