MCPcopy Create free account
hub / github.com/CodeIntelligenceTesting/jazzer / getInstrumentorAgentPath

Function getInstrumentorAgentPath

launcher/jvm_tooling.cpp:96–131  ·  view source on GitHub ↗

getInstrumentorAgentPath searches for the fuzzing instrumentation agent and returns the location if it is found. Otherwise it calls exit(0).

Source from the content-addressed store, hash-verified

94// getInstrumentorAgentPath searches for the fuzzing instrumentation agent and
95// returns the location if it is found. Otherwise it calls exit(0).
96std::string getInstrumentorAgentPath() {
97 // User provided agent location takes precedence.
98 if (!FLAGS_agent_path.empty()) {
99 if (std::ifstream(FLAGS_agent_path).good()) return FLAGS_agent_path;
100 std::cerr << "ERROR: Could not find " << kJazzerFileName << " at \""
101 << FLAGS_agent_path << "\"" << std::endl;
102 exit(1);
103 }
104
105 auto executable_path = getExecutablePath();
106
107 if (!executable_path.empty()) {
108 // First check if we are running inside the Bazel tree and use the agent
109 // runfile.
110 using bazel::tools::cpp::runfiles::Runfiles;
111 std::string error;
112 std::unique_ptr<Runfiles> runfiles(Runfiles::Create(
113 std::string(executable_path), BAZEL_CURRENT_REPOSITORY, &error));
114 if (runfiles != nullptr) {
115 auto bazel_path = runfiles->Rlocation(kJazzerBazelRunfilesPath);
116 if (!bazel_path.empty() && std::ifstream(bazel_path).good())
117 return bazel_path;
118 }
119
120 // If the agent is not in the bazel path we look next to the jazzer binary.
121 const auto dir = dirFromFullPath(executable_path);
122 auto agent_path =
123 absl::StrFormat("%s%c%s", dir, kPathSeparator, kJazzerFileName);
124 if (std::ifstream(agent_path).good()) return agent_path;
125 }
126
127 std::cerr << "ERROR: Could not find " << kJazzerFileName
128 << ". Please provide the pathname via the --agent_path flag."
129 << std::endl;
130 exit(1);
131}
132
133// Splits a string at the ARG_SEPARATOR unless it is escaped with a backslash.
134// Backslash itself can be escaped with another backslash.

Callers 1

GetClassPathFunction · 0.85

Calls 2

getExecutablePathFunction · 0.85
dirFromFullPathFunction · 0.85

Tested by

no test coverage detected