1 /* Kernel Object Display facility for Cisco
2 Copyright 1999 Free Software Foundation, Inc.
4 Written by Tom Tromey <tromey@cygnus.com>.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
29 /* Define this to turn off communication with target. */
30 /* #define FAKE_PACKET */
32 /* Size of buffer used for remote communication. */
35 /* Pointers to gdb callbacks. */
36 static void (*gdb_kod_display) (char *);
37 static void (*gdb_kod_query) (char *, char *, int *);
41 /* Initialize and return library name and version.
42 The gdb side of KOD, kod.c, passes us two functions: one for
43 displaying output (presumably to the user) and the other for
44 querying the target. */
46 cisco_kod_open (void (*display_func) (char *),
47 void (*query_func) (char *, char *, int *))
53 gdb_kod_display = display_func;
54 gdb_kod_query = query_func;
56 /* Get the OS info, and check the version field. This is the stub
57 version, which we use to see whether we will understand what
58 comes back. This is lame, but the `qKoL' request doesn't
59 actually provide enough configurability.
61 Right now the only defined version number is `0.0.0'.
62 This stub supports qKoI and the `a' (any) object requests qKaL
63 and qKaI. Each `a' object is returned as a 4-byte integer ID.
64 An info request on an object returns a pair of 4-byte integers;
65 the first is the object pointer and the second is the thread ID. */
68 (*gdb_kod_query) ("oI;", buffer, &bufsiz);
70 strcpy (buffer, "Cisco IOS/Classic/13.4 0.0.0");
74 for (i = 0; count && buffer[i] != '\0'; ++i)
80 if (buffer[i] == '\0')
81 error ("Remote returned malformed packet\n");
82 if (strcmp (&buffer[i], "0.0.0"))
83 error ("Remote returned unknown stub version: %s\n", &buffer[i]);
85 /* Return name, version, and description. I hope we have enough
87 return (strdup ("gdbkodcisco v0.0.0 - Cisco Kernel Object Display"));
90 /* Close the connection. */
96 /* Print a "bad packet" message. */
100 (*gdb_kod_display) ("Remote target returned malformed packet.\n");
103 /* Print information about currently known kernel objects.
104 We currently ignore the argument. There is only one mode of
105 querying the Cisco kernel: we ask for a dump of everything, and
108 cisco_kod_request (char *arg, int from_tty)
110 char buffer[PBUFSIZ], command[PBUFSIZ];
117 char *prev_id = NULL;
119 if (! arg || strcmp (arg, "any"))
121 /* "Top-level" command. This is really silly, but it also seems
122 to be how KOD is defined. */
123 /* Even sillier is the fact that this first line must start
124 with the word "List". See kod.tcl. */
125 (*gdb_kod_display) ("List of Cisco Kernel Objects\n");
126 (*gdb_kod_display) ("Object\tDescription\n");
127 (*gdb_kod_display) ("any\tAny and all objects\n");
133 int off = 0; /* Where we are in the string. */
134 long count; /* Number of objects in this packet. */
135 int bufsiz = PBUFSIZ;
138 strcpy (command, "aL");
141 strcat (command, ",");
142 strcat (command, prev_id);
144 strcat (command, ";");
147 /* We talk to the target by calling through the query function
148 passed to us when we were initialized. */
149 (*gdb_kod_query) (command, buffer, &bufsiz);
151 /* Fake up a multi-part packet. */
152 if (! strncmp (&command[3], "a500005a", 8))
153 strcpy (buffer, "KAL,01,1,f500005f;f500005f;");
155 strcpy (buffer, "KAL,02,0,a500005a;a500005a;de02869f;");
158 /* Empty response is an error. */
159 if (strlen (buffer) == 0)
161 (*gdb_kod_display) ("Remote target did not recognize kernel object query command.\n");
166 /* If we don't get a `K' response then the buffer holds the
167 target's error message. */
168 if (buffer[0] != 'K')
170 (*gdb_kod_display) (buffer);
175 /* Make sure we get the response we expect. */
176 if (strncmp (buffer, "KAL,", 4))
184 /* Parse out the count. We expect to convert exactly two
185 characters followed by a comma. */
186 count = strtol (&buffer[off], &s_end, 16);
187 if (s_end - &buffer[off] != 2 || buffer[off + 2] != ',')
195 /* Parse out the `done' flag. */
196 if ((buffer[off] != '0' && buffer[off] != '1')
197 || buffer[off + 1] != ',')
203 done = buffer[off] == '1';
206 /* Id of the last item; we might this to construct the next
208 prev_id = &buffer[off];
209 if (strlen (prev_id) < 8 || buffer[off + 8] != ';')
215 buffer[off + 8] = '\0';
219 sync_ids = (char **) xmalloc (count * sizeof (char *));
221 sync_ids = (char **) xrealloc (sync_ids,
222 (sync_len + count) * sizeof (char *));
225 for (i = 0; i < count; ++i)
227 if (strlen (&buffer[off]) < 8 || buffer[off + 8] != ';')
233 buffer[off + 8] = '\0';
234 sync_ids[sync_next++] = xstrdup (&buffer[off]);
238 if (buffer[off] != '\0')
246 /* We've collected all the sync object IDs. Now query to get the
247 specific information, and arrange to print this info. */
250 (*gdb_kod_display) ("Object ID\tObject Pointer\tThread ID\n");
252 for (i = 0; i < sync_next; ++i)
255 int bufsiz = PBUFSIZ;
257 /* For now assume a query can be accomplished in a single
258 transaction. This is implied in the protocol document.
259 See comments above, and the KOD protocol document, to
260 understand the parsing of the return value. */
261 strcpy (command, "aI,");
262 strcat (command, sync_ids[i]);
263 strcat (command, ";");
266 (*gdb_kod_query) (command, buffer, &bufsiz);
268 strcpy (buffer, "KAI,");
269 strcat (buffer, sync_ids[i]);
270 strcat (buffer, ",ffef00a0,cd00123d;");
273 if (strlen (buffer) == 0)
275 (*gdb_kod_display) ("Remote target did not recognize KOD command.\n");
279 if (strncmp (buffer, "KAI,", 4))
286 if (strncmp (&buffer[off], sync_ids[i], 8)
287 || buffer[off + 8] != ',')
294 /* Extract thread id and sync object pointer. */
295 if (strlen (&buffer[off]) != 2 * 8 + 2
296 || buffer[off + 8] != ','
297 || buffer[off + 17] != ';')
303 buffer[off + 8] = '\0';
304 buffer[off + 17] = '\0';
306 /* Display the result. */
307 (*gdb_kod_display) (sync_ids[i]);
308 (*gdb_kod_display) ("\t");
309 (*gdb_kod_display) (&buffer[off]);
310 (*gdb_kod_display) ("\t");
311 (*gdb_kod_display) (&buffer[off + 9]);
312 (*gdb_kod_display) ("\n");
317 for (i = 0; i < sync_next; ++i)