NCBI C++ ToolKit
ncbi_stack_libbackward.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_stack_libbackward.cpp 100478 2023-08-04 16:40:00Z gotvyans $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Anton Perkov
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 #include <ncbiconf.h>
32 
33 #if defined(HAVE_LIBDW)
34 # ifndef BACKWARD_HAS_DW
35 # define BACKWARD_HAS_DW 1
36 # endif
37 #elif defined(HAVE_LIBUNWIND)
38 # define BACKWARD_HAS_UNWIND 1
39 #endif
40 
41 #include <backward.hpp>
42 #if defined(HAVE_CXA_DEMANGLE)
43 # include <cxxabi.h>
44 #endif
45 #include <stdio.h>
46 
48 
49 #define CAN_HONOR_SIGNAL_HANDLING_CONFIGURATION 1
50 
51 #if defined(USE_LIBBACKWARD_SIG_HANDLING)
52 # define TRACE_SIGNALS_BY_DEFAULT true
53 #else
54 # define TRACE_SIGNALS_BY_DEFAULT false
55 #endif
56 
57 NCBI_PARAM_DECL(bool, Debug, Trace_Fatal_Signals);
58 NCBI_PARAM_DEF_EX(bool, Debug, Trace_Fatal_Signals, TRACE_SIGNALS_BY_DEFAULT,
59  0, DEBUG_TRACE_FATAL_SIGNALS);
60 typedef NCBI_PARAM_TYPE(Debug, Trace_Fatal_Signals) TTraceFatalSignals;
61 
62 unique_ptr<backward::SignalHandling> s_SignalHandler;
63 
64 
65 // Call this function to get a backtrace.
66 class CStackTraceImpl
67 {
68 public:
69  CStackTraceImpl(void);
70  ~CStackTraceImpl(void);
71 
73  static void s_HonorSignalHandlingConfiguration(void);
74 
75 private:
76  typedef backward::StackTrace TStack;
77 
79 };
80 
81 
83 {
84  m_Stack.load_here();
85 }
86 
87 
89 {
90 }
91 
92 
94 {
95  backward::TraceResolver resolver;
96  resolver.load_stacktrace(m_Stack);
97  for (size_t trace_idx = 0; trace_idx < m_Stack.size(); ++trace_idx) {
99  const backward::ResolvedTrace& trace
100  = resolver.resolve(m_Stack[trace_idx]);
101  info.module = trace.object_filename;
102  info.addr = trace.addr;
103 
104  if (!trace.source.filename.size()) {
105  /*os << " Object \""
106  << trace.object_filename
107  << ", at "
108  << trace.addr
109  << ", in "
110  << trace.object_function
111  << "\n";*/
112  }
113 
114  for (size_t inliner_idx = 0; inliner_idx < trace.inliners.size(); ++inliner_idx) {
115  const backward::ResolvedTrace::SourceLoc& inliner_loc = trace.inliners[inliner_idx];
117  info2.file = inliner_loc.filename;
118  info2.line = inliner_loc.line;
119  info2.func = inliner_loc.function;
120  stack.push_back(std::move(info2));
121  }
122 
123  if (trace.source.filename.size()) {
124  info.file = trace.source.filename;
125  info.line = trace.source.line;
126  //info.func = trace.source.function;
127  info.func = trace.object_function;
128  info.addr = trace.addr;
129  }
130  stack.push_back(std::move(info));
131  }
132 }
133 
135 {
136  if (TTraceFatalSignals::GetDefault()) {
137  s_SignalHandler.reset(new backward::SignalHandling);
138  }
139 }
140 
backward::StackTrace TStack
void Expand(CStackTrace::TStack &stack)
static void s_HonorSignalHandlingConfiguration(void)
list< SStackFrameInfo > TStack
Definition: ncbi_stack.hpp:78
static bool trace
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static MDB_envinfo info
Definition: mdb_load.c:37
typedef NCBI_PARAM_TYPE(Debug, Trace_Fatal_Signals) TTraceFatalSignals
#define TRACE_SIGNALS_BY_DEFAULT
NCBI_PARAM_DEF_EX(bool, Debug, Trace_Fatal_Signals, false, 0, DEBUG_TRACE_FATAL_SIGNALS)
unique_ptr< backward::SignalHandling > s_SignalHandler
NCBI_PARAM_DECL(bool, Debug, Trace_Fatal_Signals)
Front end for a platform-specific configuration summary.
Structure for holding stack trace data.
Definition: ncbi_stack.hpp:51
Modified on Sun Jul 14 04:57:43 2024 by modify_doxy.py rev. 669887