Timesheets-Server
Timesheets server
Načítám...
Vyhledávám...
Nebylo nic nalezeno
Dokumentace souboru backtrace.h
#include "pdebug.h"
#include <stdio.h>
#include <stdlib.h>
#include <execinfo.h>
#include <cxxabi.h>

Zobrazit zdrojový text tohoto souboru.

Definice maker

#define BACKTRACE()
 

Funkce

static QString stacktrace (unsigned int max_frames=63)
 

Detailní popis

Dokumentace definic maker

◆ BACKTRACE

#define BACKTRACE ( )
Hodnota:
PDEBUG << stacktrace(16)

Definice je uvedena na řádku 16 v souboru backtrace.h.

Dokumentace funkcí

◆ stacktrace()

static QString stacktrace ( unsigned int max_frames = 63)
inlinestatic

Definice je uvedena na řádku 18 v souboru backtrace.h.

18 {
19 QString text = "Backtrace:\n";
20
21 // storage array for stack trace address data
22 void *addrlist[max_frames+1];
23
24 // retrieve current stack addresses
25 int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));
26 if (addrlen == 0) {
27 text += " <empty, possibly corrupt>\n";
28 return text;
29 }
30
31 // resolve addresses into strings containing "filename(function+address)",
32 // this array must be free()-ed
33 char** symbollist = backtrace_symbols(addrlist, addrlen);
34
35 // allocate string which will be filled with the demangled function name
36 size_t funcnamesize = 256;
37 char* funcname = (char*)malloc(funcnamesize);
38
39 // iterate over the returned symbol lines. skip the first, it is the
40 // address of this function.
41 for (int i = 1; i < addrlen; i++) {
42 char *begin_name = 0, *begin_offset = 0, *end_offset = 0;
43
44 // find parentheses and +address offset surrounding the mangled name:
45 // ./module(function+0x15c) [0x8048a6d]
46 for (char *p = symbollist[i]; *p; ++p) {
47 if (*p == '(') begin_name = p;
48 else if (*p == '+') begin_offset = p;
49 else if (*p == ')' && begin_offset) {
50 end_offset = p;
51 break;
52 }
53 }
54
55 if (begin_name && begin_offset && end_offset && begin_name < begin_offset) {
56 *begin_name++ = '\0';
57 *begin_offset++ = '\0';
58 *end_offset = '\0';
59
60 // mangled name is now in [begin_name, begin_offset) and caller
61 // offset in [begin_offset, end_offset). now apply
62 // __cxa_demangle():
63
64 int status;
65 char* ret = abi::__cxa_demangle(begin_name,
66 funcname, &funcnamesize, &status);
67 if (status == 0) {
68 funcname = ret; // use possibly realloc()-ed string
69 text += QString(" %1 : %2+%3\n")
70 .arg(symbollist[i])
71 .arg(funcname)
72 .arg(begin_offset)
73 ;
74 } else {
75 // demangling failed. Output function name as a C function with
76 // no arguments.
77 text += QString(" %1 : %2+%3\n")
78 .arg(symbollist[i])
79 .arg(begin_name)
80 .arg(begin_offset)
81 ;
82 }
83 } else {
84 // couldn't parse the line? print the whole line.
85 text += QString(" %1\n").arg(symbollist[i]);
86 }
87 }
88
89 free(funcname);
90 free(symbollist);
91 return text;
92}