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
d60914ca
Commit
d60914ca
authored
Jun 04, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include file/line of stack trace locations in exception description, if possible.
parent
6632dc8d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
5 deletions
+60
-5
common.h
c++/src/kj/common.h
+2
-0
debug-test.c++
c++/src/kj/debug-test.c++
+4
-4
exception.c++
c++/src/kj/exception.c++
+54
-1
No files found.
c++/src/kj/common.h
View file @
d60914ca
...
...
@@ -157,6 +157,8 @@ void inlineRequireFailure(
kj::arrayPtr(name##_stack, name##_size) : name##_heap
#endif
#define KJ_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
// =======================================================================================
// Template metaprogramming helpers.
...
...
c++/src/kj/debug-test.c++
View file @
d60914ca
...
...
@@ -46,8 +46,8 @@ public:
void
onRecoverableException
(
Exception
&&
exception
)
override
{
text
+=
"recoverable exception: "
;
auto
what
=
str
(
exception
);
// Discard the
last line of "what" because it is a
stack trace.
const
char
*
end
=
str
rchr
(
what
.
cStr
(),
'\n'
);
// Discard the stack trace.
const
char
*
end
=
str
str
(
what
.
cStr
(),
"
\n
stack: "
);
if
(
end
==
nullptr
)
{
text
+=
what
.
cStr
();
}
else
{
...
...
@@ -59,8 +59,8 @@ public:
void
onFatalException
(
Exception
&&
exception
)
override
{
text
+=
"fatal exception: "
;
auto
what
=
str
(
exception
);
// Discard the
last line of "what" because it is a
stack trace.
const
char
*
end
=
str
rchr
(
what
.
cStr
(),
'\n'
);
// Discard the stack trace.
const
char
*
end
=
str
str
(
what
.
cStr
(),
"
\n
stack: "
);
if
(
end
==
nullptr
)
{
text
+=
what
.
cStr
();
}
else
{
...
...
c++/src/kj/exception.c++
View file @
d60914ca
...
...
@@ -29,8 +29,61 @@
#include <stdlib.h>
#include <exception>
#if defined(__linux__) && !defined(NDEBUG)
#include <stdio.h>
#endif
namespace
kj
{
namespace
{
String
getStackSymbols
(
ArrayPtr
<
void
*
const
>
trace
)
{
#if defined(__linux__) && !defined(NDEBUG)
// Get executable name from /proc/self/exe, then pass it and the stack trace to addr2line to
// get file/line pairs.
char
exe
[
512
];
ssize_t
n
=
readlink
(
"/proc/self/exe"
,
exe
,
sizeof
(
exe
));
if
(
n
<
0
||
n
>=
sizeof
(
exe
))
{
return
nullptr
;
}
exe
[
n
]
=
'\0'
;
String
lines
[
6
];
FILE
*
p
=
popen
(
str
(
"addr2line -e "
,
exe
,
' '
,
strArray
(
trace
,
" "
)).
cStr
(),
"r"
);
if
(
p
==
nullptr
)
{
return
nullptr
;
}
char
line
[
512
];
size_t
i
=
0
;
while
(
i
<
KJ_ARRAY_SIZE
(
lines
)
&&
fgets
(
line
,
sizeof
(
line
),
p
)
!=
nullptr
)
{
// Don't include exception-handling infrastructure in stack trace.
if
(
i
==
0
&&
(
strstr
(
line
,
"kj/exception."
)
!=
nullptr
||
strstr
(
line
,
"kj/debug."
)
!=
nullptr
))
{
continue
;
}
size_t
len
=
strlen
(
line
);
if
(
len
>
0
&&
line
[
len
-
1
]
==
'\n'
)
line
[
len
-
1
]
=
'\0'
;
lines
[
i
++
]
=
str
(
"
\n
"
,
line
);
}
// Skip remaining input.
while
(
fgets
(
line
,
sizeof
(
line
),
p
)
!=
nullptr
)
{}
pclose
(
p
);
return
strArray
(
arrayPtr
(
lines
,
i
),
""
);
#else
return
nullptr
;
#endif
}
}
// namespace
ArrayPtr
<
const
char
>
KJ_STRINGIFY
(
Exception
::
Nature
nature
)
{
static
const
char
*
NATURE_STRINGS
[]
=
{
"requirement not met"
,
...
...
@@ -87,7 +140,7 @@ String KJ_STRINGIFY(const Exception& e) {
e
.
getFile
(),
":"
,
e
.
getLine
(),
": "
,
e
.
getNature
(),
e
.
getDurability
()
==
Exception
::
Durability
::
TEMPORARY
?
" (temporary)"
:
""
,
e
.
getDescription
()
==
nullptr
?
""
:
": "
,
e
.
getDescription
(),
"
\n
stack: "
,
strArray
(
e
.
getStackTrace
(),
" "
));
"
\n
stack: "
,
strArray
(
e
.
getStackTrace
(),
" "
)
,
getStackSymbols
(
e
.
getStackTrace
())
);
}
Exception
::
Exception
(
Nature
nature
,
Durability
durability
,
const
char
*
file
,
int
line
,
...
...
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