Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring rizin type system: introduce type scope. #4464

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions librz/arch/dwarf_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ static bool RzBaseType_eq(const RzBaseType *a, const RzBaseType *b) {
if (a == NULL || b == NULL) {
return a == NULL && b == NULL;
}
if (a->scope.cu_name && b->scope.cu_name && RZ_STR_NE(a->scope.cu_name, b->scope.cu_name)) {
printf("types '%s' and '%s' are not equal\n", a->name, b->name);
return false;
}
return a->kind == b->kind && a->attrs == b->attrs && RZ_STR_EQ(a->name, b->name);
}

Expand Down Expand Up @@ -708,6 +712,11 @@ static RzBaseType *RzBaseType_from_die(DwContext *ctx, const RzBinDwarfDie *die)
return NULL;
}

if (ctx->unit->name) {
printf("storing cu_name: '%s'\n", ctx->unit->name);
btype->scope.cu_name = rz_str_dup(ctx->unit->name);
}

RzBinDwarfAttr *attr = NULL;
rz_vector_foreach (&die->attrs, attr) {
switch (attr->at) {
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ typedef struct {
HtUP /*<ut64, RzCallable *>*/ *callable_by_offset; ///< Store all callables parsed from DWARF by DIE offset
HtUP /*<ut64, RzType *>*/ *type_by_offset; ///< Store all RzType parsed from DWARF by DIE offset
HtUP /*<ut64, RzBaseType *>*/ *base_type_by_offset; ///< Store all RzBaseType parsed from DWARF by DIE offset
HtSP /*<const char*, RzPVector<const RzBaseType *>>*/ *base_types_by_name; ///< Store all RzBaseType parsed from DWARF by DIE offset
HtSP /*<const char*, RzPVector<const RzBaseType *>>*/ *base_types_by_name; ///< Store all RzBaseType parsed from DWARF by DIE name
DWARF_RegisterMapping dwarf_register_mapping; ///< Store the mapping function between DWARF registers number and register name in current architecture
RzBinDWARF *dw; ///< Holds ownership of RzBinDwarf, avoid releasing it prematurely
SetU *visited;
Expand Down
6 changes: 6 additions & 0 deletions librz/include/rz_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ typedef struct rz_type_db_t {
RzIOBind iob; // for RzIO in formats
} RzTypeDB;


typedef struct rz_type_scope_t {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Doxygen

char *cu_name;
} RzTypeScope;

// All types in RzTypeDB module are either concrete,
// "base" types that are types already having the
// concrete size and memory layout
Expand Down Expand Up @@ -114,6 +119,7 @@ typedef struct rz_base_type_t {
ut64 size; // size of the whole type in bits
RzBaseTypeKind kind;
RzTypeAttribute attrs;
RzTypeScope scope;
union {
RzBaseTypeStruct struct_data;
RzBaseTypeEnum enum_data;
Expand Down
Loading