source: dev/BasicCompiler_Common/CDebugThreadInfo.cpp@ 4

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