stacktrace.cc revision 14020
1/*
2 * Copyright (c) 2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 */
30
31#include "arch/arm/stacktrace.hh"
32
33#include <string>
34
35#include "arch/arm/isa_traits.hh"
36#include "arch/arm/vtophys.hh"
37#include "base/bitfield.hh"
38#include "base/trace.hh"
39#include "cpu/base.hh"
40#include "cpu/thread_context.hh"
41#include "mem/fs_translating_port_proxy.hh"
42#include "sim/system.hh"
43
44namespace ArmISA
45{
46
47static int32_t
48readSymbol(ThreadContext *tc, const std::string name)
49{
50    PortProxy &vp = tc->getVirtProxy();
51    SymbolTable *symtab = tc->getSystemPtr()->kernelSymtab;
52
53    Addr addr;
54    if (!symtab->findAddress(name, addr))
55        panic("thread info not compiled into kernel\n");
56
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 &reg, 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