libgbm: add more debug

Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>
split out common code into library

Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>