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