2014-05-02 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* gdb/common/common-utils.c [DJGPP]: Provide declaration for vsnprintf.

	* gdb/remote.c [DJGPP]: Provide declaration for vsnprintf.

	* gdb/djgpp/djtypes.h: From CVS repository, required for vsnprintf for DJGPP 2.03.

	* gdb/djgpp/dosio.h: From CVS repository, required for vsnprintf for DJGPP 2.03.

	* gdb/djgpp/file.h: From CVS repository, required for vsnprintf for DJGPP 2.03.

	* gdb/djgpp/ttyprvt.h: From CVS repository, required for vsnprintf for DJGPP 2.03.

	* gdb/djgpp/types.h: From CVS repository, required for vsnprintf for DJGPP 2.03.

	* gdb/djgpp/unistd.h: From CVS repository, required for vsnprintf for DJGPP 2.03.

	* gdb/djgpp/vsnprntf.c: From CVS repository, required for vsnprintf for DJGPP 2.03.


2014-05-01 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* bfd/cache.c (bfd_cache_max_open) [__DJGPP__]:  Do not use getrlimit
	to check for the amount of files that can be opened.


2014-04-28 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* gdb/gnulib/import/mbrtowc.c [DJGPP]: Define EILSEQ if not defined.

	* gdb/gnulib/import/mbsrtowcs.c [DJGPP]: Define EILSEQ if not defined.

	* bfd/coff-go32.c: Define COFF_GO32 macro.
	Add _bfd_go32_mkobject prototype.
	Define coff_mkobject macro to _bfd_go32_mkobject.
	Define IMAGE_SCN_LNK_NRELOC_OVFL.  Signals that relocation counter
	has overflown.
	Include sysdep.h.

	* bfd/coff-stgo32.c: Add _bfd_go32_mkobject prototype.
	Define coff_mkobject macro to _bfd_go32_mkobject.
	Add _bfd_go32_mkobject definition.
	Define IMAGE_SCN_LNK_NRELOC_OVFL.  Signals that relocation counter
	has overflown.

	* bfd/coffswap.h (coff_swap_scnhdr_in) [COFF_GO32_EXE, COFF_GO32]:
	Iff reading an executable file and iff it is the ".text" section
	header calculate the number of lines from the 16 bit field of the
	relocation counter and the 16 bit filed of the line counter.
	(coff_swap_scnhdr_out) [COFF_GO32_EXE, COFF_GO32]:
	- Iff building an executable file and iff it is the ".text" section
	header store the upper 16 bits of the line counter in the relocation
	counter.
	- Iff not building an executabe file or iff building an executable file
	but iff it is not the ".text" section header then:
	  1) if the relocation counter is greater the 65534 set the relocation
	     counter to 65535 and set the IMAGE_SCN_LNK_NRELOC_OVFL bit.
	     The relocation counter overflow is handled elsewhere.
	  2) if the line counter is greater than 65535 then abort.

	* bfd/coffcode.h [COFF_GO32_EXE, COFF_GO32, COFF_WITH_PE]: Define new
	macro COFF_WITH_EXTENDED_RELOC_COUNTER.
	(coff_write_relocs, coff_write_object_contents): Replace COFF_WITH_PE
	with COFF_WITH_EXTENDED_RELOC_COUNTER where appropriate and add
	obj_go32 to the check if relocation counter >= 0xFFFF.
	(coff_set_alignment_hook): Implementation for DJGPP.
	[COFF_GO32_EXE, COFF_GO32]:  Define COFF_PAD_SECTION_HEADERS.
	Taken from bnu219s2.zip.

	* bfd/libcoff-in.h: Define obj_go32 macro.
	Add go32 flag to struct coff_tdata.  1 if DJGPP else 0.

	* bfd/cofflink.c (_bfd_coff_final_link): If it is an obj_go32 allow
	relocations larger than 65535.

	* djgpp/build.sh:  DJGPP specific shell script to adjust, configure
	and compile progs and libs.

	* config.sub:  Use uname result to set basic_machine value
	instead of hardcoded one.

	* libiberty/cp-demangle.c (d_demangle_callback):  Pacify compiler.

	* libiberty/make-relative-prefix.c:  DJGPP specific adjustments.
	Taken from bnu219s2.zip.

	* libiberty/make-temp-file.c:  DJGPP specific adjustments.
	Taken from bnu219s2.zip.

	* libiberty/pex-common.c (temp_file, pex_run_in_environment):  Pacify
	compiler.







diff -aprNU5 gdb-7.7.1.orig/bfd/cache.c gdb-7.7.1/bfd/cache.c
--- gdb-7.7.1.orig/bfd/cache.c	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/bfd/cache.c	2014-05-10 12:41:48 +0100
@@ -77,10 +77,60 @@ static int
 bfd_cache_max_open (void)
 {
   if (max_open_files == 0)
     {
       int max;
+#ifdef __DJGPP__
+      /*  Do not trust getrlimit.  */
+
+# if 1
+      max_open_files = 15;
+# else
+#  define MAX_FILE_HANDLES  256
+
+      char dir_name[FILENAME_MAX + 1], file_name[MAX_FILE_HANDLES][FILENAME_MAX + 1];
+      char *path = getenv("TMPDIR");
+      int old_errno = errno;
+      bfd_boolean dir_created = TRUE;
+
+      snprintf(dir_name, FILENAME_MAX, "%s/%s", path ? path : ".", "ofXXXXXX");
+      if (mkdir(mktemp(dir_name), S_IWUSR))
+      {
+        snprintf(dir_name, FILENAME_MAX, "%s", "./RLIMIT.TST");
+        if (errno = 0, mkdir(dir_name, S_IWUSR) && errno && errno != EEXIST)
+          dir_created = FALSE;
+      }
+      if (dir_created)
+      {
+        int fd[MAX_FILE_HANDLES];
+
+        for (max = 0; max < MAX_FILE_HANDLES; max++)
+        {
+          snprintf(file_name[max], FILENAME_MAX, "%s/%d", dir_name, max);
+          if ((fd[max] = open(file_name[max], O_CREAT | O_RDWR)) == EOF)
+            break;
+        }
+
+        for (max_open_files = max; max > -1; max--)
+        {
+          close(fd[max]);
+          unlink(file_name[max]);
+        }
+
+        rmdir(dir_name);
+      }
+      else
+        max_open_files = 10;
+
+      errno = old_errno;
+
+      max = max_open_files / 8;
+      max_open_files = max < 2 ? 2 : max;
+
+#  undefine MAX_FILE_HANDLES
+# endif
+#else
 #ifdef HAVE_GETRLIMIT
       struct rlimit rlim;
       if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
 	  && rlim.rlim_cur != (rlim_t) RLIM_INFINITY)
 	max = rlim.rlim_cur / 8;
@@ -90,10 +140,11 @@ bfd_cache_max_open (void)
 	max = sysconf (_SC_OPEN_MAX) / 8;
 #else
 	max = 10;
 #endif /* _SC_OPEN_MAX */
       max_open_files = max < 10 ? 10 : max;
+#endif /* __DJGPP__ */
     }
 
   return max_open_files;
 }
 
diff -aprNU5 gdb-7.7.1.orig/bfd/coff-go32.c gdb-7.7.1/bfd/coff-go32.c
--- gdb-7.7.1.orig/bfd/coff-go32.c	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/bfd/coff-go32.c	2014-05-10 12:28:08 +0100
@@ -21,10 +21,11 @@
    MA 02110-1301, USA.  */
 
 #define TARGET_SYM		go32coff_vec
 #define TARGET_NAME		"coff-go32"
 #define TARGET_UNDERSCORE	'_'
+#define COFF_GO32
 #define COFF_LONG_SECTION_NAMES
 #define COFF_SUPPORT_GNU_LINKONCE
 #define COFF_LONG_FILENAMES
 
 #define COFF_SECTION_ALIGNMENT_ENTRIES \
@@ -41,6 +42,16 @@
 { COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
+/* Section contains extended relocations. */
+#define IMAGE_SCN_LNK_NRELOC_OVFL  0x01000000
+
+#include "sysdep.h"
+#include "bfd.h"
+
+bfd_boolean _bfd_go32_mkobject (bfd *abfd);
+
+#define coff_mkobject  _bfd_go32_mkobject
+
 #include "coff-i386.c"
diff -aprNU5 gdb-7.7.1.orig/bfd/coff-stgo32.c gdb-7.7.1/bfd/coff-stgo32.c
--- gdb-7.7.1.orig/bfd/coff-stgo32.c	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/bfd/coff-stgo32.c	2014-05-10 12:28:08 +0100
@@ -52,10 +52,13 @@
 { COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
+/* Section contains extended relocations. */
+#define IMAGE_SCN_LNK_NRELOC_OVFL  0x01000000
+
 #include "sysdep.h"
 #include "bfd.h"
 
 /* All that ..._PRE and ...POST functions are called from the corresponding
    coff_swap... functions. The ...PRE functions are called at the beginning
@@ -101,10 +104,14 @@ static const bfd_target *go32_check_form
 static bfd_boolean
   go32_stubbed_coff_bfd_copy_private_bfd_data (bfd *, bfd *);
 
 #define coff_bfd_copy_private_bfd_data go32_stubbed_coff_bfd_copy_private_bfd_data
 
+bfd_boolean _bfd_go32_mkobject (bfd *abfd);
+
+#define coff_mkobject  _bfd_go32_mkobject
+
 #include "coff-i386.c"
 
 /* This macro is used, because I cannot assume the endianness of the
    host system.  */
 #define _H(index) (H_GET_16 (abfd, (header + index * 2)))
@@ -421,5 +428,29 @@ go32_check_format (bfd *abfd)
   if (bfd_seek (abfd, 0, SEEK_SET) != 0)
     return NULL;
 
   return coff_object_p (abfd);
 }
+
+/*  This function is not static because it is used
+    by both targets coff-go32 and coff-go32-exe.  */
+
+bfd_boolean
+_bfd_go32_mkobject (bfd *abfd)
+{
+  coff_data_type *coff;
+  bfd_size_type amt = sizeof (coff_data_type);
+
+  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
+  if (abfd->tdata.coff_obj_data == NULL)
+    return FALSE;
+  coff = coff_data (abfd);
+  coff->symbols = NULL;
+  coff->conversion_table = NULL;
+  coff->raw_syments = NULL;
+  coff->relocbase = 0;
+  coff->local_toc_sym_map = 0;
+
+  coff->go32 = 1;
+
+  return TRUE;
+}
diff -aprNU5 gdb-7.7.1.orig/bfd/coffcode.h gdb-7.7.1/bfd/coffcode.h
--- gdb-7.7.1.orig/bfd/coffcode.h	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/bfd/coffcode.h	2014-05-10 12:28:08 +0100
@@ -373,10 +373,14 @@ CODE_FRAGMENT
 #define DOT_ZDEBUG	".zdebug"
 #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
 #define GNU_LINKONCE_WT ".gnu.linkonce.wt."
 #define DOT_RELOC	".reloc"
 
+#if defined(COFF_WITH_PE) || defined(COFF_GO32_EXE) || defined(COFF_GO32)
+# define COFF_WITH_EXTENDED_RELOC_COUNTER
+#endif
+
 #if defined (COFF_LONG_SECTION_NAMES)
 /* Needed to expand the inputs to BLANKOR1TOODD.  */
 #define COFFLONGSECTIONCATHELPER(x,y)    x ## y
 /* If the input macro Y is blank or '1', return an odd number; if it is
    '0', return an even number.  Result undefined in all other cases.  */
@@ -1956,13 +1960,50 @@ coff_set_alignment_hook (bfd *abfd, asec
     }
 }
 
 #else /* ! RS6000COFF_C */
 
+#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
+
+static void
+coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
+			 asection * section,
+			 void * scnhdr)
+{
+  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
+
+  /* Check for extended relocs.  */
+  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
+    {
+      struct external_reloc dst;
+      struct internal_reloc n;
+      file_ptr oldpos = bfd_tell (abfd);
+      bfd_size_type relsz = bfd_coff_relsz (abfd);
+
+      if (bfd_seek (abfd, (file_ptr) hdr->s_relptr, 0) != 0)
+	return;
+      if (bfd_bread (& dst, relsz, abfd) != relsz)
+	return;
+
+      coff_swap_reloc_in (abfd, &dst, &n);
+      if (bfd_seek (abfd, oldpos, 0) != 0)
+	return;
+      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
+      section->rel_filepos += relsz;
+    }
+  else if (hdr->s_nreloc == 0xffff)
+    (*_bfd_error_handler)
+      ("%s: warning: claims to have 0xffff relocs, without overflow",
+       bfd_get_filename (abfd));
+}
+
+#else /* ! COFF_GO32_EXE && ! COFF_GO32 */
+
 #define coff_set_alignment_hook \
   ((void (*) (bfd *, asection *, void *)) bfd_void)
 
+#endif /* ! COFF_GO32_EXE && ! COFF_GO32 */
 #endif /* ! RS6000COFF_C */
 #endif /* ! COFF_WITH_PE */
 #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
 
 #ifndef coff_mkobject
@@ -2668,12 +2709,12 @@ coff_write_relocs (bfd * abfd, int first
 #endif
 
       if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
 	return FALSE;
 
-#ifdef COFF_WITH_PE
-      if (obj_pe (abfd) && s->reloc_count >= 0xffff)
+#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
+      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
 	{
 	  /* Encode real count here as first reloc.  */
 	  struct internal_reloc n;
 
 	  memset (& n, 0, sizeof (n));
@@ -3575,10 +3616,14 @@ coff_apply_checksum (bfd *abfd)
   return TRUE;
 }
 
 #endif /* COFF_IMAGE_WITH_PE */
 
+#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
+# define COFF_PAD_SECTION_HEADERS
+#endif
+
 static bfd_boolean
 coff_write_object_contents (bfd * abfd)
 {
   asection *current;
   bfd_boolean hasrelocs = FALSE;
@@ -3619,13 +3664,13 @@ coff_write_object_contents (bfd * abfd)
   /* Work out the size of the reloc and linno areas.  */
 
   for (current = abfd->sections; current != NULL; current =
        current->next)
     {
-#ifdef COFF_WITH_PE
+#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
       /* We store the actual reloc count in the first reloc's addr.  */
-      if (obj_pe (abfd) && current->reloc_count >= 0xffff)
+      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
 	reloc_count ++;
 #endif
       reloc_count += current->reloc_count;
     }
 
@@ -3649,13 +3694,13 @@ coff_write_object_contents (bfd * abfd)
 
       if (current->reloc_count)
 	{
 	  current->rel_filepos = reloc_base;
 	  reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
-#ifdef COFF_WITH_PE
+#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
 	  /* Extra reloc to hold real count.  */
-	  if (obj_pe (abfd) && current->reloc_count >= 0xffff)
+	  if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
 	    reloc_base += bfd_coff_relsz (abfd);
 #endif
 	}
       else
 	current->rel_filepos = 0;
@@ -3972,10 +4017,22 @@ coff_write_object_contents (bfd * abfd)
 	}
     }
 #endif
 #endif
 
+#ifdef COFF_PAD_SECTION_HEADERS
+  if (abfd->flags & EXEC_P)
+  {
+    file_ptr cur_ptr = scn_base + abfd->section_count * bfd_coff_scnhsz(abfd);
+    long fill_size = (abfd->sections->filepos - cur_ptr);
+    bfd_byte *b = bfd_zmalloc(fill_size);
+    if (b)
+      bfd_bwrite ((PTR)b, fill_size, abfd);
+    free (b);
+  }
+#endif
+
   /* OK, now set up the filehdr...  */
 
   /* Don't include the internal abs section in the section count */
 
   /* We will NOT put a fucking timestamp in the header here. Every time you
diff -aprNU5 gdb-7.7.1.orig/bfd/cofflink.c gdb-7.7.1/bfd/cofflink.c
--- gdb-7.7.1.orig/bfd/cofflink.c	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/bfd/cofflink.c	2014-05-10 12:28:08 +0100
@@ -761,11 +761,11 @@ _bfd_coff_final_link (bfd *abfd,
 	  o->flags |= SEC_RELOC;
 	  o->rel_filepos = rel_filepos;
 	  rel_filepos += o->reloc_count * relsz;
 	  /* In PE COFF, if there are at least 0xffff relocations an
 	     extra relocation will be written out to encode the count.  */
-	  if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+	  if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff)
 	    rel_filepos += relsz;
 	}
 
       if (bfd_coff_long_section_names (abfd)
 	  && strlen (o->name) > SCNNMLEN)
@@ -1150,11 +1150,11 @@ _bfd_coff_final_link (bfd *abfd,
 	      bfd_coff_swap_reloc_out (abfd, irel, erel);
 	    }
 
 	  if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0)
 	    goto error_return;
-	  if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+	  if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff)
 	    {
 	      /* In PE COFF, write the count of relocs as the first
 		 reloc.  The header overflow bit will be set
 		 elsewhere. */
 	      struct internal_reloc incount;
diff -aprNU5 gdb-7.7.1.orig/bfd/libcoff-in.h gdb-7.7.1/bfd/libcoff-in.h
--- gdb-7.7.1.orig/bfd/libcoff-in.h	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/bfd/libcoff-in.h	2014-05-10 12:28:08 +0100
@@ -23,12 +23,13 @@
 
 /* Object file tdata; access macros.  */
 
 #define coff_data(bfd)		      ((bfd)->tdata.coff_obj_data)
 #define obj_pe(bfd)                   (coff_data (bfd)->pe)
+#define obj_go32(bfd)                 (coff_data (bfd)->go32)
 #define obj_symbols(bfd)	      (coff_data (bfd)->symbols)
-#define	obj_sym_filepos(bfd)	      (coff_data (bfd)->sym_filepos)
+#define obj_sym_filepos(bfd)	      (coff_data (bfd)->sym_filepos)
 #define obj_relocbase(bfd)	      (coff_data (bfd)->relocbase)
 #define obj_raw_syments(bfd)	      (coff_data (bfd)->raw_syments)
 #define obj_raw_syment_count(bfd)     (coff_data (bfd)->raw_syment_count)
 #define obj_convert(bfd)	      (coff_data (bfd)->conversion_table)
 #define obj_conv_table_size(bfd)      (coff_data (bfd)->conv_table_size)
@@ -101,10 +102,12 @@ typedef struct coff_tdata
 
   /* Copy of some of the f_flags bits in the COFF filehdr structure,
      used by ARM code.  */
   flagword flags;
 
+  /* Is this a GO32 coff file?  */
+  int go32;
   /* coff-stgo32 EXE stub header after BFD tdata has been allocated.  Its data
      is kept in internal_filehdr.go32stub beforehand.  */
   char *go32stub;
 } coff_data_type;
 
diff -aprNU5 gdb-7.7.1.orig/config.sub gdb-7.7.1/config.sub
--- gdb-7.7.1.orig/config.sub	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/config.sub	2014-05-10 12:28:08 +0100
@@ -615,11 +615,19 @@ case $basic_machine in
 	dicos)
 		basic_machine=i686-pc
 		os=-dicos
 		;;
 	djgpp)
-		basic_machine=i586-pc
+		UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+		case $UNAME_MACHINE in
+			*386*) basic_machine=i386-pc;;
+			*486*) basic_machine=i486-pc;;
+			*586*) basic_machine=i586-pc;;
+			*686*) basic_machine=i686-pc;;
+			*786*) basic_machine=i786-pc;;
+			*)     basic_machine=i586-pc;;
+		esac
 		os=-msdosdjgpp
 		;;
 	dpx20 | dpx20-*)
 		basic_machine=rs6000-bull
 		os=-bosx
