Mercurial > hg > truffle
comparison agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java @ 8750:39432a1cefdd
8003348: SA can not read core file on OS
Summary: Macosx uses Mach-O file format for binary files, not ELF format. Currently SA works on core files on other platforms, t his change enables SA work on core file generated on Darwin.
Reviewed-by: sla, sspitsyn
Contributed-by: yumin.qi@oracle.com
author | minqi |
---|---|
date | Thu, 14 Mar 2013 00:33:08 -0700 |
parents | 758935f7c23f |
children | f6a055fcf47d |
comparison
equal
deleted
inserted
replaced
8719:c8b31b461e1a | 8750:39432a1cefdd |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
29 import java.util.*; | 29 import java.util.*; |
30 import sun.jvm.hotspot.debugger.*; | 30 import sun.jvm.hotspot.debugger.*; |
31 import sun.jvm.hotspot.debugger.x86.*; | 31 import sun.jvm.hotspot.debugger.x86.*; |
32 import sun.jvm.hotspot.debugger.cdbg.*; | 32 import sun.jvm.hotspot.debugger.cdbg.*; |
33 import sun.jvm.hotspot.utilities.*; | 33 import sun.jvm.hotspot.utilities.*; |
34 import sun.jvm.hotspot.runtime.VM; | |
35 import sun.jvm.hotspot.runtime.Threads; | |
36 import sun.jvm.hotspot.runtime.JavaThread; | |
34 import java.lang.reflect.*; | 37 import java.lang.reflect.*; |
35 | 38 |
36 /** <P> An implementation of the JVMDebugger interface. The basic debug | 39 /** <P> An implementation of the JVMDebugger interface. The basic debug |
37 facilities are implemented through ptrace interface in the JNI code | 40 facilities are implemented through ptrace interface in the JNI code |
38 (libsaproc.so). Library maps and symbol table management are done in | 41 (libsaproc.so). Library maps and symbol table management are done in |
49 configured with the Java primitive type sizes. </P> */ | 52 configured with the Java primitive type sizes. </P> */ |
50 | 53 |
51 public class BsdDebuggerLocal extends DebuggerBase implements BsdDebugger { | 54 public class BsdDebuggerLocal extends DebuggerBase implements BsdDebugger { |
52 private boolean useGCC32ABI; | 55 private boolean useGCC32ABI; |
53 private boolean attached; | 56 private boolean attached; |
54 private long p_ps_prochandle; // native debugger handle | 57 private long p_ps_prochandle; // native debugger handle |
55 private long symbolicator; // macosx symbolicator handle | 58 private long symbolicator; // macosx symbolicator handle |
56 private long task; // macosx task handle | 59 private long task; // macosx task handle |
57 private boolean isCore; | 60 private boolean isCore; |
61 private boolean isDarwin; // variant for bsd | |
58 | 62 |
59 // CDebugger support | 63 // CDebugger support |
60 private BsdCDebugger cdbg; | 64 private BsdCDebugger cdbg; |
61 | 65 |
62 // threadList and loadObjectList are filled by attach0 method | 66 // threadList and loadObjectList are filled by attach0 method |
206 } else { | 210 } else { |
207 initCache(4096, parseCacheNumPagesProperty(4096)); | 211 initCache(4096, parseCacheNumPagesProperty(4096)); |
208 } | 212 } |
209 } | 213 } |
210 | 214 |
215 isDarwin = getOS().equals("darwin"); | |
211 workerThread = new BsdDebuggerLocalWorkerThread(this); | 216 workerThread = new BsdDebuggerLocalWorkerThread(this); |
212 workerThread.start(); | 217 workerThread.start(); |
213 } | 218 } |
214 | 219 |
215 /** From the Debugger interface via JVMDebugger */ | 220 /** From the Debugger interface via JVMDebugger */ |
238 } | 243 } |
239 } | 244 } |
240 | 245 |
241 /* called from attach methods */ | 246 /* called from attach methods */ |
242 private void findABIVersion() throws DebuggerException { | 247 private void findABIVersion() throws DebuggerException { |
243 if (lookupByName0("libjvm.so", "__vt_10JavaThread") != 0 || | 248 String libjvmName = isDarwin ? "libjvm.dylib" : "libjvm.so"; |
244 lookupByName0("libjvm_g.so", "__vt_10JavaThread") != 0) { | 249 String libjvm_gName = isDarwin? "libjvm_g.dylib" : "libjvm_g.so"; |
250 String javaThreadVt = isDarwin ? "_vt_10JavaThread" : "__vt_10JavaThread"; | |
251 if (lookupByName0(libjvmName, javaThreadVt) != 0 || | |
252 lookupByName0(libjvm_gName, javaThreadVt) != 0) { | |
245 // old C++ ABI | 253 // old C++ ABI |
246 useGCC32ABI = false; | 254 useGCC32ABI = false; |
247 } else { | 255 } else { |
248 // new C++ ABI | 256 // new C++ ABI |
249 useGCC32ABI = true; | 257 useGCC32ABI = true; |
358 if (!attached) { | 366 if (!attached) { |
359 return null; | 367 return null; |
360 } | 368 } |
361 | 369 |
362 if (isCore) { | 370 if (isCore) { |
363 long addr = lookupByName0(objectName, symbol); | 371 // MacOSX symbol with "_" as leading |
372 long addr = lookupByName0(objectName, isDarwin ? "_" + symbol : symbol); | |
364 return (addr == 0)? null : new BsdAddress(this, handleGCC32ABI(addr, symbol)); | 373 return (addr == 0)? null : new BsdAddress(this, handleGCC32ABI(addr, symbol)); |
365 } else { | 374 } else { |
366 class LookupByNameTask implements WorkerThreadTask { | 375 class LookupByNameTask implements WorkerThreadTask { |
367 String objectName, symbol; | 376 String objectName, symbol; |
368 Address result; | 377 Address result; |
401 | 410 |
402 /** From the ThreadAccess interface via Debugger and JVMDebugger */ | 411 /** From the ThreadAccess interface via Debugger and JVMDebugger */ |
403 public ThreadProxy getThreadForIdentifierAddress(Address threadIdAddr, Address uniqueThreadIdAddr) { | 412 public ThreadProxy getThreadForIdentifierAddress(Address threadIdAddr, Address uniqueThreadIdAddr) { |
404 return new BsdThread(this, threadIdAddr, uniqueThreadIdAddr); | 413 return new BsdThread(this, threadIdAddr, uniqueThreadIdAddr); |
405 } | 414 } |
415 | |
406 @Override | 416 @Override |
407 public ThreadProxy getThreadForIdentifierAddress(Address addr) { | 417 public ThreadProxy getThreadForIdentifierAddress(Address addr) { |
408 throw new RuntimeException("unimplemented"); | 418 throw new RuntimeException("unimplemented"); |
409 } | 419 } |
410 | |
411 | 420 |
412 /** From the ThreadAccess interface via Debugger and JVMDebugger */ | 421 /** From the ThreadAccess interface via Debugger and JVMDebugger */ |
413 public ThreadProxy getThreadForThreadId(long id) { | 422 public ThreadProxy getThreadForThreadId(long id) { |
414 return new BsdThread(this, id); | 423 return new BsdThread(this, id); |
415 } | 424 } |
599 throws UnmappedAddressException, DebuggerException { | 608 throws UnmappedAddressException, DebuggerException { |
600 // FIXME | 609 // FIXME |
601 throw new DebuggerException("Unimplemented"); | 610 throw new DebuggerException("Unimplemented"); |
602 } | 611 } |
603 | 612 |
613 /** this functions used for core file reading and called from native attach0, | |
614 it returns an array of long integers as | |
615 [thread_id, stack_start, stack_end, thread_id, stack_start, stack_end, ....] for | |
616 all java threads recorded in Threads. Also adds the ThreadProxy to threadList */ | |
617 public long[] getJavaThreadsInfo() { | |
618 requireAttach(); | |
619 Threads threads = VM.getVM().getThreads(); | |
620 int len = threads.getNumberOfThreads(); | |
621 long[] result = new long[len * 3]; // triple | |
622 JavaThread t = threads.first(); | |
623 long beg, end; | |
624 int i = 0; | |
625 while (t != null) { | |
626 end = t.getStackBaseValue(); | |
627 beg = end - t.getStackSize(); | |
628 BsdThread bsdt = (BsdThread)t.getThreadProxy(); | |
629 long uid = bsdt.getUniqueThreadId(); | |
630 if (threadList != null) threadList.add(bsdt); | |
631 result[i] = uid; | |
632 result[i + 1] = beg; | |
633 result[i + 2] = end; | |
634 t = t.next(); | |
635 i += 3; | |
636 } | |
637 return result; | |
638 } | |
639 | |
604 static { | 640 static { |
605 System.loadLibrary("saproc"); | 641 System.loadLibrary("saproc"); |
606 init0(); | 642 init0(); |
607 } | 643 } |
608 } | 644 } |