[llvm] [llvm-gsymutil] Add option to load callsites from DWARF (PR #119913)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 16:43:54 PST 2024


================
@@ -553,6 +558,57 @@ 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) {
+      CallSiteInfo CSI;
+      // DW_AT_call_return_pc: the return PC (address). We'll convert it to
+      // offset relative to FI's start.
+      uint64_t ReturnPC =
+          dwarf::toAddress(Child.find(dwarf::DW_AT_call_return_pc), 0);
+      if (ReturnPC < FI.startAddress() || ReturnPC >= FI.endAddress())
+        continue;
----------------
ellishg wrote:

I think we should use the `optional` version of `toAddress()` so we skip this die if it doesn't have a `DW_AT_call_return_pc`.
```suggestion
      auto ReturnPC =
          dwarf::toAddress(Child.find(dwarf::DW_AT_call_return_pc));
      if (!ReturnPC || *ReturnPC < FI.startAddress() || *ReturnPC >= FI.endAddress())
        continue;
```

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


More information about the llvm-commits mailing list