blob: 38c0aa060b4bb06869dd43b89523be4a0b1fa5a9 [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
chaopeng6fca2b02017-03-03 19:10:51151. `ctrl+k` Activate Locator, you can open file(not support sublime-like-search)
16 or type `. ` go to symbol.
chaopeng585eef9e2017-02-09 15:21:45172. `ctrl+r` Build and Run, `F5` Debug.
183. `F4` switch between header file and cpp file.
194. `ctrl+shift+r` rename symbol under cursor.
205. Code completion is built-in. And you can add your snippets.
21
22### Setup as IDE
23
241. Install latest Qt Creator
252. under chromium/src `gn gen out/Default --ide=qtcreator`
263. qtcreator out/Default/qtcreator_project/all.creator
27
28It takes 3 minutes to parsing C++ files in my workstation!!! And It will not
29block you while parsing.
30
31#### Code Style
32
331. Help - About Plugins enable Beautifier.
chaopeng6fca2b02017-03-03 19:10:51342. 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.
chaopeng585eef9e2017-02-09 15:21:45373. 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
86In left panel, projects - setup the ninja command in build and clean step and
87executable chrome path in run.
88
89## Debugger
90
91**You can skip the project settings and use QtCreator as a single file
92standalone GDB frontend. **
93
941. Tools - Options - Build & Run - Debuggers, make sure GDB is set.
952. Tools - Options - Kits, change the Desktop kit to GDB(LLDB doesnot work in
96 Linux).
973. Open file you want to debug.
984. 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
chaopeng585eef9e2017-02-09 15:21:45103#### Debugger shows start then finish
104
105```
106$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
107```
108
109Ensure yama allow you to attach another process.
110
111#### Debugger do not stop in break point
112
113Ensure you are using GDB not LLDB in Linux.
114
115#### More
116
117See
118https://chromium.googlesource.com/chromium/src/+/master/docs/linux_debugging.md