diff -aprNU5 gdb-7.7.1.orig/djgpp/bfdsymify/ChangeLog gdb-7.7.1/djgpp/bfdsymify/ChangeLog
--- gdb-7.7.1.orig/djgpp/bfdsymify/ChangeLog	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/djgpp/bfdsymify/ChangeLog	2014-05-10 12:28:08 +0100
@@ -0,0 +1,8 @@
+2012-08-21 Juan Manuel Guerrero <juan.guerrero@gmx.de>
+	Include sysdep.h before bfd.h
+
+2006-02-18 Andris Pavenis <andris.pavenis@saunalahti.fi>
+	Modified BFDSYMIFY to work with BFD from GDB-6.4. Had to use
+	bfd_get_section_size() instead of bfd_get_section_size_befor_reloc().
+	I'm not sure that this is correct, but it seems to at least work for 
+	DJGPP.
diff -aprNU5 gdb-7.7.1.orig/djgpp/bfdsymify/Makefile gdb-7.7.1/djgpp/bfdsymify/Makefile
--- gdb-7.7.1.orig/djgpp/bfdsymify/Makefile	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/djgpp/bfdsymify/Makefile	2014-05-10 12:28:08 +0100
@@ -0,0 +1,11 @@
+CFLAGS = -Wall -O2
+srcdir = ..
+CPPFLAGS = -I. -I$(srcdir)/../include -I$(srcdir)/bfd -I$(srcdir)/../bfd -I$(srcdir)/libiberty -I$(srcdir)/intl
+CC = gcc
+
+# if compiled with NLS support enable uncomment this line.
+# bfdsymify: bfdsymify.o ../bfd/.libs/libbfd.a ../libiberty/libiberty.a ../intl/libintl.a -liconv -lz
+
+# if compiled with NLS support disable uncomment this line.
+bfdsymify: bfdsymify.o ../bfd/.libs/libbfd.a ../libiberty/libiberty.a -lz
+	$(CC) $(CFLAGS) -o $@ $+
diff -aprNU5 gdb-7.7.1.orig/djgpp/bfdsymify/bfdsymify.c gdb-7.7.1/djgpp/bfdsymify/bfdsymify.c
--- gdb-7.7.1.orig/djgpp/bfdsymify/bfdsymify.c	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/djgpp/bfdsymify/bfdsymify.c	2014-05-10 12:28:08 +0100
@@ -0,0 +1,831 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2012 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <pc.h>
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "bfdver.h"
+#include "getopt.h"
+#include "libiberty.h"
+#include "demangle.h"
+
+#define SC(r,c) (*(char *)(sc + (r) * screen_cols + (c)))
+#define SW(r,c) (*(sc + (r) * screen_cols + (c)))
+
+#undef basename
+
+static asymbol **syms;		/* Symbol table.  */
+static asymbol **sorted_syms;	/* Sorted symbol table.  */
+static long symcount;
+static long sorted_symcount;
+
+/* Dummy functions, for now.  */
+
+static void
+bfd_fatal(const char *msg)
+{
+  fprintf(stderr, "BFD fatal: %s\n", msg);
+  exit(1);
+}
+
+static void
+bfd_nonfatal(const char *msg)
+{
+  fprintf(stderr, "BFD warning: %s\n", msg);
+}
+
+static void
+list_matching_formats(char **formats)
+{
+}
+
+static void
+set_default_bfd_target(void)
+{
+  bfd_set_default_target("coff-go32-exe");
+}
+/* Read in the symbol table.  */
+
+static void
+slurp_symtab(bfd *bfdp)
+{
+  long storage;
+
+  if ((bfd_get_file_flags(bfdp) & HAS_SYMS) == 0)
+    return;
+
+  storage = bfd_get_symtab_upper_bound(bfdp);
+  if (storage < 0)
+    bfd_fatal(bfd_get_filename(bfdp));
+
+  syms = (asymbol **)xmalloc(storage);
+
+  symcount = bfd_canonicalize_symtab(bfdp, syms);
+  if (symcount < 0)
+    bfd_fatal(bfd_get_filename(bfdp));
+}
+
+/* Filter out (in place) symbols that are useless for disassembly.
+   COUNT is the number of elements in SYMBOLS.
+   Return the number of useful symbols. */
+
+static long
+remove_useless_symbols(asymbol **symbols, long count)
+{
+  register asymbol **in_ptr = symbols, **out_ptr = symbols;
+
+  while (--count >= 0)
+  {
+    asymbol *sym = *in_ptr++;
+
+    if (sym->name == NULL || sym->name[0] == '\0')
+      continue;
+    /* The funky symbols .bb, .eb, .ef, .bf get in the way.  */
+    if (sym->name[0] == '.'
+        && (sym->name[1] == 'b' || sym->name[1] == 'e')
+        && (sym->name[2] == 'b' || sym->name[2] == 'f')
+        && sym->name[3] == '\0')
+      continue;
+    if (strncmp(sym->name, ".debug_", 7) == 0)
+      continue;
+    if (sym->flags & (BSF_DEBUGGING))
+      continue;
+    if (bfd_is_und_section(sym->section)
+        || bfd_is_com_section(sym->section))
+      continue;
+
+    *out_ptr++ = sym;
+  }
+  return out_ptr - symbols;
+}
+
+/* Sort symbols into value order.  */
+
+static int
+compare_symbols(const PTR ap, const PTR bp)
+{
+  const asymbol *a = *(const asymbol **)ap;
+  const asymbol *b = *(const asymbol **)bp;
+  const char *an, *bn;
+  size_t anl, bnl;
+  bool af, bf;
+  flagword aflags, bflags;
+
+  if (bfd_asymbol_value(a) > bfd_asymbol_value(b))
+    return 1;
+  else if (bfd_asymbol_value(a) < bfd_asymbol_value(b))
+    return -1;
+
+  if (a->section > b->section)
+    return 1;
+  else if (a->section < b->section)
+    return -1;
+
+  an = bfd_asymbol_name(a);
+  bn = bfd_asymbol_name(b);
+  anl = strlen(an);
+  bnl = strlen(bn);
+
+  /* The symbols gnu_compiled and gcc2_compiled convey no real
+     information, so put them after other symbols with the same value.  */
+
+  af = (strstr (an, "gnu_compiled") != NULL
+        || strstr (an, "gcc2_compiled") != NULL);
+  bf = (strstr (bn, "gnu_compiled") != NULL
+        || strstr (bn, "gcc2_compiled") != NULL);
+
+  if (af && ! bf)
+    return 1;
+  if (! af && bf)
+    return -1;
+
+  /* We use a heuristic for the file name, to try to sort it after
+     more useful symbols.  It may not work on non Unix systems, but it
+     doesn't really matter; the only difference is precisely which
+     symbol names get printed.  */
+
+#define file_symbol(s, sn, snl)          \
+  (((s)->flags & BSF_FILE) != 0          \
+   || ((sn)[(snl) - 2] == '.'            \
+       && ((sn)[(snl) - 1] == 'o'        \
+           || (sn)[(snl) - 1] == 'a')))
+
+  af = file_symbol(a, an, anl);
+  bf = file_symbol(b, bn, bnl);
+
+  if (af && ! bf)
+    return 1;
+  if (! af && bf)
+    return -1;
+
+  /* Try to sort global symbols before local symbols before function
+     symbols before debugging symbols.  */
+
+  aflags = a->flags;
+  bflags = b->flags;
+
+  if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
+  {
+    if ((aflags & BSF_DEBUGGING) != 0)
+      return 1;
+    else
+      return -1;
+  }
+  if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
+  {
+    if ((aflags & BSF_FUNCTION) != 0)
+      return -1;
+    else
+     return 1;
+  }
+  if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
+  {
+    if ((aflags & BSF_LOCAL) != 0)
+      return 1;
+    else
+     return -1;
+  }
+  if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
+  {
+    if ((aflags & BSF_GLOBAL) != 0)
+      return -1;
+    else
+      return 1;
+  }
+
+  /* Symbols that start with '.' might be section names, so sort them
+     after symbols that don't start with '.'.  */
+  if (an[0] == '.' && bn[0] != '.')
+    return 1;
+  if (an[0] != '.' && bn[0] == '.')
+    return -1;
+
+  /* Finally, if we can't distinguish them in any other way, try to
+     get consistent results by sorting the symbols by name.  */
+  return strcmp(an, bn);
+}
+
+static bfd *
+init_bfd_syms_or_die(const char *prog, const char *tgt)
+{
+  char **matching;
+  bfd  *bfdp;
+
+  bfdp = bfd_openr(prog, tgt);
+  if (bfdp == NULL)
+    bfd_fatal(prog);
+
+  if (bfd_check_format(bfdp, bfd_archive))
+    fprintf (stderr, "%s: can not get addresses from archive\n", prog);
+
+  if (!bfd_check_format_matches(bfdp, bfd_object, &matching))
+  {
+    bfd_nonfatal(bfd_get_filename(bfdp));
+    if (bfd_get_error() == bfd_error_file_ambiguously_recognized)
+    {
+      list_matching_formats(matching);
+      free(matching);
+    }
+    exit(1);
+  }
+
+  slurp_symtab(bfdp);
+
+  /* We make a copy of syms to sort.  We don't want to sort syms
+     because that will screw up the relocs.  */
+  sorted_syms = (asymbol **) xmalloc(symcount * sizeof (asymbol *));
+  memcpy(sorted_syms, syms, symcount * sizeof (asymbol *));
+
+  sorted_symcount = remove_useless_symbols(sorted_syms, symcount);
+
+  /* Sort the symbols into section and symbol order */
+  qsort(sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
+
+  return bfdp;
+}
+
+/* Locate a symbol given a bfd, a section, and a VMA.  */
+
+static asymbol *
+find_symbol_for_address(bfd *abfd, asection *sec, bfd_vma vma)
+{
+  /* @@ Would it speed things up to cache the last two symbols returned,
+     and maybe their address ranges?  For many processors, only one memory
+     operand can be present at a time, so the 2-entry cache wouldn't be
+     constantly churned by code doing heavy memory accesses.  */
+
+  /* Indices in `sorted_syms'.  */
+  long min = 0;
+  long max = sorted_symcount;
+  long this_place;
+
+  if (sorted_symcount < 1)
+    return NULL;
+
+  /* Perform a binary search looking for the closest symbol to the
+     required value.  We are searching the range (min, max].  */
+  while (min + 1 < max)
+  {
+    asymbol *sym;
+
+    this_place = (max + min) / 2;
+    sym = sorted_syms[this_place];
+
+    if (bfd_asymbol_value (sym) > vma)
+      max = this_place;
+    else if (bfd_asymbol_value (sym) < vma)
+      min = this_place;
+    else
+    {
+      min = this_place;
+      break;
+    }
+  }
+
+  /* The symbol we want is now in min, the low end of the range we
+     were searching.  If there are several symbols with the same
+     value, we want the first one.  */
+  this_place = min;
+  while (this_place > 0
+         && (bfd_asymbol_value (sorted_syms[this_place])
+             == bfd_asymbol_value (sorted_syms[this_place - 1])))
+    --this_place;
+
+  /* If the file is relocateable, and the symbol could be from this
+     section, prefer a symbol from this section over symbols from
+     others, even if the other symbol's value might be closer.
+
+     Note that this may be wrong for some symbol references if the
+     sections have overlapping memory ranges, but in that case there's
+     no way to tell what's desired without looking at the relocation
+     table.  */
+
+  if (sorted_syms[this_place]->section != sec
+      && ((abfd->flags & HAS_RELOC) != 0
+          && vma >= bfd_get_section_vma (abfd, sec)
+          && vma < (bfd_get_section_vma (abfd, sec)
+                    + bfd_section_size (abfd, sec))))
+  {
+    long i;
+
+    for (i = this_place + 1; i < sorted_symcount; i++)
+    {
+      if (bfd_asymbol_value (sorted_syms[i])
+          != bfd_asymbol_value (sorted_syms[this_place]))
+        break;
+    }
+    for (--i; i >= 0; i--)
+    {
+      if (sorted_syms[i]->section == sec
+          && (i == 0
+              || sorted_syms[i - 1]->section != sec
+              || (bfd_asymbol_value (sorted_syms[i])
+                  != bfd_asymbol_value (sorted_syms[i - 1]))))
+      {
+        this_place = i;
+        break;
+      }
+    }
+
+    if (sorted_syms[this_place]->section != sec)
+    {
+      /* We didn't find a good symbol with a smaller value.
+         Look for one with a larger value.  */
+      for (i = this_place + 1; i < sorted_symcount; i++)
+      {
+        if (sorted_syms[i]->section == sec)
+        {
+          this_place = i;
+          break;
+        }
+      }
+    }
+
+    if (sorted_syms[this_place]->section != sec
+        && ((abfd->flags & HAS_RELOC) != 0
+             && vma >= bfd_get_section_vma (abfd, sec)
+             && vma < (bfd_get_section_vma (abfd, sec)
+                       + bfd_section_size (abfd, sec))))
+    {
+      /* There is no suitable symbol.  */
+      return NULL;
+    }
+  }
+
+  return sorted_syms[this_place];
+}
+
+/* These global variables are used to pass information between
+   translate_address and find_address_in_section.  */
+
+static bfd_vma pc;
+static const char *filename;
+static const char *functionname;
+static unsigned int linenum;
+static unsigned long offset;
+static int found;
+
+/* Look for an address in a section.  This is called via
+   bfd_map_over_sections.  */
+
+static void
+find_address_in_section (bfd *bfdp, asection *section, void *data)
+{
+  bfd_vma vma;
+  bfd_size_type size;
+
+  if (found)
+    return;
+
+  if ((bfd_get_section_flags(bfdp, section) & SEC_ALLOC) == 0)
+    return;
+
+  vma = bfd_get_section_vma(bfdp, section);
+  if (pc < vma)
+    return;
+
+  size = bfd_get_section_size (section);
+  if (pc >= vma + size)
+    return;
+
+  found = bfd_find_nearest_line(bfdp, section, syms, pc - vma,
+                                &filename, &functionname, &linenum);
+}
+
+static void
+find_symbol_in_section(bfd *bfdp, asection *section, void *data)
+{
+  asymbol *sym0, *sym;
+  bfd_vma vma;
+
+  if (found)
+    return;
+
+  vma = bfd_get_section_vma(bfdp, section);
+  if (pc < vma)
+    return;
+
+  sym = sym0 = find_symbol_for_address(bfdp, section, pc);
+  if (sym)
+  {
+    const char *f = bfd_asymbol_name(sym);
+    int i = 0;
+
+    if (!functionname || *functionname == '\0')
+      functionname = f;
+
+    /* find_symbol_for_address has a nasty habit of finding local
+       labels and other irrelevant symbols that are closer to PC
+       than the enclosing function.  This loop searches backwards
+       until it finds a symbol with the same name as FUNCTIONNAME.  */
+    while (i < 0x1000 && strcmp(f, functionname) != 0)
+    {
+      sym = find_symbol_for_address(bfdp, section,
+                                      bfd_asymbol_value(sym) - 1);
+      if (!sym)
+        break;
+      f = bfd_asymbol_name(sym);
+      i++;		/* don't look too far... */
+    }
+    if (i >= 0x1000)	/* not found--fall back on the original guess */
+      sym = sym0;
+  }
+  if (sym)
+  {
+    found = 1;
+    functionname = bfd_asymbol_name(sym);
+    offset = pc - bfd_asymbol_value(sym);
+  }
+}
+
+static void
+translate_address(unsigned v, bfd *bfdp,
+                  char **func, int *lineno, char **file, unsigned long *offs)
+{
+  char *demangled_name;
+
+  pc = v;
+  found = 0;
+  bfd_map_over_sections(bfdp, find_address_in_section, (void *)NULL);
+  if (!found)
+  {
+    *func = NULL;
+    *file = NULL;
+    *lineno = -1;
+    *offs = 0;
+    functionname = NULL;
+  }
+  else
+    *file = (char *)filename;
+  if (!functionname || *functionname == '\0')
+  {
+    *lineno = -1;
+    *func = NULL;
+  }
+  else
+    *func = (char *)functionname;
+  found = 0;
+  bfd_map_over_sections(bfdp, find_symbol_in_section, (void *)NULL);
+  if (found)
+  {
+    /* The convoluted comparison with `main' is so that we filter
+       out false attributions of EIPs in library functions to the
+       last line of the main function.  */
+    if (*func
+         && (strcmp (*func, "main") == 0
+             || strcmp (*func, "_main") == 0)
+         && strcmp (functionname, "main") != 0
+         && strcmp (functionname, "_main") != 0)
+    {
+      *file = NULL;
+      *lineno = -1;
+    }
+    *func = (char *)functionname;
+  }
+  if (found && *func && **func != '\0')
+  {
+    if (**func == bfd_get_symbol_leading_char(bfdp))
+      ++*func;
+    demangled_name = cplus_demangle(*func, DMGL_ANSI | DMGL_PARAMS);
+    if (demangled_name)
+      *func = demangled_name;
+    *lineno = linenum;
+    *offs = offset;
+  }
+}
+
+int main(int argc, char **argv)
+{
+  int r, c;
+  short *sc;
+  char *buf = NULL;
+  size_t bufsize = 0;
+  int i, lineno;
+  unsigned v;
+  unsigned long d;
+  char *func, *file;
+  FILE *ofile=0;
+  FILE *ifile=0;
+  char *progname = NULL;
+  char *bfdsymify;
+  bfd  *abfd = NULL;
+  char *target = NULL;
+  int   screen_rows, screen_cols, cursor_row, cursor_col;
+
+  bfdsymify = argv[0];
+
+  if (argc < 2)
+  {
+    fprintf(stderr,
+	    "BFDSymify Version 1.2, 2002-02-24 (BFD version %s)\n",
+            BFD_VERSION_STRING);
+    fprintf(stderr,
+	    "Add source file information to a DJGPP program's call-frame traceback\n\n");
+    fprintf(stderr, "Usage: bfdsymify [-o <outfile>] [-i <corefile>] <program>\n");
+    return 1;
+  }
+  while (argv[1][0] == '-')
+  {
+    if ((strcmp(argv[1], "-o") == 0) && (argc > 3))
+    {
+      ofile = fopen(argv[2], "w");
+      if (ofile == 0)
+        fprintf(stderr, "Error: unable to open file %s\n", argv[2]);
+      argc -= 2;
+      argv += 2;
+    }
+    else if ((strcmp(argv[1], "-i") == 0) && (argc > 3))
+    {
+      ifile = fopen(argv[2], "r");
+      if (ifile == 0)
+        fprintf(stderr, "Error: unable to open file %s\n", argv[2]);
+      argc -= 2;
+      argv += 2;
+    }
+    else
+    {
+      fprintf(stderr, "Invalid option %s - type `%s' for help\n",
+	      argv[1], bfdsymify);
+      exit(1);
+    }
+  }
+
+  progname = argv[1];
+  bfd_init();
+  set_default_bfd_target();
+
+  if (ifile)
+  {
+    char line[1000];
+    if (ofile == 0)
+      ofile = stdout;
+    while (fgets(line, 1000, ifile))
+    {
+      if (strncmp(line + 25, " program=", 9) == 0)
+      {
+	fputs(line, ofile);
+	if (progname)
+	{
+	  char *arg_base = basename(progname), *prog_base = basename(line + 9);
+	  if (strcasecmp(prog_base, arg_base)
+	      && strncasecmp(prog_base, arg_base, strlen(prog_base) - 4))
+	    fprintf(stderr,
+		    "!!! Program name in corefile doesn't match `%s'\n",
+		    progname);
+	}
+	else
+	  progname = strdup(line + 9);
+      }
+      else if (strncmp(line, "  0x", 4) == 0)
+      {
+	if (progname == NULL)
+	{
+	  progname = "a.exe";
+	  if (access(progname, R_OK))
+	  {
+	    progname = "a.out";
+	    if (access(progname, R_OK))
+	    {
+	      fprintf(stderr, "Error: no usable program name given.\n");
+	      exit (1);
+	    }
+	  }
+	}
+	if (abfd == NULL)
+	  abfd = init_bfd_syms_or_die(progname, target);
+        sscanf(line+4, "%x", &v);
+
+	translate_address(v, abfd, &func, &lineno, &file, &d);
+        fprintf(ofile, "  0x%08x", v);
+        if (func)
+        {
+          fprintf(ofile, " %s", func);
+          if (d)
+            fprintf(ofile, "%+ld", d);
+        }
+        if (file)
+        {
+          if (func)
+            fprintf(ofile, ", ");
+	  fprintf(ofile, "file %s", file);
+	  if (lineno > 0)
+	    fprintf (ofile, ", line %d", lineno);
+        }
+        fputc('\n', ofile);
+      }
+      else
+        fputs(line, ofile);
+    }
+
+    if (syms != NULL)
+    {
+      free(syms);
+      syms = NULL;
+      free(sorted_syms);
+    }
+
+    if (abfd)
+      bfd_close(abfd);
+    return 0;
+  }
+
+  screen_rows = ScreenRows();
+  screen_cols =  ScreenCols();
+  sc = (short *)malloc(screen_rows * screen_cols * 2);
+
+  ScreenGetCursor(&cursor_row, &cursor_col);
+
+  ScreenRetrieve(sc);	/* FIXME: handle graphics modes! */
+
+  bufsize = screen_cols + 10;
+  buf = xmalloc (bufsize);
+
+  for (r = 0; r < screen_rows; r++)
+  {
+    if (SC(r,25) == ' '
+	&& SC(r,26) == 'p' && SC(r,27) == 'r' && SC(r,28) == 'o'
+	&& SC(r,29) == 'g' && SC(r,30) == 'r' && SC(r,31) == 'a'
+	&& SC(r,32) == 'm' && SC(r,33) == '=')
+    {
+      char prog[FILENAME_MAX];
+
+      /* The test for blank relies on the fact that DJGPP programs
+	 always get short 8+3 aliases as their DOS argv[0], and those
+	 cannot have embedded blanks.  */
+      for (i = 26; SC(r,i) != ' ' && SC(r,i) != '\0'; i++)
+         prog[i - 26] = SC(r, i);
+      prog[i - 26] = 0;
+      /* If the name is extremely long, it may overflow into the next
+	 screen line, and we err by one row at this point.  (We cannot
+	 possibly be more than one row off, since short path names are
+	 never longer than 80 characters.)  */
+      if (i >= screen_cols)
+      {
+	r += 1;
+	i -= screen_cols;
+      }
+      if (progname)
+      {
+	char *arg_base = basename(progname), *prog_base = basename(prog);
+
+	if (strcasecmp(prog_base, arg_base)
+	    && (strncasecmp(prog_base, arg_base, strlen(prog_base) - 4)
+		|| arg_base[strlen(prog_base) - 4])) /* FIXME: LFN and 8+3 */
+	  {
+	    sprintf(buf,
+		    "!!! Program name on screen doesn't match `%s'",
+		    progname);
+
+	    for (i = 0; buf[i]; i++)
+	      SW(cursor_row, i) = 0x0700 + buf[i];
+	  }
+      }
+      else
+	progname = strdup(prog);
+    }
+    else if (SC(r, 0) == ' ' && SC(r, 1) == ' '
+	     && SC(r, 2) == '0' && SC(r, 3) == 'x')
+    {
+      int l_left = bufsize - 1, l_func = 0, l_off = 0, l_file = 0, l_line = 0;
+      if (progname == NULL)
+      {
+	progname = "a.exe";
+	if (access(progname, R_OK))
+	{
+	  progname = "a.out";
+	  if (access(progname, R_OK))
+	  {
+	    ScreenSetCursor(cursor_row, cursor_col);
+	    fprintf(stderr, "Error: no usable program name given.\n");
+	    exit (1);
+	  }
+	}
+      }
+      if (abfd == NULL)
+	abfd = init_bfd_syms_or_die(progname, target);
+      buf[8] = 0;
+      for (i = 0; i < 8; i++)
+        buf[i] = SC(r, i + 4);
+      sscanf(buf, "%x", &v);
+      translate_address(v, abfd, &func, &lineno, &file, &d);
+      if (ofile)
+	fprintf (ofile, "  0x%08x", v);
+      buf[0] = 0;
+      if (func)
+      {
+	l_func = strlen (func);
+	if (l_func > l_left - 10)
+	{
+	  bufsize += l_func + 10;
+	  l_left += l_func + 10;
+	  buf = xrealloc (buf, bufsize);
+	}
+	strcat(buf, func);
+	l_left -= l_func;
+	if (d)
+	{
+	  l_left -= sprintf(buf + l_func, "%+ld", d);
+	  l_off = strlen(buf);
+	}
+	else
+	  l_off = l_func;
+      }
+      if (file)
+      {
+	l_file = strlen(file);
+	if (l_left < l_file + 25)
+	{
+	  bufsize += l_file + 25;
+	  l_left += l_file + 25;
+	  buf = xrealloc (buf, bufsize);
+	}
+        if (buf[0])
+	{
+          strcat(buf, ", ");
+	  l_left -= 2;
+	}
+        sprintf(buf+strlen(buf), "file %s", file);
+	l_file = strlen(buf);
+	if (lineno > 0)
+	  sprintf(buf+strlen(buf), ", line %d", lineno);
+      }
+      else
+	l_file = l_off;
+      l_line = strlen(buf);
+      if (buf[0])
+      {
+	int j;
+	int max_func =
+	  l_line > screen_cols - 13 && l_off > screen_cols / 2 - 6
+	  ? screen_cols / 2 - 8 - (l_off - l_func)
+	  : l_off;
+	int in_func = 1, in_file = 0;
+
+	/* 0xdeadbeef _FooBar_Func..+666, file FooBarF..e.Ext, line 1234  */
+	/*            ^             ^   ^                    ^          ^ */
+	/*            0        l_func l_off             l_file     l_line */
+	for (i = 0, j = 0; buf[j]; i++, j++)
+	{
+	  if (13 + i >= screen_cols)
+	    break;
+	  else if (in_func && i >= max_func && j < l_off)
+	  {
+	    SW(r, 13 + i) = 0x0700 + '.'; i++;
+	    SW(r, 13 + i) = 0x0700 + '.'; i++;
+	    j = l_func;		/* truncate function name, jump to offset */
+	    in_func = 0;
+	    in_file = 1;
+	  }
+	  else if (in_file
+		   && 13 + i >= screen_cols - 8 - (l_line - l_file)
+		   && j < l_file - 6)
+	  {
+	    SW(r, 13 + i) = 0x0700 + '.'; i++;
+	    SW(r, 13 + i) = 0x0700 + '.'; i++;
+	    j = l_file - 6;	/* jump to last portion of file name */
+	    in_file = 0;
+	  }
+	  SW(r, 13 + i) = 0x0f00 + buf[j];
+	}
+	if (ofile)
+	  fprintf (ofile, " %s\n", buf);
+      }
+    }
+  }
+
+  if (ofile)
+  {
+    for (r = 0; r < screen_rows; r++)
+    {
+      c = 0;
+      for (i = 0; i < screen_cols; i++)
+        if (SC(r, i) != ' ')
+          c = i;
+      for (i = 0; i <= c; i++)
+        fputc(SC(r, i), ofile);
+      fputc('\n', ofile);
+    }
+    fclose(ofile);
+  }
+  else
+    ScreenUpdate(sc);	/* FIXME: graphics modes */
+
+  if (syms != NULL)
+  {
+    free(syms);
+    syms = NULL;
+    free(sorted_syms);
+  }
+
+  if (abfd)
+    bfd_close(abfd);
+  return 0;
+}
diff -aprNU5 gdb-7.7.1.orig/djgpp/bfdsymify/readme gdb-7.7.1/djgpp/bfdsymify/readme
--- gdb-7.7.1.orig/djgpp/bfdsymify/readme	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/djgpp/bfdsymify/readme	2014-05-10 12:28:08 +0100
@@ -0,0 +1,23 @@
+Once upon a time, a long, LONG time ago, DJ asked for a version of
+SYMIFY that would be based on BFD functions, rather than on our
+private syms.c from libdbg.a.  The advantage of this would be that
+such a program would automatically support every format of debugging
+info that BFD is configured to support, not only the COFF debug info
+supported by libdbg.a.
+
+Well, it took more than a year, but I finally got to making it happen.
+I called the program BFDSYMIFY, but that's a temporary name (it also
+exceeds DOS 8+3 limits, which isn't very nice), so if you have a
+better name, I am open to suggestions.  My intent was to eventually ask
+the Binutils maintainer to include this program as part of Binutils,
+but it looks like it won't happen any time soon...
+
+In the meantime, I'm making it available as part of GDB distro.
+
+Please tell me how well does bfdsymify work (or doesn't work) for you.
+
+
+Enjoy,
+                                  Eli Zaretskii  <eliz@is.elta.co.il>
+
+
diff -aprNU5 gdb-7.7.1.orig/djgpp/build.sh gdb-7.7.1/djgpp/build.sh
--- gdb-7.7.1.orig/djgpp/build.sh	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/djgpp/build.sh	2014-05-10 12:39:38 +0100
@@ -0,0 +1,437 @@
+#  This script only works in the ./djgpp directory.
+
+export HOME=.
+export PATH_SEPARATOR=:
+export PATH_EXPAND=y
+export TEST_FINDS_EXE=y
+export LD=ld
+export NM=nm
+export LN_S="cp -p"
+export GMSGFMT=${GMSGFMT='/dev/env/DJDIR/bin/msgfmt'}
+export MSGFMT=${MSGFMT='/dev/env/DJDIR/bin/msgfmt'}
+export MSGMERGE=${MSGMERGE='/dev/env/DJDIR/bin/msgmerge'}
+export XGETTEXT=${XGETTEXT='/dev/env/DJDIR/bin/xgettext'}
+export ac_cv_path_EMACS=${EMACS='/dev/env/DJDIR/gnu/emacs/bin/emacs'}
+export ac_cv_path_M4=${M4='/dev/env/DJDIR/bin/m4'}
+export ac_cv_path_GREP=${GREP='/dev/env/DJDIR/bin/grep'}
+export ac_cv_path_EGREP=${EGREP='/dev/env/DJDIR/bin/egrep'}
+export ac_cv_path_FGREP=${FGREP='/dev/env/DJDIR/bin/fgrep'}
+export ac_cv_path_SED=${SED='/dev/env/DJDIR/bin/sed'}
+export ac_cv_path_MAKEINFO=${MAKEINFO='/dev/env/DJDIR/bin/makeinfo'}
+export ac_cv_path_INSTALL_INFO=${INSTALL_INFO='/dev/env/DJDIR/bin/install-info'}
+export ac_cv_path_ROFF=${ROFF='/dev/env/DJDIR/bin/groff'}
+export ac_cv_path_GROFF=${GROFF='/dev/env/DJDIR/bin/groff'}
+export ac_cv_path_NROFF=${NROFF='/dev/env/DJDIR/bin/nroff'}
+export ac_cv_path_PERL=${PERL='/dev/env/DJDIR/bin/perl'}
+export ac_cv_path_mkdir=${MKDIR_P='/dev/env/DJDIR/bin/mkdir -p'}
+export ac_cv_path_RM=${RM='/dev/env/DJDIR/bin/rm'}
+export ac_cv_path_MV=${MV='/dev/env/DJDIR/bin/mv'}
+export ac_cv_path_TAR=${TAR='/dev/env/DJDIR/bin/tar'}
+export ac_cv_path_PR_PROGRAM=${PR='/dev/env/DJDIR/bin/pr'}
+export ac_cv_path_ed_PROGRAM=${ED='/dev/env/DJDIR/bin/ed'}
+export ac_cv_path_TEXI2DVI=${TEXI2DVI='texi2dvi'}
+export ac_cv_path_TEXI2PDF=${TEXI2PDF='texi2pdf'}
+export ac_cv_path_DVIPS=${DVIPS='dvips'}
+export ac_cv_path_PS2PDF=${PS2PDF='ps2pdf'}
+export ac_cv_path_TEST_SHELL=${TEST_SHELL='/dev/env/DJDIR/bin/bash'}
+export ac_cv_path_MKTEMP=${MKTEMP='/dev/env/DJDIR/bin/mktemp'}
+export ac_cv_prog_LN_S="cp -p"
+export ac_cv_func_fork=no
+export ac_cv_func_mkfifo=no
+export ac_cv_func_mknod=no
+export ac_cv_func_mmap=no
+export ac_cv_func_pipe=no
+export ac_cv_func_vfork=no
+
+# Do not allow that the BFD's configure script determine the
+# host dependant file_ptr a.k.a. off_t type as BFD_HOST_64_BIT.
+# This is the case if ftello64 and fseeko64 are found.  But DJGPP
+# does not provide the full set of 64 bit file functions required
+# for a working 64 bit BFD.
+export ac_cv_func_fseeko64=${ac_cv_func_fseeko64=no}
+export ac_cv_func_ftello64=${ac_cv_func_ftello64=no}
+export ac_cv_have_decl_fseeko64=${ac_cv_have_decl_fseeko64=no}
+export ac_cv_have_decl_ftello64=${ac_cv_have_decl_ftello64=no}
+
+# Ensure that always old GNU extern inline semantics is used
+# (aka -fgnu89-inline) even if ISO C99 semantics has been specified.
+export CFLAGS=${CFLAGS='-g -O2 -fgnu89-inline -march=i386 -mtune=i586'}
+
+# DJGPP's implementation of printf survives out-of-memory conditions.
+export gl_cv_func_printf_enomem='yes'
+
+# Enable libiberty installation.
+# Passing --enable-install-libiberty to the toplovel configure seems not to be enough.
+export enable_install_libiberty=yes
+
+# Select NLS support.
+# NLS_SUPPORT='--enable-nls'
+ NLS_SUPPORT='--disable-nls'
+
+if [ "x${NLS_SUPPORT}" = "x--enable-nls" ]; then
+  rm -vf ../bfd/po/*gmo
+  rm -vf ../bfd/po/*pot
+  rm -vf ../gdb/po/*gmo
+  rm -vf ../gdb/po/*pot
+  rm -vf ../opcodes/po/*gmo
+  rm -vf ../opcodes/po/*pot
+fi
+
+
+#
+#  1: Adjust the configure scripts.
+#
+
+cat > script.sed << EOF
+# For some reason the function does not work with bash 2.05b.
+/^func_lalib_p/,/^}$/ {
+  /test/ i\\
+    case \$1 in\\
+    *.la | *.lo)
+  /GREP/ {
+    s/$/;;/
+    a\\
+    *) false;;\\
+    esac
+  }
+}
+
+# Use func_lalib_p instead of func_lalib_unsafe_p.
+/func_lalib_unsafe_p[ 	][^(]/ s/_unsafe//
+
+# Adjust temp directory.
+/{TMPDIR-\/tmp}/ s|{TMPDIR-/tmp}|{TMPDIR-\${TMP-\${TEMP-.}}}|
+
+# Remove -lc reference from the dependency_libs= line in .la files.
+# This is unnecessary when linking with static  labraries and causes
+# multiple symbol definitions that cannot be resolved when using DXE3 modules.
+/^# Libraries that this one depends upon.$/,/^# Directory that this library needs to be installed in:$/ {
+  /^# Directory that this library needs to be installed in:$/ {
+    n
+    a\\
+	  sed "/^dependency_libs=/ s|[ 	]\\\\{1,\\\\}-lc| |"  \$output > fixed.sed && cp -vf fixed.sed \$output
+  }
+}
+
+# The CR test for awk does not work for DJGPP.
+/^ac_cs_awk_cr=/,/^$/ {
+  /^fi$/ a\\
+ac_cs_awk_cr=\$ac_cr
+}
+
+# AWK program above erroneously prepends '/' to C:/dos/paths
+/# AWK program above erroneously prepends/,/esac/ {
+  s/mingw/*djgpp* | mingw/
+}
+
+# Force the test for 'ln -s' to report 'cp -pf'.
+/as_ln_s='ln -s'/ s/ln -s/cp -pf/
+
+# Set the right shell for libtool
+/^LIBTOOL=.*libtool'$/ s/".*"/'\$(SHELL) '/
+
+# Adjust the config.site path for the case
+# of recursive called configure scripts
+/^if test "\$no_recursion" != yes; then/ a\\
+  djgpp_config_site=\$CONFIG_SITE
+/case \$srcdir in/,/esac/ {
+  / # Relative name.$/ a\\
+export CONFIG_SITE=\$ac_top_build_prefix\$djgpp_config_site
+}
+
+# DJGPP specific adjustments of the compile-time system search path for libraries.
+/^[ 	]*lt_search_path_spec=.*-print-search-dirs/ s,\`\$, -e \\"s%[A-z]:[\\\\\\\\/]djgpp-[0-9].[0-9][0-9][\\\\\\\\/]%/dev/env/DJDIR/%g\\"&,
+
+# Fix realpath check.  DJGPP always prepends a drive letter.
+/checking whether realpath works/,/^_ACEOF$/ {
+  /name && \*name == '\/'/ s/\*name/name[2]/
+}
+
+# We have an emulation of nl_langinfo in go32-nat.c that supports CODESET.
+/^for ac_var in \\\$ac_precious_vars; do/i\\
+am_cv_langinfo_codeset=yes\\
+bash_cv_langinfo_codeset=yes\\
+ac_cv_header_nl_types_h=yes
+
+# Add pdcurses to the search list.
+/for ac_lib in.*ncurses cursesX curses/ s/ncurses/pdcurses &/
+EOF
+
+
+for file in ../ltmain.sh ../configure ../bfd/configure ../etc/configure ../gdb/configure ../opcodes/configure ../readline/configure; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+rm -vf ./file.out ./script.sed
+
+
+
+#
+#  2: Adjust the Makefile.ins and other files.
+#
+
+cat > script.sed << EOF
+# Fix for ./gdb/data-directory/Makefile.in
+/^stamp-syscalls:/ s/\\\$(SYSCALLS_FILES)/#&/
+/^stamp-python:/ s/\\\$(PYTHON_FILES)/#&/
+/^stamp-system-gdbinit:/ s/\\\$(SYSTEM_GDBINIT_FILES)/#&/
+
+# Fix for ./bfd/Makefile.in
+# Force the regenaration of libcoff.h
+# to define obj_go32
+/^\\\$(BFD_H):/ s/:/: stmp-lcoff-h/
+
+# Fix for ./readline/Makefile.in
+# Force the compilation of readline/tminit.c
+/^CSOURCES = \\\$(srcdir)\\/readline.c/ s|=|= \\\$(srcdir)/tminit.c|
+/^OBJECTS = readline.o/ s/=/= tminit.o/
+/^readline.o: \\\$(srcdir)\\/readline.c/ {
+i\\
+tminit.o: \\\$(srcdir)/tminit.c
+s|$| \\\$(srcdir)/tminit.c|
+}
+
+# For html docs.
+/^MAKEINFOHTML[ 	]*=/ s/$/ --no-split/
+s/--split-size=5000000/--no-split/g
+
+# Fixes for ./libiberty/Makefile.in
+# ps support for libiberty docs.
+/dvi-subdir[ 	]\\{1,\\}pdf-subdir/ s/dvi-subdir[ 	]\\{1,\\}pdf-subdir/& ps-subdir/
+
+/^LIBIBERTY_PDFFILES[ 	]*=/ i\\
+LIBIBERTY_PSFILES = libiberty.ps\\
+\\
+ps: \\\$(LIBIBERTY_PSFILES) ps-subdir\\
+
+
+/^libiberty.pdf[ 	]*:/ i\\
+libiberty.ps : ./libiberty.dvi \\\$(srcdir)/libiberty.texi \\\$(TEXISRC)\\
+	dvips -o ./libiberty.ps ./libiberty.dvi\\
+
+# Enable libiberty installation.
+# Passing --enable-install-libiberty to the toplovel configure seems not to be enough.
+s/@target_header_dir@/libiberty/
+
+# Fixes for ./etc/Makefile.in.
+/^HTMLFILES =.*configure.html$/ i\\
+PSFILES = standards.ps configure.ps
+/epstopdf/ s/[ 	]\\{1,\\}-outfile/ --outfile/
+
+# Fixes for ./gdb/Makefile
+/^COMMON_OBS[ 	]*=.*(YYOBJ).*$/,/^$/ {
+  /version.o/ i\\
+	vsnprntf.o \\\\
+}
+/^# gdb\\/cli\\/ dependencies/ i\\
+# gdb/djgpp/ dependencies\\
+#\\
+\\
+vsnprntf.o: \\\$(srcdir)/djgpp/vsnprntf.c\\
+	\\\$(COMPILE) \\\$(srcdir)/djgpp/vsnprntf.c\\
+	\\\$(POSTCOMPILE)\\
+\\
+#
+
+# Fixes for ./gdb/doc/Makefile
+# For html docs.
+/^MAKEHTML[ 	]*=/ s/$/ --no-split/
+EOF
+
+
+for file in ./../gdb/Makefile.in ./../gdb/data-directory/Makefile.in ./../bfd/Makefile.in ./../bfd/doc/Makefile.in ./../gdb/doc/Makefile.in ./../libiberty/Makefile.in ./../etc/Makefile.in ./../readline/Makefile.in; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+
+rm -vf ./file.out ./script.sed
+
+
+
+#
+#  3: Adjust the config.in headers.
+#
+
+cat > script.sed << EOF
+# DJGPP 2.03 needs the snprintf prototype.
+/^#undef HAVE_DECL_SNPRINTF$/ c\\
+#include <sys/version.h>\\
+#if __DJGPP__ == 2 && __DJGPP_MINOR__ < 4\\
+# define HAVE_DECL_SNPRINTF 0\\
+#else\\
+#undef HAVE_DECL_SNPRINTF\\
+#endif
+
+$ a\\
+#ifdef __DJGPP__\\
+# if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))\\
+#  define __gnuc_extension__  __extension__\\
+# else\\
+#  define __gnuc_extension__\\
+# endif\\
+\\
+# undef  IS_SLASH\\
+# define IS_SLASH(c)                ((c) == '/' || (c) == '\\\\\\\\')\\
+# undef  IS_DIRECTORY_SEPARATOR\\
+# define IS_DIRECTORY_SEPARATOR(c)  (IS_SLASH(c) || (c) == ':')\\
+\\
+# include <libc/unconst.h>\\
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)   \\\\\\
+  (__gnuc_extension__                               \\\\\\
+    ({                                              \\\\\\
+       char *_dst, *_src;                           \\\\\\
+       _dst = _src = unconst((file_name), char *);  \\\\\\
+       while (*_src++)                              \\\\\\
+         ;                                          \\\\\\
+       while ((_src - _dst) && (*--_src != '.'))    \\\\\\
+         ;                                          \\\\\\
+       for (*_src = '\\\\0'; (_src - _dst); _src--)    \\\\\\
+         if (IS_DIRECTORY_SEPARATOR(*_src))         \\\\\\
+           break;                                   \\\\\\
+       if (_src - _dst)                             \\\\\\
+         while ((*_dst++ = *++_src))                \\\\\\
+           ;                                        \\\\\\
+       (file_name);                                 \\\\\\
+    })                                              \\\\\\
+  )\\
+#else\\
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (file_name)\\
+#endif
+EOF
+
+
+for file in ../bfd/config.in ../gdb/config.in ../libiberty/config.in; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+rm -vf ./file.out ./script.sed
+
+
+cat > script.sed << EOF
+# DJGPP 2.03 needs the snprintf prototype.
+$ a\\
+\\
+#ifdef __DJGPP__\\
+# include <sys/version.h>\\
+# if __DJGPP__ == 2 && __DJGPP_MINOR__ < 4\\
+/* Define to 1 if you have the declaration of snprintf, and to 0 if you\\
+   do not. */\\
+#  define HAVE_DECL_SNPRINTF 0\\
+# endif\\
+\\
+# if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))\\
+#  define __gnuc_extension__  __extension__\\
+# else\\
+#  define __gnuc_extension__\\
+# endif\\
+\\
+# undef  IS_SLASH\\
+# define IS_SLASH(c)                ((c) == '/' || (c) == '\\\\\\\\')\\
+# undef  IS_DIRECTORY_SEPARATOR\\
+# define IS_DIRECTORY_SEPARATOR(c)  (IS_SLASH(c) || (c) == ':')\\
+\\
+# include <libc/unconst.h>\\
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)   \\\\\\
+  (__gnuc_extension__                               \\\\\\
+    ({                                              \\\\\\
+       char *_dst, *_src;                           \\\\\\
+       _dst = _src = unconst((file_name), char *);  \\\\\\
+       while (*_src++)                              \\\\\\
+         ;                                          \\\\\\
+       while ((_src - _dst) && (*--_src != '.'))    \\\\\\
+         ;                                          \\\\\\
+       for (*_src = '\\\\0'; (_src - _dst); _src--)    \\\\\\
+         if (IS_DIRECTORY_SEPARATOR(*_src))         \\\\\\
+           break;                                   \\\\\\
+       if (_src - _dst)                             \\\\\\
+         while ((*_dst++ = *++_src))                \\\\\\
+           ;                                        \\\\\\
+       (file_name);                                 \\\\\\
+    })                                              \\\\\\
+  )\\
+#else\\
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (file_name)\\
+#endif
+EOF
+
+
+for file in ../libdecnumber/config.in ../opcodes/config.in; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+rm -vf ./file.out ./script.sed
+
+
+
+#
+#  4: Configure and build the libs and programs.
+#
+
+touch start_build.txt
+
+echo
+echo Configuring the progs and libs.
+echo See build_log.txt file for output.
+
+
+echo Using: > build_log.txt
+gcc --version >> build_log.txt
+as --version >> build_log.txt
+echo >> build_log.txt
+ld --version >> build_log.txt
+echo >> build_log.txt
+echo >> build_log.txt
+echo >> build_log.txt
+
+echo Configuring the progs and libs for DJGPP. >> build_log.txt
+echo >> build_log.txt
+
+# Set to yes if you want TUI support.
+# BUILD_WITH_TUI_SUPPORT=yes
+BUILD_WITH_TUI_SUPPORT=no
+if [ "x${BUILD_WITH_TUI_SUPPORT}" = "xyes" ]; then
+# configuring the TUI support version.
+../configure  --disable-dependency-tracking ${NLS_SUPPORT} \
+              --with-mpc --with-mpfr --with-gmp --with-curses --enable-tui \
+              --enable-install-bfd --enable-install-libiberty \
+              --enable-build-warnings=-Wimplicit,-Wcomment,-Wformat,-Wparentheses,-Wpointer-arith >> build_log.txt  2>&1
+else
+# configuring without TUI support.
+../configure  --disable-dependency-tracking ${NLS_SUPPORT} \
+              --with-mpc --with-mpfr --with-gmp --without-curses --disable-tui \
+              --enable-install-bfd --enable-install-libiberty \
+              --enable-build-warnings=-Wimplicit,-Wcomment,-Wformat,-Wparentheses,-Wpointer-arith >> build_log.txt  2>&1
+fi
+echo >> build_log.txt
+echo ################################################################################ >> build_log.txt
+echo >> build_log.txt
+
+
+echo
+echo Building the progs and libs.
+echo See build_log.txt file for output.
+echo Building the progs and libs for DJGPP. >> build_log.txt
+echo >> build_log.txt
+make >> build_log.txt  2>&1
+
+touch stop_build.txt
diff -aprNU5 gdb-7.7.1.orig/gdb/common/common-utils.c gdb-7.7.1/gdb/common/common-utils.c
--- gdb-7.7.1.orig/gdb/common/common-utils.c	2014-01-08 09:23:36 +0100
+++ gdb-7.7.1/gdb/common/common-utils.c	2014-05-10 12:28:08 +0100
@@ -27,10 +27,16 @@
 #include <string.h>
 
 #include <stdlib.h>
 #include <stdio.h>
 
+/* DJGPP 2.03 needs vsnprintf.
+   All required files are stored in /djgpp directory.  */
+#ifdef __DJGPP__
+int vsnprintf(char *str, size_t n, const char *fmt, va_list ap);
+#endif
+
 /* The xmalloc() (libiberty.h) family of memory management routines.
 
    These are like the ISO-C malloc() family except that they implement
    consistent semantics and guard against typical memory management
    problems.  */
diff -aprNU5 gdb-7.7.1.orig/gdb/djgpp/djtypes.h gdb-7.7.1/gdb/djgpp/djtypes.h
--- gdb-7.7.1.orig/gdb/djgpp/djtypes.h	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/gdb/djgpp/djtypes.h	2014-05-10 12:28:08 +0100
@@ -0,0 +1,68 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+#ifndef __DJ_sys_djtypes_h_
+#define __DJ_sys_djtypes_h_
+
+#define __DJ_clock_t	typedef int clock_t;
+#define __DJ_gid_t	typedef int gid_t;
+#define __DJ_off_t	typedef int off_t;
+#define __DJ_off64_t	__extension__ typedef long long off64_t;
+#define __DJ_offset_t	__extension__ typedef long long offset_t;
+#define __DJ_pid_t	typedef int pid_t;
+#define __DJ_size_t	typedef long unsigned int size_t;
+#define __DJ_ssize_t	typedef long signed int ssize_t;
+#define __DJ_time_t	typedef unsigned int time_t;
+#define __DJ_uid_t	typedef int uid_t;
+
+/* For GCC 3.00 or later we use its builtin va_list.                       */
+#if __GNUC__ >= 3
+#define __DJ_va_list    typedef __builtin_va_list va_list;
+#else
+#define __DJ_va_list	typedef void *va_list;
+#endif
+
+#if defined(__cplusplus) && ( (__GNUC_MINOR__ >= 8 && __GNUC__ == 2 ) || __GNUC__ >= 3 )
+/* wchar_t is now a keyword in C++ */
+#define __DJ_wchar_t
+#else
+/* but remains a typedef in C */
+#define __DJ_wchar_t    typedef unsigned short wchar_t;
+#endif
+
+#define __DJ_wint_t     typedef int wint_t;
+
+/* Define internal type to be used for avoiding strict
+   aliasing warnings */
+#if (__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3))
+typedef short __attribute__((__may_alias__))                __dj_short_a;
+typedef int __attribute__((__may_alias__))                  __dj_int_a;
+typedef long __attribute__((__may_alias__))                 __dj_long_a;
+typedef long long __attribute__((__may_alias__))            __dj_long_long_a;
+typedef unsigned short __attribute__((__may_alias__))       __dj_unsigned_short_a;
+typedef unsigned int __attribute__((__may_alias__))         __dj_unsigned_int_a;
+typedef unsigned long __attribute__((__may_alias__))        __dj_unsigned_long_a;
+typedef unsigned long long __attribute__((__may_alias__))   __dj_unsigned_long_long_a;
+typedef float __attribute__((__may_alias__))                __dj_float_a;
+typedef double __attribute__((__may_alias__))               __dj_double_a;
+typedef long double __attribute__((__may_alias__))          __dj_long_double_a;
+#else
+typedef short                __dj_short_a;
+typedef int                  __dj_int_a;
+typedef long                 __dj_long_a;
+typedef long long            __dj_long_long_a;
+typedef unsigned short       __dj_unsigned_short_a;
+typedef unsigned int         __dj_unsigned_int_a;
+typedef unsigned long        __dj_unsigned_long_a;
+typedef unsigned long long   __dj_unsigned_long_long_a;
+typedef float                __dj_float_a;
+typedef double               __dj_double_a;
+typedef long double          __dj_long_double_a;
+#endif
+
+#endif
diff -aprNU5 gdb-7.7.1.orig/gdb/djgpp/dosio.h gdb-7.7.1/gdb/djgpp/dosio.h
--- gdb-7.7.1.orig/gdb/djgpp/dosio.h	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/gdb/djgpp/dosio.h	2014-05-10 12:28:08 +0100
@@ -0,0 +1,56 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#ifndef __dj_include_libc_dosio_h__
+#define __dj_include_libc_dosio_h__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __dj_ENFORCE_ANSI_FREESTANDING
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
+  || !defined(__STRICT_ANSI__) || defined(__cplusplus)
+
+#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+
+#ifndef __STRICT_ANSI__
+
+#ifndef _POSIX_SOURCE
+
+/* set to O_BINARY or O_TEXT */
+extern char *__file_handle_modes;
+extern void __file_handle_set(int fd, int mode);
+
+int __doserr_to_errno(int doserr);
+
+/* puts "path" in the transfer buffer, fixing
+   unix-allowed multi-slashes */
+int _put_path(const char *_path);
+int _put_path2(const char *_path, int _offset);
+
+/* Convenience functions for setting up transfers */
+
+#define __tb_offset 0	/* (__tb & 15) Always paragraph aligned */
+#define __tb_segment (_go32_info_block.linear_address_of_transfer_buffer / 16)
+
+/* Functions used by write and _write.  */
+int _write_fill_seek_gap(int fd);
+int _write_int(int fd, const char *buffer, unsigned long long count);
+
+#endif /* !_POSIX_SOURCE */
+#endif /* !__STRICT_ANSI__ */
+#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
+
+#ifndef __dj_ENFORCE_FUNCTION_CALLS
+#endif /* !__dj_ENFORCE_FUNCTION_CALLS */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __dj_include_libc_dosio_h__ */
diff -aprNU5 gdb-7.7.1.orig/gdb/djgpp/file.h gdb-7.7.1/gdb/djgpp/file.h
--- gdb-7.7.1.orig/gdb/djgpp/file.h	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/gdb/djgpp/file.h	2014-05-10 12:28:08 +0100
@@ -0,0 +1,154 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#ifndef __dj_include_libc_file_h__
+#define __dj_include_libc_file_h__
+
+#include <fcntl.h>
+#include "djgpp/dosio.h"
+#include "djgpp/ttyprvt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __dj_ENFORCE_ANSI_FREESTANDING
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
+  || !defined(__STRICT_ANSI__) || defined(__cplusplus)
+
+#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+
+#ifndef __STRICT_ANSI__
+
+#ifndef _POSIX_SOURCE
+
+#define _IOREAD   000010
+#define _IOWRT    000020
+#define _IOMYBUF  000040
+#define _IOEOF    000100
+#define _IOERR    000200
+#define _IOSTRG   000400
+#define _IORW     001000
+#define _IORMONCL 004000  /* remove on close, for temp files */
+/* if _flag & _IORMONCL, ._name_to_remove needs freeing */
+#define _IOUNGETC 010000  /* there is an ungetc'ed character in the buffer */
+#define _IOTERM   020000  /* file's handle hooked by termios */
+#define _IONTERM  040000  /* file's handle not hooked by termios */
+
+int  _flsbuf(int, FILE*);
+int  _filbuf(FILE *);
+void _fwalk(void (*)(FILE *));
+
+static __inline__ int __getc_raw(FILE *const p)
+{
+  if (p->_cnt > 0)
+  {
+    p->_cnt--;
+    return (unsigned char)*(p->_ptr++);
+  }
+  return _filbuf(p);
+}
+
+static __inline__ int __putc_raw(int const x, FILE *const p)
+{
+  if (p->_cnt > 0)
+  {
+    p->_cnt--;
+    return (unsigned char)(*(p->_ptr++) = (unsigned char)x);
+  }
+  return _flsbuf((unsigned char)x, p);
+}
+
+static __inline__ int __is_text_file(FILE *const p)
+{
+  return !(p->_flag & (_IOSTRG | _IOTERM))
+         && (__file_handle_modes[p->_file] & O_TEXT);
+}
+
+static __inline__ int __getc(FILE *const p)
+{
+  int __c;
+  if (__libc_read_termios_hook
+      && !(p->_flag & (_IOTERM | _IONTERM)))
+  {
+    extern int __isatty(int);
+    /* first time we see this handle--see if termios hooked it */
+    if (!(p->_flag & _IOSTRG) && __isatty(p->_file))
+      p->_flag |= _IOTERM;
+    else
+      p->_flag |= _IONTERM;
+  }
+  __c = __getc_raw(p);
+  if (__c == '\r' && __is_text_file(p))
+    return __getc_raw(p);
+  return __c;
+}
+
+static __inline__ int __putc(const int x, FILE *const p)
+{
+  if (__libc_write_termios_hook
+      && !(p->_flag & (_IOTERM | _IONTERM)))
+  {
+    extern int __isatty(int);
+    /* first time we see this handle--see if termios hooked it */
+    if (!(p->_flag & _IOSTRG) && __isatty(p->_file))
+      p->_flag |= _IOTERM;
+    else
+      p->_flag |= _IONTERM;
+  }
+  if (x == '\n' && __is_text_file(p))
+    __putc_raw('\r', p);
+  return __putc_raw(x, p);
+}
+
+static __inline__ void __stropenw(FILE *p, char *str, int len)
+{
+  p->_flag = _IOWRT | _IOSTRG | _IONTERM;
+  p->_ptr = str;
+  p->_cnt = len;
+}
+
+static __inline__ void __strclosew(FILE *p)
+{
+  *p->_ptr = '\0';
+}
+
+static __inline__ void __stropenr(FILE *p, const char *str)
+{
+  union {
+    char *s;
+    const char *cs;
+  } u;
+
+  u.cs = str;
+  p->_flag = _IOREAD | _IOSTRG | _IONTERM;
+  p->_ptr = p->_base = u.s;
+  p->_cnt = 0;
+  while (*str++)
+    p->_cnt++;
+  p->_bufsiz = p->_cnt;
+}
+
+#undef  fileno
+#define fileno(f)       (f->_file)
+#undef  feof
+#define feof(f)         (((f)->_flag & _IOEOF) != 0)
+#undef  ferror
+#define ferror(f)       (((f)->_flag & _IOERR) != 0)
+
+#endif /* !_POSIX_SOURCE */
+#endif /* !__STRICT_ANSI__ */
+#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
+
+#ifndef __dj_ENFORCE_FUNCTION_CALLS
+#endif /* !__dj_ENFORCE_FUNCTION_CALLS */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __dj_include_libc_file_h__ */
diff -aprNU5 gdb-7.7.1.orig/gdb/djgpp/ttyprvt.h gdb-7.7.1/gdb/djgpp/ttyprvt.h
--- gdb-7.7.1.orig/gdb/djgpp/ttyprvt.h	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/gdb/djgpp/ttyprvt.h	2014-05-10 12:28:08 +0100
@@ -0,0 +1,200 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
+#ifndef __dj_include_libc_ttyprvt_h__
+#define __dj_include_libc_ttyprvt_h__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __dj_ENFORCE_ANSI_FREESTANDING
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
+  || !defined(__STRICT_ANSI__) || defined(__cplusplus)
+
+#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+
+#ifndef __STRICT_ANSI__
+
+#ifndef _POSIX_SOURCE
+
+#include <dpmi.h>
+#include <termios.h>
+#include "djgpp/unistd.h"
+
+#define _TTY_CTRL(x) ((x) & 0x1f)
+#define _TTY_QUEUE_SIZE 2048
+#define _TTY_EDITLINE_SIZE ((_TTY_QUEUE_SIZE) / 2)
+#define _TTY_EDITLINE_CTRL 0
+#define _TTY_EDITLINE_SINGLE 1
+#define _TTY_EDITLINE_INVALID -1
+
+struct tty_queue
+{
+  int size;
+  unsigned char *top;
+  unsigned char *bottom;
+  int count;
+  unsigned char *rpos;
+  unsigned char *wpos;
+};
+
+struct tty
+{
+  struct termios __libc_termios;
+  struct tty_queue __libc_tty_queue;
+  int __libc_tty_status;
+};
+
+struct tty_editline
+{
+  int col;
+  char flag[_TTY_EDITLINE_SIZE];
+  unsigned char buf[_TTY_EDITLINE_SIZE];
+};
+
+/* Information about the screen.  */
+struct tty_screen_info
+{
+  unsigned char init_attrib;
+  unsigned char attrib;
+  int max_row;
+  int max_col;
+  unsigned char active_page;
+  unsigned int norm_blink : 1;
+  unsigned int cur_blink : 1;
+  unsigned short init_cursor_shape;
+  void (*set_cursor)(int col, int row);
+  void (*get_cursor)(int *col, int *row);
+};
+
+
+/* Pointers to functions that manipulate the screen.  */
+
+struct tty_screen_interface
+{
+  /* Initialize the interface, if required.  */
+  void (*init)(void);
+  /* Write a character and update col and row.
+     May or may not update the cursor.  */
+  void (*write_ch)(unsigned char _ch, int *_col, int *_row);
+  /* Write a character and update the cursor.  */
+  void (*putch)(unsigned char _ch);
+  /* Write a character without updating the cursor.  */
+  void (*putch_at)(unsigned char _ch);
+  /* Write out a null-terminated string.  */
+  void (*puts)(const unsigned char *_s);
+  /* Scroll the lines y1 through y2 up to ydst. */
+  void (*scroll_up)(int _y1, int _y2, int _ydst);
+  /* Scroll the lines y1 through y2 down to ydst. */
+  void (*scroll_down)(int _y1, int _y2, int _ydst);
+  /* Scroll the characters between x1 and x2 right to xdst on line y.  */
+  void (*scroll_left)(int _y, int _x1, int _x2, int _xdst);
+  /* Scroll the characters between x1 and x2 left to xdst on line y.  */
+  void (*scroll_right)(int _y, int _x1, int _x2, int _xdst);
+  /* Clear the space between (x1, y1) and (x2, y2).  */
+  void (*clear)(int _x1, int _y1, int _x2, int _y2);
+};
+
+#if !defined (_POSIX_VDISABLE) || (_POSIX_VDISABLE == 0)
+#error _POSIX_VDISABLE is undefine or zero.
+#endif
+
+#define TTYDEFAULT \
+{									\
+  /* struct termios __libc_termios */					\
+  {									\
+    /* c_cc[] */							\
+    {									\
+      (cc_t) 0,               /* pad */ 				\
+      (cc_t) _TTY_CTRL ('d'), /* VEOF */				\
+      (cc_t) _POSIX_VDISABLE, /* VEOL */				\
+      (cc_t) _TTY_CTRL ('h'), /* VERASE */				\
+      (cc_t) _TTY_CTRL ('c'), /* VINTR */				\
+      (cc_t) _TTY_CTRL ('u'), /* VKILL */				\
+      (cc_t) 1,               /* VMIN */				\
+      (cc_t) _TTY_CTRL ('\\'),/* VQUIT */				\
+      (cc_t) _TTY_CTRL ('q'), /* VSTART */				\
+      (cc_t) _TTY_CTRL ('s'), /* VSTOP */				\
+      (cc_t) _TTY_CTRL ('z'), /* VSUSP */				\
+      (cc_t) 0,               /* VTIME */				\
+    },									\
+    (tcflag_t) (CS8|CREAD|CLOCAL), /* c_cflag */			\
+    (tcflag_t) (BRKINT|ICRNL|IMAXBEL), /* c_iflag */			\
+    (tcflag_t) (ISIG|ICANON|ECHO|IEXTEN|ECHOE|ECHOKE|ECHOCTL), /* c_lflag */ \
+    (tcflag_t) (OPOST|ONLCR|ONOEOT), /* c_oflag */			\
+    (speed_t) (B9600), /* c_ispeed */					\
+    (speed_t) (B9600), /* c_ospeed */					\
+  },									\
+  /* struct tty_queue __libc_tty_queue */				\
+  {									\
+    _TTY_QUEUE_SIZE,							\
+    __libc_tty_queue_buffer,						\
+    __libc_tty_queue_buffer + _TTY_QUEUE_SIZE,				\
+    0,									\
+    __libc_tty_queue_buffer,						\
+    __libc_tty_queue_buffer,						\
+  },									\
+  /* __libc_tty_status */						\
+  0,									\
+}
+
+#define t_termios __libc_termios
+#define t_iflag __libc_termios.c_iflag
+#define t_oflag __libc_termios.c_oflag
+#define t_cflag __libc_termios.c_cflag
+#define t_lflag __libc_termios.c_lflag
+#define t_ispeed __libc_termios.c_ispeed
+#define t_ospeed __libc_termios.c_ospeed
+#define t_cc __libc_termios.c_cc
+#define t_status __libc_tty_status
+
+#define t_size __libc_tty_queue.size
+#define t_top __libc_tty_queue.top
+#define t_bottom __libc_tty_queue.bottom
+#define t_count __libc_tty_queue.count
+#define t_rpos __libc_tty_queue.rpos
+#define t_wpos __libc_tty_queue.wpos
+
+#define _TS_LNCH 0x01 /* next character is literal */
+#define _CC_EQU(v,c) (((c) == (unsigned char) __libc_tty_p->t_cc[(v)])	\
+		      && ((c) != (unsigned char) _POSIX_VDISABLE))
+#define _CC_NEQU(v,c) (((c) != (unsigned char)__libc_tty_p->t_cc[(v)])	\
+		       && ((c) != (unsigned char) _POSIX_VDISABLE))
+
+/* internal buffers */
+extern unsigned char __libc_tty_queue_buffer[];
+extern struct tty __libc_tty_internal;
+extern struct tty *__libc_tty_p;
+extern struct tty_editline __libc_tty_editline;
+extern struct tty_screen_interface __tty_direct_intface;
+extern struct tty_screen_interface __tty_vbios_intface;
+extern struct tty_screen_interface *__tty_screen_intface;
+extern struct tty_screen_info __tty_screen;
+
+
+/* termios hooks */
+extern ssize_t (*__libc_read_termios_hook)(int handle, void *buffer, size_t count,
+	   			           ssize_t *rv);
+extern ssize_t (*__libc_write_termios_hook)(int handle, const void *buffer, size_t count,
+					    ssize_t *rv);
+extern int __libc_termios_hook_common_count;
+
+/* functions */
+void __libc_termios_init(void);
+void __libc_termios_init_read(void);
+void __libc_termios_init_write(void);
+extern int __libc_termios_exist_queue (void);
+int __libc_termios_puts_queue (const unsigned char *_str);
+
+#endif /* !_POSIX_SOURCE */
+#endif /* !__STRICT_ANSI__ */
+#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__dj_include_libc_ttyprvt_h__ */
diff -aprNU5 gdb-7.7.1.orig/gdb/djgpp/types.h gdb-7.7.1/gdb/djgpp/types.h
--- gdb-7.7.1.orig/gdb/djgpp/types.h	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/gdb/djgpp/types.h	2014-05-10 12:28:08 +0100
@@ -0,0 +1,101 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#ifndef __dj_include_sys_types_h_
+#define __dj_include_sys_types_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __dj_ENFORCE_ANSI_FREESTANDING
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
+  || !defined(__STRICT_ANSI__) || defined(__cplusplus)
+
+#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+
+#ifndef __STRICT_ANSI__
+
+#include "djgpp/djtypes.h"
+
+typedef int             blkcnt_t;
+typedef int             blksize_t;
+typedef int		dev_t;
+typedef unsigned long	fsblkcnt_t;
+typedef unsigned long	fsfilcnt_t;
+typedef int		ino_t;
+typedef int		mode_t;
+typedef int		nlink_t;
+
+#ifndef _GID_T
+__DJ_gid_t
+#define _GID_T
+#endif
+#ifndef _OFF_T
+__DJ_off_t
+#define _OFF_T
+#endif
+#ifndef _OFF64_T
+__DJ_off64_t
+#define _OFF64_T
+#endif
+#ifndef _OFFSET_T
+__DJ_offset_t
+#define _OFFSET_T
+#endif
+#ifndef _PID_T
+__DJ_pid_t
+#define _PID_T
+#endif
+#ifndef _SIZE_T
+__DJ_size_t
+#define _SIZE_T
+#endif
+#ifndef _SSIZE_T
+__DJ_ssize_t
+#define _SSIZE_T
+#endif
+#ifndef _UID_T
+#define _UID_T
+__DJ_uid_t
+#endif
+
+#ifndef _POSIX_SOURCE
+
+/* Allow including program to override.  */
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 256
+#endif
+
+typedef struct fd_set {
+  unsigned char fd_bits [((FD_SETSIZE) + 7) / 8];
+} fd_set;
+
+#define FD_SET(n, p)    ((p)->fd_bits[(n) / 8] |= (1 << ((n) & 7)))
+#define FD_CLR(n, p)	((p)->fd_bits[(n) / 8] &= ~(1 << ((n) & 7)))
+#define FD_ISSET(n, p)	((p)->fd_bits[(n) / 8] & (1 << ((n) & 7)))
+#define FD_ZERO(p)	memset ((void *)(p), 0, sizeof (*(p)))
+
+#ifndef _TIME_T
+__DJ_time_t
+#define _TIME_T
+#endif
+
+#endif /* !_POSIX_SOURCE */
+#endif /* !__STRICT_ANSI__ */
+#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
+
+#ifndef __dj_ENFORCE_FUNCTION_CALLS
+#endif /* !__dj_ENFORCE_FUNCTION_CALLS */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__dj_include_sys_types_h_ */
diff -aprNU5 gdb-7.7.1.orig/gdb/djgpp/unistd.h gdb-7.7.1/gdb/djgpp/unistd.h
--- gdb-7.7.1.orig/gdb/djgpp/unistd.h	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/gdb/djgpp/unistd.h	2014-05-10 12:28:08 +0100
@@ -0,0 +1,205 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#ifndef __dj_include_unistd_h_
+#define __dj_include_unistd_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __dj_ENFORCE_ANSI_FREESTANDING
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
+  || !defined(__STRICT_ANSI__) || defined(__cplusplus)
+
+#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+
+#ifndef __STRICT_ANSI__
+
+#include "djgpp/types.h" /* NOT POSIX but you can't include just unistd.h without it */
+#include "djgpp/djtypes.h"
+
+#define SEEK_SET	0
+#define SEEK_CUR	1
+#define SEEK_END	2
+
+/* `lockf' is a simpler interface to the locking facilities of `fcntl'.
+   LEN is always relative to the current file position.
+   The CMD argument is one of the following.  */
+
+# define F_ULOCK 0     /* Unlock a previously locked region.  */
+# define F_LOCK  1     /* Lock a region for exclusive use.  */
+# define F_TLOCK 2     /* Test and lock a region for exclusive use.  */
+# define F_TEST  3     /* Test a region for other processes locks.  */
+
+/* Some programs think they know better... */
+#undef NULL
+#if (__GNUC__ >= 4) && defined(__cplusplus)
+#  define NULL          __null
+#elif defined(__cplusplus)
+#  define NULL          0
+#else
+#  define NULL          ((void*)0)
+#endif
+
+#define F_OK	0x01
+#define R_OK	0x02
+#define W_OK	0x04
+#define X_OK	0x08
+
+#define STDIN_FILENO		0
+#define STDOUT_FILENO		1
+#define STDERR_FILENO		2
+
+#define _CS_PATH				1
+#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS		2
+#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS	3
+#define _CS_POSIX_V6_ILP32_OFF32_LIBS		4
+
+#define _PC_CHOWN_RESTRICTED	1
+#define _PC_LINK_MAX		2
+#define _PC_MAX_CANON		3
+#define _PC_MAX_INPUT		4
+#define _PC_NAME_MAX		5
+#define _PC_NO_TRUNC		6
+#define _PC_PATH_MAX		7
+#define _PC_PIPE_BUF		8
+#define _PC_VDISABLE		9
+
+#define _POSIX_CHOWN_RESTRICTED	0
+#undef  _POSIX_JOB_CONTROL
+#define _POSIX_NO_TRUNC		0
+#undef  _POSIX_SAVED_IDS
+#define _POSIX_VDISABLE		-1
+#define _POSIX_VERSION		199009L
+#define _POSIX_V6_ILP32_OFF32	1
+
+#define _SC_ARG_MAX		1
+#define _SC_CHILD_MAX		2
+#define _SC_CLK_TCK		3
+#define _SC_JOB_CONTROL		4
+#define _SC_NGROUPS_MAX		5
+#define _SC_OPEN_MAX		6
+#define _SC_SAVED_IDS		7
+#define _SC_STREAM_MAX		8
+#define _SC_TZNAME_MAX		9
+#define _SC_VERSION		10
+#define _SC_V6_ILP32_OFF32	11
+
+#ifndef _SIZE_T
+__DJ_size_t
+#define _SIZE_T
+#endif
+#ifndef _SSIZE_T
+__DJ_ssize_t
+#define _SSIZE_T
+#endif
+#ifndef _OFFSET_T
+__extension__ typedef long long offset_t;
+#define _OFFSET_T
+#endif
+
+extern char *optarg;
+extern int optind, opterr, optopt;
+
+void		__exit(int _status) __attribute__((noreturn));
+void		_exit(int _status) __attribute__((noreturn));
+int		access(const char *_path, int _amode);
+unsigned int	alarm(unsigned int _seconds);
+int		chdir(const char *_path);
+int		chown(const char *_path, uid_t _owner, gid_t _group);
+int		close(int _fildes);
+size_t		confstr(int _name, char *_buf, size_t _len);
+char *		ctermid(char *_s);
+int		dup(int _fildes);
+int		dup2(int _fildes, int _fildes2);
+int		execl(const char *_path, const char *_arg, ...);
+int		execle(const char *_path, const char *_arg, ...);
+int		execlp(const char *_file, const char *_arg, ...);
+int		execv(const char *_path, char *const _argv[]);
+int		execve(const char *_path, char *const _argv[], char *const _envp[]);
+int		execvp(const char *_file, char *const _argv[]);
+int		fchdir(int _fd);
+pid_t		fork(void);
+long		fpathconf(int _fildes, int _name);
+char *		getcwd(char *_buf, size_t _size);
+gid_t		getegid(void);
+uid_t		geteuid(void);
+gid_t		getgid(void);
+int		getgroups(int _gidsetsize, gid_t *_grouplist);
+char *		getlogin(void);
+int		getopt(int _argc, char *const _argv[], const char *_optstring);
+pid_t		getpgrp(void);
+pid_t		getpid(void);
+pid_t		getppid(void);
+uid_t		getuid(void);
+int		isatty(int _fildes);
+int		link(const char *_existing, const char *_new);
+off_t		lseek(int _fildes, off_t _offset, int _whence);
+long		pathconf(const char *_path, int _name);
+int		pause(void);
+int		pipe(int _fildes[2]);
+ssize_t		pwrite(int _fildes, const void *_buf, size_t _nbyte, off_t _offset);
+ssize_t		read(int _fildes, void *_buf, size_t _nbyte);
+int		rmdir(const char *_path);
+int		setgid(gid_t _gid);
+int		setpgid(pid_t _pid, pid_t _pgid);
+pid_t		setsid(void);
+int		setuid(uid_t uid);
+unsigned int	sleep(unsigned int _seconds);
+long		sysconf(int _name);
+pid_t		tcgetpgrp(int _fildes);
+int		tcsetpgrp(int _fildes, pid_t _pgrp_id);
+char *		ttyname(int _fildes);
+int		unlink(const char *_path);
+ssize_t		write(int _fildes, const void *_buf, size_t _nbyte);
+
+#ifndef _POSIX_SOURCE
+
+/* additional access() checks */
+#define D_OK	0x10
+
+char *		basename(const char *_fn);
+int		brk(void *_heaptop);
+char *		dirname(const char *_fn);
+int		__file_exists(const char *_fn);
+int             fchown(int fd, uid_t owner, gid_t group);
+int		fsync(int _fd);
+int		ftruncate(int, off_t);
+int		getdtablesize(void);
+int		gethostname(char *buf, int size);
+int		getpagesize(void);
+char *		getwd(char *__buffer);
+int             lchown(const char * file, int owner, int group);
+int		lockf(int _fildes, int _cmd, off_t _len);
+int		llockf(int _fildes, int _cmd, offset_t _len);
+offset_t	llseek(int _fildes, offset_t _offset, int _whence);
+int		nice(int _increment);
+int             readlink(const char * __file, char * __buffer, size_t __size);
+void *		sbrk(int _delta);
+int		symlink (const char *, const char *);
+int		sync(void);
+int		truncate(const char*, off_t);
+unsigned int	usleep(unsigned int _useconds);
+#ifndef vfork
+pid_t		vfork(void);
+#endif
+
+#endif /* !_POSIX_SOURCE */
+#endif /* !__STRICT_ANSI__ */
+#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
+
+#ifndef __dj_ENFORCE_FUNCTION_CALLS
+#endif /* !__dj_ENFORCE_FUNCTION_CALLS */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__dj_include_unistd_h_ */
diff -aprNU5 gdb-7.7.1.orig/gdb/djgpp/vsnprntf.c gdb-7.7.1/gdb/djgpp/vsnprntf.c
--- gdb-7.7.1.orig/gdb/djgpp/vsnprntf.c	1970-01-01 01:00:00 +0100
+++ gdb-7.7.1/gdb/djgpp/vsnprntf.c	2014-05-10 12:28:08 +0100
@@ -0,0 +1,41 @@
+/* Copyright (C) 2014 DJ Delorie, see COPYING.DJ for details */
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <errno.h>
+#include "djgpp/file.h"
+
+int vsnprintf(char *str, size_t n, const char *fmt, va_list ap);
+
+int
+vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
+{
+  FILE _strbuf;
+  int len;
+
+  /* _cnt is an int in the FILE structure. To prevent wrap-around, we limit
+   * n to between 0 and INT_MAX inclusively. */
+  if (n > INT_MAX)
+  {
+    errno = EFBIG;
+    return -1;
+  }
+
+  memset(&_strbuf, 0, sizeof(_strbuf));
+
+  /* If n == 0, just querying how much space is needed. */
+  if (n > 0)
+    __stropenw(&_strbuf, str, n - 1);
+  else
+    __stropenw(&_strbuf, NULL, 0);
+
+  len = _doprnt(fmt, ap, &_strbuf);
+
+  /* Ensure nul termination */
+  if (n > 0)
+    __strclosew(&_strbuf);
+
+  return len;
+}
diff -aprNU5 gdb-7.7.1.orig/gdb/gnulib/import/mbrtowc.c gdb-7.7.1/gdb/gnulib/import/mbrtowc.c
--- gdb-7.7.1.orig/gdb/gnulib/import/mbrtowc.c	2013-12-08 04:11:50 +0100
+++ gdb-7.7.1/gdb/gnulib/import/mbrtowc.c	2014-05-10 12:28:08 +0100
@@ -15,10 +15,16 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+#if defined(__DJGPP__) && !defined(EILSEQ)
+# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined(__STRICT_ANSI__)
+#   define EILSEQ   41
+# endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+#endif
+
 /* Specification.  */
 #include <wchar.h>
 
 #if GNULIB_defined_mbstate_t
 /* Implement mbrtowc() on top of mbtowc().  */
diff -aprNU5 gdb-7.7.1.orig/gdb/gnulib/import/mbsrtowcs.c gdb-7.7.1/gdb/gnulib/import/mbsrtowcs.c
--- gdb-7.7.1.orig/gdb/gnulib/import/mbsrtowcs.c	2013-12-08 04:11:50 +0100
+++ gdb-7.7.1/gdb/gnulib/import/mbsrtowcs.c	2014-05-10 12:28:08 +0100
@@ -15,10 +15,16 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+#if defined(__DJGPP__) && !defined(EILSEQ)
+# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined(__STRICT_ANSI__)
+#   define EILSEQ   41
+# endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+#endif
+
 /* Specification.  */
 #include <wchar.h>
 
 #include <errno.h>
 #include <limits.h>
diff -aprNU5 gdb-7.7.1.orig/gdb/remote.c gdb-7.7.1/gdb/remote.c
--- gdb-7.7.1.orig/gdb/remote.c	2014-05-05 21:51:24 +0100
+++ gdb-7.7.1/gdb/remote.c	2014-05-10 12:28:08 +0100
@@ -84,10 +84,16 @@ static long target_buf_size;
 
    The alignment chosen is arbitrary; usually data bus width is
    important here, not the possibly larger cache line size.  */
 enum { REMOTE_ALIGN_WRITES = 16 };
 
