use of com.sun.jdi.Location in project otertool by wuntee.
the class Testing method addBreakpointToMethod.
public static void addBreakpointToMethod(Method m, EventRequestManager mgr) {
System.out.println("Breakpoint: " + m.toString());
try {
Location location = m.location();
BreakpointRequest bpr = mgr.createBreakpointRequest(location);
bpr.enable();
} catch (com.sun.jdi.NativeMethodException e) {
System.out.println("Error: Cant add breakpoint to native method (" + m.toString() + ")");
}
}
use of com.sun.jdi.Location in project kotlin by JetBrains.
the class DebuggerSteppingHelper method getCurrentClassName.
// copied from DebugProcessImpl.getActiveFilters
@Nullable
private static String getCurrentClassName(ThreadReferenceProxyImpl thread) {
try {
if (thread != null && thread.frameCount() > 0) {
StackFrameProxyImpl stackFrame = thread.frame(0);
if (stackFrame != null) {
Location location = stackFrame.location();
ReferenceType referenceType = location == null ? null : location.declaringType();
if (referenceType != null) {
return referenceType.name();
}
}
}
} catch (EvaluateException ignored) {
}
return null;
}
use of com.sun.jdi.Location in project intellij-community by JetBrains.
the class WildcardMethodBreakpoint method getEventMessage.
public String getEventMessage(LocatableEvent event) {
final Location location = event.location();
final String locationQName = DebuggerUtilsEx.getLocationMethodQName(location);
String locationFileName;
try {
locationFileName = location.sourceName();
} catch (AbsentInformationException e) {
locationFileName = "";
}
final int locationLine = location.lineNumber();
if (event instanceof MethodEntryEvent) {
MethodEntryEvent entryEvent = (MethodEntryEvent) event;
final Method method = entryEvent.method();
return DebuggerBundle.message("status.method.entry.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
}
if (event instanceof MethodExitEvent) {
MethodExitEvent exitEvent = (MethodExitEvent) event;
final Method method = exitEvent.method();
return DebuggerBundle.message("status.method.exit.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
}
return "";
}
use of com.sun.jdi.Location in project intellij-community by JetBrains.
the class AlternativeSourceNotificationProvider method createNotificationPanel.
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
if (!DebuggerSettings.getInstance().SHOW_ALTERNATIVE_SOURCE) {
return null;
}
XDebugSession session = XDebuggerManager.getInstance(myProject).getCurrentSession();
if (session == null) {
FILE_PROCESSED_KEY.set(file, null);
return null;
}
XSourcePosition position = session.getCurrentPosition();
if (position == null || !file.equals(position.getFile())) {
FILE_PROCESSED_KEY.set(file, null);
return null;
}
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (psiFile == null)
return null;
if (!(psiFile instanceof PsiJavaFile))
return null;
PsiClass[] classes = ((PsiJavaFile) psiFile).getClasses();
if (classes.length == 0)
return null;
PsiClass baseClass = classes[0];
String name = baseClass.getQualifiedName();
if (name == null)
return null;
if (DumbService.getInstance(myProject).isDumb())
return null;
ArrayList<PsiClass> alts = ContainerUtil.newArrayList(JavaPsiFacade.getInstance(myProject).findClasses(name, GlobalSearchScope.allScope(myProject)));
ContainerUtil.removeDuplicates(alts);
FILE_PROCESSED_KEY.set(file, true);
if (alts.size() > 1) {
for (PsiClass cls : alts) {
if (cls.equals(baseClass) || cls.getNavigationElement().equals(baseClass)) {
alts.remove(cls);
break;
}
}
alts.add(0, baseClass);
ComboBoxClassElement[] elems = ContainerUtil.map2Array(alts, ComboBoxClassElement.class, psiClass -> new ComboBoxClassElement((PsiClass) psiClass.getNavigationElement()));
String locationDeclName = null;
XStackFrame frame = session.getCurrentStackFrame();
if (frame instanceof JavaStackFrame) {
Location location = ((JavaStackFrame) frame).getDescriptor().getLocation();
if (location != null) {
locationDeclName = location.declaringType().name();
}
}
return new AlternativeSourceNotificationPanel(elems, baseClass, myProject, file, locationDeclName);
}
return null;
}
use of com.sun.jdi.Location in project intellij-community by JetBrains.
the class DefaultSourcePositionProvider method getSourcePositionForField.
@Nullable
private static SourcePosition getSourcePositionForField(@NotNull FieldDescriptor descriptor, @NotNull Project project, @NotNull DebuggerContextImpl context, boolean nearest) {
final ReferenceType type = descriptor.getField().declaringType();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final String fieldName = descriptor.getField().name();
if (fieldName.startsWith(FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
// this field actually mirrors a local variable in the outer class
String varName = fieldName.substring(fieldName.lastIndexOf('$') + 1);
PsiElement element = PositionUtil.getContextElement(context);
if (element == null) {
return null;
}
PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
if (aClass == null) {
return null;
}
PsiElement navigationElement = aClass.getNavigationElement();
if (!(navigationElement instanceof PsiClass)) {
return null;
}
aClass = (PsiClass) navigationElement;
PsiVariable psiVariable = facade.getResolveHelper().resolveReferencedVariable(varName, aClass);
if (psiVariable == null) {
return null;
}
if (nearest) {
return DebuggerContextUtil.findNearest(context, psiVariable, aClass.getContainingFile());
}
return SourcePosition.createFromElement(psiVariable);
} else {
final DebuggerSession session = context.getDebuggerSession();
final GlobalSearchScope scope = session != null ? session.getSearchScope() : GlobalSearchScope.allScope(project);
PsiClass aClass = facade.findClass(type.name().replace('$', '.'), scope);
if (aClass == null) {
// trying to search, assuming declaring class is an anonymous class
final DebugProcessImpl debugProcess = context.getDebugProcess();
if (debugProcess != null) {
try {
final List<Location> locations = type.allLineLocations();
if (!locations.isEmpty()) {
// important: use the last location to be sure the position will be within the anonymous class
final Location lastLocation = locations.get(locations.size() - 1);
final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation);
aClass = JVMNameUtil.getClassAt(position);
}
} catch (AbsentInformationException | ClassNotPreparedException ignored) {
}
}
}
if (aClass != null) {
PsiField field = aClass.findFieldByName(fieldName, false);
if (field == null)
return null;
if (nearest) {
return DebuggerContextUtil.findNearest(context, field.getNavigationElement(), aClass.getContainingFile());
}
return SourcePosition.createFromElement(field);
}
return null;
}
}
Aggregations