• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Tips on debugging with lws
2
3## Problem with the library, or your code?
4
5Because lws is only really used when already combined with user code,
6it can be a headache figuring out if the actual problem is inside lws
7or in the user code.
8
9If it's in lws, I would really like to solve it, but if it's in your
10code, that's your problem.  Finding out which side it's on when it
11involves your code is also something you need to try to resolve.
12
13The minimal examples are useful because if they demonstrate the same
14problem, it's something about your platform or lws itself, I have the
15minimal examples so I can test it and find out if it's your platform.
16If I can reproduce it, it's my problem.
17
18## Debug builds
19
20With cmake, build with `-DCMAKE_BUILD_TYPE=DEBUG` to build in extra
21logging, and use a log level bitmap of eg, 1039 or 1151 to enable
22the extra logs for print.
23
24The minimal examples take a -d xxx commandline parameter so you can
25select the logging level when you run it.
26
27The extra logging can be very useful to understand the sequencing of
28problematic actions.
29
30## Valgrind
31
32If your problems involve heap corruption or use-after-free, Valgrind
33is indespensible.  It's simple to use, if you normally run `xxx`, just
34run `valgrind xxx`.  Your code will run slower, usually something
35like 2 - 4x slower but it depends on the exact code.  However you will
36get a backtrace as soon as there is some kind of misbehaviour of either
37lws or your code.
38
39lws is developed using valgrind routinely and strives to be completely
40valgrind-clean.  So typically any problems reported are telling you
41about problems in user code (or my bugs).
42
43## Traffic dumping
44
45The best place for dumping traffic, assuming you are linking against a
46tls library, is `lws_ssl_capable_read()` and `lws_ssl_capable_write()`
47in either `./lib/tls/openssl/openssl-ssl.c` or
48`./lib/tls/mbedtls/mbedtls-ssl.c` according to which tls library you
49are using.  There are default-`#if 0` sections in each function like
50
51```
52#if 0
53	/*
54	 * If using mbedtls type tls library, this is the earliest point for all
55	 * paths to dump what was received as decrypted data from the tls tunnel
56	 */
57	lwsl_notice("%s: len %d\n", __func__, len);
58	lwsl_hexdump_notice(buf, len);
59#endif
60```
61
62Enable these to get hexdumps for all unencrypted data in both directions.
63
64