Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java
42819 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2021, Azul Systems, 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425package sun.jvm.hotspot.debugger.bsd;2627import java.io.*;28import java.util.*;29import sun.jvm.hotspot.debugger.*;30import sun.jvm.hotspot.debugger.cdbg.*;31import sun.jvm.hotspot.debugger.x86.*;32import sun.jvm.hotspot.debugger.amd64.*;33import sun.jvm.hotspot.debugger.aarch64.*;34import sun.jvm.hotspot.debugger.bsd.x86.*;35import sun.jvm.hotspot.debugger.bsd.amd64.*;36import sun.jvm.hotspot.debugger.bsd.aarch64.*;37import sun.jvm.hotspot.utilities.*;3839class BsdCDebugger implements CDebugger {40private BsdDebugger dbg;4142BsdCDebugger(BsdDebugger dbg) {43this.dbg = dbg;44}4546public List<ThreadProxy> getThreadList() throws DebuggerException {47return dbg.getThreadList();48}4950public List<LoadObject> getLoadObjectList() throws DebuggerException {51return dbg.getLoadObjectList();52}5354public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {55if (pc == null) {56return null;57}58List<LoadObject> objs = getLoadObjectList();59Object[] arr = objs.toArray();60// load objects are sorted by base address, do binary search61int mid = -1;62int low = 0;63int high = arr.length - 1;6465while (low <= high) {66mid = (low + high) >> 1;67LoadObject midVal = (LoadObject) arr[mid];68long cmp = pc.minus(midVal.getBase());69if (cmp < 0) {70high = mid - 1;71} else if (cmp > 0) {72long size = midVal.getSize();73if (cmp >= size) {74low = mid + 1;75} else {76return (LoadObject) arr[mid];77}78} else { // match found79return (LoadObject) arr[mid];80}81}82// no match found.83return null;84}8586public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {87String cpu = dbg.getCPU();88if (cpu.equals("x86")) {89X86ThreadContext context = (X86ThreadContext) thread.getContext();90Address ebp = context.getRegisterAsAddress(X86ThreadContext.EBP);91if (ebp == null) return null;92Address pc = context.getRegisterAsAddress(X86ThreadContext.EIP);93if (pc == null) return null;94return new BsdX86CFrame(dbg, ebp, pc);95} else if (cpu.equals("amd64") || cpu.equals("x86_64")) {96AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();97Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);98if (rbp == null) return null;99Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP);100if (pc == null) return null;101return new BsdAMD64CFrame(dbg, rbp, pc);102} else if (cpu.equals("aarch64")) {103AARCH64ThreadContext context = (AARCH64ThreadContext) thread.getContext();104Address fp = context.getRegisterAsAddress(AARCH64ThreadContext.FP);105if (fp == null) return null;106Address pc = context.getRegisterAsAddress(AARCH64ThreadContext.PC);107if (pc == null) return null;108return new BsdAARCH64CFrame(dbg, fp, pc);109} else {110throw new DebuggerException(cpu + " is not yet supported");111}112}113114public String getNameOfFile(String fileName) {115return new File(fileName).getName();116}117118public ProcessControl getProcessControl() throws DebuggerException {119// FIXME: after stabs parser120return null;121}122123public boolean canDemangle() {124return false;125}126127public String demangle(String sym) {128throw new UnsupportedOperationException();129}130}131132133