Belle II Software  release-05-01-25
Backtrace.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/utilities/Backtrace.h>
11 
12 #include <framework/logging/Logger.h>
13 #include <framework/logging/LogConfig.h>
14 
15 #include <vector>
16 
17 #include <execinfo.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 using namespace Belle2;
22 
23 void TrackFindingCDC::printBacktrace(LogConfig::ELogLevel logLevel, int nFrames)
24 {
25  std::vector<void*> buffer(nFrames);
26  void** rawBuffer = buffer.data();
27  char** traceLines;
28 
29  int traceSize = backtrace(rawBuffer, nFrames);
30  B2LOG(logLevel, 0, "backtrace() returned " << traceSize << " addresses");
31 
32  traceLines = backtrace_symbols(rawBuffer, traceSize);
33 
34  if (traceLines == NULL) {
35  B2LOG(logLevel, 0, "no backtrace obtained");
36  }
37 
38  for (int iLine = 0; iLine < traceSize; ++iLine) {
39  B2LOG(logLevel, 0, traceLines[iLine]);
40  }
41 
42  free(traceLines);
43 }
Belle2::LogConfig::ELogLevel
ELogLevel
Definition of the supported log levels.
Definition: LogConfig.h:36
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19