Debugger: Switch from readline to libedit

This commit is contained in:
Ingo Weinhold
2012-07-25 00:11:14 +02:00
parent b866f1fa54
commit aacf2782d8
3 changed files with 55 additions and 11 deletions
+3 -5
View File
@@ -3,12 +3,10 @@ SubDir HAIKU_TOP src apps debugger ;
CCFLAGS += -Werror ; CCFLAGS += -Werror ;
C++FLAGS += -Werror ; C++FLAGS += -Werror ;
UseHeaders [ FDirName $(HAIKU_TOP) headers compatibility bsd ] : true ;
UsePrivateHeaders app debug interface kernel shared libroot ; UsePrivateHeaders app debug interface kernel shared libroot ;
UsePrivateSystemHeaders ; UsePrivateSystemHeaders ;
# Use gdb's readline. It would be better to use an optional build feature.
UseHeaders [ FDirName $(HAIKU_TOP) src bin gdb ] : true ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) arch ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) arch ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) arch x86 ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) arch x86 ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) debug_info ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) debug_info ] ;
@@ -286,11 +284,11 @@ Application Debugger :
libshared.a libshared.a
libexpression_parser.a libexpression_parser.a
libmapm.a libmapm.a
<gdb>libreadline.a libedit.a
libtermcap.a libtermcap.a
$(TARGET_LIBSTDC++) $(TARGET_LIBSTDC++)
be tracker libdebug.so be tracker libbsd.so libdebug.so
: Debugger.rdef : Debugger.rdef
; ;
@@ -11,9 +11,6 @@
#include <algorithm> #include <algorithm>
#include <readline/history.h>
#include <readline/readline.h>
#include <ArgumentVector.h> #include <ArgumentVector.h>
#include <AutoDeleter.h> #include <AutoDeleter.h>
#include <Referenceable.h> #include <Referenceable.h>
@@ -23,6 +20,13 @@
#include "CliThreadsCommand.h" #include "CliThreadsCommand.h"
static const char*
get_prompt(EditLine* editLine)
{
return "debugger> ";
}
// #pragma mark - CommandEntry // #pragma mark - CommandEntry
@@ -79,6 +83,8 @@ private:
CommandLineUserInterface::CommandLineUserInterface() CommandLineUserInterface::CommandLineUserInterface()
: :
fCommands(20, true), fCommands(20, true),
fEditLine(NULL),
fHistory(NULL),
fShowSemaphore(-1), fShowSemaphore(-1),
fShown(false), fShown(false),
fTerminating(false) fTerminating(false)
@@ -90,6 +96,12 @@ CommandLineUserInterface::~CommandLineUserInterface()
{ {
if (fShowSemaphore >= 0) if (fShowSemaphore >= 0)
delete_sem(fShowSemaphore); delete_sem(fShowSemaphore);
if (fEditLine != NULL)
el_end(fEditLine);
if (fHistory != NULL)
history_end(fHistory);
} }
@@ -113,6 +125,21 @@ CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener)
if (fShowSemaphore < 0) if (fShowSemaphore < 0)
return fShowSemaphore; return fShowSemaphore;
fEditLine = el_init("Debugger", stdin, stdout, stderr);
if (fEditLine == NULL)
return B_ERROR;
fHistory = history_init();
if (fHistory == NULL)
return B_ERROR;
HistEvent historyEvent;
history(fHistory, &historyEvent, H_SETSIZE, 100);
el_set(fEditLine, EL_HIST, &history, fHistory);
el_set(fEditLine, EL_EDITOR, "emacs");
el_set(fEditLine, EL_PROMPT, &get_prompt);
return B_OK; return B_OK;
} }
@@ -141,6 +168,16 @@ CommandLineUserInterface::Terminate()
delete_sem(fShowSemaphore); delete_sem(fShowSemaphore);
fShowSemaphore = -1; fShowSemaphore = -1;
} }
if (fEditLine != NULL) {
el_end(fEditLine);
fEditLine = NULL;
}
if (fHistory != NULL) {
history_end(fHistory);
fHistory = NULL;
}
} }
@@ -205,10 +242,10 @@ CommandLineUserInterface::_InputLoop()
{ {
while (!fTerminating) { while (!fTerminating) {
// read a command line // read a command line
char* line = readline("debugger> "); int count;
const char* line = el_gets(fEditLine, &count);
if (line == NULL) if (line == NULL)
break; break;
MemoryDeleter lineDeleter(line);
// parse the command line // parse the command line
ArgumentVector args; ArgumentVector args;
@@ -231,8 +268,11 @@ CommandLineUserInterface::_InputLoop()
if (args.ArgumentCount() == 0) if (args.ArgumentCount() == 0)
continue; continue;
add_history(line); // add line to history
HistEvent historyEvent;
history(fHistory, &historyEvent, H_ENTER, line);
// execute command
_ExecuteCommand(args.ArgumentCount(), args.Arguments()); _ExecuteCommand(args.ArgumentCount(), args.Arguments());
} }
@@ -7,6 +7,10 @@
#define COMMAND_LINE_USER_INTERFACE_H #define COMMAND_LINE_USER_INTERFACE_H
#include <sys/cdefs.h>
// Needed in histedit.h.
#include <histedit.h>
#include <ObjectList.h> #include <ObjectList.h>
#include <String.h> #include <String.h>
@@ -69,6 +73,8 @@ private:
private: private:
CliContext fContext; CliContext fContext;
CommandList fCommands; CommandList fCommands;
EditLine* fEditLine;
History* fHistory;
sem_id fShowSemaphore; sem_id fShowSemaphore;
bool fShown; bool fShown;
bool fTerminating; bool fTerminating;