access-softek / llvm-project

Other
0 stars 0 forks source link

Implement debug information emitting for MSP430 #26

Closed atrosinenko closed 4 years ago

atrosinenko commented 4 years ago

When debugging MSP430 code, it would be very useful to have at least the line number information. For example, it highly speeds up debugging where UBSan was triggered.

I have patched my working copy like this:

diff --git a/llvm/lib/Target/MSP430/MCTargetDesc/MSP430MCAsmInfo.cpp b/llvm/lib/Target/MSP430/MCTargetDesc/MSP430MCAsmInfo.cpp
index 6117567dcae..08928bdc785 100644
--- a/llvm/lib/Target/MSP430/MCTargetDesc/MSP430MCAsmInfo.cpp
+++ b/llvm/lib/Target/MSP430/MCTargetDesc/MSP430MCAsmInfo.cpp
@@ -24,4 +24,8 @@ MSP430MCAsmInfo::MSP430MCAsmInfo(const Triple &TT,

   AlignmentIsInBytes = false;
   UsesELFSectionDirectiveForBSS = true;
+
+  SupportsDebugInformation = true;
 }
diff --git a/llvm/lib/Target/MSP430/MSP430RegisterInfo.td b/llvm/lib/Target/MSP430/MSP430RegisterInfo.td
index 24d94c1739f..36f8970d582 100644
--- a/llvm/lib/Target/MSP430/MSP430RegisterInfo.td
+++ b/llvm/lib/Target/MSP430/MSP430RegisterInfo.td
@@ -19,11 +19,12 @@ class MSP430Reg<bits<4> num, string n, list<string> alt = []> : Register<n> {

 class MSP430RegWithSubregs<bits<4> num, string n, list<Register> subregs,
                            list<string> alt = []> 
-  : RegisterWithSubRegs<n, subregs> {
+  : RegisterWithSubRegs<n, subregs>, DwarfRegNum<[num]> {
   field bits<4> Num = num;
   let Namespace = "MSP430";
   let HWEncoding{3-0} = num;
   let AltNames = alt;
 }

 //===----------------------------------------------------------------------===//

And it seems to basically work. The DWARF3 register numbers are taken from MSP430 EABI document (subregister handling is still to-be-written). On the other hand, other targets such as X86 involve some non-trivial DWARF-related code in the TargetFrameLowering passes, for example.

If there is some well-known simple way to get at least basic debug info support in LLVM (possibly not too comprehensive but non-misleading), I would want to work on it.

asl commented 4 years ago

I guess the key point is whether we're ok with DWARF debug info emission for 16-bit target...

atrosinenko commented 4 years ago

Frankly speaking, I'm not significantly familiar with any particular debug info format. So it was the MSP430 EABI document (part 10) I repeated the particular "DWARF version 3" after :) So, it seems to be already used on 16-bit target.

atrosinenko commented 4 years ago

Closing, as the fix was already upstreamed: 1, 2 and follow-up fix.