Skip to content

Commit b868e3c

Browse files
committed
SysModuleBuiltins.BreakpointHookNode fix getting the env $PYTHONBREAKPOINT variable
1 parent 8611898 commit b868e3c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import java.util.Set;
108108

109109
import com.oracle.graal.python.lib.PyTraceBackPrintNode;
110+
import com.oracle.graal.python.nodes.subscript.GetItemNode;
110111
import org.graalvm.nativeimage.ImageInfo;
111112

112113
import com.oracle.graal.python.PythonLanguage;
@@ -1353,7 +1354,10 @@ Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
13531354
@GenerateNodeFactory
13541355
abstract static class BreakpointHookNode extends PythonBuiltinNode {
13551356
static final String VAL_PDB_SETTRACE = "pdb.set_trace";
1357+
static final String MOD_OS = "os";
1358+
static final String ATTR_ENVIRON = "environ";
13561359

1360+
@Child private ImportNode.ImportExpression importOsNode;
13571361
@Child private ImportNode.ImportExpression importNode;
13581362

13591363
private ImportNode.ImportExpression ensureImportNode(String name) {
@@ -1364,22 +1368,32 @@ private ImportNode.ImportExpression ensureImportNode(String name) {
13641368
return importNode;
13651369
}
13661370

1367-
@TruffleBoundary
1368-
private static Object getEnv(String name) {
1369-
return System.getenv(name);
1371+
private Object importOs(VirtualFrame frame) {
1372+
if (importOsNode == null) {
1373+
CompilerDirectives.transferToInterpreterAndInvalidate();
1374+
importOsNode = insert(ImportNode.createAsExpression(MOD_OS));
1375+
}
1376+
return importOsNode.execute(frame);
1377+
}
1378+
1379+
private Object getEnv(VirtualFrame frame, PyObjectGetAttr getAttr, GetItemNode getItemNode, String name) {
1380+
Object os = importOs(frame);
1381+
final Object environ = getAttr.execute(frame, os, ATTR_ENVIRON);
1382+
return getItemNode.execute(frame, environ, name);
13701383
}
13711384

13721385
@Specialization
13731386
Object doHook(VirtualFrame frame, Object[] args, PKeyword[] keywords,
13741387
@Cached CallNode callNode,
13751388
@Cached PyObjectGetAttr getAttr,
1389+
@Cached GetItemNode getItemNode,
13761390
@Cached IsBuiltinClassProfile importErrorProfile,
13771391
@Cached IsBuiltinClassProfile attrErrorProfile,
13781392
@Cached CastToJavaStringNode castToJavaStringNode,
13791393
@Cached WarningsModuleBuiltins.WarnNode warnNode) {
1380-
Object v = getEnv(PYTHONBREAKPOINT);
1394+
Object v = getEnv(frame, getAttr, getItemNode, PYTHONBREAKPOINT);
13811395
final String hookName;
1382-
if (v == null) {
1396+
if (v == PNone.NO_VALUE) {
13831397
warnNode.warnFormat(frame, RuntimeWarning, WARN_CANNOT_RUN_PDB_YET);
13841398
hookName = VAL_PDB_SETTRACE;
13851399
} else {

0 commit comments

Comments
 (0)