source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/CDebugThreadInfo.cpp@ 797

Last change on this file since 797 was 741, checked in by dai, 16 years ago

デバッグセクション情報周りをリファクタリング

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