diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp index 85a204b3d6..f29b87ec0b 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp @@ -306,43 +306,22 @@ CommandLineUserInterface::_InputLoop() status_t CommandLineUserInterface::_RegisterCommands() { - BReference stackTraceCommandReference( - new(std::nothrow) CliStackTraceCommand, true); - BReference stackTraceCommandReference2( - stackTraceCommandReference.Get()); - - BReference dumpCommandReference( - new(std::nothrow) CliDumpMemoryCommand, true); - BReference dumpCommandReference2( - dumpCommandReference.Get()); - if (!_RegisterCommand("db", dumpCommandReference.Detach())) - return B_NO_MEMORY; - dumpCommandReference = dumpCommandReference2.Get(); - if (!_RegisterCommand("ds", dumpCommandReference.Detach())) - return B_NO_MEMORY; - dumpCommandReference = dumpCommandReference2.Get(); - if (!_RegisterCommand("dw", dumpCommandReference.Detach())) - return B_NO_MEMORY; - dumpCommandReference = dumpCommandReference2.Get(); - if (!_RegisterCommand("dl", dumpCommandReference.Detach())) - return B_NO_MEMORY; - if (!_RegisterCommand("string", dumpCommandReference2.Detach())) - return B_NO_MEMORY; - - if (_RegisterCommand("bt", stackTraceCommandReference.Detach()) + if (_RegisterCommand("bt sc", new(std::nothrow) CliStackTraceCommand) && _RegisterCommand("continue", new(std::nothrow) CliContinueCommand) + && _RegisterCommand("db ds dw dl string", new(std::nothrow) + CliDumpMemoryCommand) && _RegisterCommand("frame", new(std::nothrow) CliStackFrameCommand) && _RegisterCommand("help", new(std::nothrow) HelpCommand(this)) && _RegisterCommand("print", new(std::nothrow) CliPrintVariableCommand) && _RegisterCommand("quit", new(std::nothrow) CliQuitCommand) && _RegisterCommand("save-report", new(std::nothrow) CliDebugReportCommand) - && _RegisterCommand("sc", stackTraceCommandReference2.Detach()) && _RegisterCommand("stop", new(std::nothrow) CliStopCommand) && _RegisterCommand("thread", new(std::nothrow) CliThreadCommand) && _RegisterCommand("threads", new(std::nothrow) CliThreadsCommand) && _RegisterCommand("variables", new(std::nothrow) CliVariablesCommand)) { + fCommands.SortItems(&_CompareCommandEntries); return B_OK; } @@ -358,11 +337,23 @@ CommandLineUserInterface::_RegisterCommand(const BString& name, if (name.IsEmpty() || command == NULL) return false; - CommandEntry* entry = new(std::nothrow) CommandEntry(name, command); - if (entry == NULL || !fCommands.AddItem(entry)) { - delete entry; - return false; - } + BString nextName; + int32 startIndex = 0; + int32 spaceIndex; + do { + spaceIndex = name.FindFirst(' ', startIndex); + if (spaceIndex == B_ERROR) + spaceIndex = name.Length(); + name.CopyInto(nextName, startIndex, spaceIndex - startIndex); + + CommandEntry* entry = new(std::nothrow) CommandEntry(nextName, + command); + if (entry == NULL || !fCommands.AddItem(entry)) { + delete entry; + return false; + } + startIndex = spaceIndex + 1; + } while (startIndex < name.Length()); return true; } @@ -441,3 +432,14 @@ CommandLineUserInterface::_PrintHelp(const char* commandName) entry->Command()->Summary()); } } + + +/*static */ +int +CommandLineUserInterface::_CompareCommandEntries(const CommandEntry* command1, + const CommandEntry* command2) +{ + return ::Compare(command1->Name(), command2->Name()); +} + + diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h index 15630bd4a8..2ca34884e3 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h @@ -72,6 +72,9 @@ private: const char* const* argv); CommandEntry* _FindCommand(const char* commandName); void _PrintHelp(const char* commandName); + static int _CompareCommandEntries( + const CommandEntry* command1, + const CommandEntry* command2); private: CliContext fContext;