debugger_mt.stdio.bmx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. Strict
  2. NoDebug
  3. Private
  4. ?Win32
  5. Extern "Win32"
  6. Const SW_SHOW=5
  7. Const SW_RESTORE=9
  8. Function IsIconic( hwnd )
  9. Function GetForegroundWindow()
  10. Function SetForegroundWindow( hwnd )
  11. Function ShowWindow( hwnd,cmdShow )
  12. Function GetCurrentThreadId()
  13. End Extern
  14. ?
  15. ?MacOS
  16. Extern
  17. Function CGDisplayIsCaptured( displayId )
  18. End Extern
  19. ?
  20. Extern
  21. Global bbStringClass:Byte
  22. Global bbArrayClass:Byte
  23. Global bbNullObject:Byte
  24. Global bbEmptyArray:Byte
  25. Global bbEmptyString:Byte
  26. Global brl_blitz_NullFunctionError:Byte Ptr
  27. Function bbIsMainThread()="bbIsMainThread"
  28. Function bbGCValidate:Int( mem:Int ) = "bbGCValidate"
  29. End Extern
  30. Function ToHex$( val )
  31. Local buf:Short[8]
  32. For Local k=7 To 0 Step -1
  33. Local n=(val&15)+Asc("0")
  34. If n>Asc("9") n=n+(Asc("A")-Asc("9")-1)
  35. buf[k]=n
  36. val:Shr 4
  37. Next
  38. Return String.FromShorts( buf,8 ).ToLower()
  39. End Function
  40. Function IsAlpha( ch )
  41. Return (ch>=Asc("a") And ch<=Asc("z")) Or (ch>=Asc("A") And ch<=Asc("Z"))
  42. End Function
  43. Function IsNumeric( ch )
  44. Return ch>=Asc("0") And ch<=Asc("9")
  45. End Function
  46. Function IsAlphaNumeric( ch )
  47. Return IsAlpha(ch) Or IsNumeric(ch)
  48. End Function
  49. Function IsUnderscore( ch )
  50. Return ch=Asc("_")
  51. End Function
  52. Function Ident$( tag$ Var )
  53. If Not tag Return ""
  54. If Not IsAlpha( tag[0] ) And Not IsUnderscore( tag[0] ) Return ""
  55. Local i=1
  56. While i<tag.length And (IsAlphaNumeric(tag[i]) Or IsUnderscore(tag[i]))
  57. i:+1
  58. Wend
  59. Local id$=tag[..i]
  60. tag=tag[i..]
  61. Return id
  62. End Function
  63. Function TypeName$( tag$ Var )
  64. Local t$=tag[..1]
  65. tag=tag[1..]
  66. Select t
  67. Case "b"
  68. Return "Byte"
  69. Case "s"
  70. Return "Short"
  71. Case "i"
  72. Return "Int"
  73. Case "l"
  74. Return "Long"
  75. Case "f"
  76. Return "Float"
  77. Case "d"
  78. Return "Double"
  79. Case "$"
  80. Return "String"
  81. Case "z"
  82. Return "CString"
  83. Case "w"
  84. Return "WString"
  85. Case ":","?"
  86. Local id$=Ident( tag )
  87. While tag And tag[0]=Asc(".")
  88. tag=tag[1..]
  89. id=Ident( tag )
  90. Wend
  91. If Not id DebugError "Invalid object typetag"
  92. Return id
  93. Case "*"
  94. Return TypeName( tag )+" Ptr"
  95. Case "["
  96. While tag[..1]=","
  97. tag=tag[1..]
  98. t:+","
  99. Wend
  100. If tag[..1]<>"]" DebugError "Invalid array typetag"
  101. tag=tag[1..]
  102. Return TypeName( tag )+t+"]"
  103. Case "("
  104. If tag[..1]<>")"
  105. t:+TypeName( tag )
  106. While tag[..1]=","
  107. tag=tag[1..]
  108. t:+","+TypeName( tag )
  109. Wend
  110. If tag[..1]<>")" DebugError "Invalid function typetag"
  111. EndIf
  112. tag=tag[1..]
  113. Return TypeName( tag )+t+")"
  114. End Select
  115. DebugError "Invalid debug typetag:"+t
  116. End Function
  117. 'int offsets into 12 byte DebugStm struct
  118. Const DEBUGSTM_FILE=0
  119. Const DEBUGSTM_LINE=1
  120. Const DEBUGSTM_CHAR=2
  121. 'int offsets into 16 byte DebugDecl struct
  122. Const DEBUGDECL_KIND=0
  123. Const DEBUGDECL_NAME=1
  124. Const DEBUGDECL_TYPE=2
  125. Const DEBUGDECL_ADDR=3
  126. 'DEBUGDECL_KIND values
  127. Const DEBUGDECLKIND_END=0
  128. Const DEBUGDECLKIND_CONST=1
  129. Const DEBUGDECLKIND_LOCAL=2
  130. Const DEBUGDECLKIND_FIELD=3
  131. Const DEBUGDECLKIND_GLOBAL=4
  132. Const DEBUGDECLKIND_VARPARAM=5
  133. Const DEBUGDECLKIND_TYPEMETHOD=6
  134. Const DEBUGDECLKIND_TYPEFUNCTION=7
  135. 'int offsets into 12+n_decls*4 byte DebugScope struct
  136. Const DEBUGSCOPE_KIND=0
  137. Const DEBUGSCOPE_NAME=1
  138. Const DEBUGSCOPE_DECLS=2
  139. 'DEBUGSCOPE_KIND values
  140. Const DEBUGSCOPEKIND_FUNCTION=1
  141. Const DEBUGSCOPEKIND_TYPE=2
  142. Const DEBUGSCOPEKIND_LOCAL=3
  143. Function DebugError( t$ )
  144. WriteStderr "Debugger Error:"+t+"~n"
  145. End
  146. End Function
  147. Function DebugStmFile$( stm:Int Ptr )
  148. Return String.FromCString( Byte Ptr stm[DEBUGSTM_FILE] )
  149. End Function
  150. Function DebugStmLine( stm:Int Ptr )
  151. Return stm[DEBUGSTM_LINE]
  152. End Function
  153. Function DebugStmChar( stm:Int Ptr )
  154. Return stm[DEBUGSTM_CHAR]
  155. End Function
  156. Function DebugDeclKind$( decl:Int Ptr )
  157. Select decl[DEBUGDECL_KIND]
  158. Case DEBUGDECLKIND_CONST Return "Const"
  159. Case DEBUGDECLKIND_LOCAL Return "Local"
  160. Case DEBUGDECLKIND_FIELD Return "Field"
  161. Case DEBUGDECLKIND_GLOBAL Return "Global"
  162. Case DEBUGDECLKIND_VARPARAM Return "Local"
  163. End Select
  164. DebugError "Invalid decl kind"
  165. End Function
  166. Function DebugDeclName$( decl:Int Ptr )
  167. Return String.FromCString( Byte Ptr decl[DEBUGDECL_NAME] )
  168. End Function
  169. Function DebugDeclType$( decl:Int Ptr )
  170. Local t$=String.FromCString( Byte Ptr decl[DEBUGDECL_TYPE] )
  171. Local ty$=TypeName( t )
  172. Return ty
  173. End Function
  174. Function DebugDeclSize( decl:Int Ptr )
  175. Local tag=(Byte Ptr Ptr(decl+DEBUGDECL_TYPE))[0][0]
  176. Select tag
  177. Case Asc("b") Return 1
  178. Case Asc("s") Return 2
  179. Case Asc("l") Return 8
  180. Case Asc("d") Return 8
  181. End Select
  182. Return 4
  183. End Function
  184. Function DebugEscapeString$( s$ )
  185. If s.length>4096 s=s[..4096]
  186. s=s.Replace( "~~","~~~~")
  187. s=s.Replace( "~0","~~0" )
  188. s=s.Replace( "~t","~~t" )
  189. s=s.Replace( "~n","~~n" )
  190. s=s.Replace( "~r","~~r" )
  191. s=s.Replace( "~q","~~q" )
  192. Return "~q"+s+"~q"
  193. End Function
  194. Function DebugDeclValue$( decl:Int Ptr,inst:Byte Ptr )
  195. If decl[DEBUGDECL_KIND]=DEBUGDECLKIND_CONST
  196. Local p:Byte Ptr=Byte Ptr decl[DEBUGDECL_ADDR]
  197. Return DebugEscapeString(String.FromShorts( Short Ptr(p+12),(Int Ptr (p+8))[0] ))
  198. EndIf
  199. Local p:Byte Ptr
  200. Select decl[DEBUGDECL_KIND]
  201. Case DEBUGDECLKIND_GLOBAL
  202. p=Byte Ptr decl[DEBUGDECL_ADDR]
  203. Case DEBUGDECLKIND_LOCAL,DEBUGDECLKIND_FIELD
  204. p=Byte Ptr (inst+decl[DEBUGDECL_ADDR])
  205. Case DEBUGDECLKIND_VARPARAM
  206. p=Byte Ptr (inst+decl[DEBUGDECL_ADDR])
  207. p=Byte Ptr ( (Int Ptr p)[0] )
  208. Default
  209. DebugError "Invalid decl kind"
  210. End Select
  211. Local tag=(Byte Ptr Ptr(decl+DEBUGDECL_TYPE))[0][0]
  212. Select tag
  213. Case Asc("b")
  214. Return String.FromInt( (Byte Ptr p)[0] )
  215. Case Asc("s")
  216. Return String.FromInt( (Short Ptr p)[0] )
  217. Case Asc("i")
  218. Return String.FromInt( (Int Ptr p)[0] )
  219. Case Asc("l")
  220. Return String.FromLong( (Long Ptr p)[0] )
  221. Case Asc("f")
  222. Return String.FromFloat( (Float Ptr p)[0] )
  223. Case Asc("d")
  224. Return String.FromDouble( (Double Ptr p)[0] )
  225. Case Asc("$")
  226. p=(Byte Ptr Ptr p)[0]
  227. Local sz=Int Ptr(p+8)[0]
  228. Local s$=String.FromShorts( Short Ptr(p+12),sz )
  229. Return DebugEscapeString( s )
  230. Case Asc("z")
  231. p=(Byte Ptr Ptr p)[0]
  232. If Not p Return "Null"
  233. Local s$=String.FromCString( p )
  234. Return DebugEscapeString( s )
  235. Case Asc("w")
  236. p=(Byte Ptr Ptr p)[0]
  237. If Not p Return "Null"
  238. Local s$=String.FromWString( Short Ptr p )
  239. Return DebugEscapeString( s )
  240. Case Asc("*"),Asc("?")
  241. Return "$"+ToHex( (Int Ptr p)[0] )
  242. Case Asc("(")
  243. p=(Byte Ptr Ptr p)[0]
  244. If p=brl_blitz_NullFunctionError Return "Null"
  245. Case Asc(":")
  246. p=(Byte Ptr Ptr p)[0]
  247. If p=Varptr bbNullObject Return "Null"
  248. If p=Varptr bbEmptyArray Return "Null[]"
  249. If p=Varptr bbEmptyString Return "Null$"
  250. Case Asc("[")
  251. p=(Byte Ptr Ptr p)[0]
  252. If Not p Return "Null"
  253. If Not (Int Ptr (p+20))[0] Return "Null"
  254. Default
  255. DebugError "Invalid decl typetag:"+Chr(tag)
  256. End Select
  257. Return "$"+ToHex( Int p )
  258. End Function
  259. Function DebugScopeKind$( scope:Int Ptr )
  260. Select scope[DEBUGSCOPE_KIND]
  261. Case DEBUGSCOPEKIND_FUNCTION Return "Function"
  262. Case DEBUGSCOPEKIND_TYPE Return "Type"
  263. Case DEBUGSCOPEKIND_LOCAL Return "Local"
  264. End Select
  265. DebugError "Invalid scope kind"
  266. End Function
  267. Function DebugScopeName$( scope:Int Ptr )
  268. Return String.FromCString( Byte Ptr scope[DEBUGSCOPE_NAME] )
  269. End Function
  270. Function DebugScopeDecls:Int Ptr[]( scope:Int Ptr )
  271. Local n,p:Int Ptr=scope+DEBUGSCOPE_DECLS
  272. While p[n]<>DEBUGDECLKIND_END
  273. n:+1
  274. Wend
  275. Local decls:Int Ptr[n]
  276. For Local i=0 Until n
  277. decls[i]=p+i*4
  278. Next
  279. Return decls
  280. End Function
  281. Function DebugObjectScope:Int Ptr( inst:Byte Ptr )
  282. Local clas:Int Ptr Ptr=(Int Ptr Ptr Ptr inst)[0]
  283. Return clas[2]
  284. End Function
  285. Extern
  286. Global bbOnDebugStop()
  287. Global bbOnDebugLog( message$ )
  288. Global bbOnDebugEnterStm( stm:Int Ptr )
  289. Global bbOnDebugEnterScope( scope:Int Ptr,inst:Byte Ptr )
  290. Global bbOnDebugLeaveScope()
  291. Global bbOnDebugPushExState()
  292. Global bbOnDebugPopExState()
  293. Global bbOnDebugUnhandledEx( ex:Object )
  294. End Extern
  295. bbOnDebugStop=OnDebugStop
  296. bbOnDebugLog=OnDebugLog
  297. bbOnDebugEnterStm=OnDebugEnterStm
  298. bbOnDebugEnterScope=OnDebugEnterScope
  299. bbOnDebugLeaveScope=OnDebugLeaveScope
  300. bbOnDebugPushExState=OnDebugPushExState
  301. bbOnDebugPopExState=OnDebugPopExState
  302. bbOnDebugUnhandledEx=OnDebugUnhandledEx
  303. ?Win32
  304. Global _ideHwnd=GetForegroundWindow();
  305. Global _appHwnd
  306. ?
  307. '********** Debugger code here **********
  308. Const MODE_RUN=0
  309. Const MODE_STEP=1
  310. Const MODE_STEPIN=2
  311. Const MODE_STEPOUT=3
  312. Type TScope
  313. Field scope:Int Ptr,inst:Byte Ptr,stm:Int Ptr
  314. End Type
  315. Type TExState
  316. Field scopeStackTop
  317. End Type
  318. Type TDbgState
  319. Field mode,debugLevel,funcLevel
  320. Field currentScope:TScope=New TScope
  321. Field scopeStack:TScope[],scopeStackTop
  322. Field exStateStack:TExState[],exStateStackTop
  323. End Type
  324. ?Threaded
  325. Extern
  326. Function bbThreadAllocData()
  327. Function bbThreadSetData( index,data:Object )
  328. Function bbThreadGetData:TDbgState( index )
  329. End Extern
  330. ?
  331. Function GetDbgState:TDbgState()
  332. Global dbgStateMain:TDbgState=New TDbgState
  333. ?Threaded
  334. If bbIsMainThread() Return dbgStateMain
  335. Global dbgStateId:Int=bbThreadAllocData()
  336. Local dbgState:TDbgState=bbThreadGetData( dbgStateId )
  337. If Not dbgState
  338. dbgState = New TDbgState
  339. bbThreadSetData( dbgStateId,dbgState )
  340. End If
  341. Return dbgState
  342. ?Not Threaded
  343. Return dbgStateMain
  344. ?
  345. End Function
  346. Function ReadDebug$()
  347. Return ReadStdin()
  348. End Function
  349. Function WriteDebug( t$ )
  350. WriteStderr "~~>"+t
  351. End Function
  352. Function DumpScope( scope:Int Ptr,inst:Byte Ptr )
  353. Local decl:Int Ptr=scope+DEBUGSCOPE_DECLS
  354. Local kind$=DebugScopeKind( scope ),name$=DebugScopeName( scope )
  355. If Not name name="<local>"
  356. WriteDebug kind+" "+name+"~n"
  357. While decl[DEBUGDECL_KIND]<>DEBUGDECLKIND_END
  358. Select decl[DEBUGDECL_KIND]
  359. Case DEBUGDECLKIND_TYPEMETHOD,DEBUGDECLKIND_TYPEFUNCTION
  360. decl:+4
  361. Continue
  362. End Select
  363. Local kind$=DebugDeclKind( decl )
  364. Local name$=DebugDeclname( decl )
  365. Local tipe$=DebugDeclType( decl )
  366. Local value$=DebugDeclValue( decl,inst )
  367. WriteDebug kind+" "+name+":"+tipe+"="+value+"~n"
  368. decl:+4
  369. Wend
  370. End Function
  371. Function DumpClassScope( clas:Int Ptr,inst:Byte Ptr )
  372. Local supa:Int Ptr=Int Ptr clas[0]
  373. If Not supa Return
  374. DumpClassScope supa,inst
  375. DumpScope Int Ptr clas[2],inst
  376. End Function
  377. Function DumpObject( inst:Byte Ptr,index )
  378. Local clas:Int Ptr=(Int Ptr Ptr inst)[0]
  379. If clas=Int Ptr Varptr bbStringClass
  380. WriteDebug DebugEscapeString(String.FromShorts( Short Ptr(inst+12),(Int Ptr (inst+8))[0] ))+"~n"
  381. Return
  382. Else If clas=Int Ptr Varptr bbArrayClass
  383. Local length=(Int Ptr (inst+20))[0]
  384. If Not length Return
  385. Local decl:Int[3]
  386. decl[0]=DEBUGDECLKIND_LOCAL
  387. decl[2]=(Int Ptr (inst+8))[0]
  388. Local sz=DebugDeclSize( decl )
  389. Local p:Byte Ptr=Byte Ptr(20+(Int Ptr (inst+12))[0]*4)
  390. For Local i=1 To 10
  391. If index>=length Exit
  392. decl[3]=Int(p+index*sz)
  393. Local value$=DebugDeclValue( decl,inst )
  394. WriteDebug "["+index+"]="+value+"~n"
  395. index:+1
  396. Next
  397. If index<length
  398. WriteDebug "...=$"+ToHex(Int inst)+":"+index+"~n"
  399. EndIf
  400. Else
  401. If Not clas[0]
  402. WriteDebug "Object~n"
  403. Return
  404. EndIf
  405. DumpClassScope clas,inst
  406. EndIf
  407. End Function
  408. Function DumpScopeStack()
  409. Local dbgState:TDbgState = GetDbgState()
  410. For Local i=Max(dbgState.scopeStackTop-100,0) Until dbgState.scopeStackTop
  411. Local t:TScope=dbgState.scopeStack[i]
  412. Local stm:Int Ptr=t.stm
  413. If Not stm Continue
  414. WriteDebug "@"+DebugStmFile(stm)+"<"+DebugStmLine(stm)+","+DebugStmChar(stm)+">~n"
  415. DumpScope t.scope,t.inst
  416. Next
  417. End Function
  418. Function UpdateDebug( msg$ )
  419. Global indebug
  420. If indebug Return
  421. indebug=True
  422. Local dbgState:TDbgState = GetDbgState()
  423. ?Win32
  424. _appHwnd=GetForegroundWindow();
  425. 'SetForegroundWindow( _ideHwnd );
  426. ?
  427. ?MacOs
  428. 'fullscreen debug too hard in MacOS!
  429. If CGDisplayIsCaptured( 0 )
  430. WriteStdout msg
  431. End
  432. EndIf
  433. ?
  434. WriteDebug msg
  435. Repeat
  436. WriteDebug "~n"
  437. Local line$=ReadDebug()
  438. Select line[..1].ToLower()
  439. Case "r"
  440. dbgState.mode=MODE_RUN
  441. Exit
  442. Case "s"
  443. dbgState.mode=MODE_STEP
  444. dbgState.debugLevel=dbgState.funcLevel
  445. Exit
  446. Case "e"
  447. dbgState.mode=MODE_STEPIN
  448. Exit
  449. Case "l"
  450. dbgState.mode=MODE_STEPOUT
  451. dbgState.debugLevel=dbgState.scopeStackTop-1
  452. Exit
  453. Case "t"
  454. WriteDebug "StackTrace{~n"
  455. DumpScopeStack
  456. WriteDebug "}~n"
  457. Case "d"
  458. Local t$=line[1..].Trim()
  459. Local index
  460. Local i=t.Find(":")
  461. If i<>-1
  462. index=Int( t[i+1..] )
  463. t=t[..i]
  464. EndIf
  465. If t[..1]="$" t=t[1..].Trim()
  466. If t[..2].ToLower()="0x" t=t[2..].Trim()
  467. Local pointer = Int( "$"+t )
  468. If Not (pointer And bbGCValidate(pointer)) Then Continue
  469. Local inst:Int Ptr=Int Ptr pointer
  470. Local cmd$="ObjectDump@"+ToHex( Int inst )
  471. If i<>-1 cmd:+":"+index
  472. WriteDebug cmd$+"{~n"
  473. DumpObject inst,index
  474. WriteDebug "}~n"
  475. Case "h"
  476. WriteDebug "T - Stack trace~n"
  477. WriteDebug "R - Run from here~n"
  478. WriteDebug "S - Step through source code~n"
  479. WriteDebug "E - Step into function call~n"
  480. WriteDebug "L - Leave function or local block~n"
  481. WriteDebug "Q - Quit~n"
  482. WriteDebug "H - This text~n"
  483. WriteDebug "Dxxxxxxxx - Dump object at hex address xxxxxxxx~n"
  484. Case "q"
  485. End
  486. End Select
  487. Forever
  488. ?Win32
  489. If _appHwnd And _appHwnd<>_ideHwnd
  490. If IsIconic(_apphwnd)
  491. ShowWindow _appHwnd,SW_RESTORE
  492. Else
  493. ShowWindow _appHwnd,SW_SHOW
  494. EndIf
  495. _apphwnd=0
  496. EndIf
  497. ?
  498. indebug=False
  499. End Function
  500. Function OnDebugStop()
  501. UpdateDebug "DebugStop:~n"
  502. End Function
  503. Function OnDebugLog( message$ )
  504. WriteStdout "DebugLog:"+message+"~n"
  505. End Function
  506. Function OnDebugEnterStm( stm:Int Ptr )
  507. Local dbgState:TDbgState = GetDbgState()
  508. dbgState.currentScope.stm=stm
  509. Select dbgState.mode
  510. Case MODE_RUN
  511. Return
  512. Case MODE_STEP
  513. If dbgState.funcLevel>dbgState.debugLevel
  514. Return
  515. EndIf
  516. Case MODE_STEPOUT
  517. If dbgState.scopeStackTop>dbgState.debugLevel
  518. Return
  519. EndIf
  520. End Select
  521. UpdateDebug "Debug:~n"
  522. End Function
  523. Function OnDebugEnterScope( scope:Int Ptr,inst:Byte Ptr )
  524. Local dbgState:TDbgState = GetDbgState()
  525. GCSuspend
  526. If dbgState.scopeStackTop=dbgState.scopeStack.length
  527. dbgState.scopeStack=dbgState.scopeStack[..dbgState.scopeStackTop * 2 + 32]
  528. For Local i=dbgState.scopeStackTop Until dbgState.scopeStack.length
  529. dbgState.scopeStack[i]=New TScope
  530. Next
  531. EndIf
  532. dbgState.currentScope=dbgState.scopeStack[dbgState.scopeStackTop]
  533. dbgState.currentScope.scope=scope
  534. dbgState.currentScope.inst=inst
  535. dbgState.scopeStackTop:+1
  536. If dbgState.currentScope.scope[DEBUGSCOPE_KIND]=DEBUGSCOPEKIND_FUNCTION dbgState.funcLevel:+1
  537. GCResume
  538. End Function
  539. Function OnDebugLeaveScope()
  540. Local dbgState:TDbgState = GetDbgState()
  541. GCSuspend
  542. If Not dbgState.scopeStackTop DebugError "scope stack underflow"
  543. If dbgState.currentScope.scope[DEBUGSCOPE_KIND]=DEBUGSCOPEKIND_FUNCTION dbgState.funcLevel:-1
  544. dbgState.scopeStackTop:-1
  545. If dbgState.scopeStackTop
  546. dbgState.currentScope=dbgState.scopeStack[dbgState.scopeStackTop-1]
  547. Else
  548. dbgState.currentScope=New TScope
  549. EndIf
  550. GCResume
  551. End Function
  552. Function OnDebugPushExState()
  553. Local dbgState:TDbgState = GetDbgState()
  554. GCSuspend
  555. If dbgState.exStateStackTop=dbgState.exStateStack.length
  556. dbgState.exStateStack=dbgState.exStateStack[..dbgState.exStateStackTop * 2 + 32]
  557. For Local i=dbgState.exStateStackTop Until dbgState.exStateStack.length
  558. dbgState.exStateStack[i]=New TExState
  559. Next
  560. EndIf
  561. dbgState.exStateStack[dbgState.exStateStackTop].scopeStackTop=dbgState.scopeStackTop
  562. dbgState.exStateStackTop:+1
  563. GCResume
  564. End Function
  565. Function OnDebugPopExState()
  566. Local dbgState:TDbgState = GetDbgState()
  567. GCSuspend
  568. If Not dbgState.exStateStackTop DebugError "exception stack underflow"
  569. dbgState.exStateStackTop:-1
  570. dbgState.scopeStackTop=dbgState.exStateStack[dbgState.exStateStackTop].scopeStackTop
  571. If dbgState.scopeStackTop
  572. dbgState.currentScope=dbgState.scopeStack[dbgState.scopeStackTop-1]
  573. Else
  574. dbgState.currentScope=New TScope
  575. EndIf
  576. GCResume
  577. End Function
  578. Function OnDebugUnhandledEx( ex:Object )
  579. GCSuspend
  580. UpdateDebug "Unhandled Exception:"+ex.ToString()+"~n"
  581. GCResume
  582. End Function