stacktrace.cc revision 14020
19363Snilay@cs.wisc.edu/* 29363Snilay@cs.wisc.edu * Copyright (c) 2005 The Regents of The University of Michigan 39363Snilay@cs.wisc.edu * All rights reserved. 49363Snilay@cs.wisc.edu * 59363Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without 69363Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are 79363Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright 89363Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer; 99363Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright 109363Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 119363Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution; 129363Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its 139363Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from 149363Snilay@cs.wisc.edu * this software without specific prior written permission. 159363Snilay@cs.wisc.edu * 169363Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179363Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 189363Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 199363Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 209363Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 219363Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 229363Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239363Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249363Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259363Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 269363Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279363Snilay@cs.wisc.edu * 289363Snilay@cs.wisc.edu * Authors: Nathan Binkert 299363Snilay@cs.wisc.edu */ 309363Snilay@cs.wisc.edu 319363Snilay@cs.wisc.edu#include "arch/arm/stacktrace.hh" 329363Snilay@cs.wisc.edu 339363Snilay@cs.wisc.edu#include <string> 349363Snilay@cs.wisc.edu 359363Snilay@cs.wisc.edu#include "arch/arm/isa_traits.hh" 3611052Sandreas.hansson@arm.com#include "arch/arm/vtophys.hh" 3710301Snilay@cs.wisc.edu#include "base/bitfield.hh" 3810970Sdavid.hashe@amd.com#include "base/trace.hh" 3910970Sdavid.hashe@amd.com#include "cpu/base.hh" 4010970Sdavid.hashe@amd.com#include "cpu/thread_context.hh" 4110301Snilay@cs.wisc.edu#include "mem/fs_translating_port_proxy.hh" 429363Snilay@cs.wisc.edu#include "sim/system.hh" 4310301Snilay@cs.wisc.edu 4410301Snilay@cs.wisc.edunamespace ArmISA 4510970Sdavid.hashe@amd.com{ 4610301Snilay@cs.wisc.edu 4710301Snilay@cs.wisc.edustatic int32_t 4810970Sdavid.hashe@amd.comreadSymbol(ThreadContext *tc, const std::string name) 4910970Sdavid.hashe@amd.com{ 5010301Snilay@cs.wisc.edu PortProxy &vp = tc->getVirtProxy(); 5110301Snilay@cs.wisc.edu SymbolTable *symtab = tc->getSystemPtr()->kernelSymtab; 5210301Snilay@cs.wisc.edu 5310301Snilay@cs.wisc.edu Addr addr; 549363Snilay@cs.wisc.edu if (!symtab->findAddress(name, addr)) 5510301Snilay@cs.wisc.edu panic("thread info not compiled into kernel\n"); 5610301Snilay@cs.wisc.edu 57 return vp.read<int32_t>(addr, GuestByteOrder); 58} 59 60ProcessInfo::ProcessInfo(ThreadContext *_tc) : tc(_tc) 61{ 62 thread_info_size = readSymbol(tc, "thread_info_size"); 63 task_struct_size = readSymbol(tc, "task_struct_size"); 64 task_off = readSymbol(tc, "thread_info_task"); 65 pid_off = readSymbol(tc, "task_struct_pid"); 66 name_off = readSymbol(tc, "task_struct_comm"); 67} 68 69Addr 70ProcessInfo::task(Addr ksp) const 71{ 72 Addr base = ksp & ~0x1fff; 73 if (base == ULL(0xffffffffc0000000)) 74 return 0; 75 76 Addr tsk; 77 78 PortProxy &vp = tc->getVirtProxy(); 79 tsk = vp.read<Addr>(base + task_off, GuestByteOrder); 80 81 return tsk; 82} 83 84int 85ProcessInfo::pid(Addr ksp) const 86{ 87 Addr task = this->task(ksp); 88 if (!task) 89 return -1; 90 91 uint16_t pd; 92 93 PortProxy &vp = tc->getVirtProxy(); 94 pd = vp.read<uint16_t>(task + pid_off, GuestByteOrder); 95 96 return pd; 97} 98 99std::string 100ProcessInfo::name(Addr ksp) const 101{ 102 Addr task = this->task(ksp); 103 if (!task) 104 return "unknown"; 105 106 char comm[256]; 107 tc->getVirtProxy().readString(comm, task + name_off, sizeof(comm)); 108 if (!comm[0]) 109 return "startup"; 110 111 return comm; 112} 113 114StackTrace::StackTrace() 115 : tc(0), stack(64) 116{ 117} 118 119StackTrace::StackTrace(ThreadContext *_tc, const StaticInstPtr &inst) 120 : tc(0), stack(64) 121{ 122 trace(_tc, inst); 123} 124 125StackTrace::~StackTrace() 126{ 127} 128 129void 130StackTrace::trace(ThreadContext *_tc, bool is_call) 131{ 132} 133 134bool 135StackTrace::isEntry(Addr addr) 136{ 137 return false; 138} 139 140bool 141StackTrace::decodeStack(MachInst inst, int &disp) 142{ 143 return false; 144} 145 146bool 147StackTrace::decodeSave(MachInst inst, int ®, int &disp) 148{ 149 return false; 150} 151 152/* 153 * Decode the function prologue for the function we're in, and note 154 * which registers are stored where, and how large the stack frame is. 155 */ 156bool 157StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, 158 int &size, Addr &ra) 159{ 160 return false; 161} 162 163#if TRACING_ON 164void 165StackTrace::dump() 166{ 167 DPRINTFN("------ Stack ------\n"); 168 169 DPRINTFN(" Not implemented\n"); 170} 171#endif 172} 173