stackwalker_linux.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #include "stackwalker_linux.h"
66 
67 #include <stdlib.h>
68 
69 #ifdef ANDROID
70  #include <android/log.h>
71 #elif defined(USING_UNWIND_LIB)
72  #define UNW_LOCAL_ONLY
73  #include <libunwind.h>
74  #include <cxxabi.h>
75  #include <cstdio>
76 #endif
77 
78 #ifdef __arm__
79  #define UNW_PRINTF_POINTER "0x%x: "
80  #define UNW_PRINTF_NAME_AND_POINTER " (%s+0x%x)"
81 #else
82  #include <stdint.h>
83  #if UINTPTR_MAX == 0xffffffff
84  /* 32-bit */
85  #define UNW_PRINTF_POINTER "0x%x: "
86  #define UNW_PRINTF_NAME_AND_POINTER " (%s+0x%x)"
87  #elif UINTPTR_MAX == 0xffffffffffffffff
88  /* 64-bit */
89  #define UNW_PRINTF_POINTER "0x%lx: "
90  #define UNW_PRINTF_NAME_AND_POINTER " (%s+0x%lx)"
91  #else
92  /* wtf */
93  #endif
94 #endif
95 
97 {
98 }
99 
101 {
102 }
103 
105 {
106 #ifdef ANDROID
107  __android_log_print(ANDROID_LOG_WARN, "stackwalker", "stack trace is not available");
108 #elif defined(USING_UNWIND_LIB)
109  unw_context_t context;
110  unw_getcontext(&context);
111 
112  unw_cursor_t cursor;
113  unw_init_local(&cursor, &context);
114 
115  while (unw_step(&cursor) > 0)
116  {
117  unw_word_t instructionPointer;
118  unw_get_reg(&cursor, UNW_REG_IP, &instructionPointer);
119 
120  if (instructionPointer == 0)
121  break;
122 
123  static const int logLineSize = 256;
124  char logLine[logLineSize];
125  int offset = std::snprintf(logLine, logLineSize, UNW_PRINTF_POINTER, instructionPointer);
126 
127  char symbol[logLineSize - 20];
128  unw_word_t symbolOffset;
129  if (unw_get_proc_name(&cursor, symbol, sizeof(symbol), &symbolOffset) == 0)
130  {
131  int status;
132  char* demangled = abi::__cxa_demangle(symbol, nullptr, nullptr, &status);
133 
134  char* symbolName = symbol;
135  if (status == 0)
136  symbolName = demangled;
137 
138  std::snprintf(&logLine[offset], logLineSize - offset, UNW_PRINTF_NAME_AND_POINTER, symbolName, symbolOffset);
139  std::free(demangled);
140  }
141  else
142  std::snprintf(&logLine[offset], logLineSize - offset, " (unable to retrieve symbol name)");
143 
144  OnOutput(logLine);
145  }
146 #else
147  OnOutput("Stack trace is not available");
148 #endif
149 }
stackwalker_linux.h
StackWalker::OnOutput
virtual void OnOutput(LPCSTR szText)
Definition: stackwalker.cpp:1300
StackWalker::~StackWalker
virtual ~StackWalker()
Definition: stackwalker.cpp:841
StackWalker::StackWalker
StackWalker()
Definition: stackwalker_linux.cpp:96
StackWalker::ShowCallstack
void ShowCallstack()
Definition: stackwalker_linux.cpp:104


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20