Cobra runs on top of .NET and Mono. Also it generates the same kinds of classes, methods and statements that C# and VB use, so you can leverage tools like debuggers and profilers.
Debugging programs include:
- DbgCLR.exe
- Mdbg.exe
- Cordbg.exe
This blog post gives some useful information on debugging .NET programs sans Visual Studio:
You might also use an IDE on your executable such as VisualStudio, MonoDevelop or SharpDevelop.
Using Mono's debugger can be seen in this Github project:
Sample debugging session using Mdbg
For this example, we're going to use Mdbg.exe which comes with the Windows SDK. To start debugging, make sure your Cobra sources are compiled with the -d switch:
cobra.exe -d -compile d.cobra
For this example, let's assume d.cobra contains this:
sig SampleMethod(b as int) as int class A def main is shared a as SampleMethod = do(b as int) if b > 20 return b+5 return b+6 print a(21) print a(10)
After the command finished, you have an exe created. Fire up Mdbg like this:
Mdbg.exe d.exe
You'll see output like this:
run d.exe STOP: Breakpoint Hit 4: def main is shared
To start stepping through code, write next ( n has the same effect ). You'll see the debugger advance:
[p#:0, t#:0] mdbg> next 5: a as SampleMethod = do(b as int)
Let's keep stepping until we reach the print a(21) line:
[p#:0, t#:0] mdbg> n 5: a as SampleMethod = do(b as int) [p#:0, t#:0] mdbg> n 9: print a(21)
If you want to step in that method and see what happens, press s. At any time, you can see the value of the variables by writing:
print variable_name
and that will write the value of variable_name. Similar, you can just type print and that will write the value of all the variables in that context.
If at any time you want to quit debugging, just write exit.
This example only covers the basics. For more information, search the web.
See also: DebuggingTopics