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 /* cmdCommands - set commands for breakpoint */
1306 /*-----------------------------------------------------------------*/
1307 int cmdCommands (char *s, context *cctxt)
1311 while (isspace(*s)) s++;
1314 bpnum = getLastBreakptNumber();
1316 bpnum = strtol(s,0,10);
1319 while ((line = getNextCmdLine()))
1321 while (isspace(*line)) line++;
1322 if (!strncmp(line,"end",3))
1326 cmds = Safe_strdup(line);
1330 cmds = Safe_realloc( cmds, strlen(cmds) + 1 + strlen(line));
1334 setUserbpCommand(bpnum,cmds);
1338 /*-----------------------------------------------------------------*/
1339 /* cmdDelUserBp - delete user break point */
1340 /*-----------------------------------------------------------------*/
1341 int cmdDelUserBp (char *s, context *cctxt)
1344 while (isspace(*s)) s++;
1347 if (userBpPresent) {
1349 fprintf (stdout,"Delete all breakpoints? (y or n) ");
1351 fgets(buffer,sizeof(buffer),stdin);
1352 if (toupper(buffer[0]) == 'Y')
1358 /* determine the break point number */
1359 if (sscanf(s,"%d",&bpnum) == 1)
1360 deleteUSERbp(bpnum);
1365 /*-----------------------------------------------------------------*/
1366 /* cmdStepi - single step exactly one instruction */
1367 /*-----------------------------------------------------------------*/
1368 int cmdStepi (char *s, context *cctxt)
1371 if (STACK_EMPTY(callStack))
1372 fprintf(stdout,"The program is not being run.\n");
1383 /*-----------------------------------------------------------------*/
1384 /* cmdStep - single step thru C source file */
1385 /*-----------------------------------------------------------------*/
1386 int cmdStep (char *s, context *cctxt)
1388 function *func = NULL;
1390 if (STACK_EMPTY(callStack))
1391 fprintf(stdout,"The program is not being run.\n");
1393 /* if we are @ the end of a function then set
1394 break points at execution points of the
1395 function in the call stack... */
1396 if (cctxt->addr == cctxt->func->sym->eaddr) {
1397 if ((func = STACK_PEEK(callStack))) {
1398 if (srcMode == SRC_CMODE)
1399 applyToSet (func->cfpoints,setStepEPBp,STEP,
1402 applyToSet (func->afpoints,setStepEPBp,STEP,
1403 func->mod->asm_name);
1406 /* set breakpoints at all function entry points
1407 and all exepoints of this functions & for
1408 all functions one up in the call stack */
1410 /* all function entry points */
1411 applyToSet(functions,setStepBp);
1413 if (srcMode == SRC_CMODE) {
1414 /* for all execution points in this function */
1415 applyToSet(cctxt->func->cfpoints,setStepEPBp,STEP,
1416 cctxt->func->mod->c_name);
1418 /* set a break point @ the current function's
1420 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
1421 stepBpCB, cctxt->func->mod->c_name,
1422 cctxt->func->exitline);
1424 /* now break point @ callers execution points */
1425 if ((func = STACK_PPEEK(callStack))) {
1426 applyToSet (func->cfpoints,setStepEPBp,STEP,
1428 /* set bp @ callers exit point */
1429 setBreakPoint (func->sym->eaddr, CODE, STEP ,
1430 stepBpCB, func->mod->c_name,
1434 /* for all execution points in this function */
1435 applyToSet(cctxt->func->afpoints,setStepEPBp,STEP,
1436 cctxt->func->mod->asm_name);
1438 /* set a break point @ the current function's
1440 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
1441 stepBpCB, cctxt->func->mod->asm_name,
1442 cctxt->func->aexitline);
1444 /* now break point @ callers execution points */
1445 if ((func = STACK_PPEEK(callStack))) {
1447 applyToSet (func->afpoints,setStepEPBp,STEP,
1448 func->mod->asm_name);
1450 /* set bp @ callers exit point */
1451 setBreakPoint (func->sym->eaddr, CODE, STEP ,
1452 stepBpCB, func->mod->asm_name,
1466 /*-----------------------------------------------------------------*/
1467 /* cmdNexti - next instruction but proceed function call */
1468 /*-----------------------------------------------------------------*/
1469 int cmdNexti (char *s, context *cctxt)
1471 if (STACK_EMPTY(callStack))
1472 fprintf(stdout,"The program is not being run.\n");
1483 /*-----------------------------------------------------------------*/
1484 /* cmdNext - next executable C statement file */
1485 /*-----------------------------------------------------------------*/
1486 int cmdNext (char *s, context *cctxt)
1488 function *func = NULL;
1489 /* next is almost the same as step except we don't
1490 we don't set break point for all function entry
1492 if (STACK_EMPTY(callStack))
1493 fprintf(stdout,"The program is not being run.\n");
1495 /* if we are @ the end of a function then set
1496 break points at execution points of the
1497 function in the call stack... */
1498 if (cctxt->addr == cctxt->func->sym->eaddr) {
1499 if ((func = STACK_PEEK(callStack))) {
1500 if (srcMode == SRC_CMODE)
1501 applyToSet (func->cfpoints,setStepEPBp,NEXT,
1504 applyToSet (func->afpoints,setStepEPBp,NEXT,
1505 func->mod->asm_name);
1508 if (srcMode == SRC_CMODE) {
1509 /* for all execution points in this function */
1510 applyToSet(cctxt->func->cfpoints,setNextEPBp,NEXT,
1511 cctxt->func->mod->c_name);
1512 /* set a break point @ the current function's
1514 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
1515 nextBpCB, cctxt->func->mod->c_name,
1516 cctxt->func->exitline);
1518 /* now break point @ callers execution points */
1519 if ((func = STACK_PPEEK(callStack))) {
1520 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
1522 /* set bp @ callers exit point */
1523 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
1524 stepBpCB, func->mod->c_name,
1528 /* for all execution points in this function */
1529 applyToSet(cctxt->func->afpoints,setNextEPBp,NEXT,
1530 cctxt->func->mod->asm_name);
1531 /* set a break point @ the current function's
1533 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
1534 nextBpCB, cctxt->func->mod->asm_name,
1535 cctxt->func->aexitline);
1537 /* now break point @ callers execution points */
1538 if ((func = STACK_PPEEK(callStack))) {
1539 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
1540 func->mod->asm_name);
1541 /* set bp @ callers exit point */
1542 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
1543 stepBpCB, func->mod->asm_name,
1556 /*-----------------------------------------------------------------*/
1557 /* cmdRun - run till next break point */
1558 /*-----------------------------------------------------------------*/
1559 int cmdRun (char *s, context *cctxt)
1562 if (STACK_EMPTY(callStack)) {
1563 fprintf(stdout,"Starting program\n");
1566 fprintf(stdout,"No executable file specified.\nUse the \"file\" command.\n");
1573 "The program being debugged has been started already.\n");
1574 fprintf(stdout,"Start it from the beginning? (y or n) ");
1577 fgets(buff,sizeof(buff),stdin);
1578 if (toupper(buff[0]) == 'Y') {
1587 /*-----------------------------------------------------------------
1588 cmdListSymbols - list symbols
1589 |-----------------------------------------------------------------*/
1590 int cmdListSymbols (char *s, context *cctxt)
1592 int our_verbose = 0;
1596 if (strstr(s, "v1")) {
1598 } else if (strstr(s, "v2")) {
1602 printf("[symbols]\n");
1603 sy = setFirstItem(symbols);
1608 if (our_verbose <= 1)
1609 printf("<%s>", sy->name);
1611 if (our_verbose > 1) {
1612 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1613 sy->name, sy->size, sy->level, sy->block);
1614 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1615 sy->isonstack, sy->isfunc, sy->offset, sy->addr);
1616 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1617 sy->eaddr, sy->addr_type, sy->type, sy->etype);
1618 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1619 sy->scopetype, sy->sname, sy->rname, sy->addrspace);
1620 printf(" next:%x\n", sy->next);
1623 sy = setNextItem(symbols);
1625 printf(" %d symbols\n", i);
1629 /*-----------------------------------------------------------------
1630 cmdListFunctions - list functions.
1631 |-----------------------------------------------------------------*/
1632 int cmdListFunctions (char *s, context *cctxt)
1636 int our_verbose = 0;
1638 if (strstr(s, "v1")) {
1640 } else if (strstr(s, "v2")) {
1644 printf("[functions]\n");
1645 f = setFirstItem(functions);
1651 printf(" %d) sym:%x, fname:%s, modName:%s, mod:%x\n", i,
1652 f->sym, f->sym->name, f->modName, f->mod);
1653 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1654 f->entryline, f->aentryline, f->exitline, f->aexitline);
1655 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1656 f->cfpoints, f->afpoints, f->laddr, f->lline);
1659 printf("<%s>", f->modName);
1662 f = setNextItem(functions);
1664 printf(" %d functions\n", i);
1668 /*-----------------------------------------------------------------
1669 cmdListModules - list functions.
1670 |-----------------------------------------------------------------*/
1671 int cmdListModules (char *s, context *cctxt)
1676 int our_verbose = 0;
1678 if (strstr(s, "v1")) {
1680 } else if (strstr(s, "v2")) {
1684 printf("[modules]\n");
1685 m = setFirstItem(modules);
1691 if (our_verbose >= 0) {
1692 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1693 m->cfullname, m->afullname, m->name);
1694 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1695 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1696 printf(" cLines:%x, asmLines:%x\n",
1697 m->cLines, m->asmLines);
1699 if (our_verbose >= 2) {
1701 printf(" [cLines] ");
1703 for (i=0; i<m->ncLines; i++ ) {
1705 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1706 i, cs->addr, cs->block, cs->level, cs->src);
1709 printf("%d records", i);
1712 printf(" [asmLines] ");
1714 for (i=0; i<m->nasmLines; i++ ) {
1715 as = m->asmLines[i];
1716 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1717 i, as->addr, as->block, as->level, as->src);
1720 printf("%d records", i);
1725 m = setNextItem(modules);
1730 /*-----------------------------------------------------------------
1731 infoSymbols - This is really just a tool to dump all these
1732 huge program structures out into human readable form.
1733 |-----------------------------------------------------------------*/
1734 static void infoSymbols(context *ctxt)
1736 int our_verbose = 0;
1738 printf("[context:%x] func:%x modName:%s addr:%x\n",
1739 ctxt, ctxt->func, ctxt->modName, ctxt->addr);
1741 printf(" cline:%d asmline:%d block:%d level:%d\n",
1742 ctxt->cline, ctxt->asmline, ctxt->level);
1744 printf("[globals] currCtxt:%x, modules:%x, functions:%x symbols:%x\n",
1745 currCtxt, modules, functions, symbols);
1746 printf(" nStructs:%d, structs:%x, ssdirl:%s\n",
1747 nStructs, structs, ssdirl);
1749 /**************** modules *******************/
1754 printf("[modules]\n");
1755 m = setFirstItem(modules);
1760 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1761 m->cfullname, m->afullname, m->name);
1762 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1763 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1764 printf(" cLines:%x, asmLines:%x\n",
1765 m->cLines, m->asmLines);
1768 cs = m->cLines[i++];
1769 printf(" [cLines] ");
1772 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1773 i, cs->addr, cs->block, cs->level, cs->src);
1774 cs = m->cLines[i++];
1777 printf("%d records", i);
1781 as = m->asmLines[i++];
1782 printf(" [asmLines] ");
1785 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1786 i, as->addr, as->block, as->level, as->src);
1787 as = m->asmLines[i++];
1790 printf("%d records", i);
1794 m = setNextItem(modules);
1798 /**************** functions *******************/
1802 printf("[functions]\n");
1803 f = setFirstItem(functions);
1809 printf(" %d) sym:%x, modName:%s, mod:%x\n", i,
1810 f->sym, f->modName, f->mod);
1811 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1812 f->entryline, f->aentryline, f->exitline, f->aexitline);
1813 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1814 f->cfpoints, f->afpoints, f->laddr, f->lline);
1817 f = setNextItem(functions);
1820 printf(" %d functions\n", i);
1823 /**************** symbols *******************/
1827 printf("[symbols]\n");
1828 s = setFirstItem(symbols);
1834 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1835 s->name, s->size, s->level, s->block);
1836 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1837 s->isonstack, s->isfunc, s->offset, s->addr);
1838 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1839 s->eaddr, s->addr_type, s->type, s->etype);
1840 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1841 s->scopetype, s->sname, s->rname, s->addrspace);
1842 printf(" next:%x\n", s->next);
1845 s = setNextItem(symbols);
1848 printf(" %d symbols\n", i);
1853 /*-----------------------------------------------------------------*/
1854 /* infoRegisters - print register information */
1855 /*-----------------------------------------------------------------*/
1856 static void infoRegisters( int all, context *ctxt)
1858 static unsigned int regaddrs[] = {0x81,0x82,0x83,0xd0,0xe0,0xf0,0};
1862 i = simGetValue (0xd0,'I',1);
1863 fprintf(stdout,"PC : 0x%04X RegisterBank %d:\nR0-7:",ctxt->addr,(i>>3)&3);
1864 for ( j = 0; j < 8 ; j++ )
1866 val = simGetValue (j ,'R',1);
1867 fprintf(stdout," 0x%02X",val);
1869 fprintf(stdout,"\n");
1870 val = simGetValue (0xe0,'I',1);
1871 fprintf(stdout,"ACC : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.'));
1872 val = simGetValue (0xf0,'I',1);
1873 fprintf(stdout,"B : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.'));
1874 val = simGetValue (0x82,'I',2);
1875 fprintf(stdout,"DPTR: 0x%04X %d\n",val,val);
1876 val = simGetValue (0x81,'I',1);
1877 fprintf(stdout,"SP : 0x%02X\n",val);
1878 fprintf(stdout,"PSW : 0x%02X | CY : %c | AC : %c | OV : %c | P : %c\n",
1879 i,(i&0x80)?'1':'0',(i&0x40)?'1':'0',(i&4)?'1':'0',(i&1)?'1':'0');
1882 fprintf(stdout,"Special Function Registers:\n");
1884 for ( i = 0x80 ; i < 0x100 ; i++ )
1887 if ( *r && *r == i )
1889 /* skip normal registers */
1893 if (applyToSetFTrue(sfrsymbols,symWithAddr,i,'I',&sym))
1895 val = simGetValue (sym->addr,sym->addrspace,sym->size);
1896 fprintf(stdout,"%s : 0x%02x",sym->name,val);
1899 for ( j = 0 ; j < 8 ; j++ )
1902 if (applyToSetFTrue(sfrsymbols,symWithAddr,i+j,'J',&sym))
1904 //val = simGetValue (sym->addr,sym->addrspace,sym->size);
1905 fprintf(stdout," %s=%c",sym->name,(val&1)? '1':'0');
1910 fprintf(stdout,"\n");
1916 /*-----------------------------------------------------------------*/
1917 /* infoStack - print call stack information */
1918 /*-----------------------------------------------------------------*/
1919 static void infoStack(context *ctxt)
1924 STACK_STARTWALK(callStack) ;
1925 while ((func = STACK_WALK(callStack))) {
1926 Dprintf(D_break, ("break: infoStack: %s %p (%p)\n",func->sym->name, w_callStack,p_callStack));
1928 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",i++,
1929 func->laddr,func->sym->name,
1930 func->mod->c_name,func->lline+1);
1933 fprintf(stdout,"no stack.\n");
1936 /*-----------------------------------------------------------------*/
1937 /* cmdWhere - where command */
1938 /*-----------------------------------------------------------------*/
1939 int cmdWhere(char *s, context *cctxt)
1946 static int infomode = 0;
1947 /*-----------------------------------------------------------------*/
1948 /* cmdInfo - info command */
1949 /*-----------------------------------------------------------------*/
1950 int cmdInfo (char *s, context *cctxt)
1952 while (isspace(*s)) s++;
1954 /* list all break points */
1955 if (strncmp(s,"break",5) == 0) {
1960 /* info frame same as frame */
1961 if (strcmp(s,"frame") == 0) {
1966 if (strncmp(s,"line",4) == 0) {
1968 cmdListSrc (s+4,cctxt);
1971 if (strncmp(s,"source",6) == 0)
1977 fprintf(stdout,"Source files for which symbols have been read in:\n\n");
1978 for (m = setFirstItem(modules); m ; m = setNextItem(modules))
1980 fprintf(stdout,"%s%s, %s",k ? ", ":"",m->cfullname, m->afullname);
1983 fprintf(stdout,"\n");
1987 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1989 fprintf(stdout,"No source file loaded\n");
1992 m = cctxt->func->mod;
1993 fprintf(stdout,"Current source file is %s\n",m->c_name);
1994 fprintf(stdout,"Located in %s\n",m->cfullname);
1995 fprintf(stdout,"Contains %d lines.\nSource language is c.\n",
2000 if (strncmp(s,"functions",7) == 0)
2004 fprintf(stdout,"All defined functions:\n");
2005 for ( f = setFirstItem(functions); f ; f = setNextItem(functions))
2010 fprintf(stdout,"\nFile %s\n", m->c_name);
2012 fprintf(stdout,"%s();\n",f->sym->name);
2016 /* info stack display call stack */
2017 if (strcmp(s,"stack") == 0) {
2023 /* info stack display call stack */
2024 if (strcmp(s,"registers") == 0) {
2025 infoRegisters(0,cctxt);
2029 /* info stack display call stack */
2030 if (strcmp(s,"all-registers") == 0)
2032 infoRegisters(1,cctxt);
2036 /* info stack display call stack */
2037 if (strcmp(s,"symbols") == 0) {
2038 /* dump out symbols we have read in */
2039 fprintf(stdout,"Dumping symbols...\n");
2044 if (strcmp(s,"variables") == 0) {
2045 /* dump out symbols we have read in */
2046 fprintf(stdout,"Dumping symbols...\n");
2051 fprintf(stdout,"Undefined info command: \"%s\". Try \"help\n",s);
2056 /*-----------------------------------------------------------------*/
2057 /* cmdQuit - quit debugging */
2058 /*-----------------------------------------------------------------*/
2059 int cmdQuit (char *s, context *cctxt)
2066 /*-----------------------------------------------------------------*/
2067 /* cmdListSrc - list src */
2068 /*-----------------------------------------------------------------*/
2069 int cmdListSrc (char *s, context *cctxt)
2071 static int currline = 0;
2074 int llines = listlines;
2075 function *func = NULL;
2078 while (*s && isspace(*s)) s++;
2080 /* if the user has spcified line numer then the line number
2081 can be of the following formats
2082 LINE - just line number
2083 FILE:LINE - filename line number
2084 FILE:LINE,LASTLINE + last line
2085 FUNCTION - list a function
2086 FILE:FUNCTION - function in file */
2091 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
2093 fprintf(stdout,"Sdcdb fails to have a proper context at %d.\n", __LINE__);
2098 list_mod = cctxt->func->mod;
2099 pline = strtol(s,&s,10) - 1;
2100 if (s && (s = strchr(s,',')))
2103 llines = strtol(s+1,0,10);
2113 /* if ':' present then FILE:LINE || FILE:FUNCTION */
2114 if ((bp = strchr(s,':'))) {
2119 list_mod=NULL; /* bug fix 2-09-02, moduleWithCName expects mod to be null */
2120 if (srcMode == SRC_CMODE) {
2121 if (!applyToSet(modules,moduleWithCName,s,&list_mod)) {
2122 fprintf (stderr,"No c source file named %s.\n",s);
2126 if (!applyToSet(modules,moduleWithAsmName,s,&list_mod)) {
2127 fprintf (stderr,"No source file named %s.\n",s);
2131 pline = strtol(bp,&bp,10) - 1;
2132 if (bp && (bp = strchr(bp,',')))
2134 /* FILE:LINE,LASTLINE */
2135 llines = strtol(bp+1,0,10);
2143 if (!applyToSet(functions,funcWithNameModule,bp,s,&func)) {
2144 fprintf(stdout,"Function \"%s\" not defined.\n",bp);
2147 list_mod = func->mod;
2148 if (srcMode == SRC_CMODE) {
2149 pline = func->entryline;
2150 llines = func->exitline - func->entryline + 1;
2152 pline = func->aentryline;
2153 llines = func->aexitline - func->aentryline + 1;
2163 if ((bp = strrchr(s,'\'')))
2169 if (!applyToSet(functions,funcWithName,s,&func)) {
2170 fprintf(stderr,"Function \"%s\" not defined.\n",s);
2174 list_mod = func->mod;
2175 if (srcMode == SRC_CMODE) {
2176 pline = func->entryline;
2177 llines = func->exitline - func->entryline + 1;
2179 pline = func->aentryline;
2180 llines = func->aexitline - func->aentryline + 1;
2186 /* if no line specified & we had listed
2187 before then continue from that listing */
2191 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
2192 fprintf(stdout,"Missing context at %d. Try list filename:lineno\n", __LINE__);
2195 list_mod = cctxt->func->mod;
2196 if (srcMode == SRC_CMODE)
2197 pline = cctxt->cline;
2199 pline = cctxt->asmline;
2204 fprintf(stdout,"Sdcdb fails to have a valid module context at %d.\n", __LINE__);
2212 int firstaddr , lastaddr ;
2213 if ( pline >= list_mod->ncLines )
2214 pline = cctxt->cline;
2215 firstaddr = lastaddr = list_mod->cLines[pline]->addr;
2216 if (!func && cctxt && cctxt->func )
2218 fprintf(stdout,"Line %d of \"%s\" starts at address 0x%08x <%s+%d>",
2220 list_mod->c_name, lastaddr,
2221 func ? func->sym->name : "?",
2222 func ? lastaddr -func->sym->addr : 0);
2224 while ( pline < list_mod->ncLines )
2227 if ( list_mod->cLines[pline]->addr > lastaddr )
2229 lastaddr = list_mod->cLines[pline]->addr -1;
2233 fprintf(stdout," and ends at 0x%08x <%s+%d>.\n",
2235 func ? func->sym->name : "?",
2236 func ? lastaddr -func->sym->addr : 0);
2239 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
2240 func->mod->cfullname,
2246 for ( i = 0 ; i < llines ; i++ ) {
2247 if (srcMode == SRC_CMODE) {
2248 if ( (pline + i) >= list_mod->ncLines )
2250 fprintf(stdout,"%d\t%s",pline + i,
2251 list_mod->cLines[pline +i]->src);
2253 if ( (pline + i) >= list_mod->nasmLines )
2255 fprintf(stdout,"%d\t%s",pline + i,
2256 list_mod->asmLines[pline +i]->src);
2259 currline = pline + i ;
2263 static void setValBasic(symbol *sym, link *type,
2264 char mem, unsigned addr,int size, char *val)
2280 v.f = strtof(val,NULL);
2283 v.val = strtol(val,NULL,0);
2286 if (IS_INTEGRAL(type))
2295 if (( s = strchr(val,'\'')))
2298 v.b[0] = strtol(s+2,NULL,8);
2304 v.b[0] = strtol(val,NULL,0);
2310 v.val = strtol(val,NULL,0);
2312 v.i.lo = strtol(val,NULL,0);
2314 v.val = strtol(val,NULL,0);
2317 v.val = strtol(val,NULL,0);
2319 simSetValue(addr,mem,size,v.val);
2322 /*-----------------------------------------------------------------*/
2323 /* printFmtInteger - print value in bin,oct,dez or hex */
2324 /*-----------------------------------------------------------------*/
2325 static void printFmtInteger(char *deffmt,int fmt, long val,
2328 static char digits[] =
2330 '0' , '1' , '2' , '3' , '4' , '5' ,
2331 '6' , '7' , '8' , '9' , 'a' , 'b' ,
2332 'c' , 'd' , 'e' , 'f' , 'g' , 'h'
2334 static int radixOfFormat[] = { 0 , 2, 8 ,10, 16 };
2335 static int olenOfSize[] = { 0 , 3, 6 , 8, 11 };
2341 if ( fmt == FMT_NON || fmt == FMT_DEZ )
2343 fprintf(stdout,deffmt,val);
2346 radix = radixOfFormat[fmt];
2349 if ( sign && val < 0 )
2357 while (val <= -radix)
2359 buf[charPos--] = digits[-(val % radix)];
2362 buf[charPos] = digits[-val];
2367 radix = olenOfSize[size];
2377 while (charPos > 39 - radix )
2379 buf[--charPos] = '0';
2384 if ( buf[charPos] != '0' )
2385 buf[--charPos] = '0';
2388 buf[--charPos] = 'x';
2389 buf[--charPos] = '0';
2393 buf[--charPos] = '-';
2395 fputs(&buf[charPos],stdout);
2398 /*-----------------------------------------------------------------*/
2399 /* printValBasic - print value of basic types */
2400 /*-----------------------------------------------------------------*/
2401 static void printValBasic(symbol *sym, link *type,
2402 char mem, unsigned addr,int size, int fmt)
2418 v.val = simGetValue(addr,mem,size);
2419 /* if this a floating point number then */
2421 fprintf(stdout,"%f",v.f);
2424 fprintf(stdout,"0x%*x",size<<1,v.val);
2426 if (IS_INTEGRAL(type))
2435 if ( isprint(v.val))
2436 printFmtInteger((SPEC_USIGN(etype)?"0x%02x":"'%c'"),
2437 fmt,(long)v.val,0,size);
2439 printFmtInteger((SPEC_USIGN(etype)?"0x%02x":"'\\%o'"),
2440 fmt,(long)v.val,0,size);
2446 if (SPEC_USIGN(etype))
2447 printFmtInteger("%u",fmt,(long)v.val,0,size);
2449 printFmtInteger("%d",fmt,(long)v.sval,1,size);
2451 if (SPEC_USIGN(etype))
2452 printFmtInteger("%u",fmt,(long)v.i.lo,0,size);
2454 printFmtInteger("%d",fmt,(long)v.i.lo,1,size);
2457 if (IS_BITVAR(etype))
2458 fprintf(stdout,"%c",(v.val?'1':'0'));
2460 fprintf(stdout,"0x%0*x",size<<1,v.val);
2464 fprintf(stdout,"0x%0*x",size<<1,v.val);
2467 /*-----------------------------------------------------------------*/
2468 /* printValFunc - prints function values */
2469 /*-----------------------------------------------------------------*/
2470 static void printValFunc (symbol *sym, int fmt)
2472 fprintf(stdout,"print function not yet implemented");
2475 /*-----------------------------------------------------------------*/
2476 /* printArrayValue - will print the values of array elements */
2477 /*-----------------------------------------------------------------*/
2478 static void printArrayValue (symbol *sym, link *type,
2479 char space, unsigned int addr, int fmt)
2481 link *elem_type = type->next;
2484 fprintf(stdout,"{");
2485 for (i = 0 ; i < DCL_ELEM(type) ; i++) {
2486 if (IS_AGGREGATE(elem_type)) {
2487 printValAggregates(sym,elem_type,space,addr,fmt);
2489 printValBasic(sym,elem_type,space,addr,getSize(elem_type),fmt);
2491 addr += getSize(elem_type);
2492 if (i != DCL_ELEM(type) -1)
2493 fprintf(stdout,",");
2496 fprintf(stdout,"}");
2499 /*-----------------------------------------------------------------*/
2500 /* printStructValue - prints structures elements */
2501 /*-----------------------------------------------------------------*/
2502 static void printStructValue (symbol *sym, link *type,
2503 char space, unsigned int addr, int fmt)
2505 symbol *fields = SPEC_STRUCT(type)->fields;
2507 fprintf(stdout," { ");
2509 fprintf(stdout,"%s%s = ",(first ? "": ", "),fields->name);
2511 if (IS_AGGREGATE(fields->type)) {
2512 printValAggregates(fields,fields->type,space, addr, fmt);
2514 printValBasic(fields,fields->type,space,addr,getSize(fields->type), fmt);
2516 addr += getSize(fields->type);
2517 fields = fields->next;
2519 fprintf(stdout,"}");
2522 /*-----------------------------------------------------------------*/
2523 /* printValAggregates - print value of aggregates */
2524 /*-----------------------------------------------------------------*/
2525 static void printValAggregates (symbol *sym, link *type,
2526 char space,unsigned int addr, int fmt)
2529 if (IS_ARRAY(type)) {
2530 printArrayValue(sym, type, space, addr, fmt);
2534 if (IS_STRUCT(type)) {
2535 printStructValue(sym, type, space, addr, fmt);
2540 /*-----------------------------------------------------------------*/
2541 /* printOrSetSymValue - print or set value of a symbol */
2542 /*-----------------------------------------------------------------*/
2543 static void printOrSetSymValue (symbol *sym, context *cctxt,
2544 int flg, int dnum, int fmt, char *rs, char *val)
2546 static char fmtChar[] = " todx ";
2547 static int stack = 1;
2553 char save_ch, save_ch2;
2555 /* if it is on stack then compute address & fall thru */
2558 symbol *bp = symLookup("bp",cctxt);
2561 fprintf(stdout,"cannot determine stack frame\n");
2565 sym->addr = simGetValue(bp->addr,bp->addrspace,bp->size)
2569 /* get the value from the simulator and
2577 fprintf(stdout,"$%d = ",stack++);
2580 fprintf(stdout,"%d: ", dnum);
2581 if ( fmt != FMT_NON )
2582 fprintf(stdout,"/%c ",fmtChar[fmt]);
2583 fprintf(stdout,"%s%s = ",sym->name,rs);
2593 if ( *rs == '[' && IS_ARRAY(type))
2596 while ( *rs && *rs != ']' ) rs++ ;
2599 if ( ! isdigit(*s ))
2601 /* index seems a variable */
2602 for ( s2 = s; *s2 && ( isalnum( *s2 ) || *s2 == '_'); s2++ );
2606 fields = symLookup(s,cctxt);
2610 fprintf(stdout,"Unkown variable \"%s\" for index.\n", s);
2613 /* arrays & structures first */
2614 if (! IS_INTEGRAL(fields->type))
2616 fprintf(stdout,"Wrong type of variable \"%s\" for index \n", s);
2619 n = simGetValue(fields->addr,fields->addrspace,getSize(fields->type));
2625 if ( n < 0 || n >= DCL_ELEM(type))
2627 fprintf(stdout,"Wrong index %d.\n", n);
2631 size = getSize(type);
2635 else if ( *rs == '.' && IS_STRUCT(type))
2638 /* search structure element */
2639 for ( rs = s; *rs && ( isalnum( *rs ) || *rs == '_'); rs++ );
2643 for (fields = SPEC_STRUCT(type)->fields; fields; fields = fields->next)
2645 if (!(strcmp(s,fields->name)))
2651 fprintf(stdout,"Unknown field \"%s\" of structure\n", s);
2654 type = fields->type;
2655 size = getSize(type);
2656 addr += fields->offset;
2662 /* arrays & structures first */
2663 if (IS_AGGREGATE(type))
2666 fprintf(stdout,"Cannot set aggregate variable\n");
2668 printValAggregates(sym,type,sym->addrspace,addr,fmt);
2675 printValFunc(sym,fmt);
2680 setValBasic (sym,type,sym->addrspace,addr,size,val);
2682 printValBasic(sym,type,sym->addrspace,addr,size,fmt);
2684 if ( flg > 0 ) fprintf(stdout,"\n");
2688 /*-----------------------------------------------------------------*/
2689 /* printStructInfo - print out structure information */
2690 /*-----------------------------------------------------------------*/
2691 static void printStructInfo (structdef *sdef)
2693 symbol *field = sdef->fields ;
2698 field = field->next;
2701 fprintf(stdout,"%s %s {\n",(i ? "struct" : "union" ), sdef->tag);
2702 field = sdef->fields;
2704 printTypeInfo (field->type);
2705 fprintf(stdout," %s ;\n",field->name);
2706 field = field->next ;
2709 fprintf(stdout,"}\n");
2713 /*-----------------------------------------------------------------*/
2714 /* printTypeInfo - print out the type information */
2715 /*-----------------------------------------------------------------*/
2716 static void printTypeInfo(link *p)
2722 switch (DCL_TYPE(p)) {
2724 printTypeInfo (p->next);
2725 fprintf(stdout,"()");
2728 printTypeInfo (p->next);
2729 fprintf(stdout,"[%d]",DCL_ELEM(p));
2735 printTypeInfo (p->next);
2736 fprintf(stdout,"(_near *)");
2740 printTypeInfo (p->next);
2741 fprintf(stdout,"(_xdata *)");
2745 printTypeInfo( p->next);
2746 fprintf(stdout,"(_code *)");
2750 printTypeInfo( p->next);
2751 fprintf(stdout,"(_generic *)");
2755 switch (SPEC_NOUN(p)) { /* depending on the specifier type */
2757 (IS_LONG(p) ? fputs("long ",stdout) :
2758 ( IS_SHORT(p) ? fputs("short ",stdout) :
2759 fputs("int ",stdout))) ;
2762 fputs("float ",stdout);
2766 fputs ("char ",stdout);
2770 fputs("void ",stdout);
2774 printStructInfo (SPEC_STRUCT(p));
2778 fputs("sbit ",stdout);
2782 fprintf(stdout,": %d" ,SPEC_BLEN(p));
2788 /*-----------------------------------------------------------------*/
2789 /* cmdPrint - print value of variable */
2790 /*-----------------------------------------------------------------*/
2791 int cmdPrint (char *s, context *cctxt)
2796 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2801 printOrSetSymValue(sym,cctxt,1,0,fmt,rs,NULL);
2806 /*-----------------------------------------------------------------*/
2807 /* cmdOutput - print value of variable without number and newline */
2808 /*-----------------------------------------------------------------*/
2809 int cmdOutput (char *s, context *cctxt)
2814 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2819 printOrSetSymValue(sym,cctxt,0,0,fmt,rs,NULL);
2824 /** find display entry with this number */
2826 DEFSETFUNC(dsymWithNumber)
2828 dsymbol *dsym = item;
2830 V_ARG(dsymbol **,dsymp);
2832 if ( dsym->dnum == dnum )
2840 /*-----------------------------------------------------------------*/
2841 /* displayAll - display all valid variables */
2842 /*-----------------------------------------------------------------*/
2843 void displayAll(context *cctxt)
2849 for (dsym = setFirstItem(dispsymbols);
2851 dsym = setNextItem(dispsymbols))
2853 if ( (sym = symLookup(dsym->name,cctxt)))
2854 printOrSetSymValue(sym,cctxt,2,dsym->dnum,dsym->fmt,dsym->rs,NULL);
2858 /*-----------------------------------------------------------------*/
2859 /* cmdDisplay - display value of variable */
2860 /*-----------------------------------------------------------------*/
2861 int cmdDisplay (char *s, context *cctxt)
2863 static int dnum = 1;
2867 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
2875 dsymbol *dsym = (dsymbol *)Safe_calloc(1,sizeof(dsymbol));
2876 dsym->dnum = dnum++ ;
2877 dsym->name = sym->name;
2879 dsym->rs = gc_strdup(rs);
2880 addSetHead(&dispsymbols,dsym);
2885 /*-----------------------------------------------------------------*/
2886 /* cmdUnDisplay - undisplay value of variable */
2887 /*-----------------------------------------------------------------*/
2888 int cmdUnDisplay (char *s, context *cctxt)
2893 while (isspace(*s)) s++;
2896 for (dsym = setFirstItem(dispsymbols);
2898 dsym = setNextItem(dispsymbols))
2900 Safe_free(dsym->rs);
2903 deleteSet(&dispsymbols);
2908 dnum = strtol(s,&s,10);
2909 if (applyToSetFTrue(dispsymbols,dsymWithNumber,dnum,&dsym))
2911 deleteSetItem(&dispsymbols,dsym);
2912 Safe_free(dsym->rs);
2917 fprintf(stdout,"Arguments must be display numbers.\n");
2923 /*-----------------------------------------------------------------*/
2924 /* cmdPrintType - print type of a variable */
2925 /*-----------------------------------------------------------------*/
2926 int cmdPrintType (char *s, context *cctxt)
2929 char *bp = s+strlen(s) -1;
2931 while (isspace(*s)) s++;
2933 while (isspace(*bp)) bp--;
2937 if ((sym = symLookup(s,cctxt))) {
2938 printTypeInfo(sym->type);
2939 fprintf(stdout,"\n");
2942 "No symbol \"%s\" in current context.\n",
2948 /*-----------------------------------------------------------------*/
2949 /* cmdClrUserBp - clear user break point */
2950 /*-----------------------------------------------------------------*/
2951 int cmdClrUserBp (char *s, context *cctxt)
2954 function *func = NULL;
2956 /* clear break point location specification can be of the following
2958 a) <nothing> - break point at current location
2959 b) lineno - number of the current module
2960 c) filename:lineno - line number of the given file
2961 e) filename:function- function X in file Y (useful for static functions)
2962 f) function - function entry point
2966 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
2970 /* white space skip */
2971 while (*s && isspace(*s)) s++;
2973 /* null terminate it after stripping trailing blanks*/
2975 while (bp != s && isspace(*bp)) bp--;
2978 /* case a) nothing */
2979 /* if nothing given then current location : we know
2980 the current execution location from the currentContext */
2983 /* if current context is known */
2985 /* clear the break point @ current location */
2986 clearUSERbp (cctxt->addr);
2988 fprintf(stderr,"No default breakpoint address now.\n");
2993 /* case b) lineno */
2994 /* check if line number */
2996 /* get the lineno */
2999 /* if current context not present then we must get the module
3000 which has main & set the break point @ line number provided
3001 of that module : if current context known then set the bp
3002 at the line number given for the current module
3005 if (!cctxt->func->mod) {
3006 if (!applyToSet(functions,funcWithName,"main"))
3007 fprintf(stderr,"Function \"main\" not defined.\n");
3009 clearBPatModLine(func->mod,line);
3011 clearBPatModLine(cctxt->func->mod,line);
3017 if ((bp = strchr(s,':'))) {
3022 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
3023 fprintf (stderr,"No source file named %s.\n",s);
3027 /* case c) filename:lineno */
3028 if (isdigit(*(bp +1))) {
3030 clearBPatModLine (mod,atoi(bp+1));
3034 /* case d) filename:function */
3035 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
3036 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
3038 clearBPatModLine (mod,func->entryline);
3043 /* case e) function */
3044 if (!applyToSet(functions,funcWithName,s,&func))
3045 fprintf(stderr,"Function \"%s\" not defined.\n",s);
3047 clearBPatModLine(func->mod,func->entryline);
3053 /*-----------------------------------------------------------------*/
3054 /* cmdSimulator - send command to simulator */
3055 /*-----------------------------------------------------------------*/
3056 int cmdSimulator (char *s, context *cctxt)
3060 if (strlen(s) > 80) {
3061 printf("error 3A\n");
3065 strcat(tmpstr, "\n");
3067 waitForSim(200,NULL);
3068 fprintf(stdout,"%s",simResponse());
3072 void setMainContext()
3074 function *func = NULL;
3076 if (!applyToSet(functions,funcWithName,"main",&func) &&
3077 !applyToSet(functions,funcWithName,"_main",&func))
3080 discoverContext (func->sym->addr, func);
3083 static void printFrame()
3086 function *func = NULL;
3087 function *lastfunc = NULL;
3089 if ( currentFrame < 0 )
3092 fprintf(stdout,"Bottom (i.e., innermost) frame selected; you cannot go down.\n");
3095 STACK_STARTWALK(callStack) ;
3096 for ( i = 0; i <= currentFrame ; i++ )
3098 func = STACK_WALK(callStack);
3102 fprintf(stdout,"Initial frame selected; you cannot go up.\n");
3106 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",
3107 currentFrame,func->laddr,func->sym->name,func->mod->c_name,func->lline+1);
3108 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
3109 func->mod->cfullname,func->lline+1,func->laddr);
3111 discoverContext (func->laddr, func);
3115 /*-----------------------------------------------------------------*/
3116 /* cmdUp - Up command */
3117 /*-----------------------------------------------------------------*/
3118 int cmdUp(char *s, context *cctxt)
3120 while (isspace(*s)) s++;
3122 currentFrame += strtol(s,0,10);
3130 /*-----------------------------------------------------------------*/
3131 /* cmdDown - down command */
3132 /*-----------------------------------------------------------------*/
3133 int cmdDown(char *s, context *cctxt)
3135 while (isspace(*s)) s++;
3137 currentFrame -= strtol(s,0,10);
3144 /*-----------------------------------------------------------------*/
3145 /* cmdFrame - Frame command */
3146 /*-----------------------------------------------------------------*/
3147 int cmdFrame (char *s, context *cctxt)
3149 function *func = NULL;
3152 while (isspace(*s)) s++;
3154 currentFrame = strtol(s,0,10);
3159 /*-----------------------------------------------------------------*/
3160 /* cmdFinish - exec till end of current function */
3161 /*-----------------------------------------------------------------*/
3162 int cmdFinish (char *s, context *ctxt)
3164 if (STACK_EMPTY(callStack)) {
3165 fprintf(stdout,"The program is not running.\n");
3169 if (srcMode == SRC_CMODE) {
3170 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
3171 stepBpCB, ctxt->func->mod->c_name,
3172 ctxt->func->exitline);
3174 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
3175 stepBpCB, ctxt->func->mod->asm_name,
3176 ctxt->func->aexitline);
3186 /*-----------------------------------------------------------------*/
3187 /* cmdShow - show command */
3188 /*-----------------------------------------------------------------*/
3189 int cmdShow (char *s, context *cctxt)
3191 /* skip white space */
3192 while (*s && isspace(*s)) s++ ;
3194 if (strcmp(s,"copying") == 0) {
3195 fputs(copying,stdout);
3199 if (strcmp(s,"warranty") == 0) {
3200 fputs(warranty,stdout);