This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[obv] Replace savestring by xstrdup where possible


Hi,

this check in removes one of the code obfuscations.  I am sorry if it breaks
off-trunk patches; I maintain also a lot of such.

The only non-mechanical change there was the tracepoint.c
stringify_collection_list() one.

Verified by regexes, regression tested on x86_64-unknown-linux-gnu.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2009-05/msg00159.html

2009-05-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Replace the savestring calls by xstrdup calls where possible.
	* breakpoint.c (condition_command, set_raw_breakpoint)
	(create_catchpoint, update_breakpoint_locations): Replace the
	savestring calls by xstrdup calls where possible.
	* buildsym.c (start_subfile, patch_subfile_names, record_debugformat)
	(record_producer): Likewise.
	* coffread.c (coff_start_symtab, complete_symtab): Likewise.
	* corefile.c (set_gnutarget): Likewise.
	* dbxread.c (add_new_header_file): Likewise.
	* demangle.c (set_demangling_command, set_demangling_style): Likewise.
	* event-top.c (push_prompt, pop_prompt, command_line_handler)
	(set_async_prompt): Likewise.
	* infcmd.c (set_inferior_io_terminal, attach_command_post_wait):
	Likewise.
	* language.c (set_language_command, _initialize_language): Likewise.
	* linespec.c (decode_line_2): Likewise.
	* rs6000-nat.c (add_vmap): Likewise.
	* top.c (set_prompt, init_history, init_main): Likewise.
	* tracepoint.c (stringify_collection_list): Likewise.
	* varobj.c (varobj_create): Remove variable expr_len.  Replace the 
	savestring calls by xstrdup calls where possible.
	(value_of_root, c_name_of_variable, c_describe_child): Replace the
	savestring calls by xstrdup calls where possible.
	* xcoffread.c (complete_symtab): Likewise.
	* cli/cli-script.c (build_command_line, define_command): Likewise.
	* cli/cli-setshow.c (do_setshow_command): Likewise.

--- src/gdb/breakpoint.c	2009/05/19 00:23:49	1.397
+++ src/gdb/breakpoint.c	2009/05/23 16:17:13	1.398
@@ -597,7 +597,7 @@
 	    arg = p;
 	    /* I don't know if it matters whether this is the string the user
 	       typed in or the decompiled expression.  */
