aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorAlex Langford <alangford@apple.com>2023-02-16 18:17:59 -0800
committerAlex Langford <alangford@apple.com>2023-02-17 12:39:49 -0800
commit2f88c07cf820cff829dec5906d298fc7147af8dd (patch)
tree79122511baf9df2a36c65135675499551bacba62 /lldb/test/API/python_api
parent8caa8d95afe47db91d8a4e123ad2deac63d44754 (diff)
downloadllvm-2f88c07cf820cff829dec5906d298fc7147af8dd.zip
llvm-2f88c07cf820cff829dec5906d298fc7147af8dd.tar.gz
llvm-2f88c07cf820cff829dec5906d298fc7147af8dd.tar.bz2
[lldb] StructuredData should not truncate uint64_t values
In json::Value, getAsInteger returns an optional<int64_t> and getAsNumber returns an optional<double>. If a value is larger than what an int64_t can hold but smaller than what a uint64_t can hold, the getAsInteger function will fail but the getAsNumber will succeed. However, the value shouldn't be interpreted as a double. rdar://105556974 Differential Revision: https://reviews.llvm.org/D144238
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
index 7bbc0fe..0ab14c0 100644
--- a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
+++ b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
@@ -9,6 +9,7 @@ from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
+import json
class TestStructuredDataAPI(TestBase):
NO_DEBUG_INFO_TESTCASE = True
@@ -19,8 +20,15 @@ class TestStructuredDataAPI(TestBase):
def structured_data_api_test(self):
error = lldb.SBError()
s = lldb.SBStream()
- s.Print(
- "{\"key_dict\":{\"key_string\":\"STRING\",\"key_int\":3,\"key_float\":2.99,\"key_bool\":true,\"key_array\":[\"23\",\"arr\"]}}")
+
+ dict_str = json.dumps(
+ {"key_dict":
+ {"key_string":"STRING",
+ "key_uint":0xffffffff00000000,
+ "key_float":2.99,
+ "key_bool":True,
+ "key_array":["23","arr"]}})
+ s.Print(dict_str)
example = lldb.SBStructuredData()
# Check SetFromJSON API for dictionaries, integers, floating point
@@ -49,7 +57,7 @@ class TestStructuredDataAPI(TestBase):
self.string_struct_test(dict_struct)
# Tests for integer data type
- self.int_struct_test(dict_struct)
+ self.uint_struct_test(dict_struct)
# Tests for floating point data type
self.double_struct_test(dict_struct)
@@ -110,25 +118,27 @@ class TestStructuredDataAPI(TestBase):
str(output) +
" returned for a string object")
- def int_struct_test(self, dict_struct):
- # Check a valid SBStructuredData containing an 'integer' by
- int_struct = lldb.SBStructuredData()
- int_struct = dict_struct.GetValueForKey("key_int")
- if not int_struct.IsValid():
+ def uint_struct_test(self, dict_struct):
+ # Check a valid SBStructuredData containing an unsigned integer.
+ # We intentionally make this larger than what an int64_t can hold but
+ # still small enough to fit a uint64_t
+ uint_struct = lldb.SBStructuredData()
+ uint_struct = dict_struct.GetValueForKey("key_uint")
+ if not uint_struct.IsValid():
self.fail("A valid object should have been returned")
# Check Type API
- if not int_struct.GetType() == lldb.eStructuredDataTypeInteger:
- self.fail("Wrong type returned: " + str(int_struct.GetType()))
+ if not uint_struct.GetType() == lldb.eStructuredDataTypeInteger:
+ self.fail("Wrong type returned: " + str(uint_struct.GetType()))
# Check API returning 'integer' value
- output = int_struct.GetIntegerValue()
- if not output == 3:
+ output = uint_struct.GetIntegerValue()
+ if not output == 0xffffffff00000000:
self.fail("wrong output: " + str(output))
# Calling wrong API on a SBStructuredData
# (e.g. getting a string value from an integer type structure)
- output = int_struct.GetStringValue(25)
+ output = uint_struct.GetStringValue(25)
if output:
self.fail(
"Valid string " +