[4] | 1 | #include "../BasicCompiler_Common/common.h"
|
---|
| 2 |
|
---|
| 3 | #ifdef _AMD64_
|
---|
| 4 | #include "../BasicCompiler64/opcode.h"
|
---|
| 5 | #else
|
---|
[5] | 6 | #include "../BasicCompiler32/opcode.h"
|
---|
[4] | 7 | #endif
|
---|
| 8 |
|
---|
| 9 | #define MDLFILE_VER 0x70000003
|
---|
| 10 |
|
---|
| 11 |
|
---|
[75] | 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);
|
---|
[4] | 15 | (*p)+=lstrlen(buffer+(*p))+1;
|
---|
| 16 | }
|
---|
| 17 | else{
|
---|
[75] | 18 | *(LONG_PTR *)(buffer+(*p))=type.GetIndex();
|
---|
[4] | 19 | (*p)+=sizeof(LONG_PTR);
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 |
|
---|
[75] | 24 | void GetLpIndex_DebugFile(char *buffer,int *p,Type &type){
|
---|
| 25 | if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){
|
---|
[4] | 26 | char szClassName[VN_SIZE];
|
---|
| 27 | lstrcpy(szClassName,buffer+(*p));
|
---|
| 28 | (*p)+=lstrlen(buffer+(*p))+1;
|
---|
| 29 |
|
---|
[102] | 30 | type.SetIndex( (LONG_PTR)pobj_DBClass->Find(szClassName) );
|
---|
[4] | 31 | }
|
---|
| 32 | else{
|
---|
[75] | 33 | type.SetIndex( *(LONG_PTR *)(buffer+(*p)) );
|
---|
[4] | 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 | //////////////////
|
---|
[88] | 138 | *(long *)(buffer+i2)=(int)Smoothie::Meta::typeDefs.size();
|
---|
[4] | 139 | i2+=sizeof(long);
|
---|
[88] | 140 | for(i3=0;i3<(int)Smoothie::Meta::typeDefs.size();i3++){
|
---|
[113] | 141 | lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetName().c_str() );
|
---|
[4] | 142 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 143 |
|
---|
[88] | 144 | lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetBaseName().c_str() );
|
---|
[4] | 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 | //グローバル変数情報
|
---|
[75] | 156 | *(long *)(buffer+i2)=(int)::globalVars.size();
|
---|
[4] | 157 | i2+=sizeof(long);
|
---|
[75] | 158 | foreach( Variable *pVar, ::globalVars ){
|
---|
[4] | 159 | //変数名
|
---|
[75] | 160 | lstrcpy(buffer+i2,pVar->GetName().c_str());
|
---|
[4] | 161 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 162 |
|
---|
| 163 | //型
|
---|
[75] | 164 | *(long *)(buffer+i2)=pVar->GetBasicType();
|
---|
[4] | 165 | i2+=sizeof(long);
|
---|
| 166 |
|
---|
| 167 | //型の拡張情報
|
---|
[75] | 168 | SetLpIndex_DebugFile(buffer,&i2,*pVar);
|
---|
[4] | 169 |
|
---|
[75] | 170 | buffer[i2++] = pVar->IsRef() ? 1 : 0;
|
---|
[4] | 171 |
|
---|
[75] | 172 | buffer[i2++] = pVar->IsArray() ? 1 : 0;
|
---|
[4] | 173 |
|
---|
[75] | 174 | if(pVar->IsArray()){
|
---|
| 175 | for(i5=0;;i5++){
|
---|
| 176 | *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
|
---|
[4] | 177 | i2+=sizeof(long);
|
---|
[75] | 178 | if(pVar->GetSubScriptsPtr()[i5]==-1) break;
|
---|
[4] | 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 | //プロシージャ情報
|
---|
[100] | 207 | extern GlobalProc **ppSubHash;
|
---|
[4] | 208 | extern int SubNum;
|
---|
[100] | 209 | GlobalProc *pUserProc;
|
---|
[4] | 210 | *(long *)(buffer+i2)=SubNum;
|
---|
| 211 | i2+=sizeof(long);
|
---|
| 212 | for(i3=0;i3<MAX_HASH;i3++){
|
---|
[75] | 213 | pUserProc=ppSubHash[i3];
|
---|
| 214 | while(pUserProc){
|
---|
| 215 | if(pUserProc->GetParentClassPtr()){
|
---|
| 216 | lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->name);
|
---|
[4] | 217 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 218 | }
|
---|
| 219 | else{
|
---|
| 220 | lstrcpy(buffer+i2,"");
|
---|
| 221 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | //ID
|
---|
[75] | 225 | *(long *)(buffer+i2)=pUserProc->id;
|
---|
[4] | 226 | i2+=sizeof(long);
|
---|
| 227 |
|
---|
| 228 | //関数名
|
---|
[75] | 229 | lstrcpy(buffer+i2,pUserProc->GetName().c_str());
|
---|
[4] | 230 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 231 |
|
---|
[75] | 232 | *(long *)(buffer+i2)=pUserProc->beginOpAddress;
|
---|
[4] | 233 | i2+=sizeof(long);
|
---|
[75] | 234 | *(long *)(buffer+i2)=pUserProc->endOpAddress;
|
---|
[4] | 235 | i2+=sizeof(long);
|
---|
| 236 |
|
---|
| 237 | //ローカル変数情報
|
---|
[75] | 238 | *(long *)(buffer+i2)=(int)pUserProc->localVars.size();
|
---|
[4] | 239 | i2+=sizeof(long);
|
---|
| 240 |
|
---|
| 241 | //バッファが足りない場合は再確保
|
---|
| 242 | if(BufferSize<i2+32768){
|
---|
| 243 | BufferSize+=32768;
|
---|
| 244 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[75] | 247 | foreach( Variable *pVar, pUserProc->localVars ){
|
---|
| 248 | lstrcpy(buffer+i2,pVar->GetName().c_str());
|
---|
[4] | 249 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 250 |
|
---|
| 251 | //型
|
---|
[75] | 252 | *(long *)(buffer+i2)=pVar->GetBasicType();
|
---|
[4] | 253 | i2+=sizeof(long);
|
---|
| 254 |
|
---|
| 255 | //型の拡張情報
|
---|
[75] | 256 | SetLpIndex_DebugFile(buffer,&i2,*pVar);
|
---|
[4] | 257 |
|
---|
| 258 | //参照型パラメータかどうか
|
---|
[75] | 259 | buffer[i2++] = pVar->IsRef() ? 1 : 0;
|
---|
[4] | 260 |
|
---|
| 261 | //配列かどうか
|
---|
[75] | 262 | buffer[i2++] = pVar->IsArray() ? 1 : 0;
|
---|
[4] | 263 |
|
---|
| 264 | //配列要素
|
---|
[75] | 265 | if(pVar->IsArray()){
|
---|
[4] | 266 | for(i5=0;;i5++){
|
---|
[75] | 267 | *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
|
---|
[4] | 268 | i2+=sizeof(long);
|
---|
[75] | 269 | if(pVar->GetSubScriptsPtr()[i5]==-1) break;
|
---|
[4] | 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 |
|
---|
[75] | 295 | pUserProc=pUserProc->pNextData;
|
---|
[4] | 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 | //型
|
---|
[75] | 336 | *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetBasicType();
|
---|
[4] | 337 | i2+=sizeof(long);
|
---|
| 338 |
|
---|
| 339 | //型の拡張情報
|
---|
[75] | 340 | SetLpIndex_DebugFile(buffer,&i2,*pobj_c->ppobj_Member[i4]);
|
---|
[4] | 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 | //メソッド
|
---|
[51] | 353 | *(long *)(buffer+i2)=(long)pobj_c->methods.size();
|
---|
[4] | 354 | i2+=sizeof(long);
|
---|
[51] | 355 | foreach( CMethod *method, pobj_c->methods ){
|
---|
| 356 | *(long *)(buffer+i2)=method->dwAccess;
|
---|
[4] | 357 | i2+=sizeof(long);
|
---|
[51] | 358 | if(method->pobj_InheritsClass){
|
---|
| 359 | lstrcpy(buffer+i2,method->pobj_InheritsClass->name);
|
---|
[4] | 360 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 361 | }
|
---|
| 362 | else{
|
---|
| 363 | lstrcpy(buffer+i2,"");
|
---|
| 364 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 365 | }
|
---|
[75] | 366 | lstrcpy(buffer+i2,method->pUserProc->GetName().c_str());
|
---|
[4] | 367 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | //静的メンバ
|
---|
[53] | 371 | *(long *)(buffer+i2)=(long)pobj_c->staticMembers.size();
|
---|
[4] | 372 | i2+=sizeof(long);
|
---|
[53] | 373 | foreach( CMember *member, pobj_c->staticMembers ){
|
---|
| 374 | lstrcpy(buffer+i2,member->name);
|
---|
[4] | 375 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 376 |
|
---|
[53] | 377 | memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
|
---|
[4] | 378 | i2+=sizeof(int)*MAX_ARRAYDIM;
|
---|
| 379 |
|
---|
| 380 | //型
|
---|
[75] | 381 | *(long *)(buffer+i2)=member->GetBasicType();
|
---|
[4] | 382 | i2+=sizeof(long);
|
---|
| 383 |
|
---|
| 384 | //型の拡張情報
|
---|
[75] | 385 | SetLpIndex_DebugFile(buffer,&i2,*member);
|
---|
[4] | 386 |
|
---|
[53] | 387 | *(long *)(buffer+i2)=member->dwAccess;
|
---|
[4] | 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 |
|
---|
[114] | 430 | pobj_CompilingClass = NULL;
|
---|
[16] | 431 |
|
---|
[4] | 432 | i2=0;
|
---|
| 433 |
|
---|
| 434 | //デバッグ用ファイルのバージョンをチェック
|
---|
| 435 | if(*(long *)(buffer+i2)<MDLFILE_VER){
|
---|
| 436 | HeapDefaultFree(buffer);
|
---|
| 437 | return 0;
|
---|
| 438 | }
|
---|
| 439 | i2+=sizeof(long);
|
---|
| 440 |
|
---|
| 441 | //プラットフォームのビット数をチェック
|
---|
| 442 | if(*(long *)(buffer+i2)!=PLATFORM){
|
---|
| 443 | HeapDefaultFree(buffer);
|
---|
| 444 | return 0;
|
---|
| 445 | }
|
---|
| 446 | i2+=sizeof(long);
|
---|
| 447 |
|
---|
| 448 | //インクルード情報
|
---|
| 449 | IncludeFileInfo.FilesNum=*(long *)(buffer+i2);
|
---|
| 450 | i2+=sizeof(long);
|
---|
| 451 | IncludeFileInfo.ppFileNames=(char **)HeapAlloc(hHeap,0,IncludeFileInfo.FilesNum*sizeof(char *));
|
---|
| 452 | for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
|
---|
| 453 | if(buffer[i2]=='\0') break;
|
---|
| 454 | IncludeFileInfo.ppFileNames[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
|
---|
| 455 | lstrcpy(IncludeFileInfo.ppFileNames[i3],buffer+i2);
|
---|
| 456 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 457 | }
|
---|
| 458 | for(i2++,i3=0;;i2++,i3++){
|
---|
| 459 | IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2];
|
---|
| 460 | if(IncludeFileInfo.LineOfFile[i3]==-1) break;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | //ソースコード
|
---|
| 464 | i2++;
|
---|
[88] | 465 | source.SetBuffer( buffer + i2 );
|
---|
[15] | 466 | i2+=lstrlen(buffer+i2)+1;
|
---|
[4] | 467 |
|
---|
| 468 | //コードと行番号の関係
|
---|
| 469 | MaxLineInfoNum=*(long *)(buffer+i2);
|
---|
| 470 | i2+=sizeof(long);
|
---|
| 471 | pLineInfo=(LINEINFO *)HeapAlloc(hHeap,0,MaxLineInfoNum*sizeof(LINEINFO)+1);
|
---|
| 472 | memcpy(pLineInfo,buffer+i2,MaxLineInfoNum*sizeof(LINEINFO));
|
---|
| 473 | i2+=MaxLineInfoNum*sizeof(LINEINFO);
|
---|
| 474 |
|
---|
| 475 |
|
---|
| 476 | ///////////////////////////////////////////
|
---|
| 477 | // クラス情報(名前のみ。詳細は後で取得)
|
---|
| 478 | ///////////////////////////////////////////
|
---|
| 479 |
|
---|
| 480 | this->pobj_DBClass=new CDBClass();
|
---|
| 481 |
|
---|
| 482 | int iMaxClassCount;
|
---|
| 483 | iMaxClassCount=*(long *)(buffer+i2);
|
---|
| 484 | i2+=sizeof(long);
|
---|
| 485 | for(i3=0;i3<iMaxClassCount;i3++){
|
---|
| 486 | //クラス名
|
---|
[101] | 487 | // TODO: 名前空間が未完成
|
---|
[108] | 488 | pobj_DBClass->AddClass(NamespaceScopes(),NamespaceScopesCollection(),buffer+i2,0);
|
---|
[4] | 489 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | extern CDBClass *pobj_DBClass;
|
---|
| 493 | pobj_DBClass=this->pobj_DBClass;
|
---|
| 494 |
|
---|
| 495 |
|
---|
| 496 | //////////////////
|
---|
| 497 | // TypeDef情報
|
---|
| 498 | //////////////////
|
---|
| 499 |
|
---|
| 500 | //初期化
|
---|
[88] | 501 | Smoothie::Meta::typeDefs.clear();
|
---|
[4] | 502 |
|
---|
| 503 | //個数を取得
|
---|
| 504 | num=*(long *)(buffer+i2);
|
---|
| 505 | i2+=sizeof(long);
|
---|
| 506 | for(i3=0;i3<num;i3++){
|
---|
| 507 | temp5=buffer+i2;
|
---|
| 508 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 509 |
|
---|
[113] | 510 | // 名前空間に未対応
|
---|
| 511 | Smoothie::Meta::typeDefs.push_back( TypeDef( NamespaceScopes(), temp5, buffer+i2 ) );
|
---|
[4] | 512 |
|
---|
| 513 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | //定数を取得
|
---|
| 517 | GetConstInfo();
|
---|
| 518 | extern CONSTINFO **ppConstHash;
|
---|
| 519 | this->ppConstHash=ppConstHash;
|
---|
| 520 |
|
---|
| 521 |
|
---|
| 522 | //グローバル変数情報
|
---|
[75] | 523 | globalVars.clear();
|
---|
| 524 | int maxGlobalVars=*(long *)(buffer+i2);
|
---|
[4] | 525 | i2+=sizeof(long);
|
---|
[75] | 526 | for(i3=0;i3<maxGlobalVars;i3++){
|
---|
[4] | 527 |
|
---|
| 528 | //変数名
|
---|
[75] | 529 | char *name = buffer+i2;
|
---|
[4] | 530 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 531 |
|
---|
[75] | 532 | int basicType = *(long *)(buffer+i2);
|
---|
[4] | 533 | i2+=sizeof(long);
|
---|
| 534 |
|
---|
[75] | 535 | Type type( basicType );
|
---|
| 536 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 537 |
|
---|
[75] | 538 | bool isRef = (buffer[i2++]) ? true:false;
|
---|
[4] | 539 |
|
---|
[75] | 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];
|
---|
[4] | 546 | for(i4=0;;i4++){
|
---|
[75] | 547 | SubScripts[i4]=*(long *)(buffer+i2);
|
---|
[4] | 548 | i2+=sizeof(long);
|
---|
| 549 |
|
---|
[75] | 550 | if(SubScripts[i4]==-1) break;
|
---|
[4] | 551 | }
|
---|
[75] | 552 |
|
---|
| 553 | pVar->SetArray( SubScripts );
|
---|
[4] | 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);
|
---|
[75] | 567 |
|
---|
| 568 | //変数を追加
|
---|
| 569 | globalVars.push_back( pVar );
|
---|
[4] | 570 | }
|
---|
| 571 |
|
---|
| 572 | //グローバル実行領域のサイズ
|
---|
| 573 | GlobalOpBufferSize=*(long *)(buffer+i2);
|
---|
| 574 | i2+=sizeof(long);
|
---|
| 575 |
|
---|
| 576 | //プロシージャ情報
|
---|
[100] | 577 | GlobalProc *pUserProc;
|
---|
[4] | 578 | SubNum=*(long *)(buffer+i2);
|
---|
| 579 | i2+=sizeof(long);
|
---|
[100] | 580 | ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *));
|
---|
[75] | 581 | for(int i6=0;i6<SubNum;i6++){
|
---|
[4] | 582 | char szParentClassName[VN_SIZE];
|
---|
| 583 | lstrcpy(szParentClassName,buffer+i2);
|
---|
| 584 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 585 |
|
---|
[114] | 586 | const CClass *pClass = NULL;
|
---|
| 587 | if(szParentClassName[0]){
|
---|
[102] | 588 | pClass=pobj_DBClass->Find(szParentClassName);
|
---|
[114] | 589 | }
|
---|
[4] | 590 |
|
---|
| 591 | //ID
|
---|
[75] | 592 | int id=*(long *)(buffer+i2);
|
---|
[4] | 593 | i2+=sizeof(long);
|
---|
| 594 |
|
---|
| 595 | //名前
|
---|
[75] | 596 | char *name = buffer+i2;
|
---|
[4] | 597 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 598 |
|
---|
[75] | 599 | // オブジェクトを生成
|
---|
[100] | 600 | // TODO: 名前空間が未完成
|
---|
[108] | 601 | pUserProc = new GlobalProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false );
|
---|
[75] | 602 | pUserProc->pNextData=0;
|
---|
| 603 | pUserProc->id=id;
|
---|
| 604 | pUserProc->SetParentClass( pClass );
|
---|
| 605 |
|
---|
| 606 | pUserProc->beginOpAddress=*(long *)(buffer+i2);
|
---|
[4] | 607 | i2+=sizeof(long);
|
---|
[75] | 608 | pUserProc->endOpAddress=*(long *)(buffer+i2);
|
---|
[4] | 609 | i2+=sizeof(long);
|
---|
| 610 |
|
---|
[75] | 611 | pUserProc->CompleteCompile();
|
---|
[4] | 612 |
|
---|
| 613 | //ローカル変数情報
|
---|
[75] | 614 | pUserProc->localVars.clear();
|
---|
| 615 | int maxLocalVar=*(long *)(buffer+i2);
|
---|
[4] | 616 | i2+=sizeof(long);
|
---|
[75] | 617 | for(i3=0;i3<maxLocalVar;i3++){
|
---|
| 618 | //変数名
|
---|
| 619 | char *name = buffer+i2;
|
---|
[4] | 620 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 621 |
|
---|
[75] | 622 | int basicType = *(long *)(buffer+i2);
|
---|
[4] | 623 | i2+=sizeof(long);
|
---|
| 624 |
|
---|
[75] | 625 | Type type( basicType );
|
---|
| 626 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 627 |
|
---|
[75] | 628 | bool isRef = (buffer[i2++]) ? true:false;
|
---|
[4] | 629 |
|
---|
[75] | 630 | bool isArray = (buffer[i2++]) ? true:false;
|
---|
| 631 |
|
---|
| 632 | Variable *pVar = new Variable( name, type, false, isRef );
|
---|
| 633 |
|
---|
| 634 | if(isArray){
|
---|
| 635 | int SubScripts[MAX_ARRAYDIM];
|
---|
| 636 | for(i4=0;;i4++){
|
---|
| 637 | SubScripts[i4]=*(long *)(buffer+i2);
|
---|
[4] | 638 | i2+=sizeof(long);
|
---|
| 639 |
|
---|
[75] | 640 | if(SubScripts[i4]==-1) break;
|
---|
[4] | 641 | }
|
---|
[75] | 642 |
|
---|
| 643 | pVar->SetArray( SubScripts );
|
---|
[4] | 644 | }
|
---|
| 645 |
|
---|
| 646 | //レキシカルスコープ情報
|
---|
| 647 | pVar->ScopeStartAddress=*(long *)(buffer+i2);
|
---|
| 648 | i2+=sizeof(long);
|
---|
| 649 | pVar->ScopeEndAddress=*(long *)(buffer+i2);
|
---|
| 650 | i2+=sizeof(long);
|
---|
| 651 | pVar->ScopeLevel=*(long *)(buffer+i2);
|
---|
| 652 | i2+=sizeof(long);
|
---|
| 653 |
|
---|
[75] | 654 | //メモリ位置
|
---|
[4] | 655 | pVar->offset=*(long *)(buffer+i2);
|
---|
| 656 | i2+=sizeof(long);
|
---|
[75] | 657 |
|
---|
| 658 | //変数を追加
|
---|
| 659 | pUserProc->localVars.push_back( pVar );
|
---|
[4] | 660 | }
|
---|
| 661 |
|
---|
| 662 |
|
---|
| 663 | /////////////////////////////////
|
---|
[75] | 664 | // 格納位置を計算してpUserProcをセット
|
---|
[4] | 665 | /////////////////////////////////
|
---|
| 666 |
|
---|
[75] | 667 | i4=hash_default(pUserProc->GetName().c_str());
|
---|
[4] | 668 |
|
---|
[100] | 669 | GlobalProc *psi2;
|
---|
[4] | 670 | if(ppSubHash[i4]){
|
---|
| 671 | psi2=ppSubHash[i4];
|
---|
| 672 | while(1){
|
---|
| 673 | if(psi2->pNextData==0){
|
---|
[75] | 674 | psi2->pNextData=pUserProc;
|
---|
[4] | 675 | break;
|
---|
| 676 | }
|
---|
| 677 | psi2=psi2->pNextData;
|
---|
| 678 | }
|
---|
| 679 | }
|
---|
| 680 | else{
|
---|
[75] | 681 | ppSubHash[i4]=pUserProc;
|
---|
[4] | 682 | }
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | //クラス情報
|
---|
| 686 | CClass *pobj_c;
|
---|
| 687 | for(i3=0;i3<iMaxClassCount;i3++){
|
---|
| 688 | //クラス名
|
---|
| 689 | char szClassName[VN_SIZE];
|
---|
| 690 | lstrcpy(szClassName,buffer+i2);
|
---|
| 691 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 692 |
|
---|
[114] | 693 | pobj_c = const_cast<CClass *>( pobj_DBClass->Find(szClassName) );
|
---|
[4] | 694 |
|
---|
| 695 | //仮想関数の数
|
---|
| 696 | pobj_c->vtbl_num=*(long *)(buffer+i2);
|
---|
| 697 | i2+=sizeof(long);
|
---|
| 698 |
|
---|
| 699 | //アラインメント
|
---|
| 700 | pobj_c->iAlign=*(long *)(buffer+i2);
|
---|
| 701 | i2+=sizeof(long);
|
---|
| 702 |
|
---|
| 703 | //メンバ
|
---|
| 704 | pobj_c->iMemberNum=*(long *)(buffer+i2);
|
---|
| 705 | i2+=sizeof(long);
|
---|
| 706 | pobj_c->ppobj_Member=
|
---|
| 707 | (CMember **)HeapAlloc(hHeap,0,pobj_c->iMemberNum*sizeof(CMember *));
|
---|
| 708 | for(i4=0;i4<pobj_c->iMemberNum;i4++){
|
---|
| 709 | pobj_c->ppobj_Member[i4]=new CMember();
|
---|
| 710 |
|
---|
| 711 | pobj_c->ppobj_Member[i4]->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
|
---|
| 712 | lstrcpy(pobj_c->ppobj_Member[i4]->name,buffer+i2);
|
---|
| 713 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 714 |
|
---|
| 715 | memcpy(pobj_c->ppobj_Member[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
|
---|
| 716 | i2+=sizeof(int)*MAX_ARRAYDIM;
|
---|
| 717 |
|
---|
| 718 | //型
|
---|
[75] | 719 | Type type( *(long *)(buffer+i2) );
|
---|
[4] | 720 | i2+=sizeof(long);
|
---|
| 721 |
|
---|
| 722 | //型の拡張情報
|
---|
[75] | 723 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 724 |
|
---|
[75] | 725 | pobj_c->ppobj_Member[i4]->SetType( type.GetBasicType(), type.GetIndex() );
|
---|
| 726 |
|
---|
[4] | 727 | pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2);
|
---|
| 728 | i2+=sizeof(long);
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | //メソッド
|
---|
[51] | 732 | int nMethod = *(long *)(buffer+i2);
|
---|
[4] | 733 | i2+=sizeof(long);
|
---|
[51] | 734 | for( i4=0; i4<nMethod; i4++ ){
|
---|
[4] | 735 |
|
---|
[100] | 736 | DWORD dwAccess=*(long *)(buffer+i2);
|
---|
[4] | 737 | i2+=sizeof(long);
|
---|
| 738 |
|
---|
| 739 | char szInherits[VN_SIZE];
|
---|
| 740 | lstrcpy(szInherits,buffer+i2);
|
---|
| 741 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 742 |
|
---|
[114] | 743 | const CClass *pobj_InheritsClass = NULL;
|
---|
[100] | 744 | if(szInherits[0]){
|
---|
[102] | 745 | pobj_InheritsClass=pobj_DBClass->Find(szInherits);
|
---|
[100] | 746 | }
|
---|
[4] | 747 |
|
---|
| 748 | lstrcpy(temp2,buffer+i2);
|
---|
| 749 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 750 |
|
---|
[114] | 751 | const CClass *pobj_temp_c;
|
---|
[100] | 752 | pobj_temp_c=pobj_InheritsClass;
|
---|
[4] | 753 | if(pobj_temp_c==0) pobj_temp_c=pobj_c;
|
---|
| 754 | i5=hash_default(temp2);
|
---|
[75] | 755 | pUserProc=ppSubHash[i5];
|
---|
[4] | 756 | while(1){
|
---|
[75] | 757 | if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break;
|
---|
| 758 | pUserProc=pUserProc->pNextData;
|
---|
[4] | 759 | }
|
---|
[51] | 760 |
|
---|
[100] | 761 | CMethod *method = new CMethod( pUserProc, dwAccess, 0,0,false, false);
|
---|
| 762 | method->pobj_InheritsClass = pobj_InheritsClass;
|
---|
| 763 |
|
---|
[51] | 764 | pobj_c->methods.push_back( method );
|
---|
[4] | 765 | }
|
---|
| 766 |
|
---|
| 767 | //静的メンバ
|
---|
[53] | 768 | int nStaticMember = *(long *)(buffer+i2);
|
---|
[4] | 769 | i2+=sizeof(long);
|
---|
[53] | 770 | for( i4=0; i4<nStaticMember; i4++ ){
|
---|
| 771 | CMember *member=new CMember();
|
---|
[4] | 772 |
|
---|
[53] | 773 | member->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
|
---|
| 774 | lstrcpy(member->name,buffer+i2);
|
---|
[4] | 775 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 776 |
|
---|
[53] | 777 | memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
|
---|
[4] | 778 | i2+=sizeof(int)*MAX_ARRAYDIM;
|
---|
| 779 |
|
---|
| 780 | //型
|
---|
[75] | 781 | Type type( *(long *)(buffer+i2) );
|
---|
[4] | 782 | i2+=sizeof(long);
|
---|
| 783 |
|
---|
| 784 | //型の拡張情報
|
---|
[75] | 785 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 786 |
|
---|
[75] | 787 | member->SetType( type.GetBasicType(), type.GetIndex() );
|
---|
| 788 |
|
---|
[53] | 789 | member->dwAccess=*(long *)(buffer+i2);
|
---|
[4] | 790 | i2+=sizeof(long);
|
---|
[53] | 791 |
|
---|
| 792 | pobj_c->staticMembers.push_back( member );
|
---|
[4] | 793 | }
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | HeapDefaultFree(buffer);
|
---|
| 797 | buffer=0;
|
---|
| 798 |
|
---|
| 799 |
|
---|
| 800 |
|
---|
| 801 |
|
---|
[100] | 802 | extern GlobalProc **ppSubHash;
|
---|
[4] | 803 | ppSubHash=this->ppSubHash;
|
---|
| 804 | pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
|
---|
| 805 |
|
---|
| 806 |
|
---|
| 807 | SingleStepCodeBuffer=MakeSingleStepCode();
|
---|
| 808 |
|
---|
| 809 |
|
---|
| 810 | /////////////////////////////
|
---|
| 811 | // ブレークポイントを適用
|
---|
| 812 | /////////////////////////////
|
---|
| 813 |
|
---|
| 814 | //インクルード情報
|
---|
| 815 | extern INCLUDEFILEINFO IncludeFileInfo;
|
---|
| 816 | IncludeFileInfo=this->IncludeFileInfo;
|
---|
| 817 |
|
---|
| 818 | //コードと行番号の関係
|
---|
| 819 | extern int MaxLineInfoNum;
|
---|
| 820 | extern LINEINFO *pLineInfo;
|
---|
| 821 | MaxLineInfoNum=this->MaxLineInfoNum;
|
---|
| 822 | pLineInfo=this->pLineInfo;
|
---|
| 823 |
|
---|
| 824 | BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection);
|
---|
| 825 |
|
---|
| 826 | //プロセスメモリにコピー
|
---|
| 827 | extern HANDLE hDebugProcess;
|
---|
[76] | 828 | SIZE_T accessBytes;
|
---|
[4] | 829 | WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
|
---|
| 830 | BreakStepCodeBuffer,
|
---|
[76] | 831 | SizeOf_CodeSection,&accessBytes);
|
---|
[4] | 832 |
|
---|
| 833 |
|
---|
| 834 | return 1;
|
---|
| 835 | }
|
---|
| 836 |
|
---|
| 837 | BOOL CDebugSection::load(HMODULE hModule){
|
---|
| 838 | if(buffer){
|
---|
| 839 | HeapDefaultFree(buffer);
|
---|
| 840 | buffer=0;
|
---|
| 841 | }
|
---|
| 842 |
|
---|
| 843 |
|
---|
| 844 | extern HANDLE hDebugProcess;
|
---|
[76] | 845 | SIZE_T accessBytes;
|
---|
[4] | 846 | IMAGE_DOS_HEADER ImageDosHeader;
|
---|
[76] | 847 | ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&accessBytes);
|
---|
[4] | 848 |
|
---|
| 849 | int pe_size;
|
---|
| 850 | #ifdef _AMD64_
|
---|
| 851 | IMAGE_NT_HEADERS64 pe_hdr;
|
---|
| 852 | pe_size=sizeof(IMAGE_NT_HEADERS64);
|
---|
| 853 | #else
|
---|
| 854 | IMAGE_NT_HEADERS pe_hdr;
|
---|
| 855 | pe_size=sizeof(IMAGE_NT_HEADERS);
|
---|
| 856 | #endif
|
---|
[76] | 857 | ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&accessBytes);
|
---|
[4] | 858 |
|
---|
| 859 | IMAGE_SECTION_HEADER *pSectionHdr;
|
---|
| 860 | pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER));
|
---|
| 861 | ReadProcessMemory(hDebugProcess,
|
---|
| 862 | (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size),
|
---|
| 863 | pSectionHdr,
|
---|
| 864 | pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
|
---|
[76] | 865 | &accessBytes);
|
---|
[4] | 866 |
|
---|
| 867 | int i;
|
---|
| 868 | for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){
|
---|
| 869 |
|
---|
| 870 | //リライタブルセクション内の情報
|
---|
| 871 | if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){
|
---|
| 872 | dwRVA_RWSection=pSectionHdr[i].VirtualAddress;
|
---|
| 873 | }
|
---|
| 874 |
|
---|
| 875 | //コードセクション内の情報
|
---|
| 876 | if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){
|
---|
| 877 | dwRVA_CodeSection=pSectionHdr[i].VirtualAddress;
|
---|
| 878 | SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData;
|
---|
| 879 | }
|
---|
| 880 |
|
---|
| 881 | //デバッグセクション内の情報
|
---|
| 882 | if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){
|
---|
| 883 | length=pSectionHdr[i].Misc.VirtualSize;
|
---|
| 884 | buffer=(char *)HeapAlloc(hHeap,0,length+1);
|
---|
| 885 |
|
---|
| 886 | ReadProcessMemory(hDebugProcess,
|
---|
| 887 | (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress),
|
---|
| 888 | buffer,
|
---|
| 889 | length,
|
---|
[76] | 890 | &accessBytes);
|
---|
[4] | 891 | buffer[length]=0;
|
---|
| 892 | }
|
---|
| 893 |
|
---|
| 894 | }
|
---|
| 895 | HeapDefaultFree(pSectionHdr);
|
---|
| 896 |
|
---|
| 897 | if(!buffer) return 0;
|
---|
| 898 |
|
---|
| 899 |
|
---|
| 900 | dwImageBase=(DWORD)(ULONG_PTR)hModule;
|
---|
| 901 |
|
---|
| 902 |
|
---|
| 903 |
|
---|
| 904 | if(OpBuffer) HeapDefaultFree(OpBuffer);
|
---|
| 905 | OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
|
---|
| 906 |
|
---|
| 907 | ReadProcessMemory(hDebugProcess,
|
---|
| 908 | (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
|
---|
[76] | 909 | SizeOf_CodeSection,&accessBytes);
|
---|
[4] | 910 |
|
---|
| 911 |
|
---|
| 912 | return __load();
|
---|
| 913 | }
|
---|
| 914 |
|
---|
| 915 | void CDebugSection::choice(void){
|
---|
| 916 | //イメージベース
|
---|
| 917 | extern DWORD ImageBase;
|
---|
| 918 | ImageBase=this->dwImageBase;
|
---|
| 919 |
|
---|
| 920 | //リライタブルセクションのRVA
|
---|
| 921 | extern int MemPos_RWSection;
|
---|
| 922 | MemPos_RWSection=this->dwRVA_RWSection;
|
---|
| 923 |
|
---|
| 924 | //コードセクションのRVAとサイズ
|
---|
| 925 | extern int MemPos_CodeSection;
|
---|
| 926 | extern int FileSize_CodeSection;
|
---|
| 927 | MemPos_CodeSection=this->dwRVA_CodeSection;
|
---|
| 928 | FileSize_CodeSection=this->SizeOf_CodeSection;
|
---|
| 929 |
|
---|
| 930 | //インクルード情報
|
---|
| 931 | extern INCLUDEFILEINFO IncludeFileInfo;
|
---|
| 932 | IncludeFileInfo=this->IncludeFileInfo;
|
---|
| 933 |
|
---|
| 934 | //ソースコード
|
---|
[88] | 935 | Smoothie::Lexical::source = source;
|
---|
[4] | 936 |
|
---|
| 937 | //コードと行番号の関係
|
---|
| 938 | extern int MaxLineInfoNum;
|
---|
| 939 | extern LINEINFO *pLineInfo;
|
---|
| 940 | MaxLineInfoNum=this->MaxLineInfoNum;
|
---|
| 941 | pLineInfo=this->pLineInfo;
|
---|
| 942 |
|
---|
| 943 | // クラス情報
|
---|
| 944 | extern CDBClass *pobj_DBClass;
|
---|
| 945 | pobj_DBClass=this->pobj_DBClass;
|
---|
| 946 |
|
---|
| 947 | //定数を取得
|
---|
| 948 | extern CONSTINFO **ppConstHash;
|
---|
| 949 | ppConstHash=this->ppConstHash;
|
---|
| 950 |
|
---|
| 951 | //グローバル実行領域のサイズ
|
---|
| 952 | extern int GlobalOpBufferSize;
|
---|
| 953 | GlobalOpBufferSize=this->GlobalOpBufferSize;
|
---|
| 954 |
|
---|
| 955 | //プロシージャ
|
---|
| 956 | extern char **ppMacroNames;
|
---|
| 957 | ppMacroNames=0;
|
---|
[100] | 958 | extern GlobalProc **ppSubHash;
|
---|
[4] | 959 | extern int SubNum;
|
---|
| 960 | ppSubHash=this->ppSubHash;
|
---|
| 961 | SubNum=this->SubNum;
|
---|
| 962 |
|
---|
[75] | 963 | extern UserProc *pSub_DebugSys_EndProc;
|
---|
[4] | 964 | pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
|
---|
| 965 |
|
---|
| 966 | //ネイティブコードバッファ
|
---|
| 967 | extern char *OpBuffer;
|
---|
| 968 | OpBuffer=this->OpBuffer;
|
---|
| 969 | }
|
---|
| 970 |
|
---|
| 971 | void CDebugSection::DeleteDebugInfo(void){
|
---|
| 972 | int i2;
|
---|
| 973 |
|
---|
| 974 | //インクルード情報を解放
|
---|
| 975 | for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
|
---|
| 976 | HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
|
---|
| 977 | HeapDefaultFree(IncludeFileInfo.ppFileNames);
|
---|
| 978 |
|
---|
| 979 | //クラスに関するメモリを解放
|
---|
| 980 | delete pobj_DBClass;
|
---|
| 981 | pobj_DBClass=0;
|
---|
| 982 |
|
---|
| 983 | //サブルーチン情報のメモリ解放
|
---|
| 984 | DeleteSubInfo(ppSubHash,0,0);
|
---|
| 985 |
|
---|
| 986 | //定数に関する情報を解放
|
---|
| 987 | DeleteConstInfo(ppConstHash);
|
---|
| 988 |
|
---|
| 989 | //コードと行番号の関係を解放
|
---|
| 990 | HeapDefaultFree(pLineInfo);
|
---|
| 991 |
|
---|
| 992 | //コードバッファを解放
|
---|
| 993 | HeapDefaultFree(OpBuffer);
|
---|
| 994 | OpBuffer=0;
|
---|
| 995 |
|
---|
| 996 | HeapDefaultFree(SingleStepCodeBuffer);
|
---|
| 997 | SingleStepCodeBuffer=0;
|
---|
| 998 |
|
---|
| 999 | HeapDefaultFree(BreakStepCodeBuffer);
|
---|
| 1000 | BreakStepCodeBuffer=0;
|
---|
| 1001 | }
|
---|
| 1002 |
|
---|
| 1003 |
|
---|
| 1004 |
|
---|
| 1005 | CDBDebugSection::CDBDebugSection(){
|
---|
| 1006 | ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
|
---|
| 1007 | num=0;
|
---|
| 1008 | }
|
---|
| 1009 | CDBDebugSection::~CDBDebugSection(){
|
---|
| 1010 | int i;
|
---|
| 1011 | for(i=0;i<num;i++){
|
---|
| 1012 | delete ppobj_ds[i];
|
---|
| 1013 | }
|
---|
| 1014 | HeapDefaultFree(ppobj_ds);
|
---|
| 1015 | }
|
---|
| 1016 |
|
---|
| 1017 | BOOL CDBDebugSection::add(HMODULE hModule){
|
---|
| 1018 | CDebugSection *pobj_d;
|
---|
| 1019 | pobj_d=new CDebugSection();
|
---|
| 1020 | if(!pobj_d->load(hModule)){
|
---|
| 1021 | //デバッグ情報が存在しないとき
|
---|
| 1022 | delete pobj_d;
|
---|
| 1023 | return 0;
|
---|
| 1024 | }
|
---|
| 1025 |
|
---|
| 1026 | ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
|
---|
| 1027 | ppobj_ds[num]=pobj_d;
|
---|
| 1028 | num++;
|
---|
| 1029 |
|
---|
| 1030 | return 1;
|
---|
| 1031 | }
|
---|
| 1032 |
|
---|
| 1033 | void CDBDebugSection::del(HMODULE hModule){
|
---|
| 1034 | int i;
|
---|
| 1035 | for(i=0;i<num;i++){
|
---|
| 1036 | if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
|
---|
| 1037 | delete ppobj_ds[i];
|
---|
| 1038 |
|
---|
| 1039 | num--;
|
---|
| 1040 | for(;i<num;i++){
|
---|
| 1041 | ppobj_ds[i]=ppobj_ds[i+1];
|
---|
| 1042 | }
|
---|
| 1043 | break;
|
---|
| 1044 | }
|
---|
| 1045 | }
|
---|
| 1046 | }
|
---|
| 1047 |
|
---|
| 1048 | void CDBDebugSection::choice(int index){
|
---|
| 1049 | pobj_now=ppobj_ds[index];
|
---|
| 1050 | pobj_now->choice();
|
---|
| 1051 | }
|
---|
| 1052 |
|
---|
| 1053 |
|
---|
| 1054 |
|
---|
| 1055 | CDBDebugSection *pobj_DBDebugSection;
|
---|