Skip to content

Commit 8d66eb2

Browse files
committed
Adding some documentation to lldb_dap::Log and moving the impl out of the header.
1 parent d4a03fa commit 8d66eb2

File tree

7 files changed

+44
-14
lines changed

7 files changed

+44
-14
lines changed

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_lldb_tool(lldb-dap
2323
Breakpoint.cpp
2424
BreakpointBase.cpp
2525
DAP.cpp
26+
DAPLog.cpp
2627
EventHelper.cpp
2728
ExceptionBreakpoint.cpp
2829
FifoFiles.cpp

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ const char DEV_NULL[] = "/dev/null";
6868

6969
namespace lldb_dap {
7070

71-
DAP::DAP(llvm::StringRef path, Log *log,
72-
const ReplMode default_repl_mode,
71+
DAP::DAP(llvm::StringRef path, Log *log, const ReplMode default_repl_mode,
7372
std::vector<std::string> pre_init_commands, Transport &transport)
7473
: debug_adapter_path(path), log(log), transport(transport),
7574
broadcaster("lldb-dap"), exception_breakpoints(),

lldb/tools/lldb-dap/DAP.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ struct DAP {
218218
/// LLDB commands to execute as soon as the debugger instance is allocaed.
219219
/// \param[in] transport
220220
/// Transport for this debug session.
221-
DAP(llvm::StringRef path, Log *log,
222-
const ReplMode default_repl_mode,
221+
DAP(llvm::StringRef path, Log *log, const ReplMode default_repl_mode,
223222
std::vector<std::string> pre_init_commands, Transport &transport);
224223

225224
~DAP();

lldb/tools/lldb-dap/DAPLog.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- DAPLog.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 "DAPLog.h"
10+
#include "llvm/ADT/StringRef.h"
11+
#include <fstream>
12+
#include <mutex>
13+
14+
using namespace llvm;
15+
16+
namespace lldb_dap {
17+
18+
Log::Log(StringRef filename) : m_stream(std::ofstream(filename.str())) {}
19+
20+
void Log::WriteMessage(StringRef message) {
21+
std::scoped_lock<std::mutex> lock(m_mutex);
22+
m_stream << message.str();
23+
m_stream.flush();
24+
}
25+
26+
} // namespace lldb_dap

lldb/tools/lldb-dap/DAPLog.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,20 @@
5454

5555
namespace lldb_dap {
5656

57-
class Log {
57+
/// Log manages the lldb-dap log file, used with the corresponding `DAP_LOG` and
58+
/// `DAP_LOG_ERROR` helpers.
59+
class Log final {
5860
public:
59-
Log(std::ofstream stream) : m_stream(std::move(stream)) {}
61+
/// Creates a log file with the given filename.
62+
Log(llvm::StringRef filename);
6063

61-
void WriteMessage(llvm::StringRef message) {
62-
std::scoped_lock<std::mutex> lock(m_mutex);
63-
m_stream << message.str();
64-
m_stream.flush();
65-
}
64+
/// Log is not copyable.
65+
/// @{
66+
Log(const Log &) = delete;
67+
void operator=(const Log &) = delete;
68+
/// @}
69+
70+
void WriteMessage(llvm::StringRef message);
6671

6772
private:
6873
std::mutex m_mutex;

lldb/tools/lldb-dap/Transport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ static constexpr StringLiteral kHeaderSeparator = "\r\n\r\n";
6363

6464
namespace lldb_dap {
6565

66-
Transport::Transport(StringRef client_name, Log *log,
67-
IOObjectSP input, IOObjectSP output)
66+
Transport::Transport(StringRef client_name, Log *log, IOObjectSP input,
67+
IOObjectSP output)
6868
: m_client_name(client_name), m_log(log), m_input(std::move(input)),
6969
m_output(std::move(output)) {}
7070

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ int main(int argc, char *argv[]) {
487487
std::unique_ptr<Log> log = nullptr;
488488
const char *log_file_path = getenv("LLDBDAP_LOG");
489489
if (log_file_path)
490-
log = std::make_unique<Log>(std::ofstream(log_file_path));
490+
log = std::make_unique<Log>(log_file_path);
491491

492492
// Initialize LLDB first before we do anything.
493493
lldb::SBError error = lldb::SBDebugger::InitializeWithErrorHandling();

0 commit comments

Comments
 (0)