This blog will try to demonstrate the steps required to use eclipse for browsing Linux kernel level source code, e.g. Linux kernel tree or device driver codes. If you have already worked with Linux kernel level source code you will know that the Linux kernel is written in C and Linux kernel space device drivers are also written in C. For c/c++ source code the eclipse version I use is called Eclipse-CDT (C/C++ Development Tooling). My development environment is Ubuntu Linux. So most of my references will be based on Ubuntu packages but these steps are pretty much similar in other Linux distros.

Installing eclipse-cdt in Ubuntu

So the first step to start with will be to install the eclipse-cdt in you Linux PC. In my case it is Ubuntu Linux hence I use the below command to install the eclise-cdt in my Linux machine:

sudo apt-get install eclipse eclipse-cdt g++

If you follow the instructions afterwards and select the default options then it will install eclipse-cdt in your PC.

Launch eclipse

To launch the eclipse-cdt type the below in the Linux command prompt:

eclipse &

Once you launch the eclipse it will ask you to specify a workspace for it to operate within. This basically means you have to specify a folder in your file-system which eclipse will use for your project. Specify an empty folder which a be used for this eclipse project anywhere in the file system. I use a folder in my home directory, e.g. /home/vbhadra/workspace_drivers2 as below.

workspace

Once you have selected your workspace location eclipse will come up and it should look somewhat like the below:

workspace2

Close the welcome window.

workspace3

Now go to the File menu -> New -> Project.

workspace4

Click on the C/C++ type -> C Project

workspace5

Then click Next. You should see something like the below:

workspace6

Type in a project name for your eclipse project. Unselect the “Use Default location”. Now, specify where you want to create eclipse project files. In my case I have existing source code to browse and I do not want to import the source code to another different location. I want to create the project files inside in my GIT repo and particularly in the folder where all my kernel source codes are located. So I select the project location clicking on the Browse button as below:

workspace7

Now leave the rest as default and click on the Next button. Leave the next wizard page settings to  default and click Next again. So in the next page click Next and go to the next page.

workspace8

Once you click Next in the above page you will go to the last page as below:

workspace9

Click Finish in the above page.

Eclipse will ask whether you want to open a perspective now, say Yes.

Now, you should see something like this:

workspace11.jpg

In the left panel you will see the project explorer window. Click on you project and go to the folder where your file of interest is located and browse the file.

Few, handy shortcuts I use to explore the code are: Ctrl+L for going to a line number, select an symbol and do Ctrl+Alt+g for searching the symbol globally in the project etc.

Setting the font size

Go to the Window -> Preferences -> General -> Appearances -> Color and Fonts -> C/C++ -> Editor.

workspace12

Select Editor Text Font  and then click on the Edit button on the right.

workspace13

Running eclipse from putty console

One other useful thing would be to run our eclipse from a putty console because that is what we are left with lot of times rather than having a fancy graphical user interface. So to be ebale to run eclipase from a putty console you need to configure it.

For running eclipse from putty command line you need to install a xwindows client called XMing. Download and install XMing. Launch the application.

Next you have to configure your putty session. To configure putty session to follow the below steps:

  1. Run putty.exe from your windows machine.
  2. Go to your previously save sessions and load it. Alternatively use the default session. Select the session and then click on the Load button.

 workspace14

Configure putty

  1. Now go to the Connection option on the left hand Category window.
  2. Got to SSH.
  3. Expand the SSH option.
  4. Select X11 under SSH.
  5. Check the “Enable X11 forwarding”.
  6. Now save the session under your previously saved name or under default.
  7. Open the session and login.
  8. Launch eclipse as described previously.

workspace15

Leave a Reply