| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | #include <vector>
|
|---|
| 4 |
|
|---|
| 5 | #include <jenga/include/common/Exception.h>
|
|---|
| 6 |
|
|---|
| 7 | #include <BoostSerializationSupport.h>
|
|---|
| 8 |
|
|---|
| 9 | #include <Binary.h>
|
|---|
| 10 |
|
|---|
| 11 | class UserProc;
|
|---|
| 12 |
|
|---|
| 13 | class Schedule
|
|---|
| 14 | {
|
|---|
| 15 | public:
|
|---|
| 16 | enum Type
|
|---|
| 17 | {
|
|---|
| 18 | None = 10000,
|
|---|
| 19 | GlobalVar, // グローバル変数スケジュール
|
|---|
| 20 | DataTable, // データテーブル スケジュール
|
|---|
| 21 | CatchAddress, // Catchアドレス スケジュール
|
|---|
| 22 | Relocation, // リロケーション情報スケジュール
|
|---|
| 23 | UserProc, // ユーザ定義関数呼び出し側スケジュール
|
|---|
| 24 | AddressOf, // ユーザ定義関数位置スケジュール
|
|---|
| 25 | DllProc, // DLL関数位置スケジュール
|
|---|
| 26 | ComVtbl, // com_vtblスケジュール
|
|---|
| 27 | Vtbl, // vtblスケジュール
|
|---|
| 28 | TypeInfo, // TypeInfoスケジュール
|
|---|
| 29 | };
|
|---|
| 30 |
|
|---|
| 31 | private:
|
|---|
| 32 | Type type;
|
|---|
| 33 | long offset;
|
|---|
| 34 |
|
|---|
| 35 | union{
|
|---|
| 36 | LONG_PTR lpValue;
|
|---|
| 37 | const ::UserProc *pUserProc;
|
|---|
| 38 | const ::DllProc *pDllProc;
|
|---|
| 39 | const ::CClass *pClass;
|
|---|
| 40 | };
|
|---|
| 41 |
|
|---|
| 42 | // XMLシリアライズ用
|
|---|
| 43 | private:
|
|---|
| 44 | friend class boost::serialization::access;
|
|---|
| 45 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
|---|
| 46 | {
|
|---|
| 47 | trace_for_serialize( "serializing - Schedule" );
|
|---|
| 48 |
|
|---|
| 49 | ar & BOOST_SERIALIZATION_NVP( type );
|
|---|
| 50 | ar & BOOST_SERIALIZATION_NVP( offset );
|
|---|
| 51 |
|
|---|
| 52 | switch( type )
|
|---|
| 53 | {
|
|---|
| 54 | case UserProc:
|
|---|
| 55 | case AddressOf:
|
|---|
| 56 | case CatchAddress:
|
|---|
| 57 | ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
|
|---|
| 58 | break;
|
|---|
| 59 | case DllProc:
|
|---|
| 60 | ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
|
|---|
| 61 | break;
|
|---|
| 62 | case ComVtbl:
|
|---|
| 63 | case Vtbl:
|
|---|
| 64 | case TypeInfo:
|
|---|
| 65 | ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
|
|---|
| 66 | break;
|
|---|
| 67 | default:
|
|---|
| 68 | ar & BOOST_SERIALIZATION_NVP( lpValue );
|
|---|
| 69 | break;
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | public:
|
|---|
| 74 | Schedule()
|
|---|
| 75 | {
|
|---|
| 76 | }
|
|---|
| 77 | Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
|
|---|
| 78 | : type( type )
|
|---|
| 79 | , offset( offset )
|
|---|
| 80 | , lpValue( lpValue )
|
|---|
| 81 | {
|
|---|
| 82 | }
|
|---|
| 83 | Schedule( const ::UserProc *pUserProc, long offset )
|
|---|
| 84 | : type( Schedule::UserProc )
|
|---|
| 85 | , offset( offset )
|
|---|
| 86 | , pUserProc( pUserProc )
|
|---|
| 87 | {
|
|---|
| 88 | }
|
|---|
| 89 | Schedule( const ::DllProc *pDllProc, long offset )
|
|---|
| 90 | : type( Schedule::DllProc )
|
|---|
| 91 | , offset( offset )
|
|---|
| 92 | , pDllProc( pDllProc )
|
|---|
| 93 | {
|
|---|
| 94 | }
|
|---|
| 95 | Schedule( Type type, const ::CClass *pClass, long offset )
|
|---|
| 96 | : type( type )
|
|---|
| 97 | , pClass( pClass )
|
|---|
| 98 | , offset( offset )
|
|---|
| 99 | {
|
|---|
| 100 | if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
|
|---|
| 101 | {
|
|---|
| 102 | DebugBreak();
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 | ~Schedule()
|
|---|
| 106 | {
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | Type GetType() const
|
|---|
| 110 | {
|
|---|
| 111 | return type;
|
|---|
| 112 | }
|
|---|
| 113 | long GetOffset() const
|
|---|
| 114 | {
|
|---|
| 115 | return offset;
|
|---|
| 116 | }
|
|---|
| 117 | LONG_PTR GetLongPtrValue() const
|
|---|
| 118 | {
|
|---|
| 119 | return lpValue;
|
|---|
| 120 | }
|
|---|
| 121 | const ::DllProc &GetDllProc() const;
|
|---|
| 122 | const ::UserProc &GetUserProc() const;
|
|---|
| 123 | const ::CClass &GetClass() const;
|
|---|
| 124 |
|
|---|
| 125 | void SpecifyAddressOf();
|
|---|
| 126 | void SpecifyCatchAddress();
|
|---|
| 127 | };
|
|---|
| 128 | typedef std::vector<Schedule> Schedules;
|
|---|
| 129 |
|
|---|
| 130 | #define CODETYPE_SYSTEMPROC 0x0001
|
|---|
| 131 | #define CODETYPE_DEBUGPROC 0x0002
|
|---|
| 132 | class SourceLine
|
|---|
| 133 | {
|
|---|
| 134 | int lineNum;
|
|---|
| 135 | long nativeCodePos;
|
|---|
| 136 | int sourceIndex;
|
|---|
| 137 | long sourceCodePos;
|
|---|
| 138 | DWORD codeType;
|
|---|
| 139 |
|
|---|
| 140 | // XMLシリアライズ用
|
|---|
| 141 | private:
|
|---|
| 142 | friend class boost::serialization::access;
|
|---|
| 143 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
|---|
| 144 | {
|
|---|
| 145 | trace_for_serialize( "serializing - SourceLine" );
|
|---|
| 146 |
|
|---|
| 147 | ar & BOOST_SERIALIZATION_NVP( lineNum );
|
|---|
| 148 | ar & BOOST_SERIALIZATION_NVP( nativeCodePos );
|
|---|
| 149 | ar & BOOST_SERIALIZATION_NVP( sourceIndex );
|
|---|
| 150 | ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
|
|---|
| 151 | ar & BOOST_SERIALIZATION_NVP( codeType );
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | public:
|
|---|
| 155 | SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
|
|---|
| 156 | : lineNum( lineNum )
|
|---|
| 157 | , nativeCodePos( nativeCodePos )
|
|---|
| 158 | , sourceIndex( sourceIndex )
|
|---|
| 159 | , sourceCodePos( sourceCodePos )
|
|---|
| 160 | , codeType( codeType )
|
|---|
| 161 | {
|
|---|
| 162 | }
|
|---|
| 163 | SourceLine()
|
|---|
| 164 | {
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | int GetLineNum() const
|
|---|
| 168 | {
|
|---|
| 169 | return lineNum;
|
|---|
| 170 | }
|
|---|
| 171 | long GetNativeCodePos() const
|
|---|
| 172 | {
|
|---|
| 173 | return nativeCodePos;
|
|---|
| 174 | }
|
|---|
| 175 | int GetSourceIndex() const
|
|---|
| 176 | {
|
|---|
| 177 | return sourceIndex;
|
|---|
| 178 | }
|
|---|
| 179 | void SetSourceIndex( int sourceIndex )
|
|---|
| 180 | {
|
|---|
| 181 | this->sourceIndex = sourceIndex;
|
|---|
| 182 | }
|
|---|
| 183 | long GetSourceCodePos() const
|
|---|
| 184 | {
|
|---|
| 185 | return sourceCodePos;
|
|---|
| 186 | }
|
|---|
| 187 | void SetSourceCodePos( int sourceCodePos )
|
|---|
| 188 | {
|
|---|
| 189 | this->sourceCodePos = sourceCodePos;
|
|---|
| 190 | }
|
|---|
| 191 | DWORD GetCodeType() const
|
|---|
| 192 | {
|
|---|
| 193 | return codeType;
|
|---|
| 194 | }
|
|---|
| 195 | bool IsInSystemProc() const
|
|---|
| 196 | {
|
|---|
| 197 | return ( (codeType&CODETYPE_SYSTEMPROC) != 0 );
|
|---|
| 198 | }
|
|---|
| 199 | bool IsInDebugProc() const
|
|---|
| 200 | {
|
|---|
| 201 | return ( (codeType&CODETYPE_DEBUGPROC) != 0 );
|
|---|
| 202 | }
|
|---|
| 203 | };
|
|---|
| 204 | typedef std::vector<SourceLine> SourceLines;
|
|---|
| 205 |
|
|---|
| 206 | class NativeCode : public Binary
|
|---|
| 207 | {
|
|---|
| 208 | // リンカで解決しなければならないスケジュール
|
|---|
| 209 | Schedules schedules;
|
|---|
| 210 |
|
|---|
| 211 | // ソースコード行番号とネイティブコード位置の対応情報
|
|---|
| 212 | SourceLines sourceLines;
|
|---|
| 213 |
|
|---|
| 214 | // XMLシリアライズ用
|
|---|
| 215 | private:
|
|---|
| 216 | friend class boost::serialization::access;
|
|---|
| 217 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
|---|
| 218 | {
|
|---|
| 219 | trace_for_serialize( "serializing(load) - NativeCode" );
|
|---|
| 220 |
|
|---|
| 221 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Binary );
|
|---|
| 222 | ar & BOOST_SERIALIZATION_NVP( schedules );
|
|---|
| 223 | ar & BOOST_SERIALIZATION_NVP( sourceLines );
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | public:
|
|---|
| 227 | NativeCode()
|
|---|
| 228 | : Binary()
|
|---|
| 229 | {
|
|---|
| 230 | }
|
|---|
| 231 | NativeCode( const NativeCode &nativeCode )
|
|---|
| 232 | : Binary()
|
|---|
| 233 | {
|
|---|
| 234 | PutEx( nativeCode );
|
|---|
| 235 | }
|
|---|
| 236 | NativeCode( const char *codeBuffer, int size )
|
|---|
| 237 | : Binary( codeBuffer, size )
|
|---|
| 238 | {
|
|---|
| 239 | }
|
|---|
| 240 | ~NativeCode()
|
|---|
| 241 | {
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | void operator =( const NativeCode &nativeCode )
|
|---|
| 245 | {
|
|---|
| 246 | Clear();
|
|---|
| 247 | PutEx( nativeCode );
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | const Schedules &GetSchedules() const
|
|---|
| 251 | {
|
|---|
| 252 | return schedules;
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | void PutEx( const NativeCode &nativeCode );
|
|---|
| 256 | void PutEx( long l, Schedule::Type scheduleType );
|
|---|
| 257 | void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
|
|---|
| 258 | void PutCatchAddressSchedule( const UserProc *pUserProc, long codePos );
|
|---|
| 259 | void PutDllProcSchedule( const DllProc *pDllProc );
|
|---|
| 260 | void PutComVtblSchedule( const CClass *pClass );
|
|---|
| 261 | void PutVtblSchedule( const CClass *pClass );
|
|---|
| 262 |
|
|---|
| 263 | const SourceLines &GetSourceLines() const
|
|---|
| 264 | {
|
|---|
| 265 | return sourceLines;
|
|---|
| 266 | }
|
|---|
| 267 | void NextSourceLine();
|
|---|
| 268 |
|
|---|
| 269 | void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
|
|---|
| 270 | void ResetSourceIndexes( long sourceIndexBase );
|
|---|
| 271 | };
|
|---|