From: short <> Date: Wed, 27 Feb 2002 22:51:23 +0000 (+0000) Subject: Not yet working stack checking (symbol STACKCHECK) X-Git-Tag: uc_works1~24 X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=commitdiff_plain;h=81b1712d54efa46b3148a5beb42d32d7632ef30c Not yet working stack checking (symbol STACKCHECK) --- diff --git a/acconfig.h b/acconfig.h index dfd6d99..9bbd4bb 100644 --- a/acconfig.h +++ b/acconfig.h @@ -79,5 +79,17 @@ #include "uccompat.h" +#ifdef STACKCHECK +extern void live_check(const char *file,int line); +extern void live_disable(int how); +#define LIVE live_check(__FILE__,__LINE__) +#define LIVE_DISABLE live_disable(1) +#define LIVE_ENABLE live_disable(-1) +#else /* STACKCHECK */ +#define LIVE +#define LIVE_DISABLE +#define LIVE_ENABLE +#endif /* STACKCHECK */ + #endif /* __CONFIG_H__ */ diff --git a/common/devices/device.c b/common/devices/device.c index eb81b25..db6d768 100644 --- a/common/devices/device.c +++ b/common/devices/device.c @@ -157,18 +157,21 @@ static void device_dumpserial(void) } #endif /* DEBUG */ +static char SigHandler_buffer[255]; + static void SigHandler(int status) { - - unsigned char buffer[2048]; - int count, res; - res = device_read(buffer, 255); + LIVE_DISABLE; + LIVE; + + res = device_read(SigHandler_buffer, sizeof(SigHandler_buffer)); for (count = 0; count < res ; count ++) { - Protocol->StateMachine(buffer[count]); + Protocol->StateMachine(SigHandler_buffer[count]); } + LIVE_ENABLE; } diff --git a/do b/do index ec3e051..1923407 100755 --- a/do +++ b/do @@ -2,6 +2,7 @@ #target_m68k=1 enable_debug=1 +#stack_check=1 cfg_port="ttyS0" exec 2>&1 @@ -15,7 +16,14 @@ if [ -n "$target_m68k" ];then test -n "$AR" || export AR="m68k-pic-coff-ar" test -n "$CFLAGS" || export CFLAGS="-O2 -Wall -fPIC" test -n "$CPPFLAGS" || export CPPFLAGS="-DUCCOMPAT=1 $CPPFLAGS" + if [ -n "$stack_check" -a -n "$enable_debug" ];then + export CPPFLAGS="-DSTACKCHECK=1 $CPPFLAGS" + fi test -n "$LDFLAGS" || export LDFLAGS="gnokii/cleanup.c" +# if [ -n "$enable_debug" ];then +# export CFLAGS="-pg $CFLAGS" +# export LDFLAGS="gnokii/mcount.c $LDFLAGS" +# fi fi export CPPFLAGS="-DUCLINUX=1 $CPPFLAGS" ./configure --with-cfg-model=5110 --with-cfg-port=/dev/"$cfg_port" --without-x \ diff --git a/gnokii/cleanup.c b/gnokii/cleanup.c index e11b7c2..1900733 100644 --- a/gnokii/cleanup.c +++ b/gnokii/cleanup.c @@ -1,4 +1,48 @@ +#ifdef GNOKII_MAIN +#include "config.h" +#endif + +#include + void _cleanup(void) { /* hack for pic32 gcc */ } + +#ifdef STACKCHECK + +static volatile int live_check_disable=0; + +void live_check(const char *file,int line) +{ +static volatile char *top=NULL,*top_printed=NULL; +static volatile size_t largest=0,largest_printed=0; +volatile char mark; + + if (&mark > top) + top=&mark; + if (live_check_disable<=0 && top!=top_printed) { + printf("live_check [%s:%d]: new top=0x%08lX\n",file,line,(long)top); + fflush(stdout); + top_printed=top; + } + if (largest < top-&mark) + largest = top-&mark; + if (live_check_disable<=0 && largest!=largest_printed) { + printf("live_check [%s:%d]: largest=%ld\n",file,line,(long)largest); + fflush(stdout); + largest_printed=largest; + } + if (largest >= 12000) { + if (live_check_disable<=0) + puts("live_check - aborting!"); + _exit(99); + } +} + +void live_disable(int how) +{ + live_check_disable+=how; +} + +#endif /* STACKCHECK */ diff --git a/gnokii/gnokii.c b/gnokii/gnokii.c index d9030f7..df3ce22 100644 --- a/gnokii/gnokii.c +++ b/gnokii/gnokii.c @@ -1238,6 +1238,8 @@ int main(int argc, char *argv[]) { 0, 0, 0, 0 }, }; + LIVE; + opterr = 0; /* For GNU gettext */ @@ -4672,6 +4674,7 @@ static int getmemory(int argc, char *argv[]) fprintf(stderr, _("Unknown memory type %s!\n"), argv[0]); return (-1); } + GetMemoryTypeString(memory_type_string, &entry.MemoryType); if (argv[argc-1][0] == '-') @@ -5231,20 +5234,29 @@ static int identify( void ) /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */ char imei[64], model[64], rev[64], manufacturer[64]; + LIVE; fbusinit(NULL); + LIVE; while (GSM->GetIMEI(imei) != GE_NONE) sleep(1); + LIVE; while (GSM->GetRevision(rev) != GE_NONE) sleep(1); + LIVE; while (GSM->GetModel(model) != GE_NONE) sleep(1); + LIVE; strcpy(manufacturer, "(unknown)"); + LIVE; GSM->GetManufacturer(manufacturer); + LIVE; fprintf(stdout, _("IMEI: %s\n"), imei); fprintf(stdout, _("Model: %s %s (%s)\n"), manufacturer, GetModelName (model), model); fprintf(stdout, _("Revision: %s\n"), rev); + LIVE; GSM->Terminate(); + LIVE; return 0; } diff --git a/gnokii/hello.c b/gnokii/hello.c new file mode 100644 index 0000000..be27e74 --- /dev/null +++ b/gnokii/hello.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + puts("hello"); + return 0; +} diff --git a/gnokii/mcount.c b/gnokii/mcount.c new file mode 100644 index 0000000..cf40629 --- /dev/null +++ b/gnokii/mcount.c @@ -0,0 +1,26 @@ +#ifdef GNOKII_MAIN +#include "config.h" +#endif + +#ifdef STACKCHECK + +#include + +void mcount(void) +{ +#ifdef __m68k__X +static void *arg; + +#if 0 + asm("movel %%a0,%0" : "=r" (arg) : /* input */ : "a0"); +#endif + asm("movel %%fp@(+4),%0" : "=r" (arg) : /* input */); + + printf("mcount(0x%08lX)\n",(long)arg); +#endif /* __m68k__ */ +#ifdef LIVEX + LIVE; +#endif /* LIVE */ +} + +#endif /* STACKCHECK */