001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.cnd.debugger.gdb;
043:
044: import java.util.List;
045: import java.util.logging.Logger;
046: import javax.swing.SwingUtilities;
047: import org.netbeans.modules.cnd.debugger.gdb.models.AbstractVariable;
048:
049: /**
050: * Represents one stack frame.
051: *
052: * <pre style="background-color: rgb(255, 255, 102);">
053: * Since JDI interfaces evolve from one version to another, it's strongly recommended
054: * not to implement this interface in client code. New methods can be added to
055: * this interface at any time to keep up with the JDI functionality.</pre>
056: *
057: * @author Gordon Prieur (copied from Jan Jancura's JPDA implementation)
058: */
059: public class CallStackFrame {
060: private final GdbDebugger debugger;
061: private final int lineNumber;
062: private final String func;
063: private final String file;
064: private final String fullname;
065: private final int frameNumber;
066: private final String address;
067:
068: private LocalVariable[] cachedLocalVariables = null;
069: private Logger log = Logger.getLogger("gdb.logger"); // NOI18N
070:
071: public CallStackFrame(GdbDebugger debugger, String func,
072: String file, String fullname, String lnum, String address,
073: int frameNumber) {
074: this .debugger = debugger;
075: this .func = func;
076: this .file = file;
077: this .fullname = fullname;
078: this .address = address;
079: this .frameNumber = frameNumber;
080: int lNumber = -1;
081: if (lnum != null) {
082: try {
083: lNumber = Integer.parseInt(lnum);
084: } catch (NumberFormatException ex) {
085: lNumber = 1; // shouldn't happen
086: }
087: } else {
088: lNumber = -1;
089: }
090: this .lineNumber = lNumber;
091: }
092:
093: /**
094: * Get frame number.
095: *
096: * @return Frame nunmber in Call Stack ("0" means top)
097: */
098: public int getFrameNumber() {
099: return frameNumber;
100: }
101:
102: /**
103: * Returns line number associated with this stack frame.
104: *
105: * @return line number associated with this this stack frame
106: */
107: public int getLineNumber() {
108: return lineNumber;
109: }
110:
111: /**
112: * Returns method name associated with this stack frame.
113: *
114: * @return method name associated with this stack frame
115: */
116: public String getFunctionName() {
117: return func;
118: }
119:
120: /**
121: * Returns name of file this stack frame is stopped in.
122: *
123: * @return name of file this stack frame is stopped in
124: */
125: public String getFileName() {
126: return file;
127: }
128:
129: /**
130: * Returns name of file this stack frame is stopped in.
131: *
132: * @return name of file this stack frame is stopped in
133: */
134: public String getFullname() {
135: return fullname;
136: }
137:
138: /**
139: * @return address this stack frame is stopped in
140: */
141: public String getAddr() {
142: return address;
143: }
144:
145: /** Sets this frame current */
146: public void makeCurrent() {
147: debugger.setCurrentCallStackFrame(this );
148: }
149:
150: /** UNCOMMENT WHEN THIS METHOD IS NEEDED. IT'S ALREADY IMPLEMENTED IN THE IMPL. CLASS.
151: * Determine, if this stack frame can be poped off the stack.
152: *
153: * @return <code>true</code> if this frame can be poped
154: *
155: * public abstract boolean canPop();
156: */
157:
158: /**
159: * Pop stack frames. All frames up to and including the frame
160: * are popped off the stack. The frame previous to the parameter
161: * frame will become the current frame.
162: */
163: public void popFrame() {
164: debugger.getGdbProxy().exec_finish();
165: }
166:
167: /**
168: * Returns local variables.
169: * If local variables are not available returns empty array.
170: *
171: * NOTE: This method should <b>not</b> be called from GdbReaderRP as it can block
172: * waiting for type information to be returned on that thread.
173: *
174: * @return local variables
175: */
176: public LocalVariable[] getLocalVariables() {
177: assert !(Thread.currentThread().getName().equals("GdbReaderRP"));
178: assert !(SwingUtilities.isEventDispatchThread());
179:
180: if (cachedLocalVariables == null) {
181: List<GdbVariable> list = debugger.getLocalVariables();
182: int n = list.size();
183:
184: LocalVariable[] locals = new LocalVariable[n];
185: for (int i = 0; i < n; i++) {
186: locals[i] = new AbstractVariable(list.get(i));
187: }
188: cachedLocalVariables = locals;
189: return locals;
190: } else {
191: return cachedLocalVariables;
192: }
193: }
194:
195: @Override
196: public int hashCode() {
197: // currently default hash code and equals are the optimal ones,
198: // because CallStackFrames can not be equal if they are not the same object
199: return super.hashCode();
200: }
201: }
|