NAME=dbg.maps.count/
FILE=bins/elf/analysis/elf-nx
ARGS=-d
CMDS=<<EOF
dm~?/
EOF
EXPECT=<<EOF
6
EOF
RUN

NAME=dbg.maps
FILE=bins/elf/analysis/elf-nx
ARGS=-d
CMDS=<<EOF
. scripts/map_clean.rz
dm~?
.(dm_clean)
EOF
EXPECT=<<EOF
10
0x08048000 - 0x08049000 - usr     4K s r-x .../rizin/test/bins/elf/analysis/elf-nx .../rizin/test/bins/elf/analysis/elf-nx ; ..._rizin_test_bins_elf_analysis_elf_nx.r_x
0x08049000 - 0x0804a000 - usr     4K s rw- .../rizin/test/bins/elf/analysis/elf-nx .../rizin/test/bins/elf/analysis/elf-nx ; ..._rizin_test_bins_elf_analysis_elf_nx.rw
0x________ - 0x________ - usr     _K s r-- [vvar] [vvar] ; vvar_.r
0x________ - 0x________ - usr     8K s r-- [vvar_vclock] [vvar_vclock] ; vvar_vclock_.r
0x________ - 0x________ - usr     _K s r-x [vdso] [vdso] ; vdso_.r_x
0x________ - 0x________ - usr     4K s r-- /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.r
0x________ - 0x________ * usr   140K s r-x /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.r_x
0x________ - 0x________ - usr    56K s r-- /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.r.________
0x________ - 0x________ - usr    12K s rw- /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.rw
0x________ - 0x________ - usr   1__K s rw- [stack] [stack] ; stack_.rw
EOF
RUN

NAME=debug map flags
FILE=bins/elf/analysis/elf-nx
ARGS=-d
CMDS=<<EOF
. scripts/map_clean.rz
fl@F:maps~?
.(fl_F_maps_clean)
EOF
EXPECT=<<EOF
10
0x08048000 4096 ..._rizin_test_bins_elf_analysis_elf_nx.r_x
0x08049000 4096 ..._rizin_test_bins_elf_analysis_elf_nx.rw
0x________ ____ vvar_.r
0x________ 8192 vvar_vclock_.r
0x________ ____ vdso_.r_x
0x________ 4096 usr_lib32_ld_linux.so.2.r
0x________ 143360 usr_lib32_ld_linux.so.2.r_x
0x________ 57344 usr_lib32_ld_linux.so.2.r.________
0x________ 12288 usr_lib32_ld_linux.so.2.rw
0x________ 1_____ stack_.rw
EOF
RUN

NAME=dbg.maps.count.after.map
FILE=bins/elf/analysis/x86-helloworld-gcc
ARGS=-d
CMDS=<<EOF
. scripts/map_clean.rz
dm~?
db @ sym.imp.puts
dc~?
echo ----
$dm=%b64- `dm | base64 -w 0`
$dm~?
.(dm_cmd_clean $dm)
echo ----
dc
EOF
EXPECT=<<EOF
10
0
----
18
0x08048000 - 0x08049000 * usr     4K s r-x .../rizin/test/bins/elf/analysis/x86-helloworld-gcc .../rizin/test/bins/elf/analysis/x86-helloworld-gcc ; ..._rizin_test_bins_elf_analysis_x86_helloworld_gcc.r_x
0x08049000 - 0x0804a000 - usr     4K s rw- .../rizin/test/bins/elf/analysis/x86-helloworld-gcc .../rizin/test/bins/elf/analysis/x86-helloworld-gcc ; ..._rizin_test_bins_elf_analysis_x86_helloworld_gcc.rw
0x________ - 0x________ - usr   140K s r-- /usr/lib32/libc.so.6 /usr/lib32/libc.so.6
0x________ - 0x________ - usr   1.5M s r-x /usr/lib32/libc.so.6 /usr/lib32/libc.so.6
0x________ - 0x________ - usr   532K s r-- /usr/lib32/libc.so.6 /usr/lib32/libc.so.6
0x________ - 0x________ - usr     8K s r-- /usr/lib32/libc.so.6 /usr/lib32/libc.so.6
0x________ - 0x________ - usr     4K s rw- /usr/lib32/libc.so.6 /usr/lib32/libc.so.6
0x________ - 0x________ - usr    40K s rw- unk0 unk0
0x________ - 0x________ - usr     8K s rw- unk1 unk1
0x________ - 0x________ - usr     _K s r-- [vvar] [vvar] ; vvar_.r
0x________ - 0x________ - usr     8K s r-- [vvar_vclock] [vvar_vclock] ; vvar_vclock_.r
0x________ - 0x________ - usr     _K s r-x [vdso] [vdso] ; vdso_.r_x
0x________ - 0x________ - usr     4K s r-- /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.r
0x________ - 0x________ - usr   140K s r-x /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.r_x
0x________ - 0x________ - usr    56K s r-- /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.r.________
0x________ - 0x________ - usr     8K s r-- /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2 ; usr_lib32_ld_linux.so.2.rw
0x________ - 0x________ - usr     4K s rw- /usr/lib32/ld-linux.so.2 /usr/lib32/ld-linux.so.2
0x________ - 0x________ - usr   1__K s rw- [stack] [stack] ; stack_.rw

