SlideShare a Scribd company logo
Ring Documentation, Release 1.5.2
Function Name : mytest
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 12
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
Message from mytest
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 14
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Return
Line Number : 8
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 9
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 43
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
65.24. Example - Using the Trace Functions 725
Ring Documentation, Release 1.5.2
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Function
Line Number : 9
File Name : test1.ring
Function Name : mymethod
Method or Function : Method
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 44
File Name : test1.ring
Function Name : mymethod
Method or Function : Method
==========================================
Message from mymethod
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Return
Line Number : 9
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
65.24. Example - Using the Trace Functions 726
Ring Documentation, Release 1.5.2
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 11
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
65.25 Example - The Trace Library
The next example uses the Trace functions provided by the Ring language to create the Trace library.
Using the Trace library we have nice Tracing tools and Interaction debugger too.
# Trace Events
TRACEEVENT_NEWLINE = 1
TRACEEVENT_NEWFUNC = 2
TRACEEVENT_RETURN = 3
TRACEEVENT_ERROR = 4
TRACEEVENT_BEFORECFUNC = 5
TRACEEVENT_AFTERCFUNC = 6
# Trace Data
TRACEDATA_LINENUMBER = 1
TRACEDATA_FILENAME = 2
TRACEDATA_FUNCNAME = 3
TRACEDATA_METHODORFUNC = 4
# Method of Function
TRACEDATA_METHODORFUNC_METHOD = TRUE
TRACEDATA_METHODORFUNC_NOTMETHOD = FALSE
TRACE_BREAKPOINTS = TRUE
TRACE_TEMPLIST = []
func Trace cType
switch trim(lower(cType))
on :AllEvents
ringvm_settrace("TraceLib_AllEvents()")
on :Functions
ringvm_settrace("TraceLib_Functions()")
on :PassError
ringvm_settrace("TraceLib_PassError()")
on :Debugger
ringvm_settrace("TraceLib_Debugger()")
on :LineByLine
ringvm_settrace("TraceLib_LineByLine()")
off
func TraceLib_AllEvents
if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring"
return
ok
see "====== The Trace function is Active ======" + nl +
65.25. Example - The Trace Library 727
Ring Documentation, Release 1.5.2
"Trace Function Name : " + ringvm_TraceFunc() + nl +
"Trace Event : "
switch ringvm_TraceEvent()
on TRACEEVENT_NEWLINE see "New Line"
on TRACEEVENT_NEWFUNC see "New Function"
on TRACEEVENT_RETURN see "Return"
on TRACEEVENT_ERROR see "Error"
on TRACEEVENT_BEFORECFUNC see "Before C Function"
on TRACEEVENT_AFTERCFUNC see "After C Function"
off
see nl +
"Line Number : " + ringvm_tracedata()[TRACEDATA_LINENUMBER] + nl +
"File Name : " + ringvm_tracedata()[TRACEDATA_FILENAME] + nl +
"Function Name : " + ringvm_tracedata()[TRACEDATA_FUNCNAME] + nl +
"Method or Function : "
if ringvm_tracedata()[TRACEDATA_METHODORFUNC] =
TRACEDATA_METHODORFUNC_METHOD
see "Method"
else
if ringvm_tracedata()[TRACEDATA_FUNCNAME] = NULL
see "Command"
else
see "Function"
ok
ok
see nl + Copy("=",42) + nl
func TraceLib_Functions
if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring"
return
ok
switch ringvm_TraceEvent()
on TRACEEVENT_NEWFUNC
see "Open Func : " +
ringvm_TraceData()[TRACEDATA_FUNCNAME] + nl
on TRACEEVENT_RETURN
see "Return to Func : " +
ringvm_TraceData()[TRACEDATA_FUNCNAME] + nl
off
func TraceLib_PassError
if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring"
return
ok
switch ringvm_TraceEvent()
on TRACEEVENT_ERROR
see nl
see "TraceLib : After Error !" + nl
ringvm_passerror()
off
func TraceLib_Debugger
if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring"
return
ok
switch ringvm_TraceEvent()
on TRACEEVENT_ERROR
_BreakPoint()
65.25. Example - The Trace Library 728
Ring Documentation, Release 1.5.2
off
func TraceLib_LineByLine
if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring" or
ringvm_TraceEvent() != TRACEEVENT_NEWLINE
return
ok
aList = ringvm_tracedata()
see "Before Line : " + aList[TRACEDATA_LINENUMBER] + nl
_BreakPoint()
func BreakPoint
if not TRACE_BREAKPOINTS
return
ok
_BreakPoint()
func _BreakPoint
see nl+nl+Copy("=",60) + nl +
Copy(" ",20)+"Interactive Debugger" + nl +
Copy("=",60) + nl +
"Command (Exit) : End Program" + nl +
"Command (Cont) : Continue Execution" + nl +
"Command (Locals) : Print local variables names" + nl +
"Command (LocalsData) : Print local variables data" + nl +
"Command (Globals) : Print global variables names" + nl +
"We can execute Ring code" + nl +
Copy("=",60) + nl
while true
see nl + "code:> "
give cCode
cmd = trim(lower(cCode))
if cmd = "exit" or cmd = "bye"
shutdown()
ok
nScope = ringvm_scopescount()-2
switch cmd
on "locals"
ringvm_EvalInScope(nScope,"see locals() callgc()")
loop
on "localsdata"
PrintLocalsData(nScope)
loop
on "globals"
ringvm_EvalInScope(nScope,"see globals() callgc()")
loop
on "cont"
ringvm_passerror()
exit
off
Try
ringvm_EvalInScope(nScope,cCode)
catch
see cCatchError
done
end
func NoBreakPoints
65.25. Example - The Trace Library 729
Ring Documentation, Release 1.5.2
TRACE_BREAKPOINTS = FALSE
func PrintLocalsData nScope
if nScope = 1 # Global
ringvm_Evalinscope(nScope,'TRACE_TEMPLIST = globals()')
else
ringvm_Evalinscope(nScope,'TRACE_TEMPLIST = locals() callgc()')
ok
see nl
aTempList = TRACE_TEMPLIST
TRACE_TEMPLIST = []
nSpaces = 5
for TRACE_ITEM in aTempList
if len(TRACE_ITEM) + 5 > nSpaces
nSpaces = len(TRACE_ITEM) + 5
ok
next
for TRACE_ITEM in aTempList
see "Variable : " + TRACE_ITEM
cVarName = TRACE_ITEM
see copy(" ",nSpaces-len(cVarName)) + " Type : "
ringvm_Evalinscope(nScope,"see type(" + TRACE_ITEM +")")
ringvm_Evalinscope(nScope,"see Copy(' ',fabs(15-len(type(" +
TRACE_ITEM +"))))")
see " Value : "
ringvm_Evalinscope(nScope,"see " + TRACE_ITEM)
see nl
next
65.25. Example - The Trace Library 730
CHAPTER
SIXTYSIX
THE TRACE LIBRARY AND THE INTERACTIVE DEBUGGER
In this chapter we will learn about the Trace Library and the Interactive Debugger
66.1 Loading the Trace library
To start using the Trace library, We must load it first!
load "tracelib.ring"
66.2 Trace All Events
The next example demonstrates the Trace library usage to trace all events.
# Trace All Events
trace(:AllEvents)
see "Hello, world!" + nl
see "Welcome" + nl
see "How are you?" +nl
mytest()
new myclass { mymethod() }
func mytest
see "Message from mytest" + nl
class myclass
func mymethod
see "Message from mymethod" + nl
66.3 Trace control flow between functions
The next example demonstrates the Trace library usage to trace the control flow between functions.
Trace(:Functions)
test1()
731
Ring Documentation, Release 1.5.2
func test1
see :test1 + nl
test2()
func test2
see :test2 + nl
see test3() + nl
func test3
see :test3 + nl
return "test 3 output"
66.4 Pass Error
The next example demonstrates the Trace library usage to pass an error!
Trace(:PassError)
test1()
func test1
x = 10
see :test1 + nl
test2() # Runtime Error!
see "We can continue!"
66.5 Interactive Debugger
The next example demonstrates the Trace library usage to use the Interactive Debugger
Trace(:Debugger)
test1()
see "good bye!" + nl
func test1
x = 10
see :test1 + nl
t = 12
test2() # Runtime Error!
see "After Error!" +nl
see "t = " see t see nl
see "x = " see x see nl
66.6 Execute Program Line by Line
The next example demonstrates the Trace library usage to execute the program line by line!
Trace(:LineByLine)
test1()
66.4. Pass Error 732
Ring Documentation, Release 1.5.2
func test1
x = 10
see :test1 + nl
t = 12
test2()
see "After Error!" +nl
see "t = " + t + nl
66.7 BreakPoint
The next example demonstrates the Trace library usage to stop at a breakpoint!
test1()
func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
66.8 Disable BreakPoints
The next example demonstrates the Trace library usage and how to disable the Breakpoints!
NoBreakPoints()
test1()
func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
66.9 Using the Interactive Debugger
The next example uses a Breakpoint to open the Interactive Debugger!
load "tracelib.ring"
test1()
func test1
x = 10
see :test1 + nl
t = 12
66.7. BreakPoint 733
Ring Documentation, Release 1.5.2
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
Screen Shots:
We have the Interactive Debugger at the Breakpoint!
We can print the variables values
We can change the variables values then continue execution
66.9. Using the Interactive Debugger 734

