🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #10161

Unofficial patches to minimize GDB's size

#10161
From: Piercarlo Grandi
Date: Sat, 31 Mar 1990 11:43
468 lines
13584 bytes
Here are the very simple patches that will reduce the size of the GDB
executable by avoiding the need for the use of the termcap and readline
libraries. These patches apply to 'main.c' and 'utils.c' of GDB 3.5; they
define three new macros, M_TERMCAP, M_HISTORY, M_CEDIT, that when defined
will enable the compilation of support for the fancier aspects of GDB's
interface. With these patches they are *undefined* by default. If you
already have a pty emulator or a line discipline that does command line
editing and history, and don't mind about completion, leaving them out of
GDB reduces its size by about 30-40%.

To apply, just cd to the GDB sources directory, and say '| patch -c -N' from
rn, or similar. It is very advisable to checkin under RCS these two sources
before patching them, with something like 'ci -u3.5 main.c utils.c'.

===================================================================
RCS file: main.c,v
retrieving revision 3.5
diff -c -r3.5 main.c
*** /tmp/,RCSt1a01449	Thu Mar 15 12:50:07 1990
--- main.c	Thu Mar 15 11:51:06 1990
***************
*** 85,90 ****
--- 85,91 ----
  
  struct cmd_list_element *setlist;
  
+ #ifdef M_HISTORY
  /* Chain containing all defined \"set history\".  */
  
  struct cmd_list_element *sethistlist;
***************
*** 92,97 ****
--- 93,99 ----
  /* Chain containing all defined \"unset history\".  */
  
  struct cmd_list_element *unsethistlist;
+ #endif /* M_HISTORY */
  
  /* stdio stream that command input is being read from.  */
  
***************
*** 614,619 ****
--- 616,622 ----
      return (char *) 0;
  }
  
+ #ifdef M_CEDIT
  /* Declaration for fancy readline with command line editing.  */
  char *readline ();
  
***************
*** 621,631 ****
--- 624,639 ----
     substitution.  These variables are given default values at the end
     of this file.  */
  static int command_editing_p;
+ #endif /* M_CEDIT */
+ 
+ #ifdef M_HISTORY
  static int history_expansion_p;
  static int write_history_p;
  static int history_size;
  static char *history_filename;
+ #endif /* M_HISTORY */
  
+ #ifdef M_CEDIT
  /* Variables which are necessary for fancy command line editing.  */
  char *gdb_completer_word_break_characters =
    " \t\n!@#$%^&*()-+=|~`}{[]\"';:?/>.<,";
***************
*** 744,750 ****
  
    return (output);
  }
! 
  #ifdef STOP_SIGNAL
  static void
  stop_sig ()
--- 752,759 ----
  
    return (output);
  }
! #endif /* M_CEDIT */
! 
  #ifdef STOP_SIGNAL
  static void
  stop_sig ()
***************
*** 802,807 ****
--- 811,817 ----
  catch_termination (sig)
       int sig;
  {
+ #ifdef M_HISTORY
    /* We are probably here because GDB has a bug.  Write out the history
       so that we might have a better chance of reproducing it.  */
    /* Tell the user what we are doing so he can delete the file if
***************
*** 808,813 ****
--- 818,825 ----
       it is unwanted.  */
    write_history (history_filename);
    printf ("\n%s written.\n", history_filename);
+ #endif /* M_HISTORY */
+ 
    signal (sig, SIG_DFL);
    kill (getpid (), sig);
  }
***************
*** 883,893 ****
--- 895,907 ----
  
    while (1)
      {
+ #if M_CEDIT
        /* Don't use fancy stuff if not talking to stdin.  */
        if (command_editing_p && instream == stdin
  	  && ISATTY (instream))
  	rl = readline (local_prompt);
        else
+ #endif /* M_CEDIT */
  	rl = gdb_readline (local_prompt, 1);
  
        if (!rl || rl == (char *) EOF) break;
***************
*** 918,923 ****
--- 932,938 ----
  #endif
    immediate_quit--;
  
+ #ifdef M_HISTORY
    /* Do history expansion if that is wished.  */
    if (history_expansion_p && instream == stdin
        && ISATTY (instream))
***************
*** 948,953 ****
--- 963,969 ----
  	  free (history_value);
  	}
      }
+ #endif /* M_HISTORY */
  
    /* If we just got an empty line, and that is supposed
       to repeat the previous command, return the value in the
***************
*** 965,974 ****
--- 981,992 ----
  
    *p = 0;
  
+ #ifdef M_HISTORY
    /* Add line to history if appropriate.  */
    if (instream == stdin
        && ISATTY (stdin) && *linebuffer)
      add_history (linebuffer);
+ #endif /* M_HISTORY */
  
    /* If line is a comment, clear it out.  */
    /* Note:  comments are added to the command history.
***************
*** 1326,1334 ****
--- 1344,1356 ----
        else
  	error ("Not confirmed.");
      }
+ 
+ #ifdef M_HISTORY
    /* Save the history information if it is appropriate to do so.  */
    if (write_history_p && history_filename)
      write_history (history_filename);
