• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MAPLE_IR_INCLUDE_DBG_INFO_H
17 #define MAPLE_IR_INCLUDE_DBG_INFO_H
18 #include <iostream>
19 
20 #include "mpl_logging.h"
21 #include "types_def.h"
22 #include "prim_types.h"
23 #include "mir_nodes.h"
24 #include "mir_scope.h"
25 #include "namemangler.h"
26 #include "lexer.h"
27 #include "dwarf.h"
28 
29 namespace maple {
30 // for more color code: http://ascii-table.com/ansi-escape-sequences.php
31 #define RESET "\x1B[0m"
32 #define BOLD "\x1B[1m"
33 #define RED "\x1B[31m"
34 #define GRN "\x1B[32m"
35 #define YEL "\x1B[33m"
36 
37 const uint32 kDbgDefaultVal = 0xdeadbeef;
38 #define HEX(val) std::hex << "0x" << (val) << std::dec
39 
40 class MIRModule;
41 class MIRType;
42 class MIRSymbol;
43 class MIRSymbolTable;
44 class MIRTypeNameTable;
45 class DBGBuilder;
46 class DBGCompileMsgInfo;
47 class MIRLexer;
48 
49 // for compiletime warnings
50 class DBGLine {
51 public:
DBGLine(uint32 lnum,const char * l)52     DBGLine(uint32 lnum, const char *l) : lineNum(lnum), codeLine(l) {}
~DBGLine()53     virtual ~DBGLine() {}
54 
Dump()55     void Dump()
56     {
57         LogInfo::MapleLogger() << "LINE: " << lineNum << " " << codeLine << std::endl;
58     }
59 
60 private:
61     uint32 lineNum;
62     const char *codeLine;
63 };
64 
65 #define MAXLINELEN 4096
66 
67 class DBGCompileMsgInfo {
68 public:
69     DBGCompileMsgInfo();
~DBGCompileMsgInfo()70     virtual ~DBGCompileMsgInfo() {}
71     void ClearLine(uint32 n);
72     void SetErrPos(uint32 lnum, uint32 cnum);
73     void UpdateMsg(uint32 lnum, const char *line);
74     void EmitMsg();
75 
76 private:
77     uint32 startLine;  // mod 3
78     uint32 errLNum;
79     uint32 errCNum;
80     uint32 errPos;
81     uint32 lineNum[3];
82     uint8 codeLine[3][MAXLINELEN];  // 3 round-robin line buffers
83 };
84 
85 enum DBGDieKind { kDwTag, kDwAt, kDwOp, kDwAte, kDwForm, kDwCfa };
86 
87 typedef uint32 DwTag;   // for DW_TAG_*
88 typedef uint32 DwAt;    // for DW_AT_*
89 typedef uint32 DwOp;    // for DW_OP_*
90 typedef uint32 DwAte;   // for DW_ATE_*
91 typedef uint32 DwForm;  // for DW_FORM_*
92 typedef uint32 DwCfa;   // for DW_CFA_*
93 
94 class DBGDieAttr;
95 
96 class DBGExpr {
97 public:
DBGExpr(MIRModule * m)98     explicit DBGExpr(MIRModule *m) : dwOp(0), value(kDbgDefaultVal), opnds(m->GetMPAllocator().Adapter()) {}
99 
DBGExpr(MIRModule * m,DwOp op)100     DBGExpr(MIRModule *m, DwOp op) : dwOp(op), value(kDbgDefaultVal), opnds(m->GetMPAllocator().Adapter()) {}
101 
~DBGExpr()102     virtual ~DBGExpr() {}
103 
AddOpnd(uint64 val)104     void AddOpnd(uint64 val)
105     {
106         opnds.push_back(val);
107     }
108 
GetVal()109     int GetVal() const
110     {
111         return value;
112     }
113 
SetVal(int v)114     void SetVal(int v)
115     {
116         value = v;
117     }
118 
GetDwOp()119     DwOp GetDwOp() const
120     {
121         return dwOp;
122     }
123 
SetDwOp(DwOp op)124     void SetDwOp(DwOp op)
125     {
126         dwOp = op;
127     }
128 
GetOpnd()129     MapleVector<uint64> &GetOpnd()
130     {
131         return opnds;
132     }
133 
GetOpndSize()134     size_t GetOpndSize() const
135     {
136         return opnds.size();
137     }
138 
Clear()139     void Clear()
140     {
141         return opnds.clear();
142     }
143 
144 private:
145     DwOp dwOp;
146     // for local var fboffset, global var strIdx
147     int value;
148     MapleVector<uint64> opnds;
149 };
150 
151 class DBGExprLoc {
152 public:
DBGExprLoc(MIRModule * m)153     explicit DBGExprLoc(MIRModule *m) : module(m), exprVec(m->GetMPAllocator().Adapter()), symLoc(nullptr)
154     {
155         simpLoc = m->GetMemPool()->New<DBGExpr>(module);
156     }
157 
DBGExprLoc(MIRModule * m,DwOp op)158     DBGExprLoc(MIRModule *m, DwOp op) : module(m), exprVec(m->GetMPAllocator().Adapter()), symLoc(nullptr)
159     {
160         simpLoc = m->GetMemPool()->New<DBGExpr>(module, op);
161     }
162 
~DBGExprLoc()163     virtual ~DBGExprLoc() {}
164 
IsSimp()165     bool IsSimp() const
166     {
167         return (exprVec.size() == 0 && simpLoc->GetVal() != static_cast<int>(kDbgDefaultVal));
168     }
169 
GetFboffset()170     int GetFboffset() const
171     {
172         return simpLoc->GetVal();
173     }
174 
SetFboffset(int offset)175     void SetFboffset(int offset)
176     {
177         simpLoc->SetVal(offset);
178     }
179 
GetGvarStridx()180     int GetGvarStridx() const
181     {
182         return simpLoc->GetVal();
183     }
184 
SetGvarStridx(int idx)185     void SetGvarStridx(int idx)
186     {
187         simpLoc->SetVal(idx);
188     }
189 
GetOp()190     DwOp GetOp() const
191     {
192         return simpLoc->GetDwOp();
193     }
194 
GetSize()195     uint32 GetSize() const
196     {
197         return static_cast<uint32>(simpLoc->GetOpndSize());
198     }
199 
ClearOpnd()200     void ClearOpnd()
201     {
202         simpLoc->Clear();
203     }
204 
AddSimpLocOpnd(uint64 val)205     void AddSimpLocOpnd(uint64 val)
206     {
207         simpLoc->AddOpnd(val);
208     }
209 
GetSimpLoc()210     DBGExpr *GetSimpLoc() const
211     {
212         return simpLoc;
213     }
214 
GetSymLoc()215     void *GetSymLoc()
216     {
217         return symLoc;
218     }
219 
SetSymLoc(void * loc)220     void SetSymLoc(void *loc)
221     {
222         symLoc = loc;
223     }
224 
225     void Dump();
226 
227 private:
228     MIRModule *module;
229     DBGExpr *simpLoc;
230     MapleVector<DBGExpr> exprVec;
231     void *symLoc;
232 };
233 
234 class DBGDieAttr {
235 public:
236     size_t SizeOf(DBGDieAttr *attr);
DBGDieAttr(DBGDieKind k)237     explicit DBGDieAttr(DBGDieKind k) : dieKind(k), dwAttr(DW_AT_deleted), dwForm(DW_FORM_GNU_strp_alt)
238     {
239         value.u = kDbgDefaultVal;
240     }
241 
~DBGDieAttr()242     virtual ~DBGDieAttr() {}
243 
AddSimpLocOpnd(uint64 val)244     void AddSimpLocOpnd(uint64 val)
245     {
246         value.ptr->AddSimpLocOpnd(val);
247     }
248 
ClearSimpLocOpnd()249     void ClearSimpLocOpnd()
250     {
251         value.ptr->ClearOpnd();
252     }
253 
254     void Dump(int indent);
255 
GetKind()256     DBGDieKind GetKind() const
257     {
258         return dieKind;
259     }
260 
SetKind(DBGDieKind kind)261     void SetKind(DBGDieKind kind)
262     {
263         dieKind = kind;
264     }
265 
GetDwAt()266     DwAt GetDwAt() const
267     {
268         return dwAttr;
269     }
270 
SetDwAt(DwAt at)271     void SetDwAt(DwAt at)
272     {
273         dwAttr = at;
274     }
275 
GetDwForm()276     DwForm GetDwForm() const
277     {
278         return dwForm;
279     }
280 
SetDwForm(DwForm form)281     void SetDwForm(DwForm form)
282     {
283         dwForm = form;
284     }
285 
GetI()286     int32 GetI() const
287     {
288         return value.i;
289     }
290 
SetI(int32 val)291     void SetI(int32 val)
292     {
293         value.i = val;
294     }
295 
GetId()296     uint32 GetId() const
297     {
298         return value.id;
299     }
300 
SetId(uint32 val)301     void SetId(uint32 val)
302     {
303         value.id = val;
304     }
305 
GetJ()306     int64 GetJ() const
307     {
308         return value.j;
309     }
310 
SetJ(int64 val)311     void SetJ(int64 val)
312     {
313         value.j = val;
314     }
315 
GetU()316     uint64 GetU() const
317     {
318         return value.u;
319     }
320 
SetU(uint64 val)321     void SetU(uint64 val)
322     {
323         value.u = val;
324     }
325 
GetF()326     float GetF() const
327     {
328         return value.f;
329     }
330 
SetF(float val)331     void SetF(float val)
332     {
333         value.f = val;
334     }
335 
GetD()336     double GetD() const
337     {
338         return value.d;
339     }
340 
SetD(double val)341     void SetD(double val)
342     {
343         value.d = val;
344     }
345 
GetPtr()346     DBGExprLoc *GetPtr()
347     {
348         return value.ptr;
349     }
350 
SetPtr(DBGExprLoc * val)351     void SetPtr(DBGExprLoc *val)
352     {
353         value.ptr = val;
354     }
355 
356 private:
357     DBGDieKind dieKind;
358     DwAt dwAttr;
359     DwForm dwForm;  // type for the attribute value
360     union {
361         int32 i;
362         uint32 id;  // dieId when dwForm is of DW_FORM_ref
363                     // strIdx when dwForm is of DW_FORM_string
364         int64 j;
365         uint64 u;
366         float f;
367         double d;
368 
369         DBGExprLoc *ptr;
370     } value;
371 };
372 
373 class DBGDie {
374 public:
375     DBGDie(MIRModule *m, DwTag tag);
~DBGDie()376     virtual ~DBGDie() {}
377     void AddAttr(DBGDieAttr *attr);
378     void AddSubVec(DBGDie *die);
379 
380     DBGDieAttr *AddAttr(DwAt attr, DwForm form, uint64 val);
381     DBGDieAttr *AddSimpLocAttr(DwAt at, DwForm form, uint64 val);
382     DBGDieAttr *AddGlobalLocAttr(DwAt at, DwForm form, uint64 val);
383     DBGDieAttr *AddFrmBaseAttr(DwAt at, DwForm form);
384     DBGExprLoc *GetExprLoc();
385     bool SetAttr(DwAt attr, uint64 val);
386     bool SetAttr(DwAt attr, int64 val);
387     bool SetAttr(DwAt attr, uint32 val);
388     bool SetAttr(DwAt attr, int32 val);
389     bool SetAttr(DwAt attr, float val);
390     bool SetAttr(DwAt attr, double val);
391     bool SetSimpLocAttr(DwAt attr, int64 val);
392     bool SetAttr(DwAt attr, DBGExprLoc *ptr);
393     void ResetParentDie();
394     void Dump(int indent);
395 
GetId()396     uint32 GetId() const
397     {
398         return id;
399     }
400 
SetId(uint32 val)401     void SetId(uint32 val)
402     {
403         id = val;
404     }
405 
GetTag()406     DwTag GetTag() const
407     {
408         return tag;
409     }
410 
SetTag(DwTag val)411     void SetTag(DwTag val)
412     {
413         tag = val;
414     }
415 
GetWithChildren()416     bool GetWithChildren() const
417     {
418         return withChildren;
419     }
420 
SetWithChildren(bool val)421     void SetWithChildren(bool val)
422     {
423         withChildren = val;
424     }
425 
GetParent()426     DBGDie *GetParent() const
427     {
428         return parent;
429     }
430 
SetParent(DBGDie * val)431     void SetParent(DBGDie *val)
432     {
433         parent = val;
434     }
435 
GetSibling()436     DBGDie *GetSibling() const
437     {
438         return sibling;
439     }
440 
SetSibling(DBGDie * val)441     void SetSibling(DBGDie *val)
442     {
443         sibling = val;
444     }
445 
GetFirstChild()446     DBGDie *GetFirstChild() const
447     {
448         return firstChild;
449     }
450 
SetFirstChild(DBGDie * val)451     void SetFirstChild(DBGDie *val)
452     {
453         firstChild = val;
454     }
455 
GetAbbrevId()456     uint32 GetAbbrevId() const
457     {
458         return abbrevId;
459     }
460 
SetAbbrevId(uint32 val)461     void SetAbbrevId(uint32 val)
462     {
463         abbrevId = val;
464     }
465 
GetTyIdx()466     uint32 GetTyIdx() const
467     {
468         return tyIdx;
469     }
470 
SetTyIdx(uint32 val)471     void SetTyIdx(uint32 val)
472     {
473         tyIdx = val;
474     }
475 
GetOffset()476     uint32 GetOffset() const
477     {
478         return offset;
479     }
480 
SetOffset(uint32 val)481     void SetOffset(uint32 val)
482     {
483         offset = val;
484     }
485 
GetSize()486     uint32 GetSize() const
487     {
488         return size;
489     }
490 
SetSize(uint32 val)491     void SetSize(uint32 val)
492     {
493         size = val;
494     }
495 
GetAttrVec()496     const MapleVector<DBGDieAttr *> &GetAttrVec() const
497     {
498         return attrVec;
499     }
500 
GetAttrVec()501     MapleVector<DBGDieAttr *> &GetAttrVec()
502     {
503         return attrVec;
504     }
505 
GetSubDieVec()506     const MapleVector<DBGDie *> &GetSubDieVec() const
507     {
508         return subDieVec;
509     }
510 
GetSubDieVec()511     MapleVector<DBGDie *> &GetSubDieVec()
512     {
513         return subDieVec;
514     }
515 
GetSubDieVecSize()516     uint32 GetSubDieVecSize() const
517     {
518         return static_cast<uint32>(subDieVec.size());
519     }
520 
GetSubDieVecAt(uint32 i)521     DBGDie *GetSubDieVecAt(uint32 i) const
522     {
523         return subDieVec[i];
524     }
525 
526 private:
527     MIRModule *module;
528     DwTag tag;
529     uint32 id;  // starts from 1 which is root die compUnit
530     bool withChildren;
531     DBGDie *parent;
532     DBGDie *sibling;
533     DBGDie *firstChild;
534     uint32 abbrevId;  // id in .debug_abbrev
535     uint32 tyIdx;     // for type TAG
536     uint32 offset;    // Dwarf CU relative offset
537     uint32 size;      // DIE Size in .debug_info
538     MapleVector<DBGDieAttr *> attrVec;
539     MapleVector<DBGDie *> subDieVec;
540 };
541 
542 class DBGAbbrevEntry {
543 public:
544     DBGAbbrevEntry(MIRModule *m, DBGDie *die);
~DBGAbbrevEntry()545     virtual ~DBGAbbrevEntry() {}
546     bool Equalto(DBGAbbrevEntry *entry);
547     void Dump(int indent);
548 
GetTag()549     DwTag GetTag() const
550     {
551         return tag;
552     }
553 
SetTag(DwTag val)554     void SetTag(DwTag val)
555     {
556         tag = val;
557     }
558 
GetAbbrevId()559     uint32 GetAbbrevId() const
560     {
561         return abbrevId;
562     }
563 
SetAbbrevId(uint32 val)564     void SetAbbrevId(uint32 val)
565     {
566         abbrevId = val;
567     }
568 
GetWithChildren()569     bool GetWithChildren() const
570     {
571         return withChildren;
572     }
573 
SetWithChildren(bool val)574     void SetWithChildren(bool val)
575     {
576         withChildren = val;
577     }
578 
GetAttrPairs()579     MapleVector<uint32> &GetAttrPairs()
580     {
581         return attrPairs;
582     }
583 
584 private:
585     DwTag tag;
586     uint32 abbrevId;
587     bool withChildren;
588     MapleVector<uint32> attrPairs;  // kDwAt kDwForm pairs
589 };
590 
591 class DBGAbbrevEntryVec {
592 public:
DBGAbbrevEntryVec(MIRModule * m,DwTag tag)593     DBGAbbrevEntryVec(MIRModule *m, DwTag tag) : tag(tag), entryVec(m->GetMPAllocator().Adapter()) {}
594 
~DBGAbbrevEntryVec()595     virtual ~DBGAbbrevEntryVec() {}
596 
597     uint32 GetId(MapleVector<uint32> &attrs);
598     void Dump(int indent);
599 
GetTag()600     DwTag GetTag() const
601     {
602         return tag;
603     }
604 
SetTag(DwTag val)605     void SetTag(DwTag val)
606     {
607         tag = val;
608     }
609 
GetEntryvec()610     const MapleVector<DBGAbbrevEntry *> &GetEntryvec() const
611     {
612         return entryVec;
613     }
614 
GetEntryvec()615     MapleVector<DBGAbbrevEntry *> &GetEntryvec()
616     {
617         return entryVec;
618     }
619 
620 private:
621     DwTag tag;
622     MapleVector<DBGAbbrevEntry *> entryVec;
623 };
624 
625 class DebugInfo {
626 public:
DebugInfo(MIRModule * m)627     DebugInfo(MIRModule *m)
628         : module(m),
629           compUnit(nullptr),
630           dummyTypeDie(nullptr),
631           lexer(nullptr),
632           maxId(1),
633           builder(nullptr),
634           mplSrcIdx(0),
635           debugInfoLength(0),
636           curFunction(nullptr),
637           compileMsg(nullptr),
638           parentDieStack(m->GetMPAllocator().Adapter()),
639           idDieMap(std::less<uint32>(), m->GetMPAllocator().Adapter()),
640           abbrevVec(m->GetMPAllocator().Adapter()),
641           tagAbbrevMap(std::less<uint32>(), m->GetMPAllocator().Adapter()),
642           tyIdxDieIdMap(std::less<uint32>(), m->GetMPAllocator().Adapter()),
643           stridxDieIdMap(std::less<uint32>(), m->GetMPAllocator().Adapter()),
644           funcDefStrIdxDieIdMap(std::less<uint32>(), m->GetMPAllocator().Adapter()),
645           typeDefTyIdxMap(std::less<uint32>(), m->GetMPAllocator().Adapter()),
646           pointedPointerMap(std::less<uint32>(), m->GetMPAllocator().Adapter()),
647           funcLstrIdxDieIdMap(std::less<MIRFunction *>(), m->GetMPAllocator().Adapter()),
648           funcLstrIdxLabIdxMap(std::less<MIRFunction *>(), m->GetMPAllocator().Adapter()),
649           strps(std::less<uint32>(), m->GetMPAllocator().Adapter())
650     {
651         /* valid entry starting from index 1 as abbrevid starting from 1 as well */
652         abbrevVec.push_back(nullptr);
653         InitMsg();
654         varPtrPrefix = std::string(namemangler::kPtrPrefixStr);
655     }
656 
~DebugInfo()657     virtual ~DebugInfo() {}
658 
InitMsg()659     void InitMsg()
660     {
661         compileMsg = module->GetMemPool()->New<DBGCompileMsgInfo>();
662     }
663 
UpdateMsg(uint32 lnum,const char * line)664     void UpdateMsg(uint32 lnum, const char *line)
665     {
666         compileMsg->UpdateMsg(lnum, line);
667     }
668 
SetErrPos(uint32 lnum,uint32 cnum)669     void SetErrPos(uint32 lnum, uint32 cnum)
670     {
671         compileMsg->SetErrPos(lnum, cnum);
672     }
673 
EmitMsg()674     void EmitMsg()
675     {
676         compileMsg->EmitMsg();
677     }
678 
GetDie(uint32 id)679     DBGDie *GetDie(uint32 id)
680     {
681         return idDieMap[id];
682     }
683 
GetDummyTypeDie()684     DBGDie *GetDummyTypeDie()
685     {
686         return dummyTypeDie;
687     }
688 
689     DBGDie *GetDie(const MIRFunction *func);
690 
691     void Init();
692     void Finish();
693     void SetupCU();
694     void BuildDebugInfo();
695     void Dump(int indent);
696 
697     // build tree to populate withChildren, sibling, firstChild
698     // also insert DW_AT_sibling attributes when needed
699     void BuildDieTree();
700 
701     // replace type idx with die id in DW_AT_type attributes
702     void FillTypeAttrWithDieId();
703 
704     void BuildAbbrev();
705     uint32 GetAbbrevId(DBGAbbrevEntryVec *, DBGAbbrevEntry *);
706 
707     void SetLocalDie(GStrIdx strIdx, const DBGDie *die);
708     void SetLocalDie(MIRFunction *func, GStrIdx strIdx, const DBGDie *die);
709     DBGDie *GetLocalDie(GStrIdx strIdx);
710     DBGDie *GetLocalDie(MIRFunction *func, GStrIdx strIdx);
711     DBGDie *GetFuncDie(const MIRFunction &func, bool isDeclDie = false);
712 
713     LabelIdx GetLabelIdx(GStrIdx strIdx);
714     LabelIdx GetLabelIdx(MIRFunction *func, GStrIdx strIdx);
715     void SetLabelIdx(GStrIdx strIdx, LabelIdx idx);
716     void SetLabelIdx(MIRFunction *func, GStrIdx strIdx, LabelIdx idx);
717 
GetMaxId()718     uint32 GetMaxId() const
719     {
720         return maxId;
721     }
722 
GetIncMaxId()723     uint32 GetIncMaxId()
724     {
725         return maxId++;
726     }
727 
GetIdDieMapAt(uint32 i)728     DBGDie *GetIdDieMapAt(uint32 i)
729     {
730         return idDieMap[i];
731     }
732 
SetIdDieMap(uint32 i,DBGDie * die)733     void SetIdDieMap(uint32 i, DBGDie *die)
734     {
735         idDieMap[i] = die;
736     }
737 
GetParentDieSize()738     size_t GetParentDieSize() const
739     {
740         return parentDieStack.size();
741     }
742 
GetParentDie()743     DBGDie *GetParentDie()
744     {
745         return parentDieStack.top();
746     }
747 
PushParentDie(DBGDie * die)748     void PushParentDie(DBGDie *die)
749     {
750         parentDieStack.push(die);
751     }
752 
PopParentDie()753     void PopParentDie()
754     {
755         parentDieStack.pop();
756     }
757 
ResetParentDie()758     void ResetParentDie()
759     {
760         parentDieStack.clear();
761         parentDieStack.push(compUnit);
762     }
763 
AddStrps(uint32 val)764     void AddStrps(uint32 val)
765     {
766         strps.insert(val);
767     }
768 
GetStrps()769     MapleSet<uint32> &GetStrps()
770     {
771         return strps;
772     }
773 
GetDebugInfoLength()774     uint32 GetDebugInfoLength() const
775     {
776         return debugInfoLength;
777     }
778 
GetAbbrevVec()779     MapleVector<DBGAbbrevEntry *> &GetAbbrevVec()
780     {
781         return abbrevVec;
782     }
783 
GetCompUnit()784     DBGDie *GetCompUnit() const
785     {
786         return compUnit;
787     }
788 
GetCurFunction()789     MIRFunction *GetCurFunction()
790     {
791         return curFunction;
792     }
793 
SetCurFunction(MIRFunction * func)794     void SetCurFunction(MIRFunction *func)
795     {
796         curFunction = func;
797     }
798 
SetTyidxDieIdMap(const TyIdx tyIdx,const DBGDie * die)799     void SetTyidxDieIdMap(const TyIdx tyIdx, const DBGDie *die)
800     {
801         tyIdxDieIdMap[tyIdx.GetIdx()] = die->GetId();
802     }
803 
804     DBGDieAttr *CreateAttr(DwAt attr, DwForm form, uint64 val);
805 
806     DBGDie *CreateVarDie(MIRSymbol *sym);
807     DBGDie *CreateVarDie(MIRSymbol *sym, GStrIdx strIdx);  // use alt name
808     DBGDie *CreateFormalParaDie(MIRFunction *func, MIRType *type, MIRSymbol *sym);
809     DBGDie *CreateFieldDie(maple::FieldPair pair, uint32 lnum);
810     DBGDie *CreateBitfieldDie(const MIRBitFieldType *type, GStrIdx idx, uint32 prevBits);
811     DBGDie *CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *type, bool update = false);
812     DBGDie *CreateClassTypeDie(GStrIdx strIdx, const MIRClassType *type);
813     DBGDie *CreateInterfaceTypeDie(GStrIdx strIdx, const MIRInterfaceType *type);
814     DBGDie *CreatePointedFuncTypeDie(MIRFuncType *func);
815 
816     DBGDie *GetOrCreateLabelDie(LabelIdx labid);
817     DBGDie *GetOrCreateTypeAttrDie(MIRSymbol *sym);
818     DBGDie *GetOrCreateConstTypeDie(TypeAttrs attr, DBGDie *typedie);
819     DBGDie *GetOrCreateVolatileTypeDie(TypeAttrs attr, DBGDie *typedie);
820     DBGDie *GetOrCreateFuncDeclDie(MIRFunction *func);
821     DBGDie *GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum);
822     DBGDie *GetOrCreatePrimTypeDie(MIRType *ty);
823     DBGDie *GetOrCreateTypeDie(MIRType *type);
824     DBGDie *GetOrCreatePointTypeDie(const MIRPtrType *type);
825     DBGDie *GetOrCreateArrayTypeDie(const MIRArrayType *type);
826     DBGDie *GetOrCreateStructTypeDie(const MIRType *type);
827 
828     void AddAliasDies(MapleMap<GStrIdx, MIRAliasVars> &aliasMap);
829     void AddScopeDie(MIRScope *scope);
830 
831     // Functions for calculating the size and offset of each DW_TAG_xxx and DW_AT_xxx
832     void ComputeSizeAndOffsets();
833     void ComputeSizeAndOffset(DBGDie *die, uint32 &offset);
834 
835 private:
836     MIRModule *module;
837     DBGDie *compUnit;      // root die: compilation unit
838     DBGDie *dummyTypeDie;  // workaround for unknown types
839     MIRLexer *lexer;
840     uint32 maxId;
841     DBGBuilder *builder;
842     GStrIdx mplSrcIdx;
843     uint32 debugInfoLength;
844     MIRFunction *curFunction;
845 
846     // for compilation messages
847     DBGCompileMsgInfo *compileMsg;
848 
849     MapleStack<DBGDie *> parentDieStack;
850     MapleMap<uint32, DBGDie *> idDieMap;
851     MapleVector<DBGAbbrevEntry *> abbrevVec;  // valid entry starting from index 1
852     MapleMap<uint32, DBGAbbrevEntryVec *> tagAbbrevMap;
853 
854     // to be used when derived type references a base type die
855     MapleMap<uint32, uint32> tyIdxDieIdMap;
856     MapleMap<uint32, uint32> stridxDieIdMap;
857     MapleMap<uint32, uint32> funcDefStrIdxDieIdMap;
858     MapleMap<uint32, uint32> typeDefTyIdxMap;  // prevtyIdxtypidx_map
859     MapleMap<uint32, uint32> pointedPointerMap;
860     MapleMap<MIRFunction *, std::map<uint32, uint32>> funcLstrIdxDieIdMap;
861     MapleMap<MIRFunction *, std::map<uint32, LabelIdx>> funcLstrIdxLabIdxMap;
862     MapleSet<uint32> strps;
863     std::string varPtrPrefix;
864 };
865 }  // namespace maple
866 #endif  // MAPLE_IR_INCLUDE_DBG_INFO_H
867