Skip to content

Commit fc41013

Browse files
committed
[lldb/Reproducers] Capture reproducers from the API test suite.
Make it possible to capture reproducers from the API test suite. Given the symmetry between capture and replay, this patch also adds the necessary code for replay. For now this is a NO-OP until the corresponding reproducer instrumentation changes land. For more info please refer to the RFC on lldb-dev: http://lists.llvm.org/pipermail/lldb-dev/2020-April/016100.html Differential revision: https://reviews.llvm.org/D77588
1 parent c1a9dd9 commit fc41013

File tree

12 files changed

+100
-4
lines changed

12 files changed

+100
-4
lines changed

lldb/bindings/headers.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "lldb/API/SBProcessInfo.h"
4848
#include "lldb/API/SBQueue.h"
4949
#include "lldb/API/SBQueueItem.h"
50+
#include "lldb/API/SBReproducer.h"
5051
#include "lldb/API/SBSection.h"
5152
#include "lldb/API/SBSourceManager.h"
5253
#include "lldb/API/SBStream.h"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- SWIG Interface for SBReproducer--------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
namespace lldb {
10+
class SBReproducer
11+
{
12+
public:
13+
static const char *Capture(const char *path);
14+
static const char *PassiveReplay(const char *path);
15+
static bool SetAutoGenerate(bool b);
16+
};
17+
}

lldb/bindings/interfaces.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
%include "./interface/SBProcessInfo.i"
5555
%include "./interface/SBQueue.i"
5656
%include "./interface/SBQueueItem.i"
57+
%include "./interface/SBReproducer.i"
5758
%include "./interface/SBSection.i"
5859
%include "./interface/SBSourceManager.i"
5960
%include "./interface/SBStream.i"

lldb/include/lldb/API/SBReproducer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class LLDB_API SBReproducer {
2222
static const char *Capture(const char *path);
2323
static const char *Replay(const char *path);
2424
static const char *Replay(const char *path, bool skip_version_check);
25+
static const char *PassiveReplay(const char *path);
2526
static const char *GetPath();
2627
static bool SetAutoGenerate(bool b);
2728
static bool Generate();

lldb/packages/Python/lldbsuite/test/configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787

8888
# Set this flag if there is any session info dumped during the test run.
8989
sdir_has_content = False
90-
9190
# svn_info stores the output from 'svn info lldb.base.dir'.
9291
svn_info = ''
9392

@@ -124,6 +123,10 @@
124123
results_formatter_options = None
125124
test_result = None
126125

126+
# Reproducers
127+
capture_path = None
128+
replay_path = None
129+
127130
# Test rerun configuration vars
128131
rerun_all_issues = False
129132

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,11 @@ def is_asan():
854854
return "ASAN unsupported"
855855
return None
856856
return skipTestIfFn(is_asan)(func)
857+
858+
def skipIfReproducer(func):
859+
"""Skip this test if the environment is set up to run LLDB with reproducers."""
860+
def is_reproducer():
861+
if configuration.capture_path or configuration.replay_path:
862+
return "reproducers unsupported"
863+
return None
864+
return skipTestIfFn(is_reproducer)(func)

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,17 @@ def parseOptionsAndInitTestdirs():
429429
configuration.results_formatter_name = (
430430
"lldbsuite.test_event.formatter.results_formatter.ResultsFormatter")
431431

432+
# Reproducer arguments
433+
if args.capture_path and args.replay_path:
434+
logging.error('Cannot specify both a capture and a replay path.')
435+
sys.exit(-1)
436+
437+
if args.capture_path:
438+
configuration.capture_path = args.capture_path
439+
440+
if args.replay_path:
441+
configuration.replay_path = args.replay_path
442+
432443
# rerun-related arguments
433444
configuration.rerun_all_issues = args.rerun_all_issues
434445

@@ -955,8 +966,19 @@ def run_suite():
955966
setupSysPath()
956967

957968
import lldbconfig
969+
if configuration.capture_path or configuration.replay_path:
970+
lldbconfig.INITIALIZE = False
958971
import lldb
959972

973+
if configuration.capture_path:
974+
lldb.SBReproducer.Capture(configuration.capture_path)
975+
lldb.SBReproducer.SetAutoGenerate(True)
976+
elif configuration.replay_path:
977+
lldb.SBReproducer.PassiveReplay(configuration.replay_path)
978+
979+
if not lldbconfig.INITIALIZE:
980+
lldb.SBDebugger.Initialize()
981+
960982
# Use host platform by default.
961983
lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
962984

lldb/packages/Python/lldbsuite/test/dotest_args.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ def create_parser():
196196
metavar='platform-working-dir',
197197
help='The directory to use on the remote platform.')
198198

199+
# Reproducer options
200+
group = parser.add_argument_group('Reproducer options')
201+
group.add_argument(
202+
'--capture-path',
203+
metavar='reproducer path',
204+
help='The reproducer capture path')
205+
group.add_argument(
206+
'--replay-path',
207+
metavar='reproducer path',
208+
help='The reproducer replay path')
209+
199210
# Test-suite behaviour
200211
group = parser.add_argument_group('Runtime behaviour options')
201212
X('-d', 'Suspend the process after launch to wait indefinitely for a debugger to attach')

lldb/source/API/SBReproducer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ const char *SBReproducer::Capture(const char *path) {
124124
return nullptr;
125125
}
126126

127+
const char *SBReproducer::PassiveReplay(const char *path) {
128+
static std::string error;
129+
if (auto e = Reproducer::Initialize(ReproducerMode::Replay, FileSpec(path))) {
130+
error = llvm::toString(std::move(e));
131+
return error.c_str();
132+
}
133+
return nullptr;
134+
}
135+
127136
const char *SBReproducer::Replay(const char *path) {
128137
return SBReproducer::Replay(path, false);
129138
}

lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ReproducerAttachTestCase(TestBase):
2020
@skipIfWindows
2121
@skipIfRemote
2222
@skipIfiOSSimulator
23+
@skipIfReproducer
2324
def test_reproducer_attach(self):
2425
"""Test thread creation after process attach."""
2526
exe = '%s_%d' % (self.testMethodName, os.getpid())

0 commit comments

Comments
 (0)