blob: e9da7d56cb2a02872c5a960707fe0925fc4e00b8 [file] [log] [blame] [view]
Chris Watkins7374d032017-09-27 01:46:391# Use Qt Creator as an IDE or debugger UI
chaopeng585eef9e2017-02-09 15:21:452
3[Qt Creator](https://www.qt.io/ide/)
chaopeng6122d4c2017-09-01 19:40:054([Wiki](https://en.wikipedia.org/wiki/Qt_Creator)) is a cross-platform C++ IDE.
chaopeng585eef9e2017-02-09 15:21:455
Chris Watkins7374d032017-09-27 01:46:396You can use Qt Creator as a daily IDE or just as a GDB frontend (which does
7not require project configuration).
chaopeng585eef9e2017-02-09 15:21:458
9[TOC]
10
11## IDE
12
Chris Watkins7374d032017-09-27 01:46:3913### Workflow features
chaopeng585eef9e2017-02-09 15:21:4514
Chris Watkins7374d032017-09-27 01:46:3915* 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`.
chaopeng585eef9e2017-02-09 15:21:4521
Chris Watkins7374d032017-09-27 01:46:3922### Setup
chaopeng585eef9e2017-02-09 15:21:4523
Chris Watkins7374d032017-09-27 01:46:39241. Install the latest Qt Creator.
252. Under chromium/src `gn gen out/Default --ide=qtcreator`.
263. Start it with `qtcreator out/Default/qtcreator_project/all.creator`.
274. Help - Plugins - check ClangCodeModel to enable std completion.
chaopeng585eef9e2017-02-09 15:21:4528
Chris Watkins7374d032017-09-27 01:46:3929It takes 3 minutes to parse all of chrome's C++ files on my workstation!!! And
30it does not block while parsing.
chaopeng585eef9e2017-02-09 15:21:4531
32#### Code Style
33
Chris Watkins7374d032017-09-27 01:46:39341. Help - About Plugins, enable Beautifier.
chaopeng6122d4c2017-09-01 19:40:05352. Tools - Options - Beautifier - Clang Format,
Chris Watkins7374d032017-09-27 01:46:3936 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.
393. Tools - Options - Code Style, import this xml file.
chaopeng585eef9e2017-02-09 15:21:4540
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>
chaopeng6122d4c2017-09-01 19:40:0555 <value type="bool"
chaopeng585eef9e2017-02-09 15:21:4556 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 Watkins7374d032017-09-27 01:46:39881. (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```
962. 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
chaopeng585eef9e2017-02-09 15:21:4599
100## Debugger
101
chaopeng6122d4c2017-09-01 19:40:05102**You can skip the project settings and use QtCreator as a single file
Chris Watkins7374d032017-09-27 01:46:39103standalone GDB frontend.**
chaopeng585eef9e2017-02-09 15:21:45104
1051. Tools - Options - Build & Run - Debuggers, make sure GDB is set.
Chris Watkins7374d032017-09-27 01:46:391062. Tools - Options - Kits, change the Desktop kit to GDB (LLDB doesn't work on
107 Linux).
1083. Open the file you want to debug.
chaopeng6122d4c2017-09-01 19:40:051094. Debug - Start Debugging - Attach to running Application, you may need to
Chris Watkins7374d032017-09-27 01:46:39110 open chrome's task manager to find the process id.
chaopeng585eef9e2017-02-09 15:21:45111
112### Tips, tricks, and troubleshooting
113
Chris Watkins7374d032017-09-27 01:46:39114#### The debugger exits immediately
115
116Ensure yama allows you to attach to another process:
chaopeng585eef9e2017-02-09 15:21:45117
118```
119$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
120```
121
chaopeng585eef9e2017-02-09 15:21:45122
Chris Watkins7374d032017-09-27 01:46:39123#### The debugger does not stop on breakpoints
chaopeng585eef9e2017-02-09 15:21:45124
Chris Watkins7374d032017-09-27 01:46:39125Ensure you are using GDB on Linux, not LLDB.
chaopeng585eef9e2017-02-09 15:21:45126
127#### More
128
chaopeng6122d4c2017-09-01 19:40:05129See
Chris Watkins7374d032017-09-27 01:46:39130https://chromium.googlesource.com/chromium/src/+/master/docs/linux_debugging.md