authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-30 19:31:01+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-30 19:33:03+02:00
logfb4a5ccdeeddf56a0849b4168fe7a9525f36b107
treeb73a5a59ddb6850ee9c69d2ee8fbbc17126b4d44
parente4fd9acc2a7682d0d64d6d42e2882967cf3877aa

llvm: make debuggers actually usable

`@llvm.dbg.value` is absolutely useless, adding a temporary alloca to store the constant in will make it actually show up in debuggers. The effect on performance should be minimal since there is only one store and it the change is not applied to ReleaseSafe builds. ```zig fn foo(a: u32, b: []const u8, c: bool, d: enum { yes, no }) void { _ = a; _ = b; _ = c; _ = d; } ``` before: ``` Breakpoint 1, a.foo (a=<optimized out>, b=..., c=<optimized out>, d=<optimized out>) at a.zig:18 18 _ = d; ``` after: ``` Breakpoint 1, a.foo (a=1, b=..., c=false, d=yes) at a.zig:15 15 _ = a; _ = b; _ = c; _ = d; (gdb) p b $1 = {ptr = 0x20854f <a.main.anon_3888> "bar", len = 3} ```

1 files changed, 12 insertions(+), 0 deletions(-)

src/codegen/llvm.zig+12
......@@ -6088,6 +6088,12 @@ pub const FuncGen = struct {
60886088 const insert_block = self.builder.getInsertBlock();
60896089 if (isByRef(operand_ty)) {
60906090 _ = dib.insertDeclareAtEnd(operand, di_local_var, debug_loc, insert_block);
6091 } else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) {
6092 const alignment = operand_ty.abiAlignment(self.dg.module.getTarget());
6093 const alloca = self.buildAlloca(operand.typeOf(), alignment);
6094 const store_inst = self.builder.buildStore(operand, alloca);
6095 store_inst.setAlignment(alignment);
6096 _ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block);
60916097 } else {
60926098 _ = dib.insertDbgValueIntrinsicAtEnd(operand, di_local_var, debug_loc, insert_block);
60936099 }
......@@ -8026,6 +8032,12 @@ pub const FuncGen = struct {
80268032 const insert_block = self.builder.getInsertBlock();
80278033 if (isByRef(inst_ty)) {
80288034 _ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block);
8035 } else if (self.dg.module.comp.bin_file.options.optimize_mode == .Debug) {
8036 const alignment = inst_ty.abiAlignment(self.dg.module.getTarget());
8037 const alloca = self.buildAlloca(arg_val.typeOf(), alignment);
8038 const store_inst = self.builder.buildStore(arg_val, alloca);
8039 store_inst.setAlignment(alignment);
8040 _ = dib.insertDeclareAtEnd(alloca, di_local_var, debug_loc, insert_block);
80298041 } else {
80308042 _ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block);
80318043 }