Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java
42819 views
1
/*
2
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
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.bsd;
27
28
import java.io.*;
29
import java.util.*;
30
import sun.jvm.hotspot.debugger.*;
31
import sun.jvm.hotspot.debugger.cdbg.*;
32
import sun.jvm.hotspot.debugger.x86.*;
33
import sun.jvm.hotspot.debugger.amd64.*;
34
import sun.jvm.hotspot.debugger.aarch64.*;
35
import sun.jvm.hotspot.debugger.bsd.x86.*;
36
import sun.jvm.hotspot.debugger.bsd.amd64.*;
37
import sun.jvm.hotspot.debugger.bsd.aarch64.*;
38
import sun.jvm.hotspot.utilities.*;
39
40
class BsdCDebugger implements CDebugger {
41
private BsdDebugger dbg;
42
43
BsdCDebugger(BsdDebugger dbg) {
44
this.dbg = dbg;
45
}
46
47
public List<ThreadProxy> getThreadList() throws DebuggerException {
48
return dbg.getThreadList();
49
}
50
51
public List<LoadObject> getLoadObjectList() throws DebuggerException {
52
return dbg.getLoadObjectList();
53
}
54
55
public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {
56
if (pc == null) {
57
return null;
58
}
59
List<LoadObject> objs = getLoadObjectList();
60
Object[] arr = objs.toArray();
61
// load objects are sorted by base address, do binary search
62
int mid = -1;
63
int low = 0;
64
int high = arr.length - 1;
65
66
while (low <= high) {
67
mid = (low + high) >> 1;
68
LoadObject midVal = (LoadObject) arr[mid];
69
long cmp = pc.minus(midVal.getBase());
70
if (cmp < 0) {
71
high = mid - 1;
72
} else if (cmp > 0) {
73
long size = midVal.getSize();
74
if (cmp >= size) {
75
low = mid + 1;
76
} else {
77
return (LoadObject) arr[mid];
78
}
79
} else { // match found
80
return (LoadObject) arr[mid];
81
}
82
}
83
// no match found.
84
return null;
85
}
86
87
public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {
88
String cpu = dbg.getCPU();
89
if (cpu.equals("x86")) {
90
X86ThreadContext context = (X86ThreadContext) thread.getContext();
91
Address ebp = context.getRegisterAsAddress(X86ThreadContext.EBP);
92
if (ebp == null) return null;
93
Address pc = context.getRegisterAsAddress(X86ThreadContext.EIP);
94
if (pc == null) return null;
95
return new BsdX86CFrame(dbg, ebp, pc);
96
} else if (cpu.equals("amd64") || cpu.equals("x86_64")) {
97
AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
98
Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
99
if (rbp == null) return null;
100
Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
101
if (pc == null) return null;
102
return new BsdAMD64CFrame(dbg, rbp, pc);
103
} else if (cpu.equals("aarch64")) {
104
AARCH64ThreadContext context = (AARCH64ThreadContext) thread.getContext();
105
Address fp = context.getRegisterAsAddress(AARCH64ThreadContext.FP);
106
if (fp == null) return null;
107
Address pc = context.getRegisterAsAddress(AARCH64ThreadContext.PC);
108
if (pc == null) return null;
109
return new BsdAARCH64CFrame(dbg, fp, pc);
110
} else {
111
throw new DebuggerException(cpu + " is not yet supported");
112
}
113
}
114
115
public String getNameOfFile(String fileName) {
116
return new File(fileName).getName();
117
}
118
119
public ProcessControl getProcessControl() throws DebuggerException {
120
// FIXME: after stabs parser
121
return null;
122
}
123
124
public boolean canDemangle() {
125
return false;
126
}
127
128
public String demangle(String sym) {
129
throw new UnsupportedOperationException();
130
}
131
}
132
133