diff options
author | Marco Barisione <mbarisione@undo.io> | 2021-05-12 11:19:22 +0100 |
---|---|---|
committer | Marco Barisione <mbarisione@undo.io> | 2021-05-12 11:19:22 +0100 |
commit | 2f822da535ba9b159174d02d7114b4fc4f7c8818 (patch) | |
tree | 7014b48d9f7893385ed27091caa75c28964c3514 /gdb/breakpoint.c | |
parent | f0bbe8bab84e9b9dc5367a5fe1d0b8d233bf213c (diff) | |
download | gdb-2f822da535ba9b159174d02d7114b4fc4f7c8818.zip gdb-2f822da535ba9b159174d02d7114b4fc4f7c8818.tar.gz gdb-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/breakpoint.c')
-rw-r--r-- | gdb/breakpoint.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 38406b4..d479f00 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -15731,7 +15731,7 @@ Give breakpoint numbers (separated by spaces) as arguments.\n\ With no subcommand, breakpoints are enabled until you command otherwise.\n\ This is used to cancel the effect of the \"disable\" command.\n\ With a subcommand you can enable temporarily."), - &enablelist, "enable ", 1, &cmdlist); + &enablelist, 1, &cmdlist); add_com_alias ("en", "enable", class_breakpoint, 1); @@ -15741,7 +15741,7 @@ Usage: enable breakpoints [BREAKPOINTNUM]...\n\ Give breakpoint numbers (separated by spaces) as arguments.\n\ This is used to cancel the effect of the \"disable\" command.\n\ May be abbreviated to simply \"enable\"."), - &enablebreaklist, "enable breakpoints ", 1, &enablelist); + &enablebreaklist, 1, &enablelist); add_cmd ("once", no_class, enable_once_command, _("\ Enable some breakpoints for one hit.\n\ @@ -15787,7 +15787,7 @@ Usage: disable [BREAKPOINTNUM]...\n\ Arguments are breakpoint numbers with spaces in between.\n\ To disable all breakpoints, give no argument.\n\ A disabled breakpoint is not forgotten, but has no effect until re-enabled."), - &disablelist, "disable ", 1, &cmdlist); + &disablelist, 1, &cmdlist); add_com_alias ("dis", "disable", class_breakpoint, 1); add_com_alias ("disa", "disable", class_breakpoint, 1); @@ -15807,7 +15807,7 @@ Arguments are breakpoint numbers with spaces in between.\n\ To delete all breakpoints, give no argument.\n\ \n\ Also a prefix command for deletion of other GDB objects."), - &deletelist, "delete ", 1, &cmdlist); + &deletelist, 1, &cmdlist); add_com_alias ("d", "delete", class_breakpoint, 1); add_com_alias ("del", "delete", class_breakpoint, 1); @@ -15843,7 +15843,7 @@ BREAK_ARGS_HELP ("break"))); { add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ Break in function/address or break at a line in the current file."), - &stoplist, "stop ", 1, &cmdlist); + &stoplist, 1, &cmdlist); add_cmd ("in", class_breakpoint, stopin_command, _("Break in function or address."), &stoplist); add_cmd ("at", class_breakpoint, stopat_command, @@ -15906,12 +15906,12 @@ breakpoint set."), add_basic_prefix_cmd ("catch", class_breakpoint, _("\ Set catchpoints to catch events."), - &catch_cmdlist, "catch ", + &catch_cmdlist, 0/*allow-unknown*/, &cmdlist); add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\ Set temporary catchpoints to catch events."), - &tcatch_cmdlist, "tcatch ", + &tcatch_cmdlist, 0/*allow-unknown*/, &cmdlist); add_catch_command ("fork", _("Catch calls to fork."), @@ -16083,7 +16083,7 @@ if TPNUM is omitted, passcount refers to the last tracepoint defined.")); add_basic_prefix_cmd ("save", class_breakpoint, _("Save breakpoint definitions as a script."), - &save_cmdlist, "save ", + &save_cmdlist, 0/*allow-unknown*/, &cmdlist); c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ @@ -16107,13 +16107,13 @@ Use the 'source' command in another debug session to restore them."), Breakpoint specific settings.\n\ Configure various breakpoint-specific variables such as\n\ pending breakpoint behavior."), - &breakpoint_set_cmdlist, "set breakpoint ", + &breakpoint_set_cmdlist, 0/*allow-unknown*/, &setlist); add_show_prefix_cmd ("breakpoint", class_maintenance, _("\ Breakpoint specific settings.\n\ Configure various breakpoint-specific variables such as\n\ pending breakpoint behavior."), - &breakpoint_show_cmdlist, "show breakpoint ", + &breakpoint_show_cmdlist, 0/*allow-unknown*/, &showlist); add_setshow_auto_boolean_cmd ("pending", no_class, |