View previous topic :: View next topic |
Author |
Message |
guyuming Apprentice

Joined: 19 Nov 2020 Posts: 265
|
Posted: Thu Feb 04, 2021 12:18 pm Post subject: how to compile kernel with debug symbol? |
|
|
in ubuntu, we can install debug symbol for kernel by install the dbgsym package, but how can we compile a kernel with debug symbol in kernel? |
|
Back to top |
|
 |
alamahant Advocate

Joined: 23 Mar 2019 Posts: 3961
|
Posted: Thu Feb 04, 2021 3:08 pm Post subject: |
|
|
Hi
please try
Code: |
CONFIG_DEBUG_INFO=y
|
But it will produce maybe a 10-12 gig kernel tree.
IF you dont mind it then here are some more options
Code: |
# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
# CONFIG_XEN_DEBUG_FS is not set
# CONFIG_DEBUG_HOTPLUG_CPU0 is not set
CONFIG_BLK_DEBUG_FS=y
CONFIG_BLK_DEBUG_FS_ZONED=y
# CONFIG_CAN_DEBUG_DEVICES is not set
# CONFIG_MAC80211_DEBUG_MENU is not set
CONFIG_WIMAX_DEBUG_LEVEL=8
# CONFIG_DEBUG_DRIVER is not set
# CONFIG_DEBUG_DEVRES is not set
# CONFIG_DEBUG_TEST_DRIVER_REMOVE is not set
CONFIG_PNP_DEBUG_MESSAGES=y
CONFIG_CB710_DEBUG_ASSUMPTIONS=y
CONFIG_AIC7XXX_DEBUG_ENABLE=y
CONFIG_AIC7XXX_DEBUG_MASK=0
CONFIG_AIC79XX_DEBUG_ENABLE=y
CONFIG_AIC79XX_DEBUG_MASK=0
# CONFIG_SCSI_SNIC_DEBUG_FS is not set
# CONFIG_SCSI_LPFC_DEBUG_FS is not set
CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING=y
# CONFIG_DM_DEBUG_BLOCK_STACK_TRACING is not set
# CONFIG_VXGE_DEBUG_TRACE_ALL is not set
CONFIG_WIMAX_I2400M_DEBUG_LEVEL=8
# CONFIG_I2C_DEBUG_CORE is not set
# CONFIG_I2C_DEBUG_ALGO is not set
# CONFIG_I2C_DEBUG_BUS is not set
# CONFIG_DEBUG_PINCTRL is not set
# CONFIG_DEBUG_GPIO is not set
# CONFIG_HWMON_DEBUG_CHIP is not set
# CONFIG_DRM_DEBUG_SELFTEST is not set
CONFIG_NOUVEAU_DEBUG_DEFAULT=3
# CONFIG_NOUVEAU_DEBUG_MMU is not set
# CONFIG_NOUVEAU_DEBUG_PUSH is not set
# CONFIG_SND_DEBUG_VERBOSE is not set
# CONFIG_SND_SOC_SOF_DEBUG_PROBES is not set
# CONFIG_HFI1_DEBUG_SDMA_ORDER is not set
# CONFIG_INFINIBAND_IPOIB_DEBUG_DATA is not set
CONFIG_OCFS2_DEBUG_MASKLOG=y
# CONFIG_OCFS2_DEBUG_FS is not set
# CONFIG_CIFS_DEBUG_DUMP_KEYS is not set
# CONFIG_AFS_DEBUG_CURSOR is not set
CONFIG_DYNAMIC_DEBUG_CORE=y
CONFIG_DEBUG_BUGVERBOSE=y
# CONFIG_DEBUG_INFO is not set
# CONFIG_DEBUG_SECTION_MISMATCH is not set
# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
CONFIG_DEBUG_FS=y
CONFIG_DEBUG_FS_ALLOW_ALL=y
# CONFIG_DEBUG_FS_DISALLOW_MOUNT is not set
# CONFIG_DEBUG_FS_ALLOW_NONE is not set
CONFIG_DEBUG_KERNEL=y
# CONFIG_DEBUG_MISC is not set
# CONFIG_DEBUG_PAGEALLOC is not set
# CONFIG_DEBUG_PAGE_REF is not set
CONFIG_DEBUG_RODATA_TEST=y
CONFIG_ARCH_HAS_DEBUG_WX=y
CONFIG_DEBUG_WX=y
# CONFIG_DEBUG_OBJECTS is not set
# CONFIG_SLUB_DEBUG_ON is not set
CONFIG_HAVE_DEBUG_KMEMLEAK=y
# CONFIG_DEBUG_KMEMLEAK is not set
# CONFIG_DEBUG_STACK_USAGE is not set
CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE=y
CONFIG_DEBUG_VM=y
# CONFIG_DEBUG_VM_VMACACHE is not set
# CONFIG_DEBUG_VM_RB is not set
# CONFIG_DEBUG_VM_PGFLAGS is not set
# CONFIG_DEBUG_VM_PGTABLE is not set
CONFIG_ARCH_HAS_DEBUG_VIRTUAL=y
# CONFIG_DEBUG_VIRTUAL is not set
CONFIG_DEBUG_MEMORY_INIT=y
# CONFIG_DEBUG_PER_CPU_MAPS is not set
CONFIG_DEBUG_SHIRQ=y
# CONFIG_DEBUG_TIMEKEEPING is not set
# CONFIG_DEBUG_PREEMPT is not set
# CONFIG_DEBUG_RT_MUTEXES is not set
# CONFIG_DEBUG_SPINLOCK is not set
# CONFIG_DEBUG_MUTEXES is not set
# CONFIG_DEBUG_WW_MUTEX_SLOWPATH is not set
# CONFIG_DEBUG_RWSEMS is not set
# CONFIG_DEBUG_LOCK_ALLOC is not set
# CONFIG_DEBUG_ATOMIC_SLEEP is not set
# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
# CONFIG_DEBUG_KOBJECT is not set
# CONFIG_DEBUG_LIST is not set
# CONFIG_DEBUG_PLIST is not set
# CONFIG_DEBUG_SG is not set
# CONFIG_DEBUG_NOTIFIERS is not set
# CONFIG_DEBUG_CREDENTIALS is not set
# CONFIG_DEBUG_WQ_FORCE_RR_CPU is not set
# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
# CONFIG_DEBUG_TLBFLUSH is not set
CONFIG_DEBUG_BOOT_PARAMS=y
# CONFIG_DEBUG_ENTRY is not set
# CONFIG_DEBUG_NMI_SELFTEST is not set
# CONFIG_X86_DEBUG_FPU is n
|
_________________
 |
|
Back to top |
|
 |
guyuming Apprentice

Joined: 19 Nov 2020 Posts: 265
|
Posted: Fri Feb 05, 2021 10:27 am Post subject: |
|
|
alamahant wrote: | Hi
please try
Code: |
CONFIG_DEBUG_INFO=y
|
But it will produce maybe a 10-12 gig kernel tree.
|
i selected Kernel hacking -> Compile-time checks and compiler options,
the resulting vmlinuz-5.4.92-gentoo-x86_64 size is 9451840
i compile kernel with genkernel --menuconfig all
i can see the following in the command output: "Install 5.4.92-gentoo-x86_64 modules (and stripping) ..."
does it mean that debug infor in kernel modules are stripped?
how can i verify whether the resulting kernel image and modules contains debug info? |
|
Back to top |
|
 |
alamahant Advocate

Joined: 23 Mar 2019 Posts: 3961
|
Posted: Fri Feb 05, 2021 10:47 am Post subject: |
|
|
Please run
Code: |
grep CONFIG_DEBUG_INFO /usr/src/linux/.config
|
and if not there or not enabled append it.
Then recompile the kernel. _________________
 |
|
Back to top |
|
 |
guyuming Apprentice

Joined: 19 Nov 2020 Posts: 265
|
Posted: Fri Feb 05, 2021 2:40 pm Post subject: |
|
|
alamahant wrote: | Please run
Code: |
grep CONFIG_DEBUG_INFO /usr/src/linux/.config
|
and if not there or not enabled append it.
Then recompile the kernel. |
CONFIG_DEBUG_INFO=y
is in my grep result.
But i don't know how to check whether the debug info are there.
I know that with ordinary files, i can use readelf -S to check whether there are debug section, or just gdb the file to see whether gdb can read symbol from the file.
but i don't know how to deal with kernel image or kernel module |
|
Back to top |
|
 |
alamahant Advocate

Joined: 23 Mar 2019 Posts: 3961
|
|
Back to top |
|
 |
guyuming Apprentice

Joined: 19 Nov 2020 Posts: 265
|
Posted: Sat Feb 06, 2021 10:34 am Post subject: |
|
|
I installed gentoo on a pad with atom CPU, it just hang constantly. I have not installed the graphical interface yet. I used to install kubuntu, it also hangs sometimes.
i had get error message such as "BUG: unable to handle page fault for address", but it can be different symptoms when it hangs.
I just created a memtest86 v8.4 bootable usb and finished memory test, its OK, no error found.It takes about 6 hours to run the memory test.
I guess that maybe i had include too much in kernel, or missed something.
I hope that if debug infor is included in kernel, there might be some call stack shown on the screen which may help me to figure out what i may try to exclude from kernel.
I don't think i can truly found out what's wrong, but just hope that there maybe some clue for the incorrect configuration of the kernel.
Last edited by guyuming on Sat Feb 06, 2021 11:50 am; edited 3 times in total |
|
Back to top |
|
 |
alamahant Advocate

Joined: 23 Mar 2019 Posts: 3961
|
Posted: Sat Feb 06, 2021 10:42 am Post subject: |
|
|
Then please try this for a test
There is a precompiled kernel in Gentoo repo.
Code: |
emerge -1av gentoo-kernel-bin
emerge -1av dracut ### initramfs tool
grub-mkconfig -o /boot/grub/grub.cfg
reboot
|
If this solves your problem then you can debug further your kernel config. _________________
 |
|
Back to top |
|
 |
guyuming Apprentice

Joined: 19 Nov 2020 Posts: 265
|
Posted: Sat Feb 06, 2021 11:51 am Post subject: |
|
|
just know that System.map is the file that stores kernel symbol;
genkernel --help | grep strip
and i found that there is a --no-strip option.
and i am trying to enable KDB as described in https://www.kernel.org/doc/html/latest/dev-tools/kgdb.html
Code: |
CONFIG_FRAME_POINTER=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_KGDB_KDB=y
CONFIG_KDB_KEYBOARD=y |
it's said that kernel will open kdb shell if panic occurs and i can check call stack with bt command. |
|
Back to top |
|
 |
guyuming Apprentice

Joined: 19 Nov 2020 Posts: 265
|
Posted: Tue Mar 02, 2021 3:06 am Post subject: |
|
|
I had installed a new desktop machine, and set CONFIG_DEBUG_INFO=y
the command i used to install kernel is:
genkernel --install --no-mrproper --no-strip all
the vmlinuz-5.4.97-gentoo-x86_64 in /boot does not seem to have debug symbol in the file, but there is corresponding System.map-5.4.97-gentoo-x86_64:
Code: | gym@gymDeskGentoo /boot $ gdb
...
(gdb) file vmlinuz-5.4.97-gentoo-x86_64
BFD: /boot/vmlinuz-5.4.97-gentoo-x86_64: warning: ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .bss
Reading symbols from vmlinuz-5.4.97-gentoo-x86_64...
(No debugging symbols found in vmlinuz-5.4.97-gentoo-x86_64)
(gdb) |
but there is debug symbol in /usr/src/linux/vmlinux:
Code: | gym@gymDeskGentoo /usr/src/linux $ gdb vmlinux
...
Reading symbols from vmlinux...
(gdb) |
if i run
perf record lsblk
perf report
i can see something as follows:
Code: | Overhead Command Shared Object Symbol
# ........ ....... ................ .......................
#
20.88% lsblk libc-2.32.so [.] __vfprintf_internal
16.95% lsblk libc-2.32.so [.] wcwidth
11.71% lsblk [unknown] [k] 0xffffffffb6a00010
11.71% lsblk ld-2.32.so [.] _dl_relocate_object
11.24% lsblk [unknown] [k] 0xffffffffb6a01250
10.35% lsblk ld-2.32.so [.] strcmp
8.98% lsblk libc-2.32.so [.] _int_malloc
6.65% lsblk ld-2.32.so [.] dl_main
1.44% lsblk ld-2.32.so [.] _dl_start
0.08% lsblk ld-2.32.so [.] _start |
but if i run
sudo perf record lsblk
sudo perf report
i can see:
Code: | # Overhead Command Shared Object Symbol
# ........ ....... ................ ................................
#
29.67% lsblk ld-2.32.so [.] _dl_relocate_object
27.40% lsblk libc-2.32.so [.] __memset_sse2_unaligned_erms
24.88% lsblk lsblk [.] lsblk_device_get_mountpoint
16.98% lsblk [kernel.vmlinux] [k] vma_interval_tree_insert
1.04% perf [kernel.vmlinux] [k] __set_task_comm
0.04% perf [kernel.vmlinux] [k] native_write_msr
|
|
|
Back to top |
|
 |
|