[Lldb-commits] [lldb] r133223 - in /lldb/trunk: source/API/SBTarget.cpp test/hello_world/TestHelloWorld.py test/hello_world/main.c

Johnny Chen johnny.chen at apple.com
Thu Jun 16 17:51:15 PDT 2011


Author: johnny
Date: Thu Jun 16 19:51:15 2011
New Revision: 133223

URL: http://llvm.org/viewvc/llvm-project?rev=133223&view=rev
Log:
o TestHelloWorld.py:

  Add a test case for the SBTarget::AttachToProcessWithID() API call.

o main.c:

  The change goes with the added test case test_with_dwarf_and_attach_to_process_with_id_api() above.

o SBTarget.cpp:

  Checks whether we're in synchronous mode.  If yes, let's wait for the process to stop right after attaching.

Modified:
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/test/hello_world/TestHelloWorld.py
    lldb/trunk/test/hello_world/main.c

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=133223&r1=133222&r2=133223&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Thu Jun 16 19:51:15 2011
@@ -290,6 +290,10 @@
         if (sb_process.IsValid())
         {
             error.SetError (sb_process->Attach (pid));
+            // If we are doing synchronous mode, then wait for the
+            // process to stop!
+            if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
+                sb_process->WaitForProcessToStop (NULL);
         }
         else
         {

Modified: lldb/trunk/test/hello_world/TestHelloWorld.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/TestHelloWorld.py?rev=133223&r1=133222&r2=133223&view=diff
==============================================================================
--- lldb/trunk/test/hello_world/TestHelloWorld.py (original)
+++ lldb/trunk/test/hello_world/TestHelloWorld.py Thu Jun 16 19:51:15 2011
@@ -27,6 +27,22 @@
         self.buildDwarf()
         self.hello_world_python(useLaunchAPI = True)
 
+    @python_api_test
+    def test_with_dwarf_and_attach_to_process_with_id_api(self):
+        """Create target, breakpoint, start a process, and attach to it.
+
+        Use dwarf map (no dsym) and attach to process with id API.
+        """
+        self.buildDwarf()
+        self.hello_world_attach_api()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find a couple of the line numbers within main.c.
+        self.line1 = line_number('main.c', '// Set break point at this line.')
+        self.line2 = line_number('main.c', '// Waiting to be attached...')
+
     def hello_world_python(self, useLaunchAPI):
         """Create target, breakpoint, launch a process, and then kill it."""
 
@@ -34,7 +50,7 @@
 
         target = self.dbg.CreateTarget(exe)
 
-        breakpoint = target.BreakpointCreateByLocation("main.c", 4)
+        breakpoint = target.BreakpointCreateByLocation("main.c", self.line1)
 
         # The default state after breakpoint creation should be enabled.
         self.assertTrue(breakpoint.IsEnabled(),
@@ -74,6 +90,31 @@
         # The breakpoint should have a hit count of 1.
         self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
 
+    def hello_world_attach_api(self):
+        """Create target, breakpoint, start a process, and attach to it."""
+
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        target = self.dbg.CreateTarget(exe)
+
+        # Spawn a new process.
+        import subprocess
+        popen = subprocess.Popen([exe, "abc", "xyz"])
+        #print "pid of spawned process: %d" % popen.pid
+
+        listener = lldb.SBListener("my.attach.listener")
+        error = lldb.SBError()
+        process = target.AttachToProcessWithID(listener, popen.pid, error)
+
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+        # Let's check the stack traces of the attached process.
+        import lldbutil
+        stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
+        self.expect(stacktraces, exe=False,
+            substrs = ['main.c:%d' % self.line2,
+                       '(int)argc=3'])
+
 
 if __name__ == '__main__':
     import atexit

Modified: lldb/trunk/test/hello_world/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/main.c?rev=133223&r1=133222&r2=133223&view=diff
==============================================================================
--- lldb/trunk/test/hello_world/main.c (original)
+++ lldb/trunk/test/hello_world/main.c Thu Jun 16 19:51:15 2011
@@ -1,6 +1,15 @@
 #include <stdio.h>
 
 int main(int argc, char const *argv[]) {
-    printf("Hello world.\n");
-    return 0;
+    printf("Hello world.\n"); // Set break point at this line.
+    if (argc == 1)
+        return 0;
+
+    // Waiting to be attached by the debugger, otherwise.
+    char line[100];
+    while (fgets(line, sizeof(line), stdin)) { // Waiting to be attached...
+        printf("input line=>%s\n", line);
+    }
+
+    printf("Exiting now\n");
 }





More information about the lldb-commits mailing list