добавленна возможность отладки в *.inc файлах

Signed-off-by: Slav76 <GavrikVA@gmail.com>
This commit is contained in:
Slav76 2015-10-24 12:32:03 +10:00
parent 508d0d58fd
commit 1e0c04e620
12 changed files with 115 additions and 25 deletions

View file

@ -1682,7 +1682,7 @@ namespace PascalABCCompiler
{
PrepareCompileOptionsForProject();
}
//Environment.CurrentDirectory = CompilerOptions.SourceFileDirectory;
Environment.CurrentDirectory = CompilerOptions.SourceFileDirectory; // нужно для подключения *.inc и *.resources
Units = new PascalABCCompiler.TreeRealization.unit_node_list();
CurrentSyntaxUnit = new SyntaxTree.uses_unit_in(new SyntaxTree.string_const(CompilerOptions.SourceFileName));
CompileUnit(Units, CurrentSyntaxUnit);
@ -2370,11 +2370,11 @@ namespace PascalABCCompiler
}
//\MikhailoMMX
/*if (System.IO.File.Exists(FileName))
if (System.IO.File.Exists(FileName)) // для отладки с *.inc файлами
{
return FileName;//.ToLower();//? а надо ли tolover?
}
else*/
else
{
string name = get_assembly_path(FileName,false);//? а надо ли tolover?
if (name == null)

View file

@ -125,7 +125,7 @@ namespace PascalABCCompiler.NETGenerator
protected bool is_dot_expr = false;//флаг, стоит ли после выражения точка (нужно для упаковки размерных типов)
protected TypeInfo cur_ti;//текущий клас
protected CompilerOptions comp_opt = new CompilerOptions();//опции компилятора
protected Dictionary<ICommonNamespaceNode, ISymbolDocumentWriter> sym_docs = new Dictionary<ICommonNamespaceNode, ISymbolDocumentWriter>();//таблица отладочных документов
protected Dictionary<string, ISymbolDocumentWriter> sym_docs = new Dictionary<string, ISymbolDocumentWriter>();//таблица отладочных документов
protected bool is_constructor = false;//флаг, переводим ли мы конструктор
protected bool save_debug_info = false;
protected bool add_special_debug_variables = false;
@ -156,12 +156,35 @@ namespace PascalABCCompiler.NETGenerator
private ISymbolDocumentWriter new_doc;
private List<LocalBuilder> pinned_variables = new List<LocalBuilder>();
private void CheckLocation(SemanticTree.ILocation Location)
{
if (Location != null)
{
ISymbolDocumentWriter temp_doc = null;
if (sym_docs.ContainsKey(Location.document.file_name))
{
temp_doc = sym_docs[Location.document.file_name];
}
else
{
temp_doc = mb.DefineDocument(Location.document.file_name, SymDocumentType.Text, SymLanguageType.Pascal, SymLanguageVendor.Microsoft);
sym_docs.Add(Location.document.file_name, temp_doc);
}
if (temp_doc != doc)
{
doc = temp_doc;
cur_line = -1;
}
}
}
private bool OnNextLine(ILocation loc)
{
if (doc != new_doc)
{
new_doc = doc;
cur_line = 0;
cur_line = loc.begin_line_num;
return true;
}
if (loc.begin_line_num == cur_line) return false;
cur_line = loc.begin_line_num;
@ -180,6 +203,7 @@ namespace PascalABCCompiler.NETGenerator
protected void MarkSequencePoint(SemanticTree.ILocation Location)
{
CheckLocation(Location);
if (Location != null && OnNextLine(Location))
MarkSequencePoint(il, Location);
}
@ -192,7 +216,10 @@ namespace PascalABCCompiler.NETGenerator
protected void MarkSequencePoint(ILGenerator ilg, SemanticTree.ILocation Location)
{
if (Location != null)
{
CheckLocation(Location);
MarkSequencePoint(ilg, Location.begin_line_num, Location.begin_column_num, Location.end_line_num, Location.end_column_num);
}
}
protected void MarkSequencePoint(ILGenerator ilg, int bl, int bc, int el, int ec)
@ -520,13 +547,19 @@ namespace PascalABCCompiler.NETGenerator
first_doc = mb.DefineDocument(SourceFileName, SymDocumentType.Text, SymLanguageType.Pascal, SymLanguageVendor.Microsoft);
for (int iii = 0; iii < cnns.Length; iii++)
{
string cnns_document_file_name = null;
if (cnns[iii].Location != null)
doc = mb.DefineDocument(cnns[iii].Location.document.file_name, SymDocumentType.Text, SymLanguageType.Pascal, SymLanguageVendor.Microsoft);
{
cnns_document_file_name = cnns[iii].Location.document.file_name;
doc = mb.DefineDocument(cnns_document_file_name, SymDocumentType.Text, SymLanguageType.Pascal, SymLanguageVendor.Microsoft);
}
else
doc = first_doc;
sym_docs.Add(cnns[iii], doc);//сохраняем его в таблице документов
if (!sym_docs.ContainsKey(cnns_document_file_name))
sym_docs.Add(cnns_document_file_name, doc);//сохраняем его в таблице документов
}
first_doc = sym_docs[cnns[0]];
first_doc = sym_docs[cnns[0].Location == null ? null : cnns[0].Location.document.file_name];
if (p.main_function != null)
{
if (p.main_function.function_code is IStatementsListNode)
@ -542,7 +575,7 @@ namespace PascalABCCompiler.NETGenerator
//Переводим заголовки типов
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii]];
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? null : cnns[iii].Location.document.file_name];
bool is_main_namespace = cnns[iii].namespace_name == "" && comp_opt.target != TargetType.Dll || comp_opt.target == TargetType.Dll && cnns[iii].namespace_name == "";
ICommonNamespaceNode cnn = cnns[iii];
cur_type = entry_type;
@ -626,7 +659,7 @@ namespace PascalABCCompiler.NETGenerator
}
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii]];
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? null : cnns[iii].Location.document.file_name];
cur_type = NamespacesTypes[cnns[iii]];
cur_unit_type = NamespacesTypes[cnns[iii]];
ConvertTypeMemberHeaders(cnns[iii].types);
@ -637,7 +670,7 @@ namespace PascalABCCompiler.NETGenerator
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii]];
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? null : cnns[iii].Location.document.file_name];
cur_type = NamespacesTypes[cnns[iii]];
cur_unit_type = NamespacesTypes[cnns[iii]];
ConvertFunctionHeaders(cnns[iii].functions);
@ -672,7 +705,7 @@ namespace PascalABCCompiler.NETGenerator
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii]];
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? null : cnns[iii].Location.document.file_name];
cur_type = NamespacesTypes[cnns[iii]];
cur_unit_type = NamespacesTypes[cnns[iii]];
//генерим инциализацию для полей
@ -685,7 +718,7 @@ namespace PascalABCCompiler.NETGenerator
//Переводим заголовки всего остального (процедур, переменных)
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii]];
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? null : cnns[iii].Location.document.file_name];
bool is_main_namespace = iii == cnns.Length - 1 && comp_opt.target != TargetType.Dll;
ICommonNamespaceNode cnn = cnns[iii];
string tmp_unit_name = cur_unit;
@ -744,7 +777,7 @@ namespace PascalABCCompiler.NETGenerator
//переводим реализации
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii]];
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? null : cnns[iii].Location.document.file_name];
bool is_main_namespace = iii == 0 && comp_opt.target != TargetType.Dll;
ICommonNamespaceNode cnn = cnns[iii];
string tmp_unit_name = cur_unit;
@ -764,7 +797,7 @@ namespace PascalABCCompiler.NETGenerator
}
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii]];
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? null : cnns[iii].Location.document.file_name];
cur_type = NamespacesTypes[cnns[iii]];
cur_unit_type = NamespacesTypes[cnns[iii]];
//вставляем ret в int_meth

