Permalink
Browse files

Changes for debugging kernels via setting breakpoints and single step…

…. Note, this check in requires a special version of swigged.llvm that includes changes from the main branch of llvm. Those changes will be in a swigged.llvm version 6.0.4. There are other changes that aren't yet in LLVM which should be in order for LLVM-C to be fixed for debugging information.
  • Loading branch information...
kaby76 committed Apr 3, 2018
1 parent ac6e577 commit 4c15bdaff0ddd51790968ec38930a9e7554e98fa
Showing with 87 additions and 0 deletions.
  1. +84 −0 Campy.Compiler/inst.cs
  2. +3 −0 Campy.Compiler/jiter.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Campy.Graphs;
@@ -44,6 +45,89 @@ public virtual void ComputeStackLevel(JITER converter, ref int level_after)
+ this.ToString());
}
private static Dictionary<string, MetadataRef> debug_files = new Dictionary<string, MetadataRef>();
private static Dictionary<string, MetadataRef> debug_compile_units = new Dictionary<string, MetadataRef>();
private static Dictionary<string, MetadataRef> debug_methods = new Dictionary<string, MetadataRef>();
public static DIBuilderRef dib;
private static bool done_this;
public virtual void DebuggerInfo(JITER converter)
{
if (this.SeqPoint == null)
return;
if (!done_this)
{
done_this = true;
dib = LLVM.CreateDIBuilder(JITER.global_llvm_module);
}
var doc = SeqPoint.Document;
string assembly_name = this.Block._original_method_reference.Module.FileName;
string loc = Path.GetDirectoryName(Path.GetFullPath(doc.Url));
string file_name = Path.GetFileName(doc.Url);
MetadataRef file;
if (!debug_files.ContainsKey(file_name))
{
file = LLVM.DIBuilderCreateFile(dib,
file_name, (uint)file_name.Length, loc, (uint)loc.Length);
debug_files[file_name] = file;
}
else
{
file = debug_files[file_name];
}
string producer = "Campy Compiler";
MetadataRef compile_unit;
if (!debug_compile_units.ContainsKey(file_name))
{
compile_unit = LLVM.DIBuilderCreateCompileUnit(
dib,
DWARFSourceLanguage.DWARFSourceLanguageJava,
file, producer, (uint)producer.Length,
false, "", 0, 0, "", 0, DWARFEmissionKind.DWARFEmissionFull,
0, false, false);
debug_compile_units[file_name] = compile_unit;
}
else
{
compile_unit = debug_compile_units[file_name];
}
ContextRef context_ref = LLVM.GetModuleContext(JITER.global_llvm_module);
var normalized_method_name = JITER.RenameToLegalLLVMName(
JITER.MethodName(this.Block._original_method_reference));
MetadataRef sub;
if (!debug_methods.ContainsKey(normalized_method_name))
{
var sub_type = LLVM.DIBuilderCreateSubroutineType(
dib,
file, new MetadataRef[0], 0, DIFlags.DIFlagNoReturn);
sub = LLVM.DIBuilderCreateFunction(dib, file,
normalized_method_name,
normalized_method_name,
file,
(uint) this.SeqPoint.StartLine,
sub_type, 1, 1, (uint) this.SeqPoint.StartLine, 0, 0);
debug_methods[normalized_method_name] = sub;
LLVM.SetSubprogram(this.Block.MethodValueRef, sub);
}
else {
sub = debug_methods[normalized_method_name];
}
MetadataRef debug_location = LLVM.DIBuilderCreateDebugLocation(
LLVM.GetModuleContext(JITER.global_llvm_module),
(uint)this.SeqPoint.StartLine,
(uint)this.SeqPoint.StartColumn,
sub,
default(MetadataRef)
);
var dv = LLVM.MetadataAsValue(LLVM.GetModuleContext(JITER.global_llvm_module), debug_location);
LLVM.SetCurrentDebugLocation(Builder, dv);
}
public virtual INST Convert(JITER converter, STATE state)
{
throw new Exception("Must have an implementation for Convert! The instruction is: "
@@ -1498,6 +1498,7 @@ private List<CFG.Vertex> RemoveBasicBlocksAlreadyCompiled(List<CFG.Vertex> basic
if (Campy.Utils.Options.IsOn("jit_trace"))
System.Console.WriteLine(inst);
last_inst = inst;
inst.DebuggerInfo(this);
inst = inst.Convert(this, bb.StateOut);
if (Campy.Utils.Options.IsOn("state_computation_trace"))
bb.StateOut.OutputTrace(new String(' ', 4));
@@ -1589,6 +1590,8 @@ private List<CFG.Vertex> RemoveBasicBlocksAlreadyCompiled(List<CFG.Vertex> basic
if (Campy.Utils.Options.IsOn("module_trace"))
LLVM.DumpModule(module);
LLVM.DIBuilderFinalize(INST.dib);
MyString error = new MyString();
LLVM.VerifyModule(module, VerifierFailureAction.PrintMessageAction, error);
if (error.ToString() != "")

0 comments on commit 4c15bda

Please sign in to comment.