0
我正在使用AT & T語法。我寫了代碼,它從c調用函數mmap2。彙編 - mmap2從c調用
這是我的C文件:
#include <stdio.h>
int* callloc(int length);
int main(){
int *adres = callloc(1000);
printf("%u\n",adres);
return 0;
}
這是我的彙編函數:
#define PROT_READ 0x1 /* Page can be read. */
#define PROT_WRITE 0x2 /* Page can be written. */
#define PROT_EXEC 0x4 /* Page can be executed. */
#define PROT_NONE 0x0 /* Page can not be accessed. */
#define __NR_mmap 90
#define __NR_munmap 91
#define __NR_mmap2 192
.data
MMAP2 = 192
MUNMAP = 91
PROT_READ = 0x1
MAP_ANONYMOUS = 0x20
.global callloc
callloc:
#mmap2 function takes 6 arguments when called
#void *addr - it must be equal 0
#sieze_t length - this is variable from call in C
#int prot - access level, I guess it should be equal 0x1
#int flags - map_anonymous, then fd i offset are ignored
#int fd, off_t offset - those parameters are ignored
push %ebp
mov %esp,%ebp #esp has address of beginning of function
xor %ebx,%ebx
mov 8(%ebp),%ecx #length of memory to allocate is kept in stack since 8 byte
mov $PROT_READ,%edx
mov $MAP_ANONYMOUS,%esi
mov $MMAP2,%eax
int $0x80
mov %ebp,%esp
pop %ebp
ret
我的問題是 - 我怎麼能檢查,如果這個代碼是好?我想這個答案是在eax寄存器中,但是 - 我怎樣才能訪問這個值?在這種情況下,我不知道如何使用gdb。
對那些#define進行了註釋,因爲'#'在AT&T語法中開始註釋,所以不應該是錯誤的。我只是提醒一下。 – DzikiChrzan
而我的問題是 - 如何使用此文件運行gdb?編譯後,我有f.e.名爲exec的文件。我使用命令./exec運行這個命令 - 但是當我在gdb(「gdb ./exec」)中運行這個命令時,我不能只是傻乎乎地把斷點放在一些像。當我使用命令'文件'它說,沒有文件加載。 – DzikiChrzan
'gdb。/ exec'應該可以工作,並且您應該可以放置斷點。 – Jester