View file

@ -2319,7 +2319,7 @@ public LexLocation CurrentLexLocation
BufferContext savedCtx = MkBuffCtx();
string full_path = fName;
if (!Path.IsPathRooted(full_path))
full_path = Path.Combine(Path.GetDirectoryName(parsertools.CurrentFileName),fName);
full_path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(parsertools.CurrentFileName), fName));
SetSource(File.ReadAllText(full_path), 0);
fNameStack.Push(parsertools.CurrentFileName);
parsertools.CurrentFileName = full_path;

View file

@ -502,7 +502,7 @@ ALPHABET [^ a-zA-Z_0-9\r\n\t\'$#&,:.;@\+\-\*/=<>\^()\[\]\x01]
BufferContext savedCtx = MkBuffCtx();
string full_path = fName;
if (!Path.IsPathRooted(full_path))
full_path = Path.Combine(Path.GetDirectoryName(parsertools.CurrentFileName),fName);
full_path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(parsertools.CurrentFileName), fName));
SetSource(File.ReadAllText(full_path), 0);
fNameStack.Push(parsertools.CurrentFileName);
parsertools.CurrentFileName = full_path;

View file

@ -39,7 +39,7 @@ namespace PascalABCCompiler.PascalABCNewParser
#endif
PT parsertools = new PT(); // контекст сканера и парсера
parsertools.errors = Errs;
parsertools.CurrentFileName = FileName;
parsertools.CurrentFileName = Path.GetFullPath(FileName);
Scanner scanner = new Scanner();
@ -81,7 +81,7 @@ namespace PascalABCCompiler.PascalABCNewParser
PT parsertools = new PT(); // контекст сканера и парсера
parsertools.errors = Errs;
parsertools.CurrentFileName = FileName;
parsertools.CurrentFileName = Path.GetFullPath(FileName);
var scanner = new PreprocessorScanner();
scanner.SetSource(Text, 0);

