Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyiZzz committed Oct 8, 2023
1 parent 0fdabab commit d16714b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
42 changes: 20 additions & 22 deletions be/src/common/stack_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ namespace {
/// But we use atomic just in case, so it is possible to be modified at runtime.
std::atomic<bool> show_addresses = true;

#if defined(__ELF__) && !defined(__FreeBSD__)
void writePointerHex(const void* ptr, std::stringstream& buf) {
buf.write("0x", 2);
char hex_str[2 * sizeof(ptr)];
doris::vectorized::write_hex_uint_lowercase(reinterpret_cast<uintptr_t>(ptr), hex_str);
buf.write(hex_str, 2 * sizeof(ptr));
}
#endif
// #if defined(__ELF__) && !defined(__FreeBSD__)
// void writePointerHex(const void* ptr, std::stringstream& buf) {
// buf.write("0x", 2);
// char hex_str[2 * sizeof(ptr)];
// doris::vectorized::write_hex_uint_lowercase(reinterpret_cast<uintptr_t>(ptr), hex_str);
// buf.write(hex_str, 2 * sizeof(ptr));
// }
// #endif

bool shouldShowAddress(const void* addr) {
/// If the address is less than 4096, most likely it is a nullptr dereference with offset,
Expand Down Expand Up @@ -402,12 +402,13 @@ static void toStringEveryLineImpl([[maybe_unused]] const std::string dwarf_locat
out << " ?";
}

if (shouldShowAddress(physical_addr)) {
out << " @ ";
writePointerHex(physical_addr, out);
}
// Do not display the stack address and file name, it is not important.
// if (shouldShowAddress(physical_addr)) {
// out << " @ ";
// writePointerHex(physical_addr, out);
// }

out << " in " << (object ? object->name : "?");
// out << " in " << (object ? object->name : "?");

callback(out.str());

Expand Down Expand Up @@ -459,15 +460,12 @@ std::string toStringCached(const StackTrace::FramePointers& pointers, size_t off
}

std::string StackTrace::toString(int start_pointers_index) const {
if (start_pointers_index == 0) {
return toStringCached(frame_pointers, offset, size);
} else {
// Start output from the start_pointers_index position of frame pointers.
StackTrace::FramePointers frame_pointers_raw {};
std::copy(frame_pointers.begin() + start_pointers_index, frame_pointers.end(),
frame_pointers_raw.begin());
return toStringCached(frame_pointers_raw, offset, size - start_pointers_index);
}
// Default delete the first three frame pointers, which are inside the stack_trace.cpp.
start_pointers_index += 3;
StackTrace::FramePointers frame_pointers_raw {};
std::copy(frame_pointers.begin() + start_pointers_index, frame_pointers.end(),
frame_pointers_raw.begin());
return toStringCached(frame_pointers_raw, offset, size - start_pointers_index);
}

std::string StackTrace::toString(void** frame_pointers_raw, size_t offset, size_t size) {
Expand Down
4 changes: 2 additions & 2 deletions be/src/common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ class [[nodiscard]] Status {
}
#ifdef ENABLE_STACKTRACE
if constexpr (stacktrace && capture_stacktrace(code)) {
// Delete the first four frame pointers, which are inside the StackTrace and Status.
status._err_msg->_stack = get_stack_trace(4);
// Delete the first one frame pointers, which are inside the status.h
status._err_msg->_stack = get_stack_trace(1);
LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
}
#endif
Expand Down

0 comments on commit d16714b

Please sign in to comment.