From 6965f1bcee72f949c90e40670e3382683f59ec19 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" <SND\EreTIk_cp@9b283d60-5439-405e-af05-b73fd8c4d996> Date: Sun, 12 Jun 2011 17:51:38 +0000 Subject: [PATCH] fix:8953 git-svn-id: https://pykd.svn.codeplex.com/svn@66696 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgdump.cpp | 2 - pykd/dbgext.cpp | 1 - pykd/dbgmem.cpp | 8 +- pykd/dbgmodule.cpp | 1 - pykd/dbgpath.cpp | 2 - pykd/dbgpath.h | 1 - pykd/dbgsynsym.cpp | 1 - pykd/dbgsystem.cpp | 2 - pykd/dbgtype.cpp | 141 ++++++++++++++--------------- pykd/dbgtype.h | 25 +++--- pykd/pykd_2008.vcproj | 4 - pykd/stdafx.h | 13 +++ pykd_2008.sln | 21 +++-- test/targetapp/targetapp.vcproj | 154 ++++++++++++++++---------------- 14 files changed, 190 insertions(+), 186 deletions(-) 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 <vector> - #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 <wdbgexts.h> -#include <vector> #include <string> #include <boost/python/module.hpp> 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 <boost/scoped_array.hpp> -#include <vector> #include "dbgext.h" #include "dbgexcept.h" @@ -165,9 +164,10 @@ boost::python::object loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) { std::vector<char> 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 <boost/format.hpp> -#include <vector> #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 <vector> - #include "dbgpath.h" #include <boost/tokenizer.hpp> 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 <string> -#include <vector> /////////////////////////////////////////////////////////////////////////////// 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 <boost/interprocess/sync/scoped_lock.hpp> #include <boost/interprocess/sync/interprocess_recursive_mutex.hpp> #include <boost/interprocess/sync/interprocess_mutex.hpp> -#include <vector> #include <list> #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 <vector> - #include <exception> #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<void*>( (char*)buffer + offset, field.size ); + sstr << " " << hex << valuePrinter<void*>( (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 <string> #include <map> -#include <vector> #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<std::string, std::string>, TypeInfo> TypeInfoMap; template< typename TTypeInfo> @@ -141,11 +144,9 @@ public: }; typedef TypeFieldT<TypeInfo> TypeField; - + typedef std::vector<TypeField> 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<char> 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 @@ > </File> </Filter> - <File - RelativePath=".\pykd.vcproj" - > - </File> </Files> <Globals> </Globals> 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 <boost/python/object.hpp> #pragma warning(pop) +#include <vector> + +template <typename TElem> +TElem *getVectorBuffer(std::vector<TElem> &vec) +{ + return vec.size() ? &vec[0] : NULL; +} +template <typename TElem> +const TElem *getVectorBuffer(const std::vector<TElem> &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 @@ <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" - Version="9,00" + Version="9.00" Name="targetapp" ProjectGUID="{C6254E16-AB8E-41EE-887D-31458E93FC68}" RootNamespace="targetapp" + SccProjectName="SAK" + SccAuxPath="SAK" + SccLocalPath="SAK" + SccProvider="SAK" Keyword="Win32Proj" TargetFrameworkVersion="131072" > @@ -90,6 +94,78 @@ Name="VCPostBuildEventTool" /> </Configuration> + <Configuration + Name="Debug|x64" + OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)" + IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="2" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="17" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> <Configuration Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" @@ -164,78 +240,6 @@ Name="VCPostBuildEventTool" /> </Configuration> - <Configuration - Name="Debug|x64" - OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)" - IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" - ConfigurationType="1" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - TargetEnvironment="3" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="3" - UsePrecompiledHeader="2" - WarningLevel="3" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="2" - GenerateDebugInformation="true" - SubSystem="1" - TargetMachine="17" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> <Configuration Name="Release|x64" OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)" @@ -332,7 +336,7 @@ /> </FileConfiguration> <FileConfiguration - Name="Release|Win32" + Name="Debug|x64" > <Tool Name="VCCLCompilerTool" @@ -340,7 +344,7 @@ /> </FileConfiguration> <FileConfiguration - Name="Debug|x64" + Name="Release|Win32" > <Tool Name="VCCLCompilerTool"