[cairo] CAIRO_DEBUG support

Behdad Esfahbod behdad at behdad.org
Tue Apr 15 12:13:13 PDT 2008


Looks good to me.  Some comments:

  - Make CAIRO_DEBUG parsing more lenient.  Ignore case, take any of
" ,;:\t" as delimiter.  Match '-' and '_'.  That's what I made glib do.

  - I like the valgrind support.  But make us do a valgrind printf at
initialization so one can easily tell if cairo detected valgrind or not.

  - First clearly define and document the CAIRO_DEBUG format.  Do we
need suboptions for example?  Would help to have a map of what options
we see being added in the future, so we can design the format and
namespace right from the beginning.

  - Would be useful to be able to abort on the n-th error instead of the
first one.  Those kind of things.

  - I'm not sure about the fd argument.  Taking a log filename can be
handy too.  And maybe it should log to a pid-prefixed filename by
default?

  - Is it useful to have a general numeric verbosity level?  Like
FC_DEBUG for example?

behdad

On Sun, 2008-04-13 at 06:28 -0400, Chris Wilson wrote:
> I've started work on a framework for providing user-level debugging
> facilities for cairo. By selecting between various flags in CAIRO_DEBUG,
> the user can currently adjust what happens when cairo detects an error.
> In the future, it could be used for simplifying the output - e.g.
> uncompressed pdf output and forcing fallbacks.
> 
> The initial support is quite rudimentary and is yet to integrate with
> the improved backtrace_symbols() in utils/, but it exists as proof of
> concept and as a request for comments.
> 
> At the moment, it looks like:
> ickle at cube:~/src/cairo/test$ CAIRO_DEBUG=backtrace,abort ../libtool
> --mode=execute ./create-for-stream
> 
> TESTING create-for-stream
> _cairo_error (error while writing to output stream [11])
> /home/ickle/src/cairo/src/.libs/libcairo.so.2[0x2b9ea1e79377]
> /home/ickle/src/cairo/src/.libs/libcairo.so.2[0x2b9ea1e79451]
> /home/ickle/src/cairo/src/.libs/libcairo.so.2[0x2b9ea1e73b13]
> /home/ickle/src/cairo/src/.libs/libcairo.so.2(cairo_surface_finish
> +0x6a)[0x2b9ea1e8ac8a]
> /home/ickle/src/cairo/src/.libs/libcairo.so.2[0x2b9ea1e94438]
> /home/ickle/src/cairo/src/.libs/libcairo.so.2(cairo_surface_finish
> +0x46)[0x2b9ea1e8ac66]
> /home/ickle/src/cairo/test/.libs/lt-create-for-stream[0x4031bd]
> /home/ickle/src/cairo/test/.libs/lt-create-for-stream[0x40344d]
> /lib/libc.so.6(__libc_start_main+0xf4)[0x2b9ea34d21c4]
> /home/ickle/src/cairo/test/.libs/lt-create-for-stream[0x403059]
> Aborted
> ickle at cube:~/src/cairo/test$ CAIRO_DEBUG=backtrace,abort ../libtool
> --mode=execute valgrind ./create-for-stream
> ==13395== Memcheck, a memory error detector.
> ==13395== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et
> al.
> ==13395== Using LibVEX rev 1804, a library for dynamic binary
> translation.
> ==13395== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
> ==13395== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation
> framework.
> ==13395== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et
> al.
> ==13395== For more details, rerun with: -v
> ==13395== 
> 
> TESTING create-for-stream
> **13395** _cairo_error (error while writing to output stream [11])
> ==13395==    at 0x4E34314: _cairo_debug_backtrace_internal
> (cairo-debug.c:117)
> ==13395==    by 0x4E34450: _cairo_debug_maybe_backtrace_or_abort
> (cairo-debug.c:171)
> ==13395==    by 0x4E2EB12: _cairo_error (cairo.c:89)
> ==13395==    by 0x4E45C89: cairo_surface_finish (cairo-surface.c:518)
> ==13395==    by 0x4E4F437: _cairo_paginated_surface_finish
> (cairo-paginated-surface.c:171)
> ==13395==    by 0x4E45C65: cairo_surface_finish (cairo-surface.c:516)
> ==13395==    by 0x4031BC: test_surface (create-for-stream.c:156)
> ==13395==    by 0x40344C: main (create-for-stream.c:238)
> ==13395== 
> ==13395== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 1)
> ==13395== malloc/free: in use at exit: 2,336 bytes in 8 blocks.
> ==13395== malloc/free: 32 allocs, 24 frees, 9,545 bytes allocated.
> ==13395== For counts of detected errors, rerun with: -v
> ==13395== searching for pointers to 8 not-freed blocks.
> ==13395== checked 332,512 bytes.
> ==13395== 
> ==13395== LEAK SUMMARY:
> ==13395==    definitely lost: 0 bytes in 0 blocks.
> ==13395==      possibly lost: 0 bytes in 0 blocks.
> ==13395==    still reachable: 2,336 bytes in 8 blocks.
> ==13395==         suppressed: 0 bytes in 0 blocks.
> ==13395== Rerun with --leak-check=full to see details of leaked memory.
> Aborted
> 
> The code can found at git://people.freedesktop.org/~ickle/cairo under
> the branch cairo-debug.
-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759



More information about the cairo mailing list