fix infinite loop on client poll
[project/udebug.git] / README.md
1 # udebug - OpenWrt debugging infrastructure
2
3 udebug assists whole-system debugging by making it easy to provide ring buffers
4 with debug data and make them accessible through a unified API.
5 Through the CLI, you can either create snapshots of data with a specific duration,
6 or stream data in real time. The data itself is stored in .pcapng files, which can
7 contain a mix of packets and log messages.
8
9 ## libudebug C API
10
11 #### `void udebug_init(struct udebug *ctx)`
12
13 Initializes the udebug context. Must be called before adding buffers.
14
15 #### `int udebug_connect(struct udebug *ctx, const char *path)`
16
17 Connect to udebugd and submit any buffers that were added using `udebug_buf_add`.
18
19 #### `void udebug_auto_connect(struct udebug *ctx, const char *path)`
20
21 Connects and automatically reconnects to udebugd. Uses uloop and calls `udebug_add_uloop`.
22
23 #### `void udebug_free(struct udebug *ctx)`
24
25 Frees the udebug context and all added created buffers.
26
27 #### `int udebug_buf_init(struct udebug_buf *buf, size_t entries, size_t size)`
28
29 Allocates a buffer with a given size. Entries and size are rounded up internally to the
30 nearest power-of-2.
31
32 #### `int udebug_buf_add(struct udebug *ctx, struct udebug_buf *buf, const struct udebug_buf_meta *meta);`
33
34 Submits the buffer to udebugd and makes it visible.
35
36 #### `void udebug_buf_free(struct udebug_buf *buf)`
37
38 Removes the buffer from udebugd and frees it.
39
40 #### `void udebug_entry_init(struct udebug_buf *buf)`
41
42 Initializes a new entry on the ring buffer.
43
44 #### `void *udebug_entry_append(struct udebug_buf *buf, const void *data, uint32_t len)`
45
46 Appends data to the ring buffer. When called with data == NULL, space is only
47 reserved, and the return value provides a pointer with len bytes that can be
48 written to.
49
50 #### `int udebug_entry_printf(struct udebug_buf *buf, const char *fmt, ...)`
51
52 Appends a string to the buffer, based on format string + arguments (like printf)
53
54 #### `int udebug_entry_vprintf(struct udebug_buf *buf, const char *fmt, va_list ap)`
55
56 Like `udebug_entry_printf()`
57
58 #### `void udebug_entry_add(struct udebug_buf *buf)`
59
60 Finalizes and publishes the entry on the ring buffer.
61
62 ### Simple example
63
64 ```
65 static struct udebug ud;
66 static struct udebug_buf udb;
67
68 /* ... */
69
70 uloop_init();
71 udebug_init(&ud);
72 udebug_auto_connect(&ud, NULL);
73
74 static const struct udebug_buf_meta buf_meta = {
75 .name = "counter",
76 .format = UDEBUG_FORMAT_STRING,
77 };
78
79 int entries = 128;
80 int data_size = 1024;
81
82 udebug_buf_init(&udb, entries, data_size);
83 udebug_buf_add(&ud, &udb, &buf_meta);
84
85 /* ... */
86
87 udebug_entry_init(&udb); // initialize entry
88 udebug_entry_printf(&udb, "count=%d", count++);
89 udebug_entry_add(&udb); // finalize the entry
90
91 ```
92
93 ## udebug CLI
94
95 ```
96 Usage: udebug-cli [<options>] <command> [<args>]
97
98 Options:
99 -f Ignore errors on opening rings
100 -d <duration>: Only fetch data up to <duration> seconds old
101 -o <file>|- Set output file for snapshot/stream (or '-' for stdout)
102 -i <process>[:<name>] Select debug buffer for snapshot/stream
103 -s <path> Use udebug socket <path>
104 -q Suppress warnings/error messages
105
106 Commands:
107 list: List available debug buffers
108 snapshot: Create a pcapng snapshot of debug buffers
109 set_flag [<name>=0|1 ...] Set ring buffer flags
110 get_flags Get ring buffer flags
111
112 ```
113