]> gitweb.factorcode.org Git - factor.git/blob - basis/debugger/debugger-docs.factor
f8897712e734eca18ade29fa44d2645da8c0f899
[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.standard continuations system io.files.private
4 listener ;
5 IN: debugger
6
7 ARTICLE: "debugger" "The debugger"
8 "Caught errors can be logged in human-readable form:"
9 { $subsection print-error }
10 { $subsection try }
11 "User-defined errors can have customized printed representation by implementing a generic word:"
12 { $subsection error. }
13 "A number of words facilitate interactive debugging of errors:"
14 { $subsection :s }
15 { $subsection :r }
16 { $subsection :c }
17 { $subsection :get }
18 "Most types of errors are documented, and the documentation is instantly accessible:"
19 { $subsection :help }
20 "If the error was restartable, a list of restarts is also printed, and a numbered restart can be invoked:"
21 { $subsection :1 }
22 { $subsection :2 }
23 { $subsection :3 }
24 { $subsection :res }
25 "You can read more about error handling in " { $link "errors" } "." ;
26
27 ABOUT: "debugger"
28
29 HELP: :s
30 { $description "Prints the data stack at the time of the most recent error. Used for interactive debugging." } ;
31
32 HELP: :r
33 { $description "Prints the retain stack at the time of the most recent error. Used for interactive debugging." } ;
34
35 HELP: :c
36 { $description "Prints the call stack at the time of the most recent error. Used for interactive debugging." } ;
37
38 HELP: :get
39 { $values { "variable" "an object" } { "value" "the value, or f" } }
40 { $description "Looks up the value of a variable at the time of the most recent error." } ;
41
42 HELP: :res
43 { $values { "n" "a positive integer" } }
44 { $description "Continues executing the " { $snippet "n" } "th restart. Since restarts may only be invoked once, this resets the " { $link restarts } " global variable." } ;
45
46 HELP: :1
47 { $description "A shortcut for invoking the first restart." } ;
48
49 HELP: :2
50 { $description "A shortcut for invoking the second restart." } ;
51
52 HELP: :3
53 { $description "A shortcut for invoking the third restart." } ;
54
55 HELP: error.
56 { $values { "error" "an error" } }
57 { $contract "Print an error to " { $link output-stream } ". You can define methods on this generic word to print human-readable messages for custom errors." }
58 { $notes "Code should call " { $link print-error } " instead, which handles the case where the printing of the error itself throws an error." } ;
59
60 HELP: error-help
61 { $values { "error" "an error" } { "topic" "an article name or word" } }
62 { $contract "Outputs a help article which explains the error." } ;
63
64 { error-help :help } related-words
65
66 HELP: print-error
67 { $values { "error" "an error" } }
68 { $description "Print an error to " { $link output-stream } "." }
69 { $notes "This word is called by the listener and other tools which report caught errors to the user." } ;
70
71 HELP: restarts.
72 { $description "Print a list of restarts for the most recently thrown error to " { $link output-stream } "." } ;
73
74 HELP: try
75 { $values { "quot" "a quotation" } }
76 { $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 } "." }
77 { $examples
78     "The following example prints an error and keeps going:"
79     { $code
80         "[ \"error\" throw ] try"
81         "\"still running...\" print"
82     }
83     { $link "listener" } " uses " { $link try } " to recover from user errors."
84 } ;
85
86 HELP: expired-error.
87 { $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." }
88 { $notes "You can check if an alien object has expired by calling " { $link expired? } "." } ;
89
90 HELP: io-error.
91 { $error-description "Thrown by the C streams I/O primitives if an I/O error occurs." } ;
92
93 HELP: type-check-error.
94 { $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." } ;
95
96 HELP: divide-by-zero-error.
97 { $error-description "This error is thrown when " { $link / } " or " { $link /i } " is called with with a zero denominator." }
98 { $see-also "division-by-zero" } ;
99
100 HELP: signal-error.
101 { $error-description
102     "Thrown by the Factor VM when a Unix signal is received. While signal numbers are system-specific, the following are relatively standard:"
103     { $list
104         { "4 - Illegal instruction. If you see this error, it is a bug in Factor's compiler and should be reported." }
105         { "8 - Arithmetic exception. Most likely a divide by zero in " { $link /i } "." }
106         { "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." }
107     }
108     "The Windows equivalent of a signal 11 is a SEH fault. When one occurs, the runtime throws a singal error, even though it does not correspond to a Unix signal."
109 } ;
110
111 HELP: array-size-error.
112 { $error-description "Thrown by " { $link <array> } ", " { $link <string> } ", " { $link <vector> } " and " { $link <sbuf> } " if the specified capacity is negative or too large." } ;
113
114 HELP: c-string-error.
115 { $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" } "." } ;
116
117 HELP: ffi-error.
118 { $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" } "." } ;
119
120 HELP: heap-scan-error.
121 { $error-description "Thrown if " { $link next-object } " is called outside of a " { $link begin-scan } "/" { $link end-scan } " pair." } ;
122
123 HELP: undefined-symbol-error.
124 { $error-description "Thrown if a previously-compiled " { $link alien-invoke } " call refers to a native library symbol which no longer exists." } ;
125
126 HELP: datastack-underflow.
127 { $error-description "Thrown by the Factor VM if an attempt is made to pop elements from an empty data stack." }
128 { $notes "You can use the stack effect tool to statically check stack effects of quotations. See " { $link "inference" } "." } ;
129
130 HELP: datastack-overflow.
131 { $error-description "Thrown by the Factor VM if an attempt is made to push elements on a full data stack." }
132 { $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" } "." } ;
133
134 HELP: retainstack-underflow.
135 { $error-description "Thrown by the Factor VM if " { $link r> } " is called while the retain stack is empty." }
136 { $notes "You can use the stack effect tool to statically check stack effects of quotations. See " { $link "inference" } "." } ;
137
138 HELP: retainstack-overflow.
139 { $error-description "Thrown by the Factor VM if " { $link >r } " is called when the retain stack is full." }
140 { $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" } "." } ;
141
142 HELP: memory-error.
143 { $error-description "Thrown by the Factor VM if an invalid memory access occurs." }
144 { $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." } ;
145
146 HELP: primitive-error.
147 { $error-description "Thrown by the Factor VM if an unsupported primitive word is called." }
148 { $notes "This word is only ever thrown on Windows CE, where the " { $link cwd } ", " { $link cd } ", and " { $link os-env } " primitives are unsupported." } ;