[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){
|
---|
[131] | 14 | lstrcpy(buffer+(*p),type.GetClass().GetName().c_str());
|
---|
[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;
|
---|
[140] | 52 | int i2,i3,i5,BufferSize;
|
---|
[4] | 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 | //クラス名
|
---|
[131] | 129 | lstrcpy(buffer+i2,pobj_c->GetName().c_str());
|
---|
[4] | 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()){
|
---|
[131] | 216 | lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->GetName().c_str());
|
---|
[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 | //クラス名
|
---|
[131] | 314 | lstrcpy(buffer+i2,pobj_c->GetName().c_str());
|
---|
[4] | 315 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 316 |
|
---|
| 317 | //仮想関数の数
|
---|
[141] | 318 | *(long *)(buffer+i2)=pobj_c->GetVtblNum();
|
---|
[4] | 319 | i2+=sizeof(long);
|
---|
| 320 |
|
---|
| 321 | //アラインメント
|
---|
| 322 | *(long *)(buffer+i2)=pobj_c->iAlign;
|
---|
| 323 | i2+=sizeof(long);
|
---|
| 324 |
|
---|
| 325 | //メンバ
|
---|
[140] | 326 | *(long *)(buffer+i2)=(int)pobj_c->dynamicMembers.size();
|
---|
[4] | 327 | i2+=sizeof(long);
|
---|
[140] | 328 | foreach( CMember *member, pobj_c->dynamicMembers ){
|
---|
[137] | 329 | // 名前
|
---|
[140] | 330 | lstrcpy(buffer+i2,member->GetName().c_str());
|
---|
[4] | 331 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 332 |
|
---|
[137] | 333 | // 型
|
---|
[140] | 334 | *(long *)(buffer+i2)=member->GetType().GetBasicType();
|
---|
[4] | 335 | i2+=sizeof(long);
|
---|
| 336 |
|
---|
[137] | 337 | // 型の拡張情報
|
---|
[140] | 338 | SetLpIndex_DebugFile(buffer,&i2,member->GetType());
|
---|
[4] | 339 |
|
---|
[137] | 340 | // アクセシビリティ
|
---|
[140] | 341 | *(Prototype::Accessibility *)(buffer+i2)=member->GetAccessibility();
|
---|
[137] | 342 | i2+=sizeof(Prototype::Accessibility);
|
---|
[4] | 343 |
|
---|
[140] | 344 | memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
|
---|
[137] | 345 | i2+=sizeof(int)*MAX_ARRAYDIM;
|
---|
| 346 |
|
---|
[4] | 347 | //バッファが足りない場合は再確保
|
---|
| 348 | if(BufferSize<i2+32768){
|
---|
| 349 | BufferSize+=32768;
|
---|
| 350 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | //メソッド
|
---|
[51] | 355 | *(long *)(buffer+i2)=(long)pobj_c->methods.size();
|
---|
[4] | 356 | i2+=sizeof(long);
|
---|
[135] | 357 | foreach( const CMethod *pMethod, pobj_c->methods ){
|
---|
[137] | 358 | *(Prototype::Accessibility *)(buffer+i2)=pMethod->GetAccessibility();
|
---|
| 359 | i2+=sizeof(Prototype::Accessibility);
|
---|
[135] | 360 | if( pMethod->GetInheritsClassPtr() ){
|
---|
| 361 | lstrcpy(buffer+i2,pMethod->GetInheritsClassPtr()->GetName().c_str());
|
---|
[4] | 362 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 363 | }
|
---|
| 364 | else{
|
---|
| 365 | lstrcpy(buffer+i2,"");
|
---|
| 366 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 367 | }
|
---|
[135] | 368 | lstrcpy(buffer+i2,pMethod->pUserProc->GetName().c_str());
|
---|
[4] | 369 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | //静的メンバ
|
---|
[53] | 373 | *(long *)(buffer+i2)=(long)pobj_c->staticMembers.size();
|
---|
[4] | 374 | i2+=sizeof(long);
|
---|
[53] | 375 | foreach( CMember *member, pobj_c->staticMembers ){
|
---|
[137] | 376 | // 名前
|
---|
[135] | 377 | lstrcpy(buffer+i2,member->GetName().c_str());
|
---|
[4] | 378 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 379 |
|
---|
[137] | 380 | // 型
|
---|
| 381 | *(long *)(buffer+i2)=member->GetType().GetBasicType();
|
---|
[4] | 382 | i2+=sizeof(long);
|
---|
| 383 |
|
---|
[137] | 384 | // 型の拡張情報
|
---|
| 385 | SetLpIndex_DebugFile(buffer,&i2,member->GetType());
|
---|
[4] | 386 |
|
---|
[137] | 387 | // アクセシビリティ
|
---|
| 388 | *(Prototype::Accessibility *)(buffer+i2)=member->GetAccessibility();
|
---|
| 389 | i2+=sizeof(Prototype::Accessibility);
|
---|
[4] | 390 |
|
---|
[137] | 391 | memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
|
---|
| 392 | i2+=sizeof(int)*MAX_ARRAYDIM;
|
---|
| 393 |
|
---|
[4] | 394 | //バッファが足りない場合は再確保
|
---|
| 395 | if(BufferSize<i2+32768){
|
---|
| 396 | BufferSize+=32768;
|
---|
| 397 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
|
---|
| 398 | }
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | //バッファが足りない場合は再確保
|
---|
| 402 | if(BufferSize<i2+32768){
|
---|
| 403 | BufferSize+=32768;
|
---|
| 404 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
|
---|
| 405 | }
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | length=i2;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | char *CDebugSection::MakeSingleStepCode(void){
|
---|
| 412 | char *buffer;
|
---|
| 413 | buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
|
---|
| 414 |
|
---|
| 415 | memcpy(buffer,OpBuffer,SizeOf_CodeSection);
|
---|
| 416 |
|
---|
| 417 | int i2;
|
---|
| 418 | for(i2=0;i2<MaxLineInfoNum;i2++){
|
---|
| 419 | if(!(
|
---|
| 420 | pLineInfo[i2].dwCodeType&CODETYPE_SYSTEMPROC||
|
---|
| 421 | pLineInfo[i2].dwCodeType&CODETYPE_DEBUGPROC
|
---|
| 422 | )){
|
---|
| 423 | //int 3
|
---|
| 424 | buffer[pLineInfo[i2].TopObp]=(char)0xCC;
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | return buffer;
|
---|
| 429 | }
|
---|
| 430 | BOOL CDebugSection::__load(void){
|
---|
| 431 | int i2,i3,i4,i5,num;
|
---|
| 432 | char temp2[MAX_PATH],*temp5;
|
---|
| 433 |
|
---|
[114] | 434 | pobj_CompilingClass = NULL;
|
---|
[16] | 435 |
|
---|
[4] | 436 | i2=0;
|
---|
| 437 |
|
---|
| 438 | //デバッグ用ファイルのバージョンをチェック
|
---|
| 439 | if(*(long *)(buffer+i2)<MDLFILE_VER){
|
---|
| 440 | HeapDefaultFree(buffer);
|
---|
| 441 | return 0;
|
---|
| 442 | }
|
---|
| 443 | i2+=sizeof(long);
|
---|
| 444 |
|
---|
| 445 | //プラットフォームのビット数をチェック
|
---|
| 446 | if(*(long *)(buffer+i2)!=PLATFORM){
|
---|
| 447 | HeapDefaultFree(buffer);
|
---|
| 448 | return 0;
|
---|
| 449 | }
|
---|
| 450 | i2+=sizeof(long);
|
---|
| 451 |
|
---|
| 452 | //インクルード情報
|
---|
| 453 | IncludeFileInfo.FilesNum=*(long *)(buffer+i2);
|
---|
| 454 | i2+=sizeof(long);
|
---|
| 455 | IncludeFileInfo.ppFileNames=(char **)HeapAlloc(hHeap,0,IncludeFileInfo.FilesNum*sizeof(char *));
|
---|
| 456 | for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
|
---|
| 457 | if(buffer[i2]=='\0') break;
|
---|
| 458 | IncludeFileInfo.ppFileNames[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
|
---|
| 459 | lstrcpy(IncludeFileInfo.ppFileNames[i3],buffer+i2);
|
---|
| 460 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 461 | }
|
---|
| 462 | for(i2++,i3=0;;i2++,i3++){
|
---|
| 463 | IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2];
|
---|
| 464 | if(IncludeFileInfo.LineOfFile[i3]==-1) break;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | //ソースコード
|
---|
| 468 | i2++;
|
---|
[88] | 469 | source.SetBuffer( buffer + i2 );
|
---|
[15] | 470 | i2+=lstrlen(buffer+i2)+1;
|
---|
[4] | 471 |
|
---|
| 472 | //コードと行番号の関係
|
---|
| 473 | MaxLineInfoNum=*(long *)(buffer+i2);
|
---|
| 474 | i2+=sizeof(long);
|
---|
| 475 | pLineInfo=(LINEINFO *)HeapAlloc(hHeap,0,MaxLineInfoNum*sizeof(LINEINFO)+1);
|
---|
| 476 | memcpy(pLineInfo,buffer+i2,MaxLineInfoNum*sizeof(LINEINFO));
|
---|
| 477 | i2+=MaxLineInfoNum*sizeof(LINEINFO);
|
---|
| 478 |
|
---|
| 479 |
|
---|
| 480 | ///////////////////////////////////////////
|
---|
| 481 | // クラス情報(名前のみ。詳細は後で取得)
|
---|
| 482 | ///////////////////////////////////////////
|
---|
| 483 |
|
---|
| 484 | this->pobj_DBClass=new CDBClass();
|
---|
| 485 |
|
---|
| 486 | int iMaxClassCount;
|
---|
| 487 | iMaxClassCount=*(long *)(buffer+i2);
|
---|
| 488 | i2+=sizeof(long);
|
---|
| 489 | for(i3=0;i3<iMaxClassCount;i3++){
|
---|
| 490 | //クラス名
|
---|
[101] | 491 | // TODO: 名前空間が未完成
|
---|
[108] | 492 | pobj_DBClass->AddClass(NamespaceScopes(),NamespaceScopesCollection(),buffer+i2,0);
|
---|
[4] | 493 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | extern CDBClass *pobj_DBClass;
|
---|
| 497 | pobj_DBClass=this->pobj_DBClass;
|
---|
| 498 |
|
---|
| 499 |
|
---|
| 500 | //////////////////
|
---|
| 501 | // TypeDef情報
|
---|
| 502 | //////////////////
|
---|
| 503 |
|
---|
| 504 | //初期化
|
---|
[88] | 505 | Smoothie::Meta::typeDefs.clear();
|
---|
[4] | 506 |
|
---|
| 507 | //個数を取得
|
---|
| 508 | num=*(long *)(buffer+i2);
|
---|
| 509 | i2+=sizeof(long);
|
---|
| 510 | for(i3=0;i3<num;i3++){
|
---|
| 511 | temp5=buffer+i2;
|
---|
| 512 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 513 |
|
---|
[113] | 514 | // 名前空間に未対応
|
---|
| 515 | Smoothie::Meta::typeDefs.push_back( TypeDef( NamespaceScopes(), temp5, buffer+i2 ) );
|
---|
[4] | 516 |
|
---|
| 517 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | //定数を取得
|
---|
| 521 | GetConstInfo();
|
---|
| 522 | extern CONSTINFO **ppConstHash;
|
---|
| 523 | this->ppConstHash=ppConstHash;
|
---|
| 524 |
|
---|
| 525 |
|
---|
| 526 | //グローバル変数情報
|
---|
[75] | 527 | globalVars.clear();
|
---|
| 528 | int maxGlobalVars=*(long *)(buffer+i2);
|
---|
[4] | 529 | i2+=sizeof(long);
|
---|
[75] | 530 | for(i3=0;i3<maxGlobalVars;i3++){
|
---|
[4] | 531 |
|
---|
| 532 | //変数名
|
---|
[75] | 533 | char *name = buffer+i2;
|
---|
[4] | 534 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 535 |
|
---|
[75] | 536 | int basicType = *(long *)(buffer+i2);
|
---|
[4] | 537 | i2+=sizeof(long);
|
---|
| 538 |
|
---|
[75] | 539 | Type type( basicType );
|
---|
| 540 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 541 |
|
---|
[75] | 542 | bool isRef = (buffer[i2++]) ? true:false;
|
---|
[4] | 543 |
|
---|
[75] | 544 | bool isArray = (buffer[i2++]) ? true:false;
|
---|
| 545 |
|
---|
| 546 | Variable *pVar = new Variable( name, type, false, isRef );
|
---|
| 547 |
|
---|
| 548 | if(isArray){
|
---|
| 549 | int SubScripts[MAX_ARRAYDIM];
|
---|
[4] | 550 | for(i4=0;;i4++){
|
---|
[75] | 551 | SubScripts[i4]=*(long *)(buffer+i2);
|
---|
[4] | 552 | i2+=sizeof(long);
|
---|
| 553 |
|
---|
[75] | 554 | if(SubScripts[i4]==-1) break;
|
---|
[4] | 555 | }
|
---|
[75] | 556 |
|
---|
| 557 | pVar->SetArray( SubScripts );
|
---|
[4] | 558 | }
|
---|
| 559 |
|
---|
| 560 | //レキシカルスコープ情報
|
---|
| 561 | pVar->ScopeStartAddress=*(long *)(buffer+i2);
|
---|
| 562 | i2+=sizeof(long);
|
---|
| 563 | pVar->ScopeEndAddress=*(long *)(buffer+i2);
|
---|
| 564 | i2+=sizeof(long);
|
---|
| 565 | pVar->ScopeLevel=*(long *)(buffer+i2);
|
---|
| 566 | i2+=sizeof(long);
|
---|
| 567 |
|
---|
| 568 | //メモリ位置
|
---|
| 569 | pVar->offset=*(long *)(buffer+i2);
|
---|
| 570 | i2+=sizeof(long);
|
---|
[75] | 571 |
|
---|
| 572 | //変数を追加
|
---|
| 573 | globalVars.push_back( pVar );
|
---|
[4] | 574 | }
|
---|
| 575 |
|
---|
| 576 | //グローバル実行領域のサイズ
|
---|
| 577 | GlobalOpBufferSize=*(long *)(buffer+i2);
|
---|
| 578 | i2+=sizeof(long);
|
---|
| 579 |
|
---|
| 580 | //プロシージャ情報
|
---|
[100] | 581 | GlobalProc *pUserProc;
|
---|
[4] | 582 | SubNum=*(long *)(buffer+i2);
|
---|
| 583 | i2+=sizeof(long);
|
---|
[100] | 584 | ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *));
|
---|
[75] | 585 | for(int i6=0;i6<SubNum;i6++){
|
---|
[4] | 586 | char szParentClassName[VN_SIZE];
|
---|
| 587 | lstrcpy(szParentClassName,buffer+i2);
|
---|
| 588 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 589 |
|
---|
[114] | 590 | const CClass *pClass = NULL;
|
---|
| 591 | if(szParentClassName[0]){
|
---|
[102] | 592 | pClass=pobj_DBClass->Find(szParentClassName);
|
---|
[114] | 593 | }
|
---|
[4] | 594 |
|
---|
| 595 | //ID
|
---|
[75] | 596 | int id=*(long *)(buffer+i2);
|
---|
[4] | 597 | i2+=sizeof(long);
|
---|
| 598 |
|
---|
| 599 | //名前
|
---|
[75] | 600 | char *name = buffer+i2;
|
---|
[4] | 601 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 602 |
|
---|
[75] | 603 | // オブジェクトを生成
|
---|
[100] | 604 | // TODO: 名前空間が未完成
|
---|
[108] | 605 | pUserProc = new GlobalProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false );
|
---|
[75] | 606 | pUserProc->pNextData=0;
|
---|
| 607 | pUserProc->id=id;
|
---|
| 608 | pUserProc->SetParentClass( pClass );
|
---|
| 609 |
|
---|
| 610 | pUserProc->beginOpAddress=*(long *)(buffer+i2);
|
---|
[4] | 611 | i2+=sizeof(long);
|
---|
[75] | 612 | pUserProc->endOpAddress=*(long *)(buffer+i2);
|
---|
[4] | 613 | i2+=sizeof(long);
|
---|
| 614 |
|
---|
[75] | 615 | pUserProc->CompleteCompile();
|
---|
[4] | 616 |
|
---|
| 617 | //ローカル変数情報
|
---|
[75] | 618 | pUserProc->localVars.clear();
|
---|
| 619 | int maxLocalVar=*(long *)(buffer+i2);
|
---|
[4] | 620 | i2+=sizeof(long);
|
---|
[75] | 621 | for(i3=0;i3<maxLocalVar;i3++){
|
---|
| 622 | //変数名
|
---|
| 623 | char *name = buffer+i2;
|
---|
[4] | 624 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 625 |
|
---|
[75] | 626 | int basicType = *(long *)(buffer+i2);
|
---|
[4] | 627 | i2+=sizeof(long);
|
---|
| 628 |
|
---|
[75] | 629 | Type type( basicType );
|
---|
| 630 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 631 |
|
---|
[75] | 632 | bool isRef = (buffer[i2++]) ? true:false;
|
---|
[4] | 633 |
|
---|
[75] | 634 | bool isArray = (buffer[i2++]) ? true:false;
|
---|
| 635 |
|
---|
| 636 | Variable *pVar = new Variable( name, type, false, isRef );
|
---|
| 637 |
|
---|
| 638 | if(isArray){
|
---|
| 639 | int SubScripts[MAX_ARRAYDIM];
|
---|
| 640 | for(i4=0;;i4++){
|
---|
| 641 | SubScripts[i4]=*(long *)(buffer+i2);
|
---|
[4] | 642 | i2+=sizeof(long);
|
---|
| 643 |
|
---|
[75] | 644 | if(SubScripts[i4]==-1) break;
|
---|
[4] | 645 | }
|
---|
[75] | 646 |
|
---|
| 647 | pVar->SetArray( SubScripts );
|
---|
[4] | 648 | }
|
---|
| 649 |
|
---|
| 650 | //レキシカルスコープ情報
|
---|
| 651 | pVar->ScopeStartAddress=*(long *)(buffer+i2);
|
---|
| 652 | i2+=sizeof(long);
|
---|
| 653 | pVar->ScopeEndAddress=*(long *)(buffer+i2);
|
---|
| 654 | i2+=sizeof(long);
|
---|
| 655 | pVar->ScopeLevel=*(long *)(buffer+i2);
|
---|
| 656 | i2+=sizeof(long);
|
---|
| 657 |
|
---|
[75] | 658 | //メモリ位置
|
---|
[4] | 659 | pVar->offset=*(long *)(buffer+i2);
|
---|
| 660 | i2+=sizeof(long);
|
---|
[75] | 661 |
|
---|
| 662 | //変数を追加
|
---|
| 663 | pUserProc->localVars.push_back( pVar );
|
---|
[4] | 664 | }
|
---|
| 665 |
|
---|
| 666 |
|
---|
| 667 | /////////////////////////////////
|
---|
[75] | 668 | // 格納位置を計算してpUserProcをセット
|
---|
[4] | 669 | /////////////////////////////////
|
---|
| 670 |
|
---|
[75] | 671 | i4=hash_default(pUserProc->GetName().c_str());
|
---|
[4] | 672 |
|
---|
[100] | 673 | GlobalProc *psi2;
|
---|
[4] | 674 | if(ppSubHash[i4]){
|
---|
| 675 | psi2=ppSubHash[i4];
|
---|
| 676 | while(1){
|
---|
| 677 | if(psi2->pNextData==0){
|
---|
[75] | 678 | psi2->pNextData=pUserProc;
|
---|
[4] | 679 | break;
|
---|
| 680 | }
|
---|
| 681 | psi2=psi2->pNextData;
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 | else{
|
---|
[75] | 685 | ppSubHash[i4]=pUserProc;
|
---|
[4] | 686 | }
|
---|
| 687 | }
|
---|
| 688 |
|
---|
| 689 | //クラス情報
|
---|
| 690 | CClass *pobj_c;
|
---|
| 691 | for(i3=0;i3<iMaxClassCount;i3++){
|
---|
| 692 | //クラス名
|
---|
| 693 | char szClassName[VN_SIZE];
|
---|
| 694 | lstrcpy(szClassName,buffer+i2);
|
---|
| 695 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 696 |
|
---|
[114] | 697 | pobj_c = const_cast<CClass *>( pobj_DBClass->Find(szClassName) );
|
---|
[4] | 698 |
|
---|
| 699 | //仮想関数の数
|
---|
[141] | 700 | pobj_c->SetVtblNum( *(long *)(buffer+i2) );
|
---|
[4] | 701 | i2+=sizeof(long);
|
---|
| 702 |
|
---|
| 703 | //アラインメント
|
---|
| 704 | pobj_c->iAlign=*(long *)(buffer+i2);
|
---|
| 705 | i2+=sizeof(long);
|
---|
| 706 |
|
---|
[140] | 707 | //静的メンバ
|
---|
| 708 | int nDynamicMember = *(long *)(buffer+i2);
|
---|
[4] | 709 | i2+=sizeof(long);
|
---|
[140] | 710 | for( i4=0; i4<nDynamicMember; i4++ ){
|
---|
[137] | 711 | // 名前
|
---|
| 712 | string name = (char *)(buffer+i2);
|
---|
[4] | 713 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 714 |
|
---|
[137] | 715 | // 型
|
---|
[75] | 716 | Type type( *(long *)(buffer+i2) );
|
---|
[4] | 717 | i2+=sizeof(long);
|
---|
| 718 |
|
---|
[137] | 719 | // 型の拡張情報
|
---|
[75] | 720 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 721 |
|
---|
[137] | 722 | // アクセシビリティ
|
---|
| 723 | Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
|
---|
| 724 | i2+=sizeof(Prototype::Accessibility);
|
---|
[75] | 725 |
|
---|
[140] | 726 | CMember *member=new CMember( accessibility, name, type, false );
|
---|
[137] | 727 |
|
---|
[140] | 728 | memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
|
---|
[137] | 729 | i2+=sizeof(int)*MAX_ARRAYDIM;
|
---|
[140] | 730 |
|
---|
| 731 | pobj_c->dynamicMembers.push_back( member );
|
---|
[4] | 732 | }
|
---|
| 733 |
|
---|
| 734 | //メソッド
|
---|
[51] | 735 | int nMethod = *(long *)(buffer+i2);
|
---|
[4] | 736 | i2+=sizeof(long);
|
---|
[51] | 737 | for( i4=0; i4<nMethod; i4++ ){
|
---|
[4] | 738 |
|
---|
[137] | 739 | Prototype::Accessibility accessibility=*(Prototype::Accessibility *)(buffer+i2);
|
---|
| 740 | i2+=sizeof(Prototype::Accessibility);
|
---|
[4] | 741 |
|
---|
| 742 | char szInherits[VN_SIZE];
|
---|
| 743 | lstrcpy(szInherits,buffer+i2);
|
---|
| 744 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 745 |
|
---|
[114] | 746 | const CClass *pobj_InheritsClass = NULL;
|
---|
[100] | 747 | if(szInherits[0]){
|
---|
[102] | 748 | pobj_InheritsClass=pobj_DBClass->Find(szInherits);
|
---|
[100] | 749 | }
|
---|
[4] | 750 |
|
---|
| 751 | lstrcpy(temp2,buffer+i2);
|
---|
| 752 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 753 |
|
---|
[114] | 754 | const CClass *pobj_temp_c;
|
---|
[100] | 755 | pobj_temp_c=pobj_InheritsClass;
|
---|
[4] | 756 | if(pobj_temp_c==0) pobj_temp_c=pobj_c;
|
---|
| 757 | i5=hash_default(temp2);
|
---|
[75] | 758 | pUserProc=ppSubHash[i5];
|
---|
[4] | 759 | while(1){
|
---|
[75] | 760 | if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break;
|
---|
| 761 | pUserProc=pUserProc->pNextData;
|
---|
[4] | 762 | }
|
---|
[51] | 763 |
|
---|
[137] | 764 | CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, 0,0,false, pobj_InheritsClass);
|
---|
[100] | 765 |
|
---|
[135] | 766 | pobj_c->methods.push_back( pMethod );
|
---|
[4] | 767 | }
|
---|
| 768 |
|
---|
| 769 | //静的メンバ
|
---|
[53] | 770 | int nStaticMember = *(long *)(buffer+i2);
|
---|
[4] | 771 | i2+=sizeof(long);
|
---|
[53] | 772 | for( i4=0; i4<nStaticMember; i4++ ){
|
---|
[137] | 773 | // 名前
|
---|
| 774 | string name = (char *)(buffer+i2);
|
---|
[4] | 775 | i2+=lstrlen(buffer+i2)+1;
|
---|
| 776 |
|
---|
[137] | 777 | // 型
|
---|
[75] | 778 | Type type( *(long *)(buffer+i2) );
|
---|
[4] | 779 | i2+=sizeof(long);
|
---|
| 780 |
|
---|
[137] | 781 | // 型の拡張情報
|
---|
[75] | 782 | GetLpIndex_DebugFile(buffer,&i2,type);
|
---|
[4] | 783 |
|
---|
[137] | 784 | // アクセシビリティ
|
---|
| 785 | Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
|
---|
| 786 | i2+=sizeof(Prototype::Accessibility);
|
---|
[75] | 787 |
|
---|
[137] | 788 | CMember *member=new CMember( accessibility, name, type, false );
|
---|
[53] | 789 |
|
---|
[137] | 790 | memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
|
---|
| 791 | i2+=sizeof(int)*MAX_ARRAYDIM;
|
---|
| 792 |
|
---|
[53] | 793 | pobj_c->staticMembers.push_back( member );
|
---|
[4] | 794 | }
|
---|
| 795 | }
|
---|
| 796 |
|
---|
| 797 | HeapDefaultFree(buffer);
|
---|
| 798 | buffer=0;
|
---|
| 799 |
|
---|
| 800 |
|
---|
| 801 |
|
---|
| 802 |
|
---|
[100] | 803 | extern GlobalProc **ppSubHash;
|
---|
[4] | 804 | ppSubHash=this->ppSubHash;
|
---|
| 805 | pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
|
---|
| 806 |
|
---|
| 807 |
|
---|
| 808 | SingleStepCodeBuffer=MakeSingleStepCode();
|
---|
| 809 |
|
---|
| 810 |
|
---|
| 811 | /////////////////////////////
|
---|
| 812 | // ブレークポイントを適用
|
---|
| 813 | /////////////////////////////
|
---|
| 814 |
|
---|
| 815 | //インクルード情報
|
---|
| 816 | extern INCLUDEFILEINFO IncludeFileInfo;
|
---|
| 817 | IncludeFileInfo=this->IncludeFileInfo;
|
---|
| 818 |
|
---|
| 819 | //コードと行番号の関係
|
---|
| 820 | extern int MaxLineInfoNum;
|
---|
| 821 | extern LINEINFO *pLineInfo;
|
---|
| 822 | MaxLineInfoNum=this->MaxLineInfoNum;
|
---|
| 823 | pLineInfo=this->pLineInfo;
|
---|
| 824 |
|
---|
| 825 | BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection);
|
---|
| 826 |
|
---|
| 827 | //プロセスメモリにコピー
|
---|
| 828 | extern HANDLE hDebugProcess;
|
---|
[76] | 829 | SIZE_T accessBytes;
|
---|
[4] | 830 | WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
|
---|
| 831 | BreakStepCodeBuffer,
|
---|
[76] | 832 | SizeOf_CodeSection,&accessBytes);
|
---|
[4] | 833 |
|
---|
| 834 |
|
---|
| 835 | return 1;
|
---|
| 836 | }
|
---|
| 837 |
|
---|
| 838 | BOOL CDebugSection::load(HMODULE hModule){
|
---|
| 839 | if(buffer){
|
---|
| 840 | HeapDefaultFree(buffer);
|
---|
| 841 | buffer=0;
|
---|
| 842 | }
|
---|
| 843 |
|
---|
| 844 |
|
---|
| 845 | extern HANDLE hDebugProcess;
|
---|
[76] | 846 | SIZE_T accessBytes;
|
---|
[4] | 847 | IMAGE_DOS_HEADER ImageDosHeader;
|
---|
[76] | 848 | ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&accessBytes);
|
---|
[4] | 849 |
|
---|
| 850 | int pe_size;
|
---|
| 851 | #ifdef _AMD64_
|
---|
| 852 | IMAGE_NT_HEADERS64 pe_hdr;
|
---|
| 853 | pe_size=sizeof(IMAGE_NT_HEADERS64);
|
---|
| 854 | #else
|
---|
| 855 | IMAGE_NT_HEADERS pe_hdr;
|
---|
| 856 | pe_size=sizeof(IMAGE_NT_HEADERS);
|
---|
| 857 | #endif
|
---|
[76] | 858 | ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&accessBytes);
|
---|
[4] | 859 |
|
---|
| 860 | IMAGE_SECTION_HEADER *pSectionHdr;
|
---|
| 861 | pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER));
|
---|
| 862 | ReadProcessMemory(hDebugProcess,
|
---|
| 863 | (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size),
|
---|
| 864 | pSectionHdr,
|
---|
| 865 | pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
|
---|
[76] | 866 | &accessBytes);
|
---|
[4] | 867 |
|
---|
| 868 | int i;
|
---|
| 869 | for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){
|
---|
| 870 |
|
---|
| 871 | //リライタブルセクション内の情報
|
---|
| 872 | if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){
|
---|
| 873 | dwRVA_RWSection=pSectionHdr[i].VirtualAddress;
|
---|
| 874 | }
|
---|
| 875 |
|
---|
| 876 | //コードセクション内の情報
|
---|
| 877 | if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){
|
---|
| 878 | dwRVA_CodeSection=pSectionHdr[i].VirtualAddress;
|
---|
| 879 | SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData;
|
---|
| 880 | }
|
---|
| 881 |
|
---|
| 882 | //デバッグセクション内の情報
|
---|
| 883 | if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){
|
---|
| 884 | length=pSectionHdr[i].Misc.VirtualSize;
|
---|
| 885 | buffer=(char *)HeapAlloc(hHeap,0,length+1);
|
---|
| 886 |
|
---|
| 887 | ReadProcessMemory(hDebugProcess,
|
---|
| 888 | (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress),
|
---|
| 889 | buffer,
|
---|
| 890 | length,
|
---|
[76] | 891 | &accessBytes);
|
---|
[4] | 892 | buffer[length]=0;
|
---|
| 893 | }
|
---|
| 894 |
|
---|
| 895 | }
|
---|
| 896 | HeapDefaultFree(pSectionHdr);
|
---|
| 897 |
|
---|
| 898 | if(!buffer) return 0;
|
---|
| 899 |
|
---|
| 900 |
|
---|
| 901 | dwImageBase=(DWORD)(ULONG_PTR)hModule;
|
---|
| 902 |
|
---|
| 903 |
|
---|
| 904 |
|
---|
| 905 | if(OpBuffer) HeapDefaultFree(OpBuffer);
|
---|
| 906 | OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
|
---|
| 907 |
|
---|
| 908 | ReadProcessMemory(hDebugProcess,
|
---|
| 909 | (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
|
---|
[76] | 910 | SizeOf_CodeSection,&accessBytes);
|
---|
[4] | 911 |
|
---|
| 912 |
|
---|
| 913 | return __load();
|
---|
| 914 | }
|
---|
| 915 |
|
---|
| 916 | void CDebugSection::choice(void){
|
---|
| 917 | //イメージベース
|
---|
| 918 | extern DWORD ImageBase;
|
---|
| 919 | ImageBase=this->dwImageBase;
|
---|
| 920 |
|
---|
| 921 | //リライタブルセクションのRVA
|
---|
| 922 | extern int MemPos_RWSection;
|
---|
| 923 | MemPos_RWSection=this->dwRVA_RWSection;
|
---|
| 924 |
|
---|
| 925 | //コードセクションのRVAとサイズ
|
---|
| 926 | extern int MemPos_CodeSection;
|
---|
| 927 | extern int FileSize_CodeSection;
|
---|
| 928 | MemPos_CodeSection=this->dwRVA_CodeSection;
|
---|
| 929 | FileSize_CodeSection=this->SizeOf_CodeSection;
|
---|
| 930 |
|
---|
| 931 | //インクルード情報
|
---|
| 932 | extern INCLUDEFILEINFO IncludeFileInfo;
|
---|
| 933 | IncludeFileInfo=this->IncludeFileInfo;
|
---|
| 934 |
|
---|
| 935 | //ソースコード
|
---|
[88] | 936 | Smoothie::Lexical::source = source;
|
---|
[4] | 937 |
|
---|
| 938 | //コードと行番号の関係
|
---|
| 939 | extern int MaxLineInfoNum;
|
---|
| 940 | extern LINEINFO *pLineInfo;
|
---|
| 941 | MaxLineInfoNum=this->MaxLineInfoNum;
|
---|
| 942 | pLineInfo=this->pLineInfo;
|
---|
| 943 |
|
---|
| 944 | // クラス情報
|
---|
| 945 | extern CDBClass *pobj_DBClass;
|
---|
| 946 | pobj_DBClass=this->pobj_DBClass;
|
---|
| 947 |
|
---|
| 948 | //定数を取得
|
---|
| 949 | extern CONSTINFO **ppConstHash;
|
---|
| 950 | ppConstHash=this->ppConstHash;
|
---|
| 951 |
|
---|
| 952 | //グローバル実行領域のサイズ
|
---|
| 953 | extern int GlobalOpBufferSize;
|
---|
| 954 | GlobalOpBufferSize=this->GlobalOpBufferSize;
|
---|
| 955 |
|
---|
| 956 | //プロシージャ
|
---|
| 957 | extern char **ppMacroNames;
|
---|
| 958 | ppMacroNames=0;
|
---|
[100] | 959 | extern GlobalProc **ppSubHash;
|
---|
[4] | 960 | extern int SubNum;
|
---|
| 961 | ppSubHash=this->ppSubHash;
|
---|
| 962 | SubNum=this->SubNum;
|
---|
| 963 |
|
---|
[75] | 964 | extern UserProc *pSub_DebugSys_EndProc;
|
---|
[4] | 965 | pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
|
---|
| 966 |
|
---|
| 967 | //ネイティブコードバッファ
|
---|
| 968 | extern char *OpBuffer;
|
---|
| 969 | OpBuffer=this->OpBuffer;
|
---|
| 970 | }
|
---|
| 971 |
|
---|
| 972 | void CDebugSection::DeleteDebugInfo(void){
|
---|
| 973 | int i2;
|
---|
| 974 |
|
---|
| 975 | //インクルード情報を解放
|
---|
| 976 | for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
|
---|
| 977 | HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
|
---|
| 978 | HeapDefaultFree(IncludeFileInfo.ppFileNames);
|
---|
| 979 |
|
---|
| 980 | //クラスに関するメモリを解放
|
---|
| 981 | delete pobj_DBClass;
|
---|
| 982 | pobj_DBClass=0;
|
---|
| 983 |
|
---|
| 984 | //サブルーチン情報のメモリ解放
|
---|
| 985 | DeleteSubInfo(ppSubHash,0,0);
|
---|
| 986 |
|
---|
| 987 | //定数に関する情報を解放
|
---|
| 988 | DeleteConstInfo(ppConstHash);
|
---|
| 989 |
|
---|
| 990 | //コードと行番号の関係を解放
|
---|
| 991 | HeapDefaultFree(pLineInfo);
|
---|
| 992 |
|
---|
| 993 | //コードバッファを解放
|
---|
| 994 | HeapDefaultFree(OpBuffer);
|
---|
| 995 | OpBuffer=0;
|
---|
| 996 |
|
---|
| 997 | HeapDefaultFree(SingleStepCodeBuffer);
|
---|
| 998 | SingleStepCodeBuffer=0;
|
---|
| 999 |
|
---|
| 1000 | HeapDefaultFree(BreakStepCodeBuffer);
|
---|
| 1001 | BreakStepCodeBuffer=0;
|
---|
| 1002 | }
|
---|
| 1003 |
|
---|
| 1004 |
|
---|
| 1005 |
|
---|
| 1006 | CDBDebugSection::CDBDebugSection(){
|
---|
| 1007 | ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
|
---|
| 1008 | num=0;
|
---|
| 1009 | }
|
---|
| 1010 | CDBDebugSection::~CDBDebugSection(){
|
---|
| 1011 | int i;
|
---|
| 1012 | for(i=0;i<num;i++){
|
---|
| 1013 | delete ppobj_ds[i];
|
---|
| 1014 | }
|
---|
| 1015 | HeapDefaultFree(ppobj_ds);
|
---|
| 1016 | }
|
---|
| 1017 |
|
---|
| 1018 | BOOL CDBDebugSection::add(HMODULE hModule){
|
---|
| 1019 | CDebugSection *pobj_d;
|
---|
| 1020 | pobj_d=new CDebugSection();
|
---|
| 1021 | if(!pobj_d->load(hModule)){
|
---|
| 1022 | //デバッグ情報が存在しないとき
|
---|
| 1023 | delete pobj_d;
|
---|
| 1024 | return 0;
|
---|
| 1025 | }
|
---|
| 1026 |
|
---|
| 1027 | ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
|
---|
| 1028 | ppobj_ds[num]=pobj_d;
|
---|
| 1029 | num++;
|
---|
| 1030 |
|
---|
| 1031 | return 1;
|
---|
| 1032 | }
|
---|
| 1033 |
|
---|
| 1034 | void CDBDebugSection::del(HMODULE hModule){
|
---|
| 1035 | int i;
|
---|
| 1036 | for(i=0;i<num;i++){
|
---|
| 1037 | if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
|
---|
| 1038 | delete ppobj_ds[i];
|
---|
| 1039 |
|
---|
| 1040 | num--;
|
---|
| 1041 | for(;i<num;i++){
|
---|
| 1042 | ppobj_ds[i]=ppobj_ds[i+1];
|
---|
| 1043 | }
|
---|
| 1044 | break;
|
---|
| 1045 | }
|
---|
| 1046 | }
|
---|
| 1047 | }
|
---|
| 1048 |
|
---|
| 1049 | void CDBDebugSection::choice(int index){
|
---|
| 1050 | pobj_now=ppobj_ds[index];
|
---|
| 1051 | pobj_now->choice();
|
---|
| 1052 | }
|
---|
| 1053 |
|
---|
| 1054 |
|
---|
| 1055 |
|
---|
| 1056 | CDBDebugSection *pobj_DBDebugSection;
|
---|