Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
ENABLE_THREADS := YES
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,114 @@
"""
Test lldb watchpoint that uses '-s size' to watch a pointed location with size.
"""
from __future__ import print_function
import os
import time
import re
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class HelloWatchLocationTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Our simple source filename.
self.source = 'main.cpp'
# Find the line number to break inside main().
self.line = line_number(
self.source, '// Set break point at this line.')
# This is for verifying that watch location works.
self.violating_func = "do_bad_thing_with_location"
# Build dictionary to have unique executable names for each test
# method.
self.exe_name = self.testMethodName
self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
# Most of the MIPS boards provide only one H/W watchpoints, and S/W
# watchpoints are not supported yet
@expectedFailureAll(triple=re.compile('^mips'))
# SystemZ also currently supports only one H/W watchpoint
@expectedFailureAll(archs=['s390x'])
@skipIfDarwin
def test_hello_watchlocation(self):
"""Test watching a location with '-s size' option."""
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = os.path.join(os.getcwd(), self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1, loc_exact=False)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a write-type watchpoint pointed to by 'g_char_ptr'.
self.expect(
"watchpoint set expression -w write -s 1 -- g_char_ptr",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 1',
'type = w'])
# Get a hold of the watchpoint id just created, it is used later on to
# match the watchpoint id which is expected to be fired.
match = re.match(
"Watchpoint created: Watchpoint (.*):",
self.res.GetOutput().splitlines()[0])
if match:
expected_wp_id = int(match.group(1), 0)
else:
self.fail("Grokking watchpoint id faailed!")
self.runCmd("expr unsigned val = *g_char_ptr; val")
self.expect(self.res.GetOutput().splitlines()[0], exe=False,
endstr=' = 0')
self.runCmd("watchpoint set expression -w write -s 4 -- &threads[0]")
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v",
substrs=['hit_count = 0'])
self.runCmd("process continue")
# We should be stopped again due to the watchpoint (write type), but
# only once. The stop reason of the thread should be watchpoint.
self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stopped',
'stop reason = watchpoint %d' % expected_wp_id])
# Switch to the thread stopped due to watchpoint and issue some
# commands.
self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
self.runCmd("thread backtrace")
self.expect("frame info",
substrs=[self.violating_func])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should now be 1.
self.expect("watchpoint list -v",
substrs=['hit_count = 1'])
self.runCmd("thread backtrace all")

View File

@ -0,0 +1,104 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <chrono>
#include <condition_variable>
#include <cstdio>
#include <random>
#include <thread>
std::default_random_engine g_random_engine{std::random_device{}()};
std::uniform_int_distribution<> g_distribution{0, 3000000};
std::condition_variable g_condition_variable;
std::mutex g_mutex;
int g_count;
char *g_char_ptr = nullptr;
void
barrier_wait()
{
std::unique_lock<std::mutex> lock{g_mutex};
if (--g_count > 0)
g_condition_variable.wait(lock);
else
g_condition_variable.notify_all();
}
void
do_bad_thing_with_location(char *char_ptr, char new_val)
{
unsigned what = new_val;
printf("new value written to location(%p) = %u\n", char_ptr, what);
*char_ptr = new_val;
}
uint32_t
access_pool (bool flag = false)
{
static std::mutex g_access_mutex;
g_access_mutex.lock();
char old_val = *g_char_ptr;
if (flag)
do_bad_thing_with_location(g_char_ptr, old_val + 1);
g_access_mutex.unlock();
return *g_char_ptr;
}
void
thread_func (uint32_t thread_index)
{
printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index);
barrier_wait();
uint32_t count = 0;
uint32_t val;
while (count++ < 15)
{
// random micro second sleep from zero to 3 seconds
int usec = g_distribution(g_random_engine);
printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec);
std::this_thread::sleep_for(std::chrono::microseconds{usec});
if (count < 7)
val = access_pool ();
else
val = access_pool (true);
printf ("%s (thread = %u) after usleep access_pool returns %d (count=%d)...\n", __FUNCTION__, thread_index, val, count);
}
printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index);
}
int main (int argc, char const *argv[])
{
g_count = 4;
std::thread threads[3];
g_char_ptr = new char{};
// Create 3 threads
for (auto &thread : threads)
thread = std::thread{thread_func, std::distance(threads, &thread)};
printf ("Before turning all three threads loose...\n"); // Set break point at this line.
barrier_wait();
// Join all of our threads
for (auto &thread : threads)
thread.join();
delete g_char_ptr;
return 0;
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
C_SOURCES := main.c
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,97 @@
"""
Test my first lldb watchpoint.
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class HelloWatchpointTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Our simple source filename.
self.source = 'main.c'
# Find the line number to break inside main().
self.line = line_number(
self.source, '// Set break point at this line.')
# And the watchpoint variable declaration line number.
self.decl = line_number(self.source,
'// Watchpoint variable declaration.')
self.exe_name = 'a.out'
self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
@add_test_categories(["basic_process"])
def test_hello_watchpoint_using_watchpoint_set(self):
"""Test a simple sequence of watchpoint creation and watchpoint hit."""
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = os.path.join(os.getcwd(), self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a write-type watchpoint for 'global'.
# There should be only one watchpoint hit (see main.c).
self.expect(
"watchpoint set variable -w write global",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = w',
'%s:%d' %
(self.source,
self.decl)])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v",
substrs=['hit_count = 0'])
self.runCmd("process continue")
# We should be stopped again due to the watchpoint (write type), but
# only once. The stop reason of the thread should be watchpoint.
self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stopped',
'stop reason = watchpoint'])
self.runCmd("process continue")
# Don't expect the read of 'global' to trigger a stop exception.
process = self.dbg.GetSelectedTarget().GetProcess()
if process.GetState() == lldb.eStateStopped:
self.assertFalse(
lldbutil.get_stopped_thread(
process, lldb.eStopReasonWatchpoint))
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should now be 1.
self.expect("watchpoint list -v",
substrs=['hit_count = 1'])

View File

@ -0,0 +1,30 @@
//===-- main.c --------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <stdint.h>
int32_t global = 10; // Watchpoint variable declaration.
char gchar1 = 'a';
char gchar2 = 'b';
int main(int argc, char** argv) {
int local = 0;
printf("&global=%p\n", &global);
printf("about to write to 'global'...\n"); // Set break point at this line.
// When stopped, watch 'global' for write.
global = 20;
gchar1 += 1;
gchar2 += 1;
local += argc;
++local;
printf("local: %d\n", local);
printf("global=%d\n", global);
printf("gchar1='%c'\n", gchar1);
printf("gchar2='%c'\n", gchar2);
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
C_SOURCES := main.c
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,103 @@
"""
Test watchpoint slots we should not be able to install multiple watchpoints
within same word boundary. We should be able to install individual watchpoints
on any of the bytes, half-word, or word. This is only for ARM/AArch64 targets.
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class WatchpointSlotsTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Source filename.
self.source = 'main.c'
# Output filename.
self.exe_name = 'a.out'
self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
# This is a arm and aarch64 specific test case. No other architectures tested.
@skipIf(archs=no_match(['arm', 'aarch64']))
def test_multiple_watchpoints_on_same_word(self):
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = os.path.join(os.getcwd(), self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Detect line number after which we are going to increment arrayName.
loc_line = line_number('main.c', '// About to write byteArray')
# Set a breakpoint on the line detected above.
lldbutil.run_break_set_by_file_and_line(
self, "main.c", loc_line, num_expected_locations=1, loc_exact=True)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped', 'stop reason = breakpoint'])
# Delete breakpoint we just hit.
self.expect("breakpoint delete 1", substrs=['1 breakpoints deleted'])
# Set a watchpoint at byteArray[0]
self.expect("watchpoint set variable byteArray[0]", WATCHPOINT_CREATED,
substrs=['Watchpoint created','size = 1'])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v 1", substrs=['hit_count = 0'])
# debugserver on ios doesn't give an error, it creates another watchpoint,
# only expect errors on non-darwin platforms.
if not self.platformIsDarwin():
# Try setting a watchpoint at byteArray[1]
self.expect("watchpoint set variable byteArray[1]", error=True,
substrs=['Watchpoint creation failed'])
self.runCmd("process continue")
# We should be stopped due to the watchpoint.
# The stop reason of the thread should be watchpoint.
self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stopped', 'stop reason = watchpoint 1'])
# Delete the watchpoint we hit above successfully.
self.expect("watchpoint delete 1", substrs=['1 watchpoints deleted'])
# Set a watchpoint at byteArray[3]
self.expect("watchpoint set variable byteArray[3]", WATCHPOINT_CREATED,
substrs=['Watchpoint created','size = 1'])
# Resume inferior.
self.runCmd("process continue")
# We should be stopped due to the watchpoint.
# The stop reason of the thread should be watchpoint.
if self.platformIsDarwin():
# On darwin we'll hit byteArray[3] which is watchpoint 2
self.expect("thread list -v", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stopped', 'stop reason = watchpoint 2'])
else:
self.expect("thread list -v", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stopped', 'stop reason = watchpoint 3'])
# Resume inferior.
self.runCmd("process continue")

View File

@ -0,0 +1,29 @@
//===-- main.c --------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <stdint.h>
uint64_t pad0 = 0;
uint8_t byteArray[4] = {0};
uint64_t pad1 = 0;
int main(int argc, char** argv) {
int i;
for (i = 0; i < 4; i++)
{
printf("About to write byteArray[%d] ...\n", i); // About to write byteArray
pad0++;
byteArray[i] = 7;
pad1++;
}
return 0;
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,58 @@
"""
Test handling of cases when a single instruction triggers multiple watchpoints
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MultipleHitsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
@skipIf(bugnumber="llvm.org/pr30758", oslist=["linux"], archs=["arm", "aarch64"])
def test(self):
self.build()
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target and target.IsValid(), VALID_TARGET)
bp = target.BreakpointCreateByName("main")
self.assertTrue(bp and bp.IsValid(), "Breakpoint is valid")
process = target.LaunchSimple(None, None,
self.get_process_working_directory())
self.assertEqual(process.GetState(), lldb.eStateStopped)
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
self.assertIsNotNone(thread)
frame = thread.GetFrameAtIndex(0)
self.assertTrue(frame and frame.IsValid(), "Frame is valid")
buf = frame.FindValue("buf", lldb.eValueTypeVariableGlobal)
self.assertTrue(buf and buf.IsValid(), "buf is valid")
for i in [0, target.GetAddressByteSize()]:
member = buf.GetChildAtIndex(i)
self.assertTrue(member and member.IsValid(), "member is valid")
error = lldb.SBError()
watch = member.Watch(True, True, True, error)
self.assertTrue(error.Success())
process.Continue();
self.assertEqual(process.GetState(), lldb.eStateStopped)
self.assertEqual(thread.GetStopReason(), lldb.eStopReasonWatchpoint)

View File

@ -0,0 +1,29 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <stdint.h>
alignas(16) uint8_t buf[32];
// This uses inline assembly to generate an instruction that writes to a large
// block of memory. If it fails on your compiler/architecture, please add
// appropriate code to generate a large write to "buf". If you cannot write at
// least 2*sizeof(void*) bytes with a single instruction, you will have to skip
// this test.
int main() {
#if defined(__i386__) || defined(__x86_64__)
asm volatile ("movdqa %%xmm0, %0" : : "m"(buf));
#elif defined(__arm__)
asm volatile ("stm %0, { r0, r1, r2, r3 }" : : "r"(buf));
#elif defined(__aarch64__)
asm volatile ("stp x0, x1, %0" : : "m"(buf));
#elif defined(__mips__)
asm volatile ("lw $2, %0" : : "m"(buf));
#endif
return 0;
}

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
ENABLE_THREADS := YES
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,162 @@
"""
Test that lldb watchpoint works for multiple threads.
"""
from __future__ import print_function
import os
import time
import re
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class WatchpointForMultipleThreadsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
def test_watchpoint_multiple_threads(self):
"""Test that lldb watchpoint works for multiple threads."""
self.build()
self.setTearDownCleanup()
self.hello_multiple_threads()
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
def test_watchpoint_multiple_threads_wp_set_and_then_delete(self):
"""Test that lldb watchpoint works for multiple threads, and after the watchpoint is deleted, the watchpoint event should no longer fires."""
self.build()
self.setTearDownCleanup()
self.hello_multiple_threads_wp_set_and_then_delete()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Our simple source filename.
self.source = 'main.cpp'
# Find the line number to break inside main().
self.first_stop = line_number(
self.source, '// Set break point at this line')
def hello_multiple_threads(self):
"""Test that lldb watchpoint works for multiple threads."""
self.runCmd(
"file %s" %
os.path.join(
os.getcwd(),
'a.out'),
CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.first_stop, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a write-type watchpoint for variable 'g_val'.
self.expect(
"watchpoint set variable -w write g_val",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = w'])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v",
substrs=['hit_count = 0'])
while True:
self.runCmd("process continue")
self.runCmd("thread list")
if "stop reason = watchpoint" in self.res.GetOutput():
# Good, we verified that the watchpoint works!
self.runCmd("thread backtrace all")
break
else:
self.fail("The stop reason should be either break or watchpoint")
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should now be 1.
self.expect("watchpoint list -v",
substrs=['hit_count = 1'])
def hello_multiple_threads_wp_set_and_then_delete(self):
"""Test that lldb watchpoint works for multiple threads, and after the watchpoint is deleted, the watchpoint event should no longer fires."""
self.runCmd(
"file %s" %
os.path.join(
os.getcwd(),
'a.out'),
CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.first_stop, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a write-type watchpoint for variable 'g_val'.
self.expect(
"watchpoint set variable -w write g_val",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = w'])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v",
substrs=['hit_count = 0'])
watchpoint_stops = 0
while True:
self.runCmd("process continue")
self.runCmd("process status")
if re.search("Process .* exited", self.res.GetOutput()):
# Great, we are done with this test!
break
self.runCmd("thread list")
if "stop reason = watchpoint" in self.res.GetOutput():
self.runCmd("thread backtrace all")
watchpoint_stops += 1
if watchpoint_stops > 1:
self.fail(
"Watchpoint hits not supposed to exceed 1 by design!")
# Good, we verified that the watchpoint works! Now delete the
# watchpoint.
if self.TraceOn():
print(
"watchpoint_stops=%d at the moment we delete the watchpoint" %
watchpoint_stops)
self.runCmd("watchpoint delete 1")
self.expect("watchpoint list -v",
substrs=['No watchpoints currently set.'])
continue
else:
self.fail("The stop reason should be either break or watchpoint")

View File

@ -0,0 +1,79 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <chrono>
#include <cstdio>
#include <mutex>
#include <random>
#include <thread>
std::default_random_engine g_random_engine{std::random_device{}()};
std::uniform_int_distribution<> g_distribution{0, 3000000};
uint32_t g_val = 0;
uint32_t
access_pool (bool flag = false)
{
static std::mutex g_access_mutex;
g_access_mutex.lock();
uint32_t old_val = g_val;
if (flag)
{
printf("changing g_val to %d...\n", old_val + 1);
g_val = old_val + 1;
}
g_access_mutex.unlock();
return g_val;
}
void
thread_func (uint32_t thread_index)
{
printf ("%s (thread index = %u) starting...\n", __FUNCTION__, thread_index);
uint32_t count = 0;
uint32_t val;
while (count++ < 15)
{
// random micro second sleep from zero to 3 seconds
int usec = g_distribution(g_random_engine);
printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec);
std::this_thread::sleep_for(std::chrono::microseconds{usec});
if (count < 7)
val = access_pool ();
else
val = access_pool (true);
printf ("%s (thread = %u) after usleep access_pool returns %d (count=%d)...\n", __FUNCTION__, thread_index, val, count);
}
printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index);
}
int main (int argc, char const *argv[])
{
std::thread threads[3];
printf ("Before turning all three threads loose...\n"); // Set break point at this line,
// in order to set our watchpoint.
// Create 3 threads
for (auto &thread : threads)
thread = std::thread{thread_func, std::distance(threads, &thread)};
// Join all of our threads
for (auto &thread : threads)
thread.join();
return 0;
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
C_SOURCES := main.c
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,122 @@
"""Test stepping over watchpoints."""
from __future__ import print_function
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestStepOverWatchpoint(TestBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureAll(
oslist=["linux"],
archs=[
'aarch64',
'arm'],
bugnumber="llvm.org/pr26031")
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
# Read-write watchpoints not supported on SystemZ
@expectedFailureAll(archs=['s390x'])
@expectedFailureAll(oslist=["ios", "watchos", "tvos", "bridgeos"], bugnumber="<rdar://problem/34027183>") # watchpoint tests aren't working on arm64
@add_test_categories(["basic_process"])
def test(self):
"""Test stepping over watchpoints."""
self.build()
exe = os.path.join(os.getcwd(), 'a.out')
target = self.dbg.CreateTarget(exe)
self.assertTrue(self.target, VALID_TARGET)
lldbutil.run_break_set_by_symbol(self, 'main')
process = target.LaunchSimple(None, None,
self.get_process_working_directory())
self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
self.assertTrue(process.GetState() == lldb.eStateStopped,
PROCESS_STOPPED)
thread = lldbutil.get_stopped_thread(process,
lldb.eStopReasonBreakpoint)
self.assertTrue(thread.IsValid(), "Failed to get thread.")
frame = thread.GetFrameAtIndex(0)
self.assertTrue(frame.IsValid(), "Failed to get frame.")
read_value = frame.FindValue('g_watch_me_read',
lldb.eValueTypeVariableGlobal)
self.assertTrue(read_value.IsValid(), "Failed to find read value.")
error = lldb.SBError()
# resolve_location=True, read=True, write=False
read_watchpoint = read_value.Watch(True, True, False, error)
self.assertTrue(error.Success(),
"Error while setting watchpoint: %s" %
error.GetCString())
self.assertTrue(read_watchpoint, "Failed to set read watchpoint.")
thread.StepOver()
self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
STOPPED_DUE_TO_WATCHPOINT)
self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 1')
process.Continue()
self.assertTrue(process.GetState() == lldb.eStateStopped,
PROCESS_STOPPED)
self.assertTrue(thread.GetStopDescription(20) == 'step over')
self.step_inst_for_watchpoint(1)
write_value = frame.FindValue('g_watch_me_write',
lldb.eValueTypeVariableGlobal)
self.assertTrue(write_value, "Failed to find write value.")
# Most of the MIPS boards provide only one H/W watchpoints, and S/W
# watchpoints are not supported yet
arch = self.getArchitecture()
if re.match("^mips", arch):
self.runCmd("watchpoint delete 1")
# resolve_location=True, read=False, write=True
write_watchpoint = write_value.Watch(True, False, True, error)
self.assertTrue(write_watchpoint, "Failed to set write watchpoint.")
self.assertTrue(error.Success(),
"Error while setting watchpoint: %s" %
error.GetCString())
thread.StepOver()
self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
STOPPED_DUE_TO_WATCHPOINT)
self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 2')
process.Continue()
self.assertTrue(process.GetState() == lldb.eStateStopped,
PROCESS_STOPPED)
self.assertTrue(thread.GetStopDescription(20) == 'step over')
self.step_inst_for_watchpoint(2)
def step_inst_for_watchpoint(self, wp_id):
watchpoint_hit = False
current_line = self.frame().GetLineEntry().GetLine()
while self.frame().GetLineEntry().GetLine() == current_line:
self.thread().StepInstruction(False) # step_over=False
stop_reason = self.thread().GetStopReason()
if stop_reason == lldb.eStopReasonWatchpoint:
self.assertFalse(watchpoint_hit, "Watchpoint already hit.")
expected_stop_desc = "watchpoint %d" % wp_id
actual_stop_desc = self.thread().GetStopDescription(20)
self.assertTrue(actual_stop_desc == expected_stop_desc,
"Watchpoint ID didn't match.")
watchpoint_hit = True
else:
self.assertTrue(stop_reason == lldb.eStopReasonPlanComplete,
STOPPED_DUE_TO_STEP_IN)
self.assertTrue(watchpoint_hit, "Watchpoint never hit.")

View File

@ -0,0 +1,19 @@
char g_watch_me_read;
char g_watch_me_write;
char g_temp;
void watch_read() {
g_temp = g_watch_me_read;
}
void watch_write() {
g_watch_me_write = g_temp;
}
int main() {
watch_read();
g_temp = g_watch_me_read;
watch_write();
g_watch_me_write = g_temp;
return 0;
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
C_SOURCES := main.c
include $(LEVEL)/Makefile.rules

Some files were not shown because too many files have changed in this diff Show More