More Related Content

PDF
The Ring programming language version 1.5.4 book - Part 79 of 185
PDF
The Ring programming language version 1.6 book - Part 82 of 189
PDF
The Ring programming language version 1.7 book - Part 84 of 196
PDF
The Ring programming language version 1.5.1 book - Part 75 of 180
PDF
The Ring programming language version 1.10 book - Part 94 of 212
PDF
The Ring programming language version 1.10 book - Part 17 of 212
PDF
The Ring programming language version 1.7 book - Part 12 of 196
PDF
The Ring programming language version 1.9 book - Part 91 of 210
The Ring programming language version 1.5.4 book - Part 79 of 185
The Ring programming language version 1.6 book - Part 82 of 189
The Ring programming language version 1.7 book - Part 84 of 196
The Ring programming language version 1.5.1 book - Part 75 of 180
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.9 book - Part 91 of 210

What's hot (20)

PDF
The Ring programming language version 1.5.3 book - Part 88 of 184
DOCX
Ejemplo radio
PDF
The Ring programming language version 1.9 book - Part 92 of 210
PPTX
Java practice programs for beginners
PDF
Java 7 LavaJUG
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
PDF
Java Performance Puzzlers
PDF
JVM Mechanics: Understanding the JIT's Tricks
PDF
JVM Mechanics
PDF
Dagger & rxjava & retrofit
PDF
The Ring programming language version 1.5.1 book - Part 12 of 180
PDF
The Ring programming language version 1.5.4 book - Part 78 of 185
PDF
Software Testing - Invited Lecture at UNSW Sydney
PDF
Construire une application JavaFX 8 avec gradle
PDF
DCN Practical
PDF
Concurrency Concepts in Java
PDF
#JavaFX.forReal() - ElsassJUG
DOCX
Registro de venta
PDF
Core java pract_sem iii
PDF
Advanced Java Practical File
The Ring programming language version 1.5.3 book - Part 88 of 184
Ejemplo radio
The Ring programming language version 1.9 book - Part 92 of 210
Java practice programs for beginners
Java 7 LavaJUG
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java Performance Puzzlers
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics
Dagger & rxjava & retrofit
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.4 book - Part 78 of 185
Software Testing - Invited Lecture at UNSW Sydney
Construire une application JavaFX 8 avec gradle
DCN Practical
Concurrency Concepts in Java
#JavaFX.forReal() - ElsassJUG
Registro de venta
Core java pract_sem iii
Advanced Java Practical File
Ad

