У меня есть код:GDB не понимает код
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
size_t foo_len (const char *s)
{
return strlen (s);
}
int main (int argc, char *argv[])
{
const char *a = NULL;
printf ("size of a = %d\n", foo_len (a));
exit (0);
}
Собирать с отладочной:
$ gcc example.c -g -o example
И работать в БГД
$ gdb ./example
[email protected]:~$ gdb ./example
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./example...done.
GDB запустить
(gdb) run
Starting program: ./example
я ожидал получить что-то вроде
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400527 in foo_len (s=0x0) at example.c:8
8 return strlen (s);
Но получил:
Program received signal SIGSEGV, Segmentation fault.
strlen() at ../sysdeps/x86_64/strlen.S:106
106 ../sysdeps/x86_64/strlen.S: No such file or directory.
Где проблема?
Sample in wikipediaподтверждена неправильная?
Прочитать сообщение об ошибке. Сбой происходит в strlen, но у вас нет исходного файла strlen (так что он не может показать вам код) – deviantfan