binutils-gdb/gdb/compile
Marco Barisione 2f822da535 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
3f4d92ebdf 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.
2021-05-12 11:19:22 +01:00
..
compile-c-support.c Return unique_ptr from language_defn::get_compile_context 2021-02-05 07:17:12 -07:00
compile-c-symbols.c Use std::vector for "registers_used" in compile feature 2021-01-23 20:33:25 -07:00
compile-c-types.c gdb: rename type::{arch,objfile} -> type::{arch_owner,objfile_owner} 2021-01-28 10:09:02 -05:00
compile-c.h Use std::vector for "registers_used" in compile feature 2021-01-23 20:33:25 -07:00
compile-cplus-symbols.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
compile-cplus-types.c gdb: remove TYPE_DECLARED_CLASS 2021-04-01 21:10:09 -04:00
compile-cplus.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
compile-internal.h Remove call to reset from compile_to_object 2021-01-23 17:48:48 -07:00
compile-loc2c.c Avoid crash when "compile" expression uses cooked register 2021-01-23 20:33:25 -07:00
compile-object-load.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
compile-object-load.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
compile-object-run.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
compile-object-run.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
compile.c gdb: generate the prefix name for prefix commands on demand 2021-05-12 11:19:22 +01:00
compile.h Use std::vector for "registers_used" in compile feature 2021-01-23 20:33:25 -07:00
gcc-c-plugin.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
gcc-cp-plugin.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00