[runtime] Introduce kind test functions to cleanup things a bit.
[mono.git] / mono / metadata / debug-mono-ppdb.c
index d0fdddc9dfcb2c7cd91f93c88c57fce5509ec689..8357099a551aa9bec2f6c5dcb147724731e1ee5f 100644 (file)
@@ -7,6 +7,7 @@
  *     Mono Project (http://www.mono-project.com)
  *
  * Copyright 2015 Xamarin Inc (http://www.xamarin.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
@@ -97,7 +98,7 @@ doc_free (gpointer key)
 MonoPPDBFile*
 mono_ppdb_load_file (MonoImage *image, const guint8 *raw_contents, int size)
 {
-       MonoImage *ppdb_image;
+       MonoImage *ppdb_image = NULL;
        const char *filename;
        char *s, *ppdb_filename;
        MonoImageOpenStatus status;
@@ -106,8 +107,12 @@ mono_ppdb_load_file (MonoImage *image, const guint8 *raw_contents, int size)
        gint32 pe_timestamp;
        MonoPPDBFile *ppdb;
 
+       if (!get_pe_debug_guid (image, pe_guid, &pe_age, &pe_timestamp))
+               return NULL;
+
        if (raw_contents) {
-               ppdb_image = mono_image_open_from_data_internal ((char*)raw_contents, size, TRUE, &status, FALSE, TRUE, NULL);
+               if (size > 4 && strncmp ((char*)raw_contents, "BSJB", 4) == 0)
+                       ppdb_image = mono_image_open_from_data_internal ((char*)raw_contents, size, TRUE, &status, FALSE, TRUE, NULL);
        } else {
                /* ppdb files drop the .exe/.dll extension */
                filename = mono_image_get_filename (image);
@@ -132,18 +137,16 @@ mono_ppdb_load_file (MonoImage *image, const guint8 *raw_contents, int size)
         * The same id is stored in the Debug Directory of the PE file, and in the
         * #Pdb stream in the ppdb file.
         */
-       if (get_pe_debug_guid (image, pe_guid, &pe_age, &pe_timestamp)) {
-               PdbStreamHeader *pdb_stream = (PdbStreamHeader*)ppdb_image->heap_pdb.data;
+       PdbStreamHeader *pdb_stream = (PdbStreamHeader*)ppdb_image->heap_pdb.data;
 
-               g_assert (pdb_stream);
+       g_assert (pdb_stream);
 
-               /* The pdb id is a concentation of the pe guid and the timestamp */
-               if (memcmp (pe_guid, pdb_stream->guid, 16) != 0 || memcmp (&pe_timestamp, pdb_stream->guid + 16, 4) != 0) {
-                       g_warning ("Symbol file %s doesn't match image %s", ppdb_image->name,
-                                          image->name);
-                       mono_image_close (ppdb_image);
-                       return NULL;
-               }
+       /* The pdb id is a concentation of the pe guid and the timestamp */
+       if (memcmp (pe_guid, pdb_stream->guid, 16) != 0 || memcmp (&pe_timestamp, pdb_stream->guid + 16, 4) != 0) {
+               g_warning ("Symbol file %s doesn't match image %s", ppdb_image->name,
+                                  image->name);
+               mono_image_close (ppdb_image);
+               return NULL;
        }
 
        ppdb = g_new0 (MonoPPDBFile, 1);