1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
32 #include "vogl_dynamic_string.h"
43 const char *module; // Guaranteed to be !NULL.
44 const char *function; //
45 const char *filename; //
47 char demangled_func_buf[512];
51 * Walk up the stack getting the instruction pointers and stuffing them into your
52 * array. We will skip the first <addrs_to_skip> count of addrs, and we will return
53 * the count of addrs we found. You can pass the addrs to btrace_resolve_addr() to
54 * get modules, function names, etc.
56 int btrace_get(uintptr_t *addrs, size_t count_addrs, uint32_t addrs_to_skip);
59 * Get symbol information given an instruction pointer.
61 #define BTRACE_RESOLVE_ADDR_GET_FILENAME 0x00000001
62 #define BTRACE_RESOLVE_ADDR_DEMANGLE_FUNC 0x00000002
63 bool btrace_resolve_addr(btrace_info *info, uintptr_t addr, uint32_t flags);
66 * Get debug filename (or NULL if not found).
68 const char *btrace_get_debug_filename(const char *filename);
71 * Walk up the stack until we find a module that isn't the same as the one we're in.
72 * Return the full path string to that module. Will return NULL if nothing is found.
74 const char *btrace_get_calling_module();
75 const char *btrace_get_current_module();
78 * Called when a new module is dlopen'd.
80 void btrace_dlopen_notify(const char *filename);
83 * Return information about the current machine.
85 bool btrace_get_machine_info(vogl::json_node *machine_info);
88 * Set information about current gl context.
92 vogl::dynamic_string version_str;
93 vogl::dynamic_string glsl_version_str;
94 vogl::dynamic_string vendor_str;
95 vogl::dynamic_string renderer_str;
97 btrace_glinfo& btrace_get_glinfo();
100 const char *btrace_demangle_function(const char *name, char *buffer, size_t buflen);
102 struct btrace_module_info
104 //$ TODO mikesart: need an ID number in here. This will get incremented
105 // everytime we have an address conflict. All stack traces should get this
106 // ID so they know which module they should get symbols from.
107 uintptr_t base_address;
108 uint32_t address_size;
109 struct backtrace_state *backtrace_state;
110 const char *filename;
117 * Explicitly add a module to the module list. Used for symbol resolving.
119 bool btrace_dlopen_add_module(const btrace_module_info &module_info);
122 * Uuid helper functions.
124 int btrace_uuid_str_to_uuid(uint8_t uuid[20], const char *uuid_str);
125 void btrace_uuid_to_str(char uuid_str[41], const uint8_t *uuid, int len);
128 operator <(const btrace_module_info &info1, const btrace_module_info &info2)
130 if (info1.base_address < info2.base_address)
132 if(info1.base_address == info2.base_address)
134 if(info1.address_size < info2.address_size)
136 if (info1.address_size == info2.address_size)
138 if (strcmp(info1.filename, info2.filename) < 0)
146 operator ==(const btrace_module_info &info1, const btrace_module_info &info2)
148 return (info1.base_address == info2.base_address) &&
149 (info1.address_size == info2.address_size) &&
150 !strcmp(info1.filename, info2.filename);