andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 1 | # Linux Eclipse Dev |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 3 | Eclipse can be used on Linux (and probably Windows and Mac) as an IDE for |
| 4 | developing Chromium. It's unpolished, but here's what works: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 5 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 6 | * Editing code works well (especially if you're used to it or Visual Studio). |
| 7 | * Navigating around the code works well. There are multiple ways to do this |
| 8 | (F3, control-click, outlines). |
| 9 | * Building works fairly well and it does a decent job of parsing errors so |
| 10 | that you can click and jump to the problem spot. |
| 11 | * Debugging is hit & miss. You can set breakpoints and view variables. STL |
| 12 | containers give it (and gdb) a bit of trouble. Also, the debugger can get |
| 13 | into a bad state occasionally and eclipse will need to be restarted. |
| 14 | * Refactoring seems to work in some instances, but be afraid of refactors that |
| 15 | touch a lot of files. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 16 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 17 | [TOC] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 18 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 19 | ## Setup |
| 20 | |
| 21 | ### Get & Configure Eclipse |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 22 | |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 23 | Eclipse 4.6.1 (Neon) is known to work with Chromium for Linux. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 24 | |
nodir | a6074d4c | 2015-09-01 04:26:45 | [diff] [blame] | 25 | * [Download](http://www.eclipse.org/downloads/) the distribution appropriate |
| 26 | for your OS. For example, for Linux 64-bit/Java 64-bit, use the Linux 64 bit |
| 27 | package (Eclipse Packages Tab -> Linux 64 bit (link in bottom right)). |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 28 | * Tip: The packaged version of eclipse in distros may not work correctly |
| 29 | with the latest CDT plugin (installed below). Best to get them all from |
| 30 | the same source. |
| 31 | * Googlers: The version installed on Goobuntu works fine. The UI will be |
| 32 | much more responsive if you do not install the google3 plug-ins. Just |
| 33 | uncheck all the boxes at first launch. |
| 34 | * Unpack the distribution and edit the eclipse/eclipse.ini to increase the |
| 35 | heap available to java. For instance: |
| 36 | * Change `-Xms40m` to `-Xms1024m` (minimum heap) and `-Xmx256m` to |
| 37 | `-Xmx3072m` (maximum heap). |
| 38 | * Googlers: Edit `~/.eclipse/init.sh` to add this: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 39 | |
nodir | a6074d4c | 2015-09-01 04:26:45 | [diff] [blame] | 40 | ``` |
| 41 | export ECLIPSE_MEM_START="1024M" |
| 42 | export ECLIPSE_MEM_MAX="3072M" |
| 43 | ``` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 44 | |
| 45 | The large heap size prevents out of memory errors if you include many Chrome |
| 46 | subprojects that Eclipse is maintaining code indices for. |
| 47 | |
| 48 | * Turn off Hyperlink detection in the Eclipse preferences. (Window -> |
| 49 | Preferences, search for "Hyperlinking, and uncheck "Enable on demand |
| 50 | hyperlink style navigation"). |
| 51 | |
| 52 | Pressing the control key on (for keyboard shortcuts such as copy/paste) can |
| 53 | trigger the hyperlink detector. This occurs on the UI thread and can result in |
| 54 | the reading of jar files on the Eclipse classpath, which can tie up the editor |
| 55 | due to the size of the classpath in Chromium. |
| 56 | |
| 57 | ### A short word about paths |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 58 | |
| 59 | Before you start setting up your work space - here are a few hints: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 60 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 61 | * Don't put your checkout on a remote file system (e.g. NFS filer). It's too |
| 62 | slow both for building and for Eclipse. |
| 63 | * Make sure there is no file system link in your source path because Ninja |
| 64 | will resolve it for a faster build and Eclipse / GDB will get confused. |
| 65 | (Note: This means that the source will possibly not reside in your user |
| 66 | directory since it would require a link from filer to your local |
| 67 | repository.) |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 68 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 69 | ### Run Eclipse & Set your workspace |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 70 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 71 | Run eclipse/eclipse in a way that your regular build environment (export CC, |
| 72 | CXX, etc...) will be visible to the eclipse process. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 73 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 74 | Set the Workspace to be a directory on a local disk (e.g. |
| 75 | `/work/workspaces/chrome`). Placing it on an NFS share is not recommended -- |
| 76 | it's too slow and Eclipse will block on access. Don't put the workspace in the |
| 77 | same directory as your checkout. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 78 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 79 | ### Install the C Development Tools ("CDT") |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 80 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 81 | 1. From the Help menu, select Install New Software... |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 82 | 1. Select the 'Work with' URL for the CDT |
nodir | a6074d4c | 2015-09-01 04:26:45 | [diff] [blame] | 83 | If it's not there you can click Add... and add it. |
| 84 | See https://eclipse.org/cdt/downloads.php for up to date versions, |
| 85 | e.g. with CDT 8.7.0 for Eclipse Mars, use |
| 86 | http://download.eclipse.org/tools/cdt/releases/8.7 |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 87 | 1. Googlers: We have a local mirror, but be sure you run prodaccess before |
| 88 | trying to use it. |
| 89 | 1. Select & install the Main and Optional features. |
| 90 | 1. Restart Eclipse |
| 91 | 1. Go to Window > Open Perspective > Other... > C/C++ to switch to the C++ |
| 92 | perspective (window layout). |
| 93 | 1. Right-click on the "Java" perspective in the top-right corner and select |
| 94 | "Close" to remove it. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 95 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 96 | ### Create your project(s) |
| 97 | |
| 98 | First, turn off automatic workspace refresh and automatic building, as Eclipse |
| 99 | tries to do these too often and gets confused: |
| 100 | |
| 101 | 1. Open Window > Preferences |
| 102 | 1. Search for "workspace" |
| 103 | 1. Turn off "Build automatically" |
| 104 | 1. Turn off "Refresh using native hooks or polling" |
| 105 | 1. Click "Apply" |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 106 | |
| 107 | Create a single Eclipse project for everything: |
| 108 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 109 | 1. From the File menu, select New > Project... |
| 110 | 1. Select C/C++ Project > Makefile Project with Existing Code |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 111 | 1. Name the project the exact name of the directory: "src" (or "WebKit" if you |
| 112 | mainly work in Blink and want a faster experience) |
| 113 | 1. Provide a path to the code, like /work/chromium/src (or |
| 114 | /work/chromium/src/third_party/WebKit) |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 115 | 1. Select toolchain: Linux GCC |
| 116 | 1. Click Finish. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 117 | |
Allen Webb | 99a494a | 2019-04-16 18:25:06 | [diff] [blame] | 118 | Chromium uses C++14, so tell the indexer about it. Otherwise it will get |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 119 | confused about things like std::unique_ptr. |
| 120 | |
| 121 | 1. Right-click on "src" and select "Properties..." |
| 122 | 1. Navigate to C/C++ General > Preprocess Include Paths, Macros etc. > |
| 123 | Providers |
| 124 | 1. Select CDT GCC Built-in Compiler Settings |
Allen Webb | 99a494a | 2019-04-16 18:25:06 | [diff] [blame] | 125 | 1. In the text box entitled Command to get compiler specs append "-std=c++14" |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 126 | (leaving out the quotes) |
| 127 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 128 | Chromium has a huge amount of code, enough that Eclipse can take a very long |
| 129 | time to perform operations like "go to definition" and "open resource". You need |
| 130 | to set it up to operate on a subset of the code. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 131 | |
| 132 | In the Project Explorer on the left side: |
| 133 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 134 | 1. Right-click on "src" and select "Properties..." |
| 135 | 1. Open Resource > Resource Filters |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 136 | 1. Click "Add Filter..." |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 137 | 1. Add the following filter: |
| 138 | * Include only |
| 139 | * Files, all children (recursive) |
| 140 | * Name matches |
mfomitchev | 95f20f1 | 2016-06-09 17:37:34 | [diff] [blame] | 141 | `.*\.(c|cc|cpp|h|mm|inl|idl|js|json|css|html|gyp|gypi|grd|grdp|gn|gni|mojom)` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 142 | regular expression |
| 143 | 1. Add another filter: |
| 144 | * Exclude all |
| 145 | * Folders |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 146 | * Name matches `out_.*|\.git|web_tests` regular expression |
| 147 | * If you aren't working on WebKit, adding `|blink` will remove more |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 148 | files |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 149 | 1. Click "Apply and Close" |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 150 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 151 | Don't exclude the primary "out" directory, as it contains generated header files |
| 152 | for things like string resources and Eclipse will miss a lot of symbols if you |
| 153 | do. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 154 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 155 | Eclipse will refresh the workspace and start indexing your code. It won't find |
| 156 | most header files, however. Give it more help finding them: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 157 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 158 | 1. Open Window > Preferences |
| 159 | 1. Search for "Indexer" |
| 160 | 1. Turn on "Allow heuristic resolution of includes" |
| 161 | 1. Select "Use active build configuration" |
| 162 | 1. Set Cache limits > Index database > Limit relative... to 20% |
| 163 | 1. Set Cache limits > Index database > Absolute limit to 256 MB |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 164 | 1. Click "Apply and Close" |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 165 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 166 | Now the indexer will find many more include files, regardless of which approach |
| 167 | you take below. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 168 | |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 169 | Eclipse will still complain about unresolved includes or invalid declarations |
| 170 | (semantic errors or code analysis errors in the ```Problems``` tab), |
| 171 | which you can set eclipse to ignore: |
| 172 | |
| 173 | 1. Right-click on "src" and select "Properties..." |
| 174 | * Open C++ General > Code Analysis |
| 175 | * Change the severity from ```Error``` to ```Warning``` for each of the |
| 176 | settings that you want eclipse to ignore. |
| 177 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 178 | #### Optional: Manual header paths and symbols |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 179 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 180 | You can manually tell Eclipse where to find header files, which will allow it to |
| 181 | create the source code index before you do a real build. |
| 182 | |
| 183 | 1. Right-click on "src" and select "Properties..." |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 184 | * Open C++ General > Paths and Symbols > Includes |
| 185 | * Click "GNU C++" |
| 186 | * Click "Add..." |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 187 | * Add `/path/to/chromium/src` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 188 | * Check "Add to all configurations" and "Add to all languages" |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 189 | 1. Repeat the above for: |
| 190 | * `/path/to/chromium/src/testing/gtest/include` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 191 | |
| 192 | You may also find it helpful to define some symbols. |
| 193 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 194 | 1. Add `OS_LINUX`: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 195 | * Select the "Symbols" tab |
| 196 | * Click "GNU C++" |
| 197 | * Click "Add..." |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 198 | * Add name `OS_LINUX` with value 1 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 199 | * Click "Add to all configurations" and "Add to all languages" |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 200 | 1. Repeat for `ENABLE_EXTENSIONS 1` |
| 201 | 1. Repeat for `HAS_OUT_OF_PROC_TEST_RUNNER 1` |
| 202 | 1. Click "OK". |
| 203 | 1. Eclipse will ask if you want to rebuild the index. Click "Yes". |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 204 | |
| 205 | Let the C++ indexer run. It will take a while (10s of minutes). |
| 206 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 207 | ### Optional: Building inside Eclipse |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 208 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 209 | This allows Eclipse to automatically discover include directories and symbols. |
| 210 | If you use gold or ninja (both recommended) you'll need to tell Eclipse about |
| 211 | your path. |
| 212 | |
| 213 | 1. echo $PATH from a shell and copy it to the clipboard |
| 214 | 1. Open Window > Preferences > C/C++ > Build > Environment |
| 215 | 1. Select "Replace native environment with specified one" (since gold and ninja |
| 216 | must be at the start of your path) |
| 217 | 1. Click "Add..." |
| 218 | 1. For name, enter `PATH` |
| 219 | 1. For value, paste in your path with the ninja and gold directories. |
| 220 | 1. Click "OK" |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 221 | |
| 222 | To create a Make target: |
| 223 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 224 | 1. From the Window menu, select Show View > Make Target |
| 225 | 1. In the Make Target view, right-click on the project and select New... |
| 226 | 1. name the target (e.g. base\_unittests) |
| 227 | 1. Unclick the Build Command: Use builder Settings and type whatever build |
| 228 | command you would use to build this target (e.g. |
| 229 | `ninja -C out/Debug base_unittests`). |
| 230 | 1. Return to the project properties page a under the C/C++ Build, change the |
| 231 | Build Location/Build Directory to be /path/to/chromium/src |
| 232 | 1. In theory `${workspace_loc}` should work, but it doesn't for me. |
| 233 | 1. If you put your workspace in `/path/to/chromium`, then |
| 234 | `${workspace_loc:/src}` will work too. |
| 235 | 1. Now in the Make Targets view, select the target and click the hammer icon |
| 236 | (Build Make Target). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 237 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 238 | You should see the build proceeding in the Console View and errors will be |
| 239 | parsed and appear in the Problems View. (Note that sometimes multi-line compiler |
| 240 | errors only show up partially in the Problems view and you'll want to look at |
| 241 | the full error in the Console). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 242 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 243 | (Eclipse 3.8 has a bug where the console scrolls too slowly if you're doing a |
Takuto Ikuta | 7478af72 | 2024-05-27 07:23:19 | [diff] [blame] | 244 | fast build, e.g. with reclient. To work around, go to Window > Preferences and |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 245 | search for "console". Under C/C++ console, set "Limit console output" to |
| 246 | 2147483647, the maximum value.) |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 247 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 248 | ### Optional: Multiple build targets |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 249 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 250 | If you want to build multiple different targets in Eclipse (`chrome`, |
| 251 | `unit_tests`, etc.): |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 252 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 253 | 1. Window > Show Toolbar (if you had it off) |
| 254 | 1. Turn on special toolbar menu item (hammer) or menu bar item (Project > Build |
| 255 | configurations > Set Active > ...) |
| 256 | 1. Window > Customize Perspective... > "Command Groups Availability" |
| 257 | 1. Check "Build configuration" |
| 258 | 1. Add more Build targets |
| 259 | 1. Project > Properties > C/C++ Build > Manage Configurations |
| 260 | 1. Select "New..." |
| 261 | 1. Duplicate from current and give it a name like "Unit tests". |
| 262 | 1. Change under “Behavior” > Build > the target to e.g. `unit_tests`. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 263 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 264 | You can also drag the toolbar to the bottom of your window to save vertical |
| 265 | space. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 266 | |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 267 | ### Optional: Running inside eclipse |
| 268 | |
| 269 | Running inside eclipse is fairly straightforward: |
| 270 | |
| 271 | 1. Create a ```C/C++ Application```: |
| 272 | 1. ```Run``` > ```Run configurations``` |
| 273 | 2. Double click on ```C/C++ Application``` |
| 274 | 3. Pick a name (e.g. ```shell```) |
| 275 | 4. Point to ```C/C++ Application``` |
| 276 | (e.g. ```src/out/Default/content_shell```) |
| 277 | 6. Click ```Debug``` to run the program. |
| 278 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 279 | ### Optional: Debugging |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 280 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 281 | 1. From the toolbar at the top, click the arrow next to the debug icon and |
| 282 | select Debug Configurations... |
| 283 | 1. Select C/C++ Application and click the New Launch Configuration icon. This |
| 284 | will create a new run/debug con figuration under the C/C++ Application header. |
| 285 | 1. Name it something useful (e.g. `base_unittests`). |
| 286 | 1. Under the Main Tab, enter the path to the executable (e.g. |
| 287 | `.../out/Debug/base_unittests`) |
| 288 | 1. Select the Debugger Tab, select Debugger: gdb and unclick "Stop on startup |
| 289 | in (main)" unless you want this. |
| 290 | 1. Set a breakpoint somewhere in your code and click the debug icon to start |
| 291 | debugging. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 292 | |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 293 | #### Multi-process debugging |
| 294 | |
| 295 | If you set breakpoints and your debugger session doesn't stop it is because |
| 296 | both ```chrome``` and ```content_shell ``` spawn sub-processes. |
| 297 | To debug, you need to attach a debugger to one of those sub-processes. |
| 298 | |
| 299 | Eclipse can attach automatically to forked processes |
| 300 | (Run -> Debug configurations -> Debugger tab), but that doesn't seem to |
| 301 | work well. |
| 302 | |
| 303 | The overall idea is described [here](https://www.chromium.org/blink/getting-started-with-blink-debugging) |
| 304 | , but one way to accomplish this in eclipse is to run two ```Debug configurations```: |
| 305 | |
| 306 | 1. Create a ```C/C++ Application```: |
| 307 | 1. ```Run``` > ```Debug configurations``` |
| 308 | 2. Double click on ```C/C++ Application``` |
| 309 | 3. Pick a name (e.g. ```shell```) |
| 310 | 4. Point to ```C/C++ Application``` |
| 311 | (e.g. ```src/out/Default/content_shell```) |
| 312 | 5. In the arguments tab, add the following the to program arguments: |
| 313 | ```--no-sandbox --renderer-startup-dialog test.html``` |
| 314 | 6. Click ```Debug``` to run the program. |
| 315 | 7. That will run the application and it will stop with a message like the |
| 316 | following: |
| 317 | ```Renderer (239930) paused waiting for debugger to attach. Send SIGUSR1 to unpause.``` |
| 318 | 9. ```239930``` is the number of the process running waiting for the ```signal```. |
| 319 | 2. Create a ```C/C++ Attach to Application```: |
Sam Goto | 1c5787d | 2019-02-12 00:49:16 | [diff] [blame] | 320 | 1. ```Run``` > ```Debug configurations``` |
| 321 | 2. Double click on ```C/C++ Attach to Application``` |
| 322 | 3. Pick a name (e.g. ```shell proc```) |
| 323 | 4. Click ```Debug``` to run the configuration. |
| 324 | 5. In the ```Select Processes``` dialog, pick the process that was |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 325 | spawned above (if you type ```content_shell``` it will filter by |
| 326 | name) |
Sam Goto | 1c5787d | 2019-02-12 00:49:16 | [diff] [blame] | 327 | 6. Click on ```Debugger console``` to access the ```gdb``` console. |
| 328 | 7. Send the original process a signal |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 329 | ```signal SIGUSR1``` |
Sam Goto | 1c5787d | 2019-02-12 00:49:16 | [diff] [blame] | 330 | 8. That should unblock the original process and you should now be able to |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 331 | set breakpoints. |
| 332 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 333 | ### Optional: Accurate symbol information |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 334 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 335 | If setup properly, Eclipse can do a great job of semantic navigation of C++ code |
| 336 | (showing type hierarchies, finding all references to a particular method even |
| 337 | when other classes have methods of the same name, etc.). But doing this well |
| 338 | requires the Eclipse knows correct include paths and pre-processor definitions. |
| 339 | After fighting with with a number of approaches, I've found the below to work |
| 340 | best for me. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 341 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 342 | 1. From a shell in your src directory, run |
dgrogan | fbd6de9 | 2017-05-05 18:06:06 | [diff] [blame] | 343 | `gn gen --ide=eclipse out/Debug/` (replacing Debug with the output directory you normally use when building). |
| 344 | 1. This generates <project root>/out/Debug/eclipse-cdt-settings.xml which |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 345 | is used below. |
| 346 | 1. This creates a single list of include directories and preprocessor |
| 347 | definitions to be used for all source files, and so is a little |
| 348 | inaccurate. Here are some tips for compensating for the limitations: |
qyearsley | c0dc6f4 | 2016-12-02 22:13:39 | [diff] [blame] | 349 | 1. If you care about blink, move 'third\_party/WebKit/Source' to the |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 350 | top of the list to better resolve ambiguous include paths (eg. |
| 351 | `config.h`). |
| 352 | 1. Import paths and symbols |
| 353 | 1. Right click on the project and select Properties > C/C++ General > Paths |
| 354 | and Symbols |
| 355 | 1. Click Restore Defaults to clear any old settings |
| 356 | 1. Click Import Settings... > Browse... and select |
| 357 | `<project root>/out/Debug/eclipse-cdt-settings.xml` |
| 358 | 1. Click the Finish button. The entire preferences dialog should go away. |
| 359 | 1. Right click on the project and select Index > Rebuild |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 360 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 361 | ### Alternative: Per-file accurate include/pre-processor information |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 362 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 363 | Instead of generating a fixed list of include paths and pre-processor |
| 364 | definitions for a project (above), it is also possible to have Eclipse determine |
| 365 | the correct setting on a file-by-file basis using a built output parser. I |
| 366 | (rbyers) used this successfully for a long time, but it doesn't seem much better |
| 367 | in practice than the simpler (and less bug-prone) approach above. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 368 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 369 | 1. Install the latest version of Eclipse IDE for C/C++ developers |
| 370 | ([Juno SR1](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/junosr1) |
| 371 | at the time of this writing) |
| 372 | 1. Setup build to generate a build log that includes the g++ command lines for |
| 373 | the files you want to index: |
| 374 | 1. Project Properties -> C/C++ Build |
| 375 | 1. Uncheck "Use default build command" |
| 376 | 1. Enter your build command, eg: `ninja -v` |
| 377 | 1. Note that for better performance, you can use a command that |
| 378 | doesn't actually builds, just prints the commands that would be |
| 379 | run. For ninja/make this means adding -n. This only prints the |
| 380 | compile commands for changed files (so be sure to move your |
| 381 | existing out directory out of the way temporarily to force a |
| 382 | full "build"). ninja also supports "-t commands" which will |
| 383 | print all build commands for the specified target and runs even |
| 384 | faster as it doesn't have to check file timestamps. |
| 385 | 1. Build directory: your build path including out/Debug |
| 386 | 1. Note that for the relative paths to be parsed correctly you |
| 387 | can't use ninja's `-C <dir>` to change directories as you might |
| 388 | from the command line. |
| 389 | 1. Build: potentially change `all` to the target you want to analyze, |
| 390 | eg. `chrome` |
| 391 | 1. Deselect 'clean' |
| 392 | 1. If you're using Ninja, you need to teach eclipse to ignore the prefix it |
| 393 | adds (eg. `[10/1234]` to each line in build output): |
| 394 | 1. Project properties -> C/C++ General -> Preprocessor includes |
| 395 | 1. Providers -> CDT GCC Build Output Parser -> Compiler command pattern |
| 396 | 1. `(\[.*\] )?((gcc)|([gc]\+\+)|(clang(\+\+)?))` |
| 397 | 1. Note that there appears to be a bug with "Share setting entries |
| 398 | between projects" - it will keep resetting to off. I suggest using |
| 399 | per-project settings and using the "folder" as the container to keep |
| 400 | discovered entries ("file" may work as well). |
| 401 | 1. Eclipse / GTK has bugs where lots of output to the build console can |
| 402 | slow down the UI dramatically and cause it to hang (basically spends all |
| 403 | it's time trying to position the cursor correctly in the build console |
| 404 | window). To avoid this, close the console window and disable |
| 405 | automatically opening it on build: |
| 406 | 1. Preferences->C/C++->Build->Console -> Uncheck "Open console when |
| 407 | building" |
| 408 | 1. note you can still see the build log in |
| 409 | `<workspace>/.metadata/.plugins/org.eclipse.cdt.ui` |
| 410 | 1. Now build the project (select project, click on hammer). If all went well: |
| 411 | 1. Right click on a cpp file -> properties -> C/C++ general -> Preprocessor |
| 412 | includes -> GNU C++ -> CDT GCC Build output Parser |
| 413 | 1. You will be able to expand and see all the include paths and |
| 414 | pre-processor definitions used for this file |
| 415 | 1. Rebuild index (right-click on project, index, rebuild). If all went well: |
| 416 | 1. Open a CPP file and look at problems windows |
| 417 | 1. Should be no (or very few) errors |
| 418 | 1. Should be able to hit F3 on most symbols and jump to their definitioin |
| 419 | 1. CDT has some issues with complex C++ syntax like templates (eg. |
| 420 | `PassOwnPtr` functions) |
| 421 | 1. See |
| 422 | [this page](http://wiki.eclipse.org/CDT/User/FAQ#Why_does_Open_Declaration_.28F3.29_not_work.3F_.28also_applies_to_other_functions_using_the_indexer.29) |
| 423 | for more information. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 424 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 425 | ### Optional: static code and style guide analysis using cpplint.py |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 426 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 427 | 1. From the toolbar at the top, click the Project -> Properties and go to |
| 428 | C/C++Build. |
| 429 | 1. Click on the right side of the pop up windows, "Manage |
| 430 | Configurations...", then on New, and give it a name, f.i. "Lint current |
| 431 | file", and close the small window, then select it in the Configuration |
| 432 | drop down list. |
| 433 | 1. Under Builder settings tab, unclick "Use default build command" and type |
| 434 | as build command the full path to your `depot_tools/cpplint.py` |
| 435 | 1. Under behaviour tab, unselect Clean, select Build(incremental build) and |
| 436 | in Make build target, add `--verbose=0 ${selected_resource_loc}` |
| 437 | 1. Go back to the left side of the current window, and to C/C++Build -> |
| 438 | Settings, and click on error parsers tab, make sure CDT GNU C/C++ Error |
| 439 | Parser, CDT pushd/popd CWD Locator are set, then click Apply and OK. |
| 440 | 1. Select a file and click on the hammer icon drop down triangle next to it, |
| 441 | and make sure the build configuration is selected "Lint current file", then |
| 442 | click on the hammer. |
| 443 | 1. Note: If you get the `cpplint.py help` output, make sure you have selected a |
| 444 | file, by clicking inside the editor window or on its tab header, and make |
| 445 | sure the editor is not maximized inside Eclipse, i.e. you should see more |
| 446 | subwindows around. |
| 447 | |
| 448 | ### Additional tips |
| 449 | |
| 450 | 1. Mozilla's |
| 451 | [Eclipse CDT guide](https://developer.mozilla.org/en-US/docs/Eclipse_CDT) |
| 452 | is helpful: |
| 453 | 1. For improved performance, I use medium-granularity projects (eg. one for |
| 454 | WebKit/Source) instead of putting all of 'src/' in one project. |
Sam Goto | 0a2b48e | 2019-02-04 19:53:39 | [diff] [blame] | 455 | 1. Running [```content_shell```](https://www.chromium.org/developers/content-module) |
| 456 | as opposed to all of ```chrome``` is a lot faster/smaller. |