1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 // File vogl_backtrace.cpp
28 #include "vogl_backtrace.h"
30 #if VOGL_USE_LINUX_API
31 #define USE_LIBBACKTRACE 0
34 #include "backtrace.h"
36 #include <linux/unistd.h>
43 #if VOGL_USE_LINUX_API
46 bool get_printable_backtrace(dynamic_string_array &string_vec)
50 const uint BUF_SIZE = 256;
51 void *buffer[BUF_SIZE];
53 int nptrs = backtrace(buffer, BUF_SIZE);
57 char **strings = backtrace_symbols(buffer, nptrs);
61 string_vec.resize(nptrs);
63 for (int i = 0; i < nptrs; i++)
64 string_vec[i].set(strings[i] ? strings[i] : "?");
71 bool get_printable_backtrace(dynamic_string_array &string_vec)
77 int n = backtrace_simple_get_pcs(pcs, N);
85 string_vec.reserve(n);
87 for (int i = 0; i < n; i++)
90 utils::zero_object(info);
91 if (backtrace_simple_resolve_pc(&info, pcs[i]))
93 string_vec.enlarge(1)->format("%u %s(%i), PC: 0x%llX, Ofs: 0x%llX, Mod: %s, Filename: \"%s\"", i,
94 info.function ? demangle(info.function).get_ptr() : "?",
96 (uint64_t)info.pc, (uint64_t)info.offset,
97 info.module ? info.module : "?",
98 info.filename ? info.filename : "?");
102 string_vec.push_back("?");
108 #endif // !USE_LIBBACKTRACE
110 #else // !VOGL_USE_LINUX_API
112 bool get_printable_backtrace(dynamic_string_array &strings)
116 console::debug("TODO: %s\n", VOGL_FUNCTION_NAME);
120 #endif // VOGL_USE_LINUX_API