Allow gdb path based on image name.
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.maintenance.coredump;
+import com.yahoo.config.provision.DockerImage;
import com.yahoo.vespa.hosted.dockerapi.ProcessResult;
import com.yahoo.vespa.hosted.node.admin.docker.DockerOperations;
import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContext;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
@@ -29,15 +31,16 @@ public class CoreCollector {
private static final Pattern FROM_PATH_PATTERN = Pattern.compile("^.* from '(?<path>.*?)'");
private final DockerOperations docker;
- private final Path gdb;
+ private final Path vespaHomeInContainer;
- public CoreCollector(DockerOperations docker, Path pathToGdbInContainer) {
+ public CoreCollector(DockerOperations docker, Path vespaHomeInContainer) {
this.docker = docker;
- this.gdb = pathToGdbInContainer;
+ this.vespaHomeInContainer = vespaHomeInContainer;
}
Path readBinPathFallback(NodeAgentContext context, Path coredumpPath) {
- String command = gdb + " -n -batch -core " + coredumpPath + " | grep \'^Core was generated by\'";
+ String command = GDBPath(context).toString()
+ + " -n -batch -core " + coredumpPath + " | grep \'^Core was generated by\'";
String[] wrappedCommand = {"/bin/sh", "-c", command};
ProcessResult result = docker.executeCommandInContainerAsRoot(context, wrappedCommand);
@@ -49,6 +52,17 @@ public class CoreCollector {
return Paths.get(matcher.group("path").split(" ")[0]);
}
+ Path GDBPath(NodeAgentContext context) {
+ DockerImage image = context.node().currentDockerImage().get();
+
+ if (image.tag().get().startsWith("vespa/ci")) {
+ return vespaHomeInContainer.resolve("bin64/gdb");
+ }
+ else {
+ return Paths.get("/opt/rh/devtoolset-9/root/bin/gdb");
+ }
+ }
+
Path readBinPath(NodeAgentContext context, Path coredumpPath) {
String[] command = {"file", coredumpPath.toString()};
try {
@@ -76,7 +90,7 @@ public class CoreCollector {
List<String> readBacktrace(NodeAgentContext context, Path coredumpPath, Path binPath, boolean allThreads) {
String threads = allThreads ? "thread apply all bt" : "bt";
- String[] command = {gdb.toString(), "-n", "-ex", threads, "-batch", binPath.toString(), coredumpPath.toString()};
+ String[] command = {GDBPath(context).toString(), "-n", "-ex", threads, "-batch", binPath.toString(), coredumpPath.toString()};
ProcessResult result = docker.executeCommandInContainerAsRoot(context, command);
if (result.getExitStatus() != 0)
