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 "energize/connection.h"
31 #include "energize/genericreq.h"
32 #include "energize/debuggerreq.h"
33 #include "energize/debuggerconn.h"
34 #include "energize/ttyconn.h"
41 #include <sys/filio.h>
44 #include <sys/errno.h>
48 /* Non-zero means that we're doing the energize interface. */
51 /* Non-zero means we are reloading breakpoints, etc from the
52 Energize kernel, and we should suppress various messages */
53 static int energize_reloading
= 0;
55 /* Connection block for debugger<=>kernel communications. */
56 static Connection
*conn
= 0;
58 /* fd for our socket to the kernel. */
61 /* The kernel's ID for this instance of the program. */
62 static int program_id
;
64 static int instance_id
;
66 /* The fd for the pty associated with the inferior. */
67 static int inferior_pty
= -1;
68 static int inferior_tty
= -1;
70 static int has_run
= 0;
72 extern int pgrp_inferior
;
74 extern char *source_path
;
76 /* The name of the executable file */
77 static char *exec_file
;
79 /* Tell energize_command_line_input() where to get its text from */
80 static int doing_breakcommands_message
= 0;
82 /* Stash command text here */
83 static char *command_line_text
= 0;
84 static int command_line_length
= 0;
86 /* Flags returned by wait_for_events() */
87 #define KERNEL_EVENT 1
91 /* This routine redirects the output of fputs_filtered to the kernel so that
92 the user can see what's going on in his debugger window. */
99 CVWriteTranscriptInfo (conn
, instance_id
, (char *)ptr
);
105 energize_query(query
, args
)
114 vsprintf(buf
, query
, args
);
116 CVWriteQueryInfo(conn
,
121 ""); /* transcript */
125 energize_acknowledge_query(ack
)
128 CVWriteQueryInfo(conn
,
133 ""); /* transcript */
136 /* Copy all data from the pty to the kernel. */
147 cc
= read(inferior_pty
, buf
, sizeof(buf
));
151 && (errno
== EWOULDBLOCK
152 || errno
== EAGAIN
)))
159 perror("pty_to_kernel: pty read error");
163 req
= CWriteTtyRequest(conn
, TextIORType
);
164 CWriteVstringLen(conn
, buf
, cc
);
167 CWriteRequestBuffer(conn
);
170 /* Copy data from the kernel to the pty. */
173 kernel_to_pty(data
, len
)
179 cc
= write(inferior_pty
, data
, len
);
187 perror("kernel_to_pty: pty write error");
190 printf("Couldn't write all the data to the pty, wanted %d, got %d\n",
196 full_filename(symtab
)
197 struct symtab
*symtab
;
205 if (symtab
->fullname
)
206 return savestring(symtab
->fullname
, strlen(symtab
->fullname
));
208 if (symtab
->filename
[0] == '/')
209 return savestring(symtab
->filename
, strlen(symtab
->filename
));
212 pathlen
= strlen(symtab
->dirname
);
215 if (symtab
->filename
)
216 pathlen
+= strlen(symtab
->filename
);
218 filename
= xmalloc(pathlen
+1);
221 strcpy(filename
, symtab
->dirname
);
224 if (symtab
->filename
)
225 strcat(filename
, symtab
->filename
);
230 /* Tell the energize kernel how high the stack is so that frame numbers (which
231 are relative to the current stack height make sense.
233 Calculate the number of frames on the stack, and the number of subroutine
234 invocations that haven't changed since the last call to this routine. The
235 second number is calculated by comparing the PCs of the current stack frames
236 to the PCs of the previous set of stack frames. The screw here is that a
237 subroutine may call several different procedures, which means that the PC
238 in its frame changes, even though you are still in the same subroutine. We
239 resolve this by converting the frames PC into the PC at the start of the
240 function (for efficiency, this is done only if the simple comparison test
249 /* Non-zero means that Energize kernel already knows how high the stack is. */
250 static int stack_info_valid
= 0;
255 struct pclist
*pclist
= 0, *pli
, *opli
;
256 static struct pclist
*old_pclist
;
260 if (stack_info_valid
)
266 /* First, calculate the stack height, and build the new pclist */
268 for (frame
= get_current_frame();
270 frame
= get_prev_frame(frame
))
273 pli
= (struct pclist
*)xmalloc(sizeof(struct pclist
));
280 /* Now, figure out how much of the stack hasn't changed */
282 for (pli
= pclist
, opli
= old_pclist
;
283 pli
!= 0 && opli
!= 0;
284 pli
= pli
->next
, opli
= opli
->next
, (similar
)++)
286 if ((pli
->pc
!= opli
->pc
)
287 && (get_pc_function_start(pli
->pc
)
288 != get_pc_function_start(opli
->pc
)))
292 /* Free up all elements of the old pclist */
303 old_pclist
= pclist
; /* Install the new pclist */
305 CVWriteStackSizeInfo(conn
,
307 height
, /* Frame depth */
309 similar
, /* Frame diff */
313 stack_info_valid
= 1;
316 /* Tell the Energize server about the file and line # that corresponds to pc,
317 and which stack frame level that pc corresponds to. */
320 send_location(pc
, frame_level
)
324 char *funcname
, *filename
;
325 struct symtab_and_line sal
;
326 struct symbol
*symbol
;
328 sal
= find_pc_line(pc
, 0);
329 symbol
= find_pc_function(pc
);
331 funcname
= symbol
? symbol
->name
: "";
332 filename
= full_filename(sal
.symtab
);
336 CVWriteStackFrameInfo(conn
,
343 "" /* XXX ? transcript */
349 /* Tell the kernel where we are in the program, and what the stack looks like.
356 struct symbol
*symbol
;
357 static int sent_prog_inst
= 0;
359 symbol
= find_pc_function(stop_pc
);
360 funcname
= symbol
? symbol
->name
: "";
365 if (inferior_pid
== 0) /* target has died */
367 CVWriteProgramTerminatedInfo(conn
,
377 CVWriteProgramInstanceInfo(conn
,
386 send_location(stop_pc
,
387 selected_frame_level
); /* Had better be 0! */
389 CVWriteProgramStoppedInfo(conn
,
391 0, /* XXX - breakpoint # or signal # */
394 "" /* XXX ? transcript */
399 /* Call this to output annotated function names. Names will be demangled if
400 necessary. arg_mode contains flags that are passed on to cplus_demangle. */
403 energize_annotate_function(funcname
, arg_mode
, level
)
409 char *demangled_name
= NULL
;
411 if (funcname
== NULL
)
416 demangled_name
= cplus_demangle(funcname
, arg_mode
);
420 funcname
= demangled_name
;
421 printf_filtered("'");
427 if (level
< 0) level
= 0;
429 CVWriteBackTraceEntryInfo(conn
,
436 free(demangled_name
);
437 printf_filtered("'");
441 /* Call this just prior to printing out the name & value of a variable. This
442 tells the kernel where to annotate the output. */
445 expression - A text handle on what GDB can use to reference this value.
446 This can be a symbol name, or a convenience var, etc...
447 symbol - Used to determine the scope of the data. May be NULL.
448 type - Determines if we have a pointer ref, and the print name of the type.
449 Used in ShowValue message.
450 valaddr - The address in target memory of the data.
451 field - The field name of the struct or union element being referenced.
454 static char cum_expr
[200]; /* Cumulative expression */
455 static char *expr_stack
[100] = {cum_expr
}; /* Pointers to end of expressions */
456 static char **last_expr
= expr_stack
; /* Current expr stack pointer */
459 energize_start_variable_annotation(expression
, symbol
, type
, valaddr
, field
)
461 struct symbol
*symbol
;
468 enum type_code type_code
;
469 enum address_class sym_class
;
477 strcpy(*last_expr
++, expression
);
478 *last_expr
= *(last_expr
-1) + strlen(expression
);
480 switch (TYPE_CODE(type
))
482 case TYPE_CODE_ARRAY
:
483 case TYPE_CODE_STRUCT
:
484 case TYPE_CODE_UNION
:
488 ref_type
= CValueValueRef
;
491 ref_type
= CValuePointerRef
;
494 ref_type
= CValueUndefRef
;
498 /* Make sure that pointer points at something we understand */
500 if (ref_type
== CValuePointerRef
)
501 switch (TYPE_CODE(TYPE_TARGET_TYPE(type
)))
504 case TYPE_CODE_ARRAY
:
505 case TYPE_CODE_STRUCT
:
506 case TYPE_CODE_UNION
:
512 ref_type
= CValueUndefRef
;
518 sym_class
= SYMBOL_CLASS(symbol
);
523 case LOC_CONST_BYTES
:
524 stor_cl
= CValueStorStaticConst
;
527 stor_cl
= CValueStorStaticVar
;
531 stor_cl
= CValueStorRegister
;
537 stor_cl
= CValueStorLocalVar
;
540 stor_cl
= CValueStorUndef
;
545 stor_cl
= CValueStorUndef
;
547 type_cast
= TYPE_NAME(type
);
549 CVWriteValueBeginInfo(conn
,
554 0, /* XXX - frameno */
558 ""); /* transcript */
562 energize_end_variable_annotation()
567 last_expr
--; /* Pop the expr stack */
568 **last_expr
= '\000'; /* Cut off the last part of the expr */
570 CVWriteValueEndInfo(conn
,
572 ""); /* transcript */
575 /* Tell the kernel that the target is now running. */
580 CVWriteProgramBusyInfo(conn
,
582 ""); /* XXX ? transcript */
583 CWriteRequestBuffer(conn
); /* Must take place synchronusly! */
584 stack_info_valid
= 0;
589 energize_symbol_file(objfile
)
590 struct objfile
*objfile
;
595 CVWriteSymbolTableInfo(conn
,
597 ""); /* Transcript */
600 /* execute_command_1(echo, queue, cmd, args) - echo - non-zero means echo the
601 command. queue - non-zero means don't execute it now, just save it away for
602 later. cmd - string containing printf control sequences. args - list of
603 arguments needed by those control sequences.
606 /* Linked list of queued up commands */
607 static struct command_line
*queued_commands
= 0;
608 static struct command_line
*last_queued_command
= 0;
610 /* Call this routine to save a command for later. The command string is
611 copied into freshly malloc'ed memory. */
618 struct command_line
*cl
;
621 s
= (strlen(cmd
) + 1) + 7 & ~(unsigned long)7;
623 buf
= (char *)xmalloc(s
+ sizeof(struct command_line
));
624 cl
= (struct command_line
*)(buf
+ s
);
628 strncpy(cl
->line
, cmd
, s
);
631 last_queued_command
->next
= cl
;
633 queued_commands
= cl
;
635 last_queued_command
= cl
;
638 /* Call this procedure to take a command off of the command queue. It returns
639 a pointer to a buf which the caller is responsible for freeing. NULL is
640 returned if there are no commands queued. */
645 struct command_line
*cl
;
648 cl
= queued_commands
;
653 queued_commands
= cl
->next
;
659 execute_command_1(va_alist
)
662 char buf
[100]; /* XXX - make buf dynamic! */
670 echo
= va_arg(args
, int);
672 queue
= va_arg(args
, int);
673 cmd
= va_arg(args
, char *);
675 vsprintf(buf
, cmd
, args
);
682 printf_filtered("%s\n", buf
);
683 execute_command(buf
, 1);
693 kernel_record(fd
, ptr
, num
)
698 fwrite(ptr
, num
, 1, kerout
);
700 return write(fd
, ptr
, num
);
705 energize_condition_breakpoint(b
)
706 struct breakpoint
*b
;
709 CVWriteBreakConditionInfo(conn
,
712 b
->cond_string
? b
->cond_string
: "",
718 energize_commands_breakpoint(b
)
719 struct breakpoint
*b
;
721 struct command_line
*l
;
726 CVWriteBreakCommandBegInfo(conn
,
729 ""); /* transcript */
731 for (l
= b
->commands
; l
; l
= l
->next
)
732 CVWriteBreakCommandEntryInfo(conn
,
735 ""); /* transcript */
737 CVWriteBreakCommandEndInfo(conn
,
739 ""); /* transcript */
743 breakpoint_notify(b
, action
)
744 struct breakpoint
*b
;
750 char *included_in_filename
= "";
753 || energize_reloading
) /* Don't notify energize about breakpoint changes, as it's about to send us
757 if (b
->type
!= bp_breakpoint
)
760 filename
= full_filename(b
->symtab
);
762 sym
= find_pc_function(b
->address
);
764 funcname
= SYMBOL_NAME(sym
);
766 CVWriteBreakpointInfo (conn
,
775 filename
? filename
: "",
776 "", /* included_in_filename */
781 energize_commands_breakpoint(b
);
783 energize_condition_breakpoint(b
);
790 energize_create_breakpoint(b
)
791 struct breakpoint
*b
;
793 breakpoint_notify(b
, CEnableBreakpoint
);
797 energize_delete_breakpoint(b
)
798 struct breakpoint
*b
;
800 breakpoint_notify(b
, CDeleteBreakpoint
);
804 energize_enable_breakpoint(b
)
805 struct breakpoint
*b
;
807 breakpoint_notify(b
, CEnableBreakpoint
);
811 energize_disable_breakpoint(b
)
812 struct breakpoint
*b
;
814 breakpoint_notify(b
, CDisableBreakpoint
);
818 energize_ignore_breakpoint(b
)
819 struct breakpoint
*b
;
821 breakpoint_notify(b
, CBreakAttrUnchanged
);
824 /* Open up a pty and its associated tty. Return the fd of the tty. */
833 struct termios termios
;
835 #define HIGHPTY (('z' - 'p') * 16 - 1)
837 for (n
= 0; n
<= HIGHPTY
; n
++)
839 sprintf(dev
, "/dev/pty%c%x", n
/16 + 'p', n
%16);
840 if (stat(dev
, &statbuf
))
842 ptyfd
= open(dev
, O_RDWR
);
845 sprintf(dev
, "/dev/tty%c%x", n
/16 + 'p', n
%16);
846 ttyfd
= open(dev
, O_RDWR
);
853 /* Setup pty for non-blocking I/O. Also make it give us a SIGIO when
854 there's data available. */
856 n
= fcntl(ptyfd
, F_GETFL
, 0);
857 fcntl(ptyfd
, F_SETFL
, n
|FNDELAY
|FASYNC
);
858 fcntl(ptyfd
, F_SETOWN
, getpid());
860 tcgetattr(ttyfd
, &termios
);
861 termios
.c_oflag
&= ~OPOST
; /* No post-processing */
862 tcsetattr(ttyfd
, TCSANOW
, &termios
);
864 inferior_pty
= ptyfd
;
865 inferior_tty
= ttyfd
;
869 error ("getpty: can't get a pty\n");
872 /* Alternate getpty for NCRs */
874 #ifdef NCR486 /* LTL */
875 #define MAX_PTM_TRY 16
876 #define MAX_GRANTPT_TRY 4
881 extern char *ptsname();
885 struct termios termios
;
887 if (stat("/dev/ptmx",&statbuf
)) error ("getpty: can't locate master\n");
889 /* Number of pseudo-terms is tuneable(16 - 255). System default is 16. */
890 for (i
= 0; i
< MAX_PTM_TRY
; i
++)
892 mfd
= open("/dev/ptmx", O_RDWR
); /* get the master */
897 if (grantpt(mfd
) < 0) /* get a slave */
898 for (j
= 0; j
< MAX_GRANTPT_TRY
; j
++)
899 if (grantpt(mfd
) == 0 )
905 if (unlockpt(mfd
) < 0)
906 { /* unlock the slave so he can be opened */
911 slavename
= ptsname(mfd
); /* get the slave device name */
913 break; /* Success! */
919 sfd
= open(slavename
, O_RDWR
);
924 error ("getpty: can't open slave\n");
927 if (slavename
==NULL
&& i
>= MAX_PTM_TRY
)
928 error ("getpty: can't get a pts\n");
930 /* setup mty for non-blocking I/O. */
932 if ((n
= fcntl(mfd
, F_GETFL
)) < 0)
933 perror ("getpty: fcntl F_GETFL failed");
934 else if (fcntl(mfd
, F_SETFL
, n
|O_NDELAY
) <0)
935 perror("getpty:fcntl F_SETFL fails");
937 /* set up for async i/o - V.4 will send SIGPOLL when data available */
939 if (ioctl (mfd
, I_SETSIG
, S_INPUT
|S_RDNORM
) < 0)
940 perror ("getpty: ioctl I_SETSIG failed");
942 /* fcntl(mfd, F_SETOWN,getpid()); SVR4 does not support this */
944 if (ioctl(sfd
, I_PUSH
, "ptem")) perror ("getpty: ioctl I_PUSH fails");
945 if (ioctl(sfd
, I_PUSH
, "ldterm")) perror ("getpty: ioctl I_PUSH fails");
947 if (tcgetattr(sfd
, &termios
)) perror("getpty: tcgetattr fails");
948 termios
.c_oflag
&= ~OPOST
; /* no post-processing */
949 if (tcsetattr(sfd
, TCSANOW
, &termios
)) perror("getpty: tcsetattr fails");
959 /* Examine a protocol packet from the driver. */
962 kernel_dispatch(queue
)
963 int queue
; /* Non-zero means we should just queue up
966 register CHeader
*head
;
968 head
= (CHeader
*)CPeekNextRequest (conn
);
971 fprintf (stderr
, "EOF on kernel read!\n");
975 if (head
->reqType
< LastTtyRequestRType
)
977 CTtyRequest
* req
= CReadTtyRequest (conn
);
978 switch (req
->head
.reqType
)
980 case AcceptConnectionRType
:
981 /* Tell the rest of the world that energize is now set up */
985 case RefuseConnectionRType
:
986 fprintf (stderr
, "Debugger connection refused\n");
989 case KillProgramRType
:
997 p
= CGetVstring(conn
, &len
);
998 kernel_to_pty(p
, len
);
1002 fprintf(stderr
, "Unknown Tty request type = %d\n",
1009 CVDebuggerRequest
*req
= CVReadDebuggerRequest (conn
);
1012 fprintf (stderr
, "CVReadDebuggerRequest returned NULL, type = %d\n",
1017 switch (req
->head
.request
->reqType
)
1019 case OpenProgramInstanceRType
:
1021 char *arglist
, buf
[100]; /* XXX - Make buf dynamic! */
1023 /* XXX - should notice when program_id changes */
1024 arglist
= req
->openProgramInstance
.progArglist
.text
;
1025 arglen
= req
->openProgramInstance
.progArglist
.byteLen
;
1027 execute_command_1(1, queue
, "break main");
1028 execute_command_1(1, queue
, "enable delete $bpnum");
1031 execute_command_1(1, queue
, "set args %.*s", arglen
, arglist
);
1033 execute_command_1(1, queue
, "run");
1036 case SearchPathRType
:
1037 directory_command(req
->searchPath
.searchPath
.text
, 0);
1039 case QuitDebuggerRType
:
1040 execute_command_1(1, queue
, "quit");
1043 if (req
->run
.request
->useArglist
== CNewArglist
)
1045 execute_command_1(1, queue
, "set args %.*s",
1046 req
->run
.progArglist
.byteLen
,
1047 req
->run
.progArglist
.text
);
1049 execute_command_1(1, queue
, "run");
1052 execute_command_1(1, queue
, "continue");
1055 execute_command_1(1, queue
, "step %d", req
->step
.request
->stepCount
);
1058 execute_command_1(1, queue
, "next %d", req
->next
.request
->nextCount
);
1060 case ChangeStackFrameRType
:
1061 switch (req
->changeStackFrame
.request
->frameMovement
)
1063 case CToCurrentStackFrame
:
1064 execute_command_1(1, queue
, "frame %d",
1065 req
->changeStackFrame
.request
->frameNo
);
1067 case CToInnerStackFrame
:
1068 execute_command_1(1, queue
, "down %d",
1069 req
->changeStackFrame
.request
->frameNo
);
1071 case CToOuterStackFrame
:
1072 execute_command_1(1, queue
, "up %d",
1073 req
->changeStackFrame
.request
->frameNo
);
1075 case CToAbsoluteStackFrame
:
1076 execute_command_1(1, queue
, "frame %d",
1077 req
->changeStackFrame
.request
->frameNo
);
1081 case BackTraceRType
:
1082 /* XXX - deal with limit??? */
1083 execute_command_1(1, queue
, "backtrace");
1086 execute_command_1(1, queue
, "finish");
1088 case TerminateProgramRType
:
1089 execute_command_1(1, queue
, "kill");
1091 case NewBreakpointRType
:
1096 tail
= strrchr(req
->newBreakpoint
.fileName
.text
, '/');
1098 tail
= req
->newBreakpoint
.fileName
.text
;
1101 skipped
= tail
- req
->newBreakpoint
.fileName
.text
;
1102 execute_command_1(1, queue
, "break %.*s:%d",
1103 req
->newBreakpoint
.fileName
.byteLen
- skipped
,
1105 req
->newBreakpoint
.request
->fileLinePos
);
1109 kill(-pgrp_inferior
, SIGINT
);
1111 case UserInputRType
:
1116 /* XXX - should really break command up into seperate lines
1117 and spoon-feed it to execute_command */
1119 text
= req
->userInput
.userInput
.text
;
1120 len
= req
->userInput
.userInput
.byteLen
;
1122 if (text
[len
-1] == '\n') text
[len
-1] = '\000';
1124 while (*text
== ' ' || *text
== '\t') text
++;
1126 if (strcmp(text
, "]*[") == 0) /* XXX - What does this mean??? */
1129 if (*text
!= '\000')
1130 execute_command_1(0, queue
, "%s", text
);
1132 print_prompt(); /* User just typed a blank line */
1135 case QueryResponseRType
:
1139 if (req
->queryResponse
.request
->response
)
1143 execute_command_1(1, 1, resp
);
1144 printf_filtered("%s\n", resp
);
1147 case ChangeBreakpointRType
:
1148 switch (req
->changeBreakpoint
.request
->breakpointAttr
)
1150 case CBreakAttrUnchanged
:
1151 execute_command_1(1, queue
, "ignore %d %d",
1152 req
->changeBreakpoint
.request
->breakpointId
,
1153 req
->changeBreakpoint
.request
->ignoreCount
);
1155 case CEnableBreakpoint
:
1156 execute_command_1(1, queue
, "enable %d",
1157 req
->changeBreakpoint
.request
->breakpointId
);
1159 case CDisableBreakpoint
:
1160 execute_command_1(1, queue
, "disable %d",
1161 req
->changeBreakpoint
.request
->breakpointId
);
1163 case CDeleteBreakpoint
:
1164 execute_command_1(1, queue
, "delete %d",
1165 req
->changeBreakpoint
.request
->breakpointId
);
1167 case CEnableDisableBreakpoint
:
1168 execute_command_1(1, queue
, "enable once %d",
1169 req
->changeBreakpoint
.request
->breakpointId
);
1171 case CEnableDeleteBreakpoint
:
1172 execute_command_1(1, queue
, "enable delete %d",
1173 req
->changeBreakpoint
.request
->breakpointId
);
1176 printf_filtered("ChangeBreakpointRType: unknown breakpointAttr\n");
1177 printf_filtered(" breakpointAttr = %d\n",
1178 req
->changeBreakpoint
.request
->breakpointAttr
);
1179 printf_filtered(" breakpointId = %d\n",
1180 req
->changeBreakpoint
.request
->breakpointId
);
1181 printf_filtered(" breakpointType = %d\n",
1182 req
->changeBreakpoint
.request
->breakpointType
);
1183 printf_filtered(" ignoreCount = %d\n",
1184 req
->changeBreakpoint
.request
->ignoreCount
);
1188 case BreakConditionRType
:
1189 execute_command_1(1, queue
, "condition %d %.*s",
1190 req
->breakCondition
.request
->breakpointId
,
1191 req
->breakCondition
.condition
.byteLen
,
1192 req
->breakCondition
.condition
.text
);
1194 case BreakCommandsRType
:
1195 /* Put pointers to where energize_command_line_input() can find
1197 doing_breakcommands_message
= 1;
1198 command_line_length
= req
->breakCommands
.commands
.byteLen
;
1199 command_line_text
= req
->breakCommands
.commands
.text
;
1200 execute_command_1(1, queue
, "commands %d",
1201 req
->breakCommands
.request
->breakpointId
);
1202 command_line_text
= (char *)NULL
;
1203 command_line_length
= 0;
1204 doing_breakcommands_message
= 0;
1206 case ShowValueRType
:
1208 char expr
[100], *p
= expr
;
1212 if (req
->showValue
.request
->ref_type
== CValuePointerRef
)
1215 if (req
->showValue
.type_cast
.byteLen
)
1218 strncat(expr
, req
->showValue
.type_cast
.text
,
1219 req
->showValue
.type_cast
.byteLen
);
1223 if (req
->showValue
.field
.byteLen
)
1226 strncat(expr
, req
->showValue
.expression
.text
,
1227 req
->showValue
.expression
.byteLen
);
1229 if (req
->showValue
.field
.byteLen
)
1233 strncat(expr
, req
->showValue
.field
.text
,
1234 req
->showValue
.field
.byteLen
);
1237 execute_command_1(1, queue
, "print %s", expr
);
1242 char expr
[100], *p
= expr
;
1246 if (req
->setValue
.request
->ref_type
== CValuePointerRef
)
1250 if (req
->setValue
.type_cast
.byteLen
)
1253 strncat(expr
, req
->setValue
.type_cast
.text
,
1254 req
->setValue
.type_cast
.byteLen
);
1258 if (req
->setValue
.field
.byteLen
)
1261 strncat(expr
, req
->setValue
.expression
.text
,
1262 req
->setValue
.expression
.byteLen
);
1264 if (req
->setValue
.field
.byteLen
)
1268 strncat(expr
, req
->setValue
.field
.text
,
1269 req
->setValue
.field
.byteLen
);
1272 execute_command_1(1, queue
, "print %s = (%s) %s", expr
,
1273 req
->setValue
.type_cast
.text
,
1274 req
->setValue
.value
.text
);
1277 case DynamicLoadRType
:
1281 filename
= req
->dynamicLoad
.filenames
.byteLen
?
1282 req
->dynamicLoad
.filenames
.text
: exec_file
;
1284 switch (req
->dynamicLoad
.request
->action
)
1286 case CDynamicLoadUpdateSymtab
:
1287 energize_reloading
= 1;
1288 execute_command_1(1, queue
, "set confirm no");
1289 execute_command_1(1, queue
, "delete");
1290 /* execute_command_1(1, queue, "set $bpnum=1");*/ /* Use this to reset breakpoint #s */
1291 execute_command_1(1, queue
, "exec-file %s", filename
);
1292 execute_command_1(1, queue
, "symbol-file %s", filename
);
1293 execute_command_1(1, queue
, "set confirm yes");
1294 energize_reloading
= 0;
1296 case CDynamicLoadRestoreStart
:
1298 case CDynamicLoadRestoreEnd
: /* Not used anymore??? */
1299 printf_filtered("\n[Target has changed, automatic restoration of state has been done.]\n");
1303 printf_filtered("DynamicLoadRType: unknown action=%d, filename=%s\n",
1304 req
->dynamicLoad
.request
->action
,
1305 req
->dynamicLoad
.filenames
.text
);
1311 fprintf(stderr
, "Unknown Debugger request type = %d\n",
1312 req
->head
.request
->reqType
);
1315 free (req
); /* Should probably call CVFreeDebuggerRequest() here, but
1316 can't do so if interrupt level has mucked with req->
1317 request. CVFreeDebuggerRequest() only ends up calling
1322 /* Return a bitmask indicating if the kernel or the pty did something
1323 interesting. Set poll to non-zero if you don't want to wait. */
1326 wait_for_events(poll
)
1332 static struct timeval tv
= {0};
1334 /* Output all pending requests. */
1335 CWriteRequestBuffer(conn
);
1339 /* Wait till there's some activity from the kernel or the pty. */
1342 FD_SET(kerfd
, &readfds
);
1344 FD_SET(inferior_pty
, &readfds
);
1347 numfds
= select(sizeof(readfds
)*8, &readfds
, 0, 0, &tv
);
1349 numfds
= select(sizeof(readfds
)*8, &readfds
, 0, 0, 0);
1351 while (numfds
<= 0 && !poll
);
1356 if (FD_ISSET(inferior_pty
, &readfds
))
1357 eventmask
|= PTY_EVENT
;
1359 if (FD_ISSET(kerfd
, &readfds
))
1360 eventmask
|= KERNEL_EVENT
;
1365 /* This is called from read_command_lines() to provide the text for breakpoint
1366 commands, which is supplied in a BreakCommands message. Each call to this
1367 routine supplies a single line of text, with the newline removed. */
1369 /* This routine may be invoked in two different contexts. In the first, it
1370 is being called as a result of the BreakCommands message. In this case,
1371 all of the command text is immediately available. In the second case, it is
1372 called as a result of the user typing the 'command' command. The command
1373 text then needs to be glommed out of UserInput messages (and possibly other
1374 messages as well). The most 'straighforward' way of doing this is to
1375 basically simulate the main loop, but just accumulate the command text
1376 instead of sending it to execute_command(). */
1379 energize_command_line_input(prompt
, repeat
)
1386 return command_line_input(prompt
, repeat
);
1388 if (doing_breakcommands_message
)
1390 if (command_line_length
<= 0)
1391 return (char *)NULL
;
1393 p
= command_line_text
;
1395 while (command_line_length
-- > 0)
1397 if (*command_line_text
== '\n')
1399 *command_line_text
= '\000';
1400 command_line_text
++;
1403 command_line_text
++;
1406 printf_filtered("%s\n", p
);
1411 /* We come here when the user has typed the 'command' or 'define' command
1412 to the GDB window. We are basically deep inside of the 'command'
1413 command processing routine right now, and will be called to get a new
1414 line of input. We expect that kernel_dispatch will queue up only one
1415 command at a time. */
1418 static char buf
[100];
1420 eventmask
= wait_for_events(0);
1422 if (eventmask
& PTY_EVENT
)
1425 if (eventmask
& KERNEL_EVENT
)
1426 kernel_dispatch(1); /* Queue up commands */
1428 /* Note that command has been echoed by the time we get here */
1430 p
= dequeue_command();
1434 strncpy(buf
, p
, sizeof(buf
));
1443 /* Establish contact with the kernel. */
1446 energize_initialize(energize_id
, execarg
)
1452 extern long strtol(char *str
, char **ptr
, int base
);
1453 char pathname
[MAXPATHLEN
];
1459 if (!execarg
) execarg
= "";
1461 exec_file
= strdup(execarg
); /* Save for later */
1463 printf("\ngdb-debugger pid=%d\n", getpid()); /* XXX - debugging only */
1465 /* First establish the connection with the kernel. */
1467 kerfd
= COpenClientSocket(NULL
);
1469 printf("COpenClientSocket() failed\n");
1473 /* Setup for I/O interrupts when appropriate. */
1476 if (ioctl (kerfd
, I_SETSIG
, S_INPUT
|S_RDNORM
) < 0)
1477 perror ("getpty: ioctl I_SETSIG failed");
1479 n
= fcntl(kerfd
, F_GETFL
, 0);
1480 fcntl(kerfd
, F_SETFL
, n
|FASYNC
);
1481 fcntl(kerfd
, F_SETOWN
, getpid());
1484 /* Setup connection buffering. */
1486 CSetSocketBufferSize (kerfd
, 12000);
1488 /* Generate a new connection control block. */
1490 conn
= NewConnection (0, kerfd
, kerfd
);
1492 printf("NewConnection() failed\n");
1496 #ifdef KERNEL_RECORD
1497 kerout
= fopen("kernel.output", "+w");
1499 CReadWriteHooks(conn
, conn
->previewMethod
, conn
->readMethod
, kernel_record
);
1502 /* Tell the kernel that we are the "debugger". */
1504 req
= CWriteTtyRequest (conn
, QueryConnectionRType
);
1505 req
->generic
.queryconnection
.major
= 0;
1506 req
->generic
.queryconnection
.minor
= 0;
1507 req
->generic
.queryconnection
.cadillacId1
=strtol(energize_id
, &ctmp
, 16);
1508 req
->generic
.queryconnection
.cadillacId2
= strtol(++ctmp
, NULL
, 16);
1509 req
->generic
.queryconnection
.nProtocols
= 1;
1510 CWriteProtocol (conn
, 0, 0, "debugger");
1511 CWriteLength (conn
);
1513 /* Tell the kernel that we are actually running. */
1515 /* KROCK ALERT!!! The kernel doesn't really care about the arguments to
1516 the program at all! It only cares that argument 7 be the name of the
1517 target program. So, we just fill in the rest of the slots with
1518 padding. I hope the kernel never cares about this! */
1520 req
= CWriteTtyRequest (conn
, RunningProgramRType
);
1521 req
->runningprogram
.argc
= 8;
1522 getcwd (pathname
, MAXPATHLEN
);
1523 CWriteVstring0 (conn
, pathname
);
1525 CWriteVstring0 (conn
, "0");
1526 CWriteVstring0 (conn
, "1");
1527 CWriteVstring0 (conn
, "2");
1528 CWriteVstring0 (conn
, "3");
1529 CWriteVstring0 (conn
, "4");
1530 CWriteVstring0 (conn
, "5");
1531 CWriteVstring0 (conn
, "6");
1532 CWriteVstring0 (conn
, execarg
);
1533 CWriteLength (conn
);
1535 /* Tell the kernel our PID and all that */
1538 CVWriteDebugProgramInfo(conn
,
1544 /* Tell the rest of the world that Energize is now set up. */
1547 /* Drop controlling tty, become pgrp master */
1551 getpty(); /* Setup the pty */
1553 /* Attach all GDB I/O to the pty */
1555 dup2(inferior_tty
, 0);
1556 dup2(inferior_tty
, 1);
1557 dup2(inferior_tty
, 2);
1560 /* This is called from execute_command, and provides a wrapper around
1561 various command routines in a place where both protocol messages and
1562 user input both flow through.
1566 energize_call_command(cmdblk
, arg
, from_tty
)
1567 struct cmd_list_element
*cmdblk
;
1573 (*cmdblk
->function
.cfunc
) (arg
, from_tty
);
1577 if (cmdblk
->class == class_run
)
1581 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1585 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1587 if (strcmp(cmdblk
->name
, "up") == 0
1588 || strcmp(cmdblk
->name
, "down") == 0
1589 || strcmp(cmdblk
->name
, "frame") == 0)
1590 send_location(get_frame_info(selected_frame
)->pc
,
1591 selected_frame_level
);
1596 energize_new_process()
1598 instance_id
= inferior_pid
;
1609 eventmask
= wait_for_events(1);
1614 if (eventmask
& PTY_EVENT
)
1617 if (eventmask
& KERNEL_EVENT
)
1623 energize_wait(status
)
1627 static sigset_t nullsigmask
= {0};
1631 return proc_wait (status
);
1633 return wait(status
);
1637 action
.sa_handler
= iosig
;
1638 action
.sa_mask
= nullsigmask
;
1639 action
.sa_flags
= SA_RESTART
;
1640 sigaction(SIGIO
, &action
, NULL
);
1642 signal(SIGIO
, iosig
);
1646 pid
= proc_wait (status
);
1651 signal(SIGIO
, SIG_IGN
);
1661 /* All requests from the Energize kernel eventually end up here. */
1664 energize_main_loop()
1667 struct cleanup
*old_chain
;
1669 doing_breakcommands_message
= 0;
1671 /* We will come thru here any time there is an error, so send status if
1678 /* The actual event loop! */
1685 old_chain
= make_cleanup(null_routine
, 0);
1687 /* First, empty out the command queue, then check for new requests. */
1689 while (cmd
= dequeue_command())
1691 execute_command_1(1, 0, cmd
);
1695 eventmask
= wait_for_events(0);
1697 if (eventmask
& PTY_EVENT
)
1700 if (eventmask
& KERNEL_EVENT
)
1703 bpstat_do_actions(&stop_bpstat
);
1704 do_cleanups(old_chain
);