Coder Social home page Coder Social logo

debug's Introduction

debug

Conditional debug logging for C

install

$ clib install debug

usage

#include "debug.h"

debug_init(app)
debug_init(connection)
debug_init(error)

debug_t app_debug;
debug_t conn_debug;
debug_t err_debug;

int
main (void) {
  app_debug = debug_get(app);
  conn_debug = debug_get(connection);
  err_debug = debug_get(error);

  app_debug("starting application '%s'", "wooooo");

  // more logic later..
  return 0;
}
$ DEBUG=app ./program
app - starting application 'wooooo'

license

MIT

debug's People

Contributors

jwerle avatar stephenmathieson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

debug's Issues

Invalid usage of calloc

We're only requesting an array with one element, which causes nasal demons:

$ DEBUG=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z ./test
*** glibc detected *** ./test: double free or corruption (out): 0x0000000000ab7030 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f0010080b96]
./test[0x4009b9]
./test[0x400868]
./test[0x400beb]
./test[0x4006ce]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f001002376d]
./test[0x400765]
======= Memory map: ========
00400000-00402000 r-xp 00000000 ca:01 1058172                            /home/stephen/debug/test
00601000-00602000 r--p 00001000 ca:01 1058172                            /home/stephen/debug/test
00602000-00603000 rw-p 00002000 ca:01 1058172                            /home/stephen/debug/test
00ab7000-00ad8000 rw-p 00000000 00:00 0                                  [heap]
7f000fdec000-7f000fe01000 r-xp 00000000 ca:01 142751                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f000fe01000-7f0010000000 ---p 00015000 ca:01 142751                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f0010000000-7f0010001000 r--p 00014000 ca:01 142751                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f0010001000-7f0010002000 rw-p 00015000 ca:01 142751                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f0010002000-7f00101b7000 r-xp 00000000 ca:01 133594                     /lib/x86_64-linux-gnu/libc-2.15.so
7f00101b7000-7f00103b7000 ---p 001b5000 ca:01 133594                     /lib/x86_64-linux-gnu/libc-2.15.so
7f00103b7000-7f00103bb000 r--p 001b5000 ca:01 133594                     /lib/x86_64-linux-gnu/libc-2.15.so
7f00103bb000-7f00103bd000 rw-p 001b9000 ca:01 133594                     /lib/x86_64-linux-gnu/libc-2.15.so
7f00103bd000-7f00103c2000 rw-p 00000000 00:00 0 
7f00103c2000-7f00103e4000 r-xp 00000000 ca:01 142709                     /lib/x86_64-linux-gnu/ld-2.15.so
7f00105d4000-7f00105d7000 rw-p 00000000 00:00 0 
7f00105e1000-7f00105e4000 rw-p 00000000 00:00 0 
7f00105e4000-7f00105e5000 r--p 00022000 ca:01 142709                     /lib/x86_64-linux-gnu/ld-2.15.so
7f00105e5000-7f00105e7000 rw-p 00023000 ca:01 142709                     /lib/x86_64-linux-gnu/ld-2.15.so
7fff22444000-7fff22465000 rw-p 00000000 00:00 0                          [stack]
7fff22510000-7fff22511000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)

wildcards

i'd like to add debug()s to clib(1), but would like to namespace the debuggers with clib (makes sense, right?).

doing this would require me to:

$ DEBUG=clib,clib_package,clib_install clib install user/repo

but this would be much nicer:

$ DEBUG=clib* clib install user/repo

deprecate?

i just wrote debug.c which closes #7, #8 and #9. it's a completely different api though.

thoughts on deprecating this in favour of the newer (feature rich) impl?

Compilation warnings with gcc version 4.6.3

[ . . . ]
test.c: In function ‘_debug_foobar’:
test.c:10:1: warning: implicit declaration of function ‘vasprintf’ [-Wimplicit-function-declaration]
test.c:10:1: warning: left-hand operand of comma expression has no effect [-Wunused-value]
test.c:10:1: warning: statement with no effect [-Wunused-value]
test.c: In function ‘_debug_foo_bar’:
test.c:11:1: warning: left-hand operand of comma expression has no effect [-Wunused-value]
test.c:11:1: warning: statement with no effect [-Wunused-value]
test.c: In function ‘_debug_foobaz’:
test.c:12:1: warning: left-hand operand of comma expression has no effect [-Wunused-value]
test.c:12:1: warning: statement with no effect [-Wunused-value]
test.c: In function ‘_debug_active’:
test.c:13:1: warning: left-hand operand of comma expression has no effect [-Wunused-value]
test.c:13:1: warning: statement with no effect [-Wunused-value]
test.c: In function ‘_debug_inactive’:
test.c:14:1: warning: left-hand operand of comma expression has no effect [-Wunused-value]
test.c:14:1: warning: statement with no effect [-Wunused-value]

I know vasprintf is my fault. It's nonstandard or whatever :/

Feature request: support non-alphanumberic characters in debug names

No idea how we'd handle it with the current impl (may need a rewrite :/), but I'd greatly appreciate being able to use non-alphanumberic chars when defining debugs.

For example:

debug_init(clib);
debug_init(clib:install);
debug_init(clib:search);
debug_init(clib:help);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.