[Lldb-commits] [lldb] 957d9a0 - [lldb] remove unsigned Stream::operator<< overloads
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 26 05:28:29 PST 2019
Author: Pavel Labath
Date: 2019-11-26T14:24:28+01:00
New Revision: 957d9a0335b8199b01caec56574e72154c3a1226
URL: https://github.com/llvm/llvm-project/commit/957d9a0335b8199b01caec56574e72154c3a1226
DIFF: https://github.com/llvm/llvm-project/commit/957d9a0335b8199b01caec56574e72154c3a1226.diff
LOG: [lldb] remove unsigned Stream::operator<< overloads
Summary:
I recently re-discovered that the unsinged stream operators of the
lldb_private::Stream class have a surprising behavior in that they print
the number in hex. This is all the more confusing because the "signed"
versions of those operators behave normally.
Now that, thanks to Raphael, each Stream class has a llvm::raw_ostream
wrapper, I think we should delete most of our formatting capabilities
and just delegate to that. This patch tests the water by just deleting
the operators with the most surprising behavior.
Most of the code using these operators was printing user_id_t values. It
wasn't fully consistent about prefixing them with "0x", but I've tried
to consistenly print it without that prefix, to make it more obviously
different from pointer values.
Reviewers: teemperor, JDevlieghere, jdoerfert
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D70241
Added:
Modified:
lldb/include/lldb/Utility/Stream.h
lldb/source/Expression/DWARFExpression.cpp
lldb/source/Symbol/SymbolContext.cpp
lldb/source/Symbol/Type.cpp
lldb/source/Symbol/Variable.cpp
lldb/source/Utility/Stream.cpp
lldb/test/Shell/SymbolFile/DWARF/array-sizes.s
lldb/unittests/Utility/StreamTest.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Utility/Stream.h b/lldb/include/lldb/Utility/Stream.h
index 414f92177303..88cdb88d77ad 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -213,45 +213,10 @@ class Stream {
/// in one statement.
Stream &operator<<(char ch);
- /// Output a uint8_t \a uval to the stream \a s.
- ///
- /// \param[in] uval
- /// A uint8_t value.
- ///
- /// \return
- /// A reference to this class so multiple things can be streamed
- /// in one statement.
- Stream &operator<<(uint8_t uval);
-
- /// Output a uint16_t \a uval to the stream \a s.
- ///
- /// \param[in] uval
- /// A uint16_t value.
- ///
- /// \return
- /// A reference to this class so multiple things can be streamed
- /// in one statement.
- Stream &operator<<(uint16_t uval);
-
- /// Output a uint32_t \a uval to the stream \a s.
- ///
- /// \param[in] uval
- /// A uint32_t value.
- ///
- /// \return
- /// A reference to this class so multiple things can be streamed
- /// in one statement.
- Stream &operator<<(uint32_t uval);
-
- /// Output a uint64_t \a uval to the stream \a s.
- ///
- /// \param[in] uval
- /// A uint64_t value.
- ///
- /// \return
- /// A reference to this class so multiple things can be streamed
- /// in one statement.
- Stream &operator<<(uint64_t uval);
+ Stream &operator<<(uint8_t uval) = delete;
+ Stream &operator<<(uint16_t uval) = delete;
+ Stream &operator<<(uint32_t uval) = delete;
+ Stream &operator<<(uint64_t uval) = delete;
/// Output a int8_t \a sval to the stream \a s.
///
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
index a063da0f4e40..8947500959cb 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -146,7 +146,7 @@ void DWARFExpression::GetDescription(Stream *s, lldb::DescriptionLevel level,
// We have a new base address
if (count > 0)
s->PutCString(", ");
- *s << "base_addr = " << end_addr_offset;
+ s->Format("base_addr = {0:x}", end_addr_offset);
}
}
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 7828ca613359..c5d8547b08c8 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -315,14 +315,14 @@ void SymbolContext::Dump(Stream *s, Target *target) const {
s->Indent();
*s << "CompileUnit = " << comp_unit;
if (comp_unit != nullptr)
- *s << " {0x" << comp_unit->GetID() << "} "
- << *(static_cast<FileSpec *>(comp_unit));
+ s->Format(" {{{0:x-16}} {1}", comp_unit->GetID(),
+ *static_cast<FileSpec *>(comp_unit));
s->EOL();
s->Indent();
*s << "Function = " << function;
if (function != nullptr) {
- *s << " {0x" << function->GetID() << "} " << function->GetType()->GetName()
- << ", address-range = ";
+ s->Format(" {{{0:x-16}} {1}, address-range = ", function->GetID(),
+ function->GetType()->GetName());
function->GetAddressRange().Dump(s, target, Address::DumpStyleLoadAddress,
Address::DumpStyleModuleWithFileAddress);
s->EOL();
@@ -337,10 +337,7 @@ void SymbolContext::Dump(Stream *s, Target *target) const {
s->Indent();
*s << "Block = " << block;
if (block != nullptr)
- *s << " {0x" << block->GetID() << '}';
- // Dump the block and pass it a negative depth to we print all the parent
- // blocks if (block != NULL)
- // block->Dump(s, function->GetFileAddress(), INT_MIN);
+ s->Format(" {{{0:x-16}}", block->GetID());
s->EOL();
s->Indent();
*s << "LineEntry = ";
@@ -354,7 +351,8 @@ void SymbolContext::Dump(Stream *s, Target *target) const {
s->EOL();
*s << "Variable = " << variable;
if (variable != nullptr) {
- *s << " {0x" << variable->GetID() << "} " << variable->GetType()->GetName();
+ s->Format(" {{{0:x-16}} {1}", variable->GetID(),
+ variable->GetType()->GetName());
s->EOL();
}
s->IndentLess();
diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index c3e5c0370951..6465ce3dd156 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -255,7 +255,7 @@ void Type::Dump(Stream *s, bool show_context) {
*s << ", compiler_type = " << m_compiler_type.GetOpaqueQualType() << ' ';
GetForwardCompilerType().DumpTypeDescription(s);
} else if (m_encoding_uid != LLDB_INVALID_UID) {
- *s << ", type_data = " << (uint64_t)m_encoding_uid;
+ s->Format(", type_data = {0:x-16}", m_encoding_uid);
switch (m_encoding_uid_type) {
case eEncodingInvalid:
break;
diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 427dbf459c4e..a2eeaa1d2a5b 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -112,7 +112,7 @@ void Variable::Dump(Stream *s, bool show_context) const {
if (m_symfile_type_sp) {
Type *type = m_symfile_type_sp->GetType();
if (type) {
- *s << ", type = {" << type->GetID() << "} " << (void *)type << " (";
+ s->Format(", type = {{{0:x-16}} {1} (", type->GetID(), type);
type->DumpTypeName(s);
s->PutChar(')');
}
diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp
index c48a12acd906..991f7e924d8d 100644
--- a/lldb/source/Utility/Stream.cpp
+++ b/lldb/source/Utility/Stream.cpp
@@ -160,30 +160,6 @@ Stream &Stream::operator<<(const void *p) {
return *this;
}
-// Stream a uint8_t "uval" out to this stream.
-Stream &Stream::operator<<(uint8_t uval) {
- PutHex8(uval);
- return *this;
-}
-
-// Stream a uint16_t "uval" out to this stream.
-Stream &Stream::operator<<(uint16_t uval) {
- PutHex16(uval, m_byte_order);
- return *this;
-}
-
-// Stream a uint32_t "uval" out to this stream.
-Stream &Stream::operator<<(uint32_t uval) {
- PutHex32(uval, m_byte_order);
- return *this;
-}
-
-// Stream a uint64_t "uval" out to this stream.
-Stream &Stream::operator<<(uint64_t uval) {
- PutHex64(uval, m_byte_order);
- return *this;
-}
-
// Stream a int8_t "sval" out to this stream.
Stream &Stream::operator<<(int8_t sval) {
Printf("%i", static_cast<int>(sval));
diff --git a/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s b/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s
index f00fe2ad005d..b810527b5535 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s
+++ b/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s
@@ -10,7 +10,7 @@
# RUN: lldb-test symbols %t | FileCheck %s
# CHECK: Variable{0x7fffffff0000001e}, name = "X"
-# CHECK-SAME: type = {7fffffff00000033} 0x{{[0-9a-f]*}} (char [56])
+# CHECK-SAME: type = {7fffffff00000033} 0x{{[0-9A-F]*}} (char [56])
# Generated from "char X[47];"
diff --git a/lldb/unittests/Utility/StreamTest.cpp b/lldb/unittests/Utility/StreamTest.cpp
index 2e2bcb344fcd..40a1601b976e 100644
--- a/lldb/unittests/Utility/StreamTest.cpp
+++ b/lldb/unittests/Utility/StreamTest.cpp
@@ -304,15 +304,6 @@ TEST_F(StreamTest, ShiftOperatorInts) {
EXPECT_EQ("127 32767 2147483647 9223372036854775807", TakeValue());
}
-TEST_F(StreamTest, ShiftOperatorUInts) {
- s << std::numeric_limits<uint8_t>::max() << " ";
- s << std::numeric_limits<uint16_t>::max() << " ";
- s << std::numeric_limits<uint32_t>::max() << " ";
- s << std::numeric_limits<uint64_t>::max();
- EXPECT_EQ(33U, s.GetWrittenBytes());
- EXPECT_EQ("ff ffff ffffffff ffffffffffffffff", TakeValue());
-}
-
TEST_F(StreamTest, ShiftOperatorPtr) {
// This test is a bit tricky because pretty much everything related to
// pointer printing seems to lead to UB or IB. So let's make the most basic
More information about the lldb-commits
mailing list