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));
412 slines[(*nlines)-1]->addr= INT_MAX;
420 /*-----------------------------------------------------------------*/
421 /* loadModules - reads the source files into module structure */
422 /*-----------------------------------------------------------------*/
423 static void loadModules ()
429 /* go thru the records & find out the module
430 records & load the modules specified */
431 for ( loop = recsRoot ; loop ; loop = loop->next ) {
433 switch (loop->type) {
434 /* for module records do */
436 currMod = parseModule(loop->line,TRUE);
437 currModName = currMod->name ;
439 currMod->cfullname = searchDirsFname(currMod->c_name);
441 /* load it into buffer */
442 currMod->cLines = loadFile (currMod->c_name,
445 /* do the same for the assembler file */
446 currMod->afullname = searchDirsFname(currMod->asm_name);
447 currMod->asmLines=loadFile (currMod->asm_name,
448 &currMod->nasmLines);
451 /* if this is a function record */
453 parseFunc(loop->line);
456 /* if this is a structure record */
458 parseStruct(loop->line);
461 /* if symbol then parse the symbol */
463 parseSymbol(loop->line,&rs,2);
467 parseLnkRec(loop->line);
473 /*-----------------------------------------------------------------*/
474 /* generate extra sets of sfr and sbit symbols */
475 /*-----------------------------------------------------------------*/
476 static void specialFunctionRegs ()
479 for (sym = setFirstItem(symbols);
481 sym = setNextItem(symbols))
483 if ( sym->addrspace == 'I' ||
484 sym->addrspace == 'J')
486 addSet(&sfrsymbols,sym);
490 /*-----------------------------------------------------------------*/
491 /* functionPoints - determine the execution points within a func */
492 /*-----------------------------------------------------------------*/
493 static void functionPoints ()
499 // add _main dummy for runtime env
500 if ((func = needExtraMainFunction()))
504 /* alloc new _main function */
505 func1 = Safe_calloc(1,sizeof(function));
507 func1->sym = Safe_calloc(1,sizeof(symbol));
508 *func1->sym = *func->sym;
509 func1->sym->name = alloccpy("_main",5);
510 func1->sym->rname = alloccpy("G$_main$0$",10);
511 /* TODO must be set by symbol information */
512 func1->sym->addr = 0;
513 func1->sym->eaddr = 0x2f;
514 addSet(&functions,func1);
517 /* for all functions do */
518 for ( func = setFirstItem(functions); func;
519 func = setNextItem(functions)) {
525 Dprintf(D_sdcdb, ("sdcdb: func '%s' has entry '0x%x' exit '0x%x'\n",
530 if (!func->sym->addr && !func->sym->eaddr)
533 /* for all source lines in the module find
534 the ones with address >= start and <= end
535 and put them in the point */
537 if (! applyToSet(modules,moduleWithName,func->modName,&mod))
540 func->entryline= INT_MAX-2;
542 func->aentryline = INT_MAX-2 ;
545 /* do it for the C Lines first */
546 for ( j = 0 ; j < mod->ncLines ; j++ ) {
547 if (mod->cLines[j]->addr < INT_MAX &&
548 mod->cLines[j]->addr >= sym->addr &&
549 mod->cLines[j]->addr <= sym->eaddr ) {
552 /* add it to the execution point */
553 if (func->entryline > j)
556 if (func->exitline < j)
559 ep = Safe_calloc(1,sizeof(exePoint));
560 ep->addr = mod->cLines[j]->addr ;
562 ep->block= mod->cLines[j]->block;
563 ep->level= mod->cLines[j]->level;
564 addSet(&func->cfpoints,ep);
567 /* check double line execution points of module */
568 for (ep = setFirstItem(mod->cfpoints); ep;
569 ep = setNextItem(mod->cfpoints))
571 if (ep->addr >= sym->addr &&
572 ep->addr <= sym->eaddr )
574 addSet(&func->cfpoints,ep);
577 /* do the same for asm execution points */
578 for ( j = 0 ; j < mod->nasmLines ; j++ ) {
579 if (mod->asmLines[j]->addr < INT_MAX &&
580 mod->asmLines[j]->addr >= sym->addr &&
581 mod->asmLines[j]->addr <= sym->eaddr ) {
584 /* add it to the execution point */
585 if (func->aentryline > j)
586 func->aentryline = j;
588 if (func->aexitline < j)
591 /* add it to the execution point */
592 ep = Safe_calloc(1,sizeof(exePoint));
593 ep->addr = mod->asmLines[j]->addr ;
595 addSet(&func->afpoints,ep);
598 if ( func->entryline == INT_MAX-2 )
600 if ( func->aentryline == INT_MAX-2 )
601 func->aentryline = 0;
604 if (!( D_sdcdb & sdcdbDebug))
607 Dprintf(D_sdcdb, ("sdcdb: function '%s' has the following C exePoints\n",
612 for (ep = setFirstItem(func->cfpoints); ep;
613 ep = setNextItem(func->cfpoints))
614 Dprintf(D_sdcdb, ("sdcdb: {0x%x,%d} %s",
615 ep->addr,ep->line+1,mod->cLines[ep->line]->src));
617 Dprintf(D_sdcdb, ("sdcdb: and the following ASM exePoints\n"));
618 for (ep = setFirstItem(func->afpoints); ep;
619 ep = setNextItem(func->afpoints))
620 Dprintf (D_sdcdb, ("sdcdb: {0x%x,%d} %s",
621 ep->addr,ep->line+1,mod->asmLines[ep->line]->src));
628 /*-----------------------------------------------------------------*/
629 /* setEntryExitBP - set the entry & exit Break Points for functions*/
630 /*-----------------------------------------------------------------*/
631 DEFSETFUNC(setEntryExitBP)
633 function *func = item;
635 if (func->sym && func->sym->addr && func->sym->eaddr) {
637 /* set the entry break point */
638 setBreakPoint (func->sym->addr , CODE , FENTRY ,
639 fentryCB ,func->mod->c_name , func->entryline);
641 /* set the exit break point */
642 setBreakPoint (func->sym->eaddr , CODE , FEXIT ,
643 fexitCB ,func->mod->c_name , func->exitline );
649 /*-----------------------------------------------------------------*/
650 /* cmdFile - load file into the debugger */
651 /*-----------------------------------------------------------------*/
652 int cmdFile (char *s,context *cctxt)
658 while (isspace(*s)) s++;
660 fprintf(stdout,"No exec file now.\nNo symbol file now.\n");
664 sprintf(buffer,"%s.cdb",s);
665 /* try creating the cdbfile */
666 if (!(cdbFile = searchDirsFopen(buffer))) {
667 fprintf(stdout,"Cannot open file\"%s\", no symbolic information loaded\n",buffer);
671 /* allocate for context */
672 currCtxt = Safe_calloc(1,sizeof(context));
675 /* readin the debug information */
676 if (!readCdb (cdbFile)) {
677 fprintf(stdout,"No symbolic information found in file %s.cdb\n",s);
682 /* parse and load the modules required */
685 /* determine the execution points for this
689 /* extract known special function registers */
690 specialFunctionRegs();
692 /* start the simulator & setup connection to it */
694 openSimulator((char **)simArgs,nsimArgs);
695 fprintf(stdout,"%s",simResponse());
696 /* now send the filename to be loaded to the simulator */
697 sprintf(buffer,"%s.ihx",s);
698 bp=searchDirsFname(buffer);
702 /*set the break points
703 required by the debugger . i.e. the function entry
704 and function exit break points */
705 applyToSet(functions,setEntryExitBP);
711 /*-----------------------------------------------------------------*/
712 /* cmdSource - read commands from file */
713 /*-----------------------------------------------------------------*/
714 int cmdSource (char *s, context *cctxt)
717 char *bp = s+strlen(s) -1;
722 while (isspace(*bp)) bp--;
725 if (!( cmdfile = searchDirsFopen(s)))
727 fprintf(stderr,"commandfile '%s' not found\n",s);
730 commandLoop( cmdfile );
735 /*-----------------------------------------------------------------*/
736 /* cmdHelp - help command */
737 /*-----------------------------------------------------------------*/
738 int cmdHelp (char *s, context *cctxt)
747 endline = ((*s - '0') * 20) + 20;
749 startline = endline - 20;
753 for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++)
755 if ((cmdTab[i].htxt) && !strcmp(cmdTab[i].cmd,s))
757 s = strrchr(cmdTab[i].htxt,'\t');
762 fprintf(stdout,"%s",s);
769 for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++) {
771 /* command string matches */
773 if ((cmdTab[i].htxt) && (i >= startline))
774 fprintf(stdout,"%s",cmdTab[i].htxt);
782 #define MAX_CMD_LEN 512
783 static char cmdbuff[MAX_CMD_LEN];
784 static int sim_cmd_mode = 0;
786 /*-----------------------------------------------------------------
787 interpretCmd - interpret and do the command. Return 0 to continue,
788 return 1 to exit program.
789 |-----------------------------------------------------------------*/
790 int interpretCmd (char *s)
792 static char *pcmd = NULL;
796 /* if nothing & previous command exists then
797 execute the previous command again */
798 if (*s == '\n' && pcmd)
801 /* if previous command exists & is different
802 from the current command then copy it */
804 if (strcmp(pcmd,s)) {
811 /* lookup the command table and do the task required */
815 if (strcmp(s,".") == 0) {
819 else if (s[0] == '.') {
820 /* kill the preceeding '.' and pass on as SDCDB command */
827 cmdSimulator (s, currCtxt);
831 if (strcmp(s,".") ==0) {
837 for (i = 0 ; i < (sizeof(cmdTab)/sizeof(struct cmdtab)) ; i++) {
839 /* command string matches */
840 if (strncmp(s,cmdTab[i].cmd,strlen(cmdTab[i].cmd)) == 0) {
841 if (!cmdTab[i].cmdfunc)
844 rv = (*cmdTab[i].cmdfunc)(s + strlen(cmdTab[i].cmd),currCtxt);
846 /* if full name then give the file name & position */
847 if (fullname && showfull && currCtxt && currCtxt->func) {
849 if (srcMode == SRC_CMODE)
850 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
851 currCtxt->func->mod->cfullname,
852 currCtxt->cline+1,currCtxt->addr);
854 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
855 currCtxt->func->mod->afullname,
856 currCtxt->asmline,currCtxt->addr);
857 displayAll(currCtxt);
863 fprintf(stdout,"Undefined command: \"%s\". Try \"help\".\n",s);
868 static FILE *actualcmdfile=NULL ;
869 static char *actualcmds=NULL;
870 static int stopcmdlist;
871 /*-----------------------------------------------------------------*/
872 /* getNextCmdLine get additional lines used by special commands */
873 /*-----------------------------------------------------------------*/
874 char *getNextCmdLine()
876 //fprintf(stderr,"getNextCmdLine() actualcmdfile=%p\n",actualcmdfile);
881 if (fgets(cmdbuff,sizeof(cmdbuff),actualcmdfile) == NULL)
883 // fprintf(stderr,"getNextCmdLine() returns null\n");
886 //fprintf(stderr,"getNextCmdLine() returns: %s",cmdbuff);
890 void setCmdLine( char *cmds )
895 void stopCommandList()
900 /*-----------------------------------------------------------------*/
901 /* commandLoop - the main command loop or loop over command file */
902 /*-----------------------------------------------------------------*/
903 static void commandLoop(FILE *cmdfile)
905 char *line, save_ch, *s;
906 actualcmdfile = cmdfile;
909 if ( cmdfile == stdin )
914 fprintf(stdout,"(sdcdb) ");
918 //fprintf(stderr,"commandLoop actualcmdfile=%p cmdfile=%p\n",
919 // actualcmdfile,cmdfile);
920 if (fgets(cmdbuff,sizeof(cmdbuff),cmdfile) == NULL)
923 if (interpretCmd(cmdbuff))
928 strcpy(cmdbuff,actualcmds);
931 for ( line = cmdbuff; *line ; line = s )
933 if ( (s=strchr(line ,'\n')))
943 if (interpretCmd( line ))
956 /*-----------------------------------------------------------------*/
957 /* printVersionInfo - print the version information */
958 /*-----------------------------------------------------------------*/
959 static void printVersionInfo()
962 "SDCDB is free software and you are welcome to distribute copies of it\n"
963 "under certain conditions; type \"show copying\" to see the conditions.\n"
964 "There is absolutely no warranty for SDCDB; type \"show warranty\" for details.\n"
965 "SDCDB 0.8 . Copyright (C) 1999 Sandeep Dutta (sandeep.dutta@usa.net)\n"
966 "Type ? for help\n");
970 /*-----------------------------------------------------------------*/
971 /* parseCmdLine - parse the commandline arguments */
972 /*-----------------------------------------------------------------*/
973 static void parseCmdLine (int argc, char **argv)
976 char *filename = NULL;
977 int passon_args_flag = 0; /* if true, pass on args to simulator */
979 Dprintf(D_sdcdb, ("sdcdb: parseCmdLine\n"));
982 for ( i = 1; i < argc ; i++) {
983 //fprintf(stdout,"%s\n",argv[i]);
985 if (passon_args_flag) { /* if true, pass on args to simulator */
986 simArgs[nsimArgs++] = strdup(argv[i]);
990 /* if this is an option */
991 if (argv[i][0] == '-') {
993 /* if directory then mark directory */
994 if (strncmp(argv[i],"--directory=",12) == 0) {
996 ssdirl = &argv[i][12];
998 char *p = Safe_malloc(strlen(ssdirl)+strlen(&argv[i][12])+2);
999 strcat(strcat(strcpy(p,&argv[i][12]),":"),ssdirl);
1005 if (strncmp(argv[i],"-fullname",9) == 0) {
1010 if (strcmp(argv[i],"-cd") == 0) {
1016 if (strncmp(argv[i],"-cd=",4) == 0) {
1022 if (strncmp(argv[i],"-d=",3) == 0) {
1023 sdcdbDebug = strtol(&argv[i][3],0,0);
1027 if (strncmp(argv[i],"-contsim",8) == 0) {
1031 if (strncmp(argv[i],"-q",2) == 0) {
1036 if (strncmp(argv[i],"-m",2) == 0) {
1037 strncpy(model_str, &argv[i][2], 15);
1038 if (strcmp(model_str,"avr") == 0)
1039 simArgs[0] = "savr";
1040 else if (strcmp(model_str,"xa") == 0)
1042 else if (strcmp(model_str,"z80") == 0)
1043 simArgs[0] = "sz80";
1047 /* -z all remaining options are for simulator */
1048 if (strcmp(argv[i],"-z") == 0) {
1049 passon_args_flag = 1;
1053 /* the simulator arguments */
1056 if (strcmp(argv[i],"-t") == 0 ||
1057 strcmp(argv[i],"-cpu") == 0) {
1059 simArgs[nsimArgs++] = "-t";
1060 simArgs[nsimArgs++] = strdup(argv[++i]);
1064 /* XTAL Frequency */
1065 if (strcmp(argv[i],"-X") == 0 ||
1066 strcmp(argv[i],"-frequency") == 0) {
1067 simArgs[nsimArgs++] = "-X";
1068 simArgs[nsimArgs++] = strdup(argv[++i]);
1073 if ( (strcmp(argv[i],"-S") == 0) ||
1074 (strcmp(argv[i],"-s") == 0)) {
1075 simArgs[nsimArgs++] = strdup(argv[i]);
1076 simArgs[nsimArgs++] = strdup(argv[++i]);
1080 /* network serial port */
1081 if ( (strcmp(argv[i],"-k") == 0)) {
1082 simArgs[nsimArgs++] = strdup(argv[i]);
1083 simArgs[nsimArgs++] = strdup(argv[++i]);
1087 fprintf(stderr,"unknown option %s --- ignored\n",
1091 /* must be file name */
1093 fprintf(stderr,"too many filenames .. parameter '%s' ignored\n",
1098 filename = strtok(argv[i],".");
1104 cmdFile(filename,NULL);
1107 /*-----------------------------------------------------------------*/
1108 /* setsignals - catch some signals */
1109 /*-----------------------------------------------------------------*/
1122 /* may be interrupt from user: stop debugger and also simulator */
1128 /* the only child can be the simulator */
1129 static void sigchld(int sig)
1131 /* the only child can be the simulator */
1133 retpid = wait ( &status );
1134 /* if ( retpid == simPid ) */
1141 signal(SIGHUP , SIG_IGN);
1142 signal(SIGCONT, SIG_IGN);
1143 signal(SIGINT , sigintr );
1144 signal(SIGTERM, bad_signal);
1145 signal(SIGCHLD, sigchld );
1147 signal(SIGABRT, bad_signal);
1148 signal(SIGALRM, bad_signal);
1149 //signal(SIGFPE, bad_signal);
1150 //signal(SIGILL, bad_signal);
1151 signal(SIGPIPE, bad_signal);
1152 signal(SIGQUIT, bad_signal);
1153 //signal(SIGSEGV, bad_signal);
1156 /*-----------------------------------------------------------------*/
1158 /*-----------------------------------------------------------------*/
1160 int main ( int argc, char **argv)
1163 printf("WARNING: SDCDB is EXPERIMENTAL.\n");
1165 simArgs[nsimArgs++] = "s51";
1166 simArgs[nsimArgs++] = "-P";
1167 simArgs[nsimArgs++] = "-r 9756";
1168 /* parse command line */
1171 parseCmdLine(argc,argv);