From 8d974cfea81841e64cd5da62d8a40cbd5eb89e28 Mon Sep 17 00:00:00 2001 From: yck1509 Date: Wed, 4 Jun 2014 16:01:42 +0800 Subject: [PATCH] Fix debug symbol generation workflow --- Confuser.Core/ConfuserEngine.cs | 28 ++++++++++++---------------- Confuser.Core/Marker.cs | 8 ++++++++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs index 9184ec24b..81bb12bc1 100644 --- a/Confuser.Core/ConfuserEngine.cs +++ b/Confuser.Core/ConfuserEngine.cs @@ -300,15 +300,10 @@ private static void BeginModule(ConfuserContext context) { var snKey = context.Annotations.Get(context.CurrentModule, Marker.SNKey); context.CurrentModuleWriterOptions.InitializeStrongNameSigning(context.CurrentModule, snKey); - if (context.Project.Debug) - context.CurrentModule.LoadPdb(); - foreach (TypeDef type in context.CurrentModule.GetTypes()) foreach (MethodDef method in type.Methods) { if (method.Body != null) { method.Body.Instructions.SimplifyMacros(method.Body.Variables, method.Parameters); - if (context.Project.Debug) - context.CurrentModule.PdbState.Initialize(method.Body, method.Rid); } } } @@ -334,10 +329,11 @@ private static void WriteModule(ConfuserContext context) { context.Logger.InfoFormat("Writing module '{0}'...", context.CurrentModule.Name); MemoryStream pdb = null, output = new MemoryStream(); - if (context.Project.Debug) { + + if (context.CurrentModule.PdbState != null) { + pdb = new MemoryStream(); context.CurrentModuleWriterOptions.WritePdb = true; context.CurrentModuleWriterOptions.PdbFileName = Path.ChangeExtension(Path.GetFileName(context.OutputPaths[context.CurrentModuleIndex]), "pdb"); - pdb = new MemoryStream(); context.CurrentModuleWriterOptions.PdbStream = pdb; } @@ -347,20 +343,20 @@ private static void WriteModule(ConfuserContext context) { context.CurrentModule.NativeWrite(output, (NativeModuleWriterOptions)context.CurrentModuleWriterOptions); context.CurrentModuleOutput = output.ToArray(); - if (context.Project.Debug) + if (context.CurrentModule.PdbState != null) context.CurrentModuleSymbol = pdb.ToArray(); } private static void Debug(ConfuserContext context) { context.Logger.Info("Finalizing..."); - if (context.Project.Debug) { - for (int i = 0; i < context.OutputModules.Count; i++) { - string path = Path.GetFullPath(Path.Combine(context.OutputDirectory, context.OutputPaths[i])); - string dir = Path.GetDirectoryName(path); - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - File.WriteAllBytes(Path.ChangeExtension(path, "pdb"), context.OutputSymbols[i]); - } + for (int i = 0; i < context.OutputModules.Count; i++) { + if (context.OutputSymbols[i] == null) + continue; + string path = Path.GetFullPath(Path.Combine(context.OutputDirectory, context.OutputPaths[i])); + string dir = Path.GetDirectoryName(path); + if (!Directory.Exists(dir)) + Directory.CreateDirectory(dir); + File.WriteAllBytes(Path.ChangeExtension(path, "pdb"), context.OutputSymbols[i]); } } diff --git a/Confuser.Core/Marker.cs b/Confuser.Core/Marker.cs index dd4ba64e6..2555a7790 100644 --- a/Confuser.Core/Marker.cs +++ b/Confuser.Core/Marker.cs @@ -92,11 +92,15 @@ public static StrongNameKey LoadSNKey(ConfuserContext context, string path, stri protected internal virtual MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context) { Packer packer = null; Dictionary packerParams = null; + if (proj.Packer != null) { if (!packers.ContainsKey(proj.Packer.Id)) { context.Logger.ErrorFormat("Cannot find packer with ID '{0}'.", proj.Packer.Id); throw new ConfuserException(null); } + if (proj.Debug) + context.Logger.Warn("Generated Debug symbols might not be usable with packers!"); + packer = packers[proj.Packer.Id]; packerParams = new Dictionary(proj.Packer, StringComparer.OrdinalIgnoreCase); } @@ -104,7 +108,11 @@ protected internal virtual MarkerResult MarkProject(ConfuserProject proj, Confus var modules = new List(); foreach (ProjectModule module in proj) { context.Logger.InfoFormat("Loading '{0}'...", module.Path); + ModuleDefMD modDef = module.Resolve(proj.BaseDirectory, context.Resolver.DefaultModuleContext); + if (proj.Debug) + modDef.LoadPdb(); + Rules rules = ParseRules(proj, module, context); context.Annotations.Set(modDef, SNKey, LoadSNKey(context, module.SNKeyPath == null ? null : Path.Combine(proj.BaseDirectory, module.SNKeyPath), module.SNKeyPassword));