From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [RFC 2/5] [gdb/testsuite] Make lib/gdb.exp emacs indent compatible
Date: Fri, 4 Sep 2026 11:38:52 +0200 [thread overview]
Message-ID: <20260904093858.359604-2-tdevries@suse.de> (raw)
In-Reply-To: <20260904093858.359604-1-tdevries@suse.de>
There are cases in gdb/testsuite/lib/gdb.exp where we have inline C sources.
Say we start out by writing something like this:
...
set src {
int main (int argc) {
if (argc == 3)
return 0;
}
}
...
When editing with emacs, and using tcl-mode, auto indent will change this to:
...
set src {
int main (int argc) {
if (argc == 3)
return 0;
}
}
...
The 2 vs 4 spacing is fine, but removing indentation is not. We can fix this
by adding braces:
...
set src {
int main (int argc) {
if (argc == 3) {
return 0;
}
}
}
...
But that approach breaks down when we have a for loop. Auto indent gives us:
...
set src {
int main (int argc) {
for (int i = 0; i < 1) {
argc++;
}
return argc;
}
}
...
This can be fixed with a trick: adding an if:
...
set src {
int main (int argc) {
for (int i = 0; i < 1) if (1) {
argc++;
}
return argc;
}
}
...
Use these methods to make the inline sources in lib/gdb.exp compatible with
emacs auto indent.
Note: this does not yet use emacs indentation.
---
gdb/testsuite/lib/gdb.exp | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index ea8bffc9e89..d4a471ff7c4 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3134,6 +3134,9 @@ gdb_caching_proc allow_dlmopen_tests {} {
return 42;
}
}
+
+ # Note: we use a "for ... if (1) ..." trick to make emacs tcl-mode indent
+ # the for loop as if it was an if.
set src {
#define _GNU_SOURCE
#include <dlfcn.h>
@@ -3155,9 +3158,11 @@ gdb_caching_proc allow_dlmopen_tests {} {
r_debug = 0;
/* Taken from /usr/include/link.h. */
- for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
- if (dyn->d_tag == DT_DEBUG)
+ for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) if (1) {
+ if (dyn->d_tag == DT_DEBUG) {
r_debug = (struct r_debug *) dyn->d_un.d_ptr;
+ }
+ }
if (!r_debug) {
printf ("r_debug not found.\n");
@@ -11487,14 +11492,16 @@ gdb_caching_proc have_avx {} {
int main() {
unsigned int eax, ebx, ecx, edx;
- if (!x86_cpuid (1, &eax, &ebx, &ecx, &edx))
+ if (!x86_cpuid (1, &eax, &ebx, &ecx, &edx)) {
return 0;
+ }
- if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
+ if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE)) {
return 1;
- else
+ } else {
return 0;
}
+ }
}
set compile_flags "incdir=${srcdir}/.."
if {![gdb_simple_compile $me $src executable $compile_flags]} {
@@ -11532,14 +11539,16 @@ gdb_caching_proc have_avx2 {} {
int main() {
unsigned int eax, ebx, ecx, edx;
- if (!x86_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
- return 0;
+ if (!x86_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx)) {
+ return 0;
+ }
- if ((ebx & bit_AVX2) == bit_AVX2)
+ if ((ebx & bit_AVX2) == bit_AVX2) {
return 1;
- else
+ } else {
return 0;
}
+ }
}
set compile_flags "incdir=${srcdir}/.."
if {![gdb_simple_compile $me $src executable $compile_flags]} {
@@ -11642,8 +11651,9 @@ gdb_caching_proc has_hw_wp_support {} {
int main (void) {
volatile int local;
local = 1;
- if (local == 1)
+ if (local == 1) {
return 1;
+ }
return 0;
}
}
--
2.51.0
next prev parent reply other threads:[~2026-09-04 9:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 9:38 [RFC 1/5] [pre-commit] Add indent-exp Tom de Vries
2026-09-04 9:38 ` Tom de Vries [this message]
2026-09-04 9:38 ` [RFC 3/5] [gdb/testsuite] Update regexp in string_to_regexp Tom de Vries
2026-09-04 9:38 ` [RFC 4/5] [gdb/testsuite] Reformat lib/gdb.exp Tom de Vries
2026-09-04 9:38 ` [RFC 5/5] [gdb/testsuite] Reformat gdb.ada Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904093858.359604-2-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox