The Pedigree Project  0.1
Backtrace.h
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 #ifndef BACKTRACE_H
21 #define BACKTRACE_H
22 
23 #include "pedigree/kernel/processor/state.h"
24 #include "pedigree/kernel/processor/types.h"
25 #include "pedigree/kernel/utilities/StaticString.h"
26 
30 #define MAX_STACK_FRAMES 12
31 
32 class Backtrace
33 {
34  friend class AllocationCommand;
35  friend class LocksCommand;
36  friend class SlamAllocator;
37 
38  public:
42  Backtrace();
43  ~Backtrace();
44 
49  void performBacktrace(InterruptState &state);
50 
54  size_t numStackFrames();
55 
59  uintptr_t getReturnAddress(size_t n);
60 
64  uintptr_t getBasePointer(size_t n);
65 
66  void prettyPrint(
67  HugeStaticString &buf, size_t nFrames = 0, size_t nFromFrame = 0);
68 
69  private:
73  void performDwarfBacktrace(InterruptState &state);
74 
79  public:
80  void performBpBacktrace(uintptr_t base, uintptr_t instruction);
81 #ifdef ARM_COMMON
82  void performArmBacktrace(uintptr_t base, uintptr_t instruction);
83 #endif
84  private:
88  uintptr_t m_pReturnAddresses[MAX_STACK_FRAMES];
92  uintptr_t m_pBasePointers[MAX_STACK_FRAMES];
93 
97  ProcessorState m_pStates[MAX_STACK_FRAMES];
98 
103 };
104 
107 #endif
uintptr_t m_pBasePointers[MAX_STACK_FRAMES]
Definition: Backtrace.h:92
uintptr_t getBasePointer(size_t n)
Definition: Backtrace.cc:242
size_t m_nStackFrames
Definition: Backtrace.h:102
uintptr_t m_pReturnAddresses[MAX_STACK_FRAMES]
Definition: Backtrace.h:88
void performDwarfBacktrace(InterruptState &state)
Definition: Backtrace.cc:65
void performBacktrace(InterruptState &state)
Definition: Backtrace.cc:39
void performBpBacktrace(uintptr_t base, uintptr_t instruction)
Definition: Backtrace.cc:95
ProcessorState m_pStates[MAX_STACK_FRAMES]
Definition: Backtrace.h:97
uintptr_t getReturnAddress(size_t n)
Definition: Backtrace.cc:236
size_t numStackFrames()
Definition: Backtrace.cc:231