--- ./gdb/gcore.c_orig	2023-06-05 06:01:01.068327555 +0000
+++ ./gdb/gcore.c	2023-06-19 05:15:39.855804175 +0000
@@ -38,6 +38,10 @@
 #include "gdbsupport/gdb_unlinker.h"
 #include "gdbsupport/byte-vector.h"
 #include "gdbsupport/scope-exit.h"
+#include <core.h>
+#include <pthread.h>
+#include <sys/stat.h>
+#include <libgen.h>
 
 /* The largest amount of memory to read from the target at once.  We
    must throttle it to limit the amount of memory used by GDB during
@@ -48,6 +52,28 @@
 static enum bfd_architecture default_gcore_arch (void);
 static int gcore_memory_sections (bfd *);
 
+struct gencore_args {
+    const char *name;
+    pid_t pid; 
+};
+extern void step_1_ext (int, int, char *);
+
+int gencore_done = 0;
+void issue_gencore_aix (struct gencore_args *args)
+{
+    struct coredumpinfo dumpinfo;
+    int rc = 0;
+
+    dumpinfo.length = strlen(args->name);
+    dumpinfo.name = args->name;
+    dumpinfo.flags = GENCORE_VERSION_1;
+    dumpinfo.pid = args->pid;
+    rc = gencore(&dumpinfo);
+    if (rc != 0)
+      gdb_printf (gdb_stdout, "gencore failed\n");
+    gencore_done = 1;
+}
+
 /* create_gcore_bfd -- helper for gcore_command (exported).
    Open a new bfd core file for output, and return the handle.  */
 
@@ -126,6 +152,12 @@
 gcore_command (const char *args, int from_tty)
 {
   gdb::unique_xmalloc_ptr<char> corefilename;
+  pthread_t gcore_t;
+  struct gencore_args g_args;
+  int rc = 0;
+  time64_t last_mod = 0;
+  char *dir;
+  struct stat64 st;
 
   /* No use generating a corefile without a target process.  */
   if (!target_has_execution ())
@@ -143,21 +175,54 @@
     gdb_printf ("Opening corefile '%s' for output.\n",
 		corefilename.get ());
 
+    g_args.name = corefilename.get();
+    g_args.pid = current_inferior ()->pid;
+
+    if (!access (corefilename.get(), W_OK)) {
+        if (!stat (corefilename.get(), &st))
+           last_mod = st.st_mtime;
+    }
+    dir = dirname (corefilename.get());
+    /* Check if directory has the write permission. */
+    if (dir && !access (dir, W_OK)) {
+      rc = pthread_create(&gcore_t, NULL, &issue_gencore_aix, &g_args);
+      if (!rc) {
+        if (gencore_done)
+          step_1_ext (0, 1, "1");
+        else {
+          usleep(1000);
+          step_1_ext (0, 1, "1");
+        }
+        if (!access (corefilename.get(), R_OK) && last_mod)  {
+           stat(corefilename.get(), &st);
+           if (st.st_mtime > last_mod)
+             gdb_printf (gdb_stdout,
+                             "Saved corefile '%s' \n", corefilename.get());
+           else
+             gdb_printf (gdb_stdout,
+                             "Unable to generate core\n");
+        }
+      }
+    } else {
+       gdb_printf (gdb_stdout,
+                      "Can't open :%s for writing \n", corefilename.get());
+    }
+
   if (target_supports_dumpcore ())
     target_dumpcore (corefilename.get ());
   else
     {
       /* Open the output file.  */
-      gdb_bfd_ref_ptr obfd (create_gcore_bfd (corefilename.get ()));
+      //gdb_bfd_ref_ptr obfd (create_gcore_bfd (corefilename.get ()));
 
       /* Arrange to unlink the file on failure.  */
-      gdb::unlinker unlink_file (corefilename.get ());
+      //gdb::unlinker unlink_file (corefilename.get ());
 
       /* Call worker function.  */
-      write_gcore_file (obfd.get ());
+      //write_gcore_file (obfd.get ());
 
       /* Succeeded.  */
-      unlink_file.keep ();
+      //unlink_file.keep ();
     }
 
   gdb_printf ("Saved corefile %s\n", corefilename.get ());
--- ./gdb/infcmd.c_orig	2023-06-05 05:59:06.261482993 +0000
+++ ./gdb/infcmd.c	2023-06-15 05:36:19.258280165 +0000
@@ -760,6 +760,13 @@
   tp->control.step_start_function = find_pc_function (pc);
 }
 
+/* AIX gcore.  */
+void step_1_ext (int skip, int inst, char *string)
+{
+    step_1 (skip, inst, string);
+}
+
+
 /* Step until outside of current statement.  */
 
 static void
--- ./bfd/coffgen.c_orig	2023-06-19 08:44:01.474261168 +0000
+++ ./bfd/coffgen.c	2023-06-19 08:45:21.888544778 +0000
@@ -3156,12 +3156,14 @@
 	  && !_bfd_coff_free_symbols (abfd))
 	return false;
 
-      if (bfd_get_format (abfd) == bfd_object
-	  || bfd_get_format (abfd) == bfd_core)
+      if (bfd_get_format (abfd) == bfd_object)
 	{
 	  _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
 	  _bfd_stab_cleanup (abfd, &tdata->line_info);
 	}
+      /* Tentative Fix for Aix gcore.  */
+      if (bfd_get_format (abfd) == bfd_core)
+	_bfd_stab_cleanup (abfd, &tdata->line_info);
     }
   return _bfd_generic_close_and_cleanup (abfd);
 }
