Errors while testing Nagios
Jochen Bern
Jochen.Bern at LINworks.de
Mon Oct 25 14:07:58 CEST 2010
On 10/25/2010 12:00 PM, Andreas Ericsson wrote:
> On 10/25/2010 11:00 AM, Ton Voon wrote:
>> I had an idea to try a different technique (include the
>> source, but override some specific functions), but I couldn't redefine
>> functions in C without the compiler complaining.
> There's no sane way to do that. The un-sane way is to sed out the functions
> you want to replace and then source the sed'ed source-file.
Well, if you want only *mild* insanity, look no further than at the
preprocessor. ;-)
> $ cat main.c
> main()
> {
> speak();
> }
> $ cat normal.c
> #include <stdio.h>
>
> #ifndef DEBUGGABLE
> #define DEBUGGABLE(x) x
> #endif
>
> void DEBUGGABLE(speak) ()
> {
> printf("Business as usual\n");
> }
> $ cat debug.c
> #define DEBUGGABLE(x) debugged_ ## x
>
> #include "normal.c"
>
> void speak()
> {
> printf("This is the debug version\n");
> debugged_speak();
> }
> $ gcc -c -o normal.o normal.c
> $ gcc -o main main.c normal.o
> $ ./main
> Business as usual
> $ gcc -c -o debug.o debug.c
> $ gcc -o main main.c debug.o
> $ ./main
> This is the debug version
> Business as usual
> $ nm normal.o
> U puts
> 00000000 T speak
> $ nm debug.o
> 00000000 T debugged_speak
> U puts
> 00000014 T speak
Kind regards,
J. Bern
--
Jochen Bern, Systemingenieur --- LINworks GmbH <http://www.LINworks.de/>
Postfach 100121, 64201 Darmstadt | Robert-Koch-Str. 9, 64331 Weiterstadt
PGP (1024D/4096g) FP = D18B 41B1 16C0 11BA 7F8C DCF7 E1D5 FAF4 444E 1C27
Tel. +49 6151 9067-231, Zentr. -0, Fax -299 - Amtsg. Darmstadt HRB 85202
Unternehmenssitz Weiterstadt, Geschäftsführer Metin Dogan, Oliver Michel
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
More information about the Developers
mailing list