Developing Linux Kernel with Netbeans

Introduction#

This tutorial shows how to develop Linux kernel with Netbeans. It contains not only information how to create simple "hello world" module, but complete step-by-step guide how-to:
  • build Kernel trunk for developing,
  • debug kernel start up,
  • debug parts of kernel.



Netbeans IDE#Pre requirements #

It's one of two most important thing :) you need to get it before proceed. Download IDE from  http://www.netbeans.org  (we use 7.0 version) - You don't need to download full version. After installation go to Tools -> Plugins  and install (if not installed) following additions:
  • C/C++
  • Gdbserver
Configuration#
Working with C/C++ projects may require tuning JVM, and assigning greater heap size. We use following options added in  <Netbeans Install Dir>/etc/netbeans.conf  under key  netbeans_default_options
-J-XX:+UseCompressedOops -J-XX:+UnlockExperimentalVMOptions -J-XX:+UseG1GC 
above will reduce memory usage in 64bit virtual machines (by using 32bit pointers), unlock experimental features, and turn on quite good G1 Garbage Collector
-J-mx1g -J-XX:MaxPermSize=412m -J-Xms512m
and those sets maximum heap size to 1GB, maximum Perm size to 412 MB, and initial heap size to 512 MB

Linux Kernel Sources#

This is 2nd most important things. You may download source archive, or grab current version from git (when we wrote this, we used this command)
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6
Configure kernel#
Execute
make oldconfig
to configure kernel as your current configuration.

Now open configuration editor, if you have Qt/KDE installed call

make xconfig
in other cases call
make menuconfig
Disable all unneeded features, drivers, etc. If you don't make this parsing of sources, and build time may drastically increase - remove such things like Blluetooth, WiFi, all file systems except Ext2/3/4, NFS, sound cards support, PPP support, etc. Just keep this what you need.
Select at least following options
Kernel hacking
|- Debug Filesystem
|- Kernel debugging
|- Verbose BUG() reporting
|- Compile the kernel with debug info
|- Compile the kernel with frame pointers
Options  Compile the kernel with debug info Compile the kernel with frame pointers  are crucial.

Additionally you make edit Makefile and replace all -O2 to -O1 to reduce optimization.

At this point Your kernel source should be ready for working, but do not open your project in Netbeans yet.

qEmu / KVM#

qEmu  or  KVM  are virtual machines, we will use to run kernel.  qEmu  mainly doesn't support hardware acceleration of virtualization tasks, but have ability to emulate more architectures.  KVM  may be faster, but will only emulate your host system architecture. At least one of this must be installed.
KVM - Hardware acceleration of virtualization#
KVM  stands for Kernel Virtual Machine; it uses processor extension, found on almost all Intel(r) and AMD(r), to speed up running in virtual machine. In order to give support for  KVM  You need to:
  • Compile kvm modules in your system kernel. Probably your host kernel has it, if not enable it in configuration editor, giving support for Intel or AMD or both technologies.
  • Load modules as root invoke commands modprobe kvm-intel, or modprobe kvm-amd.
  • You need to have special privileges to use KVM as normal user, in many systems add your user to
kvm  group (sometimes you will need to relog).

Please bear in mind, that depending on systems, kvm may be called by different commands:

kvm, quem-kvm    

Otehrs#

  • Set of developer tools - including gcc, make
  • small and fast Linux distribution - it will be used as our test environment, we prefer Gentoo stage 3,
because it starts fast and may be nicely customized form useless services or start options. But... the best distribution is always those you know!

Building with Netbeans#

Note
In this tutorial we use mainly  qemu-system-x86_64  command to invoke qemu/kvm virtual machine, both of those have same set of options (at least for this tutorial), depending on virtual machine You choose You may replace  qemu-system-x86_64 , by
kvm, qemu-kvm

Compile kernel#

You should first build your kernel. Go to source tree and invoke
    make -j5
The  -j5  informs  make  how much tasks should it span. We use 5 tasks, bear in mind following rule  number of task = number of CPU or cores + 1

Running QEmu#

