{"id":84,"date":"2018-02-05T15:07:43","date_gmt":"2018-02-05T23:07:43","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=84"},"modified":"2018-02-05T15:07:43","modified_gmt":"2018-02-05T23:07:43","slug":"developing-a-kernel-module-for-the-centos-7-system","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/centos\/","title":{"rendered":"Developing a kernel module for the CentOS 7 system"},"content":{"rendered":"<p>This tutorial shows how to create, build and debug a simple kernel module on a CentOS 7 system using Visual Studio. Before you begin, install VisualKernel 2.0 or later.<\/p>\n<ol>\n<li>Start Visual Studio. Select File-&gt;New-&gt;Project and pick the VisualKernel kernel module wizard:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/01-prjname.png\" width=\"800\" \/><\/li>\n<li>Proceed with the default &#8220;Hello, World&#8221; sample:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/02-hello.png\" width=\"696\" \/><\/li>\n<li>On the next page select the CentOS machine you want to debug:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/03-machine.png\" width=\"696\" \/><\/li>\n<li>When you click &#8220;Next&#8221;, VisualKernel will begin installing and caching the kernel symbols and sources. If you are using an older kernel that does not have a matching symbol image, VisualKernel will suggest updating the kernel automatically:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/04-getfiles.png\" width=\"696\" \/><\/li>\n<li>The next page of the wizard allows choosing the locations of the source files on the Windows and Linux machines. In this tutorial we will proceed with the default settings:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/05-srcpaths.png\" width=\"696\" \/><\/li>\n<li>Finally select the debug method. If you are using VMWare, select &#8220;Debug a Virtual Machine&#8221; as it is the fastest and the most reliable method. Otherwise, you can choose between ethernet, COM port, or a manual gdb stub (e.g. JTAG with OpenOCD):<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/06-kgdboe.png\" width=\"696\" \/>If you are using KGDBoE to debug a CentOS system, you will need to specify the network interface name manually. You can find out the interface name by running the &#8220;ifconfig&#8221; command.<\/li>\n<li>Press &#8220;Finish&#8221; to create your project. Then select Build-&gt;Build Solution to build it:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/07-build.png\" width=\"701\" \/><\/li>\n<li>Now you can set a breakpoint in the init() function and hit F5 to begin debugging:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/08-makebp.png\" width=\"701\" \/><\/li>\n<li>Once the breakpoint is hit, you can step into the printk() function by pressing F11. VisualKernel will automatically find and open the corresponding source file:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/09-stepin.png\" width=\"701\" \/>Press F5 co continue debugging.<\/li>\n<li>Now we will debug the module unloading. Set a breakpoint in the exit() function and select &#8220;Unload module&#8221; in the GDB Session window:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/10-unload.png\" width=\"739\" \/><\/li>\n<li>The breakpoint will be triggered and you will be able to step through the unload function:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/11-bp.png\" width=\"699\" \/>Press Shift-F5 to end debugging.<\/li>\n<li>You can change various settings related to building and debugging of your module by right-clicking on your project in Solution Explorer and selecting VisualKernel Project Properties:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/centos\/img\/12-settings.png\" width=\"804\" \/><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create, build and debug a simple kernel module on a CentOS 7 system using Visual<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[21,20],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/84"}],"collection":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":1,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/84\/revisions\/85"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}