AssemblyDefinition sourceAssembly =
AssemblyFactory.GetAssembly(shadowCopyPath);
ModuleDefinition modDef = sourceAssembly.MainModule;
PdbFactory pdbFactory = new PdbFactory();
ISymbolReader reader = pdbFactory.CreateReader(modDef,
shadowCopyPath);
modDef.LoadSymbols(reader);
foreach (TypeDefinition type in sourceAssembly.MainModule.Types)
{
//Do some modification
}
modDef.SaveSymbols(Path.GetDirectoryName(shadowCopyPath));
AssemblyFactory.SaveAssembly(sourceAssembly, shadowCopyPath);
Am i doing something wrong?
On Tue, Mar 30, 2010 at 9:20 PM, Pavels <pavels.m...@gmail.com> wrote:
> Hi, I have a problem.
> I use mono.cecil to modify a WPF .exe file. Visual Studio creates pdb
> file that is 131 KB, after modification with mono.cecil (and
> mono.cecil.pdb) the pdb file is only 40 KB.
Are you concerned because of the size of your pdb? Or is it unusable
after Cecil manipulated it?
--
Jb Evain <j...@nurv.fr>
On Mar 30, 10:27 pm, Jb Evain <j...@nurv.fr> wrote:
> Hi,
>
> On Tue, Mar 30, 2010 at 9:20 PM, Pavels <pavels.mihail...@gmail.com> wrote:
> > Hi, I have a problem.
> > I use mono.cecil to modify a WPF .exe file. Visual Studio creates pdb
> > file that is 131 KB, after modification with mono.cecil (and
> > mono.cecil.pdb) the pdb file is only 40 KB.
>
> Are you concerned because of the size of your pdb? Or is it unusable
> after Cecil manipulated it?
>
> --
> Jb Evain <j...@nurv.fr>
It is unusable after Cecil manipulation. Visual Studio manages to
Attach to process for debugging, but even if i set a breakpoint, it is
never hit (shows empty breakpoint).
The manipulations i'm doing are :
CilWorker MSILWorker = prop.SetMethod.Body.CilWorker;
Instruction callRaisePropertyChanged = MSILWorker.Create(OpCodes.Call,
raisePropertyChanged);
if
(prop.SetMethod.Body.Instructions.Contains(callRaisePropertyChanged))
break;
Instruction ldarg0 = MSILWorker.Create(OpCodes.Ldarg_0);
Instruction propertyName = MSILWorker.Create(OpCodes.Ldstr,
prop.Name);
MSILWorker.InsertBefore(prop.SetMethod.Body.Instructions[prop.SetMethod.Body.Instructions.Count
- 1], ldarg0);
MSILWorker.InsertAfter(ldarg0, propertyName);
MSILWorker.InsertAfter(propertyName, callRaisePropertyChanged);
MSILWorker.InsertAfter(callRaisePropertyChanged,
MSILWorker.Create(OpCodes.Nop));
-- I add a method call on property set method.
What's written in VS's output window about loading your instrumented
assembly and its symbols?
--
Jb Evain <j...@nurv.fr>
But when i check breakpoint
"The breakpoint will not currently be hit. No symbols have been loaded
for this document".
Exe was compiled under debug configuration and modified on the same
PC :/
AssemblyDefinition sourceAssembly =
AssemblyFactory.GetAssembly(shadowCopyPath);
ModuleDefinition modDef = sourceAssembly.MainModule;
PdbFactory pdbFactory = new PdbFactory();
ISymbolReader reader = pdbFactory.CreateReader(modDef,
shadowCopyPath);
modDef.LoadSymbols(reader);
foreach (TypeDefinition type in sourceAssembly.MainModule.Types)
{
//Do nothing
}
modDef.SaveSymbols(Path.GetDirectoryName(shadowCopyPath));
AssemblyFactory.SaveAssembly(sourceAssembly, shadowCopyPath);
I tried to do this process manually and by using AfterBuild task.
Signing and not signing also doesn't help :/
I'm using Mono.Cecil 0.6.9.0 and Mono.Cecil.Pdb 0.2 (from the mono
trunk).
If full source code is needed i can share it.
I'm working with r132172 for a halfyear for now and the only annoying
bug I have now is this one:
http://social.msdn.microsoft.com/Forums/en-US/csharpide/thread/024f9019-699d-44e1-b0f9-43da50782e7d
WBR,
Alex
In the case of 531630, the assembly can be overwritten, and broking
the DLL/EXE, not the pdb. If VS can load the assembly but fails to
read the pdb then it's a different issue.
> But be careful: new PDB file path should be shorter than old one
> (yeap, that's another bug of CECIL).
This one will be fixed in the release due next monday.
> I'm working with r132172 for a halfyear for now and the only annoying
> bug I have now is this one:
> http://social.msdn.microsoft.com/Forums/en-US/csharpide/thread/024f9019-699d-44e1-b0f9-43da50782e7d
I don't really see how that's related to Cecil if the pdb doesn't
expose the variables and that even ildasm doesn't show them.
--
Jb Evain <j...@nurv.fr>
In the case of 531630, the assembly can be overwritten, and brokingthe DLL/EXE, not the pdb. If VS can load the assembly but fails to
read the pdb then it's a different issue.
This one will be fixed in the release due next monday.
I don't really see how that's related to Cecil if the pdb doesn'texpose the variables and that even ildasm doesn't show them.
--
Jb Evain <j...@nurv.fr>
--
--
mono-cecil
To unsubscribe, reply using "remove me" as the subject.
The case of 531630 will be fixed as well.
> Original PDB produced by compiler exposes all variables - debugger uses them
> perfectly, ildasm can see them.
> But it seems that loading+saving of that PDB looses such variables, ildasm
> still sees them, but debugger - is not.
That sucks. It's indeed maybe some special flags, I'll investigate and
see if I can get it for monday.
--
Jb Evain <j...@nurv.fr>
The case of 531630 will be fixed as well.
That sucks. It's indeed maybe some special flags, I'll investigate and
see if I can get it for monday.
I've switched to Cecil 0.9 successfully.
Good news: PDB files are written almost properly - thay are large,
debugger-valid and working fine.
Unless one annoying situation I've mentioned before (about "yieldy"
functions):
http://www.google.com/url?sa=D&q=http://social.msdn.microsoft.com/Forums/en-US/csharpide/thread/024f9019-699d-44e1-b0f9-43da50782e7d&usg=AFQjCNGxaJAnv2A_hBJfqQQPi7ThwBR30w
- these variables are still lost in the debugger.
By the way, two litte fixes:
1. diff from MethodBodyRocks.GetParameter():
if (method.HasThis) {
+ if (index == 0)
+ return body.ThisParameter;
index--;
Otherwise Cecil crashes on accessing this in IL during SimplifyMacro()
method execution.
2. in MetadataImporter.ImportAssemblyName() it's useful to check for
(name.PublicKeyToken == null) before taking key token length for byte
array - or Cecil crashes on assemblies without PublicKeyToken.
Great job anyway.
I'm looking forward to fixing "yieldy" bug - after that Cecil will be
perfect for me!
WBR,
Alex
On Apr 8, 9:21 pm, Jb Evain <j...@nurv.fr> wrote:
> On Thu, Apr 8, 2010 at 6:54 PM, Александр Буряк
>
I'll take a closer look tomorrow and give some examples of such
functions for further investigation and bugfix.
Old Cecil works with those functions properly.
WBR,
Alex
On Apr 14, 1:09 am, Buryak Alexander <buryak.alexan...@gmail.com>
wrote:
> Greetings.
>
> I've switched to Cecil 0.9 successfully.
>
> Good news: PDB files are written almost properly - thay are large,
> debugger-valid and working fine.
> Unless one annoying situation I've mentioned before (about "yieldy"
> functions):http://www.google.com/url?sa=D&q=http://social.msdn.microsoft.com/For...
2010/4/13 Buryak Alexander <buryak.a...@gmail.com>:
> Unless one annoying situation I've mentioned before (about "yieldy"
> functions):
I'll investigate those.
> 1. diff from MethodBodyRocks.GetParameter():
> 2. in MetadataImporter.ImportAssemblyName() it's useful to check for
Both are fixed.
Thanks!
--
Jb Evain <j...@nurv.fr>
2010/4/13 Buryak Alexander <buryak.a...@gmail.com>:
> Found some troubles with saving IL code: load+save breaks some random
> methods and causes runtime errors like
> "System.BadImageFormatException : Bad IL range."
>
> I'll take a closer look tomorrow and give some examples of such
> functions for further investigation and bugfix.
> Old Cecil works with those functions properly.
Weird. It would be great if you could send me samples of those assemblies.
> Weird. It would be great if you could send me samples of those assemblies.
I'll recheck my code (it worked fine on old cecil, but may be I've
made some mistakes updating it for cecil/light) - and if I fail to fix
it, I'll make some examples for you.
WBR,
Alex
> Hey,
>
> 2010/4/13 Buryak Alexander <buryak.alexan...@gmail.com>:
On Apr 14, 1:43 am, Buryak Alexander <buryak.alexan...@gmail.com>
I spent a bit of time tonight to try and figure out what's the deal
here. Apparently, at least according to the CCI sources, the pdb
contains custom metadata, and the iterator stuff is one of those
custom metadata.
I have no idea if I can get those custom metadata elements when
reading the assembly and saving them back yet. But at least we have a
clue at what's going on.