View file

@ -745,7 +745,17 @@ namespace QUT.Gppg
/// <param name="last">The last location in the result span</param>
/// <returns>The merged span</returns>
public LexLocation Merge(LexLocation last)
{ return new LexLocation(this.startLine, this.startColumn, last.endLine, last.endColumn); }
{
string n_file_name = null;
if ((last.filename == null))
n_file_name = this.filename;
else
if ((this.filename == null))
n_file_name = last.filename;
else
n_file_name = this.filename;
return new LexLocation(this.startLine, this.startColumn, last.endLine, last.endColumn, n_file_name);
}
public static implicit operator SourceContext(LexLocation loc)
{

View file

@ -0,0 +1,12 @@
procedure InitializeComponent;
begin
self.SuspendLayout();
//
// TestForm
//
self.ClientSize := new System.Drawing.Size(222, 92);
self.Name := 'TestForm';
self.Text := 'Form1';
self.Load += Form1_Load;
self.ResumeLayout(false);
end;

Binary file not shown.

BIN
TestSuite/Form1.fmabc Normal file

Binary file not shown.

30
TestSuite/Form1.pas Normal file
View file

@ -0,0 +1,30 @@
{$reference System.Windows.Forms.dll}
{$reference System.Drawing.dll}
uses System, System.Drawing, System.Windows.Forms;
type
TestForm = class(Form)
procedure Form1_Load(sender: Object; e: EventArgs);
{$region FormDesigner}
private
{$resource Form1.TestForm.resources}
{$include Form1.TestForm.inc}
{$endregion FormDesigner}
public
constructor;
begin
InitializeComponent;
end;
end;
procedure TestForm.Form1_Load(sender: Object; e: EventArgs);
begin
Close;
end;
begin
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(new TestForm)
end.

View file

@ -159,8 +159,11 @@ namespace PascalABCCompiler.TreeConverter
{
return null;
}
location loc = new location(l.begin_line_num, l.begin_column_num, l.end_line_num, l.end_column_num,
syntax_tree_visitor.CurrentDocument);
document d = new document(l.document.file_name);
if (d == null)
d = syntax_tree_visitor.CurrentDocument;
location loc = new location(l.begin_line_num, l.begin_column_num, l.end_line_num, l.end_column_num, d);
return loc;
}

View file

@ -289,7 +289,7 @@ namespace VisualPascalABC
}
foreach (Breakpoint bp in dbg.Breakpoints)
{
if (bp.SourcecodeSegment.SourceFilename == fileName || bp.SourcecodeSegment.StartLine == line)
if (bp.SourcecodeSegment.SourceFilename == fileName && bp.SourcecodeSegment.StartLine == line)
{
added = true;
br = bp;
@ -726,6 +726,7 @@ namespace VisualPascalABC
//debuggedProcess.Modules[0].SymReader.GetMethod(debuggedProcess.SelectedFunction.Token);
if (nextStatement != null)
{
string save_PrevFullFileName = PrevFullFileName;
//CodeFileDocumentControl page = null;
//DebuggerService.JumpToCurrentLine(nextStatement.SourceFullFilename, nextStatement.StartLine, nextStatement.StartColumn, nextStatement.EndLine, nextStatement.EndColumn);
if (!show_debug_tabs)//esli eshe ne pokazany watch i lokal, pokazyvaem
@ -853,7 +854,7 @@ namespace VisualPascalABC
len);
curPage.TextEditor.ActiveTextAreaControl.JumpTo(nextStatement.StartLine - 1, 0);
if ((Status == DebugStatus.StepOver || Status == DebugStatus.StepIn) && CurrentLine == nextStatement.StartLine)
if ((Status == DebugStatus.StepOver || Status == DebugStatus.StepIn) && (CurrentLine == nextStatement.StartLine && save_PrevFullFileName == debuggedProcess.NextStatement.SourceFilename))
{
if (curILOffset != nextStatement.ILOffset)
{
@ -868,7 +869,8 @@ namespace VisualPascalABC
{
curILOffset = nextStatement.ILOffset;
CurrentLine = nextStatement.StartLine;
MustDebug = false;
//MustDebug = false;
MustDebug = ((nextStatement.ILOffset + 1) == nextStatement.ILEnd);
}
//MustDebug = false;
//if (remove_breakpoints)