Path: blob/master/src/jdk.jdi/share/classes/com/sun/jdi/Location.java
41159 views
/*1* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jdi;2627import com.sun.jdi.event.BreakpointEvent;28import com.sun.jdi.event.ExceptionEvent;29import com.sun.jdi.request.EventRequestManager;3031/**32* A point within the executing code of the target VM.33* Locations are used to identify the current position of34* a suspended thread (analogous to an instruction pointer or35* program counter register in native programs). They are also used36* to identify the position at which to set a breakpoint.37* <p>38* The availability of a line number for a location will39* depend on the level of debugging information available from the40* target VM.41* <p>42* Several mirror interfaces have locations. Each such mirror43* extends a {@link Locatable} interface.44* <p>45* <a id="strata"><b>Strata</b></a>46* <p>47* The source information for a Location is dependent on the48* <i>stratum</i> which is used. A stratum is a source code49* level within a sequence of translations. For example,50* say the baz program is written in the programming language51* "Foo" then translated to the language "Bar" and finally52* translated into the Java programming language. The53* Java programming language stratum is named54* <code>"Java"</code>, let's say the other strata are named55* "Foo" and "Bar". A given location (as viewed by the56* {@link #sourceName()} and {@link #lineNumber()} methods)57* might be at line 14 of "baz.foo" in the <code>"Foo"</code>58* stratum, line 23 of "baz.bar" in the <code>"Bar"</code>59* stratum and line 71 of the <code>"Java"</code> stratum.60* Note that while the Java programming language may have61* only one source file for a reference type, this restriction62* does not apply to other strata - thus each Location should63* be consulted to determine its source path.64* Queries which do not specify a stratum65* ({@link #sourceName()}, {@link #sourcePath()} and66* {@link #lineNumber()}) use the VM's default stratum67* ({@link VirtualMachine#getDefaultStratum()}).68* If the specified stratum (whether explicitly specified69* by a method parameter or implicitly as the VM's default)70* is <code>null</code> or is not available in the declaring71* type, the declaring type's default stratum is used72* ({@link #declaringType()}.{@link ReferenceType#defaultStratum()73* defaultStratum()}). Note that in the normal case, of code74* that originates as Java programming language source, there75* will be only one stratum (<code>"Java"</code>) and it will be76* returned as the default. To determine the available strata77* use {@link ReferenceType#availableStrata()}.78*79* @see EventRequestManager80* @see StackFrame81* @see BreakpointEvent82* @see ExceptionEvent83* @see Locatable84*85* @author Robert Field86* @author Gordon Hirsch87* @author James McIlree88* @since 1.389*/90public interface Location extends Mirror, Comparable<Location> {9192/**93* Gets the type to which this Location belongs. Normally94* the declaring type is a {@link ClassType}, but executable95* locations also may exist within the static initializer of an96* {@link InterfaceType}.97*98* @return the {@link ReferenceType} containing this Location.99*/100ReferenceType declaringType();101102/**103* Gets the method containing this Location.104*105* @return the location's {@link Method}.106*/107Method method();108109/**110* Gets the code position within this location's method.111*112* @return the long representing the position within the method113* or -1 if location is within a native method.114*/115long codeIndex();116117/**118* Gets an identifing name for the source corresponding to119* this location.120* <P>121* This method is equivalent to122* <code>sourceName(vm.getDefaultStratum())</code> -123* see {@link #sourceName(String)}124* for more information.125*126* @return a string specifying the source127* @throws AbsentInformationException if the source name is not128* known129*/130String sourceName() throws AbsentInformationException;131132/**133* Gets an identifing name for the source corresponding to134* this location. Interpretation of this string is the135* responsibility of the source repository mechanism.136* <P>137* Returned name is for the specified <i>stratum</i>138* (see the {@link Location class comment} for a139* description of strata).140* <P>141* The returned string is the unqualified name of the source142* file for this Location. For example,143* <CODE>java.lang.Thread</CODE> would return144* <CODE>"Thread.java"</CODE>.145*146* @param stratum The stratum to retrieve information from147* or <code>null</code> for the declaring type's148* default stratum.149*150* @return a string specifying the source151*152* @throws AbsentInformationException if the source name is not153* known154*155* @since 1.4156*/157String sourceName(String stratum) throws AbsentInformationException;158159/**160* Gets the path to the source corresponding to this161* location.162* <P>163* This method is equivalent to164* <code>sourcePath(vm.getDefaultStratum())</code> -165* see {@link #sourcePath(String)}166* for more information.167*168* @return a string specifying the source169*170* @throws AbsentInformationException if the source name is not171* known172*/173String sourcePath() throws AbsentInformationException;174175/**176* Gets the path to the source corresponding to this177* location. Interpretation of this string is the178* responsibility of the source repository mechanism.179* <P>180* Returned path is for the specified <i>stratum</i>181* (see the {@link Location class comment} for a182* description of strata).183* <P>184* In the reference implementation, for strata which185* do not explicitly specify source path (the Java186* programming language stratum never does), the returned187* string is the package name of {@link #declaringType()}188* converted to a platform dependent path followed by the189* unqualified name of the source file for this Location190* ({@link #sourceName sourceName(stratum)}).191* For example, on a192* Windows platform, <CODE>java.lang.Thread</CODE>193* would return194* <CODE>"java\lang\Thread.java"</CODE>.195*196* @param stratum The stratum to retrieve information from197* or <code>null</code> for the declaring type's198* default stratum.199*200* @return a string specifying the source201*202* @throws AbsentInformationException if the source name is not203* known204*205* @since 1.4206*/207String sourcePath(String stratum) throws AbsentInformationException;208209/**210* Gets the line number of this Location.211* <P>212* This method is equivalent to213* <code>lineNumber(vm.getDefaultStratum())</code> -214* see {@link #lineNumber(String)}215* for more information.216*217* @return an int specifying the line in the source, returns218* -1 if the information is not available; specifically, always219* returns -1 for native methods.220*/221int lineNumber();222223/**224* The line number of this Location. The line number is225* relative to the source specified by226* {@link #sourceName(String) sourceName(stratum)}.227* <P>228* Returned line number is for the specified <i>stratum</i>229* (see the {@link Location class comment} for a230* description of strata).231*232* @param stratum The stratum to retrieve information from233* or <code>null</code> for the declaring type's234* default stratum.235*236* @return an int specifying the line in the source, returns237* -1 if the information is not available; specifically, always238* returns -1 for native methods.239*240* @since 1.4241*/242int lineNumber(String stratum);243244/**245* Compares the specified Object with this Location for equality.246*247* @return true if the Object is a Location and if it refers to248* the same point in the same VM as this Location.249*/250boolean equals(Object obj);251252/**253* Returns the hash code value for this Location.254*255* @return the integer hash code256*/257int hashCode();258}259260261