[Lldb-commits] [lldb] b709149 - [lldb][NFCI] Target::StopHook::GetDescription should take a Stream ref instead of pointer

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 3 11:45:26 PDT 2023


Author: Alex Langford
Date: 2023-07-03T11:39:38-07:00
New Revision: b709149b76277e8bea4a3d7977ccb4e818499b7b

URL: https://github.com/llvm/llvm-project/commit/b709149b76277e8bea4a3d7977ccb4e818499b7b
DIFF: https://github.com/llvm/llvm-project/commit/b709149b76277e8bea4a3d7977ccb4e818499b7b.diff

LOG: [lldb][NFCI] Target::StopHook::GetDescription should take a Stream ref instead of pointer

We always assume that this is valid anyway, might as well take a
reference.

Differential Revision: https://reviews.llvm.org/D153917

Added: 
    

Modified: 
    lldb/include/lldb/Target/Target.h
    lldb/source/Commands/CommandCompletions.cpp
    lldb/source/Commands/CommandObjectTarget.cpp
    lldb/source/Target/Target.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index eb5e87dcacb395..50cd315b0fdfa7 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1310,8 +1310,8 @@ class Target : public std::enable_shared_from_this<Target>,
 
     bool GetAutoContinue() const { return m_auto_continue; }
 
