| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include "absl/debugging/stacktrace.h" |
| 16 |
| 17 | #include "gtest/gtest.h" |
| 18 | #include "absl/base/macros.h" |
| 19 | #include "absl/base/optimization.h" |
| 20 |
| 21 | namespace { |
| 22 |
| 23 | // This test is currently only known to pass on Linux x86_64/aarch64. |
| 24 | #if defined(__linux__) && (defined(__x86_64__) || defined(__aarch64__)) |
| 25 | ABSL_ATTRIBUTE_NOINLINE void Unwind(void* p) { |
| 26 | ABSL_ATTRIBUTE_UNUSED static void* volatile sink = p; |
| 27 | constexpr int kSize = 16; |
| 28 | void* stack[kSize]; |
| 29 | int frames[kSize]; |
| 30 | absl::GetStackTrace(stack, kSize, 0); |
| 31 | absl::GetStackFrames(stack, frames, kSize, 0); |
| 32 | } |
| 33 |
| 34 | ABSL_ATTRIBUTE_NOINLINE void HugeFrame() { |
| 35 | char buffer[1 << 20]; |
| 36 | Unwind(buffer); |
| 37 | ABSL_BLOCK_TAIL_CALL_OPTIMIZATION(); |
| 38 | } |
| 39 |
| 40 | TEST(StackTrace, HugeFrame) { |
| 41 | // Ensure that the unwinder is not confused by very large stack frames. |
| 42 | HugeFrame(); |
| 43 | ABSL_BLOCK_TAIL_CALL_OPTIMIZATION(); |
| 44 | } |
| 45 | #endif |
| 46 |
| 47 | } // namespace |
| 48 |