Skip to content

Commit 5ae44bf

Browse files
authored
[LoongArch] Add debug location for register reload
Although the automatically inserted reload instruction in the `Epilogue` is unrelated to the original code, in order to improve debugger functionality, we have re-added debugging location information in the reload instruction. When using an empty debugging location, the following issue occurs: ``` loongson@linux:~$ cat -n test.c 1 int printf(const char *, ...); 2 int main(int argc, char **argv) { 3 printf("%d\n", argc); 4 return 0; 5 } clang -g -O0 test.c -o test ``` Without this patch, the debugger is unable to correctly access the current stack information when a breakpoint is set on line 4: ``` loongson@linux:~$ gdb -q ./test Reading symbols from ./test... (gdb) break 4 Breakpoint 1 at 0x7c0: file test.c, line 4. (gdb) run Starting program: /home/wanglei/test [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/loongarch64-linux-gnu/libthread_db.so.1". 1 Breakpoint 1, main (argc=<error reading variable: Cannot access memory at address 0xffffffffffffffe8>, argv=<error reading variable: Cannot access memory at address 0xffffffffffffffe0>) at test.c:4 4 return 0; ``` Reviewed By: heiher, xen0n Pull Request: #122057
1 parent fce0314 commit 5ae44bf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ void LoongArchInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
154154
Register VReg) const {
155155
MachineFunction *MF = MBB.getParent();
156156
MachineFrameInfo &MFI = MF->getFrameInfo();
157+
DebugLoc DL;
158+
if (I != MBB.end())
159+
DL = I->getDebugLoc();
157160

158161
unsigned Opcode;
159162
if (LoongArch::GPRRegClass.hasSubClassEq(RC))
@@ -177,7 +180,7 @@ void LoongArchInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
177180
MachinePointerInfo::getFixedStack(*MF, FI), MachineMemOperand::MOLoad,
178181
MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
179182

180-
BuildMI(MBB, I, DebugLoc(), get(Opcode), DstReg)
183+
BuildMI(MBB, I, DL, get(Opcode), DstReg)
181184
.addFrameIndex(FI)
182185
.addImm(0)
183186
.addMemOperand(MMO);

0 commit comments

Comments
 (0)