summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 5fad206ba0c087f207cd84c80e8aa86883c51bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# udebug - OpenWrt debugging infrastructure

udebug assists whole-system debugging by making it easy to provide ring buffers
with debug data and make them accessible through a unified API.
Through the CLI, you can either create snapshots of data with a specific duration,
or stream data in real time. The data itself is stored in .pcapng files, which can
contain a mix of packets and log messages.

## Notes on using Wireshark

In order to parse log messages in .pcapng files, you need to change the Wireshark
configuration.
Under `Preferences` -> `Protocols` -> `DLT_USER` -> `Encapsulations Table`,
add an entry for `User 0 (DLT=147)` with Payload protocol `syslog`.

## libudebug C API

#### `void udebug_init(struct udebug *ctx)`

Initializes the udebug context. Must be called before adding buffers.

#### `int udebug_connect(struct udebug *ctx, const char *path)`

Connect to udebugd and submit any buffers that were added using `udebug_buf_add`.

#### `void udebug_auto_connect(struct udebug *ctx, const char *path)`

Connects and automatically reconnects to udebugd. Uses uloop and calls `udebug_add_uloop`.

#### `void udebug_free(struct udebug *ctx)`

Frees the udebug context and all added created buffers.

#### `int udebug_buf_init(struct udebug_buf *buf, size_t entries, size_t size)`

Allocates a buffer with a given size. Entries and size are rounded up internally to the
nearest power-of-2.

#### `int udebug_buf_add(struct udebug *ctx, struct udebug_buf *buf, const struct udebug_buf_meta *meta);`

Submits the buffer to udebugd and makes it visible.

#### `void udebug_buf_free(struct udebug_buf *buf)`

Removes the buffer from udebugd and frees it.

#### `void udebug_entry_init(struct udebug_buf *buf)`

Initializes a new entry on the ring buffer.

#### `void *udebug_entry_append(struct udebug_buf *buf, const void *data, uint32_t len)`

Appends data to the ring buffer. When called with data == NULL, space is only
reserved, and the return value provides a pointer with len bytes that can be
written to.

#### `int udebug_entry_printf(struct udebug_buf *buf, const char *fmt, ...)`

Appends a string to the buffer, based on format string + arguments (like printf)

#### `int udebug_entry_vprintf(struct udebug_buf *buf, const char *fmt, va_list ap)`

Like `udebug_entry_printf()`

#### `void udebug_entry_add(struct udebug_buf *buf)`

Finalizes and publishes the entry on the ring buffer.

### Simple example

```
static struct udebug ud;
static struct udebug_buf udb;

/* ... */

uloop_init();
udebug_init(&ud);
udebug_auto_connect(&ud, NULL);

static const struct udebug_buf_meta buf_meta = {
	.name = "counter",
	.format = UDEBUG_FORMAT_STRING,
};

int entries = 128;
int data_size = 1024;

udebug_buf_init(&udb, entries, data_size);
udebug_buf_add(&ud, &udb, &buf_meta);

/* ... */

udebug_entry_init(&udb); // initialize entry
udebug_entry_printf(&udb, "count=%d", count++);
udebug_entry_add(&udb); // finalize the entry

```

## udebug CLI

```
Usage: udebug-cli [<options>] <command> [<args>]

  Options:
    -f                          Ignore errors on opening rings
    -d <duration>:              Only fetch data up to <duration> seconds old
    -o <file>|-                 Set output file for snapshot/stream (or '-' for stdout)
    -i <process>[:<name>]       Select debug buffer for snapshot/stream
    -s <path>                   Use udebug socket <path>
    -q                          Suppress warnings/error messages

  Commands:
    list:                       List available debug buffers
    snapshot:                   Create a pcapng snapshot of debug buffers
    set_flag [<name>=0|1 ...]   Set ring buffer flags
    get_flags                   Get ring buffer flags

```