Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make 
sense by default so that subclasses can check:

int
PlatformSubclass::Foo ()
{
    if (IsHost())
        return Platform::Foo (); // Let the platform base class do the host specific stuff
    
    // Platform subclass specific code...
    int result = ...
    return result;
}

Added new functions to the platform:

    virtual const char *Platform::GetUserName (uint32_t uid);
    virtual const char *Platform::GetGroupName (uint32_t gid);

The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.

Added the parent process ID to the ProcessInfo class. 

Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value, 
    euid == value, egid == value, arch == value, parent == value.
    
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class 
implements the process lookup routines, you can now lists processes on 
your local machine:

machine1.foo.com % lldb
(lldb) platform process list 
PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE                   NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538  1      username   usergroup  username   usergroup  x86_64-apple-darwin      FileMerge
94943  1      username   usergroup  username   usergroup  x86_64-apple-darwin      mdworker
94852  244    username   usergroup  username   usergroup  x86_64-apple-darwin      Safari
94727  244    username   usergroup  username   usergroup  x86_64-apple-darwin      Xcode
92742  92710  username   usergroup  username   usergroup  i386-apple-darwin        debugserver


This of course also works remotely with the lldb-platform:

machine1.foo.com % lldb-platform --listen 1234

machine2.foo.com % lldb
(lldb) platform create remote-macosx
  Platform: remote-macosx
 Connected: no
(lldb) platform connect connect://localhost:1444
  Platform: remote-macosx
    Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
    Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
  Hostname: machine1.foo.com
 Connected: yes
(lldb) platform process list 
PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE                   NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556  244    username   usergroup  username   usergroup  x86_64-apple-darwin      trustevaluation
99548  65539  username   usergroup  username   usergroup  x86_64-apple-darwin      lldb
99538  1      username   usergroup  username   usergroup  x86_64-apple-darwin      FileMerge
94943  1      username   usergroup  username   usergroup  x86_64-apple-darwin      mdworker
94852  244    username   usergroup  username   usergroup  x86_64-apple-darwin      Safari

The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.

Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:

% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out

Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.

Modified the disassembly to show the current PC value. Example output:

