source: trunk/ab5.0/ablib/src/system/debug.sbp @ 560

Last change on this file since 560 was 391, checked in by イグトランス (egtra), 15 years ago

FileStream非同期読み書きの修正、例外処理の追加。

File size: 3.1 KB
Line 
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
9Function _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
29End Function
30
31/*!
32@brief デバッグ用Set_LONG_PTR。
33削除すると、ABプログラムが正常にデバッグ実行できなくなる。
34*/
35Sub _DebugSys_Set_LONG_PTR(pPtr As VoidPtr, lpData As LONG_PTR)
36#ifdef _WIN64
37    SetQWord(pPtr,lpData)
38#else
39    SetDWord(pPtr,lpData)
40#endif
41End Sub
42
43Sub _DebugSys_StartProc(lpSpBase As ULONG_PTR, lpObp As ULONG_PTR)
44    Dim i As Long
45
46    Dim ThreadNum As Long
47    ThreadNum=_DebugSys_GetThread()
48    If ThreadNum=-1 Then Exit Sub
49
50    If _DebugSys_lplpObp[ThreadNum] Then
51        i=(_DebugSys_ProcNum[ThreadNum]+2)*SizeOf(ULONG_PTR)
52        _DebugSys_lplpObp[ThreadNum]=HeapReAlloc(GetProcessHeap(),0,_DebugSys_lplpObp[ThreadNum],i)
53        _DebugSys_lplpSpBase[ThreadNum]=HeapReAlloc(GetProcessHeap(),0,_DebugSys_lplpSpBase[ThreadNum],i)
54    Else
55        _DebugSys_ProcNum[ThreadNum]=0
56        _DebugSys_lplpObp[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
57        _DebugSys_lplpSpBase[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
58    End If
59    _DebugSys_Set_LONG_PTR(_DebugSys_lplpObp[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR),lpObp)
60    _DebugSys_Set_LONG_PTR(_DebugSys_lplpSpBase[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR),lpSpBase)
61
62    _DebugSys_ProcNum[ThreadNum]=_DebugSys_ProcNum[ThreadNum]+1
63End Sub
64
65Sub _DebugSys_EndProc()
66    Dim ThreadNum As Long
67    ThreadNum=_DebugSys_GetThread()
68    If ThreadNum=-1 Then Exit Sub
69
70    _DebugSys_ProcNum[ThreadNum]=_DebugSys_ProcNum[ThreadNum]-1
71End Sub
72
73Sub _DebugSys_SaveContext(lpSpBase As ULONG_PTR, lpObp As ULONG_PTR)
74    Dim ThreadNum As Long
75    ThreadNum=_DebugSys_GetThread()
76    If ThreadNum=-1 Then Exit Sub
77
78    If _DebugSys_lplpObp[ThreadNum]=0 Then
79        _DebugSys_ProcNum[ThreadNum]=0
80        _DebugSys_lplpObp[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
81        _DebugSys_lplpSpBase[ThreadNum]=HeapAlloc(GetProcessHeap(),0,SizeOf(ULONG_PTR)*2)
82    End If
83    _DebugSys_Set_LONG_PTR(_DebugSys_lplpObp[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR), lpObp)
84    _DebugSys_Set_LONG_PTR(_DebugSys_lplpSpBase[ThreadNum]+_DebugSys_ProcNum[ThreadNum]*SizeOf(ULONG_PTR), lpSpBase)
85End Sub
86
87Sub _esp_error()
88    MessageBox( NULL, "esp is wrong value.", "debug check error", MB_OK or MB_ICONEXCLAMATION )
89End Sub
90
91Sub _System_DebugOnly_OutputDebugString(buffer As *Char)
92#ifdef _DEBUG
93    OutputDebugString(buffer)
94#endif
95End Sub
Note: See TracBrowser for help on using the repository browser.