Similar to The Ring programming language version 1.5.2 book - Part 76 of 181 (20)

PDF
The Ring programming language version 1.8 book - Part 87 of 202
PDF
The Ring programming language version 1.6 book - Part 11 of 189
PDF
The Ring programming language version 1.5.3 book - Part 89 of 184
PDF
The Ring programming language version 1.10 book - Part 93 of 212
PDF
The Ring programming language version 1.5.2 book - Part 9 of 181
PDF
The Ring programming language version 1.5.2 book - Part 75 of 181
PDF
The Ring programming language version 1.8 book - Part 88 of 202
PDF
The Ring programming language version 1.7 book - Part 85 of 196
PDF
The Ring programming language version 1.6 book - Part 81 of 189
PDF
The Ring programming language version 1.5.1 book - Part 74 of 180
PDF
The Ring programming language version 1.8 book - Part 13 of 202
PDF
The Ring programming language version 1.9 book - Part 15 of 210
PDF
The Ring programming language version 1.9 book - Part 11 of 210
PDF
The Ring programming language version 1.9 book - Part 40 of 210
PDF
Interruption Timer Périodique
PDF
The Ring programming language version 1.5.1 book - Part 73 of 180
PDF
The Ring programming language version 1.8 book - Part 9 of 202
PDF
The Ring programming language version 1.6 book - Part 34 of 189
PDF
The Ring programming language version 1.9 book - Part 88 of 210
PDF
The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.8 book - Part 87 of 202
The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.10 book - Part 93 of 212
The Ring programming language version 1.5.2 book - Part 9 of 181
The Ring programming language version 1.5.2 book - Part 75 of 181
The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.8 book - Part 13 of 202
The Ring programming language version 1.9 book - Part 15 of 210
The Ring programming language version 1.9 book - Part 11 of 210
The Ring programming language version 1.9 book - Part 40 of 210
Interruption Timer Périodique
The Ring programming language version 1.5.1 book - Part 73 of 180
The Ring programming language version 1.8 book - Part 9 of 202
The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.9 book - Part 88 of 210
The Ring programming language version 1.5.1 book - Part 9 of 180
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PDF
creating-agentic-ai-solutions-leveraging-aws.pdf
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PPTX
How to Build Crypto Derivative Exchanges from Scratch.pptx
PDF
How AI Agents Improve Data Accuracy and Consistency in Due Diligence.pdf
PDF
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Event Presentation Google Cloud Next Extended 2025
NewMind AI Monthly Chronicles - July 2025
creating-agentic-ai-solutions-leveraging-aws.pdf
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Smarter Business Operations Powered by IoT Remote Monitoring
NewMind AI Weekly Chronicles - August'25 Week I
GamePlan Trading System Review: Professional Trader's Honest Take
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Sensors and Actuators in IoT Systems using pdf
Enable Enterprise-Ready Security on IBM i Systems.pdf
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
How to Build Crypto Derivative Exchanges from Scratch.pptx
How AI Agents Improve Data Accuracy and Consistency in Due Diligence.pdf
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
Reimagining Insurance: Connected Data for Confident Decisions.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
madgavkar20181017ppt McKinsey Presentation.pdf
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Event Presentation Google Cloud Next Extended 2025

