Monday, March 28, 2011

How to debug new Linux kernel (2.6.38) using Eclipse Helios and Qemu

(1) Make sure you have the latest QEMU from its official website and install SDL (Simple Directmedia Layer) and Eclipse Helios CDT package from Eclipse website.
(2) refer to the post
for basic setup.

Below are specific to Eclipse Helios (different from the post above):
(3) ON the menu "Run -> Debug configurations", double-click "C/C++ Application", on the right panel, make sure you got a name for this configuration. Then on the "Main" tab, click "Search project" and select "vmlinux", then NOTE: under the "vmlinux" subcategory, select the one that is NOT compressed, i.e., select "root_project_directory/vmlinux" NOT "root_project_directory/arch/x86/boot/compressed/vmlinux".

(4) Note that at the bottom of the "Main" tab, just above the "apply" and "revert" bottons, there is "Using GDB(DSF) create process launcher-select other..". We want to use another launcher because this GDB(DSF) one doesn't come with TCP connectivity. So click on "select other..", then tick "Use configuration specific setting" enabling the selection list below, then select "Standard create process launcher", then click "OK" to dismiss the "Select Preferred Launcher" dialog.

(5) Back to "Debug Configurations" dialog, click the "Debugger" tab, underneath it you will find the desired "Debugger" drawdown list, go with the post above and select "gdbserver", then pick your "Stop on startup at" (start_kernel in the post), click the "Connection", fill in "TCP", "1234", etc..then "Apply", "Close" the dialog.
(NOTE that here you have to disable the autobuild feature before debug of Eclipse. Else the debugger will NOT successfully stop execution at start_kernel(). The reason is: you first start Qemu to let the execution hang at the start point, then you turn to Eclipse to start the debugger. If you enable "autobuild", then when you try to start debugger, it will rebuild everything and the bzImage that you used to start Qemu will be replaced. That I guess will mess up the debugger. I notice this when Qemu seems to reload the kernel and flash the screen when the debugger is started)
(6) The rest steps are the same as the post. Enjoy, I know I'm thrilled..

No comments:

Post a Comment