Restored metadata file naming
This commit is contained in:
parent
273bf2e461
commit
1b8814ce0b
@ -6,6 +6,10 @@ void set_meta_dir(const char* dir);
|
|||||||
bool has_meta_dir();
|
bool has_meta_dir();
|
||||||
const char* get_meta_dir();
|
const char* get_meta_dir();
|
||||||
|
|
||||||
|
void set_srcroot_dir(const char* dir);
|
||||||
|
bool has_srcroot_dir();
|
||||||
|
const char* get_srcroot_dir();
|
||||||
|
|
||||||
bool init_src_file();
|
bool init_src_file();
|
||||||
const char* get_src_file();
|
const char* get_src_file();
|
||||||
|
|
||||||
|
|||||||
@ -14,17 +14,37 @@
|
|||||||
|
|
||||||
static std::string src_file, cu_hash;
|
static std::string src_file, cu_hash;
|
||||||
|
|
||||||
static bool meta_dir_known = false;
|
static bool meta_dir_known = false, srcroot_dir_known = false;
|
||||||
static std::string meta_dir;
|
static std::string meta_dir, srcroot_dir;
|
||||||
|
|
||||||
bool init_src_file() {
|
bool init_src_file() {
|
||||||
if (!main_input_filename)
|
if (!main_input_filename || !has_srcroot_dir())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::filesystem::path srcp = std::filesystem::weakly_canonical(
|
namespace fs = std::filesystem;
|
||||||
std::filesystem::absolute(main_input_filename)
|
|
||||||
);
|
// Canonicalize both paths (robust against symlinks, ../, etc.)
|
||||||
src_file = srcp.string();
|
fs::path src_abs = fs::weakly_canonical(fs::absolute(main_input_filename));
|
||||||
|
fs::path root_abs = fs::weakly_canonical(fs::absolute(get_srcroot_dir()));
|
||||||
|
|
||||||
|
// Ensure src_abs is actually inside root_abs
|
||||||
|
auto src_it = src_abs.begin();
|
||||||
|
auto root_it = root_abs.begin();
|
||||||
|
|
||||||
|
for (; root_it != root_abs.end(); ++root_it, ++src_it) {
|
||||||
|
if (src_it == src_abs.end() || *src_it != *root_it) {
|
||||||
|
// Not under srcroot
|
||||||
|
std::cerr << "The source file " << src_abs << " is not under source root " << root_abs << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute relative path
|
||||||
|
fs::path rel = fs::relative(src_abs, root_abs);
|
||||||
|
|
||||||
|
// Normalize to forward slashes (important for metadata consistency)
|
||||||
|
src_file = rel.generic_string();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +90,27 @@ const char* get_meta_dir() {
|
|||||||
return meta_dir.c_str();
|
return meta_dir.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_srcroot_dir(const char* dir) {
|
||||||
|
if (!dir) {
|
||||||
|
srcroot_dir_known = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
srcroot_dir = std::string{ dir };
|
||||||
|
srcroot_dir_known = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has_srcroot_dir() {
|
||||||
|
return srcroot_dir_known;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* get_srcroot_dir() {
|
||||||
|
if (!srcroot_dir_known)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return srcroot_dir.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
static void emit_dpin_alias_labels() {
|
static void emit_dpin_alias_labels() {
|
||||||
for (const DataPin& dpin : DataPin::all()) {
|
for (const DataPin& dpin : DataPin::all()) {
|
||||||
if (dpin.pin_symbol.empty() || dpin.symbol.empty())
|
if (dpin.pin_symbol.empty() || dpin.symbol.empty())
|
||||||
@ -82,13 +123,15 @@ static void emit_dpin_alias_labels() {
|
|||||||
|
|
||||||
static std::ofstream open_spslr_output_file() {
|
static std::ofstream open_spslr_output_file() {
|
||||||
std::filesystem::path metadir { get_meta_dir() };
|
std::filesystem::path metadir { get_meta_dir() };
|
||||||
std::filesystem::path metafile { std::string{ get_cu_hash() } + SPSLR_PINFILE_EXTENSION };
|
std::filesystem::path metafile { std::string{ get_src_file() } + SPSLR_PINFILE_EXTENSION };
|
||||||
|
|
||||||
std::filesystem::create_directories(metadir);
|
std::filesystem::path op = metadir / metafile;
|
||||||
|
|
||||||
std::cout << "Dumping meta data to " << (metadir / metafile) << std::endl;
|
std::filesystem::create_directories(op.parent_path());
|
||||||
|
|
||||||
std::ofstream out(metadir / metafile);
|
std::cout << "Dumping meta data to " << op << std::endl;
|
||||||
|
|
||||||
|
std::ofstream out(op);
|
||||||
if (!out)
|
if (!out)
|
||||||
pinpoint_fatal("open_spslr_output_file failed to open spslr dump file");
|
pinpoint_fatal("open_spslr_output_file failed to open spslr dump file");
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@ int plugin_init(struct plugin_name_args* plugin_info, struct plugin_gcc_version*
|
|||||||
for (int i = 0; i < plugin_info->argc; ++i) {
|
for (int i = 0; i < plugin_info->argc; ++i) {
|
||||||
if (!strcmp(plugin_info->argv[i].key, "metadir"))
|
if (!strcmp(plugin_info->argv[i].key, "metadir"))
|
||||||
set_meta_dir(plugin_info->argv[i].value);
|
set_meta_dir(plugin_info->argv[i].value);
|
||||||
|
else if (!strcmp(plugin_info->argv[i].key, "srcroot"))
|
||||||
|
set_srcroot_dir(plugin_info->argv[i].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has_meta_dir()) {
|
if (!has_meta_dir()) {
|
||||||
@ -26,6 +28,11 @@ int plugin_init(struct plugin_name_args* plugin_info, struct plugin_gcc_version*
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!has_srcroot_dir()) {
|
||||||
|
std::cerr << "spslr_pinpoint -> missing source root directory argument" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Stage 0 -> separates relevant field offsets into function calls
|
// Stage 0 -> separates relevant field offsets into function calls
|
||||||
|
|
||||||
register_callback(plugin_info->base_name, PLUGIN_START_UNIT, on_start_unit, NULL);
|
register_callback(plugin_info->base_name, PLUGIN_START_UNIT, on_start_unit, NULL);
|
||||||
|
|||||||
@ -3,6 +3,7 @@ target_include_directories(subject PRIVATE .)
|
|||||||
add_dependencies(subject spslr_pinpoint spslr_finalize spslr_selfpatch)
|
add_dependencies(subject spslr_pinpoint spslr_finalize spslr_selfpatch)
|
||||||
target_link_libraries(subject PRIVATE spslr_selfpatch)
|
target_link_libraries(subject PRIVATE spslr_selfpatch)
|
||||||
target_compile_options(subject PRIVATE -O1 -fplugin=$<TARGET_FILE:spslr_pinpoint> -fdump-tree-separate_offset -fdump-tree-asm_offset
|
target_compile_options(subject PRIVATE -O1 -fplugin=$<TARGET_FILE:spslr_pinpoint> -fdump-tree-separate_offset -fdump-tree-asm_offset
|
||||||
|
-fplugin-arg-spslr_pinpoint-srcroot=${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
-fplugin-arg-spslr_pinpoint-metadir=${CMAKE_CURRENT_BINARY_DIR}/spslr)
|
-fplugin-arg-spslr_pinpoint-metadir=${CMAKE_CURRENT_BINARY_DIR}/spslr)
|
||||||
|
|
||||||
# Apply spslr_finalizer to subject
|
# Apply spslr_finalizer to subject
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user