![]() |
Debugging, known issues and limitations | ![]() |
The basic techniques for debugging a plug-in (running the helper program by hand, checking the detection, using the standard error) are described in debugging plug-ins. This section lists the additional tools which are useful when the problem is in the connection machinery itself.
The flags are set on the command line (-debug-io), in the Debug menu (available after enabling Tools\(\rightarrow\)Debugging tool), or from Scheme with (debug-set "io" #t); they correspond to the C++ macros DEBUG_IO, DEBUG_AUTO and DEBUG_VERBOSE of
Kernel/Abstractions/basic.hpp
.
The POSIX pipe link prints every chunk it receives and, preceded by [INPUT], every string it sends, with the control characters shown as [BEGIN], [END], [ESCAPE], [COMMAND] and [ABORT] (debug_io_string). The Qt pipe link does the same, but prefixes each received chunk with [OUTPUT n], where n is the QProcess channel (0 for the standard output, 1 for the standard error). After each complete output (the closing DATA_END of the outermost block), connection_rep::read prints a horizontal rule. Command line links print the command they launch, request links the request, and the output parser reports output which it ignored because of a DATA_ABORT.
Pipe links print the launch command, and dynamic links the result of symbol_install.
connection_start prints Starting session 'ses' whenever it creates a connection.
In a Scheme session, the state of a connection can be inspected with the glue functions and the exported functions of the request queue, for instance:
(connection-info "maxima" "default") ; launcher description
(connection-status "maxima" "default") ; 0, 2 or 3
(length (pending-ref "maxima" "default")) ; queued requests
(plugin-prompt "maxima" "default") ; last prompt |
A session which is stuck (status 3 with a non-empty queue) can be reset with Interrupt execution (which empties the queue even if the program does not react) followed by Close session. The display* calls which are commented out at the beginning of the call-backs in
plugin-eval.scm
and
session-edit.scm
are a convenient way to trace the scheduler.
The protocol can also be exercised without any program: a launcher such as
printf '\002verbatim:hello\n\002prompt#> \005\005'; cat > /dev/null |
prints a banner and a prompt and then waits forever. With Qt pipes, this has to be wrapped as sh -c "…", see below.
The outermost block was not closed, or the program did not flush its standard output after the final DATA_END. If this already happens right after the creation of the session, the banner is the culprit: as long as the start request is not complete, all evaluations stay in the queue. Another cause is a launch failure with Qt pipes (see below).
The program closes more than one outermost block per request, for instance by sending the prompt as a separate block after the output instead of nesting it inside. If the second DATA_END arrives after the next request was sent, it terminates that request prematurely.
The program writes to a pipe and therefore uses block buffering; it must flush its output. This is invisible when the program is tested in a terminal.
See the race described below.
Channels other than output, error, prompt and input are only delivered to handlers declared with :handler, and the table of handlers is cached on first use.
The following problems are visible in the current sources. The first three are already known upstream.
The :socket option produces a launcher description (tuple "socket" host port), but connection_start has no branch for it, and the socket functions declared in
tm_link.hpp
are not defined (see sockets). Worse, when connection_start is called for the first time with a description which matches none of its branches, the variable con is still the nil connection when the code reaches con->info= t, which dereferences a null pointer.
connection_rep::start only reads the startup message of a link immediately if the plug-in is called dynlink, the name of the example plug-in in
src/TeXmacs/examples/plugins/dynlink
:
if (name == "dynlink") {
this->listen ();
status = WAITING_FOR_OUTPUT;
} |
For any other plug-in with a :link option, dynamic links being neither polled nor connected to notifiers, the startup message is never read, the connection never reports that it is waiting for input, and the start request of the session is never completed. The test should be on the type of the link (the launcher description (tuple "dynlink" …)) rather than on the name of the plug-in.
The value of :prioritary is stored in the plug-in cache, but it is read before the cache is loaded; see known limitations in the description of the plug-in internals.
Launch failures are not reported. plugin-start ignores the message returned by connection-start. With the POSIX pipe link this is harmless, since the failure is detected later as the death of the shell. With Qt pipes, however, start fails immediately (for instance for a launcher containing shell operators, which wordexp rejects), no status change is ever notified, and the session stays busy without any message until the user interrupts it.
Interrupts are not synchronized with the program. plugin-interrupt cancels the queued requests at once, but the connection keeps reporting the status 3 until the program closes the interrupted output. A request which is evaluated in the meantime is written to the program immediately and receives the remaining output of the interrupted computation, and its own output is attributed to the request after it.
Several sessions with the same dynamic library. When a library was already installed by another connection, dyn_link_rep::start returns a continuation of#… message without setting alive, so the link of the second session is never alive and its writes are ignored.
Status of dynamic links. dyn_link_rep::write notifies the connection synchronously, before connection_rep::write sets the status to WAITING_FOR_OUTPUT. The status therefore stays at 3 between evaluations. Sessions are not affected, but connection_eval on a dynamic link waits for a status change which never comes.
Synchronous evaluation in Qt builds without QTPIPES. connection_retrieve only calls perform_select when QTTEXMACS is undefined, while pipe_link_rep::read does not pull data from the pipe. In this configuration plugin-eval on a pipe can therefore not see new output.
Stopping blocks the interface. pipe_link_rep::stop and close_all_pipes sleep for two seconds between SIGTERM and SIGKILL, even when the program terminated at once. Moreover, neither stop nor the end-of-file branch of feed close the descriptors of the output and error pipes, and wait (NULL) may reap an unrelated child process.
Binary output with Qt pipes. QTMPipeLink::feedBuf converts the received QByteArray with constData (), that is, as a null-terminated string: everything after a null byte in a chunk is lost.
Cancelled requests. The thread which performs a request of a request_link_rep cannot be stopped and writes its result into the buffers of the link when it finishes, even if the request was cancelled and another one has started in the meantime.
Simplification of output. In plugin-output-std-simplify (
plugin-eval.scm
), the test (func? 'concat 0) lacks its first argument t, so that an empty concat is not simplified to the empty string.
Dead declarations. connection_stop_all (in
connect.hpp
) and texmacs_input_rep::ispell_flush are declared but not defined; cmdline_link_rep::write tests whether the command is empty only after having appended 2> /dev/null to it.
All communication happens in the main thread, by polling; see threading and the event loop. There is no timeout for synchronous evaluations.
Only one request per connection is in progress at any time; the protocol has no request identifiers, so the end of an output is the only synchronization point.
The relative order of standard output and standard error within one polling interval is lost.
Input is sent as a single string, and there is no flow control: pipe_link_rep::write performs a single write system call and ignores its result.
A program cannot be interrupted on Windows, and a dynamic library cannot be interrupted at all.
The session name is not passed to the functions of :cmdline and :request plug-ins.