Skip to content

Add warning message to session save when transcript isn't saved. #109020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2024

Conversation

zhyty
Copy link
Contributor

@zhyty zhyty commented Sep 17, 2024

Somewhat recently, we made the change to hide the behavior to save LLDB session history to the transcript buffer behind the flag interpreter.save-transcript. By default, interpreter.save-transcript is false. See #90703 for context.

I'm making a small update here to our session save messaging and some help docs to clarify for users that aren't aware of this change. Maybe interpreter.save-transcript could be true by default as well. Any feedback welcome.

Tests

bin/lldb-dotest -p TestSessionSave

@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2024

@llvm/pr-subscribers-lldb

Author: Tom Yang (zhyty)

Changes

Somewhat recently, we made the change to hide the behavior to save LLDB session history to the transcript buffer behind the flag interpreter.save-transcript. By default, interpreter.save-transcript is false. See #90703 for context.

I'm making a small update here to our session save messaging and some help docs to clarify for users that aren't aware of this change. Maybe interpreter.save-transcript could be true by default as well. Any feedback welcome.

Tests

bin/lldb-dotest -p TestSessionSave

Full diff: https://github.com/llvm/llvm-project/pull/109020.diff

4 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectSession.cpp (+2-1)
  • (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+2)
  • (modified) lldb/source/Interpreter/InterpreterProperties.td (+1-1)
  • (modified) lldb/test/API/commands/session/save/TestSessionSave.py (+29)
