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 ;
C++FLAGS += -Werror ;
UseHeaders [ FDirName $(HAIKU_TOP) headers compatibility bsd ] : true ;
UsePrivateHeaders app debug interface kernel shared libroot ;
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 x86 ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) debug_info ] ;
@@ -286,11 +284,11 @@ Application Debugger :
libshared.a
libexpression_parser.a
libmapm.a
<gdb>libreadline.a
libedit.a
libtermcap.a
$(TARGET_LIBSTDC++)
be tracker libdebug.so
be tracker libbsd.so libdebug.so
: Debugger.rdef
;
@@ -11,9 +11,6 @@
#include <algorithm>
#include <readline/history.h>
#include <readline/readline.h>
#include <ArgumentVector.h>
#include <AutoDeleter.h>
#include <Referenceable.h>
@@ -23,6 +20,13 @@
#include "CliThreadsCommand.h"
static const char*
get_prompt(EditLine* editLine)
{
return "debugger> ";
}
// #pragma mark - CommandEntry
@@ -79,6 +83,8 @@ private:
CommandLineUserInterface::CommandLineUserInterface()
:
fCommands(20, true),
fEditLine(NULL),
fHistory(NULL),
fShowSemaphore(-1),
fShown(false),
fTerminating(false)
@@ -90,6 +96,12 @@ CommandLineUserInterface::~CommandLineUserInterface()
{
if (fShowSemaphore >= 0)
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)
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;
}
@@ -141,6 +168,16 @@ CommandLineUserInterface::Terminate()
delete_sem(fShowSemaphore);
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) {
// read a command line
char* line = readline("debugger> ");
int count;
const char* line = el_gets(fEditLine, &count);
if (line == NULL)
break;
MemoryDeleter lineDeleter(line);
// parse the command line
ArgumentVector args;
@@ -231,8 +268,11 @@ CommandLineUserInterface::_InputLoop()
if (args.ArgumentCount() == 0)
continue;
add_history(line);
// add line to history
HistEvent historyEvent;
history(fHistory, &historyEvent, H_ENTER, line);
// execute command
_ExecuteCommand(args.ArgumentCount(), args.Arguments());
}
@@ -7,6 +7,10 @@
#define COMMAND_LINE_USER_INTERFACE_H
#include <sys/cdefs.h>
// Needed in histedit.h.
#include <histedit.h>
#include <ObjectList.h>
#include <String.h>
@@ -69,6 +73,8 @@ private:
private:
CliContext fContext;
CommandList fCommands;
EditLine* fEditLine;
History* fHistory;
sem_id fShowSemaphore;
bool fShown;
bool fTerminating;