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 */
34 static int listlines = LISTLINES;
36 /* mainly used to retain a reference to the active module being
37 listed. May be used as a general context for other commands if
38 no better context is available */
39 static module *list_mod = NULL;
41 EXTERN_STACK_DCL(callStack,function *,1024);
43 #if defined(__APPLE__) && defined(__MACH__)
45 {" GNU GENERAL PUBLIC LICENSE Version 2"};
46 static char *warranty=
50 " GNU GENERAL PUBLIC LICENSE\n"
51 " Version 2, June 1991\n"
53 " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n"
54 " 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\n"
55 " Everyone is permitted to copy and distribute verbatim copies\n"
56 " of this license document, but changing it is not allowed.\n"
60 " The licenses for most software are designed to take away your\n"
61 "freedom to share and change it. By contrast, the GNU General Public\n"
62 "License is intended to guarantee your freedom to share and change free\n"
63 "software--to make sure the software is free for all its users. This\n"
64 "General Public License applies to most of the Free Software\n"
65 "Foundation's software and to any other program whose authors commit to\n"
66 "using it. (Some other Free Software Foundation software is covered by\n"
67 "the GNU Library General Public License instead.) You can apply it to\n"
68 "your programs, too.\n"
70 " When we speak of free software, we are referring to freedom, not\n"
71 "price. Our General Public Licenses are designed to make sure that you\n"
72 "have the freedom to distribute copies of free software (and charge for\n"
73 "this service if you wish), that you receive source code or can get it\n"
74 "if you want it, that you can change the software or use pieces of it\n"
75 "in new free programs; and that you know you can do these things.\n"
77 " To protect your rights, we need to make restrictions that forbid\n"
78 "anyone to deny you these rights or to ask you to surrender the rights.\n"
79 "These restrictions translate to certain responsibilities for you if you\n"
80 "distribute copies of the software, or if you modify it.\n"
82 " For example, if you distribute copies of such a program, whether\n"
83 "gratis or for a fee, you must give the recipients all the rights that\n"
84 "you have. You must make sure that they, too, receive or can get the\n"
85 "source code. And you must show them these terms so they know their\n"
88 " We protect your rights with two steps: (1) copyright the software, and\n"
89 "(2) offer you this license which gives you legal permission to copy,\n"
90 "distribute and/or modify the software.\n"
92 " Also, for each author's protection and ours, we want to make certain\n"
93 "that everyone understands that there is no warranty for this free\n"
94 "software. If the software is modified by someone else and passed on, we\n"
95 "want its recipients to know that what they have is not the original, so\n"
96 "that any problems introduced by others will not reflect on the original\n"
97 "authors' reputations.\n"
99 " Finally, any free program is threatened constantly by software\n"
100 "patents. We wish to avoid the danger that redistributors of a free\n"
101 "program will individually obtain patent licenses, in effect making the\n"
102 "program proprietary. To prevent this, we have made it clear that any\n"
103 "patent must be licensed for everyone's free use or not licensed at all.\n"
105 " The precise terms and conditions for copying, distribution and\n"
106 "modification follow.\n"
108 " GNU GENERAL PUBLIC LICENSE\n"
109 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
111 " 0. This License applies to any program or other work which contains\n"
112 "a notice placed by the copyright holder saying it may be distributed\n"
113 "under the terms of this General Public License. The \"Program\", below,\n"
114 "refers to any such program or work, and a \"work based on the Program\"\n"
115 "means either the Program or any derivative work under copyright law:\n"
116 "that is to say, a work containing the Program or a portion of it,\n"
117 "either verbatim or with modifications and/or translated into another\n"
118 "language. (Hereinafter, translation is included without limitation in\n"
119 "the term \"modification\".) Each licensee is addressed as \"you\".\n"
121 "Activities other than copying, distribution and modification are not\n"
122 "covered by this License; they are outside its scope. The act of\n"
123 "running the Program is not restricted, and the output from the Program\n"
124 "is covered only if its contents constitute a work based on the\n"
125 "Program (independent of having been made by running the Program).\n"
126 "Whether that is true depends on what the Program does.\n"
128 " 1. You may copy and distribute verbatim copies of the Program's\n"
129 "source code as you receive it, in any medium, provided that you\n"
130 "conspicuously and appropriately publish on each copy an appropriate\n"
131 "copyright notice and disclaimer of warranty; keep intact all the\n"
132 "notices that refer to this License and to the absence of any warranty;\n"
133 "and give any other recipients of the Program a copy of this License\n"
134 "along with the Program.\n"
136 "You may charge a fee for the physical act of transferring a copy, and\n"
137 "you may at your option offer warranty protection in exchange for a fee.\n"
139 " 2. You may modify your copy or copies of the Program or any portion\n"
140 "of it, thus forming a work based on the Program, and copy and\n"
141 "distribute such modifications or work under the terms of Section 1\n"
142 "above, provided that you also meet all of these conditions:\n"
144 " a) You must cause the modified files to carry prominent notices\n"
145 " stating that you changed the files and the date of any change.\n"
147 " b) You must cause any work that you distribute or publish, that in\n"
148 " whole or in part contains or is derived from the Program or any\n"
149 " part thereof, to be licensed as a whole at no charge to all third\n"
150 " parties under the terms of this License.\n"
152 " c) If the modified program normally reads commands interactively\n"
153 " when run, you must cause it, when started running for such\n"
154 " interactive use in the most ordinary way, to print or display an\n"
155 " announcement including an appropriate copyright notice and a\n"
156 " notice that there is no warranty (or else, saying that you provide\n"
157 " a warranty) and that users may redistribute the program under\n"
158 " these conditions, and telling the user how to view a copy of this\n"
159 " License. (Exception: if the Program itself is interactive but\n"
160 " does not normally print such an announcement, your work based on\n"
161 " the Program is not required to print an announcement.)\n"
163 "These requirements apply to the modified work as a whole. If\n"
164 "identifiable sections of that work are not derived from the Program,\n"
165 "and can be reasonably considered independent and separate works in\n"
166 "themselves, then this License, and its terms, do not apply to those\n"
167 "sections when you distribute them as separate works. But when you\n"
168 "distribute the same sections as part of a whole which is a work based\n"
169 "on the Program, the distribution of the whole must be on the terms of\n"
170 "this License, whose permissions for other licensees extend to the\n"
171 "entire whole, and thus to each and every part regardless of who wrote it.\n"
173 "Thus, it is not the intent of this section to claim rights or contest\n"
174 "your rights to work written entirely by you; rather, the intent is to\n"
175 "exercise the right to control the distribution of derivative or\n"
176 "collective works based on the Program.\n"
178 "In addition, mere aggregation of another work not based on the Program\n"
179 "with the Program (or with a work based on the Program) on a volume of\n"
180 "a storage or distribution medium does not bring the other work under\n"
181 "the scope of this License.\n"
183 " 3. You may copy and distribute the Program (or a work based on it,\n"
184 "under Section 2) in object code or executable form under the terms of\n"
185 "Sections 1 and 2 above provided that you also do one of the following:\n"
187 " a) Accompany it with the complete corresponding machine-readable\n"
188 " source code, which must be distributed under the terms of Sections\n"
189 " 1 and 2 above on a medium customarily used for software interchange; or,\n"
191 " b) Accompany it with a written offer, valid for at least three\n"
192 " years, to give any third party, for a charge no more than your\n"
193 " cost of physically performing source distribution, a complete\n"
194 " machine-readable copy of the corresponding source code, to be\n"
195 " distributed under the terms of Sections 1 and 2 above on a medium\n"
196 " customarily used for software interchange; or,\n"
198 " c) Accompany it with the information you received as to the offer\n"
199 " to distribute corresponding source code. (This alternative is\n"
200 " allowed only for noncommercial distribution and only if you\n"
201 " received the program in object code or executable form with such\n"
202 " an offer, in accord with Subsection b above.)\n"
204 "The source code for a work means the preferred form of the work for\n"
205 "making modifications to it. For an executable work, complete source\n"
206 "code means all the source code for all modules it contains, plus any\n"
207 "associated interface definition files, plus the scripts used to\n"
208 "control compilation and installation of the executable. However, as a\n"
209 "special exception, the source code distributed need not include\n"
210 "anything that is normally distributed (in either source or binary\n"
211 "form) with the major components (compiler, kernel, and so on) of the\n"
212 "operating system on which the executable runs, unless that component\n"
213 "itself accompanies the executable.\n"
215 "If distribution of executable or object code is made by offering\n"
216 "access to copy from a designated place, then offering equivalent\n"
217 "access to copy the source code from the same place counts as\n"
218 "distribution of the source code, even though third parties are not\n"
219 "compelled to copy the source along with the object code.\n"
221 " 4. You may not copy, modify, sublicense, or distribute the Program\n"
222 "except as expressly provided under this License. Any attempt\n"
223 "otherwise to copy, modify, sublicense or distribute the Program is\n"
224 "void, and will automatically terminate your rights under this License.\n"
225 "However, parties who have received copies, or rights, from you under\n"
226 "this License will not have their licenses terminated so long as such\n"
227 "parties remain in full compliance.\n"
229 " 5. You are not required to accept this License, since you have not\n"
230 "signed it. However, nothing else grants you permission to modify or\n"
231 "distribute the Program or its derivative works. These actions are\n"
232 "prohibited by law if you do not accept this License. Therefore, by\n"
233 "modifying or distributing the Program (or any work based on the\n"
234 "Program), you indicate your acceptance of this License to do so, and\n"
235 "all its terms and conditions for copying, distributing or modifying\n"
236 "the Program or works based on it.\n"
238 " 6. Each time you redistribute the Program (or any work based on the\n"
239 "Program), the recipient automatically receives a license from the\n"
240 "original licensor to copy, distribute or modify the Program subject to\n"
241 "these terms and conditions. You may not impose any further\n"
242 "restrictions on the recipients' exercise of the rights granted herein.\n"
243 "You are not responsible for enforcing compliance by third parties to\n"
246 " 7. If, as a consequence of a court judgment or allegation of patent\n"
247 "infringement or for any other reason (not limited to patent issues),\n"
248 "conditions are imposed on you (whether by court order, agreement or\n"
249 "otherwise) that contradict the conditions of this License, they do not\n"
250 "excuse you from the conditions of this License. If you cannot\n"
251 "distribute so as to satisfy simultaneously your obligations under this\n"
252 "License and any other pertinent obligations, then as a consequence you\n"
253 "may not distribute the Program at all. For example, if a patent\n"
254 "license would not permit royalty-free redistribution of the Program by\n"
255 "all those who receive copies directly or indirectly through you, then\n"
256 "the only way you could satisfy both it and this License would be to\n"
257 "refrain entirely from distribution of the Program.\n"
259 "If any portion of this section is held invalid or unenforceable under\n"
260 "any particular circumstance, the balance of the section is intended to\n"
261 "apply and the section as a whole is intended to apply in other\n"
264 "It is not the purpose of this section to induce you to infringe any\n"
265 "patents or other property right claims or to contest validity of any\n"
266 "such claims; this section has the sole purpose of protecting the\n"
267 "integrity of the free software distribution system, which is\n"
268 "implemented by public license practices. Many people have made\n"
269 "generous contributions to the wide range of software distributed\n"
270 "through that system in reliance on consistent application of that\n"
271 "system; it is up to the author/donor to decide if he or she is willing\n"
272 "to distribute software through any other system and a licensee cannot\n"
273 "impose that choice.\n"
275 "This section is intended to make thoroughly clear what is believed to\n"
276 "be a consequence of the rest of this License.\n"
278 " 8. If the distribution and/or use of the Program is restricted in\n"
279 "certain countries either by patents or by copyrighted interfaces, the\n"
280 "original copyright holder who places the Program under this License\n"
281 "may add an explicit geographical distribution limitation excluding\n"
282 "those countries, so that distribution is permitted only in or among\n"
283 "countries not thus excluded. In such case, this License incorporates\n"
284 "the limitation as if written in the body of this License.\n"
286 " 9. The Free Software Foundation may publish revised and/or new versions\n"
287 "of the General Public License from time to time. Such new versions will\n"
288 "be similar in spirit to the present version, but may differ in detail to\n"
289 "address new problems or concerns.\n"
291 "Each version is given a distinguishing version number. If the Program\n"
292 "specifies a version number of this License which applies to it and \"any\n"
293 "later version\", you have the option of following the terms and conditions\n"
294 "either of that version or of any later version published by the Free\n"
295 "Software Foundation. If the Program does not specify a version number of\n"
296 "this License, you may choose any version ever published by the Free Software\n"
299 " 10. If you wish to incorporate parts of the Program into other free\n"
300 "programs whose distribution conditions are different, write to the author\n"
301 "to ask for permission. For software which is copyrighted by the Free\n"
302 "Software Foundation, write to the Free Software Foundation; we sometimes\n"
303 "make exceptions for this. Our decision will be guided by the two goals\n"
304 "of preserving the free status of all derivatives of our free software and\n"
305 "of promoting the sharing and reuse of software generally.\n";
307 static char *warranty=
310 " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
311 "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"
312 "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
313 "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
314 "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
315 "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"
316 "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"
317 "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
318 "REPAIR OR CORRECTION.\n"
320 " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
321 "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
322 "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
323 "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
324 "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
325 "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
326 "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
327 "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
328 "POSSIBILITY OF SUCH DAMAGES.\n";
331 static void printTypeInfo(link *);
332 static void printValAggregates (symbol *,link *,char,unsigned int,int);
333 static void printOrSetSymValue (symbol *sym, context *cctxt,
334 int flg, int dnum, int fmt, char *rs, char *val);
336 int srcMode = SRC_CMODE ;
337 static set *dispsymbols = NULL ; /* set of displayable symbols */
338 static int currentFrame = 0; /* actual displayed frame */
339 /*-----------------------------------------------------------------*/
340 /* funcWithName - returns function with name */
341 /*-----------------------------------------------------------------*/
342 DEFSETFUNC(funcWithName)
344 function *func = item;
346 V_ARG(function **,funcp);
351 if (strcmp(func->sym->name,name) == 0) {
359 /*-----------------------------------------------------------------*/
360 /* symWithAddr - look for symbol with sfr / sbit address */
361 /*-----------------------------------------------------------------*/
362 DEFSETFUNC(symWithAddr)
365 V_ARG(unsigned long,laddr);
366 V_ARG(int ,laddrspace);
367 V_ARG(symbol **,rsym);
372 if ( sym->addr == laddr &&
373 sym->addrspace == laddrspace )
382 /*-----------------------------------------------------------------*/
383 /* setBPatModLine - set break point at the line specified for the */
384 /*-----------------------------------------------------------------*/
385 static void setBPatModLine (module *mod, int line, char bpType )
389 /* look for the first executable line after the line
390 specified & get the break point there */
391 if (srcMode == SRC_CMODE && line > mod->ncLines) {
392 fprintf(stderr,"No line %d in file \"%s\".\n",
397 if (srcMode == SRC_AMODE && line > mod->nasmLines) {
398 fprintf(stderr,"No line %d in file \"%s\".\n",
404 for ( ; next_line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
406 if (srcMode == SRC_CMODE) {
407 if (mod->cLines[next_line]->addr) {
408 setBreakPoint (mod->cLines[next_line]->addr, CODE, bpType,
409 userBpCB, mod->c_name, next_line);
415 if (mod->asmLines[next_line]->addr) {
416 setBreakPoint (mod->asmLines[next_line]->addr, CODE, bpType,
417 userBpCB, mod->asm_name, next_line);
424 fprintf(stderr,"No line %d or after in file \"%s\"..\n",
430 /*-----------------------------------------------------------------*/
431 /* clearBPatModLine - clr break point at the line specified */
432 /*-----------------------------------------------------------------*/
433 static void clearBPatModLine (module *mod, int line)
435 /* look for the first executable line after the line
436 specified & get the break point there */
437 if (srcMode == SRC_CMODE && line > mod->ncLines) {
438 fprintf(stderr,"No line %d in file \"%s\".\n",
443 if (srcMode == SRC_AMODE && line > mod->ncLines) {
444 fprintf(stderr,"No line %d in file \"%s\".\n",
449 for ( ; line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
451 if (srcMode == SRC_CMODE)
452 if (mod->cLines[line]->addr) {
453 clearUSERbp (mod->cLines[line]->addr);
457 if (mod->asmLines[line]->addr) {
458 clearUSERbp (mod->asmLines[line]->addr);
466 /*-----------------------------------------------------------------*/
467 /* moduleLineWithAddr - finds and returns a line with a given address */
468 /*-----------------------------------------------------------------*/
469 DEFSETFUNC(moduleLineWithAddr)
474 V_ARG(unsigned int,addr);
475 V_ARG(module **,rmod);
481 for (i=0; i < mod->nasmLines; i++ )
483 if ( mod->asmLines[i]->addr == addr)
489 for ( i=0; i < mod->ncLines; i++ )
491 if ( mod->cLines[i]->addr > addr)
503 /*-----------------------------------------------------------------*/
504 /* funcWithNameModule - returns functions with a name module combo */
505 /*-----------------------------------------------------------------*/
506 DEFSETFUNC(funcWithNameModule)
508 function *func = item;
511 V_ARG(function **,funcp);
516 if (strcmp(func->sym->name,fname) == 0 &&
517 strcmp(func->mod->c_name,mname) == 0) {
525 /*-----------------------------------------------------------------*/
526 /* funcInAddr - given an address returns the function */
527 /*-----------------------------------------------------------------*/
528 DEFSETFUNC(funcInAddr)
530 function *func = item;
531 V_ARG(unsigned int,addr);
532 V_ARG(function **,funcp);
537 /* in the address range */
538 if (func->sym->addr <= addr &&
539 func->sym->eaddr >= addr) {
548 /*-----------------------------------------------------------------*/
549 /* setStepBp - will set STEP Bp @ function entry points */
550 /*-----------------------------------------------------------------*/
551 DEFSETFUNC(setStepBp)
553 function *func = item;
555 if (func->sym && func->sym->addr ) {
557 /* set the entry break point */
558 setBreakPoint (func->sym->addr , CODE , STEP ,
559 stepBpCB ,func->mod->c_name , func->entryline);
567 /*-----------------------------------------------------------------*/
568 /* setStepEPBp - sets a given type of bp @ the execution point */
569 /*-----------------------------------------------------------------*/
570 DEFSETFUNC(setStepEPBp)
576 setBreakPoint (ep->addr, CODE, bptype,
577 stepBpCB, mname, ep->line);
581 /*-----------------------------------------------------------------*/
582 /* setNextEPBp - sets a given type of bp @ the execution point */
583 /*-----------------------------------------------------------------*/
584 DEFSETFUNC(setNextEPBp)
590 setBreakPoint (ep->addr, CODE, bptype,
591 nextBpCB, mname, ep->line);
595 /*-----------------------------------------------------------------*/
596 /* lineAtAddr - for execution points returns the one with addr */
597 /*-----------------------------------------------------------------*/
598 DEFSETFUNC(lineAtAddr)
601 V_ARG(unsigned int,addr);
606 /* address must be an exact match */
607 if (ep->addr == addr) {
620 /*-----------------------------------------------------------------*/
621 /* lineNearAddr - for execution points returns the one with addr */
622 /*-----------------------------------------------------------------*/
623 DEFSETFUNC(lineNearAddr)
626 V_ARG(unsigned int,addr);
631 /* the line in which the address is */
632 if (ep->addr <= addr) {
645 /*-----------------------------------------------------------------*/
646 /* discoverContext - find out the current context of the bp */
647 /*-----------------------------------------------------------------*/
648 context *discoverContext (unsigned addr, function *func)
653 /* find the function we are in */
654 if (!func && !applyToSet(functions,funcInAddr,addr,&func)) {
655 if (!applyToSet(functions,funcWithName,"main",&func) ||
656 !applyToSet(modules,moduleLineWithAddr,addr,&mod,NULL))
658 fprintf(stderr, "Error?:discoverContext: cannot apply addr 0x%x\n",addr);
661 currCtxt->func = func;
662 currCtxt->addr = addr;
663 currCtxt->modName = mod->name;
664 currCtxt->cline = func->exitline;
668 currCtxt->func = func;
669 currCtxt->addr = func->laddr = addr;
670 currCtxt->modName = func->modName;
672 /* find the c line number */
673 if(applyToSet(func->cfpoints,lineAtAddr,addr,
674 &line,&currCtxt->block,&currCtxt->level))
675 currCtxt->cline = func->lline = line;
676 else if(applyToSet(func->cfpoints,lineNearAddr,addr,
677 &line,&currCtxt->block,&currCtxt->level))
678 currCtxt->cline = func->lline = line;
680 currCtxt->cline = func->exitline;
682 /* find the asm line number */
684 if (applyToSet(func->afpoints,lineAtAddr,addr,
686 currCtxt->asmline = line;
688 currCtxt->asmline = -1;
694 /*-----------------------------------------------------------------*/
695 /* simGo - send 'go' cmd to simulator and wait till a break occurs */
696 /*-----------------------------------------------------------------*/
697 void simGo (unsigned int gaddr)
709 addr = simGoTillBp (gaddr);
711 /* got the pc for the break point now first
712 discover the program context i.e. module, function
713 linenumber of the source etc, etc etc */
715 ctxt = discoverContext (addr, NULL);
717 /* dispatch all the break point call back functions */
718 rv = dispatchCB (addr,ctxt);
721 /* the dispatch call back function will return
722 non-zero if an user break point has been hit
723 if not then we continue with the execution
729 if ( gaddr == -1 || doingSteps == 1 )
735 /*-----------------------------------------------------------------*/
736 /* preparePrint - common parse function for */
737 /* output, print and display */
738 /*-----------------------------------------------------------------*/
739 static char *preparePrint(char *s, context *cctxt, int *fmt, symbol **sym)
741 char *bp = s+strlen(s) -1;
747 while (isspace(*s)) s++;
751 while (isspace(*bp)) bp--;
757 /* format of printout */
775 while (isspace(*s)) s++;
777 for ( bp = s; *bp && ( isalnum( *bp ) || *bp == '_'); bp++ );
782 *sym = symLookup(s,cctxt);
786 fprintf(stdout,"No symbol \"%s\" in current context.\n", s);
790 static int printAsmLine( function *func, module *m, long saddr, long eaddr)
794 int lastaddr = saddr+1;
799 symaddr = func->sym->addr;
800 symname = func->sym->name;
807 for (j=0,i=0; i < m->nasmLines; i++ )
809 if ( saddr >= 0 && m->asmLines[i]->addr < saddr)
813 if ( eaddr >= 0 && m->asmLines[i]->addr > eaddr)
818 (m->asmLines[i]->addr < func->sym->addr ||
819 m->asmLines[i]->addr > func->sym->eaddr ))
823 delta = m->asmLines[i]->addr - symaddr;
827 lastaddr = m->asmLines[i]->addr;
828 printf("0x%08x <%s",lastaddr,symname);
829 if (delta > 0) printf("+%d",delta);
830 printf(">:\t%s",m->asmLines[i]->src);
836 /*-----------------------------------------------------------------*/
837 /* cmdDisasm - disassemble asm instruction */
838 /*-----------------------------------------------------------------*/
839 static int cmdDisasm (char *s, context *cctxt, int args)
841 function *func = NULL;
846 /* white space skip */
850 while (*s && isspace(*s)) s++;
854 saddr = strtol(s,&s,0);
857 while (*s && isspace(*s)) s++;
860 eaddr = strtol(s,0,0);
869 /* no start or only start so dump function */
876 applyToSet(functions,funcInAddr,saddr,&func);
880 printf("Dump of assembler code for function %s:\n",func->sym->name);
881 printAsmLine(func,func->mod,-1,-1);
882 printf("End of assembler dump.\n");
887 if (applyToSet(modules,moduleLineWithAddr,saddr,&modul,NULL))
890 printf("Dump of assembler code:\n");
891 printAsmLine(NULL,modul,saddr,eaddr);
892 printf("End of assembler dump.\n");
900 printf("Dump of assembler code from 0x%08x to 0x%08x:\n",saddr,eaddr);
902 while ( saddr < eaddr )
905 if (applyToSet(functions,funcInAddr,saddr,&func))
914 if (!applyToSet(modules,moduleLineWithAddr,saddr,&modul,NULL))
917 saddr = printAsmLine(func,modul,saddr,eaddr) + 1;
922 printf("End of assembler dump.\n");
927 fprintf(stderr,"No function contains specified address.\n");
930 /*-----------------------------------------------------------------*/
931 /* cmdDisasm1 - disassemble one asm instruction */
932 /*-----------------------------------------------------------------*/
933 int cmdDisasm1 (char *s, context *cctxt)
935 return cmdDisasm( s, cctxt, 1);
938 /*-----------------------------------------------------------------*/
939 /* cmdDisasmF - disassemble asm instructions */
940 /*-----------------------------------------------------------------*/
941 int cmdDisasmF(char *s, context *cctxt)
943 return cmdDisasm( s, cctxt, 2);
946 static int commonSetUserBp(char *s, context *cctxt, char bpType)
949 function *func = NULL;
951 /* user break point location specification can be of the following
953 a) <nothing> - break point at current location
954 b) lineno - number of the current module
955 c) filename:lineno - line number of the given file
956 e) filename:function- function X in file Y (useful for static functions)
957 f) function - function entry point
958 g) *addr - break point at address
962 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
965 /* white space skip */
966 while (*s && isspace(*s)) s++;
968 /* null terminate it after stripping trailing blanks*/
970 while (bp != s && isspace(*bp)) bp--;
973 /* case a) nothing */
974 /* if nothing given then current location : we know
975 the current execution location from the currentContext */
978 /* if current context is known */
980 if (srcMode == SRC_CMODE)
981 /* set the break point */
982 setBreakPoint ( cctxt->addr , CODE , bpType , userBpCB ,
983 cctxt->func->mod->c_name, cctxt->cline);
985 setBreakPoint ( cctxt->addr , CODE , bpType , userBpCB ,
986 cctxt->func->mod->asm_name, cctxt->asmline);
990 fprintf(stderr,"No default breakpoint address now.\n");
995 if ( *s == '*' && isdigit(*(s+1)))
998 long braddr = strtol(s+1,0,0);
999 if (!applyToSet(functions,funcInAddr,braddr,&func))
1002 if (!applyToSet(modules,moduleLineWithAddr,braddr,&modul,&line))
1004 fprintf(stderr,"Address 0x%08x not exists in code.\n",braddr);
1008 setBreakPoint ( braddr , CODE , bpType , userBpCB ,
1009 modul->c_name,line);
1015 int line = func->exitline;
1016 if ( !applyToSet(func->cfpoints,lineAtAddr,braddr,
1018 applyToSet(func->cfpoints,lineNearAddr,braddr,&line,NULL,NULL);
1019 setBreakPoint ( braddr , CODE , bpType , userBpCB ,
1020 func->mod->c_name,line);
1024 /* case b) lineno */
1025 /* check if line number */
1027 /* get the lineno */
1028 int line = atoi(s) -1;
1030 /* if current context not present then we must get the module
1031 which has main & set the break point @ line number provided
1032 of that module : if current context known then set the bp
1033 at the line number given for the current module
1036 if (!cctxt->func->mod) {
1037 if (!applyToSet(functions,funcWithName,"main"))
1038 fprintf(stderr,"Function \"main\" not defined.\n");
1040 setBPatModLine(func->mod,line, bpType);
1042 setBPatModLine(cctxt->func->mod,line, bpType);
1045 setBPatModLine(list_mod,line, bpType);
1047 fprintf(stdout,"Sdcdb fails to have module symbol context at %d\n", __LINE__);
1054 if ((bp = strchr(s,':'))) {
1059 if (srcMode == SRC_CMODE) {
1060 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
1061 fprintf (stderr,"No source file named %s.\n",s);
1065 if (!applyToSet(modules,moduleWithAsmName,s,&mod)) {
1066 fprintf (stderr,"No source file named %s.\n",s);
1071 /* case c) filename:lineno */
1072 if (isdigit(*(bp +1))) {
1074 setBPatModLine (mod,atoi(bp+1)-1,bpType);
1078 /* case d) filename:function */
1079 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
1080 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
1082 setBPatModLine (mod,
1083 (srcMode == SRC_CMODE ?
1085 func->aentryline),bpType);
1090 /* case e) function */
1091 if (!applyToSet(functions,funcWithName,s,&func))
1092 fprintf(stderr,"Function \"%s\" not defined.\n",s);
1094 setBPatModLine(func->mod,
1095 (srcMode == SRC_CMODE ?
1097 func->aentryline),bpType);
1103 /*-----------------------------------------------------------------*/
1104 /* cmdSetTmpUserBp - settempory break point at the user specified location */
1105 /*-----------------------------------------------------------------*/
1106 int cmdSetTmpUserBp (char *s, context *cctxt)
1108 return commonSetUserBp(s, cctxt, TMPUSER );
1111 /*-----------------------------------------------------------------*/
1112 /* cmdSetUserBp - set break point at the user specified location */
1113 /*-----------------------------------------------------------------*/
1114 int cmdSetUserBp (char *s, context *cctxt)
1116 return commonSetUserBp(s, cctxt, USER );
1119 /*-----------------------------------------------------------------*/
1120 /* cmdJump - set program counter */
1121 /*-----------------------------------------------------------------*/
1122 int cmdJump (char *s, context *cctxt)
1125 function *func = NULL;
1126 if (STACK_EMPTY(callStack))
1128 fprintf(stdout,"The program is not running.\n");
1132 /* white space skip */
1133 while (*s && isspace(*s)) s++;
1135 /* null terminate it after stripping trailing blanks*/
1137 while (bp != s && isspace(*bp)) bp--;
1141 fprintf(stdout,"No argument: need line or *addr.\n");
1144 if ( *s == '*' && isdigit(*(s+1)))
1146 unsigned int addr = atoi(s);
1147 if (cctxt && cctxt->func &&
1148 cctxt->func->sym->addr <= addr &&
1149 cctxt->func->sym->eaddr >= addr)
1154 fprintf(stdout,"Warning addr 0x%x outside actual function.\n",addr);
1160 /* get the lineno */
1161 int line = atoi(s) -1;
1162 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1164 fprintf(stderr,"Function not defined.\n");
1167 if (line >= cctxt->func->entryline &&
1168 line <= cctxt->func->exitline )
1170 simSetPC(cctxt->func->mod->cLines[line]->addr);
1173 if (line >= cctxt->func->mod->ncLines )
1175 fprintf(stderr,"line not in module.\n");
1178 fprintf(stdout,"Warning line %d outside actual function.\n",line+1);
1179 simSetPC(cctxt->func->mod->cLines[line]->addr);
1182 if ((bp = strchr(s,':')))
1187 if (!applyToSet(modules,moduleWithCName,s,&mod))
1189 fprintf (stderr,"No source file named %s.\n",s);
1194 fprintf (stderr,"No line number.\n");
1198 if (line >= mod->ncLines )
1200 fprintf(stderr,"line not in module.\n");
1203 if ( mod != cctxt->func->mod ||
1204 line < cctxt->func->entryline ||
1205 line > cctxt->func->exitline )
1207 fprintf(stdout,"Warning line %d outside actual function.\n",
1210 simSetPC(mod->cLines[line]->addr);
1215 /*-----------------------------------------------------------------*/
1216 /* cmdListAsm - list assembler source code */
1217 /*-----------------------------------------------------------------*/
1218 int cmdListAsm (char *s, context *cctxt)
1220 if ( cctxt && cctxt->func)
1223 if (printAsmLine(cctxt->func,cctxt->func->mod,
1224 (long)cctxt->addr,(long)cctxt->addr))
1230 /*-----------------------------------------------------------------*/
1231 /* cmdSetOption - set debugger options */
1232 /*-----------------------------------------------------------------*/
1233 int cmdSetOption (char *s, context *cctxt)
1235 while (*s && isspace(*s)) s++;
1236 if (strncmp(s,"srcmode",7) == 0 ) {
1237 if (srcMode == SRC_CMODE)
1238 srcMode = SRC_AMODE;
1240 srcMode = SRC_CMODE;
1241 fprintf(stderr,"source mode set to '%s'\n",
1242 (srcMode == SRC_CMODE ? "C" : "asm"));
1246 if (strncmp(s,"listsize ",9) == 0)
1248 listlines = strtol(s+9,0,0);
1249 if ( listlines < LISTLINES )
1250 listlines = LISTLINES;
1255 if (strncmp(s,"debug ",6) == 0)
1257 sdcdbDebug = strtol(s+6,0,0);
1261 if (strncmp(s,"variable ",9) == 0)
1267 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
1270 while (*s && *s != '=') s++;
1272 while (isspace(*s)) *s++ = '\0';
1275 printOrSetSymValue(sym,cctxt,0,0,0,rs,s);
1279 fprintf(stdout,"No new value for \"%s\".\n",s);
1284 fprintf(stderr,"'set %s' command not yet implemented\n",s);
1288 /*-----------------------------------------------------------------*/
1289 /* cmdContinue - continue till next break point */
1290 /*-----------------------------------------------------------------*/
1291 int cmdContinue (char *s, context *cctxt)
1293 if (STACK_EMPTY(callStack)) {
1294 fprintf(stdout,"The program is not being run.\n");
1298 fprintf(stdout,"Continuing.\n");
1304 /*-----------------------------------------------------------------*/
1305 /* cmdDelUserBp - delete user break point */
1306 /*-----------------------------------------------------------------*/
1307 int cmdDelUserBp (char *s, context *cctxt)
1310 while (isspace(*s)) s++;
1313 if (userBpPresent) {
1315 fprintf (stdout,"Delete all breakpoints? (y or n) ");
1317 fgets(buffer,sizeof(buffer),stdin);
1318 if (toupper(buffer[0]) == 'Y')
1324 /* determine the break point number */
1325 if (sscanf(s,"%d",&bpnum) == 1)
1326 deleteUSERbp(bpnum);
1331 /*-----------------------------------------------------------------*/
1332 /* cmdStepi - single step exactly one instruction */
1333 /*-----------------------------------------------------------------*/
1334 int cmdStepi (char *s, context *cctxt)
1337 if (STACK_EMPTY(callStack))
1338 fprintf(stdout,"The program is not being run.\n");
1349 /*-----------------------------------------------------------------*/
1350 /* cmdStep - single step thru C source file */
1351 /*-----------------------------------------------------------------*/
1352 int cmdStep (char *s, context *cctxt)
1354 function *func = NULL;
1356 if (STACK_EMPTY(callStack))
1357 fprintf(stdout,"The program is not being run.\n");
1359 /* if we are @ the end of a function then set
1360 break points at execution points of the
1361 function in the call stack... */
1362 if (cctxt->addr == cctxt->func->sym->eaddr) {
1363 if ((func = STACK_PEEK(callStack))) {
1364 if (srcMode == SRC_CMODE)
1365 applyToSet (func->cfpoints,setStepEPBp,STEP,
1368 applyToSet (func->afpoints,setStepEPBp,STEP,
1369 func->mod->asm_name);
1372 /* set breakpoints at all function entry points
1373 and all exepoints of this functions & for
1374 all functions one up in the call stack */
1376 /* all function entry points */
1377 applyToSet(functions,setStepBp);
1379 if (srcMode == SRC_CMODE) {
1380 /* for all execution points in this function */
1381 applyToSet(cctxt->func->cfpoints,setStepEPBp,STEP,
1382 cctxt->func->mod->c_name);
1384 /* set a break point @ the current function's
1386 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
1387 stepBpCB, cctxt->func->mod->c_name,
1388 cctxt->func->exitline);
1390 /* now break point @ callers execution points */
1391 if ((func = STACK_PPEEK(callStack))) {
1392 applyToSet (func->cfpoints,setStepEPBp,STEP,
1394 /* set bp @ callers exit point */
1395 setBreakPoint (func->sym->eaddr, CODE, STEP ,
1396 stepBpCB, func->mod->c_name,
1400 /* for all execution points in this function */
1401 applyToSet(cctxt->func->afpoints,setStepEPBp,STEP,
1402 cctxt->func->mod->asm_name);
1404 /* set a break point @ the current function's
1406 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
1407 stepBpCB, cctxt->func->mod->asm_name,
1408 cctxt->func->aexitline);
1410 /* now break point @ callers execution points */
1411 if ((func = STACK_PPEEK(callStack))) {
1413 applyToSet (func->afpoints,setStepEPBp,STEP,
1414 func->mod->asm_name);
1416 /* set bp @ callers exit point */
1417 setBreakPoint (func->sym->eaddr, CODE, STEP ,
1418 stepBpCB, func->mod->asm_name,
1432 /*-----------------------------------------------------------------*/
1433 /* cmdNexti - next instruction but proceed function call */
1434 /*-----------------------------------------------------------------*/
1435 int cmdNexti (char *s, context *cctxt)
1437 if (STACK_EMPTY(callStack))
1438 fprintf(stdout,"The program is not being run.\n");
1449 /*-----------------------------------------------------------------*/
1450 /* cmdNext - next executable C statement file */
1451 /*-----------------------------------------------------------------*/
1452 int cmdNext (char *s, context *cctxt)
1454 function *func = NULL;
1455 /* next is almost the same as step except we don't
1456 we don't set break point for all function entry
1458 if (STACK_EMPTY(callStack))
1459 fprintf(stdout,"The program is not being run.\n");
1461 /* if we are @ the end of a function then set
1462 break points at execution points of the
1463 function in the call stack... */
1464 if (cctxt->addr == cctxt->func->sym->eaddr) {
1465 if ((func = STACK_PEEK(callStack))) {
1466 if (srcMode == SRC_CMODE)
1467 applyToSet (func->cfpoints,setStepEPBp,NEXT,
1470 applyToSet (func->afpoints,setStepEPBp,NEXT,
1471 func->mod->asm_name);
1474 if (srcMode == SRC_CMODE) {
1475 /* for all execution points in this function */
1476 applyToSet(cctxt->func->cfpoints,setNextEPBp,NEXT,
1477 cctxt->func->mod->c_name);
1478 /* set a break point @ the current function's
1480 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
1481 nextBpCB, cctxt->func->mod->c_name,
1482 cctxt->func->exitline);
1484 /* now break point @ callers execution points */
1485 if ((func = STACK_PPEEK(callStack))) {
1486 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
1488 /* set bp @ callers exit point */
1489 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
1490 stepBpCB, func->mod->c_name,
1494 /* for all execution points in this function */
1495 applyToSet(cctxt->func->afpoints,setNextEPBp,NEXT,
1496 cctxt->func->mod->asm_name);
1497 /* set a break point @ the current function's
1499 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
1500 nextBpCB, cctxt->func->mod->asm_name,
1501 cctxt->func->aexitline);
1503 /* now break point @ callers execution points */
1504 if ((func = STACK_PPEEK(callStack))) {
1505 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
1506 func->mod->asm_name);
1507 /* set bp @ callers exit point */
1508 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
1509 stepBpCB, func->mod->asm_name,
1522 /*-----------------------------------------------------------------*/
1523 /* cmdRun - run till next break point */
1524 /*-----------------------------------------------------------------*/
1525 int cmdRun (char *s, context *cctxt)
1528 if (STACK_EMPTY(callStack)) {
1529 fprintf(stdout,"Starting program\n");
1532 fprintf(stdout,"No executable file specified.\nUse the \"file\" command.\n");
1539 "The program being debugged has been started already.\n");
1540 fprintf(stdout,"Start it from the beginning? (y or n) ");
1543 fgets(buff,sizeof(buff),stdin);
1544 if (toupper(buff[0]) == 'Y') {
1553 /*-----------------------------------------------------------------
1554 cmdListSymbols - list symbols
1555 |-----------------------------------------------------------------*/
1556 int cmdListSymbols (char *s, context *cctxt)
1558 int our_verbose = 0;
1562 if (strstr(s, "v1")) {
1564 } else if (strstr(s, "v2")) {
1568 printf("[symbols]\n");
1569 sy = setFirstItem(symbols);
1574 if (our_verbose <= 1)
1575 printf("<%s>", sy->name);
1577 if (our_verbose > 1) {
1578 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1579 sy->name, sy->size, sy->level, sy->block);
1580 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1581 sy->isonstack, sy->isfunc, sy->offset, sy->addr);
1582 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1583 sy->eaddr, sy->addr_type, sy->type, sy->etype);
1584 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1585 sy->scopetype, sy->sname, sy->rname, sy->addrspace);
1586 printf(" next:%x\n", sy->next);
1589 sy = setNextItem(symbols);
1591 printf(" %d symbols\n", i);
1595 /*-----------------------------------------------------------------
1596 cmdListFunctions - list functions.
1597 |-----------------------------------------------------------------*/
1598 int cmdListFunctions (char *s, context *cctxt)
1602 int our_verbose = 0;
1604 if (strstr(s, "v1")) {
1606 } else if (strstr(s, "v2")) {
1610 printf("[functions]\n");
1611 f = setFirstItem(functions);
1617 printf(" %d) sym:%x, fname:%s, modName:%s, mod:%x\n", i,
1618 f->sym, f->sym->name, f->modName, f->mod);
1619 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1620 f->entryline, f->aentryline, f->exitline, f->aexitline);
1621 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1622 f->cfpoints, f->afpoints, f->laddr, f->lline);
1625 printf("<%s>", f->modName);
1628 f = setNextItem(functions);
1630 printf(" %d functions\n", i);
1634 /*-----------------------------------------------------------------
1635 cmdListModules - list functions.
1636 |-----------------------------------------------------------------*/
1637 int cmdListModules (char *s, context *cctxt)
1642 int our_verbose = 0;
1644 if (strstr(s, "v1")) {
1646 } else if (strstr(s, "v2")) {
1650 printf("[modules]\n");
1651 m = setFirstItem(modules);
1657 if (our_verbose >= 0) {
1658 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1659 m->cfullname, m->afullname, m->name);
1660 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1661 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1662 printf(" cLines:%x, asmLines:%x\n",
1663 m->cLines, m->asmLines);
1665 if (our_verbose >= 2) {
1667 printf(" [cLines] ");
1669 for (i=0; i<m->ncLines; i++ ) {
1671 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1672 i, cs->addr, cs->block, cs->level, cs->src);
1675 printf("%d records", i);
1678 printf(" [asmLines] ");
1680 for (i=0; i<m->nasmLines; i++ ) {
1681 as = m->asmLines[i];
1682 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1683 i, as->addr, as->block, as->level, as->src);
1686 printf("%d records", i);
1691 m = setNextItem(modules);
1696 /*-----------------------------------------------------------------
1697 infoSymbols - This is really just a tool to dump all these
1698 huge program structures out into human readable form.
1699 |-----------------------------------------------------------------*/
1700 static void infoSymbols(context *ctxt)
1702 int our_verbose = 0;
1704 printf("[context:%x] func:%x modName:%s addr:%x\n",
1705 ctxt, ctxt->func, ctxt->modName, ctxt->addr);
1707 printf(" cline:%d asmline:%d block:%d level:%d\n",
1708 ctxt->cline, ctxt->asmline, ctxt->level);
1710 printf("[globals] currCtxt:%x, modules:%x, functions:%x symbols:%x\n",
1711 currCtxt, modules, functions, symbols);
1712 printf(" nStructs:%d, structs:%x, ssdirl:%s\n",
1713 nStructs, structs, ssdirl);
1715 /**************** modules *******************/
1720 printf("[modules]\n");
1721 m = setFirstItem(modules);
1726 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1727 m->cfullname, m->afullname, m->name);
1728 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1729 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1730 printf(" cLines:%x, asmLines:%x\n",
1731 m->cLines, m->asmLines);
1734 cs = m->cLines[i++];
1735 printf(" [cLines] ");
1738 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1739 i, cs->addr, cs->block, cs->level, cs->src);
1740 cs = m->cLines[i++];
1743 printf("%d records", i);
1747 as = m->asmLines[i++];
1748 printf(" [asmLines] ");
1751 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1752 i, as->addr, as->block, as->level, as->src);
1753 as = m->asmLines[i++];
1756 printf("%d records", i);
1760 m = setNextItem(modules);
1764 /**************** functions *******************/
1768 printf("[functions]\n");
1769 f = setFirstItem(functions);
1775 printf(" %d) sym:%x, modName:%s, mod:%x\n", i,
1776 f->sym, f->modName, f->mod);
1777 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1778 f->entryline, f->aentryline, f->exitline, f->aexitline);
1779 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1780 f->cfpoints, f->afpoints, f->laddr, f->lline);
1783 f = setNextItem(functions);
1786 printf(" %d functions\n", i);
1789 /**************** symbols *******************/
1793 printf("[symbols]\n");
1794 s = setFirstItem(symbols);
1800 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1801 s->name, s->size, s->level, s->block);
1802 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1803 s->isonstack, s->isfunc, s->offset, s->addr);
1804 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1805 s->eaddr, s->addr_type, s->type, s->etype);
1806 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1807 s->scopetype, s->sname, s->rname, s->addrspace);
1808 printf(" next:%x\n", s->next);
1811 s = setNextItem(symbols);
1814 printf(" %d symbols\n", i);
1819 /*-----------------------------------------------------------------*/
1820 /* infoRegisters - print register information */
1821 /*-----------------------------------------------------------------*/
1822 static void infoRegisters( int all, context *ctxt)
1824 static unsigned int regaddrs[] = {0x81,0x82,0x83,0xd0,0xe0,0xf0,0};
1828 i = simGetValue (0xd0,'I',1);
1829 fprintf(stdout,"PC : 0x%04X RegisterBank %d:\nR0-7:",ctxt->addr,(i>>3)&3);
1830 for ( j = 0; j < 8 ; j++ )
1832 val = simGetValue (j ,'R',1);
1833 fprintf(stdout," 0x%02X",val);
1835 fprintf(stdout,"\n");
1836 val = simGetValue (0xe0,'I',1);
1837 fprintf(stdout,"ACC : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.'));
1838 val = simGetValue (0xf0,'I',1);
1839 fprintf(stdout,"B : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.'));
1840 val = simGetValue (0x82,'I',2);
1841 fprintf(stdout,"DPTR: 0x%04X %d\n",val,val);
1842 val = simGetValue (0x81,'I',1);
1843 fprintf(stdout,"SP : 0x%02X\n",val);
1844 fprintf(stdout,"PSW : 0x%02X | CY : %c | AC : %c | OV : %c | P : %c\n",
1845 i,(i&0x80)?'1':'0',(i&0x40)?'1':'0',(i&4)?'1':'0',(i&1)?'1':'0');
1848 fprintf(stdout,"Special Function Registers:\n");
1850 for ( i = 0x80 ; i < 0x100 ; i++ )
1853 if ( *r && *r == i )
1855 /* skip normal registers */
1859 if (applyToSetFTrue(sfrsymbols,symWithAddr,i,'I',&sym))
1861 val = simGetValue (sym->addr,sym->addrspace,sym->size);
1862 fprintf(stdout,"%s : 0x%02x",sym->name,val);
1865 for ( j = 0 ; j < 8 ; j++ )
1868 if (applyToSetFTrue(sfrsymbols,symWithAddr,i+j,'J',&sym))
1870 //val = simGetValue (sym->addr,sym->addrspace,sym->size);
1871 fprintf(stdout," %s=%c",sym->name,(val&1)? '1':'0');
1876 fprintf(stdout,"\n");
1882 /*-----------------------------------------------------------------*/
1883 /* infoStack - print call stack information */
1884 /*-----------------------------------------------------------------*/
1885 static void infoStack(context *ctxt)
1890 STACK_STARTWALK(callStack) ;
1891 while ((func = STACK_WALK(callStack))) {
1892 Dprintf(D_break, ("break: infoStack: %s %p (%p)\n",func->sym->name, w_callStack,p_callStack));
1894 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",i++,
1895 func->laddr,func->sym->name,
1896 func->mod->c_name,func->lline+1);
1899 fprintf(stdout,"no stack.\n");
1902 /*-----------------------------------------------------------------*/
1903 /* cmdWhere - where command */
1904 /*-----------------------------------------------------------------*/
1905 int cmdWhere(char *s, context *cctxt)
1912 static int infomode = 0;
1913 /*-----------------------------------------------------------------*/
1914 /* cmdInfo - info command */
1915 /*-----------------------------------------------------------------*/
1916 int cmdInfo (char *s, context *cctxt)
1918 while (isspace(*s)) s++;
1920 /* list all break points */
1921 if (strncmp(s,"break",5) == 0) {
1926 /* info frame same as frame */
1927 if (strcmp(s,"frame") == 0) {
1932 if (strncmp(s,"line",4) == 0) {
1934 cmdListSrc (s+4,cctxt);
1937 if (strncmp(s,"source",6) == 0)
1943 fprintf(stdout,"Source files for which symbols have been read in:\n\n");
1944 for (m = setFirstItem(modules); m ; m = setNextItem(modules))
1946 fprintf(stdout,"%s%s, %s",k ? ", ":"",m->cfullname, m->afullname);
1949 fprintf(stdout,"\n");
1953 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1955 fprintf(stdout,"No source file loaded\n");
1958 m = cctxt->func->mod;
1959 fprintf(stdout,"Current source file is %s\n",m->c_name);
1960 fprintf(stdout,"Located in %s\n",m->cfullname);
1961 fprintf(stdout,"Contains %d lines.\nSource language is c.\n",
1966 if (strncmp(s,"functions",7) == 0)
1970 fprintf(stdout,"All defined functions:\n");
1971 for ( f = setFirstItem(functions); f ; f = setNextItem(functions))
1976 fprintf(stdout,"\nFile %s\n", m->c_name);
1978 fprintf(stdout,"%s();\n",f->sym->name);
1982 /* info stack display call stack */
1983 if (strcmp(s,"stack") == 0) {
1989 /* info stack display call stack */
1990 if (strcmp(s,"registers") == 0) {
1991 infoRegisters(0,cctxt);
1995 /* info stack display call stack */
1996 if (strcmp(s,"all-registers") == 0)
1998 infoRegisters(1,cctxt);
2002 /* info stack display call stack */
2003 if (strcmp(s,"symbols") == 0) {
2004 /* dump out symbols we have read in */
2005 fprintf(stdout,"Dumping symbols...\n");
2010 if (strcmp(s,"variables") == 0) {
2011 /* dump out symbols we have read in */
2012 fprintf(stdout,"Dumping symbols...\n");
2017 fprintf(stdout,"Undefined info command: \"%s\". Try \"help\n",s);
2022 /*-----------------------------------------------------------------*/
2023 /* cmdQuit - quit debugging */
2024 /*-----------------------------------------------------------------*/
2025 int cmdQuit (char *s, context *cctxt)
2032 /*-----------------------------------------------------------------*/
2033 /* cmdListSrc - list src */
2034 /*-----------------------------------------------------------------*/
2035 int cmdListSrc (char *s, context *cctxt)
2037 static int currline = 0;
2040 int llines = listlines;
2041 function *func = NULL;
2044 while (*s && isspace(*s)) s++;
2046 /* if the user has spcified line numer then the line number
2047 can be of the following formats
2048 LINE - just line number
2049 FILE:LINE - filename line number
2050 FILE:LINE,LASTLINE + last line
2051 FUNCTION - list a function
2052 FILE:FUNCTION - function in file */
2057 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
2059 fprintf(stdout,"Sdcdb fails to have a proper context at %d.\n", __LINE__);
2064 list_mod = cctxt->func->mod;
2065 pline = strtol(s,&s,10) - 1;
2066 if (s && (s = strchr(s,',')))
2069 llines = strtol(s+1,0,10);
2079 /* if ':' present then FILE:LINE || FILE:FUNCTION */
2080 if ((bp = strchr(s,':'))) {
2085 list_mod=NULL; /* bug fix 2-09-02, moduleWithCName expects mod to be null */
2086 if (srcMode == SRC_CMODE) {
2087 if (!applyToSet(modules,moduleWithCName,s,&list_mod)) {
2088 fprintf (stderr,"No c source file named %s.\n",s);
2092 if (!applyToSet(modules,moduleWithAsmName,s,&list_mod)) {
2093 fprintf (stderr,"No source file named %s.\n",s);
2097 pline = strtol(bp,&bp,10) - 1;
2098 if (bp && (bp = strchr(bp,',')))
2100 /* FILE:LINE,LASTLINE */
2101 llines = strtol(bp+1,0,10);
2109 if (!applyToSet(functions,funcWithNameModule,bp,s,&func)) {
2110 fprintf(stdout,"Function \"%s\" not defined.\n",bp);
2113 list_mod = func->mod;
2114 if (srcMode == SRC_CMODE) {
2115 pline = func->entryline;
2116 llines = func->exitline - func->entryline + 1;
2118 pline = func->aentryline;
2119 llines = func->aexitline - func->aentryline + 1;
2129 if ((bp = strrchr(s,'\'')))
2135 if (!applyToSet(functions,funcWithName,s,&func)) {
2136 fprintf(stderr,"Function \"%s\" not defined.\n",s);
2140 list_mod = func->mod;
2141 if (srcMode == SRC_CMODE) {
2142 pline = func->entryline;
2143 llines = func->exitline - func->entryline + 1;
2145 pline = func->aentryline;
2146 llines = func->aexitline - func->aentryline + 1;
2152 /* if no line specified & we had listed
2153 before then continue from that listing */
2157 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
2158 fprintf(stdout,"Missing context at %d. Try list filename:lineno\n", __LINE__);
2161 list_mod = cctxt->func->mod;
2162 if (srcMode == SRC_CMODE)
2163 pline = cctxt->cline;
2165 pline = cctxt->asmline;
2170 fprintf(stdout,"Sdcdb fails to have a valid module context at %d.\n", __LINE__);
2178 int firstaddr , lastaddr ;
2179 if ( pline >= list_mod->ncLines )
2180 pline = cctxt->cline;
2181 firstaddr = lastaddr = list_mod->cLines[pline]->addr;
2182 if (!func && cctxt && cctxt->func )
2184 fprintf(stdout,"Line %d of \"%s\" starts at address 0x%08x <%s+%d>",
2186 list_mod->c_name, lastaddr,
2187 func ? func->sym->name : "?",
2188 func ? lastaddr -func->sym->addr : 0);
2190 while ( pline < list_mod->ncLines )
2193 if ( list_mod->cLines[pline]->addr > lastaddr )
2195 lastaddr = list_mod->cLines[pline]->addr -1;
2199 fprintf(stdout," and ends at 0x%08x <%s+%d>.\n",
2201 func ? func->sym->name : "?",
2202 func ? lastaddr -func->sym->addr : 0);
2205 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
2206 func->mod->cfullname,
2212 for ( i = 0 ; i < llines ; i++ ) {
2213 if (srcMode == SRC_CMODE) {
2214 if ( (pline + i) >= list_mod->ncLines )
2216 fprintf(stdout,"%d\t%s",pline + i,
2217 list_mod->cLines[pline +i]->src);
2219 if ( (pline + i) >= list_mod->nasmLines )
2221 fprintf(stdout,"%d\t%s",pline + i,
2222 list_mod->asmLines[pline +i]->src);
2225 currline = pline + i ;
2229 static void setValBasic(symbol *sym, link *type,
2230 char mem, unsigned addr,int size, char *val)
2246 v.f = strtof(val,NULL);
2249 v.val = strtol(val,NULL,0);
2252 if (IS_INTEGRAL(type))
2261 if (( s = strchr(val,'\'')))
2264 v.b[0] = strtol(s+2,NULL,8);
2270 v.b[0] = strtol(val,NULL,0);
2276 v.val = strtol(val,NULL,0);
2278 v.i.lo = strtol(val,NULL,0);
2280 v.val = strtol(val,NULL,0);
2283 v.val = strtol(val,NULL,0);
2285 simSetValue(addr,mem,size,v.val);
2288 /*-----------------------------------------------------------------*/
2289 /* printFmtInteger - print value in bin,oct,dez or hex */
2290 /*-----------------------------------------------------------------*/
2291 static void printFmtInteger(char *deffmt,int fmt, long val,
2294 static char digits[] =
2296 '0' , '1' , '2' , '3' , '4' , '5' ,
2297 '6' , '7' , '8' , '9' , 'a' , 'b' ,
2298 'c' , 'd' , 'e' , 'f' , 'g' , 'h'
2300 static int radixOfFormat[] = { 0 , 2, 8 ,10, 16 };
2301 static int olenOfSize[] = { 0 , 3, 6 , 8, 11 };
2307 if ( fmt == FMT_NON || fmt == FMT_DEZ )
2309 fprintf(stdout,deffmt,val);
2312 radix = radixOfFormat[fmt];
2315 if ( sign && val < 0 )
2323 while (val <= -radix)
2325 buf[charPos--] = digits[-(val % radix)];
2328 buf[charPos] = digits[-val];
2333 radix = olenOfSize[size];
2343 while (charPos > 39 - radix )
2345 buf[--charPos] = '0';
2350 if ( buf[charPos] != '0' )
2351 buf[--charPos] = '0';
2354 buf[--charPos] = 'x';
2355 buf[--charPos] = '0';
2359 buf[--charPos] = '-';
2361 fputs(&buf[charPos],stdout);
2364 /*-----------------------------------------------------------------*/
2365 /* printValBasic - print value of basic types */
2366 /*-----------------------------------------------------------------*/
2367 static void printValBasic(symbol *sym, link *type,
2368 char mem, unsigned addr,int size, int fmt)
2384 v.val = simGetValue(addr,mem,size);
2385 /* if this a floating point number then */
2387 fprintf(stdout,"%f",v.f);
2390 fprintf(stdout,"0x%*x",size<<1,v.val);
2392 if (IS_INTEGRAL(type))
2401 if ( isprint(v.val))
2402 printFmtInteger((SPEC_USIGN(etype)?"0x%02x":"'%c'"),
2403 fmt,(long)v.val,0,size);
2405 printFmtInteger((SPEC_USIGN(etype)?"0x%02x":"'\\%o'"),
2406 fmt,(long)v.val,0,size);
2412 if (SPEC_USIGN(etype))
2413 printFmtInteger("%u",fmt,(long)v.val,0,size);
2415 printFmtInteger("%d",fmt,(long)v.sval,1,size);
2417 if (SPEC_USIGN(etype))
2418 printFmtInteger("%u",fmt,(long)v.i.lo,0,size);
2420 printFmtInteger("%d",fmt,(long)v.i.lo,1,size);
2423 if (IS_BITVAR(etype))
2424 fprintf(stdout,"%c",(v.val?'1':'0'));
2426 fprintf(stdout,"0x%0*x",size<<1,v.val);
2430 fprintf(stdout,"0x%0*x",size<<1,v.val);
2433 /*-----------------------------------------------------------------*/
2434 /* printValFunc - prints function values */
2435 /*-----------------------------------------------------------------*/
2436 static void printValFunc (symbol *sym, int fmt)
2438 fprintf(stdout,"print function not yet implemented");
2441 /*-----------------------------------------------------------------*/
2442 /* printArrayValue - will print the values of array elements */
2443 /*-----------------------------------------------------------------*/
2444 static void printArrayValue (symbol *sym, link *type,
2445 char space, unsigned int addr, int fmt)
2447 link *elem_type = type->next;
2450 fprintf(stdout,"{");
2451 for (i = 0 ; i < DCL_ELEM(type) ; i++) {
2452 if (IS_AGGREGATE(elem_type)) {
2453 printValAggregates(sym,elem_type,space,addr,fmt);
2455 printValBasic(sym,elem_type,space,addr,getSize(elem_type),fmt);
2457 addr += getSize(elem_type);
2458 if (i != DCL_ELEM(type) -1)
2459 fprintf(stdout,",");
2462 fprintf(stdout,"}");
2465 /*-----------------------------------------------------------------*/
2466 /* printStructValue - prints structures elements */
2467 /*-----------------------------------------------------------------*/
2468 static void printStructValue (symbol *sym, link *type,
2469 char space, unsigned int addr, int fmt)
2471 symbol *fields = SPEC_STRUCT(type)->fields;
2473 fprintf(stdout," { ");
2475 fprintf(stdout,"%s%s = ",(first ? "": ", "),fields->name);
2477 if (IS_AGGREGATE(fields->type)) {
2478 printValAggregates(fields,fields->type,space, addr, fmt);
2480 printValBasic(fields,fields->type,space,addr,getSize(fields->type), fmt);
2482 addr += getSize(fields->type);
2483 fields = fields->next;
2485 fprintf(stdout,"}");
2488 /*-----------------------------------------------------------------*/
2489 /* printValAggregates - print value of aggregates */
2490 /*-----------------------------------------------------------------*/
2491 static void printValAggregates (symbol *sym, link *type,
2492 char space,unsigned int addr, int fmt)
2495 if (IS_ARRAY(type)) {
2496 printArrayValue(sym, type, space, addr, fmt);
2500 if (IS_STRUCT(type)) {
2501 printStructValue(sym, type, space, addr, fmt);
2506 /*-----------------------------------------------------------------*/
2507 /* printOrSetSymValue - print or set value of a symbol */
2508 /*-----------------------------------------------------------------*/
2509 static void printOrSetSymValue (symbol *sym, context *cctxt,
2510 int flg, int dnum, int fmt, char *rs, char *val)
2512 static char fmtChar[] = " todx ";
2513 static int stack = 1;
2519 char save_ch, save_ch2;
2521 /* if it is on stack then compute address & fall thru */
2524 symbol *bp = symLookup("bp",cctxt);
2527 fprintf(stdout,"cannot determine stack frame\n");
2531 sym->addr = simGetValue(bp->addr,bp->addrspace,bp->size)
2535 /* get the value from the simulator and
2543 fprintf(stdout,"$%d = ",stack++);
2546 fprintf(stdout,"%d: ", dnum);
2547 if ( fmt != FMT_NON )
2548 fprintf(stdout,"/%c ",fmtChar[fmt]);
2549 fprintf(stdout,"%s%s = ",sym->name,rs);
2559 if ( *rs == '[' && IS_ARRAY(type))
2562 while ( *rs && *rs != ']' ) rs++ ;
2565 if ( ! isdigit(*s ))
2567 /* index seems a variable */
2568 for ( s2 = s; *s2 && ( isalnum( *s2 ) || *s2 == '_'); s2++ );
2572 fields = symLookup(s,cctxt);
2576 fprintf(stdout,"Unkown variable \"%s\" for index.\n", s);
2579 /* arrays & structures first */
2580 if (! IS_INTEGRAL(fields->type))
2582 fprintf(stdout,"Wrong type of variable \"%s\" for index \n", s);
2585 n = simGetValue(fields->addr,fields->addrspace,getSize(fields->type));
2591 if ( n < 0 || n >= DCL_ELEM(type))
2593 fprintf(stdout,"Wrong index %d.\n", n);
2597 size = getSize(type);
2601 else if ( *rs == '.' && IS_STRUCT(type))
2604 /* search structure element */
2605 for ( rs = s; *rs && ( isalnum( *rs ) || *rs == '_'); rs++ );
2609 for (fields = SPEC_STRUCT(type)->fields; fields; fields = fields->next)
2611 if (!(strcmp(s,fields->name)))
2617 fprintf(stdout,"Unknown field \"%s\" of structure\n", s);
2620 type = fields->type;
2621 size = getSize(type);
2622 addr += fields->offset;
2628 /* arrays & structures first */
2629 if (IS_AGGREGATE(type))
2632 fprintf(stdout,"Cannot set aggregate variable\n");
2634 printValAggregates(sym,type,sym->addrspace,addr,fmt);
2641 printValFunc(sym,fmt);
2646 setValBasic (sym,type,sym->addrspace,addr,size,val);
2648 printValBasic(sym,type,sym->addrspace,addr,size,fmt);
2650 if ( flg > 0 ) fprintf(stdout,"\n");
2654 /*-----------------------------------------------------------------*/
2655 /* printStructInfo - print out structure information */
2656 /*-----------------------------------------------------------------*/
2657 static void printStructInfo (structdef *sdef)
2659 symbol *field = sdef->fields ;
2664 field = field->next;
2667 fprintf(stdout,"%s %s {\n",(i ? "struct" : "union" ), sdef->tag);
2668 field = sdef->fields;
2670 printTypeInfo (field->type);
2671 fprintf(stdout," %s ;\n",field->name);
2672 field = field->next ;
2675 fprintf(stdout,"}\n");
2679 /*-----------------------------------------------------------------*/
2680 /* printTypeInfo - print out the type information */
2681 /*-----------------------------------------------------------------*/
2682 static void printTypeInfo(link *p)
2688 switch (DCL_TYPE(p)) {
2690 printTypeInfo (p->next);
2691 fprintf(stdout,"()");
2694 printTypeInfo (p->next);
2695 fprintf(stdout,"[%d]",DCL_ELEM(p));
2701 printTypeInfo (p->next);
2702 fprintf(stdout,"(_near *)");
2706 printTypeInfo (p->next);
2707 fprintf(stdout,"(_xdata *)");
2711 printTypeInfo( p->next);
2712 fprintf(stdout,"(_code *)");
2716 printTypeInfo( p->next);
2717 fprintf(stdout,"(_generic *)");
2721 switch (SPEC_NOUN(p)) { /* depending on the specifier type */
2723 (IS_LONG(p) ? fputs("long ",stdout) :
2724 ( IS_SHORT(p) ? fputs("short ",stdout) :
2725 fputs("int ",stdout))) ;
2728 fputs("float ",stdout);
2732 fputs ("char ",stdout);
2736 fputs("void ",stdout);
2740 printStructInfo (SPEC_STRUCT(p));
2744 fputs("sbit ",stdout);
2748 fprintf(stdout,": %d" ,SPEC_BLEN(p));
2754 /*-----------------------------------------------------------------*/
2755 /* cmdPrint - print value of variable */
2756 /*-----------------------------------------------------------------*/
2757 int cmdPrint (char *s, context *cctxt)
2762 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2767 printOrSetSymValue(sym,cctxt,1,0,fmt,rs,NULL);
2772 /*-----------------------------------------------------------------*/
2773 /* cmdOutput - print value of variable without number and newline */
2774 /*-----------------------------------------------------------------*/
2775 int cmdOutput (char *s, context *cctxt)
2780 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2785 printOrSetSymValue(sym,cctxt,0,0,fmt,rs,NULL);
2790 /** find display entry with this number */
2792 DEFSETFUNC(dsymWithNumber)
2794 dsymbol *dsym = item;
2796 V_ARG(dsymbol **,dsymp);
2798 if ( dsym->dnum == dnum )
2806 /*-----------------------------------------------------------------*/
2807 /* displayAll - display all valid variables */
2808 /*-----------------------------------------------------------------*/
2809 void displayAll(context *cctxt)
2815 for (dsym = setFirstItem(dispsymbols);
2817 dsym = setNextItem(dispsymbols))
2819 if ( (sym = symLookup(dsym->name,cctxt)))
2820 printOrSetSymValue(sym,cctxt,2,dsym->dnum,dsym->fmt,dsym->rs,NULL);
2824 /*-----------------------------------------------------------------*/
2825 /* cmdDisplay - display value of variable */
2826 /*-----------------------------------------------------------------*/
2827 int cmdDisplay (char *s, context *cctxt)
2829 static int dnum = 1;
2833 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2841 dsymbol *dsym = (dsymbol *)Safe_calloc(1,sizeof(dsymbol));
2842 dsym->dnum = dnum++ ;
2843 dsym->name = sym->name;
2845 dsym->rs = gc_strdup(rs);
2846 addSetHead(&dispsymbols,dsym);
2851 /*-----------------------------------------------------------------*/
2852 /* cmdUnDisplay - undisplay value of variable */
2853 /*-----------------------------------------------------------------*/
2854 int cmdUnDisplay (char *s, context *cctxt)
2859 while (isspace(*s)) s++;
2862 for (dsym = setFirstItem(dispsymbols);
2864 dsym = setNextItem(dispsymbols))
2866 Safe_free(dsym->rs);
2869 deleteSet(&dispsymbols);
2874 dnum = strtol(s,&s,10);
2875 if (applyToSetFTrue(dispsymbols,dsymWithNumber,dnum,&dsym))
2877 deleteSetItem(&dispsymbols,dsym);
2878 Safe_free(dsym->rs);
2883 fprintf(stdout,"Arguments must be display numbers.\n");
2889 /*-----------------------------------------------------------------*/
2890 /* cmdPrintType - print type of a variable */
2891 /*-----------------------------------------------------------------*/
2892 int cmdPrintType (char *s, context *cctxt)
2895 char *bp = s+strlen(s) -1;
2897 while (isspace(*s)) s++;
2899 while (isspace(*bp)) bp--;
2903 if ((sym = symLookup(s,cctxt))) {
2904 printTypeInfo(sym->type);
2905 fprintf(stdout,"\n");
2908 "No symbol \"%s\" in current context.\n",
2914 /*-----------------------------------------------------------------*/
2915 /* cmdClrUserBp - clear user break point */
2916 /*-----------------------------------------------------------------*/
2917 int cmdClrUserBp (char *s, context *cctxt)
2920 function *func = NULL;
2922 /* clear break point location specification can be of the following
2924 a) <nothing> - break point at current location
2925 b) lineno - number of the current module
2926 c) filename:lineno - line number of the given file
2927 e) filename:function- function X in file Y (useful for static functions)
2928 f) function - function entry point
2932 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
2936 /* white space skip */
2937 while (*s && isspace(*s)) s++;
2939 /* null terminate it after stripping trailing blanks*/
2941 while (bp != s && isspace(*bp)) bp--;
2944 /* case a) nothing */
2945 /* if nothing given then current location : we know
2946 the current execution location from the currentContext */
2949 /* if current context is known */
2951 /* clear the break point @ current location */
2952 clearUSERbp (cctxt->addr);
2954 fprintf(stderr,"No default breakpoint address now.\n");
2959 /* case b) lineno */
2960 /* check if line number */
2962 /* get the lineno */
2965 /* if current context not present then we must get the module
2966 which has main & set the break point @ line number provided
2967 of that module : if current context known then set the bp
2968 at the line number given for the current module
2971 if (!cctxt->func->mod) {
2972 if (!applyToSet(functions,funcWithName,"main"))
2973 fprintf(stderr,"Function \"main\" not defined.\n");
2975 clearBPatModLine(func->mod,line);
2977 clearBPatModLine(cctxt->func->mod,line);
2983 if ((bp = strchr(s,':'))) {
2988 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
2989 fprintf (stderr,"No source file named %s.\n",s);
2993 /* case c) filename:lineno */
2994 if (isdigit(*(bp +1))) {
2996 clearBPatModLine (mod,atoi(bp+1));
3000 /* case d) filename:function */
3001 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
3002 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
3004 clearBPatModLine (mod,func->entryline);
3009 /* case e) function */
3010 if (!applyToSet(functions,funcWithName,s,&func))
3011 fprintf(stderr,"Function \"%s\" not defined.\n",s);
3013 clearBPatModLine(func->mod,func->entryline);
3020 /*-----------------------------------------------------------------*/
3021 /* cmdSimulator - send command to simulator */
3022 /*-----------------------------------------------------------------*/
3023 int cmdSimulator (char *s, context *cctxt)
3027 if (strlen(s) > 80) {
3028 printf("error 3A\n");
3032 strcat(tmpstr, "\n");
3034 waitForSim(200,NULL);
3035 fprintf(stdout,"%s",simResponse());
3039 void setMainContext()
3041 function *func = NULL;
3043 if (!applyToSet(functions,funcWithName,"main",&func) &&
3044 !applyToSet(functions,funcWithName,"_main",&func))
3047 discoverContext (func->sym->addr, func);
3050 static void printFrame()
3053 function *func = NULL;
3054 function *lastfunc = NULL;
3056 if ( currentFrame < 0 )
3059 fprintf(stdout,"Bottom (i.e., innermost) frame selected; you cannot go down.\n");
3062 STACK_STARTWALK(callStack) ;
3063 for ( i = 0; i <= currentFrame ; i++ )
3065 func = STACK_WALK(callStack);
3069 fprintf(stdout,"Initial frame selected; you cannot go up.\n");
3073 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",
3074 currentFrame,func->laddr,func->sym->name,func->mod->c_name,func->lline+1);
3075 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
3076 func->mod->cfullname,func->lline+1,func->laddr);
3078 discoverContext (func->laddr, func);
3082 /*-----------------------------------------------------------------*/
3083 /* cmdUp - Up command */
3084 /*-----------------------------------------------------------------*/
3085 int cmdUp(char *s, context *cctxt)
3087 while (isspace(*s)) s++;
3089 currentFrame += strtol(s,0,10);
3097 /*-----------------------------------------------------------------*/
3098 /* cmdDown - down command */
3099 /*-----------------------------------------------------------------*/
3100 int cmdDown(char *s, context *cctxt)
3102 while (isspace(*s)) s++;
3104 currentFrame -= strtol(s,0,10);
3111 /*-----------------------------------------------------------------*/
3112 /* cmdFrame - Frame command */
3113 /*-----------------------------------------------------------------*/
3114 int cmdFrame (char *s, context *cctxt)
3116 function *func = NULL;
3119 while (isspace(*s)) s++;
3121 currentFrame = strtol(s,0,10);
3126 /*-----------------------------------------------------------------*/
3127 /* cmdFinish - exec till end of current function */
3128 /*-----------------------------------------------------------------*/
3129 int cmdFinish (char *s, context *ctxt)
3131 if (STACK_EMPTY(callStack)) {
3132 fprintf(stdout,"The program is not running.\n");
3136 if (srcMode == SRC_CMODE) {
3137 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
3138 stepBpCB, ctxt->func->mod->c_name,
3139 ctxt->func->exitline);
3141 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
3142 stepBpCB, ctxt->func->mod->asm_name,
3143 ctxt->func->aexitline);
3153 /*-----------------------------------------------------------------*/
3154 /* cmdShow - show command */
3155 /*-----------------------------------------------------------------*/
3156 int cmdShow (char *s, context *cctxt)
3158 /* skip white space */
3159 while (*s && isspace(*s)) s++ ;
3161 if (strcmp(s,"copying") == 0) {
3162 fputs(copying,stdout);
3166 if (strcmp(s,"warranty") == 0) {
3167 fputs(warranty,stdout);