Allow use of the --core option with embedded core files
authorDavid Lichteblau <david@lichteblau.com>
Thu, 25 Aug 2011 18:35:34 +0000 (20:35 +0200)
committerDavid Lichteblau <david@lichteblau.com>
Thu, 25 Aug 2011 19:17:10 +0000 (21:17 +0200)
Thanks to Anton Kovalenko for implementation suggestions.

NEWS
src/runtime/coreparse.c
src/runtime/runtime.c

diff --git a/NEWS b/NEWS
index c28c716..453c9c9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 ;;;; -*- coding: utf-8; fill-column: 78 -*-
 changes relative to sbcl-1.0.50:
   * enhancement: ASDF has been updated to version 2.017.
+  * enhancement: the --core command line option now accepts binaries with
+    an embedded core.
   * optimization: SLEEP no longer conses.
   * optimization: *PRINT-PRETTY* no longer slows down printing of strings
     or bit-vectors when using the standard pretty-print dispatch table.
index 1757444..56daffd 100644 (file)
@@ -115,6 +115,16 @@ search_for_embedded_core(char *filename)
 
     if ((fd = open_binary(filename, O_RDONLY)) < 0)
         goto lose;
+
+    if (read(fd, &header, (size_t)lispobj_size) < lispobj_size)
+        goto lose;
+    if (header == CORE_MAGIC) {
+        /* This file is a real core, not an embedded core.  Return 0 to
+         * indicate where the core starts, and do not look for runtime
+         * options in this case. */
+        return 0;
+    }
+
     if (lseek(fd, -lispobj_size, SEEK_END) < 0)
         goto lose;
     if (read(fd, &header, (size_t)lispobj_size) < lispobj_size)
index d1a215b..1396573 100644 (file)
@@ -533,6 +533,19 @@ main(int argc, char *argv[], char *envp[])
         fflush(stdout);
     }
 
+    if (embedded_core_offset == 0) {
+        /* Here we make a last attempt at recognizing an embedded core,
+         * so that a file with an embedded core is a valid argument to
+         * --core.  We take care that any decisions on special behaviour
+         * (suppressed banner, embedded options) have already been made
+         * before we reach this block, so that there is no observable
+         * difference between "embedded" and "bare" images given to
+         * --core. */
+        os_vm_offset_t offset = search_for_embedded_core(core);
+        if (offset != -1)
+            embedded_core_offset = offset;
+    }
+
 #if defined(SVR4) || defined(__linux__) || defined(__NetBSD__)
     tzset();
 #endif