blob: af79092c7c2db4cbe125edfbb9fdb89bb025a779 [file] [log] [blame]
Bruce Beare6cc49232010-10-13 16:11:15 -07001/* 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 Brown053b8652012-06-06 16:25:03 -070018#include <stddef.h>
19#include <stdbool.h>
20#include <stdlib.h>
21#include <string.h>
Bruce Beare6cc49232010-10-13 16:11:15 -070022#include <stdio.h>
23#include <errno.h>
Bruce Beare6cc49232010-10-13 16:11:15 -070024#include <sys/types.h>
Bruce Beare6cc49232010-10-13 16:11:15 -070025#include <sys/ptrace.h>
Bruce Beare6cc49232010-10-13 16:11:15 -070026
Jeff Brown13e715b2011-10-21 12:14:56 -070027#include <corkscrew/ptrace.h>
28
Jeff Brown053b8652012-06-06 16:25:03 -070029#include <linux/user.h>
Bruce Beare6cc49232010-10-13 16:11:15 -070030
31#include "../utility.h"
Jeff Brown053b8652012-06-06 16:25:03 -070032#include "../machine.h"
Bruce Beare6cc49232010-10-13 16:11:15 -070033
Jeff Brown053b8652012-06-06 16:25:03 -070034void dump_memory_and_code(const ptrace_context_t* context __attribute((unused)),
35 log_t* log, pid_t tid, bool at_fault) {
36}
37
38void dump_registers(const ptrace_context_t* context __attribute((unused)),
39 log_t* log, pid_t tid, bool at_fault) {
Bruce Beare6cc49232010-10-13 16:11:15 -070040 struct pt_regs_x86 r;
Christopher Tate7716aef2013-04-02 14:00:27 -070041 int scopeFlags = (at_fault ? SCOPE_AT_FAULT : 0);
Bruce Beare6cc49232010-10-13 16:11:15 -070042
Jeff Brownf0c58722011-11-03 17:58:44 -070043 if(ptrace(PTRACE_GETREGS, tid, 0, &r)) {
Christopher Tate7716aef2013-04-02 14:00:27 -070044 _LOG(log, scopeFlags, "cannot get registers: %s\n", strerror(errno));
Bruce Beare6cc49232010-10-13 16:11:15 -070045 return;
46 }
Jeff Brown13e715b2011-10-21 12:14:56 -070047 //if there is no stack, no print just like arm
Bruce Beare6cc49232010-10-13 16:11:15 -070048 if(!r.ebp)
49 return;
Christopher Tate7716aef2013-04-02 14:00:27 -070050 _LOG(log, scopeFlags, " eax %08x ebx %08x ecx %08x edx %08x\n",
Bruce Beare6cc49232010-10-13 16:11:15 -070051 r.eax, r.ebx, r.ecx, r.edx);
Christopher Tate7716aef2013-04-02 14:00:27 -070052 _LOG(log, scopeFlags, " esi %08x edi %08x\n",
Bruce Beare6cc49232010-10-13 16:11:15 -070053 r.esi, r.edi);
Christopher Tate7716aef2013-04-02 14:00:27 -070054 _LOG(log, scopeFlags, " xcs %08x xds %08x xes %08x xfs %08x xss %08x\n",
Bruce Beare6cc49232010-10-13 16:11:15 -070055 r.xcs, r.xds, r.xes, r.xfs, r.xss);
Christopher Tate7716aef2013-04-02 14:00:27 -070056 _LOG(log, scopeFlags, " eip %08x ebp %08x esp %08x flags %08x\n",
Bruce Beare6cc49232010-10-13 16:11:15 -070057 r.eip, r.ebp, r.esp, r.eflags);
58}