ucode: add function for getting the number of entries in a snapshot
authorFelix Fietkau <[email protected]>
Sat, 23 Aug 2025 19:46:17 +0000 (21:46 +0200)
committerFelix Fietkau <[email protected]>
Sat, 23 Aug 2025 19:46:17 +0000 (21:46 +0200)
Signed-off-by: Felix Fietkau <[email protected]>
lib-ucode.c

index 00ab1c846417d72e07374861e92e878b4f7391f0..b905cbe837ac765ebb75df082b02f729ba5a7b92 100644 (file)
@@ -467,6 +467,17 @@ uc_udebug_snapshot_get_ring(uc_vm_t *vm, size_t nargs)
        return ucv_get(rb->priv);
 }
 
+static uc_value_t *
+uc_udebug_snapshot_entries(uc_vm_t *vm, size_t nargs)
+{
+       struct udebug_snapshot *s = uc_fn_thisval("udebug.snapshot");
+
+       if (!s)
+               return NULL;
+
+       return ucv_int64_new(s->n_entries);
+}
+
 static uc_value_t *
 uc_udebug_foreach_packet(uc_vm_t *vm, size_t nargs)
 {
@@ -667,7 +678,8 @@ static const uc_function_list_t pcap_fns[] = {
 };
 
 static const uc_function_list_t snapshot_fns[] = {
-       { "get_ring", uc_udebug_snapshot_get_ring }
+       { "get_ring", uc_udebug_snapshot_get_ring },
+       { "entries", uc_udebug_snapshot_entries }
 };
 
 static const uc_function_list_t wbuf_fns[] = {