Skip to content

Commit dcfe81e

Browse files
committed
[lldb] Add basic healthcheck command
1 parent 2db66e8 commit dcfe81e

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

lldb/include/lldb/Utility/Logging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include <cstdint>
1313

14+
#include "llvm/ADT/StringRef.h"
15+
1416
// Log Bits specific to logging in lldb
1517
#define LIBLLDB_LOG_PROCESS (1u << 1)
1618
#define LIBLLDB_LOG_THREAD (1u << 2)
@@ -64,6 +66,7 @@ Log *GetLogIfAnyCategoriesSet(uint32_t mask);
6466

6567
#ifdef LLDB_ENABLE_SWIFT
6668
Log *GetSwiftHealthLog();
69+
llvm::StringRef GetSwiftHealthLogData();
6770
#endif
6871

6972
void InitializeLldbChannel();

lldb/source/Commands/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_lldb_library(lldbCommands
1212
CommandObjectExpression.cpp
1313
CommandObjectFrame.cpp
1414
CommandObjectGUI.cpp
15+
CommandObjectHealthcheck.cpp
1516
CommandObjectHelp.cpp
1617
CommandObjectLanguage.cpp
1718
CommandObjectLog.cpp
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//===-- CommandObjectHealthcheck.cpp --------------------------------------===//
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+
9+
#include "CommandObjectHealthcheck.h"
10+
11+
#include "lldb/Host/HostInfo.h"
12+
#include "lldb/Interpreter/CommandReturnObject.h"
13+
#include "lldb/Utility/Log.h"
14+
#include "lldb/Host/FileSystem.h"
15+
#include "lldb/lldb-private.h"
16+
17+
using namespace lldb;
18+
using namespace lldb_private;
19+
20+
CommandObjectHealthcheck::CommandObjectHealthcheck(
21+
CommandInterpreter &interpreter)
22+
: CommandObjectParsed(interpreter, "healthcheck",
23+
"Show the LLDB debugger health check diagnostics.",
24+
"healthcheck") {}
25+
26+
bool CommandObjectHealthcheck::DoExecute(Args &args,
27+
CommandReturnObject &result) {
28+
std::error_code err;
29+
llvm::SmallString<128> temp_path;
30+
int temp_fd = -1;
31+
if (FileSpec temp_file_spec = HostInfo::GetProcessTempDir()) {
32+
temp_file_spec.AppendPathComponent("lldb-healthcheck-%%%%%%.log");
33+
err = llvm::sys::fs::createUniqueFile(temp_file_spec.GetPath(), temp_fd,
34+
temp_path);
35+
} else {
36+
err = llvm::sys::fs::createTemporaryFile("lldb-healthcheck", "log", temp_fd,
37+
temp_path);
38+
}
39+
40+
if (temp_fd == -1) {
41+
result.AppendErrorWithFormat("could not write to temp file %s",
42+
err.message().c_str());
43+
return false;
44+
}
45+
46+
llvm::raw_fd_ostream temp_stream(temp_fd, true, true);
47+
llvm::StringRef data = GetSwiftHealthLogData();
48+
temp_stream << data;
49+
50+
result.AppendMessageWithFormat("Health check written to %s\n",
51+
temp_path.c_str());
52+
return true;
53+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- CommandObjectHealthcheck.h ------------------------------*- C++ -*-===//
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+
9+
#ifndef LLDB_SOURCE_COMMANDS_COMMANDOBJECTHEALTHCHECK_H
10+
#define LLDB_SOURCE_COMMANDS_COMMANDOBJECTHEALTHCHECK_H
11+
12+
#include "lldb/Interpreter/CommandObject.h"
13+
14+
namespace lldb_private {
15+
16+
class CommandObjectHealthcheck : public CommandObjectParsed {
17+
public:
18+
CommandObjectHealthcheck(CommandInterpreter &interpreter);
19+
20+
~CommandObjectHealthcheck() override = default;
21+
22+
protected:
23+
bool DoExecute(Args &args, CommandReturnObject &result) override;
24+
};
25+
26+
} // namespace lldb_private
27+
28+
#endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTHEALTHCHECK_H

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "Commands/CommandObjectFrame.h"
2121
#include "Commands/CommandObjectGUI.h"
2222
#include "Commands/CommandObjectHelp.h"
23+
#include "Commands/CommandObjectHealthcheck.h"
2324
#include "Commands/CommandObjectLanguage.h"
2425
#include "Commands/CommandObjectLog.h"
2526
#include "Commands/CommandObjectMemory.h"
@@ -511,6 +512,7 @@ void CommandInterpreter::LoadCommandDictionary() {
511512
REGISTER_COMMAND_OBJECT("frame", CommandObjectMultiwordFrame);
512513
REGISTER_COMMAND_OBJECT("gui", CommandObjectGUI);
513514
REGISTER_COMMAND_OBJECT("help", CommandObjectHelp);
515+
REGISTER_COMMAND_OBJECT("healthcheck", CommandObjectHealthcheck);
514516
REGISTER_COMMAND_OBJECT("log", CommandObjectLog);
515517
REGISTER_COMMAND_OBJECT("memory", CommandObjectMemory);
516518
REGISTER_COMMAND_OBJECT("platform", CommandObjectPlatform);

lldb/source/Utility/Logging.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ Log *lldb_private::GetLogIfAnyCategoriesSet(uint32_t mask) {
8484
}
8585

8686
#ifdef LLDB_ENABLE_SWIFT
87+
8788
Log *lldb_private::GetSwiftHealthLog() {
8889
return g_swift_log_channel.GetLogIfAny(LIBLLDB_SWIFT_LOG_HEALTH);
8990
}
91+
92+
llvm::StringRef lldb_private::GetSwiftHealthLogData() {
93+
return g_swift_log_buffer;
94+
}
95+
9096
#endif

0 commit comments

Comments
 (0)