Conversation
41c9229 to
2b9f030
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Return stack dump and backtrace
Two new words
.rsand.btto support dumping the return stack.Both take a number of top elements to skip; this is useful when the word is invoked in a context that we want to elide from the dump (e.g.
debugger)..rsis a simple dump of the cell values with no interpretation..btattempts to interpret the cells as XTs, the+xsuffix indicates that the address isxcells after the XT field, which is normally the case for colon word IP addresses on the return stack.Debugger
To support debugging of colon words (which is somewhat unpleasant in GDB), the interpreter is modified to allow interrupting the normal COLON word interpretation cycle after each word. This is achieved by designating register r5 as DEBUG register and checking in each cycle if its value is 0. If not it is expected to point to a debug routine that should run at the point of interruption.
One of the main goals was to allow writing the debugger routines/words in Forth for both convenience and portability. Consequently it is critical that the debug word is executed normally (without further interruptions). Therefore the DEBUG register is cleared when entering the debug word and restored when the debug word exits (
exitd). When the debug word exits the interrupted word proceeds being executed.To enter the debugging regime, the word
breaksets up theDEBUGregister which causes the interpreter to be interrupted in the following cycle (before executing next word). The debug word should normally send debugging information back to the terminal emulator (the parameter stack state and backtrace) and then wait for input from the operator. Several different actions can be available, the fundamental two are "step" and "continue".Step simply leaves the DEBUG hook in place and resumes interpreter for single cycle and stops again. Continue instead clears the debug hook so the interpreter resumes normal execution until it hits the
breakword again.The DEBUG hook is controlled through the USER variable
debug.next, which determines the next debug action by being the source of value to restore into the DEBUG register when the debug word exits. Continue sets it to 0, which means the DEBUG register will be cleared when interpreter resumes.amforth-shellwas extended to present the stack state sent by the debugger and to relay user input back to the debugger. It also loads symbols from the symbol table file and re-interprets raw addresses from the debugger; this allows interpreting NONAME word addresses (e.g. theXT_R_WORD_INTERPRETin the example below) and also addresses from other memory regions (e.g.RAM_upper_datastackbelow).Here's a transcript of a short debugging session, the
fibword has a break at the top of it so it will halt on each entry into the word:The stacks are presented each on its own line, with the stack label and current depth, e.g.
PS(3):,RS(10):, followed by the list of top 10 values. If there are more than 10 values the list is finished with....The command prompt lists possible actions, the chosen action is shown as well.