* [PATCH v6] Add .clang-format
@ 2026-02-05 22:48 Tom Tromey
2026-02-11 1:00 ` Kevin Buettner
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2026-02-05 22:48 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This patch adds a .clang-format file to the gdb repository.
The resulting reformatting is what I'd describe as "ok but not great".
There are a few variances from our normal style, some discussed in
comments in the file, and some in the bug.
I've somewhat come around to the idea that some ugliness is
acceptable, particularly because I regularly see code that's already
ugly anyway -- either in formatting or along some other dimension.
I don't know of a way to enforce a particular version. I have only
tried clang-format 18 with this particular file, though Kevin Buettner
reported trying 19-21 as well. I've documented this in the file.
I used "AllowShortFunctionsOnASingleLine: InlineOnly" as previously
discussed. I feel that the spirit of the GNU style is that vertical
space is free, and we should use "None" here. (This goes against
something we previously decided on the list, though.)
The file is in the root directory for ease of use.
For the time being you should not bulk reformat files. I think we
should have a flag day for this, but at some later point. See the
earlier discussion for details.
New in v4:
* Comment fixes
* Remove ForEachMacros - no longer correct
* Remove IncludeCategories - no longer correct
New in v5:
* More fixes to the comments
New in v6:
* Removed 'StatementMacros' setting, we're no longer using
PyObject_HEAD
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30098
---
.clang-format | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++
.gitignore | 1 -
2 files changed, 167 insertions(+), 1 deletion(-)
create mode 100644 .clang-format
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000000..fd4f2d951e2
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,167 @@
+# -*- yaml -*-
+
+# Copyright (C) 2021-2026 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# A clang format style for gdb.
+
+# ⚠️⚠️⚠️ DO NOT BULK REFORMAT FILES ⚠️⚠️⚠️
+
+# This style is still in flux and still considered "alpha". Use "git
+# clang-format" or the like to reformat just the parts your patch
+# touches -- at most. At some point in the future we will bulk
+# reformat and at that point we'll send out new instructions.
+
+# There is currently not a blessed version of clang-format. This was
+# tried with versions 18-21 with various results.
+
+# There's a gdb bug open for discussion of the format.
+#
+# https://sourceware.org/bugzilla/show_bug.cgi?id=30098
+#
+# It also has links to relevant upstream clang-format bugs.
+
+# Options here are generally in alphabetical order.
+
+Language: Cpp
+# BasedOnStyle: GNU
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignConsecutiveMacros: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortEnumsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLambdasOnASingleLine: All
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: TopLevelDefinitions
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+#
+# Run:
+# git grep 'define ATTRIBUTE_' -- include gdb* | \
+# sed -e's/^.*\(ATTRIBUTE_[A-Z0-9_]*\).*$/\1/' | \
+# sort -u | \
+# sed -e "s/^\(.*\)$/ '\1',/"
+AttributeMacros: [
+ 'ATTRIBUTE_ALIGNED_ALIGNOF',
+ 'ATTRIBUTE_COLD',
+ 'ATTRIBUTE_FORMAT_PRINTF_STANDARD',
+ 'ATTRIBUTE_FPTR_PRINTF',
+ 'ATTRIBUTE_GCC_STRUCT',
+ 'ATTRIBUTE_HOT',
+ 'ATTRIBUTE_MALLOC',
+ 'ATTRIBUTE_NOCLONE',
+ 'ATTRIBUTE_NONNULL',
+ 'ATTRIBUTE_NONSTRING',
+ 'ATTRIBUTE_NORETURN',
+ 'ATTRIBUTE_NO_SANITIZE_UNDEFINED',
+ 'ATTRIBUTE_NULL_PRINTF',
+ 'ATTRIBUTE_PACKED',
+ 'ATTRIBUTE_PRINTF',
+ 'ATTRIBUTE_PURE',
+ 'ATTRIBUTE_RESULT_SIZE_1',
+ 'ATTRIBUTE_RESULT_SIZE_1_2',
+ 'ATTRIBUTE_RESULT_SIZE_2',
+ 'ATTRIBUTE_RETURNS_NONNULL',
+ 'ATTRIBUTE_SENTINEL',
+ 'ATTRIBUTE_UNUSED',
+ 'ATTRIBUTE_UNUSED_LABEL',
+ 'ATTRIBUTE_UNUSED_RESULT',
+ 'ATTRIBUTE_USED',
+ 'ATTRIBUTE_VISIBILITY',
+ 'ATTRIBUTE_WARN_UNUSED_RESULT',
+ ]
+BinPackArguments: true
+BinPackParameters: true
+# Because BreakBeforeBraces = GNU, we don't need BraceWrapping.
+BreakBeforeBinaryOperators: All
+BreakBeforeBraces: GNU
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeColon
+BreakInheritanceList: BeforeColon
+BreakStringLiterals: true
+ColumnLimit: 79
+CommentPragmas: 'ARI:'
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 2
+ContinuationIndentWidth: 2
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+# The docs say not to use this.
+# ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+IncludeBlocks: Preserve
+IndentCaseLabels: false
+# This next setting is incorrect but it's a clang-format issue.
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentWidth: 2
+IndentWrappedFunctionNames: false
+KeepEmptyLinesAtTheStartOfBlocks: false
+LineEnding: LF
+# MacroBlockBegin: ''
+# MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+# NamespaceMacros
+PackConstructorInitializers: Never
+PenaltyBreakAssignment: 50
+PenaltyBreakBeforeFirstCallParameter: 100
+# clang 20 setting:
+# PenaltyBreakBeforeMemberAccess: 50
+# PenaltyBreakComment
+# PenaltyBreakFirstLessLess
+PenaltyBreakOpenParenthesis: 100
+# PenaltyBreakString
+# PenaltyBreakTemplateDeclaration
+# PenaltyExcessCharacter
+# PenaltyReturnTypeOnItsOwnLine
+PointerAlignment: Right
+# RawStringFormats: [ I don't think we need this ]
+# Should be IndentOnly but that requires clang 20.
+ReflowComments: false
+# FIXME - enable
+SortIncludes: Never
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: true
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: Always
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceBeforeSquareBrackets: false
+SpaceInEmptyBlock: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInParens: Never
+SpacesInSquareBrackets: false
+Standard: c++17
+TabWidth: 8
+TypenameMacros: [ 'ENUM_BITFIELD' ]
+UseTab: ForContinuationAndIndentation
diff --git a/.gitignore b/.gitignore
index 7f1c81e00c4..eb44ff7f255 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,7 +37,6 @@ TAGS.sub
.local.vimrc
.lvimrc
-.clang-format
.clang-tidy
.clangd
.cache
--
2.49.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v6] Add .clang-format
2026-02-05 22:48 [PATCH v6] Add .clang-format Tom Tromey
@ 2026-02-11 1:00 ` Kevin Buettner
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Buettner @ 2026-02-11 1:00 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Thu, 5 Feb 2026 15:48:49 -0700
Tom Tromey <tom@tromey.com> wrote:
> This patch adds a .clang-format file to the gdb repository.
>
> The resulting reformatting is what I'd describe as "ok but not great".
> There are a few variances from our normal style, some discussed in
> comments in the file, and some in the bug.
>
> I've somewhat come around to the idea that some ugliness is
> acceptable, particularly because I regularly see code that's already
> ugly anyway -- either in formatting or along some other dimension.
>
> I don't know of a way to enforce a particular version. I have only
> tried clang-format 18 with this particular file, though Kevin Buettner
> reported trying 19-21 as well. I've documented this in the file.
>
> I used "AllowShortFunctionsOnASingleLine: InlineOnly" as previously
> discussed. I feel that the spirit of the GNU style is that vertical
> space is free, and we should use "None" here. (This goes against
> something we previously decided on the list, though.)
>
> The file is in the root directory for ease of use.
>
> For the time being you should not bulk reformat files. I think we
> should have a flag day for this, but at some later point. See the
> earlier discussion for details.
>
> New in v4:
> * Comment fixes
> * Remove ForEachMacros - no longer correct
> * Remove IncludeCategories - no longer correct
>
> New in v5:
> * More fixes to the comments
>
> New in v6:
> * Removed 'StatementMacros' setting, we're no longer using
> PyObject_HEAD
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30098
> ---
> .clang-format | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++
> .gitignore | 1 -
> 2 files changed, 167 insertions(+), 1 deletion(-)
> create mode 100644 .clang-format
I was around back in the days when we used to use gnu-indent with a
particular set of options. We all agreed that it wasn't perfect - in
fact for many things it was downright ugly. But we also agreed that
it was better than the alternative of having no code formatting tool
available.
I'm in favor of this going in. I'll give you an Approved-by in case
you wish to use it.
Kevin
Approved-by: Kevin Buettner <kevinb@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-11 1:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-05 22:48 [PATCH v6] Add .clang-format Tom Tromey
2026-02-11 1:00 ` Kevin Buettner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox