• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisionc22fef7e4cf9d3cb6d7062d248b0cc148dc76137 (tree)
Time2020-02-23 03:48:32
AuthorTom Tromey <tom@trom...>
CommiterTom Tromey

Log Message

Allow TUI sub-layouts in "new-layout" command

The new TUI layout engine has support for "sub-layouts" -- this is a
layout that includes another layout as a child. A sub-layout is
treated as a unit when allocating space.

There's not a very strong reason to use sub-layouts currently. This
patch exists to introduce the idea, and to simplify the subsequent
patch that adds horizontal layouts -- where sub-layouts are needed.

Because this patch won't go in on its own, I chose to defer
documenting this change until the subsequent horizontal layout patch.

gdb/ChangeLog
2020-02-22 Tom Tromey <tom@tromey.com>

* tui/tui-layout.h (class tui_layout_split) <add_split>: Change
parameter and return types.
(class tui_layout_base) <specification>: Add "depth".
(class tui_layout_window) <specification>: Add "depth".
(class tui_layout_split) <specification>: Add "depth".
* tui/tui-layout.c (tui_layout_split::add_split): Change parameter
and return types.
(tui_new_layout_command): Parse sub-layouts.
(_initialize_tui_layout): Update help string.
(tui_layout_window::specification): Add "depth".
(add_layout_command): Update.

gdb/testsuite/ChangeLog
2020-02-22 Tom Tromey <tom@tromey.com>

* gdb.tui/new-layout.exp: Add sub-layout tests.

Change-Id: Iddf52d067a552c168b8a67f29caf7ac86404b10c

Change Summary

