mirror of https://github.com/mongodb/mongo
SERVER-104974 make gdb dump locks work in bazel (#39768)
GitOrigin-RevId: db75a756afbfd30990abeee0e2372cb752ca77b3
This commit is contained in:
parent
a4a07ab522
commit
1eb7154b39
|
|
@ -4,6 +4,7 @@ load("//bazel/install_rules:install_rules.bzl", "TEST_TAGS", "mongo_install")
|
|||
load("//bazel/install_rules:bolt.bzl", "bolt_instrument", "bolt_optimize")
|
||||
load("//bazel:mongo_src_rules.bzl", "mongo_cc_binary")
|
||||
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain.bzl", "setup_mongo_toolchain_aliases")
|
||||
load("//bazel/toolchains/cc/mongo_linux:mongo_gdb.bzl", "setup_gdb_toolchain_aliases")
|
||||
load("//bazel/config:render_template.bzl", "render_template")
|
||||
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
|
||||
load("//bazel:mongo_js_rules.bzl", "mongo_js_library")
|
||||
|
|
@ -95,6 +96,8 @@ alias(
|
|||
|
||||
setup_mongo_toolchain_aliases()
|
||||
|
||||
setup_gdb_toolchain_aliases()
|
||||
|
||||
render_template(
|
||||
name = "clang_tidy_config",
|
||||
srcs = [
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain.bzl", "setup_mongo_toolchains")
|
||||
load("//bazel/toolchains/cc/mongo_linux:mongo_gdb.bzl", "gdb_download")
|
||||
load("//bazel/toolchains/cc/mongo_linux:mongo_gdb.bzl", "setup_gdb_toolchains")
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_lint",
|
||||
|
|
@ -11,10 +11,7 @@ http_archive(
|
|||
|
||||
setup_mongo_toolchains()
|
||||
|
||||
gdb_download(
|
||||
name = "gdb",
|
||||
version = "v5",
|
||||
)
|
||||
setup_gdb_toolchains()
|
||||
|
||||
http_archive(
|
||||
name = "windows_sasl",
|
||||
|
|
|
|||
|
|
@ -751,7 +751,7 @@ def _mongo_cc_binary_and_test(
|
|||
"testonly": testonly,
|
||||
"copts": copts,
|
||||
"data": data + SANITIZER_DATA + select({
|
||||
"//bazel/platforms:use_mongo_toolchain": ["@gdb"],
|
||||
"//bazel/platforms:use_mongo_toolchain": ["//:gdb"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
"tags": tags,
|
||||
|
|
|
|||
|
|
@ -3,40 +3,83 @@ load("//bazel:utils.bzl", "generate_noop_toolchain", "get_toolchain_subs", "retr
|
|||
|
||||
def _gdb_download(ctx):
|
||||
distro, arch, substitutions = get_toolchain_subs(ctx)
|
||||
|
||||
toolchain_key = "{distro}_{arch}".format(distro = distro, arch = arch)
|
||||
|
||||
if toolchain_key in TOOLCHAIN_MAP_V5:
|
||||
toolchain_info = TOOLCHAIN_MAP_V5[toolchain_key]
|
||||
urls = toolchain_info["url"]
|
||||
sha = toolchain_info["sha"]
|
||||
toolchain_info = None
|
||||
python3_version = None
|
||||
urls = None
|
||||
sha = None
|
||||
|
||||
ctx.report_progress("downloading {} gdb: {}".format(toolchain_key, urls))
|
||||
retry_download_and_extract(
|
||||
ctx = ctx,
|
||||
tries = 5,
|
||||
url = urls,
|
||||
sha256 = sha,
|
||||
)
|
||||
if ctx.attr.version == "v5":
|
||||
if toolchain_key in TOOLCHAIN_MAP_V5:
|
||||
python3_version = "3.10"
|
||||
toolchain_info = TOOLCHAIN_MAP_V5[toolchain_key]
|
||||
urls = toolchain_info["url"]
|
||||
sha = toolchain_info["sha"]
|
||||
|
||||
ctx.report_progress("generating gdb " + ctx.attr.version + " build file")
|
||||
pythonhome = str(ctx.workspace_root) + "/bazel-mongo/external/gdb/stow/python3-" + ctx.attr.version
|
||||
ctx.file(
|
||||
"BUILD.bazel",
|
||||
"""
|
||||
if toolchain_info == None:
|
||||
generate_noop_toolchain(ctx, substitutions)
|
||||
ctx.report_progress("Mongo gdb " + ctx.attr.version + " not supported on this platform. Platform key not found: " + toolchain_key)
|
||||
return None
|
||||
|
||||
ctx.report_progress("downloading {} gdb: {}".format(toolchain_key, urls))
|
||||
retry_download_and_extract(
|
||||
ctx = ctx,
|
||||
tries = 5,
|
||||
url = urls,
|
||||
sha256 = sha,
|
||||
)
|
||||
|
||||
ctx.report_progress("generating gdb " + ctx.attr.version + " build file")
|
||||
|
||||
external = str(ctx.path(".."))
|
||||
pythonhome = external + "/gdb_" + ctx.attr.version + "/stow/python3-" + ctx.attr.version
|
||||
|
||||
mongodb_toolchain_path = external + "/mongo_toolchain_" + ctx.attr.version
|
||||
stdlib_pp_dir = mongodb_toolchain_path + "/stow/gcc-" + ctx.attr.version + "/share"
|
||||
readelf = mongodb_toolchain_path + "/" + ctx.attr.version + "/bin/llvm-readelf"
|
||||
|
||||
if "amazon_linux_2" == distro:
|
||||
# our toolchain python version requires newer openssl, which is not available on AL2
|
||||
# so we can use pretty printers on AL2
|
||||
python_env = "{}"
|
||||
else:
|
||||
# here we only have one dependency for our pretty printers to run. It must be installed into the python
|
||||
# that gdb was built with. We use pip since this is a single dependency that we own.
|
||||
result = ctx.execute([
|
||||
pythonhome + "/bin/python3",
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"pymongo==4.12.0",
|
||||
"--target=" + pythonhome + "/lib/python" + python3_version + "/site-packages",
|
||||
])
|
||||
if result.return_code != 0:
|
||||
fail("Failed to install python module: " + result.stderr)
|
||||
|
||||
python_env = """{
|
||||
"PYTHONPATH": "%s/lib/python3.10",
|
||||
"PYTHONHOME": "%s",
|
||||
"MONGO_GDB_PP_DIR": "%s",
|
||||
"MONGO_GDB_READELF": "%s",
|
||||
}""" % (pythonhome, pythonhome, stdlib_pp_dir, readelf)
|
||||
|
||||
ctx.file(
|
||||
"BUILD.bazel",
|
||||
"""
|
||||
sh_binary(
|
||||
name = "gdb",
|
||||
srcs = ["working_dir.sh"],
|
||||
data = ["%s/bin/gdb"],
|
||||
env = {"PYTHONPATH": "%s/lib/python3.10", "PYTHONHOME": "%s"},
|
||||
env = %s,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
""" % (ctx.attr.version, pythonhome, pythonhome),
|
||||
)
|
||||
""" % (ctx.attr.version, python_env),
|
||||
)
|
||||
|
||||
ctx.file(
|
||||
"working_dir.sh",
|
||||
"""
|
||||
ctx.file(
|
||||
"working_dir.sh",
|
||||
"""
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
|
@ -44,23 +87,18 @@ set -e
|
|||
RUNFILES_WORKING_DIRECTORY="$(pwd)"
|
||||
|
||||
if [ -z $BUILD_WORKING_DIRECTORY ]; then
|
||||
echo "ERROR: BUILD_WORKING_DIRECTORY was not set, was this run from bazel?"
|
||||
exit 1
|
||||
echo "ERROR: BUILD_WORKING_DIRECTORY was not set, was this run from bazel?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $BUILD_WORKING_DIRECTORY
|
||||
|
||||
${RUNFILES_WORKING_DIRECTORY}/../gdb/%s/bin/gdb "${@:1}"
|
||||
""" % ctx.attr.version,
|
||||
)
|
||||
|
||||
else:
|
||||
generate_noop_toolchain(ctx, substitutions)
|
||||
ctx.report_progress("Mongo gdb " + ctx.attr.version + " not supported on this platform. Platform key not found: " + toolchain_key)
|
||||
${RUNFILES_WORKING_DIRECTORY}/../gdb_%s/%s/bin/gdb -iex "set auto-load safe-path %s/.gdbinit" "${@:1}"
|
||||
""" % (ctx.attr.version, ctx.attr.version, str(ctx.workspace_root)),
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
gdb_download = repository_rule(
|
||||
gdb_v5_download = repository_rule(
|
||||
implementation = _gdb_download,
|
||||
attrs = {
|
||||
"os": attr.string(
|
||||
|
|
@ -71,10 +109,28 @@ gdb_download = repository_rule(
|
|||
values = ["amd64", "aarch64", "amd64", "x86_64", "ppc64le", "s390x"],
|
||||
doc = "Host architecture.",
|
||||
),
|
||||
"version": attr.string(
|
||||
values = ["v4", "v5"],
|
||||
doc = "Mongodbtoolchain version.",
|
||||
mandatory = True,
|
||||
"version": attr.string(),
|
||||
"mongo_toolchain": attr.label(
|
||||
allow_files = True,
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
def setup_gdb_toolchains():
|
||||
gdb_v5_download(
|
||||
name = "gdb_v5",
|
||||
version = "v5",
|
||||
mongo_toolchain = "@mongo_toolchain_v5//:all",
|
||||
)
|
||||
|
||||
def setup_gdb_toolchain_aliases(name = "setup_toolchains"):
|
||||
# v5 is the default version we currently use, so we name it unversioned
|
||||
native.alias(
|
||||
name = "gdb",
|
||||
actual = "@gdb_v5//:gdb",
|
||||
)
|
||||
|
||||
native.alias(
|
||||
name = "gdb_v5",
|
||||
actual = "@gdb_v5//:gdb",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,13 +17,10 @@ if not gdb:
|
|||
|
||||
|
||||
def detect_toolchain(progspace):
|
||||
readelf_bin = "readelf"
|
||||
for path in [
|
||||
"/opt/mongodbtoolchain/v5/bin/llvm-readelf",
|
||||
]:
|
||||
if os.path.exists(path):
|
||||
readelf_bin = path
|
||||
break
|
||||
|
||||
readelf_bin = os.environ.get("MONGO_GDB_READELF", "/opt/mongodbtoolchain/v5/bin/llvm-readelf")
|
||||
if not os.path.exists(readelf_bin):
|
||||
readelf_bin = "readelf"
|
||||
|
||||
gcc_version_regex = re.compile(r".*\]\s*GCC: \(GNU\) (\d+\.\d+\.\d+)\s*$")
|
||||
clang_version_regex = re.compile(r".*\]\s*MongoDB clang version (\d+\.\d+\.\d+).*")
|
||||
|
|
@ -79,8 +76,9 @@ STDERR:
|
|||
-----------------
|
||||
Assuming {toolchain_ver} as a default, this could cause issues with the printers.""")
|
||||
|
||||
base_toolchain_dir = os.environ.get("MONGO_GDB_PP_DIR", f"/opt/mongodbtoolchain/{toolchain_ver}/share")
|
||||
pp = glob.glob(
|
||||
f"/opt/mongodbtoolchain/{toolchain_ver}/share/gcc-*/python/libstdcxx/v6/printers.py"
|
||||
f"{base_toolchain_dir}/gcc-*/python/libstdcxx/v6/printers.py"
|
||||
)
|
||||
printers = pp[0]
|
||||
return os.path.dirname(os.path.dirname(os.path.dirname(printers)))
|
||||
|
|
@ -587,7 +585,7 @@ class MongoDBDumpLocks(gdb.Command):
|
|||
print("Running Hang Analyzer Supplement - MongoDBDumpLocks")
|
||||
|
||||
main_binary_name = get_process_name()
|
||||
if main_binary_name == "mongod":
|
||||
if main_binary_name == "mongod" or main_binary_name == "mongod_with_debug":
|
||||
self.dump_mongod_locks()
|
||||
else:
|
||||
print("Not invoking mongod lock dump for: %s" % (main_binary_name))
|
||||
|
|
|
|||
Loading…
Reference in New Issue