Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 1 | # Use Qt Creator as an IDE or debugger UI |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 2 | |
| 3 | [Qt Creator](https://www.qt.io/ide/) |
chaopeng | 6122d4c | 2017-09-01 19:40:05 | [diff] [blame] | 4 | ([Wiki](https://en.wikipedia.org/wiki/Qt_Creator)) is a cross-platform C++ IDE. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 5 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 6 | You can use Qt Creator as a daily IDE or just as a GDB frontend (which does |
| 7 | not require project configuration). |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 8 | |
| 9 | [TOC] |
| 10 | |
| 11 | ## IDE |
| 12 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 13 | ### Workflow features |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 14 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 15 | * Built-in code completion. |
| 16 | * Navigate to classes, files, or symbols with `ctrl+k`. |
| 17 | * Switch between declaration and definition with `F2`. |
| 18 | * Build with `ctrl+shift+b`. |
| 19 | * Build and run with `ctrl+r`, or debug with `F5`. |
| 20 | * Switch between the header file and cpp file with `F4`. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 21 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 22 | ### Setup |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 23 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 24 | 1. Install the latest Qt Creator. |
| 25 | 2. Under chromium/src `gn gen out/Default --ide=qtcreator`. |
| 26 | 3. Start it with `qtcreator out/Default/qtcreator_project/all.creator`. |
| 27 | 4. Help - Plugins - check ClangCodeModel to enable std completion. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 28 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 29 | It takes 3 minutes to parse all of chrome's C++ files on my workstation!!! And |
| 30 | it does not block while parsing. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 31 | |
| 32 | #### Code Style |
| 33 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 34 | 1. Help - About Plugins, enable Beautifier. |
chaopeng | 6122d4c | 2017-09-01 19:40:05 | [diff] [blame] | 35 | 2. Tools - Options - Beautifier - Clang Format, |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 36 | change the Clang format command to: `$depot_tools_dir/clang-format`, and |
| 37 | set `Use predefined style: file`. You can also set a keyboard shortcut |
| 38 | for it. |
| 39 | 3. Tools - Options - Code Style, import this xml file. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 40 | |
| 41 | ``` |
| 42 | <?xml version="1.0" encoding="UTF-8"?> |
| 43 | <!DOCTYPE QtCreatorCodeStyle> |
| 44 | <!-- Written by QtCreator 4.2.1, 2017-02-08T19:07:34. --> |
| 45 | <qtcreator> |
| 46 | <data> |
| 47 | <variable>CodeStyleData</variable> |
| 48 | <valuemap type="QVariantMap"> |
| 49 | <value type="bool" key="AlignAssignments">true</value> |
| 50 | <value type="bool" key="AutoSpacesForTabs">false</value> |
| 51 | <value type="bool" key="BindStarToIdentifier">false</value> |
| 52 | <value type="bool" key="BindStarToLeftSpecifier">false</value> |
| 53 | <value type="bool" key="BindStarToRightSpecifier">false</value> |
| 54 | <value type="bool" key="BindStarToTypeName">true</value> |
chaopeng | 6122d4c | 2017-09-01 19:40:05 | [diff] [blame] | 55 | <value type="bool" |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 56 | key="ExtraPaddingForConditionsIfConfusingAlign">true</value> |
| 57 | <value type="bool" key="IndentAccessSpecifiers">true</value> |
| 58 | <value type="bool" key="IndentBlockBody">true</value> |
| 59 | <value type="bool" key="IndentBlockBraces">false</value> |
| 60 | <value type="bool" key="IndentBlocksRelativeToSwitchLabels">false</value> |
| 61 | <value type="bool" key="IndentClassBraces">false</value> |
| 62 | <value type="bool" key="IndentControlFlowRelativeToSwitchLabels">true</value> |
| 63 | <value type="bool" |
| 64 | key="IndentDeclarationsRelativeToAccessSpecifiers">false</value> |
| 65 | <value type="bool" key="IndentEnumBraces">false</value> |
| 66 | <value type="bool" key="IndentFunctionBody">true</value> |
| 67 | <value type="bool" key="IndentFunctionBraces">false</value> |
| 68 | <value type="bool" key="IndentNamespaceBody">false</value> |
| 69 | <value type="bool" key="IndentNamespaceBraces">false</value> |
| 70 | <value type="int" key="IndentSize">2</value> |
| 71 | <value type="bool" key="IndentStatementsRelativeToSwitchLabels">true</value> |
| 72 | <value type="bool" key="IndentSwitchLabels">false</value> |
| 73 | <value type="int" key="PaddingMode">2</value> |
| 74 | <value type="bool" key="ShortGetterName">true</value> |
| 75 | <value type="bool" key="SpacesForTabs">true</value> |
| 76 | <value type="int" key="TabSize">2</value> |
| 77 | </valuemap> |
| 78 | </data> |
| 79 | <data> |
| 80 | <variable>DisplayName</variable> |
| 81 | <value type="QString">chrome</value> |
| 82 | </data> |
| 83 | </qtcreator> |
| 84 | ``` |
| 85 | |
| 86 | #### Build & Run |
| 87 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 88 | 1. (Optional) Enable the issues pane for easy navigation to the location of |
| 89 | compiler errors. qtcreator expects to find compiler errors on stderr, but |
| 90 | ninja forwards all subcommand output to stdout. So use the following wrapper |
| 91 | script to forward it to stderr instead. |
| 92 | ``` |
| 93 | #!/bin/sh |
| 94 | /path/to/depot_tools/ninja "$@" >&2 |
| 95 | ``` |
| 96 | 2. In the left panel - Projects, set up the ninja command in the build and |
| 97 | clean steps, and add the path to chrome in the run configuration. |
| 98 | |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 99 | |
| 100 | ## Debugger |
| 101 | |
chaopeng | 6122d4c | 2017-09-01 19:40:05 | [diff] [blame] | 102 | **You can skip the project settings and use QtCreator as a single file |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 103 | standalone GDB frontend.** |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 104 | |
| 105 | 1. Tools - Options - Build & Run - Debuggers, make sure GDB is set. |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 106 | 2. Tools - Options - Kits, change the Desktop kit to GDB (LLDB doesn't work on |
| 107 | Linux). |
| 108 | 3. Open the file you want to debug. |
chaopeng | 6122d4c | 2017-09-01 19:40:05 | [diff] [blame] | 109 | 4. Debug - Start Debugging - Attach to running Application, you may need to |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 110 | open chrome's task manager to find the process id. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 111 | |
| 112 | ### Tips, tricks, and troubleshooting |
| 113 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 114 | #### The debugger exits immediately |
| 115 | |
| 116 | Ensure yama allows you to attach to another process: |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 117 | |
| 118 | ``` |
| 119 | $ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope |
| 120 | ``` |
| 121 | |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 122 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 123 | #### The debugger does not stop on breakpoints |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 124 | |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 125 | Ensure you are using GDB on Linux, not LLDB. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 126 | |
| 127 | #### More |
| 128 | |
chaopeng | 6122d4c | 2017-09-01 19:40:05 | [diff] [blame] | 129 | See |
Chris Watkins | 7374d03 | 2017-09-27 01:46:39 | [diff] [blame] | 130 | https://chromium.googlesource.com/chromium/src/+/master/docs/linux_debugging.md |