|
55 | 55 | import static com.oracle.graal.python.nodes.BuiltinNames.ROUND;
|
56 | 56 | import static com.oracle.graal.python.nodes.BuiltinNames.SETATTR;
|
57 | 57 | import static com.oracle.graal.python.nodes.BuiltinNames.SUM;
|
58 |
| -import static com.oracle.graal.python.nodes.BuiltinNames.__BREAKPOINT__; |
| 58 | +import static com.oracle.graal.python.nodes.BuiltinNames.BREAKPOINT; |
| 59 | +import static com.oracle.graal.python.nodes.BuiltinNames.BREAKPOINTHOOK; |
59 | 60 | import static com.oracle.graal.python.nodes.BuiltinNames.__BUILTIN__;
|
60 | 61 | import static com.oracle.graal.python.nodes.BuiltinNames.__DEBUG__;
|
61 | 62 | import static com.oracle.graal.python.nodes.BuiltinNames.__DUMP_TRUFFLE_AST__;
|
|
93 | 94 | import com.oracle.graal.python.builtins.objects.bytes.PBytes;
|
94 | 95 | import com.oracle.graal.python.builtins.objects.code.PCode;
|
95 | 96 | import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
|
| 97 | +import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes; |
96 | 98 | import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
|
97 | 99 | import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
|
98 | 100 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
|
168 | 170 | import com.oracle.truffle.api.CompilerDirectives;
|
169 | 171 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
170 | 172 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 173 | +import com.oracle.truffle.api.debug.Debugger; |
171 | 174 | import com.oracle.truffle.api.Truffle;
|
172 | 175 | import com.oracle.truffle.api.dsl.Cached;
|
173 | 176 | import com.oracle.truffle.api.dsl.Fallback;
|
@@ -1501,12 +1504,33 @@ public Object setAttr(Object object, Object key, Object value,
|
1501 | 1504 | }
|
1502 | 1505 | }
|
1503 | 1506 |
|
1504 |
| - @Builtin(name = __BREAKPOINT__, fixedNumOfPositionalArgs = 0) |
| 1507 | + @Builtin(name = BREAKPOINT, takesVarArgs = true, takesVarKeywordArgs = true) |
1505 | 1508 | @GenerateNodeFactory
|
1506 | 1509 | public abstract static class BreakPointNode extends PythonBuiltinNode {
|
| 1510 | + @Child HashingStorageNodes.GetItemNode getSysModuleNode; |
| 1511 | + @Child ReadAttributeFromObjectNode getBreakpointhookNode; |
| 1512 | + @Child CallNode callNode; |
| 1513 | + |
1507 | 1514 | @Specialization
|
1508 |
| - public Object doIt() { |
1509 |
| - return PNone.NONE; |
| 1515 | + public Object doIt(VirtualFrame frame, Object[] args, PKeyword[] kwargs) { |
| 1516 | + if (Debugger.find(getContext().getEnv()).getSessionCount() > 0) { |
| 1517 | + // we already have a Truffle debugger attached, it'll stop here |
| 1518 | + return PNone.NONE; |
| 1519 | + } else { |
| 1520 | + if (getSysModuleNode == null) { |
| 1521 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 1522 | + getSysModuleNode = insert(HashingStorageNodes.GetItemNode.create()); |
| 1523 | + getBreakpointhookNode = insert(ReadAttributeFromObjectNode.create()); |
| 1524 | + callNode = insert(CallNode.create()); |
| 1525 | + } |
| 1526 | + PDict sysModules = getContext().getSysModules(); |
| 1527 | + Object sysModule = getSysModuleNode.execute(sysModules.getDictStorage(), "sys"); |
| 1528 | + Object breakpointhook = getBreakpointhookNode.execute(sysModule, BREAKPOINTHOOK); |
| 1529 | + if (breakpointhook == PNone.NO_VALUE) { |
| 1530 | + throw raise(PythonBuiltinClassType.RuntimeError, "lost sys.breakpointhook"); |
| 1531 | + } |
| 1532 | + return callNode.execute(frame, breakpointhook, args, kwargs); |
| 1533 | + } |
1510 | 1534 | }
|
1511 | 1535 | }
|
1512 | 1536 |
|
|
0 commit comments