7 static char *rcsid_gdb_stype_c = "$Header$";
30 /************************************************************************/
34 /* GDB - System Data Type Definitions
36 /* Author: Noah Mendelsohn
37 /* Copyright: 1986 MIT Project Athena
38 /* For copying and distribution information, please see
39 /* the file <mit-copyright.h>.
41 /* This file initializes the definitions for all system defined
42 /* data types, and it includes the type specific semantic routines
43 /* for each of the system defined types.
45 /* The initialization routine which adds these type definitions
46 /* to the type definition table is at the end of this source file.
48 /************************************************************************/
50 /* This file is organized into one section for each system
51 /* defined type followed at the end by a final section which
52 /* initializes the type tables. Each of the type specific
53 /* sections does #defines for each type specific parameter. The
54 /* gdb_i_stype initialization routine at the end of this source
55 /* file uses these defines to initialize the appropriate entry in
56 /* the type definition tables.
58 /* NOTE: some of the type definitions in this file may be machine
61 /************************************************************************/
63 #include <mit-copyright.h>
68 extern u_long ntohl(), htonl();
70 #include <netinet/in.h> /* for htonl routine */
72 /************************************************************************/
76 /************************************************************************/
78 #define IN_LEN (sizeof(int))
80 #define IN_NULL g_in_null
81 #define IN_CDLEN g_in_cdlen
82 #define IN_ENC g_in_enc
83 #define IN_DEC g_in_dec
84 #define IN_FORM g_in_form
85 #define IN_NAME "INTEGER_T"
87 #define IN_EXTERNSIZE 4 /* length of an encoded */
89 /*----------------------------------------------------------*/
93 /* Fill in a null value for an integer.
95 /*----------------------------------------------------------*/
99 char *dp; /* pointer to the data */
101 *((int *)dp) = 0; /* fill in a null value */
104 /*----------------------------------------------------------*/
108 /* Return coded length for an integer. We're currently
109 /* using the Berkeley 'htonl' routine which converts
110 /* an integer (actually a long, ahem!) to a canonical
113 /*----------------------------------------------------------*/
119 char *dp; /* pointer to the data */
120 HALF_CONNECTION hcon;
122 return IN_EXTERNSIZE;
125 /*----------------------------------------------------------*/
129 /* Encode an integer for transmission
131 /*----------------------------------------------------------*/
135 g_in_enc(dp, hcon, outp)
136 char *dp; /* pointer to data */
137 HALF_CONNECTION hcon; /* connection descriptor */
138 char *outp; /* place to put the output */
140 register char *cp; /* next char in output */
141 register char *op = outp;
142 register char *endp = outp+IN_EXTERNSIZE;
144 unsigned long converted; /* the integer goes here */
145 /* in network byte order*/
148 * Put it in network format, then copy one byte at a time to
149 * account for the fact that the RT has trouble with unaligned longs
152 converted = htonl(*(u_long *)dp);
154 cp = (char *)&converted;
160 return (int)(endp); /* return pointer to next */
161 /* unused output byte*/
164 /*----------------------------------------------------------*/
168 /* Decode an integer from external form to local
172 /*----------------------------------------------------------*/
176 g_in_dec(outp, hcon, inp)
177 char *inp; /* pointer to data */
178 HALF_CONNECTION hcon; /* connection descriptor */
179 char *outp; /* place to put the output */
181 register char *ip = inp; /* next byte of input */
183 register char *bp; /* next byte in buffer */
186 * Copy a byte at a time to buffer to account for RT difficulties
187 * with unaligned ints.
189 bp = (char *)&buffer;
196 * Convert it and return pointer to next byte of input.
199 *(int *)outp = ntohl((u_long)buffer);
203 /*----------------------------------------------------------*/
207 /* Format an integer on output logging file for
210 /*----------------------------------------------------------*/
214 char *name; /* string name of the field */
215 char *dp; /* pointer to the data */
217 fprintf(gdb_log, "INTEGER_T\t%s=%d\n",name,(*(int *)dp));
220 /************************************************************************/
224 /************************************************************************/
226 #define ST_LEN (sizeof(STRING))
227 #define ST_ALI (sizeof(int))
228 #define ST_NULL g_st_null
229 #define ST_CDLEN g_st_cdlen
230 #define ST_ENC g_st_enc
231 #define ST_DEC g_st_dec
232 #define ST_FORM g_st_form
233 #define ST_NAME "STRING_T"
235 /*----------------------------------------------------------*/
239 /* Fill in a null value for a string.
241 /*----------------------------------------------------------*/
244 char *dp; /* pointer to the data */
246 register STRING *stp = (STRING *)dp; /* re-type as string */
247 STRING_DATA(*stp) = NULL; /* no data */
248 MAX_STRING_SIZE(*stp) = 0; /* for cleanliness */
251 /*----------------------------------------------------------*/
255 /* Return coded length for a string. We have to send the
256 /* actual length of the data along with the data itself.
257 /* For this reason, we leave space for a coded integer
258 /* in addition to the data bytes. We actually call the
259 /* integer coding routines to code the length.
261 /* Note that a separate type understanding null termination
262 /* might be an interesting optimization someday.
264 /*----------------------------------------------------------*/
268 char *dp; /* pointer to the data */
269 HALF_CONNECTION hcon;
271 register STRING *stp = (STRING *)dp; /* re-type as string */
273 return (MAX_STRING_SIZE(*stp) +
274 g_in_cdlen((char *)&MAX_STRING_SIZE(*stp),hcon));
277 /*----------------------------------------------------------*/
281 /* Encode a string for transmission
283 /*----------------------------------------------------------*/
286 g_st_enc(dp, hcon, outp)
287 char *dp; /* pointer to data */
288 HALF_CONNECTION hcon; /* connection descriptor */
289 char *outp; /* place to put the output */
291 register STRING *stp = (STRING *)dp; /* re-type as string */
293 register char *nextp; /* place to put next output */
296 * Use the integer coding routine to get the length encoded first
299 len = MAX_STRING_SIZE(*stp); /* length of both source */
301 nextp = (char *)g_in_enc((char *)&len, hcon, outp);
304 * Now, copy the data itself after the encoded integer length
307 bcopy(STRING_DATA(*stp), nextp, len);
308 /* copy the data without */
309 /* changing representation*/
310 return (int)(nextp+len);
313 /*----------------------------------------------------------*/
317 /* Decode a string from external form. We always
318 /* allocate new space for the string, intentionally
319 /* ignoring any which may have been in use before. If we
320 /* freed it, we would not be robust against calls on
321 /* uninitialized fields. This may have nasty side
322 /* effects if the intention was to leave 'gas' at the end
323 /* of the string, but we want to accurately copy the
324 /* data. Note that string_free is robust against null
327 /*----------------------------------------------------------*/
330 g_st_dec(outp, hcon, inp)
331 char *inp; /* pointer to input data */
332 HALF_CONNECTION hcon; /* connection descriptor */
333 char *outp; /* place to put the output */
335 register STRING *stp = (STRING *)outp; /* re-type as string */
337 register char *nextp; /* next byte to scan */
339 * Use the integer coding routine to get the length encoded first
342 nextp = (char *)g_in_dec((char *)&len, hcon, inp);
346 * Allocate memory for the string. If length is 0, then null it
347 * out. Note that we had considered freeing any existing strings
348 * which might be there, but this turns out to cause lots of
349 * trouble for the many callers who don't want to initialize before
353 STRING_DATA(*stp) = NULL;
354 MAX_STRING_SIZE(*stp) = 0;
357 (void) string_alloc(stp, len); /* this sets string length */
358 /* in addition to doing the */
362 * Now, copy the data itself
364 bcopy(nextp, STRING_DATA(*stp), len); /* copy the data without */
365 /* changing representation*/
366 return (int)(nextp+len);
369 /*----------------------------------------------------------*/
373 /* Format a string on output logging file for
376 /*----------------------------------------------------------*/
380 char *name; /* string name of the field */
381 char *dp; /* pointer to the data */
383 register STRING *stp = (STRING *)dp; /* re-type as string */
385 register char *cp; /* next char to print */
386 register char *past_end; /* 1st one not to print */
388 len = MAX_STRING_SIZE(*stp);
389 fprintf(gdb_log, "STRING_T\t%s[%d]=\"", name,len);
392 fprintf(gdb_log, "\"\n");
397 cp = STRING_DATA(*stp);
400 while (cp < past_end)
401 (void) putc(*cp++, gdb_log);
403 fprintf(gdb_log,"\"\n");
406 /************************************************************************/
410 /************************************************************************/
412 #define RL_LEN (sizeof(double))
413 #define RL_ALI RL_LEN
414 #define RL_NULL g_rl_null
415 #define RL_CDLEN g_rl_cdlen
416 #define RL_ENC g_rl_enc
417 #define RL_DEC g_rl_dec
418 #define RL_FORM g_rl_form
419 #define RL_NAME "REAL_T"
421 #define RL_EXTERNSIZE 32 /* length of ascii coding */
422 /* must change lengths in */
423 /* encode and decode */
424 /* routines to match*/
425 /*----------------------------------------------------------*/
429 /* Fill in a null value for an real.
431 /*----------------------------------------------------------*/
434 char *dp; /* pointer to the data */
436 *((double *)dp) = 0.0; /* fill in a null value */
439 /*----------------------------------------------------------*/
443 /* Return coded length for an real. For now, we just
444 /* code as a 12 digit ASCII converted string. Obviously,
445 /* we can do much better in the future.
447 /*----------------------------------------------------------*/
453 char *dp; /* pointer to the data */
454 HALF_CONNECTION hcon;
456 return RL_EXTERNSIZE;
459 /*----------------------------------------------------------*/
463 /* Encode an real for transmission
465 /*----------------------------------------------------------*/
469 g_rl_enc(dp, hcon, outp)
470 char *dp; /* pointer to data */
471 HALF_CONNECTION hcon; /* connection descriptor */
472 char *outp; /* place to put the output */
474 register char *cp; /* next char in output */
475 register char *endp = outp+RL_EXTERNSIZE;
478 * Convert the data into printable ASCII in the output stream
479 * Note that the width in the format below must be less than
480 * RL_EXTERNSIZE, because sprintf needs space for its terminating
484 (void) sprintf(outp,"%30le",*((double *)dp));
487 * Sprintf produces output of unpredictable length, and with
488 * a null termination. Pad it out to the desired length.
491 cp = outp + strlen(outp); /* find out where convertd */
494 *cp++ = ' '; /* pad to desired length */
496 return (int)(outp+RL_EXTERNSIZE); /* return pointer to next */
497 /* unused output byte*/
500 /*----------------------------------------------------------*/
504 /* Decode an real from external form
506 /*----------------------------------------------------------*/
510 g_rl_dec(outp, hcon, inp)
511 char *inp; /* pointer to data */
512 HALF_CONNECTION hcon; /* connection descriptor */
513 char *outp; /* place to put the output */
515 (void) sscanf(inp,"%30le", (double *)outp);
516 return (int)(inp+RL_EXTERNSIZE);
519 /*----------------------------------------------------------*/
523 /* Format an real on output logging file for
526 /*----------------------------------------------------------*/
530 char *name; /* string name of the field */
531 char *dp; /* pointer to the data */
533 fprintf(gdb_log, "REAL_T\t\t%s=%le\n",name,*((double *)dp) );
536 /************************************************************************/
540 /************************************************************************/
542 #define DT_LEN 25 /* see ingres definition */
543 #define DT_ALI 1 /* char data, need not align */
544 #define DT_NULL g_dt_null
545 #define DT_CDLEN g_dt_cdlen
546 #define DT_ENC g_dt_enc
547 #define DT_DEC g_dt_dec
548 #define DT_FORM g_dt_form
549 #define DT_NAME "DATE_T"
551 #define DT_EXTERNSIZE DT_LEN /* length of ascii coding */
552 /* must change lengths in */
553 /* encode and decode */
554 /* routines to match*/
555 /*----------------------------------------------------------*/
559 /* Fill in a null value for a date.
561 /*----------------------------------------------------------*/
564 char *dp; /* pointer to the data */
566 register char *cp = dp; /* next character to fill in */
567 register char *endp = dp + DT_LEN;
570 * Fill the field with character blanks
576 /*----------------------------------------------------------*/
580 /* Return coded length for an date. For now, we just
581 /* code as a 25 digit ASCII converted string.
583 /*----------------------------------------------------------*/
589 char *dp; /* pointer to the data */
590 HALF_CONNECTION hcon;
592 return DT_EXTERNSIZE;
595 /*----------------------------------------------------------*/
599 /* Encode a date for transmission
601 /*----------------------------------------------------------*/
605 g_dt_enc(dp, hcon, outp)
606 char *dp; /* pointer to data */
607 HALF_CONNECTION hcon; /* connection descriptor */
608 char *outp; /* place to put the output */
610 register char *ip = dp; /* next char in input */
611 register char *op = outp; /* next char in output */
612 register char *endp = op+DT_EXTERNSIZE;
615 * Copy the input untransformed to the output
619 *op++ = *ip++; /* pad to desired length */
621 return (int)(endp); /* return pointer to next */
622 /* unused output byte*/
625 /*----------------------------------------------------------*/
629 /* Decode an date from external form
631 /*----------------------------------------------------------*/
635 g_dt_dec(outp, hcon, inp)
636 char *inp; /* pointer to data */
637 HALF_CONNECTION hcon; /* connection descriptor */
638 char *outp; /* place to put the output */
640 register char *ip = inp; /* next char in input */
641 register char *op = outp; /* next char in output */
642 register char *endp = op+DT_EXTERNSIZE;
645 * Copy the input untransformed to the output
649 *op++ = *ip++; /* pad to desired length */
651 return (int)(endp); /* return pointer to next */
652 /* unused output byte*/
655 /*----------------------------------------------------------*/
659 /* Format a date on output logging file for
662 /*----------------------------------------------------------*/
666 char *name; /* string name of the field */
667 char *dp; /* pointer to the data */
669 char buf[DT_EXTERNSIZE+1];
671 bcopy(dp, buf, DT_EXTERNSIZE); /* copy date to buffer */
672 buf[DT_EXTERNSIZE] = '\0'; /* null terminate it */
673 fprintf(gdb_log, "DATE_T\t\t%s=%s\n",name,buf);
676 /************************************************************************/
678 /* TUPLE_DESCRIPTOR_T
680 /* The external representation of a tuple descriptor will be to
681 /* send the count of the number of fields, and then a one byte
682 /* signed integer describing each type followed by all the
683 /* corresponding null terminated strings. The tuple descriptor
684 /* will really get re-created wth proper offsets and lengths upon
685 /* receipt by the create_tuple_descriptor operation.
687 /************************************************************************/
689 #define TPD_LEN (sizeof(TUPLE_DESCRIPTOR))
690 #define TPD_ALI (sizeof(TUPLE_DESCRIPTOR))
691 #define TPD_NULL g_tpd_null
692 #define TPD_CDLEN g_tpd_cdlen
693 #define TPD_ENC g_tpd_enc
694 #define TPD_DEC g_tpd_dec
695 #define TPD_FORM g_tpd_form
696 #define TPD_NAME "TUPLE_DESCRIPTOR_T"
698 /*----------------------------------------------------------*/
702 /* Fill in a null value for a tuple_descriptor.
704 /*----------------------------------------------------------*/
707 char *dp; /* pointer to the data */
709 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)dp;
711 /* tuple_descriptor */
712 (*tdp) = NULL; /* no data */
715 /*----------------------------------------------------------*/
719 /* Return coded length for a tuple_descriptor.
721 /*----------------------------------------------------------*/
725 char *dp; /* pointer to the data */
726 HALF_CONNECTION hcon;
728 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
730 /* tuple_descriptor */
731 register int coded_len; /* the value we're trying */
735 * Validate the descriptor
738 GDB_GIVEUP("g_tpd_cdlen (coded length) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
739 GDB_CHECK_TPD(tdp,"g_tpd_cdlen: compute coded length of tuple descriptor")
741 coded_len = g_in_cdlen((char *)&(tdp->field_count),hcon);
742 /* we're going to send */
743 /* the field count as a */
746 coded_len += tdp->str_len + tdp->field_count;
747 /* space for all the */
748 /* strings, with nulls, */
749 /* and for the one byte */
756 /*----------------------------------------------------------*/
760 /* Encode a tuple_descriptor for transmission
762 /*----------------------------------------------------------*/
765 g_tpd_enc(dp, hcon, outp)
766 char *dp; /* pointer to data */
767 HALF_CONNECTION hcon; /* connection descriptor */
768 char *outp; /* place to put the output */
770 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
772 /* tuple_descriptor */
773 register char *nextp; /* place to put next output */
775 register int i; /* a loop counter */
778 * Validate the descriptor
781 GDB_GIVEUP("g_tpd_enc (encode) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
782 GDB_CHECK_TPD(tdp,"g_tpd_enc: encode tuple descriptor")
785 * Use the integer coding routine to send the number of fields first
788 nextp = (char *)g_in_enc((char *)&(tdp->field_count), hcon, outp);
791 * Next, put in the one byte codes for each of the field types
794 for (i=0; i<tdp->field_count; i++) {
795 *nextp++ = tdp->var[i].type & 0xff; /* put out the one byte */
800 * Finally, copy all the null terminated strings.
802 bcopy(((char *)(tdp))+gdb_descriptor_length(tdp->field_count),
803 nextp, tdp->str_len); /* copy the string data all */
805 return (int)(nextp+tdp->str_len);
808 /*----------------------------------------------------------*/
812 /* Decode a tuple_descriptor from external form. For
813 /* safety in memory management, we always re-allocate the
814 /* space for the tuple_descriptor. If the pointer passed
815 /* to us is not null, then we assume that it points to a
816 /* legal tuple descriptor, which we first free. Because
817 /* data representation may change, we must re-do the
818 /* create-tuple-descriptor, so it can determine the local
819 /* machine dependent representation and alignment rules
822 /*----------------------------------------------------------*/
824 #define GDB_MAX_DECODED_FIELDS 100
827 g_tpd_dec(outp, hcon, inp)
828 char *inp; /* pointer to input data */
829 HALF_CONNECTION hcon; /* connection descriptor */
830 char *outp; /* place to put the output */
832 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)outp;
834 /* tuple_descriptor */
835 int field_count; /* number of fields in the */
836 /* newly received descriptor*/
837 register int i; /* a loop counter */
839 register int tmp; /* working variable to hold */
840 /* type while they're being */
842 char *nextt; /* next byte to scan for */
843 /* a type code byte*/
844 char *nextn; /* next byte to scan for */
846 char *field_names[GDB_MAX_DECODED_FIELDS];
847 /* put pointers to the */
848 /* field names here */
849 FIELD_TYPE field_types[GDB_MAX_DECODED_FIELDS];
850 /* put the field types in */
853 * Use the integer coding routine to get the number of fields
856 nextt = (char *)g_in_dec((char *)&field_count, hcon, inp);
857 if (field_count > GDB_MAX_DECODED_FIELDS)
858 GDB_GIVEUP("g_tpd_dec: Trying to decode tuple descriptor with too many fields.\n")
862 * For each field, pick up its type code, being sure to sign extend,
863 * and a pointer to its string name.
865 nextn = nextt + field_count; /* there is one byte of */
866 /* type info for each field, */
867 /* after that comes the */
868 /* first string. nextn */
869 /* now points to the first */
871 for (i=0; i<field_count; i++) {
872 tmp = *nextt++; /* type code, may need */
875 tmp |= ((~0) ^ 0xff); /* sign extend if needed */
876 /* this is the most machine */
877 /* independent sign extension */
878 /* I could come up with. */
879 /* Presumes char is one byte, */
880 /* but makes no assumption */
881 /* about sizeof(int) */
882 field_types[i] = tmp;
883 field_names[i] = nextn; /* pointer to name of the */
885 nextn += strlen(nextn) +1; /* set up for possible name */
890 * In case there was already a tuple descriptor here, free it.
893 delete_tuple_descriptor(*tdp);
896 * Create a new descriptor based on the information we have received.
898 *tdp = create_tuple_descriptor(field_count, field_names, field_types);
903 /*----------------------------------------------------------*/
907 /* Format a tuple_descriptor on output logging file for
910 /*----------------------------------------------------------*/
914 char *name; /* tuple_descriptor name of the field */
915 char *dp; /* pointer to the data */
917 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
919 /* tuple_descriptor */
920 register int i; /* loop variable through */
921 /* field definitions */
925 * Handle the special case where the descriptor is null
928 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=NULL)\n", name);
933 * Validate the descriptor
935 GDB_CHECK_TPD(tdp,"g_tpd_form: format tuple descriptor")
938 * Descriptor is not null
940 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=0x%x)\n", name, tdp);
942 for (i=0; i<tdp->field_count; i++) {
943 fprintf(gdb_log,"\tField Type Code = %3d %20s\tField Name=%s\n" ,
945 STR_PROPERTY(tdp->var[i].type,NAME_PROPERTY),
948 fprintf(gdb_log,"\n");
951 /************************************************************************/
955 /* There is a distinction between the type tuple_t and the
956 /* type tuple_data_t. Tuple_t is a complete self-contained
957 /* tuple, with its descriptor. It actually refers to the
958 /* tuple variable itself, which is a pointer. Tuple_data
959 /* is only the data portion of the tuple, not the descriptor.
960 /* It is used when the receiving tuple is already allocated,
961 /* with a correct descriptor, for sending just the data.
963 /* Note that some of the routines for tuple_t could have been
964 /* implemented in terms of tuple_data_t routines. For the
965 /* moment, they have not been, but that may later be changed.
966 /* Doesn't seem to make much difference as long as they are
967 /* short and simple, and this way does save a bit of overhead.
969 /************************************************************************/
971 #define TP_LEN (sizeof(TUPLE))
972 #define TP_ALI TP_LEN
973 #define TP_NULL g_tp_null
974 #define TP_CDLEN g_tp_cdlen
975 #define TP_ENC g_tp_enc
976 #define TP_DEC g_tp_dec
977 #define TP_FORM g_tp_form
978 #define TP_NAME "TUPLE_T"
980 /*----------------------------------------------------------*/
984 /* Fill in a null value for a tuple.
986 /*----------------------------------------------------------*/
989 char *dp; /* pointer to the data */
991 *((TUPLE *)dp) = NULL;
994 /*----------------------------------------------------------*/
998 /* Return coded length for a tuple. We have to send the
999 /* descriptor along with the data itself. We do this
1000 /* with calls to the appropriate encodeing routines.
1002 /*----------------------------------------------------------*/
1006 char *dp; /* pointer to the data */
1007 HALF_CONNECTION hcon;
1009 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1010 register int len; /* accumulated length */
1011 register int i; /* index to fields */
1012 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1015 * Validate the tuple
1018 GDB_GIVEUP("g_tp_cdlen (coded length) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1019 GDB_CHECK_TUP(tup,"g_tp_cdlen: compute coded length of tuple")
1022 * First, get length of the descriptor when coded.
1025 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1026 len = g_tpd_cdlen((char *)&tpd,hcon);
1029 * Now, for each field, add in its coded length
1032 for (i=0; i<tpd->field_count; i++) {
1033 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1034 CODED_LENGTH_PROPERTY)
1035 (FIELD_FROM_TUPLE(tup, i),hcon);
1041 /*----------------------------------------------------------*/
1045 /* Encode a tuple for transmission
1047 /*----------------------------------------------------------*/
1050 g_tp_enc(dp, hcon, outp)
1051 char *dp; /* pointer to data */
1052 HALF_CONNECTION hcon; /* connection descriptor */
1053 char *outp; /* place to put the output */
1055 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1056 register int i; /* index to fields */
1057 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1058 char *op; /* next byte of output */
1061 * Validate the tuple
1064 GDB_GIVEUP("g_tp_enc (encode) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1065 GDB_CHECK_TUP(tup,"g_tp_enc: encode tuple")
1068 * First, get the tuple descriptor and encode it
1071 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1072 op = (char *)g_tpd_enc((char *)&tpd, hcon, outp);
1075 * Now, for each field, code it
1078 for (i=0; i<tpd->field_count; i++) {
1079 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1081 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1087 /*----------------------------------------------------------*/
1091 /* Decode a tuple from external form. For safety
1092 /* in memory management, we always re-allocate the
1093 /* space for the tuple, so the lengths come out right.
1094 /* This may have nasty side effects if the intention
1095 /* was to leave 'gas' at the end of the tuple, but
1096 /* we want to accurately copy the data. Note that
1097 /* tuple_free is robust against null pointers.
1099 /*----------------------------------------------------------*/
1102 g_tp_dec(outp, hcon, inp)
1103 char *inp; /* pointer to input data */
1104 HALF_CONNECTION hcon; /* connection descriptor */
1105 char *outp; /* place to put the output */
1107 register TUPLE tup; /* the new tuple */
1108 register int i; /* index to fields */
1109 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1110 char *ip; /* next byte of input */
1113 * First, get the tuple descriptor and decode it
1116 tpd = NULL; /* so decode will know */
1117 /* there's no existing one */
1119 ip = (char *)g_tpd_dec((char *)&tpd, hcon, inp);
1122 * Now make an empty tuple based on the descriptor
1125 tup = create_tuple(tpd);
1128 * The tuple descriptor has a reference count of 2 here, one
1129 * from the tpd_dec routine, and one from the create_tuple.
1130 * Since we don't expect to explicitly undo the two separately,
1131 * we decrement the count here.
1134 UNREFERENCE_TUPLE_DESCRIPTOR(tpd); /* decr. the reference count */
1137 * Now, for each field, decode it.
1140 for (i=0; i<tpd->field_count; i++) {
1141 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1143 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1146 *((TUPLE *)outp) = tup; /* put the new tuple */
1147 /* pointer where the */
1148 /* caller wants it */
1152 /*----------------------------------------------------------*/
1156 /* Format a tuple on output logging file for
1159 /*----------------------------------------------------------*/
1163 char *name; /* tuple name of the field */
1164 char *dp; /* pointer to the data */
1166 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1167 register int i; /* index to fields */
1168 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1172 * Handle special case where tuple is null
1176 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1180 GDB_CHECK_TUP(tup,"g_tp_form: format tuple")
1182 * Get the descriptor--for now, we won't print it
1184 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1190 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1193 * Now, for each field, print it
1196 for (i=0; i<tpd->field_count; i++) {
1197 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1199 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1202 fprintf(gdb_log,"END_OF_TUPLE\n");
1205 /************************************************************************/
1209 /* The distinction between tuple_data_t and tuple_t is a
1210 /* subtle one. Tuple_t is used when a single tuple is to
1211 /* be decoded, outside of any larger context. It (re)allocates
1212 /* memory for both the tuple itself and its descriptor.
1214 /* Tuple_data is used in the case where the tuple and its
1215 /* descriptor are already allocated, but only the data is
1216 /* to be received. This is useful in cases like receiving an
1217 /* entire relation, in which the descriptor is common to
1218 /* all the tuples, and should not be resent or reallocated
1219 /* with each one. Receive relation can send the tuple descriptor
1220 /* once, then do a create_tuple followed by a decode tuple_data
1221 /* to receive the tuple field data into the existing tuple.
1223 /* Note that the definition of null is different in the two cases.
1224 /* The null value for a tuple is just a null pointer. The null
1225 /* for tuple data is to null each of the fields in the tuple
1226 /* recursively. The routines in this section may dereference
1227 /* null pointers if the tuples they are passed are null. Note
1228 /* also that there is one less level of indirection in passing
1229 /* data to these routines than to those of tuple_t.
1231 /* Note also that the null and decode routines supplied here
1232 /* presume that any fields with dependent memory (e.g. string_t
1233 /* fields have already been cleaned up.)
1235 /* Note that this is not quite a kosher type, in the sense that
1236 /* it's length is not fixed. The entry for length below
1237 /* is meaningless, because the real length is computed from the
1238 /* desc. Among other things, this means that TUPLEs cannot
1239 /* contain fields of this type.
1241 /************************************************************************/
1243 #define TDT_LEN (sizeof(TUPLE))
1244 #define TDT_ALI TDT_LEN
1245 #define TDT_NULL g_tdt_null
1246 #define TDT_CDLEN g_tdt_cdlen
1247 #define TDT_ENC g_tdt_enc
1248 #define TDT_DEC g_tdt_dec
1249 #define TDT_FORM g_tdt_form
1250 #define TDT_NAME "TUPLE_DATA_T"
1252 /*----------------------------------------------------------*/
1256 /* Fill in a null value for a tuple.
1258 /*----------------------------------------------------------*/
1261 char *dp; /* pointer to the data */
1263 TUPLE tup = (TUPLE)dp; /* dp is of type TUPLE, */
1264 /* which is actually */
1265 /* a pointer to the */
1267 TUPLE_DESCRIPTOR tpd; /* the descriptor for this */
1269 register int i; /* a loop counter */
1272 * For each field in the tuple, call its null routine
1274 tup->id = GDB_TUP_ID;
1276 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1278 for (i=0; i<tpd->field_count; i++) {
1279 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),NULL_PROPERTY)
1280 (FIELD_FROM_TUPLE(tup,i));
1284 /*----------------------------------------------------------*/
1288 /* Return coded length for tuple data. Since the descriptor
1289 /* for the tuple is known at both sides, we send only
1290 /* the coded fields, not even the field counts.
1292 /*----------------------------------------------------------*/
1295 g_tdt_cdlen(dp,hcon)
1296 char *dp; /* pointer to the data */
1297 HALF_CONNECTION hcon;
1299 register TUPLE tup = (TUPLE)dp; /* arg typed as tuple */
1300 register int len; /* accumulated length */
1301 register int i; /* index to fields */
1302 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1305 * Validate the tuple data
1308 GDB_GIVEUP("g_tdt_cdlen (coded length) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1309 GDB_CHECK_TUP(tup,"g_tdt_cdlen: compute coded length of tuple data")
1311 * First, find the tuple descriptor and set initial coded len to 0
1314 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1318 * Now, for each field, add in its coded length
1321 for (i=0; i<tpd->field_count; i++) {
1322 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1323 CODED_LENGTH_PROPERTY)
1324 (FIELD_FROM_TUPLE(tup, i),hcon);
1330 /*----------------------------------------------------------*/
1334 /* Encode tuple data for transmission.
1336 /*----------------------------------------------------------*/
1339 g_tdt_enc(dp, hcon, outp)
1340 char *dp; /* pointer to data */
1341 HALF_CONNECTION hcon; /* connection descriptor */
1342 char *outp; /* place to put the output */
1344 register TUPLE tup = (TUPLE)dp; /* type as tuple */
1345 register int i; /* index to fields */
1346 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1347 char *op = outp; /* next byte of output */
1350 * Validate the tuple data
1353 GDB_GIVEUP("g_tdt_enc (encode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1354 GDB_CHECK_TUP(tup,"g_tdt_enc: encode of tuple data")
1356 * First, get the tuple descriptor
1359 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1362 * Now, for each field, code it
1365 for (i=0; i<tpd->field_count; i++) {
1366 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1368 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1374 /*----------------------------------------------------------*/
1378 /* Decode tuple data from external form. We presume
1379 /* that the tuple itself is allocated, and the descriptor
1380 /* properly set up for the local machine representation.
1381 /* Here we just decode the fields.
1383 /*----------------------------------------------------------*/
1386 g_tdt_dec(outp, hcon, inp)
1387 char *inp; /* pointer to input data */
1388 HALF_CONNECTION hcon; /* connection descriptor */
1389 char *outp; /* place to put the output */
1391 register TUPLE tup = (TUPLE)outp; /* the filled in tuple */
1392 register int i; /* index to fields */
1393 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1394 char *ip = inp; /* next byte of input */
1397 * Validate the tuple data
1400 GDB_GIVEUP("g_tdt_dec (decode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1401 GDB_CHECK_TUP(tup,"g_tdt_dec: decode of tuple data")
1403 * First, get the tuple descriptor
1406 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1409 * Now, for each field, decode it.
1412 for (i=0; i<tpd->field_count; i++) {
1413 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1415 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1421 /*----------------------------------------------------------*/
1425 /* Format tuple data on output logging file for
1428 /*----------------------------------------------------------*/
1431 g_tdt_form(name, dp)
1432 char *name; /* tuple name of the field */
1433 char *dp; /* pointer to the data */
1435 register TUPLE tup = (TUPLE)dp; /* as tuple */
1436 register int i; /* index to fields */
1437 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1441 * Handle special case where we're given a null address for the
1445 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1451 * Validate the tuple data
1453 GDB_CHECK_TUP(tup,"g_tdt_form: format tuple data")
1455 * Get the descriptor--for now, we won't print it
1457 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1463 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1466 * Now, for each field, print it
1469 for (i=0; i<tpd->field_count; i++) {
1470 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1472 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1475 fprintf(gdb_log,"END_OF_TUPLE\n");
1478 /************************************************************************/
1482 /* Relations consist of link lists of tuples, all of which are
1483 /* presumed to share a tuple descriptor. For transmission,
1484 /* these are encoded as follows:
1486 /* 1) A count of the number of tuples, sent as a properly coded
1489 /* 2) The tuple descriptor itself, encoded by its encoding routine.
1491 /* 3) For each tuple, its tuple data, encoded using the routines
1492 /* of the tuple_data_t type.
1494 /************************************************************************/
1496 #define REL_LEN (sizeof(RELATION))
1497 #define REL_ALI REL_LEN
1498 #define REL_NULL g_rel_null
1499 #define REL_CDLEN g_rel_cdlen
1500 #define REL_ENC g_rel_enc
1501 #define REL_DEC g_rel_dec
1502 #define REL_FORM g_rel_form
1503 #define REL_NAME "RELATION_T"
1506 /*----------------------------------------------------------*/
1510 /* Fill in a null value for a relation. Maybe we should
1511 /* check for an existing relation and properly free it,
1512 /* but for now, we don't.
1514 /*----------------------------------------------------------*/
1517 char *dp; /* pointer to the data */
1519 *((RELATION *)dp) = NULL;
1522 /*----------------------------------------------------------*/
1526 /* Return coded length for a relation.
1528 /*----------------------------------------------------------*/
1531 g_rel_cdlen(dp,hcon)
1532 char *dp; /* pointer to the data */
1533 HALF_CONNECTION hcon;
1535 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1536 int len; /* accumulated length */
1537 register TUPLE t; /* index to a tuple */
1538 int tuple_count = 0; /* number of tuples in this */
1540 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1544 * Validate the relation
1547 GDB_GIVEUP("g_rel_cdlen (coded length) was given null relation\nthis may be due to an attempt to transmit invalid data")
1548 GDB_CHECK_REL(rel,"g_rel_cdlen: compute coded length of relation")
1550 * First, get the tuple descriptor for this relation
1553 tpd = DESCRIPTOR_FROM_RELATION(rel);
1556 * Count the number of tuples in the relation
1558 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1559 t = NEXT_TUPLE_IN_RELATION(rel,t))
1562 * Start with the coded length for the tuple count and the
1563 * descriptor, which are sent first.
1566 len = g_in_cdlen((char *)&tuple_count, hcon); /* length of tuple_count */
1568 len += g_tpd_cdlen((char *)&tpd, hcon);
1571 * Now, for each tuple, add in its coded length
1574 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1575 t = NEXT_TUPLE_IN_RELATION(rel,t))
1576 len += g_tdt_cdlen((char *)t, hcon);
1581 /*----------------------------------------------------------*/
1585 /* Encode a relation for transmission
1587 /*----------------------------------------------------------*/
1590 g_rel_enc(dp, hcon, outp)
1591 char *dp; /* pointer to data */
1592 HALF_CONNECTION hcon; /* connection descriptor */
1593 char *outp; /* place to put the output */
1595 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1596 char *op; /* pointer to next unused */
1598 register TUPLE t; /* index to a tuple */
1599 int tuple_count = 0; /* number of tuples in this */
1601 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1605 * Validate the relation
1608 GDB_GIVEUP("g_rel_enc (encode) was given null relation\nthis may be due to an attempt to transmit invalid data")
1609 GDB_CHECK_REL(rel,"g_rel_enc: encode relation")
1612 * First, get the tuple descriptor for this relation
1615 tpd = DESCRIPTOR_FROM_RELATION(rel);
1618 * Count the number of tuples in the relation
1620 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1621 t = NEXT_TUPLE_IN_RELATION(rel,t))
1624 * Encode the count and the tuple descriptor for this relation
1627 op = (char *)g_in_enc((char *)&tuple_count, hcon,outp);
1628 /* length of tuple_count */
1630 op = (char *)g_tpd_enc((char *)&tpd, hcon,op);
1633 * Now, encode each tuple
1636 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1637 t = NEXT_TUPLE_IN_RELATION(rel,t))
1638 op = (char *)g_tdt_enc((char *)t, hcon, op);
1643 /*----------------------------------------------------------*/
1647 /* Decode a relation from external form. We should
1648 /* really check to make sure the relation we are given
1649 /* is null, and if not, call delete_relation on it
1650 /* first. For the moment, we just presume it's null.
1652 /* We proceed by decoding the integer count and the
1653 /* tuple descriptor, from which we create the null
1654 /* relation. We then loop for each tuple, doing a
1655 /* create, a decode, and an add to relation.
1657 /*----------------------------------------------------------*/
1660 g_rel_dec(outp, hcon, inp)
1661 char *inp; /* pointer to input data */
1662 HALF_CONNECTION hcon; /* connection descriptor */
1663 char *outp; /* place to put the output */
1665 register RELATION rel; /* build the relation here */
1666 char *ip; /* pointer to next unused */
1668 register TUPLE t; /* index to a tuple */
1669 register int i; /* loop counter on tuples */
1670 int tuple_count = 0; /* number of tuples in this */
1672 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1676 * First, get the field count and tuple descriptor for this relation
1679 ip = (char *)g_in_dec((char *)&tuple_count, hcon, inp);
1681 tpd = NULL; /* so decode will know */
1682 /* there's no existing one */
1684 ip = (char *)g_tpd_dec((char *)&tpd, hcon, ip);
1687 * Now, create a null relation using the descriptor
1690 rel = create_relation(tpd);
1693 * The reference count for the tuple descriptor is currently 2,
1694 * one from the tpd_dec and one from the create relation. Since
1695 * these will not be undone separately, we decrement the reference
1699 UNREFERENCE_TUPLE_DESCRIPTOR(tpd);
1702 * For each tuple, create it, receive it, add it to the relation
1705 for (i=0; i<tuple_count; i++) {
1706 t = create_tuple(tpd);
1707 ip = (char *)g_tdt_dec((char *)t, hcon, ip);
1708 ADD_TUPLE_TO_RELATION(rel, t);
1712 * Now store the address of the created relation where requested
1713 * and return pointer to next available input byte.
1716 *((RELATION *)outp) = rel;
1721 /*----------------------------------------------------------*/
1725 /* Format a relation on output logging file for
1728 /*----------------------------------------------------------*/
1731 g_rel_form(name, dp)
1732 char *name; /* relation name of the field */
1733 char *dp; /* pointer to the data */
1735 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1741 * Handle special case where relation is null
1745 fprintf(gdb_log,"\nRELATION Name=%s is NULL\n===========================\n",name);
1749 GDB_CHECK_REL(rel,"g_rel_form: format relation")
1755 fprintf(gdb_log,"\nRELATION at address: 0x%x Name=%s\n===========================\n",rel,name);
1758 * Now, for each field, print it
1761 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1762 t = NEXT_TUPLE_IN_RELATION(rel,t)){
1763 (void) sprintf(buffer,"Number %d",++count);
1764 g_tdt_form(buffer,(char *)t);
1767 fprintf(gdb_log,"END_OF_RELATION\n");
1770 /************************************************************************/
1772 /* DECLARE AND INITIALIZE THE SYSTEM TYPE DEFINITION
1775 /* This representation is clearly a real pain to keep up to date
1776 /* properly, mostly because C has such a lousy pre-processor.
1777 /* Probably this should be re-arranged so an initialization routine
1778 /* is called to set up the tables, but even that might be a nuissance.
1780 /************************************************************************/
1782 /*----------------------------------------------------------*/
1786 /* Called at startup to initialize the type table with
1787 /* the entries for the system types.
1789 /*----------------------------------------------------------*/
1791 #define ITYPE(inx,lp,ap,np,clp,ep,dp,fp,name) {\
1792 g_type_table[inx][LENGTH_PROPERTY].i = lp; \
1793 g_type_table[inx][ALIGNMENT_PROPERTY].i = ap; \
1794 g_type_table[inx][NULL_PROPERTY].f = np; \
1795 g_type_table[inx][CODED_LENGTH_PROPERTY].f = clp; \
1796 g_type_table[inx][ENCODE_PROPERTY].f = ep; \
1797 g_type_table[inx][DECODE_PROPERTY].f = dp; \
1798 g_type_table[inx][FORMAT_PROPERTY].f = fp; \
1799 g_type_table[inx][NAME_PROPERTY].cp = name; \
1805 gdb_n_types = SYSTEM_TYPE_COUNT;
1807 ITYPE(INTEGER_T,IN_LEN,IN_ALI,IN_NULL,IN_CDLEN,IN_ENC,IN_DEC,IN_FORM,
1809 ITYPE(STRING_T,ST_LEN,ST_ALI,ST_NULL,ST_CDLEN,ST_ENC,ST_DEC,ST_FORM,
1811 ITYPE(REAL_T,RL_LEN,RL_ALI,RL_NULL,RL_CDLEN,RL_ENC,RL_DEC,RL_FORM,
1813 ITYPE(DATE_T,DT_LEN,DT_ALI,DT_NULL,DT_CDLEN,DT_ENC,DT_DEC,DT_FORM,
1815 ITYPE(TUPLE_DESCRIPTOR_T,TPD_LEN,TPD_ALI,TPD_NULL,TPD_CDLEN,TPD_ENC,
1816 TPD_DEC,TPD_FORM,TPD_NAME)
1817 ITYPE(TUPLE_T,TP_LEN,TP_ALI,TP_NULL,TP_CDLEN,TP_ENC,TP_DEC,TP_FORM,
1819 ITYPE(TUPLE_DATA_T,TDT_LEN,TDT_ALI,TDT_NULL,TDT_CDLEN,TDT_ENC,TDT_DEC,
1821 ITYPE(RELATION_T,REL_LEN,REL_ALI,REL_NULL,REL_CDLEN,REL_ENC,REL_DEC,