llvm-project/lldb/bindings/interface
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
..
SBAddress.i [lldb][docs] Resolve the remaining sphinx formatter warnings in the SB API docs 2021-01-18 10:47:19 +01:00
SBAttachInfo.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBBlock.i [lldb] Clarify docstring for SBBlock::IsInlined, NFC 2020-09-17 16:54:58 -07:00
SBBreakpoint.i [lldb] Use internal_dict name over dict in python examples 2021-02-10 15:11:00 -08:00
SBBreakpointLocation.i [lldb] Use internal_dict name over dict in python examples 2021-02-10 15:11:00 -08:00
SBBreakpointName.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBBroadcaster.i [lldb][docs] Resolve the remaining sphinx formatter warnings in the SB API docs 2021-01-18 10:47:19 +01:00
SBCommandInterpreter.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBCommandInterpreterRunOptions.i [lldb/API] Add CommandInterpreter::{Get,Set}PrintErrors to SBAPI (NFC) 2021-03-05 19:33:33 +01:00
SBCommandReturnObject.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBCommunication.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBCompileUnit.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBData.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBDebugger.i [lldb] make it easier to find LLDB's python 2021-11-10 10:33:34 -08:00
SBDeclaration.i
SBEnvironment.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBError.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBEvent.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBExecutionContext.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBExpressionOptions.i
SBFile.i [lldb][docs] Use inline literals for code/paths instead of rendering it with the default role 2021-01-18 11:10:19 +01:00
SBFileSpec.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBFileSpecList.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBFrame.i [lldb][docs] Use inline literals for code/paths instead of rendering it with the default role 2021-01-18 11:10:19 +01:00
SBFunction.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBHostOS.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBInstruction.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBInstructionList.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBLanguageRuntime.i [lldb][docs] Add a doc page for enums and constants 2021-01-19 18:54:05 +01:00
SBLaunchInfo.i [lldb/Commands] Add command options for ScriptedProcess to ProcessLaunch 2021-03-23 18:24:47 +01:00
SBLineEntry.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBListener.i [lldb] Fix two documentation typos 2021-01-19 15:25:15 +01:00
SBMemoryRegionInfo.i [lldb/Plugins] Add memory region support in ScriptedProcess 2021-10-08 14:54:07 +02:00
SBMemoryRegionInfoList.i [lldb/Plugins] Add memory region support in ScriptedProcess 2021-10-08 14:54:07 +02:00
SBModule.i [lldb][docs] Resolve the remaining sphinx formatter warnings in the SB API docs 2021-01-18 10:47:19 +01:00
SBModuleSpec.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBPlatform.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBProcess.i [lldb] Add AllocateMemory/DeallocateMemory to the SBProcess API 2021-07-16 00:45:22 +02:00
SBProcessInfo.i Revert "[LLDB/API] Expose args and env from SBProcessInfo." 2021-06-05 15:50:49 +07:00
SBQueue.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBQueueItem.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBReproducer.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBSection.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBSourceManager.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBStream.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBStringList.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBStructuredData.i [trace][intel-pt] Create basic SB API 2021-06-17 15:14:47 -07:00
SBSymbol.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBSymbolContext.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBSymbolContextList.i [NFC] fix a typo 2021-10-15 14:51:49 +08:00
SBTarget.i [trace][intel-pt] Create basic SB API 2021-06-17 15:14:47 -07:00
SBThread.i [lldb] [gdb-remote server] Introduce new stop reasons for fork and vfork 2021-04-24 11:08:33 +02:00
SBThreadCollection.i
SBThreadPlan.i [lldb] [gdb-remote server] Introduce new stop reasons for fork and vfork 2021-04-24 11:08:33 +02:00
SBTrace.i [trace][intel-pt] Create basic SB API 2021-06-17 15:14:47 -07:00
SBType.i [lldb] Make SBType::IsTypeComplete more consistent by forcing the loading of definitions 2021-10-30 13:28:27 +02:00
SBTypeCategory.i
SBTypeEnumMember.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBTypeFilter.i
SBTypeFormat.i
SBTypeNameSpecifier.i
SBTypeSummary.i
SBTypeSynthetic.i
SBUnixSignals.i
SBValue.i [lldb][docs] Use inline literals for code/paths instead of rendering it with the default role 2021-01-18 11:10:19 +01:00
SBValueList.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00
SBVariablesOptions.i [lldb][docs] Cleanup the Python doc strings for SB API classes 2021-01-17 16:51:07 +01:00
SBWatchpoint.i [lldb][docs] Translate ASCII art to restructured text formatting 2021-01-15 14:43:27 +01:00