2010-05-26 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / metadata / debug-mono-symfile.c
index 3ae35ac68d77308f0cc56f5e54756447995ccae6..be3a4ce682973ff282b2a8fba58d61c1c4de416e 100644 (file)
@@ -123,10 +123,11 @@ mono_debug_open_mono_symbols (MonoDebugHandle *handle, const guint8 *raw_content
                symfile->raw_contents = p = g_malloc (size);
                memcpy (p, raw_contents, size);
                symfile->filename = g_strdup_printf ("LoadedFromMemory");
+               symfile->was_loaded_from_memory = TRUE;
        } else {
                MonoFileMap *f;
                symfile->filename = g_strdup_printf ("%s.mdb", mono_image_get_filename (handle->image));
-
+               symfile->was_loaded_from_memory = FALSE;
                if ((f = mono_file_map_open (symfile->filename))) {
                        symfile->raw_contents_size = mono_file_map_size (f);
                        if (symfile->raw_contents_size == 0) {
@@ -164,8 +165,12 @@ mono_debug_close_mono_symbol_file (MonoSymbolFile *symfile)
        if (symfile->method_hash)
                g_hash_table_destroy (symfile->method_hash);
 
-       if (symfile->raw_contents)
-               mono_file_unmap ((gpointer) symfile->raw_contents, symfile->raw_contents_handle);
+       if (symfile->raw_contents) {
+               if (symfile->was_loaded_from_memory)
+                       g_free ((gpointer)symfile->raw_contents);
+               else
+                       mono_file_unmap ((gpointer) symfile->raw_contents, symfile->raw_contents_handle);
+       }
 
        if (symfile->filename)
                g_free (symfile->filename);
@@ -205,7 +210,9 @@ typedef struct {
        int line_base, line_range, max_address_incr;
        guint8 opcode_base;
        guint32 last_line, last_file, last_offset;
+       guint32 first_file;
        int line, file, offset;
+       gboolean is_hidden;
 } StatementMachine;
 
 static gboolean
@@ -292,8 +299,10 @@ mono_debug_symfile_lookup_location (MonoDebugMethodInfo *minfo, guint32 offset)
        stm.offset = stm.last_offset = 0;
        stm.last_file = 0;
        stm.last_line = 0;
+       stm.first_file = 0;
        stm.file = 1;
        stm.line = 1;
+       stm.is_hidden = FALSE;
 
        while (TRUE) {
                guint8 opcode = *ptr++;
@@ -309,7 +318,7 @@ mono_debug_symfile_lookup_location (MonoDebugMethodInfo *minfo, guint32 offset)
                                        goto out_success;
                                break;
                        } else if (opcode == DW_LNE_MONO_negate_is_hidden) {
-                               ;
+                               stm.is_hidden = !stm.is_hidden;
                        } else if ((opcode >= DW_LNE_MONO__extensions_start) &&
                                   (opcode <= DW_LNE_MONO__extensions_end)) {
                                ; // reserved for future extensions
@@ -368,6 +377,22 @@ add_line (StatementMachine *stm, GPtrArray *il_offset_array, GPtrArray *line_num
                g_ptr_array_add (il_offset_array, GUINT_TO_POINTER (stm->offset));
                g_ptr_array_add (line_number_array, GUINT_TO_POINTER (stm->line));
        }
+
+       if (!stm->is_hidden && !stm->first_file)
+               stm->first_file = stm->file;
+}
+
+/*
+ * mono_debug_symfile_free_location:
+ *
+ *   Free a MonoDebugSourceLocation returned by
+ *   mono_debug_symfile_lookup_location
+ */
+void
+mono_debug_symfile_free_location   (MonoDebugSourceLocation  *location)
+{
+       g_free (location->source_file);
+       g_free (location);
 }
 
 /*
@@ -409,8 +434,10 @@ mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_f
        stm.offset = stm.last_offset = 0;
        stm.last_file = 0;
        stm.last_line = 0;
+       stm.first_file = 0;
        stm.file = 1;
        stm.line = 1;
+       stm.is_hidden = FALSE;
 
        while (TRUE) {
                guint8 opcode = *ptr++;
@@ -425,7 +452,7 @@ mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_f
                                add_line (&stm, il_offset_array, line_number_array);
                                break;
                        } else if (opcode == DW_LNE_MONO_negate_is_hidden) {
-                               ;
+                               stm.is_hidden = !stm.is_hidden;
                        } else if ((opcode >= DW_LNE_MONO__extensions_start) &&
                                   (opcode <= DW_LNE_MONO__extensions_end)) {
                                ; // reserved for future extensions
@@ -466,6 +493,9 @@ mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_f
                }
        }
 
+       if (!stm.file && stm.first_file)
+               stm.file = stm.first_file;
+
        if (stm.file) {
                int offset = read32(&(stm.symfile->offset_table->_source_table_offset)) +
                        (stm.file - 1) * sizeof (MonoSymbolFileSourceEntry);