vaz_mz писал(а): ↑17.04.2015 13:08
при отладке из под чистого gdb - отладчик не бегает по циклу, а один раз заходит а потом сразу выполняет следующую за циклом строку.
Тем не менее, последняя инструкция в выводе strace именно write-вывод на первый деструктор (т.е. на stdout) "10 \n", что и должно быть.
Кстати, и какая это строка, следующая за циклом? Т.е. какое значение j передается?
Вот мой вывод strace:
Код: Выделить всё
> strace ./test.c
execve("./test.c", ["./test.c"], [/* 97 vars */]) = 0
brk(0) = 0x2338000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffc3e9ab000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=150582, ...}) = 0
mmap(NULL, 150582, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffc3e986000
close(3) = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\34\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1915142, ...}) = 0
mmap(NULL, 3787328, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffc3e3ef000
mprotect(0x7ffc3e583000, 2093056, PROT_NONE) = 0
mmap(0x7ffc3e782000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x193000) = 0x7ffc3e782000
mmap(0x7ffc3e788000, 14912, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffc3e788000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffc3e985000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffc3e984000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffc3e983000
arch_prctl(ARCH_SET_FS, 0x7ffc3e984700) = 0
mprotect(0x7ffc3e782000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ) = 0
mprotect(0x7ffc3e9ac000, 4096, PROT_READ) = 0
munmap(0x7ffc3e986000, 150582) = 0
fstat(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffc3e9aa000
write(1, "10 \n", 410
) = 4
exit_group(0) = ?
+++ exited with 0 +++
Вот код:
Код: Выделить всё
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv)
{
int i, j=0;
for(i=0; i<10; i++)
j++;
printf("%d \n",j);
return (EXIT_SUCCESS);
}
Сеанс gdb:
Код: Выделить всё
alex@pizza:~/code/C> gcc -g test.c -o test
alex@pizza:~/code/C> gdb ./test
GNU gdb (GDB; openSUSE Factory) 7.8
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-suse-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.opensuse.org/>.
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 ./test...done.
(gdb) b main
Breakpoint 1 at 0x40056c: file test.c, line 6.
(gdb) r
Starting program: /home/alex/code/C/test
Breakpoint 1, main (argc=1, argv=0x7fffffffde68) at test.c:6
6 int i, j=0;
(gdb) n
7 for(i=0; i<10; i++)
(gdb) n
8 j++;
(gdb) n
7 for(i=0; i<10; i++)
(gdb) n
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
8 j++;
(gdb)
7 for(i=0; i<10; i++)
(gdb)
10 printf("%d \n",j);
(gdb)
10
11 return (EXIT_SUCCESS);
(gdb)
12 }
(gdb)
__libc_start_main (main=0x40055d <main>, argc=1, argv=0x7fffffffde68, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7fffffffde58) at libc-start.c:323
323 libc-start.c: No such file or directory.
(gdb)
[Inferior 1 (process 4428) exited normally]