-	    b->cond_string = savestring (arg, strlen (arg));
+	    b->cond_string = xstrdup (arg);
 	    b->condition_not_parsed = 0;
 	    for (loc = b->loc; loc; loc = loc->next)
 	      {
@@ -4394,8 +4394,7 @@
   if (sal.symtab == NULL)
     b->source_file = NULL;
   else
-    b->source_file = savestring (sal.symtab->filename,
-				 strlen (sal.symtab->filename));
+    b->source_file = xstrdup (sal.symtab->filename);
   b->loc->section = sal.section;
   b->line_number = sal.line;
 
@@ -4816,8 +4815,7 @@
   set_breakpoint_count (breakpoint_count + 1);
   b->number = breakpoint_count;
 
-  b->cond_string = (cond_string == NULL) ? 
-    NULL : savestring (cond_string, strlen (cond_string));
+  b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
   b->thread = -1;
   b->addr_string = NULL;
   b->enable_state = bp_enabled;
@@ -7490,9 +7488,7 @@
       if (sals.sals[i].symtab == NULL)
 	b->source_file = NULL;
       else
-	b->source_file =
-	  savestring (sals.sals[i].symtab->filename,
-		      strlen (sals.sals[i].symtab->filename));
+	b->source_file = xstrdup (sals.sals[i].symtab->filename);
 
       if (b->line_number == 0)
 	b->line_number = sals.sals[i].line;
--- src/gdb/buildsym.c	2009/03/24 01:32:46	1.69
+++ src/gdb/buildsym.c	2009/05/23 16:17:13	1.70
@@ -561,9 +561,8 @@
   current_subfile = subfile;
 
   /* Save its name and compilation directory name */
-  subfile->name = (name == NULL) ? NULL : savestring (name, strlen (name));
-  subfile->dirname =
-    (dirname == NULL) ? NULL : savestring (dirname, strlen (dirname));
+  subfile->name = (name == NULL) ? NULL : xstrdup (name);
+  subfile->dirname = (dirname == NULL) ? NULL : xstrdup (dirname);
 
   /* Initialize line-number recording for this subfile.  */
   subfile->line_vector = NULL;
@@ -638,7 +637,7 @@
       && subfile->name[strlen (subfile->name) - 1] == '/')
     {
       subfile->dirname = subfile->name;
-      subfile->name = savestring (name, strlen (name));
+      subfile->name = xstrdup (name);
       last_source_file = name;
 
       /* Default the source language to whatever can be deduced from
@@ -1260,7 +1259,7 @@
 void
 record_debugformat (char *format)
 {
-  current_subfile->debugformat = savestring (format, strlen (format));
+  current_subfile->debugformat = xstrdup (format);
 }
 
 void
@@ -1271,7 +1270,7 @@
   if (producer == NULL)
     return;
 
-  current_subfile->producer = savestring (producer, strlen (producer));
+  current_subfile->producer = xstrdup (producer);
 }
 
 /* Merge the first symbol list SRCLIST into the second symbol list
--- src/gdb/coffread.c	2009/05/23 09:32:47	1.91
+++ src/gdb/coffread.c	2009/05/23 16:17:13	1.92
@@ -364,7 +364,7 @@
      this pointer into last_source_file and we put it in
      subfiles->name, which end_symtab frees; that's why
      it must be malloc'd.  */
-		 savestring (name, strlen (name)),
+		 xstrdup (name),
   /* We never know the directory name for COFF.  */
 		 NULL,
   /* The start address is irrelevant, since we set
@@ -383,7 +383,7 @@
 {
   if (last_source_file != NULL)
     xfree (last_source_file);
-  last_source_file = savestring (name, strlen (name));
+  last_source_file = xstrdup (name);
   current_source_start_addr = start_addr;
   current_source_end_addr = start_addr + size;
 }
--- src/gdb/corefile.c	2009/01/28 00:09:49	1.51
+++ src/gdb/corefile.c	2009/05/23 16:17:13	1.52
@@ -399,7 +399,7 @@
 {
   if (gnutarget_string != NULL)
     xfree (gnutarget_string);
-  gnutarget_string = savestring (newtarget, strlen (newtarget));
+  gnutarget_string = xstrdup (newtarget);
   set_gnutarget_command (NULL, 0, NULL);
 }
 
--- src/gdb/dbxread.c	2009/05/02 09:41:52	1.101
+++ src/gdb/dbxread.c	2009/05/23 16:17:13	1.102
@@ -395,7 +395,7 @@
 
   i = N_HEADER_FILES (current_objfile)++;
   hfile = HEADER_FILES (current_objfile) + i;
-  hfile->name = savestring (name, strlen (name));
+  hfile->name = xstrdup (name);
   hfile->instance = instance;
   hfile->length = 10;
   hfile->vector
--- src/gdb/demangle.c	2009/01/03 05:57:51	1.22
+++ src/gdb/demangle.c	2009/05/23 16:17:13	1.23
@@ -125,8 +125,7 @@
 	    {
 	      xfree (current_demangling_style_string);
 	      current_demangling_style_string =
-		savestring (dem->demangling_style_name,
-			    strlen (dem->demangling_style_name));
+		xstrdup (dem->demangling_style_name);
 	    }
 	}
       if (current_demangling_style == unknown_demangling)
@@ -136,9 +135,7 @@
 	     one as the default. */
 	  current_demangling_style = libiberty_demanglers[0].demangling_style;
 	  current_demangling_style_string =
-	    savestring (
-              libiberty_demanglers[0].demangling_style_name,
-	      strlen (libiberty_demanglers[0].demangling_style_name));
+	    xstrdup (libiberty_demanglers[0].demangling_style_name);
 	  warning (_("`%s' style demangling chosen as the default."),
 		   current_demangling_style_string);
 	}
@@ -154,7 +151,7 @@
     {
       xfree (current_demangling_style_string);
     }
-  current_demangling_style_string = savestring (style, strlen (style));
+  current_demangling_style_string = xstrdup (style);
   set_demangling_command ((char *) NULL, 0, (struct cmd_list_element *) NULL);
 }
 
