From f92756e9ec18720f0235f89d3eedbd0aff39db15 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 2 Sep 2016 10:58:52 +0000 Subject: [PATCH] Reapply "Make Scalar::GetValue more consistent" this is a resubmission of r280476. The problem with the original commit was that it was printing out all numbers as signed, which was wrong for unsigned numbers with the MSB set. Fix that and add a unit test covering that case. llvm-svn: 280480 --- .../functionalities/memory/find/TestMemoryFind.py | 1 - lldb/source/Core/Scalar.cpp | 8 ++--- lldb/unittests/Core/ScalarTest.cpp | 37 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py b/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py index b81cb7b..6cdf5bf 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py @@ -23,7 +23,6 @@ class MemoryFindTestCase(TestBase): # Find the line number to break inside main(). self.line = line_number('main.cpp', '// break here') - @expectedFailureAll(archs=["i386", "arm"]) def test_memory_find(self): """Test the 'memory find' command.""" self.build() diff --git a/lldb/source/Core/Scalar.cpp b/lldb/source/Core/Scalar.cpp index d3e9a75..ae0e216 100644 --- a/lldb/source/Core/Scalar.cpp +++ b/lldb/source/Core/Scalar.cpp @@ -308,18 +308,18 @@ Scalar::GetValue (Stream *s, bool show_type) const case e_void: break; case e_sint: - case e_ulong: + case e_slong: case e_slonglong: case e_sint128: case e_sint256: - s->Printf("%s",m_integer.toString(10,true).c_str()); + s->PutCString(m_integer.toString(10, true).c_str()); break; case e_uint: - case e_slong: + case e_ulong: case e_ulonglong: case e_uint128: case e_uint256: - s->Printf("%s",m_integer.toString(16,false).c_str()); + s->PutCString(m_integer.toString(10, false).c_str()); break; case e_float: case e_double: diff --git a/lldb/unittests/Core/ScalarTest.cpp b/lldb/unittests/Core/ScalarTest.cpp index bf85f8e..adff5b0 100644 --- a/lldb/unittests/Core/ScalarTest.cpp +++ b/lldb/unittests/Core/ScalarTest.cpp @@ -19,6 +19,7 @@ #include "lldb/Core/Scalar.h" #include "lldb/Core/DataExtractor.h" #include "lldb/Host/Endian.h" +#include "lldb/Core/StreamString.h" using namespace lldb_private; @@ -103,3 +104,39 @@ TEST(ScalarTest, ExtractBitfield) ASSERT_TRUE(u_scalar.ExtractBitfield(len - 4, 4)); ASSERT_EQ(0, memcmp(&b2, u_scalar.GetBytes(), sizeof(b2))); } + +template +static std::string +ScalarGetValue(T value) +{ + StreamString stream; + Scalar(value).GetValue(&stream, false); + return stream.GetString(); +} + +TEST(ScalarTest, GetValue) +{ + EXPECT_EQ("12345", ScalarGetValue(12345)); + EXPECT_EQ("-12345", ScalarGetValue(-12345)); + EXPECT_EQ("12345", ScalarGetValue(12345)); + EXPECT_EQ(std::to_string(std::numeric_limits::max()), + ScalarGetValue(std::numeric_limits::max())); + + EXPECT_EQ("12345", ScalarGetValue(12345)); + EXPECT_EQ("-12345", ScalarGetValue(-12345)); + EXPECT_EQ("12345", ScalarGetValue(12345)); + EXPECT_EQ(std::to_string(std::numeric_limits::max()), + ScalarGetValue(std::numeric_limits::max())); + + EXPECT_EQ("12345678", ScalarGetValue(12345678L)); + EXPECT_EQ("-12345678", ScalarGetValue(-12345678L)); + EXPECT_EQ("12345678", ScalarGetValue(12345678UL)); + EXPECT_EQ(std::to_string(std::numeric_limits::max()), + ScalarGetValue(std::numeric_limits::max())); + + EXPECT_EQ("1234567890123", ScalarGetValue(1234567890123LL)); + EXPECT_EQ("-1234567890123", ScalarGetValue(-1234567890123LL)); + EXPECT_EQ("1234567890123", ScalarGetValue(1234567890123ULL)); + EXPECT_EQ(std::to_string(std::numeric_limits::max()), + ScalarGetValue(std::numeric_limits::max())); +} -- 2.7.4