Fix tests

This commit is contained in:
pancake 2023-06-14 22:30:17 +02:00 committed by pancake
parent 510b792f36
commit 1d6ccf8a11
6 changed files with 141 additions and 44 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2017 - rkx1209 */
/* radare - LGPL - Copyright 2017-2023 - rkx1209 */
#include <r_debug.h>
#include <r_util/r_json.h>
@ -12,7 +12,7 @@ R_API void r_debug_session_free(RDebugSession *session) {
r_vector_free (session->checkpoints);
ht_up_free (session->registers);
ht_up_free (session->memory);
R_FREE (session);
free (session);
}
}
@ -593,7 +593,7 @@ static bool deserialize_checkpoints_cb(void *user, const char *cnum, const char
baby = r_json_get (child, "arena");
CHECK_TYPE (baby, R_JSON_INTEGER);
int arena = baby->num.s_value;
if (arena < R_REG_TYPE_GPR || arena > R_REG_TYPE_SEG) {
if (arena < 0 || arena >= R_REG_TYPE_LAST) {
continue;
}
baby = r_json_get (child, "size");

View File

@ -20,16 +20,16 @@ R_LIB_VERSION_HEADER (r_reg);
* this enum aims to cover them all.
*/
typedef enum {
R_REG_TYPE_GPR, // general purpose registers
R_REG_TYPE_GPR = 0, // general purpose registers
R_REG_TYPE_DRX, // debug register state
R_REG_TYPE_FPU, // floating point unit
R_REG_TYPE_PRI, // privileged registers
R_REG_TYPE_VEC64, // MMX
R_REG_TYPE_VEC128, // XMM
R_REG_TYPE_VEC256, // YMM
R_REG_TYPE_VEC512, // ZMM
R_REG_TYPE_FLG, // cpu flags
R_REG_TYPE_SEG, // segment registers
R_REG_TYPE_PRI, // privileged registers
R_REG_TYPE_LAST,
R_REG_TYPE_ALL = -1, // TODO; rename to ANY
} RRegisterType;

View File

@ -45,8 +45,8 @@ ara+
ara~?
EOF
EXPECT=<<EOF
18
27
20
30
EOF
RUN
@ -66,11 +66,11 @@ ara-
ara~?
EOF
EXPECT=<<EOF
18
27
18
9
9
20
30
20
10
10
EOF
RUN

View File

@ -89,33 +89,35 @@ EXPECT=<<EOF
Aliases (Reg->name)
0 PC rip
1 SP rsp
2 SR ?
3 BP rbp
4 LR ?
5 RS ?
6 A0 rdi
7 A1 rsi
8 A2 rdx
9 A3 rcx
10 A4 r8
11 A5 r9
12 A6 r10
13 A7 r11
14 A8 ?
15 A9 ?
16 R0 rax
17 R1 ?
18 R2 ?
19 R3 ?
20 F0 ?
21 F1 ?
22 F2 ?
23 F3 ?
24 ZF ?
25 SF ?
26 CF ?
27 OF ?
28 SN rax
2 GP ?
3 RA ?
4 SR ?
5 BP rbp
6 LR ?
7 RS ?
8 A0 rdi
9 A1 rsi
10 A2 rdx
11 A3 rcx
12 A4 r8
13 A5 r9
14 A6 r10
15 A7 r11
16 A8 ?
17 A9 ?
18 R0 rax
19 R1 ?
20 R2 ?
21 R3 ?
22 F0 ?
23 F1 ?
24 F2 ?
25 F3 ?
26 ZF ?
27 SF ?
28 CF ?
29 OF ?
30 SN rax
regset 0 (gpr)
* arena gpr size 160
rax gpr @ gpr (offset: 80 size: 8)
@ -270,6 +272,8 @@ regset 8 (seg)
es seg @ seg (offset: 192 size: 8)
fs seg @ seg (offset: 200 size: 8)
gs seg @ seg (offset: 208 size: 8)
regset 9 ((null))
* arena (null) size 1
EOF
RUN
@ -326,15 +330,107 @@ e asm.bits=64
arps
arp scripts/badrp2.r2
arps
?e --
arp
?e --regs
ar=
?e --
-a x86
-b 32
arps
ar=
ar rax
EOF
EXPECT=<<EOF
160
1
--
--regs
--
64
oeax 0x00000000 eax 0x00000000 ebx 0x00000000 ecx 0x00000000
edx 0x00000000 esi 0x00000000 edi 0x00000000 esp 0x00000000
ebp 0x00000000 eip 0x00000000 eflags 0x00000000
bl = 0x00000000
bx = 0x00000000
ebx = 0x00000000
dr0 = 0x00000000
bh = 0x00000000
cl = 0x00000000
cx = 0x00000000
ecx = 0x00000000
dr1 = 0x00000000
ch = 0x00000000
dl = 0x00000000
dx = 0x00000000
edx = 0x00000000
dr2 = 0x00000000
dh = 0x00000000
si = 0x00000000
esi = 0x00000000
dr3 = 0x00000000
di = 0x00000000
edi = 0x00000000
bp = 0x00000000
ebp = 0x00000000
al = 0x00000000
ax = 0x00000000
eax = 0x00000000
dr6 = 0x00000000
ah = 0x00000000
dr7 = 0x00000000
xfs = 0x00000000
xgs = 0x00000000
oeax = 0x00000000
ip = 0x00000000
eip = 0x00000000
cs = 0x00000000
xcs = 0x00000000
xss = 0x00000000
cf = 0x00000000
flags = 0x00000000
eflags = 0x00000000
pf = 0x00000000
af = 0x00000000
zf = 0x00000000
sf = 0x00000000
tf = 0x00000000
if = 0x00000000
df = 0x00000000
of = 0x00000000
nt = 0x00000000
rf = 0x00000000
vm = 0x00000000
sp = 0x00000000
esp = 0x00000000
xmm0l = 0x00000000
xmm0 = 0x00000000000000000000000000000000
xmm0h = 0x00000000
xmm1l = 0x00000000
xmm1 = 0x00000000000000000000000000000000
xmm1h = 0x00000000
xmm2l = 0x00000000
xmm2 = 0x00000000000000000000000000000000
xmm2h = 0x00000000
xmm3l = 0x00000000
xmm3 = 0x00000000000000000000000000000000
xmm3h = 0x00000000
xmm4l = 0x00000000
xmm4 = 0x00000000000000000000000000000000
xmm4h = 0x00000000
vec1285l = 0x00000000
xmm5 = 0x00000000000000000000000000000000
vec1285h = 0x00000000
vec1286l = 0x00000000
xmm6 = 0x00000000000000000000000000000000
vec1286h = 0x00000000
xmm7l = 0x00000000
xmm7 = 0x00000000000000000000000000000000
xmm7h = 0x00000000
EOF
EXPECT_ERR=<<EOF
ERROR: Parse error @ line 3 (Invalid syntax: Wrong number of columns)
ERROR: No register profile defined. Try 'dr.'
EOF
RUN

View File

@ -26,7 +26,8 @@ static Sdb *ref_db() {
"{\"arena\":5,\"bytes\":\"BQUFBQUFBQUFBQUFBQUFBQ==\",\"size\":16},"
"{\"arena\":6,\"bytes\":\"BgYGBgYGBgYGBgYGBgYGBg==\",\"size\":16},"
"{\"arena\":7,\"bytes\":\"BwcHBwcHBwcHBwcHBwcHBw==\",\"size\":16},"
"{\"arena\":8,\"bytes\":\"CAgICAgICAgICAgICAgICA==\",\"size\":16}"
"{\"arena\":8,\"bytes\":\"CAgICAgICAgICAgICAgICA==\",\"size\":16},"
"{\"arena\":9,\"bytes\":\"CQkJCQkJCQkJCQkJCQkJCQ==\",\"size\":16}"
"],"
"\"snaps\":["
"{\"name\":\"[stack]\",\"addr\":8796092882944,\"addr_end\":8796092883200,\"size\":256,\"data\":\"8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8A==\",\"perm\":7,\"user\":0,\"shared\":true}"
@ -83,7 +84,7 @@ static RDebugSession *ref_session() {
static void diff_cb(const SdbDiff *diff, void *user) {
char buf[2048];
if (sdb_diff_format (buf, sizeof(buf), diff) < 0) {
if (sdb_diff_format (buf, sizeof (buf), diff) < 0) {
return;
}
printf ("%s\n", buf);

View File

@ -178,15 +178,15 @@ bool test_r_reg_get_list(void) {
bool success = r_reg_set_profile_string (reg,
"gpr eax .32 24 0\n\
fpu sf0 .32 304 0\n\
vec128@fpu xmm0 .64 160 4");
vec128 xmm0 .64 160 4");
mu_assert_eq (success, true, "define eax, sf0 and xmm0 register");
mask = ((int)1 << R_REG_TYPE_VEC128);
mu_assert_eq ((reg->regset[R_REG_TYPE_FPU].maskregstype & mask), mask,
mu_assert_eq ((reg->regset[R_REG_TYPE_VEC128].maskregstype & mask), mask,
"xmm0 stored as R_REG_TYPE_FPU");
l = r_reg_get_list (reg, R_REG_TYPE_VEC128);
mu_assert_eq (r_list_length (l), 2, "sf0 and xmm0 stored as R_REG_TYPE_FPU");
mu_assert_eq (r_list_length (l), 1, "sf0 and xmm0 stored as R_REG_TYPE_FPU");
r_reg_free (reg);
mu_end;