38
39 class LinuxCDebugger implements CDebugger {
40 private LinuxDebugger dbg;
41
42 LinuxCDebugger(LinuxDebugger dbg) {
43 this.dbg = dbg;
44 }
45
46 public List getThreadList() throws DebuggerException {
47 return dbg.getThreadList();
48 }
49
50 public List/*<LoadObject>*/ getLoadObjectList() throws DebuggerException {
51 return dbg.getLoadObjectList();
52 }
53
54 public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {
55 if (pc == null) {
56 return null;
57 }
58 List objs = getLoadObjectList();
59 Object[] arr = objs.toArray();
60 // load objects are sorted by base address, do binary search
61 int mid = -1;
62 int low = 0;
63 int high = arr.length - 1;
64
65 while (low <= high) {
66 mid = (low + high) >> 1;
67 LoadObject midVal = (LoadObject) arr[mid];
68 long cmp = pc.minus(midVal.getBase());
69 if (cmp < 0) {
70 high = mid - 1;
71 } else if (cmp > 0) {
72 long size = midVal.getSize();
73 if (cmp >= size) {
74 low = mid + 1;
75 } else {
76 return (LoadObject) arr[mid];
77 }
78 } else { // match found
79 return (LoadObject) arr[mid];
80 }
81 }
82 // no match found.
83 return null;
84 }
85
86 public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {
87 String cpu = dbg.getCPU();
88 if (cpu.equals("x86")) {
89 X86ThreadContext context = (X86ThreadContext) thread.getContext();
90 Address ebp = context.getRegisterAsAddress(X86ThreadContext.EBP);
91 if (ebp == null) return null;
92 Address pc = context.getRegisterAsAddress(X86ThreadContext.EIP);
93 if (pc == null) return null;
94 return new LinuxX86CFrame(dbg, ebp, pc);
95 } else if (cpu.equals("amd64")) {
96 AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
97 Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
98 if (rbp == null) return null;
99 Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
100 if (pc == null) return null;
101 return new LinuxAMD64CFrame(dbg, rbp, pc);
102 } else if (cpu.equals("sparc")) {
|
38
39 class LinuxCDebugger implements CDebugger {
40 private LinuxDebugger dbg;
41
42 LinuxCDebugger(LinuxDebugger dbg) {
43 this.dbg = dbg;
44 }
45
46 public List getThreadList() throws DebuggerException {
47 return dbg.getThreadList();
48 }
49
50 public List/*<LoadObject>*/ getLoadObjectList() throws DebuggerException {
51 return dbg.getLoadObjectList();
52 }
53
54 public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {
55 if (pc == null) {
56 return null;
57 }
58
59 /* Typically we have about ten loaded objects here. So no reason to do
60 sort/binary search here. Linear search gives us acceptable performance.*/
61
62 List objs = getLoadObjectList();
63
64 for (int i = 0; i < objs.size(); i++) {
65 LoadObject ob = (LoadObject) objs.get(i);
66 Address base = ob.getBase();
67 long size = ob.getSize();
68 if ( pc.greaterThanOrEqual(base) && pc.lessThan(base.addOffsetTo(size))) {
69 return ob;
70 }
71 }
72
73 return null;
74 }
75
76 public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {
77 String cpu = dbg.getCPU();
78 if (cpu.equals("x86")) {
79 X86ThreadContext context = (X86ThreadContext) thread.getContext();
80 Address ebp = context.getRegisterAsAddress(X86ThreadContext.EBP);
81 if (ebp == null) return null;
82 Address pc = context.getRegisterAsAddress(X86ThreadContext.EIP);
83 if (pc == null) return null;
84 return new LinuxX86CFrame(dbg, ebp, pc);
85 } else if (cpu.equals("amd64")) {
86 AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
87 Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
88 if (rbp == null) return null;
89 Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
90 if (pc == null) return null;
91 return new LinuxAMD64CFrame(dbg, rbp, pc);
92 } else if (cpu.equals("sparc")) {
|