| 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 |  | 
|  | 18 | #include <stdio.h> | 
|  | 19 | #include <errno.h> | 
|  | 20 | #include <signal.h> | 
|  | 21 | #include <pthread.h> | 
|  | 22 | #include <fcntl.h> | 
|  | 23 | #include <sys/types.h> | 
|  | 24 | #include <dirent.h> | 
|  | 25 |  | 
|  | 26 | #include <sys/ptrace.h> | 
|  | 27 | #include <sys/wait.h> | 
|  | 28 | #include <sys/exec_elf.h> | 
|  | 29 | #include <sys/stat.h> | 
|  | 30 |  | 
|  | 31 | #include <cutils/sockets.h> | 
|  | 32 | #include <cutils/properties.h> | 
|  | 33 |  | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 34 | #include <corkscrew/backtrace.h> | 
|  | 35 | #include <corkscrew/ptrace.h> | 
|  | 36 |  | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 37 | #include <linux/input.h> | 
|  | 38 |  | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 39 | #include "../machine.h" | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 40 | #include "../utility.h" | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 41 |  | 
| Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 42 | static void dump_registers(const ptrace_context_t* context __attribute((unused)), | 
|  | 43 | int tfd, pid_t tid, bool at_fault) { | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 44 | struct pt_regs_x86 r; | 
|  | 45 | bool only_in_tombstone = !at_fault; | 
|  | 46 |  | 
| Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 47 | if(ptrace(PTRACE_GETREGS, tid, 0, &r)) { | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 48 | _LOG(tfd, only_in_tombstone, "cannot get registers: %s\n", strerror(errno)); | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 49 | return; | 
|  | 50 | } | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 51 | //if there is no stack, no print just like arm | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 52 | if(!r.ebp) | 
|  | 53 | return; | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 54 | _LOG(tfd, only_in_tombstone, "    eax %08x  ebx %08x  ecx %08x  edx %08x\n", | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 55 | r.eax, r.ebx, r.ecx, r.edx); | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 56 | _LOG(tfd, only_in_tombstone, "    esi %08x  edi %08x\n", | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 57 | r.esi, r.edi); | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 58 | _LOG(tfd, only_in_tombstone, "    xcs %08x  xds %08x  xes %08x  xfs %08x  xss %08x\n", | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 59 | r.xcs, r.xds, r.xes, r.xfs, r.xss); | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 60 | _LOG(tfd, only_in_tombstone, "    eip %08x  ebp %08x  esp %08x  flags %08x\n", | 
| Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 61 | r.eip, r.ebp, r.esp, r.eflags); | 
|  | 62 | } | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 63 |  | 
| Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 64 | void dump_thread(const ptrace_context_t* context, int tfd, pid_t tid, bool at_fault) { | 
| Jeff Brown | 13e715b | 2011-10-21 12:14:56 -0700 | [diff] [blame] | 65 | dump_registers(context, tfd, tid, at_fault); | 
|  | 66 |  | 
|  | 67 | dump_backtrace_and_stack(context, tfd, tid, at_fault); | 
|  | 68 |  | 
|  | 69 | if (at_fault) { | 
|  | 70 | dump_nearby_maps(context, tfd, tid); | 
|  | 71 | } | 
|  | 72 | } | 
|  | 73 |  |