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

Conversation

rockrid3r
Copy link
Contributor

@rockrid3r rockrid3r commented Apr 27, 2024

Addresses #4421 .

  • Introduce RzTypeScope.
  • Make the *_by_offset hashtables in dwarf_process.c being attached to 1 compilation unit: allocate at the beginning, free before the end of processing current CU.
  • Change implementation of "by name" type requests.
  • Refactor API usage of "by name" type requests.
  • Additional API

Introduce RzTypeScope

Should be a tree-like independent structure like this:

┌──────┐                                          
│ src  │                                          
└──┬───┘                                          
   │     ┌────────┐                               
   ├─────┤ headers│                               
   │     └───┬────┘                               
   │         │         ┌►struct A;                
   │         └►inc.h───┤                          
   │                   └►enum E;                  
   │     ┌────────┐                               
   └─────┤  src   │                               
         └───┬────┘                               
             │                                    
             │   ┌────────┐                       
             ├───┤   a    │                       
             │   └───┬────┘                       
             │       └───► a.c───►struct A;       
             │                                    
             ├──► b.c─┬─►struct B;                
             │        │                           
             │        └─►typedef struct B A;      
             │                                    
             └──► c.c (includes headers/inc.h)    
                   │                              
                   ├───► struct A; (headers/inc.h)
                   │                              
                   └───► enum E; (headers/inc.h)  

Change API implementation of "by name" type requests.

  • rz_type_db_get_base_type
  • rz_type_db_get_compound_type
  • rz_type_db_save_base_type
  • rz_type_db_update_base_type
  • rz_type_db_delete_base_type
  • rz_type_db_get_base_types_of_kind
  • rz_type_db_get_base_types
  • rz_type_db_edit_base_type
  • rz_type_db_base_type_unwrap_typedef

Refactor API usage of "by name" type requests.

typedb->types usage:

  • base.c
  • serialize_types.c
  • type.c
  • typeclass.c
  • c_cpp_parser.c
  • test_type.c

rz_type_db.*base_type usage:

  • dwarf_process.c
  • pdb_process.c
  • cpdb.c
  • ctypes.c
  • base.c
  • format.c
  • helpers.c
  • path.c
  • type.c
  • typeclass.c
  • test_dwarf_integration.c
  • test_pdb.c
  • test_project_migrate.c
  • test_analysis_function.c
  • test_serialize_types.c
  • test_type.c

Additional API

  • get all types for the given scope
  • remove all types for the given scope

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the rizin book with the relevant information (if needed)

Detailed description

...

Test plan

...

Closing issues

...

Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

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

You will need to extract CU/scope from PDB too

@@ -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

@XVilka XVilka added this to the 0.8.0 milestone Apr 27, 2024
@XVilka XVilka added the RzType label Apr 27, 2024
rz_vector_foreach (&dw->info->units, unit) {
debug_info->type_by_offset = ht_up_new(NULL, (HtUPFreeValue)rz_type_free);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit awkward here.

Copy link
Contributor Author

@rockrid3r rockrid3r Apr 29, 2024

Choose a reason for hiding this comment

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

Kind of. But there is no need to have it until the rizin shuts down.

  • it is not used anywhere except dwarf_process.c.
  • we have copy of all types in typedb->types.

so it just takes RAM for nothing.
The same for debug_info->base_type_by_offset and debug_info->base_types_by_name.

@rockrid3r
Copy link
Contributor Author

rockrid3r commented Apr 30, 2024

The way scope is defined right now is wrong.

Firstly, it uses the RzBinDwarfCompUnit->name, which is basically filename of CU, not the place where struct was defined (struct may be included).

Secondly, we want the RzTypeScope to be an independent tree-like structure. And RzBaseType should contain pointers to it's nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants