refactor: rename Data to SymbolData.

This commit is contained in:
2025-02-10 00:16:13 +08:00
parent 3c9c63c0c7
commit a6365a05d4
5 changed files with 27 additions and 23 deletions

View File

@@ -11,7 +11,7 @@ using namespace llvm::pdb;
namespace makepdb::binary {
PDB::PDB(COFF&& COFF, Data&& SymbolData)
PDB::PDB(COFF&& COFF, SymbolData&& SymbolData)
: OwningCOFF(std::move(COFF)),
OwningSymbolData(std::move(SymbolData)),
Builder(Allocator) {
@@ -94,7 +94,7 @@ void PDB::BuildTPI() {
void PDB::BuildGSI() {
std::vector<BulkPublic> PublicsIn;
OwningSymbolData.forEach([&PublicsIn, this](const DataEntity& E) {
OwningSymbolData.forEach([&PublicsIn, this](const SymbolDataEntity& E) {
BulkPublic Symbol;
auto SectionIndex = OwningCOFF.SectionIndex(E.RVA - ImageBase);

View File

@@ -1,7 +1,7 @@
#pragma once
#include "binary/COFF.h"
#include "data.h"
#include "symbol_data.h"
#include <llvm/DebugInfo/PDB/Native/PDBFileBuilder.h>
#include <llvm/Support/Allocator.h>
@@ -10,7 +10,7 @@ namespace makepdb::binary {
class PDB {
public:
explicit PDB(COFF&& COFF, Data&& SymbolData);
explicit PDB(COFF&& COFF, SymbolData&& SymbolData);
void WriteTo(std::string_view Path);
@@ -22,8 +22,8 @@ private:
inline void BuildTPI();
inline void BuildGSI();
COFF OwningCOFF;
Data OwningSymbolData;
COFF OwningCOFF;
SymbolData OwningSymbolData;
uint64_t ImageBase;

View File

@@ -2,17 +2,19 @@
#include "binary/COFF.h"
#include "binary/PDB.h"
#include "data.h"
#include "symbol_data.h"
using namespace makepdb;
[[nodiscard]] auto load_args(int argc, char* argv[]) {
argparse::ArgumentParser program("makepdb", "1.0.0");
argparse::ArgumentParser program("makepdb", "1.1.0");
struct {
std::string server_program_path;
std::string data_path;
std::string symbol_data_path;
std::string typeinfo_pdb_path;
std::string output_path;
} args;
@@ -21,9 +23,9 @@ using namespace makepdb;
.store_into(args.server_program_path)
.required();
program.add_argument("--symbol-data")
program.add_argument("--symbol")
.help("Path to symbol data.")
.store_into(args.data_path)
.store_into(args.symbol_data_path)
.required();
program.add_argument("--output", "-o")
@@ -41,7 +43,7 @@ int main(int argc, char* argv[]) try {
auto args = load_args(argc, argv);
binary::COFF server_program(args.server_program_path);
Data symbol_data(args.data_path);
SymbolData symbol_data(args.symbol_data_path);
binary::PDB pdb(std::move(server_program), std::move(symbol_data));

View File

@@ -1,10 +1,10 @@
#include "data.h"
#include "symbol_data.h"
#include <nlohmann/json.hpp>
namespace makepdb {
Data::Data(std::string_view Path) {
SymbolData::SymbolData(std::string_view Path) {
std::ifstream IFS(Path.data());
if (!IFS) {
throw std::runtime_error("Failed to open data path.");
@@ -16,11 +16,13 @@ Data::Data(std::string_view Path) {
}
for (const auto& E : Data["data"]) {
Entities.emplace(DataEntity{E["symbol"], E["rva"], E["is_function"]});
Entities.emplace(
SymbolDataEntity{E["symbol"], E["rva"], E["is_function"]}
);
}
}
void Data::forEach(const std::function<void(DataEntity)> Callback) {
void SymbolData::forEach(const std::function<void(SymbolDataEntity)> Callback) {
for (const auto& E : Entities) Callback(E);
}

View File

@@ -2,18 +2,18 @@
namespace makepdb {
struct DataEntity {
struct SymbolDataEntity {
std::string SymbolName;
uint64_t RVA;
bool IsFunction;
bool operator==(const DataEntity& other) const {
bool operator==(const SymbolDataEntity& other) const {
return SymbolName == other.SymbolName && RVA == other.RVA
&& IsFunction == other.IsFunction;
}
struct H {
size_t operator()(const DataEntity E) const {
size_t operator()(const SymbolDataEntity E) const {
size_t h1 = std::hash<std::string>{}(E.SymbolName);
size_t h2 = std::hash<uint64_t>{}(E.RVA);
size_t h3 = std::hash<bool>{}(E.IsFunction);
@@ -22,14 +22,14 @@ struct DataEntity {
};
};
class Data {
class SymbolData {
public:
explicit Data(std::string_view Path);
explicit SymbolData(std::string_view Path);
void forEach(const std::function<void(DataEntity)> Callback);
void forEach(const std::function<void(SymbolDataEntity)> Callback);
private:
std::unordered_set<DataEntity, DataEntity::H> Entities;
std::unordered_set<SymbolDataEntity, SymbolDataEntity::H> Entities;
};
} // namespace makepdb