--- ./gdb/configure_orig	2017-10-10 03:49:09 -0500
+++ ./gdb/configure	2017-10-10 03:52:30 -0500
@@ -14672,6 +14672,7 @@
 _ACEOF
 
       fi
+      LIBS="$LIBS -lpthread"
       ;;
    esac
 
--- ./gdb/configure.ac_orig	2017-10-10 03:50:03 -0500
+++ ./gdb/configure.ac	2017-10-10 03:50:40 -0500
@@ -1782,6 +1782,7 @@
          # with AIX 6.x).
          AC_CHECK_DECLS(getthrds, [], [], [[#include <procinfo.h>]])
       fi
+      LIBS="$LIBS -lpthread"
       ;;
    esac
    AC_SUBST(CONFIG_LDFLAGS)
--- ./gdb/gcore.h_orig	2017-10-10 04:00:25 -0500
+++ ./gdb/gcore.h	2017-10-10 06:25:58 -0500
@@ -22,6 +22,18 @@
 
 #include "gdb_bfd.h"
 
+#if (GDB_OSABI_DEFAULT == GDB_OSABI_AIX)
+#include <core.h>
+#include <pthread.h>
+#include <sys/stat.h>
+#include <libgen.h>
+struct aix_gencore_args {
+    char *name;
+    pid_t pid; 
+};
+extern void step_1_ext (int, int, char *);
+#endif
+
 extern gdb_bfd_ref_ptr create_gcore_bfd (const char *filename);
 extern void write_gcore_file (bfd *obfd);
 extern bfd *load_corefile (char *filename, int from_tty);
--- ./gdb/gcore.c_orig	2017-10-10 04:27:47 -0500
+++ ./gdb/gcore.c	2017-10-12 08:01:45 -0500
@@ -137,6 +137,22 @@
     throw_exception (except);
 }
 
+/* AIX gcore helper function */
+void * issue_gencore_aix (void *args)
+{
+    struct coredumpinfo dumpinfo;
+    int rc = 0;
+
+    dumpinfo.length = strlen(((struct aix_gencore_args *)args)->name);
+    dumpinfo.name = ((struct aix_gencore_args *)args)->name;
+    dumpinfo.flags = GENCORE_VERSION_1;
+    dumpinfo.pid = ((struct aix_gencore_args *)args)->pid;
+    rc = gencore(&dumpinfo);
+    if (rc != 0)
+       fprintf_filtered (gdb_stdout, "gencore failed\n");
+    return NULL;
+}
+
 /* gcore_command -- implements the 'gcore' command.
    Generate a core file from the inferior process.  */
 
@@ -145,6 +161,15 @@
 {
   gdb::unique_xmalloc_ptr<char> corefilename;
 
+  #if (GDB_OSABI_DEFAULT == GDB_OSABI_AIX)
+  pthread_t gcore_t;
+  struct aix_gencore_args g_args;
+  int rc = 0;
+  time64_t last_mod = 0;
+  char *dir, *aix_core;
+  struct stat64 st;
+  #endif
+
   /* No use generating a corefile without a target process.  */
   if (!target_has_execution)
     noprocess ();
@@ -162,6 +187,49 @@
 		      "Opening corefile '%s' for output.\n",
 		      corefilename.get ());
 
+   #if (GDB_OSABI_DEFAULT == GDB_OSABI_AIX)
+   aix_core = corefilename.get ();
+   g_args.name = aix_core;
+   g_args.pid = ptid_get_pid (inferior_ptid);
+
+   memset (&st, 0, sizeof(st)); 
+   if (!access (aix_core, W_OK)) {
+       if (!stat (aix_core, &st))
+           last_mod = st.st_mtime;
+   }
+   dir = dirname (aix_core);
+   /* Check if directory has the write permission. */
+   if (dir && !access (dir, W_OK) && !S_ISDIR(st.st_mode)) {
+       rc = pthread_create(&gcore_t, NULL, issue_gencore_aix, &g_args);
+       if (!rc) {
+           step_1_ext (0, 1, "1");
+           if (!access (aix_core, R_OK) && !last_mod)
+               fprintf_filtered (gdb_stdout,
+                           "Saved corefile '%s' \n", aix_core);
+           else if (!access (aix_core, R_OK) && last_mod)  {
+               stat(aix_core, &st);
+               if (st.st_mtime >= last_mod)
+                   fprintf_filtered (gdb_stdout,
+                              "Saved corefile '%s' \n", aix_core);
+               else
+                   fprintf_filtered (gdb_stdout,
+                              "Unable to generate core\n");
+           }
+           else
+           /* Their can be a slight delay in scheduling gencore call after gdb's
+              single step for an multi-threaded programs, and above checks might
+              fail. But eventually we will be having a core file generated from
+              the gencore. So display informative message that core will be 
+              created. */
+           fprintf_filtered (gdb_stdout,
+                          "corefile might be saved as '%s' \n", aix_core); 
+       }
+   }
+   else
+       fprintf_filtered (gdb_stdout,
+                       "Can't open :%s for writing \n", aix_core);
+  #else
+
   /* Open the output file.  */
   gdb_bfd_ref_ptr obfd (create_gcore_bfd (corefilename.get ()));
 
@@ -175,6 +243,7 @@
   unlink_file.keep ();
 
   fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename.get ());
+  #endif
 }
 
 static unsigned long
--- ./gdb/infcmd.c_orig	2017-10-10 04:06:30 -0500
+++ ./gdb/infcmd.c	2017-10-10 04:07:02 -0500
@@ -136,6 +136,11 @@
 
 int startup_with_shell = 1;
 
+void step_1_ext (int skip, int inst, char *string)
+{
+    step_1 (skip, inst, string);
+}
+
 
 /* Accessor routines.  */
 
--- ./include/libiberty.h_orig	2017-10-10 06:15:51 -0500
+++ ./include/libiberty.h	2017-10-10 06:49:24 -0500
@@ -105,6 +105,7 @@
    to find the declaration so provide a fully prototyped one.  If it
    is 1, we found it so don't provide any declaration at all.  */
 #if !HAVE_DECL_BASENAME
+#ifndef _AIX
 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) \
  || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) \
  || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) \
@@ -117,6 +118,7 @@
 #define basename basename_cannot_be_used_without_a_prototype
 #endif
 #endif
+#endif
 
 /* A well-defined basename () that is always compiled in.  */
 