diff --git a/lldb/source/Commands/CommandObjectSession.cpp b/lldb/source/Commands/CommandObjectSession.cpp
index c381ba4f74f120..3f714cec414695 100644
--- a/lldb/source/Commands/CommandObjectSession.cpp
+++ b/lldb/source/Commands/CommandObjectSession.cpp
@@ -19,7 +19,8 @@ class CommandObjectSessionSave : public CommandObjectParsed {
       : CommandObjectParsed(interpreter, "session save",
                             "Save the current session transcripts to a file.\n"
                             "If no file if specified, transcripts will be "
-                            "saved to a temporary file.",
+                            "saved to a temporary file.\n"
+                            "Note: transcripts will only be saved if interpreter.save-transcript is true.\n",
                             "session save [file]") {
     AddSimpleArgumentList(eArgTypePath, eArgRepeatOptional);
   }
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index b93f47a8a8d5ec..05426771ba0335 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3306,6 +3306,8 @@ bool CommandInterpreter::SaveTranscript(
   result.SetStatus(eReturnStatusSuccessFinishNoResult);
   result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
                                  output_file->c_str());
+  if (!GetSaveTranscript())
+    result.AppendError("Note: the setting interpreter.save-transcript is set to false, so the transcript might not have been recorded.");
 
   if (GetOpenTranscriptInEditor() && Host::IsInteractiveGraphicSession()) {
     const FileSpec file_spec;
diff --git a/lldb/source/Interpreter/InterpreterProperties.td b/lldb/source/Interpreter/InterpreterProperties.td
index a5fccbbca091cf..834f7be17480c6 100644
--- a/lldb/source/Interpreter/InterpreterProperties.td
+++ b/lldb/source/Interpreter/InterpreterProperties.td
@@ -16,7 +16,7 @@ let Definition = "interpreter" in {
   def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">,
     Global,
     DefaultFalse,
-    Desc<"If true, LLDB will save the session's transcripts before quitting.">;
+    Desc<"If true, LLDB will save the session's transcripts before quitting. Note: transcripts will only be saved if interpreter.save-transcript is true.">;
   def OpenTranscriptInEditor: Property<"open-transcript-in-editor", "Boolean">,
     Global,
     DefaultTrue,
diff --git a/lldb/test/API/commands/session/save/TestSessionSave.py b/lldb/test/API/commands/session/save/TestSessionSave.py
index aa99bcd56aed46..c81ff645d9d3b8 100644
--- a/lldb/test/API/commands/session/save/TestSessionSave.py
+++ b/lldb/test/API/commands/session/save/TestSessionSave.py
@@ -85,6 +85,8 @@ def test_session_save(self):
         interpreter.HandleCommand("session save", res)
         self.assertTrue(res.Succeeded())
         raw += self.raw_transcript_builder(cmd, res)
+        # Also check that we don't print an error message about an empty transcript.
+        self.assertNotIn("interpreter.save-transcript is set to false", res.GetError())
 
         with open(os.path.join(td.name, os.listdir(td.name)[0]), "r") as file:
             content = file.read()
@@ -93,6 +95,33 @@ def test_session_save(self):
             for line in lines:
                 self.assertIn(line, content)
 
+    @no_debug_info_test
+    def test_session_save_no_transcript_warning(self):
+        interpreter = self.dbg.GetCommandInterpreter()
+
+        self.runCmd("settings set interpreter.save-transcript false")
+
+        # These commands won't be saved, so are arbitrary.
+        commands = [
+            "p 1",
+            "settings set interpreter.save-session-on-quit true",
+            "fr v",
+            "settings set interpreter.echo-comment-commands true",
+        ]
+
+        for command in commands:
+            res = lldb.SBCommandReturnObject()
+            interpreter.HandleCommand(command, res)
+
+        output_file = self.getBuildArtifact('my-session')
+
+        res = lldb.SBCommandReturnObject()
+        interpreter.HandleCommand("session save " + output_file, res)
+        self.assertTrue(res.Succeeded())
+        # We should warn about the setting being false.
+        self.assertIn("interpreter.save-transcript is set to false", res.GetError())
+        self.assertTrue(os.path.getsize(output_file) == 0, "Output file should be empty since we didn't save the transcript.")
+
     @no_debug_info_test
     def test_session_save_on_quit(self):
         raw = ""

Copy link

github-actions bot commented Sep 17, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Sep 17, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -3306,6 +3306,8 @@ bool CommandInterpreter::SaveTranscript(
result.SetStatus(eReturnStatusSuccessFinishNoResult);
result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
output_file->c_str());
if (!GetSaveTranscript())
result.AppendError("Note: the setting interpreter.save-transcript is set to false, so the transcript might not have been recorded.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why we are using might not here. Since GetSaveTranscript() is false, isn't the transcript definitely won't be saved? Maybe rewording to:

Note: the interpreter.save-transcript setting is disabled (false), so the transcript will not be saved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example:

(lldb) settings set interpreter.save-transcript true
(lldb) p 1
(int) 1
(lldb) hello
error: 'hello' is not a valid command.
(lldb) settings set interpreter.save-transcript false
(lldb) p 2
(int) 2
(lldb) session save
Session's transcripts saved to /var/folders/dh/nv6c_38j4tq3crp6r6f69sdc0000gn/T/lldb/lldb_session_2024-09-20_17-46-03.936239000.log
error: Note: the setting interpreter.save-transcript is set to false, so the transcript might not have been recorded.

In this case, the text in between the two interpreter.save-transcript settings will be saved, including the actual command to disable it. So here's what's saved:

(lldb) settings set interpreter.save-transcript true
(lldb) p 1
(int) 1
(lldb) hello
�[0;1;31merror: �[0m'hello' is not a valid command.
(lldb) settings set interpreter.save-transcript false

This is why I worded it like this. session save will save whatever's found in the transcript buffer, but what was actually saved in the transcript buffer depends if users did something like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, one would argue that when interpreter.save-transcript is set to false, it should clear any internal buffer because the name interpreter.save-transcript = false implies it should not save transcript.

For the current behavior, interpreter.save-transcript should be renamed to "stop-record-commands" or something like this.

Not say it is important or I care though.

Comment on lines 3309 to 3310
if (!GetSaveTranscript())
result.AppendError("Note: the setting interpreter.save-transcript is set to false, so the transcript might not have been recorded.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this at the beginning of the function, before doing the work and return early if save-transcript is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above.

I hate to be so pedantic about it, but I would be worried if users used this flow of

(lldb) settings set interpreter.save-transcript true
... do various things they want to save ...
(lldb) settings set interpreter.save-transcript false
... do various things they don't want to save ...
(lldb) session save 

This wouldn't work anymore if we early returned.

To your point though, I guess they could always re-toggle it before that last session save, and maybe it would be better for the average user.

Anyway, that's why I decided to make this commit so conservative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@medismailben friendly ping on any followup comments. If not, I'll go ahead and merge.

@medismailben
Copy link
Member

Maybe interpreter.save-transcript could be true by default as well. Any feedback welcome.

Although that could be useful but I'm concerned of the performance aspect of it. Not everyone cares to save transcripts so I'm not sure it should be on by default. I like this patch because it explains to the user what they need to do to save the transaction (enable the settings), may be that's good enough.

@zhyty zhyty requested a review from medismailben September 21, 2024 19:02
@zhyty zhyty force-pushed the session-save-warning branch from ad7f50d to 943b350 Compare October 1, 2024 00:23
Tom Yang added 2 commits October 5, 2024 00:28
Somewhat recently, we made the change to hide the behavior to save LLDB
session history to the transcript buffer behind the flag
`interpreter.save-transcript`.
@zhyty zhyty force-pushed the session-save-warning branch from 943b350 to ac5bc70 Compare October 5, 2024 07:29
@zhyty zhyty merged commit 835b5e2 into llvm:main Oct 5, 2024
5 of 7 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 5, 2024

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building lldb at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/4965

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: lang/cpp/dynamic-value/TestCppValueCast.py (769 of 2809)
PASS: lldb-api :: lang/cpp/elaborated-types/TestElaboratedTypes.py (770 of 2809)
PASS: lldb-api :: lang/cpp/enum_types/TestCPP11EnumTypes.py (771 of 2809)
PASS: lldb-api :: lang/cpp/extern_c/TestExternCSymbols.py (772 of 2809)
PASS: lldb-api :: lang/cpp/exceptions/TestCPPExceptionBreakpoints.py (773 of 2809)
PASS: lldb-api :: lang/cpp/dynamic-value/TestDynamicValue.py (774 of 2809)
PASS: lldb-api :: lang/cpp/forward-declared-template-specialization/TestCppForwardDeclaredTemplateSpecialization.py (775 of 2809)
PASS: lldb-api :: lang/cpp/fixits/TestCppFixIts.py (776 of 2809)
PASS: lldb-api :: lang/cpp/fpnan/TestFPNaN.py (777 of 2809)
PASS: lldb-api :: lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py (778 of 2809)
FAIL: lldb-api :: lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py (779 of 2809)
******************** TEST 'lldb-api :: lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/local/bin/llvm-ar --env OBJCOPY=/usr/bin/llvm-objcopy --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c/shared_lib_stripped_symbols -p TestSharedLibStrippedSymbols.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 835b5e278e525dc628d4d0c085eb272996aed466)
  clang revision 835b5e278e525dc628d4d0c085eb272996aed466
  llvm revision 835b5e278e525dc628d4d0c085eb272996aed466
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_expr_dsym (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test case does not fall in any category of interest for this run) 
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_expr_dwarf (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_expr_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_frame_variable_dsym (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test case does not fall in any category of interest for this run) 
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_frame_variable_dwarf (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_frame_variable_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
======================================================================
FAIL: test_expr_dwarf (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
   Test that types work when defined in a shared library and forwa/d-declared in the main executable
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1769, in test_method
    return attrvalue(self)
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py", line 24, in test_expr
    self.expect(
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2370, in expect
    self.runCmd(
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1000, in runCmd
    self.assertTrue(self.res.Succeeded(), msg + output)
AssertionError: False is not true : Variable(s) displayed correctly
Error output:

Kyvangka1610 pushed a commit to Kyvangka1610/llvm-project that referenced this pull request Oct 5, 2024
…lvm#109020)

Somewhat recently, we made the change to hide the behavior to save LLDB
session history to the transcript buffer behind the flag
`interpreter.save-transcript`. By default, `interpreter.save-transcript`
is false. See llvm#90703 for context.

I'm making a small update here to our `session save` messaging and some
help docs to clarify for users that aren't aware of this change. Maybe
`interpreter.save-transcript` could be true by default as well. Any
feedback welcome.

# Tests
```
bin/lldb-dotest -p TestSessionSave
```

---------

Co-authored-by: Tom Yang <[email protected]>
Kyvangka1610 added a commit to Kyvangka1610/llvm-project that referenced this pull request Oct 5, 2024
* commit 'FETCH_HEAD':
  [clang][bytecode] Handle UETT_OpenMPRequiredSimdAlign (llvm#111259)
  [mlir][polynomial] Add and verify constraints of coefficientModulus for ringAttr (llvm#111016)
  [clang][bytecode] Save a per-Block IsWeak bit (llvm#111248)
  [analyzer] Fix wrong `builtin_*_overflow` return type (llvm#111253)
  [SelectOpt] Don't convert constant selects to branches. (llvm#110858)
  [InstCombine] Update and-or-icmps.ll after 574266c. NFC
  [Instcombine] Test for more gep canonicalization
  [NFC][TableGen] Change `CodeGenIntrinsics` to use const references (llvm#111219)
  Add warning message to `session save` when transcript isn't saved. (llvm#109020)
  [RISCV][TTI] Recognize CONCAT_VECTORS if a shufflevector mask is multiple insert subvector. (llvm#110457)
  Revert "[InstCombine] Folding `(icmp eq/ne (and X, -P2), INT_MIN)`" (llvm#111236)
  [NFC][lsan] Add SuspendAllThreads traces
  [lsan] Add `thread_suspend_fail` flag

Signed-off-by: kyvangka1610 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants