https://github.com/qxy11 updated https://github.com/llvm/llvm-project/pull/145436
>From b7889c1f7b0be25f71c6c893bfabe0ebb26f9f52 Mon Sep 17 00:00:00 2001 From: Janet Yang <qx...@meta.com> Date: Mon, 23 Jun 2025 14:25:12 -0700 Subject: [PATCH 1/5] Disable "transcript" in "statistics dump" by default --- lldb/include/lldb/Target/Statistics.h | 2 +- .../commands/statistics/basic/TestStats.py | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index 42f03798c219e..676f3a4a118be 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -195,7 +195,7 @@ struct StatisticsOptions { return m_include_transcript.value(); // `m_include_transcript` has no value set, so return a value based on // `m_summary_only`. - return !GetSummaryOnly(); + return false; } void SetIncludePlugins(bool value) { m_include_plugins = value; } diff --git a/lldb/test/API/commands/statistics/basic/TestStats.py b/lldb/test/API/commands/statistics/basic/TestStats.py index cc7410ebe018d..138844586af7f 100644 --- a/lldb/test/API/commands/statistics/basic/TestStats.py +++ b/lldb/test/API/commands/statistics/basic/TestStats.py @@ -896,7 +896,7 @@ def get_test_cases_for_sections_existence(self): "targets.frameVariable": True, "targets.totalSharedLibraryEventHitCount": True, "modules": True, - "transcript": True, + "transcript": False, }, }, { # Summary mode @@ -983,6 +983,24 @@ def get_test_cases_for_sections_existence(self): "transcript": False, }, }, + { # Default mode without modules and with transcript + "command_options": " --modules=false --transcript=true", + "api_options": { + "SetIncludeModules": False, + "SetIncludeTranscript": True, + }, + "expect": { + "commands": True, + "targets": True, + "targets.moduleIdentifiers": False, + "targets.breakpoints": True, + "targets.expressionEvaluation": True, + "targets.frameVariable": True, + "targets.totalSharedLibraryEventHitCount": True, + "modules": False, + "transcript": True, + }, + }, { # Default mode without modules "command_options": " --modules=false", "api_options": { @@ -997,6 +1015,23 @@ def get_test_cases_for_sections_existence(self): "targets.frameVariable": True, "targets.totalSharedLibraryEventHitCount": True, "modules": False, + "transcript": False, + }, + }, + { # Default mode with transcript + "command_options": " --transcript=true", + "api_options": { + "SetIncludeTranscript": True, + }, + "expect": { + "commands": True, + "targets": True, + "targets.moduleIdentifiers": True, + "targets.breakpoints": True, + "targets.expressionEvaluation": True, + "targets.frameVariable": True, + "targets.totalSharedLibraryEventHitCount": True, + "modules": True, "transcript": True, }, }, >From 202b69d78ec22e3e8407a103ca91300e021f23c3 Mon Sep 17 00:00:00 2001 From: Janet Yang <qx...@meta.com> Date: Mon, 23 Jun 2025 15:46:42 -0700 Subject: [PATCH 2/5] Update some comments --- lldb/include/lldb/API/SBStatisticsOptions.h | 3 +-- lldb/include/lldb/Target/Statistics.h | 3 +-- lldb/source/Commands/Options.td | 16 +++++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lldb/include/lldb/API/SBStatisticsOptions.h b/lldb/include/lldb/API/SBStatisticsOptions.h index 74bea03eff9c9..bfff9dc926432 100644 --- a/lldb/include/lldb/API/SBStatisticsOptions.h +++ b/lldb/include/lldb/API/SBStatisticsOptions.h @@ -57,8 +57,7 @@ class LLDB_API SBStatisticsOptions { /// a JSON array with all commands the user and/or scripts executed during a /// debug session. /// - /// Defaults to true, unless the `SummaryOnly` mode is enabled, in which case - /// this is turned off unless specified. + /// Defaults to false. void SetIncludeTranscript(bool b); bool GetIncludeTranscript() const; diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index 676f3a4a118be..68194cf216a1a 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -193,8 +193,7 @@ struct StatisticsOptions { bool GetIncludeTranscript() const { if (m_include_transcript.has_value()) return m_include_transcript.value(); - // `m_include_transcript` has no value set, so return a value based on - // `m_summary_only`. + // Default to false in both default mode and summary mode. return false; } diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index 75bdffe16c52e..5327647d65cc4 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1482,13 +1482,15 @@ let Command = "statistics dump" in { "this is turned off unless specified. " "In default mode, if both '--targets' and '--modules' are 'true', a list " "of module identifiers will be added to the 'targets' section.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, - Arg<"Boolean">, - Desc<"If the setting interpreter.save-transcript is enabled and this " - "option is 'true', include a JSON array with all commands the user and/or " - "scripts executed during a debug session. " - "Defaults to true, unless the '--summary' mode is enabled, in which case " - "this is turned off unless specified.">; + def statistics_dump_transcript + : Option<"transcript", "t">, + Group<1>, + Arg<"Boolean">, + Desc<"If the setting interpreter.save-transcript is enabled and this " + "option is 'true', include a JSON array with all commands the " + "user and/or " + "scripts executed during a debug session. " + "Defaults to false. ">; def statistics_dump_plugins : Option<"plugins", "p">, Group<1>, >From e2c77864e57dff7c4fea0611b1d61cd4b381e1ba Mon Sep 17 00:00:00 2001 From: Janet Yang <qx...@meta.com> Date: Tue, 24 Jun 2025 13:32:31 -0700 Subject: [PATCH 3/5] Add transcript warning and refactor GetIncludeTranscript() Summary: Add warning to 'statistics dump --transcript=true' when interpreter.save-transcript is disabled, helping users understand why transcript data is empty. Also refactor StatisticsOptions::GetIncludeTranscript() to use value_or(false) instead of the verbose has_value()/value() pattern to address PR comments. --- lldb/include/lldb/Target/Statistics.h | 5 +---- lldb/source/Commands/CommandObjectStats.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index 68194cf216a1a..55dff8861a9ab 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -191,10 +191,7 @@ struct StatisticsOptions { void SetIncludeTranscript(bool value) { m_include_transcript = value; } bool GetIncludeTranscript() const { - if (m_include_transcript.has_value()) - return m_include_transcript.value(); - // Default to false in both default mode and summary mode. - return false; + return m_include_transcript.value_or(false); } void SetIncludePlugins(bool value) { m_include_plugins = value; } diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index b77c44bdf5d09..08283ef9d1699 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -9,6 +9,7 @@ #include "CommandObjectStats.h" #include "lldb/Core/Debugger.h" #include "lldb/Host/OptionParser.h" +#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandOptionArgumentTable.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" @@ -147,9 +148,18 @@ class CommandObjectStatsDump : public CommandObjectParsed { if (!m_options.m_all_targets) target = m_exe_ctx.GetTargetPtr(); + // Check if transcript is requested but transcript saving is disabled + const StatisticsOptions &stats_options = m_options.GetStatisticsOptions(); + if (stats_options.GetIncludeTranscript() && + !GetDebugger().GetCommandInterpreter().GetSaveTranscript()) { + result.AppendWarning( + "transcript requested but none was saved. Enable with " + "'settings set interpreter.save-transcript true'"); + } + result.AppendMessageWithFormatv( - "{0:2}", DebuggerStats::ReportStatistics( - GetDebugger(), target, m_options.GetStatisticsOptions())); + "{0:2}", + DebuggerStats::ReportStatistics(GetDebugger(), target, stats_options)); result.SetStatus(eReturnStatusSuccessFinishResult); } >From bf19a2238d62dbdcc88fd5f0b8e60668eea628c9 Mon Sep 17 00:00:00 2001 From: Janet Yang <qx...@meta.com> Date: Wed, 25 Jun 2025 11:44:00 -0700 Subject: [PATCH 4/5] Add a unit test around warning msg --- .../commands/statistics/basic/TestStats.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lldb/test/API/commands/statistics/basic/TestStats.py b/lldb/test/API/commands/statistics/basic/TestStats.py index 138844586af7f..a406ca134d931 100644 --- a/lldb/test/API/commands/statistics/basic/TestStats.py +++ b/lldb/test/API/commands/statistics/basic/TestStats.py @@ -849,6 +849,30 @@ def test_transcript_happy_path(self): # The second "statistics dump" in the transcript should have no output self.assertNotIn("output", transcript[2]) + def test_transcript_warning_when_disabled(self): + """ + Test that "statistics dump --transcript=true" shows a warning when + transcript saving is disabled. + """ + self.build() + exe = self.getBuildArtifact("a.out") + target = self.createTestTarget(file_path=exe) + + # Ensure transcript saving is disabled (this is the default) + self.runCmd("settings set interpreter.save-transcript false") + + # Request transcript in statistics dump and check for warning + interpreter = self.dbg.GetCommandInterpreter() + res = lldb.SBCommandReturnObject() + interpreter.HandleCommand("statistics dump --transcript=true", res) + self.assertTrue(res.Succeeded()) + # We should warn about transcript being requested but not saved + self.assertIn( + "transcript requested but none was saved. Enable with " + "'settings set interpreter.save-transcript true'", + res.GetError() + ) + def verify_stats(self, stats, expectation, options): for field_name in expectation: idx = field_name.find(".") >From 105e48fcf91ad3df0ec3138a9b6a513e9ddd227d Mon Sep 17 00:00:00 2001 From: Janet Yang <qx...@meta.com> Date: Wed, 25 Jun 2025 11:59:05 -0700 Subject: [PATCH 5/5] Run lints --- lldb/test/API/commands/statistics/basic/TestStats.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/commands/statistics/basic/TestStats.py b/lldb/test/API/commands/statistics/basic/TestStats.py index a406ca134d931..e9ee8b8661e5a 100644 --- a/lldb/test/API/commands/statistics/basic/TestStats.py +++ b/lldb/test/API/commands/statistics/basic/TestStats.py @@ -857,10 +857,10 @@ def test_transcript_warning_when_disabled(self): self.build() exe = self.getBuildArtifact("a.out") target = self.createTestTarget(file_path=exe) - + # Ensure transcript saving is disabled (this is the default) self.runCmd("settings set interpreter.save-transcript false") - + # Request transcript in statistics dump and check for warning interpreter = self.dbg.GetCommandInterpreter() res = lldb.SBCommandReturnObject() @@ -870,7 +870,7 @@ def test_transcript_warning_when_disabled(self): self.assertIn( "transcript requested but none was saved. Enable with " "'settings set interpreter.save-transcript true'", - res.GetError() + res.GetError(), ) def verify_stats(self, stats, expectation, options): _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits