[Lldb-commits] [lldb] 9d311dd - [lldb] Copy log files into diagnostic directory
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 7 16:00:35 PST 2023
Author: Jonas Devlieghere
Date: 2023-03-07T16:00:27-08:00
New Revision: 9d311dd6a71ba3910554b81fec5e6d5799ce0453
URL: https://github.com/llvm/llvm-project/commit/9d311dd6a71ba3910554b81fec5e6d5799ce0453
DIFF: https://github.com/llvm/llvm-project/commit/9d311dd6a71ba3910554b81fec5e6d5799ce0453.diff
LOG: [lldb] Copy log files into diagnostic directory
This patch copies over log files to the diagnostic directory. The caveat
here is that this only works for logs that are redirected to a file. The
implementation piggybacks of the mapping kept by the debugger. The
advantage is that it's free until you generate the diagnostics, at which
point you only pay the price of copying over the file.
Differential revision: https://reviews.llvm.org/D135631
Added:
lldb/test/Shell/Diagnostics/Inputs/TestCopyLogs.in
lldb/test/Shell/Diagnostics/TestCopyLogs.test
Modified:
lldb/include/lldb/Core/Debugger.h
lldb/source/Core/Debugger.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 07d9cf28beebf..3d2a37871d794 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -28,6 +28,7 @@
#include "lldb/Target/TargetList.h"
#include "lldb/Utility/Broadcaster.h"
#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Diagnostics.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/UserID.h"
@@ -596,6 +597,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
lldb::ListenerSP m_forward_listener_sp;
llvm::once_flag m_clear_once;
lldb::TargetSP m_dummy_target_sp;
+ Diagnostics::CallbackID m_diagnostics_callback_id;
lldb_private::DebuggerDestroyCallback m_destroy_callback = nullptr;
void *m_destroy_callback_baton = nullptr;
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index ae03ead2d654d..273660db066ca 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -44,7 +44,6 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadList.h"
#include "lldb/Utility/AnsiTerminal.h"
-#include "lldb/Utility/Diagnostics.h"
#include "lldb/Utility/Event.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Listener.h"
@@ -842,6 +841,22 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
if (!GetOutputFile().GetIsTerminalWithColors())
SetUseColor(false);
+ if (Diagnostics::Enabled()) {
+ m_diagnostics_callback_id = Diagnostics::Instance().AddCallback(
+ [this](const FileSpec &dir) -> llvm::Error {
+ for (auto &entry : m_stream_handlers) {
+ llvm::StringRef log_path = entry.first();
+ llvm::StringRef file_name = llvm::sys::path::filename(log_path);
+ FileSpec destination = dir.CopyByAppendingPathComponent(file_name);
+ std::error_code ec =
+ llvm::sys::fs::copy_file(log_path, destination.GetPath());
+ if (ec)
+ return llvm::errorCodeToError(ec);
+ }
+ return llvm::Error::success();
+ });
+ }
+
#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
// Enabling use of ANSI color codes because LLDB is using them to highlight
// text.
@@ -880,6 +895,9 @@ void Debugger::Clear() {
GetInputFile().Close();
m_command_interpreter_up->Clear();
+
+ if (Diagnostics::Enabled())
+ Diagnostics::Instance().RemoveCallback(m_diagnostics_callback_id);
});
}
diff --git a/lldb/test/Shell/Diagnostics/Inputs/TestCopyLogs.in b/lldb/test/Shell/Diagnostics/Inputs/TestCopyLogs.in
new file mode 100644
index 0000000000000..ae9e9534adaff
--- /dev/null
+++ b/lldb/test/Shell/Diagnostics/Inputs/TestCopyLogs.in
@@ -0,0 +1 @@
+command alias logcommands log enable lldb commands
diff --git a/lldb/test/Shell/Diagnostics/TestCopyLogs.test b/lldb/test/Shell/Diagnostics/TestCopyLogs.test
new file mode 100644
index 0000000000000..4706a18bee0dd
--- /dev/null
+++ b/lldb/test/Shell/Diagnostics/TestCopyLogs.test
@@ -0,0 +1,7 @@
+# RUN: rm -rf %t
+# RUN: mkdir -p %t
+
+# RUN: %lldb -s %S/Inputs/TestCopyLogs.in -o 'logcommands -f %t/commands.log' -o 'diagnostics dump -d %t/diags'
+
+# RUN: cat %t/diags/commands.log | FileCheck %s
+# CHECK: Processing command: diagnostics dump
More information about the lldb-commits
mailing list