libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-backtrace.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2022 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
36
37typedef struct {
38 uintptr_t st[32];
39 uintptr_t asize;
40
45
46typedef struct {
48 size_t pos;
49 size_t len;
51
52/*
53 * lws_backtrace() - init and fiull a backtrace struct
54 *
55 * \param si: the backtrace struct to populate
56 * \param pre: the number of call levels to snip from the top
57 * \param post: the number of call levels to snip from the bottom
58 *
59 * This describes the call stack into \p si. \p si doesn't need preparing
60 * before the call. \p pre levels of the call stack at the top will be snipped,
61 * this will usually want to be 1 or 2 to conceal the helpers that are making
62 * the call stack, such as lws_backtrace itself.
63 *
64 * \p post levels of the call stack at the bottom will be snipped, this is to
65 * conceal loaders or other machinery that was used to start your application,
66 * otherwise those entries will bloat all call stacks results on that platform.
67 *
68 * Returns 0 for success.
69 */
72
73/*
74 * lws_backtrace_compression_stream_init() - init and fiull a backtrace struct
75 *
76 * \param c: the backtrace compression struct
77 * \param comp: the buffer to take the compressed bytes
78 * \param comp_len: the number of bytes available at \p comp
79 *
80 * This initializes the caller's lws_backtrace_comp_t. Because it's expected
81 * the caller will want to put his own compressed data after the compressed
82 * backtrace, he is responsible for the compression context.
83 */
86 uint8_t *comp, size_t comp_len);
87
88/*
89 * lws_backtrace_compression_stream() - add bitfields to compression stream
90 *
91 * \param c: the backtrace compression context struct
92 * \param v: the bitfield to add to the stream
93 * \param bits: the number of bits of v to add
94 *
95 * This inserts bits from the LSB end of v to the compression stream.
96 *
97 * This is used by the backtrace compression, user code can use this to add
98 * its own bitfields into the compression stream after the compressed backtrace.
99 *
100 * User data should be added after, so that the backtrace can be processed even
101 * if the additional data is not understood by the processing script.
102 *
103 * Returns 0 for success or nonzero if ran out of compression output buffer.
104 */
107 unsigned int bits);
108
109/*
110 * lws_backtrace_compression_destream() - add bitfields to compression stream
111 *
112 * \param c: the backtrace compression context struct
113 * \param _v: pointer to take the bitfield result
114 * \param bits: the number of bits to bring out into _v
115 *
116 * This reads the compression stream and creates a bitfield from it in \p _v.
117 *
118 * Returns 0 for success (with \p _v set to the value), or nonzero if ran out
119 * of compression output buffer.
120 */
123 unsigned int bits);
124
125/*
126 * lws_backtrace_compress_backtrace() - compress backtrace si into c
127 *
128 * \param si: the backtrace struct to compress
129 * \param c: the backtrace compression context struct
130 *
131 * This compresses backtrace information acquired in \p si into the compression
132 * context \p c. It compresses first the call stack length and then each IP
133 * address in turn.
134 *
135 * Returns 0 for success.
136 */
140
142
160
184lws_alloc_metadata_gen(size_t size, uint8_t *comp, size_t comp_len, size_t *adj,
185 size_t *cl);
186
207_lws_alloc_metadata_adjust(lws_dll2_owner_t *active, void **v, size_t adj, uint8_t *comp, unsigned int cl);
208
222_lws_alloc_metadata_trim(void **ptr, uint8_t **comp, uint16_t *complen);
223
237
249
267 void *arg);
268
269#if defined(LWS_WITH_ALLOC_METADATA_LWS)
270/*
271 * Wrapper for _lws_alloc_metadata_dump() that uses the list owner that tracks
272 *
273 */
276#else
277#define _lws_alloc_metadata_dump_lws(_a, _b)
278#endif
279
struct lws_dll2_owner lws_dll2_owner_t
int(* lws_dll2_foreach_cb_t)(struct lws_dll2 *d, void *user)
Definition lws-dll2.h:231
unsigned short uint16_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
LWS_VISIBLE LWS_EXTERN void _lws_alloc_metadata_adjust(lws_dll2_owner_t *active, void **v, size_t adj, uint8_t *comp, unsigned int cl)
LWS_VISIBLE LWS_EXTERN void _lws_alloc_metadata_trim(void **ptr, uint8_t **comp, uint16_t *complen)
#define _lws_alloc_metadata_dump_lws(_a, _b)
LWS_VISIBLE LWS_EXTERN int lws_backtrace_compression_stream(lws_backtrace_comp_t *c, uintptr_t v, unsigned int bits)
LWS_VISIBLE LWS_EXTERN int lws_backtrace_compression_destream(lws_backtrace_comp_t *c, uintptr_t *_v, unsigned int bits)
LWS_VISIBLE LWS_EXTERN void _lws_alloc_metadata_dump(lws_dll2_owner_t *active, lws_dll2_foreach_cb_t cb, void *arg)
LWS_VISIBLE LWS_EXTERN int lws_alloc_metadata_parse(lws_backtrace_info_t *si, const uint8_t *adjusted_alloc)
LWS_VISIBLE LWS_EXTERN int lws_backtrace(lws_backtrace_info_t *si, uint8_t pre, uint8_t post)
LWS_VISIBLE LWS_EXTERN void lws_alloc_metadata_gen(size_t size, uint8_t *comp, size_t comp_len, size_t *adj, size_t *cl)
LWS_VISIBLE LWS_EXTERN void lws_backtrace_compression_stream_init(lws_backtrace_comp_t *c, uint8_t *comp, size_t comp_len)
LWS_VISIBLE LWS_EXTERN int lws_alloc_metadata_dump_stdout(struct lws_dll2 *d, void *user)
LWS_VISIBLE LWS_EXTERN int lws_backtrace_compress_backtrace(lws_backtrace_info_t *si, lws_backtrace_comp_t *c)