check-structures-sanity: suggest known structure types for large unknown pointers

update structures
develop
Ben Lubar 2020-03-02 21:33:04 -06:00
parent 66ded03bc1
commit c29b606a4a
No known key found for this signature in database
GPG Key ID: 92939677AB59EDA4
2 changed files with 24 additions and 1 deletions

@ -1 +1 @@
Subproject commit fa22bd5c5a6ea6ffbd883aea5dfcd2bb18d76dcf
Subproject commit 614548ce67ef3d154297167ecacfd9b8c2d49875

@ -33,6 +33,10 @@ static command_result command(color_ostream &, std::vector<std::string> &);
#define UNEXPECTED __asm__ volatile ("int $0x03")
#endif
#define MIN_SIZE_FOR_SUGGEST 64
static std::map<size_t, std::vector<std::string>> known_types_by_size;
static void build_size_table();
DFhackCExport command_result plugin_init(color_ostream &, std::vector<PluginCommand> & commands)
{
commands.push_back(PluginCommand(
@ -51,9 +55,24 @@ DFhackCExport command_result plugin_init(color_ostream &, std::vector<PluginComm
"\n"
"by default, check-structures-sanity reports invalid pointers, vectors, strings, and vtables."
));
known_types_by_size.clear();
build_size_table();
return CR_OK;
}
static void build_size_table()
{
for (auto & ident : compound_identity::getTopScope())
{
if (ident->byte_size() >= MIN_SIZE_FOR_SUGGEST)
{
known_types_by_size[ident->byte_size()].push_back(ident->getFullName());
}
}
}
static const char *const *get_enum_item_key(enum_identity *identity, int64_t value)
{
size_t index;
@ -827,6 +846,10 @@ void Checker::check_dispatch(ToCheck & item)
item.path.push_back("");
item.identity = df::identity_traits<void *>::get();
}
else if (allocated_size >= MIN_SIZE_FOR_SUGGEST && known_types_by_size.count(allocated_size))
{
FAIL("known types of this size: " << join_strings(", ", known_types_by_size.at(allocated_size)));
}
}
#ifndef WIN32
else if (auto str = check_possible_stl_string_pointer(&item.ptr))