]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEV: dev/gdb: add fdtab dump
authorWilly Tarreau <w@1wt.eu>
Wed, 27 May 2026 16:51:28 +0000 (18:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 1 Jun 2026 17:08:42 +0000 (19:08 +0200)
Three functions are provided here:
  fd_dump: lists all FDs
  fd_dump_conn: lists all FDs holding a connection
  fd_dump_listener: lists all FDs holding a listener

They take no argument, and dump some of the known info. E.g. for
a connection, ctrl, xprt, flags, mux, sessions, frontend's name
and session's age are reported. Example:

  (gdb) fd_dump_conn
  fd    31: rm=0 tm=0x2 um=0 st=0x21 refc=0x1 tkov=0 gen=0 conn=0x7fffe803b600: flg=0x300 err=0 ctrl=0xdf51c0 xprt=0xdf5c80 mux=0xbaeee0 sess=0x7ffff003b570: fe=0x1e45b00 id=foo age=0ms

They are particularly slow because they iterate over all possible FDs,
so better limit them to the desired types.

dev/gdb/fd.gdb [new file with mode: 0644]

diff --git a/dev/gdb/fd.gdb b/dev/gdb/fd.gdb
new file mode 100644 (file)
index 0000000..736dddf
--- /dev/null
@@ -0,0 +1,39 @@
+# list info about open FD
+define fd_dump
+  set $f = 0
+  while $f < $g.maxsock
+    if fdtab[$f].owner != 0
+      printf "fd %5d: rm=%#lx tm=%#lx um=%#lx cb=%p ownr=%p st=%#x refc=%#x tkov=%u gen=%u\n", $f, fdtab[$f].running_mask, fdtab[$f].thread_mask, fdtab[$f].update_mask, fdtab[$f].iocb, fdtab[$f].owner, fdtab[$f].state, fdtab[$f].refc_tgid, fdtab[$f].nb_takeover, fdtab[$f].generation
+    end
+    set $f = $f + 1
+  end
+end
+
+# only those attached to a listener
+define fd_dump_listener
+  set $f = 0
+  while $f < $g.maxsock
+    if fdtab[$f].owner != 0 && fdtab[$f].iocb == &sock_accept_iocb
+      set $c = (struct listener *)fdtab[$f].owner
+      printf "fd %5d: rm=%#lx tm=%#lx um=%#lx st=%#x refc=%#x tkov=%u gen=%u listener=%p(%s): flg=%#x state=%d fe=%p(%s) acc=%p\n", $f, fdtab[$f].running_mask, fdtab[$f].thread_mask, fdtab[$f].update_mask, fdtab[$f].state, fdtab[$f].refc_tgid, fdtab[$f].nb_takeover, fdtab[$f].generation, fdtab[$f].owner, $c->name, $c->flags, $c->state, $c->bind_conf.frontend, $c->bind_conf.frontend.id, $c->bind_conf.accept
+    end
+    set $f = $f + 1
+  end
+end
+
+# only those attached to a connection
+define fd_dump_conn
+  set $f = 0
+  while $f < $g.maxsock
+    if fdtab[$f].owner != 0 && fdtab[$f].iocb == &sock_conn_iocb
+      set $c = (struct connection *)fdtab[$f].owner
+      printf "fd %5d: rm=%#lx tm=%#lx um=%#lx st=%#x refc=%#x tkov=%u gen=%u conn=%p: flg=%#x err=%#x ctrl=%p xprt=%p mux=%p", $f, fdtab[$f].running_mask, fdtab[$f].thread_mask, fdtab[$f].update_mask, fdtab[$f].state, fdtab[$f].refc_tgid, fdtab[$f].nb_takeover, fdtab[$f].generation, fdtab[$f].owner, $c->flags, $c->err_code, $c->ctrl, $c->xprt, $c->mux
+      if *$c->target == OBJ_TYPE_LISTENER
+        set $s = (struct session *)$c->owner
+        printf " sess=%p: fe=%p id=%s age=%dms", $s, $s->fe, $s->fe->id, (*global_now_ns - $s->accept_ts) / 1000000
+      end
+      printf "\n"
+    end
+    set $f = $f + 1
+  end
+end