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#include <config.h>
21
22#if DEBUGGER
23
24#include "pedigree/kernel/processor/StackFrameBase.h"
25
26StackFrameBase::StackFrameBase(const ProcessorState& State, uintptr_t basePointer,
27 LargeStaticString mangledSymbol)
28 : m_Symbol(), m_State(State), m_BasePointer(basePointer) {
29 // Demangle the given symbol, storing in m_Symbol for future use.
30 demangle(mangledSymbol, &m_Symbol);
31}
32
34
36 bool bIsMember = isClassMember();
37
38 buf += static_cast<const char*>(m_Symbol.name);
39 buf += '(';
40
41 if (bIsMember) {
42 buf += "this=0x";
43 buf.append(getParameter(0), 16);
44 buf += ", ";
45 }
46 for (size_t i = 0; i < m_Symbol.nParams; i++) {
47 if (i != 0)
48 buf += ", ";
49
50 format(getParameter((bIsMember) ? i + 1 : i), m_Symbol.params[i], buf);
51 }
52
53 buf += ")\n";
54}
55
56void StackFrameBase::format(uintptr_t n, const LargeStaticString& type, HugeStaticString& dest) {
57 // Is the type a char * or const char *?
58 if (type == "char*" || type == "const char*") {
59 // LargeStaticString tmp(reinterpret_cast<const char*>(n));
60 // dest += '"';
61 // dest += tmp.left(22); // Only 22 characters max.
62 // dest += '"';
63 dest.append("(");
64 dest.append(type);
65 dest.append(") 0x");
66#if BITS_32
67 dest.append(n, 16, 8, '0');
68#endif
69#if BITS_64
70 dest.append(n, 16, 16, '0');
71#endif
72 }
73 // char? or const char?
74 else if (type == "char" || type == "const char") {
75 dest += '\'';
76 dest += static_cast<char>(n);
77 dest += '\'';
78 }
79 // bool?
80 else if (type == "bool" || type == "const bool") {
81 bool b = static_cast<bool>(n);
82 if (b)
83 dest += "true";
84 else
85 dest += "false";
86 }
87 // 16-bit value?
88 else if (type == "short") {
89 dest += "0x";
90 dest.append(static_cast<short>(n), 16);
91 } else if (type == "unsigned short") {
92 dest += "0x";
93 dest.append(static_cast<unsigned short>(n), 16);
94 }
95 // 32-bit value, in 64-bit mode?
96 else if (type == "int") {
97 dest += "0x";
98 dest.append(static_cast<int>(n), 16);
99 } else if (type == "unsigned int") {
100 dest += "0x";
101 dest.append(static_cast<unsigned int>(n), 16);
102 }
103 // Else just use a hex integer, represented as a cast.
104 else {
105 dest += "(";
106 dest += static_cast<const char*>(type);
107 dest += ")0x";
108 dest.append(n, 16);
109 }
110}
111
113 int nScopeIdx = m_Symbol.name.last(':');
114 if (nScopeIdx == -1)
115 return false;
116
117 int i;
118 for (i = nScopeIdx - 2; i >= 0 && m_Symbol.name[i] != ':'; i--)
119 ;
120 i++;
121
122 if (m_Symbol.name[i] >= 'A' && m_Symbol.name[i] <= 'Z')
123 return true;
124 else
125 return false;
126}
127
128#endif
StackFrameBase(const ProcessorState &State, uintptr_t basePointer, LargeStaticString mangledSymbol)
void prettyPrint(HugeStaticString &buf)
virtual ~StackFrameBase()
virtual uintptr_t getParameter(size_t n)=0
void format(uintptr_t n, const LargeStaticString &type, HugeStaticString &dest)