[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- CommandObjectReproducer.cpp ---------------------------------------===//
|
2018-11-14 03:18:16 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2018-11-14 03:18:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CommandObjectReproducer.h"
|
|
|
|
|
2020-03-13 23:49:15 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2019-09-14 07:27:31 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2018-11-15 09:05:40 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2018-11-14 03:18:16 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2020-03-13 23:49:15 +08:00
|
|
|
#include "lldb/Utility/GDBRemote.h"
|
|
|
|
#include "lldb/Utility/ProcessInfo.h"
|
|
|
|
#include "lldb/Utility/Reproducer.h"
|
2018-11-14 03:18:16 +08:00
|
|
|
|
2019-11-20 09:28:46 +08:00
|
|
|
#include <csignal>
|
|
|
|
|
2018-11-14 03:18:16 +08:00
|
|
|
using namespace lldb;
|
2019-09-14 07:27:31 +08:00
|
|
|
using namespace llvm;
|
2018-11-14 03:18:16 +08:00
|
|
|
using namespace lldb_private;
|
2019-09-14 07:27:31 +08:00
|
|
|
using namespace lldb_private::repro;
|
|
|
|
|
|
|
|
enum ReproducerProvider {
|
|
|
|
eReproducerProviderCommands,
|
|
|
|
eReproducerProviderFiles,
|
|
|
|
eReproducerProviderGDB,
|
2020-03-13 23:49:15 +08:00
|
|
|
eReproducerProviderProcessInfo,
|
2019-09-14 07:27:31 +08:00
|
|
|
eReproducerProviderVersion,
|
2019-10-17 08:02:00 +08:00
|
|
|
eReproducerProviderWorkingDirectory,
|
2019-09-14 07:27:31 +08:00
|
|
|
eReproducerProviderNone
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr OptionEnumValueElement g_reproducer_provider_type[] = {
|
|
|
|
{
|
|
|
|
eReproducerProviderCommands,
|
|
|
|
"commands",
|
|
|
|
"Command Interpreter Commands",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eReproducerProviderFiles,
|
|
|
|
"files",
|
|
|
|
"Files",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eReproducerProviderGDB,
|
|
|
|
"gdb",
|
|
|
|
"GDB Remote Packets",
|
|
|
|
},
|
2020-03-13 23:49:15 +08:00
|
|
|
{
|
|
|
|
eReproducerProviderProcessInfo,
|
|
|
|
"processes",
|
|
|
|
"Process Info",
|
|
|
|
},
|
2019-09-14 07:27:31 +08:00
|
|
|
{
|
|
|
|
eReproducerProviderVersion,
|
|
|
|
"version",
|
|
|
|
"Version",
|
|
|
|
},
|
2019-10-17 08:02:00 +08:00
|
|
|
{
|
|
|
|
eReproducerProviderWorkingDirectory,
|
|
|
|
"cwd",
|
|
|
|
"Working Directory",
|
|
|
|
},
|
2019-09-14 07:27:31 +08:00
|
|
|
{
|
|
|
|
eReproducerProviderNone,
|
|
|
|
"none",
|
|
|
|
"None",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr OptionEnumValues ReproducerProviderType() {
|
|
|
|
return OptionEnumValues(g_reproducer_provider_type);
|
|
|
|
}
|
|
|
|
|
2019-11-20 08:18:19 +08:00
|
|
|
#define LLDB_OPTIONS_reproducer_dump
|
2019-09-14 07:27:31 +08:00
|
|
|
#include "CommandOptions.inc"
|
2018-11-14 03:18:16 +08:00
|
|
|
|
2019-11-20 09:28:46 +08:00
|
|
|
enum ReproducerCrashSignal {
|
|
|
|
eReproducerCrashSigill,
|
|
|
|
eReproducerCrashSigsegv,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr OptionEnumValueElement g_reproducer_signaltype[] = {
|
|
|
|
{
|
|
|
|
eReproducerCrashSigill,
|
|
|
|
"SIGILL",
|
|
|
|
"Illegal instruction",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eReproducerCrashSigsegv,
|
|
|
|
"SIGSEGV",
|
|
|
|
"Segmentation fault",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr OptionEnumValues ReproducerSignalType() {
|
|
|
|
return OptionEnumValues(g_reproducer_signaltype);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LLDB_OPTIONS_reproducer_xcrash
|
|
|
|
#include "CommandOptions.inc"
|
|
|
|
|
2020-03-13 23:49:15 +08:00
|
|
|
template <typename T>
|
|
|
|
llvm::Expected<T> static ReadFromYAML(StringRef filename) {
|
|
|
|
auto error_or_file = MemoryBuffer::getFile(filename);
|
|
|
|
if (auto err = error_or_file.getError()) {
|
|
|
|
return errorCodeToError(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
T t;
|
|
|
|
yaml::Input yin((*error_or_file)->getBuffer());
|
|
|
|
yin >> t;
|
|
|
|
|
|
|
|
if (auto err = yin.error()) {
|
|
|
|
return errorCodeToError(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2018-11-14 03:18:16 +08:00
|
|
|
class CommandObjectReproducerGenerate : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
CommandObjectReproducerGenerate(CommandInterpreter &interpreter)
|
2019-05-03 08:10:31 +08:00
|
|
|
: CommandObjectParsed(
|
|
|
|
interpreter, "reproducer generate",
|
|
|
|
"Generate reproducer on disk. When the debugger is in capture "
|
|
|
|
"mode, this command will output the reproducer to a directory on "
|
2019-11-12 06:16:52 +08:00
|
|
|
"disk and quit. In replay mode this command in a no-op.",
|
2019-05-03 08:10:31 +08:00
|
|
|
nullptr) {}
|
2018-11-14 03:18:16 +08:00
|
|
|
|
|
|
|
~CommandObjectReproducerGenerate() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
|
|
|
if (!command.empty()) {
|
|
|
|
result.AppendErrorWithFormat("'%s' takes no arguments",
|
|
|
|
m_cmd_name.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-14 07:27:31 +08:00
|
|
|
auto &r = Reproducer::Instance();
|
2018-11-14 03:18:16 +08:00
|
|
|
if (auto generator = r.GetGenerator()) {
|
|
|
|
generator->Keep();
|
2019-10-10 05:47:49 +08:00
|
|
|
} else if (r.IsReplaying()) {
|
2019-11-22 05:34:01 +08:00
|
|
|
// Make this operation a NO-OP in replay mode.
|
2019-02-28 01:47:06 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
return result.Succeeded();
|
2018-11-14 03:18:16 +08:00
|
|
|
} else {
|
|
|
|
result.AppendErrorWithFormat("Unable to get the reproducer generator");
|
2019-02-28 01:47:06 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2018-11-14 03:18:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.GetOutputStream()
|
|
|
|
<< "Reproducer written to '" << r.GetReproducerPath() << "'\n";
|
2019-04-03 02:23:16 +08:00
|
|
|
result.GetOutputStream()
|
|
|
|
<< "Please have a look at the directory to assess if you're willing to "
|
|
|
|
"share the contained information.\n";
|
2018-11-14 03:18:16 +08:00
|
|
|
|
2019-11-12 06:16:52 +08:00
|
|
|
m_interpreter.BroadcastEvent(
|
|
|
|
CommandInterpreter::eBroadcastBitQuitCommandReceived);
|
|
|
|
result.SetStatus(eReturnStatusQuit);
|
2018-11-14 03:18:16 +08:00
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-20 09:28:46 +08:00
|
|
|
class CommandObjectReproducerXCrash : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
CommandObjectReproducerXCrash(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "reproducer xcrash",
|
|
|
|
"Intentionally force the debugger to crash in "
|
|
|
|
"order to trigger and test reproducer generation.",
|
|
|
|
nullptr) {}
|
|
|
|
|
|
|
|
~CommandObjectReproducerXCrash() override = default;
|
|
|
|
|
|
|
|
Options *GetOptions() override { return &m_options; }
|
|
|
|
|
|
|
|
class CommandOptions : public Options {
|
|
|
|
public:
|
|
|
|
CommandOptions() : Options() {}
|
|
|
|
|
|
|
|
~CommandOptions() override = default;
|
|
|
|
|
|
|
|
Status SetOptionValue(uint32_t option_idx, StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
case 's':
|
|
|
|
signal = (ReproducerCrashSignal)OptionArgParser::ToOptionEnum(
|
|
|
|
option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
|
|
|
|
if (!error.Success())
|
|
|
|
error.SetErrorStringWithFormat("unrecognized value for signal '%s'",
|
|
|
|
option_arg.str().c_str());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unimplemented option");
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
signal = eReproducerCrashSigsegv;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayRef<OptionDefinition> GetDefinitions() override {
|
|
|
|
return makeArrayRef(g_reproducer_xcrash_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReproducerCrashSignal signal = eReproducerCrashSigsegv;
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
|
|
|
if (!command.empty()) {
|
|
|
|
result.AppendErrorWithFormat("'%s' takes no arguments",
|
|
|
|
m_cmd_name.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &r = Reproducer::Instance();
|
2019-11-22 05:34:01 +08:00
|
|
|
|
|
|
|
if (!r.IsCapturing() && !r.IsReplaying()) {
|
2019-11-20 09:28:46 +08:00
|
|
|
result.SetError(
|
|
|
|
"forcing a crash is only supported when capturing a reproducer.");
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_options.signal) {
|
|
|
|
case eReproducerCrashSigill:
|
|
|
|
std::raise(SIGILL);
|
|
|
|
break;
|
|
|
|
case eReproducerCrashSigsegv:
|
|
|
|
std::raise(SIGSEGV);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusQuit);
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CommandOptions m_options;
|
|
|
|
};
|
|
|
|
|
2018-12-04 01:28:29 +08:00
|
|
|
class CommandObjectReproducerStatus : public CommandObjectParsed {
|
2018-11-14 03:18:16 +08:00
|
|
|
public:
|
2018-12-04 01:28:29 +08:00
|
|
|
CommandObjectReproducerStatus(CommandInterpreter &interpreter)
|
2019-05-03 08:10:31 +08:00
|
|
|
: CommandObjectParsed(
|
|
|
|
interpreter, "reproducer status",
|
2019-11-20 09:28:46 +08:00
|
|
|
"Show the current reproducer status. In capture mode the "
|
|
|
|
"debugger "
|
2019-05-03 08:10:31 +08:00
|
|
|
"is collecting all the information it needs to create a "
|
|
|
|
"reproducer. In replay mode the reproducer is replaying a "
|
|
|
|
"reproducer. When the reproducers are off, no data is collected "
|
|
|
|
"and no reproducer can be generated.",
|
|
|
|
nullptr) {}
|
2018-11-14 03:18:16 +08:00
|
|
|
|
2018-12-04 01:28:29 +08:00
|
|
|
~CommandObjectReproducerStatus() override = default;
|
2018-11-14 03:18:16 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2018-12-04 01:28:29 +08:00
|
|
|
if (!command.empty()) {
|
|
|
|
result.AppendErrorWithFormat("'%s' takes no arguments",
|
|
|
|
m_cmd_name.c_str());
|
2018-11-14 03:18:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-14 07:27:31 +08:00
|
|
|
auto &r = Reproducer::Instance();
|
2019-10-10 05:47:49 +08:00
|
|
|
if (r.IsCapturing()) {
|
2018-12-04 01:28:29 +08:00
|
|
|
result.GetOutputStream() << "Reproducer is in capture mode.\n";
|
2019-10-10 05:47:49 +08:00
|
|
|
} else if (r.IsReplaying()) {
|
2018-12-04 01:28:29 +08:00
|
|
|
result.GetOutputStream() << "Reproducer is in replay mode.\n";
|
|
|
|
} else {
|
|
|
|
result.GetOutputStream() << "Reproducer is off.\n";
|
2018-11-14 03:18:16 +08:00
|
|
|
}
|
|
|
|
|
2020-01-16 12:22:20 +08:00
|
|
|
if (r.IsCapturing() || r.IsReplaying()) {
|
|
|
|
result.GetOutputStream()
|
|
|
|
<< "Path: " << r.GetReproducerPath().GetPath() << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto generate is hidden unless enabled because this is mostly for
|
|
|
|
// development and testing.
|
|
|
|
if (Generator *g = r.GetGenerator()) {
|
|
|
|
if (g->IsAutoGenerate())
|
|
|
|
result.GetOutputStream() << "Auto generate: on\n";
|
|
|
|
}
|
|
|
|
|
2018-12-04 01:28:29 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2018-11-14 03:18:16 +08:00
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-14 07:27:31 +08:00
|
|
|
static void SetError(CommandReturnObject &result, Error err) {
|
|
|
|
result.GetErrorStream().Printf("error: %s\n",
|
|
|
|
toString(std::move(err)).c_str());
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
class CommandObjectReproducerDump : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
CommandObjectReproducerDump(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "reproducer dump",
|
2019-10-19 05:47:31 +08:00
|
|
|
"Dump the information contained in a reproducer. "
|
|
|
|
"If no reproducer is specified during replay, it "
|
|
|
|
"dumps the content of the current reproducer.",
|
2019-09-14 07:27:31 +08:00
|
|
|
nullptr) {}
|
|
|
|
|
|
|
|
~CommandObjectReproducerDump() override = default;
|
|
|
|
|
|
|
|
Options *GetOptions() override { return &m_options; }
|
|
|
|
|
|
|
|
class CommandOptions : public Options {
|
|
|
|
public:
|
|
|
|
CommandOptions() : Options(), file() {}
|
|
|
|
|
|
|
|
~CommandOptions() override = default;
|
|
|
|
|
|
|
|
Status SetOptionValue(uint32_t option_idx, StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
case 'f':
|
|
|
|
file.SetFile(option_arg, FileSpec::Style::native);
|
|
|
|
FileSystem::Instance().Resolve(file);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
provider = (ReproducerProvider)OptionArgParser::ToOptionEnum(
|
|
|
|
option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
|
|
|
|
if (!error.Success())
|
|
|
|
error.SetErrorStringWithFormat("unrecognized value for provider '%s'",
|
|
|
|
option_arg.str().c_str());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unimplemented option");
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
file.Clear();
|
|
|
|
provider = eReproducerProviderNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayRef<OptionDefinition> GetDefinitions() override {
|
2019-11-20 08:18:19 +08:00
|
|
|
return makeArrayRef(g_reproducer_dump_options);
|
2019-09-14 07:27:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec file;
|
|
|
|
ReproducerProvider provider = eReproducerProviderNone;
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
|
|
|
if (!command.empty()) {
|
|
|
|
result.AppendErrorWithFormat("'%s' takes no arguments",
|
|
|
|
m_cmd_name.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no reproducer path is specified, use the loader currently used for
|
|
|
|
// replay. Otherwise create a new loader just for dumping.
|
|
|
|
llvm::Optional<Loader> loader_storage;
|
|
|
|
Loader *loader = nullptr;
|
|
|
|
if (!m_options.file) {
|
|
|
|
loader = Reproducer::Instance().GetLoader();
|
|
|
|
if (loader == nullptr) {
|
|
|
|
result.SetError(
|
|
|
|
"Not specifying a reproducer is only support during replay.");
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
loader_storage.emplace(m_options.file);
|
|
|
|
loader = &(*loader_storage);
|
|
|
|
if (Error err = loader->LoadIndex()) {
|
|
|
|
SetError(result, std::move(err));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here we should have a valid loader.
|
|
|
|
assert(loader);
|
|
|
|
|
|
|
|
switch (m_options.provider) {
|
|
|
|
case eReproducerProviderFiles: {
|
|
|
|
FileSpec vfs_mapping = loader->GetFile<FileProvider::Info>();
|
|
|
|
|
|
|
|
// Read the VFS mapping.
|
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> buffer =
|
|
|
|
vfs::getRealFileSystem()->getBufferForFile(vfs_mapping.GetPath());
|
|
|
|
if (!buffer) {
|
|
|
|
SetError(result, errorCodeToError(buffer.getError()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize a VFS from the given mapping.
|
|
|
|
IntrusiveRefCntPtr<vfs::FileSystem> vfs = vfs::getVFSFromYAML(
|
|
|
|
std::move(buffer.get()), nullptr, vfs_mapping.GetPath());
|
|
|
|
|
|
|
|
// Dump the VFS to a buffer.
|
|
|
|
std::string str;
|
|
|
|
raw_string_ostream os(str);
|
|
|
|
static_cast<vfs::RedirectingFileSystem &>(*vfs).dump(os);
|
|
|
|
os.flush();
|
|
|
|
|
|
|
|
// Return the string.
|
|
|
|
result.AppendMessage(str);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case eReproducerProviderVersion: {
|
2019-10-17 08:01:57 +08:00
|
|
|
Expected<std::string> version = loader->LoadBuffer<VersionProvider>();
|
|
|
|
if (!version) {
|
|
|
|
SetError(result, version.takeError());
|
2019-09-14 07:27:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
2019-10-17 08:01:57 +08:00
|
|
|
result.AppendMessage(*version);
|
2019-09-14 07:27:31 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-17 08:02:00 +08:00
|
|
|
case eReproducerProviderWorkingDirectory: {
|
|
|
|
Expected<std::string> cwd =
|
|
|
|
loader->LoadBuffer<WorkingDirectoryProvider>();
|
|
|
|
if (!cwd) {
|
|
|
|
SetError(result, cwd.takeError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
result.AppendMessage(*cwd);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-14 07:27:31 +08:00
|
|
|
case eReproducerProviderCommands: {
|
2019-12-11 07:04:02 +08:00
|
|
|
std::unique_ptr<repro::MultiLoader<repro::CommandProvider>> multi_loader =
|
|
|
|
repro::MultiLoader<repro::CommandProvider>::Create(loader);
|
|
|
|
if (!multi_loader) {
|
2019-09-14 07:27:31 +08:00
|
|
|
SetError(result,
|
2020-03-11 14:06:39 +08:00
|
|
|
make_error<StringError>("Unable to create command loader.",
|
|
|
|
llvm::inconvertibleErrorCode()));
|
2019-09-14 07:27:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over the command files and dump them.
|
2019-12-11 07:04:02 +08:00
|
|
|
llvm::Optional<std::string> command_file;
|
|
|
|
while ((command_file = multi_loader->GetNextFile())) {
|
2019-09-14 07:27:31 +08:00
|
|
|
if (!command_file)
|
|
|
|
break;
|
|
|
|
|
|
|
|
auto command_buffer = llvm::MemoryBuffer::getFile(*command_file);
|
|
|
|
if (auto err = command_buffer.getError()) {
|
|
|
|
SetError(result, errorCodeToError(err));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
result.AppendMessage((*command_buffer)->getBuffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case eReproducerProviderGDB: {
|
2019-12-11 07:04:02 +08:00
|
|
|
std::unique_ptr<repro::MultiLoader<repro::GDBRemoteProvider>>
|
|
|
|
multi_loader =
|
|
|
|
repro::MultiLoader<repro::GDBRemoteProvider>::Create(loader);
|
2020-03-11 14:06:39 +08:00
|
|
|
|
|
|
|
if (!multi_loader) {
|
|
|
|
SetError(result,
|
|
|
|
make_error<StringError>("Unable to create GDB loader.",
|
|
|
|
llvm::inconvertibleErrorCode()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-11 07:04:02 +08:00
|
|
|
llvm::Optional<std::string> gdb_file;
|
|
|
|
while ((gdb_file = multi_loader->GetNextFile())) {
|
2020-03-13 23:49:15 +08:00
|
|
|
if (llvm::Expected<std::vector<GDBRemotePacket>> packets =
|
|
|
|
ReadFromYAML<std::vector<GDBRemotePacket>>(*gdb_file)) {
|
|
|
|
for (GDBRemotePacket &packet : *packets) {
|
|
|
|
packet.Dump(result.GetOutputStream());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SetError(result, packets.takeError());
|
2019-12-11 07:04:02 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-13 23:49:15 +08:00
|
|
|
}
|
2019-09-17 07:31:06 +08:00
|
|
|
|
2020-03-13 23:49:15 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case eReproducerProviderProcessInfo: {
|
|
|
|
std::unique_ptr<repro::MultiLoader<repro::ProcessInfoProvider>>
|
|
|
|
multi_loader =
|
|
|
|
repro::MultiLoader<repro::ProcessInfoProvider>::Create(loader);
|
2019-09-17 07:31:06 +08:00
|
|
|
|
2020-03-13 23:49:15 +08:00
|
|
|
if (!multi_loader) {
|
|
|
|
SetError(result, make_error<StringError>(
|
|
|
|
llvm::inconvertibleErrorCode(),
|
|
|
|
"Unable to create process info loader."));
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-17 07:31:06 +08:00
|
|
|
|
2020-03-13 23:49:15 +08:00
|
|
|
llvm::Optional<std::string> process_file;
|
|
|
|
while ((process_file = multi_loader->GetNextFile())) {
|
|
|
|
if (llvm::Expected<ProcessInstanceInfoList> infos =
|
|
|
|
ReadFromYAML<ProcessInstanceInfoList>(*process_file)) {
|
|
|
|
for (ProcessInstanceInfo info : *infos)
|
|
|
|
info.Dump(result.GetOutputStream(), HostInfo::GetUserIDResolver());
|
|
|
|
} else {
|
|
|
|
SetError(result, infos.takeError());
|
|
|
|
return false;
|
2019-12-11 07:04:02 +08:00
|
|
|
}
|
2019-09-17 07:31:06 +08:00
|
|
|
}
|
|
|
|
|
2019-09-14 07:27:31 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case eReproducerProviderNone:
|
|
|
|
result.SetError("No valid provider specified.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CommandOptions m_options;
|
|
|
|
};
|
|
|
|
|
2018-11-14 03:18:16 +08:00
|
|
|
CommandObjectReproducer::CommandObjectReproducer(
|
|
|
|
CommandInterpreter &interpreter)
|
2019-05-03 08:10:31 +08:00
|
|
|
: CommandObjectMultiword(
|
|
|
|
interpreter, "reproducer",
|
2019-11-20 09:28:46 +08:00
|
|
|
"Commands for manipulating reproducers. Reproducers make it "
|
|
|
|
"possible "
|
2019-10-19 05:47:31 +08:00
|
|
|
"to capture full debug sessions with all its dependencies. The "
|
|
|
|
"resulting reproducer is used to replay the debug session while "
|
|
|
|
"debugging the debugger.\n"
|
|
|
|
"Because reproducers need the whole the debug session from "
|
|
|
|
"beginning to end, you need to launch the debugger in capture or "
|
|
|
|
"replay mode, commonly though the command line driver.\n"
|
|
|
|
"Reproducers are unrelated record-replay debugging, as you cannot "
|
|
|
|
"interact with the debugger during replay.\n",
|
2019-07-31 02:06:38 +08:00
|
|
|
"reproducer <subcommand> [<subcommand-options>]") {
|
2018-11-14 03:18:16 +08:00
|
|
|
LoadSubCommand(
|
|
|
|
"generate",
|
|
|
|
CommandObjectSP(new CommandObjectReproducerGenerate(interpreter)));
|
2018-12-04 01:28:29 +08:00
|
|
|
LoadSubCommand("status", CommandObjectSP(
|
|
|
|
new CommandObjectReproducerStatus(interpreter)));
|
2019-09-14 07:27:31 +08:00
|
|
|
LoadSubCommand("dump",
|
|
|
|
CommandObjectSP(new CommandObjectReproducerDump(interpreter)));
|
2019-11-20 09:28:46 +08:00
|
|
|
LoadSubCommand("xcrash", CommandObjectSP(
|
|
|
|
new CommandObjectReproducerXCrash(interpreter)));
|
2018-11-14 03:18:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectReproducer::~CommandObjectReproducer() = default;
|