The debugger main function, should be called from m0 proper
The struct has the following fields:
- Run state => an enumerated value which is initialized to STEP. The valid
values for the enumeration are:
- INIT => the initial state during which the debugger state structure is initialized from command line arguments if they exist
- STEP => which means the debugger will execute a single iteration of the m0 run loop
- RUN => runs to the end of the program
- BREAK => runs until the next break point
- Breakpoints => an array of all the breakpoints. Breakpoints are currently envisioned to be stored as an integer PC value
- Number of breakpoint => the number of breakpoints in the breakpoint array
- Input source => a string indicating where the input function will read the
debugger commands from
- NULL => the debugger takes its input from the user
- 'filename' => the debugger takes its input from a script file specified
on the command line
- The m0 debugger script file is simply a text file with 1 m0 debugger command per line
- Comments have # in column 1
Debugger commands are treated as enumerated values internally. Externally, each command will have a long and short command string. The planned debugger commands are:
- s => step => execute one iteration of the m0 runloop
- c => continue => execute the m0 runloop until a breakpoint or the end of the program
- l => list => display the line of source code about to
be executed
- Disassembled or from the source file? Disassembled is easier
- p ARG => print hex ARG => print the register ARG in raw hex
- ps ARG => print string ARG => print the register ARG as string
- pi ARG => print integer ARG => print the register ARG as an integer
- pn ARG => print number ARG => print the register ARG as a float
- b ARG => add breakpoint ARG => add a breakpoint at PC==ARG
- B ARG => delete breakpoint ARG => delete breakpoint # ARG
- B => delete breakpoints => delete all breakpoints
- L => list breakpoints => list all breakpoints
After all of the basic commands above are implemented, maybe we should consider the following:
- conditional breakpoints
- ^C => key press that puts the debugger into the STEP run state
- modify registers => allows the user to manipulate data
- execute ops => allows the user to call any m0 op
The debugger has three main functions:
- Init
- Debugger Runloop
- Get Input
Extracts debugger arguments from the command line arguments and uses them to initialize the debugger state structure. Currently, the command line arguments are:
- -s filename => The filename is the name of an m0 debugger script file
Called prior to the current op being executed inside the m0 runloop. This is the main debugger runloop. Pseudocode for the debugger runloop can be found below:
- If the run state == STEP
- While run state == STEP
- Run the Input component
- Execute the debugger command
- Return
- While run state == STEP
- If the run state == RUN
- Return
- If the run state == BREAK
- If at a breakpoint
- Run the Input component
- Else
- Return
- If at a breakpoint
Get a single command from the input source (user or file). Pseudocode for the get input function can be found below:
- If the input source == ''
- Get user input
- If the input source == 'filename'
- Get the next line from 'filename'