We use following call (from kernel source directory)
qemu-system-x86_64 -hda /dev/zero -kernel arch/x86/boot/bzImage --no-acpi -s -S
options have following meaning:
-hda /dev/zero
Use  /dev/zero as your disk (at this moment we don't want usable hard disk)
-kernel arch/x86/boot/bzImage
Loads specified kernel
--no-acpi
Do not use ACPI
-S
Do not start CPU
-s
Open GDB server at port 1234
If you develop x86 (32 bit) you may call instead of  qemu-system-x86_64 , just  qemu

Now invoke above command without debug help (no -s -S). You should see how kernel starts, and crashes as it have no root file system.


Opening Linux kernel in Netbeans
#

  • Choose File -> New project, select C/C++ Project From Existing Sources, click Next.
  • Enter (or browse for) path where your kernel source exists.
  • Select Custom configuration. Click Next.
  • Disable Clean and Build after Finish (You have already kernel build). Click Next.
  • On Build actions step, point Build result to vmlinux file, which should resides in your source directory (after build). Click Next.
  • Click Next till last step. Do not finish yet!

You may need to do following action fast (to reduce Netbeans memory consumption on project parsing).

Right click on Your newly created project, Choose Code Assistance, unmark C/C++ Code Assistance.



Netbeans should not parse code, ok. Now, ight click on Your newly created project, Choose Code Assistance, and select Configure code assistance.

  • Choose Advance mode, click Next.
  • Select Explore executable or library file, click Next.
  • In Select executable or library file browse for vmlinux (like when you had configured project), click Next.
  • Select Configure Folder Properties, click Next, then Finish.
Now enable Code Assistance for this project (right click on Your newly created project, Choose  Code Assistance , mark  C/C++ Code Assistance ). Netbeans should start scanning and parsing.
Now You are ready to debug Linux kernel in Netbeans.

Lunching and debugging#

Actually I prefer building kernel in console instead of using Netbeans, but you may build it with Netbeans.
  • Open console and invoke qemu, this time use debugging switches (-s -S). Qemu should freeze.
  • Select Debug -> Attach debugger..., or click on small arrow on right of Debugging button on toolbar.
  • Select Gdbserver and enter Host: 127.0.0.1, Port: 1234


You attached to debugger - You should see Disassembly window and.

As the test, close Disassembly window, open ipc/shm.c, navigate to shm_init method, and put breakepoint on 1st line in this method. Click continue (or press F5). You should see result as on the top of this article!


 reference: Developing Linux Kernel with Netbeans

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习是一种人工智能(AI)的子领域,致力于研究如何利用数据和算法让计算机系统具备学习能力,从而能够自动地完成特定任务或者改进自身性能。机器学习的核心思想是让计算机系统通过学习数据中的模式和规律来实现目标,而不需要显式地编程。 机器学习应用非常广泛,包括但不限于以下领域: 图像识别和计算机视觉: 机器学习在图像识别、目标检测、人脸识别、图像分割等方面有着广泛的应用。例如,通过深度学习技术,可以训练神经网络来识别图像中的对象、人脸或者场景,用于智能监控、自动驾驶、医学影像分析等领域。 自然语言处理: 机器学习在自然语言处理领域有着重要的应用,包括文本分类、情感分析、机器翻译、语音识别等。例如,通过深度学习模型,可以训练神经网络来理解和生成自然语言,用于智能客服、智能助手、机器翻译等场景。 推荐系统: 推荐系统利用机器学习算法分析用户的行为和偏好,为用户推荐个性化的产品或服务。例如,电商网站可以利用机器学习算法分析用户的购买历史和浏览行为,向用户推荐感兴趣的商品。 预测和预测分析: 机器学习可以用于预测未来事件的发生概率或者趋势。例如,金融领域可以利用机器学习算法进行股票价格预测、信用评分、欺诈检测等。 医疗诊断和生物信息学: 机器学习在医疗诊断、药物研发、基因组学等领域有着重要的应用。例如,可以利用机器学习算法分析医学影像数据进行疾病诊断,或者利用机器学习算法分析基因数据进行疾病风险预测。 智能交通和物联网: 机器学习可以应用于智能交通系统、智能城市管理和物联网等领域。例如,可以利用机器学习算法分析交通数据优化交通流量,或者利用机器学习算法分析传感器数据监测设备状态。 以上仅是机器学习应用的一部分,随着机器学习技术的不断发展和应用场景的不断拓展,机器学习在各个领域都有着重要的应用价值,并且正在改变我们的生活和工作方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值