rizin/test/db/cmd/structures
Anton Kochkov 3c59df7e98
Refactor RzTypes to use structs instead of SDB + New Tree-Sitter based C Parser (#1047)
- Removed oldshell version of `t` (types) commands
- Removed `tk` command because types storage switched to the hashtable
- Added `tfc` command to show the calling convention of the function or set it
- Added `tsl` (RZ_OUTPUT_MODE_LONG) to show structure members' sizes and offsets
- Added `tul` (RZ_OUTPUT_MODE_LONG) to show union members' sizes
- Switched the types storage to the hashtable instead of SDB
- Added load and export from/to SDB for standard type libraries and serialization for Projects
- Changed all `char *type` occurences to the proper `RzType`
- Added `RzCallable` type for the function/class method types
- Changed all function types API to use the `RzCallable` API
- Switched the function types (`RzCallable`) storage to the hashtable instead of SDB
- Added a connection between `RzAnalysisFunction` and `RzCallable` - `rz_analysis_function_derive_type()` API function to derive new `RzCallable` type from the `RzAnalysisFunction` even if it doesn't exist in the RzTypeDB.
- Moved type links to the RzAnalysis where they belong
- Removed TCC and MPC-based parsers
- Added Tree-Sitter-based parser for C grammar (see `librz/type/parser/*`)
- Reworked type databases in `librz/analysis/d/` to be consistent with C standard, libc, platform-specific definitions
- Switched the type links from `char *` to `RzType`
- Switched the type links from SDB to the hashtable
- Added concept of the "type paths", e.g. `a.b[20].c` where `b` is a member of `a` (`a` is either structure or a union) and `c` is a member of `b`, and `b` is an array where we take 20-th element.
- Added concept of the typeclasses (a bit similar to Haskell) for numerical types: `None` (the most generic one), `Num` (includes `Integral` and `Floating`), `Integral` (includes `Signed Integral` and `Unsigned Integral`), `Floating`.
- Added concept of type equality (`rz_types_equal(a, b)` API function)
- Added Doxygen documentation to every API function in the `librz/type/*`.
- Updated the project format from **V2** to **V3**, added migration.
2021-07-20 01:46:45 +08:00

77 lines
1.5 KiB
Text

NAME=structure variable delete shadowed
FILE=bins/elf/analysis/main_structure
CMDS=<<EOF
aaa
s main
afvb*
?e ---
td "struct S1 { int a; int b; int c; char d[256]; short e; }"
afvn s1 var_110h
afvt s1 "struct S1"
afvb*
EOF
EXPECT=<<EOF
afvb -288 var_120h char ** @ 0x4004a6
afvb -276 var_114h int @ 0x4004a6
afvb -272 var_110h int64_t @ 0x4004a6
afvb -268 var_10ch int64_t @ 0x4004a6
afvb -264 var_108h int64_t @ 0x4004a6
afvb -4 var_4h int64_t @ 0x4004a6
---
afvb -288 var_120h char ** @ 0x4004a6
afvb -276 var_114h int @ 0x4004a6
afvb -272 s1 struct S1 @ 0x4004a6
EOF
RUN
NAME=structure offset in disassembly
FILE=bins/elf/analysis/main_structure
CMDS=<<EOF
e asm.bytes=false
aaa
s main
td "struct S1 { int a; int b; int c; char d[256]; short e; }"
afvn s1 var_110h
pi 4 @ 0x004004be
?e ---
afvt s1 "struct S1"
pi 4 @ 0x004004be
EOF
EXPECT=<<EOF
mov dword [s1], 1
mov dword [var_10ch], 2
mov dword [var_108h], 3
lea rax, [s1]
---
mov dword [s1.a], 1
mov dword [s1.b], 2
mov dword [s1.c], 3
lea rax, [s1.a]
EOF
RUN
NAME=structure field rename reflects immediately
FILE=bins/elf/analysis/main_structure
CMDS=<<EOF
e asm.bytes=true
aaa
s main
td "struct S1 { int a; int b; int c; char d[256]; short e; }"
afvn s1 var_110h
afvt s1 "struct S1"
pi 4 @ 0x004004be
t- S1
td "struct S1 { int x; int y; int c; char d[256]; short e; }"
pi 4 @ 0x004004be
EOF
EXPECT=<<EOF
mov dword [s1.a], 1
mov dword [s1.b], 2
mov dword [s1.c], 3
lea rax, [s1.a]
mov dword [s1.x], 1
mov dword [s1.y], 2
mov dword [s1.c], 3
lea rax, [s1.x]
EOF
RUN