From 23244e1eb8f181325f974c7901532eff92ddf810 Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Thu, 17 Jan 2013 06:50:35 +0000
Subject: [PATCH] [0.2.x] added: ptrFloat, ptrDouble, loadFloats, loadDoubles
 routines ( reading floating point data )

git-svn-id: https://pykd.svn.codeplex.com/svn@82308 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/dbgmem.cpp              | 36 ++++++++++++++++++++++++++++++++++++
 pykd/dbgmem.h                |  6 ++++++
 pykd/pykdver.h               |  2 +-
 pykd/python/pymod.cpp        | 12 +++++++++++-
 test/scripts/memtest.py      | 19 ++++++++++++++++++-
 test/scripts/moduletest.py   |  4 ++--
 test/targetapp/targetapp.cpp | 10 ++++++++++
 7 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp
index a367572..6a47d48 100644
--- a/pykd/dbgmem.cpp
+++ b/pykd/dbgmem.cpp
@@ -130,6 +130,28 @@ LONG64 ptrSignMWord( ULONG64 offset )
 
 /////////////////////////////////////////////////////////////////////////////////////
 
+double ptrSingleFloat( ULONG64 offset )
+{
+    float  val = 0;
+    
+    readMemory( offset, &val, sizeof(val), false );
+
+    return val;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+double ptrDoubleFloat( ULONG64 offset )
+{
+    double  val = 0;
+    
+    readMemory( offset, &val, sizeof(val), false );
+
+    return val;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+
 template<typename T>
 struct PyListType
 {
@@ -217,6 +239,20 @@ python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr )
 
 /////////////////////////////////////////////////////////////////////////////////////
 
+python::list loadFloats(  ULONG64 offset, ULONG count, bool phyAddr )
+{
+    return loadArray<float>( offset, count, phyAddr );
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+python::list loadDoubles(  ULONG64 offset, ULONG count, bool phyAddr )
+{
+    return loadArray<double>( offset, count, phyAddr );
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+
 std::string loadChars( ULONG64 offset, ULONG  number, bool phyAddr )
 {
     std::vector<char>   buffer(number);
diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h
index fd4ebfd..0c5d50a 100644
--- a/pykd/dbgmem.h
+++ b/pykd/dbgmem.h
@@ -28,6 +28,9 @@ LONG64 ptrSignQWord( ULONG64 offset );
 LONG64 ptrSignMWord( ULONG64 offset );
 ULONG64 ptrPtr( ULONG64 offset );
 
+double ptrSingleFloat( ULONG64 offset );
+double ptrDoubleFloat( ULONG64 offset );
+
 python::list loadBytes( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
 python::list loadWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
 python::list loadDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
@@ -37,6 +40,9 @@ python::list loadSignWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
 python::list loadSignDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
 python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
 
+python::list loadFloats(  ULONG64 offset, ULONG count, bool phyAddr = FALSE );
+python::list loadDoubles(  ULONG64 offset, ULONG count, bool phyAddr = FALSE );
+
 python::list loadPtrList( ULONG64 offset );
 python::list loadPtrArray( ULONG64 offset, ULONG  number );
 
diff --git a/pykd/pykdver.h b/pykd/pykdver.h
index 1797fd8..ef7ca3a 100644
--- a/pykd/pykdver.h
+++ b/pykd/pykdver.h
@@ -2,7 +2,7 @@
 #define PYKD_VERSION_MAJOR      0
 #define PYKD_VERSION_MINOR      2
 #define PYKD_VERSION_SUBVERSION 0
-#define PYKD_VERSION_BUILDNO    14
+#define PYKD_VERSION_BUILDNO    15
 
 
 #define __VER_STR2__(x) #x
diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp
index 3c8a4ab..794eb30 100644
--- a/pykd/python/pymod.cpp
+++ b/pykd/python/pymod.cpp
@@ -53,6 +53,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes_, loadSignBytes, 2, 3 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords_, loadSignWords, 2, 3 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords_, loadSignDWords, 2, 3 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords_, loadSignQWords, 2, 3 );
+BOOST_PYTHON_FUNCTION_OVERLOADS( loadFloats_, loadFloats, 2, 3 );
+BOOST_PYTHON_FUNCTION_OVERLOADS( loadDoubles_, loadDoubles, 2, 3 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemory_, compareMemory, 3, 4 );
 
 BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, getSourceLine, 0, 1 );
@@ -176,9 +178,13 @@ BOOST_PYTHON_MODULE( pykd )
         "Read an signed mashine's word wide integer from the target memory" );
     python::def( "ptrPtr", (ULONG64(*)(ULONG64))&ptrPtr,
         "Read an pointer value from the target memory" );
+    python::def( "ptrFloat", &ptrSingleFloat,
+        "Read a float with single precision from the target memory" );
+   python::def( "ptrDouble", &ptrDoubleFloat,
+        "Read a float with single precision from the target memory" );
 
     python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ),
-        "Read the block of the target's memory and return it as liat of unsigned bytes" ) );
+        "Read the block of the target's memory and return it as list of unsigned bytes" ) );
     python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ),
         "Read the block of the target's memory and return it as list of unsigned shorts" ) );
     python::def( "loadDWords", &loadDWords, loadDWords_( python::args( "offset", "count", "phyAddr" ),
@@ -209,6 +215,10 @@ BOOST_PYTHON_MODULE( pykd )
         "Return list of pointers, each points to next" );
     python::def( "loadPtrs", &loadPtrArray,
         "Read the block of the target's memory and return it as a list of pointers" );
+    python::def( "loadFloats", &loadFloats, loadFloats_( python::args( "offset", "count", "phyAddr" ),
+        "Read the block of the target's memory and return it as list of floats" ) );
+    python::def( "loadDoubles", &loadDoubles, loadDoubles_( python::args( "offset", "count", "phyAddr" ),
+        "Read the block of the target's memory and return it as list of doubles" ) );
 
     // types and vaiables
     python::def( "getSourceFile", &getSourceFile, getSourceFile_( python::args( "offset"),
diff --git a/test/scripts/memtest.py b/test/scripts/memtest.py
index aed0802..e221b0e 100644
--- a/test/scripts/memtest.py
+++ b/test/scripts/memtest.py
@@ -5,6 +5,7 @@
 import unittest
 import target
 import pykd
+import math
 
 class MemoryTest( unittest.TestCase ):
 
@@ -104,4 +105,20 @@ class MemoryTest( unittest.TestCase ):
             pykd.loadSignBytes( 0xDEADBEEF, 5 )
         except pykd.MemoryException:
             self.assertTrue( True )
-
+            
+    def testPtrFloat(self):
+        self.assertTrue( math.fabs( pykd.ptrFloat( target.module.g_float) - 5.123456 ) < 0.001 )
+        self.assertTrue( math.fabs( pykd.ptrDouble( target.module.g_double) - 5.1234567891 ) < 0.0000001 )
+        
+    def testLoadFloats(self):
+       testArray = [ 1.0, 2.001, -3.0004 ];
+       readArray = pykd.loadFloats( target.module.floatArray, 3 );
+       for i in range(0,3):
+           self.assertTrue( math.fabs( testArray[i] - readArray[i]  ) < 0.001 )
+           
+    def testLoadDoubles(self):
+       testArray = [ 1.0, 2.0000001, -3.0000004 ];
+       readArray = pykd.loadDoubles( target.module.doubleArray, 3 );
+       print readArray
+       for i in range(0,3):
+           self.assertTrue( math.fabs( testArray[i] - readArray[i]  ) < 0.0000001 )
diff --git a/test/scripts/moduletest.py b/test/scripts/moduletest.py
index ead0a23..c48c38f 100644
--- a/test/scripts/moduletest.py
+++ b/test/scripts/moduletest.py
@@ -65,11 +65,11 @@ class ModuleTest( unittest.TestCase ):
         fileName = pykd.getSourceFile(target.module.FuncWithName0 )
         self.assertTrue( re.search('targetapp\\.cpp', fileName ) )
         fileName, lineNo, displacement = pykd.getSourceLine( target.module.FuncWithName0 + 2)
-        self.assertEqual( 395, lineNo )
+        self.assertEqual( 400, lineNo )
         self.assertTrue( re.search('targetapp\\.cpp', fileName ) )
         self.assertEqual( 2, displacement )
         fileName, lineNo, displacement = pykd.getSourceLine()
-        self.assertEqual( 653, lineNo )
+        self.assertEqual( 663, lineNo )
 
     def testEnumSymbols( self ):
         lst = target.module.enumSymbols()
diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp
index a70d385..68b6cc3 100644
--- a/test/targetapp/targetapp.cpp
+++ b/test/targetapp/targetapp.cpp
@@ -36,6 +36,9 @@ SHORT g_shortValue = -2;
 LONG g_longValue = -4;
 LONGLONG g_longlongValue = -8;
 
+float g_float = 5.123456f;
+double g_double = 5.1234567891;
+
 std::string g_string;
 
 struct structWithBits {
@@ -114,6 +117,8 @@ unsigned long ulongArray[] = {0, 0xFF, 0x8000, 0x80000000, 0xFFFFFFFF };
 long longArray[] = {0, -10, -2000, -100000, 0xFFFFFFFF };
 unsigned __int64 ulonglongArray[] = {0, 0xFF, 0xFFFFFFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF };
 long long longlongArray[] = {0, -10, -2000, -100000, -10000000000 };
+float floatArray[] = { 1.0f, 2.001f, -3.0004f };
+double doubleArray[] = { 1.0, 2.0000001, -3.0000004 };
 
 int intMatrix[2][3] = { { 0, 1, 2}, { 3, 4, 5 } };
 int intMatrix2[2][3] = { { 0, 1, 2}, { 3, 4, 5 } };
@@ -421,6 +426,8 @@ void FuncWithName0()
     std::cout << ushortArray[2];
     std::cout << ulongArray[2];
     std::cout << ulonglongArray[2];
+    std::cout << floatArray[2];
+    std::cout << doubleArray[2];
 
     std::cout << intMatrix[1][1];
     std::cout << strArray[0];
@@ -450,6 +457,9 @@ void FuncWithName0()
     std::cout << g_nullSizeArray;
     std::cout << g_structAbstract;
 
+    std::cout << g_float;
+    std::cout << g_double;
+
     //std::cout << g_virtChild.VirtualBaseClass1::m_baseField;
 }