egg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e798b0bc4cd53118d5bb18da6408f4610c5e120e
parent 9cdde7cced2861472a1e66fbf79ec95c254146a8
Author: Gabriel G. de Brito <gabrielgbrito@icloud.com>
Date:   Tue, 27 Aug 2024 13:34:48 -0300

Added reload command

Diffstat:
Mdebugger.go | 85++++++++++++++++++++++++++-----------------------------------------------------
Minternationalization.go | 94++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Mmain.go | 2+-
3 files changed, 82 insertions(+), 99 deletions(-)

diff --git a/debugger.go b/debugger.go @@ -42,62 +42,7 @@ func breakpoint2String(breakpoint Breakpoint) string { } func debuggerHelp() { - help := machine.InterCtx.Get(`Commands: - -help - Shows this help. - Shortcut: h -print <expr>[@<length>] - Prints the content of registers and memory. - Shortcut: p -printall - Prints the content of all registers. - Shortcut: pall -next - Executes the next instruction, then pauses. - Shortcut: n -continue - Continue execution until a BREAK call or breakpoint. - Shortcut: c -break [expr] - With an argument, creates a new breakpoint. With no argument, shows all - breakpoints. Accepts numbers, Assembly labels and <file>:<line>. - Shortcut: b -remove <expr> - Removes a breakpoint. Accepts numbers and Assembly labels. - Shortcut: r -dump <address>@<length> <filename> - Dumps the content of memory to a file. - Shortcut: d -rewind - Reloads the machine, i.e., asks it to return to it's original state. - Shortcut: rew -set <expr>[@<length>] <content> - Changes the content of a register or memory. - Shortcut: s -exit - Terminate debugging session. - Shortcut: e -quit - Alias to exit. - Shortcut: q - -The print command generally follows this rules: -- If the expression is only a register (e.g., x1, t1, zero, ra, etc), it prints - it's contents; -- If the expression is a register with a length (e.g., t1@1, ra@7, etc), it - prints the content of the memory addressed by the content of the register. -The set command works the same way. - -The dump command also accepts registers, but always dereference them. - -Both print and dump commands accepts the special expression #, which means the -program itself. For example, you may dump the assembled program to a file by -running 'dump # file'. - -In the print command, <addr>#<length> means "length instructions after addr". -#<length> is a shortcut to use with the current instruction address. -`) + help := machine.InterCtx.Get(MASSIVE_HELP_STRING) fmt.Print(help) } @@ -664,6 +609,30 @@ func debuggerRewind(m machine.Machine, prog []uint8) { } } +func debuggerReload(m machine.Machine, sym *[]assembler.DebuggerToken, breakpoints *[]Breakpoint, prog *[]uint8, fileName string) { + newCode, newSym, err := m.Assemble(fileName) + if err != nil { + fmt.Println(machine.InterCtx.Get("Error assembling file:")) + fmt.Println(err) + fmt.Println(machine.InterCtx.Get("Keeping old program and program state.")) + return + } + + err = m.LoadProgram(newCode) + if err != nil { + fmt.Println(machine.InterCtx.Get("Error loading new assembled code:")) + fmt.Println(err) + fmt.Println(machine.InterCtx.Get("Keeping old program and program state.")) + } + + *prog = newCode + *sym = newSym + *breakpoints = []Breakpoint{} + + fmt.Println(machine.InterCtx.Get("Rebuild Assembly.")) + fmt.Println(machine.InterCtx.Get("Reloaded machine.")) +} + // Returns length (second value) as 0 if it's a register. func getSetExpr(m machine.Machine, expr string) (uint64, uint64, error) { addr, length, has_at := strings.Cut(expr, "@") @@ -736,7 +705,7 @@ func debuggerSet(m machine.Machine, args []string) { } } -func debugMachine(m machine.Machine, sym []assembler.DebuggerToken, prog []uint8) { +func debugMachine(m machine.Machine, sym []assembler.DebuggerToken, prog []uint8, fileName string) { version() fmt.Println(machine.InterCtx.Get("Type 'help' for a list of commands.")) @@ -786,6 +755,8 @@ func debugMachine(m machine.Machine, sym []assembler.DebuggerToken, prog []uint8 debuggerDump(m, wsl[1:], prog) case "rewind", "rew": debuggerRewind(m, prog) + case "reload", "rel": + debuggerReload(m, &sym, &breakpoints, &prog, fileName) case "set", "s": debuggerSet(m, wsl[1:]) case "exit", "e", "quit", "q": diff --git a/internationalization.go b/internationalization.go @@ -1,45 +1,6 @@ package main -var brazilian = map[string]string{ - - // - // main.go. - // - - // Infos. - `Currently supported architetures: -'riscv' - RISC-V IM, 32 bits -'mips' - Subset of MIPS32 (experimental) -'sagui' - Fantasy 8 bit RISC`: `Arquiteturas suportadas: -'riscv' - RISC-V IM, 32 bits -'mips' - Subconjunto de MIPS32 (experimental) -'sagui' - RISC fantasia de 8 bits`, - "EGG - Emulador Genérico do Gabriel - version ": "EGG - Emulador Genérico do Gabriel - versão ", - // Main execution loop. - "Instruction execution failed: %v\n": "Falha na execução da instrução: %v\n", - // Args. - "Select architeture to use.": "Seleciona a arquitetura a ser utilizada.", - "Select architeture to use (shorthand).": "Seleciona a arquitetura a ser utilizada (abrev.).", - "Lists currently supported architetures and quit.": "Lista arquiteturas suportadas e sai.", - "Lists currently supported architetures (shorthand).": "Lista arquiteturas suportadas e sai (abrev.).", - "Show current version and quit.": "Mostra a versão atual e sai.", - "Show current version and quit (shorthand).": "Mostra a versão atual e sai (abrev.).", - "Enter debugger upon startup.": "Entra no debugger após inicialização.", - "Enter debugger upon startup (shorthand).": "Entra no debugger após inicialização (abrev).", - // main(). - "Unknown architeture: %v\n": "Arquitetura desconhecida: %v\n", - "No Assembly file supplied.": "Nenhum arquivo Assembly providenciado.", - "Could not read supplied file %v\n": "Erro lendo o arquivo %v providenciado", - "Error assembling file %v: %v\n": "Erro montando o arquivo %v: %v\n", - "Error loading assembled program: %v\n": "Erro carregando o programa montado: %v\n", - "Debugging is not supported for the selected backend.": "Debugging não é suportado pelo backend selecionado.", - - // - // debugger.go. - // - - // Massive help string. - `Commands: +const MASSIVE_HELP_STRING = `Commands: help Shows this help. @@ -69,6 +30,9 @@ dump <address>@<length> <filename> rewind Reloads the machine, i.e., asks it to return to it's original state. Shortcut: rew +reload + Reload the Assembly files and them reloads the machine. + Shortcut: rel set <expr>[@<length>] <content> Changes the content of a register or memory. Shortcut: s @@ -94,7 +58,48 @@ running 'dump # file'. In the print command, <addr>#<length> means "length instructions after addr". #<length> is a shortcut to use with the current instruction address. -`: `Comandos: +` + +var brazilian = map[string]string{ + + // + // main.go. + // + + // Infos. + `Currently supported architetures: +'riscv' - RISC-V IM, 32 bits +'mips' - Subset of MIPS32 (experimental) +'sagui' - Fantasy 8 bit RISC`: `Arquiteturas suportadas: +'riscv' - RISC-V IM, 32 bits +'mips' - Subconjunto de MIPS32 (experimental) +'sagui' - RISC fantasia de 8 bits`, + "EGG - Emulador Genérico do Gabriel - version ": "EGG - Emulador Genérico do Gabriel - versão ", + // Main execution loop. + "Instruction execution failed: %v\n": "Falha na execução da instrução: %v\n", + // Args. + "Select architeture to use.": "Seleciona a arquitetura a ser utilizada.", + "Select architeture to use (shorthand).": "Seleciona a arquitetura a ser utilizada (abrev.).", + "Lists currently supported architetures and quit.": "Lista arquiteturas suportadas e sai.", + "Lists currently supported architetures (shorthand).": "Lista arquiteturas suportadas e sai (abrev.).", + "Show current version and quit.": "Mostra a versão atual e sai.", + "Show current version and quit (shorthand).": "Mostra a versão atual e sai (abrev.).", + "Enter debugger upon startup.": "Entra no debugger após inicialização.", + "Enter debugger upon startup (shorthand).": "Entra no debugger após inicialização (abrev).", + // main(). + "Unknown architeture: %v\n": "Arquitetura desconhecida: %v\n", + "No Assembly file supplied.": "Nenhum arquivo Assembly providenciado.", + "Could not read supplied file %v\n": "Erro lendo o arquivo %v providenciado", + "Error assembling file %v: %v\n": "Erro montando o arquivo %v: %v\n", + "Error loading assembled program: %v\n": "Erro carregando o programa montado: %v\n", + "Debugging is not supported for the selected backend.": "Debugging não é suportado pelo backend selecionado.", + + // + // debugger.go. + // + + // Massive help string. + MASSIVE_HELP_STRING: `Comandos: help Mostra esse texto de ajuda. @@ -124,6 +129,9 @@ dump <endereço>@<tamanho> <arquivo> rewind Recarrega a máquina, isso é, pede para que ela retorne ao estado original. Abreviação: rew +reload + Recarrega os arquivos Assembly e então recarrega a máquina. + Abreviação: rel set <expr>[@tamanho] <conteúdo> Muda o conteúdo de registradores ou da memória. Abreviação: s @@ -197,6 +205,10 @@ No comando print, <addr>#tamanho significa "tantas instruções após addr". "New breakpoint %v\n": "Novo ponto de parada (breakpoint) %v\n", "remove expects a breakpoint to remove: remove <address/label/file:line>": "remove necessita de um ponto (breakpoint) para remover: remove <endereço/etiqueta/arquivo:linha>", "No breakpoint %v\n": "Nenhum ponto de parada (breakpoint) %v\n", + "Error assembling file:": "Erro montando arquivo:", + "Keeping old program and program state.": "Mantendo o programa e estado anteriores", + "Error loading new assembled code:": "Erro carregando o novo código montado:", + "Rebuild Assembly.": "Assembly remontado.", // // assembler.go and tokenizer.go diff --git a/main.go b/main.go @@ -136,7 +136,7 @@ func main() { os.Exit(1) } // Hello fellow Acme user. Plumb this: debugger.go:/debugMachine - debugMachine(m, sym, code) + debugMachine(m, sym, code, file) } else { runMachine(m) }