1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2015, Red Hat Inc.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 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 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 package sun.jvm.hotspot.debugger.linux.aarch64;
  27 
  28 import sun.jvm.hotspot.debugger.*;
  29 import sun.jvm.hotspot.debugger.aarch64.*;
  30 import sun.jvm.hotspot.debugger.linux.*;
  31 import sun.jvm.hotspot.debugger.cdbg.*;
  32 import sun.jvm.hotspot.debugger.cdbg.basic.*;
  33 
  34 final public class LinuxAARCH64CFrame extends BasicCFrame {
  35    public LinuxAARCH64CFrame(LinuxDebugger dbg, Address fp, Address pc) {
  36       super(dbg.getCDebugger());
  37       this.fp = fp;
  38       this.pc = pc;
  39       this.dbg = dbg;
  40    }
  41 
  42    // override base class impl to avoid ELF parsing
  43    public ClosestSymbol closestSymbolToPC() {
  44       // try native lookup in debugger.
  45       return dbg.lookup(dbg.getAddressValue(pc()));
  46    }
  47 
  48    public Address pc() {
  49       return pc;
  50    }
  51 
  52    public Address localVariableBase() {
  53       return fp;
  54    }
  55 
  56    public CFrame sender(ThreadProxy thread) {
  57       AARCH64ThreadContext context = (AARCH64ThreadContext) thread.getContext();
  58       Address rsp = context.getRegisterAsAddress(AARCH64ThreadContext.SP);
  59 
  60       if ( (fp == null) || fp.lessThan(rsp) ) {
  61         return null;
  62       }
  63 
  64       // Check alignment of fp
  65       if ( dbg.getAddressValue(fp) % 2 * ADDRESS_SIZE != 0) {
  66         return null;
  67       }
  68 
  69       Address nextFP = fp.getAddressAt( 0 * ADDRESS_SIZE);
  70       if (nextFP == null || nextFP.lessThanOrEqual(rsp)) {
  71         return null;
  72       }
  73       Address nextPC  = fp.getAddressAt( 1 * ADDRESS_SIZE);
  74       if (nextPC == null) {
  75         return null;
  76       }
  77       return new LinuxAARCH64CFrame(dbg, nextFP, nextPC);
  78    }
  79 
  80    // package/class internals only
  81    private static final int ADDRESS_SIZE = 8;
  82    private Address pc;
  83    private Address sp;
  84    private Address fp;
  85    private LinuxDebugger dbg;
  86 }