blob: ad7a376be034547819de060cb429a7d6d6a2a5cc [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
Alexis Menard701a5652018-05-08 16:27:496You can use Qt Creator as a daily IDE on Linux or Mac, or just as a GDB/LLDB
7frontend (which does not 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.
Alexis Menard701a5652018-05-08 16:27:4916* Navigate to classes, files, or symbols with `ctrl+k` or `cmd+k` (macOS).
Chris Watkins7374d032017-09-27 01:46:3917* Switch between declaration and definition with `F2`.
Alexis Menard701a5652018-05-08 16:27:4918* Build with `ctrl+shift+b` or `shift+cmd+b` (macOS).
19* Build and run with `ctrl+r` or `cmd+r` (macOS), or debug with `F5`.
Chris Watkins7374d032017-09-27 01:46:3920* 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
Alexis Menard701a5652018-05-08 16:27:4929It takes 3 minutes to parse all of chromium's C++ files on my workstation!!! And
Chris Watkins7374d032017-09-27 01:46:3930it does not block while parsing.
chaopeng585eef9e2017-02-09 15:21:4531
32#### Code Style
33
Alexis Menard701a5652018-05-08 16:27:49341. Help - About Plugins (or app menu on macOS), enable Beautifier.
352. Tools - Options (Preferences on macOS) - Beautifier
36 Make sure to tick - Enable auto format on file save"
37 Select ClangFormat as the tool
38 Go to Clang Format tab
39 Change the Clang format command to: `$chromium_checkout_dir/src/buildtools/$os/clang-format`, and
Chris Watkins7374d032017-09-27 01:46:3940 set `Use predefined style: file`. You can also set a keyboard shortcut
41 for it.
Alexis Menard701a5652018-05-08 16:27:49423. Tools - Options - C++ - Code Style, import this xml file.
chaopeng585eef9e2017-02-09 15:21:4543
44```
45<?xml version="1.0" encoding="UTF-8"?>
46<!DOCTYPE QtCreatorCodeStyle>
47<!-- Written by QtCreator 4.2.1, 2017-02-08T19:07:34. -->
48<qtcreator>
49 <data>
50 <variable>CodeStyleData</variable>
51 <valuemap type="QVariantMap">
52 <value type="bool" key="AlignAssignments">true</value>
53 <value type="bool" key="AutoSpacesForTabs">false</value>
54 <value type="bool" key="BindStarToIdentifier">false</value>
55 <value type="bool" key="BindStarToLeftSpecifier">false</value>
56 <value type="bool" key="BindStarToRightSpecifier">false</value>
57 <value type="bool" key="BindStarToTypeName">true</value>
chaopeng6122d4c2017-09-01 19:40:0558 <value type="bool"
chaopeng585eef9e2017-02-09 15:21:4559 key="ExtraPaddingForConditionsIfConfusingAlign">true</value>
60 <value type="bool" key="IndentAccessSpecifiers">true</value>
61 <value type="bool" key="IndentBlockBody">true</value>
62 <value type="bool" key="IndentBlockBraces">false</value>
63 <value type="bool" key="IndentBlocksRelativeToSwitchLabels">false</value>
64 <value type="bool" key="IndentClassBraces">false</value>
65 <value type="bool" key="IndentControlFlowRelativeToSwitchLabels">true</value>
66 <value type="bool"
67 key="IndentDeclarationsRelativeToAccessSpecifiers">false</value>
68 <value type="bool" key="IndentEnumBraces">false</value>
69 <value type="bool" key="IndentFunctionBody">true</value>
70 <value type="bool" key="IndentFunctionBraces">false</value>
71 <value type="bool" key="IndentNamespaceBody">false</value>
72 <value type="bool" key="IndentNamespaceBraces">false</value>
73 <value type="int" key="IndentSize">2</value>
74 <value type="bool" key="IndentStatementsRelativeToSwitchLabels">true</value>
75 <value type="bool" key="IndentSwitchLabels">false</value>
76 <value type="int" key="PaddingMode">2</value>
77 <value type="bool" key="ShortGetterName">true</value>
78 <value type="bool" key="SpacesForTabs">true</value>
79 <value type="int" key="TabSize">2</value>
80 </valuemap>
81 </data>
82 <data>
83 <variable>DisplayName</variable>
84 <value type="QString">chrome</value>
85 </data>
86</qtcreator>
87```
88
89#### Build & Run
90
Chris Watkins7374d032017-09-27 01:46:39911. (Optional) Enable the issues pane for easy navigation to the location of
92 compiler errors. qtcreator expects to find compiler errors on stderr, but
93 ninja forwards all subcommand output to stdout. So use the following wrapper
94 script to forward it to stderr instead.
95```
96#!/bin/sh
97/path/to/depot_tools/ninja "$@" >&2
98```
992. In the left panel - Projects, set up the ninja command in the build and
100 clean steps, and add the path to chrome in the run configuration.
101
chaopeng585eef9e2017-02-09 15:21:45102
103## Debugger
104
chaopeng6122d4c2017-09-01 19:40:05105**You can skip the project settings and use QtCreator as a single file
Alexis Menard701a5652018-05-08 16:27:49106standalone GDB or LLDB (macOS) frontend.**
chaopeng585eef9e2017-02-09 15:21:45107
Alexis Menard701a5652018-05-08 16:27:49108For macOS :
1091. Open the file you want to debug.
1102. Debug - Start Debugging - Attach to running Application, you may need to
111 open chromium's task manager to find the process id.
112
113For Linux :
chaopeng585eef9e2017-02-09 15:21:451141. Tools - Options - Build & Run - Debuggers, make sure GDB is set.
Chris Watkins7374d032017-09-27 01:46:391152. Tools - Options - Kits, change the Desktop kit to GDB (LLDB doesn't work on
116 Linux).
1173. Open the file you want to debug.
chaopeng6122d4c2017-09-01 19:40:051184. Debug - Start Debugging - Attach to running Application, you may need to
Alexis Menard701a5652018-05-08 16:27:49119 open chromium's task manager to find the process id.
chaopeng585eef9e2017-02-09 15:21:45120
121### Tips, tricks, and troubleshooting
122
Alexis Menard701a5652018-05-08 16:27:49123#### [Linux] The debugger exits immediately
Chris Watkins7374d032017-09-27 01:46:39124
125Ensure yama allows you to attach to another process:
chaopeng585eef9e2017-02-09 15:21:45126
127```
128$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
129```
130
chaopeng585eef9e2017-02-09 15:21:45131
Alexis Menard701a5652018-05-08 16:27:49132#### [Linux] The debugger does not stop on breakpoints
chaopeng585eef9e2017-02-09 15:21:45133
Chris Watkins7374d032017-09-27 01:46:39134Ensure you are using GDB on Linux, not LLDB.
chaopeng585eef9e2017-02-09 15:21:45135
136#### More
137
Alexis Menard701a5652018-05-08 16:27:49138Linux :
chaopeng6122d4c2017-09-01 19:40:05139See
John Palmer046f9872021-05-24 01:24:56140https://chromium.googlesource.com/chromium/src/+/main/docs/linux/debugging.md
Alexis Menard701a5652018-05-08 16:27:49141
142macOS :
Robert Sesek3b731b12021-04-14 21:54:03143https://chromium.googlesource.com/chromium/src/+/main/docs/mac/debugging.md