From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 3/5] Allow "phony" ui-out tables
Date: Fri, 12 Jun 2026 08:25:23 -0600 [thread overview]
Message-ID: <20260612-submit-zebra-style-v1-3-cfd00b5c984c@tromey.com> (raw)
In-Reply-To: <20260612-submit-zebra-style-v1-0-cfd00b5c984c@tromey.com>
In the zebra-striping patch, it's convenient to wrap a stack trace in
a ui-out table. However, using a real table isn't really desirable,
because that would mean printing headers. So, this patch adds a hack
specifically for stack traces: a phony table, that does not have field
headers at all.
---
gdb/cli-out.c | 2 +-
gdb/cli-out.h | 8 +++++++-
gdb/mi/mi-out.c | 9 ++++++---
gdb/mi/mi-out.h | 2 +-
gdb/python/py-uiout.h | 5 +++--
gdb/ui-out.c | 25 ++++++++++++++++++++++---
gdb/ui-out.h | 18 +++++++++++++++++-
7 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index d8ac13ab827..e1501f5c652 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -59,7 +59,7 @@ cli_ui_out::do_table_body ()
/* Mark end of a table */
void
-cli_ui_out::do_table_end ()
+cli_ui_out::do_table_end (bool phony)
{
m_suppress_output = false;
}
diff --git a/gdb/cli-out.h b/gdb/cli-out.h
index 74307074a7c..ca138e5ad9a 100644
--- a/gdb/cli-out.h
+++ b/gdb/cli-out.h
@@ -44,8 +44,14 @@ class cli_ui_out : public ui_out
virtual void do_table_begin (int nbrofcols, int nr_rows,
const char *tblid) override;
+
+ /* This overload is used for "phony" tables. */
+ void do_table_begin () override
+ {
+ }
+
virtual void do_table_body () override;
- virtual void do_table_end () override;
+ virtual void do_table_end (bool phony) override;
virtual void do_table_header (int width, ui_align align,
const std::string &col_name,
const std::string &col_hdr) override;
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 41b0ee8cdbd..0d60c2557e7 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -53,10 +53,13 @@ mi_ui_out::do_table_body ()
/* Mark end of a table. */
void
-mi_ui_out::do_table_end ()
+mi_ui_out::do_table_end (bool phony)
{
- close (ui_out_type_list); /* body */
- close (ui_out_type_tuple);
+ if (!phony)
+ {
+ close (ui_out_type_list); /* body */
+ close (ui_out_type_tuple);
+ }
}
/* Specify table header. */
diff --git a/gdb/mi/mi-out.h b/gdb/mi/mi-out.h
index d1d26718ac4..6dece4d42b8 100644
--- a/gdb/mi/mi-out.h
+++ b/gdb/mi/mi-out.h
@@ -57,7 +57,7 @@ class mi_ui_out : public ui_out
virtual void do_table_header (int width, ui_align align,
const std::string &col_name,
const std::string &col_hdr) override;
- virtual void do_table_end () override;
+ virtual void do_table_end (bool phony) override;
virtual void do_begin (ui_out_type type, const char *id) override;
virtual void do_end (ui_out_type type) override;
diff --git a/gdb/python/py-uiout.h b/gdb/python/py-uiout.h
index 21c068e9077..2bf0c3a7b46 100644
--- a/gdb/python/py-uiout.h
+++ b/gdb/python/py-uiout.h
@@ -73,9 +73,10 @@ class py_ui_out : public ui_out
}
void do_table_body () override
{ }
- void do_table_end () override
+ void do_table_end (bool phony) override
{
- do_end (ui_out_type_list);
+ if (!phony)
+ do_end (ui_out_type_list);
}
void do_table_header (int width, ui_align align,
const std::string &col_name,
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index ac792b43905..1c8ceaa90ee 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -184,6 +184,12 @@ class ui_out_table
int entry_level () const;
+ /* True if this is a "phony" table. */
+ bool phony () const
+ {
+ return m_nr_cols == 0;
+ }
+
private:
state m_state;
@@ -356,9 +362,20 @@ previous table_end."));
m_table_up = std::make_unique<ui_out_table> (level () + 1, nr_cols, tblid);
+ gdb_assert (!m_table_up->phony ());
do_table_begin (nr_cols, nr_rows, tblid.c_str ());
}
+/* See ui-out.h. */
+
+void
+ui_out::table_begin ()
+{
+ gdb_assert (m_table_up == nullptr);
+ m_table_up = std::make_unique<ui_out_table> (level () + 1, 0, "");
+ do_table_begin ();
+}
+
void
ui_out::table_header (int width, ui_align alignment,
const std::string &col_name, const std::string &col_hdr)
@@ -369,7 +386,8 @@ after a table_begin and before a table_body."));
m_table_up->append_header (width, alignment, col_name, col_hdr);
- do_table_header (width, alignment, col_name, col_hdr);
+ if (!m_table_up->phony ())
+ do_table_header (width, alignment, col_name, col_hdr);
}
void
@@ -381,7 +399,8 @@ ui_out::table_body ()
m_table_up->start_body ();
- do_table_body ();
+ if (!m_table_up->phony ())
+ do_table_body ();
}
void
@@ -390,7 +409,7 @@ ui_out::table_end ()
if (m_table_up == nullptr)
internal_error (_("misplaced table_end or missing table_begin."));
- do_table_end ();
+ do_table_end (m_table_up->phony ());
m_table_up = nullptr;
}
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index a7230846115..12da0084332 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -341,8 +341,14 @@ class ui_out
virtual void do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
= 0;
+
+ /* This is only used for phony tables. */
+ virtual void do_table_begin ()
+ {
+ }
+
virtual void do_table_body () = 0;
- virtual void do_table_end () = 0;
+ virtual void do_table_end (bool phony) = 0;
virtual void do_table_header (int width, ui_align align,
const std::string &col_name,
const std::string &col_hdr) = 0;
@@ -396,6 +402,8 @@ class ui_out
/* A table can only be started or ended by ui_out_emit_table. */
friend class ui_out_emit_table;
void table_begin (int nr_cols, int nr_rows, const std::string &tblid);
+ /* This overload is only used for phony tables. */
+ void table_begin ();
void table_end ();
/* A helper for vmessage that wraps a call to do_message. This will
@@ -460,6 +468,14 @@ class ui_out_emit_table
m_uiout->table_begin (nr_cols, nr_rows, tblid);
}
+ /* This constructor creates a "phony" table -- this is a hack
+ intended for use just by the stack-generation code. */
+ explicit ui_out_emit_table (ui_out *uiout)
+ : m_uiout (uiout)
+ {
+ m_uiout->table_begin ();
+ }
+
~ui_out_emit_table ()
{
m_uiout->table_end ();
--
2.49.0
next prev parent reply other threads:[~2026-06-12 14:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 14:25 [PATCH 0/5] Add zebra-striping to CLI tables Tom Tromey
2026-06-12 14:25 ` [PATCH 1/5] Ensure tgetent is called before tgetnum Tom Tromey
2026-06-12 14:25 ` [PATCH 2/5] Make two ui_out methods 'private' Tom Tromey
2026-06-12 14:25 ` Tom Tromey [this message]
2026-06-12 14:25 ` [PATCH 4/5] Add ui_file_style::merge Tom Tromey
2026-06-12 14:25 ` [PATCH 5/5] Add zebra-striping to CLI table display Tom Tromey
2026-06-12 15:14 ` Eli Zaretskii
2026-06-13 14:28 ` Matt Rice
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=20260612-submit-zebra-style-v1-3-cfd00b5c984c@tromey.com \
--to=tom@tromey.com \
--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