-    void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
-    virtual void GetSubclassDescription(Stream *s,
+    void GetDescription(Stream &s, lldb::DescriptionLevel level) const;
+    virtual void GetSubclassDescription(Stream &s,
                                         lldb::DescriptionLevel level) const = 0;
 
   protected:
@@ -1334,7 +1334,7 @@ class Target : public std::enable_shared_from_this<Target>,
 
     StopHookResult HandleStop(ExecutionContext &exc_ctx,
                               lldb::StreamSP output_sp) override;
-    void GetSubclassDescription(Stream *s,
+    void GetSubclassDescription(Stream &s,
                                 lldb::DescriptionLevel level) const override;
 
   private:
@@ -1356,7 +1356,7 @@ class Target : public std::enable_shared_from_this<Target>,
     Status SetScriptCallback(std::string class_name,
                              StructuredData::ObjectSP extra_args_sp);
 
-    void GetSubclassDescription(Stream *s,
+    void GetSubclassDescription(Stream &s,
                                 lldb::DescriptionLevel level) const override;
 
   private:

diff  --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index 35237d419d469b..dad63b6aaa1744 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -754,7 +754,7 @@ void CommandCompletions::StopHookIDs(CommandInterpreter &interpreter,
     // neater.
     strm.SetIndentLevel(11);
     const Target::StopHookSP stophook_sp = target_sp->GetStopHookAtIndex(idx);
-    stophook_sp->GetDescription(&strm, lldb::eDescriptionLevelInitial);
+    stophook_sp->GetDescription(strm, lldb::eDescriptionLevelInitial);
     request.TryCompleteCurrentArg(std::to_string(stophook_sp->GetID()),
                                   strm.GetString());
   }

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 22045948f88ba9..b186c8e6c1ab8f 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -5057,7 +5057,7 @@ class CommandObjectTargetStopHookList : public CommandObjectParsed {
         Target::StopHookSP this_hook = target.GetStopHookAtIndex(i);
         if (i > 0)
           result.GetOutputStream().PutCString("\n");
-        this_hook->GetDescription(&(result.GetOutputStream()),
+        this_hook->GetDescription(result.GetOutputStream(),
                                   eDescriptionLevelFull);
       }
     }

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 17181569cbca29..d9cd0f0a3d1570 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -2892,7 +2892,7 @@ bool Target::RunStopHooks() {
 
       if (print_hook_header && !any_thread_matched) {
         StreamString s;
-        cur_hook_sp->GetDescription(&s, eDescriptionLevelBrief);
+        cur_hook_sp->GetDescription(s, eDescriptionLevelBrief);
         if (s.GetSize() != 0)
           output_sp->Printf("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(),
                             s.GetData());
@@ -3651,7 +3651,7 @@ bool Target::StopHook::ExecutionContextPasses(const ExecutionContext &exc_ctx) {
   return will_run;
 }
 
-void Target::StopHook::GetDescription(Stream *s,
+void Target::StopHook::GetDescription(Stream &s,
                                       lldb::DescriptionLevel level) const {
 
   // For brief descriptions, only print the subclass description:
@@ -3660,55 +3660,55 @@ void Target::StopHook::GetDescription(Stream *s,
     return;
   }
 
-  unsigned indent_level = s->GetIndentLevel();
+  unsigned indent_level = s.GetIndentLevel();
 
-  s->SetIndentLevel(indent_level + 2);
+  s.SetIndentLevel(indent_level + 2);
 
-  s->Printf("Hook: %" PRIu64 "\n", GetID());
+  s.Printf("Hook: %" PRIu64 "\n", GetID());
   if (m_active)
-    s->Indent("State: enabled\n");
+    s.Indent("State: enabled\n");
   else
-    s->Indent("State: disabled\n");
+    s.Indent("State: disabled\n");
 
   if (m_auto_continue)
-    s->Indent("AutoContinue on\n");
+    s.Indent("AutoContinue on\n");
 
   if (m_specifier_sp) {
-    s->Indent();
-    s->PutCString("Specifier:\n");
-    s->SetIndentLevel(indent_level + 4);
-    m_specifier_sp->GetDescription(s, level);
-    s->SetIndentLevel(indent_level + 2);
+    s.Indent();
+    s.PutCString("Specifier:\n");
+    s.SetIndentLevel(indent_level + 4);
+    m_specifier_sp->GetDescription(&s, level);
+    s.SetIndentLevel(indent_level + 2);
   }
 
   if (m_thread_spec_up) {
     StreamString tmp;
-    s->Indent("Thread:\n");
+    s.Indent("Thread:\n");
     m_thread_spec_up->GetDescription(&tmp, level);
-    s->SetIndentLevel(indent_level + 4);
-    s->Indent(tmp.GetString());
-    s->PutCString("\n");
-    s->SetIndentLevel(indent_level + 2);
+    s.SetIndentLevel(indent_level + 4);
+    s.Indent(tmp.GetString());
+    s.PutCString("\n");
+    s.SetIndentLevel(indent_level + 2);
   }
   GetSubclassDescription(s, level);
 }
 
 void Target::StopHookCommandLine::GetSubclassDescription(
-    Stream *s, lldb::DescriptionLevel level) const {
+    Stream &s, lldb::DescriptionLevel level) const {
   // The brief description just prints the first command.
   if (level == eDescriptionLevelBrief) {
     if (m_commands.GetSize() == 1)
-      s->PutCString(m_commands.GetStringAtIndex(0));
+      s.PutCString(m_commands.GetStringAtIndex(0));
     return;
   }
-  s->Indent("Commands: \n");
-  s->SetIndentLevel(s->GetIndentLevel() + 4);
+  s.Indent("Commands: \n");
+  s.SetIndentLevel(s.GetIndentLevel() + 4);
   uint32_t num_commands = m_commands.GetSize();
   for (uint32_t i = 0; i < num_commands; i++) {
-    s->Indent(m_commands.GetStringAtIndex(i));
-    s->PutCString("\n");
+    s.Indent(m_commands.GetStringAtIndex(i));
+    s.PutCString("\n");
   }
-  s->SetIndentLevel(s->GetIndentLevel() - 4);
+  s.SetIndentLevel(s.GetIndentLevel() - 4);
 }
 
 // Target::StopHookCommandLine
@@ -3796,13 +3796,13 @@ Target::StopHookScripted::HandleStop(ExecutionContext &exc_ctx,
 }
 
 void Target::StopHookScripted::GetSubclassDescription(
-    Stream *s, lldb::DescriptionLevel level) const {
+    Stream &s, lldb::DescriptionLevel level) const {
   if (level == eDescriptionLevelBrief) {
-    s->PutCString(m_class_name);
+    s.PutCString(m_class_name);
     return;
   }
-  s->Indent("Class:");
-  s->Printf("%s\n", m_class_name.c_str());
+  s.Indent("Class:");
+  s.Printf("%s\n", m_class_name.c_str());
 
   // Now print the extra args:
   // FIXME: We should use StructuredData.GetDescription on the m_extra_args
@@ -3821,20 +3821,20 @@ void Target::StopHookScripted::GetSubclassDescription(
   if (num_keys == 0)
     return;
 
-  s->Indent("Args:\n");
-  s->SetIndentLevel(s->GetIndentLevel() + 4);
+  s.Indent("Args:\n");
+  s.SetIndentLevel(s.GetIndentLevel() + 4);
 
   auto print_one_element = [&s](ConstString key,
                                 StructuredData::Object *object) {
-    s->Indent();
-    s->Printf("%s : %s\n", key.GetCString(),
+    s.Indent();
+    s.Printf("%s : %s\n", key.GetCString(),
               object->GetStringValue().str().c_str());
     return true;
   };
 
   as_dict->ForEach(print_one_element);
 
-  s->SetIndentLevel(s->GetIndentLevel() - 4);
+  s.SetIndentLevel(s.GetIndentLevel() - 4);
 }
 
 static constexpr OptionEnumValueElement g_dynamic_value_types[] = {


        


More information about the lldb-commits mailing list