1 /*-------------------------------------------------------------------------
2 cmd.c - source file for debugger command execution
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
32 /* default number of lines to list out */
35 /* mainly used to retain a reference to the active module being
36 listed. May be used as a general context for other commands if
37 no better context is available */
38 static module *list_mod = NULL;
40 EXTERN_STACK_DCL(callStack,function *,1024);
42 #if defined(__APPLE__) && defined(__MACH__)
44 {" GNU GENERAL PUBLIC LICENSE Version 2"};
45 static char *warranty=
49 " GNU GENERAL PUBLIC LICENSE\n"
50 " Version 2, June 1991\n"
52 " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n"
53 " 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\n"
54 " Everyone is permitted to copy and distribute verbatim copies\n"
55 " of this license document, but changing it is not allowed.\n"
59 " The licenses for most software are designed to take away your\n"
60 "freedom to share and change it. By contrast, the GNU General Public\n"
61 "License is intended to guarantee your freedom to share and change free\n"
62 "software--to make sure the software is free for all its users. This\n"
63 "General Public License applies to most of the Free Software\n"
64 "Foundation's software and to any other program whose authors commit to\n"
65 "using it. (Some other Free Software Foundation software is covered by\n"
66 "the GNU Library General Public License instead.) You can apply it to\n"
67 "your programs, too.\n"
69 " When we speak of free software, we are referring to freedom, not\n"
70 "price. Our General Public Licenses are designed to make sure that you\n"
71 "have the freedom to distribute copies of free software (and charge for\n"
72 "this service if you wish), that you receive source code or can get it\n"
73 "if you want it, that you can change the software or use pieces of it\n"
74 "in new free programs; and that you know you can do these things.\n"
76 " To protect your rights, we need to make restrictions that forbid\n"
77 "anyone to deny you these rights or to ask you to surrender the rights.\n"
78 "These restrictions translate to certain responsibilities for you if you\n"
79 "distribute copies of the software, or if you modify it.\n"
81 " For example, if you distribute copies of such a program, whether\n"
82 "gratis or for a fee, you must give the recipients all the rights that\n"
83 "you have. You must make sure that they, too, receive or can get the\n"
84 "source code. And you must show them these terms so they know their\n"
87 " We protect your rights with two steps: (1) copyright the software, and\n"
88 "(2) offer you this license which gives you legal permission to copy,\n"
89 "distribute and/or modify the software.\n"
91 " Also, for each author's protection and ours, we want to make certain\n"
92 "that everyone understands that there is no warranty for this free\n"
93 "software. If the software is modified by someone else and passed on, we\n"
94 "want its recipients to know that what they have is not the original, so\n"
95 "that any problems introduced by others will not reflect on the original\n"
96 "authors' reputations.\n"
98 " Finally, any free program is threatened constantly by software\n"
99 "patents. We wish to avoid the danger that redistributors of a free\n"
100 "program will individually obtain patent licenses, in effect making the\n"
101 "program proprietary. To prevent this, we have made it clear that any\n"
102 "patent must be licensed for everyone's free use or not licensed at all.\n"
104 " The precise terms and conditions for copying, distribution and\n"
105 "modification follow.\n"
107 " GNU GENERAL PUBLIC LICENSE\n"
108 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
110 " 0. This License applies to any program or other work which contains\n"
111 "a notice placed by the copyright holder saying it may be distributed\n"
112 "under the terms of this General Public License. The \"Program\", below,\n"
113 "refers to any such program or work, and a \"work based on the Program\"\n"
114 "means either the Program or any derivative work under copyright law:\n"
115 "that is to say, a work containing the Program or a portion of it,\n"
116 "either verbatim or with modifications and/or translated into another\n"
117 "language. (Hereinafter, translation is included without limitation in\n"
118 "the term \"modification\".) Each licensee is addressed as \"you\".\n"
120 "Activities other than copying, distribution and modification are not\n"
121 "covered by this License; they are outside its scope. The act of\n"
122 "running the Program is not restricted, and the output from the Program\n"
123 "is covered only if its contents constitute a work based on the\n"
124 "Program (independent of having been made by running the Program).\n"
125 "Whether that is true depends on what the Program does.\n"
127 " 1. You may copy and distribute verbatim copies of the Program's\n"
128 "source code as you receive it, in any medium, provided that you\n"
129 "conspicuously and appropriately publish on each copy an appropriate\n"
130 "copyright notice and disclaimer of warranty; keep intact all the\n"
131 "notices that refer to this License and to the absence of any warranty;\n"
132 "and give any other recipients of the Program a copy of this License\n"
133 "along with the Program.\n"
135 "You may charge a fee for the physical act of transferring a copy, and\n"
136 "you may at your option offer warranty protection in exchange for a fee.\n"
138 " 2. You may modify your copy or copies of the Program or any portion\n"
139 "of it, thus forming a work based on the Program, and copy and\n"
140 "distribute such modifications or work under the terms of Section 1\n"
141 "above, provided that you also meet all of these conditions:\n"
143 " a) You must cause the modified files to carry prominent notices\n"
144 " stating that you changed the files and the date of any change.\n"
146 " b) You must cause any work that you distribute or publish, that in\n"
147 " whole or in part contains or is derived from the Program or any\n"
148 " part thereof, to be licensed as a whole at no charge to all third\n"
149 " parties under the terms of this License.\n"
151 " c) If the modified program normally reads commands interactively\n"
152 " when run, you must cause it, when started running for such\n"
153 " interactive use in the most ordinary way, to print or display an\n"
154 " announcement including an appropriate copyright notice and a\n"
155 " notice that there is no warranty (or else, saying that you provide\n"
156 " a warranty) and that users may redistribute the program under\n"
157 " these conditions, and telling the user how to view a copy of this\n"
158 " License. (Exception: if the Program itself is interactive but\n"
159 " does not normally print such an announcement, your work based on\n"
160 " the Program is not required to print an announcement.)\n"
162 "These requirements apply to the modified work as a whole. If\n"
163 "identifiable sections of that work are not derived from the Program,\n"
164 "and can be reasonably considered independent and separate works in\n"
165 "themselves, then this License, and its terms, do not apply to those\n"
166 "sections when you distribute them as separate works. But when you\n"
167 "distribute the same sections as part of a whole which is a work based\n"
168 "on the Program, the distribution of the whole must be on the terms of\n"
169 "this License, whose permissions for other licensees extend to the\n"
170 "entire whole, and thus to each and every part regardless of who wrote it.\n"
172 "Thus, it is not the intent of this section to claim rights or contest\n"
173 "your rights to work written entirely by you; rather, the intent is to\n"
174 "exercise the right to control the distribution of derivative or\n"
175 "collective works based on the Program.\n"
177 "In addition, mere aggregation of another work not based on the Program\n"
178 "with the Program (or with a work based on the Program) on a volume of\n"
179 "a storage or distribution medium does not bring the other work under\n"
180 "the scope of this License.\n"
182 " 3. You may copy and distribute the Program (or a work based on it,\n"
183 "under Section 2) in object code or executable form under the terms of\n"
184 "Sections 1 and 2 above provided that you also do one of the following:\n"
186 " a) Accompany it with the complete corresponding machine-readable\n"
187 " source code, which must be distributed under the terms of Sections\n"
188 " 1 and 2 above on a medium customarily used for software interchange; or,\n"
190 " b) Accompany it with a written offer, valid for at least three\n"
191 " years, to give any third party, for a charge no more than your\n"
192 " cost of physically performing source distribution, a complete\n"
193 " machine-readable copy of the corresponding source code, to be\n"
194 " distributed under the terms of Sections 1 and 2 above on a medium\n"
195 " customarily used for software interchange; or,\n"
197 " c) Accompany it with the information you received as to the offer\n"
198 " to distribute corresponding source code. (This alternative is\n"
199 " allowed only for noncommercial distribution and only if you\n"
200 " received the program in object code or executable form with such\n"
201 " an offer, in accord with Subsection b above.)\n"
203 "The source code for a work means the preferred form of the work for\n"
204 "making modifications to it. For an executable work, complete source\n"
205 "code means all the source code for all modules it contains, plus any\n"
206 "associated interface definition files, plus the scripts used to\n"
207 "control compilation and installation of the executable. However, as a\n"
208 "special exception, the source code distributed need not include\n"
209 "anything that is normally distributed (in either source or binary\n"
210 "form) with the major components (compiler, kernel, and so on) of the\n"
211 "operating system on which the executable runs, unless that component\n"
212 "itself accompanies the executable.\n"
214 "If distribution of executable or object code is made by offering\n"
215 "access to copy from a designated place, then offering equivalent\n"
216 "access to copy the source code from the same place counts as\n"
217 "distribution of the source code, even though third parties are not\n"
218 "compelled to copy the source along with the object code.\n"
220 " 4. You may not copy, modify, sublicense, or distribute the Program\n"
221 "except as expressly provided under this License. Any attempt\n"
222 "otherwise to copy, modify, sublicense or distribute the Program is\n"
223 "void, and will automatically terminate your rights under this License.\n"
224 "However, parties who have received copies, or rights, from you under\n"
225 "this License will not have their licenses terminated so long as such\n"
226 "parties remain in full compliance.\n"
228 " 5. You are not required to accept this License, since you have not\n"
229 "signed it. However, nothing else grants you permission to modify or\n"
230 "distribute the Program or its derivative works. These actions are\n"
231 "prohibited by law if you do not accept this License. Therefore, by\n"
232 "modifying or distributing the Program (or any work based on the\n"
233 "Program), you indicate your acceptance of this License to do so, and\n"
234 "all its terms and conditions for copying, distributing or modifying\n"
235 "the Program or works based on it.\n"
237 " 6. Each time you redistribute the Program (or any work based on the\n"
238 "Program), the recipient automatically receives a license from the\n"
239 "original licensor to copy, distribute or modify the Program subject to\n"
240 "these terms and conditions. You may not impose any further\n"
241 "restrictions on the recipients' exercise of the rights granted herein.\n"
242 "You are not responsible for enforcing compliance by third parties to\n"
245 " 7. If, as a consequence of a court judgment or allegation of patent\n"
246 "infringement or for any other reason (not limited to patent issues),\n"
247 "conditions are imposed on you (whether by court order, agreement or\n"
248 "otherwise) that contradict the conditions of this License, they do not\n"
249 "excuse you from the conditions of this License. If you cannot\n"
250 "distribute so as to satisfy simultaneously your obligations under this\n"
251 "License and any other pertinent obligations, then as a consequence you\n"
252 "may not distribute the Program at all. For example, if a patent\n"
253 "license would not permit royalty-free redistribution of the Program by\n"
254 "all those who receive copies directly or indirectly through you, then\n"
255 "the only way you could satisfy both it and this License would be to\n"
256 "refrain entirely from distribution of the Program.\n"
258 "If any portion of this section is held invalid or unenforceable under\n"
259 "any particular circumstance, the balance of the section is intended to\n"
260 "apply and the section as a whole is intended to apply in other\n"
263 "It is not the purpose of this section to induce you to infringe any\n"
264 "patents or other property right claims or to contest validity of any\n"
265 "such claims; this section has the sole purpose of protecting the\n"
266 "integrity of the free software distribution system, which is\n"
267 "implemented by public license practices. Many people have made\n"
268 "generous contributions to the wide range of software distributed\n"
269 "through that system in reliance on consistent application of that\n"
270 "system; it is up to the author/donor to decide if he or she is willing\n"
271 "to distribute software through any other system and a licensee cannot\n"
272 "impose that choice.\n"
274 "This section is intended to make thoroughly clear what is believed to\n"
275 "be a consequence of the rest of this License.\n"
277 " 8. If the distribution and/or use of the Program is restricted in\n"
278 "certain countries either by patents or by copyrighted interfaces, the\n"
279 "original copyright holder who places the Program under this License\n"
280 "may add an explicit geographical distribution limitation excluding\n"
281 "those countries, so that distribution is permitted only in or among\n"
282 "countries not thus excluded. In such case, this License incorporates\n"
283 "the limitation as if written in the body of this License.\n"
285 " 9. The Free Software Foundation may publish revised and/or new versions\n"
286 "of the General Public License from time to time. Such new versions will\n"
287 "be similar in spirit to the present version, but may differ in detail to\n"
288 "address new problems or concerns.\n"
290 "Each version is given a distinguishing version number. If the Program\n"
291 "specifies a version number of this License which applies to it and \"any\n"
292 "later version\", you have the option of following the terms and conditions\n"
293 "either of that version or of any later version published by the Free\n"
294 "Software Foundation. If the Program does not specify a version number of\n"
295 "this License, you may choose any version ever published by the Free Software\n"
298 " 10. If you wish to incorporate parts of the Program into other free\n"
299 "programs whose distribution conditions are different, write to the author\n"
300 "to ask for permission. For software which is copyrighted by the Free\n"
301 "Software Foundation, write to the Free Software Foundation; we sometimes\n"
302 "make exceptions for this. Our decision will be guided by the two goals\n"
303 "of preserving the free status of all derivatives of our free software and\n"
304 "of promoting the sharing and reuse of software generally.\n";
306 static char *warranty=
309 " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
310 "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"
311 "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
312 "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
313 "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
314 "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"
315 "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"
316 "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
317 "REPAIR OR CORRECTION.\n"
319 " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
320 "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
321 "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
322 "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
323 "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
324 "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
325 "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
326 "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
327 "POSSIBILITY OF SUCH DAMAGES.\n";
330 static void printTypeInfo(link *);
331 static void printValAggregates (symbol *,link *,char,unsigned int,int);
332 static void printOrSetSymValue (symbol *sym, context *cctxt,
333 int flg, int dnum, int fmt, char *rs, char *val);
335 int srcMode = SRC_CMODE ;
336 static set *dispsymbols = NULL ; /* set of displayable symbols */
337 static int currentFrame = 0; /* actual displayed frame */
338 /*-----------------------------------------------------------------*/
339 /* funcWithName - returns function with name */
340 /*-----------------------------------------------------------------*/
341 DEFSETFUNC(funcWithName)
343 function *func = item;
345 V_ARG(function **,funcp);
350 if (strcmp(func->sym->name,name) == 0) {
358 /*-----------------------------------------------------------------*/
359 /* symWithAddr - look for symbol with sfr / sbit address */
360 /*-----------------------------------------------------------------*/
361 DEFSETFUNC(symWithAddr)
364 V_ARG(unsigned long,laddr);
365 V_ARG(int ,laddrspace);
366 V_ARG(symbol **,rsym);
371 if ( sym->addr == laddr &&
372 sym->addrspace == laddrspace )
381 /*-----------------------------------------------------------------*/
382 /* setBPatModLine - set break point at the line specified for the */
383 /*-----------------------------------------------------------------*/
384 static void setBPatModLine (module *mod, int line)
388 /* look for the first executable line after the line
389 specified & get the break point there */
390 if (srcMode == SRC_CMODE && line > mod->ncLines) {
391 fprintf(stderr,"No line %d in file \"%s\".\n",
396 if (srcMode == SRC_AMODE && line > mod->nasmLines) {
397 fprintf(stderr,"No line %d in file \"%s\".\n",
403 for ( ; next_line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
405 if (srcMode == SRC_CMODE) {
406 if (mod->cLines[next_line]->addr) {
407 setBreakPoint (mod->cLines[next_line]->addr, CODE, USER,
408 userBpCB, mod->c_name, next_line);
414 if (mod->asmLines[next_line]->addr) {
415 setBreakPoint (mod->asmLines[next_line]->addr, CODE, USER,
416 userBpCB, mod->asm_name, next_line);
423 fprintf(stderr,"No line %d or after in file \"%s\"..\n",
429 /*-----------------------------------------------------------------*/
430 /* clearBPatModLine - clr break point at the line specified */
431 /*-----------------------------------------------------------------*/
432 static void clearBPatModLine (module *mod, int line)
434 /* look for the first executable line after the line
435 specified & get the break point there */
436 if (srcMode == SRC_CMODE && line > mod->ncLines) {
437 fprintf(stderr,"No line %d in file \"%s\".\n",
442 if (srcMode == SRC_AMODE && line > mod->ncLines) {
443 fprintf(stderr,"No line %d in file \"%s\".\n",
448 for ( ; line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
450 if (srcMode == SRC_CMODE)
451 if (mod->cLines[line]->addr) {
452 clearUSERbp (mod->cLines[line]->addr);
456 if (mod->asmLines[line]->addr) {
457 clearUSERbp (mod->asmLines[line]->addr);
465 /*-----------------------------------------------------------------*/
466 /* moduleLineWithAddr - finds and returns a line with a given address */
467 /*-----------------------------------------------------------------*/
468 DEFSETFUNC(moduleLineWithAddr)
473 V_ARG(unsigned int,addr);
474 V_ARG(module **,rmod);
480 for (i=0; i < mod->nasmLines; i++ )
482 if ( mod->asmLines[i]->addr == addr)
486 *line = mod->ncLines;
494 /*-----------------------------------------------------------------*/
495 /* funcWithNameModule - returns functions with a name module combo */
496 /*-----------------------------------------------------------------*/
497 DEFSETFUNC(funcWithNameModule)
499 function *func = item;
502 V_ARG(function **,funcp);
507 if (strcmp(func->sym->name,fname) == 0 &&
508 strcmp(func->mod->c_name,mname) == 0) {
516 /*-----------------------------------------------------------------*/
517 /* funcInAddr - given an address returns the function */
518 /*-----------------------------------------------------------------*/
519 DEFSETFUNC(funcInAddr)
521 function *func = item;
522 V_ARG(unsigned int,addr);
523 V_ARG(function **,funcp);
528 /* in the address range */
529 if (func->sym->addr <= addr &&
530 func->sym->eaddr >= addr) {
539 /*-----------------------------------------------------------------*/
540 /* setStepBp - will set STEP Bp @ function entry points */
541 /*-----------------------------------------------------------------*/
542 DEFSETFUNC(setStepBp)
544 function *func = item;
546 if (func->sym && func->sym->addr ) {
548 /* set the entry break point */
549 setBreakPoint (func->sym->addr , CODE , STEP ,
550 stepBpCB ,func->mod->c_name , func->entryline);
558 /*-----------------------------------------------------------------*/
559 /* setStepEPBp - sets a given type of bp @ the execution point */
560 /*-----------------------------------------------------------------*/
561 DEFSETFUNC(setStepEPBp)
567 setBreakPoint (ep->addr, CODE, bptype,
568 stepBpCB, mname, ep->line);
572 /*-----------------------------------------------------------------*/
573 /* setNextEPBp - sets a given type of bp @ the execution point */
574 /*-----------------------------------------------------------------*/
575 DEFSETFUNC(setNextEPBp)
581 setBreakPoint (ep->addr, CODE, bptype,
582 nextBpCB, mname, ep->line);
586 /*-----------------------------------------------------------------*/
587 /* lineAtAddr - for execution points returns the one with addr */
588 /*-----------------------------------------------------------------*/
589 DEFSETFUNC(lineAtAddr)
592 V_ARG(unsigned int,addr);
597 /* address must be an exact match */
598 if (ep->addr == addr) {
611 /*-----------------------------------------------------------------*/
612 /* lineNearAddr - for execution points returns the one with addr */
613 /*-----------------------------------------------------------------*/
614 DEFSETFUNC(lineNearAddr)
617 V_ARG(unsigned int,addr);
622 /* the line in which the address is */
623 if (ep->addr <= addr) {
636 /*-----------------------------------------------------------------*/
637 /* discoverContext - find out the current context of the bp */
638 /*-----------------------------------------------------------------*/
639 context *discoverContext (unsigned addr)
641 function *func = NULL;
647 /* find the function we are in */
648 if (!applyToSet(functions,funcInAddr,addr,&func)) {
649 if (!applyToSet(functions,funcWithName,"main") ||
650 !applyToSet(modules,moduleLineWithAddr,addr,&mod,&line))
652 fprintf(stderr, "Error?:discoverContext: cannot apply to set!\n");
655 currCtxt->func = func;
656 currCtxt->addr = addr;
657 currCtxt->modName = mod->name;
658 currCtxt->cline = func->exitline;
662 currCtxt->func = func;
663 currCtxt->addr = func->laddr = addr;
664 currCtxt->modName = func->modName;
666 /* find the c line number */
667 if(applyToSet(func->cfpoints,lineNearAddr,addr,
668 &line,&currCtxt->block,&currCtxt->level))
669 currCtxt->cline = func->lline = line;
671 currCtxt->cline = func->exitline;
673 /* find the asm line number */
675 if (applyToSet(func->afpoints,lineAtAddr,addr,
677 currCtxt->asmline = line;
679 currCtxt->asmline = -1;
685 /*-----------------------------------------------------------------*/
686 /* simGo - send 'go' cmd to simulator and wait till a break occurs */
687 /*-----------------------------------------------------------------*/
688 void simGo (unsigned int gaddr)
693 static int initial_break_flag = 0;
701 addr = simGoTillBp (gaddr);
703 /* got the pc for the break point now first
704 discover the program context i.e. module, function
705 linenumber of the source etc, etc etc */
706 ctxt = discoverContext (addr);
708 /* dispatch all the break point call back functions */
709 rv = dispatchCB (addr,ctxt);
712 /* the dispatch call back function will return
713 non-zero if an user break point has been hit
714 if not then we continue with the execution
717 if (!initial_break_flag) {
718 initial_break_flag = 1; // kludge to stop only at first run
719 fprintf(stdout, "Stopping at entry. You can now list and set breakpoints\n");
727 // I took this out, after running "run" it would just keep re-running
728 // even after a lot of break points hit. For some reason above code
729 // not triggering(dispatchCB). This seems to be by design, startup adds
730 // a bunch of breakpoints-but they are not USER breakpoints. Perhaps the
731 // debugger changed with its implementation of "go"("run"). It seems we
732 // need to add a "next" or "step" followed by a "run"...
733 // I added a "step" in simi.c when we want a resume function, this seems
736 // still there is question of how do we stop it initially, since
737 // it must be started before it can get a context. If so, we would
738 // want it to just run up to an initial entry point you'd think...
739 // I don't see why we can't set breakpoints before an initial run,
740 // this does not seem right to me.
742 // line #'s are a bit off too.
752 /*-----------------------------------------------------------------*/
753 /* preparePrint - common parse function for */
754 /* output, print and display */
755 /*-----------------------------------------------------------------*/
756 static char *preparePrint(char *s, context *cctxt, int *fmt, symbol **sym)
758 char *bp = s+strlen(s) -1;
764 while (isspace(*s)) s++;
768 while (isspace(*bp)) bp--;
774 /* format of printout */
792 while (isspace(*s)) s++;
794 for ( bp = s; *bp && ( isalnum( *bp ) || *bp == '_'); bp++ );
799 *sym = symLookup(s,cctxt);
803 fprintf(stdout,"No symbol \"%s\" in current context.\n", s);
807 static int printAsmLine( function *func, module *m, long saddr, long eaddr)
811 int lastaddr = saddr+1;
816 symaddr = func->sym->addr;
817 symname = func->sym->name;
824 for (j=0,i=0; i < m->nasmLines; i++ )
826 if ( saddr >= 0 && m->asmLines[i]->addr < saddr)
830 if ( eaddr >= 0 && m->asmLines[i]->addr > eaddr)
835 (m->asmLines[i]->addr < func->sym->addr ||
836 m->asmLines[i]->addr > func->sym->eaddr ))
840 delta = m->asmLines[i]->addr - symaddr;
844 lastaddr = m->asmLines[i]->addr;
845 printf("0x%08x <%s",lastaddr,symname);
846 if (delta > 0) printf("+%d",delta);
847 printf(">:\t%s",m->asmLines[i]->src);
853 /*-----------------------------------------------------------------*/
854 /* cmdDisasm - disassemble asm instruction */
855 /*-----------------------------------------------------------------*/
856 static int cmdDisasm (char *s, context *cctxt, int args)
858 function *func = NULL;
863 /* white space skip */
867 while (*s && isspace(*s)) s++;
871 saddr = strtol(s,&s,0);
874 while (*s && isspace(*s)) s++;
877 eaddr = strtol(s,0,0);
886 /* no start or only start so dump function */
893 applyToSet(functions,funcInAddr,saddr,&func);
897 printf("Dump of assembler code for function %s:\n",func->sym->name);
898 printAsmLine(func,func->mod,-1,-1);
899 printf("End of assembler dump.\n");
904 if (applyToSet(modules,moduleLineWithAddr,saddr,&modul,NULL))
907 printf("Dump of assembler code:\n");
908 printAsmLine(NULL,modul,saddr,eaddr);
909 printf("End of assembler dump.\n");
917 printf("Dump of assembler code from 0x%08x to 0x%08x:\n",saddr,eaddr);
919 while ( saddr < eaddr )
922 if (applyToSet(functions,funcInAddr,saddr,&func))
931 if (!applyToSet(modules,moduleLineWithAddr,saddr,&modul,NULL))
934 saddr = printAsmLine(func,modul,saddr,eaddr) + 1;
939 printf("End of assembler dump.\n");
944 fprintf(stderr,"No function contains specified address.\n");
947 /*-----------------------------------------------------------------*/
948 /* cmdDisasm1 - disassemble one asm instruction */
949 /*-----------------------------------------------------------------*/
950 int cmdDisasm1 (char *s, context *cctxt)
952 return cmdDisasm( s, cctxt, 1);
955 /*-----------------------------------------------------------------*/
956 /* cmdDisasmF - disassemble asm instructions */
957 /*-----------------------------------------------------------------*/
958 int cmdDisasmF(char *s, context *cctxt)
960 return cmdDisasm( s, cctxt, 2);
963 /*-----------------------------------------------------------------*/
964 /* cmdSetUserBp - set break point at the user specified location */
965 /*-----------------------------------------------------------------*/
966 int cmdSetUserBp (char *s, context *cctxt)
969 function *func = NULL;
971 /* user break point location specification can be of the following
973 a) <nothing> - break point at current location
974 b) lineno - number of the current module
975 c) filename:lineno - line number of the given file
976 e) filename:function- function X in file Y (useful for static functions)
977 f) function - function entry point
978 g) *addr - break point at address
982 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
985 /* white space skip */
986 while (*s && isspace(*s)) s++;
988 /* null terminate it after stripping trailing blanks*/
990 while (bp != s && isspace(*bp)) bp--;
993 /* case a) nothing */
994 /* if nothing given then current location : we know
995 the current execution location from the currentContext */
998 /* if current context is known */
1000 if (srcMode == SRC_CMODE)
1001 /* set the break point */
1002 setBreakPoint ( cctxt->addr , CODE , USER , userBpCB ,
1003 cctxt->func->mod->c_name, cctxt->cline);
1005 setBreakPoint ( cctxt->addr , CODE , USER , userBpCB ,
1006 cctxt->func->mod->asm_name, cctxt->asmline);
1010 fprintf(stderr,"No default breakpoint address now.\n");
1015 if ( *s == '*' && isdigit(*(s+1)))
1018 long braddr = strtol(s+1,0,0);
1019 if (!applyToSet(functions,funcInAddr,braddr,&func))
1022 if (!applyToSet(modules,moduleLineWithAddr,braddr,&modul,&line))
1024 fprintf(stderr,"Address 0x%08x not exists in code.\n",braddr);
1028 setBreakPoint ( braddr , CODE , USER , userBpCB ,
1029 modul->c_name,line);
1035 int line = func->exitline;
1036 applyToSet(func->cfpoints,lineNearAddr,braddr,&line,NULL,NULL);
1037 setBreakPoint ( braddr , CODE , USER , userBpCB ,
1038 func->mod->c_name,line);
1042 /* case b) lineno */
1043 /* check if line number */
1045 /* get the lineno */
1048 /* if current context not present then we must get the module
1049 which has main & set the break point @ line number provided
1050 of that module : if current context known then set the bp
1051 at the line number given for the current module
1054 if (!cctxt->func->mod) {
1055 if (!applyToSet(functions,funcWithName,"main"))
1056 fprintf(stderr,"Function \"main\" not defined.\n");
1058 setBPatModLine(func->mod,line);
1060 setBPatModLine(cctxt->func->mod,line);
1063 setBPatModLine(list_mod,line);
1065 fprintf(stdout,"Sdcdb fails to have module symbol context at %d\n", __LINE__);
1072 if ((bp = strchr(s,':'))) {
1077 if (srcMode == SRC_CMODE) {
1078 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
1079 fprintf (stderr,"No source file named %s.\n",s);
1083 if (!applyToSet(modules,moduleWithAsmName,s,&mod)) {
1084 fprintf (stderr,"No source file named %s.\n",s);
1089 /* case c) filename:lineno */
1090 if (isdigit(*(bp +1))) {
1092 setBPatModLine (mod,atoi(bp+1));
1096 /* case d) filename:function */
1097 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
1098 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
1100 setBPatModLine (mod,
1101 (srcMode == SRC_CMODE ?
1108 /* case e) function */
1109 if (!applyToSet(functions,funcWithName,s,&func))
1110 fprintf(stderr,"Function \"%s\" not defined.\n",s);
1112 setBPatModLine(func->mod,
1113 (srcMode == SRC_CMODE ?
1121 /*-----------------------------------------------------------------*/
1122 /* cmdListAsm - list assembler source code */
1123 /*-----------------------------------------------------------------*/
1124 int cmdListAsm (char *s, context *cctxt)
1126 if ( cctxt && cctxt->func)
1129 if (printAsmLine(cctxt->func,cctxt->func->mod,
1130 (long)cctxt->addr,(long)cctxt->addr))
1136 /*-----------------------------------------------------------------*/
1137 /* cmdSetOption - set debugger options */
1138 /*-----------------------------------------------------------------*/
1139 int cmdSetOption (char *s, context *cctxt)
1141 while (*s && isspace(*s)) s++;
1142 if (strncmp(s,"srcmode",7) == 0 ) {
1143 if (srcMode == SRC_CMODE)
1144 srcMode = SRC_AMODE;
1146 srcMode = SRC_CMODE;
1147 fprintf(stderr,"source mode set to '%s'\n",
1148 (srcMode == SRC_CMODE ? "C" : "asm"));
1152 if (strncmp(s,"variable ",9) == 0)
1158 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
1161 while (*s && *s != '=') s++;
1163 while (isspace(*s)) *s++ = '\0';
1166 printOrSetSymValue(sym,cctxt,0,0,0,rs,s);
1170 fprintf(stdout,"No new value for \"%s\".\n",s);
1175 fprintf(stderr,"'set %s' command not yet implemented\n",s);
1179 /*-----------------------------------------------------------------*/
1180 /* cmdContinue - continue till next break point */
1181 /*-----------------------------------------------------------------*/
1182 int cmdContinue (char *s, context *cctxt)
1184 if (!cctxt || !cctxt->func) {
1185 fprintf(stdout,"The program is not being run.\n");
1189 fprintf(stdout,"Continuing.\n");
1195 /*-----------------------------------------------------------------*/
1196 /* cmdDelUserBp - delete user break point */
1197 /*-----------------------------------------------------------------*/
1198 int cmdDelUserBp (char *s, context *cctxt)
1201 while (isspace(*s)) s++;
1204 if (userBpPresent) {
1206 fprintf (stdout,"Delete all breakpoints? (y or n) ");
1208 fgets(buffer,sizeof(buffer),stdin);
1209 if (toupper(buffer[0]) == 'Y')
1215 /* determine the break point number */
1216 if (sscanf(s,"%d",&bpnum) == 1)
1217 deleteUSERbp(bpnum);
1222 /*-----------------------------------------------------------------*/
1223 /* cmdStepi - single step exactly one instruction */
1224 /*-----------------------------------------------------------------*/
1225 int cmdStepi (char *s, context *cctxt)
1228 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1229 fprintf(stdout,"The program is not being run.\n");
1238 /*-----------------------------------------------------------------*/
1239 /* cmdStep - single step thru C source file */
1240 /*-----------------------------------------------------------------*/
1241 int cmdStep (char *s, context *cctxt)
1243 function *func = NULL;
1245 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1246 fprintf(stdout,"The program is not being run.\n");
1248 /* if we are @ the end of a function then set
1249 break points at execution points of the
1250 function in the call stack... */
1251 if (cctxt->addr == cctxt->func->sym->eaddr) {
1252 if ((func = STACK_PEEK(callStack))) {
1253 if (srcMode == SRC_CMODE)
1254 applyToSet (func->cfpoints,setStepEPBp,STEP,
1257 applyToSet (func->afpoints,setStepEPBp,STEP,
1258 func->mod->asm_name);
1261 /* set breakpoints at all function entry points
1262 and all exepoints of this functions & for
1263 all functions one up in the call stack */
1265 /* all function entry points */
1266 applyToSet(functions,setStepBp);
1268 if (srcMode == SRC_CMODE) {
1269 /* for all execution points in this function */
1270 applyToSet(cctxt->func->cfpoints,setStepEPBp,STEP,
1271 cctxt->func->mod->c_name);
1273 /* set a break point @ the current function's
1275 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
1276 stepBpCB, cctxt->func->mod->c_name,
1277 cctxt->func->exitline);
1279 /* now break point @ callers execution points */
1280 if ((func = STACK_PPEEK(callStack))) {
1281 applyToSet (func->cfpoints,setStepEPBp,STEP,
1283 /* set bp @ callers exit point */
1284 setBreakPoint (func->sym->eaddr, CODE, STEP ,
1285 stepBpCB, func->mod->c_name,
1289 /* for all execution points in this function */
1290 applyToSet(cctxt->func->afpoints,setStepEPBp,STEP,
1291 cctxt->func->mod->asm_name);
1293 /* set a break point @ the current function's
1295 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
1296 stepBpCB, cctxt->func->mod->asm_name,
1297 cctxt->func->aexitline);
1299 /* now break point @ callers execution points */
1300 if ((func = STACK_PPEEK(callStack))) {
1302 applyToSet (func->afpoints,setStepEPBp,STEP,
1303 func->mod->asm_name);
1305 /* set bp @ callers exit point */
1306 setBreakPoint (func->sym->eaddr, CODE, STEP ,
1307 stepBpCB, func->mod->asm_name,
1319 /*-----------------------------------------------------------------*/
1320 /* cmdNexti - next instruction but proceed function call */
1321 /*-----------------------------------------------------------------*/
1322 int cmdNexti (char *s, context *cctxt)
1324 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1325 fprintf(stdout,"The program is not being run.\n");
1334 /*-----------------------------------------------------------------*/
1335 /* cmdNext - next executable C statement file */
1336 /*-----------------------------------------------------------------*/
1337 int cmdNext (char *s, context *cctxt)
1339 function *func = NULL;
1340 /* next is almost the same as step except we don't
1341 we don't set break point for all function entry
1343 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1344 fprintf(stdout,"The program is not being run.\n");
1346 /* if we are @ the end of a function then set
1347 break points at execution points of the
1348 function in the call stack... */
1349 if (cctxt->addr == cctxt->func->sym->eaddr) {
1350 if ((func = STACK_PEEK(callStack))) {
1351 if (srcMode == SRC_CMODE)
1352 applyToSet (func->cfpoints,setStepEPBp,STEP,
1355 applyToSet (func->afpoints,setStepEPBp,STEP,
1356 func->mod->asm_name);
1359 if (srcMode == SRC_CMODE) {
1360 /* for all execution points in this function */
1361 applyToSet(cctxt->func->cfpoints,setNextEPBp,NEXT,
1362 cctxt->func->mod->c_name);
1363 /* set a break point @ the current function's
1365 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
1366 nextBpCB, cctxt->func->mod->c_name,
1367 cctxt->func->exitline);
1369 /* now break point @ callers execution points */
1370 if ((func = STACK_PPEEK(callStack))) {
1371 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
1373 /* set bp @ callers exit point */
1374 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
1375 stepBpCB, func->mod->c_name,
1379 /* for all execution points in this function */
1380 applyToSet(cctxt->func->afpoints,setNextEPBp,NEXT,
1381 cctxt->func->mod->asm_name);
1382 /* set a break point @ the current function's
1384 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
1385 nextBpCB, cctxt->func->mod->asm_name,
1386 cctxt->func->aexitline);
1388 /* now break point @ callers execution points */
1389 if ((func = STACK_PPEEK(callStack))) {
1390 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
1391 func->mod->asm_name);
1392 /* set bp @ callers exit point */
1393 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
1394 stepBpCB, func->mod->asm_name,
1405 /*-----------------------------------------------------------------*/
1406 /* cmdRun - run till next break point */
1407 /*-----------------------------------------------------------------*/
1408 int cmdRun (char *s, context *cctxt)
1411 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
1412 fprintf(stdout,"Starting program\n");
1415 fprintf(stdout,"No executable file specified.\nUse the \"file\" command.\n");
1422 "The program being debugged has been started already.\n");
1423 fprintf(stdout,"Start it from the beginning? (y or n) ");
1426 fgets(buff,sizeof(buff),stdin);
1427 if (toupper(buff[0]) == 'Y') {
1436 /*-----------------------------------------------------------------
1437 cmdListSymbols - list symbols
1438 |-----------------------------------------------------------------*/
1439 int cmdListSymbols (char *s, context *cctxt)
1441 int our_verbose = 0;
1445 if (strstr(s, "v1")) {
1447 } else if (strstr(s, "v2")) {
1451 printf("[symbols]\n");
1452 sy = setFirstItem(symbols);
1457 if (our_verbose <= 1)
1458 printf("<%s>", sy->name);
1460 if (our_verbose > 1) {
1461 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1462 sy->name, sy->size, sy->level, sy->block);
1463 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1464 sy->isonstack, sy->isfunc, sy->offset, sy->addr);
1465 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1466 sy->eaddr, sy->addr_type, sy->type, sy->etype);
1467 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1468 sy->scopetype, sy->sname, sy->rname, sy->addrspace);
1469 printf(" next:%x\n", sy->next);
1472 sy = setNextItem(symbols);
1474 printf(" %d symbols\n", i);
1478 /*-----------------------------------------------------------------
1479 cmdListFunctions - list functions.
1480 |-----------------------------------------------------------------*/
1481 int cmdListFunctions (char *s, context *cctxt)
1485 int our_verbose = 0;
1487 if (strstr(s, "v1")) {
1489 } else if (strstr(s, "v2")) {
1493 printf("[functions]\n");
1494 f = setFirstItem(functions);
1500 printf(" %d) sym:%x, fname:%s, modName:%s, mod:%x\n", i,
1501 f->sym, f->sym->name, f->modName, f->mod);
1502 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1503 f->entryline, f->aentryline, f->exitline, f->aexitline);
1504 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1505 f->cfpoints, f->afpoints, f->laddr, f->lline);
1508 printf("<%s>", f->modName);
1511 f = setNextItem(functions);
1513 printf(" %d functions\n", i);
1517 /*-----------------------------------------------------------------
1518 cmdListModules - list functions.
1519 |-----------------------------------------------------------------*/
1520 int cmdListModules (char *s, context *cctxt)
1525 int our_verbose = 0;
1527 if (strstr(s, "v1")) {
1529 } else if (strstr(s, "v2")) {
1533 printf("[modules]\n");
1534 m = setFirstItem(modules);
1540 if (our_verbose >= 0) {
1541 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1542 m->cfullname, m->afullname, m->name);
1543 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1544 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1545 printf(" cLines:%x, asmLines:%x\n",
1546 m->cLines, m->asmLines);
1548 if (our_verbose >= 2) {
1550 printf(" [cLines] ");
1552 for (i=0; i<m->ncLines; i++ ) {
1554 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1555 i, cs->addr, cs->block, cs->level, cs->src);
1558 printf("%d records", i);
1561 printf(" [asmLines] ");
1563 for (i=0; i<m->nasmLines; i++ ) {
1564 as = m->asmLines[i];
1565 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1566 i, as->addr, as->block, as->level, as->src);
1569 printf("%d records", i);
1574 m = setNextItem(modules);
1579 /*-----------------------------------------------------------------
1580 infoSymbols - This is really just a tool to dump all these
1581 huge program structures out into human readable form.
1582 |-----------------------------------------------------------------*/
1583 static void infoSymbols(context *ctxt)
1585 int our_verbose = 0;
1587 printf("[context:%x] func:%x modName:%s addr:%x\n",
1588 ctxt, ctxt->func, ctxt->modName, ctxt->addr);
1590 printf(" cline:%d asmline:%d block:%d level:%d\n",
1591 ctxt->cline, ctxt->asmline, ctxt->level);
1593 printf("[globals] currCtxt:%x, modules:%x, functions:%x symbols:%x\n",
1594 currCtxt, modules, functions, symbols);
1595 printf(" nStructs:%d, structs:%x, ssdirl:%s\n",
1596 nStructs, structs, ssdirl);
1598 /**************** modules *******************/
1603 printf("[modules]\n");
1604 m = setFirstItem(modules);
1609 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1610 m->cfullname, m->afullname, m->name);
1611 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1612 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1613 printf(" cLines:%x, asmLines:%x\n",
1614 m->cLines, m->asmLines);
1617 cs = m->cLines[i++];
1618 printf(" [cLines] ");
1621 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1622 i, cs->addr, cs->block, cs->level, cs->src);
1623 cs = m->cLines[i++];
1626 printf("%d records", i);
1630 as = m->asmLines[i++];
1631 printf(" [asmLines] ");
1634 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1635 i, as->addr, as->block, as->level, as->src);
1636 as = m->asmLines[i++];
1639 printf("%d records", i);
1643 m = setNextItem(modules);
1647 /**************** functions *******************/
1651 printf("[functions]\n");
1652 f = setFirstItem(functions);
1658 printf(" %d) sym:%x, modName:%s, mod:%x\n", i,
1659 f->sym, f->modName, f->mod);
1660 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1661 f->entryline, f->aentryline, f->exitline, f->aexitline);
1662 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1663 f->cfpoints, f->afpoints, f->laddr, f->lline);
1666 f = setNextItem(functions);
1669 printf(" %d functions\n", i);
1672 /**************** symbols *******************/
1676 printf("[symbols]\n");
1677 s = setFirstItem(symbols);
1683 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1684 s->name, s->size, s->level, s->block);
1685 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1686 s->isonstack, s->isfunc, s->offset, s->addr);
1687 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1688 s->eaddr, s->addr_type, s->type, s->etype);
1689 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1690 s->scopetype, s->sname, s->rname, s->addrspace);
1691 printf(" next:%x\n", s->next);
1694 s = setNextItem(symbols);
1697 printf(" %d symbols\n", i);
1702 /*-----------------------------------------------------------------*/
1703 /* infoStack - print call stack information */
1704 /*-----------------------------------------------------------------*/
1705 static void infoStack(context *ctxt)
1710 STACK_STARTWALK(callStack) ;
1711 while ((func = STACK_WALK(callStack))) {
1713 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",i++,
1714 func->laddr,func->sym->name,
1715 func->mod->c_name,func->lline);
1720 /*-----------------------------------------------------------------*/
1721 /* cmdWhere - where command */
1722 /*-----------------------------------------------------------------*/
1723 int cmdWhere(char *s, context *cctxt)
1730 static int infomode = 0;
1731 /*-----------------------------------------------------------------*/
1732 /* cmdInfo - info command */
1733 /*-----------------------------------------------------------------*/
1734 int cmdInfo (char *s, context *cctxt)
1736 while (isspace(*s)) s++;
1738 /* list all break points */
1739 if (strncmp(s,"break",5) == 0) {
1744 /* info frame same as frame */
1745 if (strcmp(s,"frame") == 0) {
1750 if (strncmp(s,"line",4) == 0) {
1752 cmdListSrc (s+4,cctxt);
1756 /* info stack display call stack */
1757 if (strcmp(s,"stack") == 0) {
1763 /* info stack display call stack */
1764 if (strcmp(s,"registers") == 0) {
1765 fprintf(stdout,"%s",simRegs());
1769 /* info stack display call stack */
1770 if (strcmp(s,"all-registers") == 0)
1773 fprintf(stdout,"%s",simRegs());
1774 fprintf(stdout,"Special Function Registers:\n");
1775 for ( i = 0 ; i < 0x100 ; i++ )
1779 if (applyToSetFTrue(sfrsymbols,symWithAddr,i,'I',&sym))
1781 val = simGetValue (sym->addr,sym->addrspace,sym->size);
1782 fprintf(stdout,"%s=0x%02x",sym->name,val);
1785 for ( j = 0 ; j < 8 ; j++ )
1788 if (applyToSetFTrue(sfrsymbols,symWithAddr,i+j,'J',&sym))
1790 //val = simGetValue (sym->addr,sym->addrspace,sym->size);
1791 fprintf(stdout," %s=%c",sym->name,(val&1)? '1':'0');
1796 fprintf(stdout,"\n");
1802 /* info stack display call stack */
1803 if (strcmp(s,"symbols") == 0) {
1804 /* dump out symbols we have read in */
1805 fprintf(stdout,"Dumping symbols...\n");
1810 if (strcmp(s,"variables") == 0) {
1811 /* dump out symbols we have read in */
1812 fprintf(stdout,"Dumping symbols...\n");
1817 fprintf(stdout,"Undefined info command: \"%s\". Try \"help\n",s);
1822 /*-----------------------------------------------------------------*/
1823 /* cmdQuit - quit debugging */
1824 /*-----------------------------------------------------------------*/
1825 int cmdQuit (char *s, context *cctxt)
1832 /*-----------------------------------------------------------------*/
1833 /* cmdListSrc - list src */
1834 /*-----------------------------------------------------------------*/
1835 int cmdListSrc (char *s, context *cctxt)
1837 static int currline = 0;
1840 int llines = listLines;
1842 while (*s && isspace(*s)) s++;
1844 /* if the user has spcified line numer then the line number
1845 can be of the following formats
1846 LINE - just line number
1847 FILE:LINE - filename line number
1848 FUNCTION - list a function
1849 FILE:FUNCTION - function in file */
1854 sscanf(s,"%d",&pline);
1855 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
1857 fprintf(stdout,"Sdcdb fails to have a proper context at %d.\n", __LINE__);
1862 list_mod = cctxt->func->mod;
1866 function *func = NULL;
1868 /* if ':' present then FILE:LINE || FILE:FUNCTION */
1869 if ((bp = strchr(s,':'))) {
1874 list_mod=NULL; /* bug fix 2-09-02, moduleWithCName expects mod to be null */
1875 if (srcMode == SRC_CMODE) {
1876 if (!applyToSet(modules,moduleWithCName,s,&list_mod)) {
1877 fprintf (stderr,"No c source file named %s.\n",s);
1881 if (!applyToSet(modules,moduleWithAsmName,s,&list_mod)) {
1882 fprintf (stderr,"No source file named %s.\n",s);
1886 sscanf(bp,"%d",&pline);
1889 if (!applyToSet(functions,funcWithNameModule,bp,s,&func)) {
1890 fprintf(stdout,"Function \"%s\" not defined.\n",bp);
1893 list_mod = func->mod;
1894 if (srcMode == SRC_CMODE) {
1895 pline = func->entryline;
1896 llines = func->exitline - func->entryline + 1;
1898 pline = func->aentryline;
1899 llines = func->aexitline - func->aentryline + 1;
1905 if (!applyToSet(functions,funcWithName,s,&func)) {
1906 fprintf(stderr,"Function \"%s\" not defined.\n",s);
1910 list_mod = func->mod;
1911 if (srcMode == SRC_CMODE) {
1912 pline = func->entryline;
1913 llines = func->exitline - func->entryline + 1;
1915 pline = func->aentryline;
1916 llines = func->aexitline - func->aentryline + 1;
1922 /* if no line specified & we had listed
1923 before then continue from that listing */
1927 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
1928 fprintf(stdout,"Missing context at %d. Try list filename:lineno\n", __LINE__);
1931 list_mod = cctxt->func->mod;
1932 if (srcMode == SRC_CMODE)
1933 pline = cctxt->cline;
1935 pline = cctxt->asmline;
1940 fprintf(stdout,"Sdcdb fails to have a valid module context at %d.\n", __LINE__);
1944 if (llines > listLines) llines = listLines;
1948 fprintf(stdout,"Line %d of \"%s\" starts at address 0x%08x.\n",pline,
1949 list_mod->c_name, list_mod->cLines[pline]->addr);
1953 for ( i = 0 ; i < llines ; i++ ) {
1954 if (srcMode == SRC_CMODE) {
1955 if ( (pline + i) >= list_mod->ncLines )
1957 fprintf(stdout,"%d\t%s",pline + i,
1958 list_mod->cLines[pline +i]->src);
1960 if ( (pline + i) >= list_mod->nasmLines )
1962 fprintf(stdout,"%d\t%s",pline + i,
1963 list_mod->asmLines[pline +i]->src);
1966 currline = pline + i ;
1970 static void setValBasic(symbol *sym, link *type,
1971 char mem, unsigned addr,int size, char *val)
1987 v.f = strtof(val,NULL);
1990 v.val = strtol(val,NULL,0);
1993 if (IS_INTEGRAL(type))
2002 if (( s = strchr(val,'\'')))
2005 v.b[0] = strtol(s+2,NULL,8);
2011 v.b[0] = strtol(val,NULL,0);
2017 v.val = strtol(val,NULL,0);
2019 v.i.lo = strtol(val,NULL,0);
2021 v.val = strtol(val,NULL,0);
2024 v.val = strtol(val,NULL,0);
2026 simSetValue(addr,mem,size,v.val);
2029 /*-----------------------------------------------------------------*/
2030 /* printFmtInteger - print value in bin,oct,dez or hex */
2031 /*-----------------------------------------------------------------*/
2032 static void printFmtInteger(char *deffmt,int fmt, long val,
2035 static char digits[] =
2037 '0' , '1' , '2' , '3' , '4' , '5' ,
2038 '6' , '7' , '8' , '9' , 'a' , 'b' ,
2039 'c' , 'd' , 'e' , 'f' , 'g' , 'h'
2041 static int radixOfFormat[] = { 0 , 2, 8 ,10, 16 };
2042 static int olenOfSize[] = { 0 , 3, 6 , 8, 11 };
2048 if ( fmt == FMT_NON || fmt == FMT_DEZ )
2050 fprintf(stdout,deffmt,val);
2053 radix = radixOfFormat[fmt];
2056 if ( sign && val < 0 )
2064 while (val <= -radix)
2066 buf[charPos--] = digits[-(val % radix)];
2069 buf[charPos] = digits[-val];
2074 radix = olenOfSize[size];
2084 while (charPos > 39 - radix )
2086 buf[--charPos] = '0';
2091 if ( buf[charPos] != '0' )
2092 buf[--charPos] = '0';
2095 buf[--charPos] = 'x';
2096 buf[--charPos] = '0';
2100 buf[--charPos] = '-';
2102 fputs(&buf[charPos],stdout);
2105 /*-----------------------------------------------------------------*/
2106 /* printValBasic - print value of basic types */
2107 /*-----------------------------------------------------------------*/
2108 static void printValBasic(symbol *sym, link *type,
2109 char mem, unsigned addr,int size, int fmt)
2125 v.val = simGetValue(addr,mem,size);
2126 /* if this a floating point number then */
2128 fprintf(stdout,"%f",v.f);
2131 fprintf(stdout,"0x%*x",size<<1,v.val);
2133 if (IS_INTEGRAL(type))
2142 if ( isprint(v.val))
2143 printFmtInteger("'%c'",fmt,(long)v.val,0,size);
2145 printFmtInteger("'\\%o'",fmt,(long)v.val,0,size);
2151 if (SPEC_USIGN(etype))
2152 printFmtInteger("%u",fmt,(long)v.val,0,size);
2154 printFmtInteger("%d",fmt,(long)v.sval,1,size);
2156 if (SPEC_USIGN(etype))
2157 printFmtInteger("%u",fmt,(long)v.i.lo,0,size);
2159 printFmtInteger("%d",fmt,(long)v.i.lo,1,size);
2162 if (IS_BITVAR(etype))
2163 fprintf(stdout,"%c",(v.val?'1':'0'));
2165 fprintf(stdout,"0x%0*x",size<<1,v.val);
2169 fprintf(stdout,"0x%0*x",size<<1,v.val);
2172 /*-----------------------------------------------------------------*/
2173 /* printValFunc - prints function values */
2174 /*-----------------------------------------------------------------*/
2175 static void printValFunc (symbol *sym, int fmt)
2177 fprintf(stdout,"print function not yet implemented");
2180 /*-----------------------------------------------------------------*/
2181 /* printArrayValue - will print the values of array elements */
2182 /*-----------------------------------------------------------------*/
2183 static void printArrayValue (symbol *sym, link *type,
2184 char space, unsigned int addr, int fmt)
2186 link *elem_type = type->next;
2189 fprintf(stdout,"{");
2190 for (i = 0 ; i < DCL_ELEM(type) ; i++) {
2191 if (IS_AGGREGATE(elem_type)) {
2192 printValAggregates(sym,elem_type,space,addr,fmt);
2194 printValBasic(sym,elem_type,space,addr,getSize(elem_type),fmt);
2196 addr += getSize(elem_type);
2197 if (i != DCL_ELEM(type) -1)
2198 fprintf(stdout,",");
2201 fprintf(stdout,"}");
2204 /*-----------------------------------------------------------------*/
2205 /* printStructValue - prints structures elements */
2206 /*-----------------------------------------------------------------*/
2207 static void printStructValue (symbol *sym, link *type,
2208 char space, unsigned int addr, int fmt)
2210 symbol *fields = SPEC_STRUCT(type)->fields;
2212 fprintf(stdout," { ");
2214 fprintf(stdout,"%s%s = ",(first ? "": ", "),fields->name);
2216 if (IS_AGGREGATE(fields->type)) {
2217 printValAggregates(fields,fields->type,space, addr, fmt);
2219 printValBasic(fields,fields->type,space,addr,getSize(fields->type), fmt);
2221 addr += getSize(fields->type);
2222 fields = fields->next;
2224 fprintf(stdout,"}");
2227 /*-----------------------------------------------------------------*/
2228 /* printValAggregates - print value of aggregates */
2229 /*-----------------------------------------------------------------*/
2230 static void printValAggregates (symbol *sym, link *type,
2231 char space,unsigned int addr, int fmt)
2234 if (IS_ARRAY(type)) {
2235 printArrayValue(sym, type, space, addr, fmt);
2239 if (IS_STRUCT(type)) {
2240 printStructValue(sym, type, space, addr, fmt);
2245 /*-----------------------------------------------------------------*/
2246 /* printOrSetSymValue - print or set value of a symbol */
2247 /*-----------------------------------------------------------------*/
2248 static void printOrSetSymValue (symbol *sym, context *cctxt,
2249 int flg, int dnum, int fmt, char *rs, char *val)
2251 static char fmtChar[] = " todx ";
2252 static int stack = 1;
2258 char save_ch, save_ch2;
2260 /* if it is on stack then compute address & fall thru */
2263 symbol *bp = symLookup("bp",cctxt);
2266 fprintf(stdout,"cannot determine stack frame\n");
2270 sym->addr = simGetValue(bp->addr,bp->addrspace,bp->size)
2274 /* get the value from the simulator and
2282 fprintf(stdout,"$%d = ",stack++);
2285 fprintf(stdout,"%d: ", dnum);
2286 if ( fmt != FMT_NON )
2287 fprintf(stdout,"/%c ",fmtChar[fmt]);
2288 fprintf(stdout,"%s%s = ",sym->name,rs);
2298 if ( *rs == '[' && IS_ARRAY(type))
2301 while ( *rs && *rs != ']' ) rs++ ;
2304 if ( ! isdigit(*s ))
2306 /* index seems a variable */
2307 for ( s2 = s; *s2 && ( isalnum( *s2 ) || *s2 == '_'); s2++ );
2311 fields = symLookup(s,cctxt);
2315 fprintf(stdout,"Unkown variable \"%s\" for index.\n", s);
2318 /* arrays & structures first */
2319 if (! IS_INTEGRAL(fields->type))
2321 fprintf(stdout,"Wrong type of variable \"%s\" for index \n", s);
2324 n = simGetValue(fields->addr,fields->addrspace,getSize(fields->type));
2330 if ( n < 0 || n >= DCL_ELEM(type))
2332 fprintf(stdout,"Wrong index %d.\n", n);
2336 size = getSize(type);
2340 else if ( *rs == '.' && IS_STRUCT(type))
2343 /* search structure element */
2344 for ( rs = s; *rs && ( isalnum( *rs ) || *rs == '_'); rs++ );
2348 for (fields = SPEC_STRUCT(type)->fields; fields; fields = fields->next)
2350 if (!(strcmp(s,fields->name)))
2356 fprintf(stdout,"Unknown field \"%s\" of structure\n", s);
2359 type = fields->type;
2360 size = getSize(type);
2361 addr += fields->offset;
2367 /* arrays & structures first */
2368 if (IS_AGGREGATE(type))
2371 fprintf(stdout,"Cannot set aggregate variable\n");
2373 printValAggregates(sym,type,sym->addrspace,addr,fmt);
2380 printValFunc(sym,fmt);
2385 setValBasic (sym,type,sym->addrspace,addr,size,val);
2387 printValBasic(sym,type,sym->addrspace,addr,size,fmt);
2389 if ( flg > 0 ) fprintf(stdout,"\n");
2393 /*-----------------------------------------------------------------*/
2394 /* printStructInfo - print out structure information */
2395 /*-----------------------------------------------------------------*/
2396 static void printStructInfo (structdef *sdef)
2398 symbol *field = sdef->fields ;
2403 field = field->next;
2406 fprintf(stdout,"%s %s {\n",(i ? "struct" : "union" ), sdef->tag);
2407 field = sdef->fields;
2409 printTypeInfo (field->type);
2410 fprintf(stdout," %s ;\n",field->name);
2411 field = field->next ;
2414 fprintf(stdout,"}\n");
2418 /*-----------------------------------------------------------------*/
2419 /* printTypeInfo - print out the type information */
2420 /*-----------------------------------------------------------------*/
2421 static void printTypeInfo(link *p)
2427 switch (DCL_TYPE(p)) {
2429 printTypeInfo (p->next);
2430 fprintf(stdout,"()");
2433 printTypeInfo (p->next);
2434 fprintf(stdout,"[%d]",DCL_ELEM(p));
2440 printTypeInfo (p->next);
2441 fprintf(stdout,"(_near *)");
2445 printTypeInfo (p->next);
2446 fprintf(stdout,"(_xdata *)");
2450 printTypeInfo( p->next);
2451 fprintf(stdout,"(_code *)");
2455 printTypeInfo( p->next);
2456 fprintf(stdout,"(_generic *)");
2460 switch (SPEC_NOUN(p)) { /* depending on the specifier type */
2462 (IS_LONG(p) ? fputs("long ",stdout) :
2463 ( IS_SHORT(p) ? fputs("short ",stdout) :
2464 fputs("int ",stdout))) ;
2467 fputs("float ",stdout);
2471 fputs ("char ",stdout);
2475 fputs("void ",stdout);
2479 printStructInfo (SPEC_STRUCT(p));
2483 fputs("sbit ",stdout);
2487 fprintf(stdout,": %d" ,SPEC_BLEN(p));
2493 /*-----------------------------------------------------------------*/
2494 /* cmdPrint - print value of variable */
2495 /*-----------------------------------------------------------------*/
2496 int cmdPrint (char *s, context *cctxt)
2501 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2506 printOrSetSymValue(sym,cctxt,1,0,fmt,rs,NULL);
2511 /*-----------------------------------------------------------------*/
2512 /* cmdOutput - print value of variable without number and newline */
2513 /*-----------------------------------------------------------------*/
2514 int cmdOutput (char *s, context *cctxt)
2519 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2524 printOrSetSymValue(sym,cctxt,0,0,fmt,rs,NULL);
2529 /** find display entry with this number */
2531 DEFSETFUNC(dsymWithNumber)
2533 dsymbol *dsym = item;
2535 V_ARG(dsymbol **,dsymp);
2537 if ( dsym->dnum == dnum )
2545 /*-----------------------------------------------------------------*/
2546 /* displayAll - display all valid variables */
2547 /*-----------------------------------------------------------------*/
2548 void displayAll(context *cctxt)
2554 for (dsym = setFirstItem(dispsymbols);
2556 dsym = setNextItem(dispsymbols))
2558 if ( (sym = symLookup(dsym->name,cctxt)))
2559 printOrSetSymValue(sym,cctxt,2,dsym->dnum,dsym->fmt,dsym->rs,NULL);
2563 /*-----------------------------------------------------------------*/
2564 /* cmdDisplay - display value of variable */
2565 /*-----------------------------------------------------------------*/
2566 int cmdDisplay (char *s, context *cctxt)
2568 static int dnum = 1;
2572 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2580 dsymbol *dsym = (dsymbol *)Safe_calloc(1,sizeof(dsymbol));
2581 dsym->dnum = dnum++ ;
2582 dsym->name = sym->name;
2584 dsym->rs = gc_strdup(rs);
2585 addSetHead(&dispsymbols,dsym);
2590 /*-----------------------------------------------------------------*/
2591 /* cmdUnDisplay - undisplay value of variable */
2592 /*-----------------------------------------------------------------*/
2593 int cmdUnDisplay (char *s, context *cctxt)
2598 while (isspace(*s)) s++;
2601 for (dsym = setFirstItem(dispsymbols);
2603 dsym = setNextItem(dispsymbols))
2605 Safe_free(dsym->rs);
2608 deleteSet(&dispsymbols);
2613 dnum = strtol(s,&s,10);
2614 if (applyToSetFTrue(dispsymbols,dsymWithNumber,dnum,&dsym))
2616 deleteSetItem(&dispsymbols,dsym);
2617 Safe_free(dsym->rs);
2622 fprintf(stdout,"Arguments must be display numbers.\n");
2628 /*-----------------------------------------------------------------*/
2629 /* cmdPrintType - print type of a variable */
2630 /*-----------------------------------------------------------------*/
2631 int cmdPrintType (char *s, context *cctxt)
2634 char *bp = s+strlen(s) -1;
2636 while (isspace(*s)) s++;
2638 while (isspace(*bp)) bp--;
2642 if ((sym = symLookup(s,cctxt))) {
2643 printTypeInfo(sym->type);
2644 fprintf(stdout,"\n");
2647 "No symbol \"%s\" in current context.\n",
2653 /*-----------------------------------------------------------------*/
2654 /* cmdClrUserBp - clear user break point */
2655 /*-----------------------------------------------------------------*/
2656 int cmdClrUserBp (char *s, context *cctxt)
2659 function *func = NULL;
2661 /* clear break point location specification can be of the following
2663 a) <nothing> - break point at current location
2664 b) lineno - number of the current module
2665 c) filename:lineno - line number of the given file
2666 e) filename:function- function X in file Y (useful for static functions)
2667 f) function - function entry point
2671 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
2675 /* white space skip */
2676 while (*s && isspace(*s)) s++;
2678 /* null terminate it after stripping trailing blanks*/
2680 while (bp != s && isspace(*bp)) bp--;
2683 /* case a) nothing */
2684 /* if nothing given then current location : we know
2685 the current execution location from the currentContext */
2688 /* if current context is known */
2690 /* clear the break point @ current location */
2691 clearUSERbp (cctxt->addr);
2693 fprintf(stderr,"No default breakpoint address now.\n");
2698 /* case b) lineno */
2699 /* check if line number */
2701 /* get the lineno */
2704 /* if current context not present then we must get the module
2705 which has main & set the break point @ line number provided
2706 of that module : if current context known then set the bp
2707 at the line number given for the current module
2710 if (!cctxt->func->mod) {
2711 if (!applyToSet(functions,funcWithName,"main"))
2712 fprintf(stderr,"Function \"main\" not defined.\n");
2714 clearBPatModLine(func->mod,line);
2716 clearBPatModLine(cctxt->func->mod,line);
2722 if ((bp = strchr(s,':'))) {
2727 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
2728 fprintf (stderr,"No source file named %s.\n",s);
2732 /* case c) filename:lineno */
2733 if (isdigit(*(bp +1))) {
2735 clearBPatModLine (mod,atoi(bp+1));
2739 /* case d) filename:function */
2740 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
2741 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
2743 clearBPatModLine (mod,func->entryline);
2748 /* case e) function */
2749 if (!applyToSet(functions,funcWithName,s,&func))
2750 fprintf(stderr,"Function \"%s\" not defined.\n",s);
2752 clearBPatModLine(func->mod,func->entryline);
2759 /*-----------------------------------------------------------------*/
2760 /* cmdSimulator - send command to simulator */
2761 /*-----------------------------------------------------------------*/
2762 int cmdSimulator (char *s, context *cctxt)
2766 if (strlen(s) > 80) {
2767 printf("error 3A\n");
2771 strcat(tmpstr, "\n");
2773 waitForSim(200,NULL);
2774 fprintf(stdout,"%s",simResponse());
2778 static int printFrame(int framenr, int getlast)
2781 function *func = NULL;
2782 function *lastfunc = NULL;
2784 STACK_STARTWALK(callStack) ;
2787 for ( i = 0; i <= framenr ; i++ )
2790 func = STACK_WALK(callStack);
2797 if (! func && getlast )
2802 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",
2803 framenr,func->laddr,func->sym->name,func->mod->c_name,func->lline);
2804 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
2805 func->mod->cfullname,func->lline,func->laddr);
2808 fprintf(stdout,"No stack.\n");
2814 /*-----------------------------------------------------------------*/
2815 /* cmdUp - Up command */
2816 /*-----------------------------------------------------------------*/
2817 int cmdUp(char *s, context *cctxt)
2819 while (isspace(*s)) s++;
2821 currentFrame += strtol(s,0,10);
2825 currentFrame = printFrame(currentFrame, 1 );
2829 /*-----------------------------------------------------------------*/
2830 /* cmdDown - down command */
2831 /*-----------------------------------------------------------------*/
2832 int cmdDown(char *s, context *cctxt)
2834 while (isspace(*s)) s++;
2836 currentFrame -= strtol(s,0,10);
2840 currentFrame = printFrame(currentFrame, 1 );
2843 /*-----------------------------------------------------------------*/
2844 /* cmdFrame - Frame command */
2845 /*-----------------------------------------------------------------*/
2846 int cmdFrame (char *s, context *cctxt)
2848 function *func = NULL;
2851 while (isspace(*s)) s++;
2853 framenr = strtol(s,0,10);
2855 framenr = currentFrame;
2856 printFrame( framenr, 0 );
2860 /*-----------------------------------------------------------------*/
2861 /* cmdFinish - exec till end of current function */
2862 /*-----------------------------------------------------------------*/
2863 int cmdFinish (char *s, context *ctxt)
2865 if (!ctxt || ! ctxt->func) {
2866 fprintf(stdout,"The program is not running.\n");
2870 if (srcMode == SRC_CMODE) {
2871 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
2872 stepBpCB, ctxt->func->mod->c_name,
2873 ctxt->func->exitline);
2875 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
2876 stepBpCB, ctxt->func->mod->asm_name,
2877 ctxt->func->aexitline);
2886 /*-----------------------------------------------------------------*/
2887 /* cmdShow - show command */
2888 /*-----------------------------------------------------------------*/
2889 int cmdShow (char *s, context *cctxt)
2891 /* skip white space */
2892 while (*s && isspace(*s)) s++ ;
2894 if (strcmp(s,"copying") == 0) {
2895 fputs(copying,stdout);
2899 if (strcmp(s,"warranty") == 0) {
2900 fputs(warranty,stdout);