| 1 | #include "../BasicCompiler_Common/common.h" | 
|---|
| 2 |  | 
|---|
| 3 | #ifdef _AMD64_ | 
|---|
| 4 | #include "../BasicCompiler64/opcode.h" | 
|---|
| 5 | #else | 
|---|
| 6 | #include "../BasicCompiler32/opcode.h" | 
|---|
| 7 | #endif | 
|---|
| 8 |  | 
|---|
| 9 | #define MDLFILE_VER 0x70000003 | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | void SetLpIndex_DebugFile(char *buffer,int *p,const Type &type){ | 
|---|
| 13 | if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){ | 
|---|
| 14 | lstrcpy(buffer+(*p),type.GetClass().name); | 
|---|
| 15 | (*p)+=lstrlen(buffer+(*p))+1; | 
|---|
| 16 | } | 
|---|
| 17 | else{ | 
|---|
| 18 | *(LONG_PTR *)(buffer+(*p))=type.GetIndex(); | 
|---|
| 19 | (*p)+=sizeof(LONG_PTR); | 
|---|
| 20 | } | 
|---|
| 21 | } | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 | void GetLpIndex_DebugFile(char *buffer,int *p,Type &type){ | 
|---|
| 25 | if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){ | 
|---|
| 26 | char szClassName[VN_SIZE]; | 
|---|
| 27 | lstrcpy(szClassName,buffer+(*p)); | 
|---|
| 28 | (*p)+=lstrlen(buffer+(*p))+1; | 
|---|
| 29 |  | 
|---|
| 30 | type.SetIndex( (LONG_PTR)pobj_DBClass->Find(szClassName) ); | 
|---|
| 31 | } | 
|---|
| 32 | else{ | 
|---|
| 33 | type.SetIndex( *(LONG_PTR *)(buffer+(*p)) ); | 
|---|
| 34 | (*p)+=sizeof(LONG_PTR); | 
|---|
| 35 | } | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 | CDebugSection::CDebugSection(){ | 
|---|
| 41 | memset(this,0,sizeof(CDebugSection)); | 
|---|
| 42 | } | 
|---|
| 43 | CDebugSection::~CDebugSection(){ | 
|---|
| 44 | if(pobj_DBClass) DeleteDebugInfo(); | 
|---|
| 45 | if(buffer){ | 
|---|
| 46 | HeapDefaultFree(buffer); | 
|---|
| 47 | buffer=0; | 
|---|
| 48 | } | 
|---|
| 49 | } | 
|---|
| 50 | void CDebugSection::make(void){ | 
|---|
| 51 | extern INCLUDEFILEINFO IncludeFileInfo; | 
|---|
| 52 | int i2,i3,i4,i5,BufferSize; | 
|---|
| 53 |  | 
|---|
| 54 | if(buffer){ | 
|---|
| 55 | HeapDefaultFree(buffer); | 
|---|
| 56 | buffer=0; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | i2=0; | 
|---|
| 60 |  | 
|---|
| 61 | extern char *basbuf; | 
|---|
| 62 | BufferSize=lstrlen(basbuf)+65535; | 
|---|
| 63 | buffer=(char *)HeapAlloc(hHeap,0,BufferSize); | 
|---|
| 64 |  | 
|---|
| 65 | //デバッグ用ファイルのバージョン | 
|---|
| 66 | *(long *)(buffer+i2)=MDLFILE_VER; | 
|---|
| 67 | i2+=sizeof(long); | 
|---|
| 68 |  | 
|---|
| 69 | //プラットフォームのビット数 | 
|---|
| 70 | *(long *)(buffer+i2)=PLATFORM; | 
|---|
| 71 | i2+=sizeof(long); | 
|---|
| 72 |  | 
|---|
| 73 | //インクルード情報 | 
|---|
| 74 | *(long *)(buffer+i2)=IncludeFileInfo.FilesNum; | 
|---|
| 75 | i2+=sizeof(long); | 
|---|
| 76 | for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){ | 
|---|
| 77 | lstrcpy(buffer+i2,IncludeFileInfo.ppFileNames[i3]); | 
|---|
| 78 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 79 | } | 
|---|
| 80 | buffer[i2++]=0; | 
|---|
| 81 | for(i3=0;;i3++){ | 
|---|
| 82 | buffer[i2++]=(char)IncludeFileInfo.LineOfFile[i3]; | 
|---|
| 83 | if(IncludeFileInfo.LineOfFile[i3]==-1) break; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | //ソースコード | 
|---|
| 87 | lstrcpy(buffer+i2,basbuf); | 
|---|
| 88 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 89 |  | 
|---|
| 90 |  | 
|---|
| 91 | //////////////////////// | 
|---|
| 92 | // コードと行番号の関係 | 
|---|
| 93 | //////////////////////// | 
|---|
| 94 | extern int MaxLineInfoNum; | 
|---|
| 95 | extern LINEINFO *pLineInfo; | 
|---|
| 96 |  | 
|---|
| 97 | //バッファが足りない場合は再確保 | 
|---|
| 98 | if(MaxLineInfoNum*sizeof(LINEINFO)<32768) i3=32768; | 
|---|
| 99 | else i3=MaxLineInfoNum*sizeof(LINEINFO)+32768; | 
|---|
| 100 | if(BufferSize<i2+i3){ | 
|---|
| 101 | BufferSize+=i3; | 
|---|
| 102 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | *(long *)(buffer+i2)=MaxLineInfoNum; | 
|---|
| 106 | i2+=sizeof(long); | 
|---|
| 107 | memcpy(buffer+i2,pLineInfo,MaxLineInfoNum*sizeof(LINEINFO)); | 
|---|
| 108 | i2+=MaxLineInfoNum*sizeof(LINEINFO); | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | //////////////////////////////////////////// | 
|---|
| 113 | // クラス情報(名前のみ。詳細は後で保存) | 
|---|
| 114 | //////////////////////////////////////////// | 
|---|
| 115 |  | 
|---|
| 116 | //イテレータをリセット | 
|---|
| 117 | extern CDBClass *pobj_DBClass; | 
|---|
| 118 | pobj_DBClass->Iterator_Reset(); | 
|---|
| 119 |  | 
|---|
| 120 | //個数 | 
|---|
| 121 | *(long *)(buffer+i2)=pobj_DBClass->Iterator_GetMaxCount(); | 
|---|
| 122 | i2+=sizeof(long); | 
|---|
| 123 |  | 
|---|
| 124 | while(pobj_DBClass->Iterator_HasNext()){ | 
|---|
| 125 | CClass *pobj_c; | 
|---|
| 126 | pobj_c=pobj_DBClass->Iterator_GetNext(); | 
|---|
| 127 |  | 
|---|
| 128 | //クラス名 | 
|---|
| 129 | lstrcpy(buffer+i2,pobj_c->name); | 
|---|
| 130 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 |  | 
|---|
| 134 |  | 
|---|
| 135 | ////////////////// | 
|---|
| 136 | // TypeDef情報 | 
|---|
| 137 | ////////////////// | 
|---|
| 138 | *(long *)(buffer+i2)=(int)Smoothie::Meta::typeDefs.size(); | 
|---|
| 139 | i2+=sizeof(long); | 
|---|
| 140 | for(i3=0;i3<(int)Smoothie::Meta::typeDefs.size();i3++){ | 
|---|
| 141 | lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetNewName().c_str() ); | 
|---|
| 142 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 143 |  | 
|---|
| 144 | lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetBaseName().c_str() ); | 
|---|
| 145 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 146 |  | 
|---|
| 147 | //バッファが足りない場合は再確保 | 
|---|
| 148 | if(BufferSize<i2+32768){ | 
|---|
| 149 | BufferSize+=32768; | 
|---|
| 150 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 151 | } | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 |  | 
|---|
| 155 | //グローバル変数情報 | 
|---|
| 156 | *(long *)(buffer+i2)=(int)::globalVars.size(); | 
|---|
| 157 | i2+=sizeof(long); | 
|---|
| 158 | foreach( Variable *pVar, ::globalVars ){ | 
|---|
| 159 | //変数名 | 
|---|
| 160 | lstrcpy(buffer+i2,pVar->GetName().c_str()); | 
|---|
| 161 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 162 |  | 
|---|
| 163 | //型 | 
|---|
| 164 | *(long *)(buffer+i2)=pVar->GetBasicType(); | 
|---|
| 165 | i2+=sizeof(long); | 
|---|
| 166 |  | 
|---|
| 167 | //型の拡張情報 | 
|---|
| 168 | SetLpIndex_DebugFile(buffer,&i2,*pVar); | 
|---|
| 169 |  | 
|---|
| 170 | buffer[i2++] = pVar->IsRef() ? 1 : 0; | 
|---|
| 171 |  | 
|---|
| 172 | buffer[i2++] = pVar->IsArray() ? 1 : 0; | 
|---|
| 173 |  | 
|---|
| 174 | if(pVar->IsArray()){ | 
|---|
| 175 | for(i5=0;;i5++){ | 
|---|
| 176 | *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5]; | 
|---|
| 177 | i2+=sizeof(long); | 
|---|
| 178 | if(pVar->GetSubScriptsPtr()[i5]==-1) break; | 
|---|
| 179 | } | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | //レキシカルスコープ情報 | 
|---|
| 183 | *(long *)(buffer+i2)=pVar->ScopeStartAddress; | 
|---|
| 184 | i2+=sizeof(long); | 
|---|
| 185 | *(long *)(buffer+i2)=pVar->ScopeEndAddress; | 
|---|
| 186 | i2+=sizeof(long); | 
|---|
| 187 | *(long *)(buffer+i2)=pVar->ScopeLevel; | 
|---|
| 188 | i2+=sizeof(long); | 
|---|
| 189 |  | 
|---|
| 190 | //メモリ位置 | 
|---|
| 191 | *(long *)(buffer+i2)=pVar->offset; | 
|---|
| 192 | i2+=sizeof(long); | 
|---|
| 193 |  | 
|---|
| 194 | //バッファが足りない場合は再確保 | 
|---|
| 195 | if(BufferSize<i2+32768){ | 
|---|
| 196 | BufferSize+=32768; | 
|---|
| 197 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 198 | } | 
|---|
| 199 | } | 
|---|
| 200 |  | 
|---|
| 201 | //グローバル実行領域のサイズ | 
|---|
| 202 | extern int GlobalOpBufferSize; | 
|---|
| 203 | *(long *)(buffer+i2)=GlobalOpBufferSize; | 
|---|
| 204 | i2+=sizeof(long); | 
|---|
| 205 |  | 
|---|
| 206 | //プロシージャ情報 | 
|---|
| 207 | extern GlobalProc **ppSubHash; | 
|---|
| 208 | extern int SubNum; | 
|---|
| 209 | GlobalProc *pUserProc; | 
|---|
| 210 | *(long *)(buffer+i2)=SubNum; | 
|---|
| 211 | i2+=sizeof(long); | 
|---|
| 212 | for(i3=0;i3<MAX_HASH;i3++){ | 
|---|
| 213 | pUserProc=ppSubHash[i3]; | 
|---|
| 214 | while(pUserProc){ | 
|---|
| 215 | if(pUserProc->GetParentClassPtr()){ | 
|---|
| 216 | lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->name); | 
|---|
| 217 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 218 | } | 
|---|
| 219 | else{ | 
|---|
| 220 | lstrcpy(buffer+i2,""); | 
|---|
| 221 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 222 | } | 
|---|
| 223 |  | 
|---|
| 224 | //ID | 
|---|
| 225 | *(long *)(buffer+i2)=pUserProc->id; | 
|---|
| 226 | i2+=sizeof(long); | 
|---|
| 227 |  | 
|---|
| 228 | //関数名 | 
|---|
| 229 | lstrcpy(buffer+i2,pUserProc->GetName().c_str()); | 
|---|
| 230 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 231 |  | 
|---|
| 232 | *(long *)(buffer+i2)=pUserProc->beginOpAddress; | 
|---|
| 233 | i2+=sizeof(long); | 
|---|
| 234 | *(long *)(buffer+i2)=pUserProc->endOpAddress; | 
|---|
| 235 | i2+=sizeof(long); | 
|---|
| 236 |  | 
|---|
| 237 | //ローカル変数情報 | 
|---|
| 238 | *(long *)(buffer+i2)=(int)pUserProc->localVars.size(); | 
|---|
| 239 | i2+=sizeof(long); | 
|---|
| 240 |  | 
|---|
| 241 | //バッファが足りない場合は再確保 | 
|---|
| 242 | if(BufferSize<i2+32768){ | 
|---|
| 243 | BufferSize+=32768; | 
|---|
| 244 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 245 | } | 
|---|
| 246 |  | 
|---|
| 247 | foreach( Variable *pVar, pUserProc->localVars ){ | 
|---|
| 248 | lstrcpy(buffer+i2,pVar->GetName().c_str()); | 
|---|
| 249 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 250 |  | 
|---|
| 251 | //型 | 
|---|
| 252 | *(long *)(buffer+i2)=pVar->GetBasicType(); | 
|---|
| 253 | i2+=sizeof(long); | 
|---|
| 254 |  | 
|---|
| 255 | //型の拡張情報 | 
|---|
| 256 | SetLpIndex_DebugFile(buffer,&i2,*pVar); | 
|---|
| 257 |  | 
|---|
| 258 | //参照型パラメータかどうか | 
|---|
| 259 | buffer[i2++] = pVar->IsRef() ? 1 : 0; | 
|---|
| 260 |  | 
|---|
| 261 | //配列かどうか | 
|---|
| 262 | buffer[i2++] = pVar->IsArray() ? 1 : 0; | 
|---|
| 263 |  | 
|---|
| 264 | //配列要素 | 
|---|
| 265 | if(pVar->IsArray()){ | 
|---|
| 266 | for(i5=0;;i5++){ | 
|---|
| 267 | *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5]; | 
|---|
| 268 | i2+=sizeof(long); | 
|---|
| 269 | if(pVar->GetSubScriptsPtr()[i5]==-1) break; | 
|---|
| 270 | } | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | //レキシカルスコープ情報 | 
|---|
| 274 | *(long *)(buffer+i2)=pVar->ScopeStartAddress; | 
|---|
| 275 | i2+=sizeof(long); | 
|---|
| 276 | *(long *)(buffer+i2)=pVar->ScopeEndAddress; | 
|---|
| 277 | i2+=sizeof(long); | 
|---|
| 278 | *(long *)(buffer+i2)=pVar->ScopeLevel; | 
|---|
| 279 | i2+=sizeof(long); | 
|---|
| 280 |  | 
|---|
| 281 | //メモリ位置 | 
|---|
| 282 | *(long *)(buffer+i2)=pVar->offset; | 
|---|
| 283 | i2+=sizeof(long); | 
|---|
| 284 |  | 
|---|
| 285 |  | 
|---|
| 286 |  | 
|---|
| 287 |  | 
|---|
| 288 | //バッファが足りない場合は再確保 | 
|---|
| 289 | if(BufferSize<i2+32768){ | 
|---|
| 290 | BufferSize+=32768; | 
|---|
| 291 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 292 | } | 
|---|
| 293 | } | 
|---|
| 294 |  | 
|---|
| 295 | pUserProc=pUserProc->pNextData; | 
|---|
| 296 | } | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 |  | 
|---|
| 300 |  | 
|---|
| 301 | /////////////////// | 
|---|
| 302 | // クラス情報 | 
|---|
| 303 | /////////////////// | 
|---|
| 304 |  | 
|---|
| 305 | //イテレータをリセット | 
|---|
| 306 | pobj_DBClass->Iterator_Reset(); | 
|---|
| 307 |  | 
|---|
| 308 | while(pobj_DBClass->Iterator_HasNext()){ | 
|---|
| 309 | CClass *pobj_c; | 
|---|
| 310 | pobj_c=pobj_DBClass->Iterator_GetNext(); | 
|---|
| 311 |  | 
|---|
| 312 |  | 
|---|
| 313 | //クラス名 | 
|---|
| 314 | lstrcpy(buffer+i2,pobj_c->name); | 
|---|
| 315 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 316 |  | 
|---|
| 317 | //仮想関数の数 | 
|---|
| 318 | *(long *)(buffer+i2)=pobj_c->vtbl_num; | 
|---|
| 319 | i2+=sizeof(long); | 
|---|
| 320 |  | 
|---|
| 321 | //アラインメント | 
|---|
| 322 | *(long *)(buffer+i2)=pobj_c->iAlign; | 
|---|
| 323 | i2+=sizeof(long); | 
|---|
| 324 |  | 
|---|
| 325 | //メンバ | 
|---|
| 326 | *(long *)(buffer+i2)=pobj_c->iMemberNum; | 
|---|
| 327 | i2+=sizeof(long); | 
|---|
| 328 | for(i4=0;i4<pobj_c->iMemberNum;i4++){ | 
|---|
| 329 | lstrcpy(buffer+i2,pobj_c->ppobj_Member[i4]->name); | 
|---|
| 330 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 331 |  | 
|---|
| 332 | memcpy(buffer+i2,pobj_c->ppobj_Member[i4]->SubScripts,sizeof(int)*MAX_ARRAYDIM); | 
|---|
| 333 | i2+=sizeof(int)*MAX_ARRAYDIM; | 
|---|
| 334 |  | 
|---|
| 335 | //型 | 
|---|
| 336 | *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetBasicType(); | 
|---|
| 337 | i2+=sizeof(long); | 
|---|
| 338 |  | 
|---|
| 339 | //型の拡張情報 | 
|---|
| 340 | SetLpIndex_DebugFile(buffer,&i2,*pobj_c->ppobj_Member[i4]); | 
|---|
| 341 |  | 
|---|
| 342 | *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->dwAccess; | 
|---|
| 343 | i2+=sizeof(long); | 
|---|
| 344 |  | 
|---|
| 345 | //バッファが足りない場合は再確保 | 
|---|
| 346 | if(BufferSize<i2+32768){ | 
|---|
| 347 | BufferSize+=32768; | 
|---|
| 348 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 349 | } | 
|---|
| 350 | } | 
|---|
| 351 |  | 
|---|
| 352 | //メソッド | 
|---|
| 353 | *(long *)(buffer+i2)=(long)pobj_c->methods.size(); | 
|---|
| 354 | i2+=sizeof(long); | 
|---|
| 355 | foreach( CMethod *method, pobj_c->methods ){ | 
|---|
| 356 | *(long *)(buffer+i2)=method->dwAccess; | 
|---|
| 357 | i2+=sizeof(long); | 
|---|
| 358 | if(method->pobj_InheritsClass){ | 
|---|
| 359 | lstrcpy(buffer+i2,method->pobj_InheritsClass->name); | 
|---|
| 360 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 361 | } | 
|---|
| 362 | else{ | 
|---|
| 363 | lstrcpy(buffer+i2,""); | 
|---|
| 364 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 365 | } | 
|---|
| 366 | lstrcpy(buffer+i2,method->pUserProc->GetName().c_str()); | 
|---|
| 367 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 368 | } | 
|---|
| 369 |  | 
|---|
| 370 | //静的メンバ | 
|---|
| 371 | *(long *)(buffer+i2)=(long)pobj_c->staticMembers.size(); | 
|---|
| 372 | i2+=sizeof(long); | 
|---|
| 373 | foreach( CMember *member, pobj_c->staticMembers ){ | 
|---|
| 374 | lstrcpy(buffer+i2,member->name); | 
|---|
| 375 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 376 |  | 
|---|
| 377 | memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM); | 
|---|
| 378 | i2+=sizeof(int)*MAX_ARRAYDIM; | 
|---|
| 379 |  | 
|---|
| 380 | //型 | 
|---|
| 381 | *(long *)(buffer+i2)=member->GetBasicType(); | 
|---|
| 382 | i2+=sizeof(long); | 
|---|
| 383 |  | 
|---|
| 384 | //型の拡張情報 | 
|---|
| 385 | SetLpIndex_DebugFile(buffer,&i2,*member); | 
|---|
| 386 |  | 
|---|
| 387 | *(long *)(buffer+i2)=member->dwAccess; | 
|---|
| 388 | i2+=sizeof(long); | 
|---|
| 389 |  | 
|---|
| 390 | //バッファが足りない場合は再確保 | 
|---|
| 391 | if(BufferSize<i2+32768){ | 
|---|
| 392 | BufferSize+=32768; | 
|---|
| 393 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 394 | } | 
|---|
| 395 | } | 
|---|
| 396 |  | 
|---|
| 397 | //バッファが足りない場合は再確保 | 
|---|
| 398 | if(BufferSize<i2+32768){ | 
|---|
| 399 | BufferSize+=32768; | 
|---|
| 400 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); | 
|---|
| 401 | } | 
|---|
| 402 | } | 
|---|
| 403 |  | 
|---|
| 404 | length=i2; | 
|---|
| 405 | } | 
|---|
| 406 |  | 
|---|
| 407 | char *CDebugSection::MakeSingleStepCode(void){ | 
|---|
| 408 | char *buffer; | 
|---|
| 409 | buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection); | 
|---|
| 410 |  | 
|---|
| 411 | memcpy(buffer,OpBuffer,SizeOf_CodeSection); | 
|---|
| 412 |  | 
|---|
| 413 | int i2; | 
|---|
| 414 | for(i2=0;i2<MaxLineInfoNum;i2++){ | 
|---|
| 415 | if(!( | 
|---|
| 416 | pLineInfo[i2].dwCodeType&CODETYPE_SYSTEMPROC|| | 
|---|
| 417 | pLineInfo[i2].dwCodeType&CODETYPE_DEBUGPROC | 
|---|
| 418 | )){ | 
|---|
| 419 | //int 3 | 
|---|
| 420 | buffer[pLineInfo[i2].TopObp]=(char)0xCC; | 
|---|
| 421 | } | 
|---|
| 422 | } | 
|---|
| 423 |  | 
|---|
| 424 | return buffer; | 
|---|
| 425 | } | 
|---|
| 426 | BOOL CDebugSection::__load(void){ | 
|---|
| 427 | int i2,i3,i4,i5,num; | 
|---|
| 428 | char temp2[MAX_PATH],*temp5; | 
|---|
| 429 |  | 
|---|
| 430 | extern CClass *pobj_CompilingClass; | 
|---|
| 431 | pobj_CompilingClass=0; | 
|---|
| 432 |  | 
|---|
| 433 | i2=0; | 
|---|
| 434 |  | 
|---|
| 435 | //デバッグ用ファイルのバージョンをチェック | 
|---|
| 436 | if(*(long *)(buffer+i2)<MDLFILE_VER){ | 
|---|
| 437 | HeapDefaultFree(buffer); | 
|---|
| 438 | return 0; | 
|---|
| 439 | } | 
|---|
| 440 | i2+=sizeof(long); | 
|---|
| 441 |  | 
|---|
| 442 | //プラットフォームのビット数をチェック | 
|---|
| 443 | if(*(long *)(buffer+i2)!=PLATFORM){ | 
|---|
| 444 | HeapDefaultFree(buffer); | 
|---|
| 445 | return 0; | 
|---|
| 446 | } | 
|---|
| 447 | i2+=sizeof(long); | 
|---|
| 448 |  | 
|---|
| 449 | //インクルード情報 | 
|---|
| 450 | IncludeFileInfo.FilesNum=*(long *)(buffer+i2); | 
|---|
| 451 | i2+=sizeof(long); | 
|---|
| 452 | IncludeFileInfo.ppFileNames=(char **)HeapAlloc(hHeap,0,IncludeFileInfo.FilesNum*sizeof(char *)); | 
|---|
| 453 | for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){ | 
|---|
| 454 | if(buffer[i2]=='\0') break; | 
|---|
| 455 | IncludeFileInfo.ppFileNames[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1); | 
|---|
| 456 | lstrcpy(IncludeFileInfo.ppFileNames[i3],buffer+i2); | 
|---|
| 457 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 458 | } | 
|---|
| 459 | for(i2++,i3=0;;i2++,i3++){ | 
|---|
| 460 | IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2]; | 
|---|
| 461 | if(IncludeFileInfo.LineOfFile[i3]==-1) break; | 
|---|
| 462 | } | 
|---|
| 463 |  | 
|---|
| 464 | //ソースコード | 
|---|
| 465 | i2++; | 
|---|
| 466 | source.SetBuffer( buffer + i2 ); | 
|---|
| 467 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 468 |  | 
|---|
| 469 | //コードと行番号の関係 | 
|---|
| 470 | MaxLineInfoNum=*(long *)(buffer+i2); | 
|---|
| 471 | i2+=sizeof(long); | 
|---|
| 472 | pLineInfo=(LINEINFO *)HeapAlloc(hHeap,0,MaxLineInfoNum*sizeof(LINEINFO)+1); | 
|---|
| 473 | memcpy(pLineInfo,buffer+i2,MaxLineInfoNum*sizeof(LINEINFO)); | 
|---|
| 474 | i2+=MaxLineInfoNum*sizeof(LINEINFO); | 
|---|
| 475 |  | 
|---|
| 476 |  | 
|---|
| 477 | /////////////////////////////////////////// | 
|---|
| 478 | // クラス情報(名前のみ。詳細は後で取得) | 
|---|
| 479 | /////////////////////////////////////////// | 
|---|
| 480 |  | 
|---|
| 481 | this->pobj_DBClass=new CDBClass(); | 
|---|
| 482 |  | 
|---|
| 483 | int iMaxClassCount; | 
|---|
| 484 | iMaxClassCount=*(long *)(buffer+i2); | 
|---|
| 485 | i2+=sizeof(long); | 
|---|
| 486 | for(i3=0;i3<iMaxClassCount;i3++){ | 
|---|
| 487 | //クラス名 | 
|---|
| 488 | // TODO: 名前空間が未完成 | 
|---|
| 489 | pobj_DBClass->AddClass(NamespaceScopes(),buffer+i2,0); | 
|---|
| 490 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 491 | } | 
|---|
| 492 |  | 
|---|
| 493 | extern CDBClass *pobj_DBClass; | 
|---|
| 494 | pobj_DBClass=this->pobj_DBClass; | 
|---|
| 495 |  | 
|---|
| 496 |  | 
|---|
| 497 | ////////////////// | 
|---|
| 498 | // TypeDef情報 | 
|---|
| 499 | ////////////////// | 
|---|
| 500 |  | 
|---|
| 501 | //初期化 | 
|---|
| 502 | Smoothie::Meta::typeDefs.clear(); | 
|---|
| 503 |  | 
|---|
| 504 | //個数を取得 | 
|---|
| 505 | num=*(long *)(buffer+i2); | 
|---|
| 506 | i2+=sizeof(long); | 
|---|
| 507 | for(i3=0;i3<num;i3++){ | 
|---|
| 508 | temp5=buffer+i2; | 
|---|
| 509 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 510 |  | 
|---|
| 511 | Smoothie::Meta::typeDefs.push_back( TypeDef( temp5, buffer+i2 ) ); | 
|---|
| 512 |  | 
|---|
| 513 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 514 | } | 
|---|
| 515 |  | 
|---|
| 516 | //定数を取得 | 
|---|
| 517 | GetConstInfo(); | 
|---|
| 518 | extern CONSTINFO **ppConstHash; | 
|---|
| 519 | this->ppConstHash=ppConstHash; | 
|---|
| 520 |  | 
|---|
| 521 |  | 
|---|
| 522 | //グローバル変数情報 | 
|---|
| 523 | globalVars.clear(); | 
|---|
| 524 | int maxGlobalVars=*(long *)(buffer+i2); | 
|---|
| 525 | i2+=sizeof(long); | 
|---|
| 526 | for(i3=0;i3<maxGlobalVars;i3++){ | 
|---|
| 527 |  | 
|---|
| 528 | //変数名 | 
|---|
| 529 | char *name = buffer+i2; | 
|---|
| 530 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 531 |  | 
|---|
| 532 | int basicType = *(long *)(buffer+i2); | 
|---|
| 533 | i2+=sizeof(long); | 
|---|
| 534 |  | 
|---|
| 535 | Type type( basicType ); | 
|---|
| 536 | GetLpIndex_DebugFile(buffer,&i2,type); | 
|---|
| 537 |  | 
|---|
| 538 | bool isRef = (buffer[i2++]) ? true:false; | 
|---|
| 539 |  | 
|---|
| 540 | bool isArray = (buffer[i2++]) ? true:false; | 
|---|
| 541 |  | 
|---|
| 542 | Variable *pVar = new Variable( name, type, false, isRef ); | 
|---|
| 543 |  | 
|---|
| 544 | if(isArray){ | 
|---|
| 545 | int SubScripts[MAX_ARRAYDIM]; | 
|---|
| 546 | for(i4=0;;i4++){ | 
|---|
| 547 | SubScripts[i4]=*(long *)(buffer+i2); | 
|---|
| 548 | i2+=sizeof(long); | 
|---|
| 549 |  | 
|---|
| 550 | if(SubScripts[i4]==-1) break; | 
|---|
| 551 | } | 
|---|
| 552 |  | 
|---|
| 553 | pVar->SetArray( SubScripts ); | 
|---|
| 554 | } | 
|---|
| 555 |  | 
|---|
| 556 | //レキシカルスコープ情報 | 
|---|
| 557 | pVar->ScopeStartAddress=*(long *)(buffer+i2); | 
|---|
| 558 | i2+=sizeof(long); | 
|---|
| 559 | pVar->ScopeEndAddress=*(long *)(buffer+i2); | 
|---|
| 560 | i2+=sizeof(long); | 
|---|
| 561 | pVar->ScopeLevel=*(long *)(buffer+i2); | 
|---|
| 562 | i2+=sizeof(long); | 
|---|
| 563 |  | 
|---|
| 564 | //メモリ位置 | 
|---|
| 565 | pVar->offset=*(long *)(buffer+i2); | 
|---|
| 566 | i2+=sizeof(long); | 
|---|
| 567 |  | 
|---|
| 568 | //変数を追加 | 
|---|
| 569 | globalVars.push_back( pVar ); | 
|---|
| 570 | } | 
|---|
| 571 |  | 
|---|
| 572 | //グローバル実行領域のサイズ | 
|---|
| 573 | GlobalOpBufferSize=*(long *)(buffer+i2); | 
|---|
| 574 | i2+=sizeof(long); | 
|---|
| 575 |  | 
|---|
| 576 | //プロシージャ情報 | 
|---|
| 577 | GlobalProc *pUserProc; | 
|---|
| 578 | SubNum=*(long *)(buffer+i2); | 
|---|
| 579 | i2+=sizeof(long); | 
|---|
| 580 | ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *)); | 
|---|
| 581 | for(int i6=0;i6<SubNum;i6++){ | 
|---|
| 582 | char szParentClassName[VN_SIZE]; | 
|---|
| 583 | lstrcpy(szParentClassName,buffer+i2); | 
|---|
| 584 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 585 |  | 
|---|
| 586 | CClass *pClass = NULL; | 
|---|
| 587 | if(szParentClassName[0]) | 
|---|
| 588 | pClass=pobj_DBClass->Find(szParentClassName); | 
|---|
| 589 |  | 
|---|
| 590 | //ID | 
|---|
| 591 | int id=*(long *)(buffer+i2); | 
|---|
| 592 | i2+=sizeof(long); | 
|---|
| 593 |  | 
|---|
| 594 | //名前 | 
|---|
| 595 | char *name = buffer+i2; | 
|---|
| 596 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 597 |  | 
|---|
| 598 | // オブジェクトを生成 | 
|---|
| 599 | // TODO: 名前空間が未完成 | 
|---|
| 600 | pUserProc = new GlobalProc( NamespaceScopes(), name, Procedure::Function, false, false, false ); | 
|---|
| 601 | pUserProc->pNextData=0; | 
|---|
| 602 | pUserProc->id=id; | 
|---|
| 603 | pUserProc->SetParentClass( pClass ); | 
|---|
| 604 |  | 
|---|
| 605 | pUserProc->beginOpAddress=*(long *)(buffer+i2); | 
|---|
| 606 | i2+=sizeof(long); | 
|---|
| 607 | pUserProc->endOpAddress=*(long *)(buffer+i2); | 
|---|
| 608 | i2+=sizeof(long); | 
|---|
| 609 |  | 
|---|
| 610 | pUserProc->CompleteCompile(); | 
|---|
| 611 |  | 
|---|
| 612 | //ローカル変数情報 | 
|---|
| 613 | pUserProc->localVars.clear(); | 
|---|
| 614 | int maxLocalVar=*(long *)(buffer+i2); | 
|---|
| 615 | i2+=sizeof(long); | 
|---|
| 616 | for(i3=0;i3<maxLocalVar;i3++){ | 
|---|
| 617 | //変数名 | 
|---|
| 618 | char *name = buffer+i2; | 
|---|
| 619 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 620 |  | 
|---|
| 621 | int basicType = *(long *)(buffer+i2); | 
|---|
| 622 | i2+=sizeof(long); | 
|---|
| 623 |  | 
|---|
| 624 | Type type( basicType ); | 
|---|
| 625 | GetLpIndex_DebugFile(buffer,&i2,type); | 
|---|
| 626 |  | 
|---|
| 627 | bool isRef = (buffer[i2++]) ? true:false; | 
|---|
| 628 |  | 
|---|
| 629 | bool isArray = (buffer[i2++]) ? true:false; | 
|---|
| 630 |  | 
|---|
| 631 | Variable *pVar = new Variable( name, type, false, isRef ); | 
|---|
| 632 |  | 
|---|
| 633 | if(isArray){ | 
|---|
| 634 | int SubScripts[MAX_ARRAYDIM]; | 
|---|
| 635 | for(i4=0;;i4++){ | 
|---|
| 636 | SubScripts[i4]=*(long *)(buffer+i2); | 
|---|
| 637 | i2+=sizeof(long); | 
|---|
| 638 |  | 
|---|
| 639 | if(SubScripts[i4]==-1) break; | 
|---|
| 640 | } | 
|---|
| 641 |  | 
|---|
| 642 | pVar->SetArray( SubScripts ); | 
|---|
| 643 | } | 
|---|
| 644 |  | 
|---|
| 645 | //レキシカルスコープ情報 | 
|---|
| 646 | pVar->ScopeStartAddress=*(long *)(buffer+i2); | 
|---|
| 647 | i2+=sizeof(long); | 
|---|
| 648 | pVar->ScopeEndAddress=*(long *)(buffer+i2); | 
|---|
| 649 | i2+=sizeof(long); | 
|---|
| 650 | pVar->ScopeLevel=*(long *)(buffer+i2); | 
|---|
| 651 | i2+=sizeof(long); | 
|---|
| 652 |  | 
|---|
| 653 | //メモリ位置 | 
|---|
| 654 | pVar->offset=*(long *)(buffer+i2); | 
|---|
| 655 | i2+=sizeof(long); | 
|---|
| 656 |  | 
|---|
| 657 | //変数を追加 | 
|---|
| 658 | pUserProc->localVars.push_back( pVar ); | 
|---|
| 659 | } | 
|---|
| 660 |  | 
|---|
| 661 |  | 
|---|
| 662 | ///////////////////////////////// | 
|---|
| 663 | // 格納位置を計算してpUserProcをセット | 
|---|
| 664 | ///////////////////////////////// | 
|---|
| 665 |  | 
|---|
| 666 | i4=hash_default(pUserProc->GetName().c_str()); | 
|---|
| 667 |  | 
|---|
| 668 | GlobalProc *psi2; | 
|---|
| 669 | if(ppSubHash[i4]){ | 
|---|
| 670 | psi2=ppSubHash[i4]; | 
|---|
| 671 | while(1){ | 
|---|
| 672 | if(psi2->pNextData==0){ | 
|---|
| 673 | psi2->pNextData=pUserProc; | 
|---|
| 674 | break; | 
|---|
| 675 | } | 
|---|
| 676 | psi2=psi2->pNextData; | 
|---|
| 677 | } | 
|---|
| 678 | } | 
|---|
| 679 | else{ | 
|---|
| 680 | ppSubHash[i4]=pUserProc; | 
|---|
| 681 | } | 
|---|
| 682 | } | 
|---|
| 683 |  | 
|---|
| 684 | //クラス情報 | 
|---|
| 685 | CClass *pobj_c; | 
|---|
| 686 | for(i3=0;i3<iMaxClassCount;i3++){ | 
|---|
| 687 | //クラス名 | 
|---|
| 688 | char szClassName[VN_SIZE]; | 
|---|
| 689 | lstrcpy(szClassName,buffer+i2); | 
|---|
| 690 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 691 |  | 
|---|
| 692 | pobj_c=pobj_DBClass->Find(szClassName); | 
|---|
| 693 |  | 
|---|
| 694 | //仮想関数の数 | 
|---|
| 695 | pobj_c->vtbl_num=*(long *)(buffer+i2); | 
|---|
| 696 | i2+=sizeof(long); | 
|---|
| 697 |  | 
|---|
| 698 | //アラインメント | 
|---|
| 699 | pobj_c->iAlign=*(long *)(buffer+i2); | 
|---|
| 700 | i2+=sizeof(long); | 
|---|
| 701 |  | 
|---|
| 702 | //メンバ | 
|---|
| 703 | pobj_c->iMemberNum=*(long *)(buffer+i2); | 
|---|
| 704 | i2+=sizeof(long); | 
|---|
| 705 | pobj_c->ppobj_Member= | 
|---|
| 706 | (CMember **)HeapAlloc(hHeap,0,pobj_c->iMemberNum*sizeof(CMember *)); | 
|---|
| 707 | for(i4=0;i4<pobj_c->iMemberNum;i4++){ | 
|---|
| 708 | pobj_c->ppobj_Member[i4]=new CMember(); | 
|---|
| 709 |  | 
|---|
| 710 | pobj_c->ppobj_Member[i4]->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1); | 
|---|
| 711 | lstrcpy(pobj_c->ppobj_Member[i4]->name,buffer+i2); | 
|---|
| 712 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 713 |  | 
|---|
| 714 | memcpy(pobj_c->ppobj_Member[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM); | 
|---|
| 715 | i2+=sizeof(int)*MAX_ARRAYDIM; | 
|---|
| 716 |  | 
|---|
| 717 | //型 | 
|---|
| 718 | Type type( *(long *)(buffer+i2) ); | 
|---|
| 719 | i2+=sizeof(long); | 
|---|
| 720 |  | 
|---|
| 721 | //型の拡張情報 | 
|---|
| 722 | GetLpIndex_DebugFile(buffer,&i2,type); | 
|---|
| 723 |  | 
|---|
| 724 | pobj_c->ppobj_Member[i4]->SetType( type.GetBasicType(), type.GetIndex() ); | 
|---|
| 725 |  | 
|---|
| 726 | pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2); | 
|---|
| 727 | i2+=sizeof(long); | 
|---|
| 728 | } | 
|---|
| 729 |  | 
|---|
| 730 | //メソッド | 
|---|
| 731 | int nMethod = *(long *)(buffer+i2); | 
|---|
| 732 | i2+=sizeof(long); | 
|---|
| 733 | for( i4=0; i4<nMethod; i4++ ){ | 
|---|
| 734 |  | 
|---|
| 735 | DWORD dwAccess=*(long *)(buffer+i2); | 
|---|
| 736 | i2+=sizeof(long); | 
|---|
| 737 |  | 
|---|
| 738 | char szInherits[VN_SIZE]; | 
|---|
| 739 | lstrcpy(szInherits,buffer+i2); | 
|---|
| 740 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 741 |  | 
|---|
| 742 | CClass *pobj_InheritsClass = NULL; | 
|---|
| 743 | if(szInherits[0]){ | 
|---|
| 744 | pobj_InheritsClass=pobj_DBClass->Find(szInherits); | 
|---|
| 745 | } | 
|---|
| 746 |  | 
|---|
| 747 | lstrcpy(temp2,buffer+i2); | 
|---|
| 748 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 749 |  | 
|---|
| 750 | CClass *pobj_temp_c; | 
|---|
| 751 | pobj_temp_c=pobj_InheritsClass; | 
|---|
| 752 | if(pobj_temp_c==0) pobj_temp_c=pobj_c; | 
|---|
| 753 | i5=hash_default(temp2); | 
|---|
| 754 | pUserProc=ppSubHash[i5]; | 
|---|
| 755 | while(1){ | 
|---|
| 756 | if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break; | 
|---|
| 757 | pUserProc=pUserProc->pNextData; | 
|---|
| 758 | } | 
|---|
| 759 |  | 
|---|
| 760 | CMethod *method = new CMethod( pUserProc, dwAccess, 0,0,false, false); | 
|---|
| 761 | method->pobj_InheritsClass = pobj_InheritsClass; | 
|---|
| 762 |  | 
|---|
| 763 | pobj_c->methods.push_back( method ); | 
|---|
| 764 | } | 
|---|
| 765 |  | 
|---|
| 766 | //静的メンバ | 
|---|
| 767 | int nStaticMember = *(long *)(buffer+i2); | 
|---|
| 768 | i2+=sizeof(long); | 
|---|
| 769 | for( i4=0; i4<nStaticMember; i4++ ){ | 
|---|
| 770 | CMember *member=new CMember(); | 
|---|
| 771 |  | 
|---|
| 772 | member->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1); | 
|---|
| 773 | lstrcpy(member->name,buffer+i2); | 
|---|
| 774 | i2+=lstrlen(buffer+i2)+1; | 
|---|
| 775 |  | 
|---|
| 776 | memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM); | 
|---|
| 777 | i2+=sizeof(int)*MAX_ARRAYDIM; | 
|---|
| 778 |  | 
|---|
| 779 | //型 | 
|---|
| 780 | Type type( *(long *)(buffer+i2) ); | 
|---|
| 781 | i2+=sizeof(long); | 
|---|
| 782 |  | 
|---|
| 783 | //型の拡張情報 | 
|---|
| 784 | GetLpIndex_DebugFile(buffer,&i2,type); | 
|---|
| 785 |  | 
|---|
| 786 | member->SetType( type.GetBasicType(), type.GetIndex() ); | 
|---|
| 787 |  | 
|---|
| 788 | member->dwAccess=*(long *)(buffer+i2); | 
|---|
| 789 | i2+=sizeof(long); | 
|---|
| 790 |  | 
|---|
| 791 | pobj_c->staticMembers.push_back( member ); | 
|---|
| 792 | } | 
|---|
| 793 | } | 
|---|
| 794 |  | 
|---|
| 795 | HeapDefaultFree(buffer); | 
|---|
| 796 | buffer=0; | 
|---|
| 797 |  | 
|---|
| 798 |  | 
|---|
| 799 |  | 
|---|
| 800 |  | 
|---|
| 801 | extern GlobalProc **ppSubHash; | 
|---|
| 802 | ppSubHash=this->ppSubHash; | 
|---|
| 803 | pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc"); | 
|---|
| 804 |  | 
|---|
| 805 |  | 
|---|
| 806 | SingleStepCodeBuffer=MakeSingleStepCode(); | 
|---|
| 807 |  | 
|---|
| 808 |  | 
|---|
| 809 | ///////////////////////////// | 
|---|
| 810 | // ブレークポイントを適用 | 
|---|
| 811 | ///////////////////////////// | 
|---|
| 812 |  | 
|---|
| 813 | //インクルード情報 | 
|---|
| 814 | extern INCLUDEFILEINFO IncludeFileInfo; | 
|---|
| 815 | IncludeFileInfo=this->IncludeFileInfo; | 
|---|
| 816 |  | 
|---|
| 817 | //コードと行番号の関係 | 
|---|
| 818 | extern int MaxLineInfoNum; | 
|---|
| 819 | extern LINEINFO *pLineInfo; | 
|---|
| 820 | MaxLineInfoNum=this->MaxLineInfoNum; | 
|---|
| 821 | pLineInfo=this->pLineInfo; | 
|---|
| 822 |  | 
|---|
| 823 | BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection); | 
|---|
| 824 |  | 
|---|
| 825 | //プロセスメモリにコピー | 
|---|
| 826 | extern HANDLE hDebugProcess; | 
|---|
| 827 | SIZE_T accessBytes; | 
|---|
| 828 | WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection), | 
|---|
| 829 | BreakStepCodeBuffer, | 
|---|
| 830 | SizeOf_CodeSection,&accessBytes); | 
|---|
| 831 |  | 
|---|
| 832 |  | 
|---|
| 833 | return 1; | 
|---|
| 834 | } | 
|---|
| 835 |  | 
|---|
| 836 | BOOL CDebugSection::load(HMODULE hModule){ | 
|---|
| 837 | if(buffer){ | 
|---|
| 838 | HeapDefaultFree(buffer); | 
|---|
| 839 | buffer=0; | 
|---|
| 840 | } | 
|---|
| 841 |  | 
|---|
| 842 |  | 
|---|
| 843 | extern HANDLE hDebugProcess; | 
|---|
| 844 | SIZE_T accessBytes; | 
|---|
| 845 | IMAGE_DOS_HEADER ImageDosHeader; | 
|---|
| 846 | ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&accessBytes); | 
|---|
| 847 |  | 
|---|
| 848 | int pe_size; | 
|---|
| 849 | #ifdef _AMD64_ | 
|---|
| 850 | IMAGE_NT_HEADERS64 pe_hdr; | 
|---|
| 851 | pe_size=sizeof(IMAGE_NT_HEADERS64); | 
|---|
| 852 | #else | 
|---|
| 853 | IMAGE_NT_HEADERS pe_hdr; | 
|---|
| 854 | pe_size=sizeof(IMAGE_NT_HEADERS); | 
|---|
| 855 | #endif | 
|---|
| 856 | ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&accessBytes); | 
|---|
| 857 |  | 
|---|
| 858 | IMAGE_SECTION_HEADER *pSectionHdr; | 
|---|
| 859 | pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER)); | 
|---|
| 860 | ReadProcessMemory(hDebugProcess, | 
|---|
| 861 | (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size), | 
|---|
| 862 | pSectionHdr, | 
|---|
| 863 | pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER), | 
|---|
| 864 | &accessBytes); | 
|---|
| 865 |  | 
|---|
| 866 | int i; | 
|---|
| 867 | for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){ | 
|---|
| 868 |  | 
|---|
| 869 | //リライタブルセクション内の情報 | 
|---|
| 870 | if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){ | 
|---|
| 871 | dwRVA_RWSection=pSectionHdr[i].VirtualAddress; | 
|---|
| 872 | } | 
|---|
| 873 |  | 
|---|
| 874 | //コードセクション内の情報 | 
|---|
| 875 | if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){ | 
|---|
| 876 | dwRVA_CodeSection=pSectionHdr[i].VirtualAddress; | 
|---|
| 877 | SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData; | 
|---|
| 878 | } | 
|---|
| 879 |  | 
|---|
| 880 | //デバッグセクション内の情報 | 
|---|
| 881 | if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){ | 
|---|
| 882 | length=pSectionHdr[i].Misc.VirtualSize; | 
|---|
| 883 | buffer=(char *)HeapAlloc(hHeap,0,length+1); | 
|---|
| 884 |  | 
|---|
| 885 | ReadProcessMemory(hDebugProcess, | 
|---|
| 886 | (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress), | 
|---|
| 887 | buffer, | 
|---|
| 888 | length, | 
|---|
| 889 | &accessBytes); | 
|---|
| 890 | buffer[length]=0; | 
|---|
| 891 | } | 
|---|
| 892 |  | 
|---|
| 893 | } | 
|---|
| 894 | HeapDefaultFree(pSectionHdr); | 
|---|
| 895 |  | 
|---|
| 896 | if(!buffer) return 0; | 
|---|
| 897 |  | 
|---|
| 898 |  | 
|---|
| 899 | dwImageBase=(DWORD)(ULONG_PTR)hModule; | 
|---|
| 900 |  | 
|---|
| 901 |  | 
|---|
| 902 |  | 
|---|
| 903 | if(OpBuffer) HeapDefaultFree(OpBuffer); | 
|---|
| 904 | OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection); | 
|---|
| 905 |  | 
|---|
| 906 | ReadProcessMemory(hDebugProcess, | 
|---|
| 907 | (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer, | 
|---|
| 908 | SizeOf_CodeSection,&accessBytes); | 
|---|
| 909 |  | 
|---|
| 910 |  | 
|---|
| 911 | return __load(); | 
|---|
| 912 | } | 
|---|
| 913 |  | 
|---|
| 914 | void CDebugSection::choice(void){ | 
|---|
| 915 | //イメージベース | 
|---|
| 916 | extern DWORD ImageBase; | 
|---|
| 917 | ImageBase=this->dwImageBase; | 
|---|
| 918 |  | 
|---|
| 919 | //リライタブルセクションのRVA | 
|---|
| 920 | extern int MemPos_RWSection; | 
|---|
| 921 | MemPos_RWSection=this->dwRVA_RWSection; | 
|---|
| 922 |  | 
|---|
| 923 | //コードセクションのRVAとサイズ | 
|---|
| 924 | extern int MemPos_CodeSection; | 
|---|
| 925 | extern int FileSize_CodeSection; | 
|---|
| 926 | MemPos_CodeSection=this->dwRVA_CodeSection; | 
|---|
| 927 | FileSize_CodeSection=this->SizeOf_CodeSection; | 
|---|
| 928 |  | 
|---|
| 929 | //インクルード情報 | 
|---|
| 930 | extern INCLUDEFILEINFO IncludeFileInfo; | 
|---|
| 931 | IncludeFileInfo=this->IncludeFileInfo; | 
|---|
| 932 |  | 
|---|
| 933 | //ソースコード | 
|---|
| 934 | Smoothie::Lexical::source = source; | 
|---|
| 935 |  | 
|---|
| 936 | //コードと行番号の関係 | 
|---|
| 937 | extern int MaxLineInfoNum; | 
|---|
| 938 | extern LINEINFO *pLineInfo; | 
|---|
| 939 | MaxLineInfoNum=this->MaxLineInfoNum; | 
|---|
| 940 | pLineInfo=this->pLineInfo; | 
|---|
| 941 |  | 
|---|
| 942 | // クラス情報 | 
|---|
| 943 | extern CDBClass *pobj_DBClass; | 
|---|
| 944 | pobj_DBClass=this->pobj_DBClass; | 
|---|
| 945 |  | 
|---|
| 946 | //定数を取得 | 
|---|
| 947 | extern CONSTINFO **ppConstHash; | 
|---|
| 948 | ppConstHash=this->ppConstHash; | 
|---|
| 949 |  | 
|---|
| 950 | //グローバル実行領域のサイズ | 
|---|
| 951 | extern int GlobalOpBufferSize; | 
|---|
| 952 | GlobalOpBufferSize=this->GlobalOpBufferSize; | 
|---|
| 953 |  | 
|---|
| 954 | //プロシージャ | 
|---|
| 955 | extern char **ppMacroNames; | 
|---|
| 956 | ppMacroNames=0; | 
|---|
| 957 | extern GlobalProc **ppSubHash; | 
|---|
| 958 | extern int SubNum; | 
|---|
| 959 | ppSubHash=this->ppSubHash; | 
|---|
| 960 | SubNum=this->SubNum; | 
|---|
| 961 |  | 
|---|
| 962 | extern UserProc *pSub_DebugSys_EndProc; | 
|---|
| 963 | pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc; | 
|---|
| 964 |  | 
|---|
| 965 | //ネイティブコードバッファ | 
|---|
| 966 | extern char *OpBuffer; | 
|---|
| 967 | OpBuffer=this->OpBuffer; | 
|---|
| 968 | } | 
|---|
| 969 |  | 
|---|
| 970 | void CDebugSection::DeleteDebugInfo(void){ | 
|---|
| 971 | int i2; | 
|---|
| 972 |  | 
|---|
| 973 | //インクルード情報を解放 | 
|---|
| 974 | for(i2=0;i2<IncludeFileInfo.FilesNum;i2++) | 
|---|
| 975 | HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]); | 
|---|
| 976 | HeapDefaultFree(IncludeFileInfo.ppFileNames); | 
|---|
| 977 |  | 
|---|
| 978 | //クラスに関するメモリを解放 | 
|---|
| 979 | delete pobj_DBClass; | 
|---|
| 980 | pobj_DBClass=0; | 
|---|
| 981 |  | 
|---|
| 982 | //サブルーチン情報のメモリ解放 | 
|---|
| 983 | DeleteSubInfo(ppSubHash,0,0); | 
|---|
| 984 |  | 
|---|
| 985 | //定数に関する情報を解放 | 
|---|
| 986 | DeleteConstInfo(ppConstHash); | 
|---|
| 987 |  | 
|---|
| 988 | //コードと行番号の関係を解放 | 
|---|
| 989 | HeapDefaultFree(pLineInfo); | 
|---|
| 990 |  | 
|---|
| 991 | //コードバッファを解放 | 
|---|
| 992 | HeapDefaultFree(OpBuffer); | 
|---|
| 993 | OpBuffer=0; | 
|---|
| 994 |  | 
|---|
| 995 | HeapDefaultFree(SingleStepCodeBuffer); | 
|---|
| 996 | SingleStepCodeBuffer=0; | 
|---|
| 997 |  | 
|---|
| 998 | HeapDefaultFree(BreakStepCodeBuffer); | 
|---|
| 999 | BreakStepCodeBuffer=0; | 
|---|
| 1000 | } | 
|---|
| 1001 |  | 
|---|
| 1002 |  | 
|---|
| 1003 |  | 
|---|
| 1004 | CDBDebugSection::CDBDebugSection(){ | 
|---|
| 1005 | ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1); | 
|---|
| 1006 | num=0; | 
|---|
| 1007 | } | 
|---|
| 1008 | CDBDebugSection::~CDBDebugSection(){ | 
|---|
| 1009 | int i; | 
|---|
| 1010 | for(i=0;i<num;i++){ | 
|---|
| 1011 | delete ppobj_ds[i]; | 
|---|
| 1012 | } | 
|---|
| 1013 | HeapDefaultFree(ppobj_ds); | 
|---|
| 1014 | } | 
|---|
| 1015 |  | 
|---|
| 1016 | BOOL CDBDebugSection::add(HMODULE hModule){ | 
|---|
| 1017 | CDebugSection *pobj_d; | 
|---|
| 1018 | pobj_d=new CDebugSection(); | 
|---|
| 1019 | if(!pobj_d->load(hModule)){ | 
|---|
| 1020 | //デバッグ情報が存在しないとき | 
|---|
| 1021 | delete pobj_d; | 
|---|
| 1022 | return 0; | 
|---|
| 1023 | } | 
|---|
| 1024 |  | 
|---|
| 1025 | ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *)); | 
|---|
| 1026 | ppobj_ds[num]=pobj_d; | 
|---|
| 1027 | num++; | 
|---|
| 1028 |  | 
|---|
| 1029 | return 1; | 
|---|
| 1030 | } | 
|---|
| 1031 |  | 
|---|
| 1032 | void CDBDebugSection::del(HMODULE hModule){ | 
|---|
| 1033 | int i; | 
|---|
| 1034 | for(i=0;i<num;i++){ | 
|---|
| 1035 | if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){ | 
|---|
| 1036 | delete ppobj_ds[i]; | 
|---|
| 1037 |  | 
|---|
| 1038 | num--; | 
|---|
| 1039 | for(;i<num;i++){ | 
|---|
| 1040 | ppobj_ds[i]=ppobj_ds[i+1]; | 
|---|
| 1041 | } | 
|---|
| 1042 | break; | 
|---|
| 1043 | } | 
|---|
| 1044 | } | 
|---|
| 1045 | } | 
|---|
| 1046 |  | 
|---|
| 1047 | void CDBDebugSection::choice(int index){ | 
|---|
| 1048 | pobj_now=ppobj_ds[index]; | 
|---|
| 1049 | pobj_now->choice(); | 
|---|
| 1050 | } | 
|---|
| 1051 |  | 
|---|
| 1052 |  | 
|---|
| 1053 |  | 
|---|
| 1054 | CDBDebugSection *pobj_DBDebugSection; | 
|---|