[Lldb-commits] [lldb] r121605 - in /lldb/trunk: include/lldb/API/SBSourceManager.h include/lldb/API/SBStream.h source/API/SBSourceManager.cpp source/API/SBStream.cpp test/source-manager/TestSourceManager.py

Johnny Chen johnny.chen at apple.com
Fri Dec 10 17:20:39 PST 2010


Author: johnny
Date: Fri Dec 10 19:20:39 2010
New Revision: 121605

URL: http://llvm.org/viewvc/llvm-project?rev=121605&view=rev
Log:
Add test_display_source_python() test case to TestSourceManager.py which uses
the lldb PyThon API SBSourceManager to display source files.

To accomodate this, the C++ SBSourceManager API has been changed to take an
lldb::SBStream as the destination for display of source lines.  Modify SBStream::ctor()
so that its opaque pointer is initialized with an StreamString instance.

Modified:
    lldb/trunk/include/lldb/API/SBSourceManager.h
    lldb/trunk/include/lldb/API/SBStream.h
    lldb/trunk/source/API/SBSourceManager.cpp
    lldb/trunk/source/API/SBStream.cpp
    lldb/trunk/test/source-manager/TestSourceManager.py

Modified: lldb/trunk/include/lldb/API/SBSourceManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSourceManager.h?rev=121605&r1=121604&r2=121605&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBSourceManager.h (original)
+++ lldb/trunk/include/lldb/API/SBSourceManager.h Fri Dec 10 19:20:39 2010
@@ -34,7 +34,7 @@
                                        uint32_t context_before,
                                        uint32_t context_after,
                                        const char* current_line_cstr,
-                                       FILE *f);
+                                       lldb::SBStream &s);
 
 
 protected:

Modified: lldb/trunk/include/lldb/API/SBStream.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStream.h?rev=121605&r1=121604&r2=121605&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBStream.h (original)
+++ lldb/trunk/include/lldb/API/SBStream.h Fri Dec 10 19:20:39 2010
@@ -66,6 +66,7 @@
     friend class SBInstruction;
     friend class SBInstructionList;
     friend class SBModule;
+    friend class SBSourceManager;
     friend class SBSymbol;
     friend class SBSymbolContext;
     friend class SBTarget;

Modified: lldb/trunk/source/API/SBSourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSourceManager.cpp?rev=121605&r1=121604&r2=121605&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSourceManager.cpp (original)
+++ lldb/trunk/source/API/SBSourceManager.cpp Fri Dec 10 19:20:39 2010
@@ -9,6 +9,7 @@
 
 
 #include "lldb/API/SBSourceManager.h"
+#include "lldb/API/SBStream.h"
 
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/Core/Stream.h"
@@ -49,26 +50,23 @@
     uint32_t context_before,
     uint32_t context_after,
     const char* current_line_cstr,
-    FILE *f
+    SBStream &s
 )
 {
     if (m_opaque_ptr == NULL)
         return 0;
 
-    if (f == NULL)
+    if (s.m_opaque_ap.get() == NULL)
         return 0;
 
     if (file.IsValid())
     {
-        StreamFile str (f);
-
-
         return m_opaque_ptr->DisplaySourceLinesWithLineNumbers (*file,
                                                                 line,
                                                                 context_before,
                                                                 context_after,
                                                                 current_line_cstr,
-                                                                &str);
+                                                                s.m_opaque_ap.get());
     }
     return 0;
 }

Modified: lldb/trunk/source/API/SBStream.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBStream.cpp?rev=121605&r1=121604&r2=121605&view=diff
==============================================================================
--- lldb/trunk/source/API/SBStream.cpp (original)
+++ lldb/trunk/source/API/SBStream.cpp Fri Dec 10 19:20:39 2010
@@ -17,7 +17,7 @@
 using namespace lldb_private;
 
 SBStream::SBStream () :
-    m_opaque_ap (),
+    m_opaque_ap (new StreamString()),
     m_is_file (false)
 {
 }

Modified: lldb/trunk/test/source-manager/TestSourceManager.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/source-manager/TestSourceManager.py?rev=121605&r1=121604&r2=121605&view=diff
==============================================================================
--- lldb/trunk/test/source-manager/TestSourceManager.py (original)
+++ lldb/trunk/test/source-manager/TestSourceManager.py Fri Dec 10 19:20:39 2010
@@ -3,6 +3,8 @@
 
 Test cases:
 
+o test_display_source_python:
+  Test display of source using the SBSourceManager API.
 o test_modify_source_file_while_debugging:
   Test the caching mechanism of the source manager.
 """
@@ -21,11 +23,53 @@
         # Find the line number to break inside main().
         self.line = line_number('main.c', '// Set break point at this line.')
 
+    @python_api_test
+    def test_display_source_python(self):
+        """Test display of source using the SBSourceManager API."""
+        self.buildDefault()
+        self.display_source_python()
+
     def test_modify_source_file_while_debugging(self):
         """Modify a source file while debugging the executable."""
         self.buildDefault()
         self.modify_source_file_while_debugging()
 
+    def display_source_python(self):
+        """Display source using the SBSourceManager API."""
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target.IsValid(), VALID_TARGET)
+
+        # Launch the process, and do not stop at the entry point.
+        process = target.LaunchProcess([], [], os.ctermid(), 0, False)
+
+        #
+        # Exercise Python APIs to display source lines.
+        #
+
+        # Create the filespec for 'main.c'.
+        filespec = lldb.SBFileSpec('main.c', False)
+        source_mgr = self.dbg.GetSourceManager()
+        # Use a string stream as the destination.
+        stream = lldb.SBStream()
+        source_mgr.DisplaySourceLinesWithLineNumbers(filespec,
+                                                     self.line,
+                                                     2, # context before
+                                                     2, # context after
+                                                     "=>", # prefix for current line
+                                                     stream)
+
+        # 2   	
+        # 3   	int main(int argc, char const *argv[]) {
+        # 4 =>	    printf("Hello world.\n"); // Set break point at this line.
+        # 5   	    return 0;
+        # 6   	}
+        self.expect(stream.GetData(), "Source code displayed correctly",
+                    exe=False,
+            patterns = ['=>.*Hello world'])        
+
     def modify_source_file_while_debugging(self):
         """Modify a source file while debugging the executable."""
         exe = os.path.join(os.getcwd(), "a.out")





More information about the lldb-commits mailing list