mib updated this revision to Diff 354962.
mib marked 2 inline comments as done.
mib added a comment.
Address @jingham, @JDevlieghere & @shafik comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105038/new/
https://reviews.llvm.org/D105038
Files:
lldb/source/Commands/CommandObjectQuit.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/test/API/commands/session/save/TestSessionSave.py
Index: lldb/test/API/commands/session/save/TestSessionSave.py
===================================================================
--- lldb/test/API/commands/session/save/TestSessionSave.py
+++ 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 @@
self.assertFalse(res.Succeeded())
raw += self.raw_transcript_builder(cmd, res)
- import tempfile
tf = tempfile.NamedTemporaryFile()
output_file = tf.name
@@ -89,3 +90,37 @@
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)
+
+
+
Index: lldb/source/Interpreter/CommandInterpreter.cpp
===================================================================
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2974,6 +2974,7 @@
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());
Index: lldb/source/Core/Debugger.cpp
===================================================================
--- lldb/source/Core/Debugger.cpp
+++ 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 @@
if (!debugger_sp)
return;
+ CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();
+
+ if (cmd_interpreter.GetSaveSessionOnQuit()) {
+ CommandReturnObject result(/*colors=*/true);
+ 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) {
Index: lldb/source/Commands/CommandObjectQuit.cpp
===================================================================
--- lldb/source/Commands/CommandObjectQuit.cpp
+++ lldb/source/Commands/CommandObjectQuit.cpp
@@ -101,8 +101,5 @@
m_interpreter.BroadcastEvent(event_type);
result.SetStatus(eReturnStatusQuit);
- if (m_interpreter.GetSaveSessionOnQuit())
- m_interpreter.SaveTranscript(result);
-
return true;
}
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits