From: Wes Chalfant <wes@kofax.com>
Subject: Configuring gdb [and gcc and libg++] for SCO Unix 3.2.2 (long)
Resent-From: mmdf@xenitec.on.ca
Submit-To: scogen@xenitec.on.ca
Cc: sco-list@xenitec.on.ca, asharpe@sco.com
Organization: [resent by] The SCOGEN gateway and Propagation Society
Date: Sat, 29 Aug 1992 01:53:50 GMT
Precedence: bulk

   I have recently obtained GNU gdb 4.6 from ftp.uu.net, and I am trying to 
   get it going on SCO Unix 3.2.2. I have a number of minor problems ...

   "config.sub sco" outputs "i386-unknown-scosysv322" - why the "unknown", 
   when the README states that "sco" is a valid value for "vendor" ?

I used "i386-sco" for the configuration; it seems to work OK.  I think
that i386-unknown-scosysv322 is indeed the correct "fully qualified"
name; I don't know why the "unknown" is there either, but I think that
it's OK.

   I have gcc 1.39 (binaries only, kindly donated ages ago by a friend).

   I ran "config sco", followed by "make", and got a nice binary, which even 
   runs, and will debug programs compiled with SCO cc.

   However, it does not recognise core files. Also, it will not debug 
   programs compiled with gcc (including itself).

I think GCC 1.39 produced some not quite as good symbol table entries,
so that might be your problem.  Another possibility, though, is that
binaries you have were built using "coff encapsulation".

Best is probably to get or make more recent binaries (without encapsulation).

   I had a little troll through the source directories, and found something 
   called bfd/sco-core.c. In the comments at the top, it said to include
   "HDEFINES=-DSCO_CORE=1
   HDEPFILES=sco-core.o"
   in the "config/h-HOST" file.

   Not finding such a file, I added these lines to config/mh-sco, did a 
   "make clean", and then "make".

   Sadly, there was no improvement :-(

You have to munge a couple of things in the GDB stuff to get that
working (keep reading).

   Can anyone point me in the right direction to get this working on SCO - 
   preferably recognising all kinds of core files, and debugging binaries 
   produced with both cc and gcc.

Attached is a copy of some mail I sent to someone else who was trying
to put up the gnu tools.  It addresses everything I had to do to
get gcc (2.2.2), libg++ (2.2), and gdb (4.6) working on ODT 1.1.

----------------------

I just got done putting up gcc-2.2.2, libg++-2.2 and gdb-4.6 on some
systems here.  As I was tardy ordering ODT 2.0, this was done for ODT
1.1.  There may be a few differences between 1.1 and 2.0 (see below),
but I expect they're mostly the same.

Here's what to watch out for with these tools:

/lib/libc.a:
	If you haven't already replaced the faulty memmove routine in
the released version of /lib/libc.a with a fixed version, you should
do it now.  This is fixed in the ODT 2.0 devsys; it definitely is a
problem with older versions of the devsys.  The problem is that
memmove() clobbers register ebx; SCO's compiler doesn't seem to assign
register variables to ebx, so it doesn't matter, but the GNU compiler
does assign vars to ebx.  To fix this problem, compile memmove.s in
the shar file below (cc -c memmove.s) and update /lib/libc.a with it
(ar rv /lib/libc.a memmove.o).

All tools:
	Configure as host type "i386-sco".

gcc-2.2.2:
	Builds and installs with no problems on ODT 1.1.  Note that if
you plan to use gdb 4.6, you should also apply the patch "gcc-gdb-patch"
(this patch can be found whereever gdb-4.6 is found as
gdb-4.6-gcc.patch.Z; that name is too long for the ODT 1.1 file system
so I changed it).

Note that after installation you should replace the "specs" file
(/usr/local/lib/gcc-lib/i386-sco/2.2.2/specs) with either specs-3.2v2
or specs-3.2v4.  Specs-3.2v2 is what I use here; it works fine for SCO
UNIX 3.2v2/SCO ODT 1.1.  Specs-3.2v4 is what Chip Salzenburg posted a
while back; it calls out some libraries that I don't have and
apparently is meant for UNIX 3.2v4/ODT 2.0.

libg++-2.2:
	Apply the "libg++-2.2-pat" patch file to correct a relatively
minor problem.  Should compile and run (test programs) without any problems
after that.

gdb-4.6:
	Will compile and install OK on SCO.  There are a couple of
changes in gdb-4.6-patch that you probably want if you're going to be
doing much debugging of C++ code; that patch sets up GDB to be able to
recognize and handle SCO style core files and "hacks" the routine that
reads COFF symbol tables so that "this" is handled properly in class
methods.  Apply gcb-4.6-patch before building and installing gdb.

All in all, the GNU stuff is pretty clean for 386's in general and SCO
in specific (due largely to Chip Salzenburg and others).  I haven't yet
used the C++ stuff on any significant project (I'm just about to;
that's why I just put the stuff up), so I can't vouch for how stable
it is, but gcc as a C compiler is excellent, and I expect that the C++
stuff is just as good.

#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  gcc-gdb-patch
#	  gdb-4.6-patch
#	  libg++-2.2-pat
#	  memmove.s
#	  specs-3.2v2
#	  specs-3.2v4
#
echo "x - extracting gcc-gdb-patch (Text)"
sed 's/^X//' << 'SHAR_EOF' > gcc-gdb-patch &&
XRecent versions of gcc have had a bug in how they emit debugging
Xinformation for C++ methods (when using dbx-style stabs).
XThis patch should fix the problem.  Fix you can't fix gcc,
Xyou can alternatively define GCC_MANGLE_BUG when compling gdb/symtab.c.
X
X===================================================================
XRCS file: /rel/cvsfiles/devo/gcc/dbxout.c,v
Xretrieving revision 1.53
Xdiff -c -r1.53 dbxout.c
X*** 1.53	1992/07/05 09:50:22
X***************
X*** 683,688 ****
X    tree type_encoding;
X    register tree fndecl;
X    register tree last;
X+   char formatted_type_identifier_length[16];
X    register int type_identifier_length;
X  
X    if (methods == NULL_TREE)
X***************
X*** 711,716 ****
X  
X    type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
X  
X+   sprintf(formatted_type_identifier_length, "%d", type_identifier_length);
X+ 
X    if (TREE_CODE (methods) == FUNCTION_DECL)
X      fndecl = methods;
X    else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
X***************
X*** 754,762 ****
X  		  if (debug_name[0] == '_' && debug_name[1] == '_')
X  		    {
X  		      char *method_name = debug_name + 2;
X+ 		      char *length_ptr = formatted_type_identifier_length;
X  		      /* Get past const and volatile qualifiers.  */
X  		      while (*method_name == 'C' || *method_name == 'V')
X  			method_name++;
X+ 		      /* Skip digits for length of type_encoding. */
X+ 		      while (*method_name == *length_ptr && *length_ptr)
X+ 			  length_ptr++, method_name++;
X  		      if (! strncmp (method_name,
X  				     IDENTIFIER_POINTER (type_encoding),
X  				     type_identifier_length))
X***************
X*** 768,775 ****
X  	      else if (debug_name[0] == '_' && debug_name[1] == '_')
X  		{
X  		  char *ctor_name = debug_name + 2;
X+ 		  char *length_ptr = formatted_type_identifier_length;
X  		  while (*ctor_name == 'C' || *ctor_name == 'V')
X  		    ctor_name++;
X+ 		  /* Skip digits for length of type_encoding. */
X+ 		  while (*ctor_name == *length_ptr && *length_ptr)
X+ 		      length_ptr++, ctor_name++;
X  		  if (!strncmp (IDENTIFIER_POINTER (type_encoding), ctor_name,
X  				type_identifier_length))
X  		    debug_name = ctor_name + type_identifier_length;
SHAR_EOF
chmod 0664 gcc-gdb-patch || echo "restore of gcc-gdb-patch fails"
echo "x - extracting gdb-4.6-patch (Text)"
sed 's/^X//' << 'SHAR_EOF' > gdb-4.6-patch &&
Xdiff -r -c gdb-4.6-old/bfd/config/i386scov.mh gdb-4.6/bfd/config/i386scov.mh
X*** gdb-4.6-old/bfd/config/i386scov.mh	Tue Jul 28 15:14:41 1992
X***************
X*** 0 ****
X+ RANLIB = /bin/true
X+ ALLOCA = alloca.o
X+ HDEFINES = -DUSG -DSCO_CORE -DTRAD_CORE_VEC=sco_core_vec
X+ HDEPFILES = sco-core.o
Xdiff -r -c gdb-4.6-old/bfd/configure.in gdb-4.6/bfd/configure.in
X*** gdb-4.6-old/bfd/configure.in	Wed Jul  8 01:01:12 1992
X***************
X*** 80,86 ****
X  		case "${host_os}" in
X  		go32) my_host=go32 ;;
X  		sysv4*)	my_host=i386v4 ;;
X! 		sysv* | scosysv*) my_host=i386v ;;
X  		mach*)	my_host=i386mach ;;
X  		msdos*)	my_host=dose ;;
X  		linux)	my_host=i386linux ;;
X  		case "${host_os}" in
X  		go32) my_host=go32 ;;
X  		sysv4*)	my_host=i386v4 ;;
X! 		sysv*)  my_host=i386v ;;
X! 		scosysv*) my_host=i386scov ;;
X  		mach*)	my_host=i386mach ;;
X  		msdos*)	my_host=dose ;;
X  		linux)	my_host=i386linux ;;
Xdiff -r -c gdb-4.6-old/bfd/hosts/i386scov.h gdb-4.6/bfd/hosts/i386scov.h
X*** gdb-4.6-old/bfd/hosts/i386scov.h	Tue Jul 28 15:53:50 1992
X***************
X*** 0 ****
X+ #include <fcntl.h>
X+ #include <errno.h>
X+ #include <stdio.h>
X+ #include <sys/types.h>
X+ #include <sys/stat.h>
X+ #include <utime.h>
X+ #include <ctype.h>
X+ #include <string.h>
X+ #include <unistd.h>
X+ 
X+ #ifndef O_ACCMODE
X+ #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
X+ #endif
X+ #ifndef SEEK_SET
X+ #define SEEK_SET 0
X+ #define SEEK_CUR 1
X+ #endif
X+ 
X+ #ifndef L_SET
X+ # define L_SET SEEK_SET
X+ #endif
X+ 
X+ #define	POSIX_UTIME
X+ 
X+ /* Some things that need to be defined in order to make code written for
X+    BSD Unix compile under System V Unix.  */
X+ 
X+ /*#include <memory.h>*/
X+ #define bcmp(b1,b2,len)		memcmp(b1,b2,len)
X+ #define bcopy(src,dst,len)	memcpy(dst,src,len)
X+ #define bzero(s,n)		memset(s,0,n)
X+ 
X+ #include <string.h>
X+ #define index(s,c)		strchr(s,c)
X+ #define rindex(s,c)		strrchr(s,c)
X+ 
X+ /*
X+  * Might not need these. Leave them out for now.
X+  *
X+ #ifdef SEEK_SET
X+ #	ifndef L_SET
X+ #		define L_SET SEEK_SET
X+ #	endif
X+ # endif
X+ 
X+ #ifdef SEEK_CUR
X+ #	ifndef L_INCR
X+ #		define L_INCR SEEK_CUR
X+ #	endif
X+ # endif
X+  */
X+ 
X+ #ifndef DONTDECLARE_MALLOC
X+ extern PTR  EXFUN(malloc,(unsigned));
X+ extern PTR  EXFUN(realloc, (PTR, unsigned));
X+ extern void EXFUN(free,(PTR));
X+ #endif
X+ 
X+ /* EXACT TYPES */
X+ typedef char int8e_type;
X+ typedef unsigned char uint8e_type;
X+ typedef short int16e_type;
X+ typedef unsigned short uint16e_type;
X+ typedef int int32e_type;
X+ typedef unsigned int uint32e_type;
X+ 
X+ /* CORRECT SIZE OR GREATER */
X+ typedef char int8_type;
X+ typedef unsigned char uint8_type;
X+ typedef short int16_type;
X+ typedef unsigned short uint16_type;
X+ typedef int int32_type;
X+ typedef unsigned int uint32_type;
X+ 
X+ #include "fopen-same.h"
Xdiff -r -c gdb-4.6-old/bfd/targets.c gdb-4.6/bfd/targets.c
X*** gdb-4.6-old/bfd/targets.c	Tue Jun 23 15:10:19 1992
X***************
X*** 354,359 ****
X  
X  */
X  
X+ #if defined(TRAD_CORE_VEC) && !defined(TRAD_CORE)
X+ #define TRAD_CORE
X+ #endif 
X+ #if defined(TRAD_CORE) && !defined(TRAD_CORE_VEC)
X+ #defined TRAD_CORE_VEC trad_core_vec
X+ #endif 
X+ 
X  /* The default is to define a target_vector containing all the targets.
X     By setting MINIMIZE=1 on the "make" command line, the user can change this
X     to a vector containing just DEFAULT_VECTOR and any required
X***************
X*** 363,369 ****
X  
X  #if MINIMIZE && defined(DEFAULT_VECTOR) && !defined(SELECT_VECS)
X  #ifdef TRAD_CORE
X! #define SELECT_VECS &DEFAULT_VECTOR,&trad_core_vec
X  #else
X  #define SELECT_VECS &DEFAULT_VECTOR
X  #endif
X  
X  #if MINIMIZE && defined(DEFAULT_VECTOR) && !defined(SELECT_VECS)
X  #ifdef TRAD_CORE
X! #define SELECT_VECS &DEFAULT_VECTOR,&TRAD_CORE_VEC
X  #else
X  #define SELECT_VECS &DEFAULT_VECTOR
X  #endif
X***************
X*** 391,397 ****
X  extern bfd_target i386aout_vec;
X  extern bfd_target i386linux_vec;
X  extern bfd_target a29kcoff_big_vec;
X! extern bfd_target trad_core_vec;
X  extern bfd_target rs6000coff_vec;
X  extern bfd_target h8300coff_vec;
X  #ifdef hp9000s800
X  extern bfd_target i386aout_vec;
X  extern bfd_target i386linux_vec;
X  extern bfd_target a29kcoff_big_vec;
X! extern bfd_target TRAD_CORE_VEC;
X  extern bfd_target rs6000coff_vec;
X  extern bfd_target h8300coff_vec;
X  #ifdef hp9000s800
X***************
X*** 450,456 ****
X  #endif
X  
X  #ifdef	TRAD_CORE
X! 	&trad_core_vec,
X  #endif
X  	NULL, /* end of list marker */
X  };
X  #endif
X  
X  #ifdef	TRAD_CORE
X! 	&TRAD_CORE_VEC,
X  #endif
X  	NULL, /* end of list marker */
X  };
Xdiff -r -c gdb-4.6-old/gdb/coffread.c gdb-4.6/gdb/coffread.c
X*** gdb-4.6-old/gdb/coffread.c	Mon Jul  6 10:10:40 1992
X***************
X*** 1354,1359 ****
X        buffer[SYMNMLEN] = '\0';
X        result = buffer;
X      }
X+   /* Tackiness indeed; much better G++ handling is needed.  This
X+    * will at least get the "hidden" temporaries "this" and "eh_throw"
X+    * known to gdb.  */
X+   if (result[0] == CPLUS_MARKER && result[2] == '\0')
X+     {
X+       switch (result[1])
X+ 	{
X+ 	case 't':
X+ 	  result = "this";
X+ 	  break;
X+ 	case 'e':
X+ 	  result = "eh_throw";
X+ 	  break;
X+ 	}
X+     }
X    return result;
X  }
X  
SHAR_EOF
chmod 0664 gdb-4.6-patch || echo "restore of gdb-4.6-patch fails"
echo "x - extracting libg++-2.2-pat (Text)"
sed 's/^X//' << 'SHAR_EOF' > libg++-2.2-pat &&
X*** libg++-2.2-old/libiberty/sigsetmask.c	Mon Jun 15 01:04:38 1992
X***************
X*** 32,38 ****
X      sigset_t new;
X      sigset_t old;
X      
X!     (void) sigemptyset (&new);
X      if (set != 0) {
X        abort();	/* FIXME, we don't know how to translate old mask to new */
X      }
X      sigset_t new;
X      sigset_t old;
X      
X!     /* wgc:  Put parens around sigemptyset "call" because this is a macro
X!        under SCO ODT 1.1 and SCO didn't put parens in where they should have */
X!     (void) (sigemptyset (&new));
X      if (set != 0) {
X        abort();	/* FIXME, we don't know how to translate old mask to new */
X      }
SHAR_EOF
chmod 0664 libg++-2.2-pat || echo "restore of libg++-2.2-pat fails"
echo "x - extracting memmove.s (Text)"
sed 's/^X//' << 'SHAR_EOF' > memmove.s &&
X	.globl  memmove
Xmemmove:
X	pushl  %ebp
X	movl   %esp,%ebp
X	pushl  %ebx  	
X	movl   %edi,%edx
X	movl   %esi,%ebx
X	movl   0xc(%ebp),%esi
X	movl   0x8(%ebp),%edi
X	movl   %edi,%eax
X	movl   0x10(%ebp),%ecx
X	jcxz   done
X	cmpl   %esi,%edi
X	jbe    CopyUp
X	movl   %esi,%eax
X	addl   %ecx,%eax
X	cmpl   %eax,%edi
X	jae    CopyUp
X	movl   %edi,%eax
X	addl   %ecx,%esi
X	addl   %ecx,%edi
X	decl   %esi
X	decl   %edi
X	std    
X	repz
X	movsb
X	cld    
X	jmp    done
XCopyUp:
X	movl   %edi,%eax
X	testb  0x1,%al
X	je     move
X	movsb
X	decl   %ecx
Xmove:
X	shrl   %ecx
X	repz
X	movsw
X	adcl   %ecx,%ecx
X	repz
X	movsb
Xdone:
X	movl   %ebx,%esi
X	movl   %edx,%edi
X	popl   %ebx
X	popl   %ebp
X	ret    
SHAR_EOF
chmod 0664 memmove.s || echo "restore of memmove.s fails"
echo "x - extracting specs-3.2v2 (Text)"
sed 's/^X//' << 'SHAR_EOF' > specs-3.2v2 &&
X*asm:
X
X
X*asm_final:
X
X
X*cpp:
X
X*cc1:
X
X
X*cc1plus:
X
X
X*endfile:
Xcrtend.o%s crtn.o%s
X
X*link:
X
X
X*lib:
X%{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp} %{scointl:libintl.a%s} -lc
X
X*startfile:
X%{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}} crtbegin.o%s
X
X*switches_need_spaces:
X
X
X*signed_char:
X%{funsigned-char:-D__CHAR_UNSIGNED__}
X
X*predefines:
X
X*cross_compile:
X0
X
SHAR_EOF
chmod 0664 specs-3.2v2 || echo "restore of specs-3.2v2 fails"
echo "x - extracting specs-3.2v4 (Text)"
sed 's/^X//' << 'SHAR_EOF' > specs-3.2v4 &&
X*asm:
X
X
X*asm_final:
X
X
X*cpp:
X
X*cc1:
X
X
X*cc1plus:
X
X
X*endfile:
Xcrtend.o%s  %{sco32v2:/u/local/sco32v2/lib/crtn.o} %{!sco32v2: %{scoxpg3:crtnX.o%s}   %{!scoxpg3:   %{posix:crtnP.o%s}    %{!posix:    %{ansi:crtnA.o%s}     %{!ansi:crtn.o%s}}}}
X
X*link:
X
X
X*lib:
X%{sco32v2:%{!ansi:%{scointl:-lintl}} -lc} %{!sco32v2:%{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp}  %{scoxpg3:-lcX -lcP -lcA}  %{!scoxpg3:  %{posix:-lcP -lcA}   %{!posix:   %{ansi:-lcA}    %{!ansi:%{scointl:-lintl} -lc}}}}
X
X*startfile:
X%{sco32v2:-L/u/local/sco32v2/lib -L/u/local/sco32v2/usr/lib %{p:/u/local/sco32v2/lib/mcrt1.o}%{!p:/u/local/sco32v2/lib/crt1.o}} %{!sco32v2:%{scoxpg3:%{p:mcrt1X.o%s}%{!p:crt1X.o%s}}   %{!scoxpg3:   %{posix:%{p:mcrt1P.o%s}%{!p:crt1P.o%s}}    %{!posix:    %{ansi:%{p:mcrt1A.o%s}%{!p:crt1A.o%s}}     %{!ansi:%{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}}}}}   crtbegin.o%s
X
X*switches_need_spaces:
X
X
X*signed_char:
X%{funsigned-char:-D__CHAR_UNSIGNED__}
X
X*predefines:
X
X
X*cross_compile:
X0
X
SHAR_EOF
chmod 0664 specs-3.2v4 || echo "restore of specs-3.2v4 fails"
exit 0

Wes Chalfant    Kofax Image Products, Inc.    wes@kofax.com
Newsgroups: biz.sco.general