Merge pull request #24151 from veblush/stack-debug

Add stack-debugging features using Abseil
pull/24207/head
Esun Kim 5 years ago committed by GitHub
commit c516eb7c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      CMakeLists.txt
  2. 15
      build_autogenerated.yaml
  3. 5
      gRPC-Core.podspec
  4. 8
      grpc.gyp
  5. 7
      test/core/util/BUILD
  6. 102
      test/core/util/examine_stack.cc
  7. 34
      test/core/util/examine_stack.h
  8. 14
      test/core/util/test_config.cc

@ -1976,6 +1976,7 @@ add_library(grpc_test_util
test/core/util/cmdline.cc
test/core/util/debugger_macros.cc
test/core/util/eval_args_mock_endpoint.cc
test/core/util/examine_stack.cc
test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc
test/core/util/histogram.cc
@ -2030,6 +2031,9 @@ target_link_libraries(grpc_test_util
gpr
address_sorting
upb
absl::symbolize
absl::stacktrace
absl::failure_signal_handler
)
if(_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc_test_util "-framework CoreFoundation")
@ -2043,6 +2047,7 @@ add_library(grpc_test_util_unsecure
test/core/util/cmdline.cc
test/core/util/debugger_macros.cc
test/core/util/eval_args_mock_endpoint.cc
test/core/util/examine_stack.cc
test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc
test/core/util/histogram.cc
@ -2097,6 +2102,9 @@ target_link_libraries(grpc_test_util_unsecure
gpr
address_sorting
upb
absl::symbolize
absl::stacktrace
absl::failure_signal_handler
)
if(_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc_test_util_unsecure "-framework CoreFoundation")
@ -14826,6 +14834,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/cmdline.cc
test/core/util/debugger_macros.cc
test/core/util/eval_args_mock_endpoint.cc
test/core/util/examine_stack.cc
test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc
test/core/util/histogram.cc
@ -14875,6 +14884,9 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
gpr
address_sorting
upb
absl::symbolize
absl::stacktrace
absl::failure_signal_handler
${_gRPC_GFLAGS_LIBRARIES}
)

@ -1226,6 +1226,7 @@ libs:
- test/core/util/cmdline.h
- test/core/util/debugger_macros.h
- test/core/util/eval_args_mock_endpoint.h
- test/core/util/examine_stack.h
- test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h
- test/core/util/histogram.h
@ -1246,6 +1247,7 @@ libs:
- test/core/util/cmdline.cc
- test/core/util/debugger_macros.cc
- test/core/util/eval_args_mock_endpoint.cc
- test/core/util/examine_stack.cc
- test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc
@ -1269,6 +1271,9 @@ libs:
- gpr
- address_sorting
- upb
- absl/debugging:symbolize
- absl/debugging:stacktrace
- absl/debugging:failure_signal_handler
- name: grpc_test_util_unsecure
build: private
language: c
@ -1277,6 +1282,7 @@ libs:
- test/core/util/cmdline.h
- test/core/util/debugger_macros.h
- test/core/util/eval_args_mock_endpoint.h
- test/core/util/examine_stack.h
- test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h
- test/core/util/histogram.h
@ -1297,6 +1303,7 @@ libs:
- test/core/util/cmdline.cc
- test/core/util/debugger_macros.cc
- test/core/util/eval_args_mock_endpoint.cc
- test/core/util/examine_stack.cc
- test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc
@ -1320,6 +1327,9 @@ libs:
- gpr
- address_sorting
- upb
- absl/debugging:symbolize
- absl/debugging:stacktrace
- absl/debugging:failure_signal_handler
secure: false
- name: grpc_unsecure
build: all
@ -7435,6 +7445,7 @@ targets:
- test/core/util/cmdline.h
- test/core/util/debugger_macros.h
- test/core/util/eval_args_mock_endpoint.h
- test/core/util/examine_stack.h
- test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h
- test/core/util/histogram.h
@ -7458,6 +7469,7 @@ targets:
- test/core/util/cmdline.cc
- test/core/util/debugger_macros.cc
- test/core/util/eval_args_mock_endpoint.cc
- test/core/util/examine_stack.cc
- test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc
@ -7483,6 +7495,9 @@ targets:
- gpr
- address_sorting
- upb
- absl/debugging:symbolize
- absl/debugging:stacktrace
- absl/debugging:failure_signal_handler
platforms:
- linux
- posix

@ -1612,6 +1612,9 @@ Pod::Spec.new do |s|
ss.dependency "#{s.name}/Interface", version
ss.dependency "#{s.name}/Implementation", version
ss.dependency 'abseil/debugging/failure_signal_handler', abseil_version
ss.dependency 'abseil/debugging/stacktrace', abseil_version
ss.dependency 'abseil/debugging/symbolize', abseil_version
ss.source_files = 'test/core/end2end/cq_verifier.cc',
'test/core/end2end/cq_verifier.h',
@ -1716,6 +1719,8 @@ Pod::Spec.new do |s|
'test/core/util/debugger_macros.h',
'test/core/util/eval_args_mock_endpoint.cc',
'test/core/util/eval_args_mock_endpoint.h',
'test/core/util/examine_stack.cc',
'test/core/util/examine_stack.h',
'test/core/util/fuzzer_util.cc',
'test/core/util/fuzzer_util.h',
'test/core/util/grpc_profiler.cc',

@ -895,11 +895,15 @@
'gpr',
'address_sorting',
'upb',
'absl/debugging:symbolize',
'absl/debugging:stacktrace',
'absl/debugging:failure_signal_handler',
],
'sources': [
'test/core/util/cmdline.cc',
'test/core/util/debugger_macros.cc',
'test/core/util/eval_args_mock_endpoint.cc',
'test/core/util/examine_stack.cc',
'test/core/util/fuzzer_util.cc',
'test/core/util/grpc_profiler.cc',
'test/core/util/histogram.cc',
@ -928,11 +932,15 @@
'gpr',
'address_sorting',
'upb',
'absl/debugging:symbolize',
'absl/debugging:stacktrace',
'absl/debugging:failure_signal_handler',
],
'sources': [
'test/core/util/cmdline.cc',
'test/core/util/debugger_macros.cc',
'test/core/util/eval_args_mock_endpoint.cc',
'test/core/util/examine_stack.cc',
'test/core/util/fuzzer_util.cc',
'test/core/util/grpc_profiler.cc',
'test/core/util/histogram.cc',

@ -39,6 +39,7 @@ grpc_cc_library(
srcs = [
"cmdline.cc",
"eval_args_mock_endpoint.cc",
"examine_stack.cc",
"fuzzer_util.cc",
"grpc_profiler.cc",
"histogram.cc",
@ -61,6 +62,7 @@ grpc_cc_library(
hdrs = [
"cmdline.h",
"eval_args_mock_endpoint.h",
"examine_stack.h",
"fuzzer_util.h",
"grpc_profiler.h",
"histogram.h",
@ -83,6 +85,11 @@ grpc_cc_library(
"tsan_suppressions.txt",
"ubsan_suppressions.txt",
],
external_deps = [
"absl/debugging:failure_signal_handler",
"absl/debugging:stacktrace",
"absl/debugging:symbolize",
],
language = "C++",
deps = [
":grpc_debugger_macros",

@ -0,0 +1,102 @@
/*
*
* Copyright 2020 the gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <grpc/support/port_platform.h>
#include "test/core/util/examine_stack.h"
#include <cstdio>
#include <string>
#include "absl/debugging/stacktrace.h"
#include "absl/debugging/symbolize.h"
namespace {
static constexpr int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*);
static void DumpPCAndFrameSizeAndSymbol(void (*writerfn)(const char*, void*),
void* writerfn_arg, void* pc,
void* symbolize_pc, int framesize,
const char* const prefix) {
char tmp[1024];
const char* symbol = "(unknown)";
if (absl::Symbolize(symbolize_pc, tmp, sizeof(tmp))) {
symbol = tmp;
}
char buf[1024];
if (framesize <= 0) {
snprintf(buf, sizeof(buf), "%s@ %*p (unknown) %s\n", prefix,
kPrintfPointerFieldWidth, pc, symbol);
} else {
snprintf(buf, sizeof(buf), "%s@ %*p %9d %s\n", prefix,
kPrintfPointerFieldWidth, pc, framesize, symbol);
}
writerfn(buf, writerfn_arg);
}
static void DumpPCAndFrameSize(void (*writerfn)(const char*, void*),
void* writerfn_arg, void* pc, int framesize,
const char* const prefix) {
char buf[100];
if (framesize <= 0) {
snprintf(buf, sizeof(buf), "%s@ %*p (unknown)\n", prefix,
kPrintfPointerFieldWidth, pc);
} else {
snprintf(buf, sizeof(buf), "%s@ %*p %9d\n", prefix,
kPrintfPointerFieldWidth, pc, framesize);
}
writerfn(buf, writerfn_arg);
}
static void DumpStackTrace(void* const stack[], int frame_sizes[], int depth,
bool symbolize_stacktrace,
void (*writerfn)(const char*, void*),
void* writerfn_arg) {
for (int i = 0; i < depth; i++) {
if (symbolize_stacktrace) {
DumpPCAndFrameSizeAndSymbol(writerfn, writerfn_arg, stack[i],
reinterpret_cast<char*>(stack[i]) - 1,
frame_sizes[i], " ");
} else {
DumpPCAndFrameSize(writerfn, writerfn_arg, stack[i], frame_sizes[i],
" ");
}
}
}
static void DebugWriteToString(const char* data, void* str) {
reinterpret_cast<std::string*>(str)->append(data);
}
} // namespace
namespace grpc_core {
std::string CurrentStackTrace() {
std::string result = "Stack trace:\n";
constexpr int kNumStackFrames = 32;
void* stack[kNumStackFrames];
int frame_sizes[kNumStackFrames];
int depth = absl::GetStackFrames(stack, frame_sizes, kNumStackFrames, 1);
DumpStackTrace(stack, frame_sizes, depth, true, DebugWriteToString,
(void*)&result);
return result;
}
} // namespace grpc_core

@ -0,0 +1,34 @@
/*
*
* Copyright 2020 the gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_TEST_CORE_UTIL_EXAMINE_STACK_H
#define GRPC_TEST_CORE_UTIL_EXAMINE_STACK_H
#include <grpc/support/port_platform.h>
#include <string>
namespace grpc_core {
// Return the current stack trace as a string (on multiple lines, beginning with
// "Stack trace:\n")
std::string CurrentStackTrace();
} // namespace grpc_core
#endif /* GRPC_TEST_CORE_UTIL_EXAMINE_STACK_H */

@ -34,6 +34,9 @@
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/surface/init.h"
#include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/symbolize.h"
int64_t g_fixture_slowdown_factor = 1;
int64_t g_poller_slowdown_factor = 1;
@ -368,8 +371,17 @@ gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms) {
GPR_TIMESPAN));
}
void grpc_test_init(int /*argc*/, char** /*argv*/) {
void grpc_test_init(int argc, char** argv) {
#if GPR_WINDOWS
// Windows cannot use absl::InitializeSymbolizer until it fixes mysterious
// SymInitialize failure using Bazel RBE on Windows
// https://github.com/grpc/grpc/issues/24178
install_crash_handler();
#else
absl::InitializeSymbolizer(argv[0]);
absl::FailureSignalHandlerOptions options;
absl::InstallFailureSignalHandler(options);
#endif
gpr_log(GPR_DEBUG,
"test slowdown factor: sanitizer=%" PRId64 ", fixture=%" PRId64
", poller=%" PRId64 ", total=%" PRId64,

Loading…
Cancel
Save