use of com.sun.jdi.Field in project che by eclipse.
the class JdiStackFrameImpl method getFields.
@Override
public JdiField[] getFields() throws DebuggerException {
if (fields == null) {
try {
ObjectReference object = stackFrame.thisObject();
if (object == null) {
ReferenceType type = stackFrame.location().declaringType();
List<Field> fs = stackFrame.location().declaringType().allFields();
fields = new JdiField[fs.size()];
int i = 0;
for (Field f : fs) {
fields[i++] = new JdiFieldImpl(f, type);
}
} else {
List<Field> fs = object.referenceType().allFields();
fields = new JdiField[fs.size()];
int i = 0;
for (Field f : fs) {
fields[i++] = new JdiFieldImpl(f, object);
}
}
Arrays.sort(fields);
} catch (InvalidStackFrameException e) {
throw new DebuggerException(e.getMessage(), e);
}
}
return fields;
}
use of com.sun.jdi.Field in project che by eclipse.
the class Evaluator method getField.
public ExpressionValue getField(Value parent, String name) {
if (!(parent instanceof ObjectReference)) {
throw new ExpressionException("Value is not object. Cannot invoke method " + name);
}
ExpressionValue value = null;
try {
ObjectReference object = (ObjectReference) parent;
Field field = object.referenceType().fieldByName(name);
if (field != null) {
value = new InstanceValue(object, field);
}
} catch (ClassNotPreparedException e) {
throw new ExpressionException(e.getMessage(), e);
}
LOG.debug("GET field {} {} ", name, value);
return value;
}
use of com.sun.jdi.Field in project jdk8u_jdk by JetBrains.
the class OomDebugTest method test2.
/*
* Test case: Array reference as method parameter.
*/
// called via reflection
@SuppressWarnings("unused")
private void test2() throws Exception {
System.out.println("DEBUG: ------------> Running test2");
try {
Field field = targetClass.fieldByName("byteArray");
ArrayType arrType = (ArrayType) field.type();
for (int i = 0; i < 15; i++) {
ArrayReference byteArrayVal = arrType.newInstance(3000000);
if (byteArrayVal.isCollected()) {
System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
continue;
}
invoke("testPrimitive", "([B)V", byteArrayVal);
}
} catch (VMOutOfMemoryException e) {
defaultHandleOOMFailure(e);
}
}
use of com.sun.jdi.Field in project jdk8u_jdk by JetBrains.
the class OomDebugTest method test1.
/*
* Test case: Object reference as method parameter.
*/
// called via reflection
@SuppressWarnings("unused")
private void test1() throws Exception {
System.out.println("DEBUG: ------------> Running test1");
try {
Field field = targetClass.fieldByName("fooCls");
ClassType clsType = (ClassType) field.type();
Method constructor = getConstructorForClass(clsType);
for (int i = 0; i < 15; i++) {
@SuppressWarnings({ "rawtypes", "unchecked" }) ObjectReference objRef = clsType.newInstance(mainThread, constructor, new ArrayList(0), ObjectReference.INVOKE_NONVIRTUAL);
if (objRef.isCollected()) {
System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
continue;
}
invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
}
} catch (InvocationException e) {
handleFailure(e);
}
}
use of com.sun.jdi.Field in project intellij-community by JetBrains.
the class ToggleFieldBreakpointAction method getPlace.
@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final Project project = event.getData(CommonDataKeys.PROJECT);
if (project == null) {
return null;
}
if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
if (psiElement instanceof PsiField) {
return SourcePosition.createFromElement(psiElement);
}
return null;
}
final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
if (debugProcess != null) {
// if there is an active debug session
final Ref<SourcePosition> positionRef = new Ref<>(null);
debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {
@Override
public Priority getPriority() {
return Priority.HIGH;
}
@Override
public void threadAction() {
ApplicationManager.getApplication().runReadAction(() -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)));
}
});
final SourcePosition sourcePosition = positionRef.get();
if (sourcePosition != null) {
return sourcePosition;
}
}
}
if (DebuggerAction.isContextView(event)) {
DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
if (tree != null && tree.getSelectionPath() != null) {
DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
if (psiClass != null) {
psiClass = (PsiClass) psiClass.getNavigationElement();
final PsiField psiField = psiClass.findFieldByName(field.name(), true);
if (psiField != null) {
return SourcePosition.createFromElement(psiField);
}
}
}
}
return null;
}
Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
}
if (editor != null) {
final Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
if (StdFileTypes.JAVA == fileType || StdFileTypes.CLASS == fileType) {
final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset());
if (field != null) {
return SourcePosition.createFromElement(field);
}
}
}
}
return null;
}
Aggregations