mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Break on nullptr return address in UnwindImpl on RISC-V
PiperOrigin-RevId: 914222352 Change-Id: Iff9028a38e878465961f71e90484c2a62ed89132
This commit is contained in:
committed by
Copybara-Service
parent
5704b72fe0
commit
33bbc26609
@@ -74,10 +74,19 @@ static int UnwindImpl(void **result, uintptr_t *frames, int *sizes,
|
|||||||
size =
|
size =
|
||||||
static_cast<int>(emscripten_stack_unwind_buffer(pc, stack, kStackLength));
|
static_cast<int>(emscripten_stack_unwind_buffer(pc, stack, kStackLength));
|
||||||
|
|
||||||
int result_count = size - skip_count;
|
int num_frames = size - skip_count;
|
||||||
if (result_count < 0) result_count = 0;
|
if (num_frames < 0) num_frames = 0;
|
||||||
if (result_count > max_depth) result_count = max_depth;
|
if (num_frames > max_depth) num_frames = max_depth;
|
||||||
for (int i = 0; i < result_count; i++) result[i] = stack[i + skip_count];
|
|
||||||
|
int result_count = 0;
|
||||||
|
for (int i = 0; i < num_frames; i++) {
|
||||||
|
int stack_index = i + skip_count;
|
||||||
|
// Follow x86 and stop if the return address is null (end of stack).
|
||||||
|
if (stack[stack_index] == nullptr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result[result_count++] = stack[stack_index];
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_STACK_FRAMES) {
|
if (IS_STACK_FRAMES) {
|
||||||
// No implementation for finding out the stack frames yet.
|
// No implementation for finding out the stack frames yet.
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ static int UnwindImpl(void **result, uintptr_t *frames, int *sizes,
|
|||||||
void *return_address = nullptr;
|
void *return_address = nullptr;
|
||||||
while (frame_pointer && n < max_depth) {
|
while (frame_pointer && n < max_depth) {
|
||||||
return_address = frame_pointer[-1];
|
return_address = frame_pointer[-1];
|
||||||
|
// Follow x86 and stop if the return address is null (end of stack).
|
||||||
|
if (return_address == nullptr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// The absl::GetStackFrames routine is called when we are in some
|
// The absl::GetStackFrames routine is called when we are in some
|
||||||
// informational context (the failure signal handler for example). Use the
|
// informational context (the failure signal handler for example). Use the
|
||||||
|
|||||||
@@ -378,4 +378,14 @@ TEST(StackTrace, NestedSignal) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TEST(StackTrace, NoNullptrInPopulatedRange) {
|
||||||
|
constexpr int kMaxDepth = 1024;
|
||||||
|
void* results[kMaxDepth];
|
||||||
|
int depth = absl::GetStackTrace(results, kMaxDepth, 0);
|
||||||
|
for (int i = 0; i < depth; ++i) {
|
||||||
|
EXPECT_NE(results[i], nullptr) << "Unexpected nullptr found at index " << i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user