+/* DJGPP 2.03 needs vsnprintf.
+   All required files are stored in /djgpp directory.  */
+#ifdef __DJGPP__
+int vsnprintf(char *str, size_t n, const char *fmt, va_list ap);
+#endif
+
 /* Prototypes for local functions.  */
 static void async_cleanup_sigint_signal_handler (void *dummy);
 static int getpkt_sane (char **buf, long *sizeof_buf, int forever);
 static int getpkt_or_notif_sane (char **buf, long *sizeof_buf,
 				 int forever, int *is_notif);
diff -aprNU5 gdb-7.7.1.orig/libiberty/cp-demangle.c gdb-7.7.1/libiberty/cp-demangle.c
--- gdb-7.7.1.orig/libiberty/cp-demangle.c	2014-01-08 09:23:36 +0100
+++ gdb-7.7.1/libiberty/cp-demangle.c	2014-05-10 12:28:08 +0100
@@ -5772,11 +5772,11 @@ d_demangle_callback (const char *mangled
       DCT_GLOBAL_CTORS,
       DCT_GLOBAL_DTORS
     }
   type;
   struct d_info di;
-  struct demangle_component *dc;
+  struct demangle_component *dc = NULL;
   int status;
 
   if (mangled[0] == '_' && mangled[1] == 'Z')
     type = DCT_MANGLED;
   else if (strncmp (mangled, "_GLOBAL_", 8) == 0
diff -aprNU5 gdb-7.7.1.orig/libiberty/make-relative-prefix.c gdb-7.7.1/libiberty/make-relative-prefix.c
--- gdb-7.7.1.orig/libiberty/make-relative-prefix.c	2013-12-08 04:11:52 +0100
+++ gdb-7.7.1/libiberty/make-relative-prefix.c	2014-05-10 12:28:10 +0100
@@ -80,10 +80,11 @@ relative prefix can be found, return @co
 #if defined (_WIN32) || defined (__MSDOS__) \
     || defined (__DJGPP__) || defined (__OS2__)
 #  define HAVE_DOS_BASED_FILE_SYSTEM
 #  define HAVE_HOST_EXECUTABLE_SUFFIX
 #  define HOST_EXECUTABLE_SUFFIX ".exe"
+#  define FILENAME_COMPARE strcasecmp
 #  ifndef DIR_SEPARATOR_2 
 #    define DIR_SEPARATOR_2 '\\'
 #  endif
 #  define PATH_SEPARATOR ';'
 #else
@@ -95,10 +96,13 @@ relative prefix can be found, return @co
 #else
 #  define IS_DIR_SEPARATOR(ch) \
 	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
 #endif
 
+#ifndef FILENAME_COMPARE
+#  define FILENAME_COMPARE strcmp
+#endif
 #define DIR_UP ".."
 
 static char *save_string (const char *, int);
 static char **split_directories	(const char *, int *);
 static void free_split_directories (char **);
@@ -332,11 +336,11 @@ make_relative_prefix_1 (const char *prog
      we can do.  */
   if (prog_num == bin_num)
     {
       for (i = 0; i < bin_num; i++)
 	{
-	  if (strcmp (prog_dirs[i], bin_dirs[i]) != 0)
+	  if (FILENAME_COMPARE (prog_dirs[i], bin_dirs[i]) != 0)
 	    break;
 	}
 
       if (prog_num <= 0 || i == bin_num)
 	goto bailout;
@@ -348,11 +352,11 @@ make_relative_prefix_1 (const char *prog
 
   /* Find how many directories are in common between bin_prefix & prefix.  */
   n = (prefix_num < bin_num) ? prefix_num : bin_num;
   for (common = 0; common < n; common++)
     {
-      if (strcmp (bin_dirs[common], prefix_dirs[common]) != 0)
+      if (FILENAME_COMPARE (bin_dirs[common], prefix_dirs[common]) != 0)
 	break;
     }
 
   /* If there are no common directories, there can be no relative prefix.  */
   if (common == 0)
diff -aprNU5 gdb-7.7.1.orig/libiberty/make-temp-file.c gdb-7.7.1/libiberty/make-temp-file.c
--- gdb-7.7.1.orig/libiberty/make-temp-file.c	2013-12-08 04:11:52 +0100
+++ gdb-7.7.1/libiberty/make-temp-file.c	2014-05-10 12:28:10 +0100
@@ -53,16 +53,31 @@ extern int mkstemps (char *, int);
 /* '/' works just fine on MS-DOS based systems.  */
 #ifndef DIR_SEPARATOR
 #define DIR_SEPARATOR '/'
 #endif
 
+#if defined (_WIN32) || defined (__MSDOS__) \
+    || defined (__DJGPP__) || defined (__OS2__)
+#  define HAVE_DOS_BASED_FILE_SYSTEM
+#  ifndef DIR_SEPARATOR_2 
+#    define DIR_SEPARATOR_2 '\\'
+#  endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+#  define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else
+#  define IS_DIR_SEPARATOR(ch) \
+     (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif
+
 /* Name of temporary file.
    mktemp requires 6 trailing X's.  */
 #define TEMP_FILE "ccXXXXXX"
 #define TEMP_FILE_LEN (sizeof(TEMP_FILE) - 1)
 
-#if !defined(_WIN32) || defined(__CYGWIN__)
+#if !defined(_WIN32) || defined(__CYGWIN__) || defined(__DJGPP__)
 
 /* Subroutine of choose_tmpdir.
    If BASE is non-NULL, return it.
    Otherwise it checks if DIR is a usable directory.
    If success, DIR is returned.
@@ -105,11 +120,11 @@ files in.
 char *
 choose_tmpdir (void)
 {
   if (!memoized_tmpdir)
     {
-#if !defined(_WIN32) || defined(__CYGWIN__)
+#if !defined(_WIN32) || defined(__CYGWIN__) || defined(__DJGPP__)
       const char *base = 0;
       char *tmpdir;
       unsigned int len;
       
 #ifdef VMS
@@ -141,11 +156,12 @@ choose_tmpdir (void)
       /* Append DIR_SEPARATOR to the directory we've chosen
 	 and return it.  */
       len = strlen (base);
       tmpdir = XNEWVEC (char, len + 2);
       strcpy (tmpdir, base);
-      tmpdir[len] = DIR_SEPARATOR;
+      if (len > 0 && !IS_DIR_SEPARATOR(tmpdir[len - 1]))
+        tmpdir[len] = DIR_SEPARATOR;
       tmpdir[len+1] = '\0';
       memoized_tmpdir = tmpdir;
 #else /* defined(_WIN32) && !defined(__CYGWIN__) */
       DWORD len;
 
diff -aprNU5 gdb-7.7.1.orig/libiberty/pex-common.c gdb-7.7.1/libiberty/pex-common.c
--- gdb-7.7.1.orig/libiberty/pex-common.c	2013-12-08 04:11:52 +0100
+++ gdb-7.7.1/libiberty/pex-common.c	2014-05-10 12:28:10 +0100
@@ -115,11 +115,11 @@ temp_file (struct pex_obj *obj, int flag
 
           if (len >= 6
               && strcmp (obj->tempbase + len - 6, "XXXXXX") == 0)
             name = xstrdup (obj->tempbase);
           else
-            name = concat (obj->tempbase, "XXXXXX", NULL);
+            name = concat (obj->tempbase, "XXXXXX", (char *)NULL);
 
           out = mkstemps (name, 0);
           if (out < 0)
             {
               free (name);
@@ -136,11 +136,11 @@ temp_file (struct pex_obj *obj, int flag
   else if ((flags & PEX_SUFFIX) != 0)
     {
       if (obj->tempbase == NULL)
         name = make_temp_file (name);
       else
-        name = concat (obj->tempbase, name, NULL);
+        name = concat (obj->tempbase, name, (char *)NULL);
     }
 
   return name;
 }
 
@@ -220,11 +220,11 @@ pex_run_in_environment (struct pex_obj *
     {
       if (outname == NULL)
 	out = STDOUT_FILE_NO;
       else if ((flags & PEX_SUFFIX) != 0)
 	{
-	  outname = concat (obj->tempbase, outname, NULL);
+	  outname = concat (obj->tempbase, outname, (char *)NULL);
 	  outname_allocated = 1;
 	}
       obj->next_input = -1;
     }
   else if ((obj->flags & PEX_USE_PIPES) == 0)
