[Lldb-commits] [lldb] 4f728bf - [lldb][NFC] Use raw_ostream instead of Stream in Baton::GetDescription
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Mon Dec 2 04:27:40 PST 2019
Author: Raphael Isemann
Date: 2019-12-02T13:27:21+01:00
New Revision: 4f728bfc13c45bc744bfdbfc3086bed74a8cbb4c
URL: https://github.com/llvm/llvm-project/commit/4f728bfc13c45bc744bfdbfc3086bed74a8cbb4c
DIFF: https://github.com/llvm/llvm-project/commit/4f728bfc13c45bc744bfdbfc3086bed74a8cbb4c.diff
LOG: [lldb][NFC] Use raw_ostream instead of Stream in Baton::GetDescription
Removing raw_ostream here is getting us closer to removing LLDB's Stream
class.
Added:
Modified:
lldb/include/lldb/Breakpoint/BreakpointOptions.h
lldb/include/lldb/Breakpoint/WatchpointOptions.h
lldb/include/lldb/Utility/Baton.h
lldb/source/Breakpoint/BreakpointOptions.cpp
lldb/source/Breakpoint/WatchpointOptions.cpp
lldb/source/Commands/CommandObjectBreakpointCommand.cpp
lldb/source/Commands/CommandObjectWatchpointCommand.cpp
lldb/source/Utility/Baton.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Breakpoint/BreakpointOptions.h b/lldb/include/lldb/Breakpoint/BreakpointOptions.h
index 9e02afff5227..2c52170eb9f6 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointOptions.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointOptions.h
@@ -88,7 +88,8 @@ friend class Breakpoint;
explicit CommandBaton(std::unique_ptr<CommandData> Data)
: TypedBaton(std::move(Data)) {}
- void GetDescription(Stream *s, lldb::DescriptionLevel level) const override;
+ void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level,
+ unsigned indentation) const override;
};
typedef std::shared_ptr<CommandBaton> CommandBatonSP;
diff --git a/lldb/include/lldb/Breakpoint/WatchpointOptions.h b/lldb/include/lldb/Breakpoint/WatchpointOptions.h
index b395dde21901..0dc34d4ebef7 100644
--- a/lldb/include/lldb/Breakpoint/WatchpointOptions.h
+++ b/lldb/include/lldb/Breakpoint/WatchpointOptions.h
@@ -180,7 +180,8 @@ class WatchpointOptions {
CommandBaton(std::unique_ptr<CommandData> Data)
: TypedBaton(std::move(Data)) {}
- void GetDescription(Stream *s, lldb::DescriptionLevel level) const override;
+ void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level,
+ unsigned indentation) const override;
};
protected:
diff --git a/lldb/include/lldb/Utility/Baton.h b/lldb/include/lldb/Utility/Baton.h
index 4050f2af2bf0..c42867489c65 100644
--- a/lldb/include/lldb/Utility/Baton.h
+++ b/lldb/include/lldb/Utility/Baton.h
@@ -12,6 +12,8 @@
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-public.h"
+#include "llvm/Support/raw_ostream.h"
+
#include <memory>
namespace lldb_private {
@@ -37,8 +39,9 @@ class Baton {
virtual void *data() = 0;
- virtual void GetDescription(Stream *s,
- lldb::DescriptionLevel level) const = 0;
+ virtual void GetDescription(llvm::raw_ostream &s,
+ lldb::DescriptionLevel level,
+ unsigned indentation) const = 0;
};
class UntypedBaton : public Baton {
@@ -50,7 +53,8 @@ class UntypedBaton : public Baton {
}
void *data() override { return m_data; }
- void GetDescription(Stream *s, lldb::DescriptionLevel level) const override;
+ void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level,
+ unsigned indentation) const override;
void *m_data; // Leave baton public for easy access
};
@@ -63,7 +67,8 @@ template <typename T> class TypedBaton : public Baton {
const T *getItem() const { return Item.get(); }
void *data() override { return Item.get(); }
- void GetDescription(Stream *s, lldb::DescriptionLevel level) const override {}
+ void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level,
+ unsigned indentation) const override {}
protected:
std::unique_ptr<T> Item;
diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp b/lldb/source/Breakpoint/BreakpointOptions.cpp
index 0d4c6173c3c5..8fd16f420c04 100644
--- a/lldb/source/Breakpoint/BreakpointOptions.cpp
+++ b/lldb/source/Breakpoint/BreakpointOptions.cpp
@@ -566,7 +566,8 @@ void BreakpointOptions::GetDescription(Stream *s,
if (m_callback_baton_sp.get()) {
if (level != eDescriptionLevelBrief) {
s->EOL();
- m_callback_baton_sp->GetDescription(s, level);
+ m_callback_baton_sp->GetDescription(s->AsRawOstream(), level,
+ s->GetIndentLevel());
}
}
if (!m_condition_text.empty()) {
@@ -578,35 +579,33 @@ void BreakpointOptions::GetDescription(Stream *s,
}
void BreakpointOptions::CommandBaton::GetDescription(
- Stream *s, lldb::DescriptionLevel level) const {
+ llvm::raw_ostream &s, lldb::DescriptionLevel level,
+ unsigned indentation) const {
const CommandData *data = getItem();
if (level == eDescriptionLevelBrief) {
- s->Printf(", commands = %s",
- (data && data->user_source.GetSize() > 0) ? "yes" : "no");
+ s << ", commands = "
+ << ((data && data->user_source.GetSize() > 0) ? "yes" : "no");
return;
}
- s->IndentMore();
- s->Indent("Breakpoint commands");
+ indentation += 2;
+ s.indent(indentation);
+ s << "Breakpoint commands";
if (data->interpreter != eScriptLanguageNone)
- s->Printf(" (%s):\n",
- ScriptInterpreter::LanguageToString(data->interpreter).c_str());
+ s << llvm::formatv(" ({0}):\n",
+ ScriptInterpreter::LanguageToString(data->interpreter));
else
- s->PutCString(":\n");
+ s << ":\n";
- s->IndentMore();
+ indentation += 2;
if (data && data->user_source.GetSize() > 0) {
- const size_t num_strings = data->user_source.GetSize();
- for (size_t i = 0; i < num_strings; ++i) {
- s->Indent(data->user_source.GetStringAtIndex(i));
- s->EOL();
+ for (llvm::StringRef str : data->user_source) {
+ s.indent(indentation);
+ s << str << "\n";
}
- } else {
- s->PutCString("No commands.\n");
- }
- s->IndentLess();
- s->IndentLess();
+ } else
+ s << "No commands.\n";
}
void BreakpointOptions::SetCommandDataCallback(
diff --git a/lldb/source/Breakpoint/WatchpointOptions.cpp b/lldb/source/Breakpoint/WatchpointOptions.cpp
index cd5ef930e5dc..026bf2f746ae 100644
--- a/lldb/source/Breakpoint/WatchpointOptions.cpp
+++ b/lldb/source/Breakpoint/WatchpointOptions.cpp
@@ -121,7 +121,8 @@ void WatchpointOptions::GetCallbackDescription(
Stream *s, lldb::DescriptionLevel level) const {
if (m_callback_baton_sp.get()) {
s->EOL();
- m_callback_baton_sp->GetDescription(s, level);
+ m_callback_baton_sp->GetDescription(s->AsRawOstream(), level,
+ s->GetIndentLevel());
}
}
@@ -156,27 +157,26 @@ void WatchpointOptions::GetDescription(Stream *s,
}
void WatchpointOptions::CommandBaton::GetDescription(
- Stream *s, lldb::DescriptionLevel level) const {
+ llvm::raw_ostream &s, lldb::DescriptionLevel level,
+ unsigned indentation) const {
const CommandData *data = getItem();
if (level == eDescriptionLevelBrief) {
- s->Printf(", commands = %s",
- (data && data->user_source.GetSize() > 0) ? "yes" : "no");
+ s << ", commands = %s"
+ << ((data && data->user_source.GetSize() > 0) ? "yes" : "no");
return;
}
- s->IndentMore();
- s->Indent("watchpoint commands:\n");
+ indentation += 2;
+ s.indent(indentation);
+ s << "watchpoint commands:\n";
- s->IndentMore();
+ indentation += 2;
if (data && data->user_source.GetSize() > 0) {
for (const std::string &line : data->user_source) {
- s->Indent(line);
- s->EOL();
+ s.indent(indentation);
+ s << line << "\n";
}
- } else {
- s->PutCString("No commands.\n");
- }
- s->IndentLess();
- s->IndentLess();
+ } else
+ s << "No commands.\n";
}
diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
index 1a4432149f73..a82e70a1cdab 100644
--- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -674,10 +674,10 @@ class CommandObjectBreakpointCommandList : public CommandObjectParsed {
if (baton) {
result.GetOutputStream().Printf("Breakpoint %s:\n",
id_str.GetData());
- result.GetOutputStream().IndentMore();
- baton->GetDescription(&result.GetOutputStream(),
- eDescriptionLevelFull);
- result.GetOutputStream().IndentLess();
+ baton->GetDescription(result.GetOutputStream().AsRawOstream(),
+ eDescriptionLevelFull,
+ result.GetOutputStream().GetIndentLevel() +
+ 2);
} else {
result.AppendMessageWithFormat(
"Breakpoint %s does not have an associated command.\n",
diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
index 5683381efc85..92a91cfac220 100644
--- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
@@ -611,10 +611,10 @@ class CommandObjectWatchpointCommandList : public CommandObjectParsed {
const Baton *baton = wp_options->GetBaton();
if (baton) {
result.GetOutputStream().Printf("Watchpoint %u:\n", cur_wp_id);
- result.GetOutputStream().IndentMore();
- baton->GetDescription(&result.GetOutputStream(),
- eDescriptionLevelFull);
- result.GetOutputStream().IndentLess();
+ baton->GetDescription(result.GetOutputStream().AsRawOstream(),
+ eDescriptionLevelFull,
+ result.GetOutputStream().GetIndentLevel() +
+ 2);
} else {
result.AppendMessageWithFormat(
"Watchpoint %u does not have an associated command.\n",
diff --git a/lldb/source/Utility/Baton.cpp b/lldb/source/Utility/Baton.cpp
index 84e295e24686..7bba10dcec96 100644
--- a/lldb/source/Utility/Baton.cpp
+++ b/lldb/source/Utility/Baton.cpp
@@ -8,5 +8,6 @@
#include "lldb/Utility/Baton.h"
-void lldb_private::UntypedBaton::GetDescription(
- Stream *s, lldb::DescriptionLevel level) const {}
+void lldb_private::UntypedBaton::GetDescription(llvm::raw_ostream &s,
+ lldb::DescriptionLevel level,
+ unsigned indentation) const {}
More information about the lldb-commits
mailing list