llvm-project/lldb/source/Interpreter
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
CommandAlias.cpp [lldb] Remove redundant calls to set eReturnStatusFailed 2021-06-17 12:21:54 +01:00
CommandHistory.cpp [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
CommandInterpreter.cpp [lldb] improve the help strings for gdb-remote and kdp-remote 2021-10-19 13:08:21 -07:00
CommandObject.cpp Add a "command container" hierarchy to allow users to add container nodes. 2021-10-18 15:29:24 -07:00
CommandOptionValidators.cpp
CommandReturnObject.cpp [lldb] Remove asserts in CommandReturnObject SetError and AppendError 2021-06-23 13:11:14 +00:00
InterpreterProperties.td [lldb/Interpreter] Add setting to set session transcript save directory 2021-06-29 10:54:29 +02:00
OptionArgParser.cpp [lldb] Rename StringRef _lower() method calls to _insensitive() 2021-06-25 00:22:01 +03:00
OptionGroupArchitecture.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionGroupBoolean.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionGroupFile.cpp [lldb] Replace default bodies of special member functions with = default; 2021-07-02 11:31:16 -07:00
OptionGroupFormat.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionGroupOutputFile.cpp [lldb/Interpreter][NFC] Remove explicit default initialization of members and base classes 2021-02-28 19:23:18 +03:00
OptionGroupPlatform.cpp
OptionGroupPythonClassWithDict.cpp [lldb/Interpreter] Make OptionGroupPythonClassWithDict options non-required 2021-03-04 20:24:26 +01:00
OptionGroupString.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionGroupUInt64.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionGroupUUID.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionGroupValueObjectDisplay.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionGroupVariable.cpp [lldb/Interpreter][NFC] Remove explicit default initialization of members and base classes 2021-02-28 19:23:18 +03:00
OptionGroupWatchpoint.cpp [lldb/Interpreter][NFC] Replace default constructors/destructors bodies with "=default" 2021-02-28 19:23:16 +03:00
OptionValue.cpp [lldb][NFC] Remove all uses of StringRef::withNullAsEmpty in LLDB 2021-05-18 09:41:20 +02:00
OptionValueArch.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueArgs.cpp [lldb][NFC] Make OptionValueArgs::GetArgs constant 2021-02-28 19:23:20 +03:00
OptionValueArray.cpp [lldb] Convert misc. StringConvert uses 2021-09-25 14:19:19 +02:00
OptionValueBoolean.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueChar.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueDictionary.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueEnumeration.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueFileColonLine.cpp [lldb] Replace default bodies of special member functions with = default; 2021-07-02 11:31:16 -07:00
OptionValueFileSpec.cpp [lldb] Use C++11 default member initializers 2021-06-09 09:43:13 -07:00
OptionValueFileSpecList.cpp [lldb] Convert misc. StringConvert uses 2021-09-25 14:19:19 +02:00
OptionValueFormat.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueFormatEntity.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueLanguage.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValuePathMappings.cpp [lldb][NFC] avoid unnecessary roundtrips between different string types 2021-11-01 22:15:01 -07:00
OptionValueProperties.cpp [lldb] DeConstStringify the Property class 2021-11-10 15:07:30 +01:00
OptionValueRegex.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueSInt64.cpp [lldb] Convert misc. StringConvert uses 2021-09-25 14:19:19 +02:00
OptionValueString.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
OptionValueUInt64.cpp [lldb] Convert misc. StringConvert uses 2021-09-25 14:19:19 +02:00
OptionValueUUID.cpp [lldb/Interpreter] Fix deep copying for OptionValue classes 2021-02-28 19:23:25 +03:00
Options.cpp [lldb] Remove redundant calls to set eReturnStatusFailed 2021-06-17 12:21:54 +01:00
Property.cpp [lldb] DeConstStringify the Property class 2021-11-10 15:07:30 +01:00
ScriptInterpreter.cpp [lldb] make it easier to find LLDB's python 2021-11-10 10:33:34 -08:00
embedded_interpreter.py