Skip to content

Commit 7f72f49

Browse files
Merge pull request #84 from solyaris/master
WIKI documentation maintenance
2 parents b0af748 + 07dc350 commit 7f72f49

File tree

3 files changed

+617
-88
lines changed

3 files changed

+617
-88
lines changed

WIKI/ChatScript-Debugger.md

Lines changed: 129 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,200 @@
11
# 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
74

85
# Debugging in and out
96

107
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),
118
CS also has a text command debugger analogous to GDB in LINUX.
129

13-
You enter the debugger via ```:debug```
10+
You enter the debugger via
11+
12+
:debug
13+
1414
which begins a local command loop. Resume normal execution via
15-
```go``` or ```g```.
15+
16+
go
17+
18+
or
19+
20+
g
1621

1722
The debug command can also have one of the debug commands after it, e.g.
18-
```
19-
:debug break ^fn1 ~topic1 ^fn2
20-
```
2123

22-
# Variable and JSON displays
24+
:debug break ^fn1 ~topic1 ^fn2
25+
26+
## Variable and JSON displays
2327

2428
While in the debugger, you can display $variables just by typing in their name(s).
25-
```
26-
$myvar $_yourvar
27-
```
29+
30+
$myvar $_yourvar
2831

2932
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-
```
3333

34-
# Source locations
34+
jo-44
35+
36+
37+
## Source locations
38+
3539
Typing the name of a function or topic will tell you the file and line number of it.
3640

37-
# Breakpoints
41+
## Breakpoints
3842

3943
You can set breakpoints that will trigger the debugger on a variety of conditions. And you can
4044
name multiple conditions at once. E.g.,
41-
```
42-
break ^myfunction ~mytopic ~mytopic.myrule
43-
```
4445

45-
##Function breakpoints##
46+
break ^myfunction ~mytopic ~mytopic.myrule
47+
48+
49+
## Function breakpoints
4650

4751
A function breakpoint will, by default, break on entry and break on exit. On entry it shows the
4852
function and its arguments. On exit it shows the value being returned and any error status.
4953

5054
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
5258

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
5762

5863
Every time you call break, it prints out a summary of the breakpoints still set. So if you
5964
call break with no names, it just lists what you have.
6065

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+
6271

63-
A topic breakpoint will break on entry and exit of topic by whatever manner (normal, ```^gambit```, ```^rejoinder```,
64-
```^reuse```, etc).
72+
## Rule breakpoints
6573

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
6975

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).
7179

72-
You can name ```abort``` to request a breakpoint if the system is about to exit due to abnormal conditions.
7380

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
7591

7692
A different kind of breakpoint is a variable assign, that is, when a variable has its value changed.
7793
You can list multiple variables in a single request.
78-
```
79-
= $myvar $_hisvar
80-
```
94+
95+
= $myvar $_hisvar
8196

8297
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:
85100

86-
# Clearing Breakpoints
87-
```clear``` will remove all breakpoints including variable assigns.
101+
^myfunc.$_myvar
102+
103+
or
88104

89-
# Backtrace
105+
~mytopic.$_myvar
90106

91-
```where``` will print out a backtrace of where you are in terms of topics, rules, and functions.
92107

93-
# Controlled execution
108+
## Clearing Breakpoints
94109

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
98132
display what code it executed, what value was returned, and what code would be executed next.
99133

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.
104140

105141
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
108145

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.
113147

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
116149

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.
118156

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
121158

122-
# Sourcing a file of debug commands
159+
in
123160

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.
127181

128182
In addition, you can create a file to automatically execute on a breakpoint. The name of the breakpoint
129183
should be the name of the file in the debug directory (with .txt added). When a function named the same
130184
as such a file has a breakpoint on entry, it will execute the commands. Similarly whenever a topic
131185
has a breakpoint on entry, it will execute its commands.
132186

133-
# Hooking up to a GUI IDE
187+
188+
## Hooking up to a GUI IDE
134189

135190
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
137192
out a line of outout.
138193

139-
# MAP file
194+
195+
## MAP file
140196

141197
The compiler builds a map file used by the debugger to know what files have what and what lines have what.
142198

143199
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

Comments
 (0)