| 5868 | |
| 5869 | std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count) |
| 5870 | GTEST_LOCK_EXCLUDED_(mutex_) { |
| 5871 | #if GTEST_HAS_ABSL |
| 5872 | std::string result; |
| 5873 | |
| 5874 | if (max_depth <= 0) { |
| 5875 | return result; |
| 5876 | } |
| 5877 | |
| 5878 | max_depth = std::min(max_depth, kMaxStackTraceDepth); |
| 5879 | |
| 5880 | std::vector<void*> raw_stack(max_depth); |
| 5881 | // Skips the frames requested by the caller, plus this function. |
| 5882 | const int raw_stack_size = |
| 5883 | absl::GetStackTrace(&raw_stack[0], max_depth, skip_count + 1); |
| 5884 | |
| 5885 | void* caller_frame = nullptr; |
| 5886 | { |
| 5887 | MutexLock lock(&mutex_); |
| 5888 | caller_frame = caller_frame_; |
| 5889 | } |
| 5890 | |
| 5891 | for (int i = 0; i < raw_stack_size; ++i) { |
| 5892 | if (raw_stack[i] == caller_frame && |
| 5893 | !GTEST_FLAG(show_internal_stack_frames)) { |
| 5894 | // Add a marker to the trace and stop adding frames. |
| 5895 | absl::StrAppend(&result, kElidedFramesMarker, "\n"); |
| 5896 | break; |
| 5897 | } |
| 5898 | |
| 5899 | char tmp[1024]; |
| 5900 | const char* symbol = "(unknown)"; |
| 5901 | if (absl::Symbolize(raw_stack[i], tmp, sizeof(tmp))) { |
| 5902 | symbol = tmp; |
| 5903 | } |
| 5904 | |
| 5905 | char line[1024]; |
| 5906 | snprintf(line, sizeof(line), " %p: %s\n", raw_stack[i], symbol); |
| 5907 | result += line; |
| 5908 | } |
| 5909 | |
| 5910 | return result; |
| 5911 | |
| 5912 | #else // !GTEST_HAS_ABSL |
| 5913 | static_cast<void>(max_depth); |
| 5914 | static_cast<void>(skip_count); |
| 5915 | return ""; |
| 5916 | #endif // GTEST_HAS_ABSL |
| 5917 | } |
| 5918 | |
| 5919 | void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) { |
| 5920 | #if GTEST_HAS_ABSL |
no test coverage detected