1 /*
   2  * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.debugger.cdbg.basic;
  26 
  27 import sun.jvm.hotspot.debugger.*;
  28 import sun.jvm.hotspot.debugger.cdbg.*;
  29 
  30 /** Basic implementation of the CFrame interface providing some of the
  31     functionality in a platform-independent manner. */
  32 
  33 public abstract class BasicCFrame implements CFrame {
  34   private CDebugger dbg;
  35 
  36   protected BasicCFrame(CDebugger dbg) {
  37     this.dbg = dbg;
  38   }
  39 
  40   protected CDebugger dbg() {
  41     return dbg;
  42   }
  43 
  44   public LoadObject loadObjectForPC() {
  45     return dbg.loadObjectContainingPC(pc());
  46   }
  47 
  48   public BlockSym blockForPC() {
  49     LoadObject lo = loadObjectForPC();
  50     if (lo == null) {
  51       return null;
  52     }
  53     return lo.debugInfoForPC(pc());
  54   }
  55 
  56   public ClosestSymbol closestSymbolToPC() {
  57     LoadObject lo = loadObjectForPC();
  58     if (lo == null) {
  59       return null;
  60     }
  61     return lo.closestSymbolToPC(pc());
  62   }
  63 
  64   public void iterateLocals(ObjectVisitor v) {
  65     BlockSym block = blockForPC();
  66     while (block != null) {
  67       for (int i = 0; i < block.getNumLocals(); i++) {
  68         final LocalSym local = block.getLocal(i);
  69         Type t = local.getType();
  70         // t should not be null, but be robust in case of bugs in
  71         // debug info
  72         if (t != null) {
  73           t.iterateObject(localVariableBase().addOffsetTo(local.getFrameOffset()),
  74                           v,
  75                           new NamedFieldIdentifier() {
  76                               public Type getType() {
  77                                 return local.getType();
  78                               }
  79 
  80                               public String getName() {
  81                                 return local.getName();
  82                               }
  83 
  84                               public String toString() {
  85                                 return getName();
  86                               }
  87                             });
  88         }
  89       }
  90 
  91       block = block.getParent();
  92     }
  93   }
  94 }