
Add instructions for getting compiler errors into qtcreators Issues pane when building with ninja, and other general cleanup. TBR=chaopeng@chromium.org Change-Id: I23e238e48a688a993cf2b40b9979f94d9fe18305 Reviewed-on: https://chromium-review.googlesource.com/680715 Reviewed-by: Sam McNally <sammc@chromium.org> Reviewed-by: Chris Watkins <watk@chromium.org> Commit-Queue: Chris Watkins <watk@chromium.org> Cr-Commit-Position: refs/heads/master@{#504543}
4.5 KiB
4.5 KiB
Use Qt Creator as an IDE or debugger UI
Qt Creator (Wiki) is a cross-platform C++ IDE.
You can use Qt Creator as a daily IDE or just as a GDB frontend (which does not require project configuration).
[TOC]
IDE
Workflow features
- Built-in code completion.
- Navigate to classes, files, or symbols with
ctrl+k
. - Switch between declaration and definition with
F2
. - Build with
ctrl+shift+b
. - Build and run with
ctrl+r
, or debug withF5
. - Switch between the header file and cpp file with
F4
.
Setup
- Install the latest Qt Creator.
- Under chromium/src
gn gen out/Default --ide=qtcreator
. - Start it with
qtcreator out/Default/qtcreator_project/all.creator
. - Help - Plugins - check ClangCodeModel to enable std completion.
It takes 3 minutes to parse all of chrome's C++ files on my workstation!!! And it does not block while parsing.
Code Style
- Help - About Plugins, enable Beautifier.
- Tools - Options - Beautifier - Clang Format,
change the Clang format command to:
$depot_tools_dir/clang-format
, and setUse predefined style: file
. You can also set a keyboard shortcut for it. - Tools - Options - Code Style, import this xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorCodeStyle>
<!-- Written by QtCreator 4.2.1, 2017-02-08T19:07:34. -->
<qtcreator>
<data>
<variable>CodeStyleData</variable>
<valuemap type="QVariantMap">
<value type="bool" key="AlignAssignments">true</value>
<value type="bool" key="AutoSpacesForTabs">false</value>
<value type="bool" key="BindStarToIdentifier">false</value>
<value type="bool" key="BindStarToLeftSpecifier">false</value>
<value type="bool" key="BindStarToRightSpecifier">false</value>
<value type="bool" key="BindStarToTypeName">true</value>
<value type="bool"
key="ExtraPaddingForConditionsIfConfusingAlign">true</value>
<value type="bool" key="IndentAccessSpecifiers">true</value>
<value type="bool" key="IndentBlockBody">true</value>
<value type="bool" key="IndentBlockBraces">false</value>
<value type="bool" key="IndentBlocksRelativeToSwitchLabels">false</value>
<value type="bool" key="IndentClassBraces">false</value>
<value type="bool" key="IndentControlFlowRelativeToSwitchLabels">true</value>
<value type="bool"
key="IndentDeclarationsRelativeToAccessSpecifiers">false</value>
<value type="bool" key="IndentEnumBraces">false</value>
<value type="bool" key="IndentFunctionBody">true</value>
<value type="bool" key="IndentFunctionBraces">false</value>
<value type="bool" key="IndentNamespaceBody">false</value>
<value type="bool" key="IndentNamespaceBraces">false</value>
<value type="int" key="IndentSize">2</value>
<value type="bool" key="IndentStatementsRelativeToSwitchLabels">true</value>
<value type="bool" key="IndentSwitchLabels">false</value>
<value type="int" key="PaddingMode">2</value>
<value type="bool" key="ShortGetterName">true</value>
<value type="bool" key="SpacesForTabs">true</value>
<value type="int" key="TabSize">2</value>
</valuemap>
</data>
<data>
<variable>DisplayName</variable>
<value type="QString">chrome</value>
</data>
</qtcreator>
Build & Run
- (Optional) Enable the issues pane for easy navigation to the location of compiler errors. qtcreator expects to find compiler errors on stderr, but ninja forwards all subcommand output to stdout. So use the following wrapper script to forward it to stderr instead.
#!/bin/sh
/path/to/depot_tools/ninja "$@" >&2
- In the left panel - Projects, set up the ninja command in the build and clean steps, and add the path to chrome in the run configuration.
Debugger
You can skip the project settings and use QtCreator as a single file standalone GDB frontend.
- Tools - Options - Build & Run - Debuggers, make sure GDB is set.
- Tools - Options - Kits, change the Desktop kit to GDB (LLDB doesn't work on Linux).
- Open the file you want to debug.
- Debug - Start Debugging - Attach to running Application, you may need to open chrome's task manager to find the process id.
Tips, tricks, and troubleshooting
The debugger exits immediately
Ensure yama allows you to attach to another process:
$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
The debugger does not stop on breakpoints
Ensure you are using GDB on Linux, not LLDB.
More
See https://chromium.googlesource.com/chromium/src/+/master/docs/linux_debugging.md