summaryrefslogtreecommitdiff
path: root/Development/Documentation/UsingEclipse.mdwn
blob: f848eee6d334b2ea4d1850e395663059d072f2f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142


# Using Eclipse CDT to develop Xorg

[[!toc ]] 


## Benefits

* **Code Navigation** 
      * CDT 4.0 includes a fast code indexer and navigator which allows you browse call hierarchy, and quickly jump to the symbol declarations. 
* **Debugging** 
      * acts as an interactive frontend to the GDB debugger 
      * allows remote debugging via gdbserver 
* **It doesn't get in the way** 
      * it doesn't require any particular directory layout 
      * it doesn't require any particular build system, i.e., it plays nicely with autotools, hand-written Makefiles, or any build system which can output a build log 
      * it has a configurable C coding style 
      * it provides access to the GDB console while debugging 
      * it has powerful regular expressions searching and replacing abilities 

## Screenshots

[[!img http://people.freedesktop.org/~jrfonseca/eclipse/eclipse-cdt-main.png]] 

[[!img http://people.freedesktop.org/~jrfonseca/eclipse/eclipse-cdt-remote-debug.png]] 


## Installation How-to

If you're only interested in C/C++ development the simplest option is to download [[Eclipse IDE for C/C++ Developers|http://www.eclipse.org/downloads/moreinfo/c.php]] and extract it into /opt. 

Otherwise, you can always install CDT from the Eclipse Update Manager. 

Then install the [[Eclipse-Autotools integration plugin|http://sourceware.org/eclipse/autotools/]], which provides assistance for projects using autotools. 


## Introduction

Eclipse organizes code in _projects_ and _workspaces_. 

* A _project_ is equivalent to a X.Org module. Projects have different build settings and separate source repositories. 
* A _workspace_ is a set of related projects. Workspaces have different settings, and a workspace can only be opened by a single instance of Eclipse at any given time. 
NOTE: You don't need to create a project for every single X.Org module, and that would be overkill. The modules you are planning to actively develop and debug are perfectly sufficient, as you can still open and debug through files outside the projects. 

Eclipse organizes windows in _views_ and _perspectives_. 

* A _view_ is a display. You can add and re-arrange existing views. 
* A _perpective_ is a set of views in a given layout. You can switch perspectives. The most interesting are the C/C++ and the Debug perspective. 

## Xorg How-to

It is assumed you have installed the xorg development packages from your distribution, or you have built xorg from source as explained in the [[ModularDevelopersGuide|ModularDevelopersGuide]] in /opt/xorg. 

* Initial configuration 
      * Start eclipse and enter the path to your workspace (it can be an inexistent directory as Eclipse creates one for you) 
      * You'll be presented with the welcome screen. Click to go to the workbench. 
      * Switch to the _C/C++ Perspective_ by going to _Window > Open Perspective > Other... > C / C++_ 
      * In _Window > Preferences > C/C++ > Environment_ dialog set the following environment variables [[!format txt """
LD_LIBRARY_PATH=/opt/xorg/lib
ACLOCAL="aclocal -I /opt/xorg/share/aclocal"
CPPFLAGS="-I /opt/xorg/include"
CFLAGS="-O0 -g3 -fmessage-length=0"
CXXFLAGS="-O0 -g3 -fmessage-length=0"
"""]]
* Create a project for `xserver` 
      * In a terminal do: [[!format txt """
cd /path/to/your/workspace
git clone git://anongit.freedesktop.org/git/xorg/xserver
"""]]
      * File > New > GNU C Autotools Project 
            * Set `xserver` as the project (the same as the git module) 
      * In _Project > Properties_ dialog, _C/C++ Build > Settings > Tool Settings_ tab 
            * Under _configure > General > Directory specifiers_ set the installation directory (--prefix) to `/opt/xorg` 
            * Under _configure > Features and packages_ set _Enable maintainer mode (--enable-maintainer-mode)_ and enter any other configuration options you wish to pass to `configure` 
      * Press Ctrl+B to build the project. 
      * To switch between `configure` output and the `make` output go to the _Console_ view, and click on the _Display Selected Console_ button. 
      * Double-click install target of the _Make Targets_ view. 
* Debug Xnest locally 
      * In the _Debug > Debug settings..._ dialog, under _C/C++ Local Application_ click on the _New_ button 
      * Set `/opt/xorg/bin/Xnest` as the application path 
      * Set as arguments `:1`  
      * Click on the _Debug_ button. 
      * The gdb console is available from the _Console_ view, _Console_ by clicking on the _Display Selected Console_ button. 
* Debug Xorg remotely 
      * rsync the `/opt/xorg` directory to the remote machine [[!format txt """
rsync -av --delete /opt/xorg/ your-remote-machine:/opt/xorg/
"""]]
      * in the remote machine run [[!format txt """
gdbserver :10000 /opt/xorg/bin/Xorg
"""]]
      * In the _Debug > Debug settings..._ dialog, under _C/C++ Local Application_ click on the _New_ button 
      * Set `/opt/xorg/bin/Xorg` as the application path 
      * Choose gdbserver in the Debugger tab 
      * Enter the hostname and of the remote machine and the port that gdb is listening to 
      * Click on the _Debug_ button. 
You can add more modules and/or debug targets in a similar fashion. 


## Code Formatting

CDT allows to specify the C code style from _Window > Preferences > C/C++ > Code style_ property page. 

You can import  [[this profile|http://people.freedesktop.org/~jrfonseca/eclipse/xorg-code-style.xml]], which was made to follow [[these (un)official guidelines|http://lists.freedesktop.org/archives/xorg/2004-October/003673.html]] as close as possible. 

There is also a [[code style for Mesa|http://people.freedesktop.org/~jrfonseca/eclipse/mesa-code-style.xml]]. 


## Full tree setup

You can add the whole tree as a project, which is advantageous when cross-module work is done, or you are interested in module interdependecies. However, index generation can get darn slow then. Manually specifying include directories and disabling _automated discovery_ in the project's discovery options may be helpful. 

Also, eclipse prior to ganymede had the tendency to spend a few minutes on collecting the (admittedly huge) index whenever you'd type a member access operator (. or ->). Disabling _Content Assist_ should help that. 


## Tips

* To avoid out-of-memory errors change the last lines of `eclipse.ini` to [[!format txt """
-vmargs
-Xms64m
-Xmx1024m
"""]]
* The autotools plugin simplifies the invocation of autoconf and automake, but it has some bugs that you should watch out for: 
      * [[https://bugzilla.redhat.com/show_bug.cgi?id=324681|https://bugzilla.redhat.com/show_bug.cgi?id=324681]] 
* In _Window > Preferences > General > Keys_ bind Ctrl+B to build the current project, instead of all projects. 
* In _Window > Preferences > General_ set to _Always run in background_ 
* In _Window > Preferences > Run/Debug > Launching_ set to Launch the previous launched application 
Check more tips in: 

* [[http://tkramar.blogspot.com/2007/10/effective-eclipse-i-setup.html|http://tkramar.blogspot.com/2007/10/effective-eclipse-i-setup.html]] 
* [[http://dmy999.com/article/29/using-eclipse-efficiently|http://dmy999.com/article/29/using-eclipse-efficiently]] 

## Other plugins

Must have: 

* [[Extended VS Presentation plugin for Eclipse|http://andrei.gmxhome.de/skins/index.html]] -- this plugin modifies Eclipse's look and feel to make it waste less screen space, and easier to use. 
* [[Rectangular edit plugin|http://lunar-eclipse.sourceforge.net/editor-tutorial/index.html]] -- provides rectangular editing abilities, like VIM and Emacs. 
Optional: 

* [[Target Management plugin|http://www.eclipse.org/dsdp/tm/]] -- simplifies remote debugging and testing by allowing to seemingly manipulate remote files and shells. 
* [[egit|http://git.or.cz/gitwiki/EclipsePlugin]] -- git integration plugin -- is still on early stages of development with very limited functionality and must be compiled from source, but it already provides a visual history viewer similar to gitk.