[Lldb-commits] [lldb] r241482 - Add a GetDisplayName() API to SBFrame, SBFunction and SBSymbol

Enrico Granata egranata at apple.com
Mon Jul 6 11:28:46 PDT 2015


Author: enrico
Date: Mon Jul  6 13:28:46 2015
New Revision: 241482

URL: http://llvm.org/viewvc/llvm-project?rev=241482&view=rev
Log:
Add a GetDisplayName() API to SBFrame, SBFunction and SBSymbol

This API is currently a no-op (in the sense that it has the same behavior as the already existing GetName()), but is meant long-term to provide a best-for-visualization version of the name of a function

It is still not hooked up to the command line 'bt' command, nor to the 'gui' mode, but I do have ideas on how to make that work going forward

rdar://21203242


Modified:
    lldb/trunk/include/lldb/API/SBFrame.h
    lldb/trunk/include/lldb/API/SBFunction.h
    lldb/trunk/include/lldb/API/SBSymbol.h
    lldb/trunk/include/lldb/Core/Mangled.h
    lldb/trunk/include/lldb/Symbol/Function.h
    lldb/trunk/include/lldb/Symbol/Symbol.h
    lldb/trunk/scripts/interface/SBFrame.i
    lldb/trunk/scripts/interface/SBFunction.i
    lldb/trunk/scripts/interface/SBSymbol.i
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/source/API/SBFunction.cpp
    lldb/trunk/source/API/SBSymbol.cpp
    lldb/trunk/source/Core/Mangled.cpp
    lldb/trunk/source/Symbol/Function.cpp
    lldb/trunk/source/Symbol/Symbol.cpp

Modified: lldb/trunk/include/lldb/API/SBFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFrame.h (original)
+++ lldb/trunk/include/lldb/API/SBFrame.h Mon Jul  6 13:28:46 2015
@@ -90,6 +90,10 @@ public:
     /// See also IsInlined().
     const char *
     GetFunctionName();
+    
+    // Get an appropriate function name for this frame that is suitable for display to a user
+    const char *
+    GetDisplayFunctionName ();
 
     const char *
     GetFunctionName() const;

Modified: lldb/trunk/include/lldb/API/SBFunction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFunction.h?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFunction.h (original)
+++ lldb/trunk/include/lldb/API/SBFunction.h Mon Jul  6 13:28:46 2015
@@ -36,6 +36,9 @@ public:
     GetName() const;
 
     const char *
+    GetDisplayName() const;
+    
+    const char *
     GetMangledName () const;
 
     lldb::SBInstructionList

Modified: lldb/trunk/include/lldb/API/SBSymbol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSymbol.h?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBSymbol.h (original)
+++ lldb/trunk/include/lldb/API/SBSymbol.h Mon Jul  6 13:28:46 2015
@@ -38,6 +38,9 @@ public:
     GetName() const;
 
     const char *
+    GetDisplayName() const;
+    
+    const char *
     GetMangledName () const;
 
     lldb::SBInstructionList

Modified: lldb/trunk/include/lldb/Core/Mangled.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Mangled.h?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Mangled.h (original)
+++ lldb/trunk/include/lldb/Core/Mangled.h Mon Jul  6 13:28:46 2015
@@ -184,6 +184,15 @@ public:
     const ConstString&
     GetDemangledName () const;
 
+    //----------------------------------------------------------------------
+    /// Display demangled name get accessor.
+    ///
+    /// @return
+    ///     A const reference to the display demangled name string object.
+    //----------------------------------------------------------------------
+    ConstString
+    GetDisplayDemangledName () const;
+    
     void
     SetDemangledName (const ConstString &name)
     {

Modified: lldb/trunk/include/lldb/Symbol/Function.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Function.h (original)
+++ lldb/trunk/include/lldb/Symbol/Function.h Mon Jul  6 13:28:46 2015
@@ -245,6 +245,9 @@ public:
     const ConstString &
     GetName () const;
 
+    ConstString
+    GetDisplayName () const;
+    
     //------------------------------------------------------------------
     /// Get accessor for the call site declaration information.
     ///
@@ -529,6 +532,9 @@ public:
     {
         return m_mangled.GetName();
     }
+    
+    ConstString
+    GetDisplayName () const;
 
     const Mangled &
     GetMangled() const

Modified: lldb/trunk/include/lldb/Symbol/Symbol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symbol.h?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Symbol.h (original)
+++ lldb/trunk/include/lldb/Symbol/Symbol.h Mon Jul  6 13:28:46 2015
@@ -158,6 +158,9 @@ public:
         return m_mangled.GetName();
     }
 
+    ConstString
+    GetDisplayName () const;
+    
     uint32_t
     GetID() const
     {

Modified: lldb/trunk/scripts/interface/SBFrame.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBFrame.i?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBFrame.i (original)
+++ lldb/trunk/scripts/interface/SBFrame.i Mon Jul  6 13:28:46 2015
@@ -127,6 +127,9 @@ public:
     ") GetFunctionName;
     const char *
     GetFunctionName();
+             
+     const char *
+     GetDisplayFunctionName ();
 
     const char *
     GetFunctionName() const;

Modified: lldb/trunk/scripts/interface/SBFunction.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBFunction.i?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBFunction.i (original)
+++ lldb/trunk/scripts/interface/SBFunction.i Mon Jul  6 13:28:46 2015
@@ -58,6 +58,9 @@ public:
 
     const char *
     GetName() const;
+    
+    const char *
+    GetDisplayName() const;
 
     const char *
     GetMangledName () const;

Modified: lldb/trunk/scripts/interface/SBSymbol.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBSymbol.i?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBSymbol.i (original)
+++ lldb/trunk/scripts/interface/SBSymbol.i Mon Jul  6 13:28:46 2015
@@ -33,6 +33,9 @@ public:
     GetName() const;
 
     const char *
+    GetDisplayName() const;
+    
+    const char *
     GetMangledName () const;
 
     lldb::SBInstructionList

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Mon Jul  6 13:28:46 2015
@@ -1602,3 +1602,59 @@ SBFrame::GetFunctionName() const
     }
     return name;
 }
