rizin/test/db/cmd/structures
Florian Märkl d9950f7479
Replace bp/sp-vars by generic stack-based ones (#3167)
Variables on the stack are not identified by bp/sp+<offset> anymore, but
by their address from the bottom of the stack frame (RzStackAddr),
independent of how they are accessed.
So now there are only two kinds of variables: stack and register.

This required some major refactoring and other changes:
* RzAnalysisVar.isarg was removed. Whether a variable is an argument is
  now specified implicitly by its storage location.
* Varsub of struct fields had to be rewritten so fields can be queried
  by arbitrary stack addresses using the recently introduced sp
  tracking, as the old approach to fill a list with all fields would not
  work anymore.
* analysis.vars.stackname was removed, new behavior is more similar to
  this being true before.
* Variables will not be created at stack+0 now, because the return
  address is there. Before, vars were only created sometimes in such
  cases.
* Variables created from bp offsets in x86 are not deleted anymore if
  the function's bp_frame is false (see removed
  rz_analysis_function_delete_vars_by_kind(fcn,
  RZ_ANALYSIS_VAR_KIND_BPV); calls). This may lead to some
  false-positive detected variables. Whether this really is a practical
  issue is yet to be seen. At least there are no meaningful tests that
  are broken by this.
* Applying variables from dwarf needed some fixes for determining the
  correct stack locations of variables in order to write meaningful
  tests. The handling is still not entirely correct for all
  possibilities of dwarf info, but at least the changed/added test cases
  are right and serve as a reference for future changes.
* Projects version 11 is introduced.
* afvb commands have been removed, afvs now handles all stack vars.
2023-01-02 11:36:21 +08:00

77 lines
1.5 KiB
Text

NAME=structure variable delete shadowed
FILE=bins/elf/analysis/main_structure
CMDS=<<EOF
aaa
s main
afvs*
?e ---
td "struct S1 { int a; int b; int c; char d[256]; short e; }"
afvn s1 var_118h
afvt s1 "struct S1"
afvs*
EOF
EXPECT=<<EOF
afvs -296 var_128h char ** @ 0x4004a6
afvs -284 var_11ch int @ 0x4004a6
afvs -280 var_118h int64_t @ 0x4004a6
afvs -276 var_114h int64_t @ 0x4004a6
afvs -272 var_110h int64_t @ 0x4004a6
afvs -12 var_ch int64_t @ 0x4004a6
---
afvs -296 var_128h char ** @ 0x4004a6
afvs -284 var_11ch int @ 0x4004a6
afvs -280 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_118h
pi 4 @ 0x004004be
?e ---
afvt s1 "struct S1"
pi 4 @ 0x004004be
EOF
EXPECT=<<EOF
mov dword [s1], 1
mov dword [var_114h], 2
mov dword [var_110h], 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_118h
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