Incremental Difference

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,19 @@
11 2020-02-22 Tom Tromey <tom@tromey.com>
22
3+ * tui/tui-layout.h (class tui_layout_split) <add_split>: Change
4+ parameter and return types.
5+ (class tui_layout_base) <specification>: Add "depth".
6+ (class tui_layout_window) <specification>: Add "depth".
7+ (class tui_layout_split) <specification>: Add "depth".
8+ * tui/tui-layout.c (tui_layout_split::add_split): Change parameter
9+ and return types.
10+ (tui_new_layout_command): Parse sub-layouts.
11+ (_initialize_tui_layout): Update help string.
12+ (tui_layout_window::specification): Add "depth".
13+ (add_layout_command): Update.
14+
15+2020-02-22 Tom Tromey <tom@tromey.com>
16+
317 * NEWS: Add "tui new-layout" item.
418 * tui/tui-layout.c (add_layout_command): Return cmd_list_element.
519 Add new-layout command to help text.
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
11 2020-02-22 Tom Tromey <tom@tromey.com>
22
3+ * gdb.tui/new-layout.exp: Add sub-layout tests.
4+
5+2020-02-22 Tom Tromey <tom@tromey.com>
6+
37 * gdb.tui/new-layout.exp: New file.
48
59 2020-02-22 Tom Tromey <tom@tromey.com>
--- a/gdb/testsuite/gdb.tui/new-layout.exp
+++ b/gdb/testsuite/gdb.tui/new-layout.exp
@@ -35,12 +35,23 @@ gdb_test "tui new-layout example src 1 src 1" \
3535 "Window \"src\" seen twice in layout"
3636 gdb_test "tui new-layout example src 1" \
3737 "New layout does not contain the \"cmd\" window"
38+gdb_test "tui new-layout example src 1}" \
39+ "Extra '}' in layout specification"
40+gdb_test "tui new-layout example {src 1} 1}" \
41+ "Extra '}' in layout specification"
42+gdb_test "tui new-layout example {src 1" \
43+ "Missing '}' in layout specification"
3844
3945 gdb_test_no_output "tui new-layout example asm 1 status 0 cmd 1"
4046
4147 gdb_test "help layout example" \
4248 "Apply the \"example\" layout.*tui new-layout example asm 1 status 0 cmd 1"
4349
50+gdb_test_no_output "tui new-layout example2 {asm 1 status 0} 1 cmd 1"
51+
52+gdb_test "help layout example2" \
53+ "Apply the \"example2\" layout.*tui new-layout example2 {asm 1 status 0} 1 cmd 1"
54+
4455 if {![Term::enter_tui]} {
4556 unsupported "TUI not supported"
4657 }
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -400,20 +400,19 @@ tui_layout_window::replace_window (const char *name, const char *new_window)
400400 /* See tui-layout.h. */
401401
402402 void
403-tui_layout_window::specification (ui_file *output)
403+tui_layout_window::specification (ui_file *output, int depth)
404404 {
405405 fputs_unfiltered (get_name (), output);
406406 }
407407
408408 /* See tui-layout.h. */
409409
410-tui_layout_split *
411-tui_layout_split::add_split (int weight)
410+void
411+tui_layout_split::add_split (std::unique_ptr<tui_layout_split> &&layout,
412+ int weight)
412413 {
413- tui_layout_split *result = new tui_layout_split ();
414- split s = {weight, std::unique_ptr<tui_layout_base> (result)};
414+ split s = {weight, std::move (layout)};
415415 m_splits.push_back (std::move (s));
416- return result;
417416 }
418417
419418 /* See tui-layout.h. */
@@ -711,17 +710,23 @@ tui_layout_split::replace_window (const char *name, const char *new_window)
711710 /* See tui-layout.h. */
712711
713712 void
714-tui_layout_split::specification (ui_file *output)
713+tui_layout_split::specification (ui_file *output, int depth)
715714 {
715+ if (depth > 0)
716+ fputs_unfiltered ("{", output);
717+
716718 bool first = true;
717719 for (auto &item : m_splits)
718720 {
719721 if (!first)
720722 fputs_unfiltered (" ", output);
721723 first = false;
722- item.layout->specification (output);
724+ item.layout->specification (output, depth + 1);
723725 fprintf_unfiltered (output, " %d", item.weight);
724726 }
727+
728+ if (depth > 0)
729+ fputs_unfiltered ("}", output);
725730 }
726731
727732 /* Destroy the layout associated with SELF. */
@@ -746,7 +751,7 @@ add_layout_command (const char *name, tui_layout_split *layout)
746751 struct cmd_list_element *cmd;
747752
748753 string_file spec;
749- layout->specification (&spec);
754+ layout->specification (&spec, 0);
750755
751756 gdb::unique_xmalloc_ptr<char> doc
752757 (xstrprintf (_("Apply the \"%s\" layout.\n\
@@ -833,23 +838,60 @@ tui_new_layout_command (const char *spec, int from_tty)
833838 if (new_name[0] == '-')
834839 error (_("Layout name cannot start with '-'"));
835840
836- std::unique_ptr<tui_layout_split> new_layout (new tui_layout_split);
841+ std::vector<std::unique_ptr<tui_layout_split>> splits;
842+ splits.emplace_back (new tui_layout_split);
837843 std::unordered_set<std::string> seen_windows;
838844 while (true)
839845 {
840- std::string name = extract_arg (&spec);
841- if (name.empty ())
846+ spec = skip_spaces (spec);
847+ if (spec[0] == '\0')
842848 break;
843- if (!validate_window_name (name))
844- error (_("Unknown window \"%s\""), name.c_str ());
845- if (seen_windows.find (name) != seen_windows.end ())
846- error (_("Window \"%s\" seen twice in layout"), name.c_str ());
847- ULONGEST weight = get_ulongest (&spec);
849+
850+ if (spec[0] == '{')
851+ {
852+ splits.emplace_back (new tui_layout_split);
853+ ++spec;
854+ continue;
855+ }
856+
857+ bool is_close = false;
858+ std::string name;
859+ if (spec[0] == '}')
860+ {
861+ is_close = true;
862+ ++spec;
863+ if (splits.size () == 1)
864+ error (_("Extra '}' in layout specification"));
865+ }
866+ else
867+ {
868+ name = extract_arg (&spec);
869+ if (name.empty ())
870+ break;
871+ if (!validate_window_name (name))
872+ error (_("Unknown window \"%s\""), name.c_str ());
873+ if (seen_windows.find (name) != seen_windows.end ())
874+ error (_("Window \"%s\" seen twice in layout"), name.c_str ());
875+ }
876+
877+ ULONGEST weight = get_ulongest (&spec, '}');
848878 if ((int) weight != weight)
849879 error (_("Weight out of range: %s"), pulongest (weight));
850- new_layout->add_window (name.c_str (), weight);
851- seen_windows.insert (name);
880+ if (is_close)
881+ {
882+ std::unique_ptr<tui_layout_split> last_split
883+ = std::move (splits.back ());
884+ splits.pop_back ();
885+ splits.back ()->add_split (std::move (last_split), weight);
886+ }
887+ else
888+ {
889+ splits.back ()->add_window (name.c_str (), weight);
890+ seen_windows.insert (name);
891+ }
852892 }
893+ if (splits.size () > 1)
894+ error (_("Missing '}' in layout specification"));
853895 if (seen_windows.empty ())
854896 error (_("New layout does not contain any windows"));
855897 if (seen_windows.find ("cmd") == seen_windows.end ())
@@ -857,6 +899,7 @@ tui_new_layout_command (const char *spec, int from_tty)
857899
858900 gdb::unique_xmalloc_ptr<char> cmd_name
859901 = make_unique_xstrdup (new_name.c_str ());
902+ std::unique_ptr<tui_layout_split> new_layout = std::move (splits.back ());
860903 struct cmd_list_element *cmd
861904 = add_layout_command (cmd_name.get (), new_layout.get ());
862905 cmd->name_allocated = 1;
@@ -900,6 +943,9 @@ Usage: tui new-layout NAME WINDOW WEIGHT [WINDOW WEIGHT]...\n\
900943 Create a new TUI layout. The new layout will be named NAME,\n\
901944 and can be accessed using \"layout NAME\".\n\
902945 The windows will be displayed in the specified order.\n\
946+A WINDOW can also be of the form:\n\
947+ { NAME WEIGHT [NAME WEIGHT]... }\n\
948+This form indicates a sub-frame.\n\
903949 Each WEIGHT is an integer, which holds the relative size\n\
904950 to be allocated to the window."),
905951 tui_get_cmd_list ());
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -74,8 +74,9 @@ public:
7474 NEW_WINDOW. */
7575 virtual void replace_window (const char *name, const char *new_window) = 0;
7676
77- /* Append the specification to this window to OUTPUT. */
78- virtual void specification (ui_file *output) = 0;
77+ /* Append the specification to this window to OUTPUT. DEPTH is the
78+ depth of this layout in the hierarchy (zero-based). */
79+ virtual void specification (ui_file *output, int depth) = 0;
7980
8081 /* The most recent space allocation. */
8182 int x = 0;
@@ -125,7 +126,7 @@ public:
125126
126127 void replace_window (const char *name, const char *new_window) override;
127128
128- void specification (ui_file *output) override;
129+ void specification (ui_file *output, int depth) override;
129130
130131 protected:
131132
@@ -153,7 +154,7 @@ public:
153154 /* Add a new split layout to this layout. WEIGHT is the desired
154155 size, which is relative to the other weights given in this
155156 layout. */
156- tui_layout_split *add_split (int weight);
157+ void add_split (std::unique_ptr<tui_layout_split> &&layout, int weight);
157158
158159 /* Add a new window to this layout. NAME is the name of the window
159160 to add. WEIGHT is the desired size, which is relative to the
@@ -174,7 +175,7 @@ public:
174175
175176 void replace_window (const char *name, const char *new_window) override;
176177
177- void specification (ui_file *output) override;
178+ void specification (ui_file *output, int depth) override;
178179
179180 protected:
180181