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