The Pedigree Project  0.1
StackFrameBase.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #if defined(DEBUGGER)
21 
22 #include "pedigree/kernel/processor/StackFrameBase.h"
23 
25  const ProcessorState &State, uintptr_t basePointer,
26  LargeStaticString mangledSymbol)
27  : m_Symbol(), m_State(State), m_BasePointer(basePointer)
28 {
29  // Demangle the given symbol, storing in m_Symbol for future use.
30  demangle(mangledSymbol, &m_Symbol);
31 }
32 
34 
36 {
37  bool bIsMember = isClassMember();
38 
39  buf += static_cast<const char *>(m_Symbol.name);
40  buf += '(';
41 
42 #ifndef MIPS_COMMON
43  if (bIsMember)
44  {
45  buf += "this=0x";
46  buf.append(getParameter(0), 16);
47  buf += ", ";
48  }
49 #endif
50 
51  for (size_t i = 0; i < m_Symbol.nParams; i++)
52  {
53  if (i != 0)
54  buf += ", ";
55 
56  format(getParameter((bIsMember) ? i + 1 : i), m_Symbol.params[i], buf);
57  }
58 
59  buf += ")\n";
60 }
61 
63  uintptr_t n, const LargeStaticString &type, HugeStaticString &dest)
64 {
65 #if defined(MIPS_COMMON)
66  dest += type;
67 #else
68  // Is the type a char * or const char *?
69  if (type == "char*" || type == "const char*")
70  {
71  // LargeStaticString tmp(reinterpret_cast<const char*>(n));
72  // dest += '"';
73  // dest += tmp.left(22); // Only 22 characters max.
74  // dest += '"';
75  dest.append("(");
76  dest.append(type);
77  dest.append(") 0x");
78 #ifdef BITS_32
79  dest.append(n, 16, 8, '0');
80 #endif
81 #ifdef BITS_64
82  dest.append(n, 16, 16, '0');
83 #endif
84  }
85  // char? or const char?
86  else if (type == "char" || type == "const char")
87  {
88  dest += '\'';
89  dest += static_cast<char>(n);
90  dest += '\'';
91  }
92  // bool?
93  else if (type == "bool" || type == "const bool")
94  {
95  bool b = static_cast<bool>(n);
96  if (b)
97  dest += "true";
98  else
99  dest += "false";
100  }
101  // 16-bit value?
102  else if (type == "short")
103  {
104  dest += "0x";
105  dest.append(static_cast<short>(n), 16);
106  }
107  else if (type == "unsigned short")
108  {
109  dest += "0x";
110  dest.append(static_cast<unsigned short>(n), 16);
111  }
112  // 32-bit value, in 64-bit mode?
113  else if (type == "int")
114  {
115  dest += "0x";
116  dest.append(static_cast<int>(n), 16);
117  }
118  else if (type == "unsigned int")
119  {
120  dest += "0x";
121  dest.append(static_cast<unsigned int>(n), 16);
122  }
123  // Else just use a hex integer, represented as a cast.
124  else
125  {
126  dest += "(";
127  dest += static_cast<const char *>(type);
128  dest += ")0x";
129  dest.append(n, 16);
130  }
131 #endif
132 }
133 
135 {
136  int nScopeIdx = m_Symbol.name.last(':');
137  if (nScopeIdx == -1)
138  return false;
139 
140  int i;
141  for (i = nScopeIdx - 2; i >= 0 && m_Symbol.name[i] != ':'; i--)
142  ;
143  i++;
144 
145  if (m_Symbol.name[i] >= 'A' && m_Symbol.name[i] <= 'Z')
146  return true;
147  else
148  return false;
149 }
150 
151 #endif
void format(uintptr_t n, const LargeStaticString &type, HugeStaticString &dest)
void prettyPrint(HugeStaticString &buf)
StackFrameBase(const ProcessorState &State, uintptr_t basePointer, LargeStaticString mangledSymbol)
virtual ~StackFrameBase()
virtual uintptr_t getParameter(size_t n)=0
symbol_t m_Symbol