Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22476

How to debug kernel code without running kernel?

$
0
0

I'm reading some kernel books, I want to debug the spinlock_t usage, and prepared the following demo code:

////////////////////////////// demo/spinlock.c////////////////////////////#include <linux/spinlock.h>struct obj {    spinlock_t spinlock;}int demo0() {    struct obj o;    spin_lock_init(o.spinlock);}int main(){    demo0();}

The Makefile seems like:

####################### demo/Makefile######################demo: spinlock.c    gcc -o spinlock spinlock.c -I../linux-5.6.9/arch/x86/include -I../linux-5.6.9/include

The file tree seems like this

├── demo└── linux-5.6.9

While meke, it gave me tones of errors (too many, I can't enumerate them here), It seems like that I missed some GCC CFLAGS or others.

How to debug kernel code line by line? Most of Google results are GDB/Qemu debugging withing running kernel. Is there any suggestions to debug the kernel code without running the kernel?


Viewing all articles
Browse latest Browse all 22476

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>