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]

rename the `line' and `linesize' globals


I got bitten for not noticing "line" was a global while debugging
some other patch.  And when I realized it, I found its name
is very grep unfriendly.

This patch renames it (and gets rid of the ugly
local "extern char *line").

Tested on x86_64-linux and applied.

-- 
Pedro Alves

2011-06-13  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* top.h (line): Rename to ...
	(saved_command_line): ... this.
	(linesize): Rename to ...
	(saved_command_line_size): ... this.
	* top.c (line): Rename to ...
	(saved_command_line): ... this.
	(linesize): Rename to ...
	(saved_command_line_size): ... this.
	(dont_repeat, command_line_input, dont_repeat_command): Adjust.
	* event-top.c (command_line_handler): Adjust.
	* main.c (captured_main): Adjust.

---
 gdb/event-top.c |   16 +++++++---------
 gdb/main.c      |    4 ++--
 gdb/top.c       |   25 +++++++++++++------------
 gdb/top.h       |    4 ++--
 4 files changed, 24 insertions(+), 25 deletions(-)

Index: src/gdb/top.h
===================================================================
--- src.orig/gdb/top.h	2011-06-02 15:01:06.000000000 +0100
+++ src/gdb/top.h	2011-06-10 16:06:54.357748830 +0100
@@ -23,8 +23,8 @@
 #define TOP_H
 
 /* From top.c.  */
-extern char *line;
-extern int linesize;
+extern char *saved_command_line;
+extern int saved_command_line_size;
 extern FILE *instream;
 extern int in_user_command;
 extern int caution;
Index: src/gdb/top.c
===================================================================
--- src.orig/gdb/top.c	2011-06-10 16:02:12.000000000 +0100
+++ src/gdb/top.c	2011-06-10 16:09:10.677748782 +0100
@@ -137,8 +137,8 @@ int xgdb_verbose;
 /* Buffer used for reading command lines, and the size
    allocated for it so far.  */
 
-char *line;
-int linesize = 100;
+char *saved_command_line;
+int saved_command_line_size = 100;
 
 /* Nonzero if the current command is modified by "server ".  This
    affects things like recording into the command history, commands
@@ -572,7 +572,7 @@ dont_repeat (void)
      thing read from stdin in line and don't want to delete it.  Null
      lines won't repeat here in any case.  */
   if (instream == stdin)
-    *line = 0;
+    *saved_command_line = 0;
 }
 
 /* Prevent dont_repeat from working, and return a cleanup that
@@ -1034,10 +1034,10 @@ command_line_input (char *prompt_arg, in
   /* If we just got an empty line, and that is supposed to repeat the
      previous command, return the value in the global buffer.  */
   if (repeat && p == linebuffer)
-    return line;
+    return saved_command_line;
   for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
   if (repeat && !*p1)
-    return line;
+    return saved_command_line;
 
   *p = 0;
 
@@ -1058,13 +1058,13 @@ command_line_input (char *prompt_arg, in
   /* Save into global buffer if appropriate.  */
   if (repeat)
     {
-      if (linelength > linesize)
+      if (linelength > saved_command_line_size)
 	{
-	  line = xrealloc (line, linelength);
-	  linesize = linelength;
+	  saved_command_line = xrealloc (saved_command_line, linelength);
+	  saved_command_line_size = linelength;
 	}
-      strcpy (line, linebuffer);
-      return line;
+      strcpy (saved_command_line, linebuffer);
+      return saved_command_line;
     }
 
   return linebuffer;
@@ -1314,8 +1314,9 @@ input_from_terminal_p (void)
 static void
 dont_repeat_command (char *ignored, int from_tty)
 {
-  *line = 0;			/* Can't call dont_repeat here because we're 
-				   not necessarily reading from stdin.  */
+  /* Can't call dont_repeat here because we're not necessarily reading
+     from stdin.  */
+  *saved_command_line = 0;
 }
 
 /* Functions to manipulate command line editing control variables.  */
Index: src/gdb/event-top.c
===================================================================
--- src.orig/gdb/event-top.c	2011-06-10 16:02:12.000000000 +0100
+++ src/gdb/event-top.c	2011-06-10 16:10:55.357748746 +0100
@@ -520,8 +520,6 @@ command_line_handler (char *rl)
   static unsigned linelength = 0;
   char *p;
   char *p1;
-  extern char *line;
-  extern int linesize;
   char *nline;
   char got_eof = 0;
 
@@ -661,7 +659,7 @@ command_line_handler (char *rl)
      previous command, return the value in the global buffer.  */
   if (repeat && p == linebuffer && *p != '\\')
     {
-      command_handler (line);
+      command_handler (saved_command_line);
       display_gdb_prompt (0);
       return;
     }
@@ -669,7 +667,7 @@ command_line_handler (char *rl)
   for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
   if (repeat && !*p1)
     {
-      command_handler (line);
+      command_handler (saved_command_line);
       display_gdb_prompt (0);
       return;
     }
@@ -693,15 +691,15 @@ command_line_handler (char *rl)
   /* Save into global buffer if appropriate.  */
   if (repeat)
     {
-      if (linelength > linesize)
+      if (linelength > saved_command_line_size)
 	{
-	  line = xrealloc (line, linelength);
-	  linesize = linelength;
+	  saved_command_line = xrealloc (saved_command_line, linelength);
+	  saved_command_line_size = linelength;
 	}
-      strcpy (line, linebuffer);
+      strcpy (saved_command_line, linebuffer);
       if (!more_to_come)
 	{
-	  command_handler (line);
+	  command_handler (saved_command_line);
 	  display_gdb_prompt (0);
 	}
       return;
Index: src/gdb/main.c
===================================================================
--- src.orig/gdb/main.c	2011-05-12 14:52:36.000000000 +0100
+++ src/gdb/main.c	2011-06-10 16:07:23.927748820 +0100
@@ -319,8 +319,8 @@ captured_main (void *data)
   ndir = 0;
 
   quit_flag = 0;
-  line = (char *) xmalloc (linesize);
-  line[0] = '\0';		/* Terminate saved (now empty) cmd line.  */
+  saved_command_line = (char *) xmalloc (saved_command_line_size);
+  saved_command_line[0] = '\0';
   instream = stdin;
 
   gdb_stdout = stdio_fileopen (stdout);


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