[Lldb-commits] [lldb] d6b6461 - [lldb/Interpreter] Fix session-save-on-quit when using ^D
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 29 01:54:49 PDT 2021
Author: Med Ismail Bennani
Date: 2021-06-29T10:54:29+02:00
New Revision: d6b64612bd92cda8b53ef348fb578983124c600f
URL: https://github.com/llvm/llvm-project/commit/d6b64612bd92cda8b53ef348fb578983124c600f
DIFF: https://github.com/llvm/llvm-project/commit/d6b64612bd92cda8b53ef348fb578983124c600f.diff
LOG: [lldb/Interpreter] Fix session-save-on-quit when using ^D
Previously, when `interpreter.save-session-on-quit` was enabled, lldb
would save the session transcript only when running the `quit` command.
This patch changes that so the transcripts are saved when the debugger
object is destroyed if the setting is enabled.
rdar://72902650
Differential Revision: https://reviews.llvm.org/D105038
Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>
Added:
Modified:
lldb/source/Commands/CommandObjectQuit.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/test/API/commands/session/save/TestSessionSave.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectQuit.cpp b/lldb/source/Commands/CommandObjectQuit.cpp
index e4de347870753..6ac04290f603f 100644
--- a/lldb/source/Commands/CommandObjectQuit.cpp
+++ b/lldb/source/Commands/CommandObjectQuit.cpp
@@ -101,8 +101,5 @@ bool CommandObjectQuit::DoExecute(Args &command, CommandReturnObject &result) {
m_interpreter.BroadcastEvent(event_type);
result.SetStatus(eReturnStatusQuit);
- if (m_interpreter.GetSaveSessionOnQuit())
- m_interpreter.SaveTranscript(result);
-
return true;
}
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 735e6f43ac69f..12210ed541bc1 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -23,6 +23,7 @@
#include "lldb/Host/Terminal.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Interpreter/OptionValueSInt64.h"
@@ -604,6 +605,17 @@ void Debugger::Destroy(DebuggerSP &debugger_sp) {
if (!debugger_sp)
return;
+ CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();
+
+ if (cmd_interpreter.GetSaveSessionOnQuit()) {
+ CommandReturnObject result(debugger_sp->GetUseColor());
+ cmd_interpreter.SaveTranscript(result);
+ if (result.Succeeded())
+ debugger_sp->GetOutputStream() << result.GetOutputData() << '\n';
+ else
+ debugger_sp->GetErrorStream() << result.GetErrorData() << '\n';
+ }
+
debugger_sp->Clear();
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 68e8edfc90583..00e9ccb762c32 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2974,6 +2974,7 @@ bool CommandInterpreter::SaveTranscript(
return error_out("Unable to write to destination file",
"Bytes written do not match transcript size.");
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
output_file->c_str());
diff --git a/lldb/test/API/commands/session/save/TestSessionSave.py b/lldb/test/API/commands/session/save/TestSessionSave.py
index e144ed19d1c50..2e25047e501a7 100644
--- a/lldb/test/API/commands/session/save/TestSessionSave.py
+++ b/lldb/test/API/commands/session/save/TestSessionSave.py
@@ -2,6 +2,8 @@
Test the session save feature
"""
import os
+import tempfile
+
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -57,7 +59,6 @@ def test_session_save(self):
self.assertFalse(res.Succeeded())
raw += self.raw_transcript_builder(cmd, res)
- import tempfile
tf = tempfile.NamedTemporaryFile()
output_file = tf.name
@@ -89,3 +90,37 @@ def test_session_save(self):
lines = raw.splitlines()[:-1]
for line in lines:
self.assertIn(line, content)
+
+ @skipIfWindows
+ @skipIfReproducer
+ @no_debug_info_test
+ def test_session_save_on_quit(self):
+ raw = ""
+ interpreter = self.dbg.GetCommandInterpreter()
+
+ td = tempfile.TemporaryDirectory()
+
+ settings = [
+ 'settings set interpreter.echo-commands true',
+ 'settings set interpreter.echo-comment-commands true',
+ 'settings set interpreter.stop-command-source-on-error false',
+ 'settings set interpreter.save-session-on-quit true',
+ 'settings set interpreter.save-session-directory ' + td.name,
+ ]
+
+ for setting in settings:
+ res = lldb.SBCommandReturnObject()
+ interpreter.HandleCommand(setting, res)
+ raw += self.raw_transcript_builder(setting, res)
+
+ self.dbg.Destroy(self.dbg)
+
+ with open(os.path.join(td.name, os.listdir(td.name)[0]), "r") as file:
+ content = file.read()
+ # Exclude last line, since session won't record it's own output
+ lines = raw.splitlines()[:-1]
+ for line in lines:
+ self.assertIn(line, content)
+
+
+
More information about the lldb-commits
mailing list