LLDB mainline
GitHubReporter.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "lldb/Host/Host.h"
12
13#include "llvm/Support/FormatVariadic.h"
14#include "llvm/Support/raw_ostream.h"
15
16using namespace lldb_private;
17
19
20// A GitHub "new issue" URL is fetched with GET, so its length is bounded (the
21// server rejects very long URLs). Keep the pre-filled body well under that so
22// the rest of the URL always fits. The full payload lives in the bundle.
23static constexpr size_t g_max_body_size = 6000;
24
30
34
35std::unique_ptr<BugReporter> GitHubReporter::CreateInstance() {
36 return std::make_unique<GitHubReporter>();
37}
38
39llvm::Error GitHubReporter::File(const Diagnostics::Report &report) {
40 std::string body;
41 llvm::raw_string_ostream os(body);
42 os << "### LLDB version\n" << report.version << "\n\n";
43 os << "### Host\n" << report.os << "\n\n";
44 if (!report.invocation.empty())
45 os << "### Invocation\n`" << report.invocation << "`\n\n";
46 os << "### Diagnostics\n"
47 << "Full diagnostics were written to:\n`" << report.attachments.directory
48 << "`\nPlease attach the contents of that directory to this issue.\n";
49
50 if (body.size() > g_max_body_size) {
51 // Back up off any UTF-8 continuation bytes so truncation lands on a
52 // character boundary rather than splitting a multi-byte sequence.
53 size_t cut = g_max_body_size;
54 while (cut > 0 && (static_cast<unsigned char>(body[cut]) & 0xC0) == 0x80)
55 --cut;
56 body.resize(cut);
57 body += "\n\n...(truncated, see the attached diagnostics directory)";
58 }
59
60 std::string url = llvm::formatv("https://github.com/llvm/llvm-project/issues/"
61 "new?title={0}&body={1}&labels=lldb",
62 Host::URLEncode("[lldb] Bug report"),
63 Host::URLEncode(body));
64
65 return Host::OpenURL(url);
66}
static constexpr size_t g_max_body_size
#define LLDB_PLUGIN_DEFINE(PluginName)
Opens a pre-filled github.com/llvm/llvm-project "new issue" page.
static llvm::StringRef GetPluginNameStatic()
llvm::Error File(const Diagnostics::Report &report) override
static std::unique_ptr< BugReporter > CreateInstance()
static llvm::Error OpenURL(llvm::StringRef url)
Open a URL with the host's default handler (Launch Services on macOS, xdg-open on other Unix).
static std::string URLEncode(llvm::StringRef str)
Percent-encode a string for use in a URL query component, per RFC 3986 (alphanumerics and "-_....
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A class that represents a running process on the host machine.
The state a triager needs to make sense of a bug report.
Definition Diagnostics.h:50