[lldb] [llvm] [lldb] Add a GitHub bug reporter (PR #206607)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 15:48:30 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Jonas Devlieghere (JDevlieghere)
<details>
<summary>Changes</summary>
Add a BugReporter plugin that files a diagnostics bundle as an llvm/llvm-project GitHub issue. File() renders a short Markdown body from the Diagnostics::Report (version, host, invocation, and a pointer to the bundle directory to attach), truncates it under a GET-safe URL length on a UTF-8 character boundary, and opens a pre-filled issues/new page with Host::OpenURL.
It is gated by LLDB_ENABLE_GITHUB_BUG_REPORTER (default on) and registers ahead of the no-op fallback, so it is the default destination for "diagnostics report" while a downstream tree can still register its own reporter ahead of it.
---
Full diff: https://github.com/llvm/llvm-project/pull/206607.diff
7 Files Affected:
- (modified) lldb/source/Commands/CommandObjectDiagnostics.cpp (+3-2)
- (modified) lldb/source/Plugins/BugReporter/CMakeLists.txt (+7)
- (added) lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.cpp (+66)
- (added) lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.h (+33)
- (added) lldb/source/Plugins/BugReporter/GitHub/CMakeLists.txt (+9)
- (modified) lldb/test/Shell/Diagnostics/TestReport.test (+1-1)
- (modified) llvm/docs/ReleaseNotes.md (+2)
``````````diff
diff --git a/lldb/source/Commands/CommandObjectDiagnostics.cpp b/lldb/source/Commands/CommandObjectDiagnostics.cpp
index c8e50ac7c0b2a..4b02f3b337224 100644
--- a/lldb/source/Commands/CommandObjectDiagnostics.cpp
+++ b/lldb/source/Commands/CommandObjectDiagnostics.cpp
@@ -194,8 +194,9 @@ class CommandObjectDiagnosticsReport : public CommandObjectParsed {
Stream &out = result.GetOutputStream();
out << "Bug report written to " << directory->GetPath() << "\n";
- out << "WARNING: the report may contain file paths, command history and "
- "program data. Review it before attaching it to a public issue.\n";
+ result.AppendWarning("the report may contain file paths, command history "
+ "and program data. Review it before attaching it to a "
+ "public issue");
if (m_options.no_open) {
result.SetStatus(eReturnStatusSuccessFinishResult);
diff --git a/lldb/source/Plugins/BugReporter/CMakeLists.txt b/lldb/source/Plugins/BugReporter/CMakeLists.txt
index 784d87338c625..2e3133a03621e 100644
--- a/lldb/source/Plugins/BugReporter/CMakeLists.txt
+++ b/lldb/source/Plugins/BugReporter/CMakeLists.txt
@@ -1,5 +1,12 @@
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND BugReporter)
+option(LLDB_ENABLE_GITHUB_BUG_REPORTER
+ "Build the GitHub bug reporter so 'diagnostics report' can file a GitHub issue."
+ ON)
+
# Reporters are tried in subdirectory order, so keep None (the fallback) last.
# Downstream adds its own reporter subdirectory ahead of these.
+if(LLDB_ENABLE_GITHUB_BUG_REPORTER)
+ add_subdirectory(GitHub)
+endif()
add_subdirectory(None)
diff --git a/lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.cpp b/lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.cpp
new file mode 100644
index 0000000000000..c0f7b188e6831
--- /dev/null
+++ b/lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Plugins/BugReporter/GitHub/BugReporterGitHub.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/Host.h"
+
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(BugReporterGitHub)
+
+// A GitHub "new issue" URL is fetched with GET, so its length is bounded (the
+// server rejects very long URLs). Keep the pre-filled body well under that so
+// the rest of the URL always fits. The full payload lives in the bundle.
+static constexpr size_t g_max_body_size = 6000;
+
+void BugReporterGitHub::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ "File a bug as a GitHub issue.",
+ &BugReporterGitHub::CreateInstance);
+}
+
+void BugReporterGitHub::Terminate() {
+ PluginManager::UnregisterPlugin(&BugReporterGitHub::CreateInstance);
+}
+
+std::unique_ptr<BugReporter> BugReporterGitHub::CreateInstance() {
+ return std::make_unique<BugReporterGitHub>();
+}
+
+llvm::Error BugReporterGitHub::File(const Diagnostics::Report &report) {
+ std::string body;
+ llvm::raw_string_ostream os(body);
+ os << "### LLDB version\n" << report.version << "\n\n";
+ os << "### Host\n" << report.os << "\n\n";
+ if (!report.invocation.empty())
+ os << "### Invocation\n`" << report.invocation << "`\n\n";
+ os << "### Diagnostics\n"
+ << "Full diagnostics were written to:\n`" << report.attachments.directory
+ << "`\nPlease attach the contents of that directory to this issue.\n";
+
+ if (body.size() > g_max_body_size) {
+ // Back up off any UTF-8 continuation bytes so truncation lands on a
+ // character boundary rather than splitting a multi-byte sequence.
+ size_t cut = g_max_body_size;
+ while (cut > 0 && (static_cast<unsigned char>(body[cut]) & 0xC0) == 0x80)
+ --cut;
+ body.resize(cut);
+ body += "\n\n...(truncated, see the attached diagnostics directory)";
+ }
+
+ std::string url = llvm::formatv("https://github.com/llvm/llvm-project/issues/"
+ "new?title={0}&body={1}&labels=lldb",
+ Host::URLEncode("[lldb] Bug report"),
+ Host::URLEncode(body));
+
+ return Host::OpenURL(url);
+}
diff --git a/lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.h b/lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.h
new file mode 100644
index 0000000000000..45bcdca59d7d7
--- /dev/null
+++ b/lldb/source/Plugins/BugReporter/GitHub/BugReporterGitHub.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_BUGREPORTER_GITHUB_BUGREPORTERGITHUB_H
+#define LLDB_SOURCE_PLUGINS_BUGREPORTER_GITHUB_BUGREPORTERGITHUB_H
+
+#include "lldb/Core/BugReporter.h"
+
+namespace lldb_private {
+
+/// Opens a pre-filled github.com/llvm/llvm-project "new issue" page. The body
+/// carries a short summary and points at the on-disk bundle to attach, since
+/// large artifacts cannot travel in the URL.
+class BugReporterGitHub : public BugReporter {
+public:
+ static void Initialize();
+ static void Terminate();
+ static llvm::StringRef GetPluginNameStatic() { return "github"; }
+ static std::unique_ptr<BugReporter> CreateInstance();
+
+ llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
+
+ llvm::Error File(const Diagnostics::Report &report) override;
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_SOURCE_PLUGINS_BUGREPORTER_GITHUB_BUGREPORTERGITHUB_H
diff --git a/lldb/source/Plugins/BugReporter/GitHub/CMakeLists.txt b/lldb/source/Plugins/BugReporter/GitHub/CMakeLists.txt
new file mode 100644
index 0000000000000..5c51252567888
--- /dev/null
+++ b/lldb/source/Plugins/BugReporter/GitHub/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_lldb_library(lldbPluginBugReporterGitHub PLUGIN
+ BugReporterGitHub.cpp
+
+ LINK_COMPONENTS
+ Support
+ LINK_LIBS
+ lldbCore
+ lldbHost
+ )
diff --git a/lldb/test/Shell/Diagnostics/TestReport.test b/lldb/test/Shell/Diagnostics/TestReport.test
index d9606e52a7755..5cfb86e76df68 100644
--- a/lldb/test/Shell/Diagnostics/TestReport.test
+++ b/lldb/test/Shell/Diagnostics/TestReport.test
@@ -4,7 +4,7 @@
# RUN: rm -rf %t.report
# RUN: %lldb --no-lldbinit -b -o 'diagnostics report --no-open -d %t.report' 2>&1 | FileCheck %s
# CHECK: Bug report written to
-# CHECK: WARNING: the report may contain
+# CHECK: warning: the report may contain
# Scalars (version, OS, invocation) ride in the report, not as redundant files.
# RUN: test -f %t.report/statistics.json
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index d1448eb469614..942d9ad6d0adf 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -386,6 +386,8 @@ Makes programs 10x faster by doing Special New Thing.
show `platform.plugin.qemu-user` as one of the results.
* Reading global and static variables on WebAssembly targets now works correctly. Previously their
values could not be read because data sections were mapped to the wrong address space.
+* A new `diagnostics report` command (aliased `bugreport`) assembles a diagnostics bundle and files
+ a pre-filled GitHub issue, pointing at the bundle to attach.
#### Deprecated APIs
``````````
</details>
https://github.com/llvm/llvm-project/pull/206607
More information about the llvm-commits
mailing list