1 /*-------------------------------------------------------------------------
2 sdcdb.c - main source file for sdcdb debugger
3 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding!
22 -------------------------------------------------------------------------*/
35 char *currModName = NULL;
36 cdbrecs *recsRoot = NULL ;
37 set *modules = NULL; /* set of all modules */
38 set *functions = NULL ; /* set of functions */
39 set *symbols = NULL ; /* set of symbols */
40 set *sfrsymbols= NULL ; /* set of symbols of sfr or sbit */
42 structdef **structs = NULL ; /* all structures */
44 linkrec **linkrecs = NULL; /* all linkage editor records */
45 context *currCtxt = NULL;
48 char userinterrupt = 0;
51 char *ssdirl = DATADIR LIB_DIR_SUFFIX ":" DATADIR LIB_DIR_SUFFIX "/small" ;
55 /* fake filename & lineno to make linker */
60 static void commandLoop(FILE *cmdfile);
65 char *cmd ; /* command the user will enter */
66 int (*cmdfunc)(char *,context *); /* function to execute when command is entered */
67 char *htxt ; /* short help text */
70 /* NOTE:- the search is done from the top, so "break" should
71 precede the synonym "b" */
73 { "break" , cmdSetUserBp ,
74 "{b}reak\t\t\t [LINE | FILE:LINE | FILE:FUNCTION | FUNCTION | *<address>]\n",
76 { "tbreak" , cmdSetTmpUserBp ,
77 "tbreak\t\t\t [LINE | FILE:LINE | FILE:FUNCTION | FUNCTION | *<address>]\n",
79 { "b" , cmdSetUserBp , NULL },
82 "jump\t\t\tContinue program being debugged at specified line or address\n [LINE | FILE:LINE | *<address>]\n",
84 { "clear" , cmdClrUserBp ,
85 "{cl}ear\t\t\t [LINE | FILE:LINE | FILE:FUNCTION | FUNCTION]\n"
87 { "cl" , cmdClrUserBp , NULL },
89 { "continue" , cmdContinue ,
90 "{c}ontinue\t\t Continue program being debugged, after breakpoint.\n"
92 { "condition" , cmdCondition ,
93 "condition brkpoint_number expr\t\tSet condition for breakpoint.\n"
95 { "ignore" , cmdIgnore ,
96 "brkpoint_number count\t\tSet ignore count for breakpoint.\n"
98 { "commands" , cmdCommands ,
99 "commands [brkpoint_number]\t\tSetting commands for breakpoint.\n"
101 { "c" , cmdContinue , NULL },
103 { "disassemble",cmdDisasmF , "disassemble [startaddr [endaddress]]\tdisassemble asm commands\n" },
104 { "delete" , cmdDelUserBp ,
105 "{d}elete n\t\t clears break point number n\n"
107 { "display" , cmdDisplay ,
108 "display [/<fmt>] [<variable>]\t print value of given variable each time the program stops\n"
110 { "undisplay" , cmdUnDisplay ,
111 "undisplay [<variable>]\t dont display this variable or all\n"
114 "down\t\tSelect and print stack frame called by this one.\nAn argument says how many frames down to go.\n"
117 "up\t\tSelect and print stack frame that called this one.\nAn argument says how many frames up to go.\n"
119 { "d" , cmdDelUserBp , NULL },
122 "info <break stack frame registers all-registers>\n"
123 "\t list all break points, call-stack, frame or register information\n"
126 { "listasm" , cmdListAsm ,
127 "listasm {la}\t\t list assembler code for the current C line\n"
129 { "la" , cmdListAsm , NULL },
130 { "ls" , cmdListSymbols , "ls,lf,lm\t\t list symbols,functions,modules\n" },
131 { "lf" , cmdListFunctions, NULL },
132 { "lm" , cmdListModules , NULL },
133 { "list" , cmdListSrc ,
134 "{l}ist\t\t\t [LINE | FILE:LINE | FILE:FUNCTION | FUNCTION]\n"
136 { "l" , cmdListSrc , NULL },
139 " <copying warranty>\t copying & distribution terms, warranty\n"
141 { "set" , cmdSetOption , "set <srcmode>\t\t toggle between c/asm.\nset variable <var> = >value\t\tset variable to new value\n" },
142 { "stepi" , cmdStepi ,
143 "stepi\t\t\tStep one instruction exactly.\n"
146 "{s}tep\t\t\tStep program until it reaches a different source line.\n"
148 { "source" , cmdSource ,
149 "source <FILE>\t\t\tRead commands from a file named FILE.\n"
151 { "s" , cmdStep , NULL },
152 { "nexti" , cmdNexti ,
153 "nexti\t\t\tStep one instruction, but proceed through subroutine calls.\n"
156 "{n}ext\t\t\tStep program, proceeding through subroutine calls.\n"
158 { "n" , cmdNext , NULL },
160 "{r}un\t\t\tStart debugged program. \n"
162 { "r" , cmdRun , NULL },
163 { "ptype" , cmdPrintType ,
164 "{pt}ype <variable>\tprint type information of a variable\n"
166 { "pt" , cmdPrintType , NULL },
167 { "print" , cmdPrint ,
168 "{p}rint <variable>\t print value of given variable\n"
170 { "output" , cmdOutput ,
171 "output <variable>\t print value of given variable without $ and newline \n"
173 { "p" , cmdPrint , NULL },
175 "file <filename>\t\t load symbolic information from <filename>\n"
177 { "frame" , cmdFrame ,
178 "{fr}ame\t\t print information about the current Stack\n"
180 { "finish" , cmdFinish ,
181 "{fi}nish\t\t execute till return of current function\n"
183 { "fi" , cmdFinish , NULL },
184 { "where" , cmdWhere , "where\t\t print stack\n" },
185 { "fr" , cmdFrame , NULL },
186 { "f" , cmdFrame , NULL },
187 { "x /i" , cmdDisasm1 , "x\t\t disassemble one asm command\n" },
188 { "!" , cmdSimulator ,
189 "!<simulator command>\t send a command directly to the simulator\n"
191 { "." , cmdSimulator ,
192 ".{cmd}\t switch from simulator or debugger command mode\n"
195 "{h|?}elp\t [CMD_NAME | 0,1,2,3(help page)] (general help or specific help)\n"
197 { "?" , cmdHelp , NULL },
198 { "h" , cmdHelp , NULL },
201 "{q}uit\t\t\t \"Watch me now. Iam going Down. My name is Bobby Brown\"\n"
203 { "q" , cmdQuit , NULL }
206 /*-----------------------------------------------------------------*/
207 /* gc_strdup - make a string duplicate garbage collector aware */
208 /*-----------------------------------------------------------------*/
209 char *gc_strdup(const char *s)
212 ret = Safe_malloc(strlen(s)+1);
217 /*-----------------------------------------------------------------*/
218 /* alloccpy - allocate copy and return a new string */
219 /*-----------------------------------------------------------------*/
220 char *alloccpy ( char *s, int size)
227 d = Safe_malloc(size+1);
234 /*-----------------------------------------------------------------*/
235 /* resize - resizes array of type with new size */
236 /*-----------------------------------------------------------------*/
237 void **resize (void **array, int newSize)
242 vptr = Safe_realloc(array,newSize*(sizeof(void **)));
244 vptr = calloc(1, sizeof(void **));
247 fprintf(stderr,"sdcdb: out of memory \n");
255 /*-----------------------------------------------------------------*/
256 /* readCdb - reads the cdb files & puts the records into cdbLine */
258 /*-----------------------------------------------------------------*/
259 static int readCdb (FILE *file)
265 if (!(bp = fgets(buffer,sizeof(buffer),file)))
268 currl = Safe_calloc(1,sizeof(cdbrecs));
273 /* make sure this is a cdb record */
274 if (strchr("STLFM",*bp) && *(bp+1) == ':') {
275 /* depending on the record type */
280 currl->type = SYM_REC;
283 currl->type = STRUCT_REC;
286 currl->type = LNK_REC;
289 currl->type = FUNC_REC;
292 currl->type = MOD_REC ;
296 currl->line = Safe_malloc(strlen(bp));
297 strncpy(currl->line,bp,strlen(bp)-1);
298 currl->line[strlen(bp)-1] = '\0';
301 if (!(bp = fgets(buffer,sizeof(buffer),file)))
307 currl->next = Safe_calloc(1,sizeof(cdbrecs));
311 return (recsRoot->line ? 1 : 0);
314 /*-----------------------------------------------------------------*/
315 /* searchDirsFname - search directory list & return the filename */
316 /*-----------------------------------------------------------------*/
317 char *searchDirsFname (char *fname)
323 /* first try the current directory */
324 if ((rfile = fopen(fname,"r"))) {
326 return strdup(fname) ;
330 return strdup(fname);
332 /* make a copy of the source directories */
333 dirs = sdirs = strdup(ssdirl);
335 /* assume that the separator is ':'
336 and try for each directory in the search list */
337 dirs = strtok(dirs,":");
339 if (dirs[strlen(dirs)] == '/')
340 sprintf(buffer,"%s%s",dirs,fname);
342 sprintf(buffer,"%s/%s",dirs,fname);
343 if ((rfile = fopen(buffer,"r")))
345 dirs = strtok(NULL,":");
351 return strdup(buffer);
353 return strdup(fname);
356 /*-----------------------------------------------------------------*/
357 /* searchDirsFopen - go thru list of directories for filename given*/
358 /*-----------------------------------------------------------------*/
359 FILE *searchDirsFopen(char *fname)
365 /* first try the current directory */
366 if ((rfile = fopen(fname,"r")))
371 /* make a copy of the source directories */
372 dirs = sdirs = strdup(ssdirl);
374 /* assume that the separator is ':'
375 and try for each directory in the search list */
376 dirs = strtok(dirs,":");
378 sprintf(buffer,"%s/%s",dirs,fname);
379 if ((rfile = fopen(buffer,"r")))
381 dirs = strtok(NULL,":");
389 /*-----------------------------------------------------------------*/
390 /* loadFile - loads a file into module buffer */
391 /*-----------------------------------------------------------------*/
392 srcLine **loadFile (char *name, int *nlines)
397 srcLine **slines = NULL;
400 if (!(mfile = searchDirsFopen(name))) {
401 fprintf(stderr,"sdcdb: cannot open module %s -- use '--directory=<source directory> option\n",name);
405 while ((bp = fgets(buffer,sizeof(buffer),mfile))) {
408 slines = (srcLine **)resize((void **)slines,*nlines);
410 slines[(*nlines)-1] = Safe_calloc(1,sizeof(srcLine));
411 slines[(*nlines)-1]->src = alloccpy(bp,strlen(bp));
419 /*-----------------------------------------------------------------*/
420 /* loadModules - reads the source files into module structure */
421 /*-----------------------------------------------------------------*/
422 static void loadModules ()
428 /* go thru the records & find out the module
429 records & load the modules specified */
430 for ( loop = recsRoot ; loop ; loop = loop->next ) {
432 switch (loop->type) {
433 /* for module records do */
435 currMod = parseModule(loop->line,TRUE);
436 currModName = currMod->name ;
438 currMod->cfullname = searchDirsFname(currMod->c_name);
440 /* load it into buffer */
441 currMod->cLines = loadFile (currMod->c_name,
444 /* do the same for the assembler file */
445 currMod->afullname = searchDirsFname(currMod->asm_name);
446 currMod->asmLines=loadFile (currMod->asm_name,
447 &currMod->nasmLines);
450 /* if this is a function record */
452 parseFunc(loop->line);
455 /* if this is a structure record */
457 parseStruct(loop->line);
460 /* if symbol then parse the symbol */
462 parseSymbol(loop->line,&rs,2);
466 parseLnkRec(loop->line);
472 /*-----------------------------------------------------------------*/
473 /* generate extra sets of sfr and sbit symbols */
474 /*-----------------------------------------------------------------*/
475 static void specialFunctionRegs ()
478 for (sym = setFirstItem(symbols);
480 sym = setNextItem(symbols))
482 if ( sym->addrspace == 'I' ||
483 sym->addrspace == 'J')
485 addSet(&sfrsymbols,sym);
489 /*-----------------------------------------------------------------*/
490 /* functionPoints - determine the execution points within a func */
491 /*-----------------------------------------------------------------*/
492 static void functionPoints ()
498 /* for all functions do */
499 for ( func = setFirstItem(functions); func;
500 func = setNextItem(functions)) {
506 Dprintf(D_sdcdb, ("sdcdb: func '%s' has entry '0x%x' exit '0x%x'\n",
511 if (!func->sym->addr && !func->sym->eaddr)
514 /* for all source lines in the module find
515 the ones with address >= start and <= end
516 and put them in the point */
518 if (! applyToSet(modules,moduleWithName,func->modName,&mod))
521 func->entryline= INT_MAX;
523 func->aentryline = INT_MAX ;
526 /* do it for the C Lines first */
527 for ( j = 0 ; j < mod->ncLines ; j++ ) {
528 if (mod->cLines[j]->addr >= sym->addr &&
529 mod->cLines[j]->addr <= sym->eaddr ) {
532 /* add it to the execution point */
533 if (func->entryline > j)
536 if (func->exitline < j)
539 ep = Safe_calloc(1,sizeof(exePoint));
540 ep->addr = mod->cLines[j]->addr ;
542 ep->block= mod->cLines[j]->block;
543 ep->level= mod->cLines[j]->level;
544 addSet(&func->cfpoints,ep);
547 /* check double line execution points of module */
548 for (ep = setFirstItem(mod->cfpoints); ep;
549 ep = setNextItem(mod->cfpoints))
551 if (ep->addr >= sym->addr &&
552 ep->addr <= sym->eaddr )
554 addSet(&func->cfpoints,ep);
557 /* do the same for asm execution points */
558 for ( j = 0 ; j < mod->nasmLines ; j++ ) {
559 if (mod->asmLines[j]->addr >= sym->addr &&
560 mod->asmLines[j]->addr <= sym->eaddr ) {
563 /* add it to the execution point */
564 if (func->aentryline > j)
565 func->aentryline = j;
567 if (func->aexitline < j)
570 /* add it to the execution point */
571 ep = Safe_calloc(1,sizeof(exePoint));
572 ep->addr = mod->asmLines[j]->addr ;
574 addSet(&func->afpoints,ep);
579 if (!( D_sdcdb & sdcdbDebug))
582 Dprintf(D_sdcdb, ("sdcdb: function '%s' has the following C exePoints\n",
587 for (ep = setFirstItem(func->cfpoints); ep;
588 ep = setNextItem(func->cfpoints))
589 Dprintf(D_sdcdb, ("sdcdb: {0x%x,%d} %s",
590 ep->addr,ep->line+1,mod->cLines[ep->line]->src));
592 Dprintf(D_sdcdb, ("sdcdb: and the following ASM exePoints\n"));
593 for (ep = setFirstItem(func->afpoints); ep;
594 ep = setNextItem(func->afpoints))
595 Dprintf (D_sdcdb, ("sdcdb: {0x%x,%d} %s",
596 ep->addr,ep->line+1,mod->asmLines[ep->line]->src));
603 /*-----------------------------------------------------------------*/
604 /* setEntryExitBP - set the entry & exit Break Points for functions*/
605 /*-----------------------------------------------------------------*/
606 DEFSETFUNC(setEntryExitBP)
608 function *func = item;
610 if (func->sym && func->sym->addr && func->sym->eaddr) {
612 /* set the entry break point */
613 setBreakPoint (func->sym->addr , CODE , FENTRY ,
614 fentryCB ,func->mod->c_name , func->entryline);
616 /* set the exit break point */
617 setBreakPoint (func->sym->eaddr , CODE , FEXIT ,
618 fexitCB ,func->mod->c_name , func->exitline );
624 /*-----------------------------------------------------------------*/
625 /* cmdFile - load file into the debugger */
626 /*-----------------------------------------------------------------*/
627 int cmdFile (char *s,context *cctxt)
633 while (isspace(*s)) s++;
635 fprintf(stdout,"No exec file now.\nNo symbol file now.\n");
639 sprintf(buffer,"%s.cdb",s);
640 /* try creating the cdbfile */
641 if (!(cdbFile = searchDirsFopen(buffer))) {
642 fprintf(stdout,"Cannot open file\"%s\", no symbolic information loaded\n",buffer);
646 /* allocate for context */
647 currCtxt = Safe_calloc(1,sizeof(context));
650 /* readin the debug information */
651 if (!readCdb (cdbFile)) {
652 fprintf(stdout,"No symbolic information found in file %s.cdb\n",s);
657 /* parse and load the modules required */
660 /* determine the execution points for this
664 /* extract known special function registers */
665 specialFunctionRegs();
667 /* start the simulator & setup connection to it */
669 openSimulator((char **)simArgs,nsimArgs);
670 fprintf(stdout,"%s",simResponse());
671 /* now send the filename to be loaded to the simulator */
672 sprintf(buffer,"%s.ihx",s);
673 bp=searchDirsFname(buffer);
677 /*set the break points
678 required by the debugger . i.e. the function entry
679 and function exit break points */
680 applyToSet(functions,setEntryExitBP);
686 /*-----------------------------------------------------------------*/
687 /* cmdSource - read commands from file */
688 /*-----------------------------------------------------------------*/
689 int cmdSource (char *s, context *cctxt)
692 char *bp = s+strlen(s) -1;
697 while (isspace(*bp)) bp--;
700 if (!( cmdfile = searchDirsFopen(s)))
702 fprintf(stderr,"commandfile '%s' not found\n",s);
705 commandLoop( cmdfile );
710 /*-----------------------------------------------------------------*/
711 /* cmdHelp - help command */
712 /*-----------------------------------------------------------------*/
713 int cmdHelp (char *s, context *cctxt)
722 endline = ((*s - '0') * 20) + 20;
724 startline = endline - 20;
728 for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++)
730 if ((cmdTab[i].htxt) && !strcmp(cmdTab[i].cmd,s))
732 s = strrchr(cmdTab[i].htxt,'\t');
737 fprintf(stdout,"%s",s);
744 for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++) {
746 /* command string matches */
748 if ((cmdTab[i].htxt) && (i >= startline))
749 fprintf(stdout,"%s",cmdTab[i].htxt);
757 #define MAX_CMD_LEN 512
758 static char cmdbuff[MAX_CMD_LEN];
759 static int sim_cmd_mode = 0;
761 /*-----------------------------------------------------------------
762 interpretCmd - interpret and do the command. Return 0 to continue,
763 return 1 to exit program.
764 |-----------------------------------------------------------------*/
765 int interpretCmd (char *s)
767 static char *pcmd = NULL;
771 /* if nothing & previous command exists then
772 execute the previous command again */
773 if (*s == '\n' && pcmd)
776 /* if previous command exists & is different
777 from the current command then copy it */
779 if (strcmp(pcmd,s)) {
786 /* lookup the command table and do the task required */
790 if (strcmp(s,".") == 0) {
794 else if (s[0] == '.') {
795 /* kill the preceeding '.' and pass on as SDCDB command */
802 cmdSimulator (s, currCtxt);
806 if (strcmp(s,".") ==0) {
812 for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++) {
814 /* command string matches */
815 if (strncmp(s,cmdTab[i].cmd,strlen(cmdTab[i].cmd)) == 0) {
816 if (!cmdTab[i].cmdfunc)
819 rv = (*cmdTab[i].cmdfunc)(s + strlen(cmdTab[i].cmd),currCtxt);
821 /* if full name then give the file name & position */
822 if (fullname && showfull && currCtxt && currCtxt->func) {
824 if (srcMode == SRC_CMODE)
825 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
826 currCtxt->func->mod->cfullname,
827 currCtxt->cline+1,currCtxt->addr);
829 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
830 currCtxt->func->mod->afullname,
831 currCtxt->asmline,currCtxt->addr);
832 displayAll(currCtxt);
838 fprintf(stdout,"Undefined command: \"%s\". Try \"help\".\n",s);
843 static FILE *actualcmdfile=NULL ;
844 static char *actualcmds=NULL;
845 static int stopcmdlist;
846 /*-----------------------------------------------------------------*/
847 /* getNextCmdLine get additional lines used by special commands */
848 /*-----------------------------------------------------------------*/
849 char *getNextCmdLine()
851 //fprintf(stderr,"getNextCmdLine() actualcmdfile=%p\n",actualcmdfile);
856 if (fgets(cmdbuff,sizeof(cmdbuff),actualcmdfile) == NULL)
858 // fprintf(stderr,"getNextCmdLine() returns null\n");
861 //fprintf(stderr,"getNextCmdLine() returns: %s",cmdbuff);
865 void setCmdLine( char *cmds )
870 void stopCommandList()
875 /*-----------------------------------------------------------------*/
876 /* commandLoop - the main command loop or loop over command file */
877 /*-----------------------------------------------------------------*/
878 static void commandLoop(FILE *cmdfile)
880 char *line, save_ch, *s;
881 actualcmdfile = cmdfile;
884 if ( cmdfile == stdin )
889 fprintf(stdout,"(sdcdb) ");
893 //fprintf(stderr,"commandLoop actualcmdfile=%p cmdfile=%p\n",
894 // actualcmdfile,cmdfile);
895 if (fgets(cmdbuff,sizeof(cmdbuff),cmdfile) == NULL)
898 if (interpretCmd(cmdbuff))
903 strcpy(cmdbuff,actualcmds);
906 for ( line = cmdbuff; *line ; line = s )
908 if ( (s=strchr(line ,'\n')))
918 if (interpretCmd( line ))
931 /*-----------------------------------------------------------------*/
932 /* printVersionInfo - print the version information */
933 /*-----------------------------------------------------------------*/
934 static void printVersionInfo()
937 "SDCDB is free software and you are welcome to distribute copies of it\n"
938 "under certain conditions; type \"show copying\" to see the conditions.\n"
939 "There is absolutely no warranty for SDCDB; type \"show warranty\" for details.\n"
940 "SDCDB 0.8 . Copyright (C) 1999 Sandeep Dutta (sandeep.dutta@usa.net)\n"
941 "Type ? for help\n");
945 /*-----------------------------------------------------------------*/
946 /* parseCmdLine - parse the commandline arguments */
947 /*-----------------------------------------------------------------*/
948 static void parseCmdLine (int argc, char **argv)
951 char *filename = NULL;
952 int passon_args_flag = 0; /* if true, pass on args to simulator */
954 Dprintf(D_sdcdb, ("sdcdb: parseCmdLine\n"));
957 for ( i = 1; i < argc ; i++) {
958 //fprintf(stdout,"%s\n",argv[i]);
960 if (passon_args_flag) { /* if true, pass on args to simulator */
961 simArgs[nsimArgs++] = strdup(argv[i]);
965 /* if this is an option */
966 if (argv[i][0] == '-') {
968 /* if directory then mark directory */
969 if (strncmp(argv[i],"--directory=",12) == 0) {
971 ssdirl = &argv[i][12];
973 char *p = Safe_malloc(strlen(ssdirl)+strlen(&argv[i][12])+2);
974 strcat(strcat(strcpy(p,&argv[i][12]),":"),ssdirl);
980 if (strncmp(argv[i],"-fullname",9) == 0) {
985 if (strcmp(argv[i],"-cd") == 0) {
991 if (strncmp(argv[i],"-cd=",4) == 0) {
997 if (strncmp(argv[i],"-d=",3) == 0) {
998 sdcdbDebug = strtol(&argv[i][3],0,0);
1002 if (strncmp(argv[i],"-contsim",8) == 0) {
1006 if (strncmp(argv[i],"-q",2) == 0) {
1011 if (strncmp(argv[i],"-m",2) == 0) {
1012 strncpy(model_str, &argv[i][2], 15);
1013 if (strcmp(model_str,"avr") == 0)
1014 simArgs[0] = "savr";
1015 else if (strcmp(model_str,"xa") == 0)
1017 else if (strcmp(model_str,"z80") == 0)
1018 simArgs[0] = "sz80";
1022 /* -z all remaining options are for simulator */
1023 if (strcmp(argv[i],"-z") == 0) {
1024 passon_args_flag = 1;
1028 /* the simulator arguments */
1031 if (strcmp(argv[i],"-t") == 0 ||
1032 strcmp(argv[i],"-cpu") == 0) {
1034 simArgs[nsimArgs++] = "-t";
1035 simArgs[nsimArgs++] = strdup(argv[++i]);
1039 /* XTAL Frequency */
1040 if (strcmp(argv[i],"-X") == 0 ||
1041 strcmp(argv[i],"-frequency") == 0) {
1042 simArgs[nsimArgs++] = "-X";
1043 simArgs[nsimArgs++] = strdup(argv[++i]);
1048 if ( (strcmp(argv[i],"-S") == 0) ||
1049 (strcmp(argv[i],"-s") == 0)) {
1050 simArgs[nsimArgs++] = strdup(argv[i]);
1051 simArgs[nsimArgs++] = strdup(argv[++i]);
1055 /* network serial port */
1056 if ( (strcmp(argv[i],"-k") == 0)) {
1057 simArgs[nsimArgs++] = strdup(argv[i]);
1058 simArgs[nsimArgs++] = strdup(argv[++i]);
1062 fprintf(stderr,"unknown option %s --- ignored\n",
1066 /* must be file name */
1068 fprintf(stderr,"too many filenames .. parameter '%s' ignored\n",
1073 filename = strtok(argv[i],".");
1079 cmdFile(filename,NULL);
1082 /*-----------------------------------------------------------------*/
1083 /* setsignals - catch some signals */
1084 /*-----------------------------------------------------------------*/
1097 /* may be interrupt from user: stop debugger and also simulator */
1103 /* the only child can be the simulator */
1104 static void sigchld(int sig)
1106 /* the only child can be the simulator */
1108 retpid = wait ( &status );
1109 /* if ( retpid == simPid ) */
1116 signal(SIGHUP , SIG_IGN);
1117 signal(SIGCONT, SIG_IGN);
1118 signal(SIGINT , sigintr );
1119 signal(SIGTERM, bad_signal);
1120 signal(SIGCHLD, sigchld );
1122 signal(SIGABRT, bad_signal);
1123 signal(SIGALRM, bad_signal);
1124 //signal(SIGFPE, bad_signal);
1125 //signal(SIGILL, bad_signal);
1126 signal(SIGPIPE, bad_signal);
1127 signal(SIGQUIT, bad_signal);
1128 //signal(SIGSEGV, bad_signal);
1131 /*-----------------------------------------------------------------*/
1133 /*-----------------------------------------------------------------*/
1135 int main ( int argc, char **argv)
1138 printf("WARNING: SDCDB is EXPERIMENTAL.\n");
1140 simArgs[nsimArgs++] = "s51";
1141 simArgs[nsimArgs++] = "-P";
1142 simArgs[nsimArgs++] = "-r 9756";
1143 /* parse command line */
1146 parseCmdLine(argc,argv);