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

Last change on this file since 686 was 636, checked in by dai_9181, 16 years ago

libファイルを跨ったテンプレート展開に対応。

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