llvm-project/lldb/source/API
Lawrence D'Anna bbef51eb43 [lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing.   I'm
currently resorting to convolutions like this:

    def find_lldb(may_reexec=False):
		if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
			if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
				raise Exception("cannot import lldb.\n"
					f"  sys.prefix should be: {prefix}\n"
					f"  but it is: {sys.prefix}")
		else:
			line1, line2 = subprocess.run(
				['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
				encoding='utf8', stdout=subprocess.PIPE,
				check=True).stdout.strip().splitlines()
			assert line1.strip() == '(lldb) script print(sys.prefix)'
			prefix = line2.strip()
			os.environ['LLDB_PYTHON_PREFIX'] = prefix

		if sys.prefix != prefix:
			if not may_reexec:
				raise Exception(
					"cannot import lldb.\n" +
					f"  This python, at {sys.prefix}\n"
					f"  does not math LLDB's python at {prefix}")
			os.environ['LLDB_PYTHON_PREFIX'] = prefix
			python_exe = os.path.join(prefix, 'bin', 'python3')
			os.execl(python_exe, python_exe, *sys.argv)

		lldb_path = subprocess.run(['lldb', '-P'],
			check=True, stdout=subprocess.PIPE,
				encoding='utf8').stdout.strip()

		sys.path = [lldb_path] + sys.path

This patch aims to replace all that with:

  #!/usr/bin/env lldb-python
  import lldb
  ...

... by adding the following features:

* new command line option: --print-script-interpreter-info.  This
   prints language-specific information about the script interpreter
   in JSON format.

* new tool (unix only): lldb-python which finds python and exec's it.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D112973
2021-11-10 10:33:34 -08:00
..
CMakeLists.txt [trace][intel-pt] Create basic SB API 2021-06-17 15:14:47 -07:00
SBAddress.cpp [lldb] Pass reference instead of pointer in protected SBAddress methods. 2020-09-25 11:47:05 -07:00
SBAttachInfo.cpp
SBBlock.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBBreakpoint.cpp Convert functions that were returning BreakpointOption * to BreakpointOption &. 2021-06-15 14:34:02 -07:00
SBBreakpointLocation.cpp Convert functions that were returning BreakpointOption * to BreakpointOption &. 2021-06-15 14:34:02 -07:00
SBBreakpointName.cpp Convert functions that were returning BreakpointOption * to BreakpointOption &. 2021-06-15 14:34:02 -07:00
SBBreakpointOptionCommon.cpp
SBBreakpointOptionCommon.h
SBBroadcaster.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBCommandInterpreter.cpp Add a "command container" hierarchy to allow users to add container nodes. 2021-10-18 15:29:24 -07:00
SBCommandInterpreterRunOptions.cpp [lldb/API] Add CommandInterpreter::{Get,Set}PrintErrors to SBAPI (NFC) 2021-03-05 19:33:33 +01:00
SBCommandReturnObject.cpp [lldb] Remove CommandReturnObject's SetError(StringRef) 2021-06-23 11:25:10 +00:00
SBCommunication.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBCompileUnit.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBData.cpp
SBDebugger.cpp [lldb] make it easier to find LLDB's python 2021-11-10 10:33:34 -08:00
SBDeclaration.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
SBEnvironment.cpp [lldb/Reproducers] Add instrumentation to SBEnvironment 2020-05-20 13:02:20 -07:00
SBError.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
SBEvent.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBExecutionContext.cpp
SBExpressionOptions.cpp [lldb/API] Add missing LLDB_REGISTER_METHOD macros 2020-04-06 16:09:40 -07:00
SBFile.cpp
SBFileSpec.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
SBFileSpecList.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
SBFrame.cpp [lldb] Support querying registers via generic names without alt_names 2021-09-13 13:05:06 +02:00
SBFunction.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBHostOS.cpp [lldb] Provide GetHomeDirectory wrapper in Host::FileSystem (NFC) 2020-08-20 14:07:05 -07:00
SBInstruction.cpp [lldb] Pass reference instead of pointer in protected SBAddress methods. 2020-09-25 11:47:05 -07:00
SBInstructionList.cpp
SBLanguageRuntime.cpp [lldb][NFC] Remove all uses of StringRef::withNullAsEmpty in LLDB 2021-05-18 09:41:20 +02:00
SBLaunchInfo.cpp [lldb] Fix Scripted ProcessLaunchInfo Argument nullptr deref 2021-11-10 16:43:19 +00:00
SBLineEntry.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
SBListener.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBMemoryRegionInfo.cpp [lldb/Plugins] Add memory region support in ScriptedProcess 2021-10-08 14:54:07 +02:00
SBMemoryRegionInfoList.cpp [lldb/Plugins] Add memory region support in ScriptedProcess 2021-10-08 14:54:07 +02:00
SBModule.cpp [lldb] Use a struct to pass function search options to Module::FindFunction 2021-08-05 10:18:14 -07:00
SBModuleSpec.cpp
SBPlatform.cpp Modernize Platform::GetOSKernelDescription 2021-10-27 10:46:47 +02:00
SBProcess.cpp [lldb] Remove ConstString from GetPluginNameStatic of some plugins 2021-10-21 12:58:45 +02:00
SBProcessInfo.cpp Revert "[LLDB/API] Expose args and env from SBProcessInfo." 2021-06-05 15:50:49 +07:00
SBQueue.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBQueueItem.cpp [lldb] Pass reference instead of pointer in protected SBAddress methods. 2020-09-25 11:47:05 -07:00
SBReproducer.cpp [trace][intel-pt] Create basic SB API 2021-06-17 15:14:47 -07:00
SBReproducerPrivate.h [lldb] Extract reproducer providers & co into their own header. 2020-08-22 10:04:27 -07:00
SBSection.cpp [lldb] Switch Section-dumping code to raw_ostream 2020-05-14 11:59:18 +02:00
SBSourceManager.cpp [lldb/API] Use std::make_unique<> (NFC) 2020-06-24 16:29:30 -07:00
SBStream.cpp [lldb] [gdb-remote] Add eOpenOptionReadWrite for future gdb compat 2021-08-09 12:06:59 +02:00
SBStringList.cpp [lldb/API] Use std::make_unique<> (NFC) 2020-06-24 16:29:30 -07:00
SBStructuredData.cpp [trace][intel-pt] Create basic SB API 2021-06-17 15:14:47 -07:00
SBSymbol.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBSymbolContext.cpp [lldb/API] Use std::make_unique<> (NFC) 2020-06-24 16:29:30 -07:00
SBSymbolContextList.cpp
SBTarget.cpp [lldb][NFC] avoid unnecessary roundtrips between different string types 2021-11-01 22:15:01 -07:00
SBThread.cpp [lldb] Refactor argument group by SourceLocationSpec (NFCI) 2021-05-04 23:04:31 +00:00
SBThreadCollection.cpp
SBThreadPlan.cpp Add a setting to force stepping to always run all threads. 2020-08-07 14:47:31 -07:00
SBTrace.cpp [trace][intel-pt] Create basic SB API 2021-06-17 15:14:47 -07:00
SBType.cpp [lldb] Add SBType::GetEnumerationIntegerType method 2020-12-22 10:08:22 -08:00
SBTypeCategory.cpp [lldb][NFC] Remove all uses of StringRef::withNullAsEmpty in LLDB 2021-05-18 09:41:20 +02:00
SBTypeEnumMember.cpp [lldb/API] Use std::make_unique<> (NFC) 2020-06-24 16:29:30 -07:00
SBTypeFilter.cpp
SBTypeFormat.cpp
SBTypeNameSpecifier.cpp
SBTypeSummary.cpp [lldb/API] Use std::make_unique<> (NFC) 2020-06-24 16:29:30 -07:00
SBTypeSynthetic.cpp
SBUnixSignals.cpp
SBValue.cpp [lldb] Move and clean-up the Declaration class (NFC) 2021-05-04 16:34:44 +00:00
SBValueList.cpp [lldb/API] Use std::make_unique<> (NFC) 2020-06-24 16:29:30 -07:00
SBVariablesOptions.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
SBWatchpoint.cpp
SystemInitializerFull.cpp [lldb] Prevent that LLDB randomly crashes in CommandLineParser::addOption by initializing LLVM's command line parser 2021-04-01 20:17:54 +02:00
SystemInitializerFull.h
Utils.h
liblldb-private.exports [lldb/lua] Supplement Lua bindings for lldb module 2021-10-12 22:10:21 +08:00
liblldb.exports [lldb/lua] Supplement Lua bindings for lldb module 2021-10-12 22:10:21 +08:00