]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
stackprof.cxx minor fixes: tweak the maxframes logic
authorSerhei Makarov <serhei@serhei.io>
Mon, 9 Feb 2026 17:14:12 +0000 (12:14 -0500)
committerSerhei Makarov <serhei@serhei.io>
Mon, 9 Feb 2026 17:14:15 +0000 (12:14 -0500)
Since this is now an intended performance optimization (unwind exactly
N frames) rather than a rough safety tripwire, make sure the number of
frames returned is exact.

src/stackprof.cxx

index 679ba403e255f56758330bb8599cd645b1eae3d0..e9bd7042c5533d36b988088c35b20ca0bcd58160 100644 (file)
@@ -1437,15 +1437,17 @@ int PerfConsumerUnwinder::unwind_frame_cb(Dwfl_Frame *state)
 #endif
     }
 
-  // e.g. gmon callgraphs only requires maxframes=1 (caller ID only)
+  this->last_us.sp = sp;
+  this->last_us.addrs.push_back(pc);
+
+  /* e.g. gmon callgraphs only requires maxframes=1
+     (initial pc + one frame for caller ID only) */
   if (this->last_us.addrs.size() > this->maxframes)
     {
-      /* XXX very rarely, the unwinder can loop infinitely; worth investigating? */
+      /* XXX without maxframes, very rarely, the unwinder can loop
+        infinitely; worth investigating? */
       return DWARF_CB_ABORT;
     }
-
-  this->last_us.sp = sp;
-  this->last_us.addrs.push_back(pc);
   return DWARF_CB_OK;
 }