1 | 'debug.sbp
|
---|
2 | 'このファイル内のコードはデバッグ コンパイル時のみ有効です(リリース コンパイルでは無視されます)。
|
---|
3 |
|
---|
4 | 'Dim _DebugSys_dwThreadID[255] As DWord - コンパイラが自動的に定義します
|
---|
5 | 'Dim _DebugSys_ProcNum[255] As DWord - コンパイラが自動的に定義します
|
---|
6 | 'Dim _DebugSys_lplpObp[255] As *ULONG_PTR - コンパイラが自動的に定義します
|
---|
7 | 'Dim _DebugSys_lplpSpBase[255] As *ULONG_PTR - コンパイラが自動的に定義します
|
---|
8 |
|
---|
9 | Function _DebugSys_GetThread() As Long
|
---|
10 | Dim dwThreadID As DWord
|
---|
11 | Dim ThreadNum As Long
|
---|
12 |
|
---|
13 | dwThreadID=GetCurrentThreadId()
|
---|
14 | ThreadNum=0
|
---|
15 | Do
|
---|
16 | If dwThreadID=_DebugSys_dwThreadID[ThreadNum] Then Exit Do
|
---|
17 | ThreadNum=ThreadNum+1
|
---|
18 | If ThreadNum>255 Then
|
---|
19 | ThreadNum=-1
|
---|
20 | Exit Do
|
---|
21 |
|
---|
22 | /*debug
|
---|
23 | OutputDebugString(Ex"[GetThread]デバッグ情報が異常です。プロセスを終了します。\r\n")
|
---|
24 | ExitProcess(0)*/
|
---|
25 | End If
|
---|
26 | Loop
|
---|
27 |
|
---|
28 | _DebugSys_GetThread=ThreadNum
|
---|
29 | End Function
|
---|
30 |
|
---|
31 | Sub _DebugSys_StartProc(lpSpBase As ULONG_PTR, lpObp As ULONG_PTR)
|
---|
32 | Dim i As Long
|
---|
33 |
|
---|
34 | Dim ThreadNum As Long
|
---|
35 | ThreadNum=_DebugSys_GetThread()
|
---|
36 | If ThreadNum=-1 Then Exit Sub
|
---|
37 |
|
---|
38 | If _DebugSys_lplpObp[ThreadNum] Then
|
---|
39 | i=(_DebugSys_ProcNum[ThreadNum]+2)*SizeOf(ULONG_PTR)
|
---|
40 | _DebugSys_lplpObp[ThreadNum]=HeapReAlloc(GetProcessHeap(),0,_DebugSys_lplpObp[ThreadNum],i)
|
---|
41 | _DebugSys_lplpSpBase[ThreadNum]=HeapReAlloc(GetProcessHeap(),0,_DebugSys_lplpSpBase[ThreadNum],i)
|
---|
42 | Else
|
---|
43 | _DebugSys_ProcNum[ThreadNum]=0
|
---|
44 | _DebugSys_lplpObp[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
|
---|
45 | _DebugSys_lplpSpBase[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
|
---|
46 | End If
|
---|
47 | Set_LONG_PTR(_DebugSys_lplpObp[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR),lpObp)
|
---|
48 | Set_LONG_PTR(_DebugSys_lplpSpBase[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR),lpSpBase)
|
---|
49 |
|
---|
50 | _DebugSys_ProcNum[ThreadNum]=_DebugSys_ProcNum[ThreadNum]+1
|
---|
51 | End Sub
|
---|
52 |
|
---|
53 | Sub _DebugSys_EndProc()
|
---|
54 | Dim ThreadNum As Long
|
---|
55 | ThreadNum=_DebugSys_GetThread()
|
---|
56 | If ThreadNum=-1 Then Exit Sub
|
---|
57 |
|
---|
58 | _DebugSys_ProcNum[ThreadNum]=_DebugSys_ProcNum[ThreadNum]-1
|
---|
59 | End Sub
|
---|
60 |
|
---|
61 | Sub _DebugSys_SaveContext(lpSpBase As ULONG_PTR, lpObp As ULONG_PTR)
|
---|
62 | Dim ThreadNum As Long
|
---|
63 | ThreadNum=_DebugSys_GetThread()
|
---|
64 | If ThreadNum=-1 Then Exit Sub
|
---|
65 |
|
---|
66 | If _DebugSys_lplpObp[ThreadNum]=0 Then
|
---|
67 | _DebugSys_ProcNum[ThreadNum]=0
|
---|
68 | _DebugSys_lplpObp[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
|
---|
69 | _DebugSys_lplpSpBase[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
|
---|
70 | End If
|
---|
71 | Set_LONG_PTR(_DebugSys_lplpObp[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR), lpObp)
|
---|
72 | Set_LONG_PTR(_DebugSys_lplpSpBase[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR), lpSpBase)
|
---|
73 | End Sub
|
---|
74 |
|
---|
75 | Sub _esp_error()
|
---|
76 | MessageBox( NULL, "esp is wrong value.", "debug check error", MB_OK or MB_ICONEXCLAMATION )
|
---|
77 | End Sub
|
---|
78 |
|
---|
79 | Sub _System_DebugOnly_OutputDebugString(buffer As *Char)
|
---|
80 | #ifdef _DEBUG
|
---|
81 | OutputDebugString(buffer)
|
---|
82 | #endif
|
---|
83 | End Sub
|
---|