papa@bacall.UUCP (Marco Papa) (11/14/86)
>Date: Tue, 28 Oct 86 12:20:59 est >From: caip!cbmvax!phillip (Phillip Lindsay) >To: caip!pur-ee!pucc-j!doc >Subject: Poor Man's kprintf()... Here is something I cooked up to debug things when no terminal is around. the shar file contains: mydebug and myprintf ... ============================================================================== Phillip Lindsay - Commodore Business Machines - Amiga Technical Support Dirt: 1200 Wilson Drive, West Chester PA 19380 uucp: {ihnp4|seismo|caip}!cbmvax!phillip arpa: cbmvax!phillip@seismo -or- phillip@cbmvax.UUCP@{seismo | harvard} Tel.: (215) 431-9180 Disclaimer: [someone said I needed this] No warranty is implied or otherwise given in the form of suggestion or example. Any opinions found here are of my making. [unless Fred pops up (my other self)] ============================================================================== ***CUT HERE #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # mydebug.c # myprintf.c # mytest.c # mydebug.h # dputchar.asm # This archive created: Tue Oct 28 11:58:33 1986 export PATH; PATH=/bin:$PATH echo shar: extracting "'mydebug.c'" '(2529 characters)' if test -f 'mydebug.c' then echo shar: will not over-write existing file "'mydebug.c'" else sed 's/^ X//' << \SHAR_EOF > 'mydebug.c' X/* mydebug.c - Displays debugging info from messages sent by "myprintf" X * X * While this window is active a CTRL-C will abort operation. X * X * 27-SEP-86 (C) 1986 Commodore - Phillip Lindsay X * You may freely use this source for Amiga Development as long as the X * copyright notice is left intact. X * X * How to get going: X * X * 1. assemble dputchar.asm (assem from dputchar.asm -o dputchar.o) X * 3. compile mydebug.c X * 4. link startup.o+mydebug.o+dputchar.o [libs] debug.lib+lc.lib+amiga.lib X * 6. compile "myprintf.c" X * 7. compile "mytest.c" X * 8. link mytest.o+myprintf.o [libs] lc.lib+amiga.lib X * 9. "1> run mydebug" X * 10. "1> mytest" X * 11. repeat steps 7 and 8 for your programs using "kprintf's" X * 12. I hope that was enough... X * X * #if Using MANX & you have LATTICE X * do steps 1-4 with lattice and steps 6-12 with manx X * #else if only MANX X * "acvt" debug.lib for "KDoFmt" and goto step 1...now you are on your own. X * X */ X X#include <exec/types.h> X#include <exec/ports.h> X#include <exec/tasks.h> X#include <libraries/dos.h> X X#ifdef MANX X#include <functions.h> X#endif X X#include "mydebug.h" X X#define CONWIN "CON:0/24/640/70/My_Debug Window ( Ctrl-C to Exit )" X X/* our I/O stream */ XBPTR mycon; X X/* i/o support routines */ X Xextern void dputchar(); X Xvoid dprintf(fmt, args) Xchar *fmt; Xlong args; X{ X extern void dputchar(); X X KDoFmt(fmt, &args, dputchar, NULL); X} X Xvoid printdmess(dmess) Xstruct debug_mess *dmess; X{ X extern void dputchar(); X X KDoFmt(dmess->fmt,dmess->args, dputchar, NULL); X} X Xmain() X{ X X struct MsgPort *myport; X struct debug_mess *mymess; X X if((ULONG)FindPort(MAGIC_NAME)) X { X puts("MyDebug already installed."); X exit(0); X } X X myport = (struct MsgPort *) CreatePort(MAGIC_NAME,NULL); X X if(!myport) exit(TRUE); X X mycon = (BPTR) Open(CONWIN,MODE_OLDFILE); X X if(!mycon) X { X DeletePort(myport); X exit(TRUE); X } X X dprintf("Ready.\n"); X X/* even thou "myprintf" always checks to see if I'm still here...it isn't X * all to hard to CTRL_C me and have a pending "myprintf" kill you. X */ X X SetSignal(~SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C); X while(!((ULONG)SetSignal(0L,0L) & SIGBREAKF_CTRL_C)) X { X Wait( (1L << myport->mp_SigBit) | SIGBREAKF_CTRL_C); X mymess = (struct debug_mess *) GetMsg(myport); X if(!mymess) break; X dprintf("%s: ",mymess->mess.mn_ReplyPort->mp_SigTask->tc_Node.ln_Name); X printdmess(mymess); X ReplyMsg(mymess); X } X SetSignal(~SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C); X X Close(mycon); X DeletePort(myport); X X} X X/* EOF */ X X SHAR_EOF if test 2529 -ne "`wc -c < 'mydebug.c'`" then echo shar: error transmitting "'mydebug.c'" '(should have been 2529 characters)' fi fi # end of overwriting check echo shar: extracting "'myprintf.c'" '(1000 characters)' if test -f 'myprintf.c' then echo shar: will not over-write existing file "'myprintf.c'" else sed 's/^ X//' << \SHAR_EOF > 'myprintf.c' X/* myprintf.c - sends debugging messages to a port with MAGIC_NAME. X * X * 27-SEP-86 - Phillip Lindsay - (C) 1986 Commodore-Amiga X * This source may be freely used for Amiga development as long as the X * copyright notice is left intact. X */ X X#include <exec/types.h> X#include <exec/ports.h> X#include <exec/tasks.h> X#include <libraries/dos.h> X X#ifdef MANX X#include <functions.h> X#endif X X#include "mydebug.h" X Xvoid kprintf(fmt, args) XUBYTE *fmt; XULONG args; X{ X X struct MsgPort *myport,*debugport; X struct debug_mess mymess; X X if(!(debugport = (struct MsgPort *) FindPort(MAGIC_NAME))) X return; X X myport = (struct MsgPort *) CreatePort(NULL,NULL); X X if(!myport) return; X X mymess.mess.mn_ReplyPort = myport; X mymess.mess.mn_Node.ln_Type = NT_MESSAGE; X mymess.mess.mn_Node.ln_Pri = FALSE; X mymess.fmt = fmt; X mymess.args = &args; X X PutMsg(debugport,&mymess); X WaitPort(myport); X GetMsg(myport); X X DeletePort(myport); X X} X X/* EOF */ X X SHAR_EOF if test 1000 -ne "`wc -c < 'myprintf.c'`" then echo shar: error transmitting "'myprintf.c'" '(should have been 1000 characters)' fi fi # end of overwriting check echo shar: extracting "'mytest.c'" '(276 characters)' if test -f 'mytest.c' then echo shar: will not over-write existing file "'mytest.c'" else sed 's/^ X//' << \SHAR_EOF > 'mytest.c' X/* mytest.c - a test program for "myprintf" X * X * linking info: X * alink from startup.o+mytest.o+myprintf.o lib=lc.lib+amiga.lib to mytest X */ X Xmain() X{ X X kprintf("This is a test of myprintf..\n"); X X kprintf(" %ld + %ld = %ld \n",7,8,(7+8)); X X kprintf("\nAll done..\n"); X X} SHAR_EOF if test 276 -ne "`wc -c < 'mytest.c'`" then echo shar: error transmitting "'mytest.c'" '(should have been 276 characters)' fi fi # end of overwriting check echo shar: extracting "'mydebug.h'" '(183 characters)' if test -f 'mydebug.h' then echo shar: will not over-write existing file "'mydebug.h'" else sed 's/^ X//' << \SHAR_EOF > 'mydebug.h' X/* mydebug.h */ X X#define MAGIC_NAME "BOB_MARLEY" /* a "real" human */ X Xstruct debug_mess X { X struct Message mess; X UBYTE *fmt; X ULONG *args; X }; X X/* eof */ SHAR_EOF if test 183 -ne "`wc -c < 'mydebug.h'`" then echo shar: error transmitting "'mydebug.h'" '(should have been 183 characters)' fi fi # end of overwriting check echo shar: extracting "'dputchar.asm'" '(486 characters)' if test -f 'dputchar.asm' then echo shar: will not over-write existing file "'dputchar.asm'" else sed 's/^ X//' << \SHAR_EOF > 'dputchar.asm' X* dputchar(d0:8) - this routine handles character output for KDoFmt() X* X* 27-OCT-86 - Phillip Lindsay - (C) 1986 Commodore-Amiga X* X XREF _DOSBase X XREF _mycon X XREF _LVOWrite X X XDEF _dputchar X X X_dputchar: X X movem.l d0/d1/d2/d3/a0/a1/a6,-(sp) X move.l _DOSBase,a6 X move.l _mycon,d1 X move.b d0,buffer X move.l #buffer,d2 X move.l #1,d3 X jsr _LVOWrite(a6) X movem.l (sp)+,d0/d1/d2/d3/a0/a1/a6 X rts X Xbuffer ds.l 1 X X end X X* EOF SHAR_EOF if test 486 -ne "`wc -c < 'dputchar.asm'`" then echo shar: error transmitting "'dputchar.asm'" '(should have been 486 characters)' fi fi # end of overwriting check # End of shell archive exit 0