The Ring programming language version 1.5.2 book - Part 76 of 181

  • 1. Ring Documentation, Release 1.5.2 Function Name : mytest Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 12 File Name : test1.ring Function Name : mytest Method or Function : Function ========================================== Message from mytest ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 14 File Name : test1.ring Function Name : mytest Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : Return Line Number : 8 File Name : test1.ring Function Name : Method or Function : Command ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 9 File Name : test1.ring Function Name : Method or Function : Command ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 43 File Name : test1.ring Function Name : Method or Function : Command ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : Before C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : After C Function Line Number : 9 File Name : test1.ring Function Name : ismethod 65.24. Example - Using the Trace Functions 725
  • 2. Ring Documentation, Release 1.5.2 Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Function Line Number : 9 File Name : test1.ring Function Name : mymethod Method or Function : Method ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 44 File Name : test1.ring Function Name : mymethod Method or Function : Method ========================================== Message from mymethod ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : Return Line Number : 9 File Name : test1.ring Function Name : Method or Function : Command ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : Before C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : After C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : Before C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : After C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function 65.24. Example - Using the Trace Functions 726
  • 3. Ring Documentation, Release 1.5.2 ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 11 File Name : test1.ring Function Name : Method or Function : Command ========================================== 65.25 Example - The Trace Library The next example uses the Trace functions provided by the Ring language to create the Trace library. Using the Trace library we have nice Tracing tools and Interaction debugger too. # Trace Events TRACEEVENT_NEWLINE = 1 TRACEEVENT_NEWFUNC = 2 TRACEEVENT_RETURN = 3 TRACEEVENT_ERROR = 4 TRACEEVENT_BEFORECFUNC = 5 TRACEEVENT_AFTERCFUNC = 6 # Trace Data TRACEDATA_LINENUMBER = 1 TRACEDATA_FILENAME = 2 TRACEDATA_FUNCNAME = 3 TRACEDATA_METHODORFUNC = 4 # Method of Function TRACEDATA_METHODORFUNC_METHOD = TRUE TRACEDATA_METHODORFUNC_NOTMETHOD = FALSE TRACE_BREAKPOINTS = TRUE TRACE_TEMPLIST = [] func Trace cType switch trim(lower(cType)) on :AllEvents ringvm_settrace("TraceLib_AllEvents()") on :Functions ringvm_settrace("TraceLib_Functions()") on :PassError ringvm_settrace("TraceLib_PassError()") on :Debugger ringvm_settrace("TraceLib_Debugger()") on :LineByLine ringvm_settrace("TraceLib_LineByLine()") off func TraceLib_AllEvents if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring" return ok see "====== The Trace function is Active ======" + nl + 65.25. Example - The Trace Library 727
  • 4. Ring Documentation, Release 1.5.2 "Trace Function Name : " + ringvm_TraceFunc() + nl + "Trace Event : " switch ringvm_TraceEvent() on TRACEEVENT_NEWLINE see "New Line" on TRACEEVENT_NEWFUNC see "New Function" on TRACEEVENT_RETURN see "Return" on TRACEEVENT_ERROR see "Error" on TRACEEVENT_BEFORECFUNC see "Before C Function" on TRACEEVENT_AFTERCFUNC see "After C Function" off see nl + "Line Number : " + ringvm_tracedata()[TRACEDATA_LINENUMBER] + nl + "File Name : " + ringvm_tracedata()[TRACEDATA_FILENAME] + nl + "Function Name : " + ringvm_tracedata()[TRACEDATA_FUNCNAME] + nl + "Method or Function : " if ringvm_tracedata()[TRACEDATA_METHODORFUNC] = TRACEDATA_METHODORFUNC_METHOD see "Method" else if ringvm_tracedata()[TRACEDATA_FUNCNAME] = NULL see "Command" else see "Function" ok ok see nl + Copy("=",42) + nl func TraceLib_Functions if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring" return ok switch ringvm_TraceEvent() on TRACEEVENT_NEWFUNC see "Open Func : " + ringvm_TraceData()[TRACEDATA_FUNCNAME] + nl on TRACEEVENT_RETURN see "Return to Func : " + ringvm_TraceData()[TRACEDATA_FUNCNAME] + nl off func TraceLib_PassError if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring" return ok switch ringvm_TraceEvent() on TRACEEVENT_ERROR see nl see "TraceLib : After Error !" + nl ringvm_passerror() off func TraceLib_Debugger if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring" return ok switch ringvm_TraceEvent() on TRACEEVENT_ERROR _BreakPoint() 65.25. Example - The Trace Library 728
  • 5. Ring Documentation, Release 1.5.2 off func TraceLib_LineByLine if right(ringvm_tracedata()[TRACEDATA_FILENAME],13) = "tracelib.ring" or ringvm_TraceEvent() != TRACEEVENT_NEWLINE return ok aList = ringvm_tracedata() see "Before Line : " + aList[TRACEDATA_LINENUMBER] + nl _BreakPoint() func BreakPoint if not TRACE_BREAKPOINTS return ok _BreakPoint() func _BreakPoint see nl+nl+Copy("=",60) + nl + Copy(" ",20)+"Interactive Debugger" + nl + Copy("=",60) + nl + "Command (Exit) : End Program" + nl + "Command (Cont) : Continue Execution" + nl + "Command (Locals) : Print local variables names" + nl + "Command (LocalsData) : Print local variables data" + nl + "Command (Globals) : Print global variables names" + nl + "We can execute Ring code" + nl + Copy("=",60) + nl while true see nl + "code:> " give cCode cmd = trim(lower(cCode)) if cmd = "exit" or cmd = "bye" shutdown() ok nScope = ringvm_scopescount()-2 switch cmd on "locals" ringvm_EvalInScope(nScope,"see locals() callgc()") loop on "localsdata" PrintLocalsData(nScope) loop on "globals" ringvm_EvalInScope(nScope,"see globals() callgc()") loop on "cont" ringvm_passerror() exit off Try ringvm_EvalInScope(nScope,cCode) catch see cCatchError done end func NoBreakPoints 65.25. Example - The Trace Library 729
  • 6. Ring Documentation, Release 1.5.2 TRACE_BREAKPOINTS = FALSE func PrintLocalsData nScope if nScope = 1 # Global ringvm_Evalinscope(nScope,'TRACE_TEMPLIST = globals()') else ringvm_Evalinscope(nScope,'TRACE_TEMPLIST = locals() callgc()') ok see nl aTempList = TRACE_TEMPLIST TRACE_TEMPLIST = [] nSpaces = 5 for TRACE_ITEM in aTempList if len(TRACE_ITEM) + 5 > nSpaces nSpaces = len(TRACE_ITEM) + 5 ok next for TRACE_ITEM in aTempList see "Variable : " + TRACE_ITEM cVarName = TRACE_ITEM see copy(" ",nSpaces-len(cVarName)) + " Type : " ringvm_Evalinscope(nScope,"see type(" + TRACE_ITEM +")") ringvm_Evalinscope(nScope,"see Copy(' ',fabs(15-len(type(" + TRACE_ITEM +"))))") see " Value : " ringvm_Evalinscope(nScope,"see " + TRACE_ITEM) see nl next 65.25. Example - The Trace Library 730
  • 7. CHAPTER SIXTYSIX THE TRACE LIBRARY AND THE INTERACTIVE DEBUGGER In this chapter we will learn about the Trace Library and the Interactive Debugger 66.1 Loading the Trace library To start using the Trace library, We must load it first! load "tracelib.ring" 66.2 Trace All Events The next example demonstrates the Trace library usage to trace all events. # Trace All Events trace(:AllEvents) see "Hello, world!" + nl see "Welcome" + nl see "How are you?" +nl mytest() new myclass { mymethod() } func mytest see "Message from mytest" + nl class myclass func mymethod see "Message from mymethod" + nl 66.3 Trace control flow between functions The next example demonstrates the Trace library usage to trace the control flow between functions. Trace(:Functions) test1() 731
  • 8. Ring Documentation, Release 1.5.2 func test1 see :test1 + nl test2() func test2 see :test2 + nl see test3() + nl func test3 see :test3 + nl return "test 3 output" 66.4 Pass Error The next example demonstrates the Trace library usage to pass an error! Trace(:PassError) test1() func test1 x = 10 see :test1 + nl test2() # Runtime Error! see "We can continue!" 66.5 Interactive Debugger The next example demonstrates the Trace library usage to use the Interactive Debugger Trace(:Debugger) test1() see "good bye!" + nl func test1 x = 10 see :test1 + nl t = 12 test2() # Runtime Error! see "After Error!" +nl see "t = " see t see nl see "x = " see x see nl 66.6 Execute Program Line by Line The next example demonstrates the Trace library usage to execute the program line by line! Trace(:LineByLine) test1() 66.4. Pass Error 732
  • 9. Ring Documentation, Release 1.5.2 func test1 x = 10 see :test1 + nl t = 12 test2() see "After Error!" +nl see "t = " + t + nl 66.7 BreakPoint The next example demonstrates the Trace library usage to stop at a breakpoint! test1() func test1 x = 10 see :test1 + nl t = 12 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl 66.8 Disable BreakPoints The next example demonstrates the Trace library usage and how to disable the Breakpoints! NoBreakPoints() test1() func test1 x = 10 see :test1 + nl t = 12 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl 66.9 Using the Interactive Debugger The next example uses a Breakpoint to open the Interactive Debugger! load "tracelib.ring" test1() func test1 x = 10 see :test1 + nl t = 12 66.7. BreakPoint 733
  • 10. Ring Documentation, Release 1.5.2 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl Screen Shots: We have the Interactive Debugger at the Breakpoint! We can print the variables values We can change the variables values then continue execution 66.9. Using the Interactive Debugger 734