Belle II Software  release-08-01-10
Backtrace.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/trackFindingCDC/utilities/Backtrace.h>
9 
10 #include <framework/logging/Logger.h>
11 #include <framework/logging/LogConfig.h>
12 
13 #include <vector>
14 
15 #include <execinfo.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 
19 using namespace Belle2;
20 
21 void TrackFindingCDC::printBacktrace(LogConfig::ELogLevel logLevel, int nFrames)
22 {
23  std::vector<void*> buffer(nFrames);
24  void** rawBuffer = buffer.data();
25  char** traceLines;
26 
27  int traceSize = backtrace(rawBuffer, nFrames);
28  B2LOG(logLevel, 0, "backtrace() returned " << traceSize << " addresses");
29 
30  traceLines = backtrace_symbols(rawBuffer, traceSize);
31 
32  if (traceLines == nullptr) {
33  B2LOG(logLevel, 0, "no backtrace obtained");
34  } else {
35  for (int iLine = 0; iLine < traceSize; ++iLine) {
36  B2LOG(logLevel, 0, traceLines[iLine]);
37  }
38  }
39 
40  free(traceLines);
41 }
ELogLevel
Definition of the supported log levels.
Definition: LogConfig.h:26
Abstract base class for different kinds of events.