class DebugInfo {
public int max_il_offset;
- public string filename;
public int[] il_offsets;
public int[] line_numbers;
+ public string[] source_files;
}
struct FrameInfo {
* with newer runtimes, and vice versa.
*/
internal const int MAJOR_VERSION = 2;
- internal const int MINOR_VERSION = 12;
+ internal const int MINOR_VERSION = 13;
enum WPSuspendPolicy {
NONE = 0,
DebugInfo info = new DebugInfo ();
info.max_il_offset = res.ReadInt ();
- info.filename = res.ReadString ();
+
+ string[] filenames = null;
+ if (Version.AtLeast (2, 12)) {
+ int n = res.ReadInt ();
+ filenames = new string [n];
+ for (int i = 0; i < n; ++i)
+ filenames [i] = res.ReadString ();
+ } else {
+ filenames = new string [1];
+ filenames [0] = res.ReadString ();
+ }
int n_il_offsets = res.ReadInt ();
info.il_offsets = new int [n_il_offsets];
info.line_numbers = new int [n_il_offsets];
+ info.source_files = new string [n_il_offsets];
for (int i = 0; i < n_il_offsets; ++i) {
info.il_offsets [i] = res.ReadInt ();
info.line_numbers [i] = res.ReadInt ();
+ if (Version.AtLeast (2, 12)) {
+ int idx = res.ReadInt ();
+ info.source_files [i] = idx >= 0 ? filenames [idx] : null;
+ } else {
+ info.source_files [i] = filenames [0];
+ }
}
return info;
get {
if (debug_info == null)
debug_info = vm.conn.Method_GetDebugInfo (id);
- return debug_info.filename;
+ return debug_info.source_files.Length > 0 ? debug_info.source_files [0] : null;
}
}
var line_numbers = LineNumbers;
IList<Location> res = new Location [ILOffsets.Count];
for (int i = 0; i < il_offsets.Count; ++i)
- res [i] = new Location (vm, this, -1, il_offsets [i], SourceFile, line_numbers [i], 0);
+ res [i] = new Location (vm, this, -1, il_offsets [i], debug_info.source_files [i], line_numbers [i], 0);
locations = res;
}
return locations;
}
}
- internal int il_offset_to_line_number (int il_offset) {
+ internal int il_offset_to_line_number (int il_offset, out string src_file) {
if (debug_info == null)
debug_info = vm.conn.Method_GetDebugInfo (id);
// FIXME: Optimize this
+ src_file = null;
for (int i = debug_info.il_offsets.Length - 1; i >= 0; --i) {
- if (debug_info.il_offsets [i] <= il_offset)
+ if (debug_info.il_offsets [i] <= il_offset) {
+ src_file = debug_info.source_files [i];
return debug_info.line_numbers [i];
+ }
}
return -1;
}
get {
if (location == null) {
int line_number;
+ string src_file = null;
if (il_offset == -1)
line_number = -1;
else
- line_number = method.il_offset_to_line_number (il_offset);
+ line_number = method.il_offset_to_line_number (il_offset, out src_file);
- location = new Location (vm, Method, 0, il_offset, method.SourceFile, line_number, 0);
+ location = new Location (vm, Method, 0, il_offset, src_file != null ? src_file : method.SourceFile, line_number, 0);
}
return location;
}
[MethodImplAttribute (MethodImplOptions.NoInlining)]
public static void ln3 () {
+#pragma warning disable 0219
+ int i = 5;
+#pragma warning restore 0219
+ #line 55 "FOO"
}
}
}
[Test]
+ [Category("only88")]
public void LineNumbers () {
Event e = run_until ("line_numbers");
Assert.IsTrue (e is StepEvent);
l = e.Thread.GetFrames ()[0].Location;
Assert.AreEqual ("ln3", l.Method.Name);
- Assert.AreEqual (line_base + 10, l.LineNumber);
+ Assert.AreEqual (line_base + 11, l.LineNumber);
+
+ vm.Resume ();
+ e = GetNextEvent ();
+ Assert.IsTrue (e is StepEvent);
+ l = e.Thread.GetFrames ()[0].Location;
+ Assert.AreEqual ("ln3", l.Method.Name);
+ Assert.IsTrue (l.SourceFile.EndsWith ("FOO"));
+ Assert.AreEqual (55, l.LineNumber);
vm.Resume ();
e = GetNextEvent ();
// GetSourceFiles ()
string[] sources = l.Method.DeclaringType.GetSourceFiles ();
- Assert.AreEqual (1, sources.Length);
+ Assert.AreEqual (2, sources.Length);
Assert.AreEqual ("dtest-app.cs", sources [0]);
+ Assert.AreEqual ("FOO", sources [1]);
sources = l.Method.DeclaringType.GetSourceFiles (true);
- Assert.AreEqual (1, sources.Length);
+ Assert.AreEqual (2, sources.Length);
Assert.IsTrue (sources [0].EndsWith ("dtest-app.cs"));
+ Assert.IsTrue (sources [1].EndsWith ("FOO"));
}
[Test]
}
[Test]
+ [Category ("only88")]
public void TypeLoadSourceFileFilter () {
Event e = run_until ("type_load");
}
static void
-add_line (StatementMachine *stm, GPtrArray *il_offset_array, GPtrArray *line_number_array)
+add_line (StatementMachine *stm, GPtrArray *il_offset_array, GPtrArray *line_number_array, GPtrArray *source_file_array)
{
if (stm->line > 0) {
g_ptr_array_add (il_offset_array, GUINT_TO_POINTER (stm->offset));
g_ptr_array_add (line_number_array, GUINT_TO_POINTER (stm->line));
+ g_ptr_array_add (source_file_array, GUINT_TO_POINTER (stm->file));
}
if (!stm->is_hidden && !stm->first_file)
}
/*
- * mono_debug_symfile_get_line_numbers:
+ * mono_debug_symfile_get_line_numbers_full:
*
- * All the output parameters can be NULL.
- */
+ * On return, SOURCE_FILE_LIST will point to a GPtrArray of malloc-ed strings, and
+ * SOURCE_FILES will contain indexes into this array.
+ */
void
-mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_file, int *n_il_offsets, int **il_offsets, int **line_numbers)
+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 **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;
+ GPtrArray *il_offset_array, *line_number_array, *source_file_array;
- if (source_file)
- *source_file = NULL;
+ 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 ((symfile = minfo->handle->symfile) == NULL)
return;
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);
if (il_offset_array->len == 0)
/* Empty table */
break;
- add_line (&stm, il_offset_array, line_number_array);
+ 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 < stm.opcode_base) {
switch (opcode) {
case DW_LNS_copy:
- add_line (&stm, il_offset_array, line_number_array);
+ add_line (&stm, il_offset_array, line_number_array, source_file_array);
break;
case DW_LNS_advance_pc:
stm.offset += read_leb128 (ptr, &ptr);
stm.offset += opcode / stm.line_range;
stm.line += stm.line_base + (opcode % stm.line_range);
- add_line (&stm, il_offset_array, line_number_array);
+ add_line (&stm, il_offset_array, line_number_array, source_file_array);
}
}
if (!stm.file && stm.first_file)
stm.file = stm.first_file;
- if (stm.file) {
+ if (stm.file && source_file) {
int offset = read32(&(stm.symfile->offset_table->_source_table_offset)) +
(stm.file - 1) * sizeof (MonoSymbolFileSourceEntry);
MonoSymbolFileSourceEntry *se = (MonoSymbolFileSourceEntry *)
*source_file = read_string (stm.symfile->raw_contents + read32(&(se->_data_offset)));
}
+ if (source_file_list) {
+ int file, last_file = 0;
+ char *s;
+
+ *source_file_list = g_ptr_array_new ();
+ if (source_files)
+ *source_files = g_malloc (il_offset_array->len * sizeof (int));
+
+ for (i = 0; i < il_offset_array->len; ++i) {
+ file = GPOINTER_TO_UINT (g_ptr_array_index (source_file_array, i));
+ if (file && file != last_file) {
+ int offset = read32(&(stm.symfile->offset_table->_source_table_offset)) +
+ (file - 1) * sizeof (MonoSymbolFileSourceEntry);
+ MonoSymbolFileSourceEntry *se = (MonoSymbolFileSourceEntry *)
+ (stm.symfile->raw_contents + offset);
+
+ s = read_string (stm.symfile->raw_contents + read32(&(se->_data_offset)));
+ g_ptr_array_add (*source_file_list, s);
+ }
+ last_file = file;
+ if (source_files)
+ (*source_files) [i] = (*source_file_list)->len - 1;
+ }
+ if ((*source_file_list)->len == 0 && stm.file) {
+ int offset = read32(&(stm.symfile->offset_table->_source_table_offset)) +
+ (stm.file - 1) * sizeof (MonoSymbolFileSourceEntry);
+ MonoSymbolFileSourceEntry *se = (MonoSymbolFileSourceEntry *)
+ (stm.symfile->raw_contents + offset);
+
+ s = read_string (stm.symfile->raw_contents + read32(&(se->_data_offset)));
+ g_ptr_array_add (*source_file_list, s);
+ }
+ }
+
if (n_il_offsets)
*n_il_offsets = il_offset_array->len;
if (il_offsets && line_numbers) {
return;
}
+/*
+ * mono_debug_symfile_get_line_numbers:
+ *
+ * All the output parameters can be NULL.
+ */
+void
+mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_file, int *n_il_offsets, int **il_offsets, int **line_numbers)
+{
+ mono_debug_symfile_get_line_numbers_full (minfo, source_file, NULL, n_il_offsets, il_offsets, line_numbers, NULL);
+}
+
int32_t
_mono_debug_address_from_il_offset (MonoDebugMethodJitInfo *jit, uint32_t il_offset)
{
#ifndef __MONO_DEBUG_MONO_SYMFILE_H__
#define __MONO_DEBUG_MONO_SYMFILE_H__
+#include <glib.h>
#include <mono/metadata/class.h>
#include <mono/metadata/reflection.h>
#include <mono/metadata/mono-debug.h>
void
mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_file, int *n_il_offsets, int **il_offsets, int **line_numbers);
+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 **source_files);
+
MONO_END_DECLS
#endif /* __MONO_SYMFILE_H__ */
#define HEADER_LENGTH 11
#define MAJOR_VERSION 2
-#define MINOR_VERSION 12
+#define MINOR_VERSION 13
typedef enum {
CMD_SET_VM = 1,
MonoMethod *method;
char *source_file, *s;
gboolean found = FALSE;
+ int i;
+ GPtrArray *source_file_list;
while ((method = mono_class_get_methods (ei->klass, &iter))) {
MonoDebugMethodInfo *minfo = mono_debug_lookup_method (method);
if (minfo) {
- mono_debug_symfile_get_line_numbers (minfo, &source_file, NULL, NULL, NULL);
- if (!source_file)
- continue;
- // FIXME: flags
- /*
- * Do a case-insesitive match by converting the file name to
- * lowercase.
- */
- s = strdup_tolower (source_file);
- if (g_hash_table_lookup (mod->data.source_files, s))
- found = TRUE;
- g_free (s);
- g_free (source_file);
+ mono_debug_symfile_get_line_numbers_full (minfo, &source_file, &source_file_list, NULL, NULL, NULL, NULL);
+ for (i = 0; i < source_file_list->len; ++i) {
+ source_file = g_ptr_array_index (source_file_list, i);
+ /*
+ * Do a case-insesitive match by converting the file name to
+ * lowercase.
+ */
+ s = strdup_tolower (source_file);
+ if (g_hash_table_lookup (mod->data.source_files, s))
+ found = TRUE;
+ g_free (s);
+ g_free (source_file);
+ }
+ g_ptr_array_free (source_file_list, TRUE);
}
}
if (!found)
MonoMethod *method;
char *source_file;
GPtrArray *files;
- int i;
+ int i, j;
files = g_ptr_array_new ();
while ((method = mono_class_get_methods (klass, &iter))) {
MonoDebugMethodInfo *minfo = mono_debug_lookup_method (method);
+ GPtrArray *source_file_list;
if (minfo) {
- mono_debug_symfile_get_line_numbers (minfo, &source_file, NULL, NULL, NULL);
- if (!source_file)
- continue;
-
- for (i = 0; i < files->len; ++i)
- if (!strcmp (g_ptr_array_index (files, i), source_file))
- break;
- if (i == files->len)
- g_ptr_array_add (files, g_strdup (source_file));
- g_free (source_file);
+ mono_debug_symfile_get_line_numbers_full (minfo, NULL, &source_file_list, NULL, NULL, NULL, NULL);
+ for (j = 0; j < source_file_list->len; ++j) {
+ source_file = g_ptr_array_index (source_file_list, j);
+ for (i = 0; i < files->len; ++i)
+ if (!strcmp (g_ptr_array_index (files, i), source_file))
+ break;
+ if (i == files->len)
+ g_ptr_array_add (files, g_strdup (source_file));
+ g_free (source_file);
+ }
+ g_ptr_array_free (source_file_list, TRUE);
}
}
int i, n_il_offsets;
int *il_offsets;
int *line_numbers;
+ int *source_files;
+ GPtrArray *source_file_list;
header = mono_method_get_header (method);
if (!header) {
break;
}
- mono_debug_symfile_get_line_numbers (minfo, &source_file, &n_il_offsets, &il_offsets, &line_numbers);
+ mono_debug_symfile_get_line_numbers_full (minfo, &source_file, &source_file_list, &n_il_offsets, &il_offsets, &line_numbers, &source_files);
buffer_add_int (buf, header->code_size);
- buffer_add_string (buf, source_file);
+ if (CHECK_PROTOCOL_VERSION (2, 13)) {
+ buffer_add_int (buf, source_file_list->len);
+ for (i = 0; i < source_file_list->len; ++i)
+ buffer_add_string (buf, g_ptr_array_index (source_file_list, i));
+ } else {
+ buffer_add_string (buf, source_file);
+ }
buffer_add_int (buf, n_il_offsets);
DEBUG (10, printf ("Line number table for method %s:\n", mono_method_full_name (method, TRUE)));
for (i = 0; i < n_il_offsets; ++i) {
- DEBUG (10, printf ("IL%x -> %d\n", il_offsets [i], line_numbers [i]));
+ const char *srcfile = source_files [i] != -1 ? g_ptr_array_index (source_file_list, source_files [i]) : "";
+ DEBUG (10, printf ("IL%x -> %s:%d\n", il_offsets [i], srcfile, line_numbers [i]));
buffer_add_int (buf, il_offsets [i]);
buffer_add_int (buf, line_numbers [i]);
+ if (CHECK_PROTOCOL_VERSION (2, 13))
+ buffer_add_int (buf, source_files [i]);
}
g_free (source_file);
g_free (il_offsets);
g_free (line_numbers);
+ g_free (source_files);
+ for (i = 0; i < source_file_list->len; ++i)
+ g_free (g_ptr_array_index (source_file_list, i));
+ g_ptr_array_free (source_file_list, TRUE);
mono_metadata_free_mh (header);
break;
}