[Lldb-commits] [lldb] r147702 - in /lldb/trunk: include/lldb/API/SBData.h include/lldb/API/SBProcess.h scripts/Python/interface/SBData.i scripts/Python/interface/SBProcess.i source/API/SBData.cpp source/API/SBProcess.cpp test/python_api/sbdata/TestSBData.py
Greg Clayton
gclayton at apple.com
Fri Jan 6 16:45:50 PST 2012
Author: gclayton
Date: Fri Jan 6 18:45:50 2012
New Revision: 147702
URL: http://llvm.org/viewvc/llvm-project?rev=147702&view=rev
Log:
Patch from Enrico Granata that moves SBData related functions into the SBData
class instead of requiring a live process in order to be able to create useful
SBData objects.
Modified:
lldb/trunk/include/lldb/API/SBData.h
lldb/trunk/include/lldb/API/SBProcess.h
lldb/trunk/scripts/Python/interface/SBData.i
lldb/trunk/scripts/Python/interface/SBProcess.i
lldb/trunk/source/API/SBData.cpp
lldb/trunk/source/API/SBProcess.cpp
lldb/trunk/test/python_api/sbdata/TestSBData.py
Modified: lldb/trunk/include/lldb/API/SBData.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBData.h?rev=147702&r1=147701&r2=147702&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBData.h (original)
+++ lldb/trunk/include/lldb/API/SBData.h Fri Jan 6 18:45:50 2012
@@ -33,6 +33,9 @@
GetAddressByteSize ();
void
+ SetAddressByteSize (uint8_t addr_byte_size);
+
+ void
Clear ();
bool
@@ -44,6 +47,9 @@
lldb::ByteOrder
GetByteOrder();
+ void
+ SetByteOrder (lldb::ByteOrder endian);
+
float
GetFloat (lldb::SBError& error, uint32_t offset);
@@ -96,11 +102,50 @@
// inferred from the existing DataExtractor, but having two SetData() signatures triggers a SWIG bug where
// the typemap isn't applied before resolving the overload, and thus the right function never gets called
void
- SetData(lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
+ SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
// see SetData() for why we don't have Append(const void* buf, size_t size)
bool
- Append(const SBData& rhs);
+ Append (const SBData& rhs);
+
+ static lldb::SBData
+ CreateDataFromCString (lldb::ByteOrder endian, uint32_t addr_byte_size, const char* data);
+
+ // in the following CreateData*() and SetData*() prototypes, the two parameters array and array_len
+ // should not be renamed or rearranged, because doing so will break the SWIG typemap
+ static lldb::SBData
+ CreateDataFromUInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint64_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromUInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint32_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromSInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int64_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromSInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int32_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromDoubleArray (lldb::ByteOrder endian, uint32_t addr_byte_size, double* array, size_t array_len);
+
+ bool
+ SetDataFromCString (const char* data);
+
+ bool
+ SetDataFromUInt64Array (uint64_t* array, size_t array_len);
+
+ bool
+ SetDataFromUInt32Array (uint32_t* array, size_t array_len);
+
+ bool
+ SetDataFromSInt64Array (int64_t* array, size_t array_len);
+
+ bool
+ SetDataFromSInt32Array (int32_t* array, size_t array_len);
+
+ bool
+ SetDataFromDoubleArray (double* array, size_t array_len);
+
protected:
Modified: lldb/trunk/include/lldb/API/SBProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=147702&r1=147701&r2=147702&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBProcess.h (original)
+++ lldb/trunk/include/lldb/API/SBProcess.h Fri Jan 6 18:45:50 2012
@@ -186,24 +186,6 @@
lldb::SBError
UnloadImage (uint32_t image_token);
- lldb::SBData
- GetDataFromCString(const char* data);
-
- lldb::SBData
- GetDataFromUnsignedInt64Array(uint64_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromUnsignedInt32Array(uint32_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromSignedInt64Array(int64_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromSignedInt32Array(int32_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromDoubleArray(double* array, size_t array_len);
-
protected:
friend class SBAddress;
friend class SBBreakpoint;
Modified: lldb/trunk/scripts/Python/interface/SBData.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBData.i?rev=147702&r1=147701&r2=147702&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBData.i (original)
+++ lldb/trunk/scripts/Python/interface/SBData.i Fri Jan 6 18:45:50 2012
@@ -22,6 +22,9 @@
uint8_t
GetAddressByteSize ();
+
+ void
+ SetAddressByteSize (uint8_t addr_byte_size);
void
Clear ();
@@ -34,6 +37,9 @@
lldb::ByteOrder
GetByteOrder();
+
+ void
+ SetByteOrder (lldb::ByteOrder endian);
float
GetFloat (lldb::SBError& error, uint32_t offset);
@@ -84,11 +90,48 @@
size_t size);
void
- SetData(lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
+ SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
bool
- Append(const SBData& rhs);
-
+ Append (const SBData& rhs);
+
+ static lldb::SBData
+ CreateDataFromCString (lldb::ByteOrder endian, uint32_t addr_byte_size, const char* data);
+
+ // in the following CreateData*() and SetData*() prototypes, the two parameters array and array_len
+ // should not be renamed or rearranged, because doing so will break the SWIG typemap
+ static lldb::SBData
+ CreateDataFromUInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint64_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromUInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint32_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromSInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int64_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromSInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int32_t* array, size_t array_len);
+
+ static lldb::SBData
+ CreateDataFromDoubleArray (lldb::ByteOrder endian, uint32_t addr_byte_size, double* array, size_t array_len);
+
+ bool
+ SetDataFromCString (const char* data);
+
+ bool
+ SetDataFromUInt64Array (uint64_t* array, size_t array_len);
+
+ bool
+ SetDataFromUInt32Array (uint32_t* array, size_t array_len);
+
+ bool
+ SetDataFromSInt64Array (int64_t* array, size_t array_len);
+
+ bool
+ SetDataFromSInt32Array (int32_t* array, size_t array_len);
+
+ bool
+ SetDataFromDoubleArray (double* array, size_t array_len);
};
Modified: lldb/trunk/scripts/Python/interface/SBProcess.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBProcess.i?rev=147702&r1=147701&r2=147702&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBProcess.i (original)
+++ lldb/trunk/scripts/Python/interface/SBProcess.i Fri Jan 6 18:45:50 2012
@@ -281,24 +281,6 @@
lldb::SBError
UnloadImage (uint32_t image_token);
- lldb::SBData
- GetDataFromCString(const char* data);
-
- lldb::SBData
- GetDataFromUnsignedInt64Array(uint64_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromUnsignedInt32Array(uint32_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromSignedInt64Array(int64_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromSignedInt32Array(int32_t* array, size_t array_len);
-
- lldb::SBData
- GetDataFromDoubleArray(double* array, size_t array_len);
-
};
} // namespace lldb
Modified: lldb/trunk/source/API/SBData.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBData.cpp?rev=147702&r1=147701&r2=147702&view=diff
==============================================================================
--- lldb/trunk/source/API/SBData.cpp (original)
+++ lldb/trunk/source/API/SBData.cpp Fri Jan 6 18:45:50 2012
@@ -11,6 +11,7 @@
#include "lldb/API/SBError.h"
#include "lldb/API/SBStream.h"
+#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Stream.h"
@@ -19,7 +20,8 @@
using namespace lldb;
using namespace lldb_private;
-SBData::SBData ()
+SBData::SBData () :
+ m_opaque_sp(new DataExtractor())
{
}
@@ -95,6 +97,16 @@
}
void
+SBData::SetAddressByteSize (uint8_t addr_byte_size)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+ if (m_opaque_sp.get())
+ m_opaque_sp->SetAddressByteSize(addr_byte_size);
+ if (log)
+ log->Printf ("SBData::SetAddressByteSize (%i)", addr_byte_size);
+}
+
+void
SBData::Clear ()
{
if (m_opaque_sp.get())
@@ -127,6 +139,17 @@
return value;
}
+void
+SBData::SetByteOrder (lldb::ByteOrder endian)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+ if (m_opaque_sp.get())
+ m_opaque_sp->SetByteOrder(endian);
+ if (log)
+ log->Printf ("SBData::GetByteOrder (%i)", endian);
+}
+
+
float
SBData::GetFloat (lldb::SBError& error, uint32_t offset)
{
@@ -462,11 +485,11 @@
}
void
-SBData::SetData(lldb::SBError& error,
- const void *buf,
- size_t size,
- lldb::ByteOrder endian,
- uint8_t addr_size)
+SBData::SetData (lldb::SBError& error,
+ const void *buf,
+ size_t size,
+ lldb::ByteOrder endian,
+ uint8_t addr_size)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (!m_opaque_sp.get())
@@ -479,7 +502,7 @@
}
bool
-SBData::Append(const SBData& rhs)
+SBData::Append (const SBData& rhs)
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
bool value = false;
@@ -490,3 +513,273 @@
"(%s)", rhs.get(), value ? "true" : "false");
return value;
}
+
+lldb::SBData
+SBData::CreateDataFromCString (lldb::ByteOrder endian, uint32_t addr_byte_size, const char* data)
+{
+ if (!data || !data[0])
+ return SBData();
+
+ uint32_t data_len = strlen(data);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
+ lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
+
+ SBData ret(data_sp);
+
+ return ret;
+}
+
+lldb::SBData
+SBData::CreateDataFromUInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint64_t* array, size_t array_len)
+{
+ if (!array || array_len == 0)
+ return SBData();
+
+ size_t data_len = array_len * sizeof(uint64_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+ lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
+
+ SBData ret(data_sp);
+
+ return ret;
+}
+
+lldb::SBData
+SBData::CreateDataFromUInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint32_t* array, size_t array_len)
+{
+ if (!array || array_len == 0)
+ return SBData();
+
+ size_t data_len = array_len * sizeof(uint32_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+ lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
+
+ SBData ret(data_sp);
+
+ return ret;
+}
+
+lldb::SBData
+SBData::CreateDataFromSInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int64_t* array, size_t array_len)
+{
+ if (!array || array_len == 0)
+ return SBData();
+
+ size_t data_len = array_len * sizeof(int64_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+ lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
+
+ SBData ret(data_sp);
+
+ return ret;
+}
+
+lldb::SBData
+SBData::CreateDataFromSInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int32_t* array, size_t array_len)
+{
+ if (!array || array_len == 0)
+ return SBData();
+
+ size_t data_len = array_len * sizeof(int32_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+ lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
+
+ SBData ret(data_sp);
+
+ return ret;
+}
+
+lldb::SBData
+SBData::CreateDataFromDoubleArray (lldb::ByteOrder endian, uint32_t addr_byte_size, double* array, size_t array_len)
+{
+ if (!array || array_len == 0)
+ return SBData();
+
+ size_t data_len = array_len * sizeof(double);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+ lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, endian, addr_byte_size));
+
+ SBData ret(data_sp);
+
+ return ret;
+}
+
+bool
+SBData::SetDataFromCString (const char* data)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ if (!data)
+ {
+ if (log)
+ log->Printf ("SBData::SetDataFromCString (data=%p) => "
+ "false", data);
+ return false;
+ }
+
+ size_t data_len = strlen(data);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
+
+ if (!m_opaque_sp.get())
+ m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+ else
+ m_opaque_sp->SetData(buffer_sp);
+
+ if (log)
+ log->Printf ("SBData::SetDataFromCString (data=%p) => "
+ "true", data);
+
+ return true;
+}
+
+bool
+SBData::SetDataFromUInt64Array (uint64_t* array, size_t array_len)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ if (!array || array_len == 0)
+ {
+ if (log)
+ log->Printf ("SBData::SetDataFromUInt64Array (array=%p, array_len = %lu) => "
+ "false", array, array_len);
+ return false;
+ }
+
+ size_t data_len = array_len * sizeof(uint64_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+
+ if (!m_opaque_sp.get())
+ m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+ else
+ m_opaque_sp->SetData(buffer_sp);
+
+ if (log)
+ log->Printf ("SBData::SetDataFromUInt64Array (array=%p, array_len = %lu) => "
+ "true", array, array_len);
+
+ return true;
+}
+
+bool
+SBData::SetDataFromUInt32Array (uint32_t* array, size_t array_len)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ if (!array || array_len == 0)
+ {
+ if (log)
+ log->Printf ("SBData::SetDataFromUInt32Array (array=%p, array_len = %lu) => "
+ "false", array, array_len);
+ return false;
+ }
+
+ size_t data_len = array_len * sizeof(uint32_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+
+ if (!m_opaque_sp.get())
+ m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+ else
+ m_opaque_sp->SetData(buffer_sp);
+
+ if (log)
+ log->Printf ("SBData::SetDataFromUInt32Array (array=%p, array_len = %lu) => "
+ "true", array, array_len);
+
+ return true;
+}
+
+bool
+SBData::SetDataFromSInt64Array (int64_t* array, size_t array_len)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ if (!array || array_len == 0)
+ {
+ if (log)
+ log->Printf ("SBData::SetDataFromSInt64Array (array=%p, array_len = %lu) => "
+ "false", array, array_len);
+ return false;
+ }
+
+ size_t data_len = array_len * sizeof(int64_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+
+ if (!m_opaque_sp.get())
+ m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+ else
+ m_opaque_sp->SetData(buffer_sp);
+
+ if (log)
+ log->Printf ("SBData::SetDataFromSInt64Array (array=%p, array_len = %lu) => "
+ "true", array, array_len);
+
+ return true;
+}
+
+bool
+SBData::SetDataFromSInt32Array (int32_t* array, size_t array_len)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ if (!array || array_len == 0)
+ {
+ if (log)
+ log->Printf ("SBData::SetDataFromSInt32Array (array=%p, array_len = %lu) => "
+ "false", array, array_len);
+ return false;
+ }
+
+ size_t data_len = array_len * sizeof(int32_t);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+
+ if (!m_opaque_sp.get())
+ m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+ else
+ m_opaque_sp->SetData(buffer_sp);
+
+ if (log)
+ log->Printf ("SBData::SetDataFromSInt32Array (array=%p, array_len = %lu) => "
+ "true", array, array_len);
+
+ return true;
+}
+
+bool
+SBData::SetDataFromDoubleArray (double* array, size_t array_len)
+{
+ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ if (!array || array_len == 0)
+ {
+ if (log)
+ log->Printf ("SBData::SetDataFromDoubleArray (array=%p, array_len = %lu) => "
+ "false", array, array_len);
+ return false;
+ }
+
+ size_t data_len = array_len * sizeof(double);
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
+
+ if (!m_opaque_sp.get())
+ m_opaque_sp.reset(new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+ else
+ m_opaque_sp->SetData(buffer_sp);
+
+ if (log)
+ log->Printf ("SBData::SetDataFromDoubleArray (array=%p, array_len = %lu) => "
+ "true", array, array_len);
+
+ return true;
+}
Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=147702&r1=147701&r2=147702&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Fri Jan 6 18:45:50 2012
@@ -13,8 +13,6 @@
#include "lldb/lldb-types.h"
#include "lldb/Interpreter/Args.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/State.h"
@@ -918,130 +916,3 @@
sb_error.SetErrorString("invalid process");
return sb_error;
}
-
-lldb::SBData
-SBProcess::GetDataFromCString(const char* data)
-{
- if (!IsValid())
- return SBData();
-
- if (!data || !data[0])
- return SBData();
-
- uint32_t data_len = strlen(data);
- lldb::ByteOrder byte_order = GetByteOrder();
- uint8_t addr_size = GetAddressByteSize();
-
- lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
- lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, byte_order, addr_size));
-
- SBData ret(data_sp);
-
- return ret;
-}
-
-lldb::SBData
-SBProcess::GetDataFromUnsignedInt64Array(uint64_t* array, size_t array_len)
-{
- if (!IsValid())
- return SBData();
-
- if (!array || array_len == 0)
- return SBData();
-
- lldb::ByteOrder byte_order = GetByteOrder();
- uint8_t addr_size = GetAddressByteSize();
- size_t data_len = array_len * sizeof(uint64_t);
-
- lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
- lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, byte_order, addr_size));
-
- SBData ret(data_sp);
-
- return ret;
-}
-
-lldb::SBData
-SBProcess::GetDataFromUnsignedInt32Array(uint32_t* array, size_t array_len)
-{
- if (!IsValid())
- return SBData();
-
- if (!array || array_len == 0)
- return SBData();
-
- lldb::ByteOrder byte_order = GetByteOrder();
- uint8_t addr_size = GetAddressByteSize();
- size_t data_len = array_len * sizeof(uint32_t);
-
- lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
- lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, byte_order, addr_size));
-
- SBData ret(data_sp);
-
- return ret;
-}
-
-lldb::SBData
-SBProcess::GetDataFromSignedInt64Array(int64_t* array, size_t array_len)
-{
- if (!IsValid())
- return SBData();
-
- if (!array || array_len == 0)
- return SBData();
-
- lldb::ByteOrder byte_order = GetByteOrder();
- uint8_t addr_size = GetAddressByteSize();
- size_t data_len = array_len * sizeof(int64_t);
-
- lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
- lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, byte_order, addr_size));
-
- SBData ret(data_sp);
-
- return ret;
-}
-
-lldb::SBData
-SBProcess::GetDataFromSignedInt32Array(int32_t* array, size_t array_len)
-{
- if (!IsValid())
- return SBData();
-
- if (!array || array_len == 0)
- return SBData();
-
- lldb::ByteOrder byte_order = GetByteOrder();
- uint8_t addr_size = GetAddressByteSize();
- size_t data_len = array_len * sizeof(int32_t);
-
- lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
- lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, byte_order, addr_size));
-
- SBData ret(data_sp);
-
- return ret;
-}
-
-lldb::SBData
-SBProcess::GetDataFromDoubleArray(double* array, size_t array_len)
-{
- if (!IsValid())
- return SBData();
-
- if (!array || array_len == 0)
- return SBData();
-
- lldb::ByteOrder byte_order = GetByteOrder();
- uint8_t addr_size = GetAddressByteSize();
- size_t data_len = array_len * sizeof(double);
-
- lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
- lldb::DataExtractorSP data_sp(new DataExtractor(buffer_sp, byte_order, addr_size));
-
- SBData ret(data_sp);
-
- return ret;
-}
-
Modified: lldb/trunk/test/python_api/sbdata/TestSBData.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/sbdata/TestSBData.py?rev=147702&r1=147701&r2=147702&view=diff
==============================================================================
--- lldb/trunk/test/python_api/sbdata/TestSBData.py (original)
+++ lldb/trunk/test/python_api/sbdata/TestSBData.py Fri Jan 6 18:45:50 2012
@@ -215,7 +215,7 @@
# check the new API calls introduced per LLVM bugzilla enhancement request
# 11619 (Allow creating SBData values from arrays or primitives in Python)
- data2 = process.GetDataFromCString('hello!')
+ data2 = lldb.SBData.CreateDataFromCString(process.GetByteOrder(),process.GetAddressByteSize(),'hello!')
self.assertTrue(data2.GetUnsignedInt8(error,0) == 104, 'h == 104')
self.assertTrue(data2.GetUnsignedInt8(error,1) == 101, 'e == 101')
self.assertTrue(data2.GetUnsignedInt8(error,2) == 108, 'l == 108')
@@ -224,35 +224,72 @@
self.assertTrue(data2.GetUnsignedInt8(error,5) == 33, '! == 33')
self.assertTrue(data2.GetUnsignedInt8(error,6) == 0, 'binary 0 terminator')
- data2 = process.GetDataFromUnsignedInt64Array([1,2,3,4,5])
+ data2 = lldb.SBData.CreateDataFromUInt64Array(process.GetByteOrder(),process.GetAddressByteSize(),[1,2,3,4,5])
self.assertTrue(data2.GetUnsignedInt64(error,0) == 1, 'data2[0] = 1')
self.assertTrue(data2.GetUnsignedInt64(error,8) == 2, 'data2[1] = 2')
self.assertTrue(data2.GetUnsignedInt64(error,16) == 3, 'data2[2] = 3')
self.assertTrue(data2.GetUnsignedInt64(error,24) == 4, 'data2[3] = 4')
self.assertTrue(data2.GetUnsignedInt64(error,32) == 5, 'data2[4] = 5')
- data2 = process.GetDataFromSignedInt32Array([2, -2])
+ data2 = lldb.SBData.CreateDataFromSInt32Array(process.GetByteOrder(),process.GetAddressByteSize(),[2, -2])
self.assertTrue(data2.GetSignedInt32(error,0) == 2, 'signed32 data2[0] = 2')
self.assertTrue(data2.GetSignedInt32(error,4) == -2, 'signed32 data2[1] = -2')
- data2.Append(process.GetDataFromSignedInt64Array([2, -2]))
+ data2.Append(lldb.SBData.CreateDataFromSInt64Array(process.GetByteOrder(),process.GetAddressByteSize(),[2, -2]))
self.assertTrue(data2.GetSignedInt32(error,0) == 2, 'signed32 data2[0] = 2')
self.assertTrue(data2.GetSignedInt32(error,4) == -2, 'signed32 data2[1] = -2')
self.assertTrue(data2.GetSignedInt64(error,8) == 2, 'signed64 data2[0] = 2')
self.assertTrue(data2.GetSignedInt64(error,16) == -2, 'signed64 data2[1] = -2')
- data2 = process.GetDataFromUnsignedInt32Array([1,2,3,4,5])
+ data2 = lldb.SBData.CreateDataFromUInt32Array(process.GetByteOrder(),process.GetAddressByteSize(),[1,2,3,4,5])
self.assertTrue(data2.GetUnsignedInt32(error,0) == 1, '32-bit data2[0] = 1')
self.assertTrue(data2.GetUnsignedInt32(error,4) == 2, '32-bit data2[1] = 2')
self.assertTrue(data2.GetUnsignedInt32(error,8) == 3, '32-bit data2[2] = 3')
self.assertTrue(data2.GetUnsignedInt32(error,12) == 4, '32-bit data2[3] = 4')
self.assertTrue(data2.GetUnsignedInt32(error,16) == 5, '32-bit data2[4] = 5')
- data2 = process.GetDataFromDoubleArray([3.14,6.28,2.71])
+ data2 = lldb.SBData.CreateDataFromDoubleArray(process.GetByteOrder(),process.GetAddressByteSize(),[3.14,6.28,2.71])
self.assertTrue( fabs(data2.GetDouble(error,0) - 3.14) < 0.5, 'double data2[0] = 3.14')
self.assertTrue( fabs(data2.GetDouble(error,8) - 6.28) < 0.5, 'double data2[1] = 6.28')
self.assertTrue( fabs(data2.GetDouble(error,16) - 2.71) < 0.5, 'double data2[2] = 2.71')
-
+
+ data2 = lldb.SBData()
+
+ data2.SetDataFromCString('hello!')
+ self.assertTrue(data2.GetUnsignedInt8(error,0) == 104, 'set h == 104')
+ self.assertTrue(data2.GetUnsignedInt8(error,1) == 101, 'set e == 101')
+ self.assertTrue(data2.GetUnsignedInt8(error,2) == 108, 'set l == 108')
+ self.assertTrue(data2.GetUnsignedInt8(error,3) == 108, 'set l == 108')
+ self.assertTrue(data2.GetUnsignedInt8(error,4) == 111, 'set o == 111')
+ self.assertTrue(data2.GetUnsignedInt8(error,5) == 33, 'set ! == 33')
+ self.assertTrue(data2.GetUnsignedInt8(error,6) == 0, 'set binary 0 terminator')
+
+ data2.SetDataFromUInt64Array([1,2,3,4,5])
+ self.assertTrue(data2.GetUnsignedInt64(error,0) == 1, 'set data2[0] = 1')
+ self.assertTrue(data2.GetUnsignedInt64(error,8) == 2, 'set data2[1] = 2')
+ self.assertTrue(data2.GetUnsignedInt64(error,16) == 3, 'set data2[2] = 3')
+ self.assertTrue(data2.GetUnsignedInt64(error,24) == 4, 'set data2[3] = 4')
+ self.assertTrue(data2.GetUnsignedInt64(error,32) == 5, 'set data2[4] = 5')
+
+ data2.SetDataFromSInt32Array([2, -2])
+ self.assertTrue(data2.GetSignedInt32(error,0) == 2, 'set signed32 data2[0] = 2')
+ self.assertTrue(data2.GetSignedInt32(error,4) == -2, 'set signed32 data2[1] = -2')
+
+ data2.SetDataFromSInt64Array([2, -2])
+ self.assertTrue(data2.GetSignedInt32(error,0) == 2, 'set signed64 data2[0] = 2')
+ self.assertTrue(data2.GetSignedInt32(error,8) == -2, 'set signed64 data2[1] = -2')
+
+ data2.SetDataFromUInt32Array([1,2,3,4,5])
+ self.assertTrue(data2.GetUnsignedInt32(error,0) == 1, 'set 32-bit data2[0] = 1')
+ self.assertTrue(data2.GetUnsignedInt32(error,4) == 2, 'set 32-bit data2[1] = 2')
+ self.assertTrue(data2.GetUnsignedInt32(error,8) == 3, 'set 32-bit data2[2] = 3')
+ self.assertTrue(data2.GetUnsignedInt32(error,12) == 4, 'set 32-bit data2[3] = 4')
+ self.assertTrue(data2.GetUnsignedInt32(error,16) == 5, 'set 32-bit data2[4] = 5')
+
+ data2.SetDataFromDoubleArray([3.14,6.28,2.71])
+ self.assertTrue( fabs(data2.GetDouble(error,0) - 3.14) < 0.5, 'set double data2[0] = 3.14')
+ self.assertTrue( fabs(data2.GetDouble(error,8) - 6.28) < 0.5, 'set double data2[1] = 6.28')
+ self.assertTrue( fabs(data2.GetDouble(error,16) - 2.71) < 0.5, 'set double data2[2] = 2.71')
if __name__ == '__main__':
import atexit
More information about the lldb-commits
mailing list