(lldb) disassemble --frame
a.out`main:
   0x1eb7:  pushl  %ebp
   0x1eb8:  movl   %esp, %ebp
   0x1eba:  pushl  %ebx
   0x1ebb:  subl   $20, %esp
   0x1ebe:  calll  0x1ec3                   ; main + 12 at test.c:18
   0x1ec3:  popl   %ebx
-> 0x1ec4:  calll  0x1f12                   ; getpid
   0x1ec9:  movl   %eax, 4(%esp)
   0x1ecd:  leal   199(%ebx), %eax
   0x1ed3:  movl   %eax, (%esp)
   0x1ed6:  calll  0x1f18                   ; printf
   0x1edb:  leal   213(%ebx), %eax
   0x1ee1:  movl   %eax, (%esp)
   0x1ee4:  calll  0x1f1e                   ; puts
   0x1ee9:  calll  0x1f0c                   ; getchar
   0x1eee:  movl   $20, (%esp)
   0x1ef5:  calll  0x1e6a                   ; sleep_loop at test.c:6
   0x1efa:  movl   $12, %eax
   0x1eff:  addl   $20, %esp
   0x1f02:  popl   %ebx
   0x1f03:  leave
   0x1f04:  ret
   
This can be handy when dealing with the new --line options that was recently
added:

(lldb) disassemble --line
a.out`main + 13 at test.c:19
   18  	{
-> 19  		printf("Process: %i\n\n", getpid());
   20  	    puts("Press any key to continue..."); getchar();
-> 0x1ec4:  calll  0x1f12                   ; getpid
   0x1ec9:  movl   %eax, 4(%esp)
   0x1ecd:  leal   199(%ebx), %eax
   0x1ed3:  movl   %eax, (%esp)
   0x1ed6:  calll  0x1f18                   ; printf

Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.

Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two 
following functions to retrieve both paths:

const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;





git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@128563 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectDisassemble.cpp b/source/Commands/CommandObjectDisassemble.cpp
index 74c27e3..6567a08 100644
--- a/source/Commands/CommandObjectDisassemble.cpp
+++ b/source/Commands/CommandObjectDisassemble.cpp
@@ -36,12 +36,13 @@
     Options(),
     num_lines_context(0),
     num_instructions (0),
-    m_func_name(),
-    m_start_addr(),
-    m_end_addr (),
-    m_at_pc (false),
-    m_plugin_name (),
-    m_arch() 
+    func_name(),
+    start_addr(),
+    end_addr (),
+    at_pc (false),
+    frame_line (false),
+    plugin_name (),
+    arch() 
 {
     ResetOptionValues();
 }
@@ -82,32 +83,39 @@
         break;
 
     case 's':
-        m_start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
-        if (m_start_addr == LLDB_INVALID_ADDRESS)
-            m_start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
+        start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
+        if (start_addr == LLDB_INVALID_ADDRESS)
+            start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
 
-        if (m_start_addr == LLDB_INVALID_ADDRESS)
+        if (start_addr == LLDB_INVALID_ADDRESS)
             error.SetErrorStringWithFormat ("Invalid start address string '%s'.\n", option_arg);
         break;
     case 'e':
-        m_end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
-        if (m_end_addr == LLDB_INVALID_ADDRESS)
-            m_end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
+        end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
+        if (end_addr == LLDB_INVALID_ADDRESS)
+            end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
 
-        if (m_end_addr == LLDB_INVALID_ADDRESS)
+        if (end_addr == LLDB_INVALID_ADDRESS)
             error.SetErrorStringWithFormat ("Invalid end address string '%s'.\n", option_arg);
         break;
 
     case 'n':
-        m_func_name.assign (option_arg);
+        func_name.assign (option_arg);
         break;
 
     case 'p':
-        m_at_pc = true;
+        at_pc = true;
+        break;
+
+    case 'l':
+        frame_line = true;
+        // Disassemble the current source line kind of implies showing mixed
+        // source code context. 
+        show_mixed = true;
         break;
 
     case 'P':
-        m_plugin_name.assign (option_arg);
+        plugin_name.assign (option_arg);
         break;
 
     case 'r':
@@ -120,7 +128,7 @@
         break;
 
     case 'a':
-        m_arch.SetTriple (option_arg);
+        arch.SetTriple (option_arg);
         break;
 
     default:
@@ -134,18 +142,18 @@
 void
 CommandObjectDisassemble::CommandOptions::ResetOptionValues ()
 {
-    Options::ResetOptionValues();
     show_mixed = false;
     show_bytes = false;
     num_lines_context = 0;
     num_instructions = 0;
-    m_func_name.clear();
-    m_at_pc = false;
-    m_start_addr = LLDB_INVALID_ADDRESS;
-    m_end_addr = LLDB_INVALID_ADDRESS;
+    func_name.clear();
+    at_pc = false;
+    frame_line = false;
+    start_addr = LLDB_INVALID_ADDRESS;
+    end_addr = LLDB_INVALID_ADDRESS;
     raw = false;
-    m_plugin_name.clear();
-    m_arch.Clear();
+    plugin_name.clear();
+    arch.Clear();
 }
 
 const OptionDefinition*
@@ -172,7 +180,8 @@
   LLDB_OPT_SET_5    , false , "count",          'c', required_argument  , NULL, 0, eArgTypeNumLines,    "Number of instructions to display."},
 { LLDB_OPT_SET_3    , true  , "name",           'n', required_argument  , NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,             "Disassemble entire contents of the given function name."},
 { LLDB_OPT_SET_4    , true  , "frame",          'f', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble from the start of the current frame's function."},
-{ LLDB_OPT_SET_5    , true  , "pc",             'p', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble from the current pc."},
+{ LLDB_OPT_SET_5    , true  , "pc",             'p', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble around the current pc."},
+{ LLDB_OPT_SET_6    , true  , "line",           'l', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble the current frame's current source line instructions if there debug line table information, else disasemble around the pc."},
 { 0                 , false , NULL,             0,   0                  , NULL, 0, eArgTypeNone,        NULL }
 };
 
@@ -208,10 +217,10 @@
         result.SetStatus (eReturnStatusFailed);
         return false;
     }
-    if (!m_options.m_arch.IsValid())
-        m_options.m_arch = target->GetArchitecture();
+    if (!m_options.arch.IsValid())
+        m_options.arch = target->GetArchitecture();
 
-    if (!m_options.m_arch.IsValid())
+    if (!m_options.arch.IsValid())
     {
         result.AppendError ("use the --arch option or set the target architecure to disassemble");
         result.SetStatus (eReturnStatusFailed);
@@ -219,17 +228,17 @@
     }
 
     const char *plugin_name = m_options.GetPluginName ();
-    Disassembler *disassembler = Disassembler::FindPlugin(m_options.m_arch, plugin_name);
+    Disassembler *disassembler = Disassembler::FindPlugin(m_options.arch, plugin_name);
 
     if (disassembler == NULL)
     {
         if (plugin_name)
             result.AppendErrorWithFormat ("Unable to find Disassembler plug-in named '%s' that supports the '%s' architecture.\n", 
                                           plugin_name,
-                                          m_options.m_arch.GetArchitectureName());
+                                          m_options.arch.GetArchitectureName());
         else
             result.AppendErrorWithFormat ("Unable to find Disassembler plug-in for the '%s' architecture.\n", 
-                                          m_options.m_arch.GetArchitectureName());
+                                          m_options.arch.GetArchitectureName());
         result.SetStatus (eReturnStatusFailed);
         return false;
     }
@@ -252,12 +261,12 @@
 
     ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
 
-    if (!m_options.m_func_name.empty())
+    if (!m_options.func_name.empty())
     {
-        ConstString name(m_options.m_func_name.c_str());
+        ConstString name(m_options.func_name.c_str());
         
         if (Disassembler::Disassemble (m_interpreter.GetDebugger(), 
-                                       m_options.m_arch,
+                                       m_options.arch,
                                        plugin_name,
                                        exe_ctx,
                                        name,
@@ -278,59 +287,76 @@
     } 
     else
     {
-        Address start_addr;
-        lldb::addr_t range_byte_size = DEFAULT_DISASM_BYTE_SIZE;
-        
-        if (m_options.m_at_pc)
+        AddressRange range;
+        if (m_options.frame_line)
         {
-            if (exe_ctx.frame == NULL)
+            LineEntry pc_line_entry (exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry).line_entry);
+            if (pc_line_entry.IsValid())
             {
-                result.AppendError ("Cannot disassemble around the current PC without a selected frame.\n");
-                result.SetStatus (eReturnStatusFailed);
-                return false;
+                range = pc_line_entry.range;
             }
-            start_addr = exe_ctx.frame->GetFrameCodeAddress();
-            if (m_options.num_instructions == 0)
+            else
             {
-                // Disassembling at the PC always disassembles some number of instructions (not the whole function).
-                m_options.num_instructions = DEFAULT_DISASM_NUM_INS;
+                m_options.at_pc = true; // No line entry, so just disassemble around the current pc
+                m_options.show_mixed = false;
             }
         }
-        else
+
+        // Did the "m_options.frame_line" find a valid range already? If so
+        // skip the rest...
+        if (range.GetByteSize() == 0)
         {
-            start_addr.SetOffset (m_options.m_start_addr);
-            if (start_addr.IsValid())
+            if (m_options.at_pc)
             {
-                if (m_options.m_end_addr != LLDB_INVALID_ADDRESS)
+                if (exe_ctx.frame == NULL)
                 {
-                    if (m_options.m_end_addr < m_options.m_start_addr)
+                    result.AppendError ("Cannot disassemble around the current PC without a selected frame.\n");
+                    result.SetStatus (eReturnStatusFailed);
+                    return false;
+                }
+                range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress();
+                if (m_options.num_instructions == 0)
+                {
+                    // Disassembling at the PC always disassembles some number of instructions (not the whole function).
+                    m_options.num_instructions = DEFAULT_DISASM_NUM_INS;
+                }
+            }
+            else
+            {
+                range.GetBaseAddress().SetOffset (m_options.start_addr);
+                if (range.GetBaseAddress().IsValid())
+                {
+                    if (m_options.end_addr != LLDB_INVALID_ADDRESS)
                     {
-                        result.AppendErrorWithFormat ("End address before start address.\n");
-                        result.SetStatus (eReturnStatusFailed);
-                        return false;            
+                        if (m_options.end_addr <= m_options.start_addr)
+                        {
+                            result.AppendErrorWithFormat ("End address before start address.\n");
+                            result.SetStatus (eReturnStatusFailed);
+                            return false;            
+                        }
+                        range.SetByteSize (m_options.end_addr - m_options.start_addr);
                     }
-                    range_byte_size = m_options.m_end_addr - m_options.m_start_addr;
                 }
             }
         }
         
         if (m_options.num_instructions != 0)
         {
-            if (!start_addr.IsValid())
+            if (!range.GetBaseAddress().IsValid())
             {
                 // The default action is to disassemble the current frame function.
                 if (exe_ctx.frame)
                 {
                     SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
                     if (sc.function)
-                        start_addr = sc.function->GetAddressRange().GetBaseAddress();
+                        range.GetBaseAddress() = sc.function->GetAddressRange().GetBaseAddress();
                     else if (sc.symbol && sc.symbol->GetAddressRangePtr())
-                        start_addr = sc.symbol->GetAddressRangePtr()->GetBaseAddress();
+                        range.GetBaseAddress() = sc.symbol->GetAddressRangePtr()->GetBaseAddress();
                     else
-                        start_addr = exe_ctx.frame->GetFrameCodeAddress();
+                        range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress();
                 }
                 
-                if (!start_addr.IsValid())
+                if (!range.GetBaseAddress().IsValid())
                 {
                     result.AppendError ("invalid frame");
                     result.SetStatus (eReturnStatusFailed);
@@ -339,10 +365,10 @@
             }
 
             if (Disassembler::Disassemble (m_interpreter.GetDebugger(), 
-                                           m_options.m_arch,
+                                           m_options.arch,
                                            plugin_name,
                                            exe_ctx,
-                                           start_addr,
+                                           range.GetBaseAddress(),
                                            m_options.num_instructions,
                                            m_options.show_mixed ? m_options.num_lines_context : 0,
                                            m_options.show_bytes,
@@ -353,19 +379,13 @@
             }
             else
             {
-                result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.m_start_addr);
+                result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.start_addr);
                 result.SetStatus (eReturnStatusFailed);            
             }
         }
         else
         {
-            AddressRange range;
-            if (start_addr.IsValid())
-            {
-                range.GetBaseAddress() = start_addr;
-                range.SetByteSize (range_byte_size);
-            } 
-            else
+            if (!range.GetBaseAddress().IsValid())
             {
                 // The default action is to disassemble the current frame function.
                 if (exe_ctx.frame)
@@ -389,7 +409,7 @@
                 range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
 
             if (Disassembler::Disassemble (m_interpreter.GetDebugger(), 
-                                           m_options.m_arch,
+                                           m_options.arch,
                                            plugin_name,
                                            exe_ctx,
                                            range,
@@ -403,7 +423,7 @@
             }
             else
             {
-                result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.m_start_addr);
+                result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.start_addr);
                 result.SetStatus (eReturnStatusFailed);            
             }
         }