🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #63

User defined command bug in gdb 4.4

#63
From: larrym
Date: Wed, 08 Apr 1992 03:52
67 lines
3168 bytes
I found a low priority bug in the code that handles user commands in gdb 4.4.
It affects all systems and all targets.

The code in lookup_cmd_1(), called by lookup_cmd() to compare a command
entered by the user with all possible commands in the command list, always
maps user input to lower case.  Thus it will only match command names in
the list that are in lower case, as are all standard gdb commands.

The define_command() routine to add user defined commands to the command
list does not map to lower case.  Thus the user can define a command in
upper or mixed case, it will be shown by "help user", but when an attempt
is made to use the command, gdb responds with an undefined command error
message.

My fix was to copy the "map to lower case" code from lookup_cmd_1() and
insert it into define_command() just before the call to savestring().
This is known to be safe since the check for conflicts with existing
command names was made using a call to lookup_cmd(), which already
mapped the name to lower case (but threw away the result).

Results of "rcsdiff -c main.c" attached below.

				    Thank you very much,
				    Larry Morandi

US Mail:    Larry Morandi, Television Division, Tektronix, Inc.
            P.O. Box 500,    M.S. 58-639,    Beaverton OR 97077
E-Mail:     larrym@tv.tv.tek.com         Phone:    503-627-6002

==========================================================================
*** /tmp/,RCSt1a03722	Wed Apr  8 10:43:07 1992
--- main.c	Tue Apr  7 19:02:45 1992
***************
*** 1552,1558 ****
  End with a line saying just \"end\".\n", comname);
        fflush (stdout);
      }
!   comname = savestring (comname, strlen (comname));
  
    cmds = read_command_lines ();
  
--- 1552,1576 ----
  End with a line saying just \"end\".\n", comname);
        fflush (stdout);
      }
!   /* Bug fix to release 4.4: Since commands are always converted
!      to lower case for comparison with command structures (by the
!      lookup_cmd() and lookup_cmd_1() routines), it makes no sense
!      to save a new user command with upper case.  The command will
!      never be found.  So copy command name into a local temporary,
!      converting to lower case as we go.  */
!     { /* block for fix */
!       int len = strlen(comname);
!       int tmp;
!       char *newcomname = (char *) alloca (len + 1);
!       for (tmp = 0; tmp < len; tmp++)
! 	{
! 	  char x = comname[tmp];
! 	  newcomname[tmp] = (x >= 'A' && x <= 'Z') ? x - 'A' + 'a' : x;
! 	}
!       newcomname[len] = '\0';
!       comname = savestring (newcomname, len);
!     } /* end of block for fix */
! /*  comname = savestring (comname, strlen (comname));	/* original line, before fix */
  
    cmds = read_command_lines ();
  
Technical Details
Message-ID: <199204081752.AA03852@soul.tv.tek.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tv.tv.tek.COM!larrym

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gdb.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tv.tv.tek.COM!larrym
From: larrym@tv.tv.tek.COM
Subject: User defined command bug in gdb 4.4
Message-ID: <199204081752.AA03852@soul.tv.tek.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 8 Apr 1992 03:52:28 GMT
Approved: bug-gdb@prep.ai.mit.edu
Lines: 68