1 /*-------------------------------------------------------------------------
2 cmd.c - source file for debugger command execution
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
31 /* default number of lines to list out */
34 /* mainly used to retain a reference to the active module being
35 listed. May be used as a general context for other commands if
36 no better context is available */
37 static module *list_mod = NULL;
39 EXTERN_STACK_DCL(callStack,function *,1024);
41 #if defined(__APPLE__) && defined(__MACH__)
43 {" GNU GENERAL PUBLIC LICENSE Version 2"};
44 static char *warranty=
48 " GNU GENERAL PUBLIC LICENSE
51 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
52 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
53 Everyone is permitted to copy and distribute verbatim copies
54 of this license document, but changing it is not allowed.
58 The licenses for most software are designed to take away your
59 freedom to share and change it. By contrast, the GNU General Public
60 License is intended to guarantee your freedom to share and change free
61 software--to make sure the software is free for all its users. This
62 General Public License applies to most of the Free Software
63 Foundation's software and to any other program whose authors commit to
64 using it. (Some other Free Software Foundation software is covered by
65 the GNU Library General Public License instead.) You can apply it to
68 When we speak of free software, we are referring to freedom, not
69 price. Our General Public Licenses are designed to make sure that you
70 have the freedom to distribute copies of free software (and charge for
71 this service if you wish), that you receive source code or can get it
72 if you want it, that you can change the software or use pieces of it
73 in new free programs; and that you know you can do these things.
75 To protect your rights, we need to make restrictions that forbid
76 anyone to deny you these rights or to ask you to surrender the rights.
77 These restrictions translate to certain responsibilities for you if you
78 distribute copies of the software, or if you modify it.
80 For example, if you distribute copies of such a program, whether
81 gratis or for a fee, you must give the recipients all the rights that
82 you have. You must make sure that they, too, receive or can get the
83 source code. And you must show them these terms so they know their
86 We protect your rights with two steps: (1) copyright the software, and
87 (2) offer you this license which gives you legal permission to copy,
88 distribute and/or modify the software.
90 Also, for each author's protection and ours, we want to make certain
91 that everyone understands that there is no warranty for this free
92 software. If the software is modified by someone else and passed on, we
93 want its recipients to know that what they have is not the original, so
94 that any problems introduced by others will not reflect on the original
97 Finally, any free program is threatened constantly by software
98 patents. We wish to avoid the danger that redistributors of a free
99 program will individually obtain patent licenses, in effect making the
100 program proprietary. To prevent this, we have made it clear that any
101 patent must be licensed for everyone's free use or not licensed at all.
103 The precise terms and conditions for copying, distribution and
106 GNU GENERAL PUBLIC LICENSE
107 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
109 0. This License applies to any program or other work which contains
110 a notice placed by the copyright holder saying it may be distributed
111 under the terms of this General Public License. The \"Program\", below,
112 refers to any such program or work, and a \"work based on the Program\"
113 means either the Program or any derivative work under copyright law:
114 that is to say, a work containing the Program or a portion of it,
115 either verbatim or with modifications and/or translated into another
116 language. (Hereinafter, translation is included without limitation in
117 the term \"modification\".) Each licensee is addressed as \"you\".
119 Activities other than copying, distribution and modification are not
120 covered by this License; they are outside its scope. The act of
121 running the Program is not restricted, and the output from the Program
122 is covered only if its contents constitute a work based on the
123 Program (independent of having been made by running the Program).
124 Whether that is true depends on what the Program does.
126 1. You may copy and distribute verbatim copies of the Program's
127 source code as you receive it, in any medium, provided that you
128 conspicuously and appropriately publish on each copy an appropriate
129 copyright notice and disclaimer of warranty; keep intact all the
130 notices that refer to this License and to the absence of any warranty;
131 and give any other recipients of the Program a copy of this License
132 along with the Program.
134 You may charge a fee for the physical act of transferring a copy, and
135 you may at your option offer warranty protection in exchange for a fee.
137 2. You may modify your copy or copies of the Program or any portion
138 of it, thus forming a work based on the Program, and copy and
139 distribute such modifications or work under the terms of Section 1
140 above, provided that you also meet all of these conditions:
142 a) You must cause the modified files to carry prominent notices
143 stating that you changed the files and the date of any change.
145 b) You must cause any work that you distribute or publish, that in
146 whole or in part contains or is derived from the Program or any
147 part thereof, to be licensed as a whole at no charge to all third
148 parties under the terms of this License.
150 c) If the modified program normally reads commands interactively
151 when run, you must cause it, when started running for such
152 interactive use in the most ordinary way, to print or display an
153 announcement including an appropriate copyright notice and a
154 notice that there is no warranty (or else, saying that you provide
155 a warranty) and that users may redistribute the program under
156 these conditions, and telling the user how to view a copy of this
157 License. (Exception: if the Program itself is interactive but
158 does not normally print such an announcement, your work based on
159 the Program is not required to print an announcement.)
161 These requirements apply to the modified work as a whole. If
162 identifiable sections of that work are not derived from the Program,
163 and can be reasonably considered independent and separate works in
164 themselves, then this License, and its terms, do not apply to those
165 sections when you distribute them as separate works. But when you
166 distribute the same sections as part of a whole which is a work based
167 on the Program, the distribution of the whole must be on the terms of
168 this License, whose permissions for other licensees extend to the
169 entire whole, and thus to each and every part regardless of who wrote it.
171 Thus, it is not the intent of this section to claim rights or contest
172 your rights to work written entirely by you; rather, the intent is to
173 exercise the right to control the distribution of derivative or
174 collective works based on the Program.
176 In addition, mere aggregation of another work not based on the Program
177 with the Program (or with a work based on the Program) on a volume of
178 a storage or distribution medium does not bring the other work under
179 the scope of this License.
181 3. You may copy and distribute the Program (or a work based on it,
182 under Section 2) in object code or executable form under the terms of
183 Sections 1 and 2 above provided that you also do one of the following:
185 a) Accompany it with the complete corresponding machine-readable
186 source code, which must be distributed under the terms of Sections
187 1 and 2 above on a medium customarily used for software interchange; or,
189 b) Accompany it with a written offer, valid for at least three
190 years, to give any third party, for a charge no more than your
191 cost of physically performing source distribution, a complete
192 machine-readable copy of the corresponding source code, to be
193 distributed under the terms of Sections 1 and 2 above on a medium
194 customarily used for software interchange; or,
196 c) Accompany it with the information you received as to the offer
197 to distribute corresponding source code. (This alternative is
198 allowed only for noncommercial distribution and only if you
199 received the program in object code or executable form with such
200 an offer, in accord with Subsection b above.)
202 The source code for a work means the preferred form of the work for
203 making modifications to it. For an executable work, complete source
204 code means all the source code for all modules it contains, plus any
205 associated interface definition files, plus the scripts used to
206 control compilation and installation of the executable. However, as a
207 special exception, the source code distributed need not include
208 anything that is normally distributed (in either source or binary
209 form) with the major components (compiler, kernel, and so on) of the
210 operating system on which the executable runs, unless that component
211 itself accompanies the executable.
213 If distribution of executable or object code is made by offering
214 access to copy from a designated place, then offering equivalent
215 access to copy the source code from the same place counts as
216 distribution of the source code, even though third parties are not
217 compelled to copy the source along with the object code.
219 4. You may not copy, modify, sublicense, or distribute the Program
220 except as expressly provided under this License. Any attempt
221 otherwise to copy, modify, sublicense or distribute the Program is
222 void, and will automatically terminate your rights under this License.
223 However, parties who have received copies, or rights, from you under
224 this License will not have their licenses terminated so long as such
225 parties remain in full compliance.
227 5. You are not required to accept this License, since you have not
228 signed it. However, nothing else grants you permission to modify or
229 distribute the Program or its derivative works. These actions are
230 prohibited by law if you do not accept this License. Therefore, by
231 modifying or distributing the Program (or any work based on the
232 Program), you indicate your acceptance of this License to do so, and
233 all its terms and conditions for copying, distributing or modifying
234 the Program or works based on it.
236 6. Each time you redistribute the Program (or any work based on the
237 Program), the recipient automatically receives a license from the
238 original licensor to copy, distribute or modify the Program subject to
239 these terms and conditions. You may not impose any further
240 restrictions on the recipients' exercise of the rights granted herein.
241 You are not responsible for enforcing compliance by third parties to
244 7. If, as a consequence of a court judgment or allegation of patent
245 infringement or for any other reason (not limited to patent issues),
246 conditions are imposed on you (whether by court order, agreement or
247 otherwise) that contradict the conditions of this License, they do not
248 excuse you from the conditions of this License. If you cannot
249 distribute so as to satisfy simultaneously your obligations under this
250 License and any other pertinent obligations, then as a consequence you
251 may not distribute the Program at all. For example, if a patent
252 license would not permit royalty-free redistribution of the Program by
253 all those who receive copies directly or indirectly through you, then
254 the only way you could satisfy both it and this License would be to
255 refrain entirely from distribution of the Program.
257 If any portion of this section is held invalid or unenforceable under
258 any particular circumstance, the balance of the section is intended to
259 apply and the section as a whole is intended to apply in other
262 It is not the purpose of this section to induce you to infringe any
263 patents or other property right claims or to contest validity of any
264 such claims; this section has the sole purpose of protecting the
265 integrity of the free software distribution system, which is
266 implemented by public license practices. Many people have made
267 generous contributions to the wide range of software distributed
268 through that system in reliance on consistent application of that
269 system; it is up to the author/donor to decide if he or she is willing
270 to distribute software through any other system and a licensee cannot
273 This section is intended to make thoroughly clear what is believed to
274 be a consequence of the rest of this License.
276 8. If the distribution and/or use of the Program is restricted in
277 certain countries either by patents or by copyrighted interfaces, the
278 original copyright holder who places the Program under this License
279 may add an explicit geographical distribution limitation excluding
280 those countries, so that distribution is permitted only in or among
281 countries not thus excluded. In such case, this License incorporates
282 the limitation as if written in the body of this License.
284 9. The Free Software Foundation may publish revised and/or new versions
285 of the General Public License from time to time. Such new versions will
286 be similar in spirit to the present version, but may differ in detail to
287 address new problems or concerns.
289 Each version is given a distinguishing version number. If the Program
290 specifies a version number of this License which applies to it and \"any
291 later version\", you have the option of following the terms and conditions
292 either of that version or of any later version published by the Free
293 Software Foundation. If the Program does not specify a version number of
294 this License, you may choose any version ever published by the Free Software
297 10. If you wish to incorporate parts of the Program into other free
298 programs whose distribution conditions are different, write to the author
299 to ask for permission. For software which is copyrighted by the Free
300 Software Foundation, write to the Free Software Foundation; we sometimes
301 make exceptions for this. Our decision will be guided by the two goals
302 of preserving the free status of all derivatives of our free software and
303 of promoting the sharing and reuse of software generally.
305 static char *warranty=
308 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
309 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
310 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
311 PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
312 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
313 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
314 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
315 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
316 REPAIR OR CORRECTION.
318 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
319 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
320 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
321 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
322 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
323 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
324 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
325 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
326 POSSIBILITY OF SUCH DAMAGES.
330 static void printTypeInfo(link *);
331 static void printValAggregates (symbol *,link *,char,unsigned int);
333 int srcMode = SRC_CMODE ;
335 /*-----------------------------------------------------------------*/
336 /* funcWithName - returns function with name */
337 /*-----------------------------------------------------------------*/
338 DEFSETFUNC(funcWithName)
340 function *func = item;
342 V_ARG(function **,funcp);
347 if (strcmp(func->sym->name,name) == 0) {
355 /*-----------------------------------------------------------------*/
356 /* setBPatModLine - set break point at the line specified for the */
357 /*-----------------------------------------------------------------*/
358 static void setBPatModLine (module *mod, int line)
362 /* look for the first executable line after the line
363 specified & get the break point there */
364 if (srcMode == SRC_CMODE && line > mod->ncLines) {
365 fprintf(stderr,"No line %d in file \"%s\".\n",
370 if (srcMode == SRC_AMODE && line > mod->nasmLines) {
371 fprintf(stderr,"No line %d in file \"%s\".\n",
377 for ( ; next_line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
379 if (srcMode == SRC_CMODE) {
380 if (mod->cLines[next_line]->addr) {
381 setBreakPoint (mod->cLines[next_line]->addr, CODE, USER,
382 userBpCB, mod->c_name, next_line);
388 if (mod->asmLines[next_line]->addr) {
389 setBreakPoint (mod->asmLines[next_line]->addr, CODE, USER,
390 userBpCB, mod->asm_name, next_line);
397 fprintf(stderr,"No line %d or after in file \"%s\"..\n",
403 /*-----------------------------------------------------------------*/
404 /* clearBPatModLine - clr break point at the line specified */
405 /*-----------------------------------------------------------------*/
406 static void clearBPatModLine (module *mod, int line)
408 /* look for the first executable line after the line
409 specified & get the break point there */
410 if (srcMode == SRC_CMODE && line > mod->ncLines) {
411 fprintf(stderr,"No line %d in file \"%s\".\n",
416 if (srcMode == SRC_AMODE && line > mod->ncLines) {
417 fprintf(stderr,"No line %d in file \"%s\".\n",
422 for ( ; line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
424 if (srcMode == SRC_CMODE)
425 if (mod->cLines[line]->addr) {
426 clearUSERbp (mod->cLines[line]->addr);
430 if (mod->asmLines[line]->addr) {
431 clearUSERbp (mod->asmLines[line]->addr);
439 /*-----------------------------------------------------------------*/
440 /* funcWithNameModule - returns functions with a name module combo */
441 /*-----------------------------------------------------------------*/
442 DEFSETFUNC(funcWithNameModule)
444 function *func = item;
447 V_ARG(function **,funcp);
452 if (strcmp(func->sym->name,fname) == 0 &&
453 strcmp(func->mod->c_name,mname) == 0) {
461 /*-----------------------------------------------------------------*/
462 /* funcInAddr - given an address returns the function */
463 /*-----------------------------------------------------------------*/
464 DEFSETFUNC(funcInAddr)
466 function *func = item;
467 V_ARG(unsigned int,addr);
468 V_ARG(function **,funcp);
473 /* in the address range */
474 if (func->sym->addr <= addr &&
475 func->sym->eaddr >= addr) {
484 /*-----------------------------------------------------------------*/
485 /* setStepBp - will set STEP Bp @ function entry points */
486 /*-----------------------------------------------------------------*/
487 DEFSETFUNC(setStepBp)
489 function *func = item;
491 if (func->sym && func->sym->addr ) {
493 /* set the entry break point */
494 setBreakPoint (func->sym->addr , CODE , STEP ,
495 stepBpCB ,func->mod->c_name , func->entryline);
503 /*-----------------------------------------------------------------*/
504 /* setStepEPBp - sets a given type of bp @ the execution point */
505 /*-----------------------------------------------------------------*/
506 DEFSETFUNC(setStepEPBp)
512 setBreakPoint (ep->addr, CODE, bptype,
513 stepBpCB, mname, ep->line);
517 /*-----------------------------------------------------------------*/
518 /* setNextEPBp - sets a given type of bp @ the execution point */
519 /*-----------------------------------------------------------------*/
520 DEFSETFUNC(setNextEPBp)
526 setBreakPoint (ep->addr, CODE, bptype,
527 nextBpCB, mname, ep->line);
531 /*-----------------------------------------------------------------*/
532 /* lineAtAddr - for execution points returns the one with addr */
533 /*-----------------------------------------------------------------*/
534 DEFSETFUNC(lineAtAddr)
537 V_ARG(unsigned int,addr);
542 /* address must be an exact match */
543 if (ep->addr == addr) {
556 /*-----------------------------------------------------------------*/
557 /* discoverContext - find out the current context of the bp */
558 /*-----------------------------------------------------------------*/
559 context *discoverContext (unsigned addr)
561 function *func = NULL;
564 /* find the function we are in */
565 if (!applyToSet(functions,funcInAddr,addr,&func)) {
566 fprintf(stderr, "Error?:discoverContext: cannot apply to set!\n");
570 currCtxt->func = func;
571 currCtxt->addr = func->laddr = addr;
572 currCtxt->modName = func->modName;
574 /* find the c line number */
575 if(applyToSet(func->cfpoints,lineAtAddr,addr,
576 &line,&currCtxt->block,&currCtxt->level))
577 currCtxt->cline = func->lline = line;
579 currCtxt->cline = func->exitline;
581 /* find the asm line number */
583 if (applyToSet(func->afpoints,lineAtAddr,addr,
585 currCtxt->asmline = line;
587 currCtxt->asmline = -1;
593 /*-----------------------------------------------------------------*/
594 /* simGo - send 'go' cmd to simulator and wait till a break occurs */
595 /*-----------------------------------------------------------------*/
596 void simGo (unsigned int gaddr)
601 static int initial_break_flag = 0;
604 addr = simGoTillBp (gaddr);
606 /* got the pc for the break point now first
607 discover the program context i.e. module, function
608 linenumber of the source etc, etc etc */
609 ctxt = discoverContext (addr);
611 /* dispatch all the break point call back functions */
612 rv = dispatchCB (addr,ctxt);
616 /* the dispatch call back function will return
617 non-zero if an user break point has been hit
618 if not then we continue with the execution
621 if (!initial_break_flag) {
622 initial_break_flag = 1; // kludge to stop only at first run
623 fprintf(stdout, "Stopping at entry. You can now list and set breakpoints\n");
631 // I took this out, after running "run" it would just keep re-running
632 // even after a lot of break points hit. For some reason above code
633 // not triggering(dispatchCB). This seems to be by design, startup adds
634 // a bunch of breakpoints-but they are not USER breakpoints. Perhaps the
635 // debugger changed with its implementation of "go"("run"). It seems we
636 // need to add a "next" or "step" followed by a "run"...
637 // I added a "step" in simi.c when we want a resume function, this seems
640 // still there is question of how do we stop it initially, since
641 // it must be started before it can get a context. If so, we would
642 // want it to just run up to an initial entry point you'd think...
643 // I don't see why we can't set breakpoints before an initial run,
644 // this does not seem right to me.
646 // line #'s are a bit off too.
656 /*-----------------------------------------------------------------*/
657 /* cmdSetUserBp - set break point at the user specified location */
658 /*-----------------------------------------------------------------*/
659 int cmdSetUserBp (char *s, context *cctxt)
662 function *func = NULL;
664 /* user break point location specification can be of the following
666 a) <nothing> - break point at current location
667 b) lineno - number of the current module
668 c) filename:lineno - line number of the given file
669 e) filename:function- function X in file Y (useful for static functions)
670 f) function - function entry point
674 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
677 /* white space skip */
678 while (*s && isspace(*s)) s++;
680 /* null terminate it after stripping trailing blanks*/
682 while (bp != s && isspace(*bp)) bp--;
685 /* case a) nothing */
686 /* if nothing given then current location : we know
687 the current execution location from the currentContext */
690 /* if current context is known */
692 if (srcMode == SRC_CMODE)
693 /* set the break point */
694 setBreakPoint ( cctxt->addr , CODE , USER , userBpCB ,
695 cctxt->func->mod->c_name, cctxt->cline);
697 setBreakPoint ( cctxt->addr , CODE , USER , userBpCB ,
698 cctxt->func->mod->asm_name, cctxt->asmline);
702 fprintf(stderr,"No default breakpoint address now.\n");
708 /* check if line number */
713 /* if current context not present then we must get the module
714 which has main & set the break point @ line number provided
715 of that module : if current context known then set the bp
716 at the line number given for the current module
719 if (!cctxt->func->mod) {
720 if (!applyToSet(functions,funcWithName,"main"))
721 fprintf(stderr,"Function \"main\" not defined.\n");
723 setBPatModLine(func->mod,line);
725 setBPatModLine(cctxt->func->mod,line);
728 setBPatModLine(list_mod,line);
730 fprintf(stdout,"Sdcdb fails to have module symbol context at %d\n", __LINE__);
737 if ((bp = strchr(s,':'))) {
742 if (srcMode == SRC_CMODE) {
743 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
744 fprintf (stderr,"No source file named %s.\n",s);
748 if (!applyToSet(modules,moduleWithAsmName,s,&mod)) {
749 fprintf (stderr,"No source file named %s.\n",s);
754 /* case c) filename:lineno */
755 if (isdigit(*(bp +1))) {
757 setBPatModLine (mod,atoi(bp+1));
761 /* case d) filename:function */
762 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
763 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
766 (srcMode == SRC_CMODE ?
773 /* case e) function */
774 if (!applyToSet(functions,funcWithName,s,&func))
775 fprintf(stderr,"Function \"%s\" not defined.\n",s);
777 setBPatModLine(func->mod,
778 (srcMode == SRC_CMODE ?
786 /*-----------------------------------------------------------------*/
787 /* cmdListAsm - list assembler source code */
788 /*-----------------------------------------------------------------*/
789 int cmdListAsm (char *s, context *cctxt)
791 fprintf(stderr,"'listasm' command not yet implemented\n");
795 /*-----------------------------------------------------------------*/
796 /* cmdSetOption - set debugger options */
797 /*-----------------------------------------------------------------*/
798 int cmdSetOption (char *s, context *cctxt)
800 while (*s && isspace(*s)) s++;
801 if (strncmp(s,"srcmode",7) == 0 ) {
802 if (srcMode == SRC_CMODE)
806 fprintf(stderr,"source mode set to '%s'\n",
807 (srcMode == SRC_CMODE ? "C" : "asm"));
811 fprintf(stderr,"'set %s' command not yet implemented\n",s);
815 /*-----------------------------------------------------------------*/
816 /* cmdContinue - continue till next break point */
817 /*-----------------------------------------------------------------*/
818 int cmdContinue (char *s, context *cctxt)
820 if (!cctxt || !cctxt->func) {
821 fprintf(stdout,"The program is not being run.\n");
825 fprintf(stdout,"Continuing.\n");
830 /*-----------------------------------------------------------------*/
831 /* cmdDelUserBp - delete user break point */
832 /*-----------------------------------------------------------------*/
833 int cmdDelUserBp (char *s, context *cctxt)
836 while (isspace(*s)) s++;
841 fprintf (stdout,"Delete all breakpoints? (y or n) ");
843 fgets(buffer,sizeof(buffer),stdin);
844 if (toupper(buffer[0]) == 'Y')
850 /* determine the break point number */
851 if (sscanf(s,"%d",&bpnum) == 1)
857 /*-----------------------------------------------------------------*/
858 /* cmdStep - single step thru C source file */
859 /*-----------------------------------------------------------------*/
860 int cmdStep (char *s, context *cctxt)
862 function *func = NULL;
864 if (!cctxt || !cctxt->func || !cctxt->func->mod)
865 fprintf(stdout,"The program is not being run.\n");
867 /* if we are @ the end of a function then set
868 break points at execution points of the
869 function in the call stack... */
870 if (cctxt->addr == cctxt->func->sym->eaddr) {
871 if ((func = STACK_PEEK(callStack))) {
872 if (srcMode == SRC_CMODE)
873 applyToSet (func->cfpoints,setStepEPBp,STEP,
876 applyToSet (func->afpoints,setStepEPBp,STEP,
877 func->mod->asm_name);
880 /* set breakpoints at all function entry points
881 and all exepoints of this functions & for
882 all functions one up in the call stack */
884 /* all function entry points */
885 applyToSet(functions,setStepBp);
887 if (srcMode == SRC_CMODE) {
888 /* for all execution points in this function */
889 applyToSet(cctxt->func->cfpoints,setStepEPBp,STEP,
890 cctxt->func->mod->c_name);
892 /* set a break point @ the current function's
894 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
895 stepBpCB, cctxt->func->mod->c_name,
896 cctxt->func->exitline);
898 /* now break point @ callers execution points */
899 if ((func = STACK_PPEEK(callStack))) {
900 applyToSet (func->cfpoints,setStepEPBp,STEP,
902 /* set bp @ callers exit point */
903 setBreakPoint (func->sym->eaddr, CODE, STEP ,
904 stepBpCB, func->mod->c_name,
908 /* for all execution points in this function */
909 applyToSet(cctxt->func->afpoints,setStepEPBp,STEP,
910 cctxt->func->mod->asm_name);
912 /* set a break point @ the current function's
914 setBreakPoint (cctxt->func->sym->eaddr, CODE, STEP ,
915 stepBpCB, cctxt->func->mod->asm_name,
916 cctxt->func->aexitline);
918 /* now break point @ callers execution points */
919 if ((func = STACK_PPEEK(callStack))) {
921 applyToSet (func->afpoints,setStepEPBp,STEP,
922 func->mod->asm_name);
924 /* set bp @ callers exit point */
925 setBreakPoint (func->sym->eaddr, CODE, STEP ,
926 stepBpCB, func->mod->asm_name,
937 /*-----------------------------------------------------------------*/
938 /* cmdNext - next executable C statement file */
939 /*-----------------------------------------------------------------*/
940 int cmdNext (char *s, context *cctxt)
942 function *func = NULL;
943 /* next is almost the same as step except we don't
944 we don't set break point for all function entry
946 if (!cctxt || !cctxt->func || !cctxt->func->mod)
947 fprintf(stdout,"The program is not being run.\n");
950 /* if we are @ the end of a function then set
951 break points at execution points of the
952 function in the call stack... */
953 if (cctxt->addr == cctxt->func->sym->eaddr) {
954 if ((func = STACK_PEEK(callStack))) {
955 if (srcMode == SRC_CMODE)
956 applyToSet (func->cfpoints,setStepEPBp,STEP,
959 applyToSet (func->afpoints,setStepEPBp,STEP,
960 func->mod->asm_name);
963 if (srcMode == SRC_CMODE) {
964 /* for all execution points in this function */
965 applyToSet(cctxt->func->cfpoints,setNextEPBp,NEXT,
966 cctxt->func->mod->c_name);
967 /* set a break point @ the current function's
969 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
970 nextBpCB, cctxt->func->mod->c_name,
971 cctxt->func->exitline);
973 /* now break point @ callers execution points */
974 if ((func = STACK_PPEEK(callStack))) {
975 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
977 /* set bp @ callers exit point */
978 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
979 stepBpCB, func->mod->c_name,
983 /* for all execution points in this function */
984 applyToSet(cctxt->func->afpoints,setNextEPBp,NEXT,
985 cctxt->func->mod->asm_name);
986 /* set a break point @ the current function's
988 setBreakPoint (cctxt->func->sym->eaddr, CODE, NEXT ,
989 nextBpCB, cctxt->func->mod->asm_name,
990 cctxt->func->aexitline);
992 /* now break point @ callers execution points */
993 if ((func = STACK_PPEEK(callStack))) {
994 applyToSet (func->cfpoints,setNextEPBp,NEXT ,
995 func->mod->asm_name);
996 /* set bp @ callers exit point */
997 setBreakPoint (func->sym->eaddr, CODE, NEXT ,
998 stepBpCB, func->mod->asm_name,
1008 /*-----------------------------------------------------------------*/
1009 /* cmdRun - run till next break point */
1010 /*-----------------------------------------------------------------*/
1011 int cmdRun (char *s, context *cctxt)
1014 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
1015 fprintf(stdout,"Starting program\n");
1020 "The program being debugged has been started already.\n");
1021 fprintf(stdout,"Start it from the beginning? (y or n) ");
1024 fgets(buff,sizeof(buff),stdin);
1025 if (toupper(buff[0]) == 'Y') {
1034 /*-----------------------------------------------------------------
1035 cmdListSymbols - list symbols
1036 |-----------------------------------------------------------------*/
1037 int cmdListSymbols (char *s, context *cctxt)
1039 int our_verbose = 0;
1043 if (strstr(s, "v1")) {
1045 } else if (strstr(s, "v2")) {
1049 printf("[symbols]\n");
1050 sy = setFirstItem(symbols);
1055 if (our_verbose <= 1)
1056 printf("<%s>", sy->name);
1058 if (our_verbose > 1) {
1059 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1060 sy->name, sy->size, sy->level, sy->block);
1061 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1062 sy->isonstack, sy->isfunc, sy->offset, sy->addr);
1063 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1064 sy->eaddr, sy->addr_type, sy->type, sy->etype);
1065 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1066 sy->scopetype, sy->sname, sy->rname, sy->addrspace);
1067 printf(" next:%x\n", sy->next);
1070 sy = setNextItem(symbols);
1072 printf(" %d symbols\n", i);
1076 /*-----------------------------------------------------------------
1077 cmdListFunctions - list functions.
1078 |-----------------------------------------------------------------*/
1079 int cmdListFunctions (char *s, context *cctxt)
1083 int our_verbose = 0;
1085 if (strstr(s, "v1")) {
1087 } else if (strstr(s, "v2")) {
1091 printf("[functions]\n");
1092 f = setFirstItem(functions);
1098 printf(" %d) sym:%x, modName:%s, mod:%x\n", i,
1099 f->sym, f->modName, f->mod);
1100 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1101 f->entryline, f->aentryline, f->exitline, f->aexitline);
1102 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1103 f->cfpoints, f->afpoints, f->laddr, f->lline);
1106 printf("<%s>", f->modName);
1109 f = setNextItem(functions);
1111 printf(" %d functions\n", i);
1115 /*-----------------------------------------------------------------
1116 cmdListModules - list functions.
1117 |-----------------------------------------------------------------*/
1118 int cmdListModules (char *s, context *cctxt)
1123 int our_verbose = 0;
1125 if (strstr(s, "v1")) {
1127 } else if (strstr(s, "v2")) {
1131 printf("[modules]\n");
1132 m = setFirstItem(modules);
1138 if (our_verbose >= 0) {
1139 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1140 m->cfullname, m->afullname, m->name);
1141 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1142 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1143 printf(" cLines:%x, asmLines:%x\n",
1144 m->cLines, m->asmLines);
1146 if (our_verbose > 2) {
1149 cs = m->cLines[i++];
1150 printf(" [cLines] ");
1153 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1154 i, cs->addr, cs->block, cs->level, cs->src);
1155 cs = m->cLines[i++];
1158 printf("%d records", i);
1162 as = m->asmLines[i++];
1163 printf(" [asmLines] ");
1166 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1167 i, as->addr, as->block, as->level, as->src);
1168 as = m->asmLines[i++];
1171 printf("%d records", i);
1176 m = setNextItem(modules);
1181 /*-----------------------------------------------------------------
1182 infoSymbols - This is really just a tool to dump all these
1183 huge program structures out into human readable form.
1184 |-----------------------------------------------------------------*/
1185 static void infoSymbols(context *ctxt)
1187 int our_verbose = 0;
1189 printf("[context:%x] func:%x modName:%s addr:%x\n",
1190 ctxt, ctxt->func, ctxt->modName, ctxt->addr);
1192 printf(" cline:%d asmline:%d block:%d level:%d\n",
1193 ctxt->cline, ctxt->asmline, ctxt->level);
1195 printf("[globals] currCtxt:%x, modules:%x, functions:%x symbols:%x\n",
1196 currCtxt, modules, functions, symbols);
1197 printf(" nStructs:%d, structs:%x, ssdirl:%s\n",
1198 nStructs, structs, ssdirl);
1200 /**************** modules *******************/
1205 printf("[modules]\n");
1206 m = setFirstItem(modules);
1211 printf(" %d) cfullname:%s, afullname:%s, name:%s\n", ++mi,
1212 m->cfullname, m->afullname, m->name);
1213 printf(" c_name:%s, asm_name:%s, ncLines:%d, nasmLines:%d\n",
1214 m->c_name, m->asm_name, m->ncLines, m->nasmLines);
1215 printf(" cLines:%x, asmLines:%x\n",
1216 m->cLines, m->asmLines);
1219 cs = m->cLines[i++];
1220 printf(" [cLines] ");
1223 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1224 i, cs->addr, cs->block, cs->level, cs->src);
1225 cs = m->cLines[i++];
1228 printf("%d records", i);
1232 as = m->asmLines[i++];
1233 printf(" [asmLines] ");
1236 printf(" (%d) addr:%x, block:%d, level:%d, src:%s\n",
1237 i, as->addr, as->block, as->level, as->src);
1238 as = m->asmLines[i++];
1241 printf("%d records", i);
1245 m = setNextItem(modules);
1249 /**************** functions *******************/
1253 printf("[functions]\n");
1254 f = setFirstItem(functions);
1260 printf(" %d) sym:%x, modName:%s, mod:%x\n", i,
1261 f->sym, f->modName, f->mod);
1262 printf(" entryline:%d, aentryline:%d, exitline:%d, aexitline:%d\n",
1263 f->entryline, f->aentryline, f->exitline, f->aexitline);
1264 printf(" cfpoints:%x, afpoints:%x, laddr:%x, lline:%d\n",
1265 f->cfpoints, f->afpoints, f->laddr, f->lline);
1268 f = setNextItem(functions);
1271 printf(" %d functions\n", i);
1274 /**************** symbols *******************/
1278 printf("[symbols]\n");
1279 s = setFirstItem(symbols);
1285 printf(" %d) name:%s, size:%d, level:%d block:%d\n", i,
1286 s->name, s->size, s->level, s->block);
1287 printf(" isonstack:%d, isfunc:%d, offset:%d addr:%d\n",
1288 s->isonstack, s->isfunc, s->offset, s->addr);
1289 printf(" eaddr:%d, addr_type:%c, type:%x etype:%x\n",
1290 s->eaddr, s->addr_type, s->type, s->etype);
1291 printf(" scopetype:%c, sname:%s, rname:%s addrspace:%c\n",
1292 s->scopetype, s->sname, s->rname, s->addrspace);
1293 printf(" next:%x\n", s->next);
1296 s = setNextItem(symbols);
1299 printf(" %d symbols\n", i);
1304 /*-----------------------------------------------------------------*/
1305 /* infoStack - print call stack information */
1306 /*-----------------------------------------------------------------*/
1307 static void infoStack(context *ctxt)
1312 STACK_STARTWALK(callStack) ;
1313 while ((func = STACK_WALK(callStack))) {
1315 fprintf(stdout,"#%d 0x%04x %s () at %s:%d\n",i++,
1316 func->laddr,func->sym->name,
1317 func->mod->c_name,func->lline);
1322 /*-----------------------------------------------------------------*/
1323 /* cmdInfo - info command */
1324 /*-----------------------------------------------------------------*/
1325 int cmdInfo (char *s, context *cctxt)
1327 while (isspace(*s)) s++;
1329 /* list all break points */
1330 if (strcmp(s,"break") == 0) {
1335 /* info frame same as frame */
1336 if (strcmp(s,"frame") == 0) {
1341 /* info stack display call stack */
1342 if (strcmp(s,"stack") == 0) {
1347 /* info stack display call stack */
1348 if (strcmp(s,"registers") == 0) {
1349 fprintf(stdout,"%s",simRegs());
1353 /* info stack display call stack */
1354 if (strcmp(s,"symbols") == 0) {
1355 /* dump out symbols we have read in */
1356 fprintf(stdout,"Dumping symbols...\n");
1361 fprintf(stdout,"Undefined info command: \"%s\". Try \"help\n",s);
1366 /*-----------------------------------------------------------------*/
1367 /* cmdQuit - quit debugging */
1368 /*-----------------------------------------------------------------*/
1369 int cmdQuit (char *s, context *cctxt)
1376 /*-----------------------------------------------------------------*/
1377 /* cmdListSrc - list src */
1378 /*-----------------------------------------------------------------*/
1379 int cmdListSrc (char *s, context *cctxt)
1381 static int currline = 0;
1384 int llines = listLines;
1386 while (*s && isspace(*s)) s++;
1388 /* if the user has spcified line numer then the line number
1389 can be of the following formats
1390 LINE - just line number
1391 FILE:LINE - filename line number
1392 FUNCTION - list a function
1393 FILE:FUNCTION - function in file */
1398 sscanf(s,"%d",&pline);
1399 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
1401 fprintf(stdout,"Sdcdb fails to have a proper context at %d.\n", __LINE__);
1406 list_mod = cctxt->func->mod;
1410 function *func = NULL;
1412 /* if ':' present then FILE:LINE || FILE:FUNCTION */
1413 if ((bp = strchr(s,':'))) {
1418 list_mod=NULL; /* bug fix 2-09-02, moduleWithCName expects mod to be null */
1419 if (srcMode == SRC_CMODE) {
1420 if (!applyToSet(modules,moduleWithCName,s,&list_mod)) {
1421 fprintf (stderr,"No c source file named %s.\n",s);
1425 if (!applyToSet(modules,moduleWithAsmName,s,&list_mod)) {
1426 fprintf (stderr,"No source file named %s.\n",s);
1430 sscanf(bp,"%d",&pline);
1433 if (!applyToSet(functions,funcWithNameModule,bp,s,&func)) {
1434 fprintf(stdout,"Function \"%s\" not defined.\n",bp);
1437 list_mod = func->mod;
1438 if (srcMode == SRC_CMODE) {
1439 pline = func->entryline;
1440 llines = func->exitline - func->entryline + 1;
1442 pline = func->aentryline;
1443 llines = func->aexitline - func->aentryline + 1;
1449 if (!applyToSet(functions,funcWithName,s,&func)) {
1450 fprintf(stderr,"Function \"%s\" not defined.\n",s);
1454 list_mod = func->mod;
1455 if (srcMode == SRC_CMODE) {
1456 pline = func->entryline;
1457 llines = func->exitline - func->entryline + 1;
1459 pline = func->aentryline;
1460 llines = func->aexitline - func->aentryline + 1;
1466 /* if no line specified & we had listed
1467 before then continue from that listing */
1471 if (!cctxt || !cctxt->func || !cctxt->func->mod) {
1472 fprintf(stdout,"Missing context at %d. Try list filename:lineno\n", __LINE__);
1475 list_mod = cctxt->func->mod;
1476 if (srcMode == SRC_CMODE)
1477 pline = cctxt->cline;
1479 pline = cctxt->asmline;
1484 fprintf(stdout,"Sdcdb fails to have a valid module context at %d.\n", __LINE__);
1488 if (llines > listLines) llines = listLines;
1490 for ( i = 0 ; i < llines ; i++ ) {
1491 if (srcMode == SRC_CMODE) {
1492 if ( (pline + i) >= list_mod->ncLines )
1494 fprintf(stdout,"%d\t%s",pline + i,
1495 list_mod->cLines[pline +i]->src);
1497 if ( (pline + i) >= list_mod->nasmLines )
1499 fprintf(stdout,"%d\t%s",pline + i,
1500 list_mod->asmLines[pline +i]->src);
1503 currline = pline + i ;
1507 /*-----------------------------------------------------------------*/
1508 /* printValBasic - print value of basic types */
1509 /*-----------------------------------------------------------------*/
1510 static void printValBasic(symbol *sym,unsigned addr,char mem, int size)
1526 v.val = simGetValue(addr,mem,size);
1527 /* if this a floating point number then */
1528 if (IS_FLOAT(sym->type))
1529 fprintf(stdout,"%f",v.f);
1531 if (IS_PTR(sym->type))
1532 fprintf(stdout,"0x%x",v.val);
1534 if (IS_SPEC(sym->type) && IS_INTEGRAL(sym->type)) {
1535 if (IS_CHAR(sym->etype))
1536 fprintf(stdout,"'%c' %d 0x%x",v.val,v.val,v.val);
1538 if (IS_INT(sym->etype))
1539 if (IS_LONG(sym->etype))
1540 if (SPEC_USIGN(sym->etype))
1541 fprintf(stdout,"%d 0x%x",v.val,v.val);
1543 fprintf(stdout,"%d 0x%x",v.sval,v.sval);
1545 fprintf(stdout,"%d 0x%x",v.i.lo,v.i.lo);
1547 fprintf(stdout,"0x%x",v.val);
1549 fprintf(stdout,"0x%x",v.val);
1554 /*-----------------------------------------------------------------*/
1555 /* printValFunc - prints function values */
1556 /*-----------------------------------------------------------------*/
1557 static void printValFunc (symbol *sym)
1559 fprintf(stdout,"print function not yet implemented\n");
1562 /*-----------------------------------------------------------------*/
1563 /* printArrayValue - will print the values of array elements */
1564 /*-----------------------------------------------------------------*/
1565 static void printArrayValue (symbol *sym, char space, unsigned int addr)
1567 link *elem_type = sym->type->next;
1570 fprintf(stdout," { ");
1571 for (i = 0 ; i < DCL_ELEM(sym->type) ; i++) {
1572 if (IS_AGGREGATE(elem_type)) {
1573 printValAggregates(sym,elem_type,space,addr);
1575 printValBasic(sym,addr,space,getSize(elem_type));
1577 addr += getSize(elem_type);
1578 if (i != DCL_ELEM(sym->type) -1)
1579 fprintf(stdout,",");
1582 fprintf(stdout,"}\n");
1585 /*-----------------------------------------------------------------*/
1586 /* printStructValue - prints structures elements */
1587 /*-----------------------------------------------------------------*/
1588 static void printStructValue (symbol *sym,link *type, char space, unsigned int addr)
1590 symbol *fields = SPEC_STRUCT(type)->fields;
1592 fprintf(stdout," { ");
1594 fprintf(stdout,"%s = ",fields->name);
1595 if (IS_AGGREGATE(fields->type)) {
1596 printValAggregates(fields,fields->type,space, addr);
1598 printValBasic(fields,addr,space,getSize(fields->type));
1600 addr += getSize(fields->type);
1601 fields = fields->next;
1603 fprintf(stdout,"}\n");
1606 /*-----------------------------------------------------------------*/
1607 /* printValAggregates - print value of aggregates */
1608 /*-----------------------------------------------------------------*/
1609 static void printValAggregates (symbol *sym, link *type,char space,unsigned int addr)
1612 if (IS_ARRAY(type)) {
1613 printArrayValue(sym, space, addr);
1617 if (IS_STRUCT(type)) {
1618 printStructValue(sym,sym->type,space, addr);
1623 /*-----------------------------------------------------------------*/
1624 /* printSymValue - print value of a symbol */
1625 /*-----------------------------------------------------------------*/
1626 static void printSymValue (symbol *sym, context *cctxt)
1628 static int stack = 1;
1630 /* if it is on stack then compute address & fall thru */
1631 if (sym->isonstack) {
1632 symbol *bp = symLookup("bp",cctxt);
1634 fprintf(stdout,"cannot determine stack frame\n");
1638 sym->addr = simGetValue(bp->addr,bp->addrspace,bp->size)
1642 /* get the value from the simulator and
1644 fprintf(stdout,"$%d = ",stack++);
1645 /* arrays & structures first */
1646 if (IS_AGGREGATE(sym->type))
1647 printValAggregates(sym,sym->type,sym->addrspace,sym->addr);
1650 if (IS_FUNC(sym->type))
1653 printValBasic(sym,sym->addr,sym->addrspace,sym->size);
1654 fprintf(stdout,"\n");
1655 //fprintf(stdout,"(BASIC %x,%c,%d)\n",sym->addr,sym->addrspace,sym->size);
1659 /*-----------------------------------------------------------------*/
1660 /* printStructInfo - print out structure information */
1661 /*-----------------------------------------------------------------*/
1662 static void printStructInfo (structdef *sdef)
1664 symbol *field = sdef->fields ;
1669 field = field->next;
1672 fprintf(stdout,"%s %s {\n",(i ? "struct" : "union" ), sdef->tag);
1673 field = sdef->fields;
1675 printTypeInfo (field->type);
1676 fprintf(stdout," %s ;\n",field->name);
1677 field = field->next ;
1680 fprintf(stdout,"}\n");
1684 /*-----------------------------------------------------------------*/
1685 /* printTypeInfo - print out the type information */
1686 /*-----------------------------------------------------------------*/
1687 static void printTypeInfo(link *p)
1693 switch (DCL_TYPE(p)) {
1695 printTypeInfo (p->next);
1696 fprintf(stdout,"()");
1699 printTypeInfo (p->next);
1700 fprintf(stdout,"[%d]",DCL_ELEM(p));
1706 printTypeInfo (p->next);
1707 fprintf(stdout,"(_near *)");
1711 printTypeInfo (p->next);
1712 fprintf(stdout,"(_xdata *)");
1716 printTypeInfo( p->next);
1717 fprintf(stdout,"(_code *)");
1721 printTypeInfo( p->next);
1722 fprintf(stdout,"(_generic *)");
1726 switch (SPEC_NOUN(p)) { /* depending on the specifier type */
1728 (IS_LONG(p) ? fputs("long ",stdout) :
1729 ( IS_SHORT(p) ? fputs("short ",stdout) :
1730 fputs("int ",stdout))) ;
1733 fputs("float ",stdout);
1737 fputs ("char ",stdout);
1741 fputs("void ",stdout);
1745 printStructInfo (SPEC_STRUCT(p));
1749 fputs("sbit ",stdout);
1753 fprintf(stdout,": %d" ,SPEC_BLEN(p));
1759 /*-----------------------------------------------------------------*/
1760 /* cmdPrint - print value of variable */
1761 /*-----------------------------------------------------------------*/
1762 int cmdPrint (char *s, context *cctxt)
1765 char *bp = s+strlen(s) -1;
1767 while (isspace(*s)) s++;
1769 while (isspace(*bp)) bp--;
1773 if ((sym = symLookup(s,cctxt))) {
1774 printSymValue(sym,cctxt);
1777 "No symbol \"%s\" in current context.\n",
1783 /*-----------------------------------------------------------------*/
1784 /* cmdPrintType - print type of a variable */
1785 /*-----------------------------------------------------------------*/
1786 int cmdPrintType (char *s, context *cctxt)
1789 char *bp = s+strlen(s) -1;
1791 while (isspace(*s)) s++;
1793 while (isspace(*bp)) bp--;
1797 if ((sym = symLookup(s,cctxt))) {
1798 printTypeInfo(sym->type);
1799 fprintf(stdout,"\n");
1802 "No symbol \"%s\" in current context.\n",
1808 /*-----------------------------------------------------------------*/
1809 /* cmdClrUserBp - clear user break point */
1810 /*-----------------------------------------------------------------*/
1811 int cmdClrUserBp (char *s, context *cctxt)
1814 function *func = NULL;
1816 /* clear break point location specification can be of the following
1818 a) <nothing> - break point at current location
1819 b) lineno - number of the current module
1820 c) filename:lineno - line number of the given file
1821 e) filename:function- function X in file Y (useful for static functions)
1822 f) function - function entry point
1826 fprintf(stdout,"No symbol table is loaded. Use the \"file\" command.\n");
1830 /* white space skip */
1831 while (*s && isspace(*s)) s++;
1833 /* null terminate it after stripping trailing blanks*/
1835 while (bp != s && isspace(*bp)) bp--;
1838 /* case a) nothing */
1839 /* if nothing given then current location : we know
1840 the current execution location from the currentContext */
1843 /* if current context is known */
1845 /* clear the break point @ current location */
1846 clearUSERbp (cctxt->addr);
1848 fprintf(stderr,"No default breakpoint address now.\n");
1853 /* case b) lineno */
1854 /* check if line number */
1856 /* get the lineno */
1859 /* if current context not present then we must get the module
1860 which has main & set the break point @ line number provided
1861 of that module : if current context known then set the bp
1862 at the line number given for the current module
1865 if (!cctxt->func->mod) {
1866 if (!applyToSet(functions,funcWithName,"main"))
1867 fprintf(stderr,"Function \"main\" not defined.\n");
1869 clearBPatModLine(func->mod,line);
1871 clearBPatModLine(cctxt->func->mod,line);
1877 if ((bp = strchr(s,':'))) {
1882 if (!applyToSet(modules,moduleWithCName,s,&mod)) {
1883 fprintf (stderr,"No source file named %s.\n",s);
1887 /* case c) filename:lineno */
1888 if (isdigit(*(bp +1))) {
1890 clearBPatModLine (mod,atoi(bp+1));
1894 /* case d) filename:function */
1895 if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
1896 fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
1898 clearBPatModLine (mod,func->entryline);
1903 /* case e) function */
1904 if (!applyToSet(functions,funcWithName,s,&func))
1905 fprintf(stderr,"Function \"%s\" not defined.\n",s);
1907 clearBPatModLine(func->mod,func->entryline);
1914 /*-----------------------------------------------------------------*/
1915 /* cmdSimulator - send command to simulator */
1916 /*-----------------------------------------------------------------*/
1917 int cmdSimulator (char *s, context *cctxt)
1921 if (strlen(s) > 80) {
1922 printf("error 3A\n");
1926 strcat(tmpstr, "\n");
1929 fprintf(stdout,"%s",simResponse());
1933 /*-----------------------------------------------------------------*/
1934 /* cmdFrame - Frame command */
1935 /*-----------------------------------------------------------------*/
1936 int cmdFrame (char *s, context *cctxt)
1940 if ((func = STACK_PEEK(callStack))) {
1941 fprintf(stdout,"#0 %s () at %s:%d\n",
1942 func->sym->name,func->mod->c_name,cctxt->cline);
1944 if (cctxt->cline < func->mod->ncLines)
1945 fprintf(stdout,"%d\t%s",
1947 func->mod->cLines[cctxt->cline]->src);
1949 fprintf(stdout,"No stack.\n");
1953 /*-----------------------------------------------------------------*/
1954 /* cmdFinish - exec till end of current function */
1955 /*-----------------------------------------------------------------*/
1956 int cmdFinish (char *s, context *ctxt)
1958 if (!ctxt || ! ctxt->func) {
1959 fprintf(stdout,"The program is not running.\n");
1963 if (srcMode == SRC_CMODE) {
1964 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
1965 stepBpCB, ctxt->func->mod->c_name,
1966 ctxt->func->exitline);
1968 setBreakPoint (ctxt->func->sym->eaddr, CODE, STEP,
1969 stepBpCB, ctxt->func->mod->asm_name,
1970 ctxt->func->aexitline);
1979 /*-----------------------------------------------------------------*/
1980 /* cmdShow - show command */
1981 /*-----------------------------------------------------------------*/
1982 int cmdShow (char *s, context *cctxt)
1984 /* skip white space */
1985 while (*s && isspace(*s)) s++ ;
1987 if (strcmp(s,"copying") == 0) {
1988 fputs(copying,stdout);
1992 if (strcmp(s,"warranty") == 0) {
1993 fputs(warranty,stdout);