mem tool handles (#835)

This commit is contained in:
water111
2021-09-06 20:28:54 -04:00
committed by GitHub
parent 7099a1964e
commit c53f778ab0
2 changed files with 59 additions and 0 deletions
+3
View File
@@ -374,6 +374,9 @@ TEST_F(WithGameTests, GameCount) {
shared_compiler->compiler.run_test_from_string("(dgo-load \"game\" global #xf #x200000)");
shared_compiler->runner.run_static_test(env, testCategory, "test-game-count.gc",
get_test_pass_string("game-count", 4));
// don't leave behind a weird version of the game-count file.
std::filesystem::remove(file_util::get_file_path({"out", "iso", "GAME.CGO"}));
std::filesystem::remove(file_util::get_file_path({"out", "obj", "game-cnt.go"}));
}
TEST_F(WithGameTests, BitFieldAccess) {
+56
View File
@@ -451,6 +451,62 @@ void inspect_basics(const Ram& ram,
fmt::print(" [{}] {}\n", type_frequency.at(field_type), field_type);
}
type_results[field.name()] = field_results;
} else if (field.type().base_type() == "handle" && !field.is_array()) {
// check the types of handles.
// auto proc_type = type_system.lookup_type("process");
std::unordered_map<std::string, int> type_frequency;
fmt::print(" field {}\n", field.name());
for (auto base_addr : basics.at(name)) {
int field_addr = base_addr + field.offset();
if (ram.word_in_memory(field_addr)) {
auto proc_pointer = ram.word(field_addr); // pointer process
auto pid = ram.word(field_addr + 4);
if (ram.word_in_memory(proc_pointer)) {
auto proc = ram.word(proc_pointer);
auto proc_type_tag_addr = proc - 4;
if (ram.word_in_memory(proc_type_tag_addr)) {
auto type_tag_value = ram.word(proc_type_tag_addr);
auto type_it = types.find(type_tag_value);
if (type_it != types.end()) {
if (type_it->second == "symbol") {
auto sym_iter = symbols.addr_to_name.find(proc);
if (sym_iter != symbols.addr_to_name.end()) {
type_frequency[fmt::format("(symbol {})", sym_iter->second)]++;
}
} else {
type_frequency[type_it->second]++;
}
}
}
}
}
}
std::vector<std::string> sorted_field_types;
for (const auto& x : type_frequency) {
sorted_field_types.push_back(x.first);
}
std::sort(sorted_field_types.begin(), sorted_field_types.end(),
[&](const auto& a, const auto& b) {
return type_frequency.at(a) > type_frequency.at(b);
});
nlohmann::json field_results;
if (type_results.contains(field.name())) {
field_results = type_results.at(field.name());
} else {
field_results = {};
}
for (const auto& field_type : sorted_field_types) {
int freq = type_frequency.at(field_type);
if (field_results.contains(field_type)) {
field_results[field_type] = field_results[field_type].get<int>() + freq;
} else {
field_results[field_type] = freq;
}
fmt::print(" [{}] {} (handle)\n", type_frequency.at(field_type), field_type);
}
type_results[field.name()] = field_results;
}
}