+
+/*
+ * mono_debug_symfile_lookup_locals:
+ *
+ * Return information about the local variables of MINFO from the symbol file.
+ * Return NULL if no information can be found.
+ * The result should be freed using mono_debug_symfile_free_locals ().
+ */
+MonoDebugLocalsInfo*
+mono_debug_symfile_lookup_locals (MonoDebugMethodInfo *minfo)
+{
+ MonoSymbolFile *symfile = minfo->handle->symfile;
+ const uint8_t *p;
+ int i, len, compile_unit_index, locals_offset, num_locals, block_index;
+ int namespace_id, code_block_table_offset;
+ MonoDebugLocalsInfo *res;
+
+ if (!symfile)
+ return NULL;
+
+ p = symfile->raw_contents + minfo->data_offset;
+
+ compile_unit_index = read_leb128 (p, &p);
+ locals_offset = read_leb128 (p, &p);
+ namespace_id = read_leb128 (p, &p);
+ code_block_table_offset = read_leb128 (p, &p);
+
+ res = g_new0 (MonoDebugLocalsInfo, 1);
+
+ p = symfile->raw_contents + code_block_table_offset;
+ res->num_blocks = read_leb128 (p, &p);
+ res->code_blocks = g_new0 (MonoDebugCodeBlock, res->num_blocks);
+ for (i = 0; i < res->num_blocks; ++i) {
+ res->code_blocks [i].type = read_leb128 (p, &p);
+ res->code_blocks [i].parent = read_leb128 (p, &p);
+ res->code_blocks [i].start_offset = read_leb128 (p, &p);
+ res->code_blocks [i].end_offset = read_leb128 (p, &p);
+ }
+
+ p = symfile->raw_contents + locals_offset;
+ num_locals = read_leb128 (p, &p);
+
+ res->num_locals = num_locals;
+ res->locals = g_new0 (MonoDebugLocalVar, num_locals);
+
+ for (i = 0; i < num_locals; ++i) {
+ res->locals [i].index = read_leb128 (p, &p);
+ len = read_leb128 (p, &p);
+ res->locals [i].name = g_malloc (len + 1);
+ memcpy (res->locals [i].name, p, len);
+ res->locals [i].name [len] = '\0';
+ p += len;
+ block_index = read_leb128 (p, &p);
+ if (block_index >= 1 && block_index <= res->num_blocks)
+ res->locals [i].block = &res->code_blocks [block_index - 1];
+ }
+
+ return res;
+}
+
+/*
+ * mono_debug_symfile_free_locals:
+ *
+ * Free all the data allocated by mono_debug_symfile_lookup_locals ().
+ */
+void
+mono_debug_symfile_free_locals (MonoDebugLocalsInfo *info)
+{
+ int i;
+
+ for (i = 0; i < info->num_locals; ++i)
+ g_free (info->locals [i].name);
+ g_free (info->locals);
+ g_free (info->code_blocks);
+ g_free (info);
+}