107
107
import java .util .Set ;
108
108
109
109
import com .oracle .graal .python .lib .PyTraceBackPrintNode ;
110
+ import com .oracle .graal .python .nodes .subscript .GetItemNode ;
110
111
import org .graalvm .nativeimage .ImageInfo ;
111
112
112
113
import com .oracle .graal .python .PythonLanguage ;
@@ -1353,7 +1354,10 @@ Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
1353
1354
@ GenerateNodeFactory
1354
1355
abstract static class BreakpointHookNode extends PythonBuiltinNode {
1355
1356
static final String VAL_PDB_SETTRACE = "pdb.set_trace" ;
1357
+ static final String MOD_OS = "os" ;
1358
+ static final String ATTR_ENVIRON = "environ" ;
1356
1359
1360
+ @ Child private ImportNode .ImportExpression importOsNode ;
1357
1361
@ Child private ImportNode .ImportExpression importNode ;
1358
1362
1359
1363
private ImportNode .ImportExpression ensureImportNode (String name ) {
@@ -1364,22 +1368,32 @@ private ImportNode.ImportExpression ensureImportNode(String name) {
1364
1368
return importNode ;
1365
1369
}
1366
1370
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 );
1370
1383
}
1371
1384
1372
1385
@ Specialization
1373
1386
Object doHook (VirtualFrame frame , Object [] args , PKeyword [] keywords ,
1374
1387
@ Cached CallNode callNode ,
1375
1388
@ Cached PyObjectGetAttr getAttr ,
1389
+ @ Cached GetItemNode getItemNode ,
1376
1390
@ Cached IsBuiltinClassProfile importErrorProfile ,
1377
1391
@ Cached IsBuiltinClassProfile attrErrorProfile ,
1378
1392
@ Cached CastToJavaStringNode castToJavaStringNode ,
1379
1393
@ Cached WarningsModuleBuiltins .WarnNode warnNode ) {
1380
- Object v = getEnv (PYTHONBREAKPOINT );
1394
+ Object v = getEnv (frame , getAttr , getItemNode , PYTHONBREAKPOINT );
1381
1395
final String hookName ;
1382
- if (v == null ) {
1396
+ if (v == PNone . NO_VALUE ) {
1383
1397
warnNode .warnFormat (frame , RuntimeWarning , WARN_CANNOT_RUN_PDB_YET );
1384
1398
hookName = VAL_PDB_SETTRACE ;
1385
1399
} else {
0 commit comments