mirror of https://github.com/mgba-emu/mgba.git
Remove reliance on linenoise
This commit is contained in:
parent
c19d1117f1
commit
01d8569262
|
@ -1,3 +0,0 @@
|
|||
[submodule "third-party/linenoise"]
|
||||
path = third-party/linenoise
|
||||
url = git://github.com/antirez/linenoise.git
|
|
@ -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 @@ else()
|
|||
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})
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "linenoise.h"
|
||||
|
||||
struct DebugVector {
|
||||
struct DebugVector* next;
|
||||
|
@ -256,7 +255,7 @@ enum _DVParseState {
|
|||
};
|
||||
|
||||
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 @@ static struct DebugVector* _DVParse(struct ARMDebugger* debugger, const char* st
|
|||
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 @@ static void _DVFree(struct DebugVector* dv) {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ static int _parse(struct ARMDebugger* debugger, const char* line) {
|
|||
return 0;
|
||||
}
|
||||
} else {
|
||||
cmdLength = strlen(line);
|
||||
cmdLength = count;
|
||||
}
|
||||
|
||||
int i;
|
||||
|
@ -516,27 +515,29 @@ static int _parse(struct ARMDebugger* debugger, const char* line) {
|
|||
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,14 +546,27 @@ static void _commandLine(struct ARMDebugger* debugger) {
|
|||
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) {
|
||||
while (debugger->state != DEBUGGER_EXITING) {
|
||||
if (!debugger->breakpoints) {
|
||||
|
|
|
@ -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*);
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 27a3b4d5205a5fb3e2101128edd6653bd0c92189
|
Loading…
Reference in New Issue