home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / gdb / bug / 1412 < prev    next >
Encoding:
Text File  |  1993-01-28  |  10.1 KB  |  296 lines

  1. Path: sparky!uunet!stanford.edu!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!ras.amdahl.COM!haw30
  2. From: haw30@ras.amdahl.COM (Henry A Worth)
  3. Newsgroups: gnu.gdb.bug
  4. Subject: Solaris shared object bug (gdb-4.7)
  5. Date: 26 Jan 1993 22:14:04 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 283
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-gdb@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <9301261808.AA21189@zeus.ras.amdahl.com>
  12.  
  13.    > From: jsc@sun.com (John Cooper)
  14.    > Newsgroups: gnu.gdb.bug
  15.    > Subject: Solaris problem (again)
  16.    > 
  17.    > Could one of the gdb developers please have the courtesy to at least
  18.    > respond to my post. If gdb on Solaris doesn't work with shared
  19.    > libraries, just say so! If you're too busy to look into the issue,
  20.    > that's ok too, but please at least acknowledge the problem.
  21.    > 
  22.  
  23.    I'd like to see a response as well (in general, just what is the status
  24. of Solaris ports, some sort of concise status for each port would be a nice 
  25. addition to the distributions, trying to infer features and stability of a
  26. port from the Changelogs, NEWS,... is not easy). I've been using GCC2.3.3 
  27. and GDB-4.7 under Solaris2.0/2.1 on a Sparc with shared objects with some 
  28. mixed success. Attaching to a running process works (main excpetion is
  29. if the process is sleeping, this seems to be fixed in Solaris2.1). But 
  30. running a process from gdb as below will fail if you breakpoint at main, 
  31. or anywhere else, with a segmentation or illegal instruction exception.
  32.  
  33.    > 
  34.    > Whenever I step over any function in a shared library (in this case,
  35.    > printf() in libc.so), gdb gives the following segmentation fault:
  36.    > 
  37.    > gdb-4.7/gdb/gdb hello
  38.    > GDB is free software and you are welcome to distribute copies of it
  39.    >  under certain conditions; type "show copying" to see the conditions.
  40.    > There is absolutely no warranty for GDB; type "show warranty" for details.
  41.    > GDB 4.7, Copyright 1992 Free Software Foundation, Inc...
  42.    > (gdb) b main
  43.    > Breakpoint 1 at 0x10778: file hello.c, line 8.
  44.    > (gdb) r
  45.    > Starting program: /saxon/jsc/hello 
  46.  
  47.      I get a number of sigtraps stops at this point. I assume you
  48. edited them out, but they are an important clue to the bug.
  49.  
  50.    > 
  51.    > Breakpoint 1, main (argc=1, argv=0xeffff9cc) at hello.c:8
  52.    > 8        a = 2;
  53.    > (gdb) n
  54.    > 9        printf("Hello World\n");
  55.    > (gdb) n
  56.    > 0x208d0 in __DTOR_END__ ()
  57.    > (gdb) 
  58.    > Current function has no line number information.
  59.    > Single stepping until function exit.
  60.    > 
  61.  
  62.      gcc2.3.3 seems to have problems generating stabs for Solaris,
  63. the debugger occasionally gets confused as to where it is, even with
  64. un-optimized code. Someone posted a bug report on this. 
  65.  
  66.    > Program received signal 11, Segmentation fault
  67.    > 0xef7d906c in _fp_current_direction ()
  68.    > (gdb)
  69.    > 
  70.  
  71.      Part of the  problem is caused by the handling of sigtraps generated 
  72. by SVR4 ld.so during the start-up mapping phase, there are various comments 
  73. in solib.c that this is a problem area that needs to be reworked someday.
  74. The SVR4 "breakpoint at main" workaround does not work in Solaris as the 
  75. contents of main have not been loaded at the time enable_breaks() is 
  76. executed. The contents of main are not loaded until the last 
  77. sigtrap. The result is that the attempt to set a "mapping-complete" 
  78. breakpoint fails. Also, with all the mapping sigtraps that occur, the 
  79. mapping loop in solib_create_inferior_hook() is exited too soon, resulting 
  80. in user breakpoints being set and cleared incorrectly. I've included a 
  81. work-around hack below, with the emphasis on HACK, there are no guarantees,
  82. but so far this has worked for me (also included is a patch to an earlier
  83. reported bug covering the possibility of a nil testsection pointer in object
  84. files containing only data).
  85.  
  86.  
  87. ------------------------------ start of patch -----------------------------
  88. *** ../gdb/solib.c    Fri Jul  3 20:21:41 1992
  89. --- solib.c    Mon Jan 25 15:38:53 1993
  90. ***************
  91. *** 670,678 ****
  92.        char *arg;
  93.   {
  94.     register struct so_list *so = (struct so_list *) arg;    /* catch_errs bogon */
  95.     
  96.     so -> objfile = symbol_file_add (so -> so_name, so -> from_tty,
  97. !                    (unsigned int) so -> textsection -> addr,
  98.                      0, 0, 0);
  99.     return (1);
  100.   }
  101. --- 670,679 ----
  102.        char *arg;
  103.   {
  104.     register struct so_list *so = (struct so_list *) arg;    /* catch_errs bogon */
  105. +   register struct section_table *txt = so -> textsection; /* may be nil!!!  */
  106.     
  107.     so -> objfile = symbol_file_add (so -> so_name, so -> from_tty,
  108. !                    (unsigned int) (txt ? txt -> addr : 0),
  109.                      0, 0, 0);
  110.     return (1);
  111.   }
  112. ***************
  113. *** 1128,1134 ****
  114.   void 
  115.   solib_create_inferior_hook()
  116.   {
  117. !   
  118.     if ((debug_base = locate_base ()) == 0)
  119.       {
  120.         /* Can't find the symbol or the executable is statically linked. */
  121. --- 1129,1137 ----
  122.   void 
  123.   solib_create_inferior_hook()
  124.   {
  125. !   CORE_ADDR first_trap_pc = 0;
  126. !   CORE_ADDR second_trap_pc = 0;
  127. !  
  128.     if ((debug_base = locate_base ()) == 0)
  129.       {
  130.         /* Can't find the symbol or the executable is statically linked. */
  131. ***************
  132. *** 1135,1145 ****
  133. --- 1138,1152 ----
  134.         return;
  135.       }
  136.   
  137. + #ifdef SUN4_SOL2_SOLIB_HACK
  138. +   breakpoint_addr = 0;
  139. + #else 
  140.     if (!enable_break ())
  141.       {
  142.         warning ("shared library handler failed to enable breakpoint");
  143.         return;
  144.       }
  145. + #endif /* SUN4_SOL2_SOLIB_HACK */
  146.   
  147.     /* Now run the target.  It will eventually hit the breakpoint, at
  148.        which point all of the libraries will have been mapped in and we
  149. ***************
  150. *** 1151,1167 ****
  151.     stop_signal = 0;
  152.     do
  153.       {
  154.         target_resume (0, stop_signal);
  155.         wait_for_inferior ();
  156.       }
  157.     while (stop_signal != SIGTRAP);
  158. !   stop_soon_quietly = 0;
  159. !   
  160.     /* We are now either at the "mapping complete" breakpoint (or somewhere
  161.        else, a condition we aren't prepared to deal with anyway), so adjust
  162.        the PC as necessary after a breakpoint, disable the breakpoint, and
  163.        add any shared libraries that were mapped in. */
  164.     if (DECR_PC_AFTER_BREAK)
  165.       {
  166.         stop_pc -= DECR_PC_AFTER_BREAK;
  167. --- 1158,1244 ----
  168.     stop_signal = 0;
  169.     do
  170.       {
  171. + #ifdef SUN4_SOL2_SOLIB_HACK
  172. +       if( stop_signal == SIGTRAP )
  173. +         {
  174. +           if ( stop_pc == breakpoint_addr )
  175. +             {
  176. +               /* we've finally reached main */
  177. +               break;
  178. +             }
  179. +           /* 
  180. +            * The SVR4 "breakpoint at main" hack doesn't work for SOLARIS2,
  181. +            * when the enable_break() is called, main has not yet been loaded, 
  182. +            * also multiple sigtraps occur during shared object mapping, 
  183. +            * so we exit this loop too soon and the breakpoint at main is lost.
  184. +            * Additionally, if the user attempted to set any breakpoints, 
  185. +            * the incomplete loading state when this loop is exited 
  186. +            * results in the wrong shadow contents being saved and any
  187. +            * attempt to continue typically results in segmentation or
  188. +            * illegal instruction exceptions.
  189. +            *
  190. +            * This hack tries to determine when the last mapping sigtrap has 
  191. +            * been reached, at which point we can set the breakpoint at main.
  192. +            * When the breakpoint at main is reached we exit the loop. 
  193. +            *
  194. +            * Determining which sigtrap is the last mapping sigtrap is
  195. +            * problematic, this hack is based upon the observation that the
  196. +            * last two mapping sigtraps have a different address than the 
  197. +            * rest. When the second of this last pair is reached the
  198. +            * the breakpoint at main is set. The empahsis is on HACK
  199. +            * and there are no guarantees that this will work in all
  200. +            * situations.
  201. +            *
  202. +            * Is there some data structure that indicates we have 
  203. +            * finished mapping in shared objects (some PIOC call?)?
  204. +            * If so, that would be a much preferable method. 
  205. +            */ 
  206. +           if (first_trap_pc == 0)
  207. +             first_trap_pc = stop_pc;
  208. +           else
  209. +             {
  210. +               if (first_trap_pc != stop_pc)
  211. +                 {
  212. +                   if (second_trap_pc == 0 )
  213. +                     second_trap_pc = stop_pc;
  214. +                   else 
  215. +                     {
  216. +                       /* program space is loaded and writable, we hope! */
  217. +                       if (!enable_break ())
  218. +                         {
  219. +                           warning ("shared library handler failed to enable breakpoint");
  220. +                           return;
  221. +                         }
  222. +                     }
  223. +                 }
  224. +             }
  225. +           stop_signal = 0;
  226. +         }
  227. + #endif  /* SUN4_SOL2_SOLIB_HACK */ 
  228.         target_resume (0, stop_signal);
  229.         wait_for_inferior ();
  230.       }
  231. + #ifdef SUN4_SOL2_SOLIB_HACK 
  232. +   /* continue until ld.so finishes mapping all shared objects */
  233. +   while ( 1 );
  234. + #else 
  235.     while (stop_signal != SIGTRAP);
  236. ! #endif  /* SUN4_SOL2_SOLIB_HACK */ 
  237. !  
  238.     /* We are now either at the "mapping complete" breakpoint (or somewhere
  239.        else, a condition we aren't prepared to deal with anyway), so adjust
  240.        the PC as necessary after a breakpoint, disable the breakpoint, and
  241.        add any shared libraries that were mapped in. */
  242. !  
  243.     if (DECR_PC_AFTER_BREAK)
  244.       {
  245.         stop_pc -= DECR_PC_AFTER_BREAK;
  246. ***************
  247. *** 1168,1177 ****
  248. --- 1245,1259 ----
  249.         write_register (PC_REGNUM, stop_pc);
  250.       }
  251.   
  252. +   stop_soon_quietly = 0;
  253. +  
  254. + #ifdef BKPT_AT_MAIN
  255.     if (!disable_break ())
  256.       {
  257.         warning ("shared library handler failed to disable breakpoint");
  258.       }
  259. + #endif  /*  BKPT_AT_MAIN */ 
  260.   
  261.     solib_add ((char *) 0, 0, (struct target_ops *) 0);
  262.   }
  263.  
  264.  
  265. *** ../gdb/tm-sun4sol2.h    Thu Oct 22 10:51:08 1992
  266. --- tm-sun4sol2.h    Thu Jan 21 14:30:51 1993
  267. ***************
  268. *** 64,67 ****
  269. --- 64,73 ----
  270.   get_longjmp_target PARAMS ((CORE_ADDR *));
  271.   
  272.   #define GET_LONGJMP_TARGET(ADDR) get_longjmp_target(ADDR)
  273.   #endif  /* 0 */
  274. + /* Solaris 2 shared object startup is not yet handled correctly.
  275. +    this macro enables a work-around hack. */
  276. + #define SUN4_SOL2_SOLIB_HACK
  277. ----------------------- end of patch ---------------------------------
  278.  
  279.  
  280.  
  281.  
  282.