Thread: Solaris 10: bus errors when compiling some programs with debug info

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    Rome, NY
    Posts
    24

    Solaris 10: bus errors when compiling some programs with debug info

    Well, lately I have been having a go at a simple client/server app on a Solaris 10 machine. So far, it hasn't been fun. Now I have been reading how picky Solaris can be with memory alignment, and I even wrote a few test programs to see how they can fail (purposly mis-aligning a struct ).

    However, for the server I am writing, when ever I try to compile it using -g to include debugging symbols gdb crashes with a bus error. Now I know it says gdb was configured on Solaris 2.8 (below), but it seemed to be working with other simple apps I was debugging.

    So here is what I am seeing:

    Code:
    jaws% gcc -Wall -g -lnsl -lsocket -lresolv DataPassServer.c -o dps
    jaws% gdb dps
    GNU gdb 6.0
    Copyright 2003 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "sparc-sun-solaris2.8"...Bus Error
    Now, before I go posting tons of code, I am wondering if there is a more general solution. I am using all the normal network functions and structs just as I did a year ago when I did beejs nework programming guide. I am going to copy his program directly and see if I can debug that.

    I know lots of people run into memory alignment issues on Solaris, but I guess my question is, why does gdb die with a bus error when it trys to load my program with the included debug symbols? I haven't progressed far with the program for this reason.

    At this point, I can run the program (with both debugging symbols included and excluded) and it seems to run fine. However it only binds and then listens on a port, so its quite simplistic. If anyone has anything that can get me on the right path it would be greatly appreciated.

    Forgot to mention, this is a SunBlade 150 with a 650mhz Sparc
    Last edited by BooBoo808; 08-01-2007 at 08:33 AM. Reason: DUH!!!!!

  2. #2
    Registered User
    Join Date
    Jun 2007
    Location
    Rome, NY
    Posts
    24
    Ok, here is some of the code. I intended to move onto a more complex project, but this Solaris bus error issues is holding me back.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <sys/wait.h>
    #include <signal.h>
    
    #define MAX_BUF  1024
    
    #define ERR_CHK( A, B ) if( A == -1 ) {	\
                              perror( B ); \
                              exit(1); }
    
    
    int fdmax;
    int port     = 8000;
    int max_conn = 5;
    
    /* socket data */
    int sin_size;
    fd_set master, read_fds;
    int server_sock, client_sock;
    struct sockaddr_in server_addr;
    struct sockaddr_in *client_addr;
    
    void getInputString( char *buf );
    
    int main( int argc, char **argv ) {
      if( argc == 1 ) {
        // start server with no binding
      } else if(argc == 3) {
        // start server binded to port with max connections
        port     = atoi(argv[1]);
        max_conn = atoi(argv[2]);
      } else {
        printf( "Unkown command line arguments\n" );
      }
    
      ERR_CHK( (server_sock = socket(AF_INET, SOCK_STREAM, 0)), "socket" );
    
      fprintf( stderr, "server: local socket created...\n" );
    
      server_addr.sin_family = AF_INET;
      server_addr.sin_port = htons(port);
      server_addr.sin_addr.s_addr = INADDR_ANY;
      memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero) );
    
      ERR_CHK( (bind(server_sock, (struct sockaddr *)&server_addr, sizeof(server_addr))), 
    	   "bind" );
    
      fprintf( stderr, "server: bound to local socket...\n" );
    
      ERR_CHK( (listen(server_sock, max_conn)), "listen");
    
      fprintf( stderr, "server: listening on port %d...\n", port );
    
      FD_ZERO(&master);
      FD_ZERO(&read_fds);
    
      if((client_addr = malloc(sizeof(struct sockaddr_in) * max_conn)) == NULL  ) {
        perror("malloc");
        exit(1);
      }
      sin_size = sizeof(struct sockaddr_in);
      
      /* main loop */
      int numc = 0;
      for( ;; ) {
        if( (client_sock = accept( server_sock,
    			       (struct sockaddr *)&client_addr[numc],
    			       &sin_size )) == -1 ) {
          
          perror("accept");
          continue;
        }
    
        printf("server: recieved connection from %s\n",
    	   inet_ntoa(client_addr[numc].sin_addr));
    
        
        /*
          now prepare to fork over work for each connection
        */
        
    
      } // for
    
      return 0;
    }

  3. #3
    Registered User
    Join Date
    Jun 2007
    Location
    Rome, NY
    Posts
    24
    Ok, now I just compiled Beej's simple stream server, server.c. After fixing a single typo and comiling with -g I get the same thing when I try to launch gdb.

    BTW, Beej's network programming guide: http://beej.us/guide/bgnet/

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by BooBoo808 View Post
    Now I know it says gdb was configured on Solaris 2.8
    that seems like a red flag to me. Why not use a matched version of gdb?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Does the same problem appear if you DON'T use debug symbols (-g) with gcc?

    I do agree with robwhit, it's quite likely that your problem is caused by a gdb that isn't compatible with gcc - perhaps you can find out what format debug info gdb likes, and get gcc to generate "older" version debug info?

    Or get a newer version/build of gdb?

    --
    Mats

  6. #6
    Registered User
    Join Date
    Jun 2007
    Location
    Rome, NY
    Posts
    24
    Quote Originally Posted by robwhit View Post
    that seems like a red flag to me. Why not use a matched version of gdb?

    Yea, well I am not the system administrator here so that becomes a chore. I did finally get my real program to work by just telnet'ing to a Solaris 8 box and compiling there. I was just trying to avoid the hassle of compiling gdb from scratch, as I assume there will be issues there. Makes me like openSUSE running at my house a lot more. In the end, I assumed that the sys admin would have experienced this problem before, yet it seems I am one of the few using Solaris 10.

    Anyway, thanks for the interest.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It's been a looong time since I used gdb on solaris, but generall the "latest stable" release usually works OK.

    As to sysadmins knowing about software developers issues, you'd be very lucky if you have one that knows that...

    --
    Mats

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by matsp View Post
    Does the same problem appear if you DON'T use debug symbols (-g) with gcc?

    I do agree with robwhit, it's quite likely that your problem is caused by a gdb that isn't compatible with gcc - perhaps you can find out what format debug info gdb likes, and get gcc to generate "older" version debug info?
    I see this on Solaris (and HP-UX) all the time. Chances are there is a subtle difference between the debug symbols inserted by the compiler/assembler and what gdb is expecting to get.

    Try inserting gdb-specific debug symbols with "-ggdb" instead of "-g".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading a file
    By nhubred in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2009, 11:34 AM
  2. A-Star Pathfinding
    By mike_g in forum General AI Programming
    Replies: 1
    Last Post: 08-05-2007, 04:18 PM
  3. mkdir - solaris 10
    By StevieT in forum C Programming
    Replies: 4
    Last Post: 08-17-2006, 03:36 AM
  4. Segmentation Fault
    By Lost__Soul in forum C Programming
    Replies: 46
    Last Post: 04-28-2003, 04:24 AM
  5. Scheduling Algo
    By BigDaddyDrew in forum C++ Programming
    Replies: 41
    Last Post: 03-08-2003, 11:00 AM