Skip to content

Commit

Permalink
Debug: add cgo symbolizer (#5255)
Browse files Browse the repository at this point in the history
* Add cgo_symbolizer config

* Add comment

* use import block
  • Loading branch information
prestonvanloon committed Mar 31, 2020
1 parent 6edb301 commit 00ef08b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .bazelrc
Expand Up @@ -39,6 +39,12 @@ build:release --compilation_mode=opt
build:llvm --crosstool_top=@llvm_toolchain//:toolchain
build:llvm --define compiler=llvm

# Build binary with cgo symbolizer for debugging / profiling.
build:cgo_symbolizer --config=llvm
build:cgo_symbolizer --copt=-g
build:cgo_symbolizer --define=USE_CGO_SYMBOLIZER=true
build:cgo_symbolizer -c dbg

# multi-arch cross-compiling toolchain configs:
-----------------------------------------------
build:cross --crosstool_top=@prysm_toolchains//:multiarch_toolchain
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,6 +17,7 @@ bazel-*
# Coverage outputs
coverage.txt
profile.out
profile.grind

# Nodejs
node_modules
Expand Down
7 changes: 7 additions & 0 deletions WORKSPACE
Expand Up @@ -1649,3 +1649,10 @@ go_repository(
load("@com_github_prysmaticlabs_prombbolt//:repositories.bzl", "prombbolt_dependencies")

prombbolt_dependencies()

go_repository(
name = "com_github_ianlancetaylor_cgosymbolizer",
importpath = "github.com/ianlancetaylor/cgosymbolizer",
sum = "h1:GWsU1WjSE2rtvyTYGcndqmPPkQkBNV7pEuZdnGtwtu4=",
version = "v0.0.0-20200321040036-d43e30eacb43",
)
16 changes: 14 additions & 2 deletions shared/debug/BUILD.bazel
@@ -1,11 +1,20 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

config_setting(
name = "use_cgosymbolizer",
values = {"define": "USE_CGO_SYMBOLIZER=true"},
)

# gazelle:ignore cgo_symbolizer.go
go_library(
name = "go_default_library",
srcs = [
"debug.go",
"maxprocs_metric.go",
],
] + select({
":use_cgosymbolizer": ["cgo_symbolizer.go"],
"//conditions:default": [],
}),
importpath = "github.com/prysmaticlabs/prysm/shared/debug",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -14,5 +23,8 @@ go_library(
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@in_gopkg_urfave_cli_v2//:go_default_library",
],
] + select({
":use_cgosymbolizer": ["@com_github_ianlancetaylor_cgosymbolizer//:go_default_library"],
"//conditions:default": [],
}),
)
8 changes: 8 additions & 0 deletions shared/debug/cgo_symbolizer.go
@@ -0,0 +1,8 @@
package debug

import (
// Using this file with this imported library configures the process to
// expose cgo symbols when possible. Use --config=cgo_symbolizer to make use of
// this feature.
_ "github.com/ianlancetaylor/cgosymbolizer"
)

0 comments on commit 00ef08b

Please sign in to comment.