[Lldb-commits] [lldb] r111606 - in /lldb/trunk: include/lldb/Symbol/Function.h source/Symbol/Function.cpp

Jim Ingham jingham at apple.com
Thu Aug 19 18:15:02 PDT 2010


Author: jingham
Date: Thu Aug 19 20:15:01 2010
New Revision: 111606

URL: http://llvm.org/viewvc/llvm-project?rev=111606&view=rev
Log:
Add methods to Function to get the first and last source lines of the function, and to get whether this Function is an inlined instance or not.

Modified:
    lldb/trunk/include/lldb/Symbol/Function.h
    lldb/trunk/source/Symbol/Function.cpp

Modified: lldb/trunk/include/lldb/Symbol/Function.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=111606&r1=111605&r2=111606&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Function.h (original)
+++ lldb/trunk/include/lldb/Symbol/Function.h Thu Aug 19 20:15:01 2010
@@ -420,6 +420,44 @@
 
     const AddressRange &
     GetAddressRange();
+    
+    //------------------------------------------------------------------
+    /// Find the file and line number of the source location of the start
+    /// of the function.  This will use the declaration if present and fall
+    /// back on the line table if that fails.  So there may NOT be a line
+    /// table entry for this source file/line combo.
+    ///
+    /// @param[out] source_file
+    ///     The source file.
+    ///
+    /// @param[out] line_no
+    ///     The line number.
+    //------------------------------------------------------------------
+    void
+    GetStartLineSourceInfo (FileSpec &source_file, uint32_t &line_no);
+    
+     //------------------------------------------------------------------
+    /// Find the file and line number of the source location of the end
+    /// of the function.
+    ///
+    ///
+    /// @param[out] source_file
+    ///     The source file.
+    ///
+    /// @param[out] line_no
+    ///     The line number.
+    //------------------------------------------------------------------
+   void
+    GetEndLineSourceInfo (FileSpec &source_file, uint32_t &line_no);
+
+     //------------------------------------------------------------------
+    /// Return whether this Function represents an inlined version of the
+    /// original function.
+    ///
+    /// @return
+    ///     \b true if inlined, \b false otherwise.
+    //------------------------------------------------------------------
+    bool IsInlined();
 
     //------------------------------------------------------------------
     /// Get accessor for the block list.

Modified: lldb/trunk/source/Symbol/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Function.cpp?rev=111606&r1=111605&r2=111606&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Function.cpp (original)
+++ lldb/trunk/source/Symbol/Function.cpp Thu Aug 19 20:15:01 2010
@@ -237,6 +237,70 @@
     return GetBlocks(true).GetAddressRange();
 }
 
+bool
+Function::IsInlined()
+{
+    Block *root_block = GetBlocks(true).GetBlockByID(Block::RootID);
+    if (root_block)
+    {
+        if (root_block->InlinedFunctionInfo() != NULL)
+            return true;
+    }
+    return false;
+
+}
+void
+Function::GetStartLineSourceInfo (FileSpec &source_file, uint32_t &line_no)
+{
+    line_no = 0;
+    source_file.Clear();
+    
+    if (m_comp_unit == NULL)
+        return;
+        
+    if (m_type != NULL && m_type->GetDeclaration().GetLine() != 0)
+    {
+        source_file = m_type->GetDeclaration().GetFile();
+        line_no = m_type->GetDeclaration().GetLine();
+    }
+    else 
+    {
+        LineTable *line_table = m_comp_unit->GetLineTable();
+        if (line_table == NULL)
+            return;
+            
+        LineEntry line_entry;
+        if (line_table->FindLineEntryByAddress (GetAddressRange().GetBaseAddress(), line_entry, NULL))
+        {
+            line_no = line_entry.line;
+            source_file = line_entry.file;
+        }
+    }
+}
+
+void
+Function::GetEndLineSourceInfo (FileSpec &source_file, uint32_t &line_no)
+{
+    line_no = 0;
+    source_file.Clear();
+    
+    // The -1 is kind of cheesy, but I want to get the last line entry for the given function, not the 
+    // first entry of the next.
+    Address scratch_addr(GetAddressRange().GetBaseAddress());
+    scratch_addr.SetOffset (scratch_addr.GetOffset() + GetAddressRange().GetByteSize() - 1);
+    
+    LineTable *line_table = m_comp_unit->GetLineTable();
+    if (line_table == NULL)
+        return;
+        
+    LineEntry line_entry;
+    if (line_table->FindLineEntryByAddress (scratch_addr, line_entry, NULL))
+    {
+        line_no = line_entry.line;
+        source_file = line_entry.file;
+    }
+}
+
 BlockList &
 Function::GetBlocks(bool can_create)
 {





More information about the lldb-commits mailing list