このファイルがあるとしましょう:
xb@dnxb:/tmp/c$ cat helloworld.h
void hello();
xb@dnxb:/tmp/c$ cat helloworld.c
#include <stdio.h>
void hello() {
printf("Hello world!\n");
printf("Next line\n");
}
xb@dnxb:/tmp/c$ cat main.c
#include <stdio.h>
#include "helloworld.h"
int
main(void) {
hello();
return 0;
}
そして、次のようにコンパイルされました:
xb@dnxb:/tmp/c$ gcc -g3 -shared -o libhello.so -fPIC helloworld.c -std=c11
xb@dnxb:/tmp/c$ gcc -g3 main.c -o main -Wl,-rpath,"$PWD" -L. -lhello
次に、gdb でデバッグします。
xb@dnxb:/tmp/c$ gdb -q -n ./main
Reading symbols from ./main...done.
(gdb) b main
Breakpoint 1 at 0x40062a: file main.c, line 5.
(gdb) r
Starting program: /tmp/c/main
Breakpoint 1, main () at main.c:5
5 hello();
(gdb) s
hello () at helloworld.c:3
3 printf("Hello world!\n");
この時点で、繰り返し押します(タイプしEnterて繰り返し押すのと同じです):s
Enter
(gdb)
_IO_puts (str=0x7ffff7bd9689 "Hello world!") at ioputs.c:33
33 ioputs.c: No such file or directory.
(gdb)
35 in ioputs.c
(gdb)
strlen () at ../sysdeps/x86_64/strlen.S:66
66 ../sysdeps/x86_64/strlen.S: No such file or directory.
(gdb)
上記のhelloworld.c
ステップに踏み込まずに、私が気にするだけの場合はどうなりますか?printf()
ioputs.c
xb@dnxb:/tmp/c$ gdb -q -n ./main
Reading symbols from ./main...done.
(gdb) b main
Breakpoint 1 at 0x40062a: file main.c, line 5.
(gdb) r
Starting program: /tmp/c/main
Breakpoint 1, main () at main.c:5
5 hello();
(gdb) s
hello () at helloworld.c:3
3 printf("Hello world!\n");
(gdb) n
Hello world!
4 printf("Next line\n");
(gdb)
これは私が望んでいるものですが、自分が入っていることを手動で見つける必要があり、helloworld.c
それに応じて入力する時が来ましたn
. 私の希望は:
(gdb) s
hello () at helloworld.c:3
3 printf("Hello world!\n");
を押すEnterと、たとえばこの場合、カスタム ファイル名のステップインがスキップされ、次のhelloworld.c
場所に直接スキップされprintf("Next line\n");
ます。
(gdb)
Hello world!
4 printf("Next line\n");
(gdb)
利点は、特にコード階層が大きく、何度も足を踏み入れる可能性がある場合に、どこで停止s
して変更する必要があるかを特定する必要がないことです。不要な深さ/レベルを繰り返し押してスキップするだけです。n
helloworld.c
Enter
どうすればいいですか?