aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorMarco Barisione <mbarisione@undo.io>2021-05-12 11:19:22 +0100
committerMarco Barisione <mbarisione@undo.io>2021-05-12 11:19:22 +0100
commit2f822da535ba9b159174d02d7114b4fc4f7c8818 (patch)
tree7014b48d9f7893385ed27091caa75c28964c3514 /gdb/tui
parentf0bbe8bab84e9b9dc5367a5fe1d0b8d233bf213c (diff)
downloadbinutils-2f822da535ba9b159174d02d7114b4fc4f7c8818.zip
binutils-2f822da535ba9b159174d02d7114b4fc4f7c8818.tar.gz
binutils-2f822da535ba9b159174d02d7114b4fc4f7c8818.tar.bz2
gdb: generate the prefix name for prefix commands on demand
Previously, the prefixname field of struct cmd_list_element was manually set for prefix commands. This seems verbose and error prone as it required every single call to functions adding prefix commands to specify the prefix name while the same information can be easily generated. Historically, this was not possible as the prefix field was null for many commands, but this was fixed in commit 3f4d92ebdf7f848b5ccc9e8d8e8514c64fde1183 by Philippe Waroquiers, so we can rely on the prefix field being set when generating the prefix name. This commit also fixes a use after free in this scenario: * A command gets created via Python (using the gdb.Command class). The prefix name member is dynamically allocated. * An alias to the new command is created. The alias's prefixname is set to point to the prefixname for the original command with a direct assignment. * A new command with the same name as the Python command is created. * The object for the original Python command gets freed and its prefixname gets freed as well. * The alias is updated to point to the new command, but its prefixname is not updated so it keeps pointing to the freed one. gdb/ChangeLog: * command.h (add_prefix_cmd): Remove the prefixname argument as it can now be generated automatically. Update all callers. (add_basic_prefix_cmd): Ditto. (add_show_prefix_cmd): Ditto. (add_prefix_cmd_suppress_notification): Ditto. (add_abbrev_prefix_cmd): Ditto. * cli/cli-decode.c (add_prefix_cmd): Ditto. (add_basic_prefix_cmd): Ditto. (add_show_prefix_cmd): Ditto. (add_prefix_cmd_suppress_notification): Ditto. (add_prefix_cmd_suppress_notification): Ditto. (add_abbrev_prefix_cmd): Ditto. * cli/cli-decode.h (struct cmd_list_element): Replace the prefixname member variable with a method which generates the prefix name at runtime. Update all code reading the prefix name to use the method, and remove all code setting it. * python/py-cmd.c (cmdpy_destroyer): Remove code to free the prefixname member as it's now a method. (cmdpy_function): Determine if the command is a prefix by looking at prefixlist, not prefixname.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-layout.c2
-rw-r--r--gdb/tui/tui-win.c8
2 files changed, 4 insertions, 6 deletions
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index bf9c3ff..b54e748 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -1022,7 +1022,7 @@ _initialize_tui_layout ()
add_basic_prefix_cmd ("layout", class_tui, _("\
Change the layout of windows.\n\
Usage: layout prev | next | LAYOUT-NAME"),
- &layout_list, "layout ", 0, &cmdlist);
+ &layout_list, 0, &cmdlist);
add_cmd ("next", class_tui, tui_next_layout_command,
_("Apply the next TUI layout."),
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 17682b0..f036127 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -306,7 +306,7 @@ tui_get_cmd_list (void)
if (tuilist == 0)
add_basic_prefix_cmd ("tui", class_tui,
_("Text User Interface commands."),
- &tuilist, "tui ", 0, &cmdlist);
+ &tuilist, 0, &cmdlist);
return &tuilist;
}
@@ -996,12 +996,10 @@ _initialize_tui_win ()
They will appear in the help list in the reverse of this order. */
add_basic_prefix_cmd ("tui", class_tui,
_("TUI configuration variables."),
- &tui_setlist, "set tui ",
- 0 /* allow-unknown */, &setlist);
+ &tui_setlist, 0 /* allow-unknown */, &setlist);
add_show_prefix_cmd ("tui", class_tui,
_("TUI configuration variables."),
- &tui_showlist, "show tui ",
- 0 /* allow-unknown */, &showlist);
+ &tui_showlist, 0 /* allow-unknown */, &showlist);
add_com ("refresh", class_tui, tui_refresh_all_command,
_("Refresh the terminal display."));