Add an SBFrame::FindRegister() method to make it a little
easier to retrieve a register value.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@187184 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lldb/API/SBFrame.h b/include/lldb/API/SBFrame.h
index f8e86be..4ae38c1 100644
--- a/include/lldb/API/SBFrame.h
+++ b/include/lldb/API/SBFrame.h
@@ -159,6 +159,9 @@
     lldb::SBValueList
     GetRegisters ();
 
+    lldb::SBValue
+    FindRegister (const char *name);
+
     /// The version that doesn't supply a 'use_dynamic' value will use the
     /// target's default.
     lldb::SBValue
diff --git a/scripts/Python/interface/SBFrame.i b/scripts/Python/interface/SBFrame.i
index 1735dd9..8f36cec 100644
--- a/scripts/Python/interface/SBFrame.i
+++ b/scripts/Python/interface/SBFrame.i
@@ -211,6 +211,9 @@
     lldb::SBValue
     FindVariable (const char *var_name, lldb::DynamicValueType use_dynamic);
 
+    lldb::SBValue
+    FindRegister (const char *name);
+
     %feature("docstring", "
     /// Get a lldb.SBValue for a variable path. 
     ///
diff --git a/source/API/SBFrame.cpp b/source/API/SBFrame.cpp
index 2822060..409603a 100644
--- a/source/API/SBFrame.cpp
+++ b/source/API/SBFrame.cpp
@@ -1214,6 +1214,64 @@
     return value_list;
 }
 
+SBValue
+SBFrame::FindRegister (const char *name)
+{
+    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+    SBValue result;
+    ValueObjectSP value_sp;
+    Mutex::Locker api_locker;
+    ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
+
+    StackFrame *frame = NULL;
+    Target *target = exe_ctx.GetTargetPtr();
+    Process *process = exe_ctx.GetProcessPtr();
+    if (target && process)
+    {
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&process->GetRunLock()))
+        {
+            frame = exe_ctx.GetFramePtr();
+            if (frame)
+            {
+                RegisterContextSP reg_ctx (frame->GetRegisterContext());
+                if (reg_ctx)
+                {
+                    const uint32_t num_regs = reg_ctx->GetRegisterCount();
+                    for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
+                    {
+                        const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
+                        if (reg_info && 
+                            ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
+                             (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
+                        {
+                            value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
+                            result.SetSP (value_sp);
+                            break;
+                        }
+                    }
+                }
+            }
+            else
+            {
+                if (log)
+                    log->Printf ("SBFrame::GetRegisterByName () => error: could not reconstruct frame object for this SBFrame.");
+            }
+        }
+        else
+        {
+            if (log)
+                log->Printf ("SBFrame::GetRegisterByName () => error: process is running");
+        }            
+    }
+
+    if (log)
+        log->Printf ("SBFrame(%p)::GetRegisterByName () => SBValue(%p)", frame, value_sp.get());
+
+    return result;
+}
+
 bool
 SBFrame::GetDescription (SBStream &description)
 {
diff --git a/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp b/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp
index 330a818..a904d8b 100644
--- a/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp
+++ b/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp
@@ -1187,6 +1187,7 @@
 // "System V Application Binary Interface"
 // "AMD64 Architecture Processor Supplement" 
 // (or "x86-64(tm) Architecture Processor Supplement" in earlier revisions)
+// (this doc is also commonly referred to as the x86-64/AMD64 psABI)
 // Edited by Michael Matz, Jan Hubicka, Andreas Jaeger, and Mark Mitchell
 // current version is 0.99.6 released 2012-07-02 at http://refspecs.linuxfoundation.org/elf/x86-64-abi-0.99.pdf