Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
3c994f45
Commit
3c994f45
authored
May 25, 2023
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Simplify backtrace output
This makes backtrace readable
parent
99394c69
No related branches found
No related tags found
1 merge request
!168
Simplify backtrace output
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/BacktraceManager.cpp
+19
-11
19 additions, 11 deletions
src/utils/BacktraceManager.cpp
src/utils/BacktraceManager.hpp
+1
-1
1 addition, 1 deletion
src/utils/BacktraceManager.hpp
with
20 additions
and
12 deletions
src/utils/BacktraceManager.cpp
+
19
−
11
View file @
3c994f45
...
@@ -25,7 +25,7 @@ BacktraceManager::BacktraceManager()
...
@@ -25,7 +25,7 @@ BacktraceManager::BacktraceManager()
char
**
ptr
=
backtrace_symbols
(
buffer
,
ret
);
char
**
ptr
=
backtrace_symbols
(
buffer
,
ret
);
for
(
int
i
=
2
;
i
<
ret
;
++
i
)
{
for
(
int
i
=
2
;
i
<
ret
;
++
i
)
{
m_lines
.
push_back
(
ptr
[
i
]);
m_
stack_
lines
.
push_back
(
ptr
[
i
]);
}
}
free
(
ptr
);
free
(
ptr
);
...
@@ -35,27 +35,35 @@ std::ostream&
...
@@ -35,27 +35,35 @@ std::ostream&
operator
<<
(
std
::
ostream
&
os
,
const
BacktraceManager
&
btm
)
operator
<<
(
std
::
ostream
&
os
,
const
BacktraceManager
&
btm
)
{
{
if
(
BacktraceManager
::
s_show
)
{
if
(
BacktraceManager
::
s_show
)
{
const
std
::
vector
<
std
::
string
>&
lines
=
btm
.
m_lines
;
const
std
::
vector
<
std
::
string
>&
stack_
lines
=
btm
.
m_
stack_
lines
;
const
std
::
regex
mangled_function
(
R"%(\(.*\+)%"
);
const
std
::
regex
mangled_function
(
R"%(\(.*\+)%"
);
const
int
width
=
std
::
log10
(
lines
.
size
())
+
1
;
const
int
width
=
std
::
log10
(
stack_
lines
.
size
())
+
1
;
for
(
size_t
i_line
=
0
;
i_line
<
lines
.
size
();
++
i_line
)
{
for
(
size_t
i_stack_line
=
0
;
i_stack_line
<
stack_lines
.
size
();
++
i_stack_line
)
{
const
auto
&
line
=
lines
[
i_line
];
const
size_t
i_line
=
stack_lines
.
size
()
-
i_stack_line
-
1
;
os
<<
rang
::
fg
::
green
<<
"["
<<
std
::
setw
(
width
)
<<
i_line
+
1
<<
'/'
<<
lines
.
size
()
<<
"] "
<<
rang
::
fg
::
reset
;
const
auto
&
stack_line
=
stack_lines
[
i_line
];
os
<<
rang
::
fg
::
green
<<
"["
<<
std
::
setw
(
width
)
<<
i_line
+
1
<<
'/'
<<
stack_lines
.
size
()
<<
"] "
<<
rang
::
fg
::
reset
;
std
::
smatch
matchex
;
std
::
smatch
matchex
;
if
(
std
::
regex_search
(
line
,
matchex
,
mangled_function
))
{
if
(
std
::
regex_search
(
stack_
line
,
matchex
,
mangled_function
))
{
std
::
string
prefix
=
matchex
.
prefix
().
str
();
std
::
string
prefix
=
matchex
.
prefix
().
str
();
std
::
string
function
=
line
.
substr
(
matchex
.
position
()
+
1
,
matchex
.
length
()
-
2
);
std
::
string
function
=
stack_
line
.
substr
(
matchex
.
position
()
+
1
,
matchex
.
length
()
-
2
);
std
::
string
suffix
=
matchex
.
suffix
().
str
();
std
::
string
suffix
=
matchex
.
suffix
().
str
();
os
<<
prefix
<<
'('
;
os
<<
prefix
<<
'\n'
;
os
<<
std
::
setw
(
5
+
2
*
width
)
<<
"from "
<<
'('
;
if
(
function
.
size
()
>
0
)
{
if
(
function
.
size
()
>
0
)
{
os
<<
rang
::
style
::
bold
<<
demangle
(
function
)
<<
rang
::
style
::
reset
;
std
::
string
function_full_name
=
demangle
(
function
);
if
(
function_full_name
.
size
()
>
80
)
{
function_full_name
.
resize
(
75
);
function_full_name
+=
"[...]"
;
}
os
<<
rang
::
style
::
bold
<<
function_full_name
<<
rang
::
style
::
reset
;
}
}
os
<<
'+'
<<
suffix
<<
'\n'
;
os
<<
'+'
<<
suffix
<<
'\n'
;
}
else
{
}
else
{
os
<<
line
<<
'\n'
;
os
<<
stack_
line
<<
'\n'
;
}
}
}
}
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/utils/BacktraceManager.hpp
+
1
−
1
View file @
3c994f45
...
@@ -8,7 +8,7 @@ class BacktraceManager
...
@@ -8,7 +8,7 @@ class BacktraceManager
{
{
private:
private:
static
bool
s_show
;
static
bool
s_show
;
std
::
vector
<
std
::
string
>
m_lines
;
std
::
vector
<
std
::
string
>
m_
stack_
lines
;
public:
public:
static
void
setShow
(
bool
show_backtrace
);
static
void
setShow
(
bool
show_backtrace
);
...
...
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