1 /* Energize (formerly known as Cadillac) interface routines.
2 Copyright 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
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, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <connection.h>
31 #include <genericreq.h>
32 #include <debuggerreq.h>
33 #include <debuggerconn.h>
41 #include <sys/filio.h>
44 #include <sys/errno.h>
48 /* Non-zero means that we're doing the energize interface. */
51 /* Connection block for debugger<=>kernel communications. */
52 static Connection
*conn
= 0;
54 /* fd for our socket to the kernel. */
57 /* The kernel's ID for this instance of the program. */
58 static int program_id
;
60 static int instance_id
;
62 /* The fd for the pty associated with the inferior. */
63 static int inferior_pty
= -1;
64 static int inferior_tty
= -1;
66 static int has_run
= 0;
68 extern int pgrp_inferior
;
70 extern char *source_path
;
72 char **pprompt
; /* Pointer to pointer to prompt */
74 /* Tell energize_command_line_input() where to get its text from */
75 static int doing_breakcommands_message
= 0;
77 /* Stash command text here */
78 static char *command_line_text
= 0;
79 static int command_line_length
= 0;
81 /* Flags returned by wait_for_events() */
82 #define KERNEL_EVENT 1
86 /* This routine redirects the output of fputs_filtered to the kernel so that
87 the user can see what's going on in his debugger window. */
94 CVWriteTranscriptInfo (conn
, instance_id
, (char *)ptr
);
100 energize_query(query
, args
)
109 vsprintf(buf
, query
, args
);
111 CVWriteQueryInfo(conn
,
116 ""); /* transcript */
120 energize_acknowledge_query(ack
)
123 CVWriteQueryInfo(conn
,
128 ""); /* transcript */
131 /* Copy all data from the pty to the kernel. */
142 cc
= read(inferior_pty
, buf
, sizeof(buf
));
146 && errno
== EWOULDBLOCK
))
153 perror("pty read error");
157 req
= CWriteTtyRequest(conn
, TextIORType
);
158 CWriteVstringLen(conn
, buf
, cc
);
161 CWriteRequestBuffer(conn
);
164 /* Copy data from the kernel to the pty. */
167 kernel_to_pty(data
, len
)
173 cc
= write(inferior_pty
, data
, len
);
181 perror("pty write error");
184 printf("Couldn't write all the data to the pty, wanted %d, got %d\n",
190 full_filename(symtab
)
191 struct symtab
*symtab
;
199 if (symtab
->fullname
)
200 return savestring(symtab
->fullname
, strlen(symtab
->fullname
));
203 pathlen
= strlen(symtab
->dirname
);
206 if (symtab
->filename
)
207 pathlen
+= strlen(symtab
->filename
);
209 filename
= xmalloc(pathlen
+1);
212 strcpy(filename
, symtab
->dirname
);
215 if (symtab
->filename
)
216 strcat(filename
, symtab
->filename
);
221 /* Tell the energize kernel how high the stack is so that frame numbers (which
222 are relative to the current stack height make sense.
224 Calculate the number of frames on the stack, and the number of subroutine
225 invocations that haven't changed since the last call to this routine. The
226 second number is calculated by comparing the PCs of the current stack frames
227 to the PCs of the previous set of stack frames. The screw here is that a
228 subroutine may call several different procedures, which means that the PC
229 in its frame changes, even though you are still in the same subroutine. We
230 resolve this by converting the frames PC into the PC at the start of the
231 function (for efficiency, this is done only if the simple comparison test
240 /* Non-zero means that Energize kernel already knows how high the stack is. */
241 static int stack_info_valid
= 0;
246 struct pclist
*pclist
= 0, *pli
, *opli
;
247 static struct pclist
*old_pclist
;
251 if (stack_info_valid
)
257 /* First, calculate the stack height, and build the new pclist */
259 for (frame
= get_current_frame();
261 frame
= get_prev_frame(frame
))
264 pli
= (struct pclist
*)xmalloc(sizeof(struct pclist
));
271 /* Now, figure out how much of the stack hasn't changed */
273 for (pli
= pclist
, opli
= old_pclist
;
274 pli
!= 0 && opli
!= 0;
275 pli
= pli
->next
, opli
= opli
->next
, (similar
)++)
277 if ((pli
->pc
!= opli
->pc
)
278 && (get_pc_function_start(pli
->pc
)
279 != get_pc_function_start(opli
->pc
)))
283 /* Free up all elements of the old pclist */
294 old_pclist
= pclist
; /* Install the new pclist */
296 CVWriteStackSizeInfo(conn
,
298 height
, /* Frame depth */
300 similar
, /* Frame diff */
304 stack_info_valid
= 1;
307 /* Tell the kernel where we are in the program, and what the stack looks like.
313 static int linecount
= 48;
314 struct symtab_and_line sal
;
315 struct symbol
*symbol
;
316 char *funcname
, *filename
;
317 static int sent_prog_inst
= 0;
322 if (inferior_pid
== 0) /* target has died */
324 CVWriteProgramTerminatedInfo(conn
,
331 sal
= find_pc_line(stop_pc
, 0);
332 symbol
= find_pc_function(stop_pc
);
334 funcname
= symbol
? symbol
->name
: "";
335 filename
= full_filename(sal
.symtab
);
340 CVWriteProgramInstanceInfo(conn
,
351 CVWriteStackFrameInfo(conn
,
355 0, /* XXX - frame # */
358 "" /* XXX ? transcript */
361 CVWriteProgramStoppedInfo(conn
,
363 0, /* XXX - breakpoint # or signal # */
366 "" /* XXX ? transcript */
373 /* Call this to output annotated function names. Names will be demangled if
374 necessary. arg_mode contains flags that are passed on to cplus_demangle. */
377 energize_annotate_function(funcname
, arg_mode
, level
)
383 char *demangled_name
= NULL
;
385 if (funcname
== NULL
)
390 demangled_name
= cplus_demangle(funcname
, arg_mode
);
393 funcname
= demangled_name
;
398 if (level
< 0) level
= 0;
400 CVWriteBackTraceEntryInfo(conn
,
406 free(demangled_name
);
409 /* Call this just prior to printing out the name & value of a variable. This
410 tells the kernel where to annotate the output. */
413 expression - A text handle on what GDB can use to reference this value.
414 This can be a symbol name, or a convenience var, etc...
415 symbol - Used to determine the scope of the data. May be NULL.
416 type - Determines if we have a pointer ref, and the print name of the type.
417 Used in ShowValue message.
418 valaddr - The address in target memory of the data.
419 field - The field name of the struct or union element being referenced.
422 static char cum_expr
[200]; /* Cumulative expression */
423 static char *expr_stack
[100] = {cum_expr
}; /* Pointers to end of expressions */
424 static char **last_expr
= expr_stack
; /* Current expr stack pointer */
427 energize_start_variable_annotation(expression
, symbol
, type
, valaddr
, field
)
429 struct symbol
*symbol
;
436 enum type_code type_code
;
437 enum address_class sym_class
;
445 strcpy(*last_expr
++, expression
);
446 *last_expr
= *(last_expr
-1) + strlen(expression
);
448 switch (TYPE_CODE(type
))
450 case TYPE_CODE_ARRAY
:
451 case TYPE_CODE_STRUCT
:
452 case TYPE_CODE_UNION
:
456 ref_type
= CValueValueRef
;
459 ref_type
= CValuePointerRef
;
462 ref_type
= CValueUndefRef
;
466 /* Make sure that pointer points at something we understand */
468 if (ref_type
== CValuePointerRef
)
469 switch (TYPE_CODE(TYPE_TARGET_TYPE(type
)))
472 case TYPE_CODE_ARRAY
:
473 case TYPE_CODE_STRUCT
:
474 case TYPE_CODE_UNION
:
480 ref_type
= CValueUndefRef
;
486 sym_class
= SYMBOL_CLASS(symbol
);
491 case LOC_CONST_BYTES
:
492 stor_cl
= CValueStorStaticConst
;
495 stor_cl
= CValueStorStaticVar
;
499 stor_cl
= CValueStorRegister
;
505 stor_cl
= CValueStorLocalVar
;
508 stor_cl
= CValueStorUndef
;
513 stor_cl
= CValueStorUndef
;
515 type_cast
= TYPE_NAME(type
);
517 CVWriteValueBeginInfo(conn
,
522 0, /* XXX - frameno */
526 ""); /* transcript */
530 energize_end_variable_annotation()
535 last_expr
--; /* Pop the expr stack */
536 **last_expr
= '\000'; /* Cut off the last part of the expr */
538 CVWriteValueEndInfo(conn
,
540 ""); /* transcript */
543 /* Tell the kernel that the target is now running. */
548 CVWriteProgramBusyInfo(conn
,
550 ""); /* XXX ? transcript */
551 CWriteRequestBuffer(conn
); /* Must take place synchronusly! */
552 stack_info_valid
= 0;
557 energize_symbol_file(objfile
)
558 struct objfile
*objfile
;
563 CVWriteSymbolTableInfo(conn
,
565 ""); /* Transcript */
568 /* execute_command_1(echo, queue, cmd, args) - echo - non-zero means echo the
569 command. queue - non-zero means don't execute it now, just save it away for
570 later. cmd - string containing printf control sequences. args - list of
571 arguments needed by those control sequences.
574 /* Linked list of queued up commands */
575 static struct command_line
*queued_commands
= 0;
576 static struct command_line
*last_queued_command
= 0;
578 /* Call this routine to save a command for later. The command string is
579 copied into freshly malloc'ed memory. */
586 struct command_line
*cl
;
589 s
= (strlen(cmd
) + 1) + 7 & ~(unsigned long)7;
591 buf
= (char *)xmalloc(s
+ sizeof(struct command_line
));
592 cl
= (struct command_line
*)(buf
+ s
);
596 strncpy(cl
->line
, cmd
, s
);
599 last_queued_command
->next
= cl
;
601 queued_commands
= cl
;
603 last_queued_command
= cl
;
606 /* Call this procedure to take a command off of the command queue. It returns
607 a pointer to a buf which the caller is responsible for freeing. NULL is
608 returned if there are no commands queued. */
613 struct command_line
*cl
;
616 cl
= queued_commands
;
621 queued_commands
= cl
->next
;
627 execute_command_1(va_alist
)
630 char buf
[100]; /* XXX - make buf dynamic! */
639 echo
= va_arg(args
, int);
640 queue
= va_arg(args
, int);
641 cmd
= va_arg(args
, char *);
643 vsprintf(buf
, cmd
, args
);
650 printf_filtered("%s\n", buf
);
651 execute_command(buf
, 1);
661 kernel_record(fd
, ptr
, num
)
666 fwrite(ptr
, num
, 1, kerout
);
668 return write(fd
, ptr
, num
);
673 energize_condition_breakpoint(b
)
674 struct breakpoint
*b
;
677 CVWriteBreakConditionInfo(conn
,
680 b
->cond_string
? b
->cond_string
: "",
686 energize_commands_breakpoint(b
)
687 struct breakpoint
*b
;
689 struct command_line
*l
;
694 CVWriteBreakCommandBegInfo(conn
,
697 ""); /* transcript */
699 for (l
= b
->commands
; l
; l
= l
->next
)
700 CVWriteBreakCommandEntryInfo(conn
,
703 ""); /* transcript */
705 CVWriteBreakCommandEndInfo(conn
,
707 ""); /* transcript */
711 breakpoint_notify(b
, action
)
712 struct breakpoint
*b
;
718 char *included_in_filename
= "";
723 if (b
->type
!= bp_breakpoint
)
726 filename
= full_filename(b
->symtab
);
728 sym
= find_pc_function(b
->address
);
730 funcname
= SYMBOL_NAME(sym
);
732 CVWriteBreakpointInfo (conn
,
741 filename
? filename
: "",
742 "", /* included_in_filename */
747 energize_commands_breakpoint(b
);
749 energize_condition_breakpoint(b
);
756 energize_create_breakpoint(b
)
757 struct breakpoint
*b
;
759 breakpoint_notify(b
, CEnableBreakpoint
);
763 energize_delete_breakpoint(b
)
764 struct breakpoint
*b
;
766 breakpoint_notify(b
, CDeleteBreakpoint
);
770 energize_enable_breakpoint(b
)
771 struct breakpoint
*b
;
773 breakpoint_notify(b
, CEnableBreakpoint
);
777 energize_disable_breakpoint(b
)
778 struct breakpoint
*b
;
780 breakpoint_notify(b
, CDisableBreakpoint
);
784 energize_ignore_breakpoint(b
)
785 struct breakpoint
*b
;
787 breakpoint_notify(b
, CBreakAttrUnchanged
);
790 /* Open up a pty and its associated tty. Return the fd of the tty. */
798 struct termios termios
;
800 #define HIGHPTY (('z' - 'p') * 16 - 1)
802 for (n
= 0; n
<= HIGHPTY
; n
++)
804 sprintf(dev
, "/dev/pty%c%x", n
/16 + 'p', n
%16);
805 if (stat(dev
, &statbuf
))
807 ptyfd
= open(dev
, O_RDWR
);
810 sprintf(dev
, "/dev/tty%c%x", n
/16 + 'p', n
%16);
811 ttyfd
= open(dev
, O_RDWR
);
812 if (ttyfd
< 0) {close(ptyfd
); continue;}
814 /* Setup pty for non-blocking I/O. Also make it give us a SIGIO when
815 there's data available. */
817 n
= fcntl(ptyfd
, F_GETFL
, 0);
818 fcntl(ptyfd
, F_SETFL
, n
|FNDELAY
|FASYNC
);
819 fcntl(ptyfd
, F_SETOWN
, getpid());
821 tcgetattr(ttyfd
, &termios
);
822 termios
.c_oflag
&= ~OPOST
; /* No post-processing */
823 tcsetattr(ttyfd
, TCSANOW
, &termios
);
825 inferior_pty
= ptyfd
;
826 inferior_tty
= ttyfd
;
830 error ("getpty: can't get a pty\n");
833 /* Examine a protocol packet from the driver. */
836 kernel_dispatch(queue
)
837 int queue
; /* Non-zero means we should just queue up
840 register CHeader
*head
;
842 head
= (CHeader
*)CPeekNextRequest (conn
);
845 fprintf (stderr
, "EOF on kernel read!\n");
849 if (head
->reqType
< LastTtyRequestRType
)
851 CTtyRequest
* req
= CReadTtyRequest (conn
);
852 switch (req
->head
.reqType
)
854 case AcceptConnectionRType
:
855 /* Tell the rest of the world that energize is now set up */
859 case RefuseConnectionRType
:
860 fprintf (stderr
, "Debugger connection refused\n");
863 case KillProgramRType
:
871 p
= CGetVstring(conn
, &len
);
872 kernel_to_pty(p
, len
);
876 fprintf(stderr
, "Unknown request type = %d\n",
883 CVDebuggerRequest
*req
= CVReadDebuggerRequest (conn
);
886 fprintf (stderr
, "CVReadDebuggerRequest returned NULL, type = %d\n",
891 switch (req
->head
.request
->reqType
)
893 case OpenProgramInstanceRType
:
895 char *arglist
, buf
[100]; /* XXX - Make buf dynamic! */
897 /* XXX - should notice when program_id changes */
898 arglist
= req
->openProgramInstance
.progArglist
.text
;
899 arglen
= req
->openProgramInstance
.progArglist
.byteLen
;
901 execute_command_1(1, queue
, "break main");
902 execute_command_1(1, queue
, "enable delete $bpnum");
905 execute_command_1(1, queue
, "set args %.*s", arglen
, arglist
);
907 execute_command_1(1, queue
, "run");
910 case SearchPathRType
:
911 directory_command(req
->searchPath
.searchPath
.text
, 0);
913 case QuitDebuggerRType
:
914 execute_command_1(1, queue
, "quit");
917 if (req
->run
.request
->useArglist
== CNewArglist
)
919 execute_command_1(1, queue
, "set args %.*s",
920 req
->run
.progArglist
.byteLen
,
921 req
->run
.progArglist
.text
);
923 execute_command_1(1, queue
, "run");
926 execute_command_1(1, queue
, "continue");
929 execute_command_1(1, queue
, "step %d", req
->step
.request
->stepCount
);
932 execute_command_1(1, queue
, "next %d", req
->next
.request
->nextCount
);
934 case ChangeStackFrameRType
:
935 switch (req
->changeStackFrame
.request
->frameMovement
)
937 case CToCurrentStackFrame
:
938 execute_command_1(1, queue
, "frame %d",
939 req
->changeStackFrame
.request
->frameNo
);
941 case CToInnerStackFrame
:
942 execute_command_1(1, queue
, "down %d",
943 req
->changeStackFrame
.request
->frameNo
);
945 case CToOuterStackFrame
:
946 execute_command_1(1, queue
, "up %d",
947 req
->changeStackFrame
.request
->frameNo
);
949 case CToAbsoluteStackFrame
:
950 execute_command_1(1, queue
, "frame %d",
951 req
->changeStackFrame
.request
->frameNo
);
956 /* XXX - deal with limit??? */
957 execute_command_1(1, queue
, "backtrace");
960 execute_command_1(1, queue
, "finish");
962 case TerminateProgramRType
:
963 execute_command_1(1, queue
, "kill");
965 case NewBreakpointRType
:
970 tail
= strrchr(req
->newBreakpoint
.fileName
.text
, '/');
972 tail
= req
->newBreakpoint
.fileName
.text
;
975 skipped
= tail
- req
->newBreakpoint
.fileName
.text
;
976 execute_command_1(1, queue
, "break %.*s:%d",
977 req
->newBreakpoint
.fileName
.byteLen
- skipped
,
979 req
->newBreakpoint
.request
->fileLinePos
);
983 killpg(pgrp_inferior
, SIGINT
);
990 /* XXX - should really break command up into seperate lines
991 and spoon-feed it to execute_command */
993 text
= req
->userInput
.userInput
.text
;
994 len
= req
->userInput
.userInput
.byteLen
;
996 if (text
[len
-1] == '\n') text
[len
-1] = '\000';
998 while (*text
== ' ' || *text
== '\t') text
++;
1000 if (strcmp(text
, "]*[") == 0) /* XXX - What does this mean??? */
1003 if (*text
!= '\000')
1004 execute_command_1(0, queue
, "%s", text
);
1006 print_prompt(); /* User just typed a blank line */
1009 case QueryResponseRType
:
1013 if (req
->queryResponse
.request
->response
)
1017 execute_command_1(1, 1, resp
);
1018 printf_filtered("%s\n", resp
);
1021 case ChangeBreakpointRType
:
1022 switch (req
->changeBreakpoint
.request
->breakpointAttr
)
1024 case CBreakAttrUnchanged
:
1025 execute_command_1(1, queue
, "ignore %d %d",
1026 req
->changeBreakpoint
.request
->breakpointId
,
1027 req
->changeBreakpoint
.request
->ignoreCount
);
1029 case CEnableBreakpoint
:
1030 execute_command_1(1, queue
, "enable %d",
1031 req
->changeBreakpoint
.request
->breakpointId
);
1033 case CDisableBreakpoint
:
1034 execute_command_1(1, queue
, "disable %d",
1035 req
->changeBreakpoint
.request
->breakpointId
);
1037 case CDeleteBreakpoint
:
1038 execute_command_1(1, queue
, "delete %d",
1039 req
->changeBreakpoint
.request
->breakpointId
);
1041 case CEnableDisableBreakpoint
:
1042 execute_command_1(1, queue
, "enable once %d",
1043 req
->changeBreakpoint
.request
->breakpointId
);
1045 case CEnableDeleteBreakpoint
:
1046 execute_command_1(1, queue
, "enable delete %d",
1047 req
->changeBreakpoint
.request
->breakpointId
);
1050 printf_filtered("ChangeBreakpointRType: unknown breakpointAttr\n");
1051 printf_filtered(" breakpointAttr = %d\n",
1052 req
->changeBreakpoint
.request
->breakpointAttr
);
1053 printf_filtered(" breakpointId = %d\n",
1054 req
->changeBreakpoint
.request
->breakpointId
);
1055 printf_filtered(" breakpointType = %d\n",
1056 req
->changeBreakpoint
.request
->breakpointType
);
1057 printf_filtered(" ignoreCount = %d\n",
1058 req
->changeBreakpoint
.request
->ignoreCount
);
1062 case BreakConditionRType
:
1063 execute_command_1(1, queue
, "condition %d %.*s",
1064 req
->breakCondition
.request
->breakpointId
,
1065 req
->breakCondition
.condition
.byteLen
,
1066 req
->breakCondition
.condition
.text
);
1068 case BreakCommandsRType
:
1069 /* Put pointers to where energize_command_line_input() can find
1071 doing_breakcommands_message
= 1;
1072 command_line_length
= req
->breakCommands
.commands
.byteLen
;
1073 command_line_text
= req
->breakCommands
.commands
.text
;
1074 execute_command_1(1, queue
, "commands %d",
1075 req
->breakCommands
.request
->breakpointId
);
1076 command_line_text
= (char *)NULL
;
1077 command_line_length
= 0;
1078 doing_breakcommands_message
= 0;
1080 case ShowValueRType
:
1082 char expr
[100], *p
= expr
;
1086 if (req
->showValue
.request
->ref_type
== CValuePointerRef
)
1089 if (req
->showValue
.type_cast
.byteLen
)
1092 strncat(expr
, req
->showValue
.type_cast
.text
,
1093 req
->showValue
.type_cast
.byteLen
);
1097 if (req
->showValue
.field
.byteLen
)
1100 strncat(expr
, req
->showValue
.expression
.text
,
1101 req
->showValue
.expression
.byteLen
);
1103 if (req
->showValue
.field
.byteLen
)
1107 strncat(expr
, req
->showValue
.field
.text
,
1108 req
->showValue
.field
.byteLen
);
1111 execute_command_1(1, queue
, "print %s", expr
);
1116 char expr
[100], *p
= expr
;
1120 if (req
->setValue
.request
->ref_type
== CValuePointerRef
)
1124 if (req
->setValue
.type_cast
.byteLen
)
1127 strncat(expr
, req
->setValue
.type_cast
.text
,
1128 req
->setValue
.type_cast
.byteLen
);
1132 if (req
->setValue
.field
.byteLen
)
1135 strncat(expr
, req
->setValue
.expression
.text
,
1136 req
->setValue
.expression
.byteLen
);
1138 if (req
->setValue
.field
.byteLen
)
1142 strncat(expr
, req
->setValue
.field
.text
,
1143 req
->setValue
.field
.byteLen
);
1146 execute_command_1(1, queue
, "print %s = (%s) %s", expr
,
1147 req
->setValue
.type_cast
.text
,
1148 req
->setValue
.value
.text
);
1152 fprintf(stderr
, "Unknown request type = %d\n",
1153 req
->head
.request
->reqType
);
1156 free (req
); /* Should probably call CVFreeDebuggerRequest() here, but
1157 can't do so if interrupt level has mucked with req->
1158 request. CVFreeDebuggerRequest() only ends up calling
1163 /* Return a bitmask indicating if the kernel or the pty did something
1164 interesting. Set poll to non-zero if you don't want to wait. */
1167 wait_for_events(poll
)
1173 static struct timeval tv
= {0};
1175 /* Output all pending requests. */
1176 CWriteRequestBuffer(conn
);
1180 /* Wait till there's some activity from the kernel or the pty. */
1183 FD_SET(kerfd
, &readfds
);
1184 if (inferior_pty
> 0)
1185 FD_SET(inferior_pty
, &readfds
);
1187 numfds
= select(sizeof(readfds
)*8, &readfds
, 0, 0, &tv
);
1189 numfds
= select(sizeof(readfds
)*8, &readfds
, 0, 0, 0);
1191 while (numfds
<= 0 && !poll
);
1193 if (FD_ISSET(inferior_pty
, &readfds
))
1194 eventmask
|= PTY_EVENT
;
1196 if (FD_ISSET(kerfd
, &readfds
))
1197 eventmask
|= KERNEL_EVENT
;
1202 /* This is called from read_command_lines() to provide the text for breakpoint
1203 commands, which is supplied in a BreakCommands message. Each call to this
1204 routine supplies a single line of text, with the newline removed. */
1206 /* This routine may be invoked in two different contexts. In the first, it
1207 is being called as a result of the BreakCommands message. In this case,
1208 all of the command text is immediately available. In the second case, it is
1209 called as a result of the user typing the 'command' command. The command
1210 text then needs to be glommed out of UserInput messages (and possibly other
1211 messages as well). The most 'straighforward' way of doing this is to
1212 basically simulate the main loop, but just accumulate the command text
1213 instead of sending it to execute_command(). */
1216 energize_command_line_input(prompt
, repeat
)
1223 return command_line_input(prompt
, repeat
);
1225 if (doing_breakcommands_message
)
1227 if (command_line_length
<= 0)
1228 return (char *)NULL
;
1230 p
= command_line_text
;
1232 while (command_line_length
-- > 0)
1234 if (*command_line_text
== '\n')
1236 *command_line_text
= '\000';
1237 command_line_text
++;
1240 command_line_text
++;
1243 printf_filtered("%s\n", p
);
1248 /* We come here when the user has typed the 'command' or 'define' command
1249 to the GDB window. We are basically deep inside of the 'command'
1250 command processing routine right now, and will be called to get a new
1251 line of input. We expect that kernel_dispatch will queue up only one
1252 command at a time. */
1255 static char buf
[100];
1257 eventmask
= wait_for_events(0);
1259 if (eventmask
& PTY_EVENT
)
1262 if (eventmask
& KERNEL_EVENT
)
1263 kernel_dispatch(1); /* Queue up commands */
1265 /* Note that command has been echoed by the time we get here */
1267 p
= dequeue_command();
1271 strncpy(buf
, p
, sizeof(buf
));
1280 /* Establish contact with the kernel. */
1283 energize_initialize(energize_id
, execarg
)
1289 extern long strtol(char *str
, char **ptr
, int base
);
1290 char pathname
[MAXPATHLEN
];
1296 if (!execarg
) execarg
= "";
1298 printf("\ngdb-debugger pid=%d\n", getpid()); /* XXX - debugging only */
1300 /* First establish the connection with the kernel. */
1302 kerfd
= COpenClientSocket(NULL
);
1304 printf("COpenClientSocket() failed\n");
1308 /* Setup for I/O interrupts when appropriate. */
1310 n
= fcntl(kerfd
, F_GETFL
, 0);
1311 fcntl(kerfd
, F_SETFL
, n
|FASYNC
);
1312 fcntl(kerfd
, F_SETOWN
, getpid());
1314 /* Setup connection buffering. */
1316 CSetSocketBufferSize (kerfd
, 12000);
1318 /* Generate a new connection control block. */
1320 conn
= NewConnection (0, kerfd
, kerfd
);
1322 printf("NewConnection() failed\n");
1326 #ifdef KERNEL_RECORD
1327 kerout
= fopen("kernel.output", "+w");
1329 CReadWriteHooks(conn
, conn
->previewMethod
, conn
->readMethod
, kernel_record
);
1332 /* Tell the kernel that we are the "debugger". */
1334 req
= CWriteTtyRequest (conn
, QueryConnectionRType
);
1335 req
->generic
.queryconnection
.major
= 0;
1336 req
->generic
.queryconnection
.minor
= 0;
1337 req
->generic
.queryconnection
.cadillacId1
=strtol(energize_id
, &ctmp
, 16);
1338 req
->generic
.queryconnection
.cadillacId2
= strtol(++ctmp
, NULL
, 16);
1339 req
->generic
.queryconnection
.nProtocols
= 1;
1340 CWriteProtocol (conn
, 0, 0, "debugger");
1341 CWriteLength (conn
);
1343 /* Tell the kernel that we are actually running. */
1345 /* KROCK ALERT!!! The kernel doesn't really care about the arguments to
1346 the program at all! It only cares that argument 7 be the name of the
1347 target program. So, we just fill in the rest of the slots with
1348 padding. I hope the kernel never cares about this! */
1350 req
= CWriteTtyRequest (conn
, RunningProgramRType
);
1351 req
->runningprogram
.argc
= 8;
1353 CWriteVstring0 (conn
, pathname
);
1355 CWriteVstring0 (conn
, "0");
1356 CWriteVstring0 (conn
, "1");
1357 CWriteVstring0 (conn
, "2");
1358 CWriteVstring0 (conn
, "3");
1359 CWriteVstring0 (conn
, "4");
1360 CWriteVstring0 (conn
, "5");
1361 CWriteVstring0 (conn
, "6");
1362 CWriteVstring0 (conn
, execarg
);
1363 CWriteLength (conn
);
1365 /* Tell the kernel our PID and all that */
1368 CVWriteDebugProgramInfo(conn
,
1374 /* Tell the rest of the world that Energize is now set up. */
1377 setsid(); /* Drop controlling tty, become pgrp master */
1378 getpty(); /* Setup the pty */
1379 dup2(inferior_tty
, 0); /* Attach all GDB I/O to the pty */
1380 dup2(inferior_tty
, 1);
1381 dup2(inferior_tty
, 2);
1384 /* This is called from execute_command, and provides a wrapper around
1385 various command routines in a place where both protocol messages and
1386 user input both flow through.
1390 energize_call_command(cmdblk
, arg
, from_tty
)
1391 struct cmd_list_element
*cmdblk
;
1397 (*cmdblk
->function
.cfunc
) (arg
, from_tty
);
1401 if (cmdblk
->class == class_run
)
1405 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1409 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1415 energize_new_process()
1417 instance_id
= inferior_pid
;
1428 eventmask
= wait_for_events(1);
1433 if (eventmask
& PTY_EVENT
)
1436 if (eventmask
& KERNEL_EVENT
)
1442 energize_wait(status
)
1448 return wait(status
);
1450 signal(SIGIO
, iosig
);
1454 signal(SIGIO
, SIG_DFL
);
1464 /* All requests from the Energize kernel eventually end up here. */
1467 energize_main_loop()
1470 struct cleanup
*old_chain
;
1472 doing_breakcommands_message
= 0;
1474 /* We will come thru here any time there is an error, so send status if
1481 /* The actual event loop! */
1488 old_chain
= make_cleanup(null_routine
, 0);
1490 /* First, empty out the command queue, then check for new requests. */
1492 while (cmd
= dequeue_command())
1494 execute_command_1(1, 0, cmd
);
1498 eventmask
= wait_for_events(0);
1500 if (eventmask
& PTY_EVENT
)
1503 if (eventmask
& KERNEL_EVENT
)
1506 bpstat_do_actions(&stop_bpstat
);
1507 do_cleanups(old_chain
);