gem5  v20.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 
29 #include "arch/arm/stacktrace.hh"
30 
31 #include <string>
32 
33 #include "arch/arm/isa_traits.hh"
34 #include "base/bitfield.hh"
35 #include "base/trace.hh"
36 #include "cpu/base.hh"
37 #include "cpu/thread_context.hh"
38 #include "mem/port_proxy.hh"
39 #include "sim/system.hh"
40 
41 namespace ArmISA
42 {
43 
44 static int32_t
45 readSymbol(ThreadContext *tc, const std::string name)
46 {
47  PortProxy &vp = tc->getVirtProxy();
48  const auto *symtab = tc->getSystemPtr()->workload->symtab(tc);
49 
50  Addr addr;
51  if (!symtab->findAddress(name, addr))
52  panic("thread info not compiled into kernel\n");
53 
54  return vp.read<int32_t>(addr, GuestByteOrder);
55 }
56 
58 {
59  thread_info_size = readSymbol(tc, "thread_info_size");
60  task_struct_size = readSymbol(tc, "task_struct_size");
61  task_off = readSymbol(tc, "thread_info_task");
62  pid_off = readSymbol(tc, "task_struct_pid");
63  name_off = readSymbol(tc, "task_struct_comm");
64 }
65 
66 Addr
68 {
69  Addr base = ksp & ~0x1fff;
70  if (base == ULL(0xffffffffc0000000))
71  return 0;
72 
73  Addr tsk;
74 
75  PortProxy &vp = tc->getVirtProxy();
76  tsk = vp.read<Addr>(base + task_off, GuestByteOrder);
77 
78  return tsk;
79 }
80 
81 int
83 {
84  Addr task = this->task(ksp);
85  if (!task)
86  return -1;
87 
88  uint16_t pd;
89 
90  PortProxy &vp = tc->getVirtProxy();
91  pd = vp.read<uint16_t>(task + pid_off, GuestByteOrder);
92 
93  return pd;
94 }
95 
96 std::string
98 {
99  Addr task = this->task(ksp);
100  if (!task)
101  return "unknown";
102 
103  char comm[256];
104  tc->getVirtProxy().readString(comm, task + name_off, sizeof(comm));
105  if (!comm[0])
106  return "startup";
107 
108  return comm;
109 }
110 
112  : tc(0), stack(64)
113 {
114 }
115 
117  : tc(0), stack(64)
118 {
119  trace(_tc, inst);
120 }
121 
123 {
124 }
125 
126 void
127 StackTrace::trace(ThreadContext *_tc, bool is_call)
128 {
129 }
130 
131 bool
133 {
134  return false;
135 }
136 
137 bool
139 {
140  return false;
141 }
142 
143 bool
144 StackTrace::decodeSave(MachInst inst, int &reg, int &disp)
145 {
146  return false;
147 }
148 
149 /*
150  * Decode the function prologue for the function we're in, and note
151  * which registers are stored where, and how large the stack frame is.
152  */
153 bool
155  int &size, Addr &ra)
156 {
157  return false;
158 }
159 
160 #if TRACING_ON
161 void
163 {
164  DPRINTFN("------ Stack ------\n");
165 
166  DPRINTFN(" Not implemented\n");
167 }
168 #endif
169 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
virtual System * getSystemPtr()=0
virtual const Loader::SymbolTable * symtab(ThreadContext *tc)=0
Bitfield< 5, 3 > reg
Definition: types.hh:87
const std::string & name()
Definition: trace.cc:50
void trace(ThreadContext *tc, bool is_call)
Definition: stacktrace.cc:127
bool decodeSave(MachInst inst, int &reg, int &disp)
Definition: stacktrace.cc:144
ip6_addr_t addr
Definition: inet.hh:330
ArmISA::MachInst MachInst
Definition: stacktrace.hh:64
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:282
std::string name(Addr ksp) const
Definition: stacktrace.cc:97
Definition: ccregs.hh:41
ThreadContext * tc
Definition: stacktrace.hh:66
ThreadContext is the external interface to all thread state for anything outside of the CPU...
#define DPRINTFN(...)
Definition: trace.hh:229
bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra)
Definition: stacktrace.cc:154
ProcessInfo(ThreadContext *_tc)
Definition: stacktrace.cc:57
PortProxy Object Declaration.
bool isEntry(Addr addr)
Definition: stacktrace.cc:132
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Workload * workload
OS kernel.
Definition: system.hh:213
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
#define ULL(N)
uint64_t constant
Definition: types.hh:48
Addr task(Addr ksp) const
Definition: stacktrace.cc:67
Bitfield< 20, 16 > ra
Definition: types.hh:45
Bitfield< 17, 16 > stack
Definition: misc.hh:587
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:80
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:255
std::vector< Addr > stack
Definition: stacktrace.hh:67
bool decodeStack(MachInst inst, int &disp)
Definition: stacktrace.cc:138
int pid(Addr ksp) const
Definition: stacktrace.cc:82
ThreadContext * tc
Definition: stacktrace.hh:45
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:560
const ByteOrder GuestByteOrder
Definition: isa_traits.hh:51
static int32_t readSymbol(ThreadContext *tc, const std::string name)
Definition: stacktrace.cc:45

Generated on Thu May 28 2020 16:11:02 for gem5 by doxygen 1.8.13