2022-12-19 14:37:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <variant>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-04-26 16:20:53 +01:00
|
|
|
#include "oi/Common.h"
|
|
|
|
#include "oi/Descs.h"
|
2022-12-19 14:37:51 +00:00
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
2023-04-13 18:58:35 +01:00
|
|
|
struct Dwfl;
|
2022-12-19 14:37:51 +00:00
|
|
|
struct drgn_program;
|
|
|
|
struct irequest;
|
|
|
|
|
|
|
|
struct SymbolInfo {
|
|
|
|
uint64_t addr;
|
|
|
|
uint64_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SymbolService {
|
|
|
|
public:
|
2023-04-13 18:58:35 +01:00
|
|
|
SymbolService(pid_t);
|
|
|
|
SymbolService(fs::path);
|
|
|
|
SymbolService(const SymbolService&) = delete;
|
|
|
|
SymbolService& operator=(const SymbolService&) = delete;
|
2022-12-19 14:37:51 +00:00
|
|
|
~SymbolService();
|
|
|
|
|
2023-03-22 16:16:17 +00:00
|
|
|
struct drgn_program* getDrgnProgram();
|
2022-12-19 14:37:51 +00:00
|
|
|
|
|
|
|
std::optional<std::string> locateBuildID();
|
2023-03-22 16:16:17 +00:00
|
|
|
std::optional<SymbolInfo> locateSymbol(const std::string&,
|
2023-01-25 14:37:16 +00:00
|
|
|
bool demangle = false);
|
2022-12-19 14:37:51 +00:00
|
|
|
|
2023-03-22 16:16:17 +00:00
|
|
|
std::shared_ptr<FuncDesc> findFuncDesc(const irequest&);
|
|
|
|
std::shared_ptr<GlobalDesc> findGlobalDesc(const std::string&);
|
|
|
|
static std::string getTypeName(struct drgn_type*);
|
|
|
|
std::optional<RootInfo> getRootType(const irequest&);
|
2022-12-19 14:37:51 +00:00
|
|
|
|
|
|
|
std::unordered_map<std::string, std::shared_ptr<FuncDesc>> funcDescs;
|
|
|
|
std::unordered_map<std::string, std::shared_ptr<GlobalDesc>> globalDescs;
|
|
|
|
|
|
|
|
void setHardDisableDrgn(bool val) {
|
|
|
|
hardDisableDrgn = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-04-13 18:58:35 +01:00
|
|
|
std::variant<pid_t, fs::path> target;
|
|
|
|
struct Dwfl* dwfl{nullptr};
|
2023-03-22 16:16:17 +00:00
|
|
|
struct drgn_program* prog{nullptr};
|
2022-12-19 14:37:51 +00:00
|
|
|
|
2023-04-13 18:58:35 +01:00
|
|
|
bool loadModules();
|
|
|
|
bool loadModulesFromPid(pid_t);
|
|
|
|
bool loadModulesFromPath(const fs::path&);
|
|
|
|
|
2022-12-19 14:37:51 +00:00
|
|
|
std::vector<std::pair<uint64_t, uint64_t>> executableAddrs{};
|
|
|
|
bool hardDisableDrgn = false;
|
|
|
|
};
|