Skip to content

Commit

Permalink
Output DWARF info for local variables
Browse files Browse the repository at this point in the history
Nothing seems to be showing up, though. Very weird.
  • Loading branch information
Bike committed May 16, 2024
1 parent 6bce0d9 commit 5b40490
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 18 deletions.
30 changes: 30 additions & 0 deletions src/lisp/kernel/cleavir/debuginfo.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,36 @@
(llvm-sys:get-dilocation (cmp:thread-local-llvm-context)
lineno column *dbg-current-scope*)))

;;; Generate debug info for a variable binding.
(defun di-bind-variable (name alloca spi vrtype)
(when spi
(multiple-value-bind (path line) (spi-info spi)
(let* ((type (vrtype->di vrtype))
(var
(llvm-sys:create-auto-variable
*dibuilder* *dbg-current-scope* name
(ensure-difile path) line type nil (di-zeroflags) 0))
(expr
(llvm-sys:create-expression-none *dibuilder*)))
(llvm-sys:dibuilder/insert-declare
*dibuilder* alloca var expr (get-dilocation spi)
(llvm-sys:get-insert-block cmp:*irbuilder*))))))

;;; Generate debug info for an SSA variable binding.
(defun di-bind-value (name value spi vrtype)
(when spi
(multiple-value-bind (path line) (spi-info spi)
(let* ((type (vrtype->di vrtype))
(var
(llvm-sys:create-auto-variable
*dibuilder* *dbg-current-scope* name
(ensure-difile path) line type nil (di-zeroflags) 0))
(expr
(llvm-sys:create-expression-none *dibuilder*)))
(llvm-sys:dibuilder/insert-dbg-value-intrinsic
*dibuilder* value var expr (get-dilocation spi)
(llvm-sys:get-insert-block cmp:*irbuilder*))))))

;;; if SPI is nil we unset the debug location.
(defun set-instruction-source-position (spi)
(when *generate-dwarf*
Expand Down
21 changes: 9 additions & 12 deletions src/lisp/kernel/cleavir/translation-environment.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
;;; a little bit more complete.
(defun full-datum-name-as-string (datum)
(let ((*package* (find-package "KEYWORD")))
(write-to-string datum :escape t :readably nil :pretty nil)))
(write-to-string (bir:name datum)
:escape t :readably nil :pretty nil)))

(defgeneric vrtype->llvm (vrtype))
(defmethod vrtype->llvm ((vrtype (eql :object))) cmp:%t*%)
Expand All @@ -79,7 +80,6 @@
((:local :dynamic)
;; just an alloca
(let* ((name (datum-name-as-string var))
#+(or)
(fname (full-datum-name-as-string var))
(rtype (cc-bmir:rtype var)))
(if (null rtype)
Expand All @@ -91,12 +91,8 @@
(first (cc-bmir:rtype var)))
(t (error "BUG: Bad rtype ~a" rtype))))
(alloca (cmp:alloca (vrtype->llvm vrtype) 1 name))
#+(or)
(spi (origin-spi (bir:origin var))))
;; set up debug info
;; Disable for now - FIXME and get it working
#+(or)(cmp:dbg-variable-alloca alloca fname spi)
;; return
(spi (origin-spi (origin-source (bir:origin var)))))
(di-bind-variable fname alloca spi vrtype)
alloca))))
((:indefinite)
;; make a cell
Expand Down Expand Up @@ -204,10 +200,11 @@
(check-type variable bir:variable)
(if (bir:immutablep variable)
(prog1 (setf (gethash variable *datum-values*) value)
;; FIXME - this doesn't work yet
#+(or)(cmp:dbg-variable-value
value (full-datum-name-as-string variable)
(origin-spi (bir:origin variable))))
(let ((rtype (cc-bmir:rtype variable)))
(unless (null rtype)
(di-bind-value (full-datum-name-as-string variable)
value (origin-spi (origin-source (bir:origin variable)))
(first rtype)))))
(if (null (cc-bmir:rtype variable))
value
;; NOTE: For typed loads in the future, use the rtype
Expand Down
41 changes: 35 additions & 6 deletions src/llvmo/debugInfoExpose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,42 @@ CL_LAMBDA(dibuilder scope name argno file lineno type always-preserve-p flags an
CL_LISPIFY_NAME(createParameterVariable);
CL_EXTERN_DEFMETHOD(DIBuilder_O, &llvm::DIBuilder::createParameterVariable);

// We don't expose the instruction version since we don't really need it.
// We want to use these instead of manually inserting an intrinsic
// call so that when LLVM transitions to debug info records we
// don't have to do anything.
// (Despite the name, insertDbgValueIntrinsic can insert the new
// records rather than an intrinsic.)
// We don't expose the insert-before-instruction versions as we
// do not need them.
// FIXME: Function instead of a method because we don't really
// care about the DbgInstPtr return value and exposing it would
// be rather complex.
CL_LAMBDA(dibuilder val varinfo expr dilocation basic-block);
CL_LISPIFY_NAME(insertDbgValueIntrinsic);
CL_EXTERN_DEFMETHOD(DIBuilder_O, (llvm::Instruction * (llvm::DIBuilder::*)(llvm::Value * Val, llvm::DILocalVariable* VarInfo,
llvm::DIExpression* Expr, const llvm::DILocation* DL,
llvm::BasicBlock* InsertAtEnd)) &
llvm::DIBuilder::insertDbgValueIntrinsic);
CL_LISPIFY_NAME(dibuilder/insertDbgValueIntrinsic);
CL_DEFUN void llvm_sys__insert_dbg_value(llvm::DIBuilder& DIBuilder,
llvm::Value* V,
llvm::DILocalVariable* VarInfo,
llvm::DIExpression* Expr,
DILocation_sp DL,
llvm::BasicBlock* InsertAtEnd)
{
// FIXME: why not just use from_object?
// This is cargo-culted from IRBuilderBase_O::SetCurrentDebugLocation
llvm::DILocation* real_diloc = DL->operator llvm::DILocation*();
DIBuilder.insertDbgValueIntrinsic(V, VarInfo, Expr, real_diloc, InsertAtEnd);
}
CL_LAMBDA(dibuilder val varinfo expr dilocation basic-block);
CL_LISPIFY_NAME(dibuilder/insertDeclare);
CL_DEFUN void llvm_sys__insert_declare(llvm::DIBuilder& DIBuilder,
llvm::Value* Storage,
llvm::DILocalVariable* VarInfo,
llvm::DIExpression* Expr,
DILocation_sp DL,
llvm::BasicBlock* InsertAtEnd)
{
llvm::DILocation* real_diloc = DL->operator llvm::DILocation*();
DIBuilder.insertDeclare(Storage, VarInfo, Expr, real_diloc, InsertAtEnd);
}

CL_LAMBDA(dibuilder);
CL_LISPIFY_NAME(finalize);
Expand Down

0 comments on commit 5b40490

Please sign in to comment.