| 15 | == Sample debugging session using Mdbg == |
| 16 | |
| 17 | For this example, we're gonna' use '''Mdbg.exe'''. To start debugging, make sure your Cobra sources are compiled with the '''-d''' switch: |
| 18 | |
| 19 | {{{ |
| 20 | cobra.exe -d -compile d.cobra |
| 21 | }}} |
| 22 | |
| 23 | For this example, let's assume '''d.cobra''' contains this: |
| 24 | |
| 25 | {{{ |
| 26 | #!python |
| 27 | sig SampleMethod(b as int) as int |
| 28 | |
| 29 | class 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 | |
| 39 | After the command finished, you have an exe created. Fire up Mdbg like this: |
| 40 | |
| 41 | {{{ |
| 42 | Mdbg.exe d.exe |
| 43 | }}} |
| 44 | |
| 45 | You'll see output like this: |
| 46 | |
| 47 | {{{ |
| 48 | run d.exe |
| 49 | STOP: Breakpoint Hit |
| 50 | 4: def main is shared |
| 51 | }}} |
| 52 | |
| 53 | To 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 |
| 57 | 5: a as SampleMethod = do(b as int) |
| 58 | }}} |
| 59 | |
| 60 | Let's keep stepping until we reach the {{{ print a(21) }}} line: |
| 61 | |
| 62 | {{{ |
| 63 | [p#:0, t#:0] mdbg> n |
| 64 | 5: a as SampleMethod = do(b as int) |
| 65 | [p#:0, t#:0] mdbg> n |
| 66 | 9: print a(21) |
| 67 | }}} |
| 68 | |
| 69 | 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: |
| 70 | {{{ |
| 71 | print variable_name |
| 72 | }}} |
| 73 | |
| 74 | 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. |
| 75 | |
| 76 | If at any time you want to quit debugging, just write '''exit'''. |
| 77 | |
| 78 | Even though this example only covers the basics, I hope it's enough to get you started. |
| 79 | |