tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

debug.h (3016B)


      1 /* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
      2   Licensed under the Apache 2.0 and MIT Licenses. */
      3 
      4 #ifndef KRML_HEADER_DEBUG_H
      5 #define KRML_HEADER_DEBUG_H
      6 
      7 #include <inttypes.h>
      8 
      9 #include "krml/internal/target.h"
     10 
     11 /******************************************************************************/
     12 /* Debugging helpers - intended only for KaRaMeL developers                   */
     13 /******************************************************************************/
     14 
     15 /* In support of "-wasm -d force-c": we might need this function to be
     16 * forward-declared, because the dependency on WasmSupport appears very late,
     17 * after SimplifyWasm, and sadly, after the topological order has been done. */
     18 void WasmSupport_check_buffer_size(uint32_t s);
     19 
     20 /* A series of GCC atrocities to trace function calls (karamel's [-d c-calls]
     21 * option). Useful when trying to debug, say, Wasm, to compare traces. */
     22 /* clang-format off */
     23 #ifdef __GNUC__
     24 #define KRML_FORMAT(X) _Generic((X),                                           \
     25  uint8_t : "0x%08" PRIx8,                                                     \
     26  uint16_t: "0x%08" PRIx16,                                                    \
     27  uint32_t: "0x%08" PRIx32,                                                    \
     28  uint64_t: "0x%08" PRIx64,                                                    \
     29  int8_t  : "0x%08" PRIx8,                                                     \
     30  int16_t : "0x%08" PRIx16,                                                    \
     31  int32_t : "0x%08" PRIx32,                                                    \
     32  int64_t : "0x%08" PRIx64,                                                    \
     33  default : "%s")
     34 
     35 #define KRML_FORMAT_ARG(X) _Generic((X),                                       \
     36  uint8_t : X,                                                                 \
     37  uint16_t: X,                                                                 \
     38  uint32_t: X,                                                                 \
     39  uint64_t: X,                                                                 \
     40  int8_t  : X,                                                                 \
     41  int16_t : X,                                                                 \
     42  int32_t : X,                                                                 \
     43  int64_t : X,                                                                 \
     44  default : "unknown")
     45 /* clang-format on */
     46 
     47 #define KRML_DEBUG_RETURN(X)                                        \
     48    ({                                                              \
     49        __auto_type _ret = (X);                                     \
     50        KRML_HOST_PRINTF("returning: ");                            \
     51        KRML_HOST_PRINTF(KRML_FORMAT(_ret), KRML_FORMAT_ARG(_ret)); \
     52        KRML_HOST_PRINTF(" \n");                                    \
     53        _ret;                                                       \
     54    })
     55 #endif
     56 
     57 #endif /* KRML_HEADER_DEBUG_H */