1 /*-------------------------------------------------------------------------
2 cmd.c - source file for debugger command execution
3 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding!
22 -------------------------------------------------------------------------*/
31 /* default number of lines to list out */
33 static int listlines = LISTLINES;
35 /* mainly used to retain a reference to the active module being
36 listed. May be used as a general context for other commands if
37 no better context is available */
38 static module *list_mod = NULL;
40 #if defined(__APPLE__) && defined(__MACH__)
42 {" GNU GENERAL PUBLIC LICENSE Version 2"};
43 static char *warranty=
47 " GNU GENERAL PUBLIC LICENSE\n"
48 " Version 2, June 1991\n"
50 " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n"
51 " 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\n"
52 " Everyone is permitted to copy and distribute verbatim copies\n"
53 " of this license document, but changing it is not allowed.\n"
57 " The licenses for most software are designed to take away your\n"
58 "freedom to share and change it. By contrast, the GNU General Public\n"
59 "License is intended to guarantee your freedom to share and change free\n"
60 "software--to make sure the software is free for all its users. This\n"
61 "General Public License applies to most of the Free Software\n"
62 "Foundation's software and to any other program whose authors commit to\n"
63 "using it. (Some other Free Software Foundation software is covered by\n"
64 "the GNU Library General Public License instead.) You can apply it to\n"
65 "your programs, too.\n"
67 " When we speak of free software, we are referring to freedom, not\n"
68 "price. Our General Public Licenses are designed to make sure that you\n"
69 "have the freedom to distribute copies of free software (and charge for\n"
70 "this service if you wish), that you receive source code or can get it\n"
71 "if you want it, that you can change the software or use pieces of it\n"
72 "in new free programs; and that you know you can do these things.\n"
74 " To protect your rights, we need to make restrictions that forbid\n"
75 "anyone to deny you these rights or to ask you to surrender the rights.\n"
76 "These restrictions translate to certain responsibilities for you if you\n"
77 "distribute copies of the software, or if you modify it.\n"
79 " For example, if you distribute copies of such a program, whether\n"
80 "gratis or for a fee, you must give the recipients all the rights that\n"
81 "you have. You must make sure that they, too, receive or can get the\n"
82 "source code. And you must show them these terms so they know their\n"
85 " We protect your rights with two steps: (1) copyright the software, and\n"
86 "(2) offer you this license which gives you legal permission to copy,\n"
87 "distribute and/or modify the software.\n"
89 " Also, for each author's protection and ours, we want to make certain\n"
90 "that everyone understands that there is no warranty for this free\n"
91 "software. If the software is modified by someone else and passed on, we\n"
92 "want its recipients to know that what they have is not the original, so\n"
93 "that any problems introduced by others will not reflect on the original\n"
94 "authors' reputations.\n"
96 " Finally, any free program is threatened constantly by software\n"
97 "patents. We wish to avoid the danger that redistributors of a free\n"
98 "program will individually obtain patent licenses, in effect making the\n"
99 "program proprietary. To prevent this, we have made it clear that any\n"
100 "patent must be licensed for everyone's free use or not licensed at all.\n"
102 " The precise terms and conditions for copying, distribution and\n"
103 "modification follow.\n"
105 " GNU GENERAL PUBLIC LICENSE\n"
106 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
108 " 0. This License applies to any program or other work which contains\n"
109 "a notice placed by the copyright holder saying it may be distributed\n"
110 "under the terms of this General Public License. The \"Program\", below,\n"
111 "refers to any such program or work, and a \"work based on the Program\"\n"
112 "means either the Program or any derivative work under copyright law:\n"
113 "that is to say, a work containing the Program or a portion of it,\n"
114 "either verbatim or with modifications and/or translated into another\n"
115 "language. (Hereinafter, translation is included without limitation in\n"
116 "the term \"modification\".) Each licensee is addressed as \"you\".\n"
118 "Activities other than copying, distribution and modification are not\n"
119 "covered by this License; they are outside its scope. The act of\n"
120 "running the Program is not restricted, and the output from the Program\n"
121 "is covered only if its contents constitute a work based on the\n"
122 "Program (independent of having been made by running the Program).\n"
123 "Whether that is true depends on what the Program does.\n"
125 " 1. You may copy and distribute verbatim copies of the Program's\n"
126 "source code as you receive it, in any medium, provided that you\n"
127 "conspicuously and appropriately publish on each copy an appropriate\n"
128 "copyright notice and disclaimer of warranty; keep intact all the\n"
129 "notices that refer to this License and to the absence of any warranty;\n"
130 "and give any other recipients of the Program a copy of this License\n"
131 "along with the Program.\n"
133 "You may charge a fee for the physical act of transferring a copy, and\n"
134 "you may at your option offer warranty protection in exchange for a fee.\n"
136 " 2. You may modify your copy or copies of the Program or any portion\n"
137 "of it, thus forming a work based on the Program, and copy and\n"
138 "distribute such modifications or work under the terms of Section 1\n"
139 "above, provided that you also meet all of these conditions:\n"
141 " a) You must cause the modified files to carry prominent notices\n"
142 " stating that you changed the files and the date of any change.\n"
144 " b) You must cause any work that you distribute or publish, that in\n"
145 " whole or in part contains or is derived from the Program or any\n"
146 " part thereof, to be licensed as a whole at no charge to all third\n"
147 " parties under the terms of this License.\n"
149 " c) If the modified program normally reads commands interactively\n"
150 " when run, you must cause it, when started running for such\n"
151 " interactive use in the most ordinary way, to print or display an\n"
152 " announcement including an appropriate copyright notice and a\n"
153 " notice that there is no warranty (or else, saying that you provide\n"
154 " a warranty) and that users may redistribute the program under\n"
155 " these conditions, and telling the user how to view a copy of this\n"
156 " License. (Exception: if the Program itself is interactive but\n"
157 " does not normally print such an announcement, your work based on\n"
158 " the Program is not required to print an announcement.)\n"
160 "These requirements apply to the modified work as a whole. If\n"
161 "identifiable sections of that work are not derived from the Program,\n"
162 "and can be reasonably considered independent and separate works in\n"
163 "themselves, then this License, and its terms, do not apply to those\n"
164 "sections when you distribute them as separate works. But when you\n"
165 "distribute the same sections as part of a whole which is a work based\n"
166 "on the Program, the distribution of the whole must be on the terms of\n"
167 "this License, whose permissions for other licensees extend to the\n"
168 "entire whole, and thus to each and every part regardless of who wrote it.\n"
170 "Thus, it is not the intent of this section to claim rights or contest\n"
171 "your rights to work written entirely by you; rather, the intent is to\n"
172 "exercise the right to control the distribution of derivative or\n"
173 "collective works based on the Program.\n"
175 "In addition, mere aggregation of another work not based on the Program\n"
176 "with the Program (or with a work based on the Program) on a volume of\n"
177 "a storage or distribution medium does not bring the other work under\n"
178 "the scope of this License.\n"
180 " 3. You may copy and distribute the Program (or a work based on it,\n"
181 "under Section 2) in object code or executable form under the terms of\n"
182 "Sections 1 and 2 above provided that you also do one of the following:\n"
184 " a) Accompany it with the complete corresponding machine-readable\n"
185 " source code, which must be distributed under the terms of Sections\n"
186 " 1 and 2 above on a medium customarily used for software interchange; or,\n"
188 " b) Accompany it with a written offer, valid for at least three\n"
189 " years, to give any third party, for a charge no more than your\n"
190 " cost of physically performing source distribution, a complete\n"
191 " machine-readable copy of the corresponding source code, to be\n"
192 " distributed under the terms of Sections 1 and 2 above on a medium\n"
193 " customarily used for software interchange; or,\n"
195 " c) Accompany it with the information you received as to the offer\n"
196 " to distribute corresponding source code. (This alternative is\n"
197 " allowed only for noncommercial distribution and only if you\n"
198 " received the program in object code or executable form with such\n"
199 " an offer, in accord with Subsection b above.)\n"
201 "The source code for a work means the preferred form of the work for\n"
202 "making modifications to it. For an executable work, complete source\n"
203 "code means all the source code for all modules it contains, plus any\n"
204 "associated interface definition files, plus the scripts used to\n"
205 "control compilation and installation of the executable. However, as a\n"
206 "special exception, the source code distributed need not include\n"
207 "anything that is normally distributed (in either source or binary\n"
208 "form) with the major components (compiler, kernel, and so on) of the\n"
209 "operating system on which the executable runs, unless that component\n"
210 "itself accompanies the executable.\n"
212 "If distribution of executable or object code is made by offering\n"
213 "access to copy from a designated place, then offering equivalent\n"
214 "access to copy the source code from the same place counts as\n"
215 "distribution of the source code, even though third parties are not\n"
216 "compelled to copy the source along with the object code.\n"
218 " 4. You may not copy, modify, sublicense, or distribute the Program\n"
219 "except as expressly provided under this License. Any attempt\n"
220 "otherwise to copy, modify, sublicense or distribute the Program is\n"
221 "void, and will automatically terminate your rights under this License.\n"
222 "However, parties who have received copies, or rights, from you under\n"
223 "this License will not have their licenses terminated so long as such\n"
224 "parties remain in full compliance.\n"
226 " 5. You are not required to accept this License, since you have not\n"
227 "signed it. However, nothing else grants you permission to modify or\n"
228 "distribute the Program or its derivative works. These actions are\n"
229 "prohibited by law if you do not accept this License. Therefore, by\n"
230 "modifying or distributing the Program (or any work based on the\n"
231 "Program), you indicate your acceptance of this License to do so, and\n"
232 "all its terms and conditions for copying, distributing or modifying\n"
233 "the Program or works based on it.\n"
235 " 6. Each time you redistribute the Program (or any work based on the\n"
236 "Program), the recipient automatically receives a license from the\n"
237 "original licensor to copy, distribute or modify the Program subject to\n"
238 "these terms and conditions. You may not impose any further\n"
239 "restrictions on the recipients' exercise of the rights granted herein.\n"
240 "You are not responsible for enforcing compliance by third parties to\n"
243 " 7. If, as a consequence of a court judgment or allegation of patent\n"
244 "infringement or for any other reason (not limited to patent issues),\n"
245 "conditions are imposed on you (whether by court order, agreement or\n"
246 "otherwise) that contradict the conditions of this License, they do not\n"
247 "excuse you from the conditions of this License. If you cannot\n"
248 "distribute so as to satisfy simultaneously your obligations under this\n"
249 "License and any other pertinent obligations, then as a consequence you\n"
250 "may not distribute the Program at all. For example, if a patent\n"
251 "license would not permit royalty-free redistribution of the Program by\n"
252 "all those who receive copies directly or indirectly through you, then\n"
253 "the only way you could satisfy both it and this License would be to\n"
254 "refrain entirely from distribution of the Program.\n"
256 "If any portion of this section is held invalid or unenforceable under\n"
257 "any particular circumstance, the balance of the section is intended to\n"
258 "apply and the section as a whole is intended to apply in other\n"
261 "It is not the purpose of this section to induce you to infringe any\n"
262 "patents or other property right claims or to contest validity of any\n"
263 "such claims; this section has the sole purpose of protecting the\n"
264 "integrity of the free software distribution system, which is\n"
265 "implemented by public license practices. Many people have made\n"
266 "generous contributions to the wide range of software distributed\n"
267 "through that system in reliance on consistent application of that\n"
268 "system; it is up to the author/donor to decide if he or she is willing\n"
269 "to distribute software through any other system and a licensee cannot\n"
270 "impose that choice.\n"
272 "This section is intended to make thoroughly clear what is believed to\n"
273 "be a consequence of the rest of this License.\n"
275 " 8. If the distribution and/or use of the Program is restricted in\n"
276 "certain countries either by patents or by copyrighted interfaces, the\n"
277 "original copyright holder who places the Program under this License\n"
278 "may add an explicit geographical distribution limitation excluding\n"
279 "those countries, so that distribution is permitted only in or among\n"
280 "countries not thus excluded. In such case, this License incorporates\n"
281 "the limitation as if written in the body of this License.\n"
283 " 9. The Free Software Foundation may publish revised and/or new versions\n"
284 "of the General Public License from time to time. Such new versions will\n"
285 "be similar in spirit to the present version, but may differ in detail to\n"
286 "address new problems or concerns.\n"
288 "Each version is given a distinguishing version number. If the Program\n"
289 "specifies a version number of this License which applies to it and \"any\n"
290 "later version\", you have the option of following the terms and conditions\n"
291 "either of that version or of any later version published by the Free\n"
292 "Software Foundation. If the Program does not specify a version number of\n"
293 "this License, you may choose any version ever published by the Free Software\n"
296 " 10. If you wish to incorporate parts of the Program into other free\n"
297 "programs whose distribution conditions are different, write to the author\n"
298 "to ask for permission. For software which is copyrighted by the Free\n"
299 "Software Foundation, write to the Free Software Foundation; we sometimes\n"
300 "make exceptions for this. Our decision will be guided by the two goals\n"
301 "of preserving the free status of all derivatives of our free software and\n"
302 "of promoting the sharing and reuse of software generally.\n";
304 static char *warranty=
307 " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
308 "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"
309 "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
310 "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
311 "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
312 "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"
313 "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"
314 "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
315 "REPAIR OR CORRECTION.\n"
317 " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
318 "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
319 "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
320 "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
321 "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
322 "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
323 "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
324 "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
325 "POSSIBILITY OF SUCH DAMAGES.\n";
328 static void printTypeInfo(link *);
329 static void printValAggregates (symbol *,link *,char,unsigned int,int,int);
330 static int printOrSetSymValue (symbol *sym, context *cctxt,
331 int flg, int dnum, int fmt,
332 char *rs, char *val, char cmp);
334 int srcMode = SRC_CMODE ;
335 set *dispsymbols = NULL ; /* set of displayable symbols */
336 static int currentFrame = 0; /* actual displayed frame */
337 /*-----------------------------------------------------------------*/
338 /* funcWithName - returns function with name */
339 /*-----------------------------------------------------------------*/
340 DEFSETFUNC(funcWithName)
342 function *func = item;
344 V_ARG(function **,funcp);
349 if (strcmp(func->sym->name,name) == 0) {
357 /*-----------------------------------------------------------------*/
358 /* symWithAddr - look for symbol with sfr / sbit address */
359 /*-----------------------------------------------------------------*/
360 DEFSETFUNC(symWithAddr)
363 V_ARG(unsigned long,laddr);
364 V_ARG(int ,laddrspace);
365 V_ARG(symbol **,rsym);
370 if ( sym->addr == laddr &&
371 sym->addrspace == laddrspace )
380 /*-----------------------------------------------------------------*/
381 /* setBPatModLine - set break point at the line specified for the */
382 /*-----------------------------------------------------------------*/
383 static void setBPatModLine (module *mod, int line, char bpType )
387 /* look for the first executable line after the line
388 specified & get the break point there */
393 if (srcMode == SRC_CMODE && line > mod->ncLines) {
394 fprintf(stderr,"No line %d in file \"%s\".\n",
399 if (srcMode == SRC_AMODE && line > mod->nasmLines) {
400 fprintf(stderr,"No line %d in file \"%s\".\n",
406 for ( ; next_line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
408 if (srcMode == SRC_CMODE) {
409 if (mod->cLines[next_line]->addr != INT_MAX) {
410 setBreakPoint (mod->cLines[next_line]->addr, CODE, bpType,
411 userBpCB, mod->c_name, next_line);
417 if (mod->asmLines[next_line]->addr != INT_MAX) {
418 setBreakPoint (mod->asmLines[next_line]->addr, CODE, bpType,
419 userBpCB, mod->asm_name, next_line);
426 fprintf(stderr,"No line %d or after in file \"%s\"..\n",
432 /*-----------------------------------------------------------------*/
433 /* clearBPatModLine - clr break point at the line specified */
434 /*-----------------------------------------------------------------*/
435 static void clearBPatModLine (module *mod, int line)
437 /* look for the first executable line after the line
438 specified & get the break point there */
439 if (srcMode == SRC_CMODE && line > mod->ncLines) {
440 fprintf(stderr,"No line %d in file \"%s\".\n",
445 if (srcMode == SRC_AMODE && line > mod->ncLines) {
446 fprintf(stderr,"No line %d in file \"%s\".\n",
451 for ( ; line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
453 if (srcMode == SRC_CMODE)
454 if (mod->cLines[line]->addr) {
455 clearUSERbp (mod->cLines[line]->addr);
459 if (mod->asmLines[line]->addr) {
460 clearUSERbp (mod->asmLines[line]->addr);
468 /*-----------------------------------------------------------------*/
469 /* moduleLineWithAddr - finds and returns a line with a given address */
470 /*-----------------------------------------------------------------*/
471 DEFSETFUNC(moduleLineWithAddr)
476 V_ARG(unsigned int,addr);
477 V_ARG(module **,rmod);
483 for (i=0; i < mod->nasmLines; i++ )
485 if ( mod->asmLines[i]->addr == addr)
491 for ( i=0; i < mod->ncLines; i++ )
493 if ( mod->cLines[i]->addr > addr)
505 /*-----------------------------------------------------------------*/
506 /* funcWithNameModule - returns functions with a name module combo */
507 /*-----------------------------------------------------------------*/
508 DEFSETFUNC(funcWithNameModule)
510 function *func = item;
513 V_ARG(function **,funcp);
518 if (strcmp(func->sym->name,fname) == 0 &&
519 strcmp(func->mod->c_name,mname) == 0) {
527 /*-----------------------------------------------------------------*/
528 /* funcInAddr - given an address returns the function */
529 /*-----------------------------------------------------------------*/
530 DEFSETFUNC(funcInAddr)
532 function *func = item;
533 V_ARG(unsigned int,addr);
534 V_ARG(function **,funcp);
539 /* in the address range */
540 if (func->sym->addr <= addr &&
541 func->sym->eaddr >= addr) {
550 /*-----------------------------------------------------------------*/
551 /* setStepBp - will set STEP Bp @ function entry points */
552 /*-----------------------------------------------------------------*/
553 DEFSETFUNC(setStepBp)
555 function *func = item;
557 if (func->sym && func->sym->addr ) {
559 /* set the entry break point */
560 setBreakPoint (func->sym->addr , CODE , STEP ,
561 stepBpCB ,func->mod->c_name , func->entryline);
569 /*-----------------------------------------------------------------*/
570 /* setStepEPBp - sets a given type of bp @ the execution point */
571 /*-----------------------------------------------------------------*/
572 DEFSETFUNC(setStepEPBp)
578 setBreakPoint (ep->addr, CODE, bptype,
579 stepBpCB, mname, ep->line);
583 /*-----------------------------------------------------------------*/
584 /* setNextEPBp - sets a given type of bp @ the execution point */
585 /*-----------------------------------------------------------------*/
586 DEFSETFUNC(setNextEPBp)
592 setBreakPoint (ep->addr, CODE, bptype,
593 nextBpCB, mname, ep->line);
597 /*-----------------------------------------------------------------*/
598 /* lineAtAddr - for execution points returns the one with addr */
599 /*-----------------------------------------------------------------*/
600 DEFSETFUNC(lineAtAddr)
603 V_ARG(unsigned int,addr);
608 /* address must be an exact match */
609 if (ep->addr == addr) {
622 /*-----------------------------------------------------------------*/
623 /* lineNearAddr - for execution points returns the one with addr */
624 /*-----------------------------------------------------------------*/
625 DEFSETFUNC(lineNearAddr)
628 V_ARG(unsigned int,addr);
633 /* the line in which the address is */
634 if (ep->addr <= addr) {
647 /*-----------------------------------------------------------------*/
648 /* discoverContext - find out the current context of the bp */
649 /*-----------------------------------------------------------------*/
650 context *discoverContext (unsigned addr, function *func, context *ctxt)
655 /* find the function we are in */
656 if (!func && !applyToSet(functions,funcInAddr,addr,&func)) {
657 if (!applyToSet(functions,funcWithName,"_main",&func) ||
658 !applyToSet(modules,moduleLineWithAddr,addr,&mod,NULL))
660 fprintf(stderr, "addr 0x%x in no module/function (runtime env?)\n",addr);
665 ctxt->modName = mod->name;
666 ctxt->cline = func->exitline;
671 ctxt->addr = func->laddr = addr;
672 ctxt->modName = func->modName;
674 /* find the c line number */
675 if(applyToSet(func->cfpoints,lineAtAddr,addr,
676 &line,&ctxt->block,&ctxt->level))
677 ctxt->cline = func->lline = line;
678 else if(applyToSet(func->cfpoints,lineNearAddr,addr,
679 &line,&ctxt->block,&ctxt->level))
680 ctxt->cline = func->lline = line;
684 /* find the asm line number */
686 if (applyToSet(func->afpoints,lineAtAddr,addr,
688 ctxt->asmline = line;
707 static struct instruction instructions[] = {
708 [0x28] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
709 [0x29] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
710 [0x2A] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
711 [0x2B] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
712 [0x2C] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
713 [0x2D] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
714 [0x2E] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
715 [0x2F] = { .flags = 0, .len = 1 }, /* ADD A,Rn */
716 [0x25] = { .flags = 0, .len = 2 }, /* ADD A,direct */
717 [0x26] = { .flags = 0, .len = 1 }, /* ADD A,@Ri */
718 [0x27] = { .flags = 0, .len = 1 }, /* ADD A,@Ri */
719 [0x24] = { .flags = 0, .len = 2 }, /* ADD A,#data */
721 [0x38] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
722 [0x39] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
723 [0x3A] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
724 [0x3B] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
725 [0x3C] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
726 [0x3D] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
727 [0x3E] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
728 [0x3F] = { .flags = 0, .len = 1 }, /* ADDC A,Rn */
729 [0x35] = { .flags = 0, .len = 2 }, /* ADDC A,direct */
730 [0x36] = { .flags = 0, .len = 1 }, /* ADDC A,@Ri */
731 [0x37] = { .flags = 0, .len = 1 }, /* ADDC A,@Ri */
732 [0x34] = { .flags = 0, .len = 2 }, /* ADDC A,#data */
734 [0x98] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
735 [0x99] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
736 [0x9A] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
737 [0x9B] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
738 [0x9C] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
739 [0x9D] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
740 [0x9E] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
741 [0x9F] = { .flags = 0, .len = 1 }, /* SUBB A,Rn */
742 [0x95] = { .flags = 0, .len = 2 }, /* SUBB A,direct */
743 [0x96] = { .flags = 0, .len = 1 }, /* SUBB A,@Ri */
744 [0x97] = { .flags = 0, .len = 1 }, /* SUBB A,@Ri */
745 [0x94] = { .flags = 0, .len = 2 }, /* SUBB A,#data */
747 [0x08] = { .flags = 0, .len = 1 }, /* INC Rn */
748 [0x09] = { .flags = 0, .len = 1 }, /* INC Rn */
749 [0x0A] = { .flags = 0, .len = 1 }, /* INC Rn */
750 [0x0B] = { .flags = 0, .len = 1 }, /* INC Rn */
751 [0x0C] = { .flags = 0, .len = 1 }, /* INC Rn */
752 [0x0D] = { .flags = 0, .len = 1 }, /* INC Rn */
753 [0x0E] = { .flags = 0, .len = 1 }, /* INC Rn */
754 [0x0F] = { .flags = 0, .len = 1 }, /* INC Rn */
755 [0x05] = { .flags = 0, .len = 2 }, /* INC direct */
756 [0x06] = { .flags = 0, .len = 1 }, /* INC @Ri */
757 [0x07] = { .flags = 0, .len = 1 }, /* INC @Ri */
758 [0x04] = { .flags = 0, .len = 1 }, /* INC A */
760 [0xA3] = { .flags = 0, .len = 1 }, /* INC DPTR */
762 [0x18] = { .flags = 0, .len = 1 }, /* DEC Rn */
763 [0x19] = { .flags = 0, .len = 1 }, /* DEC Rn */
764 [0x1A] = { .flags = 0, .len = 1 }, /* DEC Rn */
765 [0x1B] = { .flags = 0, .len = 1 }, /* DEC Rn */
766 [0x1C] = { .flags = 0, .len = 1 }, /* DEC Rn */
767 [0x1D] = { .flags = 0, .len = 1 }, /* DEC Rn */
768 [0x1E] = { .flags = 0, .len = 1 }, /* DEC Rn */
769 [0x1F] = { .flags = 0, .len = 1 }, /* DEC Rn */
770 [0x15] = { .flags = 0, .len = 2 }, /* DEC direct */
771 [0x16] = { .flags = 0, .len = 1 }, /* DEC @Ri */
772 [0x17] = { .flags = 0, .len = 1 }, /* DEC @Ri */
773 [0x14] = { .flags = 0, .len = 1 }, /* DEC A */
775 [0xA4] = { .flags = 0, .len = 1 }, /* MUL AB */
776 [0x84] = { .flags = 0, .len = 1 }, /* DIV AB */
778 [0xD4] = { .flags = 0, .len = 1 }, /* DA A */
780 [0x58] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
781 [0x59] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
782 [0x5A] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
783 [0x5B] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
784 [0x5C] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
785 [0x5D] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
786 [0x5E] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
787 [0x5F] = { .flags = 0, .len = 1 }, /* ANL A,Rn */
788 [0x55] = { .flags = 0, .len = 2 }, /* ANL A,direct */
789 [0x56] = { .flags = 0, .len = 1 }, /* ANL A,@Ri */
790 [0x57] = { .flags = 0, .len = 1 }, /* ANL A,@Ri */
791 [0x54] = { .flags = 0, .len = 2 }, /* ANL A,#data */
792 [0x52] = { .flags = 0, .len = 2 }, /* ANL direct,A */
793 [0x53] = { .flags = 0, .len = 3 }, /* ANL direct,#data */
795 [0x48] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
796 [0x49] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
797 [0x4A] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
798 [0x4B] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
799 [0x4C] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
800 [0x4D] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
801 [0x4E] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
802 [0x4F] = { .flags = 0, .len = 1 }, /* ORL A,Rn */
803 [0x45] = { .flags = 0, .len = 2 }, /* ORL A,direct */
804 [0x46] = { .flags = 0, .len = 1 }, /* ORL A,@Ri */
805 [0x47] = { .flags = 0, .len = 1 }, /* ORL A,@Ri */
806 [0x44] = { .flags = 0, .len = 2 }, /* ORL A,#data */
807 [0x42] = { .flags = 0, .len = 2 }, /* ORL direct,A */
808 [0x43] = { .flags = 0, .len = 3 }, /* ORL direct,#data */
810 [0x68] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
811 [0x69] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
812 [0x6A] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
813 [0x6B] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
814 [0x6C] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
815 [0x6D] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
816 [0x6E] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
817 [0x6F] = { .flags = 0, .len = 1 }, /* XRL A,Rn */
818 [0x65] = { .flags = 0, .len = 2 }, /* XRL A,direct */
819 [0x66] = { .flags = 0, .len = 1 }, /* XRL A,@Ri */
820 [0x67] = { .flags = 0, .len = 1 }, /* XRL A,@Ri */
821 [0x64] = { .flags = 0, .len = 2 }, /* XRL A,#data */
822 [0x62] = { .flags = 0, .len = 2 }, /* XRL direct,A */
823 [0x63] = { .flags = 0, .len = 3 }, /* XRL direct,#data */
825 [0xE4] = { .flags = 0, .len = 1 }, /* CLR A */
826 [0xF4] = { .flags = 0, .len = 1 }, /* CPL A */
828 [0x23] = { .flags = 0, .len = 1 }, /* RL A */
829 [0x33] = { .flags = 0, .len = 1 }, /* RLC A */
830 [0x03] = { .flags = 0, .len = 1 }, /* RR A */
831 [0x13] = { .flags = 0, .len = 1 }, /* RRC A */
833 [0xC4] = { .flags = 0, .len = 1 }, /* SWAP A */
835 [0xE8] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
836 [0xE9] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
837 [0xEA] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
838 [0xEB] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
839 [0xEC] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
840 [0xED] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
841 [0xEE] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
842 [0xEF] = { .flags = 0, .len = 1 }, /* MOV A,Rn */
843 [0xE5] = { .flags = 0, .len = 2 }, /* MOV A,direct */
844 [0xE6] = { .flags = 0, .len = 1 }, /* MOV A,@Ri */
845 [0xE7] = { .flags = 0, .len = 1 }, /* MOV A,@Ri */
846 [0x74] = { .flags = 0, .len = 2 }, /* MOV A,#data */
848 [0xF8] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
849 [0xF9] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
850 [0xFA] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
851 [0xFB] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
852 [0xFC] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
853 [0xFD] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
854 [0xFE] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
855 [0xFF] = { .flags = 0, .len = 1 }, /* MOV Rn,A */
857 [0xA8] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
858 [0xA9] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
859 [0xAA] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
860 [0xAB] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
861 [0xAC] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
862 [0xAD] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
863 [0xAE] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
864 [0xAF] = { .flags = 0, .len = 2 }, /* MOV Rn,direct */
866 [0x78] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
867 [0x79] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
868 [0x7A] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
869 [0x7B] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
870 [0x7C] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
871 [0x7D] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
872 [0x7E] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
873 [0x7F] = { .flags = 0, .len = 2 }, /* MOV Rn,#data */
875 [0xF5] = { .flags = 0, .len = 2 }, /* MOV direct,A */
876 [0x88] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
877 [0x89] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
878 [0x8A] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
879 [0x8B] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
880 [0x8C] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
881 [0x8D] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
882 [0x8E] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
883 [0x8F] = { .flags = 0, .len = 2 }, /* MOV direct,Rn */
884 [0x85] = { .flags = 0, .len = 3 }, /* MOV direct,direct */
885 [0x86] = { .flags = 0, .len = 2 }, /* MOV direct,@Ri */
886 [0x87] = { .flags = 0, .len = 2 }, /* MOV direct,@Ri */
887 [0x75] = { .flags = 0, .len = 3 }, /* MOV direct,#data */
889 [0xF6] = { .flags = 0, .len = 1 }, /* MOV @Ri,A */
890 [0xF7] = { .flags = 0, .len = 1 }, /* MOV @Ri,A */
891 [0xA6] = { .flags = 0, .len = 2 }, /* MOV @Ri,direct */
892 [0xA7] = { .flags = 0, .len = 2 }, /* MOV @Ri,direct */
893 [0x76] = { .flags = 0, .len = 2 }, /* MOV @Ri,#data */
894 [0x77] = { .flags = 0, .len = 2 }, /* MOV @Ri,#data */
897 [0x90] = { .flags = 0, .len = 3 }, /* MOV DPTR,#data16 */
899 [0x93] = { .flags = 0, .len = 1 }, /* MOVC A,@A+DPTR */
900 [0x83] = { .flags = 0, .len = 1 }, /* MOVC A,@A+PC */
902 [0xE2] = { .flags = 0, .len = 1 }, /* MOVX A,@Ri */
903 [0xE3] = { .flags = 0, .len = 1 }, /* MOVX A,@Ri */
904 [0xE0] = { .flags = 0, .len = 1 }, /* MOVX A,@DPTR */
905 [0xF2] = { .flags = 0, .len = 1 }, /* MOVX @Ri,A */
906 [0xF3] = { .flags = 0, .len = 1 }, /* MOVX @Ri,A */
907 [0xF0] = { .flags = 0, .len = 1 }, /* MOVX @DPTR,A */
909 [0xC0] = { .flags = 0, .len = 2 }, /* PUSH direct */
910 [0xD0] = { .flags = 0, .len = 2 }, /* POP direct */
911 [0xF5] = { .flags = 0, .len = 2 }, /* MOV direct,A */
912 [0xF5] = { .flags = 0, .len = 2 }, /* MOV direct,A */
913 [0xF5] = { .flags = 0, .len = 2 }, /* MOV direct,A */
914 [0xF5] = { .flags = 0, .len = 2 }, /* MOV direct,A */
916 [0xC8] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
917 [0xC9] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
918 [0xCA] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
919 [0xCB] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
920 [0xCC] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
921 [0xCD] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
922 [0xCE] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
923 [0xCF] = { .flags = 0, .len = 1 }, /* XCH A,Rn */
924 [0xC5] = { .flags = 0, .len = 2 }, /* XCH A,direct */
925 [0xC6] = { .flags = 0, .len = 1 }, /* XCH A,@Ri */
926 [0xC7] = { .flags = 0, .len = 1 }, /* XCH A,@Ri */
927 [0xD6] = { .flags = 0, .len = 1 }, /* XCHD A,@Ri */
928 [0xD7] = { .flags = 0, .len = 1 }, /* XCHD A,@Ri */
930 [0x11] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
931 [0x31] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
932 [0x51] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
933 [0x71] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
934 [0x91] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
935 [0xb1] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
936 [0xd1] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
937 [0xf1] = { .flags = IS_CALL, .len = 2 }, /* ACALL addr11 */
938 [0x12] = { .flags = IS_CALL, .len = 3 }, /* LCALL addr16 */
940 [0x22] = { .flags = IS_RET, .len = 1 }, /* RET */
941 [0x32] = { .flags = IS_RET, .len = 1 }, /* RETI */
943 [0x01] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
944 [0x21] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
945 [0x41] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
946 [0x61] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
947 [0x81] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
948 [0xa1] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
949 [0xc1] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
950 [0xe1] = { .flags = IS_BRANCH, .len = 2 }, /* AJMP addr11 */
951 [0x02] = { .flags = IS_BRANCH, .len = 3 }, /* LJMP addr16 */
953 [0x80] = { .flags = IS_BRANCH, .len = 2 }, /* SJMP rel */
955 [0x73] = { .flags = IS_BRANCH, .len = 1 }, /* JMP @A+DPTR */
957 [0x60] = { .flags = IS_BRANCH, .len = 2 }, /* JZ rel */
958 [0x70] = { .flags = IS_BRANCH, .len = 2 }, /* JNZ rel */
959 [0x40] = { .flags = IS_BRANCH, .len = 2 }, /* JC rel */
960 [0x50] = { .flags = IS_BRANCH, .len = 2 }, /* JNC rel */
961 [0x20] = { .flags = IS_BRANCH, .len = 3 }, /* JB bit,rel */
962 [0x30] = { .flags = IS_BRANCH, .len = 3 }, /* JNB bit,rel */
963 [0x10] = { .flags = IS_BRANCH, .len = 3 }, /* JBC bit,direct rel */
965 [0xB5] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE A,direct rel */
966 [0xB4] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE A,#data rel */
967 [0xB8] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
968 [0xB9] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
969 [0xBA] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
970 [0xBB] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
971 [0xBC] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
972 [0xBD] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
973 [0xBE] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
974 [0xBF] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE Rn,#data rel */
975 [0xB6] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE @Ri,direct rel */
976 [0xB7] = { .flags = IS_BRANCH, .len = 3 }, /* CJNE @Ri,direct rel */
978 [0xD8] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
979 [0xD9] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
980 [0xDA] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
981 [0xDB] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
982 [0xDC] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
983 [0xDD] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
984 [0xDE] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
985 [0xDF] = { .flags = IS_BRANCH, .len = 2 }, /* DNJZ Rn,rel */
986 [0xD5] = { .flags = IS_BRANCH, .len = 3 }, /* DNJZ direct,rel */
988 [0x00] = { .flags = 0, .len = 1 }, /* NOP */
990 [0xC3] = { .flags = 0, .len = 1 }, /* CLR C */
991 [0xC2] = { .flags = 0, .len = 2 }, /* CLR bit */
992 [0xD3] = { .flags = 0, .len = 1 }, /* SETB C */
993 [0xD2] = { .flags = 0, .len = 2 }, /* SETB bit */
995 [0xB3] = { .flags = 0, .len = 1 }, /* CPL C */
996 [0xB2] = { .flags = 0, .len = 2 }, /* CPL bit */
998 [0x82] = { .flags = 0, .len = 2 }, /* ANL C,bit */
999 [0xB0] = { .flags = 0, .len = 2 }, /* ANL C,/bit */
1000 [0x72] = { .flags = 0, .len = 2 }, /* ORL C,bit */
1001 [0xA0] = { .flags = 0, .len = 2 }, /* ORL C,/bit */
1003 [0xA2] = { .flags = 0, .len = 2 }, /* MOV C,bit */
1004 [0x92] = { .flags = 0, .len = 2 }, /* MOV bit,C */
1006 [0xA5] = { .flags = 0, .len = 1 }, /* TRAP */
1014 #define MOV_direct_A 0xF5
1015 #define MOV_A_direct 0xE5
1016 #define ADD_A_imm 0x24
1020 #define LJMP_addr16 0x02
1021 #define SJMP_rel 0x80
1023 static int stack_change(unsigned addr)
1026 unsigned char direct;
1028 insn = simGetValue(addr, 'C', 1);
1035 direct = simGetValue(addr+1, 'C', 1);
1037 unsigned char add_insn;
1038 unsigned char add_direct;
1040 add_insn = simGetValue(addr-2, 'C', 1);
1041 if (add_insn == ADD_A_imm) {
1042 add_direct = simGetValue(addr-1, 'C', 1);
1043 return (signed char) add_direct;
1056 static int pc_change(unsigned addr, unsigned addrs[2])
1063 insn = simGetValue(addr, 'C', 1);
1064 if (instructions[insn].flags & IS_RET)
1067 if (!(instructions[insn].flags & IS_BRANCH)) {
1068 addrs[0] = addr + instructions[insn].len;
1072 if (insn == LJMP_addr16) {
1073 addrs[0] = ((simGetValue(addr+1, 'C', 1) << 8) |
1074 (simGetValue(addr+2, 'C', 1)));
1079 if ((insn & 0x1f) == 0x01) {
1080 unsigned char direct = simGetValue(addr+1,'C', 1);
1082 addrs[0] = ((addr + 2) & 0xf800) | ((insn & 0xe0) << 3) | direct;
1086 /* otherwise, relative branch */
1087 len = instructions[insn].len;
1089 delta = (signed char) simGetValue(addr+len-1, 'C', 1);
1090 new_addr = (addr + len) + delta;
1092 if (insn == SJMP_rel) {
1093 addrs[0] = new_addr;
1097 addrs[0] = addr + len;
1098 addrs[1] = new_addr;
1102 #define SEARCH_FAILED 0x8000
1105 stack_depth(unsigned pc, int search)
1108 unsigned max_pc = pc;
1115 change += stack_change(pc);
1116 n = pc_change(pc, new_pc);
1122 /* detect infinite loop */
1130 return SEARCH_FAILED;
1132 for (s = 0; s < search - 1; s++) {
1136 for (i = 0; i < n; i++) {
1137 d = stack_depth(new_pc[i], search-1);
1138 if (d != SEARCH_FAILED)
1142 return SEARCH_FAILED;
1148 symbol *start_stack = symLookup("__start_stack", NULL);
1150 return start_stack->addr;
1155 frameStart(unsigned int *bpp, unsigned int *pcp)
1164 sp = simGetValue(0x81,'I',1);
1165 depth = stack_depth(pc, 100);
1167 if (bp < stack_start())
1175 frameNext(unsigned int *bpp, unsigned int *pcp)
1177 unsigned int bp = *bpp;
1180 symbol *start_stack;
1182 if (bp < stack_start())
1184 pc = simGetValue(bp - 1, 'B', 2);
1185 depth = stack_depth(pc, 100);
1186 bp = bp - 2 + depth;
1192 static int running = 0;
1194 static int is_running(void) {
1198 static int set_running(int run) {
1202 /*-----------------------------------------------------------------*/
1203 /* simGo - send 'go' cmd to simulator and wait till a break occurs */
1204 /*-----------------------------------------------------------------*/
1205 void simGo (unsigned int gaddr)
1212 if ( userinterrupt )
1220 function *func = NULL;;
1221 if (applyToSet(functions,funcInAddr,gaddr,&func))
1222 STACK_PUSH(callStack,func);
1225 addr = simGoTillBp (gaddr);
1227 /* got the pc for the break point now first
1228 discover the program context i.e. module, function
1229 linenumber of the source etc, etc etc */
1231 ctxt = discoverContext (addr, NULL, currCtxt);
1233 /* dispatch all the break point call back functions */
1234 rv = dispatchCB (addr,ctxt);
1236 /* the dispatch call back function will return
1237 non-zero if an user break point has been hit
1238 if not then we continue with the execution
1244 if ( gaddr == -1 || doingSteps == 1 )
1250 /*-----------------------------------------------------------------*/
1251 /* preparePrint - common parse function for set variable, */
1252 /* output, print and display */
1253 /*-----------------------------------------------------------------*/
1254 static char *preparePrint(char *s, context *cctxt, int *fmt, symbol **sym)
1269 /* format of printout */
1293 for ( bp = s; *bp && ( isalnum( *bp ) || *bp == '_' || *bp == '$'); bp++ );
1299 *sym = symLookup(s,cctxt);
1305 fprintf(stdout,"No symbol \"%s\" in current context.\n", s);
1309 static int printAsmLine( function *func, module *m, unsigned saddr, unsigned eaddr)
1313 unsigned lastaddr = saddr+1;
1318 symaddr = func->sym->addr;
1319 symname = func->sym->name;
1326 for (j=0,i=0; i < m->nasmLines; i++ )
1328 if ( saddr >= 0 && m->asmLines[i]->addr < saddr)
1332 if ( eaddr >= 0 && m->asmLines[i]->addr > eaddr)
1337 (m->asmLines[i]->addr < func->sym->addr ||
1338 m->asmLines[i]->addr > func->sym->eaddr ))
1342 delta = m->asmLines[i]->addr - symaddr;
1346 lastaddr = m->asmLines[i]->addr;
1347 printf("0x%08x <%s",lastaddr,symname);
1348 if (delta > 0) printf("+%d",delta);
1349 printf(">:\t%s",m->asmLines[i]->src);
1355 /*-----------------------------------------------------------------*/
1356 /* cmdDisasm - disassemble asm instruction */
1357 /*-----------------------------------------------------------------*/
1358 static int cmdDisasm (char *s, context *cctxt, int args)
1360 function *func = NULL;
1365 /* white space skip */
1373 saddr = strtol(s,&s,0);
1379 eaddr = strtol(s,0,0);
1388 /* no start or only start so dump function */
1395 applyToSet(functions,funcInAddr,saddr,&func);
1399 printf("Dump of assembler code for function %s:\n",func->sym->name);
1400 printAsmLine(func,func->mod,-1,-1);
1401 printf("End of assembler dump.\n");
1406 if (applyToSet(modules,moduleLineWithAddr,saddr,&modul,NULL))
1409 printf("Dump of assembler code:\n");
1410 printAsmLine(NULL,modul,saddr,eaddr);
1411 printf("End of assembler dump.\n");
1419 printf("Dump of assembler code from 0x%08lx to 0x%08lx:\n",saddr,eaddr);
1421 while ( saddr < eaddr )
1424 if (applyToSet(functions,funcInAddr,saddr,&func))
1433 if (!applyToSet(modules,moduleLineWithAddr,saddr,&modul,NULL))
1436 saddr = printAsmLine(func,modul,saddr,eaddr) + 1;
1441 printf("End of assembler dump.\n");
1446 fprintf(stderr,"No function contains specified address.\n");
1450 sprintf(lbuf,"dis 0x%lx 0 %ld\n",saddr,( eaddr == -1 )?1L:eaddr-saddr);
1452 waitForSim(1000, NULL);
1453 fputs(simResponse(),stdout);
1457 /*-----------------------------------------------------------------*/
1458 /* cmdDisasm1 - disassemble one asm instruction */
1459 /*-----------------------------------------------------------------*/
1460 int cmdDisasm1 (char *s, context *cctxt)
1462 return cmdDisasm( s, cctxt, 1);
1465 /*-----------------------------------------------------------------*/
1466 /* cmdDisasmF - disassemble asm instructions */
1467 /*-----------------------------------------------------------------*/
1468 int cmdDisasmF(char *s, context *cctxt)
1470 return cmdDisasm( s, cctxt, 2);
1473 static int commonSetUserBp(char *s, context *cctxt, char bpType)
1476 function *func = NULL;
1478 /* user break point location specification can be of the following
1480 a) <nothing> - break point at current location
1481 b) lineno - number of the current module
1482 c) filename:lineno - line number of the given file
1483 e) filename:function- function X in file Y (useful for static functions)
1484 f) function - function entry point
1485 g) *addr - break point at address
1489 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
1492 /* trim left and right */
1495 /* case a) nothing */
1496 /* if nothing given then current location : we know
1497 the current execution location from the currentContext */
1500 /* if current context is known */
1502 Dprintf(D_break, ("commonSetUserBp: a) cctxtaddr:%x \n",cctxt->addr));
1503 if (srcMode == SRC_CMODE)
1504 /* set the break point */
1505 setBreakPoint ( cctxt->addr , CODE , bpType , userBpCB ,
1506 cctxt->func->mod->c_name, cctxt->cline);
1508 setBreakPoint ( cctxt->addr , CODE , bpType , userBpCB ,
1509 cctxt->func->mod->asm_name, cctxt->asmline);
1513 fprintf(stderr,"No default breakpoint address now.\n");
1518 if ( *s == '*' && isdigit(*(s+1)))
1521 long braddr = strtol(s+1,0,0);
1522 if (!applyToSet(functions,funcInAddr,braddr,&func))
1525 if (!applyToSet(modules,moduleLineWithAddr,braddr,&modul,&line))
1527 fprintf(stderr,"Address 0x%08lx not exists in code.\n",braddr);
1531 Dprintf(D_break, ("commonSetUserBp: g) addr:%lx \n",braddr));
1532 setBreakPoint ( braddr , CODE , bpType , userBpCB ,
1533 modul->c_name,line);
1539 int line = func->exitline;
1540 if ( !applyToSet(func->cfpoints,lineAtAddr,braddr,
1542 applyToSet(func->cfpoints,lineNearAddr,braddr,&line,NULL,NULL);
1543 setBreakPoint ( braddr , CODE , bpType , userBpCB ,
1544 func->mod->c_name,line);
1548 /* case b) lineno */
1549 /* check if line number */
1550 if ( !strchr(s,':') && isdigit(*s)) {
1551 /* get the lineno */
1552 int line = atoi(s) -1;
1553 Dprintf(D_break, ("commonSetUserBp: b) line:%d \n",line));
1556 fprintf(stdout,"linenumber <= 0\n");
1559 /* if current context not present then we must get the module
1560 which has main & set the break point @ line number provided
1561 of that module : if current context known then set the bp
1562 at the line number given for the current module
1565 if (!cctxt->func->mod) {
1566 if (!applyToSet(functions,funcWithName,"main"))
1567 fprintf(stderr,"Function \"main\" not defined.\n");
1569 setBPatModLine(func->mod,line, bpType);
1571 setBPatModLine(cctxt->func->mod,line, bpType);
1574 setBPatModLine(list_mod,line, bpType);
1576 fprintf(stdout,"Sdcdb fails to have module symbol context at %d\n", __LINE__);
1583 if ((bp = strchr(s,':'))) {
1588 if (srcMode == SRC_CMODE) {
1589 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
1590 fprintf (stderr,"No source file named %s.\n",s);
1594 if (!applyToSet(modules,moduleWithAsmName,s,&mod)) {
1595 fprintf (stderr,"No source file named %s.\n",s);
1600 /* case c) filename:lineno */
1601 if (isdigit(*(bp +1))) {
1602 Dprintf(D_break, ("commonSetUserBp: c) line:%d \n",atoi(bp+1)));
1603 setBPatModLine (mod,atoi(bp+1)-1,bpType);
1607 /* case d) filename:function */
1608 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
1609 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
1611 Dprintf(D_break, ("commonSetUserBp: d) \n"));
1612 setBPatModLine (mod,
1613 (srcMode == SRC_CMODE ?
1615 func->aentryline),bpType);
1620 /* case e) function */
1621 Dprintf(D_break, ("commonSetUserBp: e) \n"));
1622 if (!applyToSet(functions,funcWithName,s,&func))
1623 fprintf(stderr,"Function \"%s\" not defined.\n",s);
1625 setBPatModLine(func->mod,
1626 (srcMode == SRC_CMODE ?
1628 func->aentryline),bpType);
1634 /*-----------------------------------------------------------------*/
1635 /* cmdSetTmpUserBp - settempory break point at the user specified location */
1636 /*-----------------------------------------------------------------*/
1637 int cmdSetTmpUserBp (char *s, context *cctxt)
1639 return commonSetUserBp(s, cctxt, TMPUSER );
1642 /*-----------------------------------------------------------------*/
1643 /* cmdSetUserBp - set break point at the user specified location */
1644 /*-----------------------------------------------------------------*/
1645 int cmdSetUserBp (char *s, context *cctxt)
1647 return commonSetUserBp(s, cctxt, USER );
1650 /*-----------------------------------------------------------------*/
1651 /* cmdJump - set program counter */
1652 /*-----------------------------------------------------------------*/
1653 int cmdJump (char *s, context *cctxt)
1656 function *func = NULL;
1659 fprintf(stdout,"The program is not running.\n");
1663 /* trim left and right */
1668 fprintf(stdout,"No argument: need line or *addr.\n");
1671 if ( *s == '*' && isdigit(*(s+1)))
1673 unsigned int addr = atoi(s);
1674 if (cctxt && cctxt->func &&
1675 cctxt->func->sym->addr <= addr &&
1676 cctxt->func->sym->eaddr >= addr)
1681 fprintf(stdout,"Warning addr 0x%x outside actual function.\n",addr);
1687 /* get the lineno */
1688 int line = atoi(s) -1;
1689 if (!cctxt || !cctxt->func || !cctxt->func->mod)
1691 fprintf(stderr,"Function not defined.\n");
1694 if (line >= cctxt->func->entryline &&
1695 line <= cctxt->func->exitline )
1697 simSetPC(cctxt->func->mod->cLines[line]->addr);
1700 if (line >= cctxt->func->mod->ncLines )
1702 fprintf(stderr,"line not in module.\n");
1705 fprintf(stdout,"Warning line %d outside actual function.\n",line+1);
1706 simSetPC(cctxt->func->mod->cLines[line]->addr);
1709 if ((bp = strchr(s,':')))
1714 if (!applyToSet(modules,moduleWithCName,s,&mod))
1716 fprintf (stderr,"No source file named %s.\n",s);
1721 fprintf (stderr,"No line number.\n");
1725 if (line >= mod->ncLines )
1727 fprintf(stderr,"line not in module.\n");
1730 if ( mod != cctxt->func->mod ||
1731 line < cctxt->func->entryline ||
1732 line > cctxt->func->exitline )
1734 fprintf(stdout,"Warning line %d outside actual function.\n",
1737 simSetPC(mod->cLines[line]->addr);
1742 /*-----------------------------------------------------------------*/
1743 /* cmdListAsm - list assembler source code */
1744 /*-----------------------------------------------------------------*/
1745 int cmdListAsm (char *s, context *cctxt)
1747 if ( cctxt && cctxt->func)
1750 if ( cctxt->addr != INT_MAX )
1752 if (printAsmLine(cctxt->func,cctxt->func->mod,
1753 (long)cctxt->addr,(long)cctxt->addr))
1760 /*-----------------------------------------------------------------*/
1761 /* cmdSetOption - set debugger options */
1762 /*-----------------------------------------------------------------*/
1763 int cmdSetOption (char *s, context *cctxt)
1766 if (strncmp(s,"srcmode",7) == 0 ) {
1767 if (srcMode == SRC_CMODE)
1768 srcMode = SRC_AMODE;
1770 srcMode = SRC_CMODE;
1771 fprintf(stderr,"source mode set to '%s'\n",
1772 (srcMode == SRC_CMODE ? "C" : "asm"));
1776 if (strncmp(s,"listsize ",9) == 0)
1778 listlines = strtol(s+9,0,0);
1779 if ( listlines < LISTLINES )
1780 listlines = LISTLINES;
1785 if (strncmp(s,"debug ",6) == 0)
1787 sdcdbDebug = strtol(s+6,0,0);
1791 if (strncmp(s,"variable ",9) == 0)
1797 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
1800 while (*s && *s != '=') s++;
1805 printOrSetSymValue(sym,cctxt,0,0,0,rs,s,'\0');
1809 fprintf(stdout,"No new value for \"%s\".\n",s);
1814 fprintf(stderr,"'set %s' command not yet implemented\n",s);
1818 /*-----------------------------------------------------------------*/
1819 /* cmdContinue - continue till next break point */
1820 /*-----------------------------------------------------------------*/
1821 int cmdContinue (char *s, context *cctxt)
1823 if (!is_running()) {
1824 fprintf(stdout,"The program is not being run.\n");
1828 fprintf(stdout,"Continuing.\n");
1834 /*-----------------------------------------------------------------*/
1835 /* cmdIgnore - set ignorecount for breakpoint */
1836 /*-----------------------------------------------------------------*/
1837 int cmdIgnore (char *s, context *cctxt)
1843 fprintf(stdout,"Argument required (breakpoint number).\n");
1846 bpnum = strtol(s,&s,10);
1850 fprintf(stdout,"Second argument (specified ignore-count) is missing.");
1853 cnt = strtol(s,0,10);
1854 setUserbpIgnCount(bpnum,cnt);
1858 /*-----------------------------------------------------------------*/
1859 /* cmdCondition - set condition for breakpoint */
1860 /*-----------------------------------------------------------------*/
1861 int cmdCondition (char *s, context *cctxt)
1867 fprintf(stdout,"Argument required (breakpoint number).\n");
1870 bpnum = strtol(s,&s,10);
1876 setUserbpCondition(bpnum,s);
1880 /*-----------------------------------------------------------------*/
1881 /* cmdCommands - set commands for breakpoint */
1882 /*-----------------------------------------------------------------*/
1883 int cmdCommands (char *s, context *cctxt)
1890 bpnum = getLastBreakptNumber();
1892 bpnum = strtol(s,0,10);
1895 while ((line = getNextCmdLine()))
1897 line = trim_left(line);
1898 if (!strncmp(line,"end",3))
1902 cmds = Safe_strdup(line);
1906 cmds = Safe_realloc( cmds, strlen(cmds) + 1 + strlen(line));
1910 setUserbpCommand(bpnum,cmds);
1914 /*-----------------------------------------------------------------*/
1915 /* cmdDelUserBp - delete user break point */
1916 /*-----------------------------------------------------------------*/
1917 int cmdDelUserBp (char *s, context *cctxt)
1923 if (userBpPresent) {
1925 fprintf (stdout,"Delete all breakpoints? (y or n) ");
1927 fgets(buffer,sizeof(buffer),stdin);
1928 if (toupper(buffer[0]) == 'Y')
1934 /* determine the break point number */
1935 if (sscanf(s,"%d",&bpnum) == 1)
1936 deleteUSERbp(bpnum);
1941 /*-----------------------------------------------------------------*/
1942 /* cmdStepi - single step exactly one instruction */
1943 /*-----------------------------------------------------------------*/
1944 int cmdStepi (char *s, context *cctxt)
1948 fprintf(stdout,"The program is not being run.\n");
1959 static unsigned line_start_addr(context *ctx, int line)
1961 function *func = ctx->func;
1962 module *mod = func->mod;
1966 if (srcMode == SRC_CMODE)
1967 nlines = mod->ncLines;
1969 nlines = mod->nasmLines;
1972 if (srcMode == SRC_CMODE)
1973 addr = mod->cLines[line]->addr;
1975 addr = mod->asmLines[line]->addr;
1977 } while (addr == 0x7fffffff && line < nlines);
1978 if (addr == 0x7fffffff)
1979 addr = func->sym->eaddr;
1983 static unsigned line_end_addr(context *ctx, int line)
1985 function *func = ctx->func;
1986 module *mod = func->mod;
1987 int next_line, nlines;
1988 unsigned start_addr = line_start_addr(ctx, line);
1989 unsigned next_addr = func->sym->eaddr + 1;
1992 if (srcMode == SRC_CMODE)
1993 nlines = mod->ncLines;
1995 nlines = mod->nasmLines;
1996 for (next_line = 0; next_line < nlines; next_line++) {
1997 if (next_line == line)
1999 if (srcMode == SRC_CMODE)
2000 addr = mod->cLines[next_line]->addr;
2002 addr = mod->asmLines[next_line]->addr;
2003 if (start_addr < addr && addr < next_addr)
2009 BP_CALLBACK(step_bp_callback)
2015 static int do_step(context *ctx, int into)
2017 function *func = ctx->func;
2018 module *mod = func->mod;
2025 unsigned start_addr, end_addr, addr;
2027 unsigned char flags;
2029 if (srcMode == SRC_CMODE) {
2030 lines = mod->cLines;
2031 nlines = mod->ncLines;
2032 start_l = ctx->cline;
2034 lines = mod->asmLines;
2035 nlines = mod->nasmLines;
2036 start_l = ctx->asmline;
2040 flags = IS_BRANCH|IS_RET;
2043 line = lines[start_l];
2044 start = line_start_addr(ctx, start_l);
2045 end = line_end_addr(ctx, start_l);
2047 while (start <= ctx->addr && ctx->addr < end) {
2049 for (addr = ctx->addr; addr < end; addr += len) {
2050 insn = simGetValue(addr, 'C', 1);
2051 if (instructions[insn].flags & flags)
2053 len = instructions[insn].len;
2055 fprintf(stderr, "Unknown opcode 0x%02x\n", insn);
2059 if (addr != ctx->addr) {
2060 setBreakPoint(addr, CODE, STEP,
2062 mod->name, start_l);
2064 /* run to breakpoint */
2068 /* step over instruction at breakpoint */
2069 if (start <= ctx->addr && ctx->addr < end) {
2075 stepBpCB(ctx->addr, NULL, ctx);
2079 /*-----------------------------------------------------------------*/
2080 /* cmdStep - single step thru C source file */
2081 /*-----------------------------------------------------------------*/
2082 int cmdStep (char *s, context *cctxt)
2084 function *func = NULL;
2087 fprintf(stdout,"The program is not being run.\n");
2093 /*-----------------------------------------------------------------*/
2094 /* cmdNexti - next instruction but proceed function call */
2095 /*-----------------------------------------------------------------*/
2096 int cmdNexti (char *s, context *cctxt)
2099 fprintf(stdout,"The program is not being run.\n");
2110 /*-----------------------------------------------------------------*/
2111 /* cmdNext - next executable C statement file */
2112 /*-----------------------------------------------------------------*/
2113 int cmdNext (char *s, context *cctxt)
2115 function *func = NULL;
2116 /* next is almost the same as step except we don't
2117 we don't set break point for all function entry
2120 fprintf(stdout,"The program is not being run.\n");
2126 /*-----------------------------------------------------------------*/
2127 /* cmdRun - run till next break point */
2128 /*-----------------------------------------------------------------*/
2129 int cmdRun (char *s, context *cctxt)
2133 if (!is_running()) {
2134 fprintf(stdout,"Starting program\n");
2137 fprintf(stdout,"No executable file specified.\nUse the \"file\" command.\n");
2145 "The program being debugged has been started already.\n");
2146 fprintf(stdout,"Start it from the beginning? (y or n) ");
2149 fgets(buff,sizeof(buff),stdin);
2150 if (toupper(buff[0]) == 'Y') {
2161 /*-----------------------------------------------------------------
2162 cmdListSymbols - list symbols
2163 |-----------------------------------------------------------------*/
2164 int cmdListSymbols (char *s, context *cctxt)
2166 int our_verbose = 0;
2170 if (strstr(s, "v1")) {
2172 } else if (strstr(s, "v2")) {
2176 printf("[symbols]\n");
2177 sy = setFirstItem(symbols);
2182 if (our_verbose <= 1)
2183 printf("<%s>", sy->name);
2185 if (our_verbose > 1) {
2186 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
2187 sy->name, sy->size, sy->level, sy->block);
2188 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
2189 sy->isonstack, sy->isfunc, sy->offset, sy->addr);
2190 printf(" eaddr:%d, addr_type:%c, type:%p etype:%p\n",
2191 sy->eaddr, sy->addr_type, sy->type, sy->etype);
2192 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
2193 sy->scopetype, sy->sname, sy->rname, sy->addrspace);
2194 printf(" next:%p\n", sy->next);
2197 sy = setNextItem(symbols);
2199 printf(" %d symbols\n", i);
2203 /*-----------------------------------------------------------------
2204 cmdListFunctions - list functions.
2205 |-----------------------------------------------------------------*/
2206 int cmdListFunctions (char *s, context *cctxt)
2210 int our_verbose = 0;
2212 if (strstr(s, "v1")) {
2214 } else if (strstr(s, "v2")) {
2218 printf("[functions]\n");
2219 f = setFirstItem(functions);
2223 printf(" %d) sym:%p, fname:%s, modName:%s, mod:%p\n", i,
2224 f->sym, f->sym->name, f->modName, f->mod);
2225 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
2226 f->entryline, f->aentryline, f->exitline, f->aexitline);
2227 printf(" cfpoints:%p, afpoints:%p, laddr:%x, lline:%d\n",
2228 f->cfpoints, f->afpoints, f->laddr, f->lline);
2231 printf("<%s>", f->sym->name);
2234 f = setNextItem(functions);
2236 printf(" %d functions\n", i);
2240 /*-----------------------------------------------------------------
2241 cmdListModules - list modules.
2242 |-----------------------------------------------------------------*/
2243 int cmdListModules (char *s, context *cctxt)
2248 int our_verbose = 0;
2250 if (strstr(s, "v1")) {
2252 } else if (strstr(s, "v2")) {
2256 printf("[modules]\n");
2257 m = setFirstItem(modules);
2263 if (our_verbose >= 0) {
2264 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
2265 m->cfullname, m->afullname, m->name);
2266 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
2267 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
2268 printf(" cLines:%p, asmLines:%p\n",
2269 m->cLines, m->asmLines);
2271 if (our_verbose >= 2) {
2273 printf(" [cLines] ");
2275 for (i=0; i<m->ncLines; i++ ) {
2277 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
2278 i, cs->addr, cs->block, cs->level, cs->src);
2281 printf("%d records", i);
2284 printf(" [asmLines] ");
2286 for (i=0; i<m->nasmLines; i++ ) {
2287 as = m->asmLines[i];
2288 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
2289 i, as->addr, as->block, as->level, as->src);
2292 printf("%d records", i);
2297 m = setNextItem(modules);
2302 /*-----------------------------------------------------------------
2303 infoSymbols - This is really just a tool to dump all these
2304 huge program structures out into human readable form.
2305 |-----------------------------------------------------------------*/
2306 static void infoSymbols(context *ctxt)
2308 int our_verbose = 0;
2310 printf("[context:%p] func:%p modName:%s addr:%x\n",
2311 ctxt, ctxt->func, ctxt->modName, ctxt->addr);
2313 printf(" cline:%d asmline:%d block:%d level:%d\n",
2314 ctxt->cline, ctxt->asmline, ctxt->block, ctxt->level);
2316 printf("[globals] currCtxt:%p, modules:%p, functions:%p symbols:%p\n",
2317 currCtxt, modules, functions, symbols);
2318 printf(" nStructs:%d, structs:%p, ssdirl:%s\n",
2319 nStructs, structs, ssdirl);
2321 /**************** modules *******************/
2326 printf("[modules]\n");
2327 m = setFirstItem(modules);
2332 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
2333 m->cfullname, m->afullname, m->name);
2334 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
2335 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
2336 printf(" cLines:%p, asmLines:%p\n",
2337 m->cLines, m->asmLines);
2340 cs = m->cLines[i++];
2341 printf(" [cLines] ");
2344 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
2345 i, cs->addr, cs->block, cs->level, cs->src);
2346 cs = m->cLines[i++];
2349 printf("%d records", i);
2353 as = m->asmLines[i++];
2354 printf(" [asmLines] ");
2357 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
2358 i, as->addr, as->block, as->level, as->src);
2359 as = m->asmLines[i++];
2362 printf("%d records", i);
2366 m = setNextItem(modules);
2370 /**************** functions *******************/
2374 printf("[functions]\n");
2375 f = setFirstItem(functions);
2381 printf(" %d) sym:%p, modName:%s, mod:%p\n", i,
2382 f->sym, f->modName, f->mod);
2383 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
2384 f->entryline, f->aentryline, f->exitline, f->aexitline);
2385 printf(" cfpoints:%p, afpoints:%p, laddr:%x, lline:%d\n",
2386 f->cfpoints, f->afpoints, f->laddr, f->lline);
2389 f = setNextItem(functions);
2392 printf(" %d functions\n", i);
2395 /**************** symbols *******************/
2399 printf("[symbols]\n");
2400 s = setFirstItem(symbols);
2406 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
2407 s->name, s->size, s->level, s->block);
2408 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
2409 s->isonstack, s->isfunc, s->offset, s->addr);
2410 printf(" eaddr:%d, addr_type:%c, type:%p etype:%p\n",
2411 s->eaddr, s->addr_type, s->type, s->etype);
2412 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
2413 s->scopetype, s->sname, s->rname, s->addrspace);
2414 printf(" next:%p\n", s->next);
2417 s = setNextItem(symbols);
2420 printf(" %d symbols\n", i);
2425 /*-----------------------------------------------------------------*/
2426 /* infoRegisters - print register information */
2427 /*-----------------------------------------------------------------*/
2428 static void infoRegisters( int all, context *ctxt)
2430 static int regaddrs[] = {0x81,0x82,0x83,0xb8,0xd0,0xe0,0xf0,0};
2434 i = simGetValue (0xd0,'I',1);
2435 fprintf(stdout,"IP : 0x%04X RegisterBank %d:\nR0-7:",ctxt->addr,(i>>3)&3);
2436 for ( j = 0; j < 8 ; j++ )
2438 val = simGetValue (j,'R',1);
2439 fprintf(stdout," 0x%02lX",val);
2441 fprintf(stdout,"\n");
2442 val = simGetValue (0xe0,'I',1);
2443 fprintf(stdout,"ACC : 0x%02lX %lu %c\n",val,val,(isprint(val) ? (char)val : '.'));
2444 val = simGetValue (0xf0,'I',1);
2445 fprintf(stdout,"B : 0x%02lX %lu %c\n",val,val,(isprint(val) ? (char)val : '.'));
2446 val = simGetValue (0x82,'I',2);
2447 fprintf(stdout,"DPTR: 0x%04lX %lu\n",val,val);
2448 val = simGetValue (0x81,'I',1);
2449 fprintf(stdout,"SP : 0x%02lX (0x%04lX)\n",val,simGetValue (val-1,'B',2));
2450 fprintf(stdout,"PSW : 0x%02X | CY : %c | AC : %c | OV : %c | P : %c\n",
2451 i,(i&0x80)?'1':'0',(i&0x40)?'1':'0',(i&4)?'1':'0',(i&1)?'1':'0');
2454 fprintf(stdout,"Special Function Registers:\n");
2456 for ( i = 0x80 ; i < 0x100 ; i++ )
2459 if ( *r && *r == i )
2461 /* skip normal registers */
2465 if (applyToSetFTrue(sfrsymbols,symWithAddr,i,'I',&sym))
2467 val = simGetValue (sym->addr,sym->addrspace,sym->size);
2468 fprintf(stdout,"%s : 0x%02lx",sym->name,val);
2471 for ( j = 0 ; j < 8 ; j++ )
2474 if (applyToSetFTrue(sfrsymbols,symWithAddr,i+j,'J',&sym))
2476 //val = simGetValue (sym->addr,sym->addrspace,sym->size);
2477 fprintf(stdout," %s=%c",sym->name,(val&1)? '1':'0');
2482 fprintf(stdout,"\n");
2488 /*-----------------------------------------------------------------*/
2489 /* infoStack - print call stack information */
2490 /*-----------------------------------------------------------------*/
2491 static void infoStack(context *ctxt)
2495 context *ctx, my_context;
2496 unsigned int bp, pc, addr = ctxt->addr;
2499 for (status = frameStart(&bp,&pc); status; status = frameNext(&bp, &pc)) {
2500 ctx = discoverContext(pc, NULL, &my_context);
2503 Dprintf(D_break, ("break: infoStack: %s 0x%02x\n",func->sym->name, bp));
2505 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",i++,
2507 func->mod->c_name,func->lline+1);
2509 fprintf(stdout,"#%d 0x%08x\n", i++, pc);
2513 fprintf(stdout,"no stack.\n");
2516 /*-----------------------------------------------------------------*/
2517 /* cmdWhere - where command */
2518 /*-----------------------------------------------------------------*/
2519 int cmdWhere(char *s, context *cctxt)
2526 static int infomode = 0;
2527 /*-----------------------------------------------------------------*/
2528 /* cmdInfo - info command */
2529 /*-----------------------------------------------------------------*/
2530 int cmdInfo (char *s, context *cctxt)
2532 /* trim left and_right*/
2535 /* list all break points */
2536 if (strncmp(s,"break",5) == 0) {
2541 /* info frame same as frame */
2542 if (strncmp(s,"frame",5) == 0) {
2543 cmdFrame (s+5,cctxt);
2547 if (strncmp(s,"line",4) == 0) {
2549 cmdListSrc (s+4,cctxt);
2552 if (strncmp(s,"source",6) == 0)
2558 fprintf(stdout,"Source files for which symbols have been read in:\n\n");
2559 for (m = setFirstItem(modules); m ; m = setNextItem(modules))
2561 fprintf(stdout,"%s%s, %s",k ? ", ":"",m->cfullname, m->afullname);
2564 fprintf(stdout,"\n");
2568 if (!cctxt || !cctxt->func || !cctxt->func->mod)
2570 fprintf(stdout,"No source file loaded\n");
2573 m = cctxt->func->mod;
2574 fprintf(stdout,"Current source file is %s\n",m->c_name);
2575 fprintf(stdout,"Located in %s\n",m->cfullname);
2576 fprintf(stdout,"Contains %d lines.\nSource language is c.\n",
2581 if (strcmp(s,"functions") == 0)
2585 fprintf(stdout,"All defined functions:\n");
2586 for ( f = setFirstItem(functions); f ; f = setNextItem(functions))
2591 fprintf(stdout,"\nFile %s\n", m->c_name);
2593 fprintf(stdout,"%s();\n",f->sym->name);
2597 /* info stack display call stack */
2598 if (strcmp(s,"stack") == 0) {
2604 /* info stack display call stack */
2605 if (strcmp(s,"registers") == 0) {
2606 infoRegisters(0,cctxt);
2610 /* info stack display call stack */
2611 if (strcmp(s,"all-registers") == 0)
2613 infoRegisters(1,cctxt);
2617 /* info stack display call stack */
2618 if (strcmp(s,"symbols") == 0) {
2619 /* dump out symbols we have read in */
2620 fprintf(stdout,"Dumping symbols...\n");
2625 if (strcmp(s,"variables") == 0) {
2626 /* dump out symbols we have read in */
2627 fprintf(stdout,"Dumping symbols...\n");
2632 fprintf(stdout,"Undefined info command: \"%s\". Try \"help\n",s);
2637 /*-----------------------------------------------------------------*/
2638 /* cmdQuit - quit debugging */
2639 /*-----------------------------------------------------------------*/
2640 int cmdQuit (char *s, context *cctxt)
2647 /*-----------------------------------------------------------------*/
2648 /* cmdListSrc - list src */
2649 /*-----------------------------------------------------------------*/
2650 int cmdListSrc (char *s, context *cctxt)
2652 static int currline = 0;
2655 int llines = listlines;
2656 function *func = NULL;
2661 /* if the user has spcified line numer then the line number
2662 can be of the following formats
2663 LINE - just line number
2664 FILE:LINE - filename line number
2665 FILE:LINE,LASTLINE + last line
2666 FUNCTION - list a function
2667 FILE:FUNCTION - function in file */
2672 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
2674 fprintf(stdout,"Sdcdb fails to have a proper context at %d.\n", __LINE__);
2679 list_mod = cctxt->func->mod;
2680 pline = strtol(s,&s,10) - 1;
2681 if (s && (s = strchr(s,',')))
2684 llines = strtol(s+1,0,10);
2694 /* if ':' present then FILE:LINE || FILE:FUNCTION */
2695 if ((bp = strchr(s,':'))) {
2700 list_mod=NULL; /* bug fix 2-09-02, moduleWithCName expects mod to be null */
2701 if (srcMode == SRC_CMODE) {
2702 if (!applyToSet(modules,moduleWithCName,s,&list_mod)) {
2703 fprintf (stderr,"No c source file named %s.\n",s);
2707 if (!applyToSet(modules,moduleWithAsmName,s,&list_mod)) {
2708 fprintf (stderr,"No source file named %s.\n",s);
2712 pline = strtol(bp,&bp,10) - 1;
2713 if (bp && (bp = strchr(bp,',')))
2715 /* FILE:LINE,LASTLINE */
2716 llines = strtol(bp+1,0,10);
2724 if (!applyToSet(functions,funcWithNameModule,bp,s,&func)) {
2725 fprintf(stdout,"Function \"%s\" not defined.\n",bp);
2728 list_mod = func->mod;
2729 if (srcMode == SRC_CMODE) {
2730 pline = func->entryline;
2731 llines = func->exitline - func->entryline + 1;
2733 pline = func->aentryline;
2734 llines = func->aexitline - func->aentryline + 1;
2744 if ((bp = strrchr(s,'\'')))
2750 if (!applyToSet(functions,funcWithName,s,&func)) {
2751 fprintf(stderr,"Function \"%s\" not defined.\n",s);
2755 list_mod = func->mod;
2756 if (srcMode == SRC_CMODE) {
2757 pline = func->entryline;
2758 llines = func->exitline - func->entryline + 1;
2760 pline = func->aentryline;
2761 llines = func->aexitline - func->aentryline + 1;
2767 /* if no line specified & we had listed
2768 before then continue from that listing */
2772 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
2773 fprintf(stdout,"Missing context at %d. Try list filename:lineno\n", __LINE__);
2776 list_mod = cctxt->func->mod;
2777 if (srcMode == SRC_CMODE)
2778 pline = cctxt->cline;
2780 pline = cctxt->asmline;
2785 fprintf(stdout,"Sdcdb fails to have a valid module context at %d.\n", __LINE__);
2793 unsigned firstaddr , lastaddr ;
2794 if ( pline >= list_mod->ncLines )
2795 pline = cctxt->cline;
2796 firstaddr = lastaddr = list_mod->cLines[pline]->addr;
2797 if (!func && cctxt && cctxt->func )
2799 fprintf(stdout,"Line %d of \"%s\" starts at address 0x%08x <%s+%d>",
2801 list_mod->c_name, lastaddr,
2802 func ? func->sym->name : "?",
2803 func ? lastaddr -func->sym->addr : 0);
2805 for ( ; pline < list_mod->ncLines; pline++ )
2807 if ( list_mod->cLines[pline]->addr > lastaddr )
2809 lastaddr = list_mod->cLines[pline]->addr -1;
2813 fprintf(stdout," and ends at 0x%08x <%s+%d>.\n",
2815 func ? func->sym->name : "?",
2816 func ? lastaddr -func->sym->addr : 0);
2819 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
2820 canonname(func->mod->cfullname),
2826 for ( i = 0 ; i < llines ; i++ ) {
2827 if (srcMode == SRC_CMODE) {
2828 if ( (pline + i) >= list_mod->ncLines )
2830 fprintf(stdout,"%d\t%s",pline + i,
2831 list_mod->cLines[pline +i]->src);
2833 if ( (pline + i) >= list_mod->nasmLines )
2835 fprintf(stdout,"%d\t%s",pline + i,
2836 list_mod->asmLines[pline +i]->src);
2839 currline = pline + i ;
2843 static unsigned long getValBasic(symbol *sym, link *type, char *val)
2859 v.f = strtod(val,NULL);
2862 v.val = strtol(val,NULL,0);
2865 if (IS_INTEGRAL(type))
2874 if (( s = strchr(val,'\'')))
2877 v.b[0] = strtol(s+2,NULL,8);
2883 v.b[0] = strtol(val,NULL,0);
2889 v.val = strtol(val,NULL,0);
2891 v.i.lo = strtol(val,NULL,0);
2893 v.val = strtol(val,NULL,0);
2896 v.val = strtol(val,NULL,0);
2901 /*-----------------------------------------------------------------*/
2902 /* printFmtInteger - print value in bin,oct,dez or hex */
2903 /*-----------------------------------------------------------------*/
2904 static void printFmtInteger(char *deffmt,int fmt, long val,
2907 static char digits[] =
2909 '0' , '1' , '2' , '3' , '4' , '5' ,
2910 '6' , '7' , '8' , '9' , 'a' , 'b' ,
2911 'c' , 'd' , 'e' , 'f' , 'g' , 'h'
2913 static int radixOfFormat[] = { 0 , 2, 8 ,10, 16 };
2914 static int olenOfSize[] = { 0 , 3, 6 , 8, 11 };
2920 if ( fmt == FMT_NON || fmt == FMT_DEZ )
2922 fprintf(stdout,deffmt,val);
2925 radix = radixOfFormat[fmt];
2928 if ( sign && val < 0 )
2936 while (val <= -radix)
2938 buf[charPos--] = digits[-(val % radix)];
2941 buf[charPos] = digits[-val];
2946 radix = olenOfSize[size];
2956 while (charPos > 39 - radix )
2958 buf[--charPos] = '0';
2963 if ( buf[charPos] != '0' )
2964 buf[--charPos] = '0';
2967 buf[--charPos] = 'x';
2968 buf[--charPos] = '0';
2972 buf[--charPos] = '-';
2974 fputs(&buf[charPos],stdout);
2977 /*-----------------------------------------------------------------*/
2978 /* printValBasic - print value of basic types */
2979 /*-----------------------------------------------------------------*/
2980 static void printValBasic(symbol *sym, link *type,
2981 char mem, unsigned addr,int size, int fmt)
2994 v.val = simGetValue(addr,mem,size);
2995 /* if this a floating point number then */
2997 fprintf(stdout,"%f",v.f);
3000 fprintf(stdout,"0x%0*lx",size<<1,v.val);
3002 if (IS_INTEGRAL(type))
3011 if ( isprint(v.val))
3012 printFmtInteger((SPEC_USIGN(etype)?"0x%02x":"'%c'"),
3013 fmt,(long)v.val,0,size);
3015 printFmtInteger((SPEC_USIGN(etype)?"0x%02x":"'\\%o'"),
3016 fmt,(long)v.val,0,size);
3022 if (SPEC_USIGN(etype))
3023 printFmtInteger("%u",fmt,(long)v.val,0,size);
3025 printFmtInteger("%d",fmt,(long)v.sval,1,size);
3027 if (SPEC_USIGN(etype))
3028 printFmtInteger("%u",fmt,(long)v.i.lo,0,size);
3030 printFmtInteger("%d",fmt,(long)v.i.lo,1,size);
3033 if (IS_BITVAR(etype))
3034 fprintf(stdout,"%c",(v.val?'1':'0'));
3036 fprintf(stdout,"0x%0*lx",size<<1,v.val);
3040 fprintf(stdout,"0x%0*lx",size<<1,v.val);
3043 /*-----------------------------------------------------------------*/
3044 /* printValFunc - prints function values */
3045 /*-----------------------------------------------------------------*/
3046 static void printValFunc (symbol *sym, int fmt)
3048 fprintf(stdout,"print function not yet implemented");
3052 do_indent(int indent) {
3054 fprintf(stdout, " ");
3058 /*-----------------------------------------------------------------*/
3059 /* printArrayValue - will print the values of array elements */
3060 /*-----------------------------------------------------------------*/
3061 static void printArrayValue (symbol *sym, link *type,
3062 char space, unsigned int addr, int fmt,
3065 link *elem_type = type->next;
3069 fprintf(stdout,"{");
3070 for (i = 0 ; i < DCL_ELEM(type) ; i++) {
3071 if (IS_AGGREGATE(elem_type)) {
3072 printValAggregates(sym,elem_type,space,addr,fmt,indent);
3075 printValBasic(sym,elem_type,space,addr,getSize(elem_type),fmt);
3078 addr += getSize(elem_type);
3079 if (i != DCL_ELEM(type) -1) {
3080 fprintf(stdout,",");
3082 fprintf(stdout,"\n");
3089 fprintf(stdout,"}");
3092 /*-----------------------------------------------------------------*/
3093 /* printStructValue - prints structures elements */
3094 /*-----------------------------------------------------------------*/
3095 static void printStructValue (symbol *sym, link *type,
3096 char space, unsigned int addr, int fmt,
3099 symbol *fields = SPEC_STRUCT(type)->fields;
3102 fprintf(stdout,"{\n");
3104 do_indent(indent + 1);
3105 fprintf(stdout,"%s = ", fields->name);
3107 if (IS_AGGREGATE(fields->type)) {
3108 printValAggregates(fields,fields->type,space, addr, fmt, indent + 1);
3110 printValBasic(fields,fields->type,space,addr,getSize(fields->type), fmt);
3112 fprintf(stdout,",\n");
3113 addr += getSize(fields->type);
3114 fields = fields->next;
3117 fprintf(stdout,"}");
3120 /*-----------------------------------------------------------------*/
3121 /* printValAggregates - print value of aggregates */
3122 /*-----------------------------------------------------------------*/
3123 static void printValAggregates (symbol *sym, link *type,
3124 char space,unsigned int addr, int fmt,
3128 if (IS_ARRAY(type)) {
3129 printArrayValue(sym, type, space, addr, fmt, indent);
3133 if (IS_STRUCT(type)) {
3134 printStructValue(sym, type, space, addr, fmt, indent);
3139 /*-----------------------------------------------------------------*/
3140 /* printOrSetSymValue - print or set value of a symbol */
3141 /*-----------------------------------------------------------------*/
3142 static int printOrSetSymValue (symbol *sym, context *cctxt,
3143 int flg, int dnum, int fmt, char *rs,
3144 char *val, char cmp )
3146 static char fmtChar[] = " todx ";
3147 static int stack = 1;
3153 char save_ch, save_ch2;
3156 /* if it is on stack then compute address & fall thru */
3159 symbol *bp = symLookup("bp",cctxt);
3162 fprintf(stdout,"cannot determine stack frame\n");
3166 sym->addr = simGetValue(bp->addr,bp->addrspace,bp->size)
3170 /* get the value from the simulator and
3178 fprintf(stdout,"$%d = ",stack++);
3181 fprintf(stdout,"%d: ", dnum);
3182 if ( fmt != FMT_NON )
3183 fprintf(stdout,"/%c ",fmtChar[fmt]);
3184 fprintf(stdout,"%s%s = ",sym->name,rs);
3194 if ( *rs == '[' && (IS_ARRAY(type) || IS_PTR(type)))
3197 while ( *rs && *rs != ']' ) rs++ ;
3200 if ( ! isdigit(*s ))
3202 /* index seems a variable */
3203 for ( s2 = s; *s2 && ( isalnum( *s2 ) || *s2 == '_'); s2++ );
3207 fields = symLookup(s,cctxt);
3211 fprintf(stdout,"Unknown variable \"%s\" for index.\n", s);
3214 /* arrays & structures first */
3215 if (! IS_INTEGRAL(fields->type))
3217 fprintf(stdout,"Wrong type of variable \"%s\" for index \n", s);
3220 n = simGetValue(fields->addr,fields->addrspace,getSize(fields->type));
3226 if ( IS_ARRAY(type) && (n < 0 || n >= DCL_ELEM(type)))
3228 fprintf(stdout,"Wrong index %d.\n", n);
3232 addr = simGetValue(addr, sym->addrspace, size);
3234 size = getSize(type);
3238 else if ( (*rs == '.' || get_member) && IS_STRUCT(type))
3241 /* search structure element */
3242 for ( rs = s; *rs && ( isalnum( *rs ) || *rs == '_'); rs++ );
3246 for (fields = SPEC_STRUCT(type)->fields; fields; fields = fields->next)
3248 if (!(strcmp(s,fields->name)))
3254 fprintf(stdout,"Unknown field \"%s\" of structure\n", s);
3257 type = fields->type;
3258 size = getSize(type);
3259 addr += fields->offset;
3261 else if ( *rs == '*' && IS_PTR(type))
3263 addr = simGetValue(addr, sym->addrspace, size);
3265 size = getSize(type);
3268 else if ( rs[0] == '-' && rs[1] == '>' &&
3269 IS_PTR(type) && IS_STRUCT(type->next))
3271 addr = simGetValue(addr, sym->addrspace, size);
3273 size = getSize(type);
3283 /* arrays & structures first */
3284 if (IS_AGGREGATE(type))
3288 fprintf(stdout,"Cannot set/compare aggregate variable\n");
3292 printValAggregates(sym,type,sym->addrspace,addr,fmt,0);
3299 printValFunc(sym,fmt);
3307 unsigned long newval;
3308 newval = getValBasic(sym,type,val);
3313 lval = simGetValue(addr,sym->addrspace,size);
3316 case '<' : return ( lval < newval ? 1:0 ); break;
3317 case '>' : return ( lval > newval ? 1:0 ); break;
3318 case 'l' : return ( lval <= newval ? 1:0 ); break;
3319 case 'g' : return ( lval >= newval ? 1:0 ); break;
3320 case '=' : return ( lval == newval ? 1:0 ); break;
3321 case '!' : return ( lval != newval ? 1:0 ); break;
3326 if ( sym->addrspace == 'I' && addr == 0xb8 )
3328 /* Symbol with address of IP */
3329 if ( cctxt ) cctxt->addr = newval;
3330 simSetPC(cctxt->addr);
3333 simSetValue(addr,sym->addrspace,size,newval);
3338 printValBasic(sym,type,sym->addrspace,addr,size,fmt);
3340 if ( flg > 0 ) fprintf(stdout,"\n");
3344 /*-----------------------------------------------------------------*/
3345 /* printStructInfo - print out structure information */
3346 /*-----------------------------------------------------------------*/
3347 static void printStructInfo (structdef *sdef)
3349 symbol *field = sdef->fields ;
3354 field = field->next;
3357 fprintf(stdout,"%s %s {\n",(i ? "struct" : "union" ), sdef->tag);
3358 field = sdef->fields;
3360 printTypeInfo (field->type);
3361 fprintf(stdout," %s ;\n",field->name);
3362 field = field->next ;
3365 fprintf(stdout,"}\n");
3369 /*-----------------------------------------------------------------*/
3370 /* printTypeInfo - print out the type information */
3371 /*-----------------------------------------------------------------*/
3372 static void printTypeInfo(link *p)
3378 switch (DCL_TYPE(p)) {
3380 printTypeInfo (p->next);
3381 fprintf(stdout,"()");
3384 printTypeInfo (p->next);
3385 fprintf(stdout,"[%d]",DCL_ELEM(p));
3391 printTypeInfo (p->next);
3392 fprintf(stdout,"(_near *)");
3396 printTypeInfo (p->next);
3397 fprintf(stdout,"(_xdata *)");
3401 printTypeInfo( p->next);
3402 fprintf(stdout,"(_code *)");
3406 printTypeInfo( p->next);
3407 fprintf(stdout,"(_generic *)");
3411 switch (SPEC_NOUN(p)) { /* depending on the specifier type */
3413 (IS_LONG(p) ? fputs("long ",stdout) :
3414 ( IS_SHORT(p) ? fputs("short ",stdout) :
3415 fputs("int ",stdout))) ;
3418 fputs("float ",stdout);
3422 fputs ("char ",stdout);
3426 fputs("void ",stdout);
3430 printStructInfo (SPEC_STRUCT(p));
3434 fputs("sbit ",stdout);
3438 fprintf(stdout,": %d" ,SPEC_BLEN(p));
3444 /*-----------------------------------------------------------------*/
3445 /* conditionIsTrue - compare variable with constant value */
3446 /*-----------------------------------------------------------------*/
3447 int conditionIsTrue( char *s, context *cctxt)
3451 char *rs, *dup, cmp_char;
3452 dup = s = Safe_strdup(s);
3453 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )) || !sym)
3455 else if (!( s = strpbrk(rs,"<>=!")))
3463 /* if <= or >= an other char is used
3464 * == or != not checked in switch
3468 case '>': cmp_char = 'g' ; break;
3469 case '<': cmp_char = 'l' ; break;
3474 fmt = printOrSetSymValue(sym,cctxt,0,0,0,rs,s,cmp_char);
3480 /*-----------------------------------------------------------------*/
3481 /* cmdPrint - print value of variable */
3482 /*-----------------------------------------------------------------*/
3483 int cmdPrint (char *s, context *cctxt)
3488 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
3493 printOrSetSymValue(sym,cctxt,1,0,fmt,rs,NULL,'\0');
3498 /*-----------------------------------------------------------------*/
3499 /* cmdOutput - print value of variable without number and newline */
3500 /*-----------------------------------------------------------------*/
3501 int cmdOutput (char *s, context *cctxt)
3506 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
3511 printOrSetSymValue(sym,cctxt,0,0,fmt,rs,NULL,'\0');
3516 /** find display entry with this number */
3518 DEFSETFUNC(dsymWithNumber)
3520 dsymbol *dsym = item;
3522 V_ARG(dsymbol **,dsymp);
3524 if ( dsym->dnum == dnum )
3532 /*-----------------------------------------------------------------*/
3533 /* displayAll - display all valid variables */
3534 /*-----------------------------------------------------------------*/
3535 void displayAll(context *cctxt)
3541 for (dsym = setFirstItem(dispsymbols);
3543 dsym = setNextItem(dispsymbols))
3545 if ( (sym = symLookup(dsym->name,cctxt)))
3546 printOrSetSymValue(sym,cctxt,2,dsym->dnum,dsym->fmt,
3547 dsym->rs,NULL,'\0');
3551 /*-----------------------------------------------------------------*/
3552 /* cmdDisplay - display value of variable */
3553 /*-----------------------------------------------------------------*/
3554 int cmdDisplay (char *s, context *cctxt)
3556 static int dnum = 1;
3560 if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )))
3568 dsymbol *dsym = (dsymbol *)Safe_calloc(1,sizeof(dsymbol));
3569 dsym->dnum = dnum++ ;
3570 dsym->name = sym->name;
3572 dsym->rs = gc_strdup(rs);
3573 addSetHead(&dispsymbols,dsym);
3578 /*-----------------------------------------------------------------*/
3579 /* cmdUnDisplay - undisplay value of variable */
3580 /*-----------------------------------------------------------------*/
3581 int cmdUnDisplay (char *s, context *cctxt)
3589 for (dsym = setFirstItem(dispsymbols);
3591 dsym = setNextItem(dispsymbols))
3593 Safe_free(dsym->rs);
3596 deleteSet(&dispsymbols);
3601 dnum = strtol(s,&s,10);
3602 if (applyToSetFTrue(dispsymbols,dsymWithNumber,dnum,&dsym))
3604 deleteSetItem(&dispsymbols,dsym);
3605 Safe_free(dsym->rs);
3610 fprintf(stdout,"Arguments must be display numbers.\n");
3616 /*-----------------------------------------------------------------*/
3617 /* cmdPrintType - print type of a variable */
3618 /*-----------------------------------------------------------------*/
3619 int cmdPrintType (char *s, context *cctxt)
3623 /* trim left and right */
3627 if ((sym = symLookup(s,cctxt))) {
3628 printTypeInfo(sym->type);
3629 fprintf(stdout,"\n");
3632 "No symbol \"%s\" in current context.\n",
3638 /*-----------------------------------------------------------------*/
3639 /* cmdClrUserBp - clear user break point */
3640 /*-----------------------------------------------------------------*/
3641 int cmdClrUserBp (char *s, context *cctxt)
3644 function *func = NULL;
3646 /* clear break point location specification can be of the following
3648 a) <nothing> - break point at current location
3649 b) lineno - number of the current module
3650 c) filename:lineno - line number of the given file
3651 e) filename:function- function X in file Y (useful for static functions)
3652 f) function - function entry point
3656 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
3660 /* trim left and right */
3663 /* case a) nothing */
3664 /* if nothing given then current location : we know
3665 the current execution location from the currentContext */
3668 /* if current context is known */
3670 /* clear the break point @ current location */
3671 clearUSERbp (cctxt->addr);
3673 fprintf(stderr,"No default breakpoint address now.\n");
3678 /* case b) lineno */
3679 /* check if line number */
3681 /* get the lineno */
3684 /* if current context not present then we must get the module
3685 which has main & set the break point @ line number provided
3686 of that module : if current context known then set the bp
3687 at the line number given for the current module
3690 if (!cctxt->func->mod) {
3691 if (!applyToSet(functions,funcWithName,"main"))
3692 fprintf(stderr,"Function \"main\" not defined.\n");
3694 clearBPatModLine(func->mod,line);
3696 clearBPatModLine(cctxt->func->mod,line);
3702 if ((bp = strchr(s,':'))) {
3707 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
3708 fprintf (stderr,"No source file named %s.\n",s);
3712 /* case c) filename:lineno */
3713 if (isdigit(*(bp +1))) {
3715 clearBPatModLine (mod,atoi(bp+1));
3719 /* case d) filename:function */
3720 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
3721 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
3723 clearBPatModLine (mod,func->entryline);
3728 /* case e) function */
3729 if (!applyToSet(functions,funcWithName,s,&func))
3730 fprintf(stderr,"Function \"%s\" not defined.\n",s);
3732 clearBPatModLine(func->mod,func->entryline);
3738 /*-----------------------------------------------------------------*/
3739 /* cmdSimulator - send command to simulator */
3740 /*-----------------------------------------------------------------*/
3741 int cmdSimulator (char *s, context *cctxt)
3745 if (strlen(s) > 80) {
3746 printf("error 3A\n");
3750 strcat(tmpstr, "\n");
3752 waitForSim(200,NULL);
3753 fprintf(stdout,"%s",simResponse());
3757 void setMainContext()
3759 function *func = NULL;
3761 if (!applyToSet(functions,funcWithName,"_main",&func) &&
3762 !applyToSet(functions,funcWithName,"main",&func))
3765 discoverContext (func->sym->addr, func, currCtxt);
3768 function *needExtraMainFunction()
3770 function *func = NULL;
3771 if (!applyToSet(functions,funcWithName,"_main",&func))
3773 if (applyToSet(functions,funcWithName,"main",&func))
3781 static void printFrame()
3784 function *func = NULL;
3785 function *lastfunc = NULL;
3786 context *ctx, my_context;
3787 unsigned int bp, pc;
3790 if ( currentFrame < 0 )
3793 fprintf(stdout,"Bottom (i.e., innermost) frame selected; you cannot go down.\n");
3797 for (status = frameStart(&bp, &pc); status; status = frameNext(&bp, &pc))
3799 if (i >= currentFrame)
3803 if (i < currentFrame) {
3805 fprintf(stdout,"Initial frame selected; you cannot go up.\n");
3808 ctx = discoverContext(pc, NULL, &my_context);
3809 if (ctx && (func = ctx->func)) {
3810 fprintf(stdout,"#%d 0x%08x in %s () at %s:%d\n",
3811 currentFrame,pc,func->sym->name,func->mod->c_name,func->lline+1);
3812 fprintf(stdout,"\032\032%s:%d:1:beg:0x%08x\n",
3813 canonname(func->mod->cfullname),func->lline+1,func->laddr);
3815 fprintf(stdout,"#%d 0x%08x\n",
3821 /*-----------------------------------------------------------------*/
3822 /* cmdUp - Up command */
3823 /*-----------------------------------------------------------------*/
3824 int cmdUp(char *s, context *cctxt)
3828 currentFrame += strtol(s,0,10);
3836 /*-----------------------------------------------------------------*/
3837 /* cmdDown - down command */
3838 /*-----------------------------------------------------------------*/
3839 int cmdDown(char *s, context *cctxt)
3843 currentFrame -= strtol(s,0,10);
3850 /*-----------------------------------------------------------------*/
3851 /* cmdFrame - Frame command */
3852 /*-----------------------------------------------------------------*/
3853 int cmdFrame (char *s, context *cctxt)
3855 function *func = NULL;
3860 currentFrame = strtol(s,0,10);
3865 /*-----------------------------------------------------------------*/
3866 /* cmdFinish - exec till end of current function */
3867 /*-----------------------------------------------------------------*/
3868 int cmdFinish (char *s, context *ctxt)
3871 if (STACK_EMPTY(callStack)) {
3872 fprintf(stdout,"The program is not running.\n");
3877 if (srcMode == SRC_CMODE) {
3878 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
3879 stepBpCB, ctxt->func->mod->c_name,
3880 ctxt->func->exitline);
3882 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
3883 stepBpCB, ctxt->func->mod->asm_name,
3884 ctxt->func->aexitline);
3894 /*-----------------------------------------------------------------*/
3895 /* cmdShow - show command */
3896 /*-----------------------------------------------------------------*/
3897 int cmdShow (char *s, context *cctxt)
3899 /* skip white space */
3902 if (strcmp(s,"copying") == 0) {
3903 fputs(copying,stdout);
3907 if (strcmp(s,"warranty") == 0) {
3908 fputs(warranty,stdout);