]> gitweb.factorcode.org Git - factor.git/blob - basis/debugger/debugger-docs.factor
50461226b55477bbb7b77bf7cbe294593ed74add
[factor.git] / basis / debugger / debugger-docs.factor
1 USING: alien arrays generic generic.math help.markup help.syntax
2 kernel math memory strings sbufs vectors io io.files classes
3 help generic.single continuations io.files.private listener
4 alien.libraries ;
5 IN: debugger
6
7 ARTICLE: "debugger" "The debugger"
8 "Caught errors can be logged in human-readable form:"
9 { $subsections
10     print-error
11     try
12 }
13 "User-defined errors can have customized printed representation by implementing a generic word:"
14 { $subsections error. }
15 "A number of words facilitate interactive debugging of errors:"
16 { $subsections
17     :error
18     :s
19     :r
20     :c
21     :get
22 }
23 "Most types of errors are documented, and the documentation is instantly accessible:"
24 { $subsections :help }
25 "If the error was restartable, a list of restarts is also printed, and a numbered restart can be invoked:"
26 { $subsections
27     :1
28     :2
29     :3
30     :res
31 }
32 "You can read more about error handling in " { $link "errors" } "."
33 $nl
34 "Note that in Factor, the debugger is a tool for printing and inspecting errors, not for walking through code. For the latter, see " { $link "ui-walker" } "." ;
35
36 ABOUT: "debugger"
37
38 HELP: :error
39 { $description "Prints the most recent error. Used for interactive debugging." } ;
40
41 HELP: :s
42 { $description "Prints the data stack at the time of the most recent error. Used for interactive debugging." } ;
43
44 HELP: :r
45 { $description "Prints the retain stack at the time of the most recent error. Used for interactive debugging." } ;
46
47 HELP: :c
48 { $description "Prints the call stack at the time of the most recent error. Used for interactive debugging." } ;
49
50 HELP: :get
51 { $values { "variable" "an object" } { "value" "the value, or f" } }
52 { $description "Looks up the value of a variable at the time of the most recent error." } ;
53
54 HELP: :res
55 { $values { "n" "a positive integer" } }
56 { $description "Continues executing the " { $snippet "n" } "th restart. Since restarts may only be invoked once, this resets the " { $link restarts } " global variable." } ;
57
58 HELP: :1
59 { $description "A shortcut for invoking the first restart." } ;
60
61 HELP: :2
62 { $description "A shortcut for invoking the second restart." } ;
63
64 HELP: :3
65 { $description "A shortcut for invoking the third restart." } ;
66
67 HELP: error.
68 { $values { "error" "an error" } }
69 { $contract "Print an error to " { $link output-stream } ". You can define methods on this generic word to print human-readable messages for custom errors." }
70 { $notes "Code should call " { $link print-error } " instead, which handles the case where the printing of the error itself throws an error." } ;
71
72 HELP: error-help
73 { $values { "error" "an error" } { "topic" "an article name or word" } }
74 { $contract "Outputs a help article which explains the error." } ;
75
76 { error-help :help } related-words
77
78 HELP: print-error
79 { $values { "error" "an error" } }
80 { $description "Print an error to " { $link output-stream } "." }
81 { $notes "This word is called by the listener and other tools which report caught errors to the user." } ;
82
83 HELP: restarts.
84 { $description "Print a list of restarts for the most recently thrown error to " { $link output-stream } "." } ;
85
86 HELP: try
87 { $values { "quot" "a quotation" } }
88 { $description "Attempts to call a quotation; if it throws an error, the error is printed to " { $link output-stream } ", stacks are restored, and execution continues after the call to " { $link try } "." }
89 { $examples
90     "The following example prints an error and keeps going:"
91     { $code
92         "[ \"error\" throw ] try"
93         "\"still running...\" print"
94     }
95     { $link "listener" } " uses " { $link try } " to recover from user errors."
96 } ;
97
98 HELP: expired-error.
99 { $error-description "Thrown by " { $link alien-address } " and " { $link alien-invoke } " if an " { $link alien } " object passed in as a parameter has expired. Alien objects expire if they are saved an image which is subsequently loaded; this prevents a certain class of programming errors, usually attempts to use uninitialized objects, since holding a C address is meaningless between sessions." }
100 { $notes "You can check if an alien object has expired by calling " { $link expired? } "." } ;
101
102 HELP: io-error.
103 { $error-description "Thrown by the C streams I/O primitives if an I/O error occurs." } ;
104
105 HELP: type-check-error.
106 { $error-description "Thrown by various primitives if one of the inputs does not have the expected type. Generic words throw " { $link no-method } " and " { $link no-math-method } " errors in such cases instead." } ;
107
108 HELP: divide-by-zero-error.
109 { $error-description "This error is thrown when " { $link / } " or " { $link /i } " is called with with a zero denominator." }
110 { $see-also "division-by-zero" } ;
111
112 HELP: signal-error.
113 { $error-description
114     "Thrown by the Factor VM when a Unix signal is received. While signal numbers are system-specific, the following are relatively standard:"
115     { $list
116         { "4 - Illegal instruction. If you see this error, it is a bug in Factor's compiler and should be reported." }
117         { "8 - Arithmetic exception. Most likely a divide by zero in " { $link /i } "." }
118         { "10, 11 - Memory protection fault. This error suggests invalid values are being passed to C functions by an " { $link alien-invoke } ". Factor also uses memory protection to trap stack underflows and overflows, but usually these are reported as their own errors. Sometimes they'll show up as a generic signal 11, though." }
119     }
120     "The Windows equivalent of a signal 11 is a SEH fault. When one occurs, the runtime throws a signal error, even though it does not correspond to a Unix signal."
121 } ;
122
123 HELP: array-size-error.
124 { $error-description "Thrown by " { $link <array> } ", " { $link <string> } ", " { $link <vector> } " and " { $link <sbuf> } " if the specified capacity is negative or too large." } ;
125
126 HELP: c-string-error.
127 { $error-description "Thrown by " { $link alien-invoke } " and various primitives if a string containing null bytes, or characters with values higher than 255 is passed in where a C string is expected. See " { $link "c-strings" } "." } ;
128
129 HELP: ffi-error.
130 { $error-description "Thrown by " { $link dlopen } " and " { $link dlsym } " if a problem occurs while loading a native library or looking up a symbol. See " { $link "alien" } "." } ;
131
132 HELP: undefined-symbol-error.
133 { $error-description "Thrown if a previously-compiled " { $link alien-invoke } " call refers to a native library symbol which no longer exists." } ;
134
135 HELP: datastack-underflow.
136 { $error-description "Thrown by the Factor VM if an attempt is made to pop elements from an empty data stack." }
137 { $notes "You can use the stack effect tool to statically check stack effects of quotations. See " { $link "inference" } "." } ;
138
139 HELP: datastack-overflow.
140 { $error-description "Thrown by the Factor VM if an attempt is made to push elements on a full data stack." }
141 { $notes "This error usually indicates a run-away recursion, however if you legitimately need a data stack larger than the default, see " { $link "runtime-cli-args" } "." } ;
142
143 HELP: retainstack-underflow.
144 { $error-description "Thrown by the Factor VM if an attempt is made to access the retain stack in an invalid manner. This bug should never come up in practice and indicates a bug in Factor." }
145 { $notes "You can use the stack effect tool to statically check stack effects of quotations. See " { $link "inference" } "." } ;
146
147 HELP: retainstack-overflow.
148 { $error-description "Thrown by the Factor VM if " { $link dip } " is called when the retain stack is full." }
149 { $notes "This error usually indicates a run-away recursion, however if you legitimately need a retain stack larger than the default, see " { $link "runtime-cli-args" } "." } ;
150
151 HELP: memory-error.
152 { $error-description "Thrown by the Factor VM if an invalid memory access occurs." }
153 { $notes "This can be a result of incorrect usage of C library interface words, a bug in the compiler, or a bug in the VM." } ;
154
155 HELP: primitive-error.
156 { $error-description "Thrown by the Factor VM if an unsupported primitive word is called." } ;