[Mono-dev] [PROPOSAL] gendarme - support for displaying the source code of violations
Sebastien Pouliot
sebastien.pouliot at gmail.com
Wed Sep 27 14:07:21 EDT 2006
Hello Christian,
Yes, it's definitively something coming for Gendarme :-)
JB and I discussed about this a few weeks ago when he committed this new
feature to SVN. We will resume this talk (and hopefully code) when we
meet at the Mono meeting in October.
[more inline]
On Wed, 2006-09-27 at 19:37 +0200, Christian Birkl wrote:
> Hi,
>
> currently gendarme just displays TypeName::MethodName::Offset of
> violations. This results for example in the following output:
>
> [snip]
> 1. NewLineLiteralRule
>
> Problem: The method 'System.Void
> Mono.Xml.MiniParser::Parse(Mono.Xml.MiniParser/IReader,Mono.Xml.MiniParser/IHandler)' use some literal values for new lines (e.g. \r\n) which aren't portable across operating systems.
>
> Details:
> Mono.Xml.MiniParser::Parse:00b5
>
> [/snip]
>
> Thanks to Jb Mono.Cecil has support of reading debug files of MS.NET
> (pdb) and mono (mdb). With just a few lines of code we can embed this
> feature into gendarme. I've "hacked" together a sample implementation
> which produces the following output:
>
> [snip]
>
> 1. NewLineLiteralRule
>
> Problem: The method 'System.Void
> Mono.Xml.MiniParser::Parse(Mono.Xml.MiniParser/IReader,Mono.Xml.MiniParser/IHandler)' use some literal values for new lines (e.g. \r\n) which aren't portable across operating systems.
>
> Details:
> Mono.Xml.MiniParser::Parse:00b5: Found string: "<>/?=&'"![ ] \r\n"
> Source Text:
>
> int charCode = "<>/?=&'\"![ ]\t\r
> \n".IndexOf((char)currCh) & 0xF;
> --------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> if (charCode == (int)CharKind.CR)
> continue; // ignore
>
> [/snip]
>
> The changes for supporting this stuff aren't a big deal, but since I
> haven't worked with Mono.Cecil.Mdb and/or Mono.Cecil.Pdb I'd like to
> hear what other might think about this implementation:
>
> 1) Add Runner::LoadDebugInfos (AssemblyDefinition, string fileName):
>
> private Hashtable symbolReaders = new Hashtable ();
>
> public void LoadDebugInfos (AssemblyDefinition ad, string fileName)
> {
> symbolReaders.Clear ();
>
> ISymbolStoreFactory factory = GetSymbolStoreFactory (fileName);
> if (factory == null)
> return;
>
> foreach (ModuleDefinition md in ad.Modules) {
> symbolReaders [md] = factory.CreateReader (md, fileName);
> }
> }
>
> private ISymbolStoreFactory GetSymbolStoreFactory (string fileName)
> {
> string pdbFileName = Path.ChangeExtension (fileName, "pdb");
> if (File.Exists (pdbFileName)) {
> return new Mono.Cecil.Pdb.PdbFactory ();
> }
>
> string mdbFileName = Path.ChangeExtension (fileName, "mdb");
> if (File.Exists (mdbFileName)) {
> return new Mono.Cecil.Mdb.MdbFactory ();
> }
>
> return null;
> }
>
> 3) Add reading code to the foreach loop in Runner::Process to read
> debugging infos (if available)
>
> 4) Change Location.cs and add a new Constructor (MethodDeclaration,
> Instruction) to load the source text out of the SequencePoint of the
> given instruction. Read in the file name specified in the document and
> extract the source text beginning at StartLine.
>
> 5) Modify Runner(s) to display the new Source Text.
>
> Any ideas how this can be easier/better/... done? Should there be a
> command line flag to specifiy where to search for debug files or to
> enable/disable debug symbol resolving? Does this really belong into
> the framework or is it something each runner need to implement on its
> own?
I haven't (yet) looked at the new Cecil code, nor where it would be best
to implement it (framework versus runner). Please feel free to
experiment (and report to the list) with the feature until the API
freeze (and that JB release a version of Cecil with it).
One thing for sure we need this feature to works in future GUI runners,
e.g. imagine a Gendarme plugin for MonoDevelop where you can
double-click any defect and see the exact line to fix :-)
> BTW - It seems like "Mono.Cecil.Pdb" and "Mono.Cecil.Mdb" aren't part
> of the "official" Mono.Cecil package - at least they aren't download
> able from the cecil homepage. Are they intended to be used by other
> applications yet?
AFAIK no Cecil version has been released since the new assemblies were
added in SVN (so you can't download them). Also I'm not sure if (or
when) their API will be frozen.
> Christian
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
--
Sebastien Pouliot <sebastien at ximian.com>
Blog: http://pages.infinit.net/ctech/
More information about the Mono-devel-list
mailing list