source: dev/branches/x64_compiler_on_32/abdev/BasicCompiler_Common/CDebugThreadInfo.cpp@ 759

Last change on this file since 759 was 759, checked in by イグトランス (egtra), 16 years ago

マクロBUILD_X64_COMPILERの導入

File size: 3.2 KB
Line 
1#include "stdafx.h"
2
3#include "common.h"
4#include "DebugSection.h"
5
6
7//デバッグ用
8#include "../BasicCompiler_Common/debug.h"
9
10
11extern HANDLE hDebugProcess;
12extern DebugSectionCollection debugSectionCollection;
13
14CDebugThreadInfo *pobj_dti;
15
16CDebugThreadInfo::CDebugThreadInfo(){
17 memset(this,0,sizeof(CDebugThreadInfo));
18}
19CDebugThreadInfo::~CDebugThreadInfo(){
20 Free();
21}
22
23BOOL CDebugThreadInfo::Reflesh(int ThreadNum){
24#if defined _WIN64 || !defined BUILD_X64_COMPILER
25 Free();
26
27 ULONG_PTR lpData;
28 ULONG_PTR lpAccBytes;
29
30 DWORD dwRWSectionPos;
31 dwRWSectionPos=debugSectionCollection.debugSections[0]->dwImageBase+
32 debugSectionCollection.debugSections[0]->dwRVA_RWSection;
33
34 ReadProcessMemory(hDebugProcess,
35 (void *)(dwRWSectionPos+sizeof(DWORD)*256+ThreadNum*sizeof(DWORD)),
36 &iProcLevel,
37 sizeof(DWORD),&lpAccBytes);
38 lplpObp=(ULONG_PTR *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(ULONG_PTR));
39 lplpSpBase=(ULONG_PTR *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(ULONG_PTR));
40 lpdwCp=(DWORD *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(DWORD));
41 this->relationalObjectModuleIndexes.resize( iProcLevel + 1 );
42
43 //lplpObp
44 ReadProcessMemory(hDebugProcess,
45 (void *)(dwRWSectionPos+sizeof(DWORD)*256*2+ThreadNum*sizeof(DWORD)),
46 &lpData,
47 sizeof(ULONG_PTR),&lpAccBytes);
48 ReadProcessMemory(hDebugProcess,
49 (void *)lpData,
50 lplpObp,
51 (iProcLevel+1)*sizeof(ULONG_PTR),&lpAccBytes);
52
53 //lplpSpBase
54 ReadProcessMemory(hDebugProcess,
55 (void *)(dwRWSectionPos+sizeof(DWORD)*256*2+sizeof(ULONG_PTR)*256+ThreadNum*sizeof(ULONG_PTR)),
56 &lpData,
57 sizeof(ULONG_PTR),&lpAccBytes);
58 ReadProcessMemory(hDebugProcess,
59 (void *)lpData,
60 lplpSpBase,
61 (iProcLevel+1)*sizeof(ULONG_PTR),&lpAccBytes);
62
63 //現在の実行情報
64 CONTEXT Context;
65 Context.ContextFlags=CONTEXT_CONTROL;
66 GetThreadContext(array_hDebugThread[ThreadNum],&Context);
67
68
69 //マッピングされているモジュールのイメージベースを取得
70 HMODULE array_hModule[1024];
71 DWORD cbReturned;
72 if(!EnumProcessModules( hDebugProcess, array_hModule, sizeof(HMODULE)*1024, &cbReturned )) return 0;
73
74 int i;
75 HMODULE hTargetModule=0;
76 for(i=0;i<(int)(cbReturned/sizeof(HMODULE));i++){
77 if((LONG_PTR)array_hModule[i]<=(LONG_PTR)EIP_RIP(Context)){
78 if(hTargetModule<array_hModule[i]) hTargetModule=array_hModule[i];
79 }
80 }
81
82 extern DWORD ImageBase;
83 if((HMODULE)(ULONG_PTR)ImageBase!=hTargetModule){
84 for(i=0;i<debugSectionCollection.debugSections.size();i++){
85 if((HMODULE)(ULONG_PTR)debugSectionCollection.debugSections[i]->dwImageBase==hTargetModule){
86 debugSectionCollection.choice(i);
87 break;
88 }
89 }
90 }
91
92
93
94 extern int MemPos_CodeSection;
95 extern int FileSize_CodeSection;
96
97 if(ImageBase+MemPos_CodeSection <= EIP_RIP(Context) &&
98 EIP_RIP(Context) < ImageBase+MemPos_CodeSection+FileSize_CodeSection){
99 lplpObp[iProcLevel]=EIP_RIP(Context);
100 lplpSpBase[iProcLevel]=SP_BASE(Context);
101 }
102 //else API関数内などの場合は既存の lplpObp[iProcLevel] を利用する
103
104 return 1;
105#else
106 return 0;
107#endif
108}
109
110void CDebugThreadInfo::Free(void){
111 if(lplpObp){
112 HeapDefaultFree(lplpObp);
113 HeapDefaultFree(lplpSpBase);
114 HeapDefaultFree(lpdwCp);
115 relationalObjectModuleIndexes.clear();
116 }
117
118 memset(this,0,sizeof(CDebugThreadInfo));
119}
Note: See TracBrowser for help on using the repository browser.