Author: lluis
Date: 2005-05-25 05:37:07 -0400 (Wed, 25 May 2005)
New Revision: 44983
Modified:
trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
trunk/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs
trunk/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs
trunk/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
trunk/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs
trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
trunk/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs
trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
Log:
2005-05-25 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* ModuleBuilder.cs: Implemented DefineDocument(). Generate debug
info when saving the module.
* ILGenerator.cs: Keep marked sequence points in a list.
Added a GenerateDebugInfo method, which dumps the info collected
during code generation.
* TypeBuilder.cs:
* ConstructorBuilder.cs:
* MethodBuilder.cs: Added method for generating debug info.
* LocalBuilder.cs: Added StartOffset and EndOffset properties.
* CustomAttributeBuilder.cs: Use IsInstanceOfType instead of
IsAssignableFrom when possible.
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog 2005-05-25
09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog 2005-05-25
09:37:07 UTC (rev 44983)
@@ -1,3 +1,17 @@
+2005-05-25 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * ModuleBuilder.cs: Implemented DefineDocument(). Generate debug
+ info when saving the module.
+ * ILGenerator.cs: Keep marked sequence points in a list.
+ Added a GenerateDebugInfo method, which dumps the info collected
+ during code generation.
+ * TypeBuilder.cs:
+ * ConstructorBuilder.cs:
+ * MethodBuilder.cs: Added method for generating debug info.
+ * LocalBuilder.cs: Added StartOffset and EndOffset properties.
+ * CustomAttributeBuilder.cs: Use IsInstanceOfType instead of
+ IsAssignableFrom when possible.
+
2005-05-20 Miguel de Icaza <[EMAIL PROTECTED]>
* TypeBuilder.cs (UnderlyingSystemType): should always return this
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs
2005-05-25 09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs
2005-05-25 09:37:07 UTC (rev 44983)
@@ -37,6 +37,7 @@
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
+using System.Diagnostics.SymbolStore;
namespace System.Reflection.Emit {
@@ -274,6 +275,18 @@
if (ilgen != null)
ilgen.label_fixup ();
}
+
+ internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
+ {
+ if (ilgen != null && ilgen.HasDebugInfo) {
+ SymbolToken token = new SymbolToken
(GetToken().Token);
+ symbolWriter.OpenMethod (token);
+ symbolWriter.SetSymAttribute (token, "__name",
System.Text.Encoding.UTF8.GetBytes (Name));
+ ilgen.GenerateDebugInfo (symbolWriter);
+ symbolWriter.CloseMethod ();
+ }
+ }
+
internal override int get_next_table_index (object obj, int
table, bool inc) {
return type.get_next_table_index (obj, table, inc);
}
Modified:
trunk/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs
2005-05-25 09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs
2005-05-25 09:37:07 UTC (rev 44983)
@@ -133,7 +133,7 @@
// FIXME: Check enums and TypeBuilders as well
if (fieldValues [i] != null)
// IsEnum does not seem to work on
TypeBuilders
- if (!(fi.FieldType is TypeBuilder) &&
!fi.FieldType.IsEnum && !fi.FieldType.IsAssignableFrom (fieldValues [i].GetType
())) {
+ if (!(fi.FieldType is TypeBuilder) &&
!fi.FieldType.IsEnum && !fi.FieldType.IsInstanceOfType (fieldValues [i])) {
//
// mcs allways uses object[]
for array types and
// MS.NET allows this
@@ -154,7 +154,7 @@
if ((atype != t) && (!t.IsSubclassOf (atype))
&& (!atype.IsSubclassOf (t)))
throw new ArgumentException ("Property
'" + pi.Name + "' does not belong to the same class as the constructor");
if (propertyValues [i] != null) {
- if (!(pi.PropertyType is TypeBuilder)
&& !pi.PropertyType.IsEnum && !pi.PropertyType.IsAssignableFrom (propertyValues
[i].GetType ()))
+ if (!(pi.PropertyType is TypeBuilder)
&& !pi.PropertyType.IsEnum && !pi.PropertyType.IsInstanceOfType (propertyValues
[i]))
if (!pi.PropertyType.IsArray)
throw new
ArgumentException ("Value of property '" + pi.Name + "' does not match property
type: " + pi.PropertyType + " -> " + propertyValues [i]);
}
@@ -168,7 +168,7 @@
if (!IsValidType (paramType))
throw new ArgumentException
("Argument " + i + " does not have a valid type.");
if (constructorArgs [i] != null)
- if (!(paramType is TypeBuilder)
&& !paramType.IsEnum && !paramType.IsAssignableFrom (constructorArgs
[i].GetType ()))
+ if (!(paramType is TypeBuilder)
&& !paramType.IsEnum && !paramType.IsInstanceOfType (constructorArgs [i]))
if (!paramType.IsArray)
throw new
ArgumentException ("Value of argument " + i + " does not match parameter type:
" + paramType + " -> " + constructorArgs [i]);
}
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
2005-05-25 09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
2005-05-25 09:37:07 UTC (rev 44983)
@@ -203,6 +203,8 @@
const int defaultFixupSize = 8;
const int defaultLabelsSize = 8;
+ ArrayList sequencePointLists;
+ SequencePointList currentSequence;
internal ILGenerator (Module m, TokenGenerator token_gen, int
size)
{
@@ -218,7 +220,7 @@
open_blocks = new Stack ();
this.token_gen = token_gen;
}
-
+
private void add_token_fixup (MemberInfo mi)
{
if (num_token_fixups == token_fixups.Length) {
@@ -840,7 +842,45 @@
public virtual void MarkSequencePoint (ISymbolDocumentWriter
document, int startLine,
int startColumn, int
endLine, int endColumn)
- { }
+ {
+ if (currentSequence == null || currentSequence.Document
!= document) {
+ if (sequencePointLists == null)
+ sequencePointLists = new ArrayList ();
+ currentSequence = new SequencePointList
(document);
+ sequencePointLists.Add (currentSequence);
+ }
+
+ currentSequence.AddSequencePoint (code_len, startLine,
startColumn, endLine, endColumn);
+ }
+
+ internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
+ {
+ if (sequencePointLists != null) {
+ SequencePointList first = (SequencePointList)
sequencePointLists [0];
+ SequencePointList last = (SequencePointList)
sequencePointLists [sequencePointLists.Count - 1];
+ symbolWriter.SetMethodSourceRange
(first.Document, first.StartLine, first.StartColumn, last.Document,
last.EndLine, last.EndColumn);
+
+ foreach (SequencePointList list in
sequencePointLists)
+ symbolWriter.DefineSequencePoints
(list.Document, list.GetOffsets(), list.GetLines(), list.GetColumns(),
list.GetEndLines(), list.GetEndColumns());
+
+ if (locals != null) {
+ foreach (LocalBuilder local in locals) {
+ if (local.Name != null &&
local.Name.Length > 0) {
+ SignatureHelper
sighelper = SignatureHelper.GetLocalVarSigHelper (module);
+ sighelper.AddArgument
(local.LocalType);
+ byte[] signature =
sighelper.GetSignature ();
+
symbolWriter.DefineLocalVariable (local.Name, FieldAttributes.Public,
signature, SymAddressKind.ILOffset, local.position, 0, 0, local.StartOffset,
local.EndOffset);
+ }
+ }
+ }
+ sequencePointLists = null;
+ }
+ }
+
+ internal bool HasDebugInfo
+ {
+ get { return sequencePointLists != null; }
+ }
public virtual void ThrowException (Type exceptionType)
{
@@ -884,4 +924,93 @@
return ig.code_len;
}
}
+
+ internal class SequencePointList
+ {
+ ISymbolDocumentWriter doc;
+ SequencePoint[] points;
+ int count;
+ const int arrayGrow = 10;
+
+ public SequencePointList (ISymbolDocumentWriter doc)
+ {
+ this.doc = doc;
+ }
+
+ public ISymbolDocumentWriter Document {
+ get { return doc; }
+ }
+
+ public int[] GetOffsets()
+ {
+ int[] data = new int [count];
+ for (int n=0; n<count; n++) data [n] = points[n].Offset;
+ return data;
+ }
+ public int[] GetLines()
+ {
+ int[] data = new int [count];
+ for (int n=0; n<count; n++) data [n] = points[n].Line;
+ return data;
+ }
+ public int[] GetColumns()
+ {
+ int[] data = new int [count];
+ for (int n=0; n<count; n++) data [n] = points[n].Col;
+ return data;
+ }
+ public int[] GetEndLines()
+ {
+ int[] data = new int [count];
+ for (int n=0; n<count; n++) data [n] =
points[n].EndLine;
+ return data;
+ }
+ public int[] GetEndColumns()
+ {
+ int[] data = new int [count];
+ for (int n=0; n<count; n++) data [n] = points[n].EndCol;
+ return data;
+ }
+ public int StartLine {
+ get { return points[0].Line; }
+ }
+ public int EndLine {
+ get { return points[count - 1].Line; }
+ }
+ public int StartColumn {
+ get { return points[0].Col; }
+ }
+ public int EndColumn {
+ get { return points[count - 1].Col; }
+ }
+
+ public void AddSequencePoint (int offset, int line, int col,
int endLine, int endCol)
+ {
+ SequencePoint s = new SequencePoint ();
+ s.Offset = offset;
+ s.Line = line;
+ s.Col = col;
+ s.EndLine = endLine;
+ s.EndCol = endCol;
+
+ if (points == null) {
+ points = new SequencePoint [arrayGrow];
+ } else if (count >= points.Length) {
+ SequencePoint[] temp = new SequencePoint [count
+ arrayGrow];
+ Array.Copy (points, temp, points.Length);
+ points = temp;
+ }
+
+ points [count] = s;
+ count++;
+ }
+ }
+
+ struct SequencePoint {
+ public int Offset;
+ public int Line;
+ public int Col;
+ public int EndLine;
+ public int EndCol;
+ }
}
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs
2005-05-25 09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs
2005-05-25 09:37:07 UTC (rev 44983)
@@ -62,6 +62,8 @@
#endif
internal ILGenerator ilgen;
+ int startOffset;
+ int endOffset;
internal LocalBuilder (Type t, ILGenerator ilgen)
{
@@ -71,7 +73,9 @@
public void SetLocalSymInfo (string lname, int startOffset, int
endOffset)
{
- // nop
+ name = lname;
+ this.startOffset = startOffset;
+ this.endOffset = endOffset;
}
public void SetLocalSymInfo (string lname)
@@ -104,5 +108,17 @@
}
}
#endif
+
+ internal string Name {
+ get { return name; }
+ }
+
+ internal int StartOffset {
+ get { return startOffset; }
+ }
+
+ internal int EndOffset {
+ get { return endOffset; }
+ }
}
}
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
2005-05-25 09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
2005-05-25 09:37:07 UTC (rev 44983)
@@ -38,6 +38,7 @@
using System.Security.Permissions;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Diagnostics.SymbolStore;
namespace System.Reflection.Emit {
@@ -261,6 +262,17 @@
if (ilgen != null)
ilgen.label_fixup ();
}
+
+ internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
+ {
+ if (ilgen != null && ilgen.HasDebugInfo) {
+ SymbolToken token = new SymbolToken
(GetToken().Token);
+ symbolWriter.OpenMethod (token);
+ symbolWriter.SetSymAttribute (token, "__name",
System.Text.Encoding.UTF8.GetBytes (Name));
+ ilgen.GenerateDebugInfo (symbolWriter);
+ symbolWriter.CloseMethod ();
+ }
+ }
public void SetCustomAttribute( CustomAttributeBuilder
customBuilder) {
if (customBuilder == null)
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs
2005-05-25 09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs
2005-05-25 09:37:07 UTC (rev 44983)
@@ -64,6 +64,7 @@
bool transient;
ModuleBuilderTokenGenerator token_gen;
ArrayList resource_writers = null;
+ ISymbolWriter symbolWriter;
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void basic_init (ModuleBuilder ab);
@@ -82,6 +83,18 @@
basic_init (this);
CreateGlobalType ();
+
+ if (emitSymbolInfo) {
+ Assembly asm = Assembly.LoadWithPartialName
("Mono.CompilerServices.SymbolWriter");
+ Type t = asm.GetType
("Mono.CompilerServices.SymbolWriter.SymbolWriterImpl");
+ if (t != null) {
+ symbolWriter = (ISymbolWriter)
Activator.CreateInstance (t, new object[] { this });
+ string fileName = fqname;
+ if (assemblyb.AssemblyDir != null)
+ fileName = Path.Combine
(assemblyb.AssemblyDir, fileName);
+ symbolWriter.Initialize (IntPtr.Zero,
fileName, true);
+ }
+ }
}
public override string FullyQualifiedName {get { return
fqname;}}
@@ -396,11 +409,15 @@
}
public ISymbolWriter GetSymWriter () {
- return null;
+ return symbolWriter;
}
- public ISymbolDocumentWriter DefineDocument (string url, Guid
language, Guid languageVendor, Guid documentType) {
- return null;
+ public ISymbolDocumentWriter DefineDocument (string url, Guid
language, Guid languageVendor, Guid documentType)
+ {
+ if (symbolWriter != null)
+ return symbolWriter.DefineDocument (url,
language, languageVendor, documentType);
+ else
+ return null;
}
public override Type [] GetTypes ()
@@ -635,6 +652,12 @@
// The constant 0x80000000 is internal to Mono, it
means `make executable'
//
File.SetAttributes (fileName, (FileAttributes)
(unchecked ((int) 0x80000000)));
+
+ if (types != null && symbolWriter != null) {
+ for (int i = 0; i < num_types; ++i)
+ types [i].GenerateDebugInfo
(symbolWriter);
+ symbolWriter.Close ();
+ }
}
internal string FileName {
@@ -685,3 +708,4 @@
}
}
}
+
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
2005-05-25 09:31:53 UTC (rev 44982)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
2005-05-25 09:37:07 UTC (rev 44983)
@@ -40,6 +40,7 @@
using System.Collections;
using System.Security;
using System.Security.Permissions;
+using System.Diagnostics.SymbolStore;
namespace System.Reflection.Emit {
@@ -676,13 +677,32 @@
foreach (ConstructorBuilder ctor in ctors)
ctor.fixup ();
}
-
+
created = create_runtime_class (this);
if (created != null)
return created;
return this;
}
+ internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
+ {
+ symbolWriter.OpenNamespace (this.Namespace);
+
+ if (methods != null) {
+ for (int i = 0; i < num_methods; ++i) {
+ MethodBuilder metb = (MethodBuilder)
methods[i];
+ metb.GenerateDebugInfo (symbolWriter);
+ }
+ }
+
+ if (ctors != null) {
+ foreach (ConstructorBuilder ctor in ctors)
+ ctor.GenerateDebugInfo (symbolWriter);
+ }
+
+ symbolWriter.CloseNamespace ();
+ }
+
public override ConstructorInfo[] GetConstructors (BindingFlags
bindingAttr)
{
if (ctors == null)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches