Skip to content

Commit 2d14f02

Browse files
committed
Output DWARF info for local variables
Nothing seems to be showing up, though. Very weird.
1 parent c40fe7a commit 2d14f02

File tree

3 files changed

+74
-18
lines changed

3 files changed

+74
-18
lines changed

src/lisp/kernel/cleavir/debuginfo.lisp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,36 @@
279279
(llvm-sys:get-dilocation (cmp:thread-local-llvm-context)
280280
lineno column *dbg-current-scope*)))
281281

282+
;;; Generate debug info for a variable binding.
283+
(defun di-bind-variable (name alloca spi vrtype)
284+
(when spi
285+
(multiple-value-bind (path line) (spi-info spi)
286+
(let* ((type (vrtype->di vrtype))
287+
(var
288+
(llvm-sys:create-auto-variable
289+
*dibuilder* *dbg-current-scope* name
290+
(ensure-difile path) line type nil (di-zeroflags) 0))
291+
(expr
292+
(llvm-sys:create-expression-none *dibuilder*)))
293+
(llvm-sys:dibuilder/insert-declare
294+
*dibuilder* alloca var expr (get-dilocation spi)
295+
(llvm-sys:get-insert-block cmp:*irbuilder*))))))
296+
297+
;;; Generate debug info for an SSA variable binding.
298+
(defun di-bind-value (name value spi vrtype)
299+
(when spi
300+
(multiple-value-bind (path line) (spi-info spi)
301+
(let* ((type (vrtype->di vrtype))
302+
(var
303+
(llvm-sys:create-auto-variable
304+
*dibuilder* *dbg-current-scope* name
305+
(ensure-difile path) line type nil (di-zeroflags) 0))
306+
(expr
307+
(llvm-sys:create-expression-none *dibuilder*)))
308+
(llvm-sys:dibuilder/insert-dbg-value-intrinsic
309+
*dibuilder* value var expr (get-dilocation spi)
310+
(llvm-sys:get-insert-block cmp:*irbuilder*))))))
311+
282312
;;; if SPI is nil we unset the debug location.
283313
(defun set-instruction-source-position (spi)
284314
(when *generate-dwarf*

src/lisp/kernel/cleavir/translation-environment.lisp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
;;; a little bit more complete.
5656
(defun full-datum-name-as-string (datum)
5757
(let ((*package* (find-package "KEYWORD")))
58-
(write-to-string datum :escape t :readably nil :pretty nil)))
58+
(write-to-string (bir:name datum)
59+
:escape t :readably nil :pretty nil)))
5960

6061
(defgeneric vrtype->llvm (vrtype))
6162
(defmethod vrtype->llvm ((vrtype (eql :object))) cmp:%t*%)
@@ -79,7 +80,6 @@
7980
((:local :dynamic)
8081
;; just an alloca
8182
(let* ((name (datum-name-as-string var))
82-
#+(or)
8383
(fname (full-datum-name-as-string var))
8484
(rtype (cc-bmir:rtype var)))
8585
(if (null rtype)
@@ -91,12 +91,8 @@
9191
(first (cc-bmir:rtype var)))
9292
(t (error "BUG: Bad rtype ~a" rtype))))
9393
(alloca (cmp:alloca (vrtype->llvm vrtype) 1 name))
94-
#+(or)
95-
(spi (origin-spi (bir:origin var))))
96-
;; set up debug info
97-
;; Disable for now - FIXME and get it working
98-
#+(or)(cmp:dbg-variable-alloca alloca fname spi)
99-
;; return
94+
(spi (origin-spi (origin-source (bir:origin var)))))
95+
(di-bind-variable fname alloca spi vrtype)
10096
alloca))))
10197
((:indefinite)
10298
;; make a cell
@@ -204,10 +200,11 @@
204200
(check-type variable bir:variable)
205201
(if (bir:immutablep variable)
206202
(prog1 (setf (gethash variable *datum-values*) value)
207-
;; FIXME - this doesn't work yet
208-
#+(or)(cmp:dbg-variable-value
209-
value (full-datum-name-as-string variable)
210-
(origin-spi (bir:origin variable))))
203+
(let ((rtype (cc-bmir:rtype variable)))
204+
(unless (null rtype)
205+
(di-bind-value (full-datum-name-as-string variable)
206+
value (origin-spi (origin-source (bir:origin variable)))
207+
(first rtype)))))
211208
(if (null (cc-bmir:rtype variable))
212209
value
213210
;; NOTE: For typed loads in the future, use the rtype

src/llvmo/debugInfoExpose.cc

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,42 @@ CL_LAMBDA(dibuilder scope name argno file lineno type always-preserve-p flags an
333333
CL_LISPIFY_NAME(createParameterVariable);
334334
CL_EXTERN_DEFMETHOD(DIBuilder_O, &llvm::DIBuilder::createParameterVariable);
335335

336-
// We don't expose the instruction version since we don't really need it.
336+
// We want to use these instead of manually inserting an intrinsic
337+
// call so that when LLVM transitions to debug info records we
338+
// don't have to do anything.
339+
// (Despite the name, insertDbgValueIntrinsic can insert the new
340+
// records rather than an intrinsic.)
341+
// We don't expose the insert-before-instruction versions as we
342+
// do not need them.
343+
// FIXME: Function instead of a method because we don't really
344+
// care about the DbgInstPtr return value and exposing it would
345+
// be rather complex.
337346
CL_LAMBDA(dibuilder val varinfo expr dilocation basic-block);
338-
CL_LISPIFY_NAME(insertDbgValueIntrinsic);
339-
CL_EXTERN_DEFMETHOD(DIBuilder_O, (llvm::Instruction * (llvm::DIBuilder::*)(llvm::Value * Val, llvm::DILocalVariable* VarInfo,
340-
llvm::DIExpression* Expr, const llvm::DILocation* DL,
341-
llvm::BasicBlock* InsertAtEnd)) &
342-
llvm::DIBuilder::insertDbgValueIntrinsic);
347+
CL_LISPIFY_NAME(dibuilder/insertDbgValueIntrinsic);
348+
CL_DEFUN void llvm_sys__insert_dbg_value(llvm::DIBuilder& DIBuilder,
349+
llvm::Value* V,
350+
llvm::DILocalVariable* VarInfo,
351+
llvm::DIExpression* Expr,
352+
DILocation_sp DL,
353+
llvm::BasicBlock* InsertAtEnd)
354+
{
355+
// FIXME: why not just use from_object?
356+
// This is cargo-culted from IRBuilderBase_O::SetCurrentDebugLocation
357+
llvm::DILocation* real_diloc = DL->operator llvm::DILocation*();
358+
DIBuilder.insertDbgValueIntrinsic(V, VarInfo, Expr, real_diloc, InsertAtEnd);
359+
}
360+
CL_LAMBDA(dibuilder val varinfo expr dilocation basic-block);
361+
CL_LISPIFY_NAME(dibuilder/insertDeclare);
362+
CL_DEFUN void llvm_sys__insert_declare(llvm::DIBuilder& DIBuilder,
363+
llvm::Value* Storage,
364+
llvm::DILocalVariable* VarInfo,
365+
llvm::DIExpression* Expr,
366+
DILocation_sp DL,
367+
llvm::BasicBlock* InsertAtEnd)
368+
{
369+
llvm::DILocation* real_diloc = DL->operator llvm::DILocation*();
370+
DIBuilder.insertDeclare(Storage, VarInfo, Expr, real_diloc, InsertAtEnd);
371+
}
343372

344373
CL_LAMBDA(dibuilder);
345374
CL_LISPIFY_NAME(finalize);

0 commit comments

Comments
 (0)