Skip to content

Commit 2a568ce

Browse files
committed
add support for debugging with gas
1 parent a674c8d commit 2a568ce

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

source/backends/x86_64.d

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class BackendX86_64 : CompilerBackend {
5050
uint tempLabelNum;
5151
bool useGas = false;
5252
bool useFramePtr = true;
53+
int[string] fileID;
5354

5455
this() {
5556
output = new Output();
@@ -112,6 +113,21 @@ class BackendX86_64 : CompilerBackend {
112113
);
113114
}
114115

116+
int GetMaxFileID() {
117+
int ret = 0;
118+
foreach (key, value ; fileID) {
119+
if (value > ret) ret = value;
120+
}
121+
return ret;
122+
}
123+
124+
int GetOrCreateFileID(string file) {
125+
if (file !in fileID) {
126+
fileID[file] = GetMaxFileID() + 1;
127+
}
128+
return fileID[file];
129+
}
130+
115131
string TempLabel() {
116132
++ tempLabelNum;
117133
return format("__temp_%d", tempLabelNum);
@@ -260,6 +276,28 @@ class BackendX86_64 : CompilerBackend {
260276
}
261277
}
262278

279+
override void BeforeCompile(Node node) {
280+
static string thisFile;
281+
282+
if (useDebug && useGas) {
283+
if (thisFile != node.error.file) {
284+
thisFile = node.error.file;
285+
286+
if (node.error.file !in fileID) {
287+
output ~= format(
288+
".file %d \"%s\"\n", GetOrCreateFileID(node.error.file),
289+
node.error.file
290+
);
291+
}
292+
}
293+
294+
output ~= format(
295+
".loc %d %d %d\n", GetOrCreateFileID(node.error.file),
296+
node.error.line + 1, node.error.col + 1
297+
);
298+
}
299+
}
300+
263301
override void BeginMain() {
264302
output ~= "__calmain:\n";
265303

@@ -774,11 +812,6 @@ class BackendX86_64 : CompilerBackend {
774812
}
775813

776814
if (node.inline) {
777-
if (node.errors) {
778-
output ~= format("lea rax, __global_%s\n", Sanitise("_cal_exception"));
779-
output ~= "mov [rax], 0\n";
780-
}
781-
782815
words[node.name] = Word(
783816
WordType.Callisto, true, node.nodes, node.errors, params
784817
);

source/compiler.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class CompilerBackend {
103103
abstract string DefaultHeader();
104104
abstract bool HandleOption(string opt, ref string[] versions, Preprocessor preproc);
105105

106+
void BeforeCompile(Node node) {}
107+
106108
abstract void BeginMain();
107109

108110
abstract void Init();
@@ -404,6 +406,8 @@ class Compiler {
404406
}
405407

406408
void CompileNode(Node inode) {
409+
backend.BeforeCompile(inode);
410+
407411
switch (inode.type) {
408412
case NodeType.Word: {
409413
auto node = cast(WordNode) inode;

0 commit comments

Comments
 (0)