DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
src
Context.cpp
Go to the documentation of this file.
1
/*
2
* DUNE DAQ modification notice:
3
* This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4
* Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5
* Renamed since fork: yes (from src/Context.cxx to src/Context.cpp).
6
*
7
* Original copyright:
8
* Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9
* Licensed under the Apache License, Version 2.0.
10
*/
11
12
/*
13
* Context.cxx
14
* ers
15
*
16
* Created by Serguei Kolos on 26.11.05.
17
* Copyright 2004 CERN. All rights reserved.
18
*
19
*/
20
#include <cxxabi.h>
21
#include <pwd.h>
22
#include <string.h>
23
#include <sys/types.h>
24
#include <unistd.h>
25
26
#include <iostream>
27
#include <sstream>
28
29
#ifndef __rtems__
30
#include <execinfo.h>
31
#else
32
char
**
33
backtrace_symbols(
void
**,
int
size)
34
{
35
return
0;
36
}
37
#endif
38
39
#include <
ers/Configuration.hpp
>
40
#include <
ers/Context.hpp
>
41
42
namespace
{
43
std::string
44
demangle(
char
* mangled)
45
{
46
int
status
;
47
char
* function_begin = ::strchr(mangled,
'('
);
48
if
(function_begin) {
49
char
* function_end = ::strchr(++function_begin,
'+'
);
50
if
(function_end && function_end != function_begin) {
51
std::string fname(function_begin, function_end - function_begin);
52
char
* name = abi::__cxa_demangle(fname.c_str(), 0, 0, &status);
53
54
if
(!name) {
55
return
std::string(mangled);
56
}
57
58
std::ostringstream
out
;
59
out
<< std::string(mangled, function_begin - mangled) << name << function_end;
60
free(name);
61
return
out
.str();
62
}
63
}
64
return
std::string(mangled);
65
}
66
67
void
68
print_function(std::ostream& out,
const
char
* function,
int
verbosity)
69
{
70
if
(verbosity) {
71
out
<< function;
72
return
;
73
}
74
75
const
char
* end = strchr(function,
'('
);
76
if
(end) {
77
const
char
* beg = end;
78
while
(beg > function) {
79
if
(*(beg - 1) ==
' '
) {
80
break
;
81
}
82
--beg;
83
}
84
out
.write(beg, end - beg);
85
out
<<
"(...)"
;
86
}
else
{
87
out
<< function;
88
}
89
}
90
}
91
92
std::vector<std::string>
93
ers::Context::stack
()
const
94
{
95
std::vector<std::string>
stack
;
96
stack
.reserve(
stack_size
());
97
char
** symbols = backtrace_symbols((
void
**)
stack_symbols
(),
stack_size
());
98
99
if
(symbols) {
100
for
(
int
i = 1; i <
stack_size
(); i++) {
101
stack
.push_back(demangle(symbols[i]));
102
}
103
free(symbols);
104
}
105
106
return
stack
;
107
}
108
113
std::string
114
ers::Context::position
(
int
verbosity)
const
115
{
116
std::ostringstream out;
117
print_function(out,
function_name
(), verbosity);
118
out <<
" at "
;
119
120
const
char
* file =
file_name
();
121
if
(file[0] ==
'.'
&& file[1] ==
'.'
&& file[2] ==
'/'
)
// file name starts with "../"
122
{
123
out <<
package_name
() << (file + 2);
124
}
else
{
125
out << file;
126
}
127
out <<
":"
<<
line_number
();
128
return
out.str();
129
}
Context.hpp
ers::Context::stack_symbols
virtual void *const * stack_symbols() const =0
ers::Context::line_number
virtual int line_number() const =0
ers::Context::stack_size
virtual int stack_size() const =0
ers::Context::position
std::string position(int verbosity=ers::Configuration::instance().verbosity_level()) const
Definition
Context.cpp:114
ers::Context::package_name
virtual const char * package_name() const =0
ers::Context::file_name
virtual const char * file_name() const =0
ers::Context::stack
std::vector< std::string > stack() const
Definition
Context.cpp:93
ers::Context::function_name
virtual const char * function_name() const =0
Configuration.hpp
dunedaq::out
FELIX Initialization std::string initerror FELIX queue timed out
Definition
FelixIssues.hpp:24
timing.cli.design.status
status(obj)
Definition
design.py:92
Generated on
for DUNE-DAQ by
1.18.0