[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:33 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));
----------------
clayborg wrote:

Use .findRecursively() instead just in case? That will allow a DIE to have a DW_AT_specification or DW_AT_abstract_origin attribute and then find the DW_AT_call_return_pc in the top level DIE or follow the DW_AT_specification or DW_AT_abstract_origin to another die that has this attribute.

https://github.com/llvm/llvm-project/pull/119913


More information about the llvm-commits mailing list