+ #endif /* M_HISTORY */
+ 
    exit (0);
  }
  
***************
*** 1505,1510 ****
--- 1527,1533 ----
        error ("\"%s\" not given a binary valued argument.", caller);
  }
  
+ #ifdef M_CEDIT
  /* Functions to manipulate command line editing control variables.  */
  
  static void
***************
*** 1514,1520 ****
--- 1537,1545 ----
  {
    command_editing_p = parse_binary_operation ("set command-editing", arg);
  }
+ #endif /* M_CEDIT */
  
+ #if defined(M_CEDIT) || defined(M_HISTORY)
  /* Number of commands to print in each call to editing_info.  */
  #define Hist_print 10
  static void
***************
*** 1522,1527 ****
--- 1547,1553 ----
       char *arg;
       int from_tty;
  {
+ #ifdef M_HISTORY
    /* Index for history commands.  Relative to history_base.  */
    int offset;
  
***************
*** 1538,1547 ****
--- 1564,1577 ----
      char *data;
    } *history_get();
    extern int history_base;
+ #endif /* M_HISTORY */
  
+ #ifdef M_CEDIT
    printf_filtered ("Interactive command editing is %s.\n",
  	  command_editing_p ? "on" : "off");
+ #endif /* M_HISTORY */
  
+ #ifdef M_HISTORY
    printf_filtered ("History expansion of command input is %s.\n",
  	  history_expansion_p ? "on" : "off");
    printf_filtered ("Writing of a history record upon exit is %s.\n",
***************
*** 1613,1620 ****
--- 1643,1653 ----
        arg[0] = '+';
        arg[1] = '\0';
      }
+ #endif /* M_HISTORY */
  }
+ #endif /* M_CEDIT || M_HISTORY */
  
+ #ifdef M_HISTORY
  static void
  set_history_expansion (arg, from_tty)
       char *arg;
***************
*** 1677,1682 ****
--- 1710,1716 ----
      history_filename = savestring (arg, i + 1);
    history_filename[i] = '\0';
  }
+ #endif /* M_HISTORY */
  
  int info_verbose;
  
***************
*** 1717,1724 ****
--- 1751,1760 ----
    deletelist = (struct cmd_list_element *) 0;
    enablebreaklist = (struct cmd_list_element *) 0;
    setlist = (struct cmd_list_element *) 0;
+ #ifdef M_HISTORY
    sethistlist = (struct cmd_list_element *) 0;
    unsethistlist = (struct cmd_list_element *) 0;
+ #endif /* M_HISTORY */
  }
  
  static void