+
+const char *
+SBFrame::GetDisplayFunctionName()
+{
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    const char *name = NULL;
+    ExecutionContext exe_ctx(m_opaque_sp.get());
+    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)
+            {
+                SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
+                if (sc.block)
+                {
+                    Block *inlined_block = sc.block->GetContainingInlinedBlock ();
+                    if (inlined_block)
+                    {
+                        const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
+                        name = inlined_info->GetDisplayName().AsCString();
+                    }
+                }
+                
+                if (name == NULL)
+                {
+                    if (sc.function)
+                        name = sc.function->GetDisplayName().GetCString();
+                }
+                
+                if (name == NULL)
+                {
+                    if (sc.symbol)
+                        name = sc.symbol->GetDisplayName().GetCString();
+                }
+            }
+            else
+            {
+                if (log)
+                    log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame.");
+            }
+        }
+        else
+        {
+            if (log)
+                log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running");
+            
+        }
+    }
+    return name;
+}

Modified: lldb/trunk/source/API/SBFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFunction.cpp?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFunction.cpp (original)
+++ lldb/trunk/source/API/SBFunction.cpp Mon Jul  6 13:28:46 2015
@@ -76,6 +76,26 @@ SBFunction::GetName() const
 }
 
 const char *
+SBFunction::GetDisplayName() const
+{
+    const char *cstr = NULL;
+    if (m_opaque_ptr)
+    cstr = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
+    
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+    {
+        if (cstr)
+        log->Printf ("SBFunction(%p)::GetDisplayName () => \"%s\"",
+                     static_cast<void*>(m_opaque_ptr), cstr);
+        else
+        log->Printf ("SBFunction(%p)::GetDisplayName () => NULL",
+                     static_cast<void*>(m_opaque_ptr));
+    }
+    return cstr;
+}
+
+const char *
 SBFunction::GetMangledName () const
 {
     const char *cstr = NULL;

Modified: lldb/trunk/source/API/SBSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbol.cpp?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSymbol.cpp (original)
+++ lldb/trunk/source/API/SBSymbol.cpp Mon Jul  6 13:28:46 2015
@@ -73,6 +73,20 @@ SBSymbol::GetName() const
 }
 
 const char *
+SBSymbol::GetDisplayName() const
+{
+    const char *name = NULL;
+    if (m_opaque_ptr)
+    name = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
+    
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+    log->Printf ("SBSymbol(%p)::GetDisplayName () => \"%s\"",
+                 static_cast<void*>(m_opaque_ptr), name ? name : "");
+    return name;
+}
+
+const char *
 SBSymbol::GetMangledName () const
 {
     const char *name = NULL;

Modified: lldb/trunk/source/Core/Mangled.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Mangled.cpp?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/source/Core/Mangled.cpp (original)
+++ lldb/trunk/source/Core/Mangled.cpp Mon Jul  6 13:28:46 2015
@@ -339,6 +339,12 @@ Mangled::GetDemangledName () const
 }
 
 
+ConstString
+Mangled::GetDisplayDemangledName () const
+{
+    return GetDemangledName();
+}
+
 bool
 Mangled::NameMatches (const RegularExpression& regex) const
 {

Modified: lldb/trunk/source/Symbol/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Function.cpp?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Function.cpp (original)
+++ lldb/trunk/source/Symbol/Function.cpp Mon Jul  6 13:28:46 2015
@@ -159,6 +159,13 @@ InlineFunctionInfo::GetName () const
     return m_name;
 }
 
+ConstString
+InlineFunctionInfo::GetDisplayName () const
+{
+    if (m_mangled)
+        return m_mangled.GetDisplayDemangledName();
+    return m_name;
+}
 
 Declaration &
 InlineFunctionInfo::GetCallSite ()
@@ -459,6 +466,14 @@ Function::MemorySize () const
     return mem_size;
 }
 
+ConstString
+Function::GetDisplayName () const
+{
+    if (!m_mangled)
+        return ConstString();
+    return m_mangled.GetDisplayDemangledName();
+}
+
 clang::DeclContext *
 Function::GetClangDeclContext()
 {

Modified: lldb/trunk/source/Symbol/Symbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=241482&r1=241481&r2=241482&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symbol.cpp (original)
+++ lldb/trunk/source/Symbol/Symbol.cpp Mon Jul  6 13:28:46 2015
@@ -185,6 +185,14 @@ Symbol::ValueIsAddress() const
 }
 
 ConstString
+Symbol::GetDisplayName () const
+{
+    if (!m_mangled)
+        return ConstString();
+    return m_mangled.GetDisplayDemangledName();
+}
+
+ConstString
 Symbol::GetReExportedSymbolName() const
 {
     if (m_type == eSymbolTypeReExported)





More information about the lldb-commits mailing list