source: dev/trunk/abdev/BasicCompiler_Common/CDebugThreadInfo.cpp@ 250

Last change on this file since 250 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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