~ubuntu-branches/ubuntu/lucid/monodevelop/lucid

« back to all changes in this revision

Viewing changes to contrib/Mono.Cecil/Mono.Cecil.Mdb/Mono.Cecil.MdbOld/MdbReader.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-02-02 11:39:59 UTC
  • mfrom: (1.2.6 upstream) (1.3.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100202113959-s4exdz7er7igylz2
Tags: 2.2.1+dfsg-1
* New upstream release
* debian/control:
  + Standards version 3.8.4 (no changes needed)
* debian/patches/remove_support_for_non_debian_functionality.patch,
  debian/patches/remove_support_for_soft_debugger.patch,
  debian/patches/remove_support_for_moonlight.patch,
  debian/rules:
  + Split patch into two pieces, to make it easier to enable either
    SDB or Moonlight support with a rebuild
* debian/monodevelop-moonlight.install,
  debian/monodevelop-debugger-sdb.install,
  debian/control:
  + Create packaging data for the Soft Debugger addin and Moonlight addin -
    and comment them out of debian/control as we can't provide them on
    Debian for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// MdbReader.cs
3
 
//
4
 
// Author:
5
 
//   Jb Evain (jbevain@gmail.com)
6
 
//
7
 
// (C) 2006 Jb Evain
8
 
//
9
 
// Permission is hereby granted, free of charge, to any person obtaining
10
 
// a copy of this software and associated documentation files (the
11
 
// "Software"), to deal in the Software without restriction, including
12
 
// without limitation the rights to use, copy, modify, merge, publish,
13
 
// distribute, sublicense, and/or sell copies of the Software, and to
14
 
// permit persons to whom the Software is furnished to do so, subject to
15
 
// the following conditions:
16
 
//
17
 
// The above copyright notice and this permission notice shall be
18
 
// included in all copies or substantial portions of the Software.
19
 
//
20
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
 
//
28
 
 
29
 
namespace Mono.Cecil.MdbOld {
30
 
 
31
 
        using System.Collections;
32
 
 
33
 
        using Mono.Cecil.Cil;
34
 
 
35
 
        using Mono.CompilerServices.SymbolWriterOld;
36
 
 
37
 
        class MdbReader : ISymbolReader {
38
 
 
39
 
                MonoSymbolFile m_symFile;
40
 
                Hashtable m_documents;
41
 
                Hashtable m_scopes;
42
 
 
43
 
                public MdbReader (MonoSymbolFile symFile)
44
 
                {
45
 
                        m_symFile = symFile;
46
 
                        m_documents = new Hashtable ();
47
 
                        m_scopes = new Hashtable ();
48
 
                }
49
 
 
50
 
                Instruction GetInstruction (MethodBody body, IDictionary instructions, int offset)
51
 
                {
52
 
                        Instruction instr = (Instruction) instructions [offset];
53
 
                        if (instr != null)
54
 
                                return instr;
55
 
 
56
 
                        return body.Instructions.Outside;
57
 
                }
58
 
 
59
 
                public void Read (MethodBody body, IDictionary instructions)
60
 
                {
61
 
                        MethodEntry entry = m_symFile.GetMethodByToken ((int) body.Method.MetadataToken.ToUInt ());
62
 
                        if (entry == null)
63
 
                                return;
64
 
 
65
 
                        ReadScopes (entry, body, instructions);
66
 
                        ReadLineNumbers (entry, instructions);
67
 
                        ReadLocalVariables (entry, body);
68
 
                }
69
 
 
70
 
                void ReadLocalVariables (MethodEntry entry, MethodBody body)
71
 
                {
72
 
                        foreach (LocalVariableEntry loc in entry.Locals) {
73
 
                                VariableDefinition var = body.Variables [loc.Index];
74
 
                                var.Name = loc.Name;
75
 
 
76
 
                                Scope scope = m_scopes [loc.BlockIndex] as Scope;
77
 
                                if (scope == null)
78
 
                                        continue;
79
 
                                scope.Variables.Add (var);
80
 
                        }
81
 
                }
82
 
 
83
 
                void ReadLineNumbers (MethodEntry entry, IDictionary instructions)
84
 
                {
85
 
                        foreach (LineNumberEntry line in entry.LineNumbers) {
86
 
                                Instruction instr = instructions [line.Offset] as Instruction;
87
 
                                if (instr == null)
88
 
                                        continue;
89
 
 
90
 
                                Document doc = GetDocument (entry.SourceFile);
91
 
                                instr.SequencePoint = new SequencePoint (doc);
92
 
                                instr.SequencePoint.StartLine = line.Row;
93
 
                                instr.SequencePoint.EndLine = line.Row;
94
 
                        }
95
 
                }
96
 
 
97
 
                Document GetDocument (SourceFileEntry file)
98
 
                {
99
 
                        Document doc = m_documents [file.FileName] as Document;
100
 
                        if (doc != null)
101
 
                                return doc;
102
 
 
103
 
                        doc = new Document (file.FileName);
104
 
 
105
 
                        m_documents [file.FileName] = doc;
106
 
                        return doc;
107
 
                }
108
 
 
109
 
                void ReadScopes (MethodEntry entry, MethodBody body, IDictionary instructions)
110
 
                {
111
 
                        foreach (LexicalBlockEntry scope in entry.LexicalBlocks) {
112
 
                                Scope s = new Scope ();
113
 
                                s.Start = GetInstruction (body, instructions, scope.StartOffset);
114
 
                                s.End = GetInstruction(body, instructions, scope.EndOffset);
115
 
                                m_scopes [scope.Index] = s;
116
 
 
117
 
                                if (!AddScope (body, s))
118
 
                                        body.Scopes.Add (s);
119
 
                        }
120
 
                }
121
 
 
122
 
                bool AddScope (IScopeProvider provider, Scope s)
123
 
                {
124
 
                        foreach (Scope scope in provider.Scopes) {
125
 
                                if (AddScope (scope, s))
126
 
                                        return true;
127
 
 
128
 
                                if (s.Start.Offset >= scope.Start.Offset && s.End.Offset <= scope.End.Offset) {
129
 
                                        scope.Scopes.Add (s);
130
 
                                        return true;
131
 
                                }
132
 
                        }
133
 
 
134
 
                        return false;
135
 
                }
136
 
 
137
 
                public void Dispose ()
138
 
                {
139
 
                        m_symFile.Dispose ();
140
 
                }
141
 
        }
142
 
}