How to add a debug print

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
volkerjaenisch
Posts: 5
Joined: Thu Jun 10, 2021 9:38 pm

How to add a debug print

Post by volkerjaenisch » Wed Sep 22, 2021 9:08 pm

Dear Micropython Developers!

ATM I use the following code to write debug output to the console:

Code: Select all

STATIC mp_obj_t mono_horiz_get_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
    /*
        Return the raw bytes of a rectangle given by its x ,y ,w ,h definition.
        Caution! Bytes overlapping the left/right border will transferred completely.
        The rectangle will be returned in the same order the buffer is aligned.
    */

   mp_printf(&mp_plat_print,"get_rect=%d %d %d %d\n", x, y, w, h);

This is surely not the best way!
Is there a way to do it controlled by a micropython-DEBUG switch.

Any help appreciated,
Volker

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: How to add a debug print

Post by stijn » Thu Sep 23, 2021 6:13 am

Typical way is using DEBUG_printf and eventually mp_obj_print_helper(MICROPY_DEBUG_PRINTER, ...), guarded by e.g. MICROPY_DEBUG_VERBOSE. There are many examples in various source files in core/extmod/...

But what's the purpose? If it's just for debugging your own code it doesn't really matter (though DEBUG_printf is still shorter to write).

Post Reply