Skip to content

Commit 416d4e5

Browse files
committed
Support both functions and function pointers in debug expressions.
1 parent 1a533dd commit 416d4e5

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/debug/debugexpr/nodes/DebugExprFunctionCallNode.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -43,6 +43,7 @@
4343
import com.oracle.truffle.llvm.runtime.debug.debugexpr.parser.DebugExprException;
4444
import com.oracle.truffle.llvm.runtime.debug.debugexpr.parser.DebugExprType;
4545
import com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode;
46+
import com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer;
4647
import com.oracle.truffle.llvm.runtime.types.Type;
4748

4849
public abstract class DebugExprFunctionCallNode extends LLVMExpressionNode {
@@ -64,24 +65,30 @@ public DebugExprFunctionCallNode(String functionName, List<DebugExpressionPair>
6465
@TruffleBoundary
6566
public DebugExprType getType() {
6667
InteropLibrary library = InteropLibrary.getFactory().getUncached();
67-
if (library.isMemberExisting(scope, functionName)) {
68+
if (library.isMemberReadable(scope, functionName)) {
6869
try {
6970
Object member = library.readMember(scope, functionName);
70-
try {
71+
if (LLVMManagedPointer.isInstance(member)) {
72+
LLVMManagedPointer pointer = LLVMManagedPointer.cast(member);
73+
if (pointer.getOffset() == 0) {
74+
member = pointer.getObject();
75+
}
76+
}
77+
if (member instanceof LLVMFunctionDescriptor) {
7178
LLVMFunctionDescriptor ldv = (LLVMFunctionDescriptor) member;
7279
Type returnType = ldv.getLLVMFunction().getType().getReturnType();
7380
DebugExprType t = DebugExprType.getTypeFromLLVMType(returnType);
7481
return t;
75-
} catch (ClassCastException e) {
82+
} else {
83+
throw DebugExprException.create(this, "variable %s does not point to a function", functionName);
7684
}
77-
throw DebugExprException.create(this, "no type found for function %s", functionName);
7885
} catch (UnsupportedMessageException e) {
7986
throw DebugExprException.create(this, "error while accessing function %s", functionName);
8087
} catch (UnknownIdentifierException e) {
81-
throw DebugExprException.symbolNotFound(this, functionName, null);
88+
// fallthrough
8289
}
8390
}
84-
throw DebugExprException.create(this, "no type found for function %s", functionName);
91+
throw DebugExprException.symbolNotFound(this, functionName, null);
8592
}
8693

8794
@Specialization

0 commit comments

Comments
 (0)