1 /*
2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
85 private Map<Integer, Integer> nspidMap;
86
87 // called by native method lookupByAddress0
88 private ClosestSymbol createClosestSymbol(String name, long offset) {
89 return new ClosestSymbol(name, offset);
90 }
91
92 // called by native method attach0
93 private LoadObject createLoadObject(String fileName, long textsize,
94 long base) {
95 File f = new File(fileName);
96 Address baseAddr = newAddress(base);
97 return new SharedObject(this, fileName, f.length(), baseAddr);
98 }
99
100 // native methods
101
102 private native static void init0()
103 throws DebuggerException;
104 private native void setSAAltRoot0(String altroot);
105 private native void attach0(int pid, boolean isInContainer)
106 throws DebuggerException;
107 private native void attach0(String execName, String coreName)
108 throws DebuggerException;
109 private native void detach0()
110 throws DebuggerException;
111 private native long lookupByName0(String objectName, String symbol)
112 throws DebuggerException;
113 private native ClosestSymbol lookupByAddress0(long address)
114 throws DebuggerException;
115 private native long[] getThreadIntegerRegisterSet0(int lwp_id)
116 throws DebuggerException;
117 private native byte[] readBytesFromProcess0(long address, long numBytes)
118 throws DebuggerException;
119 public native static int getAddressSize() ;
120
121 // Note on Linux threads are really processes. When target process is
122 // attached by a serviceability agent thread, only that thread can do
123 // ptrace operations on the target. This is because from kernel's point
124 // view, other threads are just separate processes and they are not
125 // attached to the target. When they attempt to make ptrace calls,
304
305 /** From the Debugger interface via JVMDebugger */
306 public synchronized void attach(int processID) throws DebuggerException {
307 checkAttached();
308 threadList = new ArrayList();
309 loadObjectList = new ArrayList();
310
311 Path proc = Paths.get("/proc", Integer.toString(processID));
312 int NSpid = getNamespacePID(Paths.get(proc.toString(), "status"));
313 if (NSpid != processID) {
314 // If PID different from namespace PID, we can assume the process
315 // is running in the container.
316 // So we need to set SA_ALTROOT environment variable that SA reads
317 // binaries in the container.
318 setSAAltRoot0(Paths.get(proc.toString(), "root").toString());
319 fillNSpidMap(proc);
320 }
321
322 class AttachTask implements WorkerThreadTask {
323 int pid;
324 boolean isInContainer;
325 public void doit(LinuxDebuggerLocal debugger) {
326 debugger.attach0(pid, isInContainer);
327 debugger.attached = true;
328 debugger.isCore = false;
329 findABIVersion();
330 }
331 }
332
333 AttachTask task = new AttachTask();
334 task.pid = processID;
335 task.isInContainer = (processID != NSpid);
336 workerThread.execute(task);
337 }
338
339 /** From the Debugger interface via JVMDebugger */
340 public synchronized void attach(String execName, String coreName) {
341 checkAttached();
342 threadList = new ArrayList();
343 loadObjectList = new ArrayList();
344 attach0(execName, coreName);
345 attached = true;
346 isCore = true;
347 findABIVersion();
348 }
349
350 /** From the Debugger interface via JVMDebugger */
351 public synchronized boolean detach() {
352 if (!attached) {
353 return false;
354 }
355
|
1 /*
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
85 private Map<Integer, Integer> nspidMap;
86
87 // called by native method lookupByAddress0
88 private ClosestSymbol createClosestSymbol(String name, long offset) {
89 return new ClosestSymbol(name, offset);
90 }
91
92 // called by native method attach0
93 private LoadObject createLoadObject(String fileName, long textsize,
94 long base) {
95 File f = new File(fileName);
96 Address baseAddr = newAddress(base);
97 return new SharedObject(this, fileName, f.length(), baseAddr);
98 }
99
100 // native methods
101
102 private native static void init0()
103 throws DebuggerException;
104 private native void setSAAltRoot0(String altroot);
105 private native void attach0(int pid)
106 throws DebuggerException;
107 private native void attach0(String execName, String coreName)
108 throws DebuggerException;
109 private native void detach0()
110 throws DebuggerException;
111 private native long lookupByName0(String objectName, String symbol)
112 throws DebuggerException;
113 private native ClosestSymbol lookupByAddress0(long address)
114 throws DebuggerException;
115 private native long[] getThreadIntegerRegisterSet0(int lwp_id)
116 throws DebuggerException;
117 private native byte[] readBytesFromProcess0(long address, long numBytes)
118 throws DebuggerException;
119 public native static int getAddressSize() ;
120
121 // Note on Linux threads are really processes. When target process is
122 // attached by a serviceability agent thread, only that thread can do
123 // ptrace operations on the target. This is because from kernel's point
124 // view, other threads are just separate processes and they are not
125 // attached to the target. When they attempt to make ptrace calls,
304
305 /** From the Debugger interface via JVMDebugger */
306 public synchronized void attach(int processID) throws DebuggerException {
307 checkAttached();
308 threadList = new ArrayList();
309 loadObjectList = new ArrayList();
310
311 Path proc = Paths.get("/proc", Integer.toString(processID));
312 int NSpid = getNamespacePID(Paths.get(proc.toString(), "status"));
313 if (NSpid != processID) {
314 // If PID different from namespace PID, we can assume the process
315 // is running in the container.
316 // So we need to set SA_ALTROOT environment variable that SA reads
317 // binaries in the container.
318 setSAAltRoot0(Paths.get(proc.toString(), "root").toString());
319 fillNSpidMap(proc);
320 }
321
322 class AttachTask implements WorkerThreadTask {
323 int pid;
324 public void doit(LinuxDebuggerLocal debugger) {
325 debugger.attach0(pid);
326 debugger.attached = true;
327 debugger.isCore = false;
328 findABIVersion();
329 }
330 }
331
332 AttachTask task = new AttachTask();
333 task.pid = processID;
334 workerThread.execute(task);
335 }
336
337 /** From the Debugger interface via JVMDebugger */
338 public synchronized void attach(String execName, String coreName) {
339 checkAttached();
340 threadList = new ArrayList();
341 loadObjectList = new ArrayList();
342 attach0(execName, coreName);
343 attached = true;
344 isCore = true;
345 findABIVersion();
346 }
347
348 /** From the Debugger interface via JVMDebugger */
349 public synchronized boolean detach() {
350 if (!attached) {
351 return false;
352 }
353
|