@@ -892,32 +892,106 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
892
892
ContextCU->addDIEEntry (*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
893
893
}
894
894
895
- DIE &DwarfCompileUnit::constructCallSiteEntryDIE (DIE &ScopeDIE,
896
- const DISubprogram &CalleeSP,
897
- bool IsTail,
898
- const MCExpr *PCOffset) {
899
- // Insert a call site entry DIE within ScopeDIE.
900
- DIE &CallSiteDIE =
901
- createAndAddDIE (dwarf::DW_TAG_call_site, ScopeDIE, nullptr );
895
+ dwarf::Tag DwarfCompileUnit::getDwarf5OrGNUCallSiteTag (dwarf::Tag Tag) const {
896
+ bool ApplyGNUExtensions = DD->getDwarfVersion () == 4 && DD->tuneForGDB ();
897
+ if (!ApplyGNUExtensions)
898
+ return Tag;
899
+ switch (Tag) {
900
+ case dwarf::DW_TAG_call_site:
901
+ return dwarf::DW_TAG_GNU_call_site;
902
+ case dwarf::DW_TAG_call_site_parameter:
903
+ return dwarf::DW_TAG_GNU_call_site_parameter;
904
+ default :
905
+ llvm_unreachable (" unhandled call site tag" );
906
+ }
907
+ }
902
908
903
- // For the purposes of showing tail call frames in backtraces, a key piece of
904
- // information is DW_AT_call_origin, a pointer to the callee DIE.
905
- DIE *CalleeDIE = getOrCreateSubprogramDIE (&CalleeSP);
906
- assert (CalleeDIE && " Could not create DIE for call site entry origin" );
907
- addDIEEntry (CallSiteDIE, dwarf::DW_AT_call_origin, *CalleeDIE);
909
+ dwarf::Attribute
910
+ DwarfCompileUnit::getDwarf5OrGNUCallSiteAttr (dwarf::Attribute Attr) const {
911
+ bool ApplyGNUExtensions = DD->getDwarfVersion () == 4 && DD->tuneForGDB ();
912
+ if (!ApplyGNUExtensions)
913
+ return Attr;
914
+ switch (Attr) {
915
+ case dwarf::DW_AT_call_all_calls:
916
+ return dwarf::DW_AT_GNU_all_call_sites;
917
+ case dwarf::DW_AT_call_target:
918
+ return dwarf::DW_AT_GNU_call_site_target;
919
+ case dwarf::DW_AT_call_origin:
920
+ return dwarf::DW_AT_abstract_origin;
921
+ case dwarf::DW_AT_call_pc:
922
+ return dwarf::DW_AT_low_pc;
923
+ case dwarf::DW_AT_call_value:
924
+ return dwarf::DW_AT_GNU_call_site_value;
925
+ case dwarf::DW_AT_call_tail_call:
926
+ return dwarf::DW_AT_GNU_tail_call;
927
+ default :
928
+ llvm_unreachable (" unhandled call site attribute" );
929
+ }
930
+ }
908
931
909
- if (IsTail) {
910
- // Attach DW_AT_call_tail_call to tail calls for standards compliance.
911
- addFlag (CallSiteDIE, dwarf::DW_AT_call_tail_call);
932
+ DIE &DwarfCompileUnit::constructCallSiteEntryDIE (
933
+ DIE &ScopeDIE, const DISubprogram *CalleeSP, bool IsTail,
934
+ const MCSymbol *PCAddr, const MCExpr *PCOffset, unsigned CallReg) {
935
+ // Insert a call site entry DIE within ScopeDIE.
936
+ DIE &CallSiteDIE = createAndAddDIE (
937
+ getDwarf5OrGNUCallSiteTag (dwarf::DW_TAG_call_site), ScopeDIE, nullptr );
938
+
939
+ if (CallReg) {
940
+ // Indirect call.
941
+ addAddress (CallSiteDIE,
942
+ getDwarf5OrGNUCallSiteAttr (dwarf::DW_AT_call_target),
943
+ MachineLocation (CallReg));
912
944
} else {
913
- // Attach the return PC to allow the debugger to disambiguate call paths
914
- // from one function to another.
945
+ DIE *CalleeDIE = getOrCreateSubprogramDIE (CalleeSP);
946
+ assert (CalleeDIE && " Could not create DIE for call site entry origin" );
947
+ addDIEEntry (CallSiteDIE,
948
+ getDwarf5OrGNUCallSiteAttr (dwarf::DW_AT_call_origin),
949
+ *CalleeDIE);
950
+ }
951
+
952
+ if (IsTail)
953
+ // Attach DW_AT_call_tail_call to tail calls for standards compliance.
954
+ addFlag (CallSiteDIE,
955
+ getDwarf5OrGNUCallSiteAttr (dwarf::DW_AT_call_tail_call));
956
+
957
+ // Attach the return PC to allow the debugger to disambiguate call paths
958
+ // from one function to another.
959
+ if (DD->getDwarfVersion () == 4 && DD->tuneForGDB ()) {
960
+ assert (PCAddr && " Missing PC information for a call" );
961
+ addLabelAddress (CallSiteDIE, dwarf::DW_AT_low_pc, PCAddr);
962
+ } else if (!IsTail || DD->tuneForGDB ()) {
915
963
assert (PCOffset && " Missing return PC information for a call" );
916
964
addAddressExpr (CallSiteDIE, dwarf::DW_AT_call_return_pc, PCOffset);
917
965
}
966
+
918
967
return CallSiteDIE;
919
968
}
920
969
970
+ void DwarfCompileUnit::constructCallSiteParmEntryDIEs (
971
+ DIE &CallSiteDIE, SmallVector<DbgCallSiteParam, 4 > &Params) {
972
+ for (const auto &Param : Params) {
973
+ unsigned Register = Param.getRegister ();
974
+ auto CallSiteDieParam =
975
+ DIE::get (DIEValueAllocator,
976
+ getDwarf5OrGNUCallSiteTag (dwarf::DW_TAG_call_site_parameter));
977
+ insertDIE (CallSiteDieParam);
978
+ addAddress (*CallSiteDieParam, dwarf::DW_AT_location,
979
+ MachineLocation (Register));
980
+
981
+ DIELoc *Loc = new (DIEValueAllocator) DIELoc;
982
+ DIEDwarfExpression DwarfExpr (*Asm, *this , *Loc);
983
+ DwarfExpr.setCallSiteParamValueFlag ();
984
+
985
+ DwarfDebug::emitDebugLocValue (*Asm, nullptr , Param.getValue (), DwarfExpr);
986
+
987
+ addBlock (*CallSiteDieParam,
988
+ getDwarf5OrGNUCallSiteAttr (dwarf::DW_AT_call_value),
989
+ DwarfExpr.finalize ());
990
+
991
+ CallSiteDIE.addChild (CallSiteDieParam);
992
+ }
993
+ }
994
+
921
995
DIE *DwarfCompileUnit::constructImportedEntityDIE (
922
996
const DIImportedEntity *Module) {
923
997
DIE *IMDie = DIE::get (DIEValueAllocator, (dwarf::Tag)Module->getTag ());
0 commit comments