gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
stacktrace.cc
Go to the documentation of this file.
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"
42 #include "sim/system.hh"
43 
44 namespace ArmISA
45 {
46 
47 static int32_t
48 readSymbol(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 
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 
69 Addr
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 
84 int
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 
99 std::string
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 
115  : tc(0), stack(64)
116 {
117 }
118 
120  : tc(0), stack(64)
121 {
122  trace(_tc, inst);
123 }
124 
126 {
127 }
128 
129 void
130 StackTrace::trace(ThreadContext *_tc, bool is_call)
131 {
132 }
133 
134 bool
136 {
137  return false;
138 }
139 
140 bool
142 {
143  return false;
144 }
145 
146 bool
147 StackTrace::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  */
156 bool
158  int &size, Addr &ra)
159 {
160  return false;
161 }
162 
163 #if TRACING_ON
164 void
166 {
167  DPRINTFN("------ Stack ------\n");
168 
169  DPRINTFN(" Not implemented\n");
170 }
171 #endif
172 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
virtual System * getSystemPtr()=0
Bitfield< 5, 3 > reg
Definition: types.hh:89
const std::string & name()
Definition: trace.cc:54
void trace(ThreadContext *tc, bool is_call)
Definition: stacktrace.cc:130
bool decodeSave(MachInst inst, int &reg, int &disp)
Definition: stacktrace.cc:147
ip6_addr_t addr
Definition: inet.hh:335
ArmISA::MachInst MachInst
Definition: stacktrace.hh:66
virtual PortProxy & getVirtProxy()=0
Bitfield< 0 > sp
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:284
std::string name(Addr ksp) const
Definition: stacktrace.cc:100
Definition: ccregs.hh:42
ThreadContext * tc
Definition: stacktrace.hh:68
ThreadContext is the external interface to all thread state for anything outside of the CPU...
#define DPRINTFN(...)
Definition: trace.hh:233
bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra)
Definition: stacktrace.cc:157
ProcessInfo(ThreadContext *_tc)
Definition: stacktrace.cc:60
bool findAddress(const std::string &symbol, Addr &address) const
Definition: symtab.hh:97
bool isEntry(Addr addr)
Definition: stacktrace.cc:135
Bitfield< 51, 12 > base
Definition: pagetable.hh:142
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
Addr task(Addr ksp) const
Definition: stacktrace.cc:70
SymbolTable * kernelSymtab
kernel symbol table
Definition: system.hh:221
Bitfield< 20, 16 > ra
Definition: types.hh:47
Bitfield< 17, 16 > stack
Definition: misc.hh:589
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:257
std::vector< Addr > stack
Definition: stacktrace.hh:69
bool decodeStack(MachInst inst, int &disp)
Definition: stacktrace.cc:141
int pid(Addr ksp) const
Definition: stacktrace.cc:85
ThreadContext * tc
Definition: stacktrace.hh:47
TranslatingPortProxy Object Declaration for FS.
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:561
const ByteOrder GuestByteOrder
Definition: isa_traits.hh:54
static int32_t readSymbol(ThreadContext *tc, const std::string name)
Definition: stacktrace.cc:48

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13