7 static char *rcsid_gdb_c = "$Header$";
11 /************************************************************************/
15 /* Global Database Library - main controlling functions and globally
18 /* Author: Noah Mendelsohn
20 /* Copyright: 1986 MIT Project Athena
23 /* In addition to defining the main routines for gdb, this source
24 /* file #includes gdb_lib.h, which does the external definitions
25 /* for all global data used by the library. Everyone else gets
26 /* externs for this data defined by gdb.h.
28 /************************************************************************/
39 extern char *sys_errlist[];
43 /* This global is defined to make sure that Moira clients are linked
44 * against the correct library.
46 int link_against_the_moira_version_of_gdb = 0;
47 int g_inited = FALSE; /* gdb_init has not been */
50 /*----------------------------------------------------------*/
54 /* Initialize the global database facility. Must be
55 /* called before any of the other gdb functions
56 /* are used. Among other things, this function
57 /* sets to ignore signals for writing on broken pipes.
59 /*----------------------------------------------------------*/
65 char hostname[255]; /* name of local host */
66 extern uid_t getuid();
67 int uid; /* Unix user-i.d. number */
68 char *uname; /* string form of i.d. */
70 struct passwd *pw_struct; /* passwd entry comes back */
73 * So we know we've been initialized, and we do it only once
80 * Initialize the system defined types table
85 * Initialize the connection control data structures.
87 gdb_mcons = 0; /* number of connections */
89 for (i=0; i<GDB_MAX_CONNECTIONS; i++) {
90 gdb_cons[i].id = GDB_CON_ID;
91 gdb_cons[i].in.stream_buffer = NULL;
92 gdb_cons[i].in.stream_buffer_length = GDB_STREAM_BUFFER_SIZE;
95 * Initialize the fd maps
104 * Initialize the server/client layer
109 * Ignore the signal generated when writing to a pipe which has been
110 * closed at the other end. gdb_move_data handles this condition
113 (void) signal(SIGPIPE, SIG_IGN);
116 * Make a note of the local host and user name
118 if (gethostname(hostname, sizeof(hostname)-1)!=0)
119 (void) strcpy(hostname, "????");
120 gdb_host = db_alloc(strlen(hostname)+1);
121 (void) strcpy(gdb_host, hostname);
125 pw_struct = getpwuid(uid);
127 if (pw_struct != NULL && pw_struct ->pw_name != NULL &&
128 *pw_struct->pw_name !='\0')
129 uname = pw_struct->pw_name;
132 gdb_uname = db_alloc(strlen(uname)+1);
133 (void) strcpy(gdb_uname, uname);
137 /*----------------------------------------------------------*/
141 /* Make sure gdb has been initialized, blow up if not.
143 /*----------------------------------------------------------*/
149 GDB_GIVEUP("You must call gdb_init before using GDB services.")
152 /*----------------------------------------------------------*/
156 /* Count the number of bits in a word. Adapted from
159 /*----------------------------------------------------------*/
165 register unsigned int x = inp; /* the word to check */
166 register int count; /* the count to return */
168 for (count=0; x !=0; x=x>>1)
175 /*----------------------------------------------------------*/
179 /* Utility routine to conditionally free a null
180 /* terminated string.
182 /*----------------------------------------------------------*/
189 db_free(str, strlen(str)+1);
192 /*----------------------------------------------------------*/
196 /* Called when a fatal error occurs.
198 /*----------------------------------------------------------*/
204 fprintf(gdb_log,"\n\nFATAL GDB ERROR:\n\n\t");
205 fprintf(gdb_log,errormsg);
206 fprintf(gdb_log,"\n\n");
210 /*----------------------------------------------------------*/
214 /* Acts like gdb_perror, but takes its errno from
215 /* the connection. Resets errno as a side effect.
216 /* THIS ROUTINE IS A NO_OP IF connection_status(con)!=CON_STOPPING
218 /*----------------------------------------------------------*/
221 connection_perror(con, msg)
225 if (con == NULL || connection_status(con) != CON_STOPPING)
227 errno = connection_errno(con);
231 /*----------------------------------------------------------*/
235 /* Performs same function as system perror, but does
236 /* it on gdb_log instead of stderr.
238 /*----------------------------------------------------------*/
245 fprintf(gdb_log, "%s: ", msg);
247 fprintf(gdb_log, "%s.\n", sys_errlist[errno]);
249 fprintf(gdb_log, "errno %d is out of range of message table.\n");