Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 1 | /* system/debuggerd/debuggerd.c |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 18 | #include <stddef.h> |
| 19 | #include <stdbool.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <errno.h> |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 24 | #include <sys/types.h> |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 25 | #include <sys/ptrace.h> |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 26 | |
Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 27 | #include <corkscrew/ptrace.h> |
| 28 | |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 29 | #include <linux/user.h> |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 30 | |
| 31 | #include "../utility.h" |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 32 | #include "../machine.h" |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 33 | |
Christopher Ferris | 365e4ae | 2013-10-02 12:26:48 -0700 | [diff] [blame] | 34 | void dump_memory_and_code(log_t* log, pid_t tid, int scope_flags) { |
Jeff Brown | 053b865 | 2012-06-06 16:25:03 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Christopher Ferris | 365e4ae | 2013-10-02 12:26:48 -0700 | [diff] [blame] | 37 | void dump_registers(log_t* log, pid_t tid, int scope_flags) { |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 38 | struct pt_regs_x86 r; |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 39 | if(ptrace(PTRACE_GETREGS, tid, 0, &r)) { |
Christopher Ferris | 365e4ae | 2013-10-02 12:26:48 -0700 | [diff] [blame] | 40 | _LOG(log, scope_flags, "cannot get registers: %s\n", strerror(errno)); |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 41 | return; |
| 42 | } |
Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 43 | //if there is no stack, no print just like arm |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 44 | if(!r.ebp) |
| 45 | return; |
Christopher Ferris | 365e4ae | 2013-10-02 12:26:48 -0700 | [diff] [blame] | 46 | _LOG(log, scope_flags, " eax %08x ebx %08x ecx %08x edx %08x\n", |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 47 | r.eax, r.ebx, r.ecx, r.edx); |
Christopher Ferris | 365e4ae | 2013-10-02 12:26:48 -0700 | [diff] [blame] | 48 | _LOG(log, scope_flags, " esi %08x edi %08x\n", |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 49 | r.esi, r.edi); |
Christopher Ferris | 365e4ae | 2013-10-02 12:26:48 -0700 | [diff] [blame] | 50 | _LOG(log, scope_flags, " xcs %08x xds %08x xes %08x xfs %08x xss %08x\n", |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 51 | r.xcs, r.xds, r.xes, r.xfs, r.xss); |
Christopher Ferris | 365e4ae | 2013-10-02 12:26:48 -0700 | [diff] [blame] | 52 | _LOG(log, scope_flags, " eip %08x ebp %08x esp %08x flags %08x\n", |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 53 | r.eip, r.ebp, r.esp, r.eflags); |
| 54 | } |