Debugger: Use readline in the CLI

This is a bit hacky, since gdb's readline is used. It would probably be
best to prepare an optional build package.
This commit is contained in:
Ingo Weinhold
2012-07-23 23:52:45 +02:00
parent c082e8f2e2
commit abbcb2caf5
2 changed files with 20 additions and 7 deletions
+9 -1
View File
@@ -6,6 +6,9 @@ C++FLAGS += -Werror ;
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 ] ;
@@ -273,9 +276,14 @@ Application Debugger :
<bin>debug_utils.a <bin>debug_utils.a
libcolumnlistview.a libcolumnlistview.a
libshared.a libshared.a
libshared.a
libexpression_parser.a
libmapm.a
<gdb>libreadline.a
libtermcap.a
$(TARGET_LIBSTDC++) $(TARGET_LIBSTDC++)
be tracker libdebug.so libshared.a libexpression_parser.a libmapm.a be tracker libdebug.so
: Debugger.rdef : Debugger.rdef
; ;
@@ -11,7 +11,11 @@
#include <algorithm> #include <algorithm>
#include <readline/history.h>
#include <readline/readline.h>
#include <ArgumentVector.h> #include <ArgumentVector.h>
#include <AutoDeleter.h>
#include <Referenceable.h> #include <Referenceable.h>
#include "CliCommand.h" #include "CliCommand.h"
@@ -226,16 +230,15 @@ CommandLineUserInterface::_InputLoop()
{ {
while (!fTerminating) { while (!fTerminating) {
// read a command line // read a command line
printf("debugger> "); char* line = readline("debugger> ");
fflush(stdout); if (line == NULL)
char buffer[256];
if (fgets(buffer, sizeof(buffer), stdin) == NULL)
break; break;
MemoryDeleter lineDeleter(line);
// parse the command line // parse the command line
ArgumentVector args; ArgumentVector args;
const char* parseErrorLocation; const char* parseErrorLocation;
switch (args.Parse(buffer, &parseErrorLocation)) { switch (args.Parse(line, &parseErrorLocation)) {
case ArgumentVector::NO_ERROR: case ArgumentVector::NO_ERROR:
break; break;
case ArgumentVector::NO_MEMORY: case ArgumentVector::NO_MEMORY:
@@ -243,7 +246,7 @@ CommandLineUserInterface::_InputLoop()
continue; continue;
case ArgumentVector::UNTERMINATED_QUOTED_STRING: case ArgumentVector::UNTERMINATED_QUOTED_STRING:
printf("Parse error: Unterminated quoted string starting at " printf("Parse error: Unterminated quoted string starting at "
"character %zu.\n", parseErrorLocation - buffer + 1); "character %zu.\n", parseErrorLocation - line + 1);
continue; continue;
case ArgumentVector::TRAILING_BACKSPACE: case ArgumentVector::TRAILING_BACKSPACE:
printf("Parse error: trailing backspace.\n"); printf("Parse error: trailing backspace.\n");
@@ -253,6 +256,8 @@ CommandLineUserInterface::_InputLoop()
if (args.ArgumentCount() == 0) if (args.ArgumentCount() == 0)
continue; continue;
add_history(line);
_ExecuteCommand(args.ArgumentCount(), args.Arguments()); _ExecuteCommand(args.ArgumentCount(), args.Arguments());
} }