labath created this revision. labath added reviewers: teemperor, JDevlieghere. Herald added a reviewer: jdoerfert. Herald added a project: LLDB.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70241 Files: 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
Index: lldb/unittests/Utility/StreamTest.cpp =================================================================== --- lldb/unittests/Utility/StreamTest.cpp +++ lldb/unittests/Utility/StreamTest.cpp @@ -304,15 +304,6 @@ 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 Index: lldb/test/Shell/SymbolFile/DWARF/array-sizes.s =================================================================== --- lldb/test/Shell/SymbolFile/DWARF/array-sizes.s +++ 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];" Index: lldb/source/Utility/Stream.cpp =================================================================== --- lldb/source/Utility/Stream.cpp +++ lldb/source/Utility/Stream.cpp @@ -160,30 +160,6 @@ 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)); Index: lldb/source/Symbol/Variable.cpp =================================================================== --- lldb/source/Symbol/Variable.cpp +++ lldb/source/Symbol/Variable.cpp @@ -112,7 +112,7 @@ 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(')'); } Index: lldb/source/Symbol/Type.cpp =================================================================== --- lldb/source/Symbol/Type.cpp +++ lldb/source/Symbol/Type.cpp @@ -256,7 +256,7 @@ *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; Index: lldb/source/Symbol/SymbolContext.cpp =================================================================== --- lldb/source/Symbol/SymbolContext.cpp +++ lldb/source/Symbol/SymbolContext.cpp @@ -315,14 +315,14 @@ 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 @@ 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 @@ 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(); Index: lldb/source/Expression/DWARFExpression.cpp =================================================================== --- lldb/source/Expression/DWARFExpression.cpp +++ lldb/source/Expression/DWARFExpression.cpp @@ -146,7 +146,7 @@ // 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); } } Index: lldb/include/lldb/Utility/Stream.h =================================================================== --- lldb/include/lldb/Utility/Stream.h +++ lldb/include/lldb/Utility/Stream.h @@ -213,45 +213,10 @@ /// 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. ///
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits