diff --git a/lldb/bindings/interface/SBCommandInterpreter.i b/lldb/bindings/interface/SBCommandInterpreter.i --- a/lldb/bindings/interface/SBCommandInterpreter.i +++ b/lldb/bindings/interface/SBCommandInterpreter.i @@ -169,6 +169,9 @@ bool CommandExists (const char *cmd); + bool + UserCommandExists (const char *cmd); + bool AliasExists (const char *cmd); diff --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h --- a/lldb/include/lldb/API/SBCommandInterpreter.h +++ b/lldb/include/lldb/API/SBCommandInterpreter.h @@ -91,8 +91,28 @@ bool IsValid() const; + /// Determine whether a command exists in this CommandInterpreter. + /// + /// For commands registered using the LLDB API, see UserCommandExists + /// + /// \param[in] cmd + /// The command to look up. + /// + /// \return + /// \b true if the provided command exists, \b false otherwise. bool CommandExists(const char *cmd); + /// Determine whether a user command exists in this CommandInterpreter. + /// Users commands are the ones registered using the LLDB API and are not + /// provided by default in LLDB. + /// + /// \param[in] cmd + /// The command to look up. + /// + /// \return + /// \b true if the provided command exists, \b false otherwise. + bool UserCommandExists(const char *cmd); + bool AliasExists(const char *cmd); lldb::SBBroadcaster GetBroadcaster(); diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -216,6 +216,14 @@ : false); } +bool SBCommandInterpreter::UserCommandExists(const char *cmd) { + LLDB_RECORD_METHOD(bool, SBCommandInterpreter, UserCommandExists, + (const char *), cmd); + + return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->UserCommandExists(cmd) + : false); +} + bool SBCommandInterpreter::AliasExists(const char *cmd) { LLDB_RECORD_METHOD(bool, SBCommandInterpreter, AliasExists, (const char *), cmd); @@ -874,6 +882,8 @@ LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, operator bool, ()); LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, CommandExists, (const char *)); + LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, UserCommandExists, + (const char *)); LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, AliasExists, (const char *)); LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, IsActive, ()); diff --git a/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py b/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py --- a/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py +++ b/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py @@ -14,22 +14,26 @@ mydir = TestBase.compute_mydir(__file__) NO_DEBUG_INFO_TESTCASE = True + def setUp(self): + TestBase.setUp(self) + + plugin_so = "liblldbIntelFeatures.so" + plugin_path = os.path.join(os.environ["LLDB_IMPLIB_DIR"], plugin_so) + if not os.path.exists(plugin_path): + self.skipTest("Intel PT plugin %s missing." % (plugin_so)) + + self.runCmd("plugin load " + plugin_path) + if not self.dbg.GetCommandInterpreter().UserCommandExists("processor-trace"): + self.skipTest("%s was built without Intel PT support" % (plugin_so)) + # This could happen if the user has intel-mpx support but not intel-pt. + @skipIf(oslist=no_match(['linux'])) @skipIf(archs=no_match(['i386', 'x86_64'])) @skipIfRemote def test_basic_flow(self): """Test collection, decoding, and dumping instructions""" - if os.environ.get('TEST_INTEL_PT') != '1': - self.skipTest("The environment variable TEST_INTEL_PT=1 is needed to run this test.") - - lldb_exec_dir = os.environ["LLDB_IMPLIB_DIR"] - lldb_lib_dir = os.path.join(lldb_exec_dir, os.pardir, "lib") - plugin_file = os.path.join(lldb_lib_dir, "liblldbIntelFeatures.so") self.build() - - self.runCmd("plugin load " + plugin_file) - exe = self.getBuildArtifact("a.out") lldbutil.run_to_name_breakpoint(self, "main", exe_name=exe) # We start tracing from main