import gdb-1999-10-18 snapshot
[deliverable/binutils-gdb.git] / gdb / kod.c
CommitLineData
96baa820
JM
1/* Kernel Object Display generic routines and callbacks
2 Copyright 1998, 1999 Free Software Foundation, Inc.
3
4 Written by Fernando Nasser <fnasser@cygnus.com> for Cygnus Solutions.
5
6 This file is part of GDB.
7
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.
12
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.
17
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,
21 Boston, MA 02111-1307, USA. */
22
23#include "defs.h"
24#include "command.h"
25#include "gdbcmd.h"
26#include "target.h"
27#include "gdb_string.h"
c2c6d25f 28#include "kod.h"
96baa820
JM
29
30/* Prototypes for exported functions. */
31void _initialize_kod (void);
32
33/* Prototypes for local functions. */
34static void show_kod (char *, int);
35static void info_kod_command (char *, int);
36static void load_kod_library (char *);
37
38/* Prototypes for callbacks. These are passed into the KOD modules. */
39static void gdb_kod_display (char *);
40static void gdb_kod_query (char *, char *, int *);
41
42/* These functions are imported from the KOD module.
43
44 gdb_kod_open - initiates the KOD connection to the remote. The
45 first argument is the display function the module should use to
46 communicate with the user. The second argument is the query
47 function the display should use to communicate with the target.
48 This should call error() if there is an error. Otherwise it should
49 return a malloc()d string of the form:
50
51 NAME VERSION - DESCRIPTION
52
53 Neither NAME nor VERSION should contain a hyphen.
54
55
56 gdb_kod_request - This is used when the user enters an "info
57 <module>" request. The remaining arguments are passed as the first
58 argument. The second argument is the standard `from_tty'
59 argument.
60
61
62 gdb_kod_close - This is called when the KOD connection to the
63 remote should be terminated. */
64
c2c6d25f
JM
65static char *(*gdb_kod_open) (kod_display_callback_ftype *display,
66 kod_query_callback_ftype *query);
96baa820
JM
67static void (*gdb_kod_request) (char *, int);
68static void (*gdb_kod_close) ();
69
70
71/* Name of inferior's operating system. */
72char *operating_system;
73
74/* We save a copy of the OS so that we can properly reset when
75 switching OS's. */
76static char *old_operating_system;
77
96baa820
JM
78/* Print a line of data generated by the module. */
79
80static void
81gdb_kod_display (char *arg)
82{
83 printf_filtered ("%s", arg);
84}
85
86/* Queries the target on behalf of the module. */
87
88static void
89gdb_kod_query (char *arg, char *result, int *maxsiz)
90{
91 int bufsiz = 0;
92
93 /* Check if current target has remote_query capabilities.
94 If not, it does not have kod either. */
95 if (! current_target.to_query)
96 {
97 strcpy (result,
98 "ERR: Kernel Object Display not supported by current target\n");
99 return;
100 }
101
102 /* Just get the maximum buffer size. */
103 target_query ((int) 'K', 0, 0, &bufsiz);
104
105 /* Check if *we* were called just for getting the buffer size. */
106 if (*maxsiz == 0)
107 {
108 *maxsiz = bufsiz;
109 strcpy (result, "OK");
110 return;
111 }
112
113 /* Check if caller can handle a buffer this large, if not, adjust. */
114 if (bufsiz > *maxsiz)
115 bufsiz = *maxsiz;
116
117 /* See if buffer can hold the query (usually it can, as the query is
118 short). */
119 if (strlen (arg) >= bufsiz)
120 error ("kod: query argument too long");
121
122 /* Send actual request. */
123 if (target_query ((int) 'K', arg, result, &bufsiz))
124 strcpy (result, "ERR: remote query failed");
125}
126
127/* Print name of kod command after selecting the appropriate kod
128 formatting library module. As a side effect we create a new "info"
129 subcommand which is what the user actually uses to query the OS. */
130
131static void
132kod_set_os (char *arg, int from_tty, struct cmd_list_element *command)
133{
134 char *p;
135
136 if (command->type != set_cmd)
137 return;
138
139 /* If we had already had an open OS, close it. */
140 if (gdb_kod_close)
141 (*gdb_kod_close) ();
142
143 /* Also remove the old OS's command. */
144 if (old_operating_system)
145 {
146 delete_cmd (old_operating_system, &infolist);
147 free (old_operating_system);
148 }
149 old_operating_system = strdup (operating_system);
150
151 if (! operating_system || ! *operating_system)
152 {
153 /* If user set operating system to empty, we want to forget we
154 had a module open. Setting these variables is just nice for
155 debugging and clarity. */
156 gdb_kod_open = NULL;
157 gdb_kod_request = NULL;
158 gdb_kod_close = NULL;
159 }
160 else
161 {
162 char *kodlib;
163
164 load_kod_library (operating_system);
165
166 kodlib = (*gdb_kod_open) (gdb_kod_display, gdb_kod_query);
167
168 /* Add kod related info commands to gdb. */
169 add_info (operating_system, info_kod_command,
170 "Displays information about Kernel Objects.");
171
172 p = strrchr (kodlib, '-');
173 if (p != NULL)
174 p++;
175 else
176 p = "Unknown KOD library";
177 printf_filtered ("%s - %s\n", operating_system, p);
178
179 free (kodlib);
180 }
181}
182
183/* Print information about currently known kernel objects of the
184 specified type or a list of all known kernel object types if
185 argument is empty. */
186
187static void
188info_kod_command (char *arg, int from_tty)
189{
190 (*gdb_kod_request) (arg, from_tty);
191}
192
193/* Print name of kod command after selecting the appropriate kod
194 formatting library module. */
195
196static void
197load_kod_library (char *lib)
198{
199#if 0
200 /* FIXME: Don't have the eCos code here. */
201 if (! strcmp (lib, "ecos"))
202 {
203 gdb_kod_open = ecos_kod_open;
204 gdb_kod_request = ecos_kod_request;
205 gdb_kod_close = ecos_kod_close;
206 }
207 else
208#endif /* 0 */
209 if (! strcmp (lib, "cisco"))
210 {
211 gdb_kod_open = cisco_kod_open;
212 gdb_kod_request = cisco_kod_request;
213 gdb_kod_close = cisco_kod_close;
214 }
215 else
216 error ("Unknown operating system: %s\n", operating_system);
217}
218
219void
220_initialize_kod ()
221{
222 struct cmd_list_element *c;
223
224 c = add_set_cmd ("os", no_class, var_string,
225 (char *) &operating_system,
226 "Set operating system",
227 &setlist);
228 c->function.sfunc = kod_set_os;
229 add_show_from_set (c, &showlist);
230}
This page took 0.041298 seconds and 4 git commands to generate.