This is the mail archive of the gdb-patches@sources.redhat.com 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]

Patch for --cd=... bug and for reading .gdbinit in exec dir


Hi!

I have made a patch for gdb/main.c, that accomplishes the following
functionality: 

* If --cd=... directive is then directory is changed first, and then
  .gdbinit  is stated

* If there is no .gdbinit in current directory and executable /
  symfile is specified, directory where executable resides is tested
  for the presence of .gdbinit. If it is different from the one in
  $HOME  it is read and executed.


I have tested this patch thoroughly and it works for me just fine in
all  circumstances. I tested all possible combinations. 

Please change the code as much as you wish. I have tried to follow
your standards in the coding, but it is likely that code will have to
be changed to be accepted.

I have spent 30 minutes in coding and 30 minutes in testing, so this
is truly nothing much. If you accept any of this, I would be very
happy if I would be mentioned anywhere in GDB Changelog.... ;o)

Here is a patch:

*** tmp/main.c	Fri Nov  2 13:29:47 2001
--- gdb/main.c	Fri Nov  2 18:29:08 2001
***************
*** 36,41 ****
--- 36,47 ----
  #include "event-loop.h"
  #include "ui-out.h"
  
+ #ifdef _WIN32
+ #define dirchar '\\'
+ #else
+ #define dirchar '/'
+ #endif
+ 
  /* If nonzero, display time usage both at startup and for each command.  */
  
  int display_time;
***************
*** 151,158 ****
    /* Number of elements used.  */
    int ndir;
  
!   struct stat homebuf, cwdbuf;
!   char *homedir, *homeinit;
  
    register int i;
  
--- 157,164 ----
    /* Number of elements used.  */
    int ndir;
  
!   struct stat homebuf, cwdbuf, execbuf;
!   char *homedir, *homeinit, *execinit=(char *)NULL;
  
    register int i;
  
***************
*** 511,516 ****
--- 517,528 ----
       *before* all the command line arguments are processed; it sets
       global parameters, which are independent of what file you are
       debugging or what directory you are in.  */
+ 
+   if (cdarg != NULL)
+     {
+       catch_command_errors (cd_command, cdarg, 0, RETURN_MASK_ALL);
+     }
+ 
    homedir = getenv ("HOME");
    if (homedir)
      {
***************
*** 539,548 ****
      }
  
    /* Now perform all the actions indicated by the arguments.  */
-   if (cdarg != NULL)
-     {
-       catch_command_errors (cd_command, cdarg, 0, RETURN_MASK_ALL);
-     }
  
    for (i = 0; i < ndir; i++)
      catch_command_errors (directory_command, dirarg[i], 0, RETURN_MASK_ALL);
--- 551,556 ----
***************
*** 597,611 ****
    quit_pre_print = NULL;
    warning_pre_print = "warning: ";
  
-   /* Read the .gdbinit file in the current directory, *if* it isn't
-      the same as the $HOME/.gdbinit file (it should exist, also).  */
  
!   if (!homedir
!       || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
!     if (!inhibit_gdbinit)
        {
! 	catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
        }
  
    for (i = 0; i < ncmd; i++)
      {
--- 605,642 ----
    quit_pre_print = NULL;
    warning_pre_print = "warning: ";
  
  
!   {
!     char *strstart=(execarg) ? execarg : symarg;
!     if (strstart)
        {
! 	char *strend=strrchr(strstart,dirchar);
! 	if (strend)
! 	  {
! 	    int len=strend-strstart + 1;
! 	    execinit = (char *) xmalloc (len + 20);
! 	    strncpy (execinit, strstart,len);
! 	    execinit[len]='\0';
! 	    strcat (execinit, gdbinit);
! 	    memset (&execbuf, 0, sizeof (struct stat));
! 	    stat (execinit, &execbuf);
! 	  }
        }
+   }
+   /* Read the .gdbinit file in the current directory, *if* it isn't
+      the same as the $HOME/.gdbinit file (it should exist, also).  */
+   if (!inhibit_gdbinit)
+     {
+       if (!homedir
+ 	  || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
+         {
+ 	  catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
+ 	}
+       else if (execinit && memcmp ((char *) &execbuf, (char *) &cwdbuf, sizeof (struct stat)))
+         {
+ 	  catch_command_errors (source_command, execinit, 0, RETURN_MASK_ALL);
+ 	}
+     }
  
    for (i = 0; i < ncmd; i++)
      {



-- 
Regards,
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Mr. Sinisa Milivojevic <sinisa@mysql.com>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Fulltime Developer
/_/  /_/\_, /___/\___\_\___/   Larnaca, Cyprus
       <___/   www.mysql.com


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