[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
JDevlieghere added inline comments. Comment at: lldb/source/Interpreter/CommandInterpreter.cpp:506-519 m_command_dict["register"] = CommandObjectSP(new CommandObjectRegister(*this)); m_command_dict["reproducer"] = CommandObjectSP(new CommandObjectReproducer(*this)); m_command_dict["script"] = CommandObjectSP(new CommandObjectScript(*this, script_language)); + m_command_dict["session"] = CommandObjectSP(new CommandObjectSession(*this)); labath wrote: > /me wonders how this file escaped Jonas's make_shared-ification. Oh my god. Let's fix that ASAP: https://reviews.llvm.org/D84336 Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
This revision was automatically updated to reflect the committed changes. Closed by commit rG5bb742b10daf: [lldb/interpreter] Add ability to save lldb session to a file (authored by mib). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 Files: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Commands/CMakeLists.txt lldb/source/Commands/CommandObjectQuit.cpp lldb/source/Commands/CommandObjectSession.cpp lldb/source/Commands/CommandObjectSession.h lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Interpreter/InterpreterProperties.td lldb/test/API/commands/session/save/TestSessionSave.py Index: lldb/test/API/commands/session/save/TestSessionSave.py === --- /dev/null +++ lldb/test/API/commands/session/save/TestSessionSave.py @@ -0,0 +1,74 @@ +""" +Test the session save feature +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SessionSaveTestCase(TestBase): + +mydir = TestBase.compute_mydir(__file__) + +def raw_transcript_builder(self, cmd, res): +raw = "(lldb) " + cmd + "\n" +if res.GetOutputSize(): + raw += res.GetOutput() +if res.GetErrorSize(): + raw += res.GetError() +return raw + + +@skipIfWindows +@skipIfReproducer +@no_debug_info_test +def test_session_save(self): +raw = "" +interpreter = self.dbg.GetCommandInterpreter() + +settings = [ + 'settings set interpreter.echo-commands true', + 'settings set interpreter.echo-comment-commands true', + 'settings set interpreter.stop-command-source-on-error false' +] + +for setting in settings: + interpreter.HandleCommand(setting, lldb.SBCommandReturnObject()) + +inputs = [ + '# This is a comment', # Comment + 'help session', # Valid command + 'Lorem ipsum' # Invalid command +] + +for cmd in inputs: + res = lldb.SBCommandReturnObject() + interpreter.HandleCommand(cmd, res) + raw += self.raw_transcript_builder(cmd, res) + +self.assertTrue(interpreter.HasCommands()) +self.assertTrue(len(raw) != 0) + +# Check for error +cmd = 'session save /root/file' +interpreter.HandleCommand(cmd, res) +self.assertFalse(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +import tempfile +tf = tempfile.NamedTemporaryFile() +output_file = tf.name + +res = lldb.SBCommandReturnObject() +interpreter.HandleCommand('session save ' + output_file, res) +self.assertTrue(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +with open(output_file, "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/InterpreterProperties.td === --- lldb/source/Interpreter/InterpreterProperties.td +++ lldb/source/Interpreter/InterpreterProperties.td @@ -9,6 +9,10 @@ Global, DefaultTrue, Desc<"If true, LLDB will prompt you before quitting if there are any live processes being debugged. If false, LLDB will quit without asking in any case.">; + def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">, +Global, +DefaultFalse, +Desc<"If true, LLDB will save the session's transcripts before quitting.">; def StopCmdSourceOnError: Property<"stop-command-source-on-error", "Boolean">, Global, DefaultTrue, Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -6,6 +6,7 @@ // //===--===// +#include #include #include #include @@ -31,6 +32,7 @@ #include "Commands/CommandObjectQuit.h" #include "Commands/CommandObjectRegister.h" #include "Commands/CommandObjectReproducer.h" +#include "Commands/CommandObjectSession.h" #include "Commands/CommandObjectSettings.h" #include "Commands/CommandObjectSource.h" #include "Commands/CommandObjectStats.h" @@ -52,6 +54,8 @@ #if LLDB_ENABLE_LIBEDIT #include "lldb/Host/Editline.h" #endif +#include "lldb/Host/File.h" +#include "lldb/Host/FileCache.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -74,6 +78,7 @@ #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Path.h" #include
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
mib updated this revision to Diff 279737. mib added a comment. Address @labath comments Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 Files: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Commands/CMakeLists.txt lldb/source/Commands/CommandObjectQuit.cpp lldb/source/Commands/CommandObjectSession.cpp lldb/source/Commands/CommandObjectSession.h lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Interpreter/InterpreterProperties.td lldb/test/API/commands/session/save/TestSessionSave.py Index: lldb/test/API/commands/session/save/TestSessionSave.py === --- /dev/null +++ lldb/test/API/commands/session/save/TestSessionSave.py @@ -0,0 +1,74 @@ +""" +Test the session save feature +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SessionSaveTestCase(TestBase): + +mydir = TestBase.compute_mydir(__file__) + +def raw_transcript_builder(self, cmd, res): +raw = "(lldb) " + cmd + "\n" +if res.GetOutputSize(): + raw += res.GetOutput() +if res.GetErrorSize(): + raw += res.GetError() +return raw + + +@skipIfWindows +@skipIfReproducer +@no_debug_info_test +def test_session_save(self): +raw = "" +interpreter = self.dbg.GetCommandInterpreter() + +settings = [ + 'settings set interpreter.echo-commands true', + 'settings set interpreter.echo-comment-commands true', + 'settings set interpreter.stop-command-source-on-error false' +] + +for setting in settings: + interpreter.HandleCommand(setting, lldb.SBCommandReturnObject()) + +inputs = [ + '# This is a comment', # Comment + 'help session', # Valid command + 'Lorem ipsum' # Invalid command +] + +for cmd in inputs: + res = lldb.SBCommandReturnObject() + interpreter.HandleCommand(cmd, res) + raw += self.raw_transcript_builder(cmd, res) + +self.assertTrue(interpreter.HasCommands()) +self.assertTrue(len(raw) != 0) + +# Check for error +cmd = 'session save /root/file' +interpreter.HandleCommand(cmd, res) +self.assertFalse(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +import tempfile +tf = tempfile.NamedTemporaryFile() +output_file = tf.name + +res = lldb.SBCommandReturnObject() +interpreter.HandleCommand('session save ' + output_file, res) +self.assertTrue(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +with open(output_file, "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/InterpreterProperties.td === --- lldb/source/Interpreter/InterpreterProperties.td +++ lldb/source/Interpreter/InterpreterProperties.td @@ -9,6 +9,10 @@ Global, DefaultTrue, Desc<"If true, LLDB will prompt you before quitting if there are any live processes being debugged. If false, LLDB will quit without asking in any case.">; + def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">, +Global, +DefaultFalse, +Desc<"If true, LLDB will save the session's transcripts before quitting.">; def StopCmdSourceOnError: Property<"stop-command-source-on-error", "Boolean">, Global, DefaultTrue, Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -6,6 +6,7 @@ // //===--===// +#include #include #include #include @@ -31,6 +32,7 @@ #include "Commands/CommandObjectQuit.h" #include "Commands/CommandObjectRegister.h" #include "Commands/CommandObjectReproducer.h" +#include "Commands/CommandObjectSession.h" #include "Commands/CommandObjectSettings.h" #include "Commands/CommandObjectSource.h" #include "Commands/CommandObjectStats.h" @@ -52,6 +54,8 @@ #if LLDB_ENABLE_LIBEDIT #include "lldb/Host/Editline.h" #endif +#include "lldb/Host/File.h" +#include "lldb/Host/FileCache.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -74,6 +78,7 @@ #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/ScopedPrinter.h" using namespace lldb; using namespace
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
labath marked an inline comment as done. labath added inline comments. Comment at: lldb/source/Commands/CommandObjectQuit.cpp:75-80 + if (m_interpreter.GetSaveSessionOnQuit()) { +if (!m_interpreter.SaveTranscript(result)) { + result.SetStatus(eReturnStatusFailed); + return false; +} + } I think this should be done only after we have done all the validation and decided that we actually want to quit (i.e. line ~109). I am also not sure that a failure to save the transcript should abort the quit. Maybe it just print an error message but quit nonetheless? Comment at: lldb/source/Interpreter/CommandInterpreter.cpp:506-519 m_command_dict["register"] = CommandObjectSP(new CommandObjectRegister(*this)); m_command_dict["reproducer"] = CommandObjectSP(new CommandObjectReproducer(*this)); m_command_dict["script"] = CommandObjectSP(new CommandObjectScript(*this, script_language)); + m_command_dict["session"] = CommandObjectSP(new CommandObjectSession(*this)); /me wonders how this file escaped Jonas's make_shared-ification. Comment at: lldb/test/API/commands/session/save/TestSessionSave.py:16-18 + configuration.settings.append(("interpreter.echo-commands", "true")) + configuration.settings.append(("interpreter.echo-comment-commands", "true")) + configuration.settings.append(("interpreter.stop-command-source-on-error", "false")) This will modify the global configuration object. Best just set the relevant settings manually... Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
JDevlieghere accepted this revision. JDevlieghere added a comment. This revision is now accepted and ready to land. LGTM Comment at: lldb/source/Interpreter/CommandInterpreter.cpp:2941 + + GetDebugger().GetOutputStreamSP()->Printf( + "Session's transcripts saved to %s\n", output_file->c_str()); I'd write this to the `CommandReturnObject` and include it in the transcript. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
mib updated this revision to Diff 279639. mib added a comment. Reformat patch. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 Files: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Commands/CMakeLists.txt lldb/source/Commands/CommandObjectQuit.cpp lldb/source/Commands/CommandObjectSession.cpp lldb/source/Commands/CommandObjectSession.h lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Interpreter/InterpreterProperties.td lldb/test/API/commands/session/save/TestSessionSave.py Index: lldb/test/API/commands/session/save/TestSessionSave.py === --- /dev/null +++ lldb/test/API/commands/session/save/TestSessionSave.py @@ -0,0 +1,70 @@ +""" +Test the session save feature +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SessionSaveTestCase(TestBase): + +mydir = TestBase.compute_mydir(__file__) + +def setUp(self): + configuration.settings.append(("interpreter.echo-commands", "true")) + configuration.settings.append(("interpreter.echo-comment-commands", "true")) + configuration.settings.append(("interpreter.stop-command-source-on-error", "false")) + TestBase.setUp(self) + + +def raw_transcript_builder(self, cmd, res): +raw = "(lldb) " + cmd + "\n" +if res.GetOutputSize(): + raw += res.GetOutput() +if res.GetErrorSize(): + raw += res.GetError() +return raw + + +@skipIfWindows +@skipIfReproducer +@no_debug_info_test +def test_session_save(self): +raw = "" +inputs = [ + '# This is a comment', # Comment + 'help session', # Valid command + 'Lorem ipsum' # Invalid command +] + +import tempfile +tf = tempfile.NamedTemporaryFile() + +interpreter = self.dbg.GetCommandInterpreter() +for cmd in inputs: + res = lldb.SBCommandReturnObject() + interpreter.HandleCommand(cmd, res) + raw += self.raw_transcript_builder(cmd, res) + +self.assertTrue(interpreter.HasCommands()) +self.assertTrue(len(raw) != 0) + +# Check for error +cmd = 'session save /root/file' +interpreter.HandleCommand(cmd, res) +self.assertFalse(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +output_file = tf.name + +res = lldb.SBCommandReturnObject() +interpreter.HandleCommand('session save ' + output_file, res) +self.assertTrue(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +with open(output_file, "r") as file: + content = file.read() + for line in raw.splitlines(): +self.assertIn(line, content) Index: lldb/source/Interpreter/InterpreterProperties.td === --- lldb/source/Interpreter/InterpreterProperties.td +++ lldb/source/Interpreter/InterpreterProperties.td @@ -9,6 +9,10 @@ Global, DefaultTrue, Desc<"If true, LLDB will prompt you before quitting if there are any live processes being debugged. If false, LLDB will quit without asking in any case.">; + def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">, +Global, +DefaultFalse, +Desc<"If true, LLDB will save the session's transcripts before quitting.">; def StopCmdSourceOnError: Property<"stop-command-source-on-error", "Boolean">, Global, DefaultTrue, Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -6,6 +6,7 @@ // //===--===// +#include #include #include #include @@ -31,6 +32,7 @@ #include "Commands/CommandObjectQuit.h" #include "Commands/CommandObjectRegister.h" #include "Commands/CommandObjectReproducer.h" +#include "Commands/CommandObjectSession.h" #include "Commands/CommandObjectSettings.h" #include "Commands/CommandObjectSource.h" #include "Commands/CommandObjectStats.h" @@ -52,6 +54,8 @@ #if LLDB_ENABLE_LIBEDIT #include "lldb/Host/Editline.h" #endif +#include "lldb/Host/File.h" +#include "lldb/Host/FileCache.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -74,6 +78,7 @@ #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/ScopedPrinter.h" using namespace lldb; using namespace lldb_private; @@ -116,7 +121,7 @@ m_skip_lldbinit_files(false), m_skip_app_init_files(false), m_command_io_handler_sp(), m_comment_char('#'),
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
mib updated this revision to Diff 279638. mib marked 6 inline comments as done. mib added a comment. Address @JDevlieghere comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 Files: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Commands/CMakeLists.txt lldb/source/Commands/CommandObjectLog.cpp lldb/source/Commands/CommandObjectQuit.cpp lldb/source/Commands/CommandObjectSession.cpp lldb/source/Commands/CommandObjectSession.h lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Interpreter/InterpreterProperties.td lldb/test/API/commands/session/save/TestSessionSave.py Index: lldb/test/API/commands/session/save/TestSessionSave.py === --- /dev/null +++ lldb/test/API/commands/session/save/TestSessionSave.py @@ -0,0 +1,70 @@ +""" +Test the session save feature +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SessionSaveTestCase(TestBase): + +mydir = TestBase.compute_mydir(__file__) + +def setUp(self): + configuration.settings.append(("interpreter.echo-commands", "true")) + configuration.settings.append(("interpreter.echo-comment-commands", "true")) + configuration.settings.append(("interpreter.stop-command-source-on-error", "false")) + TestBase.setUp(self) + + +def raw_transcript_builder(self, cmd, res): +raw = "(lldb) " + cmd + "\n" +if res.GetOutputSize(): + raw += res.GetOutput() +if res.GetErrorSize(): + raw += res.GetError() +return raw + + +@skipIfWindows +@skipIfReproducer +@no_debug_info_test +def test_session_save(self): +raw = "" +inputs = [ + '# This is a comment', # Comment + 'help session', # Valid command + 'Lorem ipsum' # Invalid command +] + +import tempfile +tf = tempfile.NamedTemporaryFile() + +interpreter = self.dbg.GetCommandInterpreter() +for cmd in inputs: + res = lldb.SBCommandReturnObject() + interpreter.HandleCommand(cmd, res) + raw += self.raw_transcript_builder(cmd, res) + +self.assertTrue(interpreter.HasCommands()) +self.assertTrue(len(raw) != 0) + +# Check for error +cmd = 'session save /root/file' +interpreter.HandleCommand(cmd, res) +self.assertFalse(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +output_file = tf.name + +res = lldb.SBCommandReturnObject() +interpreter.HandleCommand('session save ' + output_file, res) +self.assertTrue(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +with open(output_file, "r") as file: + content = file.read() + for line in raw.splitlines(): +self.assertIn(line, content) Index: lldb/source/Interpreter/InterpreterProperties.td === --- lldb/source/Interpreter/InterpreterProperties.td +++ lldb/source/Interpreter/InterpreterProperties.td @@ -9,6 +9,10 @@ Global, DefaultTrue, Desc<"If true, LLDB will prompt you before quitting if there are any live processes being debugged. If false, LLDB will quit without asking in any case.">; + def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">, +Global, +DefaultFalse, +Desc<"If true, LLDB will save the session's transcripts before quitting.">; def StopCmdSourceOnError: Property<"stop-command-source-on-error", "Boolean">, Global, DefaultTrue, Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -6,6 +6,7 @@ // //===--===// +#include #include #include #include @@ -31,6 +32,7 @@ #include "Commands/CommandObjectQuit.h" #include "Commands/CommandObjectRegister.h" #include "Commands/CommandObjectReproducer.h" +#include "Commands/CommandObjectSession.h" #include "Commands/CommandObjectSettings.h" #include "Commands/CommandObjectSource.h" #include "Commands/CommandObjectStats.h" @@ -52,6 +54,8 @@ #if LLDB_ENABLE_LIBEDIT #include "lldb/Host/Editline.h" #endif +#include "lldb/Host/File.h" +#include "lldb/Host/FileCache.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -74,6 +78,7 @@ #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/ScopedPrinter.h" using namespace lldb; using namespace lldb_private; @@ -116,7 +121,7 @@
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
JDevlieghere added inline comments. Comment at: lldb/include/lldb/Interpreter/CommandInterpreter.h:532 + bool SaveTranscripts(std::string file_path); + - Is there more than one transcript? - Maybe make the string optional as you have logic to deal with that so you can call `SaveTranscripts()` instead of `SaveTranscripts("")` which looks a bit messy. - Add a Doxygen comment documenting the empty-string behavior. Comment at: lldb/include/lldb/Interpreter/CommandInterpreter.h:630 + + StreamString m_session_transcripts; }; The current name isn't very descriptive of what this object is exactly, especially since it's plural. How about `m_transcript_stream`? Comment at: lldb/source/Commands/CommandObjectSession.cpp:25 +// argument entry. +arg1.push_back(channel_arg); + I changed the `CommandArgumentData` constructor so you can do ``` arg1.emplace_back(eArgTypePath, eArgRepeatOptional) ``` Comment at: lldb/source/Commands/CommandObjectSession.h:16 + +// CommandObjectSession + Redundant. Comment at: lldb/source/Interpreter/CommandInterpreter.cpp:2915 + error_message, output_file, description); +StreamSP error_stream = GetDebugger().GetErrorStreamSP(); +*error_stream << "Failed to save session's transcripts to " << output_file Something that's called from a command should not write to the debugger's output/error stream directly. This should return an `Error` instead which then can be dealt with in the caller. If the caller is a CommandObject, it can write it to the return object. If the caller is something else it can still decide to write it to the debugger's error stream. Comment at: lldb/test/API/commands/session/save/TestSessionSave.py:42 + +#import pdb +#pdb.set_trace() You probably didn't mean to leave this around. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
mib updated this revision to Diff 279519. mib added a comment. Reformat. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 Files: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Commands/CMakeLists.txt lldb/source/Commands/CommandObjectQuit.cpp lldb/source/Commands/CommandObjectSession.cpp lldb/source/Commands/CommandObjectSession.h lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Interpreter/InterpreterProperties.td lldb/test/API/commands/session/save/TestSessionSave.py Index: lldb/test/API/commands/session/save/TestSessionSave.py === --- /dev/null +++ lldb/test/API/commands/session/save/TestSessionSave.py @@ -0,0 +1,73 @@ +""" +Test the session save feature +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SessionSaveTestCase(TestBase): + +mydir = TestBase.compute_mydir(__file__) + +def setUp(self): + configuration.settings.append(("interpreter.echo-commands", "true")) + configuration.settings.append(("interpreter.echo-comment-commands", "true")) + configuration.settings.append(("interpreter.stop-command-source-on-error", "false")) + TestBase.setUp(self) + + +def raw_transcript_builder(self, cmd, res): +raw = "(lldb) " + cmd + "\n" +if res.GetOutputSize(): + raw += res.GetOutput() +if res.GetErrorSize(): + raw += res.GetError() +return raw + + +@skipIfWindows +@skipIfReproducer +@no_debug_info_test +def test_session_save(self): +raw = "" +inputs = [ + '# This is a comment', # Comment + 'help session', # Valid command + 'Lorem ipsum' # Invalid command +] + +#import pdb +#pdb.set_trace() + +import tempfile +tf = tempfile.NamedTemporaryFile() + +interpreter = self.dbg.GetCommandInterpreter() +for cmd in inputs: + res = lldb.SBCommandReturnObject() + interpreter.HandleCommand(cmd, res) + raw += self.raw_transcript_builder(cmd, res) + +self.assertTrue(interpreter.HasCommands()) +self.assertTrue(len(raw) != 0) + +# Check for error +cmd = 'session save /root/file' +interpreter.HandleCommand(cmd, res) +self.assertFalse(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +output_file = tf.name + +res = lldb.SBCommandReturnObject() +interpreter.HandleCommand('session save ' + output_file, res) +self.assertTrue(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +with open(output_file, "r") as file: + content = file.read() + for line in raw.splitlines(): +self.assertIn(line, content) Index: lldb/source/Interpreter/InterpreterProperties.td === --- lldb/source/Interpreter/InterpreterProperties.td +++ lldb/source/Interpreter/InterpreterProperties.td @@ -9,6 +9,10 @@ Global, DefaultTrue, Desc<"If true, LLDB will prompt you before quitting if there are any live processes being debugged. If false, LLDB will quit without asking in any case.">; + def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">, +Global, +DefaultFalse, +Desc<"If true, LLDB will save the session's transcripts before quitting.">; def StopCmdSourceOnError: Property<"stop-command-source-on-error", "Boolean">, Global, DefaultTrue, Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -6,6 +6,7 @@ // //===--===// +#include #include #include #include @@ -31,6 +32,7 @@ #include "Commands/CommandObjectQuit.h" #include "Commands/CommandObjectRegister.h" #include "Commands/CommandObjectReproducer.h" +#include "Commands/CommandObjectSession.h" #include "Commands/CommandObjectSettings.h" #include "Commands/CommandObjectSource.h" #include "Commands/CommandObjectStats.h" @@ -52,6 +54,8 @@ #if LLDB_ENABLE_LIBEDIT #include "lldb/Host/Editline.h" #endif +#include "lldb/Host/File.h" +#include "lldb/Host/FileCache.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -74,6 +78,7 @@ #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/ScopedPrinter.h" using namespace lldb; using namespace lldb_private; @@ -116,7 +121,7 @@ m_skip_lldbinit_files(false), m_skip_app_init_files(false),
[Lldb-commits] [PATCH] D82155: [lldb/interpreter] Add ability to save lldb session to a file
mib updated this revision to Diff 279505. mib retitled this revision from "[WIP][lldb/interpreter] Add ability to save lldb session to a file" to "[lldb/interpreter] Add ability to save lldb session to a file". mib added a comment. - Address previous comments - Add test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82155/new/ https://reviews.llvm.org/D82155 Files: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Commands/CMakeLists.txt lldb/source/Commands/CommandObjectQuit.cpp lldb/source/Commands/CommandObjectSession.cpp lldb/source/Commands/CommandObjectSession.h lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Interpreter/InterpreterProperties.td lldb/test/API/commands/session/save/TestSessionSave.py Index: lldb/test/API/commands/session/save/TestSessionSave.py === --- /dev/null +++ lldb/test/API/commands/session/save/TestSessionSave.py @@ -0,0 +1,73 @@ +""" +Test the session save feature +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SessionSaveTestCase(TestBase): + +mydir = TestBase.compute_mydir(__file__) + +def setUp(self): + configuration.settings.append(("interpreter.echo-commands", "true")) + configuration.settings.append(("interpreter.echo-comment-commands", "true")) + configuration.settings.append(("interpreter.stop-command-source-on-error", "false")) + TestBase.setUp(self) + + +def raw_transcript_builder(self, cmd, res): +raw = "(lldb) " + cmd + "\n" +if res.GetOutputSize(): + raw += res.GetOutput() +if res.GetErrorSize(): + raw += res.GetError() +return raw + + +@skipIfWindows +@skipIfReproducer +@no_debug_info_test +def test_session_save(self): +raw = "" +inputs = [ + '# This is a comment', # Comment + 'help session', # Valid command + 'Lorem ipsum' # Invalid command +] + +#import pdb +#pdb.set_trace() + +import tempfile +tf = tempfile.NamedTemporaryFile() + +interpreter = self.dbg.GetCommandInterpreter() +for cmd in inputs: + res = lldb.SBCommandReturnObject() + interpreter.HandleCommand(cmd, res) + raw += self.raw_transcript_builder(cmd, res) + +self.assertTrue(interpreter.HasCommands()) +self.assertTrue(len(raw) != 0) + +# Check for error +cmd = 'session save /root/file' +interpreter.HandleCommand(cmd, res) +self.assertFalse(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +output_file = tf.name + +res = lldb.SBCommandReturnObject() +interpreter.HandleCommand('session save ' + output_file, res) +self.assertTrue(res.Succeeded()) +raw += self.raw_transcript_builder(cmd, res) + +with open(output_file, "r") as file: + content = file.read() + for line in raw.splitlines(): +self.assertIn(line, content) Index: lldb/source/Interpreter/InterpreterProperties.td === --- lldb/source/Interpreter/InterpreterProperties.td +++ lldb/source/Interpreter/InterpreterProperties.td @@ -9,6 +9,10 @@ Global, DefaultTrue, Desc<"If true, LLDB will prompt you before quitting if there are any live processes being debugged. If false, LLDB will quit without asking in any case.">; + def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">, +Global, +DefaultFalse, +Desc<"If true, LLDB will save the session's transcripts before quitting.">; def StopCmdSourceOnError: Property<"stop-command-source-on-error", "Boolean">, Global, DefaultTrue, Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -6,6 +6,7 @@ // //===--===// +#include #include #include #include @@ -31,6 +32,7 @@ #include "Commands/CommandObjectQuit.h" #include "Commands/CommandObjectRegister.h" #include "Commands/CommandObjectReproducer.h" +#include "Commands/CommandObjectSession.h" #include "Commands/CommandObjectSettings.h" #include "Commands/CommandObjectSource.h" #include "Commands/CommandObjectStats.h" @@ -52,6 +54,8 @@ #if LLDB_ENABLE_LIBEDIT #include "lldb/Host/Editline.h" #endif +#include "lldb/Host/File.h" +#include "lldb/Host/FileCache.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -74,6 +78,7 @@ #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h"