Skip to content

Commit d885e62

Browse files
miladfarcacopybara-github
authored andcommitted
PR #2051: Fix absl_stacktrace_test on s390x
Imported from GitHub PR #2051 Commit 33bbc26 made changes to stacktrace_emscripten-inl.inc but did not change the stacktrace_generic-inl.inc file. This caused `absl_stacktrace_test` to fail on s390x. ``` Expected: (results[i]) != (nullptr), actual: NULL vs (nullptr) Unexpected nullptr found at index 14 [ FAILED ] StackTrace.NoNullptrInPopulatedRange (0 ms) ``` This patch applies the same logic to stacktrace_generic-inl.inc. Merge b2fef21 into 89203a0 Merging this change closes #2051 COPYBARA_INTEGRATE_REVIEW=#2051 from miladfarca:fix-33bbc26 b2fef21 PiperOrigin-RevId: 915361786 Change-Id: Iafb02166414df57845410457796758a97bcc253a
1 parent ca1d7cb commit d885e62

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

absl/debugging/internal/stacktrace_generic-inl.inc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,20 @@ static int UnwindImpl(void** result, uintptr_t* frames, int* sizes,
7171

7272
size = backtrace(stack, kStackLength);
7373
skip_count++; // we want to skip the current frame as well
74-
int result_count = size - skip_count;
75-
if (result_count < 0)
76-
result_count = 0;
77-
if (result_count > max_depth)
78-
result_count = max_depth;
79-
for (int i = 0; i < result_count; i++)
80-
result[i] = stack[i + skip_count];
74+
75+
int num_frames = size - skip_count;
76+
if (num_frames < 0) num_frames = 0;
77+
if (num_frames > max_depth) num_frames = max_depth;
78+
79+
int result_count = 0;
80+
for (int i = 0; i < num_frames; i++) {
81+
int stack_index = i + skip_count;
82+
// Follow x86 and stop if the return address is null (end of stack).
83+
if (stack[stack_index] == nullptr) {
84+
break;
85+
}
86+
result[result_count++] = stack[stack_index];
87+
}
8188

8289
if (IS_STACK_FRAMES) {
8390
// No implementation for finding out the stack frames yet.

0 commit comments

Comments
 (0)