7 #ifdef DYNAMIC_COMMAND_SUPPORT
11 typedef unsigned long ulong;
13 #ifdef DYNAMIC_COMMAND_SUPPORT
15 dlopen_command PARAMS ((char *, int));
18 #ifdef DYNAMIC_COMMAND_SUPPORT
21 dlopen_command (arg, from_tty)
30 error ("No arguments specified.");
34 while(*p != ' ' && *p != '\0')
37 error ("Not enough arguments.");
42 hdl = dlopen(arg, RTLD_NOW);
44 fprintf(stderr, "%s: %s\n", arg, dlerror());
50 fprintf(stderr, "%s: %s\n", p, dlerror());
59 local_shell_escape (char *arg)
62 /* FIXME: what about errors (I don't know how GO32 system() handles
69 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
70 user_shell = "/bin/sh";
72 /* Get the name of the shell for arg0 */
73 if ((p = strrchr (user_shell, '/')) == NULL)
76 p++; /* Get past '/' */
78 if ((pid = fork()) == 0)
81 execl (user_shell, p, 0);
83 execl (user_shell, p, "-c", arg, 0);
85 fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
86 safe_strerror (errno));
87 gdb_flush (gdb_stderr);
92 while ((rc = wait (&status)) != pid && rc != -1)
95 error ("Fork failed");
96 #endif /* Can fork. */
100 GetClassName(long objectID, char* name)
102 register value_ptr val;
103 register struct symbol *sym;
104 struct minimal_symbol *msymbol;
109 /* Find the address of RemoteGetClassName in the inferior. */
111 sym = lookup_symbol ("RemoteGetClassName", 0, VAR_NAMESPACE, 0, NULL);
114 if (SYMBOL_CLASS (sym) != LOC_BLOCK)
116 error ("\"RemoteGetClassName\" exists in this program but is not a function.");
118 val = value_of_variable (sym, NULL);
122 msymbol = lookup_minimal_symbol ("RemoteGetClassName", "", (struct objfile *) NULL);
125 type = lookup_pointer_type (builtin_type_char);
126 type = lookup_function_type (type);
127 type = lookup_pointer_type (type);
128 maddr = (LONGEST) SYMBOL_VALUE_ADDRESS (msymbol);
129 val = value_from_longest (type, maddr);
133 error ("evaluation of this expression requires the program to have a function \"RemoteGetClassName\".");
137 blocklen = value_from_longest (builtin_type_int, (LONGEST) objectID);
138 val = call_function_by_hand (val, 1, &blocklen);
139 if (value_logical_not (val))
141 error ("Could not get class name.");
143 read_memory(value_as_pointer(val), name, 32);
148 GetBasePtr(long objectID)
150 register value_ptr val;
151 register struct symbol *sym;
152 struct minimal_symbol *msymbol;
157 /* Find the address of RemoteGetBasePtr in the inferior. */
159 sym = lookup_symbol ("RemoteGetBasePtr", 0, VAR_NAMESPACE, 0, NULL);
162 if (SYMBOL_CLASS (sym) != LOC_BLOCK)
164 error ("\"RemoteGetBasePtr\" exists in this program but is not a function.");
166 val = value_of_variable (sym, NULL);
170 msymbol = lookup_minimal_symbol ("RemoteGetBasePtr", "", (struct objfile *) NULL);
173 type = lookup_pointer_type (builtin_type_char);
174 type = lookup_function_type (type);
175 type = lookup_pointer_type (type);
176 maddr = (LONGEST) SYMBOL_VALUE_ADDRESS (msymbol);
177 val = value_from_longest (type, maddr);
181 error ("evaluation of this expression requires the program to have a function \"RemoteGetBasePtr\".");
185 blocklen = value_from_longest (builtin_type_int, (LONGEST) objectID);
186 val = call_function_by_hand (val, 1, &blocklen);
187 if (value_logical_not (val))
189 error ("Could not get base pointer to object.");
191 return value_as_pointer(val);
195 dump_extra_data(CORE_ADDR addr, ulong length)
197 ulong buf[5], chunk, i;
201 chunk = (length > 16) ? 16 : length;
203 memset(buf, 0, 5*sizeof(long));
204 read_memory(addr, &buf, chunk);
205 fprintf(gdb_stdout, "%08lx %08lx %08lx %08lx | ", buf[0],
206 buf[1], buf[2], buf[3]);
207 for (i = 0, p = (char*)buf; i < chunk; i++, p++) {
211 fprintf(gdb_stdout, "%s |\n", buf);
217 struct type *type_of_object(CORE_ADDR object)
219 char className[32], classAllFieldsName[128];
220 struct type *type = NULL;
221 GetClassName(object, className);
222 sprintf(classAllFieldsName, "%s_AllFields", className);
224 type = lookup_typename(classAllFieldsName, (struct block *)NULL, 0);
225 return lookup_pointer_type(type);
228 CORE_ADDR baseptr_of_object(ulong object)
230 return GetBasePtr(object) + 12;
235 print_object (arg, dump)
240 ulong object, objectLength, typeLength = 0;
241 char className[32], classAllFieldsName[128];
242 struct type* type = NULL;
244 object = parse_and_eval_address(arg);
246 GetClassName(object, className);
247 sprintf(classAllFieldsName, "%s_AllFields", className);
249 type = lookup_typename(classAllFieldsName, (struct block *)NULL, 0);
250 typeLength = TYPE_LENGTH(type);
251 addr = GetBasePtr(object);
252 read_memory(addr, &objectLength, 4);
255 if (TYPE_CODE(type) != TYPE_CODE_UNDEF && !(TYPE_FLAGS(type)&TYPE_FLAG_STUB)) {
257 value_ptr valptr = value_at_lazy(type, addr);
258 int histindex = record_latest_value(valptr);
259 printf_filtered("Object 0x%08lx at address 0x%08lx of class %s\n",
260 object, addr, className);
261 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
262 value_print(valptr, gdb_stdout, 0, Val_prettyprint);
263 objectLength -= typeLength;
265 printf_filtered("\n");
266 dump_extra_data(addr, objectLength);
267 printf_filtered("\n");
269 value_ptr valptr = value_from_longest(lookup_pointer_type(type), addr);
270 int histindex = record_latest_value(valptr);
271 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
272 value_print(valptr, gdb_stdout, 0, Val_prettyprint);
273 printf_filtered("\n");
280 dobj_command (arg, from_tty)
284 print_object(arg, 1);
289 pobj_command (arg, from_tty)
293 print_object(arg, 0);
298 getint_command (arg, from_tty)
302 char shellCommand[128];
304 sprintf(shellCommand, "getint %s", arg);
305 local_shell_escape(shellCommand);
310 getindexical_command (arg, from_tty)
314 char shellCommand[128];
316 sprintf(shellCommand, "getindexical %s", arg);
317 local_shell_escape(shellCommand);
322 exc_command (arg, from_tty)
326 char shellCommand[128];
329 sprintf(shellCommand, "getexc %s", arg);
330 local_shell_escape(shellCommand);
333 static CORE_ADDR dispatch_method_addr = -1, dispatch_inherited_addr = -1, dispatch_delegated_addr = -1, dispatch_intrinsic_addr = -1;
334 CORE_ADDR do_dispatch_method_addr = -1, do_dispatch_intrinsic_addr = -1;
337 lookup_address(const char *name)
339 struct symbol *sym = lookup_symbol(name, NULL, VAR_NAMESPACE, NULL, NULL);
341 return BLOCK_START(SYMBOL_BLOCK_VALUE(sym));
344 /* printf("Couldn't find %s!\n", name); */
352 dispatch_method_addr = lookup_address("__DispatchMethod");
353 dispatch_inherited_addr = lookup_address("__DispatchInherited");
354 dispatch_delegated_addr = lookup_address("__DispatchDelegated");
355 dispatch_intrinsic_addr = lookup_address("__DispatchIntrinsic");
356 do_dispatch_method_addr = lookup_address("__DoTheDispatch");
357 do_dispatch_intrinsic_addr = lookup_address("__DoDispatchIntrinsic");
361 is_dispatch(CORE_ADDR pc)
363 return (pc == dispatch_method_addr) || (pc == dispatch_inherited_addr) || (pc == dispatch_delegated_addr);
367 is_dispatch_intrinsic(CORE_ADDR pc)
369 return pc == dispatch_intrinsic_addr;
372 /* If we are stopped at one of the entry points to the dispatcher, we want to continue until just
373 before we jump to the implementation. If we are at that point, we want to continue until we
374 actually get to the implementation. Likewise for the intrinsic dispatcher
377 deal_with_dispatch(CORE_ADDR stop_pc)
379 if (is_dispatch(stop_pc))
380 return do_dispatch_method_addr;
381 else if (is_dispatch_intrinsic(stop_pc))
382 return do_dispatch_intrinsic_addr;
383 else if (stop_pc == do_dispatch_method_addr)
384 /* This assumes that we branch through t6 */
385 return read_register(14);
386 else if (stop_pc == do_dispatch_intrinsic_addr)
387 /* This assumes that we branch through t0 */
388 return read_register(8);
394 magic_create_inferior_hook()
396 struct symbol *sym = lookup_symbol("gHandleError", NULL, VAR_NAMESPACE, NULL, NULL);
399 CORE_ADDR addr = SYMBOL_VALUE(sym);
400 unsigned long errorDebugger = 2;
401 target_write_memory(addr, &errorDebugger, 4);
410 add_com ("dobj", class_support, dobj_command, "Display Object Contents");
411 add_com ("pobj", class_support, pobj_command, "Print object base pointer");
412 add_com ("getint", class_support, getint_command, "Convert intrinsic name to number or vice versa.");
413 add_com ("getindexical", class_support, getindexical_command, "Convert indexical name to number or vice versa.");
414 add_com ("exc", class_support, exc_command, "Convert exception name to number or vice versa.");
416 #ifdef DYNAMIC_COMMAND_SUPPORT
417 add_com ("dlopen", class_support, dlopen_command,
418 "Load the dynamic library specified and execute the specified symbol");