简体   繁体   English

使用gdb进入内核源代码

[英]Stepping into kernel source code with gdb

What I'm basically trying to do is to step into the kernel source code line by line using gdb. 我基本上要做的是使用gdb逐行进入内核源代码。

This is the code I've got: 这是我得到的代码:

int main(void)
{
    int childPID;
    childPID = fork();
    return 0;
}

when I compile something using gcc -g I get meaningful output when I trace the program step by step in gdb. 当我使用gcc -g编译一些东西时,当我在gdb中逐步跟踪程序时,我得到了有意义的输出。 I've checked the configuration file of my linux install (\\boot\\config-3.19.0-15-generic) and the config_debug_info is on: 我检查了我的linux安装配置文件(\\ boot \\ config-3.19.0-15-generic),并且config_debug_info打开:

CONFIG_DEBUG_INFO=y

based on the help text: 基于帮助文本:

If you say Y here the resulting kernel image will include debugging info resulting in a larger kernel image. 如果你在这里说Y,结果内核映像将包含调试信息,从而产生更大的内核映像。 Say Y here only if you plan to use gdb to debug the kernel. 只有在您计划使用gdb来调试内核时才说这里。 If you don't debug the kernel, you can say N. 如果你不调试内核,你可以说N.

What I don't understand is how come when I trace using gdb I don't get any meaningful output? 我不明白的是,当我使用gdb跟踪时,我没有得到任何有意义的输出?

here is some of the output I'm getting: 这是我得到的一些输出:

Breakpoint 1, main () at ftest.c:7
7           childPID = fork();
(gdb) s 
__libc_fork () at ../sysdeps/nptl/fork.c:59
59      ../sysdeps/nptl/fork.c: No such file or directory.
(gdb) s 
54      in ../sysdeps/nptl/fork.c
(gdb) s 
111     in ../sysdeps/nptl/fork.c
(gdb) s 
__GI__IO_list_lock () at genops.c:1300
1300    genops.c: No such file or directory.
(gdb) s 
__x86.get_pc_thunk.bx () at ../sysdeps/i386/i686/multiarch/strcat.S:55
55      ../sysdeps/i386/i686/multiarch/strcat.S: No such file or directory.
(gdb) s 
__GI__IO_list_lock () at genops.c:1302
1302    genops.c: No such file or directory.
(gdb) s 
1304    in genops.c
(gdb) s 
__libc_fork () at ../sysdeps/nptl/fork.c:114
114     ../sysdeps/nptl/fork.c: No such file or directory.
(gdb) s 
120     in ../sysdeps/nptl/fork.c
(gdb) s 
121     in ../sysdeps/nptl/fork.c
(gdb) s 
124     in ../sysdeps/nptl/fork.c
(gdb) s 
131     in ../sysdeps/nptl/fork.c
(gdb) s 
124     in ../sysdeps/nptl/fork.c
(gdb) s 
131     in ../sysdeps/nptl/fork.c
(gdb) s 
206     in ../sysdeps/nptl/fork.c
(gdb) s 
209     in ../sysdeps/nptl/fork.c
(gdb) s 
212     in ../sysdeps/nptl/fork.c
(gdb) s 
__GI__IO_list_unlock () at genops.c:1309
1309    genops.c: No such file or directory.
(gdb) s 
__x86.get_pc_thunk.cx () at ../sysdeps/unix/syscall-template.S:83
83      ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) s 
__GI__IO_list_unlock () at genops.c:1311
1311    genops.c: No such file or directory.
(gdb) s 
__libc_fork () at ../sysdeps/nptl/fork.c:215
215     ../sysdeps/nptl/fork.c: No such file or directory.
(gdb) s 
229     in ../sysdeps/nptl/fork.c
(gdb) s 
main () at ftest.c:8
8               childPID = childPID+ 1;
(gdb) s 
10          return 0;
(gdb) Quit
(gdb) 

Thanks in advance 提前致谢

This is a misunderstanding: The option is solely to get better information when opening the kernel-imagefile with gdb: 这是一个误解:该选项仅用于在使用gdb打开kernel-imagefile时获得更好的信息:

gdb vmlinux

Note that this works only with the (not for booting postprocessed) ELF-image. 请注意,这仅适用于(不用于引导后处理的)ELF图像。

It has nothing to do with debugging processes, neither with live-debugging the linux kernel 它与调试进程无关,也没有与linux内核进行实时调试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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