From 008ec446440646ac154a15dc1f4a3cb2160f7295 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 10 Aug 2016 23:25:57 +0000 Subject: Fix a problem where if a uint64_t value is placed into a python dictionary and sent up to LLDB and converted to StructuredData, it would not be able to parse the full 64 bit value. A number like 0xf000000000000000L could be placed into a dictionary, and sent to LLDB and it would end up being 0xffffffffffffffff since it would overflow a int64_t. We leave the old code there, but if it overflows, we treat the number like a uint64_t and get it to decode correctly. Added a gtest to cover this so we don't regress. I verified the gtest failed prior to the fix, and it succeeds after it. llvm-svn: 278304 --- .../Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index b460ab5..2bc7515 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -624,7 +624,18 @@ PythonInteger::GetInteger() const { assert(PyLong_Check(m_py_obj) && "PythonInteger::GetInteger has a PyObject that isn't a PyLong"); - return PyLong_AsLongLong(m_py_obj); + int overflow = 0; + int64_t result = PyLong_AsLongLongAndOverflow(m_py_obj, &overflow); + if (overflow != 0) + { + // We got an integer that overflows, like 18446744072853913392L + // we can't use PyLong_AsLongLong() as it will return + // 0xffffffffffffffff. If we use the unsigned long long + // it will work as expected. + const uint64_t uval = PyLong_AsUnsignedLongLong(m_py_obj); + result = *((int64_t *)&uval); + } + return result; } return UINT64_MAX; } -- cgit v1.1