简体   繁体   中英

Is mmap a built in function?

I know that mmap is a system call, but there must be some wrapper in glibc that does the system call. Yet when I try to use gdb to step through the mmap function in my program, gdb ignores it as it can't find any source file for it (Note I compile my own glibc from source). I can step through other glibc library functions such as printf and malloc but not mmap . I also use the flag -fno-builtin so that gcc doesn't use built in functions. Any help on this will be greatly appreciated.

I don't know what your problem is. It works perfectly fine for me.

Using system libc.so.6 , with debug symbols installed:

// mmap.c
#include <sys/mman.h>

int main()
{
  void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  return 0;
}

gcc -g mmap.c


$ gdb -q a.out
Reading symbols from /tmp/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x40052c: file mmap.c, line 5.

Temporary breakpoint 1, main () at mmap.c:5
5         void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
(gdb) step
mmap64 () at ../sysdeps/unix/syscall-template.S:82
82      ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) 
mmap64 () at ../sysdeps/unix/syscall-template.S:83
83      in ../sysdeps/unix/syscall-template.S
(gdb) 
main () at mmap.c:6
6         return 0;
(gdb) q

Using my own glibc build:

gdb -q a.out
Reading symbols from /tmp/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x40056c: file mmap.c, line 5.
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Temporary breakpoint 1, main () at mmap.c:5
5         void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
(gdb) step
mmap64 () at ../sysdeps/unix/syscall-template.S:81
81      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
(gdb) 
mmap64 () at ../sysdeps/unix/syscall-template.S:82
82              ret
(gdb) 
main () at mmap.c:6
6         return 0;
(gdb) q

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM