| 197 | } |
| 198 | |
| 199 | uint64_t getSymbolAddress(const char* symbol, const char* file) |
| 200 | { |
| 201 | static std::string symbol_file; |
| 202 | static std::map<std::string, uint64_t> symbol_addresses; |
| 203 | |
| 204 | if (symbol_file.compare(file) != 0) { |
| 205 | symbol_file = file; |
| 206 | symbol_addresses.clear(); |
| 207 | |
| 208 | std::ostringstream cmd; |
| 209 | cmd << "readelf -Ws \"" << file << "\" | awk '{print $2 " " $8}'"; |
| 210 | |
| 211 | std::string outputstr; |
| 212 | FILE *output = popen(cmd.str().c_str(), "r"); |
| 213 | if (output != NULL) { |
| 214 | char buf[256]; |
| 215 | while (fgets(buf, 256, output) != nullptr) { |
| 216 | std::istringstream iss(buf); |
| 217 | uint64_t addr; |
| 218 | std::string sym; |
| 219 | iss >> std::hex >> addr >> sym; |
| 220 | symbol_addresses[sym] = addr; |
| 221 | } |
| 222 | pclose(output); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | auto search = symbol_addresses.find(std::string(symbol)); |
| 227 | if (search != symbol_addresses.end()) |
| 228 | return search->second; |
| 229 | |
| 230 | return 0; |
| 231 | } |
no test coverage detected