Skip to content

Instantly share code, notes, and snippets.

@zhuomingliang
Forked from nbrown/gist:2706968
Created May 16, 2012 03:07
Show Gist options
  • Save zhuomingliang/2706999 to your computer and use it in GitHub Desktop.
Save zhuomingliang/2706999 to your computer and use it in GitHub Desktop.
M0 Debugger idea

Debugger:

Use the same m0 run loop and ops as m0 proper

The debugger main function, should be called from m0 proper should have the same signature as m0 ops

Store all state data in a debugger state struct

The struct has the following fields:

  • Run state => an enumerated value which is initialized to STEP. The valid values for the enumeration are:
    • 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
    • '' => 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

OPEN QUESTIONS: - How does this struct get passed around?

Debugger commands:

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 the breakpoint at PC==ARG
  • L => list breakpoints => list all breakpoints

Potential debugger commands/features:

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

Main Functions:

The debugger has three main functions:

  • Init
  • Debugger Runloop
  • Get Input

Init

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

Debugger Runloop

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
  • If the run state == RUN
    • Return
  • If the run state == BREAK
    • If at a breakpoint
      • Run the Input component
    • Else
      • Return

Get Input

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment