Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openfpm_devices
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sbalzarini Lab
Software
Parallel Computing
OpenFPM
openfpm_devices
Commits
b96708b8
Commit
b96708b8
authored
8 years ago
by
Pietro Incardona
Browse files
Options
Downloads
Patches
Plain Diff
Adding missing file
parent
128dc3d3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/util/print_stack.hpp
+82
-0
82 additions, 0 deletions
src/util/print_stack.hpp
with
82 additions
and
0 deletions
src/util/print_stack.hpp
0 → 100644
+
82
−
0
View file @
b96708b8
/*
* print_stack.hpp
*
* Created on: Feb 12, 2017
* Author: i-bird
*/
#ifndef OPENFPM_DATA_SRC_UTIL_PRINT_STACK_HPP_
#define OPENFPM_DATA_SRC_UTIL_PRINT_STACK_HPP_
#include
<sstream>
#include
<cstdio>
#include
<iostream>
#include
<memory>
#include
<stdexcept>
#include
<string>
#include
<array>
#include
<execinfo.h>
extern
std
::
string
program_name
;
/*! \brief Execute a command getting the std::cout
*
*
*/
static
inline
std
::
string
exec
(
const
char
*
cmd
)
{
std
::
array
<
char
,
128
>
buffer
;
std
::
string
result
;
std
::
shared_ptr
<
FILE
>
pipe
(
popen
(
cmd
,
"r"
),
pclose
);
if
(
!
pipe
)
throw
std
::
runtime_error
(
"popen() failed!"
);
while
(
!
feof
(
pipe
.
get
()))
{
if
(
fgets
(
buffer
.
data
(),
128
,
pipe
.
get
())
!=
NULL
)
result
+=
buffer
.
data
();
}
return
result
;
}
/*! \brief Print the stack trace
*
*
*/
static
inline
void
print_stack
()
{
#ifdef PRINT_STACKTRACE
void
*
trace
[
256
];
int
ncall
=
backtrace
(
trace
,
256
);
char
**
messages
=
backtrace_symbols
(
trace
,
ncall
);
std
::
stringstream
str
;
str
<<
"
\033
[1;31m*******************************************
\033
[0m"
<<
std
::
endl
;
str
<<
"
\033
[1;31m*********** STACK TRACE *******************
\033
[0m"
<<
std
::
endl
;
str
<<
"
\033
[1;31m*******************************************
\033
[0m"
<<
std
::
endl
;
str
<<
"
\033
[1mThe stack trace indicate where in the code happened the error the error "
<<
"is in general detected inside the library. In order to find the position "
<<
"in your code, follow from top to bottom the list of calls until you find "
<<
"a source code familiar to you.
\033
[0m"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
ncall
;
i
++
)
{
str
<<
"STACK TRACE Address: "
<<
trace
[
i
]
<<
" "
<<
messages
[
i
]
<<
" source:"
;
char
syscom
[
256
];
sprintf
(
syscom
,
"addr2line %p -e %s"
,
trace
[
i
],
program_name
.
c_str
());
//last parameter is the name of this app
std
::
string
ss
=
exec
(
syscom
);
str
<<
std
::
endl
<<
"
\033
[1;31m"
<<
ss
<<
"
\033
[0m"
;
}
std
::
cerr
<<
str
.
str
()
<<
std
::
endl
;
#endif
}
#endif
/* OPENFPM_DATA_SRC_UTIL_PRINT_STACK_HPP_ */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment