Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Fix debug symbol generation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yck1509 committed Jun 4, 2014
1 parent 1f74ba1 commit 8d974cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
28 changes: 12 additions & 16 deletions Confuser.Core/ConfuserEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,10 @@ public static class ConfuserEngine {
var snKey = context.Annotations.Get<StrongNameKey>(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);
}
}
}
Expand All @@ -334,10 +329,11 @@ public static class ConfuserEngine {
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;
}

Expand All @@ -347,20 +343,20 @@ public static class ConfuserEngine {
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]);
}
}

Expand Down
8 changes: 8 additions & 0 deletions Confuser.Core/Marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,27 @@ public class Marker {
protected internal virtual MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context) {
Packer packer = null;
Dictionary<string, string> 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<string, string>(proj.Packer, StringComparer.OrdinalIgnoreCase);
}

var modules = new List<ModuleDefMD>();
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));
Expand Down

0 comments on commit 8d974cf

Please sign in to comment.