--- src/gdb/event-top.c	2009/05/21 16:00:13	1.67
+++ src/gdb/event-top.c	2009/05/23 16:17:15	1.68
@@ -372,22 +372,22 @@
 /* Pushes a new prompt on the prompt stack. Each prompt has three
    parts: prefix, prompt, suffix. Usually prefix and suffix are empty
    strings, except when the annotation level is 2. Memory is allocated
-   within savestring for the new prompt. */
+   within xstrdup for the new prompt. */
 void
 push_prompt (char *prefix, char *prompt, char *suffix)
 {
   the_prompts.top++;
-  PREFIX (0) = savestring (prefix, strlen (prefix));
+  PREFIX (0) = xstrdup (prefix);
 
   /* Note that this function is used by the set annotate 2
      command. This is why we take care of saving the old prompt
      in case a new one is not specified. */
   if (prompt)
-    PROMPT (0) = savestring (prompt, strlen (prompt));
+    PROMPT (0) = xstrdup (prompt);
   else
-    PROMPT (0) = savestring (PROMPT (-1), strlen (PROMPT (-1)));
+    PROMPT (0) = xstrdup (PROMPT (-1));
 
-  SUFFIX (0) = savestring (suffix, strlen (suffix));
+  SUFFIX (0) = xstrdup (suffix);
 }
 
 /* Pops the top of the prompt stack, and frees the memory allocated for it. */
@@ -404,7 +404,7 @@
     if (strcmp (PROMPT (0), PROMPT (-1)))
       {
 	xfree (PROMPT (-1));
-	PROMPT (-1) = savestring (PROMPT (0), strlen (PROMPT (0)));
+	PROMPT (-1) = xstrdup (PROMPT (0));
       }
 
   xfree (PREFIX (0));
@@ -624,8 +624,7 @@
     {
       p--;			/* Put on top of '\'.  */
 
-      readline_input_state.linebuffer = savestring (linebuffer,
-						    strlen (linebuffer));
+      readline_input_state.linebuffer = xstrdup (linebuffer);
       readline_input_state.linebuffer_ptr = p;
 
       /* We will not invoke a execute_command if there is more
@@ -1063,7 +1062,7 @@
 void
 set_async_prompt (char *args, int from_tty, struct cmd_list_element *c)
 {
-  PROMPT (0) = savestring (new_async_prompt, strlen (new_async_prompt));
+  PROMPT (0) = xstrdup (new_async_prompt);
 }
 
 /* Set things up for readline to be invoked via the alternate
--- src/gdb/infcmd.c	2009/05/19 10:08:19	1.242
+++ src/gdb/infcmd.c	2009/05/23 16:17:15	1.243
@@ -178,7 +178,7 @@
   if (!terminal_name)
     inferior_io_terminal = NULL;
   else
-    inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
+    inferior_io_terminal = xstrdup (terminal_name);
 }
 
 const char *
@@ -2154,7 +2154,7 @@
 	     filename.  Not much more we can do...)
 	   */
 	  if (!source_full_path_of (exec_file, &full_exec_path))
-	    full_exec_path = savestring (exec_file, strlen (exec_file));
+	    full_exec_path = xstrdup (exec_file);
 
 	  exec_file_attach (full_exec_path, from_tty);
 	  symbol_file_add_main (full_exec_path, from_tty);
--- src/gdb/language.c	2009/03/20 23:04:33	1.83
+++ src/gdb/language.c	2009/05/23 16:17:17	1.84
@@ -215,7 +215,7 @@
 
   /* Reset the language (esp. the global string "language") to the 
      correct values. */
-  err_lang = savestring (language, strlen (language));
+  err_lang = xstrdup (language);
   make_cleanup (xfree, err_lang);	/* Free it after error */
   set_language (current_language->la_language);
   error (_("Unknown language `%s'."), err_lang);
@@ -1401,10 +1401,10 @@
   add_language (&local_language_defn);
   add_language (&auto_language_defn);
 
-  language = savestring ("auto", strlen ("auto"));
-  type = savestring ("auto", strlen ("auto"));
-  range = savestring ("auto", strlen ("auto"));
-  case_sensitive = savestring ("auto",strlen ("auto"));
+  language = xstrdup ("auto");
+  type = xstrdup ("auto");
+  range = xstrdup ("auto");
+  case_sensitive = xstrdup ("auto");
 
   /* Have the above take effect */
   set_language (language_auto);
--- src/gdb/linespec.c	2009/01/03 05:57:52	1.84
+++ src/gdb/linespec.c	2009/05/23 16:17:17	1.85
@@ -587,7 +587,7 @@
 		  if (canonical_arr[i] == NULL)
 		    {
 		      symname = SYMBOL_LINKAGE_NAME (sym_arr[i]);
-		      canonical_arr[i] = savestring (symname, strlen (symname));
+		      canonical_arr[i] = xstrdup (symname);
 		    }
 		}
 	    }
@@ -611,7 +611,7 @@
 		{
 		  symname = SYMBOL_LINKAGE_NAME (sym_arr[num]);
 		  make_cleanup (xfree, symname);
-		  canonical_arr[i] = savestring (symname, strlen (symname));
+		  canonical_arr[i] = xstrdup (symname);
 		}
 	      return_values.sals[i++] = values.sals[num];
 	      values.sals[num].pc = 0;
--- src/gdb/rs6000-nat.c	2009/05/22 23:49:13	1.91
+++ src/gdb/rs6000-nat.c	2009/05/23 16:17:18	1.92
@@ -736,8 +736,8 @@
 
   filename = LDI_FILENAME (ldi, arch64);
   mem = filename + strlen (filename) + 1;
-  mem = savestring (mem, strlen (mem));
-  objname = savestring (filename, strlen (filename));
+  mem = xstrdup (mem);
+  objname = xstrdup (filename);
 
   fd = LDI_FD (ldi, arch64);
   if (fd < 0)
--- src/gdb/top.c	2009/05/21 15:48:41	1.165
+++ src/gdb/top.c	2009/05/23 16:17:18	1.166
@@ -1153,11 +1153,11 @@
 set_prompt (char *s)
 {
 /* ??rehrauer: I don't know why this fails, since it looks as though
-   assignments to prompt are wrapped in calls to savestring...
+   assignments to prompt are wrapped in calls to xstrdup...
    if (prompt != NULL)
    xfree (prompt);
  */
-  PROMPT (0) = savestring (s, strlen (s));
+  PROMPT (0) = xstrdup (s);
 }
 
 
@@ -1458,7 +1458,7 @@
 
   tmpenv = getenv ("GDBHISTFILE");
   if (tmpenv)
-    history_filename = savestring (tmpenv, strlen (tmpenv));
+    history_filename = xstrdup (tmpenv);
   else if (!history_filename)
     {
       /* We include the current directory so that if the user changes
@@ -1516,13 +1516,13 @@
      whatever the DEFAULT_PROMPT is.  */
   the_prompts.top = 0;
   PREFIX (0) = "";
-  PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
+  PROMPT (0) = xstrdup (DEFAULT_PROMPT);
   SUFFIX (0) = "";
   /* Set things up for annotation_level > 1, if the user ever decides
      to use it.  */
   async_annotation_suffix = "prompt";
   /* Set the variable associated with the setshow prompt command.  */
-  new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0)));
+  new_async_prompt = xstrdup (PROMPT (0));
 
   /* If gdb was started with --annotate=2, this is equivalent to the
      user entering the command 'set annotate 2' at the gdb prompt, so
--- src/gdb/tracepoint.c	2009/05/22 00:52:05	1.118
+++ src/gdb/tracepoint.c	2009/05/23 16:17:18	1.119
@@ -938,7 +938,7 @@
 	  sprintf (end, "%02X", list->regs_mask[i]);
 	  end += 2;
 	}
-      (*str_list)[ndx] = savestring (temp_buf, end - temp_buf);
+      (*str_list)[ndx] = xstrdup (temp_buf);
       ndx++;
     }
   if (info_verbose)
--- src/gdb/varobj.c	2009/05/23 15:34:36	1.129
+++ src/gdb/varobj.c	2009/05/23 16:17:18	1.130
@@ -461,7 +461,6 @@
       char *p;
       enum varobj_languages lang;
       struct value *value = NULL;
-      int expr_len;
 
       /* Parse and evaluate the expression, filling in as much of the
          variable's data as possible.  */
