diff --git a/pykd/dbgdump.cpp b/pykd/dbgdump.cpp index 282702a..3c333d7 100644 --- a/pykd/dbgdump.cpp +++ b/pykd/dbgdump.cpp @@ -1,7 +1,5 @@ #include "stdafx.h" -#include - #include "dbgext.h" #include "dbgdump.h" #include "dbgexcept.h" diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 35d444d..023eb63 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -2,7 +2,6 @@ #include -#include #include #include diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index 6ed805d..b6e23d9 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include -#include #include "dbgext.h" #include "dbgexcept.h" @@ -165,9 +164,10 @@ boost::python::object loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) { std::vector buffer(number); - - loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); - + + if (number) + loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); + return boost::python::object(std::string( buffer.begin(), buffer.end() ) ); } diff --git a/pykd/dbgmodule.cpp b/pykd/dbgmodule.cpp index 34127f1..59ce510 100644 --- a/pykd/dbgmodule.cpp +++ b/pykd/dbgmodule.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include -#include #include "dbgext.h" #include "dbgmem.h" diff --git a/pykd/dbgpath.cpp b/pykd/dbgpath.cpp index b74aa2e..10be731 100644 --- a/pykd/dbgpath.cpp +++ b/pykd/dbgpath.cpp @@ -1,7 +1,5 @@ #include "stdafx.h" -#include - #include "dbgpath.h" #include diff --git a/pykd/dbgpath.h b/pykd/dbgpath.h index 5ba7051..3f790f1 100644 --- a/pykd/dbgpath.h +++ b/pykd/dbgpath.h @@ -1,7 +1,6 @@ #pragma once #include -#include /////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgsynsym.cpp b/pykd/dbgsynsym.cpp index 7c46703..70e2dba 100644 --- a/pykd/dbgsynsym.cpp +++ b/pykd/dbgsynsym.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "dbgext.h" diff --git a/pykd/dbgsystem.cpp b/pykd/dbgsystem.cpp index d7e4d93..25f003a 100644 --- a/pykd/dbgsystem.cpp +++ b/pykd/dbgsystem.cpp @@ -1,7 +1,5 @@ #include "stdafx.h" -#include - #include #include "dbgext.h" #include "dbgexcept.h" diff --git a/pykd/dbgtype.cpp b/pykd/dbgtype.cpp index f965854..e8a58a3 100644 --- a/pykd/dbgtype.cpp +++ b/pykd/dbgtype.cpp @@ -111,10 +111,10 @@ TypeInfo::TypeInfo( const std::string &moduleName, const std::string &typeName } } - } while( FALSE ); + } while( FALSE ); m_arraySize = m_size; - + g_typeInfoCache.insert( std::make_pair( std::make_pair( m_moduleName, m_typeName), *this) ); } @@ -167,10 +167,10 @@ TypeInfo::TypeInfo( const std::string &moduleName, ULONG64 moduleBase, ULONG typ else { m_fields.push_back( TypeField( fieldName, TypeInfo( moduleName, fieldTypeName ), fieldSize, fieldOffset ) ); - } - } - - m_arraySize = m_size; + } + } + + m_arraySize = m_size; } /////////////////////////////////////////////////////////////////////////////////// @@ -206,7 +206,7 @@ TypeInfo::print() const sstream << "unnamed"; if ( m_arraySize > m_size ) - { + { sstream << " size = " << dec << m_arraySize << "(0x" << hex << m_arraySize << ") " << dec << "[" << m_arraySize/m_size << "]"; } else @@ -234,14 +234,14 @@ TypeInfo::getField( const std::string &fieldName ) const if ( it->name == fieldName ) { TypeInfo tinf = it->type; - + tinf.m_parentOffset = m_parentOffset + it->offset; tinf.m_arraySize = it->size; - + return tinf; - } - } - + } + } + throw TypeException(); } @@ -251,11 +251,11 @@ TypeInfo TypeInfo::getFieldAt( size_t index ) const { TypeInfo tinf = m_fields[index].type; - + tinf.m_parentOffset = m_parentOffset + m_fields[index].offset; tinf.m_arraySize = m_fields[index].size; - - return tinf; + + return tinf; } /////////////////////////////////////////////////////////////////////////////////// @@ -319,20 +319,20 @@ void TypeInfo::appendField( const TypeInfo &typeInfo, const std::string &fieldName, ULONG count ) { if ( m_isFreezed ) - throw TypeException(); + throw TypeException(); if ( count == 0 ) - throw TypeException(); + throw TypeException(); if ( count == 1 && typeInfo.m_typeName.find("[]") != std::string::npos ) - throw TypeException(); + throw TypeException(); TypeFieldList::const_iterator it = m_fields.begin(); for(;it != m_fields.end(); ++it ) { if ( it->name == fieldName ) throw TypeException(); - } + } if ( count > 1 && typeInfo.m_typeName.find("[]") == std::string::npos ) { @@ -340,25 +340,19 @@ TypeInfo::appendField( const TypeInfo &typeInfo, const std::string &fieldName, U arrayInfo.m_typeName += "[]"; appendField( arrayInfo, fieldName, count ); return; - } - - ULONG offset = m_size; - + } + + ULONG offset = m_size; + if ( typeInfo.isBaseType() ) { offset += offset % min( typeInfo.size(), m_align ); } - - if ( count == 1 ) - { - m_fields.push_back( TypeField( fieldName, typeInfo, typeInfo.size(), offset ) ); - m_size = offset + typeInfo.size(); - } - else - { - m_fields.push_back( TypeField( fieldName, typeInfo, typeInfo.size()*count, offset ) ); - m_size = offset + typeInfo.size()*count; - } + + const ULONG addSize = typeInfo.size() * count; + m_fields.push_back( TypeField( fieldName, typeInfo, addSize, offset ) ); + m_size = offset + addSize; + m_arraySize = offset + addSize; } /////////////////////////////////////////////////////////////////////////////////// @@ -489,7 +483,7 @@ valuePrinter( void* address, size_t size ) { valType v = *(valType*)address; - sstr << v; + sstr << v << hex << " (0x" << v << ")"; } else { @@ -746,7 +740,7 @@ TypeInfo::printField( size_t index, void* buffer, size_t bufferLength ) const sstr << hex << "+" << offset; sstr << " " << field.name; sstr << " " << fieldType.name(); - sstr << " " << valuePrinter( (char*)buffer + offset, field.size ); + sstr << " " << hex << valuePrinter( (char*)buffer + offset, field.size ); sstr << endl; return sstr.str(); } @@ -812,16 +806,22 @@ TypedVar::getFieldWrap( PyObject* self, const std::string &fieldName ) return tv.getField( pyobj, fieldName ); } +void TypedVar::reallocBuffer() +{ + const size_t fullSize = m_typeInfo.fullSize(); + if (m_buffer.size() < fullSize) + { + assert(fullSize); + m_buffer.resize( fullSize ); + loadMemory( m_targetOffset, (PVOID)&m_buffer[0], (ULONG)m_buffer.size() ); + } +} + boost::python::object TypedVar::getField( boost::python::object &pyobj, const std::string &fieldName ) { - if ( m_buffer.size() == 0 ) - { - m_buffer.resize( (size_t)m_typeInfo.fullSize() ); - - loadMemory( m_targetOffset, (PVOID)&m_buffer[0], (ULONG)m_buffer.size() ); - } - + reallocBuffer(); + TypeInfo typeInfo = m_typeInfo.getField( fieldName ); // относительный оффсет @@ -835,13 +835,16 @@ TypedVar::getField( boost::python::object &pyobj, const std::string &fieldName { if ( typeInfo.count() == 1 ) { - pyobj.attr(fieldName.c_str()) = - boost::python::object( - TypedVar( - typeInfo, - m_targetOffset + offset, - &m_buffer[0] + offset, - typeInfo.size() ) ); + if (m_buffer.size()) + { + pyobj.attr(fieldName.c_str()) = + boost::python::object( + TypedVar( + typeInfo, + m_targetOffset + offset, + &m_buffer[0] + offset, + typeInfo.size() ) ); + } } else { @@ -849,20 +852,23 @@ TypedVar::getField( boost::python::object &pyobj, const std::string &fieldName for ( unsigned int i = 0; i < typeInfo.count(); ++i ) { - arr.append( - boost::python::object( - TypedVar( - typeInfo, - m_targetOffset + offset + i*typeInfo.size(), - &m_buffer[0] + offset + i*typeInfo.size(), - typeInfo.size() ) ) ); + if (m_buffer.size()) + { + arr.append( + boost::python::object( + TypedVar( + typeInfo, + m_targetOffset + offset + i*typeInfo.size(), + &m_buffer[0] + offset + i*typeInfo.size(), + typeInfo.size() ) ) ); + } } pyobj.attr(fieldName.c_str()) = arr; } } - return pyobj.attr(fieldName.c_str()); + return pyobj.attr(fieldName.c_str()); } ///////////////////////////////////////////////////////////////////////////////////// @@ -870,14 +876,8 @@ TypedVar::getField( boost::python::object &pyobj, const std::string &fieldName std::string TypedVar::data() { - if ( m_buffer.size() == 0 ) - { - m_buffer.resize( (size_t)m_typeInfo.fullSize() ); - - loadMemory( m_targetOffset, (PVOID)&m_buffer[0], (ULONG)m_buffer.size() ); - } - - return std::string( &m_buffer[0], m_buffer.size() ); + reallocBuffer(); + return std::string( getVectorBuffer(m_buffer), m_buffer.size() ); } ///////////////////////////////////////////////////////////////////////////////////// @@ -885,12 +885,7 @@ TypedVar::data() std::string TypedVar::print() { - if ( m_buffer.size() == 0 ) - { - m_buffer.resize( (size_t)m_typeInfo.fullSize() ); - - loadMemory( m_targetOffset, (PVOID)&m_buffer[0], (ULONG)m_buffer.size() ); - } + reallocBuffer(); stringstream sstr; @@ -910,7 +905,7 @@ TypedVar::print() for ( size_t i = 0; i < m_typeInfo.getFieldCount(); ++i ) { - sstr << m_typeInfo.printField( i, (PVOID)&m_buffer[0], (ULONG)m_buffer.size() ); + sstr << m_typeInfo.printField( i, (PVOID)getVectorBuffer(m_buffer), (ULONG)m_buffer.size() ); //TypeInfo fieldType = m_typeInfo.getFieldAt( i ); diff --git a/pykd/dbgtype.h b/pykd/dbgtype.h index 097004e..3ccd619 100644 --- a/pykd/dbgtype.h +++ b/pykd/dbgtype.h @@ -2,7 +2,6 @@ #include #include -#include #include "dbgmem.h" #include "dbgsystem.h" @@ -25,7 +24,9 @@ public: m_arraySize( 0 ), m_parentOffset( 0 ), m_align( ptrSize() ), - m_isFreezed( false ) + m_isFreezed( false ), + m_isBaseType( false ), + m_isPointer( false ) {} TypeInfo( const std::string customName, ULONG align=0 ) : @@ -34,7 +35,9 @@ public: m_arraySize( 0 ), m_parentOffset( 0 ), m_isFreezed( false ), - m_align( align == 0 ? ptrSize() : align ) + m_align( align == 0 ? ptrSize() : align ), + m_isBaseType( false ), + m_isPointer( false ) {} TypeInfo( const std::string &moduleName, const std::string &typeName ); @@ -52,7 +55,7 @@ public: ULONG count() const { - assert( m_size != 0 ); + assert( m_size != 0 && m_arraySize >= m_size ); return m_arraySize / m_size; } @@ -116,7 +119,7 @@ public: loadVar( ULONG64 targetOffset, ULONG count = 1) const; public: - + typedef std::map< std::pair, TypeInfo> TypeInfoMap; template< typename TTypeInfo> @@ -141,11 +144,9 @@ public: }; typedef TypeFieldT TypeField; - + typedef std::vector TypeFieldList; - - - + private: typedef @@ -239,15 +240,17 @@ public: private: + void reallocBuffer(); + TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset, char* buffer, size_t bufferLength ); ULONG64 m_targetOffset; TypeInfo m_typeInfo; - + std::vector m_buffer; }; - + /////////////////////////////////////////////////////////////////////////////////// boost::python::object diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 84278e5..296c39c 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -558,10 +558,6 @@ > - - diff --git a/pykd/stdafx.h b/pykd/stdafx.h index 8e6babf..871ab52 100644 --- a/pykd/stdafx.h +++ b/pykd/stdafx.h @@ -45,4 +45,17 @@ #include #pragma warning(pop) +#include + +template +TElem *getVectorBuffer(std::vector &vec) +{ + return vec.size() ? &vec[0] : NULL; +} +template +const TElem *getVectorBuffer(const std::vector &vec) +{ + return vec.size() ? &vec[0] : NULL; +} + // TODO: reference additional headers your program requires here diff --git a/pykd_2008.sln b/pykd_2008.sln index f135593..e339971 100644 --- a/pykd_2008.sln +++ b/pykd_2008.sln @@ -9,6 +9,18 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "targetapp", "test\targetapp\targetapp.vcproj", "{C6254E16-AB8E-41EE-887D-31458E93FC68}" EndProject Global + GlobalSection(TeamFoundationVersionControl) = preSolution + SccNumberOfProjects = 3 + SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} + SccTeamFoundationServer = https://tfs.codeplex.com/tfs/TFS08 + SccLocalPath0 = . + SccProjectUniqueName1 = pykd\\pykd_2008.vcproj + SccProjectName1 = pykd + SccLocalPath1 = pykd + SccProjectUniqueName2 = test\\targetapp\\targetapp.vcproj + SccProjectName2 = test/targetapp + SccLocalPath2 = test\\targetapp + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 @@ -36,13 +48,4 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(TeamFoundationVersionControl) = preSolution - SccNumberOfProjects = 2 - SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} - SccTeamFoundationServer = https://tfs.codeplex.com/tfs/TFS08 - SccLocalPath0 = . - SccProjectUniqueName1 = pykd\\pykd_2008.vcproj - SccProjectName1 = pykd - SccLocalPath1 = pykd - EndGlobalSection EndGlobal diff --git a/test/targetapp/targetapp.vcproj b/test/targetapp/targetapp.vcproj index c5731f9..91059c9 100644 --- a/test/targetapp/targetapp.vcproj +++ b/test/targetapp/targetapp.vcproj @@ -1,10 +1,14 @@ @@ -90,6 +94,78 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - -