I'm trying to debug a kernel module and as such, need to compile it without optimizations. I'm using the Yocto Project and can't get the module to compile with a -O0 flag despite trying several things. So far I've tried adding the following to my local.conf.
EXTRA_IMAGE_FEATURES = "debug-tweaks tools-profile dbg-pkgs"
INHIBIT_PACKAGE_STRIP = "1"
DEBUG_BUILD = "1"PACKAGE_DEBUG_SPLIT_STYLE = 'debug-file-directory'
I've also added the following to my kernel recipe in addition to the changes above.
DEBUG_FLAGS += "-O0"
None of this has worked. If I run objdump -g on the .ko file in question I still find -O2 is being used. This leads to the debugger jumping all around when I'm trying to step through source.
Is there a way to override the kernel compile optimization level in the Yocto Project?
For kernel module debugging I'm following this guide from DS-MDK and the imx_rpmsg_tty module.
http://www2.keil.com/docs/default-source/default-document-library/gs_ds-mdk_5_27_r1.pdf?sfvrsn=2
I'm working with this SOM.
CL-SOM-iMX7 | NXP (Freescale) i.MX 7 | System-on-Module | Computer-on-Module | CompuLab
I've attached my local.conf, my kernel recipe, and my kernel .config. Let me know if you need any more information.
Thanks for the help,
James
Solved! Go to Solution.
Hi YuriMuhin_ng,
Thanks for the response. I tried building the kernel outside of Yocto and was able to eventually get it working.
I made and installed two SDK's, one with debug options enable in the local.conf mentioned above and one without. After running the environment-setup script for the debug SDK I echo'd my CFLAGS variable. It had a -O (which goes to a -O1) in it so I appended a -O0. I copied over my .config and ran make. This didn't work, the kernel object was still being compiled with -O2.
Eventually I added the following line to the Makefile in the directory with the kernel module.
CFLAGS_imx_rpmsg_tty.o := -O0
After adding that, the module compiled with -O0 and the debugging experience was fixed. Interestingly it also worked when I used the environment-setup script for the regular SDK.
At this point I guess I still have a few questions:
Thank you,
James
Hello,
Please try to build kernel without Yocto:
https://community.nxp.com/docs/DOC-334814
Have a great day,
Yuri
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi YuriMuhin_ng,
Thanks for the response. I tried building the kernel outside of Yocto and was able to eventually get it working.
I made and installed two SDK's, one with debug options enable in the local.conf mentioned above and one without. After running the environment-setup script for the debug SDK I echo'd my CFLAGS variable. It had a -O (which goes to a -O1) in it so I appended a -O0. I copied over my .config and ran make. This didn't work, the kernel object was still being compiled with -O2.
Eventually I added the following line to the Makefile in the directory with the kernel module.
CFLAGS_imx_rpmsg_tty.o := -O0
After adding that, the module compiled with -O0 and the debugging experience was fixed. Interestingly it also worked when I used the environment-setup script for the regular SDK.
At this point I guess I still have a few questions:
Thank you,
James