|
1 | 1 | # ChatScript Debugger Manual
|
2 |
| - |
3 |
| -> © Bruce Wilcox, [email protected] brilligunderstanding.com |
4 |
| -
|
5 |
| - |
6 |
| -> Revision 1/7/2017 cs7.1 |
| 2 | +© Bruce Wilcox, mailto:[email protected] www.brilligunderstanding.com |
| 3 | +<br>Revision 1/7/2017 cs7.1 |
7 | 4 |
|
8 | 5 | # Debugging in and out
|
9 | 6 |
|
10 | 7 | While it is possible to connect ChatScript to a GUI IDE for debugging (if you create one because CS does not come with one natively),
|
11 | 8 | CS also has a text command debugger analogous to GDB in LINUX.
|
12 | 9 |
|
13 |
| -You enter the debugger via ```:debug``` |
| 10 | +You enter the debugger via |
| 11 | + |
| 12 | + :debug |
| 13 | + |
14 | 14 | which begins a local command loop. Resume normal execution via
|
15 |
| -```go``` or ```g```. |
| 15 | + |
| 16 | + go |
| 17 | + |
| 18 | +or |
| 19 | + |
| 20 | + g |
16 | 21 |
|
17 | 22 | The debug command can also have one of the debug commands after it, e.g.
|
18 |
| -``` |
19 |
| -:debug break ^fn1 ~topic1 ^fn2 |
20 |
| -``` |
21 | 23 |
|
22 |
| -# Variable and JSON displays |
| 24 | + :debug break ^fn1 ~topic1 ^fn2 |
| 25 | + |
| 26 | +## Variable and JSON displays |
23 | 27 |
|
24 | 28 | While in the debugger, you can display $variables just by typing in their name(s).
|
25 |
| -``` |
26 |
| -$myvar $_yourvar |
27 |
| -``` |
| 29 | + |
| 30 | + $myvar $_yourvar |
28 | 31 |
|
29 | 32 | If you know the name of a JSON unit, you can just type that and get a display of the array or object.
|
30 |
| -``` |
31 |
| -jo-44 |
32 |
| -``` |
33 | 33 |
|
34 |
| -# Source locations |
| 34 | + jo-44 |
| 35 | + |
| 36 | + |
| 37 | +## Source locations |
| 38 | + |
35 | 39 | Typing the name of a function or topic will tell you the file and line number of it.
|
36 | 40 |
|
37 |
| -# Breakpoints |
| 41 | +## Breakpoints |
38 | 42 |
|
39 | 43 | You can set breakpoints that will trigger the debugger on a variety of conditions. And you can
|
40 | 44 | name multiple conditions at once. E.g.,
|
41 |
| -``` |
42 |
| -break ^myfunction ~mytopic ~mytopic.myrule |
43 |
| -``` |
44 | 45 |
|
45 |
| -##Function breakpoints## |
| 46 | + break ^myfunction ~mytopic ~mytopic.myrule |
| 47 | + |
| 48 | + |
| 49 | +## Function breakpoints |
46 | 50 |
|
47 | 51 | A function breakpoint will, by default, break on entry and break on exit. On entry it shows the
|
48 | 52 | function and its arguments. On exit it shows the value being returned and any error status.
|
49 | 53 |
|
50 | 54 | You can restrict a function to only breaking on entry or exit by suffixing the name with @i or
|
51 |
| -@o. Like ```break ^myfunc@i``` |
| 55 | +@o. Like |
| 56 | + |
| 57 | + break ^myfunc@i |
52 | 58 |
|
53 |
| -You can delete a breakpoint by putting ```!``` in front of the base name. E.g. |
54 |
| -``` |
55 |
| -break ^myfunc !^otherfunc |
56 |
| -``` |
| 59 | +You can delete a breakpoint by putting `!` in front of the base name. E.g. |
| 60 | + |
| 61 | + break ^myfunc !^otherfunc |
57 | 62 |
|
58 | 63 | Every time you call break, it prints out a summary of the breakpoints still set. So if you
|
59 | 64 | call break with no names, it just lists what you have.
|
60 | 65 |
|
61 |
| -##Topic breakpoints## |
| 66 | +## Topic breakpoints |
| 67 | + |
| 68 | +A topic breakpoint will break on entry and exit of topic by whatever manner (normal, `^gambit`, `^rejoinder`, |
| 69 | +`^reuse`, etc). |
| 70 | + |
62 | 71 |
|
63 |
| -A topic breakpoint will break on entry and exit of topic by whatever manner (normal, ```^gambit```, ```^rejoinder```, |
64 |
| -```^reuse```, etc). |
| 72 | +## Rule breakpoints |
65 | 73 |
|
66 |
| -##Rule breakpoints## |
67 |
| -A rule can broken upon by doing `break ~mytopic.label` where label is either the label of a rule |
68 |
| -or its tag (e.g., `1.0` for the 2nd top level rule of the topic). |
| 74 | +A rule can broken upon by doing |
69 | 75 |
|
70 |
| -##Abnormal breakpoints## |
| 76 | + break ~mytopic.label |
| 77 | + |
| 78 | +where label is either the label of a rule or its tag (e.g., `1.0` for the 2nd top level rule of the topic). |
71 | 79 |
|
72 |
| -You can name ```abort``` to request a breakpoint if the system is about to exit due to abnormal conditions. |
73 | 80 |
|
74 |
| -# Variable Assigns |
| 81 | +## Abnormal breakpoints |
| 82 | + |
| 83 | +You can name |
| 84 | + |
| 85 | + abort |
| 86 | + |
| 87 | +to request a breakpoint if the system is about to exit due to abnormal conditions. |
| 88 | + |
| 89 | + |
| 90 | +## Variable Assigns |
75 | 91 |
|
76 | 92 | A different kind of breakpoint is a variable assign, that is, when a variable has its value changed.
|
77 | 93 | You can list multiple variables in a single request.
|
78 |
| -``` |
79 |
| -= $myvar $_hisvar |
80 |
| -``` |
| 94 | + |
| 95 | + = $myvar $_hisvar |
81 | 96 |
|
82 | 97 | The breakpoint will tell you the new value it is taking on. Be aware that if you break on a local variable like
|
83 |
| -```$_myvar``` then you break on the next change to it in whatever topic or function it is within. You may, if you want, |
84 |
| -create a restricted breakpoint for $_vars like this: ```^myfunc.$_myvar``` or ```~mytopic.$_myvar```. |
| 98 | +`$_myvar` then you break on the next change to it in whatever topic or function it is within. You may, if you want, |
| 99 | +create a restricted breakpoint for $_vars like this: |
85 | 100 |
|
86 |
| -# Clearing Breakpoints |
87 |
| -```clear``` will remove all breakpoints including variable assigns. |
| 101 | + ^myfunc.$_myvar |
| 102 | + |
| 103 | +or |
88 | 104 |
|
89 |
| -# Backtrace |
| 105 | + ~mytopic.$_myvar |
90 | 106 |
|
91 |
| -```where``` will print out a backtrace of where you are in terms of topics, rules, and functions. |
92 | 107 |
|
93 |
| -# Controlled execution |
| 108 | +## Clearing Breakpoints |
94 | 109 |
|
95 |
| -You can step from action to action in your code by typing ```s``` or ```step```. Which is |
96 |
| -equivalent to `step across`. This will execute the |
97 |
| -next thing at the current level (maybe a function call, rule test, assignment or whatever). It will then |
| 110 | + clear |
| 111 | + |
| 112 | +will remove all breakpoints including variable assigns. |
| 113 | + |
| 114 | +## Backtrace |
| 115 | + |
| 116 | + where |
| 117 | + |
| 118 | +will print out a backtrace of where you are in terms of topics, rules, and functions. |
| 119 | + |
| 120 | +## Controlled execution |
| 121 | + |
| 122 | +You can step from action to action in your code by typing |
| 123 | + |
| 124 | + s |
| 125 | + |
| 126 | +or |
| 127 | + |
| 128 | + step |
| 129 | + |
| 130 | +Which is equivalent to `step across`. This will execute the next thing at the current level |
| 131 | +(maybe a function call, rule test, assignment or whatever). It will then |
98 | 132 | display what code it executed, what value was returned, and what code would be executed next.
|
99 | 133 |
|
100 |
| -When you are at |
101 |
| -a rule, ```s``` moves to the next rule. Alternatively, you can ask the system to execute rules |
102 |
| -in a topic until it comes to one that would match by saying ```step match```. It will stop before |
103 |
| -entering the output of the rule or until it leaves the topic. |
| 134 | +When you are at a rule, `s` moves to the next rule. Alternatively, you can ask the system to execute rules |
| 135 | +in a topic until it comes to one that would match by saying |
| 136 | + |
| 137 | + step match |
| 138 | + |
| 139 | +It will stop before entering the output of the rule or until it leaves the topic. |
104 | 140 |
|
105 | 141 | If you discover that the executed code called a function that did something wrong and you want to
|
106 |
| -watch it, you can type ```redo in```, which will retry that same piece of code, but this time |
107 |
| -going in instead of stepping over. |
| 142 | +watch it, you can type |
| 143 | + |
| 144 | + redo in |
108 | 145 |
|
109 |
| -You can step out from a function or topic by typing ```out```, which will execute code until it |
110 |
| -leaves the current function or topic or rule. ** topic is confusing when you have rules. |
111 |
| -If stepping out returns to code which has nothing left to do, that code will also complete and |
112 |
| -the system will pop out to the next level. |
| 146 | +which will retry that same piece of code, but this time going in instead of stepping over. |
113 | 147 |
|
114 |
| -You can step in from an action in your code by typing ```in```. This will execute one or more |
115 |
| -bits of code until it calls into some function or exits the current scope entirely. |
| 148 | +You can step out from a function or topic by typing |
116 | 149 |
|
117 |
| -# Executing script and other debug commands |
| 150 | + out |
| 151 | + |
| 152 | +which will execute code until it leaves the current function or topic or rule. |
| 153 | +topic is confusing when you have rules. |
| 154 | +If stepping out returns to code which has nothing left to do, |
| 155 | +that code will also complete and the system will pop out to the next level. |
118 | 156 |
|
119 |
| -You can type in a ```do``` command, which is analogous to ```:do```, which allows you to set |
120 |
| -variables, execute script functions, etc. |
| 157 | +You can step in from an action in your code by typing |
121 | 158 |
|
122 |
| -# Sourcing a file of debug commands |
| 159 | + in |
123 | 160 |
|
124 |
| -The ```source filename ``` command will take debugger input from the named file (with a .txt suffix |
125 |
| -added to the name) where the file is in a top level folder called ```debug```. Any command that |
126 |
| -resumes execution (like ```go```, ```in```, ```out```, ```s```) will terminate reading from the file. |
| 161 | +This will execute one or more bits of code until it calls into some function or exits the current scope entirely. |
| 162 | + |
| 163 | +## Executing script and other debug commands |
| 164 | + |
| 165 | +You can type in a |
| 166 | + |
| 167 | + do |
| 168 | + |
| 169 | +command, which is analogous to `:do`, which allows you to set variables, execute script functions, etc. |
| 170 | + |
| 171 | + |
| 172 | +## Sourcing a file of debug commands |
| 173 | + |
| 174 | +The command |
| 175 | + |
| 176 | + source filename |
| 177 | + |
| 178 | +will take debugger input from the named file (with a .txt suffix added to the name) |
| 179 | +where the file is in a top level folder called `debug`. Any command that |
| 180 | +resumes execution (like `go`, `in`, `out`, `s`) will terminate reading from the file. |
127 | 181 |
|
128 | 182 | In addition, you can create a file to automatically execute on a breakpoint. The name of the breakpoint
|
129 | 183 | should be the name of the file in the debug directory (with .txt added). When a function named the same
|
130 | 184 | as such a file has a breakpoint on entry, it will execute the commands. Similarly whenever a topic
|
131 | 185 | has a breakpoint on entry, it will execute its commands.
|
132 | 186 |
|
133 |
| -# Hooking up to a GUI IDE |
| 187 | + |
| 188 | +## Hooking up to a GUI IDE |
134 | 189 |
|
135 | 190 | The debugger can swap out its stdin and stdout interactions with the user with functions supplied on the
|
136 |
| -`InitSystem` interface. The functions take a single argument char* and either get a line of input or write |
| 191 | +`InitSystem` interface. The functions take a single argument `char*` and either get a line of input or write |
137 | 192 | out a line of outout.
|
138 | 193 |
|
139 |
| -# MAP file |
| 194 | + |
| 195 | +## MAP file |
140 | 196 |
|
141 | 197 | The compiler builds a map file used by the debugger to know what files have what and what lines have what.
|
142 | 198 |
|
143 | 199 | In addition, for every rule and function at the end of their data, the system prints out
|
144 |
| -the `cyclomatic complexity` of the output code. |
| 200 | +the `cyclomatic complexity` of the output code. |
0 commit comments