mirror of
				https://github.com/espressif/binutils-gdb.git
				synced 2025-11-04 06:37:06 +08:00 
			
		
		
		
	gdb: use std::string for internalvar::name
Change internalvar::name to std::string, automating memory management. It becomes necessary to allocate internalvar with new instead of XNEW. I didn't find how to trigger the code in complete_internalvar. It is called from condition_completer, so it should be by using the "condition" command, but I never managed to get in the right code path. Change-Id: I814d61361663e7becb8f3fb5f58c0180cdc414bc Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
		
							
								
								
									
										20
									
								
								gdb/value.c
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										20
									
								
								gdb/value.c
									
									
									
									
									
								
							@ -1830,7 +1830,7 @@ union internalvar_data
 | 
				
			|||||||
struct internalvar
 | 
					struct internalvar
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  struct internalvar *next;
 | 
					  struct internalvar *next;
 | 
				
			||||||
  char *name;
 | 
					  std::string name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* We support various different kinds of content of an internal variable.
 | 
					  /* We support various different kinds of content of an internal variable.
 | 
				
			||||||
     enum internalvar_kind specifies the kind, and union internalvar_data
 | 
					     enum internalvar_kind specifies the kind, and union internalvar_data
 | 
				
			||||||
@ -1894,7 +1894,7 @@ lookup_only_internalvar (const char *name)
 | 
				
			|||||||
  struct internalvar *var;
 | 
					  struct internalvar *var;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (var = internalvars; var; var = var->next)
 | 
					  for (var = internalvars; var; var = var->next)
 | 
				
			||||||
    if (strcmp (var->name, name) == 0)
 | 
					    if (var->name == name)
 | 
				
			||||||
      return var;
 | 
					      return var;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return NULL;
 | 
					  return NULL;
 | 
				
			||||||
@ -1912,8 +1912,8 @@ complete_internalvar (completion_tracker &tracker, const char *name)
 | 
				
			|||||||
  len = strlen (name);
 | 
					  len = strlen (name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (var = internalvars; var; var = var->next)
 | 
					  for (var = internalvars; var; var = var->next)
 | 
				
			||||||
    if (strncmp (var->name, name, len) == 0)
 | 
					    if (var->name.compare (0, len, name) == 0)
 | 
				
			||||||
      tracker.add_completion (make_unique_xstrdup (var->name));
 | 
					      tracker.add_completion (make_unique_xstrdup (var->name.c_str ()));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Create an internal variable with name NAME and with a void value.
 | 
					/* Create an internal variable with name NAME and with a void value.
 | 
				
			||||||
@ -1922,9 +1922,9 @@ complete_internalvar (completion_tracker &tracker, const char *name)
 | 
				
			|||||||
struct internalvar *
 | 
					struct internalvar *
 | 
				
			||||||
create_internalvar (const char *name)
 | 
					create_internalvar (const char *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  struct internalvar *var = XNEW (struct internalvar);
 | 
					  internalvar *var = new internalvar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var->name = xstrdup (name);
 | 
					  var->name = name;
 | 
				
			||||||
  var->kind = INTERNALVAR_VOID;
 | 
					  var->kind = INTERNALVAR_VOID;
 | 
				
			||||||
  var->next = internalvars;
 | 
					  var->next = internalvars;
 | 
				
			||||||
  internalvars = var;
 | 
					  internalvars = var;
 | 
				
			||||||
@ -1996,7 +1996,7 @@ value_of_internalvar (struct gdbarch *gdbarch, struct internalvar *var)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  /* If there is a trace state variable of the same name, assume that
 | 
					  /* If there is a trace state variable of the same name, assume that
 | 
				
			||||||
     is what we really want to see.  */
 | 
					     is what we really want to see.  */
 | 
				
			||||||
  tsv = find_trace_state_variable (var->name);
 | 
					  tsv = find_trace_state_variable (var->name.c_str ());
 | 
				
			||||||
  if (tsv)
 | 
					  if (tsv)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      tsv->value_known = target_get_trace_state_variable_value (tsv->number,
 | 
					      tsv->value_known = target_get_trace_state_variable_value (tsv->number,
 | 
				
			||||||
@ -2149,7 +2149,7 @@ set_internalvar (struct internalvar *var, struct value *val)
 | 
				
			|||||||
  union internalvar_data new_data = { 0 };
 | 
					  union internalvar_data new_data = { 0 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (var->kind == INTERNALVAR_FUNCTION && var->u.fn.canonical)
 | 
					  if (var->kind == INTERNALVAR_FUNCTION && var->u.fn.canonical)
 | 
				
			||||||
    error (_("Cannot overwrite convenience function %s"), var->name);
 | 
					    error (_("Cannot overwrite convenience function %s"), var->name.c_str ());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Prepare new contents.  */
 | 
					  /* Prepare new contents.  */
 | 
				
			||||||
  switch (check_typedef (val->type ())->code ())
 | 
					  switch (check_typedef (val->type ())->code ())
 | 
				
			||||||
@ -2261,7 +2261,7 @@ clear_internalvar (struct internalvar *var)
 | 
				
			|||||||
const char *
 | 
					const char *
 | 
				
			||||||
internalvar_name (const struct internalvar *var)
 | 
					internalvar_name (const struct internalvar *var)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  return var->name;
 | 
					  return var->name.c_str ();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct internal_function *
 | 
					static struct internal_function *
 | 
				
			||||||
@ -2453,7 +2453,7 @@ show_convenience (const char *ignore, int from_tty)
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
	  varseen = 1;
 | 
						  varseen = 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
      gdb_printf (("$%s = "), var->name);
 | 
					      gdb_printf (("$%s = "), var->name.c_str ());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      try
 | 
					      try
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user