summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/API/SBTarget.cpp4
-rw-r--r--lldb/test/hello_world/TestHelloWorld.py43
-rw-r--r--lldb/test/hello_world/main.c13
3 files changed, 57 insertions, 3 deletions
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 629308f7cfb..78b67db3b0c 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -290,6 +290,10 @@ SBTarget::AttachToProcessWithID
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
{
diff --git a/lldb/test/hello_world/TestHelloWorld.py b/lldb/test/hello_world/TestHelloWorld.py
index f5ba6923dab..0fc5d541db2 100644
--- a/lldb/test/hello_world/TestHelloWorld.py
+++ b/lldb/test/hello_world/TestHelloWorld.py
@@ -27,6 +27,22 @@ class HelloWorldTestCase(TestBase):
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 @@ class HelloWorldTestCase(TestBase):
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 @@ class HelloWorldTestCase(TestBase):
# 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
diff --git a/lldb/test/hello_world/main.c b/lldb/test/hello_world/main.c
index 277aa54a4ee..dffc8c77b04 100644
--- a/lldb/test/hello_world/main.c
+++ b/lldb/test/hello_world/main.c
@@ -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");
}
OpenPOWER on IntegriCloud