[232] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[280] | 3 | #include <Compiler.h>
|
---|
[245] | 4 |
|
---|
[237] | 5 | #define BREAK_EIP(checkEip) (obp+0x00401000>=checkEip)
|
---|
[232] | 6 |
|
---|
[465] | 7 | const ::DllProc &Schedule::GetDllProc() const
|
---|
| 8 | {
|
---|
[549] | 9 | _ASSERT( type == Schedule::DllProc );
|
---|
[465] | 10 | return *pDllProc;
|
---|
| 11 | }
|
---|
| 12 | const ::UserProc &Schedule::GetUserProc() const
|
---|
| 13 | {
|
---|
[549] | 14 | _ASSERT( type == Schedule::UserProc || type == Schedule::AddressOf || type == Schedule::CatchAddress );
|
---|
[465] | 15 | return *pUserProc;
|
---|
| 16 | }
|
---|
| 17 | const ::CClass &Schedule::GetClass() const
|
---|
| 18 | {
|
---|
[549] | 19 | _ASSERT( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo );
|
---|
[465] | 20 | return *pClass;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | void Schedule::SpecifyAddressOf()
|
---|
| 24 | {
|
---|
[549] | 25 | _ASSERT( type == Schedule::UserProc );
|
---|
[465] | 26 | type = Schedule::AddressOf;
|
---|
| 27 | }
|
---|
| 28 | void Schedule::SpecifyCatchAddress()
|
---|
| 29 | {
|
---|
[549] | 30 | _ASSERT( type == Schedule::UserProc );
|
---|
[465] | 31 | type = Schedule::CatchAddress;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[287] | 34 | void NativeCode::PutEx( const NativeCode &nativeCode )
|
---|
[232] | 35 | {
|
---|
[287] | 36 | long baseOffset = GetSize();
|
---|
[257] | 37 |
|
---|
[263] | 38 | // コードバッファを追加
|
---|
[287] | 39 | Put( nativeCode.GetBuffer(), nativeCode.GetSize() );
|
---|
[257] | 40 |
|
---|
[263] | 41 | // スケジュールを追加
|
---|
[257] | 42 | BOOST_FOREACH( const Schedule &schedule, nativeCode.schedules )
|
---|
| 43 | {
|
---|
| 44 | this->schedules.push_back(
|
---|
| 45 | Schedule(
|
---|
| 46 | schedule.GetType(),
|
---|
[258] | 47 | baseOffset + schedule.GetOffset(),
|
---|
| 48 | schedule.GetLongPtrValue()
|
---|
[257] | 49 | )
|
---|
| 50 | );
|
---|
| 51 | }
|
---|
[263] | 52 |
|
---|
| 53 | // ソースコード行番号とネイティブコード位置の対応情報を追加
|
---|
| 54 | BOOST_FOREACH( const SourceLine &sourceLine, nativeCode.sourceLines )
|
---|
| 55 | {
|
---|
| 56 | this->sourceLines.push_back(
|
---|
| 57 | SourceLine(
|
---|
| 58 | sourceLine.GetLineNum(),
|
---|
| 59 | baseOffset + sourceLine.GetNativeCodePos(),
|
---|
[280] | 60 | sourceLine.GetSourceIndex(),
|
---|
[263] | 61 | sourceLine.GetSourceCodePos(),
|
---|
| 62 | sourceLine.GetCodeType()
|
---|
| 63 | )
|
---|
| 64 | );
|
---|
| 65 | }
|
---|
[257] | 66 | }
|
---|
| 67 |
|
---|
[357] | 68 | void NativeCode::PutEx( long l, Schedule::Type scheduleType )
|
---|
| 69 | {
|
---|
| 70 | if( scheduleType == Schedule::CatchAddress )
|
---|
| 71 | {
|
---|
[537] | 72 | const UserProc *pUserProc = &compiler.GetCompilingUserProc();
|
---|
| 73 | if( compiler.IsGlobalAreaCompiling() )
|
---|
[364] | 74 | {
|
---|
| 75 | pUserProc = UserProc::pGlobalProc;
|
---|
| 76 | }
|
---|
| 77 | PutCatchAddressSchedule( pUserProc, l );
|
---|
[357] | 78 | }
|
---|
| 79 | else
|
---|
| 80 | {
|
---|
| 81 | if( scheduleType != Schedule::None )
|
---|
| 82 | {
|
---|
| 83 | schedules.push_back( Schedule( scheduleType, GetSize() ) );
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | Put( l );
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[245] | 90 | void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
|
---|
| 91 | {
|
---|
| 92 | pUserProc->Using();
|
---|
| 93 |
|
---|
[287] | 94 | Schedule schedule( pUserProc, GetSize() );
|
---|
[245] | 95 | if( isCall == false )
|
---|
| 96 | {
|
---|
| 97 | schedule.SpecifyAddressOf();
|
---|
| 98 | }
|
---|
| 99 | schedules.push_back( schedule );
|
---|
| 100 |
|
---|
[287] | 101 | Put( (long)0 );
|
---|
[245] | 102 | }
|
---|
[250] | 103 |
|
---|
[357] | 104 | void NativeCode::PutCatchAddressSchedule( const UserProc *pUserProc, long codePos )
|
---|
| 105 | {
|
---|
| 106 | pUserProc->Using();
|
---|
| 107 |
|
---|
| 108 | Schedule schedule( pUserProc, GetSize() );
|
---|
| 109 | schedule.SpecifyCatchAddress();
|
---|
| 110 | schedules.push_back( schedule );
|
---|
| 111 |
|
---|
| 112 | Put( codePos );
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[250] | 115 | void NativeCode::PutDllProcSchedule( const DllProc *pDllProc )
|
---|
| 116 | {
|
---|
| 117 | pDllProc->Using();
|
---|
| 118 |
|
---|
[287] | 119 | schedules.push_back( Schedule( pDllProc, GetSize() ) );
|
---|
[250] | 120 |
|
---|
[287] | 121 | Put( (long)0 );
|
---|
[250] | 122 | }
|
---|
[263] | 123 |
|
---|
[370] | 124 | void NativeCode::PutComVtblSchedule( const CClass *pClass )
|
---|
| 125 | {
|
---|
| 126 | schedules.push_back( Schedule( Schedule::ComVtbl, pClass, GetSize() ) );
|
---|
| 127 |
|
---|
| 128 | Put( (long)0 );
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[282] | 131 | void NativeCode::PutVtblSchedule( const CClass *pClass )
|
---|
| 132 | {
|
---|
[370] | 133 | schedules.push_back( Schedule( Schedule::Vtbl, pClass, GetSize() ) );
|
---|
[282] | 134 |
|
---|
[287] | 135 | Put( (long)0 );
|
---|
[282] | 136 | }
|
---|
| 137 |
|
---|
[263] | 138 | void NativeCode::NextSourceLine()
|
---|
| 139 | {
|
---|
| 140 | if( sourceLines.size() )
|
---|
| 141 | {
|
---|
[287] | 142 | if( sourceLines.back().GetNativeCodePos() == GetSize() )
|
---|
[263] | 143 | {
|
---|
| 144 | sourceLines.back().SetSourceCodePos( cp );
|
---|
| 145 | return;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | extern BOOL bDebugSupportProc;
|
---|
| 150 | extern BOOL bSystemProc;
|
---|
| 151 | DWORD sourceLineType = 0;
|
---|
| 152 | if( bDebugSupportProc )
|
---|
| 153 | {
|
---|
| 154 | sourceLineType |= CODETYPE_DEBUGPROC;
|
---|
| 155 | }
|
---|
| 156 | if( bSystemProc )
|
---|
| 157 | {
|
---|
| 158 | sourceLineType |= CODETYPE_SYSTEMPROC;
|
---|
| 159 | }
|
---|
[280] | 160 | sourceLines.push_back(
|
---|
| 161 | SourceLine(
|
---|
| 162 | (long)sourceLines.size(),
|
---|
[287] | 163 | GetSize(),
|
---|
[280] | 164 | compiler.GetObjectModule().GetCurrentSourceIndex(),
|
---|
| 165 | cp,
|
---|
| 166 | sourceLineType
|
---|
| 167 | )
|
---|
| 168 | );
|
---|
[263] | 169 | }
|
---|
[273] | 170 |
|
---|
| 171 | void NativeCode::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
|
---|
| 172 | {
|
---|
| 173 | BOOST_FOREACH( const Schedule &schedule, schedules )
|
---|
| 174 | {
|
---|
| 175 | if( schedule.GetType() == Schedule::DataTable )
|
---|
| 176 | {
|
---|
| 177 | Overwrite(
|
---|
| 178 | schedule.GetOffset(),
|
---|
| 179 | GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
|
---|
| 180 | );
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
[280] | 184 | void NativeCode::ResetSourceIndexes( long sourceIndexBase )
|
---|
| 185 | {
|
---|
| 186 | BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
|
---|
| 187 | {
|
---|
| 188 | sourceLine.SetSourceIndex( sourceLine.GetSourceIndex() + sourceIndexBase );
|
---|
| 189 | }
|
---|
| 190 | }
|
---|