[llvm] [llvm-gsymutil] Add option to load callsites from DWARF (PR #119913)
Greg Clayton via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 16 13:31:34 PST 2024
================
@@ -553,6 +558,58 @@ void DwarfTransformer::handleDie(OutputAggregator &Out, CUInfo &CUI,
handleDie(Out, CUI, ChildDie);
}
+void DwarfTransformer::parseCallSiteInfoFromDwarf(CUInfo &CUI, DWARFDie Die,
+ FunctionInfo &FI) {
+ // Parse all DW_TAG_call_site DIEs that are children of this subprogram DIE.
+ // DWARF specification:
+ // - DW_TAG_call_site can have DW_AT_call_return_pc for return address offset.
+ // - DW_AT_call_origin might point to a DIE of the function being called.
+ // For simplicity, we will just extract return_offset and possibly target name
+ // if available.
+
+ CallSiteInfoCollection CSIC;
+
+ for (DWARFDie Child : Die.children()) {
+ if (Child.getTag() != dwarf::DW_TAG_call_site)
+ continue;
+
+ CallSiteInfo CSI;
+ // DW_AT_call_return_pc: the return PC (address). We'll convert it to
+ // offset relative to FI's start.
+ auto ReturnPC = dwarf::toAddress(Child.find(dwarf::DW_AT_call_return_pc));
+ if (!ReturnPC || *ReturnPC < FI.startAddress() ||
+ *ReturnPC >= FI.endAddress())
+ continue;
+
+ CSI.ReturnOffset = *ReturnPC - FI.startAddress();
+
+ // Attempt to get function name from DW_AT_call_origin. If present, we can
+ // insert it as a match regex.
+ if (DWARFDie OriginDie =
+ Child.getAttributeValueAsReferencedDie(dwarf::DW_AT_call_origin)) {
+ if (auto Name = OriginDie.getName(DINameKind::ShortName)) {
----------------
clayborg wrote:
You might want the linkage name instead:
```
0x0000002d: DW_TAG_subprogram
DW_AT_linkage_name ("_Z3foov")
DW_AT_name ("foo")
DW_AT_decl_file ("/Users/gclayton/Documents/src/inlined/main.cpp")
DW_AT_decl_line (3)
DW_AT_type (0x0000000000000036 "int")
DW_AT_external (true)
DW_AT_inline (DW_INL_inlined)
```
Use `DWARFDie::getLinkageName()` first, and if that returns NULL, then use `DWARFDie::getShortName()`
https://github.com/llvm/llvm-project/pull/119913
More information about the llvm-commits
mailing list