Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
30b06acb
Commit
30b06acb
authored
Jul 20, 2014
by
Philip Quinn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace 'goto' error handling with KJ_DEFER.
parent
ef501b1c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
14 deletions
+9
-14
exception.c++
c++/src/kj/exception.c++
+9
-14
No files found.
c++/src/kj/exception.c++
View file @
30b06acb
...
...
@@ -55,6 +55,7 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
// is in use.
static
pthread_mutex_t
mutex
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_lock
(
&
mutex
);
KJ_DEFER
(
pthread_mutex_unlock
(
&
mutex
));
// Don't heapcheck / intercept syscalls.
const
char
*
preload
=
getenv
(
"LD_PRELOAD"
);
...
...
@@ -63,9 +64,9 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
oldPreload
=
heapString
(
preload
);
unsetenv
(
"LD_PRELOAD"
);
}
KJ_DEFER
(
if
(
oldPreload
!=
nullptr
)
{
setenv
(
"LD_PRELOAD"
,
oldPreload
.
cStr
(),
true
);
});
String
lines
[
8
];
size_t
lines_read
=
0
;
FILE
*
p
=
nullptr
;
#if __linux__
...
...
@@ -74,7 +75,7 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
char
exe
[
512
];
ssize_t
n
=
readlink
(
"/proc/self/exe"
,
exe
,
sizeof
(
exe
));
if
(
n
<
0
||
n
>=
static_cast
<
ssize_t
>
(
sizeof
(
exe
)))
{
goto
cleanup
;
return
nullptr
;
}
exe
[
n
]
=
'\0'
;
...
...
@@ -86,14 +87,15 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
#endif
if
(
p
==
nullptr
)
{
goto
cleanup
;
return
nullptr
;
}
char
line
[
512
];
while
(
lines_read
<
kj
::
size
(
lines
)
&&
fgets
(
line
,
sizeof
(
line
),
p
)
!=
nullptr
)
{
size_t
i
=
0
;
while
(
i
<
kj
::
size
(
lines
)
&&
fgets
(
line
,
sizeof
(
line
),
p
)
!=
nullptr
)
{
// Don't include exception-handling infrastructure in stack trace.
// addr2line output matches file names; atos output matches symbol names.
if
(
lines_read
==
0
&&
if
(
i
==
0
&&
(
strstr
(
line
,
"kj/common.c++"
)
!=
nullptr
||
strstr
(
line
,
"kj/exception."
)
!=
nullptr
||
strstr
(
line
,
"kj/debug."
)
!=
nullptr
||
...
...
@@ -104,7 +106,7 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
size_t
len
=
strlen
(
line
);
if
(
len
>
0
&&
line
[
len
-
1
]
==
'\n'
)
line
[
len
-
1
]
=
'\0'
;
lines
[
lines_read
++
]
=
str
(
"
\n
"
,
line
,
": called here"
);
lines
[
i
++
]
=
str
(
"
\n
"
,
line
,
": called here"
);
}
// Skip remaining input.
...
...
@@ -112,14 +114,7 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
pclose
(
p
);
cleanup
:
if
(
oldPreload
!=
nullptr
)
{
setenv
(
"LD_PRELOAD"
,
oldPreload
.
cStr
(),
true
);
}
pthread_mutex_unlock
(
&
mutex
);
return
(
lines_read
>
0
?
strArray
(
arrayPtr
(
lines
,
lines_read
),
""
)
:
nullptr
);
return
strArray
(
arrayPtr
(
lines
,
i
),
""
);
#else
return
nullptr
;
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment