Difference between revisions of "Debug Stream"

From ROBOTC API Guide
Jump to: navigation, search
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| style="font-family:Verdana, Genega, sans-sarif; font-size:80%;color:gray;" width="100%" cellpadding="0%" cellspacing="0" border="0"
+
<yambe:breadcrumb self="Debug Stream">General|General Programming</yambe:breadcrumb>
|-
+
<br />
|
+
'''Dexter Industries''' has created a great introductory blog post on the debug stream, which can be [http://dexterindustries.com/howto/using-debugger-stream-in-robotc-for-lego found here].
''[[Main_Page|Main]] >> [[NXT_Main|NXT]] >> [[NXT: Functions| Functions]] >> [[Debug_Stream|Debug Stream]] ''
+
|-
+
|}
+
  
  
'''“Traditional” Debugging Techniques'''
+
{{tl|1|1}}
 +
<br />
  
Debugging a program – finding the errors and correcting them – can be a slow process in solutions without a run-time debugger. Without a debugger you may have to resort to different techniques like:
+
== “Traditional” Debugging Techniques ==
 +
{| class="wikiText"
 +
|-
 +
| Debugging a program – finding the errors and correcting them – can be a slow process in solutions without a run-time debugger. Without a debugger you may have to resort to different techniques such as:
  
 
*There’s no way to determine if your program is executing the intended logic. So you add code to play different tones/sounds to your program as it executes different “blocks” of code. You determine from the sound what is being executed within your program.
 
*There’s no way to determine if your program is executing the intended logic. So you add code to play different tones/sounds to your program as it executes different “blocks” of code. You determine from the sound what is being executed within your program.
 
*If your robot platform supports a display device (which could be a serial link to your PC or an LCD display on the robot) then you would have to add “print” statements to your program code at various points in your program. By examining the display, you can (hopefully) determine what’s happened in your program's execution by the display.
 
*If your robot platform supports a display device (which could be a serial link to your PC or an LCD display on the robot) then you would have to add “print” statements to your program code at various points in your program. By examining the display, you can (hopefully) determine what’s happened in your program's execution by the display.
Both of the above techniques are available in ROBOTC. However, a real-time debugger eliminates the need to resort to them. There’s no need to add code for debugging to your program. A built-in debugger provides better functionality without ever having to modify your source code!
+
Both of the above techniques are available in ROBOTC; however, a real-time debugger eliminates the need to resort to them. There’s no need to add code for debugging to your program. A built-in debugger provides better functionality without ever having to modify your source code!
  
 
There is also a built-in Debug Stream that you can use to keep track of your program from behind the scenes.  For example, you could print a message to the Debug Stream when you enter and exit loops, functions, etc.  Then you can view the cached Debug Stream to help in the debugging process.
 
There is also a built-in Debug Stream that you can use to keep track of your program from behind the scenes.  For example, you could print a message to the Debug Stream when you enter and exit loops, functions, etc.  Then you can view the cached Debug Stream to help in the debugging process.
  
<IMAGE HERE>
+
[[File:Debug_stream_3.png]]
----
+
|-
 
+
|}
  
 
== writeDebugStream ==
 
== writeDebugStream ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#E6E6E6; text-align:left; font-size:100%;"| '''void writeDebugStream(const string sFormatString, ...)'''
+
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">writeDebugStream</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const string </span><span class="bigCodeBasic">sFormatString</span><span class="bigCodePunc">, </span><span class="bigCodeBasic">...</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Writes a String to the Debug Stream.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Writes a String to the Debug Stream.
 
+
|-
 
+
|
   {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
   {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''sFormatString''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''sFormatString''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|A string to write to the debug stream (can be formatted!)
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|A string to write to the debug stream<br />(can be formatted!)
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_string|string]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 46: Line 49:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== writeDebugStreamLine ==
 
== writeDebugStreamLine ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#E6E6E6; text-align:left; font-size:100%;"| '''void writeDebugStreamLine(const string sFormatString, ...)'''
+
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">writeDebugStreamLine</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const string </span><span class="bigCodeBasic">sFormatString</span><span class="bigCodePunc">, </span><span class="bigCodeBasic">...</span><span class="bigCodePunc">)</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Writes a String to the Debug Stream starting on a new line.
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Writes a String to the Debug Stream starting on a new line.
+
|
 
+
  {| class="parameterTable" cellpadding="5%" width="100%"
 
+
   ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
   {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
  ! Explanation
+
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''sFormatString''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''sFormatString''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|A string to write to the debug stream (can be formatted!)
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|A string to write to the debug stream<br />(can be formatted!)
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_string|string]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 73: Line 78:
 
|-
 
|-
 
|}
 
|}
 +
<br />

Latest revision as of 16:53, 20 July 2012

General Programming → Debug Stream


Dexter Industries has created a great introductory blog post on the debug stream, which can be found here.


Color Key
Function:
Variable:


“Traditional” Debugging Techniques

Debugging a program – finding the errors and correcting them – can be a slow process in solutions without a run-time debugger. Without a debugger you may have to resort to different techniques such as:
  • There’s no way to determine if your program is executing the intended logic. So you add code to play different tones/sounds to your program as it executes different “blocks” of code. You determine from the sound what is being executed within your program.
  • If your robot platform supports a display device (which could be a serial link to your PC or an LCD display on the robot) then you would have to add “print” statements to your program code at various points in your program. By examining the display, you can (hopefully) determine what’s happened in your program's execution by the display.

Both of the above techniques are available in ROBOTC; however, a real-time debugger eliminates the need to resort to them. There’s no need to add code for debugging to your program. A built-in debugger provides better functionality without ever having to modify your source code!

There is also a built-in Debug Stream that you can use to keep track of your program from behind the scenes. For example, you could print a message to the Debug Stream when you enter and exit loops, functions, etc. Then you can view the cached Debug Stream to help in the debugging process.

Debug stream 3.png

writeDebugStream

void writeDebugStream(const string sFormatString, ...)
(void) Writes a String to the Debug Stream.
Parameter Explanation Data Type
sFormatString A string to write to the debug stream
(can be formatted!)
string
writeDebugStream("int x is: %d", x);  // writes the current value of int 'x' to the debug stream


writeDebugStreamLine

void writeDebugStreamLine(const string sFormatString, ...)
(void) Writes a String to the Debug Stream starting on a new line.
Parameter Explanation Data Type
sFormatString A string to write to the debug stream
(can be formatted!)
string
writeDebugStreamLine("int x is: %d", x);  // writes the current value of int 'x' to the debug stream on a new line.