source: dev/branches/egtra/ab5.0/abdev/BasicCompiler_Common/CDebugThreadInfo.cpp@ 805

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

PSAPIを使用している箇所について、Toolhelp32と選択するよう修正

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