7 static char *rcsid_gdb_stype_c = "$Header$";
11 /************************************************************************
15 * GDB - System Data Type Definitions
17 * Author: Noah Mendelsohn
18 * Copyright: 1986 MIT Project Athena
19 * For copying and distribution information, please see
20 * the file <mit-copyright.h>.
22 * This file initializes the definitions for all system defined
23 * data types, and it includes the type specific semantic routines
24 * for each of the system defined types.
26 * The initialization routine which adds these type definitions
27 * to the type definition table is at the end of this source file.
29 ************************************************************************
31 * This file is organized into one section for each system
32 * defined type followed at the end by a final section which
33 * initializes the type tables. Each of the type specific
34 * sections does #defines for each type specific parameter. The
35 * gdb_i_stype initialization routine at the end of this source
36 * file uses these defines to initialize the appropriate entry in
37 * the type definition tables.
39 * NOTE: some of the type definitions in this file may be machine
42 ************************************************************************/
44 #include <mit-copyright.h>
48 #include <netinet/in.h> /* for htonl routine */
51 /************************************************************************
55 ************************************************************************/
57 #define IN_LEN (sizeof(int))
59 #define IN_NULL g_in_null
60 #define IN_CDLEN g_in_cdlen
61 #define IN_ENC g_in_enc
62 #define IN_DEC g_in_dec
63 #define IN_FORM g_in_form
64 #define IN_NAME "INTEGER_T"
66 #define IN_EXTERNSIZE 4 /* length of an encoded */
68 /*----------------------------------------------------------*/
72 /* Fill in a null value for an integer.
74 /*----------------------------------------------------------*/
78 char *dp; /* pointer to the data */
80 *((int *)dp) = 0; /* fill in a null value */
83 /*----------------------------------------------------------*/
87 /* Return coded length for an integer. We're currently
88 /* using the Berkeley 'htonl' routine which converts
89 /* an integer (actually a long, ahem!) to a canonical
92 /*----------------------------------------------------------*/
98 char *dp; /* pointer to the data */
101 return IN_EXTERNSIZE;
104 /*----------------------------------------------------------*/
108 /* Encode an integer for transmission
110 /*----------------------------------------------------------*/
114 g_in_enc(dp, hcon, outp)
115 char *dp; /* pointer to data */
116 HALF_CONNECTION hcon; /* connection descriptor */
117 char *outp; /* place to put the output */
119 register char *cp; /* next char in output */
120 register char *op = outp;
121 register char *endp = outp+IN_EXTERNSIZE;
123 uint32 converted; /* the integer goes here */
124 /* in network byte order*/
127 * Put it in network format, then copy one byte at a time to
128 * account for the fact that the RT has trouble with unaligned longs
131 converted = htonl(*(uint32 *)dp);
133 cp = (char *)&converted;
139 return endp; /* return pointer to next */
140 /* unused output byte*/
143 /*----------------------------------------------------------*/
147 /* Decode an integer from external form to local
151 /*----------------------------------------------------------*/
155 g_in_dec(outp, hcon, inp)
156 char *inp; /* pointer to data */
157 HALF_CONNECTION hcon; /* connection descriptor */
158 char *outp; /* place to put the output */
160 register char *ip = inp; /* next byte of input */
162 register char *bp; /* next byte in buffer */
165 * Copy a byte at a time to buffer to account for RT difficulties
166 * with unaligned ints.
168 bp = (char *)&buffer;
175 * Convert it and return pointer to next byte of input.
178 *(int *)outp = ntohl((u_long)buffer);
182 /*----------------------------------------------------------*/
186 /* Format an integer on output logging file for
189 /*----------------------------------------------------------*/
193 char *name; /* string name of the field */
194 char *dp; /* pointer to the data */
196 fprintf(gdb_log, "INTEGER_T\t%s=%d\n",name,(*(int *)dp));
200 /************************************************************************/
204 /************************************************************************/
206 #define ST_LEN (sizeof(STRING))
207 #define ST_ALI (sizeof(char *))
208 #define ST_NULL g_st_null
209 #define ST_CDLEN g_st_cdlen
210 #define ST_ENC g_st_enc
211 #define ST_DEC g_st_dec
212 #define ST_FORM g_st_form
213 #define ST_NAME "STRING_T"
215 /*----------------------------------------------------------*/
219 /* Fill in a null value for a string.
221 /*----------------------------------------------------------*/
224 char *dp; /* pointer to the data */
226 register STRING *stp = (STRING *)dp; /* re-type as string */
227 STRING_DATA(*stp) = NULL; /* no data */
228 MAX_STRING_SIZE(*stp) = 0; /* for cleanliness */
231 /*----------------------------------------------------------*/
235 /* Return coded length for a string. We have to send the
236 /* actual length of the data along with the data itself.
237 /* For this reason, we leave space for a coded integer
238 /* in addition to the data bytes. We actually call the
239 /* integer coding routines to code the length.
241 /* Note that a separate type understanding null termination
242 /* might be an interesting optimization someday.
244 /*----------------------------------------------------------*/
248 char *dp; /* pointer to the data */
249 HALF_CONNECTION hcon;
251 register STRING *stp = (STRING *)dp; /* re-type as string */
253 return (MAX_STRING_SIZE(*stp) +
254 g_in_cdlen((char *)&MAX_STRING_SIZE(*stp),hcon));
257 /*----------------------------------------------------------*/
261 /* Encode a string for transmission
263 /*----------------------------------------------------------*/
266 g_st_enc(dp, hcon, outp)
267 char *dp; /* pointer to data */
268 HALF_CONNECTION hcon; /* connection descriptor */
269 char *outp; /* place to put the output */
271 register STRING *stp = (STRING *)dp; /* re-type as string */
273 register char *nextp; /* place to put next output */
276 * Use the integer coding routine to get the length encoded first
279 len = MAX_STRING_SIZE(*stp); /* length of both source */
281 nextp = (char *)g_in_enc((char *)&len, hcon, outp);
284 * Now, copy the data itself after the encoded integer length
287 memcpy(nextp, STRING_DATA(*stp), len);
288 /* copy the data without */
289 /* changing representation*/
293 /*----------------------------------------------------------*/
297 /* Decode a string from external form. We always
298 /* allocate new space for the string, intentionally
299 /* ignoring any which may have been in use before. If we
300 /* freed it, we would not be robust against calls on
301 /* uninitialized fields. This may have nasty side
302 /* effects if the intention was to leave 'gas' at the end
303 /* of the string, but we want to accurately copy the
304 /* data. Note that string_free is robust against null
307 /*----------------------------------------------------------*/
310 g_st_dec(outp, hcon, inp)
311 char *inp; /* pointer to input data */
312 HALF_CONNECTION hcon; /* connection descriptor */
313 char *outp; /* place to put the output */
315 register STRING *stp = (STRING *)outp; /* re-type as string */
317 register char *nextp; /* next byte to scan */
319 * Use the integer coding routine to get the length encoded first
322 nextp = (char *)g_in_dec((char *)&len, hcon, inp);
326 * Allocate memory for the string. If length is 0, then null it
327 * out. Note that we had considered freeing any existing strings
328 * which might be there, but this turns out to cause lots of
329 * trouble for the many callers who don't want to initialize before
333 STRING_DATA(*stp) = NULL;
334 MAX_STRING_SIZE(*stp) = 0;
337 (void) string_alloc(stp, len); /* this sets string length */
338 /* in addition to doing the */
342 * Now, copy the data itself
344 memcpy(STRING_DATA(*stp), nextp, len); /* copy the data without */
345 /* changing representation*/
349 /*----------------------------------------------------------*/
353 /* Format a string on output logging file for
356 /*----------------------------------------------------------*/
360 char *name; /* string name of the field */
361 char *dp; /* pointer to the data */
363 register STRING *stp = (STRING *)dp; /* re-type as string */
365 register char *cp; /* next char to print */
366 register char *past_end; /* 1st one not to print */
368 len = MAX_STRING_SIZE(*stp);
369 fprintf(gdb_log, "STRING_T\t%s[%d]=\"", name,len);
372 fprintf(gdb_log, "\"\n");
377 cp = STRING_DATA(*stp);
380 while (cp < past_end)
381 (void) putc(*cp++, gdb_log);
383 fprintf(gdb_log,"\"\n");
387 /************************************************************************/
391 /************************************************************************/
393 #define RL_LEN (sizeof(double))
394 #define RL_ALI RL_LEN
395 #define RL_NULL g_rl_null
396 #define RL_CDLEN g_rl_cdlen
397 #define RL_ENC g_rl_enc
398 #define RL_DEC g_rl_dec
399 #define RL_FORM g_rl_form
400 #define RL_NAME "REAL_T"
402 #define RL_EXTERNSIZE 32 /* length of ascii coding */
403 /* must change lengths in */
404 /* encode and decode */
405 /* routines to match*/
406 /*----------------------------------------------------------*/
410 /* Fill in a null value for an real.
412 /*----------------------------------------------------------*/
415 char *dp; /* pointer to the data */
417 *((double *)dp) = 0.0; /* fill in a null value */
420 /*----------------------------------------------------------*/
424 /* Return coded length for an real. For now, we just
425 /* code as a 12 digit ASCII converted string. Obviously,
426 /* we can do much better in the future.
428 /*----------------------------------------------------------*/
434 char *dp; /* pointer to the data */
435 HALF_CONNECTION hcon;
437 return RL_EXTERNSIZE;
440 /*----------------------------------------------------------*/
444 /* Encode an real for transmission
446 /*----------------------------------------------------------*/
450 g_rl_enc(dp, hcon, outp)
451 char *dp; /* pointer to data */
452 HALF_CONNECTION hcon; /* connection descriptor */
453 char *outp; /* place to put the output */
455 register char *cp; /* next char in output */
456 register char *endp = outp+RL_EXTERNSIZE;
459 * Convert the data into printable ASCII in the output stream
460 * Note that the width in the format below must be less than
461 * RL_EXTERNSIZE, because sprintf needs space for its terminating
465 (void) sprintf(outp,"%30le",*((double *)dp));
468 * Sprintf produces output of unpredictable length, and with
469 * a null termination. Pad it out to the desired length.
472 cp = outp + strlen(outp); /* find out where convertd */
475 *cp++ = ' '; /* pad to desired length */
477 return outp+RL_EXTERNSIZE; /* return pointer to next */
478 /* unused output byte*/
481 /*----------------------------------------------------------*/
485 /* Decode an real from external form
487 /*----------------------------------------------------------*/
491 g_rl_dec(outp, hcon, inp)
492 char *inp; /* pointer to data */
493 HALF_CONNECTION hcon; /* connection descriptor */
494 char *outp; /* place to put the output */
496 (void) sscanf(inp,"%30le", (double *)outp);
497 return inp+RL_EXTERNSIZE;
500 /*----------------------------------------------------------*/
504 /* Format an real on output logging file for
507 /*----------------------------------------------------------*/
511 char *name; /* string name of the field */
512 char *dp; /* pointer to the data */
514 fprintf(gdb_log, "REAL_T\t\t%s=%le\n",name,*((double *)dp) );
518 /************************************************************************/
522 /************************************************************************/
524 #define DT_LEN 25 /* see ingres definition */
525 #define DT_ALI 1 /* char data, need not align */
526 #define DT_NULL g_dt_null
527 #define DT_CDLEN g_dt_cdlen
528 #define DT_ENC g_dt_enc
529 #define DT_DEC g_dt_dec
530 #define DT_FORM g_dt_form
531 #define DT_NAME "DATE_T"
533 #define DT_EXTERNSIZE DT_LEN /* length of ascii coding */
534 /* must change lengths in */
535 /* encode and decode */
536 /* routines to match*/
537 /*----------------------------------------------------------*/
541 /* Fill in a null value for a date.
543 /*----------------------------------------------------------*/
546 char *dp; /* pointer to the data */
548 register char *cp = dp; /* next character to fill in */
549 register char *endp = dp + DT_LEN;
552 * Fill the field with character blanks
558 /*----------------------------------------------------------*/
562 /* Return coded length for an date. For now, we just
563 /* code as a 25 digit ASCII converted string.
565 /*----------------------------------------------------------*/
571 char *dp; /* pointer to the data */
572 HALF_CONNECTION hcon;
574 return DT_EXTERNSIZE;
577 /*----------------------------------------------------------*/
581 /* Encode a date for transmission
583 /*----------------------------------------------------------*/
587 g_dt_enc(dp, hcon, outp)
588 char *dp; /* pointer to data */
589 HALF_CONNECTION hcon; /* connection descriptor */
590 char *outp; /* place to put the output */
592 register char *ip = dp; /* next char in input */
593 register char *op = outp; /* next char in output */
594 register char *endp = op+DT_EXTERNSIZE;
597 * Copy the input untransformed to the output
601 *op++ = *ip++; /* pad to desired length */
603 return endp; /* return pointer to next */
604 /* unused output byte*/
607 /*----------------------------------------------------------*/
611 /* Decode an date from external form
613 /*----------------------------------------------------------*/
617 g_dt_dec(outp, hcon, inp)
618 char *inp; /* pointer to data */
619 HALF_CONNECTION hcon; /* connection descriptor */
620 char *outp; /* place to put the output */
622 register char *ip = inp; /* next char in input */
623 register char *op = outp; /* next char in output */
624 register char *endp = op+DT_EXTERNSIZE;
627 * Copy the input untransformed to the output
631 *op++ = *ip++; /* pad to desired length */
633 return endp; /* return pointer to next */
634 /* unused output byte*/
637 /*----------------------------------------------------------*/
641 /* Format a date on output logging file for
644 /*----------------------------------------------------------*/
648 char *name; /* string name of the field */
649 char *dp; /* pointer to the data */
651 char buf[DT_EXTERNSIZE+1];
653 memcpy(buf, dp, DT_EXTERNSIZE); /* copy date to buffer */
654 buf[DT_EXTERNSIZE] = '\0'; /* null terminate it */
655 fprintf(gdb_log, "DATE_T\t\t%s=%s\n",name,buf);
659 /************************************************************************/
661 /* TUPLE_DESCRIPTOR_T
663 /* The external representation of a tuple descriptor will be to
664 /* send the count of the number of fields, and then a one byte
665 /* signed integer describing each type followed by all the
666 /* corresponding null terminated strings. The tuple descriptor
667 /* will really get re-created wth proper offsets and lengths upon
668 /* receipt by the create_tuple_descriptor operation.
670 /************************************************************************/
672 #define TPD_LEN (sizeof(TUPLE_DESCRIPTOR))
673 #define TPD_ALI (sizeof(TUPLE_DESCRIPTOR))
674 #define TPD_NULL g_tpd_null
675 #define TPD_CDLEN g_tpd_cdlen
676 #define TPD_ENC g_tpd_enc
677 #define TPD_DEC g_tpd_dec
678 #define TPD_FORM g_tpd_form
679 #define TPD_NAME "TUPLE_DESCRIPTOR_T"
681 /*----------------------------------------------------------*/
685 /* Fill in a null value for a tuple_descriptor.
687 /*----------------------------------------------------------*/
690 char *dp; /* pointer to the data */
692 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)dp;
694 /* tuple_descriptor */
695 (*tdp) = NULL; /* no data */
698 /*----------------------------------------------------------*/
702 /* Return coded length for a tuple_descriptor.
704 /*----------------------------------------------------------*/
708 char *dp; /* pointer to the data */
709 HALF_CONNECTION hcon;
711 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
713 /* tuple_descriptor */
714 register int coded_len; /* the value we're trying */
718 * Validate the descriptor
721 GDB_GIVEUP("g_tpd_cdlen (coded length) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
722 GDB_CHECK_TPD(tdp,"g_tpd_cdlen: compute coded length of tuple descriptor")
724 coded_len = g_in_cdlen((char *)&(tdp->field_count),hcon);
725 /* we're going to send */
726 /* the field count as a */
729 coded_len += tdp->str_len + tdp->field_count;
730 /* space for all the */
731 /* strings, with nulls, */
732 /* and for the one byte */
739 /*----------------------------------------------------------*/
743 /* Encode a tuple_descriptor for transmission
745 /*----------------------------------------------------------*/
748 g_tpd_enc(dp, hcon, outp)
749 char *dp; /* pointer to data */
750 HALF_CONNECTION hcon; /* connection descriptor */
751 char *outp; /* place to put the output */
753 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
755 /* tuple_descriptor */
756 register char *nextp; /* place to put next output */
758 register int i; /* a loop counter */
761 * Validate the descriptor
764 GDB_GIVEUP("g_tpd_enc (encode) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
765 GDB_CHECK_TPD(tdp,"g_tpd_enc: encode tuple descriptor")
768 * Use the integer coding routine to send the number of fields first
771 nextp = (char *)g_in_enc((char *)&(tdp->field_count), hcon, outp);
774 * Next, put in the one byte codes for each of the field types
777 for (i=0; i<tdp->field_count; i++) {
778 *nextp++ = tdp->var[i].type & 0xff; /* put out the one byte */
783 * Finally, copy all the null terminated strings.
785 memcpy(nextp,((char *)(tdp))+gdb_descriptor_length(tdp->field_count),
786 tdp->str_len); /* copy the string data all */
788 return nextp+tdp->str_len;
791 /*----------------------------------------------------------*/
795 /* Decode a tuple_descriptor from external form. For
796 /* safety in memory management, we always re-allocate the
797 /* space for the tuple_descriptor. If the pointer passed
798 /* to us is not null, then we assume that it points to a
799 /* legal tuple descriptor, which we first free. Because
800 /* data representation may change, we must re-do the
801 /* create-tuple-descriptor, so it can determine the local
802 /* machine dependent representation and alignment rules
805 /*----------------------------------------------------------*/
807 #define GDB_MAX_DECODED_FIELDS 100
810 g_tpd_dec(outp, hcon, inp)
811 char *inp; /* pointer to input data */
812 HALF_CONNECTION hcon; /* connection descriptor */
813 char *outp; /* place to put the output */
815 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)outp;
817 /* tuple_descriptor */
818 int field_count; /* number of fields in the */
819 /* newly received descriptor*/
820 register int i; /* a loop counter */
822 register int tmp; /* working variable to hold */
823 /* type while they're being */
825 char *nextt; /* next byte to scan for */
826 /* a type code byte*/
827 char *nextn; /* next byte to scan for */
829 char *field_names[GDB_MAX_DECODED_FIELDS];
830 /* put pointers to the */
831 /* field names here */
832 FIELD_TYPE field_types[GDB_MAX_DECODED_FIELDS];
833 /* put the field types in */
836 * Use the integer coding routine to get the number of fields
839 nextt = (char *)g_in_dec((char *)&field_count, hcon, inp);
840 if (field_count > GDB_MAX_DECODED_FIELDS)
841 GDB_GIVEUP("g_tpd_dec: Trying to decode tuple descriptor with too many fields.\n")
845 * For each field, pick up its type code, being sure to sign extend,
846 * and a pointer to its string name.
848 nextn = nextt + field_count; /* there is one byte of */
849 /* type info for each field, */
850 /* after that comes the */
851 /* first string. nextn */
852 /* now points to the first */
854 for (i=0; i<field_count; i++) {
855 tmp = *nextt++; /* type code, may need */
858 tmp |= ((~0) ^ 0xff); /* sign extend if needed */
859 /* this is the most machine */
860 /* independent sign extension */
861 /* I could come up with. */
862 /* Presumes char is one byte, */
863 /* but makes no assumption */
864 /* about sizeof(int) */
865 field_types[i] = tmp;
866 field_names[i] = nextn; /* pointer to name of the */
868 nextn += strlen(nextn) +1; /* set up for possible name */
873 * In case there was already a tuple descriptor here, free it.
876 delete_tuple_descriptor(*tdp);
879 * Create a new descriptor based on the information we have received.
881 *tdp = create_tuple_descriptor(field_count, field_names, field_types);
886 /*----------------------------------------------------------*/
890 /* Format a tuple_descriptor on output logging file for
893 /*----------------------------------------------------------*/
897 char *name; /* tuple_descriptor name of the field */
898 char *dp; /* pointer to the data */
900 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
902 /* tuple_descriptor */
903 register int i; /* loop variable through */
904 /* field definitions */
908 * Handle the special case where the descriptor is null
911 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=NULL)\n", name);
916 * Validate the descriptor
918 GDB_CHECK_TPD(tdp,"g_tpd_form: format tuple descriptor")
921 * Descriptor is not null
923 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=0x%x)\n", name, tdp);
925 for (i=0; i<tdp->field_count; i++) {
926 fprintf(gdb_log,"\tField Type Code = %3d %20s\tField Name=%s\n" ,
928 STR_PROPERTY(tdp->var[i].type,NAME_PROPERTY),
931 fprintf(gdb_log,"\n");
935 /************************************************************************/
939 /* There is a distinction between the type tuple_t and the
940 /* type tuple_data_t. Tuple_t is a complete self-contained
941 /* tuple, with its descriptor. It actually refers to the
942 /* tuple variable itself, which is a pointer. Tuple_data
943 /* is only the data portion of the tuple, not the descriptor.
944 /* It is used when the receiving tuple is already allocated,
945 /* with a correct descriptor, for sending just the data.
947 /* Note that some of the routines for tuple_t could have been
948 /* implemented in terms of tuple_data_t routines. For the
949 /* moment, they have not been, but that may later be changed.
950 /* Doesn't seem to make much difference as long as they are
951 /* short and simple, and this way does save a bit of overhead.
953 /************************************************************************/
955 #define TP_LEN (sizeof(TUPLE))
956 #define TP_ALI TP_LEN
957 #define TP_NULL g_tp_null
958 #define TP_CDLEN g_tp_cdlen
959 #define TP_ENC g_tp_enc
960 #define TP_DEC g_tp_dec
961 #define TP_FORM g_tp_form
962 #define TP_NAME "TUPLE_T"
964 /*----------------------------------------------------------*/
968 /* Fill in a null value for a tuple.
970 /*----------------------------------------------------------*/
973 char *dp; /* pointer to the data */
975 *((TUPLE *)dp) = NULL;
978 /*----------------------------------------------------------*/
982 /* Return coded length for a tuple. We have to send the
983 /* descriptor along with the data itself. We do this
984 /* with calls to the appropriate encodeing routines.
986 /*----------------------------------------------------------*/
990 char *dp; /* pointer to the data */
991 HALF_CONNECTION hcon;
993 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
994 register int len; /* accumulated length */
995 register int i; /* index to fields */
996 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1002 GDB_GIVEUP("g_tp_cdlen (coded length) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1003 GDB_CHECK_TUP(tup,"g_tp_cdlen: compute coded length of tuple")
1006 * First, get length of the descriptor when coded.
1009 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1010 len = g_tpd_cdlen((char *)&tpd,hcon);
1013 * Now, for each field, add in its coded length
1016 for (i=0; i<tpd->field_count; i++) {
1017 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1018 CODED_LENGTH_PROPERTY)
1019 (FIELD_FROM_TUPLE(tup, i),hcon);
1025 /*----------------------------------------------------------*/
1029 /* Encode a tuple for transmission
1031 /*----------------------------------------------------------*/
1034 g_tp_enc(dp, hcon, outp)
1035 char *dp; /* pointer to data */
1036 HALF_CONNECTION hcon; /* connection descriptor */
1037 char *outp; /* place to put the output */
1039 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1040 register int i; /* index to fields */
1041 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1042 char *op; /* next byte of output */
1045 * Validate the tuple
1048 GDB_GIVEUP("g_tp_enc (encode) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1049 GDB_CHECK_TUP(tup,"g_tp_enc: encode tuple")
1052 * First, get the tuple descriptor and encode it
1055 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1056 op = (char *)g_tpd_enc((char *)&tpd, hcon, outp);
1059 * Now, for each field, code it
1062 for (i=0; i<tpd->field_count; i++) {
1063 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1065 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1071 /*----------------------------------------------------------*/
1075 /* Decode a tuple from external form. For safety
1076 /* in memory management, we always re-allocate the
1077 /* space for the tuple, so the lengths come out right.
1078 /* This may have nasty side effects if the intention
1079 /* was to leave 'gas' at the end of the tuple, but
1080 /* we want to accurately copy the data. Note that
1081 /* tuple_free is robust against null pointers.
1083 /*----------------------------------------------------------*/
1086 g_tp_dec(outp, hcon, inp)
1087 char *inp; /* pointer to input data */
1088 HALF_CONNECTION hcon; /* connection descriptor */
1089 char *outp; /* place to put the output */
1091 register TUPLE tup; /* the new tuple */
1092 register int i; /* index to fields */
1093 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1094 char *ip; /* next byte of input */
1097 * First, get the tuple descriptor and decode it
1100 tpd = NULL; /* so decode will know */
1101 /* there's no existing one */
1103 ip = (char *)g_tpd_dec((char *)&tpd, hcon, inp);
1106 * Now make an empty tuple based on the descriptor
1109 tup = create_tuple(tpd);
1112 * The tuple descriptor has a reference count of 2 here, one
1113 * from the tpd_dec routine, and one from the create_tuple.
1114 * Since we don't expect to explicitly undo the two separately,
1115 * we decrement the count here.
1118 UNREFERENCE_TUPLE_DESCRIPTOR(tpd); /* decr. the reference count */
1121 * Now, for each field, decode it.
1124 for (i=0; i<tpd->field_count; i++) {
1125 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1127 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1130 *((TUPLE *)outp) = tup; /* put the new tuple */
1131 /* pointer where the */
1132 /* caller wants it */
1136 /*----------------------------------------------------------*/
1140 /* Format a tuple on output logging file for
1143 /*----------------------------------------------------------*/
1147 char *name; /* tuple name of the field */
1148 char *dp; /* pointer to the data */
1150 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1151 register int i; /* index to fields */
1152 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1156 * Handle special case where tuple is null
1160 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1164 GDB_CHECK_TUP(tup,"g_tp_form: format tuple")
1166 * Get the descriptor--for now, we won't print it
1168 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1174 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1177 * Now, for each field, print it
1180 for (i=0; i<tpd->field_count; i++) {
1181 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1183 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1186 fprintf(gdb_log,"END_OF_TUPLE\n");
1190 /************************************************************************/
1194 /* The distinction between tuple_data_t and tuple_t is a
1195 /* subtle one. Tuple_t is used when a single tuple is to
1196 /* be decoded, outside of any larger context. It (re)allocates
1197 /* memory for both the tuple itself and its descriptor.
1199 /* Tuple_data is used in the case where the tuple and its
1200 /* descriptor are already allocated, but only the data is
1201 /* to be received. This is useful in cases like receiving an
1202 /* entire relation, in which the descriptor is common to
1203 /* all the tuples, and should not be resent or reallocated
1204 /* with each one. Receive relation can send the tuple descriptor
1205 /* once, then do a create_tuple followed by a decode tuple_data
1206 /* to receive the tuple field data into the existing tuple.
1208 /* Note that the definition of null is different in the two cases.
1209 /* The null value for a tuple is just a null pointer. The null
1210 /* for tuple data is to null each of the fields in the tuple
1211 /* recursively. The routines in this section may dereference
1212 /* null pointers if the tuples they are passed are null. Note
1213 /* also that there is one less level of indirection in passing
1214 /* data to these routines than to those of tuple_t.
1216 /* Note also that the null and decode routines supplied here
1217 /* presume that any fields with dependent memory (e.g. string_t
1218 /* fields have already been cleaned up.)
1220 /* Note that this is not quite a kosher type, in the sense that
1221 /* it's length is not fixed. The entry for length below
1222 /* is meaningless, because the real length is computed from the
1223 /* desc. Among other things, this means that TUPLEs cannot
1224 /* contain fields of this type.
1226 /************************************************************************/
1228 #define TDT_LEN (sizeof(TUPLE))
1229 #define TDT_ALI TDT_LEN
1230 #define TDT_NULL g_tdt_null
1231 #define TDT_CDLEN g_tdt_cdlen
1232 #define TDT_ENC g_tdt_enc
1233 #define TDT_DEC g_tdt_dec
1234 #define TDT_FORM g_tdt_form
1235 #define TDT_NAME "TUPLE_DATA_T"
1237 /*----------------------------------------------------------*/
1241 /* Fill in a null value for a tuple.
1243 /*----------------------------------------------------------*/
1246 char *dp; /* pointer to the data */
1248 TUPLE tup = (TUPLE)dp; /* dp is of type TUPLE, */
1249 /* which is actually */
1250 /* a pointer to the */
1252 TUPLE_DESCRIPTOR tpd; /* the descriptor for this */
1254 register int i; /* a loop counter */
1257 * For each field in the tuple, call its null routine
1259 tup->id = GDB_TUP_ID;
1261 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1263 for (i=0; i<tpd->field_count; i++) {
1264 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),NULL_PROPERTY)
1265 (FIELD_FROM_TUPLE(tup,i));
1269 /*----------------------------------------------------------*/
1273 /* Return coded length for tuple data. Since the descriptor
1274 /* for the tuple is known at both sides, we send only
1275 /* the coded fields, not even the field counts.
1277 /*----------------------------------------------------------*/
1280 g_tdt_cdlen(dp,hcon)
1281 char *dp; /* pointer to the data */
1282 HALF_CONNECTION hcon;
1284 register TUPLE tup = (TUPLE)dp; /* arg typed as tuple */
1285 register int len; /* accumulated length */
1286 register int i; /* index to fields */
1287 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1290 * Validate the tuple data
1293 GDB_GIVEUP("g_tdt_cdlen (coded length) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1294 GDB_CHECK_TUP(tup,"g_tdt_cdlen: compute coded length of tuple data")
1296 * First, find the tuple descriptor and set initial coded len to 0
1299 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1303 * Now, for each field, add in its coded length
1306 for (i=0; i<tpd->field_count; i++) {
1307 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1308 CODED_LENGTH_PROPERTY)
1309 (FIELD_FROM_TUPLE(tup, i),hcon);
1315 /*----------------------------------------------------------*/
1319 /* Encode tuple data for transmission.
1321 /*----------------------------------------------------------*/
1324 g_tdt_enc(dp, hcon, outp)
1325 char *dp; /* pointer to data */
1326 HALF_CONNECTION hcon; /* connection descriptor */
1327 char *outp; /* place to put the output */
1329 register TUPLE tup = (TUPLE)dp; /* type as tuple */
1330 register int i; /* index to fields */
1331 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1332 char *op = outp; /* next byte of output */
1335 * Validate the tuple data
1338 GDB_GIVEUP("g_tdt_enc (encode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1339 GDB_CHECK_TUP(tup,"g_tdt_enc: encode of tuple data")
1341 * First, get the tuple descriptor
1344 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1347 * Now, for each field, code it
1350 for (i=0; i<tpd->field_count; i++) {
1351 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1353 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1359 /*----------------------------------------------------------*/
1363 /* Decode tuple data from external form. We presume
1364 /* that the tuple itself is allocated, and the descriptor
1365 /* properly set up for the local machine representation.
1366 /* Here we just decode the fields.
1368 /*----------------------------------------------------------*/
1371 g_tdt_dec(outp, hcon, inp)
1372 char *inp; /* pointer to input data */
1373 HALF_CONNECTION hcon; /* connection descriptor */
1374 char *outp; /* place to put the output */
1376 register TUPLE tup = (TUPLE)outp; /* the filled in tuple */
1377 register int i; /* index to fields */
1378 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1379 char *ip = inp; /* next byte of input */
1382 * Validate the tuple data
1385 GDB_GIVEUP("g_tdt_dec (decode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1386 GDB_CHECK_TUP(tup,"g_tdt_dec: decode of tuple data")
1388 * First, get the tuple descriptor
1391 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1394 * Now, for each field, decode it.
1397 for (i=0; i<tpd->field_count; i++) {
1398 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1400 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1406 /*----------------------------------------------------------*/
1410 /* Format tuple data on output logging file for
1413 /*----------------------------------------------------------*/
1416 g_tdt_form(name, dp)
1417 char *name; /* tuple name of the field */
1418 char *dp; /* pointer to the data */
1420 register TUPLE tup = (TUPLE)dp; /* as tuple */
1421 register int i; /* index to fields */
1422 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1426 * Handle special case where we're given a null address for the
1430 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1436 * Validate the tuple data
1438 GDB_CHECK_TUP(tup,"g_tdt_form: format tuple data")
1440 * Get the descriptor--for now, we won't print it
1442 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1448 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1451 * Now, for each field, print it
1454 for (i=0; i<tpd->field_count; i++) {
1455 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1457 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1460 fprintf(gdb_log,"END_OF_TUPLE\n");
1464 /************************************************************************/
1468 /* Relations consist of link lists of tuples, all of which are
1469 /* presumed to share a tuple descriptor. For transmission,
1470 /* these are encoded as follows:
1472 /* 1) A count of the number of tuples, sent as a properly coded
1475 /* 2) The tuple descriptor itself, encoded by its encoding routine.
1477 /* 3) For each tuple, its tuple data, encoded using the routines
1478 /* of the tuple_data_t type.
1480 /************************************************************************/
1482 #define REL_LEN (sizeof(RELATION))
1483 #define REL_ALI REL_LEN
1484 #define REL_NULL g_rel_null
1485 #define REL_CDLEN g_rel_cdlen
1486 #define REL_ENC g_rel_enc
1487 #define REL_DEC g_rel_dec
1488 #define REL_FORM g_rel_form
1489 #define REL_NAME "RELATION_T"
1492 /*----------------------------------------------------------*/
1496 /* Fill in a null value for a relation. Maybe we should
1497 /* check for an existing relation and properly free it,
1498 /* but for now, we don't.
1500 /*----------------------------------------------------------*/
1503 char *dp; /* pointer to the data */
1505 *((RELATION *)dp) = NULL;
1508 /*----------------------------------------------------------*/
1512 /* Return coded length for a relation.
1514 /*----------------------------------------------------------*/
1517 g_rel_cdlen(dp,hcon)
1518 char *dp; /* pointer to the data */
1519 HALF_CONNECTION hcon;
1521 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1522 int len; /* accumulated length */
1523 register TUPLE t; /* index to a tuple */
1524 int tuple_count = 0; /* number of tuples in this */
1526 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1530 * Validate the relation
1533 GDB_GIVEUP("g_rel_cdlen (coded length) was given null relation\nthis may be due to an attempt to transmit invalid data")
1534 GDB_CHECK_REL(rel,"g_rel_cdlen: compute coded length of relation")
1536 * First, get the tuple descriptor for this relation
1539 tpd = DESCRIPTOR_FROM_RELATION(rel);
1542 * Count the number of tuples in the relation
1544 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1545 t = NEXT_TUPLE_IN_RELATION(rel,t))
1548 * Start with the coded length for the tuple count and the
1549 * descriptor, which are sent first.
1552 len = g_in_cdlen((char *)&tuple_count, hcon); /* length of tuple_count */
1554 len += g_tpd_cdlen((char *)&tpd, hcon);
1557 * Now, for each tuple, add in its coded length
1560 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1561 t = NEXT_TUPLE_IN_RELATION(rel,t))
1562 len += g_tdt_cdlen((char *)t, hcon);
1567 /*----------------------------------------------------------*/
1571 /* Encode a relation for transmission
1573 /*----------------------------------------------------------*/
1576 g_rel_enc(dp, hcon, outp)
1577 char *dp; /* pointer to data */
1578 HALF_CONNECTION hcon; /* connection descriptor */
1579 char *outp; /* place to put the output */
1581 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1582 char *op; /* pointer to next unused */
1584 register TUPLE t; /* index to a tuple */
1585 int tuple_count = 0; /* number of tuples in this */
1587 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1591 * Validate the relation
1594 GDB_GIVEUP("g_rel_enc (encode) was given null relation\nthis may be due to an attempt to transmit invalid data")
1595 GDB_CHECK_REL(rel,"g_rel_enc: encode relation")
1598 * First, get the tuple descriptor for this relation
1601 tpd = DESCRIPTOR_FROM_RELATION(rel);
1604 * Count the number of tuples in the relation
1606 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1607 t = NEXT_TUPLE_IN_RELATION(rel,t))
1610 * Encode the count and the tuple descriptor for this relation
1613 op = (char *)g_in_enc((char *)&tuple_count, hcon,outp);
1614 /* length of tuple_count */
1616 op = (char *)g_tpd_enc((char *)&tpd, hcon,op);
1619 * Now, encode each tuple
1622 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1623 t = NEXT_TUPLE_IN_RELATION(rel,t))
1624 op = (char *)g_tdt_enc((char *)t, hcon, op);
1629 /*----------------------------------------------------------*/
1633 /* Decode a relation from external form. We should
1634 /* really check to make sure the relation we are given
1635 /* is null, and if not, call delete_relation on it
1636 /* first. For the moment, we just presume it's null.
1638 /* We proceed by decoding the integer count and the
1639 /* tuple descriptor, from which we create the null
1640 /* relation. We then loop for each tuple, doing a
1641 /* create, a decode, and an add to relation.
1643 /*----------------------------------------------------------*/
1646 g_rel_dec(outp, hcon, inp)
1647 char *inp; /* pointer to input data */
1648 HALF_CONNECTION hcon; /* connection descriptor */
1649 char *outp; /* place to put the output */
1651 register RELATION rel; /* build the relation here */
1652 char *ip; /* pointer to next unused */
1654 register TUPLE t; /* index to a tuple */
1655 register int i; /* loop counter on tuples */
1656 int tuple_count = 0; /* number of tuples in this */
1658 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1662 * First, get the field count and tuple descriptor for this relation
1665 ip = (char *)g_in_dec((char *)&tuple_count, hcon, inp);
1667 tpd = NULL; /* so decode will know */
1668 /* there's no existing one */
1670 ip = (char *)g_tpd_dec((char *)&tpd, hcon, ip);
1673 * Now, create a null relation using the descriptor
1676 rel = create_relation(tpd);
1679 * The reference count for the tuple descriptor is currently 2,
1680 * one from the tpd_dec and one from the create relation. Since
1681 * these will not be undone separately, we decrement the reference
1685 UNREFERENCE_TUPLE_DESCRIPTOR(tpd);
1688 * For each tuple, create it, receive it, add it to the relation
1691 for (i=0; i<tuple_count; i++) {
1692 t = create_tuple(tpd);
1693 ip = (char *)g_tdt_dec((char *)t, hcon, ip);
1694 ADD_TUPLE_TO_RELATION(rel, t);
1698 * Now store the address of the created relation where requested
1699 * and return pointer to next available input byte.
1702 *((RELATION *)outp) = rel;
1707 /*----------------------------------------------------------*/
1711 /* Format a relation on output logging file for
1714 /*----------------------------------------------------------*/
1717 g_rel_form(name, dp)
1718 char *name; /* relation name of the field */
1719 char *dp; /* pointer to the data */
1721 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1727 * Handle special case where relation is null
1731 fprintf(gdb_log,"\nRELATION Name=%s is NULL\n===========================\n",name);
1735 GDB_CHECK_REL(rel,"g_rel_form: format relation")
1741 fprintf(gdb_log,"\nRELATION at address: 0x%x Name=%s\n===========================\n",rel,name);
1744 * Now, for each field, print it
1747 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1748 t = NEXT_TUPLE_IN_RELATION(rel,t)){
1749 (void) sprintf(buffer,"Number %d",++count);
1750 g_tdt_form(buffer,(char *)t);
1753 fprintf(gdb_log,"END_OF_RELATION\n");
1757 /************************************************************************/
1759 /* DECLARE AND INITIALIZE THE SYSTEM TYPE DEFINITION
1762 /* This representation is clearly a real pain to keep up to date
1763 /* properly, mostly because C has such a lousy pre-processor.
1764 /* Probably this should be re-arranged so an initialization routine
1765 /* is called to set up the tables, but even that might be a nuissance.
1767 /************************************************************************/
1769 /*----------------------------------------------------------*/
1773 /* Called at startup to initialize the type table with
1774 /* the entries for the system types.
1776 /*----------------------------------------------------------*/
1778 #define ITYPE(inx,lp,ap,np,clp,ep,dp,fp,name) {\
1779 g_type_table[inx][LENGTH_PROPERTY].i = lp; \
1780 g_type_table[inx][ALIGNMENT_PROPERTY].i = ap; \
1781 g_type_table[inx][NULL_PROPERTY].f = np; \
1782 g_type_table[inx][CODED_LENGTH_PROPERTY].f = clp; \
1783 g_type_table[inx][ENCODE_PROPERTY].cpf = ep; \
1784 g_type_table[inx][DECODE_PROPERTY].cpf = dp; \
1785 g_type_table[inx][FORMAT_PROPERTY].f = fp; \
1786 g_type_table[inx][NAME_PROPERTY].cp = name; \
1792 gdb_n_types = SYSTEM_TYPE_COUNT;
1794 ITYPE(INTEGER_T,IN_LEN,IN_ALI,IN_NULL,IN_CDLEN,IN_ENC,IN_DEC,IN_FORM,
1796 ITYPE(STRING_T,ST_LEN,ST_ALI,ST_NULL,ST_CDLEN,ST_ENC,ST_DEC,ST_FORM,
1798 ITYPE(REAL_T,RL_LEN,RL_ALI,RL_NULL,RL_CDLEN,RL_ENC,RL_DEC,RL_FORM,
1800 ITYPE(DATE_T,DT_LEN,DT_ALI,DT_NULL,DT_CDLEN,DT_ENC,DT_DEC,DT_FORM,
1802 ITYPE(TUPLE_DESCRIPTOR_T,TPD_LEN,TPD_ALI,TPD_NULL,TPD_CDLEN,TPD_ENC,
1803 TPD_DEC,TPD_FORM,TPD_NAME)
1804 ITYPE(TUPLE_T,TP_LEN,TP_ALI,TP_NULL,TP_CDLEN,TP_ENC,TP_DEC,TP_FORM,
1806 ITYPE(TUPLE_DATA_T,TDT_LEN,TDT_ALI,TDT_NULL,TDT_CDLEN,TDT_ENC,TDT_DEC,
1808 ITYPE(RELATION_T,REL_LEN,REL_ALI,REL_NULL,REL_CDLEN,REL_ENC,REL_DEC,