Skip to content

Commit

Permalink
Add an object address to stacktrace_frame entries, addresses #97 (no …
Browse files Browse the repository at this point in the history
…pun intended)
  • Loading branch information
jeremy-rifkin committed Feb 27, 2024
1 parent d5b2646 commit 3c7a677
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
6 changes: 4 additions & 2 deletions include/cpptrace/cpptrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,17 @@ namespace cpptrace {
};

struct CPPTRACE_EXPORT stacktrace_frame {
frame_ptr address;
frame_ptr raw_address;
frame_ptr object_address;
nullable<std::uint32_t> line;
nullable<std::uint32_t> column;
std::string filename;
std::string symbol;
bool is_inline;

bool operator==(const stacktrace_frame& other) const {
return address == other.address
return raw_address == other.raw_address
&& object_address == other.object_address
&& line == other.line
&& column == other.column
&& filename == other.filename
Expand Down
3 changes: 2 additions & 1 deletion include/ctrace/ctrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ CTRACE_BEGIN_DEFINITIONS
};

struct ctrace_stacktrace_frame {
ctrace_frame_ptr address;
ctrace_frame_ptr raw_address;
ctrace_frame_ptr object_address;
uint32_t line;
uint32_t column;
const char* filename;
Expand Down
4 changes: 2 additions & 2 deletions src/cpptrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace cpptrace {
<< "0x"
<< std::setw(2 * sizeof(frame_ptr))
<< std::setfill('0')
<< frame.address
<< frame.raw_address
<< std::dec
<< std::setfill(' ');
if(!frame.symbol.empty()) {
Expand Down Expand Up @@ -204,7 +204,7 @@ namespace cpptrace {
<< "0x"
<< std::setw(2 * sizeof(frame_ptr))
<< std::setfill('0')
<< frame.address
<< frame.raw_address
<< std::dec
<< std::setfill(' ')
<< reset;
Expand Down
8 changes: 5 additions & 3 deletions src/ctrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ CTRACE_FORMAT_EPILOGUE
frames,
[] (const cpptrace::stacktrace_frame& frame) -> ctrace_stacktrace_frame {
ctrace_stacktrace_frame new_frame;
new_frame.address = frame.address;
new_frame.raw_address = frame.raw_address;
new_frame.object_address = frame.object_address;
new_frame.line = frame.line.value_or(invalid_pos);
new_frame.column = frame.column.value_or(invalid_pos);
new_frame.filename = generate_owning_string(frame.filename).data;
Expand All @@ -135,7 +136,8 @@ CTRACE_FORMAT_EPILOGUE
static constexpr auto null_v = nullable_type::null().raw_value;
const ctrace_stacktrace_frame& old_frame = ptrace->frames[i];
cpptrace::stacktrace_frame new_frame;
new_frame.address = old_frame.address;
new_frame.raw_address = old_frame.raw_address;
new_frame.object_address = old_frame.object_address;
new_frame.line = nullable_type{is_empty(old_frame.line) ? null_v : old_frame.line};
new_frame.column = nullable_type{is_empty(old_frame.column) ? null_v : old_frame.column};
new_frame.filename = old_frame.filename;
Expand Down Expand Up @@ -348,7 +350,7 @@ extern "C" {
(void)std::fprintf(to, "%s0x%0*llx%s",
blue,
int(ptr_len),
cpptrace::detail::to_ull(frames[i].address),
cpptrace::detail::to_ull(frames[i].raw_address),
reset);
}
if(!ctrace::is_empty(frames[i].symbol)) {
Expand Down
2 changes: 1 addition & 1 deletion src/symbols/symbols_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace detail {
std::vector<frame_ptr> addresses;
for(const auto& frame : vec) {
if(frame.symbol.empty() || frame.filename.empty()) {
addresses.push_back(frame.address);
addresses.push_back(frame.raw_address);
}
}
std::vector<stacktrace_frame> new_frames = resolver(addresses);
Expand Down
10 changes: 8 additions & 2 deletions src/symbols/symbols_with_libdwarf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ namespace libdwarf {
const auto col = die.get_unsigned_attribute(DW_AT_call_column);
inlines.push_back(stacktrace_frame{
0,
0, // TODO: Could put an object address here...
{static_cast<std::uint32_t>(line.value_or(0))},
{static_cast<std::uint32_t>(col.value_or(0))},
file,
Expand Down Expand Up @@ -901,6 +902,7 @@ namespace libdwarf {
return {
{
frame_info.raw_address,
frame_info.object_address,
nullable<std::uint32_t>::null(),
nullable<std::uint32_t>::null(),
frame_info.object_path,
Expand All @@ -912,7 +914,8 @@ namespace libdwarf {
}
stacktrace_frame frame = null_frame;
frame.filename = frame_info.object_path;
frame.address = frame_info.raw_address;
frame.raw_address = frame_info.raw_address;
frame.object_address = frame_info.object_address;
if(trace_dwarf) {
std::fprintf(
stderr,
Expand Down Expand Up @@ -941,6 +944,7 @@ namespace libdwarf {
return {
{
frame_info.raw_address,
frame_info.object_address,
nullable<std::uint32_t>::null(),
nullable<std::uint32_t>::null(),
frame_info.object_path,
Expand Down Expand Up @@ -1145,7 +1149,8 @@ namespace libdwarf {
try {
frame = resolver->resolve_frame(dlframe);
} catch(...) {
frame.frame.address = dlframe.raw_address;
frame.frame.raw_address = dlframe.raw_address;
frame.frame.object_address = dlframe.object_address;
frame.frame.filename = dlframe.object_path;
if(!should_absorb_trace_exceptions()) {
throw;
Expand All @@ -1166,6 +1171,7 @@ namespace libdwarf {
frame = {
{
dlframe.raw_address,
dlframe.object_address,
nullable<std::uint32_t>::null(),
nullable<std::uint32_t>::null(),
dlframe.object_path,
Expand Down
10 changes: 9 additions & 1 deletion src/utils/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ namespace detail {
return str;
}

static const stacktrace_frame null_frame {0, nullable<uint32_t>::null(), nullable<uint32_t>::null(), "", "", false};
static const stacktrace_frame null_frame {
0,
0,
nullable<uint32_t>::null(),
nullable<uint32_t>::null(),
"",
"",
false
};

bool should_absorb_trace_exceptions();
bool should_resolve_inlined_calls();
Expand Down

0 comments on commit 3c7a677

Please sign in to comment.