all repos — mgba @ 01d85692623df695ca13f762dc0e6ff750d2604d

mGBA Game Boy Advance Emulator

Remove reliance on linenoise
Jeffrey Pfau jeffrey@endrift.com
Wed, 09 Oct 2013 21:52:56 -0700
commit

01d85692623df695ca13f762dc0e6ff750d2604d

parent

c19d1117f18da6a407ae8332a904004e9edf0677

4 files changed, 40 insertions(+), 25 deletions(-)

jump to
D .gitmodules

@@ -1,3 +0,0 @@

-[submodule "third-party/linenoise"] - path = third-party/linenoise - url = git://github.com/antirez/linenoise.git
M CMakeLists.txtCMakeLists.txt

@@ -8,7 +8,6 @@ file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)

file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.c) file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/video-software.c) file(GLOB DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/*.c) -file(GLOB THIRD_PARTY ${CMAKE_SOURCE_DIR}/third-party/linenoise/linenoise.c) include_directories(${CMAKE_SOURCE_DIR}/src/arm) include_directories(${CMAKE_SOURCE_DIR}/src/gba) include_directories(${CMAKE_SOURCE_DIR}/src/debugger)

@@ -33,5 +32,5 @@ include_directories(${SDL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})

endif() include_directories(${SDL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) -add_executable(${BINARY_NAME} ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${THIRD_PARTY} ${SDL_SRC} ${MAIN_SRC}) -target_link_libraries(${BINARY_NAME} m pthread ${SDL_LIBRARY} ${OPENGL_LIBRARY}) +add_executable(${BINARY_NAME} ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${SDL_SRC} ${MAIN_SRC}) +target_link_libraries(${BINARY_NAME} m pthread edit ${SDL_LIBRARY} ${OPENGL_LIBRARY})
M src/debugger/debugger.csrc/debugger/debugger.c

@@ -10,7 +10,6 @@ #include <stdarg.h>

#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "linenoise.h" struct DebugVector { struct DebugVector* next;

@@ -256,7 +255,7 @@ PARSE_EXPECT_SUFFIX,

}; static struct DebugVector* _DVParse(struct ARMDebugger* debugger, const char* string) { - if (!string || !string[0]) { + if (!string || !string[0] || string[0] == '\n') { return 0; }

@@ -264,7 +263,7 @@ enum _DVParseState state = PARSE_ROOT;

struct DebugVector dvTemp = { .type = INT_TYPE }; uint32_t current = 0; - while (string[0] && string[0] != ' ' && state != PARSE_ERROR) { + while (string[0] && string[0] != ' ' && string[0] != '\n' && state != PARSE_ERROR) { char token = string[0]; ++string; switch (state) {

@@ -483,7 +482,7 @@ dv = next;

} } -static int _parse(struct ARMDebugger* debugger, const char* line) { +static int _parse(struct ARMDebugger* debugger, const char* line, size_t count) { char* firstSpace = strchr(line, ' '); size_t cmdLength; struct DebugVector* dv = 0;

@@ -496,7 +495,7 @@ _DVFree(dv);

return 0; } } else { - cmdLength = strlen(line); + cmdLength = count; } int i;

@@ -516,27 +515,29 @@ printf("Command not found\n");

return 0; } +static char* _prompt(EditLine* el) { + (void)(el); + return "> "; +} + static void _commandLine(struct ARMDebugger* debugger) { - char* line; + const char* line; _printStatus(debugger, 0); + int count = 0; + HistEvent ev; while (debugger->state == DEBUGGER_PAUSED) { - line = linenoise("> "); + line = el_gets(debugger->elstate, &count); if (!line) { debugger->state = DEBUGGER_EXITING; return; } - if (!line[0]) { - if (debugger->lastCommand) { - _parse(debugger, debugger->lastCommand); + if (line[0] == '\n') { + if (history(debugger->histate, &ev, H_FIRST) >= 0) { + _parse(debugger, ev.str, strlen(ev.str) - 1); } } else { - linenoiseHistoryAdd(line); - if (_parse(debugger, line)) { - char* oldLine = debugger->lastCommand; - debugger->lastCommand = line; - free(oldLine); - } else { - free(line); + if (_parse(debugger, line, count - 1)) { + history(debugger->histate, &ev, H_ENTER, line); } } }

@@ -545,12 +546,25 @@

void ARMDebuggerInit(struct ARMDebugger* debugger, struct ARMCore* cpu) { debugger->cpu = cpu; debugger->state = DEBUGGER_PAUSED; - debugger->lastCommand = 0; debugger->breakpoints = 0; + // TODO: get argv[0] + debugger->elstate = el_init("gbac", stdin, stdout, stderr); + el_set(debugger->elstate, EL_PROMPT, _prompt); + el_set(debugger->elstate, EL_EDITOR, "emacs"); + debugger->histate = history_init(); + HistEvent ev; + history(debugger->histate, &ev, H_SETSIZE, 200); + el_set(debugger->elstate, EL_HIST, history, debugger->histate); debugger->memoryShim.p = debugger; debugger->memoryShim.watchpoints = 0; _activeDebugger = debugger; signal(SIGINT, _breakIntoDefault); +} + +void ARMDebuggerDeinit(struct ARMDebugger* debugger) { + // TODO: actually call this + history_end(debugger->histate); + el_end(debugger->elstate); } void ARMDebuggerRun(struct ARMDebugger* debugger) {
M src/debugger/debugger.hsrc/debugger/debugger.h

@@ -1,6 +1,8 @@

#ifndef DEBUGGER_H #define DEBUGGER_H +#include <histedit.h> + #include "arm.h" enum DebuggerState {

@@ -26,12 +28,15 @@ struct ARMDebugger {

enum DebuggerState state; struct ARMCore* cpu; - char* lastCommand; + EditLine* elstate; + History* histate; + struct DebugBreakpoint* breakpoints; struct DebugMemoryShim memoryShim; }; void ARMDebuggerInit(struct ARMDebugger*, struct ARMCore*); +void ARMDebuggerDeinit(struct ARMDebugger*); void ARMDebuggerRun(struct ARMDebugger*); void ARMDebuggerEnter(struct ARMDebugger*);