lawrence_danna created this revision.
lawrence_danna added reviewers: jasonmolenda, JDevlieghere, jingham.
lawrence_danna requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
Apparently "{sys.prefix}/bin/python3" isn't where you find the
python interpreter on windows, so the test I wrote for
-print-script-interpreter-info is failing.
I'm not thrilled with this solution, as it requires a posix-specific
rule and a windows-specific rule, but as far as I can tell there's
not a better way to do it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113650
Files:
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -410,30 +410,40 @@
return g_spec;
}
+static const char GetInterpreterInfoScript[] = R"(
+import os
+import sysconfig
+import sys
+
+def main(lldb_python_dir):
+ info = {
+ "lldb-pythonpath": lldb_python_dir,
+ "language": "python",
+ "prefix": sys.prefix,
+ }
+ sc = sysconfig.get_config_vars()
+ if os.name == 'nt':
+ if sc['EXT_SUFFIX'].startswith("_d"):
+ exename = "python_d.exe"
+ else:
+ exename = "python.exe"
+ info['executable'] = os.path.normpath(os.path.join(sys.prefix, exename))
+ elif os.name == 'posix':
+ exename = "python" + str(sys.version_info[0])
+ info['executable'] = os.path.join(sys.prefix, 'bin', exename)
+ return info
+
+)";
+
+
StructuredData::DictionarySP ScriptInterpreterPython::GetInterpreterInfo() {
GIL gil;
FileSpec python_dir_spec = GetPythonDir();
if (!python_dir_spec)
return nullptr;
PythonString python_dir(python_dir_spec.GetPath());
- PythonDictionary info(PyInitialValue::Empty);
- llvm::Error error = info.SetItem("lldb-pythonpath", python_dir);
- if (error)
- return nullptr;
- static const char script[] = R"(
-def main(info):
- import sys
- import os
- name = 'python' + str(sys.version_info.major)
- info.update({
- "language": "python",
- "prefix": sys.prefix,
- "executable": os.path.join(sys.prefix, "bin", name),
- })
- return info
-)";
- PythonScript get_info(script);
- auto info_json = unwrapIgnoringErrors(As<PythonDictionary>(get_info(info)));
+ PythonScript get_info(GetInterpreterInfoScript);
+ auto info_json =
unwrapIgnoringErrors(As<PythonDictionary>(get_info(python_dir)));
if (!info_json)
return nullptr;
return info_json.CreateStructuredDictionary();
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -410,30 +410,40 @@
return g_spec;
}
+static const char GetInterpreterInfoScript[] = R"(
+import os
+import sysconfig
+import sys
+
+def main(lldb_python_dir):
+ info = {
+ "lldb-pythonpath": lldb_python_dir,
+ "language": "python",
+ "prefix": sys.prefix,
+ }
+ sc = sysconfig.get_config_vars()
+ if os.name == 'nt':
+ if sc['EXT_SUFFIX'].startswith("_d"):
+ exename = "python_d.exe"
+ else:
+ exename = "python.exe"
+ info['executable'] = os.path.normpath(os.path.join(sys.prefix, exename))
+ elif os.name == 'posix':
+ exename = "python" + str(sys.version_info[0])
+ info['executable'] = os.path.join(sys.prefix, 'bin', exename)
+ return info
+
+)";
+
+
StructuredData::DictionarySP ScriptInterpreterPython::GetInterpreterInfo() {
GIL gil;
FileSpec python_dir_spec = GetPythonDir();
if (!python_dir_spec)
return nullptr;
PythonString python_dir(python_dir_spec.GetPath());
- PythonDictionary info(PyInitialValue::Empty);
- llvm::Error error = info.SetItem("lldb-pythonpath", python_dir);
- if (error)
- return nullptr;
- static const char script[] = R"(
-def main(info):
- import sys
- import os
- name = 'python' + str(sys.version_info.major)
- info.update({
- "language": "python",
- "prefix": sys.prefix,
- "executable": os.path.join(sys.prefix, "bin", name),
- })
- return info
-)";
- PythonScript get_info(script);
- auto info_json = unwrapIgnoringErrors(As<PythonDictionary>(get_info(info)));
+ PythonScript get_info(GetInterpreterInfoScript);
+ auto info_json = unwrapIgnoringErrors(As<PythonDictionary>(get_info(python_dir)));
if (!info_json)
return nullptr;
return info_json.CreateStructuredDictionary();
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits