[lldb-dev] [PATCH] Fixing a crashing bug in multiword commands

William Lynch wlynch at wlynch.cx
Tue Jul 20 13:44:18 PDT 2010


Hi everyone,

*Currently, this is the output from a LLDB session:*

[3:21pm][wlynch at orange bin] ./lldb
(lldb) process
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct NULL not valid

*If the attached patch is applied, the following is the LLDB session:*

[3:25pm][wlynch at orange bin] ./lldb
(lldb) process
The following subcommands are supported:

    attach    -- Attaches to a process.
    continue  -- Continues execution all threads in the current process.
    detach    -- Detaches from the current process being debugged.
    interrupt -- Interrupts the current process being debugged.
    kill      -- Terminates the current process being debugged.
    launch    -- Launches the executable in the debugger.
    signal    -- Sends a UNIX signal to the current process being debugged.
    status    -- Shows the current status and location of executing process.

For more help on any particular subcommand, type 'help <command>
<subcommand>'.

*Here's some notes on what's going on:*
*
*
So, "process" is a multiword command object. That is, it uses
CommandObjectMultiword to choose between a set of possible classes. In
CommandObjectMultiword, a map is created to search for the desired
subcommand. If null is searched for in that map, an uncaught exception is
thrown by the standard library. Basically, it calls std::string(NULL).

The fix for this is to make sure that when we look for the next subcommand,
to verify that one does in fact exist.

*And here's the patch:*

Index: source/Commands/CommandObjectMultiword.cpp
===================================================================
--- source/Commands/CommandObjectMultiword.cpp (revision 108841)
+++ source/Commands/CommandObjectMultiword.cpp (working copy)
@@ -290,13 +290,12 @@
 const char *
 CommandObjectMultiword::GetRepeatCommand (Args &current_command_args,
uint32_t index)
 {
-    if (current_command_args.GetArgumentCount() == 0)
-        return NULL;
     index++;
+    if (current_command_args.GetArgumentCount() <= index)
+        return NULL;
     CommandObject *sub_command_object = GetSubcommandObject
(current_command_args.GetArgumentAtIndex(index));
     if (sub_command_object == NULL)
         return NULL;
-    else
     return sub_command_object->GetRepeatCommand(current_command_args,
index);
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20100720/00fd2295/attachment.html>


More information about the lldb-dev mailing list