add integer type checking function
This commit is contained in:
parent
c436f755c9
commit
3f4396689e
58
src/symbol.cpp
Normal file
58
src/symbol.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "symbol.hpp"
|
||||
#include <cstring>
|
||||
#include <dwarf.h>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <libdwarf.h>
|
||||
|
||||
bool Symbol::is_integer_type(Dwarf_Debug dbg, Dwarf_Die die) {
|
||||
Dwarf_Error err;
|
||||
Dwarf_Attribute type_attr;
|
||||
Dwarf_Off type_offset;
|
||||
Dwarf_Die type_die;
|
||||
Dwarf_Half tag;
|
||||
|
||||
// Get the type attribute
|
||||
if (dwarf_attr(die, DW_AT_type, &type_attr, &err) != DW_DLV_OK)
|
||||
return false;
|
||||
|
||||
// Get the type offset
|
||||
if (dwarf_global_formref(type_attr, &type_offset, &err) != DW_DLV_OK) {
|
||||
dwarf_dealloc(dbg, type_attr, DW_DLA_ATTR);
|
||||
return false;
|
||||
}
|
||||
|
||||
dwarf_dealloc(dbg, type_attr, DW_DLA_ATTR);
|
||||
|
||||
// Get the type DIE
|
||||
if (dwarf_offdie_b(dbg, type_offset, true, &type_die, &err) != DW_DLV_OK)
|
||||
return false;
|
||||
|
||||
// Get the tag of the type DIE
|
||||
if (dwarf_tag(type_die, &tag, &err) != DW_DLV_OK) {
|
||||
dwarf_dealloc(dbg, type_die, DW_DLA_DIE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if it's a base type (integer types are base types)
|
||||
if (tag != DW_TAG_base_type) {
|
||||
dwarf_dealloc(dbg, type_die, DW_DLA_DIE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the base type name to verify it's an integer type
|
||||
char *type_name = nullptr;
|
||||
bool is_integer = false;
|
||||
|
||||
if (dwarf_diename(type_die, &type_name, &err) == DW_DLV_OK && type_name) {
|
||||
std::string name(type_name);
|
||||
dwarf_dealloc(dbg, type_name, DW_DLA_STRING);
|
||||
|
||||
// Check for common integer type names
|
||||
is_integer = (name.find("int") != std::string::npos ||
|
||||
name.find("char") != std::string::npos);
|
||||
}
|
||||
|
||||
dwarf_dealloc(dbg, type_die, DW_DLA_DIE);
|
||||
return is_integer;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user