docs/linux/eclipse_dev.md
Eclipse can be used on Linux (and probably Windows and Mac) as an IDE for developing Chromium. It's unpolished, but here's what works:
[TOC]
Eclipse 4.6.1 (Neon) is known to work with Chromium for Linux.
-Xms40m to -Xms1024m (minimum heap) and -Xmx256m to
-Xmx3072m (maximum heap).~/.eclipse/init.sh to add this:export ECLIPSE_MEM_START="1024M"
export ECLIPSE_MEM_MAX="3072M"
The large heap size prevents out of memory errors if you include many Chrome subprojects that Eclipse is maintaining code indices for.
Pressing the control key on (for keyboard shortcuts such as copy/paste) can trigger the hyperlink detector. This occurs on the UI thread and can result in the reading of jar files on the Eclipse classpath, which can tie up the editor due to the size of the classpath in Chromium.
Before you start setting up your work space - here are a few hints:
Run eclipse/eclipse in a way that your regular build environment (export CC, CXX, etc...) will be visible to the eclipse process.
Set the Workspace to be a directory on a local disk (e.g.
/work/workspaces/chrome). Placing it on an NFS share is not recommended --
it's too slow and Eclipse will block on access. Don't put the workspace in the
same directory as your checkout.
First, turn off automatic workspace refresh and automatic building, as Eclipse tries to do these too often and gets confused:
Create a single Eclipse project for everything:
Chromium uses C++14, so tell the indexer about it. Otherwise it will get confused about things like std::unique_ptr.
Chromium has a huge amount of code, enough that Eclipse can take a very long time to perform operations like "go to definition" and "open resource". You need to set it up to operate on a subset of the code.
In the Project Explorer on the left side:
.*\.(c|cc|cpp|h|mm|inl|idl|js|json|css|html|gyp|gypi|grd|grdp|gn|gni|mojom)
regular expressionout_.*|\.git|web_tests regular expression
|blink will remove more
filesDon't exclude the primary "out" directory, as it contains generated header files for things like string resources and Eclipse will miss a lot of symbols if you do.
Eclipse will refresh the workspace and start indexing your code. It won't find most header files, however. Give it more help finding them:
Now the indexer will find many more include files, regardless of which approach you take below.
Eclipse will still complain about unresolved includes or invalid declarations
(semantic errors or code analysis errors in the Problems tab),
which you can set eclipse to ignore:
Error to Warning for each of the
settings that you want eclipse to ignore.You can manually tell Eclipse where to find header files, which will allow it to create the source code index before you do a real build.
/path/to/chromium/src/path/to/chromium/src/testing/gtest/includeYou may also find it helpful to define some symbols.
OS_LINUX:
OS_LINUX with value 1ENABLE_EXTENSIONS 1HAS_OUT_OF_PROC_TEST_RUNNER 1Let the C++ indexer run. It will take a while (10s of minutes).
This allows Eclipse to automatically discover include directories and symbols. If you use gold or ninja (both recommended) you'll need to tell Eclipse about your path.
PATHTo create a Make target:
ninja -C out/Debug base_unittests).${workspace_loc} should work, but it doesn't for me./path/to/chromium, then
${workspace_loc:/src} will work too.You should see the build proceeding in the Console View and errors will be parsed and appear in the Problems View. (Note that sometimes multi-line compiler errors only show up partially in the Problems view and you'll want to look at the full error in the Console).
(Eclipse 3.8 has a bug where the console scrolls too slowly if you're doing a fast build, e.g. with reclient. To work around, go to Window > Preferences and search for "console". Under C/C++ console, set "Limit console output" to 2147483647, the maximum value.)
If you want to build multiple different targets in Eclipse (chrome,
unit_tests, etc.):
unit_tests.You can also drag the toolbar to the bottom of your window to save vertical space.
Running inside eclipse is fairly straightforward:
C/C++ Application:
Run > Run configurationsC/C++ Applicationshell)C/C++ Application
(e.g. src/out/Default/content_shell)Debug to run the program.base_unittests)..../out/Debug/base_unittests)If you set breakpoints and your debugger session doesn't stop it is because
both chrome and content_shell spawn sub-processes.
To debug, you need to attach a debugger to one of those sub-processes.
Eclipse can attach automatically to forked processes (Run -> Debug configurations -> Debugger tab), but that doesn't seem to work well.
The overall idea is described here
, but one way to accomplish this in eclipse is to run two Debug configurations:
C/C++ Application:
Run > Debug configurationsC/C++ Applicationshell)C/C++ Application
(e.g. src/out/Default/content_shell)--no-sandbox --renderer-startup-dialog test.htmlDebug to run the program.Renderer (239930) paused waiting for debugger to attach. Send SIGUSR1 to unpause.239930 is the number of the process running waiting for the signal.C/C++ Attach to Application:
Run > Debug configurationsC/C++ Attach to Applicationshell proc)Debug to run the configuration.Select Processes dialog, pick the process that was
spawned above (if you type content_shell it will filter by
name)Debugger console to access the gdb console.signal SIGUSR1If setup properly, Eclipse can do a great job of semantic navigation of C++ code (showing type hierarchies, finding all references to a particular method even when other classes have methods of the same name, etc.). But doing this well requires the Eclipse knows correct include paths and pre-processor definitions. After fighting with with a number of approaches, I've found the below to work best for me.
gn gen --ide=eclipse out/Debug/ (replacing Debug with the output directory you normally use when building).
config.h).<project root>/out/Debug/eclipse-cdt-settings.xmlInstead of generating a fixed list of include paths and pre-processor definitions for a project (above), it is also possible to have Eclipse determine the correct setting on a file-by-file basis using a built output parser. I (rbyers) used this successfully for a long time, but it doesn't seem much better in practice than the simpler (and less bug-prone) approach above.
ninja -v
-C <dir> to change directories as you might
from the command line.all to the target you want to analyze,
eg. chrome[10/1234] to each line in build output):
(\[.*\] )?((gcc)|([gc]\+\+)|(clang(\+\+)?))<workspace>/.metadata/.plugins/org.eclipse.cdt.uiPassOwnPtr functions)depot_tools/cpplint.py--verbose=0 ${selected_resource_loc}cpplint.py help output, make sure you have selected a
file, by clicking inside the editor window or on its tab header, and make
sure the editor is not maximized inside Eclipse, i.e. you should see more
subwindows around.content_shell
as opposed to all of chrome is a lot faster/smaller.