--- ./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	2024-03-14 04:50:40.599449391 +0000
+++ ./bfd/coffgen.c	2024-03-14 04:53:17.885692778 +0000
@@ -3265,8 +3265,7 @@
   struct coff_tdata *tdata;
 
   if (bfd_family_coff (abfd)
-      && (bfd_get_format (abfd) == bfd_object
-	  || bfd_get_format (abfd) == bfd_core)
+      && (bfd_get_format (abfd) == bfd_object)
       && (tdata = coff_data (abfd)) != NULL)
     {
       if (tdata->section_by_index)
@@ -3297,6 +3296,9 @@
       if (!_bfd_coff_free_symbols (abfd))
 	return false;
     }
+   if (bfd_family_coff (abfd)
+       && (tdata = coff_data (abfd)) != NULL)
+	_bfd_stab_cleanup (abfd, &tdata->line_info);
 
   return _bfd_generic_bfd_free_cached_info (abfd);
 }
