chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 1 | # Use Qt Creator as IDE or GUI Debugger |
| 2 | |
| 3 | [Qt Creator](https://www.qt.io/ide/) |
| 4 | ([Wiki](https://en.wikipedia.org/wiki/Qt_Creator)) is a cross-platform C++ IDE. |
| 5 | |
| 6 | You can use Qt Creator as a daily IDE or just as a GDB frontend and that does |
| 7 | not require project configuration. |
| 8 | |
| 9 | [TOC] |
| 10 | |
| 11 | ## IDE |
| 12 | |
| 13 | ### Workflow |
| 14 | |
chaopeng | 6fca2b0 | 2017-03-03 19:10:51 | [diff] [blame] | 15 | 1. `ctrl+k` Activate Locator, you can open file(not support sublime-like-search) |
| 16 | or type `. ` go to symbol. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 17 | 2. `ctrl+r` Build and Run, `F5` Debug. |
| 18 | 3. `F4` switch between header file and cpp file. |
| 19 | 4. `ctrl+shift+r` rename symbol under cursor. |
| 20 | 5. Code completion is built-in. And you can add your snippets. |
| 21 | |
| 22 | ### Setup as IDE |
| 23 | |
| 24 | 1. Install latest Qt Creator |
| 25 | 2. under chromium/src `gn gen out/Default --ide=qtcreator` |
| 26 | 3. qtcreator out/Default/qtcreator_project/all.creator |
| 27 | |
| 28 | It takes 3 minutes to parsing C++ files in my workstation!!! And It will not |
| 29 | block you while parsing. |
| 30 | |
| 31 | #### Code Style |
| 32 | |
| 33 | 1. Help - About Plugins enable Beautifier. |
chaopeng | 6fca2b0 | 2017-03-03 19:10:51 | [diff] [blame] | 34 | 2. Tools - Options - Beautifier - Clang Format, |
| 35 | change Clang format command: `$depot_tools_dir/clang-format`, select use |
| 36 | predefined style: file. You can also set a keyboard shortcut for it. |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 37 | 3. Tools - Options - Code Style import this xml file |
| 38 | |
| 39 | ``` |
| 40 | <?xml version="1.0" encoding="UTF-8"?> |
| 41 | <!DOCTYPE QtCreatorCodeStyle> |
| 42 | <!-- Written by QtCreator 4.2.1, 2017-02-08T19:07:34. --> |
| 43 | <qtcreator> |
| 44 | <data> |
| 45 | <variable>CodeStyleData</variable> |
| 46 | <valuemap type="QVariantMap"> |
| 47 | <value type="bool" key="AlignAssignments">true</value> |
| 48 | <value type="bool" key="AutoSpacesForTabs">false</value> |
| 49 | <value type="bool" key="BindStarToIdentifier">false</value> |
| 50 | <value type="bool" key="BindStarToLeftSpecifier">false</value> |
| 51 | <value type="bool" key="BindStarToRightSpecifier">false</value> |
| 52 | <value type="bool" key="BindStarToTypeName">true</value> |
| 53 | <value type="bool" |
| 54 | key="ExtraPaddingForConditionsIfConfusingAlign">true</value> |
| 55 | <value type="bool" key="IndentAccessSpecifiers">true</value> |
| 56 | <value type="bool" key="IndentBlockBody">true</value> |
| 57 | <value type="bool" key="IndentBlockBraces">false</value> |
| 58 | <value type="bool" key="IndentBlocksRelativeToSwitchLabels">false</value> |
| 59 | <value type="bool" key="IndentClassBraces">false</value> |
| 60 | <value type="bool" key="IndentControlFlowRelativeToSwitchLabels">true</value> |
| 61 | <value type="bool" |
| 62 | key="IndentDeclarationsRelativeToAccessSpecifiers">false</value> |
| 63 | <value type="bool" key="IndentEnumBraces">false</value> |
| 64 | <value type="bool" key="IndentFunctionBody">true</value> |
| 65 | <value type="bool" key="IndentFunctionBraces">false</value> |
| 66 | <value type="bool" key="IndentNamespaceBody">false</value> |
| 67 | <value type="bool" key="IndentNamespaceBraces">false</value> |
| 68 | <value type="int" key="IndentSize">2</value> |
| 69 | <value type="bool" key="IndentStatementsRelativeToSwitchLabels">true</value> |
| 70 | <value type="bool" key="IndentSwitchLabels">false</value> |
| 71 | <value type="int" key="PaddingMode">2</value> |
| 72 | <value type="bool" key="ShortGetterName">true</value> |
| 73 | <value type="bool" key="SpacesForTabs">true</value> |
| 74 | <value type="int" key="TabSize">2</value> |
| 75 | </valuemap> |
| 76 | </data> |
| 77 | <data> |
| 78 | <variable>DisplayName</variable> |
| 79 | <value type="QString">chrome</value> |
| 80 | </data> |
| 81 | </qtcreator> |
| 82 | ``` |
| 83 | |
| 84 | #### Build & Run |
| 85 | |
| 86 | In left panel, projects - setup the ninja command in build and clean step and |
| 87 | executable chrome path in run. |
| 88 | |
| 89 | ## Debugger |
| 90 | |
| 91 | **You can skip the project settings and use QtCreator as a single file |
| 92 | standalone GDB frontend. ** |
| 93 | |
| 94 | 1. Tools - Options - Build & Run - Debuggers, make sure GDB is set. |
| 95 | 2. Tools - Options - Kits, change the Desktop kit to GDB(LLDB doesnot work in |
| 96 | Linux). |
| 97 | 3. Open file you want to debug. |
| 98 | 4. Debug - Start Debugging - Attach to running Application, you may need to |
| 99 | open chrome's task manager to find the process number. |
| 100 | |
| 101 | ### Tips, tricks, and troubleshooting |
| 102 | |
chaopeng | 585eef9e | 2017-02-09 15:21:45 | [diff] [blame] | 103 | #### Debugger shows start then finish |
| 104 | |
| 105 | ``` |
| 106 | $ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope |
| 107 | ``` |
| 108 | |
| 109 | Ensure yama allow you to attach another process. |
| 110 | |
| 111 | #### Debugger do not stop in break point |
| 112 | |
| 113 | Ensure you are using GDB not LLDB in Linux. |
| 114 | |
| 115 | #### More |
| 116 | |
| 117 | See |
| 118 | https://chromium.googlesource.com/chromium/src/+/master/docs/linux_debugging.md |