***************
*** 1726,1741 ****
  {
    char *tmpenv;
    /* Command line editing externals.  */
    extern int (*rl_completion_entry_function)();
    extern char *rl_completer_word_break_characters;
!   
    /* Set default verbose mode on.  */
    info_verbose = 1;
  
    prompt = savestring ("(gdb) ", 6);
  
    /* Set the important stuff up for command editing.  */
    command_editing_p = 1;
    history_expansion_p = 0;
    write_history_p = 0;
    
--- 1762,1783 ----
  {
    char *tmpenv;
    /* Command line editing externals.  */
+ #ifdef M_CEDIT
    extern int (*rl_completion_entry_function)();
    extern char *rl_completer_word_break_characters;
! #endif /* M_CEDIT */
! 
    /* Set default verbose mode on.  */
    info_verbose = 1;
  
    prompt = savestring ("(gdb) ", 6);
  
+ #ifdef M_CEDIT
    /* Set the important stuff up for command editing.  */
    command_editing_p = 1;
+ #endif /* M_CEDIT */
+ 
+ #ifdef M_HISTORY
    history_expansion_p = 0;
    write_history_p = 0;
    
***************
*** 1755,1764 ****
--- 1797,1809 ----
      history_filename = concat (current_directory, "/.gdb_history", "");
  
    read_history (history_filename);
+ #endif /* M_HISTORY */
  
+ #ifdef M_CEDIT
    /* Setup important stuff for command line editing.  */
    rl_completion_entry_function = (int (*)()) symbol_completion_function;
    rl_completer_word_break_characters = gdb_completer_word_break_characters;
+ #endif /* M_CEDIT */
  
    /* Define the classes of commands.
       They will appear in the help list in the reverse of this order.  */
***************
*** 1830,1840 ****
--- 1875,1888 ----
    add_com ("dump-me", class_obscure, dump_me_command,
  	   "Get fatal error; make debugger dump its core.");
  
+ #ifdef M_CEDIT
    add_cmd ("editing", class_support, set_editing,
  	   "Enable or disable command line editing.\n\
  Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
  Without an argument, command line editing is enabled.", &setlist);
+ #endif /* M_CEDIT */
  
+ #ifdef M_HISTORY
    add_prefix_cmd ("history", class_support, set_history,
  		  "Generic command for setting command history parameters.",
  		  &sethistlist, "set history ", 0, &setlist);
***************
*** 1855,1860 ****
--- 1903,1909 ----
    add_cmd ("filename", no_class, set_history_filename,
  	   "Set the filename in which to record the command history\n\
   (the list of previous commands of which a record is kept).", &sethistlist);
+ #endif /* M_HISTORY */
  
    add_prefix_cmd ("info", class_info, info_command,
  		  "Generic command for printing status.",
***************
*** 1861,1867 ****
--- 1910,1998 ----
  		  &infolist, "info ", 0, &cmdlist);
    add_com_alias ("i", "info", class_info, 1);
  
+ #if defined M_HISTORY || defined M_CEDIT
    add_info ("editing", editing_info, "Status of command editor.");
+ #endif
  
    add_info ("version", version_info, "Report what version of GDB this is.");
+ }
+ 
+ #ifndef M_CEDIT
+ 
+ #include <pwd.h>
+ #ifdef SYSV
+ struct passwd *getpwuid (), *getpwent ();
+ #endif /* SYSV */
+ 
+ #ifndef SYSV
+ #include <sys/dir.h>
+ #else  /* SYSV */
+ #ifdef hpux
+ #include <ndir.h>
+ #else
+ #include <dirent.h>
+ #define direct dirent
+ #define d_namlen d_reclen
+ #endif  /* hpux */
+ #endif  /* SYSV */
+ 
+ /* Expand FILENAME if it begins with a tilde.  This always returns
+    a new string. */
+ char *
+ tilde_expand (filename)
+      char *filename;
+ {
+   char *dirname = filename ? savestring (filename,strlen(filename)) : (char *)NULL;
+ 
+   if (dirname && *dirname == '~')
+     {
+       char *temp_name;
+       if (!dirname[1] || dirname[1] == '/')
+ 	{
+ 	  /* Prepend $HOME to the rest of the string. */
+ 	  char *temp_home = (char *)getenv ("HOME");
+ 
+ 	  temp_name = (char *)alloca (1 + strlen (&dirname[1])
+ 				      + (temp_home? strlen (temp_home) : 0));
+ 	  temp_name[0] = '\0';
+ 	  if (temp_home)
+ 	    strcpy (temp_name, temp_home);
+ 	  strcat (temp_name, &dirname[1]);
+ 	  free (dirname);
+ 	  dirname = savestring (temp_name,strlen(temp_name));
+ 	}
+       else
+ 	{
+ 	  struct passwd *getpwnam (), *user_entry;
+ 	  char *username = (char *)alloca (257);
+ 	  int i, c;
+ 
+ 	  for (i = 1; c = dirname[i]; i++)
+ 	    {
+ 	      if (c == '/') break;
+ 	      else username[i - 1] = c;
+ 	    }
+ 	  username[i - 1] = '\0';
+ 
+ 	  if (!(user_entry = getpwnam (username)))
+ 	    {
+ 	      /*
+ 	       * We shouldn't report errors.
+ 	       */
+ 	    }
+ 	  else
+ 	    {
+ 	      temp_name = (char *)alloca (1 + strlen (user_entry->pw_dir)
+ 					  + strlen (&dirname[i]));
+ 	      strcpy (temp_name, user_entry->pw_dir);
+ 	      strcat (temp_name, &dirname[i]);
+ 	    return_name:
+ 	      free (dirname);
+ 	      dirname = savestring (temp_name,strlen(savestring));
+ 	    }
+ 	}
+     }
+   return (dirname);
  }
+ 
+ #endif /* M_CEDIT */
===================================================================
RCS file: utils.c,v
retrieving revision 3.5
diff -c -r3.5 utils.c
*** /tmp/,RCSt1a01449	Thu Mar 15 12:50:10 1990
--- utils.c	Thu Mar 15 12:45:46 1990
***************
*** 851,856 ****
--- 851,857 ----
       values from termcap.  */
    lines_per_page = 24;
    chars_per_line = 80;
+ #ifdef M_TERMCAP
    /* Initialize the screen height and width from termcap.  */
    {
      int termtype = getenv ("TERM");
***************
*** 885,890 ****
--- 886,892 ----
  	  }
        }
    }
+ #endif /* M_TERMCAP */
  
  #ifdef USG
    /* Initialize signal names.  */

-- 
Piercarlo "Peter" Grandi           | ARPA: pcg%cs.aber.ac.uk@nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth        | UUCP: ...!mcvax!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk
Technical Details
Message-ID: <1706@aber-cs.UUCP>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!ukc!dcl-cs!aber-cs!pcg

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5053,2537cd0626286b64,start
X-Google-Attributes: gidf5053,public
X-Google-ArrivalTime: 1990-03-31 03:43:12 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!ukc!dcl-cs!aber-cs!pcg
From: pcg@aber-cs.UUCP (Piercarlo Grandi)
Newsgroups: gnu.gdb.bug
Subject: Unofficial patches to minimize GDB's size
Summary: Remove (optionally) use of termcap, history, command line editing
Keywords: GDB termcap readline minimize
Message-ID: <1706@aber-cs.UUCP>
Date: 31 Mar 90 11:43:12 GMT
Reply-To: pcg@cs.aber.ac.uk (Piercarlo Grandi)
Organization: Dept of CS, UCW Aberystwyth
 (Disclaimer: my statements are purely personal)
Lines: 468
Posted: Sat Mar 31 12:43:12 1990