+ 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);
+}
+
+/*
+ * LOCKING: Assumes the debugger lock is held.
+ */
+static MonoDebugSourceInfo*
+get_source_info (MonoSymbolFile *symfile, int index)
+{
+ MonoDebugSourceInfo *info;
+
+ info = g_hash_table_lookup (symfile->source_hash, GUINT_TO_POINTER (index));
+ if (!info) {
+ int offset = read32(&(symfile->offset_table->_source_table_offset)) +
+ (index - 1) * sizeof (MonoSymbolFileSourceEntry);
+ MonoSymbolFileSourceEntry *se = (MonoSymbolFileSourceEntry *)
+ (symfile->raw_contents + offset);
+ const uint8_t *ptr = symfile->raw_contents + read32(&(se->_data_offset));
+
+ info = g_new0 (MonoDebugSourceInfo, 1);
+ info->source_file = read_string (ptr, &ptr);
+ info->guid = g_malloc0 (16);
+ memcpy (info->guid, ptr, 16);
+ ptr += 16;
+ info->hash = g_malloc0 (16);
+ memcpy (info->hash, ptr, 16);
+ ptr += 16;
+ g_hash_table_insert (symfile->source_hash, GUINT_TO_POINTER (index), info);
+ }
+ return info;
+}
+
+static gboolean
+method_has_column_info (MonoDebugMethodInfo *minfo)
+{
+ MonoSymbolFile *symfile;
+ const unsigned char *ptr;
+ guint32 flags;
+
+ if ((symfile = minfo->handle->symfile) == NULL)
+ return FALSE;
+
+ ptr = symfile->raw_contents + minfo->data_offset;
+
+ /* Has to read 'flags' which is preceeded by a bunch of other data */
+ /* compile_unit_index */
+ read_leb128 (ptr, &ptr);
+ /* local variable table offset */
+ read_leb128 (ptr, &ptr);
+ /* namespace id */
+ read_leb128 (ptr, &ptr);
+ /* code block table offset */
+ read_leb128 (ptr, &ptr);
+ /* scope variable table offset */
+ read_leb128 (ptr, &ptr);
+ /* real name offset */
+ read_leb128 (ptr, &ptr);
+
+ flags = read_leb128 (ptr, &ptr);
+ return (flags & 2) > 0;
+}
+
+/*
+ * mono_debug_symfile_get_line_numbers_full:
+ *
+ * On return, SOURCE_FILE_LIST will point to a GPtrArray of MonoDebugSourceFile
+ * structures, and SOURCE_FILES will contain indexes into this array.
+ * The MonoDebugSourceFile structures are owned by this module.
+ */
+void
+mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **source_file, GPtrArray **source_file_list, int *n_il_offsets, int **il_offsets, int **line_numbers, int **column_numbers, int **source_files)
+{
+ // FIXME: Unify this with mono_debug_symfile_lookup_location
+ MonoSymbolFile *symfile;
+ const unsigned char *ptr;
+ StatementMachine stm;
+ uint32_t i;
+ GPtrArray *il_offset_array, *line_number_array, *source_file_array;
+ gboolean has_column_info;
+
+ if (source_file_list)
+ *source_file_list = NULL;
+ if (n_il_offsets)
+ *n_il_offsets = 0;
+ if (source_files)
+ *source_files = NULL;
+ if (source_file)
+ *source_file = NULL;
+ if (column_numbers)
+ *column_numbers = NULL;
+
+ if ((symfile = minfo->handle->symfile) == NULL)
+ return;
+
+ has_column_info = method_has_column_info (minfo);
+
+ il_offset_array = g_ptr_array_new ();
+ line_number_array = g_ptr_array_new ();
+ source_file_array = g_ptr_array_new ();
+
+ stm.line_base = read32 (&symfile->offset_table->_line_number_table_line_base);
+ stm.line_range = read32 (&symfile->offset_table->_line_number_table_line_range);
+ stm.opcode_base = (uint8_t) read32 (&symfile->offset_table->_line_number_table_opcode_base);
+ stm.max_address_incr = (255 - stm.opcode_base) / stm.line_range;
+
+ mono_debugger_lock ();
+
+ ptr = symfile->raw_contents + minfo->lnt_offset;
+
+ stm.symfile = symfile;
+ 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) {
+ uint8_t opcode = *ptr++;
+
+ if (opcode == 0) {
+ uint8_t size = *ptr++;
+ const unsigned char *end_ptr = ptr + size;
+
+ opcode = *ptr++;
+
+ if (opcode == DW_LNE_end_sequence) {
+ if (il_offset_array->len == 0)
+ /* Empty table */
+ break;
+ add_line (&stm, il_offset_array, line_number_array, source_file_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
+ } else {
+ g_warning ("Unknown extended opcode %x in LNT", opcode);
+ }
+
+ ptr = end_ptr;