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 -------------------------------------------------------------------------*/
32 /* default number of lines to list out */
34 static int listlines
= LISTLINES
;
36 /* mainly used to retain a reference to the active module being
37 listed. May be used as a general context for other commands if
38 no better context is available */
39 static module
*list_mod
= NULL
;
41 EXTERN_STACK_DCL(callStack
,function
*,1024)
43 #if defined(__APPLE__) && defined(__MACH__)
45 {" GNU GENERAL PUBLIC LICENSE Version 2"};
46 static char *warranty
=
50 " GNU GENERAL PUBLIC LICENSE\n"
51 " Version 2, June 1991\n"
53 " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n"
54 " 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\n"
55 " Everyone is permitted to copy and distribute verbatim copies\n"
56 " of this license document, but changing it is not allowed.\n"
60 " The licenses for most software are designed to take away your\n"
61 "freedom to share and change it. By contrast, the GNU General Public\n"
62 "License is intended to guarantee your freedom to share and change free\n"
63 "software--to make sure the software is free for all its users. This\n"
64 "General Public License applies to most of the Free Software\n"
65 "Foundation's software and to any other program whose authors commit to\n"
66 "using it. (Some other Free Software Foundation software is covered by\n"
67 "the GNU Library General Public License instead.) You can apply it to\n"
68 "your programs, too.\n"
70 " When we speak of free software, we are referring to freedom, not\n"
71 "price. Our General Public Licenses are designed to make sure that you\n"
72 "have the freedom to distribute copies of free software (and charge for\n"
73 "this service if you wish), that you receive source code or can get it\n"
74 "if you want it, that you can change the software or use pieces of it\n"
75 "in new free programs; and that you know you can do these things.\n"
77 " To protect your rights, we need to make restrictions that forbid\n"
78 "anyone to deny you these rights or to ask you to surrender the rights.\n"
79 "These restrictions translate to certain responsibilities for you if you\n"
80 "distribute copies of the software, or if you modify it.\n"
82 " For example, if you distribute copies of such a program, whether\n"
83 "gratis or for a fee, you must give the recipients all the rights that\n"
84 "you have. You must make sure that they, too, receive or can get the\n"
85 "source code. And you must show them these terms so they know their\n"
88 " We protect your rights with two steps: (1) copyright the software, and\n"
89 "(2) offer you this license which gives you legal permission to copy,\n"
90 "distribute and/or modify the software.\n"
92 " Also, for each author's protection and ours, we want to make certain\n"
93 "that everyone understands that there is no warranty for this free\n"
94 "software. If the software is modified by someone else and passed on, we\n"
95 "want its recipients to know that what they have is not the original, so\n"
96 "that any problems introduced by others will not reflect on the original\n"
97 "authors' reputations.\n"
99 " Finally, any free program is threatened constantly by software\n"
100 "patents. We wish to avoid the danger that redistributors of a free\n"
101 "program will individually obtain patent licenses, in effect making the\n"
102 "program proprietary. To prevent this, we have made it clear that any\n"
103 "patent must be licensed for everyone's free use or not licensed at all.\n"
105 " The precise terms and conditions for copying, distribution and\n"
106 "modification follow.\n"
108 " GNU GENERAL PUBLIC LICENSE\n"
109 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
111 " 0. This License applies to any program or other work which contains\n"
112 "a notice placed by the copyright holder saying it may be distributed\n"
113 "under the terms of this General Public License. The \"Program\", below,\n"
114 "refers to any such program or work, and a \"work based on the Program\"\n"
115 "means either the Program or any derivative work under copyright law:\n"
116 "that is to say, a work containing the Program or a portion of it,\n"
117 "either verbatim or with modifications and/or translated into another\n"
118 "language. (Hereinafter, translation is included without limitation in\n"
119 "the term \"modification\".) Each licensee is addressed as \"you\".\n"
121 "Activities other than copying, distribution and modification are not\n"
122 "covered by this License; they are outside its scope. The act of\n"
123 "running the Program is not restricted, and the output from the Program\n"
124 "is covered only if its contents constitute a work based on the\n"
125 "Program (independent of having been made by running the Program).\n"
126 "Whether that is true depends on what the Program does.\n"
128 " 1. You may copy and distribute verbatim copies of the Program's\n"
129 "source code as you receive it, in any medium, provided that you\n"
130 "conspicuously and appropriately publish on each copy an appropriate\n"
131 "copyright notice and disclaimer of warranty; keep intact all the\n"
132 "notices that refer to this License and to the absence of any warranty;\n"
133 "and give any other recipients of the Program a copy of this License\n"
134 "along with the Program.\n"
136 "You may charge a fee for the physical act of transferring a copy, and\n"
137 "you may at your option offer warranty protection in exchange for a fee.\n"
139 " 2. You may modify your copy or copies of the Program or any portion\n"
140 "of it, thus forming a work based on the Program, and copy and\n"
141 "distribute such modifications or work under the terms of Section 1\n"
142 "above, provided that you also meet all of these conditions:\n"
144 " a) You must cause the modified files to carry prominent notices\n"
145 " stating that you changed the files and the date of any change.\n"
147 " b) You must cause any work that you distribute or publish, that in\n"
148 " whole or in part contains or is derived from the Program or any\n"
149 " part thereof, to be licensed as a whole at no charge to all third\n"
150 " parties under the terms of this License.\n"
152 " c) If the modified program normally reads commands interactively\n"
153 " when run, you must cause it, when started running for such\n"
154 " interactive use in the most ordinary way, to print or display an\n"
155 " announcement including an appropriate copyright notice and a\n"
156 " notice that there is no warranty (or else, saying that you provide\n"
157 " a warranty) and that users may redistribute the program under\n"
158 " these conditions, and telling the user how to view a copy of this\n"
159 " License. (Exception: if the Program itself is interactive but\n"
160 " does not normally print such an announcement, your work based on\n"
161 " the Program is not required to print an announcement.)\n"
163 "These requirements apply to the modified work as a whole. If\n"
164 "identifiable sections of that work are not derived from the Program,\n"
165 "and can be reasonably considered independent and separate works in\n"
166 "themselves, then this License, and its terms, do not apply to those\n"
167 "sections when you distribute them as separate works. But when you\n"
168 "distribute the same sections as part of a whole which is a work based\n"
169 "on the Program, the distribution of the whole must be on the terms of\n"
170 "this License, whose permissions for other licensees extend to the\n"
171 "entire whole, and thus to each and every part regardless of who wrote it.\n"
173 "Thus, it is not the intent of this section to claim rights or contest\n"
174 "your rights to work written entirely by you; rather, the intent is to\n"
175 "exercise the right to control the distribution of derivative or\n"
176 "collective works based on the Program.\n"
178 "In addition, mere aggregation of another work not based on the Program\n"
179 "with the Program (or with a work based on the Program) on a volume of\n"
180 "a storage or distribution medium does not bring the other work under\n"
181 "the scope of this License.\n"
183 " 3. You may copy and distribute the Program (or a work based on it,\n"
184 "under Section 2) in object code or executable form under the terms of\n"
185 "Sections 1 and 2 above provided that you also do one of the following:\n"
187 " a) Accompany it with the complete corresponding machine-readable\n"
188 " source code, which must be distributed under the terms of Sections\n"
189 " 1 and 2 above on a medium customarily used for software interchange; or,\n"
191 " b) Accompany it with a written offer, valid for at least three\n"
192 " years, to give any third party, for a charge no more than your\n"
193 " cost of physically performing source distribution, a complete\n"
194 " machine-readable copy of the corresponding source code, to be\n"
195 " distributed under the terms of Sections 1 and 2 above on a medium\n"
196 " customarily used for software interchange; or,\n"
198 " c) Accompany it with the information you received as to the offer\n"
199 " to distribute corresponding source code. (This alternative is\n"
200 " allowed only for noncommercial distribution and only if you\n"
201 " received the program in object code or executable form with such\n"
202 " an offer, in accord with Subsection b above.)\n"
204 "The source code for a work means the preferred form of the work for\n"
205 "making modifications to it. For an executable work, complete source\n"
206 "code means all the source code for all modules it contains, plus any\n"
207 "associated interface definition files, plus the scripts used to\n"
208 "control compilation and installation of the executable. However, as a\n"
209 "special exception, the source code distributed need not include\n"
210 "anything that is normally distributed (in either source or binary\n"
211 "form) with the major components (compiler, kernel, and so on) of the\n"
212 "operating system on which the executable runs, unless that component\n"
213 "itself accompanies the executable.\n"
215 "If distribution of executable or object code is made by offering\n"
216 "access to copy from a designated place, then offering equivalent\n"
217 "access to copy the source code from the same place counts as\n"
218 "distribution of the source code, even though third parties are not\n"
219 "compelled to copy the source along with the object code.\n"
221 " 4. You may not copy, modify, sublicense, or distribute the Program\n"
222 "except as expressly provided under this License. Any attempt\n"
223 "otherwise to copy, modify, sublicense or distribute the Program is\n"
224 "void, and will automatically terminate your rights under this License.\n"
225 "However, parties who have received copies, or rights, from you under\n"
226 "this License will not have their licenses terminated so long as such\n"
227 "parties remain in full compliance.\n"
229 " 5. You are not required to accept this License, since you have not\n"
230 "signed it. However, nothing else grants you permission to modify or\n"
231 "distribute the Program or its derivative works. These actions are\n"
232 "prohibited by law if you do not accept this License. Therefore, by\n"
233 "modifying or distributing the Program (or any work based on the\n"
234 "Program), you indicate your acceptance of this License to do so, and\n"
235 "all its terms and conditions for copying, distributing or modifying\n"
236 "the Program or works based on it.\n"
238 " 6. Each time you redistribute the Program (or any work based on the\n"
239 "Program), the recipient automatically receives a license from the\n"
240 "original licensor to copy, distribute or modify the Program subject to\n"
241 "these terms and conditions. You may not impose any further\n"
242 "restrictions on the recipients' exercise of the rights granted herein.\n"
243 "You are not responsible for enforcing compliance by third parties to\n"
246 " 7. If, as a consequence of a court judgment or allegation of patent\n"
247 "infringement or for any other reason (not limited to patent issues),\n"
248 "conditions are imposed on you (whether by court order, agreement or\n"
249 "otherwise) that contradict the conditions of this License, they do not\n"
250 "excuse you from the conditions of this License. If you cannot\n"
251 "distribute so as to satisfy simultaneously your obligations under this\n"
252 "License and any other pertinent obligations, then as a consequence you\n"
253 "may not distribute the Program at all. For example, if a patent\n"
254 "license would not permit royalty-free redistribution of the Program by\n"
255 "all those who receive copies directly or indirectly through you, then\n"
256 "the only way you could satisfy both it and this License would be to\n"
257 "refrain entirely from distribution of the Program.\n"
259 "If any portion of this section is held invalid or unenforceable under\n"
260 "any particular circumstance, the balance of the section is intended to\n"
261 "apply and the section as a whole is intended to apply in other\n"
264 "It is not the purpose of this section to induce you to infringe any\n"
265 "patents or other property right claims or to contest validity of any\n"
266 "such claims; this section has the sole purpose of protecting the\n"
267 "integrity of the free software distribution system, which is\n"
268 "implemented by public license practices. Many people have made\n"
269 "generous contributions to the wide range of software distributed\n"
270 "through that system in reliance on consistent application of that\n"
271 "system; it is up to the author/donor to decide if he or she is willing\n"
272 "to distribute software through any other system and a licensee cannot\n"
273 "impose that choice.\n"
275 "This section is intended to make thoroughly clear what is believed to\n"
276 "be a consequence of the rest of this License.\n"
278 " 8. If the distribution and/or use of the Program is restricted in\n"
279 "certain countries either by patents or by copyrighted interfaces, the\n"
280 "original copyright holder who places the Program under this License\n"
281 "may add an explicit geographical distribution limitation excluding\n"
282 "those countries, so that distribution is permitted only in or among\n"
283 "countries not thus excluded. In such case, this License incorporates\n"
284 "the limitation as if written in the body of this License.\n"
286 " 9. The Free Software Foundation may publish revised and/or new versions\n"
287 "of the General Public License from time to time. Such new versions will\n"
288 "be similar in spirit to the present version, but may differ in detail to\n"
289 "address new problems or concerns.\n"
291 "Each version is given a distinguishing version number. If the Program\n"
292 "specifies a version number of this License which applies to it and \"any\n"
293 "later version\", you have the option of following the terms and conditions\n"
294 "either of that version or of any later version published by the Free\n"
295 "Software Foundation. If the Program does not specify a version number of\n"
296 "this License, you may choose any version ever published by the Free Software\n"
299 " 10. If you wish to incorporate parts of the Program into other free\n"
300 "programs whose distribution conditions are different, write to the author\n"
301 "to ask for permission. For software which is copyrighted by the Free\n"
302 "Software Foundation, write to the Free Software Foundation; we sometimes\n"
303 "make exceptions for this. Our decision will be guided by the two goals\n"
304 "of preserving the free status of all derivatives of our free software and\n"
305 "of promoting the sharing and reuse of software generally.\n";
307 static char *warranty
=
310 " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
311 "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"
312 "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
313 "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
314 "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
315 "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"
316 "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"
317 "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
318 "REPAIR OR CORRECTION.\n"
320 " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
321 "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
322 "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
323 "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
324 "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
325 "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
326 "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
327 "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
328 "POSSIBILITY OF SUCH DAMAGES.\n";
331 static void printTypeInfo(st_link
*);
332 static void printValAggregates (symbol
*,st_link
*,char,unsigned int,int);
333 static int printOrSetSymValue (symbol
*sym
, context
*cctxt
,
334 int flg
, int dnum
, int fmt
,
335 char *rs
, char *val
, char cmp
);
337 int srcMode
= SRC_CMODE
;
338 set
*dispsymbols
= NULL
; /* set of displayable symbols */
339 static int currentFrame
= 0; /* actual displayed frame */
340 /*-----------------------------------------------------------------*/
341 /* funcWithName - returns function with name */
342 /*-----------------------------------------------------------------*/
343 DEFSETFUNC(funcWithName
)
345 function
*func
= item
;
347 V_ARG(function
**, funcp
);
352 if (strcmp(func
->sym
->name
, name
) == 0)
361 /*-----------------------------------------------------------------*/
362 /* symWithAddr - look for symbol with sfr / sbit address */
363 /*-----------------------------------------------------------------*/
364 DEFSETFUNC(symWithAddr
)
367 V_ARG(unsigned long, laddr
);
368 V_ARG(int, laddrspace
);
369 V_ARG(symbol
**, rsym
);
374 if (sym
->addr
== laddr
&& sym
->addrspace
== laddrspace
)
383 /*-----------------------------------------------------------------*/
384 /* setBPatModLine - set break point at the line specified for the */
385 /*-----------------------------------------------------------------*/
386 static void setBPatModLine (module
*mod
, int line
, char bpType
)
390 /* look for the first executable line after the line
391 specified & get the break point there */
398 fprintf(stderr
, "Internal error: NULL module\n");
402 if (srcMode
== SRC_CMODE
&& line
> mod
->ncLines
)
404 fprintf(stderr
,"No line %d in file \"%s\".\n",
409 if (srcMode
== SRC_AMODE
&& line
> mod
->nasmLines
)
411 fprintf(stderr
,"No line %d in file \"%s\".\n",
418 next_line
< (srcMode
== SRC_CMODE
? mod
->ncLines
: mod
->nasmLines
) ;
421 if (srcMode
== SRC_CMODE
)
423 if (mod
->cLines
[next_line
]->addr
!= INT_MAX
)
425 setBreakPoint (mod
->cLines
[next_line
]->addr
, CODE
, bpType
,
426 userBpCB
, mod
->c_name
, next_line
);
433 if (mod
->asmLines
[next_line
]->addr
!= INT_MAX
)
435 setBreakPoint (mod
->asmLines
[next_line
]->addr
, CODE
, bpType
,
436 userBpCB
, mod
->asm_name
, next_line
);
443 fprintf(stderr
, "No line %d or after in file \"%s\"..\n",
449 /*-----------------------------------------------------------------*/
450 /* clearBPatModLine - clr break point at the line specified */
451 /*-----------------------------------------------------------------*/
452 static void clearBPatModLine (module
*mod
, int line
)
454 /* look for the first executable line after the line
455 specified & get the break point there */
456 if (srcMode
== SRC_CMODE
&& line
> mod
->ncLines
)
458 fprintf(stderr
, "No line %d in file \"%s\".\n",
463 if (srcMode
== SRC_AMODE
&& line
> mod
->ncLines
)
465 fprintf(stderr
, "No line %d in file \"%s\".\n",
471 line
< (srcMode
== SRC_CMODE
? mod
->ncLines
: mod
->nasmLines
) ;
474 if (srcMode
== SRC_CMODE
)
476 if (mod
->cLines
[line
]->addr
)
478 clearUSERbp (mod
->cLines
[line
]->addr
);
484 if (mod
->asmLines
[line
]->addr
)
486 clearUSERbp (mod
->asmLines
[line
]->addr
);
495 /*-----------------------------------------------------------------*/
496 /* moduleLineWithAddr - finds and returns a line with a given address */
497 /*-----------------------------------------------------------------*/
498 DEFSETFUNC(moduleLineWithAddr
)
503 V_ARG(unsigned int, addr
);
504 V_ARG(module
**, rmod
);
510 for (i
= 0; i
< mod
->nasmLines
; i
++)
512 if (mod
->asmLines
[i
]->addr
== addr
)
518 for (i
= 0; i
< mod
->ncLines
; i
++)
520 if (mod
->cLines
[i
]->addr
> addr
)
532 /*-----------------------------------------------------------------*/
533 /* funcWithNameModule - returns functions with a name module combo */
534 /*-----------------------------------------------------------------*/
535 DEFSETFUNC(funcWithNameModule
)
537 function
*func
= item
;
538 V_ARG(char *, fname
);
539 V_ARG(char *, mname
);
540 V_ARG(function
**, funcp
);
545 if (strcmp(func
->sym
->name
, fname
) == 0 &&
546 strcmp(func
->mod
->c_name
, mname
) == 0)
555 /*-----------------------------------------------------------------*/
556 /* funcInAddr - given an address returns the function */
557 /*-----------------------------------------------------------------*/
558 DEFSETFUNC(funcInAddr
)
560 function
*func
= item
;
561 V_ARG(unsigned int, addr
);
562 V_ARG(function
**, funcp
);
567 /* in the address range */
568 if (func
->sym
->addr
<= addr
&& func
->sym
->eaddr
>= addr
)
577 /*-----------------------------------------------------------------*/
578 /* setStepBp - will set STEP Bp @ function entry points */
579 /*-----------------------------------------------------------------*/
580 DEFSETFUNC(setStepBp
)
582 function
*func
= item
;
584 if (func
->sym
&& func
->sym
->addr
)
586 /* set the entry break point */
587 setBreakPoint (func
->sym
->addr
, CODE
, STEP
,
588 stepBpCB
,func
->mod
->c_name
, func
->entryline
);
596 /*-----------------------------------------------------------------*/
597 /* setStepEPBp - sets a given type of bp @ the execution point */
598 /*-----------------------------------------------------------------*/
599 DEFSETFUNC(setStepEPBp
)
603 V_ARG(char *, mname
);
605 setBreakPoint (ep
->addr
, CODE
, bptype
, stepBpCB
, mname
, ep
->line
);
609 /*-----------------------------------------------------------------*/
610 /* setNextEPBp - sets a given type of bp @ the execution point */
611 /*-----------------------------------------------------------------*/
612 DEFSETFUNC(setNextEPBp
)
616 V_ARG(char *, mname
);
618 setBreakPoint (ep
->addr
, CODE
, bptype
, nextBpCB
, mname
, ep
->line
);
622 /*-----------------------------------------------------------------*/
623 /* lineAtAddr - for execution points returns the one with addr */
624 /*-----------------------------------------------------------------*/
625 DEFSETFUNC(lineAtAddr
)
628 V_ARG(unsigned int, addr
);
633 /* address must be an exact match */
634 if (ep
->addr
== addr
)
647 /*-----------------------------------------------------------------*/
648 /* lineNearAddr - for execution points returns the one with addr */
649 /*-----------------------------------------------------------------*/
650 DEFSETFUNC(lineNearAddr
)
653 V_ARG(unsigned int, addr
);
658 /* the line in which the address is */
659 if (ep
->addr
<= addr
)
672 /*-----------------------------------------------------------------*/
673 /* discoverContext - find out the current context of the bp */
674 /*-----------------------------------------------------------------*/
675 context
*discoverContext (unsigned addr
, function
*func
)
680 /* find the function we are in */
681 if (!func
&& !applyToSet(functions
, funcInAddr
, addr
, &func
))
683 if (!applyToSet(functions
, funcWithName
, "_main", &func
) ||
684 !applyToSet(modules
, moduleLineWithAddr
, addr
, &mod
, NULL
))
686 fprintf (stderr
, "addr 0x%x in no module/function (runtime env?)\n",addr
);
689 currCtxt
->func
= func
;
690 currCtxt
->addr
= addr
;
691 currCtxt
->modName
= mod
->name
;
692 currCtxt
->cline
= func
->exitline
;
696 currCtxt
->func
= func
;
697 currCtxt
->addr
= func
->laddr
= addr
;
698 currCtxt
->modName
= func
->modName
;
700 /* find the c line number */
701 if (applyToSet(func
->cfpoints
, lineAtAddr
, addr
, &line
,
702 &currCtxt
->block
, &currCtxt
->level
))
703 currCtxt
->cline
= func
->lline
= line
;
704 else if (applyToSet(func
->cfpoints
, lineNearAddr
, addr
, &line
,
705 &currCtxt
->block
, &currCtxt
->level
))
706 currCtxt
->cline
= func
->lline
= line
;
708 currCtxt
->cline
= -1;
710 /* find the asm line number */
712 if (applyToSet(func
->afpoints
, lineAtAddr
, addr
, &line
, NULL
, NULL
))
713 currCtxt
->asmline
= line
;
715 currCtxt
->asmline
= -1;
720 /*-----------------------------------------------------------------*/
721 /* simGo - send 'go' cmd to simulator and wait till a break occurs */
722 /*-----------------------------------------------------------------*/
723 void simGo (unsigned int gaddr
)
738 function
*func
= NULL
;
739 if (applyToSet(functions
, funcInAddr
, gaddr
, &func
))
740 STACK_PUSH(callStack
, func
);
742 addr
= simGoTillBp (gaddr
);
744 /* got the pc for the break point now first
745 discover the program context i.e. module, function
746 linenumber of the source etc, etc etc */
748 ctxt
= discoverContext (addr
, NULL
);
750 /* dispatch all the break point call back functions */
751 rv
= dispatchCB (addr
, ctxt
);
753 /* the dispatch call back function will return
754 non-zero if an user break point has been hit
755 if not then we continue with the execution
761 if ( gaddr
== -1 || doingSteps
== 1 )
766 /*-----------------------------------------------------------------*/
767 /* preparePrint - common parse function for set variable, */
768 /* output, print and display */
769 /*-----------------------------------------------------------------*/
770 static char *preparePrint (char *s
, context
*cctxt
, int *fmt
, symbol
**sym
)
784 /* format of printout */
804 for ( bp
= s
; *bp
&& ( isalnum( *bp
) || *bp
== '_' || *bp
== '$'); bp
++ );
810 *sym
= symLookup(s
, cctxt
);
814 fprintf(stdout
,"No symbol \"%s\" in current context.\n", s
);
818 static int printAsmLine (function
*func
, module
*m
, unsigned saddr
, unsigned eaddr
)
822 unsigned lastaddr
= saddr
+1;
827 symaddr
= func
->sym
->addr
;
828 symname
= func
->sym
->name
;
835 for (j
=0, i
=0; i
< m
->nasmLines
; i
++)
837 if (saddr
>= 0 && m
->asmLines
[i
]->addr
< saddr
)
841 if (eaddr
>= 0 && m
->asmLines
[i
]->addr
> eaddr
)
846 (m
->asmLines
[i
]->addr
< func
->sym
->addr
||
847 m
->asmLines
[i
]->addr
> func
->sym
->eaddr
))
851 delta
= m
->asmLines
[i
]->addr
- symaddr
;
855 lastaddr
= m
->asmLines
[i
]->addr
;
856 printf("0x%08x <%s", lastaddr
, symname
);
858 printf("+%d", delta
);
859 printf(">:\t%s", m
->asmLines
[i
]->src
);
865 /*-----------------------------------------------------------------*/
866 /* cmdDisasm - disassemble asm instruction */
867 /*-----------------------------------------------------------------*/
868 static int cmdDisasm (char *s
, context
*cctxt
, int args
)
870 function
*func
= NULL
;
875 /* white space skip */
883 saddr
= strtol(s
, &s
, 0);
889 eaddr
= strtol(s
, 0, 0);
900 /* no start or only start so dump function */
907 applyToSet(functions
, funcInAddr
, saddr
, &func
);
911 printf("Dump of assembler code for function %s:\n", func
->sym
->name
);
912 printAsmLine(func
, func
->mod
, -1, -1);
913 printf("End of assembler dump.\n");
918 if (applyToSet(modules
, moduleLineWithAddr
, saddr
, &modul
, NULL
))
921 printf("Dump of assembler code:\n");
922 printAsmLine(NULL
, modul
, saddr
, eaddr
);
923 printf("End of assembler dump.\n");
931 printf("Dump of assembler code from 0x%08lx to 0x%08lx:\n", saddr
, eaddr
);
933 while ( saddr
< eaddr
)
936 if (applyToSet(functions
, funcInAddr
, saddr
, &func
))
945 if (!applyToSet(modules
, moduleLineWithAddr
, saddr
, &modul
, NULL
))
948 saddr
= printAsmLine(func
, modul
, saddr
, eaddr
) + 1;
953 printf("End of assembler dump.\n");
957 fprintf(stderr
,"No function contains specified address.\n");
961 sprintf(lbuf
, "dis 0x%lx 0 %ld\n", saddr
, (eaddr
== -1) ? 1L : eaddr
-saddr
);
963 waitForSim(1000, NULL
);
964 fputs(simResponse(), stdout
);
968 /*-----------------------------------------------------------------*/
969 /* cmdDisasm1 - disassemble one asm instruction */
970 /*-----------------------------------------------------------------*/
971 int cmdDisasm1 (char *s
, context
*cctxt
)
973 return cmdDisasm(s
, cctxt
, 1);
976 /*-----------------------------------------------------------------*/
977 /* cmdDisasmF - disassemble asm instructions */
978 /*-----------------------------------------------------------------*/
979 int cmdDisasmF(char *s
, context
*cctxt
)
981 return cmdDisasm(s
, cctxt
, 2);
984 static int commonSetUserBp(char *s
, context
*cctxt
, char bpType
)
987 function
*func
= NULL
;
989 /* user break point location specification can be of the following
991 a) <nothing> - break point at current location
992 b) lineno - number of the current module
993 c) filename:lineno - line number of the given file
994 e) filename:function- function X in file Y (useful for static functions)
995 f) function - function entry point
996 g) *addr - break point at address
1001 fprintf (stdout
, "No symbol table is loaded. Use the \"file\" command.\n");
1004 /* trim left and right */
1007 /* case a) nothing */
1008 /* if nothing given then current location : we know
1009 the current execution location from the currentContext */
1012 /* if current context is known */
1015 Dprintf (D_break
, ("commonSetUserBp: a) cctxtaddr:%x \n", cctxt
->addr
));
1016 if (srcMode
== SRC_CMODE
)
1018 /* set the break point */
1019 setBreakPoint (cctxt
->addr
, CODE
, bpType
, userBpCB
,
1020 cctxt
->func
->mod
->c_name
, cctxt
->cline
);
1024 setBreakPoint (cctxt
->addr
, CODE
, bpType
, userBpCB
,
1025 cctxt
->func
->mod
->asm_name
, cctxt
->asmline
);
1030 fprintf(stderr
, "No default breakpoint address now.\n");
1036 if (*s
== '*' && isdigit(*(s
+1)))
1039 long braddr
= strtol(s
+1, 0, 0);
1040 if (!applyToSet (functions
, funcInAddr
, braddr
, &func
))
1043 if (!applyToSet (modules
, moduleLineWithAddr
, braddr
, &modul
, &line
))
1045 fprintf (stderr
, "Address 0x%08lx not exists in code.\n", braddr
);
1049 Dprintf (D_break
, ("commonSetUserBp: g) addr:%lx \n", braddr
));
1050 setBreakPoint (braddr
, CODE
, bpType
, userBpCB
, modul
->c_name
, line
);
1056 int line
= func
->exitline
;
1057 if (!applyToSet (func
->cfpoints
, lineAtAddr
, braddr
, &line
, NULL
, NULL
))
1059 applyToSet (func
->cfpoints
, lineNearAddr
, braddr
, &line
, NULL
, NULL
);
1061 setBreakPoint (braddr
, CODE
, bpType
, userBpCB
, func
->mod
->c_name
, line
);
1065 /* case b) lineno */
1066 /* check if line number */
1067 if (!strchr(s
, ':') && isdigit(*s
))
1069 /* get the lineno */
1070 int line
= atoi(s
) -1;
1071 Dprintf (D_break
, ("commonSetUserBp: b) line:%d \n", line
));
1074 fprintf(stdout
, "linenumber <= 0\n");
1077 /* if current context not present then we must get the module
1078 which has main & set the break point @ line number provided
1079 of that module : if current context known then set the bp
1080 at the line number given for the current module
1084 if (!cctxt
->func
->mod
)
1086 if (!applyToSet (functions
, funcWithName
, "main", &func
))
1088 fprintf (stderr
, "Function \"main\" not defined.\n");
1092 setBPatModLine (func
->mod
, line
, bpType
);
1097 setBPatModLine(cctxt
->func
->mod
,line
, bpType
);
1104 setBPatModLine (list_mod
, line
, bpType
);
1108 fprintf (stdout
, "Sdcdb fails to have module symbol context at %d\n", __LINE__
);
1115 if ((bp
= strchr(s
, ':')))
1120 if (srcMode
== SRC_CMODE
)
1122 if (!applyToSet (modules
, moduleWithCName
, s
, &mod
))
1124 fprintf (stderr
, "No source file named %s.\n", s
);
1130 if (!applyToSet (modules
, moduleWithAsmName
, s
, &mod
))
1132 fprintf (stderr
, "No source file named %s.\n", s
);
1137 /* case c) filename:lineno */
1138 if (isdigit(*(bp
+1)))
1140 Dprintf (D_break
, ("commonSetUserBp: c) line:%d \n", atoi(bp
+1)));
1141 setBPatModLine (mod
, atoi(bp
+1)-1, bpType
);
1144 /* case d) filename:function */
1145 if (!applyToSet (functions
, funcWithNameModule
, bp
+1, s
, &func
))
1147 fprintf(stderr
, "Function \"%s\" not defined.\n", bp
+1);
1151 Dprintf (D_break
, ("commonSetUserBp: d) \n"));
1152 setBPatModLine (mod
,
1153 (srcMode
== SRC_CMODE
?
1155 func
->aentryline
), bpType
);
1160 /* case e) function */
1161 Dprintf (D_break
, ("commonSetUserBp: e) \n"));
1162 if (!applyToSet (functions
, funcWithName
, s
, &func
))
1164 fprintf(stderr
, "Function \"%s\" not defined.\n", s
);
1168 setBPatModLine (func
->mod
,
1169 (srcMode
== SRC_CMODE
?
1171 func
->aentryline
), bpType
);
1178 /*-----------------------------------------------------------------*/
1179 /* cmdSetTmpUserBp - settempory break point at the user specified location */
1180 /*-----------------------------------------------------------------*/
1181 int cmdSetTmpUserBp (char *s
, context
*cctxt
)
1183 return commonSetUserBp (s
, cctxt
, TMPUSER
);
1186 /*-----------------------------------------------------------------*/
1187 /* cmdSetUserBp - set break point at the user specified location */
1188 /*-----------------------------------------------------------------*/
1189 int cmdSetUserBp (char *s
, context
*cctxt
)
1191 return commonSetUserBp (s
, cctxt
, USER
);
1194 /*-----------------------------------------------------------------*/
1195 /* cmdJump - set program counter */
1196 /*-----------------------------------------------------------------*/
1197 int cmdJump (char *s
, context
*cctxt
)
1200 if (STACK_EMPTY(callStack
))
1202 fprintf (stdout
, "The program is not running.\n");
1206 /* trim left and right */
1211 fprintf (stdout
, "No argument: need line or *addr.\n");
1214 if (*s
== '*' && isdigit(*(s
+1)))
1216 unsigned int addr
= atoi(s
);
1217 if (cctxt
&& cctxt
->func
&&
1218 cctxt
->func
->sym
->addr
<= addr
&&
1219 cctxt
->func
->sym
->eaddr
>= addr
)
1224 fprintf (stdout
, "Warning addr 0x%x outside actual function.\n", addr
);
1230 /* get the lineno */
1231 int line
= atoi(s
) -1;
1232 if (!cctxt
|| !cctxt
->func
|| !cctxt
->func
->mod
)
1234 fprintf (stderr
, "Function not defined.\n");
1237 if (line
>= cctxt
->func
->entryline
&&
1238 line
<= cctxt
->func
->exitline
)
1240 simSetPC (cctxt
->func
->mod
->cLines
[line
]->addr
);
1243 if (line
>= cctxt
->func
->mod
->ncLines
)
1245 fprintf (stderr
, "line not in module.\n");
1248 fprintf (stdout
, "Warning line %d outside actual function.\n", line
+1);
1249 simSetPC (cctxt
->func
->mod
->cLines
[line
]->addr
);
1252 if ((bp
= strchr(s
,':')))
1257 if (!applyToSet (modules
, moduleWithCName
, s
, &mod
))
1259 fprintf (stderr
, "No source file named %s.\n", s
);
1264 fprintf (stderr
, "No line number.\n");
1268 if (line
>= mod
->ncLines
)
1270 fprintf (stderr
, "line not in module.\n");
1273 if ( mod
!= cctxt
->func
->mod
||
1274 line
< cctxt
->func
->entryline
||
1275 line
> cctxt
->func
->exitline
)
1277 fprintf (stdout
, "Warning line %d outside actual function.\n", line
+1);
1279 simSetPC (mod
->cLines
[line
]->addr
);
1284 /*-----------------------------------------------------------------*/
1285 /* cmdListAsm - list assembler source code */
1286 /*-----------------------------------------------------------------*/
1287 int cmdListAsm (char *s
, context
*cctxt
)
1289 if (cctxt
&& cctxt
->func
)
1292 if (cctxt
->addr
!= INT_MAX
)
1294 if (printAsmLine (cctxt
->func
, cctxt
->func
->mod
,
1295 cctxt
->addr
, cctxt
->addr
))
1302 /*-----------------------------------------------------------------*/
1303 /* cmdSetOption - set debugger options */
1304 /*-----------------------------------------------------------------*/
1305 int cmdSetOption (char *s
, context
*cctxt
)
1308 if (strncmp (s
, "srcmode", 7) == 0)
1310 if (srcMode
== SRC_CMODE
)
1311 srcMode
= SRC_AMODE
;
1313 srcMode
= SRC_CMODE
;
1314 fprintf (stderr
,"source mode set to '%s'\n",
1315 (srcMode
== SRC_CMODE
? "C" : "asm"));
1319 if (strncmp (s
, "listsize ", 9) == 0)
1321 listlines
= strtol(s
+9, 0, 0);
1322 if (listlines
< LISTLINES
)
1323 listlines
= LISTLINES
;
1328 if (strncmp(s
,"debug ",6) == 0)
1330 sdcdbDebug
= strtol(s
+6, 0, 0);
1334 if (strncmp (s
, "variable ", 9) == 0)
1340 if (!(rs
= preparePrint (s
, cctxt
, &fmt
, &sym
)))
1343 while (*s
&& *s
!= '=')
1349 printOrSetSymValue (sym
, cctxt
, 0, 0, 0, rs
, s
, '\0');
1354 fprintf (stdout
, "No new value for \"%s\".\n", s
);
1359 fprintf (stderr
, "'set %s' command not yet implemented\n", s
);
1363 /*-----------------------------------------------------------------*/
1364 /* cmdContinue - continue till next break point */
1365 /*-----------------------------------------------------------------*/
1366 int cmdContinue (char *s
, context
*cctxt
)
1368 if (STACK_EMPTY(callStack
))
1370 fprintf(stdout
, "The program is not being run.\n");
1374 fprintf(stdout
, "Continuing.\n");
1380 /*-----------------------------------------------------------------*/
1381 /* cmdIgnore - set ignorecount for breakpoint */
1382 /*-----------------------------------------------------------------*/
1383 int cmdIgnore (char *s
, context
*cctxt
)
1389 fprintf(stdout
, "Argument required (breakpoint number).\n");
1392 bpnum
= strtol (s
, &s
, 10);
1396 fprintf (stdout
, "Second argument (specified ignore-count) is missing.");
1399 cnt
= strtol (s
, 0, 10);
1400 setUserbpIgnCount (bpnum
, cnt
);
1404 /*-----------------------------------------------------------------*/
1405 /* cmdCondition - set condition for breakpoint */
1406 /*-----------------------------------------------------------------*/
1407 int cmdCondition (char *s
, context
*cctxt
)
1413 fprintf (stdout
, "Argument required (breakpoint number).\n");
1416 bpnum
= strtol (s
, &s
, 10);
1422 setUserbpCondition (bpnum
, s
);
1426 /*-----------------------------------------------------------------*/
1427 /* cmdCommands - set commands for breakpoint */
1428 /*-----------------------------------------------------------------*/
1429 int cmdCommands (char *s
, context
*cctxt
)
1436 bpnum
= getLastBreakptNumber();
1438 bpnum
= strtol (s
, 0, 10);
1441 while ((line
= getNextCmdLine()))
1443 line
= trim_left (line
);
1444 if (!strncmp (line
, "end", 3))
1448 cmds
= Safe_strdup (line
);
1452 cmds
= Safe_realloc (cmds
, strlen(cmds
) + 1 + strlen(line
));
1453 strcat (cmds
, line
);
1456 setUserbpCommand (bpnum
, cmds
);
1460 /*-----------------------------------------------------------------*/
1461 /* cmdDelUserBp - delete user break point */
1462 /*-----------------------------------------------------------------*/
1463 int cmdDelUserBp (char *s
, context
*cctxt
)
1473 fprintf (stdout
, "Delete all breakpoints? (y or n) ");
1475 if (fgets (buffer
, sizeof(buffer
), stdin
) && toupper(buffer
[0]) == 'Y')
1481 /* determine the break point number */
1482 if (sscanf (s
, "%d",&bpnum
) == 1)
1483 deleteUSERbp (bpnum
);
1488 /*-----------------------------------------------------------------*/
1489 /* cmdStepi - single step exactly one instruction */
1490 /*-----------------------------------------------------------------*/
1491 int cmdStepi (char *s
, context
*cctxt
)
1493 if (0 /*STACK_EMPTY(callStack)*/)
1495 fprintf (stdout
, "The program is not being run.\n");
1507 /*-----------------------------------------------------------------*/
1508 /* cmdStep - single step thru C source file */
1509 /*-----------------------------------------------------------------*/
1510 int cmdStep (char *s
, context
*cctxt
)
1512 function
*func
= NULL
;
1514 if (STACK_EMPTY (callStack
))
1516 fprintf (stdout
, "The program is not being run.\n");
1520 /* if we are @ the end of a function then set
1521 break points at execution points of the
1522 function in the call stack... */
1523 if (cctxt
->addr
== cctxt
->func
->sym
->eaddr
)
1525 if ((func
= STACK_PEEK (callStack
)))
1527 if (srcMode
== SRC_CMODE
)
1528 applyToSet (func
->cfpoints
, setStepEPBp
, STEP
,
1531 applyToSet (func
->afpoints
, setStepEPBp
, STEP
,
1532 func
->mod
->asm_name
);
1537 /* set breakpoints at all function entry points
1538 and all exepoints of this functions & for
1539 all functions one up in the call stack */
1541 /* all function entry points */
1542 applyToSet (functions
, setStepBp
);
1544 if (srcMode
== SRC_CMODE
)
1546 /* for all execution points in this function */
1547 applyToSet (cctxt
->func
->cfpoints
, setStepEPBp
, STEP
,
1548 cctxt
->func
->mod
->c_name
);
1550 /* set a break point @ the current function's
1552 setBreakPoint (cctxt
->func
->sym
->eaddr
, CODE
, STEP
,
1553 stepBpCB
, cctxt
->func
->mod
->c_name
,
1554 cctxt
->func
->exitline
);
1556 /* now break point @ callers execution points */
1557 if ((func
= STACK_PPEEK (callStack
)))
1559 applyToSet (func
->cfpoints
, setStepEPBp
, STEP
,
1561 /* set bp @ callers exit point */
1562 setBreakPoint (func
->sym
->eaddr
, CODE
, STEP
,
1563 stepBpCB
, func
->mod
->c_name
,
1569 /* for all execution points in this function */
1570 applyToSet (cctxt
->func
->afpoints
, setStepEPBp
, STEP
,
1571 cctxt
->func
->mod
->asm_name
);
1573 /* set a break point @ the current function's
1575 setBreakPoint (cctxt
->func
->sym
->eaddr
, CODE
, STEP
,
1576 stepBpCB
, cctxt
->func
->mod
->asm_name
,
1577 cctxt
->func
->aexitline
);
1579 /* now break point @ callers execution points */
1580 if ((func
= STACK_PPEEK (callStack
)))
1582 applyToSet (func
->afpoints
, setStepEPBp
, STEP
,
1583 func
->mod
->asm_name
);
1585 /* set bp @ callers exit point */
1586 setBreakPoint (func
->sym
->eaddr
, CODE
, STEP
,
1587 stepBpCB
, func
->mod
->asm_name
,
1601 /*-----------------------------------------------------------------*/
1602 /* cmdNexti - next instruction but proceed function call */
1603 /*-----------------------------------------------------------------*/
1604 int cmdNexti (char *s
, context
*cctxt
)
1606 if (STACK_EMPTY (callStack
))
1608 fprintf (stdout
, "The program is not being run.\n");
1620 /*-----------------------------------------------------------------*/
1621 /* cmdNext - next executable C statement file */
1622 /*-----------------------------------------------------------------*/
1623 int cmdNext (char *s
, context
*cctxt
)
1625 function
*func
= NULL
;
1626 /* next is almost the same as step except we don't
1627 we don't set break point for all function entry
1629 if (STACK_EMPTY (callStack
))
1631 fprintf (stdout
, "The program is not being run.\n");
1635 /* if we are @ the end of a function then set
1636 break points at execution points of the
1637 function in the call stack... */
1638 if (cctxt
->addr
== cctxt
->func
->sym
->eaddr
)
1640 if ((func
= STACK_PEEK (callStack
)))
1642 if (srcMode
== SRC_CMODE
)
1643 applyToSet (func
->cfpoints
, setStepEPBp
, NEXT
,
1646 applyToSet (func
->afpoints
, setStepEPBp
, NEXT
,
1647 func
->mod
->asm_name
);
1652 if (srcMode
== SRC_CMODE
)
1654 /* for all execution points in this function */
1655 applyToSet (cctxt
->func
->cfpoints
, setNextEPBp
, NEXT
,
1656 cctxt
->func
->mod
->c_name
);
1657 /* set a break point @ the current function's
1659 setBreakPoint (cctxt
->func
->sym
->eaddr
, CODE
, NEXT
,
1660 nextBpCB
, cctxt
->func
->mod
->c_name
,
1661 cctxt
->func
->exitline
);
1663 /* now break point @ callers execution points */
1664 if ((func
= STACK_PPEEK(callStack
)))
1666 applyToSet (func
->cfpoints
, setNextEPBp
, NEXT
,
1668 /* set bp @ callers exit point */
1669 setBreakPoint (func
->sym
->eaddr
, CODE
, NEXT
,
1670 stepBpCB
, func
->mod
->c_name
,
1676 /* for all execution points in this function */
1677 applyToSet (cctxt
->func
->afpoints
, setNextEPBp
, NEXT
,
1678 cctxt
->func
->mod
->asm_name
);
1679 /* set a break point @ the current function's
1681 setBreakPoint (cctxt
->func
->sym
->eaddr
, CODE
, NEXT
,
1682 nextBpCB
, cctxt
->func
->mod
->asm_name
,
1683 cctxt
->func
->aexitline
);
1685 /* now break point @ callers execution points */
1686 if ((func
= STACK_PPEEK (callStack
)))
1688 applyToSet (func
->cfpoints
, setNextEPBp
, NEXT
,
1689 func
->mod
->asm_name
);
1690 /* set bp @ callers exit point */
1691 setBreakPoint (func
->sym
->eaddr
, CODE
, NEXT
,
1692 stepBpCB
, func
->mod
->asm_name
,
1705 /*-----------------------------------------------------------------*/
1706 /* cmdRun - run till next break point */
1707 /*-----------------------------------------------------------------*/
1708 int cmdRun (char *s
, context
*cctxt
)
1711 if (STACK_EMPTY (callStack
))
1713 fprintf (stdout
, "Starting program\n");
1716 fprintf (stdout
, "No executable file specified.\nUse the \"file\" command.\n");
1724 fprintf (stdout
, "The program being debugged has been started already.\n");
1725 fprintf (stdout
, "Start it from the beginning? (y or n) ");
1728 if (fgets (buff
, sizeof(buff
), stdin
) && toupper(buff
[0]) == 'Y')
1739 /*-----------------------------------------------------------------
1740 cmdListSymbols - list symbols
1741 |-----------------------------------------------------------------*/
1742 int cmdListSymbols (char *s
, context
*cctxt
)
1744 int our_verbose
= 0;
1748 if (strstr (s
, "v1"))
1752 else if (strstr (s
, "v2"))
1757 printf ("[symbols]\n");
1758 sy
= setFirstItem (symbols
);
1764 if (our_verbose
<= 1)
1765 printf ("<%s>", sy
->name
);
1767 if (our_verbose
> 1)
1769 printf (" %d) name:%s, size:%d, level:%d block:%d\n", i
,
1770 sy
->name
, sy
->size
, sy
->level
, sy
->block
);
1771 printf (" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1772 sy
->isonstack
, sy
->isfunc
, sy
->offset
, sy
->addr
);
1773 printf (" eaddr:%d, addr_type:%c, type:%p etype:%p\n",
1774 sy
->eaddr
, sy
->addr_type
, sy
->type
, sy
->etype
);
1775 printf (" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1776 sy
->scopetype
, sy
->sname
, sy
->rname
, sy
->addrspace
);
1777 printf (" next:%p\n", sy
->next
);
1780 sy
= setNextItem (symbols
);
1782 printf (" %d symbols\n", i
);
1786 /*-----------------------------------------------------------------
1787 cmdListFunctions - list functions.
1788 |-----------------------------------------------------------------*/
1789 int cmdListFunctions (char *s
, context
*cctxt
)
1793 int our_verbose
= 0;
1795 if (strstr (s
, "v1"))
1799 else if (strstr (s
, "v2"))
1804 printf ("[functions]\n");
1805 f
= setFirstItem (functions
);
1811 printf (" %d) sym:%p, fname:%s, modName:%s, mod:%p\n", i
,
1812 f
->sym
, f
->sym
->name
, f
->modName
, f
->mod
);
1813 printf (" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1814 f
->entryline
, f
->aentryline
, f
->exitline
, f
->aexitline
);
1815 printf (" cfpoints:%p, afpoints:%p, laddr:%x, lline:%d\n",
1816 f
->cfpoints
, f
->afpoints
, f
->laddr
, f
->lline
);
1820 printf ("<%s>", f
->sym
->name
);
1823 f
= setNextItem (functions
);
1825 printf (" %d functions\n", i
);
1829 /*-----------------------------------------------------------------
1830 cmdListModules - list modules.
1831 |-----------------------------------------------------------------*/
1832 int cmdListModules (char *s
, context
*cctxt
)
1837 int our_verbose
= 0;
1839 if (strstr (s
, "v1"))
1843 else if (strstr (s
, "v2"))
1848 printf ("[modules]\n");
1849 m
= setFirstItem (modules
);
1856 if (our_verbose
>= 0)
1858 printf (" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi
,
1859 m
->cfullname
, m
->afullname
, m
->name
);
1860 printf (" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1861 m
->c_name
, m
->asm_name
, m
->ncLines
, m
->nasmLines
);
1862 printf (" cLines:%p, asmLines:%p\n",
1863 m
->cLines
, m
->asmLines
);
1865 if (our_verbose
>= 2)
1869 printf (" [cLines] ");
1872 for (i
= 0; i
< m
->ncLines
; i
++)
1875 printf (" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1876 i
, cs
->addr
, cs
->block
, cs
->level
, cs
->src
);
1882 printf (" [asmLines] ");
1885 for (i
= 0; i
< m
->nasmLines
; i
++)
1887 as
= m
->asmLines
[i
];
1888 printf (" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1889 i
, as
->addr
, as
->block
, as
->level
, as
->src
);
1895 m
= setNextItem (modules
);
1900 /*-----------------------------------------------------------------
1901 infoSymbols - This is really just a tool to dump all these
1902 huge program structures out into human readable form.
1903 |-----------------------------------------------------------------*/
1904 static void infoSymbols (context
*ctxt
)
1906 int our_verbose
= 0;
1908 printf ("[context:%p] func:%p modName:%s addr:%x\n",
1909 ctxt
, ctxt
->func
, ctxt
->modName
, ctxt
->addr
);
1911 printf (" cline:%d asmline:%d block:%d level:%d\n",
1912 ctxt
->cline
, ctxt
->asmline
, ctxt
->block
, ctxt
->level
);
1914 printf ("[globals] currCtxt:%p, modules:%p, functions:%p symbols:%p\n",
1915 currCtxt
, modules
, functions
, symbols
);
1916 printf (" nStructs:%d, structs:%p, ssdirl:%s\n",
1917 nStructs
, structs
, ssdirl
);
1919 /**************** modules *******************/
1924 printf ("[modules]\n");
1925 m
= setFirstItem (modules
);
1931 printf (" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi
,
1932 m
->cfullname
, m
->afullname
, m
->name
);
1933 printf (" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1934 m
->c_name
, m
->asm_name
, m
->ncLines
, m
->nasmLines
);
1935 printf (" cLines:%p, asmLines:%p\n",
1936 m
->cLines
, m
->asmLines
);
1940 cs
= m
->cLines
[i
++];
1941 printf (" [cLines] ");
1945 printf (" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1946 i
, cs
->addr
, cs
->block
, cs
->level
, cs
->src
);
1947 cs
= m
->cLines
[i
++];
1950 printf ("%d records", i
);
1955 as
= m
->asmLines
[i
++];
1956 printf (" [asmLines] ");
1960 printf (" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1961 i
, as
->addr
, as
->block
, as
->level
, as
->src
);
1962 as
= m
->asmLines
[i
++];
1965 printf ("%d records", i
);
1969 m
= setNextItem (modules
);
1973 /**************** functions *******************/
1977 printf ("[functions]\n");
1978 f
= setFirstItem (functions
);
1986 printf (" %d) sym:%p, modName:%s, mod:%p\n", i
,
1987 f
->sym
, f
->modName
, f
->mod
);
1988 printf (" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1989 f
->entryline
, f
->aentryline
, f
->exitline
, f
->aexitline
);
1990 printf (" cfpoints:%p, afpoints:%p, laddr:%x, lline:%d\n",
1991 f
->cfpoints
, f
->afpoints
, f
->laddr
, f
->lline
);
1994 f
= setNextItem (functions
);
1997 printf (" %d functions\n", i
);
2000 /**************** symbols *******************/
2004 printf ("[symbols]\n");
2005 s
= setFirstItem (symbols
);
2013 printf (" %d) name:%s, size:%d, level:%d block:%d\n", i
,
2014 s
->name
, s
->size
, s
->level
, s
->block
);
2015 printf (" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
2016 s
->isonstack
, s
->isfunc
, s
->offset
, s
->addr
);
2017 printf (" eaddr:%d, addr_type:%c, type:%p etype:%p\n",
2018 s
->eaddr
, s
->addr_type
, s
->type
, s
->etype
);
2019 printf (" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
2020 s
->scopetype
, s
->sname
, s
->rname
, s
->addrspace
);
2021 printf (" next:%p\n", s
->next
);
2024 s
= setNextItem (symbols
);
2027 printf (" %d symbols\n", i
);
2032 /*-----------------------------------------------------------------*/
2033 /* infoRegisters - print register information */
2034 /*-----------------------------------------------------------------*/
2035 static void infoRegisters (int all
, context
*ctxt
)
2037 static int regaddrs
[] = {0x81,0x82,0x83,0xb8,0xd0,0xe0,0xf0,0};
2041 i
= simGetValue (0xd0, 'I', 1);
2042 fprintf (stdout
, "IP : 0x%04X RegisterBank %d:\nR0-7:", ctxt
->addr
, (i
>>3)&3);
2043 for (j
= 0; j
< 8 ; j
++)
2045 val
= simGetValue (j
, 'R', 1);
2046 fprintf(stdout
," 0x%02lX", val
);
2048 fprintf(stdout
, "\n");
2049 val
= simGetValue (0xe0, 'I', 1);
2050 fprintf (stdout
, "ACC : 0x%02lX %lu %c\n", val
, val
, isprint(val
) ? (char)val
: '.');
2051 val
= simGetValue (0xf0, 'I', 1);
2052 fprintf (stdout
, "B : 0x%02lX %lu %c\n", val
, val
, isprint(val
) ? (char)val
: '.');
2053 val
= simGetValue (0x82, 'I', 2);
2054 fprintf (stdout
, "DPTR: 0x%04lX %lu\n", val
, val
);
2055 val
= simGetValue (0x81, 'I', 1);
2056 fprintf (stdout
, "SP : 0x%02lX (0x%04lX)\n", val
, val
? simGetValue (val
-1, 'B', 2) : 0);
2057 fprintf (stdout
, "PSW : 0x%02X | CY : %c | AC : %c | OV : %c | P : %c\n",
2058 i
, (i
&0x80)?'1':'0', (i
&0x40)?'1':'0', (i
&4)?'1':'0', (i
&1)?'1':'0');
2061 fprintf (stdout
, "Special Function Registers:\n");
2063 for (i
= 0x80 ; i
< 0x100 ; i
++)
2066 if ( *r
&& *r
== i
)
2068 /* skip normal registers */
2072 if (applyToSetFTrue (sfrsymbols
, symWithAddr
, i
, 'I', &sym
))
2074 val
= simGetValue (sym
->addr
, sym
->addrspace
, sym
->size
);
2075 fprintf (stdout
,"%s : 0x%02lx", sym
->name
, val
);
2078 for (j
= 0 ; j
< 8 ; j
++)
2081 if (applyToSetFTrue (sfrsymbols
, symWithAddr
, i
+j
, 'J', &sym
))
2083 //val = simGetValue (sym->addr, sym->addrspace, sym->size);
2084 fprintf (stdout
," %s=%c", sym
->name
, (val
&1)? '1':'0');
2089 fprintf (stdout
,"\n");
2095 /*-----------------------------------------------------------------*/
2096 /* infoStack - print call stack information */
2097 /*-----------------------------------------------------------------*/
2098 static void infoStack(context
*ctxt
)
2103 STACK_STARTWALK(callStack
) ;
2104 while ((func
= STACK_WALK(callStack
)))
2106 Dprintf (D_break
, ("break: infoStack: %s %p (%p)\n", func
->sym
->name
, w_callStack
, p_callStack
));
2108 fprintf (stdout
, "#%d 0x%08x in %s () at %s:%d\n", i
++,
2109 func
->laddr
, func
->sym
->name
,
2110 func
->mod
->c_name
, func
->lline
+1);
2113 fprintf (stdout
, "no stack.\n");
2116 /*-----------------------------------------------------------------*/
2117 /* cmdWhere - where command */
2118 /*-----------------------------------------------------------------*/
2119 int cmdWhere (char *s
, context
*cctxt
)
2125 static int infomode
= 0;
2126 /*-----------------------------------------------------------------*/
2127 /* cmdInfo - info command */
2128 /*-----------------------------------------------------------------*/
2129 int cmdInfo (char *s
, context
*cctxt
)
2133 fprintf (stdout
, "No executable file specified.\nUse the \"file\" command.\n");
2137 /* trim left and_right*/
2140 /* list all break points */
2141 if (strncmp (s
, "break", 5) == 0)
2147 /* info frame same as frame */
2148 if (strncmp (s
, "frame", 5) == 0)
2150 cmdFrame (s
+5, cctxt
);
2154 if (strncmp (s
, "line", 4) == 0)
2157 cmdListSrc (s
+4, cctxt
);
2160 if (strncmp (s
, "source", 6) == 0)
2166 fprintf (stdout
, "Source files for which symbols have been read in:\n\n");
2167 for (m
= setFirstItem(modules
); m
; m
= setNextItem(modules
))
2169 fprintf (stdout
, "%s%s, %s", k
? ", ":"", m
->cfullname
, m
->afullname
);
2172 fprintf(stdout
,"\n");
2176 if (!cctxt
|| !cctxt
->func
|| !cctxt
->func
->mod
)
2178 fprintf (stdout
, "No source file loaded\n");
2181 m
= cctxt
->func
->mod
;
2182 fprintf (stdout
, "Current source file is %s\n", m
->c_name
);
2183 fprintf (stdout
, "Located in %s\n", m
->cfullname
);
2184 fprintf (stdout
, "Contains %d lines.\nSource language is c.\n",
2189 if (strcmp (s
, "functions") == 0)
2193 fprintf(stdout
, "All defined functions:\n");
2194 for ( f
= setFirstItem(functions
); f
; f
= setNextItem(functions
))
2199 fprintf (stdout
, "\nFile %s\n", m
->c_name
);
2201 fprintf (stdout
, "%s();\n", f
->sym
->name
);
2205 /* info stack display call stack */
2206 if (strcmp (s
, "stack") == 0)
2213 /* info stack display call stack */
2214 if (strcmp (s
, "registers") == 0)
2216 infoRegisters (0, cctxt
);
2220 /* info stack display call stack */
2221 if (strcmp (s
, "all-registers") == 0)
2223 infoRegisters (1, cctxt
);
2227 /* info stack display call stack */
2228 if (strcmp (s
, "symbols") == 0)
2230 /* dump out symbols we have read in */
2231 fprintf (stdout
, "Dumping symbols...\n");
2232 infoSymbols (cctxt
);
2236 if (strcmp (s
, "variables") == 0)
2238 /* dump out symbols we have read in */
2239 fprintf (stdout
, "Dumping symbols...\n");
2240 infoSymbols (cctxt
);
2244 fprintf (stdout
, "Undefined info command: \"%s\". Try \"help\n", s
);
2248 /*-----------------------------------------------------------------*/
2249 /* cmdQuit - quit debugging */
2250 /*-----------------------------------------------------------------*/
2251 int cmdQuit (char *s
, context
*cctxt
)
2258 /*-----------------------------------------------------------------*/
2259 /* cmdListSrc - list src */
2260 /*-----------------------------------------------------------------*/
2261 int cmdListSrc (char *s
, context
*cctxt
)
2263 static int currline
= 0;
2266 int llines
= listlines
;
2267 function
*func
= NULL
;
2271 /* if the user has spcified line numer then the line number
2272 can be of the following formats
2273 LINE - just line number
2274 FILE:LINE - filename line number
2275 FILE:LINE,LASTLINE + last line
2276 FUNCTION - list a function
2277 FILE:FUNCTION - function in file */
2284 if (!cctxt
|| !cctxt
->func
|| !cctxt
->func
->mod
)
2288 fprintf (stdout
, "Sdcdb fails to have a proper context at %d.\n", __LINE__
);
2294 list_mod
= cctxt
->func
->mod
;
2296 pline
= strtol (s
, &s
, 10) - 1;
2297 if (s
&& (s
= strchr(s
,',')))
2300 llines
= strtol (s
+1, 0, 10);
2311 /* if ':' present then FILE:LINE || FILE:FUNCTION */
2312 if ((bp
= strchr(s
,':')))
2319 list_mod
=NULL
; /* bug fix 2-09-02, moduleWithCName expects mod to be null */
2320 if (srcMode
== SRC_CMODE
)
2322 if (!applyToSet (modules
, moduleWithCName
, s
, &list_mod
))
2324 fprintf (stderr
,"No c source file named %s.\n",s
);
2330 if (!applyToSet (modules
, moduleWithAsmName
, s
, &list_mod
))
2332 fprintf (stderr
, "No source file named %s.\n", s
);
2336 pline
= strtol (bp
, &bp
, 10) - 1;
2337 if (bp
&& (bp
= strchr (bp
, ',')))
2339 /* FILE:LINE,LASTLINE */
2340 llines
= strtol (bp
+1, 0, 10);
2350 if (!applyToSet (functions
, funcWithNameModule
, bp
, s
, &func
))
2352 fprintf (stdout
, "Function \"%s\" not defined.\n", bp
);
2355 list_mod
= func
->mod
;
2356 if (srcMode
== SRC_CMODE
)
2358 pline
= func
->entryline
;
2359 llines
= func
->exitline
- func
->entryline
+ 1;
2363 pline
= func
->aentryline
;
2364 llines
= func
->aexitline
- func
->aentryline
+ 1;
2375 if ((bp
= strrchr(s
,'\'')))
2380 if (!applyToSet (functions
, funcWithName
, s
, &func
))
2382 fprintf (stderr
, "Function \"%s\" not defined.\n", s
);
2387 list_mod
= func
->mod
;
2388 if (srcMode
== SRC_CMODE
)
2390 pline
= func
->entryline
;
2391 llines
= func
->exitline
- func
->entryline
+ 1;
2395 pline
= func
->aentryline
;
2396 llines
= func
->aexitline
- func
->aentryline
+ 1;
2404 /* if no line specified & we had listed
2405 before then continue from that listing */
2410 if (!cctxt
|| !cctxt
->func
|| !cctxt
->func
->mod
)
2412 fprintf (stdout
, "Missing context at %d. Try list filename:lineno\n", __LINE__
);
2415 list_mod
= cctxt
->func
->mod
;
2416 if (srcMode
== SRC_CMODE
)
2417 pline
= cctxt
->cline
;
2419 pline
= cctxt
->asmline
;
2425 fprintf (stdout
, "Sdcdb fails to have a valid module context at %d.\n", __LINE__
);
2433 unsigned firstaddr
, lastaddr
;
2435 if (pline
>= list_mod
->ncLines
)
2439 fprintf (stdout
, "Missing context at %d. Try list filename:lineno\n", __LINE__
);
2444 pline
= cctxt
->cline
;
2448 firstaddr
= lastaddr
= list_mod
->cLines
[pline
]->addr
;
2449 if (!func
&& cctxt
&& cctxt
->func
)
2451 fprintf (stdout
, "Line %d of \"%s\" starts at address 0x%08x <%s+%d>",
2453 list_mod
->c_name
, lastaddr
,
2454 func
? func
->sym
->name
: "?",
2455 func
? lastaddr
-func
->sym
->addr
: 0);
2457 for ( ; pline
< list_mod
->ncLines
; pline
++)
2459 if (list_mod
->cLines
[pline
]->addr
> lastaddr
)
2461 lastaddr
= list_mod
->cLines
[pline
]->addr
-1;
2465 fprintf (stdout
, " and ends at 0x%08x <%s+%d>.\n",
2467 func
? func
->sym
->name
: "?",
2468 func
? lastaddr
-func
->sym
->addr
: 0);
2471 fprintf (stdout
, "\032\032%s:%d:1:beg:0x%08x\n",
2472 func
->mod
->cfullname
,
2478 for ( i
= 0 ; i
< llines
; i
++ )
2480 if (srcMode
== SRC_CMODE
)
2482 if ( (pline
+i
) >= list_mod
->ncLines
)
2484 fprintf (stdout
, "%d\t%s", pline
+i
,
2485 list_mod
->cLines
[pline
+i
]->src
);
2489 if ( (pline
+i
) >= list_mod
->nasmLines
)
2491 fprintf (stdout
, "%d\t%s", pline
+i
,
2492 list_mod
->asmLines
[pline
+i
]->src
);
2495 currline
= pline
+i
;
2499 static unsigned long getValBasic (symbol
*sym
, st_link
*type
, char *val
)
2517 v
.f
= (float)strtod (val
, NULL
);
2519 else if (IS_PTR (type
))
2521 v
.val
= strtol (val
, NULL
, 0);
2523 else if (IS_INTEGRAL (type
))
2531 if (IS_CHAR (etype
))
2533 if (( s
= strchr (val
, '\'')))
2536 v
.b
[0] = (unsigned char)strtol (s
+2, NULL
, 8);
2542 v
.b
[0] = (unsigned char)strtol(val
,NULL
,0);
2545 else if (IS_INT (etype
))
2547 if (IS_LONG (etype
))
2548 v
.val
= strtol (val
, NULL
, 0);
2550 v
.i
.lo
= (unsigned short)strtol (val
, NULL
, 0);
2554 v
.val
= strtol (val
, NULL
, 0);
2559 v
.val
= strtol (val
, NULL
, 0);
2564 /*-----------------------------------------------------------------*/
2565 /* printFmtInteger - print value in bin,oct,dec or hex */
2566 /*-----------------------------------------------------------------*/
2567 static void printFmtInteger (char *deffmt
,int fmt
, long val
,
2570 static char digits
[] =
2572 '0' , '1' , '2' , '3' , '4' , '5' ,
2573 '6' , '7' , '8' , '9' , 'a' , 'b' ,
2574 'c' , 'd' , 'e' , 'f' , 'g' , 'h'
2576 static int radixOfFormat
[] = { 0 , 2, 8 ,10, 16 };
2577 static int olenOfSize
[] = { 0 , 3, 6 , 8, 11 };
2583 if ( fmt
== FMT_NON
|| fmt
== FMT_DEZ
)
2585 fprintf (stdout
, deffmt
, val
);
2588 radix
= radixOfFormat
[fmt
];
2591 if ( sign && val < 0 )
2599 while (val
<= -radix
)
2601 buf
[charPos
--] = digits
[-(val
% radix
)];
2604 buf
[charPos
] = digits
[-val
];
2609 radix
= olenOfSize
[size
];
2619 while (charPos
> 39 - radix
)
2621 buf
[--charPos
] = '0';
2626 if ( buf
[charPos
] != '0' )
2627 buf
[--charPos
] = '0';
2630 buf
[--charPos
] = 'x';
2631 buf
[--charPos
] = '0';
2636 buf
[--charPos
] = '-';
2638 fputs (&buf
[charPos
], stdout
);
2641 /*-----------------------------------------------------------------*/
2642 /* printValBasic - print value of basic types */
2643 /*-----------------------------------------------------------------*/
2644 static void printValBasic (symbol
*sym
, st_link
*type
,
2645 char mem
, unsigned addr
,int size
, int fmt
)
2660 v
.val
= simGetValue (addr
, mem
, size
);
2661 /* if this a floating point number then */
2662 if (IS_FLOAT (type
))
2664 fprintf (stdout
, "%f", v
.f
);
2666 else if (IS_PTR (type
))
2668 fprintf (stdout
, "0x%*lx", size
<<1, v
.val
);
2670 else if (IS_INTEGRAL (type
))
2677 if (IS_CHAR (etype
))
2679 if (isprint (v
.val
))
2680 printFmtInteger ((SPEC_USIGN(etype
)?"0x%02x":"'%c'"),
2681 fmt
, (long)v
.val
, 0, size
);
2683 printFmtInteger ((SPEC_USIGN(etype
)?"0x%02x":"'\\%o'"),
2684 fmt
, (long)v
.val
, 0, size
);
2686 else if (IS_INT (etype
))
2688 if (IS_LONG (etype
))
2689 if (SPEC_USIGN (etype
))
2690 printFmtInteger ("%u", fmt
, (long)v
.val
, 0, size
);
2692 printFmtInteger ("%d", fmt
, (long)v
.sval
, 1, size
);
2694 if (SPEC_USIGN (etype
))
2695 printFmtInteger ("%u", fmt
, (long)v
.i
.lo
, 0, size
);
2697 printFmtInteger ("%d", fmt
, (long)v
.i
.lo
, 1, size
);
2699 else if (IS_BITVAR (etype
))
2701 fprintf (stdout
, "%c", (v
.val
?'1':'0'));
2705 fprintf (stdout
, "0x%0*lx", size
<<1, v
.val
);
2710 fprintf (stdout
, "0x%0*lx", size
<<1, v
.val
);
2714 /*-----------------------------------------------------------------*/
2715 /* printValFunc - prints function values */
2716 /*-----------------------------------------------------------------*/
2717 static void printValFunc (symbol
*sym
, int fmt
)
2719 fprintf (stdout
, "print function not yet implemented");
2722 /*-----------------------------------------------------------------*/
2723 /* printArrayValue - will print the values of array elements */
2724 /*-----------------------------------------------------------------*/
2725 static void printArrayValue (symbol
*sym
, st_link
*type
,
2726 char space
, unsigned int addr
, int fmt
)
2728 st_link
*elem_type
= type
->next
;
2731 fprintf (stdout
, "{");
2732 for (i
= 0 ; i
< DCL_ELEM (type
) ; i
++)
2734 if (IS_AGGREGATE (elem_type
))
2736 printValAggregates (sym
, elem_type
, space
, addr
, fmt
);
2740 printValBasic (sym
, elem_type
, space
, addr
, getSize (elem_type
), fmt
);
2742 addr
+= getSize (elem_type
);
2743 if (i
!= DCL_ELEM (type
) -1)
2744 fprintf (stdout
, ",");
2747 fprintf (stdout
, "}");
2750 /*-----------------------------------------------------------------*/
2751 /* printStructValue - prints structures elements */
2752 /*-----------------------------------------------------------------*/
2753 static void printStructValue (symbol
*sym
, st_link
*type
,
2754 char space
, unsigned int addr
, int fmt
)
2756 symbol
*fields
= SPEC_STRUCT(type
)->fields
;
2759 fprintf (stdout
, " { ");
2762 fprintf (stdout
, "%s%s = ",(first
? "": ", "), fields
->name
);
2764 if (IS_AGGREGATE (fields
->type
))
2766 printValAggregates (fields
, fields
->type
, space
, addr
, fmt
);
2770 printValBasic (fields
, fields
->type
, space
, addr
, getSize(fields
->type
), fmt
);
2772 addr
+= getSize (fields
->type
);
2773 fields
= fields
->next
;
2775 fprintf (stdout
, "}");
2778 /*-----------------------------------------------------------------*/
2779 /* printValAggregates - print value of aggregates */
2780 /*-----------------------------------------------------------------*/
2781 static void printValAggregates (symbol
*sym
, st_link
*type
,
2782 char space
,unsigned int addr
, int fmt
)
2784 if (IS_ARRAY (type
))
2786 printArrayValue (sym
, type
, space
, addr
, fmt
);
2790 if (IS_STRUCT (type
))
2792 printStructValue (sym
, type
, space
, addr
, fmt
);
2797 /*-----------------------------------------------------------------*/
2798 /* printOrSetSymValue - print or set value of a symbol */
2799 /*-----------------------------------------------------------------*/
2800 static int printOrSetSymValue (symbol
*sym
, context
*cctxt
,
2801 int flg
, int dnum
, int fmt
, char *rs
,
2802 char *val
, char cmp
)
2804 static char fmtChar
[] = " todx ";
2805 static int stack
= 1;
2808 unsigned int addr
, size
;
2811 char save_ch
, save_ch2
;
2813 /* if it is on stack then compute address & fall thru */
2816 symbol
*bp
= symLookup ("bp", cctxt
);
2819 fprintf (stdout
, "cannot determine stack frame\n");
2823 sym
->addr
= simGetValue (bp
->addr
, bp
->addrspace
, bp
->size
) + sym
->offset
;
2826 /* get the value from the simulator and print it */
2833 fprintf (stdout
, "$%d = ", stack
++);
2836 fprintf (stdout
, "%d: ", dnum
);
2837 if ( fmt
!= FMT_NON
)
2838 fprintf (stdout
, "/%c ", fmtChar
[fmt
]);
2839 fprintf (stdout
, "%s%s = ", sym
->name
, rs
);
2849 if (*rs
== '[' && IS_ARRAY(type
))
2852 while (*rs
&& *rs
!= ']')
2856 if ( ! isdigit (*s
))
2858 /* index seems a variable */
2859 for (s2
= s
; *s2
&& (isalnum (*s2
) || *s2
== '_'); s2
++);
2863 fields
= symLookup (s
, cctxt
);
2867 fprintf (stdout
, "Unknown variable \"%s\" for index.\n", s
);
2870 /* arrays & structures first */
2871 if (! IS_INTEGRAL (fields
->type
))
2873 fprintf (stdout
, "Wrong type of variable \"%s\" for index \n", s
);
2876 n
= simGetValue (fields
->addr
, fields
->addrspace
, getSize (fields
->type
));
2880 n
= strtol (s
, 0, 0);
2882 if (n
< 0 || n
>= DCL_ELEM (type
))
2884 fprintf (stdout
, "Wrong index %d.\n", n
);
2888 size
= getSize (type
);
2892 else if (*rs
== '.' && IS_STRUCT (type
))
2895 /* search structure element */
2896 for (rs
= s
; *rs
&& (isalnum (*rs
) || *rs
== '_'); rs
++);
2900 for (fields
= SPEC_STRUCT (type
)->fields
; fields
; fields
= fields
->next
)
2902 if (!(strcmp (s
, fields
->name
)))
2908 fprintf (stdout
, "Unknown field \"%s\" of structure\n", s
);
2911 type
= fields
->type
;
2912 size
= getSize (type
);
2913 addr
+= fields
->offset
;
2921 if (IS_AGGREGATE (type
)) /* arrays & structures first */
2925 fprintf (stdout
, "Cannot set/compare aggregate variable\n");
2930 printValAggregates (sym
, type
, sym
->addrspace
, addr
, fmt
);
2933 else if (IS_FUNC (type
)) /* functions */
2936 printValFunc (sym
, fmt
);
2944 unsigned long newval
;
2945 newval
= getValBasic (sym
, type
, val
);
2950 lval
= simGetValue (addr
, sym
->addrspace
, size
);
2953 case '<' : return ( lval
< newval
? 1:0 ); break;
2954 case '>' : return ( lval
> newval
? 1:0 ); break;
2955 case 'l' : return ( lval
<= newval
? 1:0 ); break;
2956 case 'g' : return ( lval
>= newval
? 1:0 ); break;
2957 case '=' : return ( lval
== newval
? 1:0 ); break;
2958 case '!' : return ( lval
!= newval
? 1:0 ); break;
2963 if ( sym
->addrspace
== 'I' && addr
== 0xb8 )
2965 /* Symbol with address of IP */
2967 cctxt
->addr
= newval
;
2968 simSetPC (cctxt
->addr
);
2972 simSetValue (addr
, sym
->addrspace
, size
, newval
);
2979 printValBasic (sym
, type
, sym
->addrspace
, addr
, size
, fmt
);
2983 fprintf (stdout
, "\n");
2987 /*-----------------------------------------------------------------*/
2988 /* printStructInfo - print out structure information */
2989 /*-----------------------------------------------------------------*/
2990 static void printStructInfo (structdef
*sdef
)
2992 symbol
*field
= sdef
->fields
;
2998 field
= field
->next
;
3001 fprintf (stdout
, "%s %s {\n",(i
? "struct" : "union" ), sdef
->tag
);
3002 field
= sdef
->fields
;
3005 printTypeInfo (field
->type
);
3006 fprintf (stdout
, " %s ;\n", field
->name
);
3007 field
= field
->next
;
3010 fprintf (stdout
, "}\n");
3013 /*-----------------------------------------------------------------*/
3014 /* printTypeInfo - print out the type information */
3015 /*-----------------------------------------------------------------*/
3016 static void printTypeInfo (st_link
*p
)
3023 switch (DCL_TYPE (p
))
3026 printTypeInfo (p
->next
);
3027 fprintf (stdout
, "()");
3030 printTypeInfo (p
->next
);
3031 fprintf (stdout
, "[%d]", DCL_ELEM (p
));
3037 printTypeInfo (p
->next
);
3038 fprintf (stdout
, "(_near *)");
3042 printTypeInfo (p
->next
);
3043 fprintf (stdout
, "(_xdata *)");
3047 printTypeInfo (p
->next
);
3048 fprintf (stdout
, "(_code *)");
3052 printTypeInfo (p
->next
);
3053 fprintf (stdout
, "(_generic *)");
3059 switch (SPEC_NOUN (p
)) /* depending on the specifier type */
3062 (IS_LONG (p
) ? fputs ("long ", stdout
) :
3063 IS_SHORT(p
) ? fputs ("short ", stdout
) :
3064 fputs ("int ", stdout
));
3067 fputs ("float ", stdout
);
3071 fputs ("char ", stdout
);
3075 fputs ("void ", stdout
);
3079 printStructInfo (SPEC_STRUCT (p
));
3083 fputs ("sbit ", stdout
);
3087 fprintf (stdout
, ": %d", SPEC_BLEN(p
));
3093 /*-----------------------------------------------------------------*/
3094 /* conditionIsTrue - compare variable with constant value */
3095 /*-----------------------------------------------------------------*/
3096 int conditionIsTrue (char *s
, context
*cctxt
)
3100 char *rs
, *dup
, cmp_char
;
3101 dup
= s
= Safe_strdup (s
);
3102 if ( !( rs
= preparePrint (s
, cctxt
, &fmt
, &sym
)) || !sym
)
3104 else if (!( s
= strpbrk (rs
,"<>=!")))
3112 /* if <= or >= an other char is used
3113 * == or != not checked in switch
3117 case '>': cmp_char
= 'g' ; break;
3118 case '<': cmp_char
= 'l' ; break;
3123 fmt
= printOrSetSymValue (sym
, cctxt
, 0, 0, 0, rs
, s
, cmp_char
);
3129 /*-----------------------------------------------------------------*/
3130 /* cmdPrint - print value of variable */
3131 /*-----------------------------------------------------------------*/
3132 int cmdPrint (char *s
, context
*cctxt
)
3137 if ( !(rs
= preparePrint (s
, cctxt
, &fmt
, &sym
)))
3142 printOrSetSymValue (sym
, cctxt
, 1, 0, fmt
, rs
, NULL
, '\0');
3147 /*-----------------------------------------------------------------*/
3148 /* cmdOutput - print value of variable without number and newline */
3149 /*-----------------------------------------------------------------*/
3150 int cmdOutput (char *s
, context
*cctxt
)
3155 if ( !(rs
= preparePrint (s
, cctxt
, &fmt
, &sym
)))
3160 printOrSetSymValue (sym
, cctxt
, 0, 0, fmt
, rs
, NULL
, '\0');
3165 /** find display entry with this number */
3167 DEFSETFUNC (dsymWithNumber
)
3169 dsymbol
*dsym
= item
;
3171 V_ARG (dsymbol
**, dsymp
);
3173 if ( dsym
->dnum
== dnum
)
3181 /*-----------------------------------------------------------------*/
3182 /* displayAll - display all valid variables */
3183 /*-----------------------------------------------------------------*/
3184 void displayAll (context
*cctxt
)
3189 for (dsym
= setFirstItem (dispsymbols
);
3191 dsym
= setNextItem (dispsymbols
))
3193 symbol
*sym
= symLookup (dsym
->name
, cctxt
);
3195 printOrSetSymValue (sym
, cctxt
, 2, dsym
->dnum
, dsym
->fmt
,
3196 dsym
->rs
, NULL
, '\0');
3200 /*-----------------------------------------------------------------*/
3201 /* cmdDisplay - display value of variable */
3202 /*-----------------------------------------------------------------*/
3203 int cmdDisplay (char *s
, context
*cctxt
)
3205 static int dnum
= 1;
3209 if ( !(rs
= preparePrint (s
, cctxt
, &fmt
, &sym
)))
3217 dsymbol
*dsym
= (dsymbol
*)Safe_calloc (1, sizeof(dsymbol
));
3218 dsym
->dnum
= dnum
++ ;
3219 dsym
->name
= sym
->name
;
3221 dsym
->rs
= gc_strdup (rs
);
3222 addSetHead (&dispsymbols
, dsym
);
3227 /*-----------------------------------------------------------------*/
3228 /* cmdUnDisplay - undisplay value of variable */
3229 /*-----------------------------------------------------------------*/
3230 int cmdUnDisplay (char *s
, context
*cctxt
)
3238 for (dsym
= setFirstItem (dispsymbols
);
3240 dsym
= setNextItem (dispsymbols
))
3242 Safe_free (dsym
->rs
);
3245 deleteSet (&dispsymbols
);
3250 dnum
= strtol (s
, &s
, 10);
3251 if (applyToSetFTrue (dispsymbols
, dsymWithNumber
, dnum
, &dsym
))
3253 deleteSetItem (&dispsymbols
, dsym
);
3254 Safe_free (dsym
->rs
);
3259 fprintf (stdout
, "Arguments must be display numbers.\n");
3265 /*-----------------------------------------------------------------*/
3266 /* cmdPrintType - print type of a variable */
3267 /*-----------------------------------------------------------------*/
3268 int cmdPrintType (char *s
, context
*cctxt
)
3272 /* trim left and right */
3277 if ((sym
= symLookup (s
, cctxt
)))
3279 printTypeInfo (sym
->type
);
3280 fprintf (stdout
, "\n");
3284 fprintf (stdout
, "No symbol \"%s\" in current context.\n", s
);
3289 /*-----------------------------------------------------------------*/
3290 /* cmdClrUserBp - clear user break point */
3291 /*-----------------------------------------------------------------*/
3292 int cmdClrUserBp (char *s
, context
*cctxt
)
3295 function
*func
= NULL
;
3297 /* clear break point location specification can be of the following
3299 a) <nothing> - break point at current location
3300 b) lineno - number of the current module
3301 c) filename:lineno - line number of the given file
3302 e) filename:function- function X in file Y (useful for static functions)
3303 f) function - function entry point
3308 fprintf (stdout
, "No symbol table is loaded. Use the \"file\" command.\n");
3312 /* trim left and right */
3315 /* case a) nothing */
3316 /* if nothing given then current location : we know
3317 the current execution location from the currentContext */
3320 /* if current context is known */
3322 /* clear the break point @ current location */
3323 clearUSERbp (cctxt
->addr
);
3325 fprintf (stderr
, "No default breakpoint address now.\n");
3330 /* case b) lineno */
3331 /* check if line number */
3334 /* get the lineno */
3335 int line
= atoi (s
);
3337 /* if current context not present then we must get the module
3338 which has main & set the break point @ line number provided
3339 of that module : if current context known then set the bp
3340 at the line number given for the current module
3344 if (!cctxt
->func
->mod
)
3346 if (!applyToSet (functions
, funcWithName
, "main", &func
))
3347 fprintf (stderr
, "Function \"main\" not defined.\n");
3349 clearBPatModLine (func
->mod
, line
);
3353 clearBPatModLine (cctxt
->func
->mod
, line
);
3360 if ((bp
= strchr (s
, ':')))
3365 if (!applyToSet (modules
, moduleWithCName
, s
, &mod
))
3367 fprintf (stderr
, "No source file named %s.\n", s
);
3371 /* case c) filename:lineno */
3372 if (isdigit (*(bp
+1)))
3374 clearBPatModLine (mod
, atoi (bp
+1));
3377 /* case d) filename:function */
3378 if (!applyToSet (functions
, funcWithNameModule
, bp
+1, s
, &func
))
3379 fprintf (stderr
, "Function \"%s\" not defined.\n", bp
+1);
3381 clearBPatModLine (mod
, func
->entryline
);
3386 /* case e) function */
3387 if (!applyToSet (functions
, funcWithName
, s
, &func
))
3388 fprintf (stderr
, "Function \"%s\" not defined.\n", s
);
3390 clearBPatModLine (func
->mod
, func
->entryline
);
3396 /*-----------------------------------------------------------------*/
3397 /* cmdSimulator - send command to simulator */
3398 /*-----------------------------------------------------------------*/
3399 int cmdSimulator (char *s
, context
*cctxt
)
3403 if (strlen (s
) > 80)
3405 printf ("error 3A\n");
3409 strcat (tmpstr
, "\n");
3411 waitForSim (200, NULL
);
3412 fprintf (stdout
, "%s", simResponse());
3416 void setMainContext()
3418 function
*func
= NULL
;
3420 if (!applyToSet (functions
, funcWithName
, "_main", &func
) &&
3421 !applyToSet (functions
, funcWithName
, "main", &func
))
3425 discoverContext (func
->sym
->addr
, func
);
3428 function
*needExtraMainFunction (void)
3430 function
*func
= NULL
;
3431 if (!applyToSet (functions
, funcWithName
, "_main", &func
))
3433 if (applyToSet (functions
, funcWithName
, "main", &func
))
3441 static void printFrame (void)
3444 function
*func
= NULL
;
3446 if ( currentFrame
< 0 )
3449 fprintf (stdout
, "Bottom (i.e., innermost) frame selected; you cannot go down.\n");
3452 STACK_STARTWALK (callStack
) ;
3453 for ( i
= 0; i
<= currentFrame
; i
++ )
3455 func
= STACK_WALK (callStack
);
3459 fprintf (stdout
, "Initial frame selected; you cannot go up.\n");
3463 fprintf (stdout
, "#%d 0x%08x in %s () at %s:%d\n",
3464 currentFrame
, func
->laddr
, func
->sym
->name
, func
->mod
->c_name
, func
->lline
+1);
3465 fprintf (stdout
, "\032\032%s:%d:1:beg:0x%08x\n",
3466 func
->mod
->cfullname
, func
->lline
+1, func
->laddr
);
3468 discoverContext (func
->laddr
, func
);
3472 /*-----------------------------------------------------------------*/
3473 /* cmdUp - Up command */
3474 /*-----------------------------------------------------------------*/
3475 int cmdUp (char *s
, context
*cctxt
)
3479 currentFrame
+= strtol (s
, 0, 10);
3487 /*-----------------------------------------------------------------*/
3488 /* cmdDown - down command */
3489 /*-----------------------------------------------------------------*/
3490 int cmdDown (char *s
, context
*cctxt
)
3494 currentFrame
-= strtol (s
, 0, 10);
3502 /*-----------------------------------------------------------------*/
3503 /* cmdFrame - Frame command */
3504 /*-----------------------------------------------------------------*/
3505 int cmdFrame (char *s
, context
*cctxt
)
3509 currentFrame
= strtol (s
, 0, 10);
3514 /*-----------------------------------------------------------------*/
3515 /* cmdFinish - exec till end of current function */
3516 /*-----------------------------------------------------------------*/
3517 int cmdFinish (char *s
, context
*ctxt
)
3519 if (STACK_EMPTY (callStack
))
3521 fprintf (stdout
, "The program is not running.\n");
3525 if (srcMode
== SRC_CMODE
)
3527 setBreakPoint (ctxt
->func
->sym
->eaddr
, CODE
, STEP
,
3528 stepBpCB
, ctxt
->func
->mod
->c_name
,
3529 ctxt
->func
->exitline
);
3533 setBreakPoint (ctxt
->func
->sym
->eaddr
, CODE
, STEP
,
3534 stepBpCB
, ctxt
->func
->mod
->asm_name
,
3535 ctxt
->func
->aexitline
);
3543 /*-----------------------------------------------------------------*/
3544 /* cmdShow - show command */
3545 /*-----------------------------------------------------------------*/
3546 int cmdShow (char *s
, context
*cctxt
)
3548 /* skip white space */
3551 if (strcmp (s
, "copying") == 0)
3553 fputs (copying
, stdout
);
3557 if (strcmp (s
, "warranty") == 0)
3559 fputs (warranty
, stdout
);