Wiki

Changes between Version 1 and Version 2 of DebuggingSansVisualStudio

Show
Ignore:
Timestamp:
05/07/10 06:38:52 (15 years ago)
Author:
Gameday
Comment:

added an example on how to use Mdbg

Legend:

Unmodified
Added
Removed
Modified
  • DebuggingSansVisualStudio

    v1 v2  
    1313You might also [wiki:DebuggingWithAnIDE use an IDE] on your executable such as VisualStudio, MonoDevelop or SharpDevelop. 
    1414 
     15== Sample debugging session using Mdbg == 
     16 
     17For this example, we're gonna' use '''Mdbg.exe'''. To start debugging, make sure your Cobra sources are compiled with the '''-d''' switch: 
     18 
     19{{{ 
     20cobra.exe -d -compile d.cobra 
     21}}} 
     22 
     23For this example, let's assume '''d.cobra''' contains this: 
     24 
     25{{{ 
     26#!python 
     27sig SampleMethod(b as int) as int 
     28 
     29class A 
     30        def main is shared 
     31                a as SampleMethod = do(b as int) 
     32                        if b > 20 
     33                                return b+5 
     34                        return b+6 
     35                print a(21) 
     36                print a(10) 
     37}}} 
     38 
     39After the command finished, you have an exe created. Fire up Mdbg like this: 
     40 
     41{{{ 
     42Mdbg.exe d.exe 
     43}}} 
     44 
     45You'll see output like this: 
     46 
     47{{{ 
     48run d.exe 
     49STOP: Breakpoint Hit 
     504:      def main is shared 
     51}}} 
     52 
     53To start stepping through code, write '''next''' ( '''n''' has the same effect ). You'll see the debugger advance: 
     54 
     55{{{ 
     56[p#:0, t#:0] mdbg> next 
     575:              a as SampleMethod = do(b as int) 
     58}}} 
     59 
     60Let's keep stepping until we reach the {{{ print a(21) }}} line: 
     61 
     62{{{ 
     63[p#:0, t#:0] mdbg> n 
     645:              a as SampleMethod = do(b as int) 
     65[p#:0, t#:0] mdbg> n 
     669:              print a(21) 
     67}}} 
     68 
     69If 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: 
     70{{{ 
     71print variable_name 
     72}}} 
     73 
     74and 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.  
     75 
     76If at any time you want to quit debugging, just write '''exit'''.  
     77 
     78Even though this example only covers the basics, I hope it's enough to get you started. 
     79 
    1580See also: DebuggingTopics