@@ -512,10 +511,9 @@
 
       var->format = variable_default_display (var);
       var->root->valid_block = innermost_block;
-      expr_len = strlen (expression);
-      var->name = savestring (expression, expr_len);
+      var->name = xstrdup (expression);
       /* For a root var, the name and the expr are the same.  */
-      var->path_expr = savestring (expression, expr_len);
+      var->path_expr = xstrdup (expression);
 
       /* When the frame is different from the current frame, 
          we must select the appropriate frame before parsing
@@ -561,7 +559,7 @@
 
   if ((var != NULL) && (objname != NULL))
     {
-      var->obj_name = savestring (objname, strlen (objname));
+      var->obj_name = xstrdup (objname);
 
       /* If a varobj name is duplicated, the install will fail so
          we must clenup */
@@ -1765,8 +1763,7 @@
 	}
       else
 	{
-	  tmp_var->obj_name =
-	    savestring (var->obj_name, strlen (var->obj_name));
+	  tmp_var->obj_name = xstrdup (var->obj_name);
 	  varobj_delete (var, NULL, 0);
 
 	  install_variable (tmp_var);
@@ -2015,7 +2012,7 @@
 static char *
 c_name_of_variable (struct varobj *parent)
 {
-  return savestring (parent->name, strlen (parent->name));
+  return xstrdup (parent->name);
 }
 
 /* Return the value of element TYPE_INDEX of a structure
@@ -2114,10 +2111,7 @@
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
       if (cname)
-	{
-	  char *string = TYPE_FIELD_NAME (type, index);
-	  *cname = savestring (string, strlen (string));
-	}
+	*cname = xstrdup (TYPE_FIELD_NAME (type, index));
 
       if (cvalue && value)
 	{
--- src/gdb/xcoffread.c	2009/03/12 17:56:20	1.67
+++ src/gdb/xcoffread.c	2009/05/23 16:17:18	1.68
@@ -831,8 +831,8 @@
    text address for the file, and SIZE is the number of bytes of text.  */
 
 #define complete_symtab(name, start_addr) {	\
-  last_source_file = savestring (name, strlen (name));	\
-  last_source_start_addr = start_addr;			\
+  last_source_file = xstrdup (name);		\
+  last_source_start_addr = start_addr;		\
 }
 
 
--- src/gdb/cli/cli-script.c	2009/02/25 02:14:23	1.51
+++ src/gdb/cli/cli-script.c	2009/05/23 16:17:18	1.52
@@ -94,7 +94,7 @@
     = (struct command_line **) xmalloc (sizeof (struct command_line *)
 					* cmd->body_count);
   memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
-  cmd->line = savestring (args, strlen (args));
+  cmd->line = xstrdup (args);
 
   return cmd;
 }
@@ -1384,7 +1384,7 @@
 	}
     }
 
-  comname = savestring (comname, strlen (comname));
+  comname = xstrdup (comname);
 
   /* If the rest of the commands will be case insensitive, this one
      should behave in the same manner. */
@@ -1400,7 +1400,7 @@
 
   newc = add_cmd (comname, class_user, user_defined_command,
 		  (c && c->class == class_user)
-		  ? c->doc : savestring ("User-defined.", 13), list);
+		  ? c->doc : xstrdup ("User-defined."), list);
   newc->user_commands = cmds;
 
   /* If this new command is a hook, then mark both commands as being
--- src/gdb/cli/cli-setshow.c	2009/01/23 18:47:45	1.35
+++ src/gdb/cli/cli-setshow.c	2009/05/23 16:17:18	1.36
@@ -177,14 +177,14 @@
 	    arg = "";
 	  if (*(char **) c->var != NULL)
 	    xfree (*(char **) c->var);
-	  *(char **) c->var = savestring (arg, strlen (arg));
+	  *(char **) c->var = xstrdup (arg);
 	  break;
 	case var_optional_filename:
 	  if (arg == NULL)
 	    arg = "";
 	  if (*(char **) c->var != NULL)
 	    xfree (*(char **) c->var);
-	  *(char **) c->var = savestring (arg, strlen (arg));
+	  *(char **) c->var = xstrdup (arg);
 	  break;
 	case var_filename:
 	  if (arg == NULL)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]