----
Hello world!
EOF
RUN

NAME=dbg.modules.count
FILE=bins/elf/analysis/elf-nx
ARGS=-d
CMDS=dmm~?
EXPECT=<<EOF
2
EOF
RUN

NAME=dbg.curmod.count
BROKEN=1
FILE=bins/elf/analysis/elf-nx
ARGS=-d
CMDS=dmm.~?
EXPECT=<<EOF
1
EOF
RUN

NAME=db.maps.symbols.after.map.complete
FILE=bins/elf/analysis/x86-helloworld-gcc
ARGS=-d
BROKEN=1
CMDS=<<EOF
dm~?
db @ sym.imp.puts
dc~?
dmi libc~?
dmi libc~libc|wc -l
EOF
EXPECT=<<EOF
7
0
2392
45
Hello world!
EOF
RUN

NAME=dbg.maps.sections.after.map.only_filtered
FILE=bins/elf/analysis/x86-helloworld-gcc
ARGS=-d
BROKEN=1
CMDS=<<EOF
dm~?
db @ sym.imp.puts
dc~?
dmS libc~?
dmS libc~libc|wc -l
dmS* libc~?
dmS* libc~libc|wc -l
EOF
EXPECT=<<EOF
7
0
80
78
314
312
Hello world!
EOF
RUN


NAME=dbg.maps.sections.after.map.complete
FILE=bins/elf/analysis/x86-helloworld-gcc
ARGS=-d
BROKEN=1
CMDS=<<EOF
dm~?
db @ sym.imp.puts
dc~?
dmS libc~?
dmS libc~libc|wc -l
dmS* libc~?
dmS* libc~libc|wc -l
dmS~?
dmS*~?
dmS~libc|wc -l
dmS*~libc|wc -l
EOF
EXPECT=<<EOF
7
0
80
78
314
312
154
598
78
312
Hello world!
EOF
RUN

NAME=db.maps.sections.are.singletons
FILE=bins/elf/analysis/x86-helloworld-gcc
ARGS=-d
BROKEN=1
CMDS=<<EOF
dmm~?
db @ sym.imp.puts
dc~?
dmm~?
S~.text|wc -l
dmS hello~.text|wc -l
dmS~x86-helloworld-gcc..text|wc -l
dmS~libc-2.19.so..text|wc -l
dmS~ld-2.19.so..text|wc -l
EOF
EXPECT=<<EOF
2
0
3
1
1
1
1
1
Hello world!
EOF
RUN

NAME=db.maps.current.section.after.dmS
FILE=bins/elf/analysis/x86-helloworld-gcc
ARGS=-d
BROKEN=1
CMDS=<<EOF
dmm~?
db @ sym.imp.puts
dc~?
dmm~?
s map._lib_i386_linux_gnu_ld_2.19.so._r_x
S.~?
.dmS*~?
S.~libc-2.19.so..text|wc -l
EOF
EXPECT=<<EOF
2
0
3
0
3
1
Hello world!
EOF
RUN
