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